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

Command line

The nanoflash command checks and writes layouts, flashes boards, builds flash images and shows the serial output of a board. It has these subcommands:

nanoflash layout check [<layout>] [--image <partition>=<file>]... [--manifest <manifest>] [--board-identifier <identifier>] [--flash-size <size>] [--json]
nanoflash layout write <layout> --format espressif|mbr|linker|constants --output <file> [--flash-size <size>] [--json]
nanoflash flash [--board <manifest>] [--port <port>] [--board-identifier <identifier>] [--erase-all] [--no-verify] [--baud-rate <rate>] [--progress <format>] [--json]
nanoflash detect --port <port> [--protocol <protocol>] [--progress <format>] [--json]
nanoflash image build [--board <manifest>] [--board-identifier <identifier>] --output <file> [--fill] [--flash-size <size>] [--json]
nanoflash monitor [--port <port>] [--board <manifest>] [--board-identifier <identifier>] [--baud-rate <rate>] [--raw] [--reset] [--elf <file>] [--progress <format>] [--json]
nanoflash run <image> [--board <manifest>] [--board-identifier <identifier>] [--port <port>] [--erase-all] [--no-verify] [--baud-rate <rate>] [--flash-baud-rate <rate>] [--no-monitor] [--raw] [--progress <format>] [--json]

nanoflash --help and nanoflash <subcommand> --help print the options. nanoflash --version prints the version.

Common behaviour

  • No prompts. --port is required when more than one candidate port exists.
  • Errors go to standard error: each line of the message is printed as error: <line>, and the message has a hint when one helps. Every error message names the partitions and the addresses involved, in 0x hexadecimal.
  • --json prints one JSON document on standard output (one JSON object per line for monitor and run). A bad option with --json prints the bare error as JSON.
  • --progress human|json|quiet reports progress on standard error: one line per stage, one JSON object per event, or nothing. It is quiet with --json unless given.
  • Sizes such as --flash-size take an integer, hexadecimal or a number with a binary unit ("16 MiB").
  • Hidden options record and replay transcripts for the test suite: --record <file> on flash and detect records the session with real hardware, and --replay <file> replays one.
  • An argument that is not Unicode text is an input error on every platform but Unix, where arguments are bytes, as for a path.

Exit codes

CodeMeaning
0Success. Ctrl-C in monitor and run also exits with 0.
1Input error: an option, a file, a layout, a manifest, an image.
2Device or connection error. A device that does not come back to monitor within 30 s.
3Verification failure: the flash does not read back as written.

The board of the Cargo package

--board is optional on flash, image build, monitor and run. Without it, the board is the one that [package.metadata.nanoflash] of the Cargo.toml of the package names, and --board-identifier replaces its board-identifier. layout check without a layout file checks the layout of that board. See Build and cargo features for the keys and how the Cargo.toml is found. monitor works without a board: a Cargo.toml with no metadata is not an error there, unless --board-identifier is given.

nanoflash layout check

Checks a layout and prints the offset, size and headroom of every partition.

OptionMeaning
<layout>The layout file. By default the layout of the board of the Cargo package, or of --manifest.
--image <partition>=<file>An image written to a partition (binary, Intel HEX or ELF), to show its headroom. Repeatable. Conflicts with --manifest.
--manifest <manifest>A board manifest: check the images that it writes. Without a layout file, check the layout of its board. layout check warns when a manifest image of the partition table differs from the generated table.
--board-identifier <identifier>The board of the manifest, when several boards use different layouts. With a layout file, it needs --manifest: without it, the command fails with an input error.
--flash-size <size>Resolve a detect layout for this flash size. Refused for a fixed layout and below the minimum. Images are still checked against the partition sizes on the minimum flash, as flash does, so this option changes only the offsets, sizes and headroom shown.
--jsonPrint one JSON document instead of the table.
$ nanoflash layout check layouts/esp32-s3-8mb.toml
flash 8 MiB (0x800000), unallocated 4 KiB
name             role             offset    end       size      image  headroom
bootloader       bootloader       0x0       0x8000    32 KiB    -      -
partition-table  partition-table  0x8000    0x9000    4 KiB     -      -
nvs              custom           0x9000    0xf000    24 KiB    -      -
application      firmware         0x10000   0x310000  3 MiB     -      -
storage          storage          0x310000  0x800000  5056 KiB  -      -

For a detect layout, the report shows the minimum, adds the minimum and growth columns when a partition grows, and a line that names the partitions that move with the flash size:

$ nanoflash layout check layouts/esp32-s3-detect.toml --flash-size "8 MiB"
flash 8 MiB (0x800000), minimum 4 MiB (0x400000), unallocated 60 KiB
name             role             offset    end       size      minimum  growth     image  headroom
...
storage          storage          0x320000  0x800000  4992 KiB  0 B      +4992 KiB  -      -

nanoflash layout write

Writes a partition table, linker regions or Rust constants for a layout.

OptionMeaning
<layout>The layout file.
--format <format>espressif (binary partition table), mbr (binary master boot record), linker (linker memory regions, text) or constants (Rust constants, text).
--output <file>The file to write.
--flash-size <size>Resolve a detect layout for this flash size. The linker and constants formats refuse any size but the minimum.
--jsonPrint one JSON document instead of a sentence.

See Layout file for the formats.

nanoflash flash

Writes the images of a board to the device on a serial port.

OptionMeaning
--board <manifest>The board manifest (TOML or JSON). By default the board of the Cargo package.
--port <port>The serial port. By default the only one that suits the board.
--board-identifier <identifier>The board of the manifest to flash, when the device cannot tell. By default the one that the Cargo package names.
--erase-allErase the whole flash first, from the lowest offset that the bootloader writes to the end. A protected bootloader stays. On AVR, pages are programmed with 0xFF up to where the bootloader starts.
--no-verifyDo not check what was written (MD5, CRC-16 or read-back).
--baud-rate <rate>The baud rate to flash at. Default 460800 through a UART bridge on an Espressif board. USB-Serial-JTAG and the ESP32-C2 stay at 115200 baud whatever the value (Espressif). On STK500 it is the rate of the bootloader: STK500v1 tries 115200, then 57600; STK500v2 uses 115200 only. SAM-BA and AVR109 ignore it.
--progress <format>human, json or quiet.
--jsonPrint one JSON document instead of sentences.
$ 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

With a layout whose flash size is detected, the warnings come before the report:

$ nanoflash flash --board boards/esp32-s3-detect.toml
...
warning: the chip has 0x800000 bytes of flash, more than the minimum of 0x400000 of the layout, so partitions grew: "storage" from 0xe0000 to 0x4e0000 bytes; the bootloader image must be built for this flash size or with flash size detection
flashed esp32-s3-devkitc-detect (esp32-s3, 8 MiB)

nanoflash detect

Connects to a device and tells what chip it is.

OptionMeaning
--port <port>The serial port. Required.
--protocol <protocol>espressif, samba, stk500v1 (alias arduino), stk500v2 (alias wiring) or avr109, when the USB identity of the device does not tell.
--progress <format>human, json or quiet.
--jsonPrint one JSON document instead of sentences.
$ nanoflash detect --port /dev/ttyACM0
protocol espressif
chip esp32-s3
flash 8 MiB
usb 303a:1001
secure download mode no

On SAM-BA and AVR boards, the output also has the lines writable from <offset> and writable to <offset>, before the usb line. detect resets the board into its application at the end.

nanoflash image build

Merges the images of a board into one flash image, 0xFF between them.

OptionMeaning
--board <manifest>The board manifest. By default the board of the Cargo package.
--board-identifier <identifier>The board of the manifest, when it has several.
--output <file>The file to write.
--fillPad the image to the flash size of the layout: the minimum of a detect layout, or --flash-size.
--flash-size <size>Build a detect layout for this flash size: the partition table is generated for it and the images go where their partitions then are. By default the minimum, because a merged image cannot follow the chip.
--jsonPrint one JSON document instead of a sentence.
$ nanoflash image build --board boards/esp32-s3.toml --fill --output flash.bin
wrote 8388608 bytes to flash.bin

nanoflash monitor

Shows what a board writes to its serial port and sends what you type.

OptionMeaning
--port <port>The serial port. By default the only one that suits the board, else the only USB serial port.
--board <manifest>The board manifest: its USB identities find the port, and --reset uses its protocol and reset sequence. By default the board of the Cargo package, if it names one.
--board-identifier <identifier>The board of the manifest, when it has several.
--baud-rate <rate>The baud rate of the serial output. Default 115200. 1200 is refused for a board whose reset is a 1200-baud touch.
--rawSend each key as the terminal encodes it, without waiting for the end of the line. Standard input must be a terminal. The terminal goes back to its state when the command ends.
--resetReset the board into its application first, through its bootloader. It needs the protocol of the board: pass --board, or use a port with a known USB identity.
--elf <file>Decode the defmt frames of this ELF file in the output. A file with no defmt table, or with the raw encoding, is an input error.
--progress <format>How to report the progress of --reset.
--jsonPrint one JSON object per line of output, with its time.

Behaviour:

  • Notes go to standard error. The output of the board goes to standard output, byte for byte.
  • In line mode (the default), each line of standard input goes to the board with \n at its end. When standard input ends, the monitor goes on showing the output.
  • Ctrl-C quits in both modes, and so does a signal, with exit code 0.
  • After it opens a port, the monitor clears DTR and RTS for an Espressif board and for a port with an unknown USB identity (a UART bridge), and sets DTR for a board with a known AVR or SAM-BA identity.
  • When the device leaves, the monitor waits up to 30 s for the same device and opens it again.
$ nanoflash monitor --board hardware/nano33ble/manifest.toml
monitoring /dev/ttyACM0 at 115200 baud; Ctrl-C quits
connected to /dev/ttyACM0
boot

JSON lines

With --json, standard output has one compact JSON object per line. Each has a timestamp (RFC 3339, UTC, milliseconds).

RecordFields
A line of outputline. "complete": false is added for output that ended without a line feed.
connected eventevent, port.
disconnected eventevent.
error eventevent, errors. A failure is the last line.
A defmt framedefmt: level, message, device_timestamp, location (file, line, module, or null without debug information).
malformed_defmt_frame eventevent.
$ nanoflash monitor --port /dev/ttyACM0 --json
{"timestamp":"2026-11-24T09:30:01.250Z","event":"connected","port":"/dev/ttyACM0"}
{"timestamp":"2026-11-24T09:30:01.412Z","line":"boot"}
{"timestamp":"2026-11-24T09:30:09.870Z","event":"disconnected"}

defmt frames

A frame is shown on its own line as [INFO ] message (file:line). The location is shown only when the ELF file has debug information for the statement. The timestamp of the firmware, if it defines one, comes first. A frame that cannot be decoded is shown as [MALFORMED defmt frame]. See Decode defmt logs and The serial monitor and defmt.

nanoflash run

Flashes an application, then shows what it writes to its serial port: a runner for Cargo.

OptionMeaning
<image>The firmware to flash: the ELF file that Cargo builds, or a binary or Intel HEX image. Options may come before or after it.
--board <manifest>The board manifest. The image replaces the one of its firmware partition. By default the board of the Cargo package.
--board-identifier <identifier>The board of the manifest, when it has several.
--port <port>The serial port. By default the only one that suits the board.
--erase-allAs for flash.
--no-verifyAs for flash.
--baud-rate <rate>The baud rate of the serial output. Default 115200.
--flash-baud-rate <rate>The baud rate to flash at, as --baud-rate of flash, with the same exceptions.
--no-monitorOnly flash. The output is then the output of flash.
--rawAs for monitor. Conflicts with --no-monitor. The command checks for a terminal before it flashes.
--progress <format>How to report the progress of flashing.
--jsonOne JSON document with --no-monitor, else one JSON object per line. The first line is the event flashed with the report of flash --json.

Behaviour:

  • The image replaces the application image of the board. With a layout, this is the image of the one partition with the role firmware (by name or by offset); the image is added when the manifest has none. Without a layout, it is the only image of the board. The new image targets the partition by name, has the absolute path of the file and has no digest, because the file changes at every build.
  • A layout with no firmware partition or with several, a manifest with several images for the firmware partition, and a board without layout that lists no image or several images, are input errors that name the board, the partitions and the offsets.
  • flash resets the board into its application, so the monitor does not reset it again. It opens the application-devices of the board, else the exact USB identity that the port had before flashing, else the path of the port when it has no USB identity, and waits up to 30 s.
  • When the board starts in its bootloader and lists no application-devices, the identity is the one of the bootloader, and the application never matches it: the monitor waits 30 s and fails. List the application-devices of the board to avoid it.
  • When the image is an ELF file with a defmt table, the monitor decodes the defmt frames. When the table cannot be used, run writes a note on standard error and does not decode.
$ nanoflash run firmware.elf --board boards/nano33ble.toml --json
{"timestamp":"2026-11-30T09:30:01.250Z","event":"flashed","report":{"board":"arduino-nano-33-ble",...}}
{"timestamp":"2026-11-30T09:30:03.011Z","event":"connected","port":"/dev/ttyACM0"}
{"timestamp":"2026-11-30T09:30:03.412Z","line":"hello from the sketch"}

cargo nanoflash

cargo-nanoflash is the same command under the name that Cargo looks for to run a subcommand. Cargo runs cargo-nanoflash nanoflash <arguments>. The binary drops the first argument when it is exactly nanoflash, once, then runs the command. Run directly, without that name, it behaves alike. The output, the errors and the exit codes are those of nanoflash, --help, --version and a bad option with --json included, because both binaries call the same function. Cargo sets no variable for a subcommand, so the package is found from the working directory.

cargo nanoflash flash only flashes. It does not build the firmware.