Skip to content

feat(fqbn): convert the linked ELF into the package's firmware images (#1298 4f) - #2246

Merged
zackees merged 1 commit into
mainfrom
agent/1298-fqbn-objcopy
Dec 4, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/1298-fqbn-objcopy

Conversation

@zackees

@zackees zackees commented Dec 4, 2026

Copy link
Copy Markdown
Member

Follow-up 4f of #1298: the step after the link.

fbuild fqbn <FQBN> --objcopy <name>.elf converts the linked ELF through every
non-empty recipe.objcopy.<ext>.pattern the package declares and reports
each image it wrote. --link and --objcopy may be one invocation, exactly
like --archive and --link — the ELF only has to exist when the step runs.

The two decisions

  1. Order is name order (bin, eep, hex, zip), because a step may
    consume an earlier step's output. Real Seeeduino:[email protected]
    platform.txt:
    recipe.objcopy.zip.pattern="{tools.nrfutil.cmd}" dfu genpkg … "{build.project_name}.hex" "{build.project_name}.zip"
    packages the .hex, not the ELF, so hex must run first.
  2. An empty recipe is not a recipe. Seeeduino:[email protected] declares
    recipe.objcopy.eep.pattern= with no value. Arduino skips it; a planner
    that expanded it would refuse a perfectly good package with "expands to an
    empty command".

Each output is derived as {build.path}/{build.project_name}.<ext> from the
ELF's directory and stem, and the expansion must name that path
(require_names), so a recipe writing elsewhere is refused by name instead of
being reported as a file the caller did not ask for. A non-.elf input is
refused.

Success is "every step exited 0 and every declared image exists" — not
"every image is non-empty": the real AVR eep recipe writes a 0-byte .eep for
a sketch with no EEPROM data.

Real e2e (real arduino:[email protected] package + avr-gcc 7.3.0, not a fixture)

24/24 core units compiled → core.a 347,362 B → sketch TU → link
Blink.elf 14,160 B (link_exit=0) → --objcopy build/Blink.elf --run:

objcopy_images=2
objcopy_exit=0
objcopy_written=2
image.0=build/Blink.eep bytes=13
image.1=build/Blink.hex bytes=2615
hex first bytes: b':100000000C945C0'

Non-ELF input: the objcopy step converts the linked .elf, not build/Blink.eeelf (exit 1).

Gates (real output)

  • soldr cargo test -p fbuild-build-engine --lib → 716 passed / 0 failed / 6 ignored
    (7 new in fqbn_objcopy::tests).
  • soldr cargo test -p fbuild-cli --bin fbuild → 592 passed / 0 failed
    (3 new: text report, JSON report, link+objcopy in one invocation).
  • soldr cargo clippy -p fbuild-build-engine -p fbuild-cli --all-targets -- -D warnings → exit 0.
  • ci/enforce_platform_boundary.py --print-totals → rows=0; dylint_rows=0.
  • soldr cargo fmt --check → clean.

RED, twice, each guard disabled and restored (then re-run green):

  • dropping the empty-value filter → skips_an_empty_recipe_and_runs_a_consumer_after_its_input
    and refuses_a_package_with_no_objcopy_recipe fail (2 failed).
  • dropping the require_names call → refuses_a_recipe_that_does_not_name_its_derived_image
    fails (1 failed).

The CLI tests drive plan_and_run, the same function the binary calls, so the
wiring is proven and not just the helpers.

#1298 stays open: the remaining cell is the upload/deploy side of a vendor
core (naming the board a vendor FQBN produced and flashing the image above).

…#1298 4f)

A board does not flash an ELF. `fbuild fqbn --objcopy <name>.elf` now plans
and runs every non-empty `recipe.objcopy.<ext>.pattern` the package declares,
in name order, and reports each image it wrote.

Two rules are the builder's, not the template's:

- Order is the suffix's name order (bin, eep, hex, zip) because a later step
  can consume an earlier step's output: the Seeeduino `mbed` core's
  recipe.objcopy.zip.pattern packages `{build.project_name}.hex`, not the ELF.
- An empty recipe is not a recipe: Seeeduino:[email protected] declares
  `recipe.objcopy.eep.pattern=` with no value, and Arduino skips it.

Each image path is derived as `{build.path}/{build.project_name}.<ext>` from
the ELF's own directory and stem, and the expansion must name it
(`require_names`), so a recipe that writes elsewhere is refused by name.

Success is "every step exited 0 and every declared image exists", not "every
image is non-empty": the real AVR eep recipe writes a zero-byte `.eep` for a
sketch with no EEPROM data, while a step that exits 0 and writes nothing at
all is the failure worth catching.

The link half's shared helpers (`base_props`, `merge_caller`, `require_names`,
`remove_stale`, `size_of`, `file_stem`) move to `pub(crate)` rather than being
reimplemented, so the post-link stage cannot drift from the derivation rules.
@zackees
zackees added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit afafa8d Dec 4, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant