From f3e79c8b565aa4e74dfeedd1b562784e01cac81f Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Wed, 8 Apr 2026 19:56:42 +0200 Subject: [PATCH] qemu/boards/VIRT_RV64: Add ROMFS support. This commit reserves a memory area to mount ROMFS partitions into, and lets the port Makefile know the memory area details. A 4 MiB segment is allocated at 0x8062_0000, which is inside the emulated machine's DRAM segment. The virt board requires the image loaded in its DRAM segment to be contiguous, so the ROMFS segment is placed right after the stack area. Signed-off-by: Alessandro Gatti --- ports/qemu/boards/VIRT_RV64/mpconfigboard.mk | 6 ++++++ ports/qemu/mcu/rv64/virt.ld | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ports/qemu/boards/VIRT_RV64/mpconfigboard.mk b/ports/qemu/boards/VIRT_RV64/mpconfigboard.mk index dae4ca3e03..38939b032c 100644 --- a/ports/qemu/boards/VIRT_RV64/mpconfigboard.mk +++ b/ports/qemu/boards/VIRT_RV64/mpconfigboard.mk @@ -6,6 +6,12 @@ CFLAGS += -DMICROPY_HW_MCU_NAME='"$(RV64_ARCH)"' LDSCRIPT = mcu/rv64/virt.ld +# If the ROMFS partition size is not enough, remember to change +# ports/qemu/mcu/rv64/virt.ld to resize the ROMFS section as well. + +MICROPY_HW_ROMFS_PART0_START = 0x80620000 +MICROPY_HW_ROMFS_PART0_SIZE = 0x00400000 + SRC_BOARD_O += shared/runtime/gchelper_native.o shared/runtime/gchelper_rv64i.o MPY_CROSS_FLAGS += -march=rv64imc diff --git a/ports/qemu/mcu/rv64/virt.ld b/ports/qemu/mcu/rv64/virt.ld index 7727839e0d..4373be30c1 100644 --- a/ports/qemu/mcu/rv64/virt.ld +++ b/ports/qemu/mcu/rv64/virt.ld @@ -38,12 +38,14 @@ OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv"); * 0x0000_0000_8060_0000: .stack * 0x0000_0000_8060_0000: _sstack * 0x0000_0000_8061_FFFF: _estack + * 0x0000_0000_8062_0000: .romfs */ MEMORY { - ROM (xr) : ORIGIN = 0x0000000080000000, LENGTH = 4M - RAM (xrw) : ORIGIN = ORIGIN(ROM) + LENGTH(ROM), LENGTH = 2M - STACK (rw) : ORIGIN = ORIGIN(RAM) + LENGTH(RAM), LENGTH = 128K + ROM (xr) : ORIGIN = 0x0000000080000000, LENGTH = 4M + RAM (xrw) : ORIGIN = ORIGIN(ROM) + LENGTH(ROM), LENGTH = 2M + STACK (rw) : ORIGIN = ORIGIN(RAM) + LENGTH(RAM), LENGTH = 128K + ROMFS (xr) : ORIGIN = ORIGIN(STACK) + LENGTH(STACK), LENGTH = 4M } SECTIONS