Geen omschrijving
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.5KB

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