/****************************************************************************
* I.MX6 Android 5.1 快速合成系统
* 说明:
* Android源代码编译系统是一件很痛苦的事,主要是在修改了一些很小的东西,但
* 要重新编译,要等很久才能编译完,如使用了mmm编译完,只是要打包一下system.img
* 就行了,没必要去做那么多检查编译工作,所以这里跟一下系统合成原来,再精简
* 一下,做一个快速合成系统的工具:a51m(shell 脚本)。
*
* 2016-11-10 深圳 南山平山村 曾剑锋
***************************************************************************/ \\\\\\\\\\\\\\\\\-*-目录-*-//////////////////
| 一、Android 5.1 生成U-Boot信息解析
| 二、Android 5.1 完整生成img镜像信息
| 三、Android 5.1 生成内核信息解析
| 四、解读 Target boot image
| 五、解读 Making recovery image
| 六、解读 Target system fs image
| 七、a51m脚本
-------------------------------------------- 一、Android 5.1 生成U-Boot信息解析:
. 命令行输出信息如下:
for ubootplat in imx6q:mx6qsabresdandroid_config imx6dl:mx6dlsabresdandroid_config imx6qp:mx6qpsabresdandroid_config; do \
UBOOT_PLATFORM=`echo $ubootplat | cut -d':' -f1`; \
UBOOT_CONFIG=`echo $ubootplat | cut -d':' -f2`; \
echo ; \
echo ; \
make -C bootable/bootloader/uboot-imx/ distclean ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-; \
make -C bootable/bootloader/uboot-imx/ $UBOOT_CONFIG ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-; \
make -C bootable/bootloader/uboot-imx/ ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-; \
install -D bootable/bootloader/uboot-imx/u-boot.imx out/target/product/sabresd_6dq/u-boot-$UBOOT_PLATFORM.imx; \
install -D bootable/bootloader/uboot-imx/u-boot.imx out/target/product/sabresd_6dq/u-boot.imx; \
done
. 整理并解读代码如下:
for ubootplat in imx6q:mx6qsabresdandroid_config imx6dl:mx6dlsabresdandroid_config imx6qp:mx6qpsabresdandroid_config; do
# 获取平台类型
UBOOT_PLATFORM=`echo $ubootplat | cut -d':' -f1`;
# 获取配置文件名
UBOOT_CONFIG=`echo $ubootplat | cut -d':' -f2`;
echo ;
echo ;
# 清空之前的编译
make -C bootable/bootloader/uboot-imx/ distclean ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-;
# 重新配置
make -C bootable/bootloader/uboot-imx/ $UBOOT_CONFIG ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-;
# 编译
make -C bootable/bootloader/uboot-imx/ ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-;
# 拷贝
install -D bootable/bootloader/uboot-imx/u-boot.imx out/target/product/sabresd_6dq/u-boot-$UBOOT_PLATFORM.imx;
# 拷贝
install -D bootable/bootloader/uboot-imx/u-boot.imx out/target/product/sabresd_6dq/u-boot.imx;
done 二、Android 5.1 完整生成img镜像信息:
Target ram disk: out/target/product/sabresd_6dq/ramdisk.img
Target boot image: out/target/product/sabresd_6dq/boot.img
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do \
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`; \
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`; \
BOOT_IMAGE_BOARD=out/target/product/sabresd_6dq/boot-$DTS_PLATFORM.img; \
out/host/linux-x86/bin/mkbootimg --kernel out/target/product/sabresd_6dq/kernel --ramdisk out/target/product/sabresd_6dq/ramdisk.img --cmdline "console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consoleblank=0 androidboot.hardware=freescale cma=384M" --base 0x14000000 --second out/target/product/sabresd_6dq/$DTS_BOARD --output out/target/product/sabresd_6dq/boot.img; \
out/host/linux-x86/bin/boot_signer /boot out/target/product/sabresd_6dq/boot.img build/target/product/security/verity.pk8 build/target/product/security/verity.x509.pem out/target/product/sabresd_6dq/boot.img; \
size=$(for i in out/target/product/sabresd_6dq/boot.img; do stat --format "%s" "$i" | tr -d '\n'; echo +; done; echo ); total=$(( $( echo "$size" ) )); printname=$(echo -n "out/target/product/sabresd_6dq/boot.img" | tr " " +); img_blocksize=; twoblocks=$((img_blocksize * )); onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize)); reserve=$((twoblocks > onepct ? twoblocks : onepct)); maxsize=$(( - reserve)); echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve"; if [ "$total" -gt "$maxsize" ]; then echo "error: $printname too large ($total > [17301504 - $reserve])"; false; elif [ "$total" -gt $((maxsize - )) ]; then echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)"; fi ; \
cp -f out/target/product/sabresd_6dq/boot.img $BOOT_IMAGE_BOARD; \
done
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
----- Making recovery image ------
Copying baseline ramdisk...
Modifying ramdisk contents...
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do \
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`; \
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`; \
RECOVERY_IMAGE_BOARD=out/target/product/sabresd_6dq/recovery-$DTS_PLATFORM.img; \
out/host/linux-x86/bin/mkbootimg --kernel out/target/product/sabresd_6dq/kernel --ramdisk out/target/product/sabresd_6dq/ramdisk-recovery.img --cmdline "console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consoleblank=0 androidboot.hardware=freescale cma=384M" --base 0x14000000 --second out/target/product/sabresd_6dq/$DTS_BOARD --output out/target/product/sabresd_6dq/recovery.img; \
if [ true = true ]; then \
out/host/linux-x86/bin/boot_signer /recovery out/target/product/sabresd_6dq/recovery.img build/target/product/security/verity.pk8 build/target/product/security/verity.x509.pem out/target/product/sabresd_6dq/recovery.img; \
fi;\
size=$(for i in out/target/product/sabresd_6dq/recovery.img; do stat --format "%s" "$i" | tr -d '\n'; echo +; done; echo ); total=$(( $( echo "$size" ) )); printname=$(echo -n "out/target/product/sabresd_6dq/recovery.img" | tr " " +); img_blocksize=; twoblocks=$((img_blocksize * )); onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize)); reserve=$((twoblocks > onepct ? twoblocks : onepct)); maxsize=$(( - reserve)); echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve"; if [ "$total" -gt "$maxsize" ]; then echo "error: $printname too large ($total > [17301504 - $reserve])"; false; elif [ "$total" -gt $((maxsize - )) ]; then echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)"; fi ; \
cp -f out/target/product/sabresd_6dq/recovery.img $RECOVERY_IMAGE_BOARD; \
done
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
----- Made recovery image: out/target/product/sabresd_6dq/recovery.img --------
Installed file list: out/target/product/sabresd_6dq/installed-files.txt
Target system fs image: out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img
make_ext4fs -s -T - -S out/target/product/sabresd_6dq/root/file_contexts -l -a system out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/sabresd_6dq/system
Creating filesystem with parameters:
Size:
Block size:
Blocks per group:
Inodes per group:
Inode size:
Journal blocks:
Label:
Blocks:
Block groups:
Reserved block group size:
Created filesystem with / inodes and / blocks
Running: mkuserimg.sh -s out/target/product/sabresd_6dq/system out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img ext4 system out/target/product/sabresd_6dq/root/file_contexts
build_verity_tree -A aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity.img
system/extras/verity/build_verity_metadata.py /tmp/tmpMr__Ct_verity_images/verity_metadata.img c05456d1171333727af2a3f82feb59856e56229fe81c75c90fd2a1359893a438 aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 /dev/block/mmcblk3p5 out/host/linux-x86/bin/verity_signer build/target/product/security/verity.pk8
append2simg out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity_metadata.img
append2simg out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity.img
Construct recovery from boot
mkdir -p out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/
PATH=out/host/linux-x86/bin:$PATH
out/host/linux-x86/bin/imgdiff out/target/product/sabresd_6dq/boot.img out/target/product/sabresd_6dq/recovery.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p
chunk : type start len
chunk : type start len
chunk : type start len
Construct patches for chunks...
patch is bytes (of )
patch is bytes (of )
patch is bytes (of )
chunk : normal ( , )
chunk : deflate ( , ) (null)
chunk : normal ( , )
Install system fs image: out/target/product/sabresd_6dq/system.img
out/target/product/sabresd_6dq/system.img+out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p maxsize= blocksize= total= reserve= #### make completed successfully (: (mm:ss)) #### 三、Android 5.1 生成内核信息解析:
. 命令行输出信息如下:
Target ram disk: out/target/product/sabresd_6dq/ramdisk.img
Target boot image: out/target/product/sabresd_6dq/boot.img
install -D kernel_imx/arch/arm/boot/zImage out/target/product/sabresd_6dq/kernel
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do \
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`; \
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`; \
install -D kernel_imx/arch/arm/boot/dts/$DTS_BOARD out/target/product/sabresd_6dq/$DTS_BOARD; \
done
make -C kernel_imx modules ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi- LOADADDR=0x10008000
. 整理并解读代码如下:
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`;
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`;
install -D kernel_imx/arch/arm/boot/dts/$DTS_BOARD out/target/product/sabresd_6dq/$DTS_BOARD;
done
. 由上可知out/target/product/sabresd_6dq/kernel是kernel_imx/arch/arm/boot/zImage文件,同时编译生成的dts在arch/arm/boot/dts目录下面。 四、解读 Target boot image:
. 命令行输出信息如下:
Target ram disk: out/target/product/sabresd_6dq/ramdisk.img
Target boot image: out/target/product/sabresd_6dq/boot.img
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do \
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`; \
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`; \
BOOT_IMAGE_BOARD=out/target/product/sabresd_6dq/boot-$DTS_PLATFORM.img; \
out/host/linux-x86/bin/mkbootimg --kernel out/target/product/sabresd_6dq/kernel --ramdisk out/target/product/sabresd_6dq/ramdisk.img --cmdline "console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consoleblank=0 androidboot.hardware=freescale cma=384M" --base 0x14000000 --second out/target/product/sabresd_6dq/$DTS_BOARD --output out/target/product/sabresd_6dq/boot.img; \
out/host/linux-x86/bin/boot_signer /boot out/target/product/sabresd_6dq/boot.img build/target/product/security/verity.pk8 build/target/product/security/verity.x509.pem out/target/product/sabresd_6dq/boot.img; \
size=$(for i in out/target/product/sabresd_6dq/boot.img; do stat --format "%s" "$i" | tr -d '\n'; echo +; done; echo ); total=$(( $( echo "$size" ) )); printname=$(echo -n "out/target/product/sabresd_6dq/boot.img" | tr " " +); img_blocksize=; twoblocks=$((img_blocksize * )); onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize)); reserve=$((twoblocks > onepct ? twoblocks : onepct)); maxsize=$(( - reserve)); echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve"; if [ "$total" -gt "$maxsize" ]; then echo "error: $printname too large ($total > [17301504 - $reserve])"; false; elif [ "$total" -gt $((maxsize - )) ]; then echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)"; fi ; \
cp -f out/target/product/sabresd_6dq/boot.img $BOOT_IMAGE_BOARD; \
done
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
. 由上可知,ramdisk合成没有给出信息:
. 参考文档:
. ramdisk.img及boot.img的生成过程
http://blog.csdn.net/zhijianjingling00/article/details/16841683
. 修改build/core/Makefile:
......
# We just build this directly to the install location.
INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
$(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) | $(MINIGZIP)
$(call pretty,"Target ram disk: $@")
$(MKBOOTFS) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $@ # 去掉前面的"$(hide)"
......
. 得到输出信息:
out/host/linux-x86/bin/mkbootfs out/target/product/sabresd_6dq/root | out/host/linux-x86/bin/minigzip > out/target/product/sabresd_6dq/ramdisk.img
. 整理并解读代码如下:
# for循环迭代以下四种情况:
# . dtsplat:imx6q:imx6q-sabresd.dtb
# . dtsplat:imx6dl:imx6dl-sabresd.dtb
# . dtsplat:imx6q-ldo:imx6q-sabresd-ldo.dtb
# . dtsplat:imx6qp:imx6qp-sabresd.dtb
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do
# 截取dtsplat中的冒号前面的那部分字符,也就是:
# . imx6q;
# . imx6dl;
# . imx6q-ldo;
# . imx6qp;
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`;
# 截取dtsplat中的冒号后面的那部分字符,也就是:
# . imx6q-sabresd.dtb;
# . imx6dl-sabresd.dtb;
# . imx6q-sabresd-ldo.dtb;
# . imx6qp-sabresd.dtb;
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`;
# 合成当前次要生成的boot.img文件名
BOOT_IMAGE_BOARD=out/target/product/sabresd_6dq/boot-$DTS_PLATFORM.img;
# 使用mkbootimg合成boot.img文件,除了dts文件,其他的都是明确的
out/host/linux-x86/bin/mkbootimg --kernel out/target/product/sabresd_6dq/kernel --ramdisk out/target/product/sabresd_6dq/ramdisk.img --cmdline "console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consoleblank=0 androidboot.hardware=freescale cma=384M" --base 0x14000000 --second out/target/product/sabresd_6dq/$DTS_BOARD --output out/target/product/sabresd_6dq/boot.img;
# 这里不是很明确到底要在做什么
out/host/linux-x86/bin/boot_signer /boot out/target/product/sabresd_6dq/boot.img build/target/product/security/verity.pk8 build/target/product/security/verity.x509.pem out/target/product/sabresd_6dq/boot.img;
# 接下来这段更多的是校验文件大小是否超出16M,
size=$(
for i in out/target/product/sabresd_6dq/boot.img; do
stat --format "%s" "$i" | tr -d '\n';
echo +;
done;
echo
);
total=$(( $( echo "$size" ) ));
printname=$(echo -n "out/target/product/sabresd_6dq/boot.img" | tr " " +);
img_blocksize=;
twoblocks=$((img_blocksize * ));
onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize));
reserve=$((twoblocks > onepct ? twoblocks : onepct));
maxsize=$(( - reserve));
echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve";
if [ "$total" -gt "$maxsize" ]; then
echo "error: $printname too large ($total > [17301504 - $reserve])";
false;
elif [ "$total" -gt $((maxsize - )) ]; then
echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)";
fi ;
# 以上检查都正常,拷贝文件
cp -f out/target/product/sabresd_6dq/boot.img $BOOT_IMAGE_BOARD;
done
. 和上面的shell脚本对比,输出信息正常:
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/boot.img maxsize= blocksize= total= reserve= 五、解读 Making recovery image :
. 命令行输出信息如下:
----- Making recovery image ------
Copying baseline ramdisk...
Modifying ramdisk contents...
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do \
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`; \
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`; \
RECOVERY_IMAGE_BOARD=out/target/product/sabresd_6dq/recovery-$DTS_PLATFORM.img; \
out/host/linux-x86/bin/mkbootimg --kernel out/target/product/sabresd_6dq/kernel --ramdisk out/target/product/sabresd_6dq/ramdisk-recovery.img --cmdline "console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consoleblank=0 androidboot.hardware=freescale cma=384M" --base 0x14000000 --second out/target/product/sabresd_6dq/$DTS_BOARD --output out/target/product/sabresd_6dq/recovery.img; \
if [ true = true ]; then \
out/host/linux-x86/bin/boot_signer /recovery out/target/product/sabresd_6dq/recovery.img build/target/product/security/verity.pk8 build/target/product/security/verity.x509.pem out/target/product/sabresd_6dq/recovery.img; \
fi;\
size=$(for i in out/target/product/sabresd_6dq/recovery.img; do stat --format "%s" "$i" | tr -d '\n'; echo +; done; echo ); total=$(( $( echo "$size" ) )); printname=$(echo -n "out/target/product/sabresd_6dq/recovery.img" | tr " " +); img_blocksize=; twoblocks=$((img_blocksize * )); onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize)); reserve=$((twoblocks > onepct ? twoblocks : onepct)); maxsize=$(( - reserve)); echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve"; if [ "$total" -gt "$maxsize" ]; then echo "error: $printname too large ($total > [17301504 - $reserve])"; false; elif [ "$total" -gt $((maxsize - )) ]; then echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)"; fi ; \
cp -f out/target/product/sabresd_6dq/recovery.img $RECOVERY_IMAGE_BOARD; \
done
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
----- Made recovery image: out/target/product/sabresd_6dq/recovery.img --------
. 整理并解读代码如下:
# for循环迭代以下四种情况:
# . dtsplat:imx6q:imx6q-sabresd.dtb
# . dtsplat:imx6dl:imx6dl-sabresd.dtb
# . dtsplat:imx6q-ldo:imx6q-sabresd-ldo.dtb
# . dtsplat:imx6qp:imx6qp-sabresd.dtb
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do
# 截取dtsplat中的冒号前面的那部分字符,也就是:
# . imx6q;
# . imx6dl;
# . imx6q-ldo;
# . imx6qp;
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`;
# 截取dtsplat中的冒号后面的那部分字符,也就是:
# . imx6q-sabresd.dtb;
# . imx6dl-sabresd.dtb;
# . imx6q-sabresd-ldo.dtb;
# . imx6qp-sabresd.dtb;
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`;
# 合成当前次要生成的recovery.img文件名
RECOVERY_IMAGE_BOARD=out/target/product/sabresd_6dq/recovery-$DTS_PLATFORM.img;
# 使用mkbootimg合成recovery.img文件,除了dts文件,其他的都是明确的,请对比boot.img合成的命令,几乎一样
# out/host/linux-x86/bin/mkbootimg --kernel out/target/product/sabresd_6dq/kernel --ramdisk out/target/product/sabresd_6dq/ramdisk.img --cmdline "console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consoleblank=0 androidboot.hardware=freescale cma=384M" --base 0x14000000 --second out/target/product/sabresd_6dq/$DTS_BOARD --output out/target/product/sabresd_6dq/boot.img;
out/host/linux-x86/bin/mkbootimg --kernel out/target/product/sabresd_6dq/kernel --ramdisk out/target/product/sabresd_6dq/ramdisk-recovery.img --cmdline "console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consoleblank=0 androidboot.hardware=freescale cma=384M" --base 0x14000000 --second out/target/product/sabresd_6dq/$DTS_BOARD --output out/target/product/sabresd_6dq/recovery.img;
# 加入校验,这里不是很明确到底要在做什么
if [ true = true ]; then
out/host/linux-x86/bin/boot_signer /recovery out/target/product/sabresd_6dq/recovery.img build/target/product/security/verity.pk8 build/target/product/security/verity.x509.pem out/target/product/sabresd_6dq/recovery.img;
fi;
# 接下来这段更多的是校验文件大小是否超出16M,
size=$(
for i in out/target/product/sabresd_6dq/recovery.img; do
stat --format "%s" "$i" | tr -d '\n';
echo +;
done;
echo
);
total=$(( $( echo "$size" ) ));
printname=$(echo -n "out/target/product/sabresd_6dq/recovery.img" | tr " " +);
img_blocksize=;
twoblocks=$((img_blocksize * ));
onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize));
reserve=$((twoblocks > onepct ? twoblocks : onepct));
maxsize=$(( - reserve));
echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve";
if [ "$total" -gt "$maxsize" ]; then
echo "error: $printname too large ($total > [17301504 - $reserve])";
false;
elif [ "$total" -gt $((maxsize - )) ]; then
echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)";
fi ;
# 以上检查都正常,拷贝文件
cp -f out/target/product/sabresd_6dq/recovery.img $RECOVERY_IMAGE_BOARD;
done
. 和上面的shell脚本对比,输出信息正常:
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve=
out/target/product/sabresd_6dq/recovery.img maxsize= blocksize= total= reserve= 六、解读 Target system fs image:
. 命令行输出信息如下:
Target system fs image: out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img
make_ext4fs -s -T - -S out/target/product/sabresd_6dq/root/file_contexts -l -a system out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/sabresd_6dq/system
Creating filesystem with parameters:
Size:
Block size:
Blocks per group:
Inodes per group:
Inode size:
Journal blocks:
Label:
Blocks:
Block groups:
Reserved block group size:
Created filesystem with / inodes and / blocks
Running: mkuserimg.sh -s out/target/product/sabresd_6dq/system out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img ext4 system out/target/product/sabresd_6dq/root/file_contexts
build_verity_tree -A aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity.img
system/extras/verity/build_verity_metadata.py /tmp/tmpMr__Ct_verity_images/verity_metadata.img c05456d1171333727af2a3f82feb59856e56229fe81c75c90fd2a1359893a438 aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 /dev/block/mmcblk3p5 out/host/linux-x86/bin/verity_signer build/target/product/security/verity.pk8
append2simg out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity_metadata.img
append2simg out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity.img
Construct recovery from boot
mkdir -p out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/
PATH=out/host/linux-x86/bin:$PATH
out/host/linux-x86/bin/imgdiff out/target/product/sabresd_6dq/boot.img out/target/product/sabresd_6dq/recovery.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p
chunk : type start len
chunk : type start len
chunk : type start len
Construct patches for chunks...
patch is bytes (of )
patch is bytes (of )
patch is bytes (of )
chunk : normal ( , )
chunk : deflate ( , ) (null)
chunk : normal ( , )
Install system fs image: out/target/product/sabresd_6dq/system.img
out/target/product/sabresd_6dq/system.img+out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p maxsize= blocksize= total= reserve= #### make completed successfully (: (mm:ss)) ####
. 如上可知,最后生成out/target/product/sabresd_6dq/system.img部分内容好像被隐藏了。
. 为了看到整个程序执行信息,修改源代码:
. 参考文档:
. 参考文档:Android——编译体系中的【PRODUCT_COPY_FILES】【ALL_PREBUILT】【BUILD_PREBUILT】
http://blog.csdn.net/jscese/article/details/40615801
. Android编译系统分析五:system.img的生成过程
http://blog.csdn.net/u011913612/article/details/52503318
. Android系统镜像文件的打包过程分析
http://blog.csdn.net/Luoshengyang/article/details/20501657
. 修改build/core/definitions.mk
......
define copy-file-to-target
@mkdir -p $(dir $@)
$(hide) $(ACP) -fp $< $@ # 移除前面的"$(hide)"
endef
......
. 修改build/core/Makefile
......
INSTALLED_SYSTEMIMAGE := $(PRODUCT_OUT)/system.img
......
systemimage_intermediates := \
$(call intermediates-dir-for,PACKAGING,systemimage)
BUILT_SYSTEMIMAGE := $(systemimage_intermediates)/system.img
......
$(INSTALLED_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE) $(RECOVERY_FROM_BOOT_PATCH) | $(ACP)
@echo "Install system fs image: $@"
$(copy-file-to-target)
# 为了看到这部分完整的处理流程,将"$(hide)"去掉
# $(hide) $(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
$(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)) systemimage: $(INSTALLED_SYSTEMIMAGE)
......
. 隐藏的处理信息如下:
Install system fs image: out/target/product/sabresd_6dq/system.img
out/host/linux-x86/bin/acp -fp out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/sabresd_6dq/system.img
size=$(for i in out/target/product/sabresd_6dq/system.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p; do stat --format "%s" "$i" | tr -d '\n'; echo +; done; echo ); total=$(( $( echo "$size" ) )); printname=$(echo -n "out/target/product/sabresd_6dq/system.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p" | tr " " +); img_blocksize=; twoblocks=$((img_blocksize * )); onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize)); reserve=$((twoblocks > onepct ? twoblocks : onepct)); maxsize=$(( - reserve)); echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve"; if [ "$total" -gt "$maxsize" ]; then echo "error: $printname too large ($total > [389283840 - $reserve])"; false; elif [ "$total" -gt $((maxsize - )) ]; then echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)"; fi
out/target/product/sabresd_6dq/system.img+out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p maxsize= blocksize= total= reserve=
# @ size=$(for i in out/target/product/sabresd_6dq/system.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p; do stat --format "%s" "$i" | tr -d '\n'; echo +; done; echo ); total=$(( $( echo "$size" ) )); printname=$(echo -n "out/target/product/sabresd_6dq/system.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p" | tr " " +); img_blocksize=; twoblocks=$((img_blocksize * )); onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize)); reserve=$((twoblocks > onepct ? twoblocks : onepct)); maxsize=$(( - reserve)); echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve"; if [ "$total" -gt "$maxsize" ]; then echo "error: $printname too large ($total > [389283840 - $reserve])"; false; elif [ "$total" -gt $((maxsize - )) ]; then echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)"; fi #### make completed successfully (: (mm:ss)) ####
. 整理并解读代码如下:
. 制作ext4fs文件系统:
make_ext4fs -s -T - -S out/target/product/sabresd_6dq/root/file_contexts -l -a system out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/sabresd_6dq/system
. 以下步骤基本上是没什么变量,所以也就不解析了:
mkuserimg.sh -s out/target/product/sabresd_6dq/system out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img ext4 system out/target/product/sabresd_6dq/root/file_contexts
build_verity_tree -A aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity.img
system/extras/verity/build_verity_metadata.py /tmp/tmpMr__Ct_verity_images/verity_metadata.img c05456d1171333727af2a3f82feb59856e56229fe81c75c90fd2a1359893a438 aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 /dev/block/mmcblk3p5 out/host/linux-x86/bin/verity_signer build/target/product/security/verity.pk8
append2simg out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity_metadata.img
append2simg out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity.img
mkdir -p out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/
PATH=out/host/linux-x86/bin:$PATH
out/host/linux-x86/bin/imgdiff out/target/product/sabresd_6dq/boot.img out/target/product/sabresd_6dq/recovery.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p
. 隐藏信息解读:
# 直接将前面声场的system.img文件拷贝到输出目录中
out/host/linux-x86/bin/acp -fp out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/sabresd_6dq/system.img
# 统计两个文件的大小,并判断system.img文件是否正常,和前面类似,其实没有过多的解析必要
size=$(
for i in out/target/product/sabresd_6dq/system.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p; do
stat --format "%s" "$i" | tr -d '\n';
echo +;
done;
echo
);
total=$(( $( echo "$size" ) ));
# 将两个文件中的空格换成+号
printname=$(echo -n "out/target/product/sabresd_6dq/system.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p" | tr " " +);
img_blocksize=;
twoblocks=$((img_blocksize * ));
onepct=$((((( / ) - ) / img_blocksize + ) * img_blocksize));
reserve=$((twoblocks > onepct ? twoblocks : onepct));
maxsize=$(( - reserve));
echo "$printname maxsize=$maxsize blocksize=$img_blocksize total=$total reserve=$reserve";
if [ "$total" -gt "$maxsize" ]; then
echo "error: $printname too large ($total > [389283840 - $reserve])";
false;
elif [ "$total" -gt $((maxsize - )) ]; then
echo "WARNING: $printname approaching size limit ($total now; limit $maxsize)";
fi 七、a51m脚本:
#!/bin/bash # source build/envsetup.sh && lunch sabresd_6dq-user && make >& | tee build-log.txt if [ $# != ]; then
echo "USAGE:"
echo " a51m <ub | bi | fs> "
echo " 1. ub: U-Boot compile."
echo " 2. bi: boot.img compile."
echo " 3. fs: system.img repack"
echo
exit -
fi # for U-Boot compile
if [ $ = "ub" ]; then
for ubootplat in imx6q:mx6qsabresdandroid_config imx6dl:mx6dlsabresdandroid_config imx6qp:mx6qpsabresdandroid_config; do
UBOOT_PLATFORM=`echo $ubootplat | cut -d':' -f1`;
UBOOT_CONFIG=`echo $ubootplat | cut -d':' -f2`;
echo ;
echo ;
make -C bootable/bootloader/uboot-imx/ distclean ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-;
make -C bootable/bootloader/uboot-imx/ $UBOOT_CONFIG ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-;
make -C bootable/bootloader/uboot-imx/ ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-; echo -e "\tcp bootable/bootloader/uboot-imx/u-boot.imx out/target/product/sabresd_6dq/u-boot-$UBOOT_PLATFORM.imx; "
cp bootable/bootloader/uboot-imx/u-boot.imx out/target/product/sabresd_6dq/u-boot-$UBOOT_PLATFORM.imx;
done echo -e "\n\033[32mGenerate u-boot.imx Work Over.\033[0m\n" exit
fi # for boot.img compile
if [ $ = "bi" ]; then
make -C kernel_imx ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi- LOADADDR=0x10008000
echo -e "\n\033[32m[Copy zImage file to target]:\033[0m"
echo -e "\tcp kernel_imx/arch/arm/boot/zImage out/target/product/sabresd_6dq/kernel"
cp kernel_imx/arch/arm/boot/zImage out/target/product/sabresd_6dq/kernel echo -e "\n\033[32m[Copy dtb file to target]:\033[0m"
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`;
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`;
echo -e "\tcp kernel_imx/arch/arm/boot/dts/$DTS_BOARD out/target/product/sabresd_6dq/$DTS_BOARD"
cp kernel_imx/arch/arm/boot/dts/$DTS_BOARD out/target/product/sabresd_6dq/$DTS_BOARD;
done echo -e "\n\033[32m[Generate ramdisk.img file to target]:\033[0m"
echo -e "\tout/host/linux-x86/bin/mkbootfs out/target/product/sabresd_6dq/root | out/host/linux-x86/bin/minigzip > out/target/product/sabresd_6dq/ramdisk.img"
out/host/linux-x86/bin/mkbootfs out/target/product/sabresd_6dq/root | out/host/linux-x86/bin/minigzip > out/target/product/sabresd_6dq/ramdisk.img echo -e "\n\033[32m[Generate boot.img file to target]:\033[0m"
for dtsplat in imx6q:imx6q-sabresd.dtb imx6dl:imx6dl-sabresd.dtb imx6q-ldo:imx6q-sabresd-ldo.dtb imx6qp:imx6qp-sabresd.dtb; do
DTS_PLATFORM=`echo $dtsplat | cut -d':' -f1`;
DTS_BOARD=`echo $dtsplat | cut -d':' -f2`;
BOOT_IMAGE_BOARD=out/target/product/sabresd_6dq/boot-$DTS_PLATFORM.img;
out/host/linux-x86/bin/mkbootimg --kernel out/target/product/sabresd_6dq/kernel --ramdisk out/target/product/sabresd_6dq/ramdisk.img --cmdline "console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consoleblank=0 androidboot.hardware=freescale cma=384M" --base 0x14000000 --second out/target/product/sabresd_6dq/$DTS_BOARD --output out/target/product/sabresd_6dq/boot.img;
out/host/linux-x86/bin/boot_signer /boot out/target/product/sabresd_6dq/boot.img build/target/product/security/verity.pk8 build/target/product/security/verity.x509.pem out/target/product/sabresd_6dq/boot.img;
echo -e "\tcp -f out/target/product/sabresd_6dq/boot.img $BOOT_IMAGE_BOARD"
cp -f out/target/product/sabresd_6dq/boot.img $BOOT_IMAGE_BOARD;
done echo -e "\n\033[32mGenerate boot.img Work Over.\033[0m\n" exit
fi # for system.img repack
if [ $ = "fs" ]; then
make_ext4fs -s -T - -S out/target/product/sabresd_6dq/root/file_contexts -l -a system out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/sabresd_6dq/system
mkuserimg.sh -s out/target/product/sabresd_6dq/system out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img ext4 system out/target/product/sabresd_6dq/root/file_contexts
mkdir -p /tmp/tmpMr__Ct_verity_images
build_verity_tree -A aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity.img
system/extras/verity/build_verity_metadata.py /tmp/tmpMr__Ct_verity_images/verity_metadata.img c05456d1171333727af2a3f82feb59856e56229fe81c75c90fd2a1359893a438 aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 /dev/block/mmcblk3p5 out/host/linux-x86/bin/verity_signer build/target/product/security/verity.pk8
append2simg out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity_metadata.img
append2simg out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpMr__Ct_verity_images/verity.img
mkdir -p out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/
PATH=out/host/linux-x86/bin:$PATH
out/host/linux-x86/bin/imgdiff out/target/product/sabresd_6dq/boot.img out/target/product/sabresd_6dq/recovery.img out/target/product/sabresd_6dq/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p
out/host/linux-x86/bin/acp -fp out/target/product/sabresd_6dq/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/sabresd_6dq/system.img echo -e "\n\033[32mGenerate system.img Work Over.\033[0m\n" exit
fi echo "USAGE:"
echo " a51m <ub | bi | fs> "
echo " 1. ub: U-Boot compile."
echo " 2. bi: boot.img compile."
echo " 3. fs: system.img repack"
echo