diff options
| author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2024-01-24 09:08:29 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-04-03 15:08:58 +1100 |
| commit | b33b9f81217bb1521138a8064d1d1bee3eb49e0f (patch) | |
| tree | 888d13e0a67d6ce6ee0f0e07803df306d53a7965 /tools/codeformat.py | |
| parent | f96417dbf28617c533e4f2e65c65d1ed11f089fa (diff) | |
stm32/main: Catch and report corrupted lfs filesystem at startup.
On stm32, the startup code attempts to mount the configured filesystem. If
there is an existing littlefs filesystem that's suitable corrupted it's
possible for the reported blocksize to be incorrect here:
uint32_t block_size = lfs2_fromle32(superblock->block_size);
This `block_size` (which is read from the filesystem iteself) is used to
create the len argument passed to `pyb_flash_make_new()`. In that function
the len arg is validated to be a mutliple of the underlying hardware block
size, as well as not bigger than the physical flash. Any failure is raised
as a ValueError. This exception is not caught currently in main, it flows
up to the high level assert / startup failure.
As this occurs before `boot.py` is run, the users (potentially frozen)
application code doesn't have any opportunity to detect and handle the
issue.
This commit adds a helper function which attempts to create a block device,
and on error returns `None` instead of raising an exception. Using this in
main means that a potentially corrupt filesystem will simply remain
unmounted, and the application can handle the issue safely.
The fix here also handles the case where the littlefs filesystem is valid
but the autodetection code (which detects the filesystem size) does not
work correctly. In that case it will retry mounting the filesystem using
the whole size of the block device.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Diffstat (limited to 'tools/codeformat.py')
0 files changed, 0 insertions, 0 deletions
