首页 > 代码库 > AM335x Android eMMC mkmmc-android.sh hacking

AM335x Android eMMC mkmmc-android.sh hacking

#                   AM335x Android eMMC mkmmc-android.sh hacking## 1. 有空解读一下android的分区文件。# 2. 代码来源:https://github.com/hendersa/bbbandroid-external-ti_android_utilities/blob/master/am335x/mk-mmc/mkmmc-android.sh##                                          2016-9-8 深圳 南山平山村 曾剑锋#!/bin/bash# 如果参数只有一个,这里就会直接退出EXPECTED_ARGS=1if [ $# == $EXPECTED_ARGS ]then    echo "Assuming Default Locations for Prebuilt Images"    $0 $1 Boot_Images/MLO Boot_Images/u-boot.img Boot_Images/zImage Boot_Images/uEnv.txt Boot_Images/dtbs/am335x-boneblack.dtb Filesystem/rootfs* Media_Clips START_HERE    exitfi# 六个参数,一个都不能少if [[ -z $1 || -z $2 || -z $3 || -z $4 || -z $5 || -z $6 ]]then    echo "mkmmc-android Usage:"    echo "  mkmmc-android <device> <MLO> <u-boot.img> <zImage> <uEnv.txt> <am335x-boneblack.dtb> <rootfs tar.bz2> <Optional Media_Clips> <Optional START_HERE folder>"    echo "  Example: mkmmc-android /dev/sdc MLO u-boot.img zImage uEnv.txt am335x-boneblack.dtb rootfs.tar.bz2 Media_Clips START_HERE"    exitfi# 判断文件是否存在if ! [[ -e $2 ]]then    echo "Incorrect MLO location!"    exitfiif ! [[ -e $3 ]]then    echo "Incorrect u-boot.img location!"    exitfiif ! [[ -e $4 ]]then    echo "Incorrect zImage location!"    exitfiif ! [[ -e $5 ]]then    echo "Incorrect uEnv.txt location!"    exitfiif ! [[ -e $6 ]]then    echo "Incorrect am335x-boneblack.dtb!"    exitfiif ! [[ -e $7 ]]then    echo "Incorrect rootfs location!"    exitfi# 提示信息echo "All data on "$1" now will be destroyed! Continue? [y/n]"read ansif ! [ $ans == y ]then    exitfi# 卸载所有$1分区挂载echo "[Unmounting all existing partitions on the device ]"umount $1*echo "[Partitioning $1...]"# 擦除分区表DRIVE=$1dd if=/dev/zero of=$DRIVE bs=1024 count=1024 &>/dev/null# 获取eMMC相关信息SIZE=`fdisk -l $DRIVE | grep Disk | awk {print $5}`echo DISK SIZE - $SIZE bytesCYLINDERS=`echo $SIZE/255/63/512 | bc`# 分区,并设置boot分区echo CYLINDERS - $CYLINDERS{echo ,9,0x0C,*echo ,$(expr $CYLINDERS / 4),,-echo ,$(expr $CYLINDERS / 4),,-echo ,,0x0C,-} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE &> /dev/nullecho "[Making filesystems...]"if [[ ${DRIVE} == /dev/*mmcblk* ]]then    DRIVE=${DRIVE}pfi# 格式化分区mkfs.vfat -F 32 -n boot ${DRIVE}1 &> /dev/nullmkfs.ext4 -L rootfs ${DRIVE}2 &> /dev/nullmkfs.ext4 -L usrdata ${DRIVE}3 &> /dev/nullmkfs.vfat -F 32 -n data ${DRIVE}4 &> /dev/nullecho "[Copying files...]"# 挂载并拷贝文件到分区1mount ${DRIVE}1 /mntcp $2 /mnt/MLOcp $3 /mnt/u-boot.imgcp $4 /mnt/zImagecp $5 /mnt/uEnv.txtmkdir /mnt/dtbscp $6 /mnt/dtbs/am335x-boneblack.dtbif [ "$9" ]then        echo "[Copying START_HERE folder to boot partition]"        cp -r $9 /mnt/START_HEREfi# 卸载分区umount ${DRIVE}1# 拷贝文件系统内容到分区2mount ${DRIVE}2 /mnttar jxvf $7 -C /mnt &> /dev/nullchmod 755 /mntumount ${DRIVE}2# 拷贝data到数据分区if [ "$8" ]then    echo "[Copying all clips to data partition]"    mount ${DRIVE}4 /mnt    cp -r $8/* /mnt/    umount ${DRIVE}4fiecho "[Done]"

 

AM335x Android eMMC mkmmc-android.sh hacking