renesas-ra: Add support for VfsRom filesystem.

The ROM partition is taken from the last part of the flash text section, so
the existing writable filesystem is untouched.  VfsRom file system sizes:
- EK_RA4M1: 12K
- RA4M1_CLICKER: 12k
- EK_RA4W1: 64k
- EK_RA6M1: 64k
- EK_RA6M2: 256k
- VK_RA6M5: 384k
- ARDUINO_PORTENTA_C33: 256k

Tested with Weact RA4M1 core board with EK_RA4M1 firmware and EK_RA6M2.

Signed-off-by: robert-hh <robert@hammelrath.com>
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
robert-hh
2024-12-11 14:21:18 +01:00
committed by Damien George
parent c07b178dbd
commit cee950673d
9 changed files with 115 additions and 13 deletions

View File

@@ -6,7 +6,8 @@
MEMORY
{
FLASH_BOOT (r) : ORIGIN = 0x00000000, LENGTH = 0x00010000 /* 64K */
FLASH (rx) : ORIGIN = 0x00010000, LENGTH = 0x000f0000 /* 960KB */
FLASH (rx) : ORIGIN = 0x00010000, LENGTH = 0x000B0000 /* 704KB/2MB */
FLASH_ROMFS (r) : ORIGIN = 0x000C0000, LENGTH = 0x00040000 /* 256KB/2MB */
FLASH_FS (r) : ORIGIN = 0x00100000, LENGTH = 0x00100000 /* 1MB */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000 /* 512KB */
OSPI_RAM (rwx) : ORIGIN = 0x68000000, LENGTH = 0x00800000 /* 8MB/8MB */
@@ -304,3 +305,6 @@ _heap_end = __HeapLimit; /* tunable */
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

View File

@@ -3,9 +3,14 @@
*/
/* Linker script to configure memory regions. */
/*
* FLASH_ROMFS and FLASH_FS must start and length must be a multiple
* of the physical sector size of that region (2k).
*/
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00037000 /* 220KB/256KB */
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00034000 /* 208KB/256KB */
FLASH_ROMFS (r) : ORIGIN = 0x00034000, LENGTH = 0x00003000 /* 12KB/256KB */
FLASH_FS (r) : ORIGIN = 0x00037000, LENGTH = 0x00009000 /* 36KB/256KB */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 /* 32KB */
DATA_FLASH (rx) : ORIGIN = 0x40100000, LENGTH = 0x00002000 /* 8KB */
@@ -300,3 +305,6 @@ _heap_end = __HeapLimit; /* tunable */
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

View File

@@ -3,9 +3,14 @@
*/
/* Linker script to configure memory regions. */
/*
* FLASH_ROMFS and FLASH_FS must start and length must be a multiple
* of the physical sector size of that region (2k).
*/
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00070000 /* 448KB/512KB */
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00060000 /* 384KB/512KB */
FLASH_ROMFS (r) : ORIGIN = 0x00060000, LENGTH = 0x00010000 /* 64KB/512KB */
FLASH_FS (r) : ORIGIN = 0x00070000, LENGTH = 0x00010000 /* 64KB/512KB */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00018000 /* 96KB */
DATA_FLASH (rx) : ORIGIN = 0x40100000, LENGTH = 0x00002000 /* 8KB */
@@ -300,3 +305,6 @@ _heap_end = __HeapLimit; /* tunable */
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

View File

@@ -5,7 +5,8 @@
/* Linker script to configure memory regions. */
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00070000 /* 448KB/512KB */
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00060000 /* 384KB/512KB */
FLASH_ROMFS (r) : ORIGIN = 0x00060000, LENGTH = 0x00010000 /* 64KB/512KB */
FLASH_FS (r) : ORIGIN = 0x00070000, LENGTH = 0x00010000 /* 64KB/512KB */
RAM (rwx) : ORIGIN = 0x1FFE0000, LENGTH = 0x00040000 /* 256KB */
DATA_FLASH (rx) : ORIGIN = 0x40100000, LENGTH = 0x00002000 /* 8KB */
@@ -300,3 +301,6 @@ _heap_end = __HeapLimit; /* tunable */
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

View File

@@ -3,9 +3,15 @@
*/
/* Linker script to configure memory regions. */
/*
* FLASH_ROMFS and FLASH_FS must start and length must be a multiple
* of the physical sector size of that region (32k).
*/
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x000e0000 /* 896KB/1MB */
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x000A0000 /* 768KB/1MB */
FLASH_ROMFS (r) : ORIGIN = 0x000A0000, LENGTH = 0x00040000 /* 256KB/1MB */
FLASH_FS (r) : ORIGIN = 0x000e0000, LENGTH = 0x00020000 /* 128KB/1MB */
RAM (rwx) : ORIGIN = 0x1FFE0000, LENGTH = 0x00060000 /* 384KB */
DATA_FLASH (rx) : ORIGIN = 0x40100000, LENGTH = 0x00008000 /* 32KB */
@@ -300,3 +306,6 @@ _heap_end = __HeapLimit; /* tunable */
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

View File

@@ -5,7 +5,8 @@
/* Linker script to configure memory regions. */
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00037000 /* 220KB/256KB */
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00034000 /* 208KB/256KB */
FLASH_ROMFS (r) : ORIGIN = 0x00034000, LENGTH = 0x00003000 /* 12KB/256KB */
FLASH_FS (r) : ORIGIN = 0x00037000, LENGTH = 0x00009000 /* 36KB/256KB */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 /* 32KB */
DATA_FLASH (rx) : ORIGIN = 0x40100000, LENGTH = 0x00002000 /* 8KB */
@@ -300,3 +301,6 @@ _heap_end = __HeapLimit; /* tunable */
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

View File

@@ -5,7 +5,8 @@
/* Linker script to configure memory regions. */
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00100000 /* 1MB/2MB */
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x000A0000 /* 640KB/2MB */
FLASH_ROMFS (r) : ORIGIN = 0x000A0000, LENGTH = 0x00060000 /* 384KB/2MB */
FLASH_FS (r) : ORIGIN = 0x00100000, LENGTH = 0x00100000 /* 1MB/2MB */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000 /* 512KB */
OSPI_RAM (rwx) : ORIGIN = 0x68000000, LENGTH = 0x00800000 /* 8MB/8MB */
@@ -306,3 +307,6 @@ _micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
_micropy_hw_external_flash_storage_start = ORIGIN(QSPI_FLASH);
_micropy_hw_external_flash_storage_end = ORIGIN(QSPI_FLASH) + LENGTH(QSPI_FLASH);
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

View File

@@ -154,6 +154,11 @@
#define MICROPY_HW_UART_IS_RESERVED(uart_id) (false)
#endif
// Whether to support the VFSROM file system
#ifndef MICROPY_VFS_ROM
#define MICROPY_VFS_ROM (1)
#endif
/*****************************************************************************/
// General configuration

View File

@@ -28,6 +28,7 @@
#include <stdint.h>
#include <string.h>
#include "py/objarray.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "extmod/vfs_fat.h"
@@ -36,6 +37,13 @@
#include "led.h"
#include "storage.h"
#include "irq.h"
#include "flash.h"
typedef struct _pyb_flash_obj_t {
mp_obj_base_t base;
uint32_t start; // in bytes
uint32_t len; // in bytes
} pyb_flash_obj_t;
#if MICROPY_HW_ENABLE_STORAGE
@@ -236,12 +244,6 @@ int storage_readblocks_ext(uint8_t *dest, uint32_t block, uint32_t offset, uint3
}
#endif
typedef struct _pyb_flash_obj_t {
mp_obj_base_t base;
uint32_t start; // in bytes
uint32_t len; // in bytes
} pyb_flash_obj_t;
// This Flash object represents the entire available flash, with emulated partition table at start
const pyb_flash_obj_t pyb_flash_obj = {
{ &pyb_flash_type },
@@ -427,3 +429,57 @@ void pyb_flash_init_vfs(fs_user_mount_t *vfs) {
}
#endif
#if MICROPY_VFS_ROM
extern uint32_t _micropy_hw_romfs_part0_start, _micropy_hw_romfs_part0_size;
#define MICROPY_HW_ROMFS_BASE ((uint32_t)&_micropy_hw_romfs_part0_start)
#define MICROPY_HW_ROMFS_BYTES ((uint32_t)&_micropy_hw_romfs_part0_size)
#define VFSROM_BLOCK_SIZE (2048)
static const MP_DEFINE_MEMORYVIEW_OBJ(romfs_obj, 'B', 0, MICROPY_HW_ROMFS_BYTES, (void *)MICROPY_HW_ROMFS_BASE);
mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args) {
if (MICROPY_HW_ROMFS_BYTES <= 0) {
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
}
switch (mp_obj_get_int(args[0])) {
case MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS:
return MP_OBJ_NEW_SMALL_INT(1);
case MP_VFS_ROM_IOCTL_GET_SEGMENT:
return MP_OBJ_FROM_PTR(&romfs_obj);
case MP_VFS_ROM_IOCTL_WRITE_PREPARE: {
// Erase sectors in given range.
if (n_args < 3) {
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
}
uint32_t dest = MICROPY_HW_ROMFS_BASE;
uint32_t dest_max = dest + mp_obj_get_int(args[2]);
uint32_t sec_size = sector_size(dest);
for (; dest < dest_max; dest += sec_size) {
flash_erase(dest, sec_size);
}
return MP_OBJ_NEW_SMALL_INT(4); // minimum write size
}
case MP_VFS_ROM_IOCTL_WRITE: {
// Write data to flash.
if (n_args < 4) {
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
}
uint32_t dest = MICROPY_HW_ROMFS_BASE + mp_obj_get_int(args[2]);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
flash_write(dest, bufinfo.buf, bufinfo.len);
return MP_OBJ_NEW_SMALL_INT(0);
}
default:
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
}
}
#endif // MICROPY_VFS_ROM