在《Lichee(三) Android4.0的目标产品文件夹与Lichee的纽带---extract-bsp》中我们分析了extract-bsp的作用和意义。到这里,我们能够開始编译Android了
运行 make -j8
………………
漫长的等待之后。Android的目标文件都到了out文件夹,假设我们的目标产品名叫crane-mt7332
out/target/product/crane-mt7332/
├── android-info.txt
├── boot.img
├── clean_steps.mk
├── data
├── installed-files.txt
├── kernel
├── obj
├── previous_build_config.mk
├── ramdisk.img
├── ramdisk-recovery.img
├── recovery
├── recovery.fstab
├── recovery.img
├── root
├── symbols
├── system
├── system.img
└── userdata.img
非常高兴,我们看到了非常多的.img文件。这些文件就是为了给我们打包做准备
接下来,我们開始具体地分析Lichee的打包过程
打包有2种方式。在lichee。Android中都能够完毕pack
在lichee中运行
$ ./build.sh pack就能够实现打包
在 buildroot/scripts/common.sh中有:
if [ "$1" = "pack" ]; then
${BR_DIR}/scripts/build_pack.sh
exit 0
fi
这里环境变量BR_DIR=buildroot,事实上去运行buildroot/script/build_pack.sh
变量赋值部分:
LICHEE_ROOT=$PWD
PACK_ROOT=tools/pack
TARGET_CHIP="sun4i"
TARGET_PLATFORM="linux"
TARGET_BOARD="evb"
count=0
选择chip
文件夹结构
#tree -L 1 tools/pack/chips/
#tools/pack/chips/
#└── sun4i
printf "Start packing for Lichee system\n\n"
select_chips
我们分析这个函数
select_chips()
{
count=0
printf "All valid chips:\n"
# $PACK_ROOT/chips/ 就是 lichee/tools/pack/chips
#find -mindepth 1 -maxdepth 1 -type d |sort 意思是查找 lichee/tools/pack/chips中的全部文件夹。深度为1。也就是仅仅查找到chips这一级。不再往下查找子文件夹了
#我们来tree一下 tools/pack/chips/ 这个文件夹。发现就仅仅有sun4i一个子文件夹
for chip in $(cd $PACK_ROOT/chips/; find -mindepth 1 -maxdepth 1 -type d |sort); do
chips[$count]=`basename $PACK_ROOT/chips/$chip`
printf "$count. ${chips[$count]}\n"
let count=$count+1
done
# 在这里读取我们的选择,并对输入的数据做验证
while true; do
read -p "Please select a chip:"
RES=`expr match $REPLY "[0-9][0-9]*$"`
if [ "$RES" -le 0 ]; then
echo "please use index number"
continue
fi
if [ "$REPLY" -ge $count ]; then
echo "too big"
continue
fi
if [ "$REPLY" -lt "0" ]; then
echo "too small"
continue
fi
break
done
TARGET_CHIP=${chips[$REPLY]}
}
我们来看看实际运行结果
Start packing for Lichee system
All valid chips:
0. sun4i
Please select a chip:0
果然不出所料 仅仅有一个sun4i 说明我们前面的分析全然正确,这里我们输入 '0'
选择平台
运行命令
select_platform $TARGET_CHIP
文件夹结构
tools/pack/chips/sun4i/configs/
├── crane
├── dragonboard
├── linux
└── test
select_platform()
{
count=0
chip=$1
printf "All valid platforms:\n"
# 由于之前select_chips已经$TARGET_CHIP=sun4i 所以$chip=sun4i
# 相似于select_chips,这里会find tools/pack/chips/sun4i/configs/的结果,以序号. 文件夹名的方式输出到终端,让用户选择
for platform in $(cd $PACK_ROOT/chips/$chip/configs/; find -mindepth 1 -maxdepth 1 -type d |sort); do
platforms[$count]=`basename $PACK_ROOT/chips/$chip/configs/$platform`
printf "$count. ${platforms[$count]}\n"
let count=$count+1
done
……
TARGET_PLATFORM=${platforms[$REPLY]}
}
运行结果
All valid platforms:
0. crane
1. dragonboard
2. linux
3. test
Please select a platform:0
这么我们要打包的平台是Android 所以我们选择crane,输入 '0'
选择目标板
select_boards $TARGET_CHIP $TARGET_PLATFORM
文件夹结构
tree -L 1 tools/pack/chips/sun4i/configs/crane/
tools/pack/chips/sun4i/configs/crane/
├── 3g
├── aino
├── aino-aurora
├── bk7011
├── default
├── evb
├── evb_mmc
├── evb-v12r
├── evb-v13
├── m1003h6
├── m802h6
├── mid7042
├── MID9742-sc3052
├── t780
└── tvdevb
select_boards()
{
count=0
# 把我们选定的chip 和 platform 參数传进来
chip=$1
platform=$2
printf "All valid boards:\n"
# 依据传进来的參数 $PACK_ROOT/chips/$chip/configs/$platform/ 即 tools/pack/chips/sun4i/configs/crane 查找1级子文件夹 ,并排序
for board in $(cd $PACK_ROOT/chips/$chip/configs/$platform/; find -mindepth 1 -maxdepth 1 -type d |grep -v default|sort); do
boards[$count]=`basename $PACK_ROOT/chips/$chip/configs/$platform/$board`
printf "$count. ${boards[$count]}\n"
let count=$count+1
done
……
}
到这里我们发现了我们打包缺少了一个非常重要的步骤,记得《Lichee(三) Android4.0的目标产品文件夹与Lichee的纽带---extract-bsp》我们lunch之后。会有自己的目标产品,通过上面的分析我们能够看出,我们必须在打包的时候在tools/pack/chips/sun4i/configs/crane文件夹下创建一个自己产品的文件夹,我们临时把evb-v13文件夹复制过来,改名为mt7332,关于mt7332目下的具体内容。后面会作为重点对象单独提出来分析
运行pack
cd $PACK_ROOT
./pack -c $TARGET_CHIP -p $TARGET_PLATFORM -b $TARGET_BOARD
cd -
当编译完毕后我们会运行一个pack命令。pack也是一个脚本。路径:lichee/tools/pack/pack。这是一个可运行的脚本文件(softwinner相同也提供了windows的打包工具),然后我们来看看pack到底干了些什么
do_pack_crane()
{
printf "!!!Packing for crane!!!\n"
if [ -z "$LICHEE_OUT" ]; then
LICHEE_OUT=`cd ../../out; pwd`
fi
if [ -z "$CRANE_IMAGE_OUT" ]; then
echo "please specify CRANE_IMAGE_OUT env"
exit 1
fi
#拷贝全部的fex cfg文件到out文件夹
cp -v chips/$PACK_CHIP/configs/$PACK_PLATFORM/default/* out/
cp -v chips/$PACK_CHIP/configs/$PACK_PLATFORM/$PACK_BOARD/*.fex out/ 2>/dev/null
cp -v chips/$PACK_CHIP/configs/$PACK_PLATFORM/$PACK_BOARD/*.cfg out/ 2>/dev/null
#cp -v (verbose)选项。cp命令将告诉用户正在做什么。