# AM335x Android eMMC mkmmc-android.sh hacking
#
# . 有空解读一下android的分区文件。
# . 代码来源:https://github.com/hendersa/bbbandroid-external-ti_android_utilities/blob/master/am335x/mk-mmc/mkmmc-android.sh
#
# -- 深圳 南山平山村 曾剑锋 #!/bin/bash # 如果参数只有一个,这里就会使用默认文件夹下的程序,mkmmc-android.sh会重新调用,执行完再退出
EXPECTED_ARGS=
if [ $# == $EXPECTED_ARGS ]
then
echo "Assuming Default Locations for Prebuilt Images"
$ $ 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
exit
fi # 六个参数,一个都不能少
if [[ -z $ || -z $ || -z $ || -z $ || -z $ || -z $ ]]
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"
exit
fi # 判断文件是否存在
if ! [[ -e $ ]]
then
echo "Incorrect MLO location!"
exit
fi if ! [[ -e $ ]]
then
echo "Incorrect u-boot.img location!"
exit
fi if ! [[ -e $ ]]
then
echo "Incorrect zImage location!"
exit
fi if ! [[ -e $ ]]
then
echo "Incorrect uEnv.txt location!"
exit
fi if ! [[ -e $ ]]
then
echo "Incorrect am335x-boneblack.dtb!"
exit
fi if ! [[ -e $ ]]
then
echo "Incorrect rootfs location!"
exit
fi # 提示信息
echo "All data on "$" now will be destroyed! Continue? [y/n]"
read ans
if ! [ $ans == 'y' ]
then
exit
fi # 卸载所有$1分区挂载
echo "[Unmounting all existing partitions on the device ]" umount $* echo "[Partitioning $1...]" # 擦除分区表
DRIVE=$
dd if=/dev/zero of=$DRIVE bs= count= &>/dev/null # 获取eMMC相关信息
SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'` echo DISK SIZE - $SIZE bytes CYLINDERS=`echo $SIZE/// | bc` # 分区,并设置boot分区
echo CYLINDERS - $CYLINDERS
{
echo ,,0x0C,*
echo ,$(expr $CYLINDERS / ),,-
echo ,$(expr $CYLINDERS / ),,-
echo ,,0x0C,-
} | sfdisk -D -H -S -C $CYLINDERS $DRIVE &> /dev/null echo "[Making filesystems...]" if [[ ${DRIVE} == /dev/*mmcblk* ]]
then
DRIVE=${DRIVE}p
fi # 格式化分区
mkfs.vfat -F 32 -n boot ${DRIVE}1 &> /dev/null
mkfs.ext4 -L rootfs ${DRIVE}2 &> /dev/null
mkfs.ext4 -L usrdata ${DRIVE}3 &> /dev/null
mkfs.vfat -F 32 -n data ${DRIVE}4 &> /dev/null echo "[Copying files...]" # 挂载并拷贝文件到分区1
mount ${DRIVE}1 /mnt
cp $2 /mnt/MLO
cp $3 /mnt/u-boot.img
cp $4 /mnt/zImage
cp $5 /mnt/uEnv.txt
mkdir /mnt/dtbs
cp $6 /mnt/dtbs/am335x-boneblack.dtb if [ "$9" ]
then
echo "[Copying START_HERE folder to boot partition]"
cp -r $9 /mnt/START_HERE
fi # 卸载分区
umount ${DRIVE}1 # 拷贝文件系统内容到分区2
mount ${DRIVE}2 /mnt
tar jxvf $7 -C /mnt &> /dev/null
chmod 755 /mnt
umount ${DRIVE}2 # 拷贝data到数据分区
if [ "$8" ]
then
echo "[Copying all clips to data partition]"
mount ${DRIVE}4 /mnt
cp -r $8/* /mnt/
umount ${DRIVE}4
fi echo "[Done]"