暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

flash.sh 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. if [ "$#" -ne 1 ] ; then
  3. echo "Usage: $0 /dev/disk" >&2
  4. exit 1
  5. fi
  6. # Unmount mounted partitions
  7. for fs in `grep $1 /proc/mounts|cut -d ' ' -f 1` ; do
  8. echo Unmounting $fs
  9. sudo umount $fs
  10. done
  11. echo Overwriting old partition table
  12. sudo dd if=/dev/zero of=$1 bs=1024 count=1024
  13. if [ -e output/images/u-boot.sd ] ; then
  14. echo Recreating new partition table
  15. sed 's/#.*//' << EOF | tr -d " \t" | sudo fdisk $1
  16. n # new partition
  17. p # primary partition
  18. 1 # number 1
  19. # default start
  20. +16M # 16MB
  21. t # New Type field
  22. 53 # OnTrack DM6 Aux3
  23. n # new partition
  24. p # primary partition
  25. 2 # number 2
  26. # default start
  27. # default size
  28. w # write changes
  29. EOF
  30. echo Writing U-Boot bootstream
  31. sudo dd if=output/images/u-boot.sd of="$1"1
  32. elif [ -d output/images/rpi-firmware ] ; then
  33. SIZE=`sudo fdisk -l $1 | grep Disk | grep bytes | awk '{print $5}'`
  34. echo Disk size: $SIZE bytes
  35. CYLINDERS=`echo $SIZE/255/63/512 | bc`
  36. echo Cylinders: $CYLINDERS
  37. sed 's/#.*//' << EOF | tr -d " \t" | sudo sfdisk -D -H 255 -S 63 -C $CYLINDERS $1
  38. ,9,0x0C,* # From http://downloads.angstrom-distribution.org/demo/beaglebone/mkcard.txt
  39. ,,,- # Found in http://elinux.org/RPi_Advanced_Setup#Advanced_SD_card_setup
  40. EOF
  41. echo Creaeting boot filesystem
  42. sudo mkfs.vfat -F 32 -n boot "$1"1
  43. echo Mounting boot filesystem
  44. sudo mkdir -p /media/boot
  45. sudo mount "$1"1 /media/boot
  46. echo Copying bootloader files
  47. sudo cp output/images/rpi-firmware/* /media/boot/
  48. sudo cp output/images/*.dtb /media/boot/
  49. echo Preparing and copying Kernel Image
  50. sudo output/host/usr/bin/mkknlimg output/images/zImage /media/boot/zImage
  51. echo Synchronising changes to disk
  52. sudo sync
  53. echo Unmounting boot filesystem
  54. sudo umount /media/boot
  55. sudo rm -rf /media/boot
  56. else
  57. echo Could not find a suitable bootstream!
  58. fi
  59. if [ -e output/images/rootfs.tar ] ; then
  60. echo Creating root filesystem
  61. sudo mkfs.ext4 "$1"2 -L rootfs
  62. echo Mounting root filesystem
  63. sudo mkdir -p /media/rootfs
  64. sudo mount "$1"2 /media/rootfs
  65. echo Copying root filesystem
  66. sudo tar xfp output/images/rootfs.tar -C /media/rootfs
  67. echo Synchronising changes to disk
  68. sudo sync
  69. echo Unmounting root filesystem
  70. sudo umount /media/rootfs
  71. sudo rm -rf /media/rootfs
  72. elif [ -e output/images/rootfs.ext2 ] ; then
  73. echo Writing ext2 root filesystem
  74. sudo dd if=output/images/rootfs.ext2 of="$1"2 bs=512
  75. echo Synchronising changes to disk
  76. sudo sync
  77. else
  78. echo Could not find a suitable root filesystem!
  79. fi