diff --git a/mkbootimg/include/bootimg/bootimg.h b/mkbootimg/include/bootimg/bootimg.h index 4432f9ec9..9ee786927 100644 --- a/mkbootimg/include/bootimg/bootimg.h +++ b/mkbootimg/include/bootimg/bootimg.h @@ -115,7 +115,7 @@ struct boot_img_hdr_v1 : public boot_img_hdr_v0 { uint32_t header_size; } __attribute__((packed)); -/* When the boot image header has a version of 1, the structure of the boot +/* When the boot image header has a version of 2, the structure of the boot * image is as follows: * * +---------------------+ @@ -129,17 +129,21 @@ struct boot_img_hdr_v1 : public boot_img_hdr_v0 { * +---------------------+ * | recovery dtbo/acpio | p pages * +---------------------+ + * | dtb | q 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 = (recovery_dtbo_size + page_size - 1) / page_size + * q = (dtb_size + page_size - 1) / page_size * * 0. all entities are page_size aligned in flash - * 1. kernel and ramdisk are required (size != 0) + * 1. kernel, ramdisk and DTB are required (size != 0) * 2. recovery_dtbo/recovery_acpio is required for recovery.img in non-A/B * devices(recovery_dtbo_size != 0) * 3. second is optional (second_size == 0 -> no second) - * 4. load each element (kernel, ramdisk, second) at + * 4. load each element (kernel, ramdisk, second, dtb) at * the specified physical address (kernel_addr, etc) * 5. If booting to recovery mode in a non-A/B device, extract recovery * dtbo/acpio and apply the correct set of overlays on the base device tree @@ -150,3 +154,7 @@ struct boot_img_hdr_v1 : public boot_img_hdr_v0 { * 8. if second_size != 0: jump to second_addr * else: jump to kernel_addr */ +struct boot_img_hdr_v2 : public boot_img_hdr_v1 { + uint32_t dtb_size; /* size in bytes for DTB image */ + uint64_t dtb_addr; /* physical load address for DTB image */ +} __attribute__((packed)); diff --git a/mkbootimg/mkbootimg.py b/mkbootimg/mkbootimg.py index 2eb2bab56..859b1e489 100644 --- a/mkbootimg/mkbootimg.py +++ b/mkbootimg/mkbootimg.py @@ -85,6 +85,8 @@ def write_header(args): if args.header_version > 0: update_sha(sha, args.recovery_dtbo) + if args.header_version > 1: + update_sha(sha, args.dtb) img_id = pack('32s', sha.digest()) @@ -99,6 +101,10 @@ def write_header(args): args.output.write(pack('Q', 0)) # Will be set to 0 for devices without a recovery dtbo args.output.write(pack('I', args.output.tell() + 4)) # size of boot header + + if args.header_version > 1: + args.output.write(pack('I', filesize(args.dtb))) # size in bytes + args.output.write(pack('Q', args.base + args.dtb_offset)) # dtb physical load address pad_file(args.output, args.pagesize) return img_id @@ -161,6 +167,7 @@ def parse_cmdline(): required=True) parser.add_argument('--ramdisk', help='path to the ramdisk', type=FileType('rb')) parser.add_argument('--second', help='path to the 2nd bootloader', type=FileType('rb')) + parser.add_argument('--dtb', help='path to dtb', type=FileType('rb')) recovery_dtbo_group = parser.add_mutually_exclusive_group() recovery_dtbo_group.add_argument('--recovery_dtbo', help='path to the recovery DTBO', type=FileType('rb')) recovery_dtbo_group.add_argument('--recovery_acpio', help='path to the recovery ACPIO', @@ -172,6 +179,8 @@ def parse_cmdline(): parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000) parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int, default=0x00f00000) + parser.add_argument('--dtb_offset', help='dtb offset', type=parse_int, default=0x01f00000) + parser.add_argument('--os_version', help='operating system version', type=parse_os_version, default=0) parser.add_argument('--os_patch_level', help='operating system patch level', @@ -196,6 +205,8 @@ def write_data(args): if args.header_version > 0: write_padded_file(args.output, args.recovery_dtbo, args.pagesize) + if args.header_version > 1: + write_padded_file(args.output, args.dtb, args.pagesize) def main(): args = parse_cmdline() diff --git a/mkbootimg/unpack_bootimg.py b/mkbootimg/unpack_bootimg.py old mode 100644 new mode 100755 index c37acd5ac..6b5d5d0da --- a/mkbootimg/unpack_bootimg.py +++ b/mkbootimg/unpack_bootimg.py @@ -15,7 +15,7 @@ """unpacks the bootimage. -Extracts the kernel, ramdisk, second bootloader and recovery dtbo images. +Extracts the kernel, ramdisk, second bootloader, dtb and recovery dtbo images. """ from __future__ import print_function @@ -82,6 +82,14 @@ def unpack_bootimage(args): print('boot header size: %s' % boot_header_size) else: recovery_dtbo_size = 0 + if version > 1: + dtb_size = unpack('I', args.boot_img.read(4))[0] + print('dtb size: %s' % dtb_size) + dtb_load_address = unpack('Q', args.boot_img.read(8))[0] + print('dtb address: %s' % dtb_load_address) + else: + dtb_size = 0 + # The first page contains the boot header num_header_pages = 1 @@ -103,6 +111,15 @@ def unpack_bootimage(args): if recovery_dtbo_size > 0: image_info_list.append((recovery_dtbo_offset, recovery_dtbo_size, 'recovery_dtbo')) + if dtb_size > 0: + num_second_pages = get_number_of_pages(second_size, page_size) + num_recovery_dtbo_pages = get_number_of_pages(recovery_dtbo_size, page_size) + dtb_offset = page_size * ( + num_header_pages + num_kernel_pages + num_ramdisk_pages + num_second_pages + + num_recovery_dtbo_pages + ) + + image_info_list.append((dtb_offset, dtb_size, 'dtb')) for image_info in image_info_list: extract_image(image_info[0], image_info[1], args.boot_img, @@ -113,7 +130,7 @@ def parse_cmdline(): """parse command line arguments""" parser = ArgumentParser( description='Unpacks boot.img/recovery.img, extracts the kernel,' - 'ramdisk, second bootloader and recovery dtbo') + 'ramdisk, second bootloader, recovery dtbo and dtb') parser.add_argument( '--boot_img', help='path to boot image',