From 953f84a79a511e6c6968b86cd2950dad6fcbbc24 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Mon, 4 Nov 2024 09:49:47 +0100 Subject: [PATCH] parse: bootimg: make it work again (MR 2477) Commit 826bb4f2ddaa (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 --- pmb/aportgen/device.py | 36 +++++++++++------------------------- pmb/parse/bootimg.py | 12 ++++++------ 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/pmb/aportgen/device.py b/pmb/aportgen/device.py index 197abb0c..af75e256 100644 --- a/pmb/aportgen/device.py +++ b/pmb/aportgen/device.py @@ -142,37 +142,23 @@ 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(): - 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"]}" - """ - - if bootimg["header_version"] == "2": + 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_append_dtb="false" - deviceinfo_flash_offset_dtb="{bootimg["dtb_offset"]}" + deviceinfo_{k}="{v}" """ - 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"""\ deviceinfo_flash_offset_base="{bootimg["base"]}" deviceinfo_flash_offset_kernel="{bootimg["kernel_offset"]}" diff --git a/pmb/parse/bootimg.py b/pmb/parse/bootimg.py index 36c9e564..4021a4f1 100644 --- a/pmb/parse/bootimg.py +++ b/pmb/parse/bootimg.py @@ -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", ""),