Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions flash/nuke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ target_link_libraries(flash_nuke
hardware_flash
)

# We use flash command 0x9f to dynamically get the flash size
# If that fails, assume 16Mb
math(EXPR FLASH_SIZE_OVERRIDE "16 * 1024 * 1024" OUTPUT_FORMAT DECIMAL)
target_compile_definitions(flash_nuke PRIVATE
PICO_INCLUDE_FLASH_UTILS=1
PICO_FLASH_SIZE_BYTES=${FLASH_SIZE_OVERRIDE}
)

# It doesn't make sense to run this program from flash. Always build a
# RAM-only binary.
pico_set_binary_type(flash_nuke no_flash)
Expand Down
18 changes: 11 additions & 7 deletions flash/nuke/nuke.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
#include "hardware/flash.h"
#include "pico/bootrom.h"

#define MIN_FLASH_SIZE (1024 * 1024 * 2)

int main() {
uint flash_size_bytes;
#ifndef PICO_FLASH_SIZE_BYTES
#warning PICO_FLASH_SIZE_BYTES not set, assuming 16M
flash_size_bytes = 16 * 1024 * 1024;
#else
flash_size_bytes = PICO_FLASH_SIZE_BYTES;
#endif
uint flash_size_bytes = 0;
uint8_t txbuf[4];
uint8_t rxbuf[4];
txbuf[0] = 0x9f;
flash_do_cmd(txbuf, rxbuf, 4);
flash_size_bytes = 1u << rxbuf[3];
if (flash_size_bytes < MIN_FLASH_SIZE || flash_size_bytes > PICO_FLASH_SIZE_BYTES) {
flash_size_bytes = PICO_FLASH_SIZE_BYTES;
}
flash_range_erase(0, flash_size_bytes);
// Leave an eyecatcher pattern in the first page of flash so picotool can
// more easily check the size:
Expand Down
Loading