Chinaunix首页 | 论坛 | 博客
  • 博客访问: 883345
  • 博文数量: 376
  • 博客积分: 154
  • 博客等级: 入伍新兵
  • 技术积分: 1558
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-13 08:42
文章分类

全部博文(376)

文章存档

2014年(11)

2013年(88)

2012年(260)

2011年(17)

分类:

2013-01-03 17:07:50

上篇博客介绍过SD卡启动android的脚本的大致情况,此脚本是在上一篇的基础上有所改过,它是支持s5pv210的,相关烧写参数发生了改变,这个脚本要把android的system目录data目录和cache目录都挂到root根目录下,与上一篇有点差别。

点击(此处)折叠或打开

  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='s5pv210'

  12. #OFFSET_AUTHKEY=1
  13. #OFFSET_BL1=9
  14. #OFFSET_BL2=57
  15. bl1_position=1
  16. uboot_position=49
  17. OFFSET_KERNEL=1073
  18. OFFSET_ROOTFS=9265

  19. SIZE_AUTHKEY=8
  20. SIZE_UBOOT=1072
  21. SIZE_KERNEL=8192
  22. SIZE_ROOTFS=6142

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

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

  46. function format_vfat () {
  47. echo "Formatting vfat data partition"

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

  59. }


  60. function write_disk (){
  61. echo "Writing android images into disck"

  62. if [ -b ${DRIVE} ]; then
  63.     ./${OUT_DIR}/mkbl1 ${OUT_DIR}/u-boot.bin SD-bl1-8k.bin 8192
  64.     dd iflag=dsync oflag=dsync if=SD-bl1-8k.bin of=${DRIVE} seek=$bl1_position
  65.     rm SD-bl1-8k.bin
  66. #    dd of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$OFFSET_AUTHKEY count=$SIZE_AUTHKEY bs=512
  67. #    dd of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$OFFSET_BL1 count=$SIZE_UBOOT bs=512
  68.     dd iflag=dsync oflag=dsync of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$uboot_position bs=512
  69.     dd iflag=dsync oflag=dsync of=${DRIVE} if=${OUT_DIR}/zImage seek=$OFFSET_KERNEL count=$SIZE_KERNEL bs=512
  70. #    dd iflag=dsync oflag=dsync of=${DRIVE} if=${OUT_DIR}/ramdisk-uboot.img skip=$OFFSET_ROOTFS count=$SIZE_ROOTFS bs=512
  71. else
  72.     echo "Can't write boot sectors into ${DRIVE}"
  73. fi

  74. }


  75. function cp_root (){
  76. mkdir ${OUT_DIR}/tmp
  77. if [ -b ${DRIVE}2 ]; then
  78.     umount ${DRIVE}2
  79.     mount -t ext4 ${DRIVE}2 ${OUT_DIR}/tmp
  80. else
  81.         if [ -b ${DRIVE}p2 ]; then
  82.         umount ${DRIVE}p2
  83.             mount -t ext4 ${DRIVE}p2 ${OUT_DIR}/tmp
  84.         else
  85.                 echo "Can't find root partition in ${DRIVE}"
  86.         fi
  87. fi

  88. if [ "$?" -eq 0 ] ; then
  89.     echo "No root partition found, quit."
  90. fi
  91.     cp -rp ${OUT_DIR}/root/* ${OUT_DIR}/tmp
  92.     umount ${OUT_DIR}/tmp
  93.     rm -rf ${OUT_DIR}/tmp
  94.     echo "Writing root files finished."
  95.     return $?

  96. }

  97. function wite_image (){
  98.     echo "Writing kernrl images into disck"
  99.     ./${OUT_DIR}/mkbl1 ${OUT_DIR}/u-boot.bin SD-bl1-8k.bin 8192
  100.     dd iflag=dsync oflag=dsync if=SD-bl1-8k.bin of=${DRIVE} seek=$bl1_position
  101.     rm SD-bl1-8k.bin
  102. #    dd of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$OFFSET_AUTHKEY count=$SIZE_AUTHKEY bs=512
  103. #    dd of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$OFFSET_BL1 count=$SIZE_UBOOT bs=512
  104.     dd iflag=dsync oflag=dsync of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$uboot_position bs=512
  105.     dd iflag=dsync oflag=dsync of=${DRIVE} if=${OUT_DIR}/zImage seek=$OFFSET_KERNEL count=$SIZE_KERNEL bs=512
  106. }

  107. function create_drives(){
  108. if [ -b ${DRIVE}1 ]; then
  109.         umount ${DRIVE}1
  110.     umount ${DRIVE}2
  111. else
  112.         if [ -b ${DRIVE}p1 ]; then
  113.             umount ${DRIVE}p1
  114.         umount ${DRIVE}p2
  115.         else
  116.                 echo "Can't find boot partition in /dev"
  117.         fi
  118. fi

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

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

  121. echo DISK SIZE - $SIZE bytes

  122. CYLINDERS=`echo $SIZE/255/63/512 | bc`
  123. echo CYLINDERS - $CYLINDERS

  124. {
  125. echo 203,,0x0C,-
  126. echo 9,191,0x83,-
  127. } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE

  128. sleep 1
  129. }


  130. #MAIN fucntion
  131. echo "To Writing uboot kernrl images into disck, enter 'k'."
  132. echo "To create a new drive, and fill it with android image enter 'c'."
  133. echo "To Exit, enter 'r'."
  134. echo -n "Enter k , c or r:"

  135. read answer

  136. case "$answer" in
  137. k) format_drive; wite_image; exit;;
  138. c) create_drives; format_drive; format_vfat; write_disk; cp_root; exit ;;
  139. r) exit;;
  140. *) echo "Not a valid option. Exiting"; exit ;;
  141. esac

  142. eject ${DRIVE}

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