nuttx-apps/examples/nxflatxip
Marco Casaroli 2492317f15 examples/nxflatxip: Run an NXFLAT module in place out of xipfs.
The point of a writable execute-in-place file system is that a module can
arrive after the firmware was built and still run without being copied into
RAM.  This demonstrates exactly that, end to end: it writes an NXFLAT module
into xipfs the way a download would, declaring the size up front so the
extent is exact, checks the file system can hand out a real flash pointer
for it, and runs two instances concurrently.

Both instances report the address of their own text and of their stack.  The
text address is the same in both and is inside the flash window -- it is the
address the file occupies on the media -- while the stacks differ.  While
they run, the extent carries one pin per instance, which is what stops the
defragmenter relocating code that is executing.

Two subcommands cover the file system rather than the module.  bench times a
bulk read out of the mapped flash before and after a write, which on the
RP2350 is the cost of whichever path the driver used to restore XIP.  defrag
fills the volume, deletes every other file until an allocation genuinely
cannot be satisfied, compacts, retries the same allocation, then verifies
every relocated file byte for byte and again after a remount, printing a
block map at each step.

The module has neither static data nor string constants, and reports through
a callback into the firmware instead of formatting its own output.  That is
not stylistic: the ldnxflat in circulation resolves the GOT entries for .bss
objects into the import table, and drops the addend when it resolves the
PC-relative references to .rodata, so a module using either quietly computes
wrong addresses.  The comment in module/xipmod.c records both.  The callback
also exercises the other direction of the interface, firmware code entered
with the module's data base still live in r10.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-28 16:47:49 +08:00
..
module examples/nxflatxip: Run an NXFLAT module in place out of xipfs. 2026-07-28 16:47:49 +08:00
.gitignore examples/nxflatxip: Run an NXFLAT module in place out of xipfs. 2026-07-28 16:47:49 +08:00
CMakeLists.txt examples/nxflatxip: Run an NXFLAT module in place out of xipfs. 2026-07-28 16:47:49 +08:00
Kconfig examples/nxflatxip: Run an NXFLAT module in place out of xipfs. 2026-07-28 16:47:49 +08:00
Make.defs examples/nxflatxip: Run an NXFLAT module in place out of xipfs. 2026-07-28 16:47:49 +08:00
Makefile examples/nxflatxip: Run an NXFLAT module in place out of xipfs. 2026-07-28 16:47:49 +08:00
nxflatxip_main.c examples/nxflatxip: Run an NXFLAT module in place out of xipfs. 2026-07-28 16:47:49 +08:00