Merge "Populate recovery DTBO offset correctly" into pi-dev

This commit is contained in:
TreeHugger Robot 2018-06-14 17:29:54 +00:00 committed by Android (Google) Code Review
commit 74e8061fd0
2 changed files with 25 additions and 11 deletions

View file

@ -45,6 +45,22 @@ def pad_file(f, padding):
f.write(pack(str(pad) + 'x'))
def get_number_of_pages(image_size, page_size):
"""calculates the number of pages required for the image"""
return (image_size + page_size - 1) / page_size
def get_recovery_dtbo_offset(args):
"""calculates the offset of recovery_dtbo image in the boot image"""
num_header_pages = 1 # header occupies a page
num_kernel_pages = get_number_of_pages(filesize(args.kernel), args.pagesize)
num_ramdisk_pages = get_number_of_pages(filesize(args.ramdisk), args.pagesize)
num_second_pages = get_number_of_pages(filesize(args.second), args.pagesize)
dtbo_offset = args.pagesize * (num_header_pages + num_kernel_pages +
num_ramdisk_pages + num_second_pages)
return dtbo_offset
def write_header(args):
BOOT_MAGIC = 'ANDROID!'.encode()
args.output.write(pack('8s', BOOT_MAGIC))
@ -76,9 +92,12 @@ def write_header(args):
args.output.write(pack('1024s', args.cmdline[512:].encode()))
if args.header_version > 0:
args.output.write(pack('I', filesize(args.recovery_dtbo))) # size in bytes
args.output.write(pack('Q', args.base + args.recovery_dtbo_offset)) # physical load addr
args.output.write(pack('I', args.output.tell() + 4)) # size of boot header
args.output.write(pack('I', filesize(args.recovery_dtbo))) # size in bytes
if args.recovery_dtbo:
args.output.write(pack('Q', get_recovery_dtbo_offset(args))) # recovery dtbo offset
else:
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
pad_file(args.output, args.pagesize)
return img_id
@ -150,8 +169,6 @@ 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('--recovery_dtbo_offset', help='recovery dtbo offset', type=parse_int,
default=0x0f000000)
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',

View file

@ -76,8 +76,8 @@ def unpack_bootimage(args):
if version > 0:
recovery_dtbo_size = unpack('I', args.boot_img.read(1 * 4))[0]
print('recovery dtbo size: %s' % recovery_dtbo_size)
recovery_dtbo_address = unpack('Q', args.boot_img.read(8))[0]
print('recovery dtbo load address: %s' % recovery_dtbo_address)
recovery_dtbo_offset = unpack('Q', args.boot_img.read(8))[0]
print('recovery dtbo offset: %s' % recovery_dtbo_offset)
boot_header_size = unpack('I', args.boot_img.read(4))[0]
print('boot header size: %s' % boot_header_size)
else:
@ -95,16 +95,13 @@ def unpack_bootimage(args):
) # header + kernel
image_info_list.append((ramdisk_offset, ramdisk_size, 'ramdisk'))
num_second_pages = get_number_of_pages(second_size, page_size)
second_offset = page_size * (
num_header_pages + num_kernel_pages + num_ramdisk_pages
) # header + kernel + ramdisk
image_info_list.append((second_offset, second_size, 'second'))
if recovery_dtbo_size > 0:
dtbo_offset = page_size * (num_header_pages + num_kernel_pages +
num_ramdisk_pages + num_second_pages)
image_info_list.append((dtbo_offset, recovery_dtbo_size,
image_info_list.append((recovery_dtbo_offset, recovery_dtbo_size,
'recovery_dtbo'))
for image_info in image_info_list: