bootimg_analyze: Add support for boot header version 3 (MR 2073)

This commit is contained in:
Anri Dellal 2021-06-19 18:50:27 +03:00 committed by Alexey Min
parent 9d22989a88
commit d764b0de58
No known key found for this signature in database
GPG Key ID: EBF5ECFFFEE34DED
4 changed files with 53 additions and 20 deletions

View File

@ -128,20 +128,31 @@ def generate_deviceinfo_fastboot_content(args, bootimg=None):
"second_offset": "",
"tags_offset": "",
"pagesize": "2048"}
return f"""\
content = f"""\
deviceinfo_kernel_cmdline="{bootimg["cmdline"]}"
deviceinfo_generate_bootimg="true"
deviceinfo_bootimg_qcdt="{bootimg["qcdt"]}"
deviceinfo_bootimg_mtk_mkimage="{bootimg["mtk_mkimage"]}"
deviceinfo_bootimg_dtb_second="{bootimg["dtb_second"]}"
deviceinfo_flash_pagesize="{bootimg["pagesize"]}"
"""
if "header_version" in bootimg.keys():
content += f"""\
deviceinfo_header_version="{bootimg["header_version"]}"
"""
else:
content += f"""\
deviceinfo_flash_offset_base="{bootimg["base"]}"
deviceinfo_flash_offset_kernel="{bootimg["kernel_offset"]}"
deviceinfo_flash_offset_ramdisk="{bootimg["ramdisk_offset"]}"
deviceinfo_flash_offset_second="{bootimg["second_offset"]}"
deviceinfo_flash_offset_tags="{bootimg["tags_offset"]}"
deviceinfo_flash_pagesize="{bootimg["pagesize"]}"
"""
return content
def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
chassis, has_keyboard, has_external_storage,

View File

@ -73,25 +73,34 @@ def bootimg(args, path):
working_dir=temp_path)
output = {}
header_version = None
# Get base, offsets, pagesize, cmdline and qcdt info
with open(bootimg_path + "-base", 'r') as f:
output["base"] = ("0x%08x" % int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-kernel_offset", 'r') as f:
output["kernel_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-ramdisk_offset", 'r') as f:
output["ramdisk_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-second_offset", 'r') as f:
output["second_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-tags_offset", 'r') as f:
output["tags_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-pagesize", 'r') as f:
output["pagesize"] = f.read().replace('\n', '')
with open(bootimg_path + "-cmdline", 'r') as f:
output["cmdline"] = f.read().replace('\n', '')
# This file does not exist for example for qcdt images
if os.path.isfile(f"{bootimg_path}-header_version"):
with open(f"{bootimg_path}-header_version", 'r') as f:
header_version = int(f.read().replace('\n', ''))
if header_version is not None and header_version >= 3:
output["header_version"] = str(header_version)
output["pagesize"] = "4096"
else:
with open(f"{bootimg_path}-base", 'r') as f:
output["base"] = ("0x%08x" % int(f.read().replace('\n', ''), 16))
with open(f"{bootimg_path}-kernel_offset", 'r') as f:
output["kernel_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(f"{bootimg_path}-ramdisk_offset", 'r') as f:
output["ramdisk_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(f"{bootimg_path}-second_offset", 'r') as f:
output["second_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(f"{bootimg_path}-tags_offset", 'r') as f:
output["tags_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(f"{bootimg_path}-pagesize", 'r') as f:
output["pagesize"] = f.read().replace('\n', '')
output["qcdt"] = ("true" if os.path.isfile(f"{bootimg_path}-dt") and
os.path.getsize(f"{bootimg_path}-dt") > 0 else "false")
output["mtk_mkimage"] = ("true" if has_mtk_header(f"{bootimg_path}-kernel",
@ -99,6 +108,8 @@ def bootimg(args, path):
output["dtb_second"] = ("true" if is_dtb(f"{bootimg_path}-second")
else "false")
with open(f"{bootimg_path}-cmdline", 'r') as f:
output["cmdline"] = f.read().replace('\n', '')
# Mediatek: Check that the ramdisk also has a known-good label
# We don't care about the return value, just whether it throws an exception
# or not.

View File

@ -99,3 +99,14 @@ def test_bootimg_dtb_second(args):
"mtk_mkimage": "false",
"dtb_second": "true"}
assert pmb.parse.bootimg(args, path) == output
def test_bootimg_v3(args):
path = pmb_test.const.testdata + "/bootimg/boot-header-v3.img"
output = {"header_version": "3",
"pagesize": "4096",
"cmdline": "twrpfastboot=1",
"qcdt": "false",
"mtk_mkimage": "false",
"dtb_second": "false"}
assert pmb.parse.bootimg(args, path) == output

BIN
test/testdata/bootimg/boot-header-v3.img vendored Normal file

Binary file not shown.