summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHridya Valsaraju2018-05-31 14:39:58 -0500
committerHridya Valsaraju2018-06-04 17:26:42 -0500
commit26e01bbdc5cb2dcad64d73ec836447b8ded4fc6c (patch)
tree60b486d3a7de8f0b4da5214efb33687fbfe80c76 /mkbootimg
parentd0ab4e3701dcec866cb05f4d2a122fbbcabf61cc (diff)
downloadplatform-system-core-26e01bbdc5cb2dcad64d73ec836447b8ded4fc6c.tar.gz
platform-system-core-26e01bbdc5cb2dcad64d73ec836447b8ded4fc6c.tar.xz
platform-system-core-26e01bbdc5cb2dcad64d73ec836447b8ded4fc6c.zip
Populate recovery DTBO offset correctly
Also, remove recovery_dtbo_offset argument for mkbootimg as this is calculated based on sizes of kernel, ramdisk and second binaries. Also, modify unpack_bootimg to use the recovery_dtbo_offset field to extract recovery_dtbo. Test: make recoveryimage showcommands -j32 unpack_bootimg --boot_img $OUT/recovery.img diff recovery_dtbo dtbo.img Change-Id: I588ccc8b739c169b6f78c17ffe554c5562397d98
Diffstat (limited to 'mkbootimg')
-rwxr-xr-xmkbootimg/mkbootimg27
-rwxr-xr-xmkbootimg/unpack_bootimg9
2 files changed, 25 insertions, 11 deletions
diff --git a/mkbootimg/mkbootimg b/mkbootimg/mkbootimg
index ac20d0503..fda9af0d2 100755
--- a/mkbootimg/mkbootimg
+++ b/mkbootimg/mkbootimg
@@ -45,6 +45,22 @@ def pad_file(f, padding):
45 f.write(pack(str(pad) + 'x')) 45 f.write(pack(str(pad) + 'x'))
46 46
47 47
48def get_number_of_pages(image_size, page_size):
49 """calculates the number of pages required for the image"""
50 return (image_size + page_size - 1) / page_size
51
52
53def get_recovery_dtbo_offset(args):
54 """calculates the offset of recovery_dtbo image in the boot image"""
55 num_header_pages = 1 # header occupies a page
56 num_kernel_pages = get_number_of_pages(filesize(args.kernel), args.pagesize)
57 num_ramdisk_pages = get_number_of_pages(filesize(args.ramdisk), args.pagesize)
58 num_second_pages = get_number_of_pages(filesize(args.second), args.pagesize)
59 dtbo_offset = args.pagesize * (num_header_pages + num_kernel_pages +
60 num_ramdisk_pages + num_second_pages)
61 return dtbo_offset
62
63
48def write_header(args): 64def write_header(args):
49 BOOT_MAGIC = 'ANDROID!'.encode() 65 BOOT_MAGIC = 'ANDROID!'.encode()
50 args.output.write(pack('8s', BOOT_MAGIC)) 66 args.output.write(pack('8s', BOOT_MAGIC))
@@ -76,9 +92,12 @@ def write_header(args):
76 args.output.write(pack('1024s', args.cmdline[512:].encode())) 92 args.output.write(pack('1024s', args.cmdline[512:].encode()))
77 93
78 if args.header_version > 0: 94 if args.header_version > 0:
79 args.output.write(pack('I', filesize(args.recovery_dtbo))) # size in bytes 95 args.output.write(pack('I', filesize(args.recovery_dtbo))) # size in bytes
80 args.output.write(pack('Q', args.base + args.recovery_dtbo_offset)) # physical load addr 96 if args.recovery_dtbo:
81 args.output.write(pack('I', args.output.tell() + 4)) # size of boot header 97 args.output.write(pack('Q', get_recovery_dtbo_offset(args))) # recovery dtbo offset
98 else:
99 args.output.write(pack('Q', 0)) # Will be set to 0 for devices without a recovery dtbo
100 args.output.write(pack('I', args.output.tell() + 4)) # size of boot header
82 101
83 pad_file(args.output, args.pagesize) 102 pad_file(args.output, args.pagesize)
84 return img_id 103 return img_id
@@ -150,8 +169,6 @@ def parse_cmdline():
150 parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000) 169 parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000)
151 parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int, 170 parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int,
152 default=0x00f00000) 171 default=0x00f00000)
153 parser.add_argument('--recovery_dtbo_offset', help='recovery dtbo offset', type=parse_int,
154 default=0x0f000000)
155 parser.add_argument('--os_version', help='operating system version', type=parse_os_version, 172 parser.add_argument('--os_version', help='operating system version', type=parse_os_version,
156 default=0) 173 default=0)
157 parser.add_argument('--os_patch_level', help='operating system patch level', 174 parser.add_argument('--os_patch_level', help='operating system patch level',
diff --git a/mkbootimg/unpack_bootimg b/mkbootimg/unpack_bootimg
index 8e42ec029..c37acd5ac 100755
--- a/mkbootimg/unpack_bootimg
+++ b/mkbootimg/unpack_bootimg
@@ -76,8 +76,8 @@ def unpack_bootimage(args):
76 if version > 0: 76 if version > 0:
77 recovery_dtbo_size = unpack('I', args.boot_img.read(1 * 4))[0] 77 recovery_dtbo_size = unpack('I', args.boot_img.read(1 * 4))[0]
78 print('recovery dtbo size: %s' % recovery_dtbo_size) 78 print('recovery dtbo size: %s' % recovery_dtbo_size)
79 recovery_dtbo_address = unpack('Q', args.boot_img.read(8))[0] 79 recovery_dtbo_offset = unpack('Q', args.boot_img.read(8))[0]
80 print('recovery dtbo load address: %s' % recovery_dtbo_address) 80 print('recovery dtbo offset: %s' % recovery_dtbo_offset)
81 boot_header_size = unpack('I', args.boot_img.read(4))[0] 81 boot_header_size = unpack('I', args.boot_img.read(4))[0]
82 print('boot header size: %s' % boot_header_size) 82 print('boot header size: %s' % boot_header_size)
83 else: 83 else:
@@ -95,16 +95,13 @@ def unpack_bootimage(args):
95 ) # header + kernel 95 ) # header + kernel
96 image_info_list.append((ramdisk_offset, ramdisk_size, 'ramdisk')) 96 image_info_list.append((ramdisk_offset, ramdisk_size, 'ramdisk'))
97 97
98 num_second_pages = get_number_of_pages(second_size, page_size)
99 second_offset = page_size * ( 98 second_offset = page_size * (
100 num_header_pages + num_kernel_pages + num_ramdisk_pages 99 num_header_pages + num_kernel_pages + num_ramdisk_pages
101 ) # header + kernel + ramdisk 100 ) # header + kernel + ramdisk
102 image_info_list.append((second_offset, second_size, 'second')) 101 image_info_list.append((second_offset, second_size, 'second'))
103 102
104 if recovery_dtbo_size > 0: 103 if recovery_dtbo_size > 0:
105 dtbo_offset = page_size * (num_header_pages + num_kernel_pages + 104 image_info_list.append((recovery_dtbo_offset, recovery_dtbo_size,
106 num_ramdisk_pages + num_second_pages)
107 image_info_list.append((dtbo_offset, recovery_dtbo_size,
108 'recovery_dtbo')) 105 'recovery_dtbo'))
109 106
110 for image_info in image_info_list: 107 for image_info in image_info_list: