Skip to content

Commit 50637ff

Browse files
committed
extmod/vfs_rom: Add VfsRom filesystem object.
This commit defines a new ROMFS filesystem for storing read-only files that can be memory mapped, and a new VfsRom driver. Files opened from this filesystem support the buffer protocol. This allows naturally getting the memory-mapped address of the file using: - memoryview(file) - uctypes.addressof(file) Furthermore, if these files are .mpy files then their content can be referenced in-place when importing. Such imports take up a lot less RAM than importing from a normal filesystem. This is essentially dynamically frozen .mpy files, building on the revamped v6 .mpy file format. Signed-off-by: Damien George <[email protected]>
1 parent 4729a89 commit 50637ff

File tree

7 files changed

+639
-0
lines changed

7 files changed

+639
-0
lines changed

extmod/extmod.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ set(MICROPY_SOURCE_EXTMOD
5858
${MICROPY_EXTMOD_DIR}/vfs_fat_diskio.c
5959
${MICROPY_EXTMOD_DIR}/vfs_fat_file.c
6060
${MICROPY_EXTMOD_DIR}/vfs_lfs.c
61+
${MICROPY_EXTMOD_DIR}/vfs_rom.c
62+
${MICROPY_EXTMOD_DIR}/vfs_rom_file.c
6163
${MICROPY_EXTMOD_DIR}/vfs_posix.c
6264
${MICROPY_EXTMOD_DIR}/vfs_posix_file.c
6365
${MICROPY_EXTMOD_DIR}/vfs_reader.c

extmod/extmod.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ SRC_EXTMOD_C += \
6161
extmod/vfs_fat_diskio.c \
6262
extmod/vfs_fat_file.c \
6363
extmod/vfs_lfs.c \
64+
extmod/vfs_rom.c \
65+
extmod/vfs_rom_file.c \
6466
extmod/vfs_posix.c \
6567
extmod/vfs_posix_file.c \
6668
extmod/vfs_reader.c \

extmod/modvfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "extmod/vfs_fat.h"
3333
#include "extmod/vfs_lfs.h"
3434
#include "extmod/vfs_posix.h"
35+
#include "extmod/vfs_rom.h"
3536

3637
#if !MICROPY_VFS
3738
#error "MICROPY_PY_VFS requires MICROPY_VFS"
@@ -51,6 +52,9 @@ static const mp_rom_map_elem_t vfs_module_globals_table[] = {
5152
#if MICROPY_VFS_LFS2
5253
{ MP_ROM_QSTR(MP_QSTR_VfsLfs2), MP_ROM_PTR(&mp_type_vfs_lfs2) },
5354
#endif
55+
#if MICROPY_VFS_ROM
56+
{ MP_ROM_QSTR(MP_QSTR_VfsRom), MP_ROM_PTR(&mp_type_vfs_rom) },
57+
#endif
5458
#if MICROPY_VFS_POSIX
5559
{ MP_ROM_QSTR(MP_QSTR_VfsPosix), MP_ROM_PTR(&mp_type_vfs_posix) },
5660
#endif

0 commit comments

Comments
 (0)