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

# 如果参数只有一个,这里就会使用默认文件夹下的程序,mkmmc-android.sh会重新调用,执行完再退出
EXPECTED_ARGS=1
if [ $# == $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
    exit
fi

# 六个参数,一个都不能少
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"
    exit
fi

# 判断文件是否存在
if ! [[ -e $2 ]]
then
    echo "Incorrect MLO location!"
    exit
fi

if ! [[ -e $3 ]]
then
    echo "Incorrect u-boot.img location!"
    exit
fi

if ! [[ -e $4 ]]
then
    echo "Incorrect zImage location!"
    exit
fi

if ! [[ -e $5 ]]
then
    echo "Incorrect uEnv.txt location!"
    exit
fi

if ! [[ -e $6 ]]
then
    echo "Incorrect am335x-boneblack.dtb!"
    exit
fi

if ! [[ -e $7 ]]
then
    echo "Incorrect rootfs location!"
    exit
fi

# 提示信息
echo "All data on "$1" 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 $1*

echo "[Partitioning $1...]"

# 擦除分区表
DRIVE=$1
dd 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 bytes

CYLINDERS=`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/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]"

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
README for preparing SD/MMC/Micro-SD CARD for booting Android Pre-Requesites -------------- 1) Need to have an SD/MMC/Micro-SD card with atleast 2GB of size. 2) The script needs to be invoked from ubuntu linux machine 8.04 or above. 3) User needs to have sudo privileges. What script will do ------------------- The mkmmc-android.sh partitions the MMC/SD card into three partiions namely boot, rootfs and data. The script will then put the boot images on boot partition and extracts the android rootfs-rootfs_*.tar.bz2 to rootfs partition. Finally the script will copy the Media clips to the data partition and START_HERE folder to boot partition. How to invoke the script ------------------------ There are three ways of invoking this script. 1) Command: sudo ./mkmmc-android <device> <MLO> <u-boot.bin> <uImage> <boot.scr> <rootfs tar.bz2 > <Media_Clips> <START_HERE Location> Example: sudo ./mkmmc-android /dev/sdc MLO u-boot.bin uImage boot.scr rootfs.tar.bz2 Media_Clips Details: In this case, the script will take Boot Images (MLO,u-boot.bin, uImage and boot.scr) Root Filesystem tarball, Media Clips and START_HERE folder as arguements. The script will then put the boot images on boot partition, extract the android rootfs-rootfs_*.tar.bz2 to rootfs partition. Finally the script will copy the Media clips to the data partition and START_HERE folder to boot partition. 2) Command: sudo ./mkmmc-android <device> <MLO> <u-boot.bin> <uImage> <boot.scr> <rootfs tar.bz2 > Example: sudo ./mkmmc-android /dev/sdc MLO u-boot.bin uImage boot.scr rootfs.tar.bz2 Details: In this case, the script will take Boot Images (MLO,u-boot.bin, uImage and boot.scr) and Root Filesystem tarball as arguements. The script will then put the boot images on boot partition, extract the android rootfs-rootfs_*.tar.bz2 to rootfs partition. The data partiton will be left empty in this case. 3) Command: sudo ./mkmmc-android.sh <device> Example: sudo ./mkmmc-android.sh /dev/sdc Details: In this case, the script will assume default locations for BootImages, Root Filesystem, Media_Clips and START_HERE. This command is equivalent to the following sudo ./mkmmc-android /dev/sdc Boot_Images/MLO Boot_Images/u-boot.bin Boot_Images/uImage Boot_Images/boot.scr Filesystem/rootfs.tar.bz2 Media_Clips START_HERE If you are in a particular Board Specific Directory, extracted from DevKit Release, then you can prepare the sd card by executing sudo ./mkmmc-android.sh <device>, to prepare sd card.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值