Chinaunix首页 | 论坛 | 博客
  • 博客访问: 520638
  • 博文数量: 56
  • 博客积分: 1136
  • 博客等级: 少尉
  • 技术积分: 1378
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-28 14:02
文章存档

2014年(1)

2013年(7)

2012年(45)

2011年(3)

分类: 嵌入式

2012-04-04 16:34:17

前段时间,调试android的时候,老刷nandflash,出现了很多坏块,导致内核和android无法启动,无耐要调试从
SD启动android,此脚本分了三个区,一个用于持载android的sys目录,一个用于挂载android的data目录,这两个都是etx4格式,另一个是fat格式,用于挂载SD卡目录,android的cache目录可以挂到其它目录下,也可以修改此脚本中

点击(此处)折叠或打开

  1. {
  2. echo 212,,0x0C,-
  3. echo 9,68,0x83,-
  4. echo 77,135,0x83,-
  5. }
在其中加入一项,并修改相关的format_drive; format_vfat函数,脚本write_disk中的相关参数要根据U-boot中的定义来设置
 

点击(此处)折叠或打开

  1. #! /bin/bash
  2. export LC_ALL=C

  3. if [ $# -ne 1 ]; then
  4.         echo "Usage: $0 "
  5.         exit 1;
  6. fi

  7. DRIVE=$1

  8. SKIPMEDIA=0

  9. OUT_READY=0
  10. ROOT_DIR=$(pwd)
  11. PRODUCT='s5pc110'

  12. OFFSET_AUTHKEY=1
  13. OFFSET_BL1=9
  14. OFFSET_BL2=57
  15. OFFSET_KERNEL=1081
  16. OFFSET_ROOTFS=9273

  17. SIZE_AUTHKEY=8
  18. SIZE_UBOOT=1072
  19. SIZE_KERNEL=8192
  20. SIZE_ROOTFS=6142

  21. BACKUP_DIR="backup"
  22. if [ -e "$ROOT_DIR/out/target/product/$PRODUCT" ] ; then
  23. OUT_DIR="$ROOT_DIR/out/target/product/$PRODUCT"
  24. elif [ -e "$PRODUCT" ] ; then
  25. OUT_DIR="$PRODUCT"
  26. else
  27.     echo "At least one out dir needed."
  28.     OUT_DIR=""
  29.     exit 1
  30. fi

  31. function format_drive (){
  32. echo "Formatting boot drive"
  33. if [ -b ${DRIVE}2 ]; then
  34.     umount ${DRIVE}2
  35.     umount ${DRIVE}3
  36.         mkfs.ext4 -L "sys_uw" ${DRIVE}2
  37.         mkfs.ext4 -L "data_uw" ${DRIVE}3
  38. else
  39.         if [ -b ${DRIVE}p2 ]; then
  40.         umount ${DRIVE}p2
  41.         umount ${DRIVE}p3
  42.             mkfs.ext4 -L "sys_uw" ${DRIVE}p2
  43.             mkfs.ext4 -L "data_uw" ${DRIVE}p3
  44.         else
  45.                 echo "Can't find boot partition in /dev"
  46.         fi
  47. fi
  48. }

  49. function format_vfat () {
  50. echo "Formatting vfat data partition"

  51. if [ -b ${DRIVE}1 ]; then
  52.     umount ${DRIVE}1
  53.         mkfs.vfat -F 32 -n "fat_uw" ${DRIVE}1
  54. else
  55.         if [ -b ${DRIVE}p1 ]; then
  56.         umount ${DRIVE}p1
  57.             mkfs.vfat -F 32 -n "fat_uw" ${DRIVE}p1
  58.         else
  59.                 echo "Can't find boot partition in /dev"
  60.         fi
  61. fi

  62. }

  63. function check_files (){
  64. echo "Checking files in $OUT_DIR."

  65. if [ ! -e "$OUT_DIR"/u-boot.bin ] ; then
  66.     OUT_DIR=""
  67.     echo "No u-boot.bin, checking if file existed."
  68.     exit 1
  69. elif [ ! -e "$OUT_DIR"/zImage ] ; then
  70.     OUT_DIR=""
  71.     echo "No zImage, checking if file existed."
  72.     exit 1
  73. elif [ ! -e "$OUT_DIR"/ramdisk-uboot.img ]; then
  74.     OUT_DIR=""
  75.     echo "No ramdisk-uboot.img, check if file existed."
  76.     exit 1
  77. elif [ ! -e "$OUT_DIR"/system/build.prop ]; then
  78.     OUT_DIR=""
  79.     echo "No system files, check if file existed."
  80.     exit 1
  81. fi

  82. }

  83. function backup_disk (){
  84. echo "Backup disck"
  85. if [ -e ${BACKUP_DIR} ]; then
  86.     mv ${BACKUP_DIR} "${BACKUP_DIR}-`date`"
  87.     mkdir ${BACKUP_DIR}
  88. else
  89.     mkdir ${BACKUP_DIR}
  90. fi

  91. if [ -b ${DRIVE} ]; then
  92.     dd if=${DRIVE} of=${BACKUP_DIR}/secure.bin skip=$OFFSET_AUTHKEY count=$SIZE_AUTHKEY bs=512
  93.     dd if=${DRIVE} of=${BACKUP_DIR}/u-boot.bin skip=$OFFSET_BL1 count=$SIZE_UBOOT bs=512
  94.     dd if=${DRIVE} of=${BACKUP_DIR}/zImage skip=$OFFSET_KERNEL count=$SIZE_KERNEL bs=512
  95.     dd if=${DRIVE} of=${BACKUP_DIR}/ramdisk-uboot.img skip=$OFFSET_ROOTFS count=$SIZE_ROOTFS bs=512
  96. else
  97.     echo "Can't find boot partition in /dev"
  98. fi

  99. mkdir ${BACKUP_DIR}/tmp
  100. if [ -b ${DRIVE}2 ]; then
  101.     umount ${DRIVE}2
  102.     mount -t ext4 ${DRIVE}2 ${BACKUP_DIR}/tmp
  103. else
  104.         if [ -b ${DRIVE}p2 ]; then
  105.         umount ${DRIVE}p2
  106.             mount -t ext4 ${DRIVE}p2 ${BACKUP_DIR}/tmp
  107.         else
  108.                 echo "Can't find system partition in /dev"
  109.         fi
  110. fi

  111. if [ "$?" != 0 ] ; then
  112.     echo "Warning, no system partition found."
  113. fi

  114.     cp -rp ${BACKUP_DIR}/tmp ${BACKUP_DIR}/system
  115.     umount ${BACKUP_DIR}/tmp
  116.     rmdir ${BACKUP_DIR}/tmp
  117.     echo "Backup finished."
  118.     return 0
  119. }

  120. function write_disk (){
  121. echo "Writing android images into disck"

  122. check_files

  123. if [ -b ${DRIVE} ]; then
  124.     dd of=${DRIVE} if=${OUT_DIR}/secure.bin seek=$OFFSET_AUTHKEY count=$SIZE_AUTHKEY bs=512
  125.     dd of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$OFFSET_BL1 count=$SIZE_UBOOT bs=512
  126. #    dd of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$OFFSET_BL2 bs=512
  127.     dd of=${DRIVE} if=${OUT_DIR}/zImage seek=$OFFSET_KERNEL count=$SIZE_KERNEL bs=512
  128.     dd of=${DRIVE} if=${OUT_DIR}/ramdisk-uboot.img seek=$OFFSET_ROOTFS count=$SIZE_ROOTFS bs=512
  129. else
  130.     echo "Can't write boot sectors into ${DRIVE}"
  131. fi

  132. mkdir ${OUT_DIR}/tmp
  133. if [ -b ${DRIVE}2 ]; then
  134.     umount ${DRIVE}2
  135.     mount -t ext4 ${DRIVE}2 ${OUT_DIR}/tmp
  136. else
  137.         if [ -b ${DRIVE}p2 ]; then
  138.         umount ${DRIVE}p2
  139.             mount -t ext4 ${DRIVE}p2 ${OUT_DIR}/tmp
  140.         else
  141.                 echo "Can't find system partition in ${DRIVE}"
  142.         fi
  143. fi

  144. if [ "$?" -eq 0 ] ; then
  145.     echo "No system partition found, quit."
  146. fi
  147.     cp -rp ${OUT_DIR}/system/* ${OUT_DIR}/tmp
  148.     umount ${OUT_DIR}/tmp
  149.     rmdir ${OUT_DIR}/tmp
  150.     echo "Writing system files finished."
  151.     return $?

  152. }

  153. function create_drives(){
  154. if [ -b ${DRIVE}1 ]; then
  155.         umount ${DRIVE}1
  156.     umount ${DRIVE}2
  157.     umount ${DRIVE}3
  158. else
  159.         if [ -b ${DRIVE}p1 ]; then
  160.             umount ${DRIVE}p1
  161.         umount ${DRIVE}p2
  162.         umount ${DRIVE}p3
  163.         else
  164.                 echo "Can't find boot partition in /dev"
  165.         fi
  166. fi

  167. dd if=/dev/zero of=$DRIVE bs=1024 count=1024

  168. SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`

  169. echo DISK SIZE - $SIZE bytes

  170. CYLINDERS=`echo $SIZE/255/63/512 | bc`
  171. echo CYLINDERS - $CYLINDERS

  172. {
  173. echo 212,,0x0C,-
  174. echo 9,68,0x83,-
  175. echo 77,135,0x83,-
  176. } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE

  177. sleep 1
  178. }


  179. #MAIN fucntion
  180. echo "To backup a functional disk, enter 'b'."
  181. echo "To create a new drive, and fill it with android image enter 'c'."
  182. echo "To write boot android image only, enter 'w'."
  183. echo -n "Enter b , c or w:"

  184. read answer

  185. case "$answer" in
  186. b) backup_disk; exit;;
  187. c) check_files; create_drives; format_drive; format_vfat; write_disk; exit ;;
  188. w) check_files; format_drive; backup_disk; write_disk; exit;;
  189. *) echo "Not a valid option. Exiting"; exit ;;
  190. esac

  191. eject ${DRIVE}

阅读(6361) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~