nanoflash flashes ESP32, ESP32-S3, ESP32-C3 and the other Espressif chips, the Arduino Uno, Nano,
Pro Mini, Mega 2560 and Leonardo, the Arduino Nano 33 BLE and SAMD21 boards from one command. It
is an alternative to esptool, bossac and avrdude, written in Rust: the same engine runs in your
terminal, as a Cargo runner behind cargo run, in a serial monitor with defmt decoding, and
in the browser as a Web Serial flasher. A TOML layout file describes the partition table
once: nanoflash computes the offsets, checks them, and writes the Espressif partition table, an MBR,
linker regions or Rust constants from it.
It is for firmware developers who flash boards of several vendors, Rust embedded developers who want
cargo run to flash and monitor, and projects that ship firmware to users and want a flash button
on a web page. It replaces a different flashing tool and partition format per vendor with one tool
and one format.
Why nanoflash
- One tool for three families. The Espressif ROM loader, SAM-BA with the Arduino extensions of bossac, and the STK500v1, STK500v2 and AVR109 bootloaders of Arduino's AVR boards.
- Nothing erased before every check passes. Digests, alignment, overlap, partition sizes, flash size and the limits of the bootloader are checked before the first erase, then again against the flash that the chip reports.
- One layout file as the source of truth. The command, the
build.rsof your firmware and the browser read the same file. Partitions can grow with the flash that the chip reports. - Made for Rust firmware.
cargo runbuilds, flashes and monitors. ELF files are accepted as they are. Thebuildfeature writes yourmemory.xfrom the layout. - The same engine in the browser. The library compiles to WebAssembly: an npm package, a
<nanoflash-button>web component and a hosted flasher page. - Made for CI. No prompts,
--jsonoutput, exit codes that tell an input error from a device error and a failed verification. - Binary, Intel HEX and ELF images. Existing esp-web-tools manifests work unchanged.
Quick start
Install the command from the Linux, macOS and Windows binaries of GitHub Releases (the install guide shows how to check them), or build it from the source with Rust 1.95 or later:
$ cargo install --locked --git https://github.com/AlixANNERAUD/nanoflash nanoflash-cli
Describe the flash of the board in a layout file. It gives the flash size and the partitions.
nanoflash checks their alignment, overlap and size, and places a partition without an offset
after the one before it:
# layouts/esp32-s3-8mb.toml
[]
= "8 MiB"
[[]]
= "bootloader"
= "bootloader"
= 0x0
= "32 KiB"
[[]]
= "partition-table"
= "partition-table"
= 0x8000
= "4 KiB"
[[]]
= "application"
= "firmware"
= "64 KiB" # no offset: the first 64 KiB boundary after the table, 0x10000
= "3 MiB"
Describe the board in a manifest that names its layout and images:
# boards/esp32-s3.toml
[[]]
= "esp32-s3-devkitc"
= "espressif"
= "esp32-s3"
= "../layouts/esp32-s3-8mb.toml"
= [{ = 0x303a, = 0x1001 }]
[[]]
= "bootloader"
= "../build/bootloader.bin"
[[]]
= "application"
= "../build/application.bin"
Then flash it:
$ nanoflash flash --board boards/esp32-s3.toml
connecting
writing at 0x0
writing at 0x8000
writing at 0x10000
verifying
resetting
flashed esp32-s3-devkitc (esp32-s3, 8 MiB)
0x0 bootloader 21 KiB
0x8000 partition-table 3 KiB
0x10000 application 812 KiB
verified
nanoflash found the port, generated the partition table from the layout, wrote and verified every
image. nanoflash monitor shows the serial output, and runner = "nanoflash run" in
.cargo/config.toml makes cargo run do both. The first
tutorial walks through a
full example.
Supported boards
| Family | Boards and chips | Protocol |
|---|---|---|
| Espressif | ESP32, ESP32-S2, ESP32-S3, ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-H2, ESP32-P4 | ROM loader |
| Arduino SAM-BA | Nano 33 BLE (nRF52840), SAMD21 boards such as the MKR WiFi 1010 | SAM-BA |
| Arduino AVR | Uno, Nano, Pro Mini (ATmega328P) | STK500v1 |
| Arduino AVR | Mega 2560 (ATmega2560) | STK500v2 |
| Arduino AVR | Leonardo, Micro, Pro Micro (ATmega32U4) | AVR109 |
USB DFU, UF2, CMSIS-DAP and Nordic serial DFU come next. See supported boards and protocols.
Flash from the browser
The flasher page flashes a board from a manifest URL or from files on your computer, in Chrome, Edge or Opera, with nothing to install. To put a flash button on your own page:
Documentation
The full guide lives at https://alixanneraud.github.io/nanoflash/:
- Tutorials: flash your first ESP32-S3, flash and monitor a Nano 33 BLE with cargo run, add a flash button to a web page.
- How-to guides: install, write a layout, write a board manifest, flash a board, erase, monitor, decode defmt, use the Cargo runner, generate memory.x, migrate from esptool, bossac or avrdude.
- Reference: layout file, board manifest, command line, errors, library, browser API.
- Explanation: how nanoflash works, checks before the first erase, growable partitions, design decisions, prior art.
Its source is in docs/src.
Status
Layout checks, the table writers and flashing work natively and in the browser. The monitor and the Cargo runner work in the command. Flashing is tested against recorded transcripts, Espressif's QEMU, arduino/BOSSA's emulated SAM-BA bootloader and the Arduino bootloaders emulated by simavr. The release workflow attaches the binaries of the command to its GitHub releases. The crates are not on crates.io yet, and the npm package is not on npm yet.
Contributing
Issues and pull requests are welcome. Commits follow Conventional
Commits. See develop and
contribute and AGENTS.md.
Licence
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.