Files
opencode.siil.arti.ee 8dc2c663d4 G90 (RK3128) handheld: dump analysis, patched EmuELEC, upstream notes
- hardware decoded from the stock DTB (panel, keys, battery, gamepad, WiFi,
  power, storage layout) and the 16 MiB boot area
- EmuELEC 4.7 / Linux 5.10.160 inventory, partition map, extlinux boot chain
- patched SYSTEM with dropbear SSH, userspace WireGuard, jq, dtach, iperf3,
  tcpdump; build script, units, authorized keys, install/rollback docs
- EmuELEC OTA tar format and the initramfs apply logic, incl. the FAT32
  EEROMS:/.update bind mount
- upstream EmuELEC vs rk3128-cfw vs mainline 6.6 assessment and driver gaps
- SV6160/RK915 WiFi: vendor module metadata, firmware hashes, clean-room
  mainline driver requirements, Codeberg DNS workaround
- tools: dump/partition extractors, FDT dumper, Kagi share exporter
2026-11-18 08:44:38 +00:00

102 lines
3.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""Minimal Flattened Device Tree (DTB) dumper - no dtc needed.
Usage:
fdt_dump.py file.dtb # tree with properties
fdt_dump.py file.dtb -p pattern # only nodes/props matching pattern
fdt_dump.py file.dtb -l # node names only
"""
import struct
import sys
FDT_MAGIC = 0xD00DFEED
FDT_BEGIN_NODE, FDT_END_NODE, FDT_PROP, FDT_NOP, FDT_END = 1, 2, 3, 4, 9
def load(path):
data = open(path, "rb").read()
magic, totalsize, off_struct, off_strings, off_rsv, version, lastcp, cpu, size_str, size_struct = \
struct.unpack(">10I", data[:40])
if magic != FDT_MAGIC:
raise SystemExit(f"{path}: not a DTB (magic {magic:#x})")
return data, off_struct, off_strings, size_struct, version
def cstr(buf, off):
end = buf.index(b"\0", off)
return buf[off:end].decode("utf-8", "replace")
def parse(data, off, off_strings, size_struct):
struct_blk = data[off:off + size_struct]
strings_blk = data[off_strings:]
pos = 0
path = []
while pos < len(struct_blk):
tok = struct.unpack(">I", struct_blk[pos:pos + 4])[0]
pos += 4
if tok == FDT_BEGIN_NODE:
name = cstr(struct_blk, pos)
pos += (len(name) + 1 + 3) & ~3
path.append(name)
yield ("node", list(path))
elif tok == FDT_END_NODE:
if path:
path.pop()
elif tok == FDT_PROP:
length, nameoff = struct.unpack(">II", struct_blk[pos:pos + 8])
pos += 8
val = struct_blk[pos:pos + length]
pos += (length + 3) & ~3
yield ("prop", list(path), cstr(strings_blk, nameoff), val)
elif tok == FDT_END:
break
def fmt(val):
if len(val) == 0:
return ""
if len(val) == 4:
return f"<{struct.unpack('>I', val)[0]:#x}>"
if len(val) % 4 == 0:
ints = struct.unpack(f">{len(val)//4}I", val)
printable = all(32 <= b < 127 or b == 0 for b in val) and val[-1] == 0
if printable:
return '"' + val.decode("ascii").replace("\0", '", "').strip('"') + '"'
return "<" + " ".join(f"{i:#x}" for i in ints) + ">"
if all(32 <= b < 127 or b == 0 for b in val):
return '"' + val.decode().replace("\0", '", "').strip('"') + '"'
return "<" + val.hex() + ">"
def main():
args = sys.argv[1:]
if not args:
raise SystemExit(__doc__)
path = args[0]
pattern = None
names_only = "-l" in args
if "-p" in args:
pattern = args[args.index("-p") + 1].lower()
data, off, off_strings, size_struct, version = load(path)
print(f"# {path} (dtb version {version})")
for item in parse(data, off, off_strings, size_struct):
if item[0] == "node":
if names_only:
print("/" + "/".join(item[1]))
else:
print(" " * (len(item[1]) - 1) + (item[1][-1] or "/") + " {")
else:
_, p, name, val = item
text = fmt(val)
line = " " * (len(p) - 1) + f" {name} = {text}"
if pattern and pattern not in line.lower() and pattern not in "/".join(p).lower():
continue
print(line)
if __name__ == "__main__":
main()