diff --git a/pmb/aportgen/device.py b/pmb/aportgen/device.py index 658e139b..9fb99d54 100644 --- a/pmb/aportgen/device.py +++ b/pmb/aportgen/device.py @@ -106,6 +106,7 @@ def generate_deviceinfo_fastboot_content(args, bootimg=None): if bootimg is None: bootimg = {"cmdline": "", "qcdt": "false", + "dtb_second": "false", "base": "", "kernel_offset": "", "ramdisk_offset": "", @@ -116,6 +117,7 @@ def generate_deviceinfo_fastboot_content(args, bootimg=None): deviceinfo_kernel_cmdline=\"""" + bootimg["cmdline"] + """\" deviceinfo_generate_bootimg="true" deviceinfo_bootimg_qcdt=\"""" + bootimg["qcdt"] + """\" + deviceinfo_bootimg_dtb_second=\"""" + bootimg["dtb_second"] + """\" deviceinfo_flash_offset_base=\"""" + bootimg["base"] + """\" deviceinfo_flash_offset_kernel=\"""" + bootimg["kernel_offset"] + """\" deviceinfo_flash_offset_ramdisk=\"""" + bootimg["ramdisk_offset"] + """\" diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 7847885b..64003998 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -267,6 +267,7 @@ deviceinfo_attributes = [ "kernel_cmdline", "generate_bootimg", "bootimg_qcdt", + "bootimg_dtb_second", "flash_offset_base", "flash_offset_kernel", "flash_offset_ramdisk", diff --git a/pmb/parse/bootimg.py b/pmb/parse/bootimg.py index 2eee1de0..067a2189 100644 --- a/pmb/parse/bootimg.py +++ b/pmb/parse/bootimg.py @@ -21,6 +21,14 @@ import logging import pmb +def is_dtb(path): + if not os.path.isfile(path): + return False + with open(path, 'rb') as f: + # Check FDT magic identifier (0xd00dfeed) + return f.read(4) == b'\xd0\x0d\xfe\xed' + + def bootimg(args, path): if not os.path.exists(path): raise RuntimeError("Could not find file '" + path + "'") @@ -77,6 +85,7 @@ def bootimg(args, path): output["cmdline"] = f.read().replace('\n', '') output["qcdt"] = ("true" if os.path.isfile(bootimg_path + "-dt") and os.path.getsize(bootimg_path + "-dt") > 0 else "false") + output["dtb_second"] = ("true" if is_dtb(bootimg_path + "-second") else "false") # Cleanup pmb.chroot.root(args, ["rm", "-r", temp_path]) diff --git a/test/test_bootimg.py b/test/test_bootimg.py index 0ad38936..7c51587f 100644 --- a/test/test_bootimg.py +++ b/test/test_bootimg.py @@ -68,7 +68,8 @@ def test_bootimg_normal(args): "tags_offset": "0x0e000000", "pagesize": "2048", "cmdline": "bootopt=64S3,32S1,32S1", - "qcdt": "false"} + "qcdt": "false", + "dtb_second": "false"} assert pmb.parse.bootimg(args, path) == output @@ -81,5 +82,20 @@ def test_bootimg_qcdt(args): "tags_offset": "0x0e000000", "pagesize": "2048", "cmdline": "bootopt=64S3,32S1,32S1", - "qcdt": "true"} + "qcdt": "true", + "dtb_second": "false"} + assert pmb.parse.bootimg(args, path) == output + + +def test_bootimg_dtb_second(args): + path = pmb_src + "/test/testdata/bootimg/dtb-second-boot.img" + output = {"base": "0x00000000", + "kernel_offset": "0x00008000", + "ramdisk_offset": "0x02000000", + "second_offset": "0x00f00000", + "tags_offset": "0x00000100", + "pagesize": "2048", + "cmdline": "bootopt=64S3,32S1,32S1", + "qcdt": "false", + "dtb_second": "true"} assert pmb.parse.bootimg(args, path) == output diff --git a/test/test_questions.py b/test/test_questions.py index a8bb068f..e5660425 100644 --- a/test/test_questions.py +++ b/test/test_questions.py @@ -113,7 +113,8 @@ def test_questions_bootimg(args, monkeypatch): "tags_offset": "0x0e000000", "pagesize": "2048", "cmdline": "bootopt=64S3,32S1,32S1", - "qcdt": "false"} + "qcdt": "false", + "dtb_second": "false"} assert func(args) == output diff --git a/test/testdata/bootimg/dtb-second-boot.img b/test/testdata/bootimg/dtb-second-boot.img new file mode 100644 index 00000000..fcc76849 Binary files /dev/null and b/test/testdata/bootimg/dtb-second-boot.img differ