pmb.parse.bootimg: Add preliminary support for header v2 (MR 2194)

This includes setting header_version="2" as well as dtb_offset
according to the input boot.img when header v2 is detected.

Also adds the following previously missed deviceinfo_attributes:

* "header_version"
* "bootimg_custom_args"

And fixes failing tests now that header_version is always parsed from
boot.img files.
This commit is contained in:
Jami Kettunen 2022-07-15 17:10:04 +03:00 committed by Clayton Craft
parent c36e4a43ac
commit 255e69be5e
No known key found for this signature in database
GPG Key ID: 4A4CED6D7EDF950A
4 changed files with 21 additions and 8 deletions

View File

@ -721,10 +721,13 @@ deviceinfo_attributes = [
"generate_legacy_uboot_initfs",
"kernel_cmdline",
"generate_bootimg",
"header_version",
"bootimg_qcdt",
"bootimg_mtk_mkimage",
"bootimg_dtb_second",
"bootimg_custom_args",
"flash_offset_base",
"flash_offset_dtb",
"flash_offset_kernel",
"flash_offset_ramdisk",
"flash_offset_second",

View File

@ -119,15 +119,15 @@ def bootimg(args, path):
working_dir=temp_path)
output = {}
header_version = None
header_version = 0
# Get base, offsets, pagesize, cmdline and qcdt info
# 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', ''))
output["header_version"] = str(header_version)
if header_version is not None and header_version >= 3:
output["header_version"] = str(header_version)
if header_version >= 3:
output["pagesize"] = "4096"
else:
with open(f"{bootimg_path}-base", 'r') as f:
@ -147,6 +147,11 @@ def bootimg(args, path):
with open(f"{bootimg_path}-pagesize", 'r') as f:
output["pagesize"] = f.read().replace('\n', '')
if header_version == 2:
with open(f"{bootimg_path}-dtb_offset", 'r') as f:
output["dtb_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
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 check_mtk_bootimg(bootimg_path)

View File

@ -43,7 +43,8 @@ def test_bootimg_invalid_file(args):
def test_bootimg_normal(args):
path = pmb_test.const.testdata + "/bootimg/normal-boot.img"
output = {"base": "0x80000000",
output = {"header_version": "0",
"base": "0x80000000",
"kernel_offset": "0x00008000",
"ramdisk_offset": "0x04000000",
"second_offset": "0x00f00000",
@ -73,7 +74,8 @@ def test_bootimg_qcdt(args):
def test_bootimg_mtk_mkimage(args):
path = pmb_test.const.testdata + "/bootimg/mtk_mkimage-boot.img"
output = {"base": "0x10000000",
output = {"header_version": "0",
"base": "0x10000000",
"kernel_offset": "0x00008000",
"ramdisk_offset": "0x01000000",
"second_offset": "0x00f00000",
@ -88,7 +90,8 @@ def test_bootimg_mtk_mkimage(args):
def test_bootimg_mtk_mkimage_recovery(args):
path = pmb_test.const.testdata + "/bootimg/mtk_mkimage-boot-recovery.img"
output = {"base": "0x80000000",
output = {"header_version": "0",
"base": "0x80000000",
"kernel_offset": "0x00008000",
"ramdisk_offset": "0x04000000",
"second_offset": "0x00f00000",
@ -103,7 +106,8 @@ def test_bootimg_mtk_mkimage_recovery(args):
def test_bootimg_dtb_second(args):
path = pmb_test.const.testdata + "/bootimg/dtb-second-boot.img"
output = {"base": "0x00000000",
output = {"header_version": "0",
"base": "0x00000000",
"kernel_offset": "0x00008000",
"ramdisk_offset": "0x02000000",
"second_offset": "0x00f00000",

View File

@ -91,7 +91,8 @@ def test_questions_bootimg(args, monkeypatch):
bootimg_path = pmb_test.const.testdata + "/bootimg/normal-boot.img"
fake_answers(monkeypatch, [bootimg_path])
output = {"base": "0x80000000",
output = {"header_version": "0",
"base": "0x80000000",
"kernel_offset": "0x00008000",
"ramdisk_offset": "0x04000000",
"second_offset": "0x00f00000",