parse: bootimg: make it work again (MR 2477)

Commit 826bb4f2dd (pmb: Properly type Bootimg (MR 2464)) broke the
bootimg_analyze command since some assumptions in whether the bootimg
dictionary had empty keys or non-existent keys were changed without
their usage being updated.

Fix this and apply a trivial cleanup to aportgen.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-11-04 09:49:47 +01:00
parent 4ecd45749d
commit 953f84a79a
No known key found for this signature in database
GPG key ID: 0583312B195F64B6
2 changed files with 17 additions and 31 deletions

View file

@ -142,28 +142,14 @@ def generate_deviceinfo_fastboot_content(bootimg: Bootimg | None = None) -> str:
content = f"""\
deviceinfo_kernel_cmdline="{bootimg["cmdline"]}"
deviceinfo_generate_bootimg="true"
deviceinfo_bootimg_qcdt="{bootimg["qcdt"]}"
deviceinfo_bootimg_dtb_second="{bootimg["dtb_second"]}"
deviceinfo_flash_pagesize="{bootimg["pagesize"]}"
"""
if "qcdt_type" in bootimg.keys():
for k in ["qcdt_type", "dtb_second", "mtk_label_kernel", "mtk_label_ramdisk", "header_version"]:
v = bootimg[k] # type: ignore
if v:
content += f"""\
deviceinfo_bootimg_qcdt_type="{bootimg["qcdt_type"]}"
"""
if "mtk_label_kernel" in bootimg.keys():
content += f"""\
deviceinfo_mtk_label_kernel="{bootimg["mtk_label_kernel"]}"
"""
if "mtk_label_ramdisk" in bootimg.keys():
content += f"""\
deviceinfo_mtk_label_ramdisk="{bootimg["mtk_label_ramdisk"]}"
"""
if "header_version" in bootimg.keys():
content += f"""\
deviceinfo_header_version="{bootimg["header_version"]}"
deviceinfo_{k}="{v}"
"""
if bootimg["header_version"] == "2":
@ -172,7 +158,7 @@ def generate_deviceinfo_fastboot_content(bootimg: Bootimg | None = None) -> str:
deviceinfo_flash_offset_dtb="{bootimg["dtb_offset"]}"
"""
if "base" in bootimg.keys():
if bootimg["base"]:
content += f"""\
deviceinfo_flash_offset_base="{bootimg["base"]}"
deviceinfo_flash_offset_kernel="{bootimg["kernel_offset"]}"

View file

@ -171,7 +171,7 @@ def bootimg(path: Path) -> Bootimg:
if value is not None
}
)
output["dtb_second"] = "true" if is_dtb(f"{bootimg_path}-second") else "false"
output["dtb_second"] = "true" if is_dtb(f"{bootimg_path}-second") else ""
with open(f"{bootimg_path}-cmdline") as f:
output["cmdline"] = trim_input(f)
@ -185,11 +185,11 @@ def bootimg(path: Path) -> Bootimg:
qcdt_type=output.get("qcdt_type"),
dtb_offset=output.get("dtb_offset"),
dtb_second=output["dtb_second"],
base=output["base"],
kernel_offset=output["kernel_offset"],
ramdisk_offset=output["ramdisk_offset"],
second_offset=output["second_offset"],
tags_offset=output["tags_offset"],
base=output.get("base", ""),
kernel_offset=output.get("kernel_offset", ""),
ramdisk_offset=output.get("ramdisk_offset", ""),
second_offset=output.get("second_offset", ""),
tags_offset=output.get("tags_offset", ""),
pagesize=output["pagesize"],
header_version=output.get("header_version"),
mtk_label_kernel=output.get("mtk_label_kernel", ""),