zephyr-cp: size nvm and storage to a whole erase block on RP2040/RP2350 - #11272
Open
lynt-smitka wants to merge 1 commit into
Open
zephyr-cp: size nvm and storage to a whole erase block on RP2040/RP2350#11272lynt-smitka wants to merge 1 commit into
lynt-smitka wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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...