From 78b217d250610c1b514c41286562226438ac053f Mon Sep 17 00:00:00 2001 From: Vladimir Smitka Date: Sat, 29 Aug 2026 14:36:32 +0000 Subject: [PATCH 1/2] 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 f159dfbe29f..acb3083096d 100644 --- a/ports/zephyr-cp/boards/adafruit/feather_rp2040_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/adafruit/feather_rp2040_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(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 16b3251df5a..c09c600461d 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 @@ -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)>; }; }; }; 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)>; }; }; }; From fdb56f994b5e219d319044bb32ca85e884f17148 Mon Sep 17 00:00:00 2001 From: Vladimir Smitka Date: Wed, 2 Sep 2026 15:50:32 +0000 Subject: [PATCH 2/2] zephyr-cp: put nvm and circuitpy where ports/raspberrypi has them After the previous commit the partitions sat at 0x180000 (nvm), 0x181000 (storage) and 0x182000 (circuitpy) on all five boards, which matches neither port. ports/raspberrypi derives both from CIRCUITPY_FIRMWARE_SIZE: nvm sits at that address, the drive 4 KB above it. Three of the boards take the 1020K default, so nvm at 0xff000 and CIRCUITPY at 0x100000; pico_w and pico2_w set 1536K, so 0x180000 and 0x181000. Use those addresses, and take storage out of the code partition rather than pushing circuitpy up, so a board keeps both its filesystem and its nvm contents across a switch between the two ports. That leaves the W boards' nvm and circuitpy where they already were; the three non-W boards move circuitpy down from 0x181000, which grows their drive by 516 KB (rpi_pico: 508 KB -> 1 MB) and costs one empty CIRCUITPY on update. The code partitions are just under 1016 KB and 1532 KB, against images of 490 KB (rpi_pico) and 1042 KB (rpi_pico_w). Verified on an RP2040 with 2 MB flash, both layouts and both directions, against the 10.3.0 raspberry_pi_pico and raspberry_pi_pico_w release images: CIRCUITPY keeps its files and nvm keeps its contents across every switch. --- .../feather_rp2040_zephyr/board.overlay | 18 +++++++++--------- .../rpi_pico2_w_zephyr/board.overlay | 18 +++++++++--------- .../raspberrypi/rpi_pico2_zephyr/board.overlay | 18 +++++++++--------- .../rpi_pico_w_zephyr/board.overlay | 18 +++++++++--------- .../raspberrypi/rpi_pico_zephyr/board.overlay | 18 +++++++++--------- 5 files changed, 45 insertions(+), 45 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 acb3083096d..71c30f06406 100644 --- a/ports/zephyr-cp/boards/adafruit/feather_rp2040_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/adafruit/feather_rp2040_zephyr/board.overlay @@ -17,26 +17,26 @@ code_partition: partition@100 { compatible = "zephyr,mapped-partition"; label = "code-partition"; - reg = <0x100 (0x180000 - 0x100)>; + reg = <0x100 (0xfe000 - 0x100)>; read-only; }; - nvm_partition: partition@180000 { + storage_partition: partition@fe000 { compatible = "zephyr,mapped-partition"; - label = "nvm"; - reg = <0x180000 0x1000>; + label = "storage"; + reg = <0xfe000 0x1000>; }; - storage_partition: partition@181000 { + nvm_partition: partition@ff000 { compatible = "zephyr,mapped-partition"; - label = "storage"; - reg = <0x181000 0x1000>; + label = "nvm"; + reg = <0xff000 0x1000>; }; - circuitpy_partition: partition@182000 { + circuitpy_partition: partition@100000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x182000 (DT_SIZE_M(8) - 0x182000)>; + reg = <0x100000 (DT_SIZE_M(8) - 0x100000)>; }; }; }; 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 7c097fbec31..436cfc83276 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 @@ -6,26 +6,26 @@ code_partition: partition@0 { compatible = "zephyr,mapped-partition"; label = "code-partition"; - reg = <0x0 0x180000>; + reg = <0x0 0x17f000>; read-only; }; - nvm_partition: partition@180000 { + storage_partition: partition@17f000 { compatible = "zephyr,mapped-partition"; - label = "nvm"; - reg = <0x180000 0x1000>; + label = "storage"; + reg = <0x17f000 0x1000>; }; - storage_partition: partition@181000 { + nvm_partition: partition@180000 { compatible = "zephyr,mapped-partition"; - label = "storage"; - reg = <0x181000 0x1000>; + label = "nvm"; + reg = <0x180000 0x1000>; }; - circuitpy_partition: partition@182000 { + circuitpy_partition: partition@181000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x182000 (DT_SIZE_M(4) - 0x182000)>; + reg = <0x181000 (DT_SIZE_M(4) - 0x181000)>; }; }; }; 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 7c097fbec31..a8ce944ab8a 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_zephyr/board.overlay @@ -6,26 +6,26 @@ code_partition: partition@0 { compatible = "zephyr,mapped-partition"; label = "code-partition"; - reg = <0x0 0x180000>; + reg = <0x0 0xfe000>; read-only; }; - nvm_partition: partition@180000 { + storage_partition: partition@fe000 { compatible = "zephyr,mapped-partition"; - label = "nvm"; - reg = <0x180000 0x1000>; + label = "storage"; + reg = <0xfe000 0x1000>; }; - storage_partition: partition@181000 { + nvm_partition: partition@ff000 { compatible = "zephyr,mapped-partition"; - label = "storage"; - reg = <0x181000 0x1000>; + label = "nvm"; + reg = <0xff000 0x1000>; }; - circuitpy_partition: partition@182000 { + circuitpy_partition: partition@100000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x182000 (DT_SIZE_M(4) - 0x182000)>; + reg = <0x100000 (DT_SIZE_M(4) - 0x100000)>; }; }; }; 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 c09c600461d..3130d8dc5aa 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 @@ -17,26 +17,26 @@ code_partition: partition@100 { compatible = "zephyr,mapped-partition"; label = "code-partition"; - reg = <0x100 (0x180000 - 0x100)>; + reg = <0x100 (0x17f000 - 0x100)>; read-only; }; - nvm_partition: partition@180000 { + storage_partition: partition@17f000 { compatible = "zephyr,mapped-partition"; - label = "nvm"; - reg = <0x180000 0x1000>; + label = "storage"; + reg = <0x17f000 0x1000>; }; - storage_partition: partition@181000 { + nvm_partition: partition@180000 { compatible = "zephyr,mapped-partition"; - label = "storage"; - reg = <0x181000 0x1000>; + label = "nvm"; + reg = <0x180000 0x1000>; }; - circuitpy_partition: partition@182000 { + circuitpy_partition: partition@181000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x182000 (DT_SIZE_M(2) - 0x182000)>; + reg = <0x181000 (DT_SIZE_M(2) - 0x181000)>; }; }; }; 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 c09c600461d..bfd690085a7 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_zephyr/board.overlay @@ -17,26 +17,26 @@ code_partition: partition@100 { compatible = "zephyr,mapped-partition"; label = "code-partition"; - reg = <0x100 (0x180000 - 0x100)>; + reg = <0x100 (0xfe000 - 0x100)>; read-only; }; - nvm_partition: partition@180000 { + storage_partition: partition@fe000 { compatible = "zephyr,mapped-partition"; - label = "nvm"; - reg = <0x180000 0x1000>; + label = "storage"; + reg = <0xfe000 0x1000>; }; - storage_partition: partition@181000 { + nvm_partition: partition@ff000 { compatible = "zephyr,mapped-partition"; - label = "storage"; - reg = <0x181000 0x1000>; + label = "nvm"; + reg = <0xff000 0x1000>; }; - circuitpy_partition: partition@182000 { + circuitpy_partition: partition@100000 { compatible = "zephyr,mapped-partition"; label = "circuitpy"; - reg = <0x182000 (DT_SIZE_M(2) - 0x182000)>; + reg = <0x100000 (DT_SIZE_M(2) - 0x100000)>; }; }; };