From c7edaabc9d6c99b03530d8f56a77c94990bf6c80 Mon Sep 17 00:00:00 2001 From: Vladimir Smitka Date: Sat, 29 Aug 2026 14:36:32 +0000 Subject: [PATCH] zephyr-cp: size nvm and storage to a whole erase block on RP2040/RP2350 Both partitions are 0x800 on the five RP2040 and RP2350 boards, but the erase block on those chips is 4096. common_hal_nvm_bytearray_set_bytes takes its page size from the flash device, so it asks flash_area_read for 4096 bytes out of a 2048-byte area; flash_area_read bounds-checks that and returns -EINVAL, and the write fails. Were it to get past that, the following flash_area_erase of a full page would take storage_partition with it. Measured on a picopad running zephyr-cp: len(microcontroller.nvm) is 2048 and nvm[0:4] = b"ABCD" raises RuntimeError: Unable to write to nvm. The same code on the raspberrypi port, where nvm is a full 4096, writes and reads back fine. Both partitions grow to one erase block, which shifts circuitpy_partition 4 KB up. The filesystem moves with it, so a board updating to this comes up with an empty CIRCUITPY drive and whatever was on it is gone. --- .../adafruit/feather_rp2040_zephyr/board.overlay | 10 +++++----- .../raspberrypi/rpi_pico2_w_zephyr/board.overlay | 10 +++++----- .../boards/raspberrypi/rpi_pico2_zephyr/board.overlay | 10 +++++----- .../boards/raspberrypi/rpi_pico_w_zephyr/board.overlay | 10 +++++----- .../boards/raspberrypi/rpi_pico_zephyr/board.overlay | 10 +++++----- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ports/zephyr-cp/boards/adafruit/feather_rp2040_zephyr/board.overlay b/ports/zephyr-cp/boards/adafruit/feather_rp2040_zephyr/board.overlay index 10cc674a66a..2c31260a0a4 100644 --- a/ports/zephyr-cp/boards/adafruit/feather_rp2040_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/adafruit/feather_rp2040_zephyr/board.overlay @@ -23,19 +23,19 @@ nvm_partition: partition@180000 { compatible = "zephyr,mapped-partition"; label = "nvm"; - reg = <0x180000 0x800>; + reg = <0x180000 0x1000>; }; - storage_partition: partition@180800 { + storage_partition: partition@181000 { compatible = "zephyr,mapped-partition"; label = "storage"; - reg = <0x180800 0x800>; + reg = <0x181000 0x1000>; }; - circuitpy_partition: partition@181000 { + circuitpy_partition: partition@182000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x181000 (DT_SIZE_M(8) - 0x181000)>; + reg = <0x182000 (DT_SIZE_M(8) - 0x182000)>; }; }; }; diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.overlay b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.overlay index c35cb42519a..7c097fbec31 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.overlay @@ -13,19 +13,19 @@ nvm_partition: partition@180000 { compatible = "zephyr,mapped-partition"; label = "nvm"; - reg = <0x180000 0x800>; + reg = <0x180000 0x1000>; }; - storage_partition: partition@180800 { + storage_partition: partition@181000 { compatible = "zephyr,mapped-partition"; label = "storage"; - reg = <0x180800 0x800>; + reg = <0x181000 0x1000>; }; - circuitpy_partition: partition@181000 { + circuitpy_partition: partition@182000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x181000 (DT_SIZE_M(4) - 0x181000)>; + reg = <0x182000 (DT_SIZE_M(4) - 0x182000)>; }; }; }; diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_zephyr/board.overlay b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_zephyr/board.overlay index c35cb42519a..7c097fbec31 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_zephyr/board.overlay @@ -13,19 +13,19 @@ nvm_partition: partition@180000 { compatible = "zephyr,mapped-partition"; label = "nvm"; - reg = <0x180000 0x800>; + reg = <0x180000 0x1000>; }; - storage_partition: partition@180800 { + storage_partition: partition@181000 { compatible = "zephyr,mapped-partition"; label = "storage"; - reg = <0x180800 0x800>; + reg = <0x181000 0x1000>; }; - circuitpy_partition: partition@181000 { + circuitpy_partition: partition@182000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x181000 (DT_SIZE_M(4) - 0x181000)>; + reg = <0x182000 (DT_SIZE_M(4) - 0x182000)>; }; }; }; diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.overlay b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.overlay index f1228e10138..bc4c3da66fb 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.overlay @@ -23,19 +23,19 @@ nvm_partition: partition@180000 { compatible = "zephyr,mapped-partition"; label = "nvm"; - reg = <0x180000 0x800>; + reg = <0x180000 0x1000>; }; - storage_partition: partition@180800 { + storage_partition: partition@181000 { compatible = "zephyr,mapped-partition"; label = "storage"; - reg = <0x180800 0x800>; + reg = <0x181000 0x1000>; }; - circuitpy_partition: partition@181000 { + circuitpy_partition: partition@182000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x181000 (DT_SIZE_M(2) - 0x181000)>; + reg = <0x182000 (DT_SIZE_M(2) - 0x182000)>; }; }; }; diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_zephyr/board.overlay b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_zephyr/board.overlay index 16b3251df5a..c09c600461d 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_zephyr/board.overlay @@ -24,19 +24,19 @@ nvm_partition: partition@180000 { compatible = "zephyr,mapped-partition"; label = "nvm"; - reg = <0x180000 0x800>; + reg = <0x180000 0x1000>; }; - storage_partition: partition@180800 { + storage_partition: partition@181000 { compatible = "zephyr,mapped-partition"; label = "storage"; - reg = <0x180800 0x800>; + reg = <0x181000 0x1000>; }; - circuitpy_partition: partition@181000 { + circuitpy_partition: partition@182000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x181000 (DT_SIZE_M(2) - 0x181000)>; + reg = <0x182000 (DT_SIZE_M(2) - 0x182000)>; }; }; };