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

Erase the flash

By default, flash erases only the regions that it writes, rounded to the erase unit. Data partitions such as NVS or storage keep their content, except on the SAMD21.

Erase one partition before writing

Add an erase entry to the board of the manifest:

[[board.erase]]
partition = "nvs"

Or give a region:

[[board.erase]]
offset = 0x9000
size = "24 KiB"

Erase entries are checked with the images, before anything is erased. On the SAMD21, an erase entry must end at the end of the flash. On the Mega 2560, it must start at 0x0, unless --erase-all is given.

To reset otadata on Espressif, list an erase entry for its partition, or an image for it. nanoflash does not initialise otadata by itself.

Erase the whole flash

$ nanoflash flash --board boards/esp32-s3.toml --erase-all

--erase-all erases the flash first, from the lowest offset that the bootloader writes to the end:

BootloaderWhat --erase-all erases
Espressif ROM loaderThe whole flash.
SAM-BA, Nano 33 BLEFrom 0x10000 to the end, with 0xFF pages. The bootloader stays.
SAM-BA, SAMD21From 0x2000 to the end. The bootloader stays.
AVRPages programmed with 0xFF up to where the bootloader starts, or up to the bootloader partition of the layout when it starts lower.

In the browser, pass eraseAll: true to prepared.flash, or set the erase-all attribute of <nanoflash-button>. A manifest with prompt-erase = true makes the button offer a checkbox.

Why the SAMD21 erases more

The SAMD21 bootloader erases from the lowest written address to the end of the flash, data partitions included. What flash erases describes this and the other bootloaders.