Skip to content

feat(fqbn): plan the package's own upload step (#1298) - #2249

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

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

Conversation

@zackees

@zackees zackees commented Dec 4, 2026

Copy link
Copy Markdown
Member

What

Follow-up 4g of #1298: the last step of the Arduino builder — handing a firmware
image to the package's own uploader.

boards.txt names it (uno.upload.tool=avrdude, upload.tool.default,
upload.tool.network=arduino_ota), platform.txt spells the command:
tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} {upload.verify} -p{build.mcu} -c{upload.protocol} "-P{serial.port}" -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i".

fbuild fqbn <FQBN> --upload <image> --port <port> [--protocol <p>] [--upload-verbose] [--run] plans it; --run is the only thing that spawns.

Decisions (each a refusal, not a guess)

  • Which tool: upload.tool.<protocol> when a protocol is named, else
    upload.tool.default, else upload.tool; a board declaring none is refused
    with the keys it could declare.
  • Which port: {serial.port} is never defaulted — a plan for a device the
    caller did not name is a command line nobody can audit.
  • Builder variables that are the package's: {upload.verbose} is
    tools.<tool>.upload.params.<level>; {upload.verify} is
    tools.<tool>.upload.verify, which the AVR core declares empty.
  • Tool-scoped references: {cmd.path} / {config.path} / {path} are
    siblings in tools.<tool>., not package-wide properties. Expansion consults
    the package map first, then falls back to tools.<tool>.<name>, and refuses
    an unresolvable reference by name and namespace.
  • Naming the file: the flasher receives the image inside a larger argument
    (-Uflash:w:<path>.hex:i), so the check is containment bounded by
    path-characters, not argument equality — and a recipe naming another file is
    still refused.
  • The image must exist and must not be the ELF; the uploader's exit code is the
    verdict, with no retry (a half-flashed board must be re-flashed deliberately).

Real e2e (arduino:[email protected] from the published index)

25 core units → core.a 353,404 B → sketch TU 3,916 B → Blink.elf 14,200 B →
--objcopy → Blink.hex 2,611 B + Blink.eep 13 B → --upload:

upload_tool=avrdude
upload_recipe=tools.avrdude.upload.pattern
upload_command="…/avrdude" "-C…/etc/avrdude.conf" -q -q  -patmega328p -carduino "-P/dev/ttyACM0" -b115200 -D "-Uflash:w:build/Blink.hex:i"

--run against a nonexistent port spawns the real avrdude and reports its own
failure (upload_exit=1, avrdude: ser_open(): can't open device …). No board
was flashed. --protocol network on this package selects arduino_ota and is
refused by name for {upload.port.address} — the honest outcome, since nothing
declares it.

Gates (real output)

  • soldr cargo test -p fbuild-build-engine --lib: 730 passed / 0 failed / 6 ignored
  • soldr cargo test -p fbuild-cli --bin fbuild: 594 passed / 0 failed
  • clippy -p fbuild-build-engine -p fbuild-cli --all-targets -- -D warnings: exit 0
  • cargo fmt --all: clean; boundary rows=0; dylint_rows=0
  • RED proven twice: scope disabled → 5 failures incl. the real AVR plan; the
    containment check neutered → the "names another image" test passes when it
    must fail.

Docs: docs/design/fqbn-resolution.md (status, follow-up 4g, remaining cells),
docs/reference/cli.md, engine README.

#1298 stays open: library discovery and fbuild build --fqbn remain.

The Arduino chain ends with a flash step that is not a build recipe:
`tools.<tool>.upload.pattern`, selected by the board's `upload.tool.<protocol>`
(falling back to `upload.tool.default`, then `upload.tool`).

- `fqbn_upload` plans the command for an image and a caller-named port:
  `{serial.port}` is never defaulted, `{upload.verbose}` is the package's
  `upload.params.<level>`, `{upload.verify}` its declared (possibly empty)
  value, and the image must exist and must not be the ELF.
- Tool-scoped `{…}` references (`{cmd.path}`, `{config.path}`, `{path}`)
  resolve inside `tools.<tool>.` — the real AVR core names its uploader that
  way — with the package-wide map consulted first and an unresolvable
  reference refused by name and namespace.
- The "command must name the file you asked for" rule is containment with
  path-character bounds, because the flasher receives the image inside a larger
  argument (`-Uflash:w:<path>.hex:i`); a recipe naming another file is refused.
- CLI `fbuild fqbn --upload <image> --port <port> [--protocol <p>]
  [--upload-verbose] [--run]`, text and JSON; `--run` spawns the uploader and
  reports its exit code, with no retry.

Real e2e on `arduino:[email protected]` (published index, checksums verified): 25 core
units -> core.a 353,404 B -> sketch TU 3,916 B -> Blink.elf 14,200 B ->
Blink.hex 2,611 B + Blink.eep 13 B -> `--upload` plans the real avrdude
command; `--run` on a nonexistent port exits 1 with avrdude's own
`ser_open(): can't open device` message.

#1298 stays open (library discovery and `fbuild build --fqbn` remain).
@zackees
zackees added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit db1e254 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