On 1/27/22 07:11, Anup Patel wrote:
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 <apa...@ventanamicro.com>
Reviewed-by: Rick Chen <r...@andestech.com>
---
board/emulation/qemu-riscv/qemu-riscv.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/board/emulation/qemu-riscv/qemu-riscv.c
b/board/emulation/qemu-riscv/qemu-riscv.c
index b0d9dd59b1..ae3b7a3295 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <dm.h>
+#include <dm/ofnode.h>
#include <env.h>
#include <fdtdec.h>
#include <image.h>
@@ -16,6 +17,17 @@
DECLARE_GLOBAL_DATA_PTR;
+#if IS_ENABLED(CONFIG_MTD_NOR_FLASH)
I do not think that we need an #if here. The weak function is only
defined and called if CONFIG_MTD_NOR_FLASH=y (cf. common/board_r.c).
Without the #if the linker will detect that this function is not needed
and will eliminate it if CONFIG_MTD_NOR_FLASH=n.
As this ensures that the function is always compiled this is the
preferred way of implementation.
+int is_flash_available(void)
Currently there is no include defining the is_flash_available(). This
needs to be fixed.
Best regards
Heinrich
+{
+ if (!ofnode_equal(ofnode_by_compatible(ofnode_null(), "cfi-flash"),
+ ofnode_null()))
+ return 1;
+
+ return 0;
+}
+#endif
+
int board_init(void)
{
/*