Parsing the structure of the instance in the boot. img Format File disassembling and the boot. img file disassembling
Take msm8226 as an example to explain how to compile the boot. img structure for android source code. Boot. img includes the boot. img header, kernel, and ramdisk file system. The following describes the structure of boot. img.
The detailed structure of the boot. img file header information can be seen in system/core/mkbootimg/bootimg. h:
Typedef struct boot_img_hdr;
# Define BOOT_MAGIC "ANDROID! "
# Define BOOT_MAGIC_SIZE 8
# Define BOOT_NAME_SIZE 16
# Define BOOT_ARGS_SIZE 512
Struct boot_img_hdr
{
Unsigned char magic [BOOT_MAGIC_SIZE];
Unsigned kernel_size;/* size in bytes */
Unsigned kernel_addr;/* physical load addr */
Unsigned ramdisk_size;/* size in bytes */
Unsigned ramdisk_addr;/* physical load addr */
Unsigned second_size;/* size in bytes */
Unsigned second_addr;/* physical load addr */
Unsigned tags_addr;/* physical addr for kernel tags */
Unsigned page_size;/* flash page size we assume */
Unsigned dt_size;/* device tree in bytes */
Unsigned unused;/* future expansion: shocould be 0 */
Unsigned char name [BOOT_NAME_SIZE];/* asciiz product name */
Unsigned char character line [BOOT_ARGS_SIZE];
Unsigned id [8];/* timestamp/checksum/sha1/etc */
};
Boot: After the IMG file skips the 2 K file header, it includes two gzpackages, one is boot.img-kernel.gz: linux, and the other is boot.img-ramdisk.cpio.gz.
The approximate structure is as follows:
** + ----------------- +
** | Boot header | 1 page
** + ----------------- +
** | Kernel | n pages
** + ----------------- +
** | Ramdisk | m pages
** + ----------------- +
** | Second stage | o pages
** + ----------------- +
** | Device tree | p pages
** + ----------------- +
** N = (kernel_size + page_size-1)/page_size
** M = (ramdisk_size + page_size-1)/page_size
** O = (second_size + page_size-1)/page_size
** P = (dt_size + page_size-1)/page_size
Figure 1 shows the structure of the boot. img header file:
Structure Analysis of boot. img header files
Lap 1: ANDROID boot. img standard File Header Format: ANDROID! (8 bytes)
Circle 2: kernel_size (4 bytes)
Circle 3: kernel_addr (4 bytes)
Lap 4: ramdisk_size (4 bytes)
Lap 5: ramdisk_addr (4 bytes)
Lap 6: second_stage_size (4 bytes)
Circle 7: second_stage_addr (4 bytes)
Figure 8: tags_addr (4 bytes)
Circle 9: page_size (4 bytes)
Boot. img header file information, kernel_addr, ramdisk_addr, and second_stage_addr are set in bootable \ bootloader \ lk \ target \ msm8226 \ Rules. mk:
PLATFORM: = msm8226
MEMBASE: = 0x0FF00000 # SDRAM
MEMSIZE: = 0x00500000 #5 MB
BASE_ADDR: = 0x00000
TAGS_ADDR: = BASE_ADDR + 0x00000100
KERNEL_ADDR: = BASE_ADDR + 0x00008000
RAMDISK_ADDR: = BASE_ADDR + 0x01000000
SCRATCH_ADDR: = 0x10400000.
Page is an integer multiple of 1 k (1024. 0x00000800 in decimal format.
Verify with the actual boot. imgfile. 2. msm8226 boot. img
Figure 2 msm8226 boot. img content
After parsing the msm8226 boot. img content, you can get:
Base = 0x00000000
Kernel_size = 0x005ff6f0
Kernel_addr = 0x00008000 + base = 0x00008000
Ramdisk_size = 0x00195de2
Ramdisk_addr = 0x01000000 + base = 0x01000000
Sencond_stage_size = 0x00000000
Sencond_stage_addr = 0x00f00000 + base = 0x00f00000
Tag_size = 0x00000100
Page_size = 0x00000800 (2 KB)
View Details: file structure parsing instance in boot format