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,37 +142,23 @@ def generate_deviceinfo_fastboot_content(bootimg: Bootimg | None = None) -> str:
content = f"""\ content = f"""\
deviceinfo_kernel_cmdline="{bootimg["cmdline"]}" deviceinfo_kernel_cmdline="{bootimg["cmdline"]}"
deviceinfo_generate_bootimg="true" deviceinfo_generate_bootimg="true"
deviceinfo_bootimg_qcdt="{bootimg["qcdt"]}"
deviceinfo_bootimg_dtb_second="{bootimg["dtb_second"]}"
deviceinfo_flash_pagesize="{bootimg["pagesize"]}" 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"]:
content += f"""\ v = bootimg[k] # type: ignore
deviceinfo_bootimg_qcdt_type="{bootimg["qcdt_type"]}" if v:
"""
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"]}"
"""
if bootimg["header_version"] == "2":
content += f"""\ content += f"""\
deviceinfo_append_dtb="false" deviceinfo_{k}="{v}"
deviceinfo_flash_offset_dtb="{bootimg["dtb_offset"]}"
""" """
if "base" in bootimg.keys(): if bootimg["header_version"] == "2":
content += f"""\
deviceinfo_append_dtb="false"
deviceinfo_flash_offset_dtb="{bootimg["dtb_offset"]}"
"""
if bootimg["base"]:
content += f"""\ content += f"""\
deviceinfo_flash_offset_base="{bootimg["base"]}" deviceinfo_flash_offset_base="{bootimg["base"]}"
deviceinfo_flash_offset_kernel="{bootimg["kernel_offset"]}" deviceinfo_flash_offset_kernel="{bootimg["kernel_offset"]}"

View file

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