forked from Mirror/pmbootstrap
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:
parent
cf9d648ac9
commit
67b080b158
6 changed files with 32 additions and 3 deletions
|
@ -106,6 +106,7 @@ def generate_deviceinfo_fastboot_content(args, bootimg=None):
|
||||||
if bootimg is None:
|
if bootimg is None:
|
||||||
bootimg = {"cmdline": "",
|
bootimg = {"cmdline": "",
|
||||||
"qcdt": "false",
|
"qcdt": "false",
|
||||||
|
"dtb_second": "false",
|
||||||
"base": "",
|
"base": "",
|
||||||
"kernel_offset": "",
|
"kernel_offset": "",
|
||||||
"ramdisk_offset": "",
|
"ramdisk_offset": "",
|
||||||
|
@ -116,6 +117,7 @@ def generate_deviceinfo_fastboot_content(args, bootimg=None):
|
||||||
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_qcdt=\"""" + bootimg["qcdt"] + """\"
|
||||||
|
deviceinfo_bootimg_dtb_second=\"""" + bootimg["dtb_second"] + """\"
|
||||||
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"] + """\"
|
||||||
deviceinfo_flash_offset_ramdisk=\"""" + bootimg["ramdisk_offset"] + """\"
|
deviceinfo_flash_offset_ramdisk=\"""" + bootimg["ramdisk_offset"] + """\"
|
||||||
|
|
|
@ -267,6 +267,7 @@ deviceinfo_attributes = [
|
||||||
"kernel_cmdline",
|
"kernel_cmdline",
|
||||||
"generate_bootimg",
|
"generate_bootimg",
|
||||||
"bootimg_qcdt",
|
"bootimg_qcdt",
|
||||||
|
"bootimg_dtb_second",
|
||||||
"flash_offset_base",
|
"flash_offset_base",
|
||||||
"flash_offset_kernel",
|
"flash_offset_kernel",
|
||||||
"flash_offset_ramdisk",
|
"flash_offset_ramdisk",
|
||||||
|
|
|
@ -21,6 +21,14 @@ import logging
|
||||||
import pmb
|
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):
|
def bootimg(args, path):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise RuntimeError("Could not find file '" + path + "'")
|
raise RuntimeError("Could not find file '" + path + "'")
|
||||||
|
@ -77,6 +85,7 @@ def bootimg(args, path):
|
||||||
output["cmdline"] = f.read().replace('\n', '')
|
output["cmdline"] = f.read().replace('\n', '')
|
||||||
output["qcdt"] = ("true" if os.path.isfile(bootimg_path + "-dt") and
|
output["qcdt"] = ("true" if os.path.isfile(bootimg_path + "-dt") and
|
||||||
os.path.getsize(bootimg_path + "-dt") > 0 else "false")
|
os.path.getsize(bootimg_path + "-dt") > 0 else "false")
|
||||||
|
output["dtb_second"] = ("true" if is_dtb(bootimg_path + "-second") else "false")
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
pmb.chroot.root(args, ["rm", "-r", temp_path])
|
pmb.chroot.root(args, ["rm", "-r", temp_path])
|
||||||
|
|
|
@ -68,7 +68,8 @@ def test_bootimg_normal(args):
|
||||||
"tags_offset": "0x0e000000",
|
"tags_offset": "0x0e000000",
|
||||||
"pagesize": "2048",
|
"pagesize": "2048",
|
||||||
"cmdline": "bootopt=64S3,32S1,32S1",
|
"cmdline": "bootopt=64S3,32S1,32S1",
|
||||||
"qcdt": "false"}
|
"qcdt": "false",
|
||||||
|
"dtb_second": "false"}
|
||||||
assert pmb.parse.bootimg(args, path) == output
|
assert pmb.parse.bootimg(args, path) == output
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,5 +82,20 @@ def test_bootimg_qcdt(args):
|
||||||
"tags_offset": "0x0e000000",
|
"tags_offset": "0x0e000000",
|
||||||
"pagesize": "2048",
|
"pagesize": "2048",
|
||||||
"cmdline": "bootopt=64S3,32S1,32S1",
|
"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
|
assert pmb.parse.bootimg(args, path) == output
|
||||||
|
|
|
@ -113,7 +113,8 @@ def test_questions_bootimg(args, monkeypatch):
|
||||||
"tags_offset": "0x0e000000",
|
"tags_offset": "0x0e000000",
|
||||||
"pagesize": "2048",
|
"pagesize": "2048",
|
||||||
"cmdline": "bootopt=64S3,32S1,32S1",
|
"cmdline": "bootopt=64S3,32S1,32S1",
|
||||||
"qcdt": "false"}
|
"qcdt": "false",
|
||||||
|
"dtb_second": "false"}
|
||||||
assert func(args) == output
|
assert func(args) == output
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
test/testdata/bootimg/dtb-second-boot.img
vendored
Normal file
BIN
test/testdata/bootimg/dtb-second-boot.img
vendored
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue