Skip to content

zephyr-cp: size nvm and storage to a whole erase block on RP2040/RP2350 - #11272

Open
lynt-smitka wants to merge 1 commit into
adafruit:mainfrom
MakerClassCZ:zephyr-cp-nvm-erase-block
Open

zephyr-cp: size nvm and storage to a whole erase block on RP2040/RP2350#11272
lynt-smitka wants to merge 1 commit into
adafruit:mainfrom
MakerClassCZ:zephyr-cp-nvm-erase-block

Conversation

@lynt-smitka

Copy link
Copy Markdown

nvm_partition and storage_partition are 0x800 on all five RP2040/RP2350 boards, but the erase block on those chips is 4096.

common_hal_nvm_bytearray_set_bytes reads a whole erase page before modifying it, and takes that page size from the flash device rather than the partition, so it asks flash_area_read for 4096 bytes out of a 2048-byte area. flash_area_read bounds-checks and returns -EINVAL.

Measured on a picopad running zephyr-cp:

    >>> len(microcontroller.nvm)
    2048
    >>> microcontroller.nvm[0:4] = b"ABCD"
    RuntimeError: Unable to write to nvm.

The same test 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...

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant