Design decisions
This page records what nanoflash aims for, what it leaves out, and the approaches that were considered. Prior art and licences has the survey of existing tools behind these choices.
Goals
- One vendor-neutral TOML layout file per board: flash size and named partitions with a role. nanoflash resolves offsets, checks them, reports headroom and writes the table of each family.
- One vendor-neutral board manifest: protocol, chip, layout, images, reset sequence, digests. The esp-web-tools manifest is accepted as it is.
- One asynchronous code path for every backend, running natively and in WebAssembly over a transport trait.
- Backends, in order: Espressif ROM loader, SAM-BA (with the Arduino dialect of bossac), the STK500v1, STK500v2 and AVR109 bootloaders of Arduino’s AVR boards, USB DFU, UF2, then CMSIS-DAP (in the command only) and Nordic serial DFU.
- Binary, Intel HEX and ELF images for every backend.
- A
buildfeature, so that thebuild.rsof a firmware reads the same layout file: one source of truth. - A command line for CI: clear errors,
--json, no prompts.
Non-goals
- Building firmware, or vendor image formats beyond what flashing needs.
- Signing, encryption and secure boot provisioning. Verification is a hook of the caller.
- A debugger.
- Browsers without Web Serial or WebUSB (Firefox, Safari). The command line is the alternative.
Anti-goals
These would make nanoflash a failure even if it worked:
- Two engines per protocol (one native, one in the browser) that drift apart.
- A WebAssembly bundle that ships every backend to flash one board.
- Code ported from a copyleft implementation (esptool is GPL-2.0-or-later).
- Interactive prompts or ambiguous output in CI.
Constraints
- Stable Rust, edition 2024, minimum supported version 1.95. The library is
no_stdwithalloc. - Licence MIT OR Apache-2.0 for every crate. No code is ported from implementations under other licences. They serve as behaviour references only.
- Identifiers, documentation and messages spell words out (
device,directory,configuration) unless an external API forces otherwise. - Conventional commits. The tooling is the same as in the author’s other crates: mise, mbx (mr-boxington), release-plz, cargo-deny, codecov, a pull request title check and the nanobom SBOM upload.
- Web Serial and WebUSB exist in Chromium-based browsers only.
- Futures are not
Send: browser APIs are single-threaded, so every trait is designed for a single-threaded executor. - The library never panics on an input or a device answer, bounds every wait on a device, and
forbids
unsafecode. Invariants lists these rules. - Distribution channels: git tags and GitHub releases first (archives of the command, with a
checksum, a software bill of materials and a build provenance attestation for each target, see
Release archives), then crates.io and npm. release-plz publishes nothing to a registry. The workflow
publish.ymlpublishes a release to crates.io by hand, after the hardware check. It only stages the npm package, through npm trusted publishing with no token, and a maintainer approves the staged version with two-factor authentication. The crates and the npm package are published since version 0.1.0. The archives hold every binary ofnanoflash-cliand have no version in their names, so one URL always gives the latest command.cargo binstallreads[package.metadata.binstall]ofnanoflash-cliand downloads the same archives. The macOS binaries are not signed. There is no container image.
Approaches considered
For the backends, the choice was between reusing existing tools and writing new code.
| Approach | Trade-off | Outcome |
|---|---|---|
| A. Reuse protocol libraries where they run asynchronously over our transport; write the missing loop | One engine per protocol on both platforms; some code of our own (Espressif loop, SAM-BA, AVR) | Chosen |
| B. Wrap the existing tool per platform (espflash natively, esptool-js in the browser; bossac natively) | Least code, but two engines per protocol, tests cover only one, no SAM-BA in the browser | Rejected (anti-goal) |
B’. For SAM-BA, BOSSA everywhere (cxx natively, BOSSA compiled to WebAssembly with Chromium’s JSPI in the browser) | Reuses BOSSA, but needs a C++ toolchain, a second WebAssembly module with JavaScript glue, and makes the crate BSD-3-Clause | Rejected in favour of our own code |
| C. Make the upstream tools asynchronous first (espflash, probe-rs), then build on them | Best for the ecosystem, but blocked on the major-version decisions of their maintainers | Deferred for espflash. Closed for probe-rs, see below |
For each backend, the choice favours the smallest codebase, simplicity and portability.
Dependencies count as code: they weigh on the WebAssembly bundle and on no_std.
| Backend or writer | Reused | Ours |
|---|---|---|
| Espressif ROM loader | miniz_oxide (compression), md-5 | SLIP framing, commands, a chip table of about 40 lines copied from espflash (MIT OR Apache-2.0, attributed), the asynchronous loop, reset sequences, orchestration. No flasher stub: the ROM already supports compressed writes and MD5, and the stub is only a speed-up. The ESP32 is written uncompressed: its ROM programs a whole 32 KiB inflate window after every compressed image (seen in Espressif’s QEMU). |
| SAM-BA | none usable in the browser | Our own code, written from the protocol (Microchip’s SAM-BA documentation, observed bootloader behaviour). BOSSA (BSD-3-Clause) is a behaviour reference only. No code is ported. |
| STK500v1, STK500v2, AVR109 | none: no crate is no_std, asynchronous over our transport and permissively licensed | Our own code, written from Atmel’s application notes AVR061, AVR068 and AVR109 and from observing the bootloaders. avrdude, Optiboot, ATmegaBOOT, the wiring bootloader and Caterina (GPL) are behaviour references only. No code is ported. |
| Intel HEX | ihex as a test-only dependency, to read the fixture back | A decoder of about 300 lines: ihex needs std. |
| Espressif partition table | md-5 | About 100 lines: 32-byte entries and the MD5 row. esp-idf-part (needs std, regex, deku) is a test-only dependency that reads the output back. |
| MBR | none | About 50 lines: four 16-byte entries and the signature. mbrman is a test-only dependency. |
| USB DFU (later) | dfu-core (no_std, sans-I/O) | Glue to the USB transport, DfuSe. |
| UF2 (later) | none (the format is a 32-byte header) | Encoder, family identifiers, drive handling. |
| CMSIS-DAP (later) | probe-rs natively; none in the browser | Glue in the command. |
espflash as a dependency was considered: it builds for WebAssembly without its serial feature.
But it would bring regex, deku, object and esp-idf-part into the bundle for about 40 lines
of constants, so the constants are copied instead.
The command line is the exception, for one task only. It uses image_format of espflash 4.7
(without its serial port code) to build the ESP-IDF application image of an ELF file
(crates/nanoflash-cli/src/espressif_image.rs). The library and the WebAssembly modules do not
depend on espflash. The command line writes a temporary partition table with esp-idf-part and
passes its path to espflash, which takes it as a file. With no bootloader path, espflash reads
the header of its bundled bootloader for the flash mode and frequency of the application header.
The command line therefore links all the bundled bootloaders, about 750 KB. nanoflash never writes
them to a device.
CMSIS-DAP is planned for the command only, through the probe-rs crate. On 2026-11-30 the browser
route through probe-rs was judged a dead end: its WebAssembly build is several MB, over the limit
of 256000 bytes of a module, and upstream did not take the proposed changes. DAPjs in the browser
would be a second engine next to probe-rs, which is an anti-goal.
Transports
The original brief asked for one transport trait with USB control requests too. USB devices get
their own trait (control and bulk transfers, over nusb natively and in the browser) with the
first USB backend, DFU. No device is both a serial port and a raw USB device. A PortProvider was
added because the touch reset makes the bootloader appear as a new device. Timeouts are part of
read, so no_std backends need no timer of their own.
In the browser, a device that comes back under another USB identity is reachable without a user
gesture only if permission was granted earlier. The web component asks for the application and
bootloader identities of the board in one requestPort filter list. When the bootloader device was
never granted, it shows a second button (“Select the board in bootloader mode”) instead of failing.
The facade dispatches over an enum of the enabled backends, because async fn in traits is not
object-safe.
Roles and table writers
The roles are bootloader, partition-table, firmware, update, storage, crash-record and
custom. partition-table was added to the roles of the brief, because table writers need to know
where their table goes. Per-family attributes live in a table named after the family and override
what the role implies.
A GPT writer (protective MBR, primary and backup GPT, with gpt_disk_types, type GUIDs from
attributes and deterministic GUIDs from a seed for reproducible images) comes later. So does a
FileSystemImageWriter trait that builds a FAT (fatfs) or LittleFS (littlefs2, native only)
image of a given size from a list of files. Nothing depends on it: a manifest image may target a
storage partition with an image that the caller supplies, which is checked to fit.
The monitor is not in the library
nanoflash monitor is in nanoflash-cli and not in the library, because it needs a clock, a
terminal and threads, and it must not reach the WebAssembly modules. The serial monitor and
defmt explains how it works.
Roadmap
The work came in stacked deliverables, one pull request each:
- The design, the prior art report, the licence files.
- Workspace and tooling; the layout model, resolution, checks, manifest model and traits; the
Espressif, MBR and
linkerwriters; thebuildfeature;layout checkandlayout write. - Transports (native and web); the Espressif backend;
flash,detectandimage build; the npm package and web component for Espressif. - The SAM-BA backend for the Arduino Nano 33 BLE. Arduino’s SAMD bootloaders speak the same
dialect (
X,Y,Z), so their family data came along, tested against transcripts only. - The AVR backend (STK500v1, STK500v2, AVR109) for the Arduino Uno, Nano, Mega 2560 and Leonardo,
with Intel HEX images for every protocol and an
avrWebAssembly module, tested against transcripts and simavr. - The Rust toolchain: ELF images,
nanoflash monitor,nanoflash run, the board in[package.metadata.nanoflash],cargo nanoflash, thebuildfeature writing a wholememory.x, and the example firmwareexamples/nano33ble. - Release binaries: release-plz in git-only mode, and the archives, checksums, SBOMs and provenance
of the command on its GitHub release. Tested by dry runs of
binaries.yml. The first real release has not happened yet.
Next, in this order unless the order changes: the GPT writer and file system images, USB DFU, UF2, CMSIS-DAP, Nordic serial DFU. UF2 in the browser will write through the File System Access API: the user picks the drive of the board once.