Skip to content

ports/unix,windows: Add embedded romfs support with auto-mount.#43

Draft
andrewleech wants to merge 1 commit intomasterfrom
pr/unix-windows-romfs
Draft

ports/unix,windows: Add embedded romfs support with auto-mount.#43
andrewleech wants to merge 1 commit intomasterfrom
pr/unix-windows-romfs

Conversation

@andrewleech
Copy link
Copy Markdown
Owner

Summary

Adds support for an embedded romfs image linked into the unix/windows binary. With ROMFS_IMG=path/to/romfs.img the image is embedded as a .rodata section via objcopy and registered as a read-only filesystem at startup. Auto-mount at /rom and (when present) prepend to sys.path. If the romfs contains main.py or main.mpy, it is executed in preference to the file-system search.

Also adds a make romfs ROMFS_DIR=... target on both ports for building images via mpremote, and MICROPY_ENABLE_COMPILER=0 guards in unix main.c so the port can be built compiler-less when only frozen .mpy modules are needed.

Testing

Unix build with and without ROMFS_IMG; Windows mingw build with embedded romfs; auto-execution of main.mpy from /rom.

Add support for an embedded romfs image linked directly into the
unix/windows binary. When built with ROMFS_IMG=path/to/romfs.img, the
image is embedded as a .rodata section via objcopy and registered as a
read-only filesystem at startup.

Auto-mount the embedded romfs at /rom and (when present) prepend it to
sys.path. If the romfs contains main.py or main.mpy, it is executed in
preference to the file-system search after startup. The unix port also
gains a 'make romfs ROMFS_DIR=...' target to build a romfs image from a
directory using mpremote.

The same plumbing is added to the windows port (with PE-COFF objcopy
output and a separate vfs_rom_ioctl.c since the Windows variant uses
MICROPY_VFS_ROM_IOCTL_USE_EXTERNAL=1 to avoid pulling the ioctl helper
into main.c).

Also adds MICROPY_ENABLE_COMPILER=0 guards in the unix main.c so the
port can be built without the compiler when only pre-compiled .mpy
modules are needed (relevant when shipping a frozen-only application
binary).

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
@github-actions
Copy link
Copy Markdown

Code size report:

Reference:  extmod/moductypes: Be more defensive with uctypes_struct_agg_size args. [8a56be6]
Comparison: ports/unix,windows: Add embedded romfs support with auto-mount. [merge of af886f8]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64: +1912 +0.223% standard[incl +48(data) +32(bss)]
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@andrewleech andrewleech force-pushed the master branch 7 times, most recently from ce2c0c9 to 9f396bb Compare May 1, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants