From 259e6fba599a0a3a23f7b92ffd2886e30f610769 Mon Sep 17 00:00:00 2001 From: methanal <13671494-methanal@users.noreply.gitlab.com> Date: Sat, 16 Mar 2024 04:34:24 +0000 Subject: [PATCH] pmb.parse.bootimg: implement detection of QCDT types (MR 2276) Implement a function to verify the type of QCDT image by comparing the first four bytes of the file. This is represented in a deviceinfo variable, used by boot-deploy for dt.img generation. --- pmb/parse/bootimg.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pmb/parse/bootimg.py b/pmb/parse/bootimg.py index 02b0f234..9212f8bd 100644 --- a/pmb/parse/bootimg.py +++ b/pmb/parse/bootimg.py @@ -44,6 +44,27 @@ def get_mtk_label(path): return label +def get_qcdt_type(path): + """ Get the dt.img type by reading the first four bytes of the file. + :param path: to the qcdt image extracted from boot.img + :returns: * None: dt.img is of unknown type + * Type string (e.g. "qcom", "sprd", "exynos") """ + if not os.path.exists(path): + return None + + with open(path, 'rb') as f: + fourcc = f.read(4) + + if fourcc == b'QCDT': + return "qcom" + elif fourcc == b'SPRD': + return "sprd" + elif fourcc == b'DTBH': + return "exynos" + else: + return None + + def bootimg(args, path): if not os.path.exists(path): raise RuntimeError("Could not find file '" + path + "'") @@ -129,6 +150,9 @@ def bootimg(args, path): output["qcdt"] = ("true" if os.path.isfile(f"{bootimg_path}-dt") and os.path.getsize(f"{bootimg_path}-dt") > 0 else "false") + if get_qcdt_type(f"{bootimg_path}-dt") is not None: + output["qcdt_type"] = get_qcdt_type(f"{bootimg_path}-dt") + output["dtb_second"] = ("true" if is_dtb(f"{bootimg_path}-second") else "false")