arch/arm/rp23xx: add on-chip flash LittleFS (MTD) support#19255
arch/arm/rp23xx: add on-chip flash LittleFS (MTD) support#19255ricardgb wants to merge 1 commit into
Conversation
|
@ricardgb I am doubting this is the correct way to setup the mtd on flash for the rp2350. Normally I would expect the mtd to be setup for the whole flash and then to do some partitioning on top of that, not set it up for only a part. If you later want to do some firmware upgrade you also want to have the nuttx part avalable (at e.g. /ota0). Also I think you should always specify the length of the data partition. So I think there should be 2 parts in the config: 1. Enable mtd_flash support, 2. Enable a mtd_flash data partition (depending on mtd_flash support) with specified mountpoint, offset and size. |
You're right — this should be a whole-flash MTD with mtd_partition() on top, not a pre-offset partial device, so the NuttX/OTA region stays addressable (e.g. /dev/rpflash, /ota0). |
linguini1
left a comment
There was a problem hiding this comment.
Waiting for consensus about fully generated PRs.
@linguini1 whether this is fully generated or not doesn't matter. The PR is clean, and the author is willing to do changes to improve it. Yes the PR description is too verbose, but at least it gives a good background for reviewing. |
I beg to differ. It's not that the PR description itself is the issue, it's that we would be setting a precedent as a project that we accept entirely agent written PRs into the kernel. I am against that, and I know there are others who are against it, which is why I opened a discussion on the mailing list so we could gather feedback. The major issue here is that there is no guarantee that largely unaltered LLM output is compatible with our open source licensing. |
dfe513a to
58642bb
Compare
58642bb to
8922959
Compare
This is now done, thanks |
8922959 to
bc1583e
Compare
|
|
||
| if (erase) | ||
| { | ||
| g_rom.flash_range_erase(addr, count, FLASH_LARGE_BLOCK, |
There was a problem hiding this comment.
Are you sure this is correct? It seems strange to use FLASH_LARGE_BLOCK.
There was a problem hiding this comment.
It's correct — this mirrors the Pico SDK's own flash_range_erase(), which calls the bootrom with exactly these arguments: flash_range_erase_func(flash_offs, count, FLASH_BLOCK_SIZE, FLASH_BLOCK_ERASE_CMD), where FLASH_BLOCK_SIZE is (1u << 16) = 65536 and FLASH_BLOCK_ERASE_CMD is 0xD8 (pico-sdk hardware_flash/flash.c).
The 3rd/4th args are the geometry of the optional large block-erase: the bootrom issues the 0xD8 64 KiB block erase only for 64 KiB-aligned 64 KiB runs and falls back to the 4 KiB sector erase (0x20) for anything smaller or unaligned — so it's always safe, including here, where each call erases a single 4 KiB block and therefore always takes the 4 KiB path.
The only oddity is naming: this driver already uses FLASH_BLOCK_SIZE for its 4 KiB MTD erase unit, so the 64 KiB value is named FLASH_LARGE_BLOCK to avoid the clash. I can add a short comment noting the Pico SDK correspondence if that's clearer.
|
please squash into one patch @ricardgb |
Add an MTD driver over the RP2350's on-chip QSPI flash, registered as a whole-chip device (/dev/rpflash) so the NuttX image / OTA region stays addressable; a bounded data partition (/dev/rpdata) is carved out with mtd_partition() and a persistent read/write LittleFS is mounted on it via the common board bringup. The driver uses the RP2350 bootrom flash programming functions. The erase/program routine (do_flash_op) must not be fetched from flash while XIP is disabled, so it is placed in ".time_critical.flash_mtd", which the RP2350 board linker scripts relocate into RAM. It runs with interrupts disabled, one 4 KiB block per critical section, so a large erase (e.g. a LittleFS format) never holds interrupts off for long or faults on an XIP-cache miss. Reads go through the cached XIP window -- freshness is guaranteed because do_flash_op() calls the bootrom flash_flush_cache() after every operation. The per-operation critical section provides all the hardware atomicity the driver needs; serializing whole multi-block operations against concurrent callers is the consumer/filesystem's responsibility under the usual MTD contract, so the driver holds no mutex (reads are a plain XIP memcpy). Enabled with CONFIG_RP23XX_FLASH_MTD (off by default); the data partition offset/size and mount point are configurable. A blank or corrupt filesystem is a non-fatal, logged condition (format once from NSH with 'mount -t littlefs -o autoformat /dev/rpdata /data') so it never aborts the rest of board bringup. Developed with Claude Code (Anthropic's agentic coding tool) and validated on a Raspberry Pi Pico 2 W: format, read/write, persistence across an unmount/remount and a power-cycle, and loading and executing a code image from the LittleFS. Signed-off-by: Ricard Rosson <ricard@groundbits.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
62a675e to
d8c8805
Compare
|
Squashed into a single commit ( |
Summary
Adds an on-chip flash LittleFS for the RP2350 (rp23xx). A new MTD driver (
rp23xx_flash_mtd.c) is created over the region of the QSPI flash that lies beyond the NuttX image, and the common board bringup mounts a LittleFS on it for persistent local storage. It uses the RP2350 bootrom flash programming functions.Design notes:
do_flash_op) runs from RAM (.ram_code) with interrupts disabled and XIP exited during the operation; the QMI window‑1 (CS1) registers thatflash_exit_xip()disturbs on the RP2350 are saved/restored. Erase is chunked one 4 KiB block per critical section to bound the interrupts‑off window.0x10000000) — the same alias the CPU executes from; freshness after a program/erase is guaranteed becausedo_flash_op()calls the bootromflash_flush_cache().CONFIG_RP23XX_FLASH_FILE_SYSTEM). Region offset/size and mount point are Kconfig‑configurable.mount -t littlefs -o autoformat /dev/rpflash /data.Impact
arch/arm/src/rp23xx/rp23xx_flash_mtd.{c,h}.Make.defs/CMakeLists.txt(compiled only underCONFIG_RP23XX_FLASH_FILE_SYSTEM), archKconfig(new options), common bringup (mount block, guarded). No behaviour change when the option is off (the default).Testing
raspberrypi-pico-2:nsh+CONFIG_RP23XX_FLASH_FILE_SYSTEM=y— the driver and bringup compile cleanly;nxstyleclean on all changed files./dataauto-mounts and the contents persist.🤖 Generated with Claude Code