Merge "Populate recovery DTBO offset correctly" into pi-dev
This commit is contained in:
commit
74e8061fd0
|
@ -45,6 +45,22 @@ def pad_file(f, padding):
|
||||||
f.write(pack(str(pad) + 'x'))
|
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):
|
def write_header(args):
|
||||||
BOOT_MAGIC = 'ANDROID!'.encode()
|
BOOT_MAGIC = 'ANDROID!'.encode()
|
||||||
args.output.write(pack('8s', BOOT_MAGIC))
|
args.output.write(pack('8s', BOOT_MAGIC))
|
||||||
|
@ -77,7 +93,10 @@ def write_header(args):
|
||||||
|
|
||||||
if args.header_version > 0:
|
if args.header_version > 0:
|
||||||
args.output.write(pack('I', filesize(args.recovery_dtbo))) # size in bytes
|
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
|
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
|
args.output.write(pack('I', args.output.tell() + 4)) # size of boot header
|
||||||
|
|
||||||
pad_file(args.output, args.pagesize)
|
pad_file(args.output, args.pagesize)
|
||||||
|
@ -150,8 +169,6 @@ def parse_cmdline():
|
||||||
parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000)
|
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,
|
parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int,
|
||||||
default=0x00f00000)
|
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,
|
parser.add_argument('--os_version', help='operating system version', type=parse_os_version,
|
||||||
default=0)
|
default=0)
|
||||||
parser.add_argument('--os_patch_level', help='operating system patch level',
|
parser.add_argument('--os_patch_level', help='operating system patch level',
|
||||||
|
|
|
@ -76,8 +76,8 @@ def unpack_bootimage(args):
|
||||||
if version > 0:
|
if version > 0:
|
||||||
recovery_dtbo_size = unpack('I', args.boot_img.read(1 * 4))[0]
|
recovery_dtbo_size = unpack('I', args.boot_img.read(1 * 4))[0]
|
||||||
print('recovery dtbo size: %s' % recovery_dtbo_size)
|
print('recovery dtbo size: %s' % recovery_dtbo_size)
|
||||||
recovery_dtbo_address = unpack('Q', args.boot_img.read(8))[0]
|
recovery_dtbo_offset = unpack('Q', args.boot_img.read(8))[0]
|
||||||
print('recovery dtbo load address: %s' % recovery_dtbo_address)
|
print('recovery dtbo offset: %s' % recovery_dtbo_offset)
|
||||||
boot_header_size = unpack('I', args.boot_img.read(4))[0]
|
boot_header_size = unpack('I', args.boot_img.read(4))[0]
|
||||||
print('boot header size: %s' % boot_header_size)
|
print('boot header size: %s' % boot_header_size)
|
||||||
else:
|
else:
|
||||||
|
@ -95,16 +95,13 @@ def unpack_bootimage(args):
|
||||||
) # header + kernel
|
) # header + kernel
|
||||||
image_info_list.append((ramdisk_offset, ramdisk_size, 'ramdisk'))
|
image_info_list.append((ramdisk_offset, ramdisk_size, 'ramdisk'))
|
||||||
|
|
||||||
num_second_pages = get_number_of_pages(second_size, page_size)
|
|
||||||
second_offset = page_size * (
|
second_offset = page_size * (
|
||||||
num_header_pages + num_kernel_pages + num_ramdisk_pages
|
num_header_pages + num_kernel_pages + num_ramdisk_pages
|
||||||
) # header + kernel + ramdisk
|
) # header + kernel + ramdisk
|
||||||
image_info_list.append((second_offset, second_size, 'second'))
|
image_info_list.append((second_offset, second_size, 'second'))
|
||||||
|
|
||||||
if recovery_dtbo_size > 0:
|
if recovery_dtbo_size > 0:
|
||||||
dtbo_offset = page_size * (num_header_pages + num_kernel_pages +
|
image_info_list.append((recovery_dtbo_offset, recovery_dtbo_size,
|
||||||
num_ramdisk_pages + num_second_pages)
|
|
||||||
image_info_list.append((dtbo_offset, recovery_dtbo_size,
|
|
||||||
'recovery_dtbo'))
|
'recovery_dtbo'))
|
||||||
|
|
||||||
for image_info in image_info_list:
|
for image_info in image_info_list:
|
||||||
|
|
Loading…
Reference in New Issue