制作android SD启动卡shell脚本
2012-03-01 13:03
302 查看
制作android SD启动卡shell脚本
#! /bin/bash export LC_ALL=C if [ $# -ne 1 ]; then echo "Usage: $0 <drive>" 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 #格式化SD卡,格式化为了三个分区 #第一个分区为VFAT格式 #第二个分区和第三个分区为EXT4格式 function format_drive (){ echo "Formatting boot drive" if [ -b ${DRIVE}2 ]; then umount ${DRIVE}2 umount ${DRIVE}3 mkfs.ext4 -L "sys" ${DRIVE}2 mkfs.ext4 -L "data" ${DRIVE}3 else if [ -b ${DRIVE}p2 ]; then umount ${DRIVE}p2 umount ${DRIVE}p3 mkfs.ext4 -L "sys" ${DRIVE}p2 mkfs.ext4 -L "data" ${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" ${DRIVE}1 else if [ -b ${DRIVE}p1 ]; then umount ${DRIVE}p1 mkfs.vfat -F 32 -n "fat" ${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 } #备份SD中的数据 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 } #烧写SD 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}
相关文章推荐
- 在android init.xxx.rc中启动shell脚本
- 制作 shell 脚本压缩 Android 8.0代码
- Linux下为可执行shell脚本文件(.sh),制作桌面启动快捷方式
- 修改am335x 制作android sd启动卡的bug
- android 在手机sd 卡中执行linux 命令 和shell 脚本
- android启动时,如何执行shell脚本
- Android 7.0 init.rc 执行shell脚本 ---- 制作一初始化配置文件
- Android自动化技术之自动monkey:shell脚本实现自动创建模拟器、启动模拟器、自动安装apk并进行monkey测试
- Shell脚本安装成服务加入系统启动-service XX does not support chkconfig
- 使用交互式shell脚本启动DHCP服务器以及对其进行设置
- linux设置shell脚本开机启动
- 启动Java应用的Shell脚本
- mysql5.6.7多实例安装、配置的详细讲解分析及shell启动脚本的编写
- Android在init.rc中加入脚本开机安装APK并启动APK的服务
- Freescale IMX6 Android (3): 手动制作Android启动用SD卡 省去MFGTOOLS烧写
- shell脚本控制jar的启动和停止
- crontab启动shell脚本的环境变量问题
- 编写可以监控oracle监听器是否启动的shell脚本
- linux中各个shell配置脚本文件的作用域和启动时间
- [shell] tomcat启动脚本评析 - 1. startup.sh