-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rp2: per-board custom memmap_mp.ld to enforce configured flash size #8680
Comments
For similar reasons, it probably wouldn't hurt to add the following to target_link_options(${MICROPY_TARGET} PRIVATE
-Wl,--print-memory-usage
) Producing:
Which gives a much more immediate and intuitive picture of flash usage. |
I was just helping someone on Discord with exactly this issue. As outlined above, the linker is the right place to solve this. Maybe instead of having board-specific |
Also, at the very least we should make this a runtime error and verify that (Edit: we already have this! it's just only in debug builds... https://github.com/micropython/micropython/blob/master/ports/rp2/rp2_flash.c#L83 ) |
I was totally stonewalled by the Pico My approach was to set total flash† and "app" sizes in each board config, preprocess the linker file and try to use the linker symbols to handle everything else. The "app" size would configure how much is deserved for MicroPython - rather than have it be implicitly the remaining flash - and trying to link a binary too large for this reserved space would blow up the build with a linker error. Enabling some variety of the debug feature to catch the overflow on build might be a quick(er) win, though. But that assert check will only prevent the build self-corrupting, and not warn beforehand? † - The total flash size should - in theory at least - be set by the Pico SDK in |
I'm not sure this pertains just to RP2, but I have little experience with other platforms so I'm going to keep the scope narrow unless anyone wants to chime in. That said I think this approach is pretty generic and should be - SDK's willing - portable to other platforms.
The long and short of it is that
ports/rp2/boards/PICO/mpconfigboard.h
specifiesMICROPY_HW_FLASH_STORAGE_BYTES
which - at runtime - is the region allocated to the user-facing filesystem on an RP2-based MicroPython board.This is configurable since boards can have 2MB, 4MB, 8MB and 16MB (and maybe beyond?) of Flash storage.
However this region is not enforced by the
memmap_mp.ld
linker script used to build the RP2 ports.The practical upshot of this is that you can build a MicroPython port with too much stuff baked into it (and oh my do we bake in a lot of stuff) which will happily link and flash but then immediately soft-brick the board it's flashed to. (Turns out MicroPython has some pretty important stuff at the high-end of its binary.)
My proposal is either:
or
memmap_mp.ld
files that are auto-detected and used in place of the port one.The latter would be achieved something like so:
And then
boards/PICO/memmap_mp.ld
would correctly configure the flash size:This ensures that an oversized build (for whatever reason) will fail something like this:
Rather than failing when it's flashed, run and inevitably overwrites something important!
The text was updated successfully, but these errors were encountered: