micropython/ports/nrf/modules/scripts/_boot.py
robert-hh 610552010d nrf: Add support for VfsRom filesystem.
The implementation uses the object based capabilities, which avoids
complication about different flash block sizes.  The ROM partition is
placed between the text and writable filesystem sections, and the latter
size is unchanged.  VfsRom sizes are:
- NRF51x22: 12K
- NRF52832: 128K
- NRF52840: 256K
- NRF9160:  256K

Use frozen `_boot.py` to set up and mount the filesystem, replacing a mix
of C-Code and Python code.  The mkfs part has been simplified to save code.

Tested with Microbit and Arduino Nano Connect.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: robert-hh <robert@hammelrath.com>
2026-01-02 15:28:02 +11:00

29 lines
566 B
Python

def setup_fs():
import gc
import vfs
import sys
import nrf
import os
fs_type = getattr(vfs, "VfsLfs2", getattr(vfs, "VfsLfs1", getattr(vfs, "VfsFat", None)))
try:
bdev = nrf.Flash()
vfs.mount(bdev, "/flash")
except:
if fs_type is not None:
try:
fs_type.mkfs(bdev)
vfs.mount(bdev, "/flash")
except:
return
os.chdir("/flash")
sys.path.append("/flash")
sys.path.append("/flash/lib")
gc.collect()
setup_fs()
del setup_fs