Advertisement
Guest User

Untitled

a guest
Jun 11th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.54 KB | None | 0 0
  1. #!/bin/bash
  2. # mkcard.sh v0.5
  3. # (c) Copyright 2009 Graeme Gregory <[email protected]>
  4. # Licensed under terms of GPLv2
  5. #
  6. # Parts of the procudure base on the work of Denys Dmytriyenko
  7. # http://wiki.omap.com/index.php/MMC_Boot_Format
  8. #
  9. # Extended for 3 partitions by Prasad Golla <[email protected]> in April 2011.
  10. # The 'media' partition can be used for storing media clips which can
  11. # be preserved even if the binaries in the other partitions are erased.
  12.  
  13. export LC_ALL=C
  14.  
  15. if [ $# -ne 1 ]; then
  16.         echo "Usage: $0 <drive>"
  17.         exit 1;
  18. fi
  19.  
  20. DRIVE=$1
  21.  
  22. SKIPMEDIA=0
  23.  
  24. function format_boot_drive (){
  25. echo "Formatting boot drive"
  26. if [ -b ${DRIVE}1 ]; then
  27.         umount ${DRIVE}1
  28.         mkfs.vfat -F 32 -n "boot" ${DRIVE}1
  29. else
  30.         if [ -b ${DRIVE}p1 ]; then
  31.                 umount ${DRIVE}p1
  32.                 mkfs.vfat -F 32 -n "boot" ${DRIVE}p1
  33.         else
  34.                 echo "Can't find boot partition in /dev"
  35.         fi
  36. fi
  37. }
  38.  
  39. function format_rootfs_drive (){
  40. echo "Formatting rootfs drive"
  41. if [ -b ${DRIVE}2 ]; then
  42.         umount ${DRIVE}2
  43.         mke2fs -j -L "rootfs" ${DRIVE}2
  44. else
  45.         if [ -b ${DRIVE}p2 ]; then
  46.                 umount ${DRIVE}p2
  47.                 mke2fs -j -L "rootfs" ${DRIVE}p2
  48.         else
  49.                 echo "Can't find rootfs partition in /dev"
  50.         fi
  51. fi
  52. }
  53.  
  54. function format_media_drive (){
  55. echo "Formatting media mediadrive"
  56. if [ -b ${DRIVE}3 ]; then
  57.         umount ${DRIVE}3
  58.         mkfs.vfat -F 32 -n "media" ${DRIVE}3
  59. else
  60.         if [ -b ${DRIVE}p3 ]; then
  61.                 umount ${DRIVE}p3
  62.                 mkfs.vfat -F 32 -n "media" ${DRIVE}p3
  63.         else
  64.                 echo "Can't find media partition in /dev"
  65.         fi
  66. fi
  67. }
  68.  
  69. function get_media_drive_size(){
  70.  
  71. echo "How big of a media drive do you want?"
  72. echo "Enter 0 to NOT create the media drive."
  73. echo "Enter 1 for 1GB."
  74. echo "Enter 64 for 64MB."
  75. echo "Enter 128 for 128MB."
  76. echo "Enter 512 for 512MB."
  77. echo "Enter 256 for 256MB."
  78. echo -n "Enter size of media drive you want: "
  79.  
  80. read disksize
  81.  
  82. case "$disksize" in
  83. 0)   SKIPMEDIA=1; return ;;
  84. 1)   MEDIASIZEREQ=`echo "1024 * 1024 * 1024" | bc` ;;
  85. 512) MEDIASIZEREQ=`echo "1024 * 1024 * 1024 / 2" | bc` ;;
  86. 256) MEDIASIZEREQ=`echo "1024 * 1024 * 1024 / 4" | bc` ;;
  87. 128) MEDIASIZEREQ=`echo "1024 * 1024 * 1024 / 8" | bc` ;;
  88. 64)  MEDIASIZEREQ=`echo "1024 * 1024 * 1024 / 16" | bc` ;;
  89. *)   echo "Not a valid option. Try again."; get_media_drive_size;;
  90. esac
  91.  
  92. echo Media size in bytes - $MEDIASIZEREQ
  93. MEDIACYLINDERS=`echo $MEDIASIZEREQ/255/63/512 | bc`
  94. echo Media CYLINDERS - $MEDIACYLINDERS
  95.  
  96. }
  97.  
  98. function create_drives(){
  99. dd if=/dev/zero of=$DRIVE bs=1024 count=1024
  100.  
  101. SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`
  102.  
  103. echo DISK SIZE - $SIZE bytes
  104.  
  105. CYLINDERS=`echo $SIZE/255/63/512 | bc`
  106. echo CYLINDERS - $CYLINDERS
  107.  
  108. get_media_drive_size;
  109.  
  110. if [ $SKIPMEDIA == 1 ] ; then
  111. {
  112. echo ,9,0x0C,*
  113. echo ,,,-
  114. } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
  115. sleep 1
  116. return;
  117. fi
  118.  
  119. LASTCYLINDERLINUX=`echo $CYLINDERS - 9 - $MEDIACYLINDERS | bc`
  120.  
  121. {
  122. echo ,9,0x0C,*
  123. echo ,$LASTCYLINDERLINUX,,-
  124. echo ,,0x0C,-
  125. } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
  126.  
  127. sleep 1
  128. }
  129.  
  130. echo "To format the boot and rootfs only, enter 'f'."
  131. echo "To create the boot, media and rootfs and format them, enter 'c'."
  132. echo -n "Enter c or f:"
  133.  
  134. read answer
  135.  
  136. case "$answer" in
  137. f) format_boot_drive; format_rootfs_drive; exit ;;
  138. c) create_drives; format_boot_drive; format_rootfs_drive; format_media_drive; exit;;
  139. *) echo "Not a valid option. Exiting"; exit ;;
  140. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement