The way the filesystem works is:
- In ports/rp2/boards/PICO/mpconfigboard.h we define MICROPY_HW_FLASH_STORAGE_BYTES which is how many bytes of flash to reserve for the "user accessible flash" (i.e. the rp2.Flash object). This is always at the end of the flash, i.e. offset from PICO_FLASH_SIZE_BYTES (which is 2MiB).
- In ports/rp2/rp2_flash.c we define the rp2.Flash object using those two macros.
- In ports/rp2/modules/_boot.py we construct a LittleFS filesystem using the entire rp2.Flash object. The flash object (a block device) provides an ioctl that returns the size, and the filesystem uses that to figure out how much space it has available.
So there are a couple of ways to do this:
- Extend rp2_flash.c to make it work like pyb.Flash (where rather than returning a singleton, you can construct it with any arbitrary offset and length). Then in _boot.py you could just create the filesystem with a smaller Flash object.
- In _boot.py, you could define a class that wraps rp2.Flash and provides the block device interface, mostly passing straight through to rp2.Flash but providing a modified offset and length. Then pass an instance of that to the filesystem instead. (Effectively you're defining a "partition" class).
I like the second approach more I think, and not just because it doesn't involve writing C
The other option would be to just make MICROPY_HW_FLASH_STORAGE_BYTES smaller, and you'd know that there was some reserved space. You could modify rp2_flash.c to offset MICROPY_HW_FLASH_STORAGE_BASE by the amount you shrunk it by, which will force your reserved region to be at the end of flash (and a known size).
More info at https://docs.micropython.org/en/latest/ ... ystem.html