* feat(firmware): inspect and extract Android DTBO partition images * fix(firmware): replace fixed DTBO limits with artifact_limits * fix(artifacts): keep saved effective_limits compatible without android_dtbo * fix(firmware): accept shared DTBO payloads and keep unknown facts unknown mkdtimg writes a repeated input file once and points every entry for it at the same payload (libufdt mkdtimg_core.c search_fdt_info), so an exactly shared range is valid; only partial overlaps are refused. A compressed entry's inner FDT magic was not examined, so fdt_magic_valid is now null rather than false. Bytes inside total_size that the header, entry table and payloads do not claim are reported with their range and make coverage unknown. dt_table_header and dt_table_entry field offsets are named after dt_table.h. * fix(firmware): charge every DTBO row against artifact_limits.expanded_bytes Shared payloads are valid, but each row is hashed and can be extracted separately, so 4096 rows naming one 16 MiB payload multiplied inventory and extraction work to 64 GiB. Admit the declared bytes of every row against the shared aggregate expansion allowance before reading any payload, as PCK aliases do. * test(firmware): throw the parser's typed error in DTBO success cases Success cases asserted ok and returned, so a parse failure showed only a boolean mismatch. They now throw the typed ParseFailureError, as the testing guide requires. * test(firmware): drop a duplicated result guard --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
5.6 KiB
Android DTBO partition images
inspect-artifact and extract-artifact recognize Android device tree
table overlay (DTBO) partition images starting with the big-endian
dt_table_header magic 0xd7b7ab1e regardless of filename. The reader parses
static container headers and dt_table_entry records without decompressing,
overlaying, or executing any binary code.
Header and entry table layout
The container begins with a big-endian 32-byte dt_table_header:
| Header field | Purpose |
|---|---|
magic |
Must be 0xd7b7ab1e |
total_size |
Declared container byte extent (>= header_size, <= file size) |
header_size |
Must be at least 32 bytes (bounded by total_size and dt_entries_offset; only 32 header bytes are read) |
dt_entry_size |
Must be at least 32 bytes when entries exist |
dt_entry_count |
Entry table row count |
dt_entries_offset |
Table start (>= header_size, fits within total_size) |
page_size |
Flash page alignment declared by the builder |
version |
Table revision (0 or 1) |
Each dt_table_entry row yields an entry named dtbo-<index>.dtbo unless
dt_size is 0 (empty rows are omitted and noted in limitations):
- Common entry fields:
dt_size,dt_offset(relative to header start),id,rev. - Version 0 (
version = 0):flagsandcompressionarenull;customrecords the four trailing 32-bit words (custom[4]). - Version 1 (
version = 1):flagsrecords the raw 32-bit word,compressiondecodesflags & 0x0f(0=none,1=zlib,2=gzip,3..15=unknown), andcustomrecords the three trailing 32-bit words (custom[3]).
Child magic verification and limitations
For every non-empty entry, the reader probes the first 4 bytes at dt_offset:
- Uncompressed entries (
version = 0orcompression = "none") setfdt_magic_valid = truewhen the payload begins with0xd00dfeed, and record an explicit limitation when the bytes are shorter than 4 bytes or start with a different magic. - Compressed v1 entries (
zlib,gzip, orunknown) keep their stored bytes verbatim, setfdt_magic_valid = null(the inner magic is unknown, not absent), and record a limitation stating that compressed payloads are not decompressed. - Extra bytes beyond the 32-byte header/entry records and trailing file bytes
after
total_sizeremain undecoded and are reported in limitations. - Entries that point at exactly the same payload range are valid:
mkdtimgwrites a repeated input file once and points every entry for it at that payload. Each entry is listed, and a limitation names the shared range. Every row is hashed and can be extracted separately, so the declared bytes of all rows, shared or not, are admitted againstartifact_limits.expanded_bytesbefore any payload is read. - Bytes inside
total_sizethat the header, entry table and payloads do not claim are reported with their range, and coverage becomesunknownbecause they may hold data no entry lists.
Extraction and device tree inspection
rea inspect-artifact ./dtbo.img --json
rea extract-artifact ./dtbo.img --json
When one or more uncompressed entries start with 0xd00dfeed, inspection probes
propose extract_artifact followed by inspect_devicetree on the extracted
.dtbo files (see Flattened devicetree inspection).
Bounds, overlap checks, and admission limits
dt_table_headerversion other than0or1returns an unsupported-input refusal (version).- Files shorter than the 32-byte header, declared
header_size, declaredtotal_size, or entry table return a truncated refusal before entry admission limits are applied. header_sizeanddt_entry_sizeare bounded by intrinsic format invariants and declaredtotal_size/ file size; the reader reads only 32 bytes fromdt_table_headerand 32 decoded bytes per row.- Every non-empty entry payload is verified not to overlap
dt_table_header, thedt_table_entrytable, ortotal_size, and not to partially overlap another non-empty payload (an exactly shared payload is allowed, as above). - Table size and row count are bounded by caller-adjustable per-call controls in
artifact_limits.android_dtbo(defaults:entry_table_bytes = 16777216,entry_count = 4096):artifact_limits.android_dtbo.entry_table_bytesbounds the buffereddt_entry_count * dt_entry_sizeread (bytes, up to Node string/buffer representation capacity).artifact_limits.android_dtbo.entry_countboundsdt_entry_count(count).- Refusals carry
details.reader_limitnaming the exact parameter and allowed range so callers can raise it on the next call (for example,--artifact-limits '{"android_dtbo":{"entry_count":8192}}').
- Standalone DTBO partition images are distinct from single
0xd00dfeeddevicetrees and Android boot/vendor_boot images (see Android boot and vendor_boot images).