On 8/27/2026 2:44 AM, Joel Stanley wrote:
On Thu, 27 Aug 2026 at 07:16, Daniel Henrique Barboza
<[email protected]> wrote:
Add a common helper to create a cfi-flash compatible flash subnode.
This change only affects the existing 'virt' board for now but it will
be used by the future 'riscv-server-ref' board in the future.
Why do we have two flash devices?
(I know why ARM does, where the code was copied from, but why does RISC-V?)
The first RISC-V 'virt' board was a port of ARM 'virt' board and ended up
inheriting
lots of stuff from it. The RISC-V port would try to match the same use cases
that
the ARM board already.
So the second CFI-flash exists in RISC-V for the same reason it exists in ARM:
secure
flash memory for trust boot.
No FDT changes intended.
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
---
hw/riscv/fdt-common.c | 12 ++++++++++++
hw/riscv/virt.c | 18 ++----------------
include/hw/riscv/fdt-common.h | 1 +
3 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c
index 3a8da03cfb..6fcc1ce21f 100644
--- a/hw/riscv/fdt-common.c
+++ b/hw/riscv/fdt-common.c
@@ -283,3 +283,15 @@ void riscv_pmu_generate_fdt_node(void *fdt, uint32_t
cmask, char *pmu_name)
qemu_fdt_setprop(fdt, pmu_name, "riscv,event-to-mhpmcounters",
fdt_event_ctr_map, sizeof(fdt_event_ctr_map));
}
+
+void riscv_create_fdt_flash(void *fdt, hwaddr flashbase, hwaddr flashsize)
+{
+ g_autofree char *name = g_strdup_printf("/flash@%" PRIx64, flashbase);
+
+ qemu_fdt_add_subnode(fdt, name);
+ qemu_fdt_setprop_string(fdt, name, "compatible", "cfi-flash");
+ qemu_fdt_setprop_sized_cells(fdt, name, "reg",
+ 2, flashbase, 2, flashsize,
+ 2, flashbase + flashsize, 2, flashsize);
+ qemu_fdt_setprop_cell(fdt, name, "bank-width", 4);
+}
This is a copy of the code in hw/arm/virt.c, which was also copied by
hw/loongarch/virt-fdt-build.c.
I discussed in the past the possibility of delegating FDTs to devices instead of
boards/helpers. This would be an example where the CFIFlash device could create
its own DT.
Can't recall the conclusion back then. Probably something we can revisit. For
now
we can at least not copy/paste this code in other RISC-V boards.
Thanks,
Daniel