MTK6577+Android编译之preloader
开发环境:虚拟机+Ubuntu14.04
MTK6577采用的内存芯片为H9TP32A4GDMCPR,包括4GB的eNAND和512MB的 LPDDR2,先升级为H9TP32A8JDMCPR,包括4GB的eNAND和1GB的LPDDR2
先来看MTK源代码树概观图:
图1
由图1可知编译的入口是makeMtk文件,其采用perl语言编写的,包装了编译命令,下面来看编译系统的概述:
图2
编译命令./mk r pr,时间约为20s
(1) 编译后发现有更新的文件有EBR1、MBR、preloader_hsimobile77_ics2.bin和MT6577_Android_scatter_emmc.txt
(2) 编译后有更新的log文件有hsimobile77_ics2_check-dep、hsimobile77_ics2_custgen、hsimobile77_ics2_preloader、hsimobile77_ics2_ptgen和MT6577_Android_scatter_emmc.txt。
1. hsimobile77_ics2_check-dep
内容如下:
2014/08/1908:52:58 custgening... LOG:out/target/product/hsimobile77_ics2_custgen.log ==> [OK] 2014/08/19 08:52:59</span>
Check-dep指check feature dependency,表示检查功能的依赖,此文件没有具体的内容,只是说编译信息见hsimobile77_ics2_custgen.log文件
2. hsimobile77_ics2_custgen
用./mk custgen命令编译时log文件也是这个。
内容如下:
make[1]: Enteringdirectory `/home/cw6577' done make[1]: Leavingdirectory `/home/cw6577'</span>
根据这些信息具体不知道做了哪些工作,custgen指generate customization source,表示生成客户自定义的source,这部分后面再学习相关的《Android_Build_System_for_customer》文档。
3. hsimobile77_ics2_ptgen
ptgen:生成分区设置数据头文件(partition_define.h)和分散加载文件(MT6577_Android_scatter_emmc.txt)(generatepartition setting header&scatter file)
下面我们来看partition_define.h和MT6577_Android_scatter_emmc.txt文件是由\mediatek\build\tools\ptgen\MT6577\ptgen.pl生成的,通过hsimobile77_ics2_ptgen文件中下面的内容可以判断:
*******************Arguments********************* Version=3.3ChangeHistory:3.3 Support Shared SD Card PLATFORM = MT6577; PROJECT =hsimobile77_ics2; LCA_PRJ = no; PAGE_SIZE = 4K; EMMC_SUPPORT= yes; LDVT_SUPPORT= no; TARGET_BUILD_VARIANT=; MTK_EMMC_OTP_SUPPORT=; MTK_SHARED_SDCARD=no; SHEET_NAME=emmc SCAT_NAME=mediatek/source/misc/MT6577_Android_scatter_emmc.txt *******************Arguments********************* …………………….. START=0xFFFF00a8, Partition=BMTPOOL, SIZE=21504, DL_=0, Partition_Index=0, REGION =USER,RESERVE = 0 There are 19Partition totally!. Useof uninitialized value in string ne atmediatek/build/tools/ptgen/MT6577/ptgen.pl line 563. Useof uninitialized value in string ne atmediatek/build/tools/ptgen/MT6577/ptgen.pl line 563. …………………….. Generatemediatek/source/misc/MBR bin file Generatemediatek/source/misc/EBR1 bin file **********PtgenDone********** ^_^ Ptgen modified orGenerated files list: mediatek/source/misc/MT6577_Android_scatter_emmc.txt mediatek/custom/hsimobile77_ics2/common/partition_define.h mediatek/config/hsimobile77_ics2/configs/EMMC_partition_size.mk /out/MBR EBR1 EBR2</span>
图3
那具体是怎么生成这些文件的呢?继续:
(1) partition_define.h
ptgen.pl中有下面一些语句语句:
my$PART_TABLE_FILENAME ="mediatek/build/tools/ptgen/$PLATFORM/partition_table_$PLATFORM.xls";# excel file name my$PARTITION_DEFINE_H_NAME ="mediatek/custom/$PROJECT/common/partition_define.h";</span>
像C语言一样,表示定义一个变量PARTITION_DEFINE_H_NAME,并初始化。
通过这行语句可以知道分区信息从\mediatek\build\tools\ptgen\MT6577\ partition_table_MT6577.xls文件中获取,下面给出此文件的内容:
图4
但是partition_define.h比图4的18个分区多了EBR1分区。这个分区应该也是ptgen.pl生成的,但具体怎么生成还不知道。
(2) MT6577_Android_scatter_emmc.txt
my$SCAT_NAME_DIR ="mediatek/source/misc/"; # $PLATFORM =$ENV{MTK_PLATFORM}; if ($EMMC_SUPPORTeq "yes") { $SCAT_NAME = $SCAT_NAME_DIR . $PLATFORM."_Android_scatter_emmc.txt" ; }else{ $SCAT_NAME = $SCAT_NAME_DIR . $PLATFORM."_Android_scatter.txt" ; }</span>
可知知道,如果\mediatek\config\hsimobile77_ics2\ ProjectConfig.mk文件中有:
MTK_EMMC_SUPPORT=yes
则会有SCAT_NAME=mediatek/source/misc/MT6577_Android_scatter_emmc.txt
此文件内容可见http://blog.csdn.net/loongembedded/article/details/37591369
具体是怎么生成的,需要去研究ptgen.pl源代码。
(3) EMMC_partition_size.mk
内容如下,给出了分区的大小信息
ifeq($(MTK_EMMC_SUPPORT),yes) BOARD_SECROIMAGE_PARTITION_SIZE:=5M BOARD_SYSTEMIMAGE_PARTITION_SIZE:=512M BOARD_CACHEIMAGE_PARTITION_SIZE:=512M BOARD_USERDATAIMAGE_PARTITION_SIZE:=511M BOARD_FATIMAGE_PARTITION_SIZE:=0M endif</span>
4. hsimobile77_ics2_preloader
编译生成prloader镜像文件的主要流程如下:
图5
生成的preloader_hsimobile77_ics2.bin先是放在\mediatek\source\preloader\bin目录下,然后依次拷贝到\out\Download\flash、\out\target\product\hsimobile77_ics2目录下。
(1) 编译preloader的主要工作
############################################################## # Main Flow # build_preloader; post_process; dump_build_info; copy_binary;</span>
下面我们通过此文件的内容来学习编译preloader涉及的一些动作:
(2) 生成custom_emi.c文件
mediatek/custom/hsimobile77_ics2/preloader/custom_emi.c
图6
Os = linux mediatek/custom/hsimobile77_ics2/preloader/inc/custom_MemoryDevice.h mediatek/build/tools/emigen/MT6577/MemoryDeviceList_MT6577.xls MT6577 mediatek/custom/hsimobile77_ics2/preloader/inc/custom_emi.h mediatek/custom/hsimobile77_ics2/preloader/custom_emi.c mediatek/custom/hsimobile77_ics2/preloader/MTK_Loader_Info.tag H9TP32A4GDMCPR</span>
可以判断出编译的时候是从custom_MemoryDevice.h中下面的内容
#defineCS_PART_NUMBER[0] H9TP32A4GDMCPR //KMSJS000KM_B308
知道我们设备采用的EMMC+DDR2是H9TP32A4GDMCPR的
----------------------------------------------------------------------------------------------------------------
先来看ptgen.pl下面的内容:
可以知道ptgen会在MemoryDeviceList_MT6577.xls中看能否找到名为emmc_region的子页面,然后从中获取信息并生成emmc_region.xls文件,再接着打开custom_MemoryDevice.h文件获取到H9TP32A4GDMCPR,然后用此值来和emmc_region.xls文件里的值对比,找到之后输出下面的log信息
----------------------------------------------------------------------------------------------------------------
1 num is 0, nandIDis mt6577[1][scan_idx]EQnull, 7 [2][scan_idx]EQnull, 6 PartNum(H9TP32A4GDMCPR==H9TP32A4GDMCPR)found in row 9 {0x90,0x01,0x4A,0x20,0x58,0x49,0x4E,0x59,0x48,0x0,0x0,0x0} ……………………………. mediatek/custom/hsimobile77_ics2/preloader/custom_emi.cis generated PROJECT =hsimobile77_ics2, pre_bin = preloader_hsimobile77_ics2.bin mediatek/custom/hsimobile77_ics2/preloader/MTK_Loader_Info.tagis generated!</span>
可以看出是在emmc_region.xls的第9列(从MCP所在的第0列开始)
(3) 修改一下目录或是文件需要./mk r(n) pl
\mediatek\platform\mt6577\preloader
\mediatek\custom\common\preloader
\mediatek\custom\mt6577\preloader
\mediatek\custom\hsimobile77_ics2\preloader
\mediatek\custom\hsimobile77_ics2\common下的头文件
\mediatek\custom\hsimobile77_ics2\kernel\dct\dct下的头文件
(4) Preloader的组成
Log信息里有下面的内容:
<span style="font-size:14px;">cat /home/cw6577/mediatek/custom/mt6577/preloader/preloader_ext.bin >>/home/cw6577/mediatek/source/preloader/bin/preloader_hsimobile77_ics2.bin cat /home/cw6577/mediatek/custom/out/hsimobile77_ics2/preloader/MTK_Loader_Info.tag>>/home/cw6577/mediatek/source/preloader/bin/preloader_hsimobile77_ics2.bin</span>
通过mediatek/source/preloader/Makefile文件中下面的内容也可以看出来
############################################################## # ELF Generation # $(D_BIN)/$(PL_IMAGE_NAME).elf: $(LD) --gc-sections -Bstatic-T$(LDSCRIPT) \ $(wildcard $(D_OBJ)/*)$(SECURITY_LIB) \ $(shell if [ -f $(DA_VERIFY_LIB)]; then echo $(DA_VERIFY_LIB); else echo ""; fi;) \ -Map system.map -o$(D_BIN)/$(PL_IMAGE_NAME).elf @$(OBJCOPY) ${OBJCFLAGS}$(D_BIN)/$(PL_IMAGE_NAME).elf -O binary $(D_BIN)/$(PL_IMAGE_NAME).bin ifeq("$(PRELOADER_EXT_BIN_EXIST)","TRUE") cat $(PRELOADER_EXT_BIN) >>$(D_BIN)/$(PL_IMAGE_NAME).bin endif cat$(MTK_PATH_CUSTOM)/MTK_Loader_Info.tag >> $(D_BIN)/$(PL_IMAGE_NAME).bin …………………………..</span>
说明preloader_hsimobile77_ics2.bin=
preloader_hsimobile77_ics2.bin+preloader_ext.bin+ MTK_Loader_Info.tag
(1) Preloader镜像文件的名称preloader_$(PROJECT).bin
我们来看\mediatek\build\makemtk.mk下面的相关内容:
PRELOADER_WD = mediatek/source/preloader PRELOADER_IMAGES:= $(PRELOADER_WD)/bin/preloader_$(PROJECT).bin
这里的PROJECT在源代码根目录下的makeMtk.ini配置文件中赋值的,如下:
project =hsimobile77_ics2
由此可见编译生成的preloader镜像文件为preloader_ hsimobile77_ics2.bin,所在的目录为mediatek/source/preloader/bin。
参考链接:
《Android_Build_System_for_customer》
http://www.cnblogs.com/chyl411/p/3242778.html