Skip to content

feat(artifacts): inventory and extract U-Boot FIT images - #7771

Merged
gensokyo-dev merged 14 commits into
morluto:mainfrom
555aaditya:feat/fit-images
Oct 29, 2026
Merged

gensokyo-dev merged 14 commits into
morluto:mainfrom
555aaditya:feat/fit-images

Conversation

@555aaditya

@555aaditya 555aaditya commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #7129. Add U-Boot FIT (.itb) inventory and stored-byte extraction to the existing CLI/MCP artifact workflows, replacing unsupported-format refusal. This continuation retains the original contributor's commits and integrates main 429355ca4.

  • Image occurrences retain stable source paths, physical ranges, content identities and declared type/architecture/OS/compression/load/entry. Embedded data, external offsets and absolute positions are supported; equivalent external forms share their resolved range, and embedded sharing requires equal bytes.
  • CRC32/MD5/SHA1/SHA256/SHA384/SHA512 are verified in one streamed pass per image. Unsupported/incomplete hashes remain unverified. Signature declaration/unreadable counts and missing/malformed algorithm limitations distinguish unknown from absent. Cipher presence is separate from its nullable algorithm. Per-field unreadable_fields distinguishes absent declarations from parsing failures; algorithm names remain arrays. Shared entry ownership deep-copies nested facts and compares them structurally without serialization.
  • Configuration facts preserve every reference and an unresolved count. One diagnostic per configuration prevents long names from expanding once per dangling reference.
  • Existing summary/filtered inventory views preserve complete parent Evidence. FIT accepts current summary identities; historical aliases are restricted to a frozen set of formats that actually existed in the old projection epochs.
  • Shared artifact comparison recognizes load/entry and other payload-interpretation changes, preserves unknowns/known partial differences, and ignores physical placement/order. Raw-analysis hints reuse admitRawBinary, identify an admitted image with exact parameters, and withhold incompatible or divergent mapping/entry declarations.

Boundaries and resources

Static format inspection and ordinary extraction use the shared artifact provider. parseDevicetree owns FDT decoding, FitStructure owns FIT interpretation, and the reader owns identity/stream lifecycle; adapters consume those facts. Additive fit, fit/fit-image metadata; no new tools. Signature/cipher verification, decompression and target execution are outside this capability. Stored ciphertext is copied as opaque payload; cipher_present retains that declaration.

The FDT is capped at 16 MiB, with 1,024 images/configurations, 8 hash nodes per image, and 16,384 configuration references counted before expansion. Existing parser/archive bounds apply; external bytes stream from disk. Embedded equality uses source-buffer views. Returned streams retain cancellation and ownership until readable close, including buffered bytes; active/final validation failures retain precedence. No additional cache or retained image buffer.

Validation

Linux x64, Node 24.22.1 / npm 11.16.0, head 2c198c582e:

  • Local: 387 passed, 2 skipped, 2 unrelated Node SEA failures, 17 focused files (all 323 FIT/core tests pass): domain/raw admission, reader, ranges/classification, comparison resolution, filesystem, compiled CLI and full/compact stdio MCP. SDK-converted schemas and actual named responses are validated.
  • Shared reader/uImage/ESP checks pass. The two unchanged Node SEA post-classification mutation cases reproduce on the frozen pre-fix control (39 pass / 2 fail); both cases also reproduce on latest main d157560d4 (39 pass / 2 fail). Their production and test blobs are unchanged by this PR. Earlier same-file runs passed, so this is timing-sensitive baseline behavior, retained in the validation record.
  • check:fast, formatting, git diff --check, and docs:check pass (including 9 README conformance tests).
  • Regression proofs failed before their fixes: missing/malformed cipher algorithms, buffered cancellation (including null/object reasons), mismatched embedded links, invented legacy FIT summary IDs, diagnostic expansion, unknown signatures, mixed external source forms, load-only comparison, 7 invalid raw hints, and absent-to-present load changes under unrelated hash warnings. A CLI control also preserves valid raw hints under the same unrelated warning. Positive controls preserve valid links, legacy plist projections, layout independence and known changes alongside unknown fields.
  • The long-name/16,384-reference regression checks one bounded diagnostic, retained raw values and serialization below four times its input size. It does not serialize the old attack-scale result.

Codex review was requested, but its current-head bot response reports the repository code-review usage limit. All actionable findings are addressed. Greptile reviewed this exact head at 5/5, with every thread resolved.

Final CI at this head: all required checks pass. Source tests: 21,650 passed /16 skipped; all 8/8 portable test shards and their aggregate pass. Static checks, package build, documentation, Windows capability/package and macOS arm64/Linux x64/Linux arm64 native package lanes pass. The timing-sensitive local Node SEA baseline failures above did not recur in CI. CI run.

Real data and independent oracles:

  • OpenWrt 24.10.3 ABT ASR3000 recovery FIT: 8,585,216 bytes; SHA-256 fb1eb7ef752bfc41fbc9e890d4af21f06e0a0dd5a77eb701d45e224ba47027f9. Kernel/initrd/FDT declarations match mkimage -l/fdtget; extracted files and reported carrier slices match independent dumpimage hashes. CLI bundle views also work from another cwd with the original target path absent. A final-head complete MCP task passes the same independent metadata/payload oracles and cleanup at 499,214 estimated transport tokens (488,039 catalog), 3.695 s / 5.54 CPU s / 574.8 MiB peak family RSS.
  • Real mkimage 2023.01 + dtc 1.6.1 produce embedded, -E -B 0x200, and -E -p 0x2000 -B 0x200 layouts containing a stored Debian executable and DTB. Public workflows check exact bytes, a 64-bit address, configurations, and current admitted raw hints. Three current-head MCP runs pass all layouts with cleanup under the resource guard (498,449–498,468 estimated transport tokens, including 488,039 catalog tokens; 2.663–2.687 s, 3.65–3.68 CPU s, 508.1–510.9 MiB peak family RSS).
  • A controlled OpenWrt copy changes kernel load to 0x48010000, confirmed by native tools. Public MCP comparison reports the kernel metadata change plus root bytes; all three payload hashes remain equal. This correctness task passes in 2.888 s / 4.10 CPU s / 541.4 MiB peak family RSS; tokens unmeasured.

Measured task costs

32 completed measurement tasks across pinned integration revisions, plus three current-head layout checks and the functional comparison above. Fresh client/server sessions, warm OS caches, compact input schemas, families artifact,application,session; SDK 2.3.1 validates named responses. Complete tasks include initialization/instructions, catalog discovery, inspection, optional views, extraction, byte verification and close.

For the diagnostic correction, four alternating tasks use an OpenWrt copy with a 4,096-byte configuration name and 16 distinct dangling references. Before is ac585f6ca; after is 310eb6e05 (production identical to measured 2e63e1997).

Task Estimated tokens Elapsed CPU Peak family RSS
Before 636,256 3.586–5.488 s 5.20–7.93 s 570.1–575.0 MiB
After 509,200 4.584–5.580 s 6.46–7.99 s 572.6–572.7 MiB

Diagnostics fall from 16 to 1 while preserving all references, image facts and provenance. Whole-message token estimates decrease about 20%, including the added fact schemas (catalog 487,671 → 487,901). CPU/time/RSS do not establish an improvement. A four-task duplicate-reference control records 508,677 → 509,085 tokens: the old downstream dedup already collapses equal messages, so that control shows no token saving.

Earlier pristine OpenWrt measurements at ac585f6ca show why small containers should prefer complete delivery: 498,627 estimated tokens / 3.139–3.412 s versus summary plus selected image metadata at 498,241 / 5.787–6.999 s. The extra view saves little context and incurs first-use client schema validation. No general speedup is claimed.

Tokenx 1.3.0 estimates serialized JSON-RPC messages, including text/structured representations; these are transport estimates, not billed model/context counts. RSS is a 10 ms sampled sum for the Node client/server process group; CPU includes both, excludes the external sampler, and elapsed includes instrumentation. Node heaps are capped at 2 GiB with a 1.5 GiB family/150 s guard; all measured tasks complete without guard stops. Compilation-cache state was not independently controlled; cold caches and full-schema costs are unmeasured. Native producer/oracle preparation is outside task timings. Attack-scale OOM is source-derived and was deliberately not executed. No payload or deep provider was executed.

Author readiness

Human owner: @555aaditya

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

open_binary refused U-Boot Flattened Image Tree files as an unsupported
format, so inspect_artifact and extract_artifact could not list or
recover a FIT's kernel, devicetree, ramdisk and loadable images.

Recognize an FDT v16/v17 with a top-level /images node and parse it with
the existing parseDevicetree. Each /images child becomes an inventory
entry named images/<unit-name>.bin that extracts its stored bytes from
embedded data, data-offset (past the 4-aligned devicetree end) or
data-position (from the file start). Image format_metadata records the
declared type, arch, os, compression, load and entry; root metadata
records the description, timestamp and configurations.

crc32, md5, sha1, sha256, sha384 and sha512 hash nodes are verified in
one streamed pass per image; other algorithms are reported unverified.
Signatures are reported, not verified, and nothing is decompressed,
decrypted or executed. Data outside the file, overlapping or duplicate
image data, a missing or repeated data source and hash mismatches fail
closed. The devicetree is bounded by the fixed 16 MiB allowance;
external image data is streamed from disk.

Refs morluto#7129
# Conflicts:
#	src/application/BinaryTargetResolver.ts
#	src/artifacts/inventory/ArtifactGraphConstruction.ts
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; the latest change fixes the remaining saved-metadata finding.

Summary

Adds U-Boot FIT inventory and stored-byte extraction through the shared CLI/MCP artifact workflows.

  • FIT files show up as image entries in the artifact inventory.
  • FIT comparisons show changes to image load and entry declarations.
  • Inspection suggests follow-up analysis for suitable FIT images.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["CLI / MCP"] --> B["Shared FIT reader"]
  B --> C["FDT parser and FIT facts"]
  B --> D["Inventory and Evidence"]
  B --> E["Stored-byte extraction"]
  D --> F["Views and comparison"]
Loading

Reviews (13) · Last reviewed commit: "fix(artifacts): isolate nested entry met..." · Reviewed by Greptile

Comment thread src/artifacts/fit/FitStructure.ts Resolved
Comment thread src/domain/artifactInspection.ts Resolved
Comment thread src/artifacts/FitArtifactReader.test.ts Resolved
@555aaditya
555aaditya marked this pull request as ready for review October 28, 2026 11:00
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T05:06:14.701656Z
We couldn’t complete this review. Comment @codex review to try again.
2c198c5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

# Conflicts:
#	docs/cli.md
#	docs/firmware-analysis.md
#	src/application/BinaryTargetResolver.ts
#	src/artifacts/inventory/reader.ts
#	src/domain/artifactFormatMetadata.ts
Comment thread src/artifacts/FitArtifactReader.ts Resolved
Comment thread src/cli/cliResultOutput.ts Resolved
Comment thread src/artifacts/FitArtifactReader.test.ts Resolved
@gensokyo-dev

Copy link
Copy Markdown
Collaborator

@codex review

Please review current head d4f033d. The final test-only change replaces a global read ordinal with an observed source-end phase and reader-scoped fault. The preceding production lifecycle fix and real-data validation are described in the current PR body; unrelated main findings have been explicitly scoped in their threads.

@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Final-head CI audit (d4f033d, run 40811293422): Source tests has 21,645 passing / 16 skipped tests and one failure, NativeMacOSProviderInput.test.ts (unreadable lipo output for inspect_macho). The same case reproduces on isolated current main cf9f010 (1 failed / 4 passed); all src/native blobs are unchanged between that main and this PR. The completed Source job log confirms this exact failure. Static checks, build, docs, macOS/Linux arm64 package checks and several compatibility lanes have passed; portable shards remain running. Greptile reviewed this exact 28-file head at 5/5 with no new findings. This records the unrelated baseline failure while awaiting the remaining CI and requested Codex review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4f033d78d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/artifacts/fit/FitStructure.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2724c61c68

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/artifacts/fit/FitStructure.ts Resolved
Comment thread src/artifacts/fit/FitStructure.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac585f6caf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/artifactFormatMetadata.ts Resolved
Comment thread src/artifacts/fit/FitStructure.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/artifactInspection.ts Resolved
Comment thread src/domain/artifactInspection.ts Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Comment thread src/domain/artifactComparison.ts Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Comment thread src/artifacts/ArtifactReader.ts Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gensokyo-dev
gensokyo-dev merged commit d39b300 into morluto:main Oct 29, 2026
46 of 50 checks passed
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 29, 2026
morluto#7771's U-Boot FIT probe read a bare entry from admitRawBinary's result.
On this branch the result carries the whole load, and admission without an
entry may first need a vector-table read. The probe always selects an
entry, so it reads the canonical entry from the admitted load.
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 29, 2026
morluto#7771 adds the `fit` target format. As this test intends, it stopped
compiling until `fit` had a fixture, so the merge adds that row.
@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants