Skip to content

Commit cee9506

Browse files
robert-hhdpgeorge
authored andcommitted
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>
1 parent c07b178 commit cee9506

9 files changed

Lines changed: 115 additions & 13 deletions

File tree

ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra6m5.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
MEMORY
77
{
88
FLASH_BOOT (r) : ORIGIN = 0x00000000, LENGTH = 0x00010000 /* 64K */
9-
FLASH (rx) : ORIGIN = 0x00010000, LENGTH = 0x000f0000 /* 960KB */
9+
FLASH (rx) : ORIGIN = 0x00010000, LENGTH = 0x000B0000 /* 704KB/2MB */
10+
FLASH_ROMFS (r) : ORIGIN = 0x000C0000, LENGTH = 0x00040000 /* 256KB/2MB */
1011
FLASH_FS (r) : ORIGIN = 0x00100000, LENGTH = 0x00100000 /* 1MB */
1112
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000 /* 512KB */
1213
OSPI_RAM (rwx) : ORIGIN = 0x68000000, LENGTH = 0x00800000 /* 8MB/8MB */
@@ -304,3 +305,6 @@ _heap_end = __HeapLimit; /* tunable */
304305

305306
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
306307
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
308+
309+
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
310+
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

ports/renesas-ra/boards/EK_RA4M1/ra4m1_ek.ld

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
*/
44

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

301306
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
302307
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
308+
309+
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
310+
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

ports/renesas-ra/boards/EK_RA4W1/ra4w1_ek.ld

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
*/
44

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

301306
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
302307
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
308+
309+
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
310+
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

ports/renesas-ra/boards/EK_RA6M1/ra6m1_ek.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/* Linker script to configure memory regions. */
66
MEMORY
77
{
8-
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00070000 /* 448KB/512KB */
8+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00060000 /* 384KB/512KB */
9+
FLASH_ROMFS (r) : ORIGIN = 0x00060000, LENGTH = 0x00010000 /* 64KB/512KB */
910
FLASH_FS (r) : ORIGIN = 0x00070000, LENGTH = 0x00010000 /* 64KB/512KB */
1011
RAM (rwx) : ORIGIN = 0x1FFE0000, LENGTH = 0x00040000 /* 256KB */
1112
DATA_FLASH (rx) : ORIGIN = 0x40100000, LENGTH = 0x00002000 /* 8KB */
@@ -300,3 +301,6 @@ _heap_end = __HeapLimit; /* tunable */
300301

301302
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
302303
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
304+
305+
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
306+
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

ports/renesas-ra/boards/EK_RA6M2/ra6m2_ek.ld

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
*/
44

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

301307
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
302308
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
309+
310+
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
311+
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

ports/renesas-ra/boards/RA4M1_CLICKER/ra4m1_clicker.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/* Linker script to configure memory regions. */
66
MEMORY
77
{
8-
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00037000 /* 220KB/256KB */
8+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00034000 /* 208KB/256KB */
9+
FLASH_ROMFS (r) : ORIGIN = 0x00034000, LENGTH = 0x00003000 /* 12KB/256KB */
910
FLASH_FS (r) : ORIGIN = 0x00037000, LENGTH = 0x00009000 /* 36KB/256KB */
1011
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 /* 32KB */
1112
DATA_FLASH (rx) : ORIGIN = 0x40100000, LENGTH = 0x00002000 /* 8KB */
@@ -300,3 +301,6 @@ _heap_end = __HeapLimit; /* tunable */
300301

301302
_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
302303
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
304+
305+
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
306+
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/* Linker script to configure memory regions. */
66
MEMORY
77
{
8-
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00100000 /* 1MB/2MB */
8+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x000A0000 /* 640KB/2MB */
9+
FLASH_ROMFS (r) : ORIGIN = 0x000A0000, LENGTH = 0x00060000 /* 384KB/2MB */
910
FLASH_FS (r) : ORIGIN = 0x00100000, LENGTH = 0x00100000 /* 1MB/2MB */
1011
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000 /* 512KB */
1112
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);
306307

307308
_micropy_hw_external_flash_storage_start = ORIGIN(QSPI_FLASH);
308309
_micropy_hw_external_flash_storage_end = ORIGIN(QSPI_FLASH) + LENGTH(QSPI_FLASH);
310+
311+
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
312+
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

ports/renesas-ra/mpconfigboard_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@
154154
#define MICROPY_HW_UART_IS_RESERVED(uart_id) (false)
155155
#endif
156156

157+
// Whether to support the VFSROM file system
158+
#ifndef MICROPY_VFS_ROM
159+
#define MICROPY_VFS_ROM (1)
160+
#endif
161+
157162
/*****************************************************************************/
158163
// General configuration
159164

ports/renesas-ra/storage.c

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <stdint.h>
2929
#include <string.h>
3030

31+
#include "py/objarray.h"
3132
#include "py/runtime.h"
3233
#include "py/mperrno.h"
3334
#include "extmod/vfs_fat.h"
@@ -36,6 +37,13 @@
3637
#include "led.h"
3738
#include "storage.h"
3839
#include "irq.h"
40+
#include "flash.h"
41+
42+
typedef struct _pyb_flash_obj_t {
43+
mp_obj_base_t base;
44+
uint32_t start; // in bytes
45+
uint32_t len; // in bytes
46+
} pyb_flash_obj_t;
3947

4048
#if MICROPY_HW_ENABLE_STORAGE
4149

@@ -236,12 +244,6 @@ int storage_readblocks_ext(uint8_t *dest, uint32_t block, uint32_t offset, uint3
236244
}
237245
#endif
238246

239-
typedef struct _pyb_flash_obj_t {
240-
mp_obj_base_t base;
241-
uint32_t start; // in bytes
242-
uint32_t len; // in bytes
243-
} pyb_flash_obj_t;
244-
245247
// This Flash object represents the entire available flash, with emulated partition table at start
246248
const pyb_flash_obj_t pyb_flash_obj = {
247249
{ &pyb_flash_type },
@@ -427,3 +429,57 @@ void pyb_flash_init_vfs(fs_user_mount_t *vfs) {
427429
}
428430

429431
#endif
432+
433+
#if MICROPY_VFS_ROM
434+
435+
extern uint32_t _micropy_hw_romfs_part0_start, _micropy_hw_romfs_part0_size;
436+
437+
#define MICROPY_HW_ROMFS_BASE ((uint32_t)&_micropy_hw_romfs_part0_start)
438+
#define MICROPY_HW_ROMFS_BYTES ((uint32_t)&_micropy_hw_romfs_part0_size)
439+
#define VFSROM_BLOCK_SIZE (2048)
440+
441+
static const MP_DEFINE_MEMORYVIEW_OBJ(romfs_obj, 'B', 0, MICROPY_HW_ROMFS_BYTES, (void *)MICROPY_HW_ROMFS_BASE);
442+
443+
mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args) {
444+
if (MICROPY_HW_ROMFS_BYTES <= 0) {
445+
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
446+
}
447+
switch (mp_obj_get_int(args[0])) {
448+
case MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS:
449+
return MP_OBJ_NEW_SMALL_INT(1);
450+
451+
case MP_VFS_ROM_IOCTL_GET_SEGMENT:
452+
return MP_OBJ_FROM_PTR(&romfs_obj);
453+
454+
case MP_VFS_ROM_IOCTL_WRITE_PREPARE: {
455+
// Erase sectors in given range.
456+
if (n_args < 3) {
457+
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
458+
}
459+
uint32_t dest = MICROPY_HW_ROMFS_BASE;
460+
uint32_t dest_max = dest + mp_obj_get_int(args[2]);
461+
uint32_t sec_size = sector_size(dest);
462+
for (; dest < dest_max; dest += sec_size) {
463+
flash_erase(dest, sec_size);
464+
}
465+
return MP_OBJ_NEW_SMALL_INT(4); // minimum write size
466+
}
467+
468+
case MP_VFS_ROM_IOCTL_WRITE: {
469+
// Write data to flash.
470+
if (n_args < 4) {
471+
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
472+
}
473+
uint32_t dest = MICROPY_HW_ROMFS_BASE + mp_obj_get_int(args[2]);
474+
mp_buffer_info_t bufinfo;
475+
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
476+
flash_write(dest, bufinfo.buf, bufinfo.len);
477+
return MP_OBJ_NEW_SMALL_INT(0);
478+
}
479+
480+
default:
481+
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
482+
}
483+
}
484+
485+
#endif // MICROPY_VFS_ROM

0 commit comments

Comments
 (0)