[PATCH 3/3] riscv: qemu: Implement is_flash_available() for MTD NOR

Anup Patel apatel at ventanamicro.com
Fri Jan 14 17:20:08 CET 2022


Currently, if MTD NOR is enabled then U-Boot tries to issue flash
commands even when CFI flash DT node is not present. This causes
access fault on RISC-V emulators or ISS which do not emulate CFI
flash. To handle this issue, we implement is_flash_available() for
qemu-riscv board which will return 1 only if CFI flash DT node is
present.

Fixes: d248627f9d42 ("riscv: qemu: Enable MTD NOR flash support")
Signed-off-by: Anup Patel <apatel at ventanamicro.com>
---
 board/emulation/qemu-riscv/qemu-riscv.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/board/emulation/qemu-riscv/qemu-riscv.c b/board/emulation/qemu-riscv/qemu-riscv.c
index b0d9dd59b1..cd02dae1ab 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -8,6 +8,7 @@
 #include <env.h>
 #include <fdtdec.h>
 #include <image.h>
+#include <linux/libfdt.h>
 #include <log.h>
 #include <spl.h>
 #include <init.h>
@@ -16,6 +17,22 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#if IS_ENABLED(CONFIG_MTD_NOR_FLASH)
+int is_flash_available(void)
+{
+	if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
+		const void *fdt =
+			(const void *)(uintptr_t)gd->arch.firmware_fdt_addr;
+		int rc = fdt_node_offset_by_compatible(fdt, -1, "cfi-flash");
+
+		if (rc >= 0)
+			return 1;
+	}
+
+	return 0;
+}
+#endif
+
 int board_init(void)
 {
 	/*
-- 
2.25.1



More information about the U-Boot mailing list