博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Android]构建boot.img(三):boot.img的生成与结构
阅读量:7063 次
发布时间:2019-06-28

本文共 3069 字,大约阅读时间需要 10 分钟。

  hot3.png

在前两篇同一系列的文章中都提到了以下一段语句:

#build/core/MakefileINTERNAL_BOOTIMAGE_ARGS := \            --kernel $(INSTALLED_KERNEL_TARGET) \            --ramdisk $(INSTALLED_RAMDISK_TARGET)

显然,boot.img中包含了Image和ramdisk.img文件,但boot.img中的内容远不只这么多,本文将介绍

boot.img中的其它参数,boot.img的生成以及最终boot.img的组成格式.

INTERNAL_BOOTIMAGE_ARGS还包含以下内容:

1.附加的内核命令行(cmdline): BOARD_KERNEL_CMDLINE

同样在build/core/Makefile中,有以下一段内容(strip起到去除空格的作用):

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_BASE

同样在build/core/Makefile中,有以下一段内容:

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中定义。

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的大致组成结构了。

-----------------------------------------------------------------------------------------------------------------------------------------------

转载于:https://my.oschina.net/armsky/blog/32115

你可能感兴趣的文章
kafka伪分布式安装(2.12版)
查看>>
Android 流媒体系列(二)
查看>>
Clone Graph
查看>>
Java的接口总结
查看>>
C++复习
查看>>
cpsr与cpsr_c的区别
查看>>
阿里云CDN的一些资料记录
查看>>
MQTT消息中间件Mosquitto的安装和配置
查看>>
星星评分
查看>>
Django - - Django REST framework基础:分页
查看>>
Floyd算法(求最短路)
查看>>
no module name cx_oracle 的解决方法
查看>>
poj - 2240 Arbitrage
查看>>
springmvc文件上传
查看>>
TypeScript 学习笔记
查看>>
Selenium3+python3-发送添加附件的邮件
查看>>
移动端-必要知识
查看>>
Redis指令
查看>>
Date12
查看>>
HTTP协议09-响应首部字段
查看>>