在前兩篇同一系列的文章中都提到了如下一段語句:linux
#build/core/Makefile INTERNAL_BOOTIMAGE_ARGS := \ --kernel $(INSTALLED_KERNEL_TARGET) \ --ramdisk $(INSTALLED_RAMDISK_TARGET)
顯然,boot.img中包含了Image和ramdisk.img文件,但boot.img中的內容遠不僅這麼多,本文將介紹shell
boot.img中的其它參數,boot.img的生成以及最終boot.img的組成格式.ide
INTERNAL_BOOTIMAGE_ARGS還包含如下內容:ui
1.附加的內核命令行(cmdline): BOARD_KERNEL_CMDLINE加密
一樣在build/core/Makefile中,有如下一段內容(strip起到去除空格的做用):spa
BOARD_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE) ifdef BOARD_KERNEL_CMDLINE INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)" #endif
而BOARD_KERNEL_CMDLINE則在文件device/telechips/tcc88xx-common/BoardConfigCommon.mk中定義:命令行
BOARD_KERNEL_CMDLINE := console=ttyTCC, 115200n8
2.內核加載的基地址,BOARD_KERNEL_BASEcode
一樣在build/core/Makefile中,有如下一段內容:ip
BOARD_KERNEL_BASE := $(strip $(BOARD_KERNEL_BASE)) ifdef BOARD_KERNEL_BASE INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE) endif
而BOARD_KERNEL_BASE也在device/telechips/tcc88xx-common/BoardConfigCommon.mk中定義。get
BOARD_KERNEL_BASE := 0x40000000
3.映像的頁面大小:BOARD_KERNEL_PAGESIZE
一樣在build/core/Makefile中,有如下一段內容:
BOARD_KERNEL_PAGESIZE:= $(strip $(BOARD_KERNEL_PAGESIZE)) ifdef BOARD_KERNEL_PAGESIZE INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE) endif
而BOARD_KERNEL_PAGESIZE 卻在device/telechips/tcc8800/BoardConfig.mk中定義:
BOARD_KERNEL_PAGESIZE := 8192
剩下的內容就是生成boot.img的關鍵語句,在 build/core/Makefile中,內容以下:
INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img $(INTALLED_BOOTIMAGE_TARGET) : $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILE $(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) --output $@
到此,咱們能夠知道 INTERNAL_BOOTIMAGE_ARGS的內容是:
--kernel out/target/product/tcc8800/kernel --ramdisk out/target/product/tcc8800/ramdisk.img --cmdline console=ttyTCC,115200n8 --base 0x40000000 --pagesize 8192
而預知boot.img的格式,必須查看MKBOOTIMG這個程序,其實就是out/host/linux-x86/bin/mkbootimg中的mkbootimg程序。
mkbootimg程序由system/core/mkbootimg工程生成獲得,爲此咱們來看看其中的mkbootimg.c文件,其中有這樣一段:
//信息頭部分 if(write(fd,&hdr,sizeof(hdr)) != sizeof(hdr)) goto fail; if(write_padding(fd,pagesize,sizeof(hdr))) goto fail; //內核部分 if(write(fd,&kernel_data, hdr.kernel_size)!= hdr.kernel_size) goto fail; if(write_padding(fd,pagesize,hdr.kernel_size)) goto fail; //文件系統部分 if(write(fd,&ramdisk_data,hdr.ramdisk_size)!= hdr.ramdisk_size) goto fail; if(wirte_padding(fd,pagesize,hdr.ramdisk_size)) goto fail;
可見boot.img是由文件頭信息,內核數據以及文件系統數據組成,它們之間非頁面對齊部分用0填充(能夠
查看write_padding的代碼),文件頭信息的具體結構能夠在system/core/mkbootimg/bootimg.h中看到:
struct boot_img_hdr { unsigned char magic[BOOT_MAGIC_SIZE]; unsigned kernel_size; unsigned kernel_addr; unsigned ramdisk_size; unsigned ramdisk_addr; unsigned second_size; unsigned second_addr; unsigned tags_addr; unsigned page_size; unsigned unused[2]; unsigned char name[BOOT_NAME_SIZE] unsigned char cmdline[BOOT_ARGS_SIZE] unsigned id[8]; //存放時間戳,校驗和,SHA加密等內容 }
其它成員也很明瞭,由此可知boot.img的大體組成結構了。
-----------------------------------------------------------------------------------------------------------------------------------------------