Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Prior art and licences

What already exists for flashing and partitioning microcontrollers, natively and in the browser, and what nanoflash reuses, contributes to or writes itself. Surveyed on 2026-11-22; versions and licences come from crates.io, npm and the projects’ repositories on that date.

Summary

  • No Rust or WebAssembly project unifies several bootloader protocols behind one API, and none unifies partition layouts across vendors. The closest, probe-rs, only drives debug probes.
  • Every web flasher covers one vendor or one protocol (esptool-js, esp-web-tools, webdfu, DAPjs).
  • The building blocks exist and are permissively licensed: espflash (without its serial port layer), dfu-core, nusb (now with a WebUSB backend), mbrman, gpt_disk_types, esp-idf-part, uf2_block.
  • Some protocols have no reusable Rust implementation: the Espressif ROM loader over an asynchronous transport, SAM-BA, and the STK500v1, STK500v2 and AVR109 bootloaders of Arduino’s AVR boards. nanoflash writes those, using espflash, BOSSA and avrdude as references. See Design decisions for the choices that follow from this survey.

Multi-protocol flashers

ProjectScopeLicenceNotes
probe-rs 0.32.0Debug probes: CMSIS-DAP, ST-Link, J-Link, ESP USB-JTAG, WCH-LinkMIT OR Apache-2.0No ROM serial loaders, SAM-BA, DFU or UF2. Synchronous. Its WebAssembly build is several MB, far above the limit of 256000 bytes of a nanoflash module, and the proposed changes for asynchronous probes (pull request #2958) were not taken upstream. The CMSIS-DAP layer is not a separate crate.
esptool-js 0.7.1Espressif ROM loader over Web Serial (and WebUSB for CH34x bridges)Apache-2.0Espressif only.
esp-web-tools 10.5.2Install button and manifest on top of esptool-jsApache-2.0Espressif only. Its manifest format is accepted by nanoflash.
Adafruit WebSerial ESPToolEspressif over Web SerialMITEspressif only.
webdfuUSB DFU over WebUSBISCUnmaintained since 2021.
DAPjsCMSIS-DAP over WebUSBMITJavaScript.
Arduino Cloud AgentNative helper that runs bossac, avrdude… for the browserAGPL-3.0Not a web flasher; not reused.
espflash-wasmExperiment running espflash in the browserMIT OR Apache-2.0Last change in 2023.
ESP32 Bit Pirate web toolsesptool-js, STM32 AN3155, avrdude in WebAssemblyvariousSeveral separate tools on one page, not one API.

Per protocol

Espressif ROM serial bootloader

  • espflash 4.7.0, MIT OR Apache-2.0 (relicensed in #224). Supports ESP32, C2, C3, C5, C6, C61, H2, H21, H4, P4, S2, S3 and S31.
    • Its Connection and Flasher are synchronous and bound to the concrete serialport types; they only exist behind the serialport feature. There is no custom transport and Web Serial is asynchronous only, so they cannot run in the browser.
    • Without that feature the crate still provides the command module (encoding of every loader command), target::Chip (chip detection values, register addresses, write sizes, eFuse fields) and the flasher stubs. We built it for wasm32-unknown-unknown with default-features = false: it compiles. Its dependencies (regex, deku, object, esp-idf-part) weigh on the WebAssembly bundle; this is measured before committing to it.
    • Issue #1091 asks for user-supplied serial ports; the maintainer put it on hold but would consider a contribution for a future major version. PR #834 (no_std with embedded-io) is open and inactive since 2025-07.
  • esptool 5.6.0 (Python) is GPL-2.0-or-later: nanoflash does not port from it.
  • esp-flasher-stub is Apache-2.0 OR MIT; the stubs can be redistributed.
  • The protocol is documented by Espressif: serial protocol.

Decision: write our own asynchronous loader over nanoflash’s transport trait: SLIP framing, commands, reset sequences, orchestration, written from Espressif’s protocol documentation with espflash and esptool-js as references. Copy the few chip constants we need (detection values, about 40 lines) from espflash with attribution (MIT OR Apache-2.0) rather than depending on it: its dependency tree would dominate the WebAssembly bundle for those few lines. Use the ROM loader without a flasher stub at first (the ROM supports compressed writes and MD5); the stub is a later speed-up. Offer the transport design upstream on #1091 once it has proven itself.

The nanoflash command uses one more part of espflash 4.7: image_format, to turn an ELF file into an ESP-IDF application image. That code is large and changes with each chip, and it needs no transport, so it is reused natively and not rewritten. The library and the browser package do not use it.

SAM-BA and the bossac dialect

  • BOSSA 1.9.1 and the active arduino/BOSSA fork (1.9.1-arduino6): BSD-3-Clause. The reference implementation is Samba.cpp: ASCII commands N#, V#, O/o/W/w/S/R/G, plus the Arduino extensions advertised as [Arduino:XYZ...] in the version string: X (erase), Y (write buffer to flash), Z (CRC), I (identify chip), K (reset). arduino/BOSSA ships a SAM-BA emulator in its tests.
  • The SAMD bootloader of ArduinoCore-samd is LGPL-2.1 (device side; not vendored).
  • Arduino Nano 33 BLE (ArduinoCore-mbed boards.txt): upload.tool=bossac, use_1200bps_touch=true, wait_for_upload_port=true, VID 0x2341, PIDs 0x005a, 0x805a, 0x015a, 0x025a; upload command bossac -U -i -e -w file.bin -R. arduino/BOSSA identifies nRF52840-QIAA through I. The bootloader itself is distributed as a binary only (issue #90).
  • Rust: only bossa, C++ bindings through cxx, native only, last changed in 2023.

Decision: write our own SAM-BA implementation in Rust from the protocol (the command set with the Arduino extensions, the nRF52 and SAMD families of Arduino’s bootloaders, and the 1200-baud touch), with BOSSA as a behaviour reference only: no code is ported, so the crate stays MIT OR Apache-2.0. A binding to BOSSA works natively only: its serial I/O is blocking C++ with exceptions, so running it in the browser would need a separate C++ to WebAssembly build and Chromium’s JSPI to suspend on Web Serial. That would mean a second toolchain and module to replace about 700 lines of Rust.

STK500 and AVR109 (Arduino’s AVR boards)

Surveyed on 2026-11-23. Arduino’s boards.txt (ArduinoCore-avr) uploads every AVR board with avrdude: upload.protocol=arduino (STK500v1: Optiboot on the Uno, ATmegaBOOT on the old Nano and Pro Mini), wiring (STK500v2: the Mega 2560’s bootloader) or avr109 (Caterina on the Leonardo, Micro and other ATmega32U4 boards, after a 1200-baud touch).

  • The protocols are documented by Atmel: application notes AVR061 (STK500 communication protocol), AVR068 (STK500v2) and AVR109 (self-programming).
  • avrdude: GPL-2.0-or-later, C, the reference uploader. nanoflash does not port from it.
  • Rust crates: none fits. ravedude 0.3.0 (MIT OR Apache-2.0, avr-hal) runs the avrdude binary; avrisp 0.3.1 (BSD-2-Clause, no_std) holds the SPI instructions of in-system programming, not the bootloaders’ serial protocols; avr-boot 0.3.2 (MIT) is for firmware that programs its own flash. Nothing speaks STK500v1, STK500v2 or AVR109 over an asynchronous transport, natively or in the browser.
  • The bootloaders run on the board and are behaviour references only: Optiboot (GPL-2.0), ATmegaBOOT and the wiring bootloader of the Mega 2560 (GPL-2.0-or-later, stk500boot.c in ArduinoCore-avr), and Caterina, derived from LUFA’s CDC bootloader. The wiring bootloader erases one page per page programmed, in order from 0x0, and never from 0x3C000 (its APP_END): nanoflash follows that order.
  • simavr: GPL-3.0, an AVR simulator; it runs the bootloaders from ArduinoCore-avr in mise run test-simavr, as a test tool installed or downloaded at test time, never committed or distributed with nanoflash.
  • Intel HEX, the format of Arduino’s images: ihex 3.0.0 (MIT OR Apache-2.0) needs std; nanoflash decodes it itself (no_std, fallible allocation) and uses ihex in its tests.

Decision: write the three protocols in Rust from Atmel’s application notes and from observing the bootloaders (and avrdude) on simavr and on boards, sharing the 1200-baud touch with SAM-BA: no code is ported from avrdude, Optiboot, ATmegaBOOT, the wiring bootloader, Caterina or simavr, and each file of src/avr/ says so in its first comment.

USB DFU

  • dfu-core 0.11.1: MIT OR Apache-2.0, #![no_std], sans-I/O (DfuIo trait), synchronous and async modes, DfuSe memory layouts.
  • dfu-nusb 0.2.0 (async, on nusb 0.2) and dfu-libusb 0.6.2: same licence.
  • webdfu: ISC, JavaScript, unmaintained.

Decision: reuse dfu-core over nanoflash’s USB transport (nusb natively and in the browser).

UF2

Decision: encode blocks ourselves (a 32-byte header and a 476-byte payload; about 50 lines); native writes copy the file onto the mounted drive, the browser writes through the File System Access API (a directory picker on the board’s drive).

CMSIS-DAP and Nordic serial DFU (later)

  • The probe-rs crate, in the command only. There is no CMSIS-DAP route in the browser: on 2026-11-30 the browser route through probe-rs was judged a dead end, because its WebAssembly build is several MB, over the limit of 256000 bytes of a module, and upstream did not take the proposed changes. DAPjs (MIT, JavaScript) would be a second engine, which is an anti-goal.
  • Nordic serial DFU: no Rust implementation surveyed in depth; to be revisited when the backend is scheduled.

Partition tables and file system images

NeedCrateLicenceno_std
Espressif partition tableesp-idf-part 0.6.0MIT OR Apache-2.0no (CSV, regex, deku)
MBRmbrman 0.7.0MIT OR Apache-2.0yes (new in 0.7)
GPTgpt_disk_types 0.16.1MIT OR Apache-2.0yes
GPT (reading, tests)gpt 4.1.0MITno
FAT imagefatfs 0.3.6MIT0.4 (unreleased)
LittleFS imagelittlefs2 0.8.1MIT OR Apache-2.0yes, but wraps C (littlefs2-sys)

esp-idf-part needs std, and both the Espressif table (32-byte entries plus an MD5 row) and the MBR (four 16-byte entries) are small fixed formats, so nanoflash writes them itself, no_std, and uses esp-idf-part, mbrman, ESP-IDF’s gen_esp32part.py and sfdisk in tests to read its output back. LittleFS image building stays native only (C toolchain); the browser accepts an image built elsewhere.

Transports

NeedNativeBrowser
Serialserialport 4.10.1 (MPL-2.0, used as a dependency, never copied)web-sys Web Serial (behind web_sys_unstable_apis); no maintained wrapper crate, so nanoflash writes a thin one. serialport’s Web Serial work (#165, PR #224 closed) did not land.
USBnusb 0.2.9 (Apache-2.0 OR MIT)nusb’s WebUSB backend (#199, since 0.2.6, async API only, --cfg=web_sys_unstable_apis)
Mass storage (UF2)std::fsFile System Access API

Web Serial and WebUSB are implemented by Chromium-based browsers only; the command line is the fallback everywhere else.

esp-web-tools manifest

Documented at esphome.github.io/esp-web-tools, types in src/const.ts:

  • top level: name, version, home_assistant_domain?, funding_url?, new_install_prompt_erase?, new_install_skip_erase? (deprecated), new_install_improv_wait_time?, builds[];
  • build: chipFamily (ESP32, ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-P4, ESP32-S2, ESP32-S3, ESP8266), parts[] with path (relative to the manifest, or a URL) and offset, and serialType? (cdc or uart, in the code only).

Licences of reference implementations

ReferenceLicenceHow nanoflash uses it
espflashMIT OR Apache-2.0reference for the loader; chip constants copied with attribution
esptool-jsApache-2.0reference for reset sequences in the browser
esptool (Python)GPL-2.0-or-laternot used
esp-flasher-stubApache-2.0 OR MITstubs, later
BOSSA, arduino/BOSSABSD-3-Clausebehaviour reference, no code ported
ArduinoCore-samd bootloaderLGPL-2.1protocol reference only, not vendored
avrdudeGPL-2.0-or-laterbehaviour reference only, no code ported
OptibootGPL-2.0behaviour reference only (on the board), no code ported
ATmegaBOOT, the wiring bootloader (ArduinoCore-avr)GPL-2.0-or-laterbehaviour reference only (on the board), no code ported
Caterina (ArduinoCore-avr)derived from LUFAbehaviour reference only (on the board), no code ported
simavrGPL-3.0test tool only, installed or downloaded at test time, never distributed
ihexMIT OR Apache-2.0test-only dependency
dfu-coreMIT OR Apache-2.0dependency
microsoft/uf2MITspecification and family identifiers
pico-sdkBSD-3-Clausefamily identifiers (cross-check)
probe-rsMIT OR Apache-2.0dependency (later)
DAPjsMITnot used
serialportMPL-2.0dependency only
Arduino Cloud AgentAGPL-3.0not used

nanoflash itself is licensed MIT OR Apache-2.0.

What could go upstream

  • espflash: an asynchronous transport trait (issue #1091), once nanoflash’s loop has run on hardware. This would let espflash itself run in the browser.
  • probe-rs: nothing. The route through asynchronous probes for WebUSB (#2958) is closed.
  • esp-idf-part: no_std support, so the Espressif writer can move next to the others.