extmod/modvfs: Add vfs.rom_ioctl function and its ioctl constants.

This is a generic interface to allow querying and modifying the read-only
memory area of a device, if it has such an area.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-11-15 12:57:34 +11:00
parent 9dd4cef814
commit 89e6c58c80
5 changed files with 29 additions and 0 deletions

View File

@@ -38,11 +38,18 @@
#error "MICROPY_PY_VFS requires MICROPY_VFS"
#endif
#if MICROPY_VFS_ROM_IOCTL
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_vfs_rom_ioctl_obj, 1, 4, mp_vfs_rom_ioctl);
#endif
static const mp_rom_map_elem_t vfs_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_vfs) },
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
#if MICROPY_VFS_ROM_IOCTL
{ MP_ROM_QSTR(MP_QSTR_rom_ioctl), MP_ROM_PTR(&mp_vfs_rom_ioctl_obj) },
#endif
#if MICROPY_VFS_FAT
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
#endif

View File

@@ -52,6 +52,13 @@
#define MP_BLOCKDEV_IOCTL_BLOCK_SIZE (5)
#define MP_BLOCKDEV_IOCTL_BLOCK_ERASE (6)
// Constants for vfs.rom_ioctl() function.
#define MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS (1) // rom_ioctl(1)
#define MP_VFS_ROM_IOCTL_GET_SEGMENT (2) // rom_ioctl(2, <id>)
#define MP_VFS_ROM_IOCTL_WRITE_PREPARE (3) // rom_ioctl(3, <id>, <len>)
#define MP_VFS_ROM_IOCTL_WRITE (4) // rom_ioctl(4, <id>, <offset>, <buf>)
#define MP_VFS_ROM_IOCTL_WRITE_COMPLETE (5) // rom_ioctl(5, <id>)
// At the moment the VFS protocol just has import_stat, but could be extended to other methods
typedef struct _mp_vfs_proto_t {
mp_import_stat_t (*import_stat)(void *self, const char *path);
@@ -122,4 +129,12 @@ MP_DECLARE_CONST_FUN_OBJ_1(mp_vfs_rmdir_obj);
MP_DECLARE_CONST_FUN_OBJ_1(mp_vfs_stat_obj);
MP_DECLARE_CONST_FUN_OBJ_1(mp_vfs_statvfs_obj);
#if MICROPY_VFS_ROM_IOCTL
// When MICROPY_VFS_ROM_IOCTL is enabled a port must define the following function.
// This is a generic interface to allow querying and modifying the user-accessible,
// read-only memory area of a device, if it is configured with such an area.
// Supported ioctl commands are given by MP_VFS_ROM_IOCTL_xxx.
mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args);
#endif
#endif // MICROPY_INCLUDED_EXTMOD_VFS_H

View File

@@ -64,6 +64,7 @@
#define MICROPY_PY_MACHINE_PIN_BASE (1)
#define MICROPY_VFS (1)
#define MICROPY_VFS_ROM (1)
#define MICROPY_VFS_ROM_IOCTL (0)
// type definitions for the specific machine

View File

@@ -123,3 +123,4 @@
#define MICROPY_PY_MACHINE_PIN_BASE (1)
#define MICROPY_VFS_ROM (1)
#define MICROPY_VFS_ROM_IOCTL (0)

View File

@@ -1006,6 +1006,11 @@ typedef double mp_float_t;
#define MICROPY_VFS_WRITABLE (1)
#endif
// Whether to enable the mp_vfs_rom_ioctl C function, and vfs.rom_ioctl Python function
#ifndef MICROPY_VFS_ROM_IOCTL
#define MICROPY_VFS_ROM_IOCTL (MICROPY_VFS_ROM)
#endif
// Support for VFS POSIX component, to mount a POSIX filesystem within VFS
#ifndef MICROPY_VFS_POSIX
#define MICROPY_VFS_POSIX (0)