前段时间,调试android的时候,老刷nandflash,出现了很多坏块,导致内核和android无法启动,无耐要调试从
SD启动android,此脚本分了三个区,一个用于持载android的sys目录,一个用于挂载android的data目录,这两个都是etx4格式,另一个是fat格式,用于挂载SD卡目录,android的cache目录可以挂到其它目录下,也可以修改此脚本中
- {
- echo 212,,0x0C,-
- echo 9,68,0x83,-
- echo 77,135,0x83,-
- }
在其中加入一项,并修改相关的format_drive; format_vfat函数,脚本write_disk中的相关参数要根据U-boot中的定义来设置
- #! /bin/bash
- export LC_ALL=C
- if [ $# -ne 1 ]; then
- echo "Usage: $0 "
- exit 1;
- fi
- DRIVE=$1
- SKIPMEDIA=0
- OUT_READY=0
- ROOT_DIR=$(pwd)
- PRODUCT='s5pc110'
- OFFSET_AUTHKEY=1
- OFFSET_BL1=9
- OFFSET_BL2=57
- OFFSET_KERNEL=1081
- OFFSET_ROOTFS=9273
- SIZE_AUTHKEY=8
- SIZE_UBOOT=1072
- SIZE_KERNEL=8192
- SIZE_ROOTFS=6142
- BACKUP_DIR="backup"
- if [ -e "$ROOT_DIR/out/target/product/$PRODUCT" ] ; then
- OUT_DIR="$ROOT_DIR/out/target/product/$PRODUCT"
- elif [ -e "$PRODUCT" ] ; then
- OUT_DIR="$PRODUCT"
- else
- echo "At least one out dir needed."
- OUT_DIR=""
- exit 1
- fi
- function format_drive (){
- echo "Formatting boot drive"
- if [ -b ${DRIVE}2 ]; then
- umount ${DRIVE}2
- umount ${DRIVE}3
- mkfs.ext4 -L "sys_uw" ${DRIVE}2
- mkfs.ext4 -L "data_uw" ${DRIVE}3
- else
- if [ -b ${DRIVE}p2 ]; then
- umount ${DRIVE}p2
- umount ${DRIVE}p3
- mkfs.ext4 -L "sys_uw" ${DRIVE}p2
- mkfs.ext4 -L "data_uw" ${DRIVE}p3
- else
- echo "Can't find boot partition in /dev"
- fi
- fi
- }
- function format_vfat () {
- echo "Formatting vfat data partition"
- if [ -b ${DRIVE}1 ]; then
- umount ${DRIVE}1
- mkfs.vfat -F 32 -n "fat_uw" ${DRIVE}1
- else
- if [ -b ${DRIVE}p1 ]; then
- umount ${DRIVE}p1
- mkfs.vfat -F 32 -n "fat_uw" ${DRIVE}p1
- else
- echo "Can't find boot partition in /dev"
- fi
- fi
- }
- function check_files (){
- echo "Checking files in $OUT_DIR."
- if [ ! -e "$OUT_DIR"/u-boot.bin ] ; then
- OUT_DIR=""
- echo "No u-boot.bin, checking if file existed."
- exit 1
- elif [ ! -e "$OUT_DIR"/zImage ] ; then
- OUT_DIR=""
- echo "No zImage, checking if file existed."
- exit 1
- elif [ ! -e "$OUT_DIR"/ramdisk-uboot.img ]; then
- OUT_DIR=""
- echo "No ramdisk-uboot.img, check if file existed."
- exit 1
- elif [ ! -e "$OUT_DIR"/system/build.prop ]; then
- OUT_DIR=""
- echo "No system files, check if file existed."
- exit 1
- fi
- }
- function backup_disk (){
- echo "Backup disck"
- if [ -e ${BACKUP_DIR} ]; then
- mv ${BACKUP_DIR} "${BACKUP_DIR}-`date`"
- mkdir ${BACKUP_DIR}
- else
- mkdir ${BACKUP_DIR}
- fi
- if [ -b ${DRIVE} ]; then
- dd if=${DRIVE} of=${BACKUP_DIR}/secure.bin skip=$OFFSET_AUTHKEY count=$SIZE_AUTHKEY bs=512
- dd if=${DRIVE} of=${BACKUP_DIR}/u-boot.bin skip=$OFFSET_BL1 count=$SIZE_UBOOT bs=512
- dd if=${DRIVE} of=${BACKUP_DIR}/zImage skip=$OFFSET_KERNEL count=$SIZE_KERNEL bs=512
- dd if=${DRIVE} of=${BACKUP_DIR}/ramdisk-uboot.img skip=$OFFSET_ROOTFS count=$SIZE_ROOTFS bs=512
- else
- echo "Can't find boot partition in /dev"
- fi
- mkdir ${BACKUP_DIR}/tmp
- if [ -b ${DRIVE}2 ]; then
- umount ${DRIVE}2
- mount -t ext4 ${DRIVE}2 ${BACKUP_DIR}/tmp
- else
- if [ -b ${DRIVE}p2 ]; then
- umount ${DRIVE}p2
- mount -t ext4 ${DRIVE}p2 ${BACKUP_DIR}/tmp
- else
- echo "Can't find system partition in /dev"
- fi
- fi
- if [ "$?" != 0 ] ; then
- echo "Warning, no system partition found."
- fi
- cp -rp ${BACKUP_DIR}/tmp ${BACKUP_DIR}/system
- umount ${BACKUP_DIR}/tmp
- rmdir ${BACKUP_DIR}/tmp
- echo "Backup finished."
- return 0
- }
- function write_disk (){
- echo "Writing android images into disck"
- check_files
- if [ -b ${DRIVE} ]; then
- dd of=${DRIVE} if=${OUT_DIR}/secure.bin seek=$OFFSET_AUTHKEY count=$SIZE_AUTHKEY bs=512
- dd of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$OFFSET_BL1 count=$SIZE_UBOOT bs=512
- # dd of=${DRIVE} if=${OUT_DIR}/u-boot.bin seek=$OFFSET_BL2 bs=512
- dd of=${DRIVE} if=${OUT_DIR}/zImage seek=$OFFSET_KERNEL count=$SIZE_KERNEL bs=512
- dd of=${DRIVE} if=${OUT_DIR}/ramdisk-uboot.img seek=$OFFSET_ROOTFS count=$SIZE_ROOTFS bs=512
- else
- echo "Can't write boot sectors into ${DRIVE}"
- fi
- mkdir ${OUT_DIR}/tmp
- if [ -b ${DRIVE}2 ]; then
- umount ${DRIVE}2
- mount -t ext4 ${DRIVE}2 ${OUT_DIR}/tmp
- else
- if [ -b ${DRIVE}p2 ]; then
- umount ${DRIVE}p2
- mount -t ext4 ${DRIVE}p2 ${OUT_DIR}/tmp
- else
- echo "Can't find system partition in ${DRIVE}"
- fi
- fi
- if [ "$?" -eq 0 ] ; then
- echo "No system partition found, quit."
- fi
- cp -rp ${OUT_DIR}/system/* ${OUT_DIR}/tmp
- umount ${OUT_DIR}/tmp
- rmdir ${OUT_DIR}/tmp
- echo "Writing system files finished."
- return $?
- }
- function create_drives(){
- if [ -b ${DRIVE}1 ]; then
- umount ${DRIVE}1
- umount ${DRIVE}2
- umount ${DRIVE}3
- else
- if [ -b ${DRIVE}p1 ]; then
- umount ${DRIVE}p1
- umount ${DRIVE}p2
- umount ${DRIVE}p3
- else
- echo "Can't find boot partition in /dev"
- fi
- fi
- dd if=/dev/zero of=$DRIVE bs=1024 count=1024
- SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`
- echo DISK SIZE - $SIZE bytes
- CYLINDERS=`echo $SIZE/255/63/512 | bc`
- echo CYLINDERS - $CYLINDERS
- {
- echo 212,,0x0C,-
- echo 9,68,0x83,-
- echo 77,135,0x83,-
- } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
- sleep 1
- }
- #MAIN fucntion
- echo "To backup a functional disk, enter 'b'."
- echo "To create a new drive, and fill it with android image enter 'c'."
- echo "To write boot android image only, enter 'w'."
- echo -n "Enter b , c or w:"
- read answer
- case "$answer" in
- b) backup_disk; exit;;
- c) check_files; create_drives; format_drive; format_vfat; write_disk; exit ;;
- w) check_files; format_drive; backup_disk; write_disk; exit;;
- *) echo "Not a valid option. Exiting"; exit ;;
- esac
- eject ${DRIVE}
阅读(6356) | 评论(0) | 转发(1) |