码迷,mamicode.com
首页 > 移动开发 > 详细

AM335x Android eMMC mkmmc-android.sh hacking

时间:2016-09-08 21:28:20      阅读:424      评论:0      收藏:0      [点我收藏+]

标签:

#                   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=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]"

 

AM335x Android eMMC mkmmc-android.sh hacking

标签:

原文地址:http://www.cnblogs.com/zengjfgit/p/5854431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!