stm32/vfs_rom_ioctl: Allow ROMFS configuration to be dynamic.

Options for a board to configure ROMFS are:

- Leave ROMFS disabled, do nothing.

- Enable by defining `MICROPY_HW_ROMFS_ENABLE_PARTx` to 1 and then in the
  linker script define `_micropy_hw_romfs_partX_start` and
  `_micropy_hw_romfs_partX_size`.

- Enable by defining `MICROPY_HW_ROMFS_ENABLE_PARTx` to 1 and also define
  `MICROPY_HW_ROMFS_PARTx_START` and `MICROPY_HW_ROMFS_PARTx_SIZE` which
  can be arbitrary expressions (not necessarily static)

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-04-01 14:31:26 +11:00
parent 2c0240e068
commit 1d83c81756

View File

@@ -36,28 +36,32 @@
#if MICROPY_VFS_ROM_IOCTL #if MICROPY_VFS_ROM_IOCTL
#if MICROPY_HW_ROMFS_ENABLE_PART0 && !defined(MICROPY_HW_ROMFS_PART0_START) #if MICROPY_HW_ROMFS_ENABLE_PART0 && defined(MICROPY_HW_ROMFS_PART0_START)
#define MICROPY_HW_ROMFS_PART0_START (uintptr_t)(&_micropy_hw_romfs_part0_start) #define ROMFS0_DYNAMIC (1)
#define MICROPY_HW_ROMFS_PART0_SIZE (uintptr_t)(&_micropy_hw_romfs_part0_size) static MP_DEFINE_MEMORYVIEW_OBJ(romfs0_obj, 'B', 0, (uintptr_t)-1, (void *)-1);
#elif MICROPY_HW_ROMFS_ENABLE_PART0 && !defined(MICROPY_HW_ROMFS_PART0_START)
#define ROMFS0_DYNAMIC (0)
extern uint8_t _micropy_hw_romfs_part0_start; extern uint8_t _micropy_hw_romfs_part0_start;
extern uint8_t _micropy_hw_romfs_part0_size; extern uint8_t _micropy_hw_romfs_part0_size;
static const MP_DEFINE_MEMORYVIEW_OBJ(romfs0_obj, 'B', 0, (uintptr_t)&_micropy_hw_romfs_part0_size, (void *)&_micropy_hw_romfs_part0_start);
#endif #endif
#if MICROPY_HW_ROMFS_ENABLE_PART1 && !defined(MICROPY_HW_ROMFS_PART1_START) #if MICROPY_HW_ROMFS_ENABLE_PART1 && defined(MICROPY_HW_ROMFS_PART1_START)
#define MICROPY_HW_ROMFS_PART1_START (uintptr_t)(&_micropy_hw_romfs_part1_start) #define ROMFS1_DYNAMIC (1)
#define MICROPY_HW_ROMFS_PART1_SIZE (uintptr_t)(&_micropy_hw_romfs_part1_size) static MP_DEFINE_MEMORYVIEW_OBJ(romfs1_obj, 'B', 0, (uintptr_t)-1, (void *)-1);
#elif MICROPY_HW_ROMFS_ENABLE_PART1 && !defined(MICROPY_HW_ROMFS_PART1_START)
#define ROMFS1_DYNAMIC (0)
extern uint8_t _micropy_hw_romfs_part1_start; extern uint8_t _micropy_hw_romfs_part1_start;
extern uint8_t _micropy_hw_romfs_part1_size; extern uint8_t _micropy_hw_romfs_part1_size;
static const MP_DEFINE_MEMORYVIEW_OBJ(romfs1_obj, 'B', 0, (uintptr_t)&_micropy_hw_romfs_part1_size, (void *)&_micropy_hw_romfs_part1_start);
#endif #endif
#define ROMFS_MEMORYVIEW(base, size) {{&mp_type_memoryview}, 'B', 0, (size), (void *)(base)} static const mp_obj_array_t *romfs_obj_table[] = {
static const mp_obj_array_t romfs_obj_table[] = {
#if MICROPY_HW_ROMFS_ENABLE_PART0 #if MICROPY_HW_ROMFS_ENABLE_PART0
ROMFS_MEMORYVIEW(MICROPY_HW_ROMFS_PART0_START, MICROPY_HW_ROMFS_PART0_SIZE), &romfs0_obj,
#endif #endif
#if MICROPY_HW_ROMFS_ENABLE_PART1 #if MICROPY_HW_ROMFS_ENABLE_PART1
ROMFS_MEMORYVIEW(MICROPY_HW_ROMFS_PART1_START, MICROPY_HW_ROMFS_PART1_SIZE), &romfs1_obj,
#endif #endif
}; };
@@ -76,7 +80,20 @@ mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL); return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
} }
const mp_obj_array_t *romfs_obj = &romfs_obj_table[romfs_id]; #if ROMFS0_DYNAMIC
if (romfs_id == 0) {
romfs0_obj.items = (void *)MICROPY_HW_ROMFS_PART0_START;
romfs0_obj.len = MICROPY_HW_ROMFS_PART0_SIZE;
}
#endif
#if ROMFS1_DYNAMIC
if (romfs_id == 1) {
romfs1_obj.items = (void *)MICROPY_HW_ROMFS_PART1_START;
romfs1_obj.len = MICROPY_HW_ROMFS_PART1_SIZE;
}
#endif
const mp_obj_array_t *romfs_obj = romfs_obj_table[romfs_id];
uintptr_t romfs_base = (uintptr_t)romfs_obj->items; uintptr_t romfs_base = (uintptr_t)romfs_obj->items;
uintptr_t romfs_len = romfs_obj->len; uintptr_t romfs_len = romfs_obj->len;