public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Anup Patel <apatel@ventanamicro.com>
To: Rick Chen <rick@andestech.com>, Bin Meng <bmeng.cn@gmail.com>
Cc: Atish Patra <atishp@atishpatra.org>,
	Alistair Francis <Alistair.Francis@wdc.com>,
	Anup Patel <anup@brainfault.org>,
	U-Boot Mailing List <u-boot@lists.denx.de>,
	Anup Patel <apatel@ventanamicro.com>
Subject: [PATCH 3/3] riscv: qemu: Implement is_flash_available() for MTD NOR
Date: Fri, 14 Jan 2022 21:50:08 +0530	[thread overview]
Message-ID: <20220114162008.70468-4-apatel@ventanamicro.com> (raw)
In-Reply-To: <20220114162008.70468-1-apatel@ventanamicro.com>

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@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


  parent reply	other threads:[~2022-01-14 16:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-14 16:20 [PATCH 0/3] QEMU spike machine support for U-Boot Anup Patel
2022-01-14 16:20 ` [PATCH 1/3] serial: Add RISC-V HTIF console driver Anup Patel
     [not found]   ` <HK0PR03MB2994046A80E42E46BC77050EC15F9@HK0PR03MB2994.apcprd03.prod.outlook.com>
2022-01-25  1:14     ` Rick Chen
2022-01-25  4:52   ` Bin Meng
2022-01-25  6:00     ` Anup Patel
2022-01-25  9:16       ` Bin Meng
2022-01-25 11:31         ` Anup Patel
2022-01-14 16:20 ` [PATCH 2/3] riscv: qemu: Enable HTIF console support Anup Patel
     [not found]   ` <HK0PR03MB299495170A039FA84DE6AA7CC15F9@HK0PR03MB2994.apcprd03.prod.outlook.com>
2022-01-25  1:16     ` Rick Chen
2022-01-14 16:20 ` Anup Patel [this message]
     [not found]   ` <HK0PR03MB2994115F103502B3A46F7D38C15F9@HK0PR03MB2994.apcprd03.prod.outlook.com>
2022-01-25  1:18     ` [PATCH 3/3] riscv: qemu: Implement is_flash_available() for MTD NOR Rick Chen
2022-01-25  5:03   ` Bin Meng
2022-01-25  6:02     ` Anup Patel
2022-01-25  9:46       ` Bin Meng
2022-01-25 11:32         ` Anup Patel
2022-01-18 10:10 ` [PATCH 0/3] QEMU spike machine support for U-Boot Bin Meng
2022-01-18 10:56   ` Anup Patel
2022-01-25  5:10     ` Bin Meng
2022-01-25  6:03       ` Anup Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220114162008.70468-4-apatel@ventanamicro.com \
    --to=apatel@ventanamicro.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=anup@brainfault.org \
    --cc=atishp@atishpatra.org \
    --cc=bmeng.cn@gmail.com \
    --cc=rick@andestech.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox