Detect if DTB is placed in second area of Android boot image (!1828)

postmarketOS/pmaports!700 adds a new "deviceinfo_bootimg_dtb_second"
option that places the DTB in the "second" area of the Android boot
image.

Attempt to detect this automatically by checking the extracted
second binary for the FDT magic (0xd00dfeed).
This commit is contained in:
lambdadroid 2019-10-25 17:07:08 +02:00
parent cf9d648ac9
commit 67b080b158
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
6 changed files with 32 additions and 3 deletions

View File

@ -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"] + """\"

View File

@ -267,6 +267,7 @@ deviceinfo_attributes = [
"kernel_cmdline",
"generate_bootimg",
"bootimg_qcdt",
"bootimg_dtb_second",
"flash_offset_base",
"flash_offset_kernel",
"flash_offset_ramdisk",

View File

@ -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])

View File

@ -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

View File

@ -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

Binary file not shown.