製作android SD啟動卡shell指令碼

來源:互聯網
上載者:User

製作android SD啟動卡shell指令碼

#! /bin/bashexport LC_ALL=Cif [ $# -ne 1 ]; then        echo "Usage: $0 <drive>"        exit 1;fiDRIVE=$1SKIPMEDIA=0OUT_READY=0 ROOT_DIR=$(pwd)PRODUCT='s5pc110'#位移OFFSET_AUTHKEY=1OFFSET_BL1=9OFFSET_BL2=57OFFSET_KERNEL=1081OFFSET_ROOTFS=9273#大小SIZE_AUTHKEY=8SIZE_UBOOT=1072SIZE_KERNEL=8192SIZE_ROOTFS=6142 BACKUP_DIR="backup"if [ -e "$ROOT_DIR/out/target/product/$PRODUCT" ] ; thenOUT_DIR="$ROOT_DIR/out/target/product/$PRODUCT"elif [ -e "$PRODUCT" ] ; thenOUT_DIR="$PRODUCT"elseecho "At least one out dir needed."OUT_DIR=""exit 1fi#格式化SD卡,格式化為了三個分區#第一個分區為VFAT格式#第二個分區和第三個分區為EXT4格式function format_drive (){echo "Formatting boot drive"if [ -b ${DRIVE}2 ]; thenumount ${DRIVE}2umount ${DRIVE}3        mkfs.ext4 -L "sys" ${DRIVE}2        mkfs.ext4 -L "data" ${DRIVE}3else        if [ -b ${DRIVE}p2 ]; thenumount ${DRIVE}p2umount ${DRIVE}p3        mkfs.ext4 -L "sys" ${DRIVE}p2        mkfs.ext4 -L "data" ${DRIVE}p3        else                echo "Can't find boot partition in /dev"        fifi}function format_vfat () {echo "Formatting vfat data partition"if [ -b ${DRIVE}1 ]; thenumount ${DRIVE}1        mkfs.vfat -F 32 -n "fat" ${DRIVE}1else        if [ -b ${DRIVE}p1 ]; thenumount ${DRIVE}p1        mkfs.vfat -F 32 -n "fat" ${DRIVE}p1        else                echo "Can't find boot partition in /dev"        fifi}#檢查是否預備了相應的鏡像檔案function check_files (){echo "Checking files in $OUT_DIR."if [ ! -e "$OUT_DIR"/u-boot.bin ] ; thenOUT_DIR=""echo "No u-boot.bin, checking if file existed."exit 1elif [ ! -e "$OUT_DIR"/zImage ] ; thenOUT_DIR=""echo "No zImage, checking if file existed."exit 1elif [ ! -e "$OUT_DIR"/ramdisk-uboot.img ]; thenOUT_DIR=""echo "No ramdisk-uboot.img, check if file existed."exit 1elif [ ! -e "$OUT_DIR"/system/build.prop ]; thenOUT_DIR=""echo "No system files, check if file existed."exit 1fi}#備份SD中的資料function backup_disk (){echo "Backup disck"if [ -e ${BACKUP_DIR} ]; thenmv ${BACKUP_DIR} "${BACKUP_DIR}-`date`"mkdir ${BACKUP_DIR}elsemkdir ${BACKUP_DIR}fiif [ -b ${DRIVE} ]; thendd if=${DRIVE} of=${BACKUP_DIR}/secure.bin skip=$OFFSET_AUTHKEY count=$SIZE_AUTHKEY bs=512dd if=${DRIVE} of=${BACKUP_DIR}/u-boot.bin skip=$OFFSET_BL1 count=$SIZE_UBOOT bs=512dd if=${DRIVE} of=${BACKUP_DIR}/zImage skip=$OFFSET_KERNEL count=$SIZE_KERNEL bs=512dd if=${DRIVE} of=${BACKUP_DIR}/ramdisk-uboot.img skip=$OFFSET_ROOTFS count=$SIZE_ROOTFS bs=512elseecho "Can't find boot partition in /dev"fimkdir ${BACKUP_DIR}/tmpif [ -b ${DRIVE}2 ]; thenumount ${DRIVE}2mount -t ext4 ${DRIVE}2 ${BACKUP_DIR}/tmpelse        if [ -b ${DRIVE}p2 ]; thenumount ${DRIVE}p2        mount -t ext4 ${DRIVE}p2 ${BACKUP_DIR}/tmp        else                echo "Can't find system partition in /dev"        fifiif [ "$?" != 0 ] ; thenecho "Warning, no system partition found."ficp -rp ${BACKUP_DIR}/tmp ${BACKUP_DIR}/systemumount ${BACKUP_DIR}/tmprmdir ${BACKUP_DIR}/tmpecho "Backup finished."return 0}#燒寫SDfunction write_disk (){echo "Writing android images into disck"check_filesif [ -b ${DRIVE} ]; thendd of=${DRIVE} if=${OUT_DIR}/secure.bin seek=$OFFSET_AUTHKEY count=$SIZE_AUTHKEY bs=512dd 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=512dd of=${DRIVE} if=${OUT_DIR}/zImage seek=$OFFSET_KERNEL count=$SIZE_KERNEL bs=512dd of=${DRIVE} if=${OUT_DIR}/ramdisk-uboot.img seek=$OFFSET_ROOTFS count=$SIZE_ROOTFS bs=512elseecho "Can't write boot sectors into ${DRIVE}"fimkdir ${OUT_DIR}/tmpif [ -b ${DRIVE}2 ]; thenumount ${DRIVE}2mount -t ext4 ${DRIVE}2 ${OUT_DIR}/tmpelse        if [ -b ${DRIVE}p2 ]; thenumount ${DRIVE}p2        mount -t ext4 ${DRIVE}p2 ${OUT_DIR}/tmp        else                echo "Can't find system partition in ${DRIVE}"        fifiif [ "$?" -eq 0 ] ; thenecho "No system partition found, quit."ficp -rp ${OUT_DIR}/system/* ${OUT_DIR}/tmpumount ${OUT_DIR}/tmprmdir ${OUT_DIR}/tmpecho "Writing system files finished."return $?}#建立分區function create_drives(){if [ -b ${DRIVE}1 ]; then    umount ${DRIVE}1umount ${DRIVE}2umount ${DRIVE}3else        if [ -b ${DRIVE}p1 ]; then        umount ${DRIVE}p1umount ${DRIVE}p2umount ${DRIVE}p3        else                echo "Can't find boot partition in /dev"        fifidd if=/dev/zero of=$DRIVE bs=1024 count=1024SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`echo DISK SIZE - $SIZE bytesCYLINDERS=`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 $DRIVEsleep 1}#MAIN fucntionecho "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 answercase "$answer" inb) 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 ;;esaceject ${DRIVE}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.