Skip to contentSkip to conversation

QEMU spike machine support for U-Boot

PATCH Superseded Anup Patel 4 participants 19 messages Jan 14, 2022 – Jan 25, 2022 3 messages not in the archive RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

cover QEMU spike machine support for U-Boot

We can use same U-Boot binary compiled using qemu-riscv64_smode_defconfig on QEMU virt machine and QEMU spike machine. To achieve this, we need HTIF console support for U-Boot QEMU RISC-V board hence this series.

To test this series with latest OpenSBI, we can use the following command:
qemu-system-riscv64 -M spike -m 256M -display none -serial stdio \
-bios opensbi/build/platform/generic/firmware/fw_jump.bin -kernel \
./u-boot/u-boot.bin

These patch can be found in qemu_riscv_htif_v1 branch at:
https://github.com/avpatel/u-boot.git

Anup Patel (3):
serial: Add RISC-V HTIF console driver
riscv: qemu: Enable HTIF console support
riscv: qemu: Implement is_flash_available() for MTD NOR

 board/emulation/qemu-riscv/Kconfig      |   1 +
 board/emulation/qemu-riscv/qemu-riscv.c |  17 +++
 drivers/serial/Kconfig                  |   8 ++
 drivers/serial/Makefile                 |   1 +
 drivers/serial/serial_htif.c            | 178 ++++++++++++++++++++++++
 5 files changed, 205 insertions(+)
 create mode 100644 drivers/serial/serial_htif.c
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/3 serial: Add RISC-V HTIF console driver

Quite a few RISC-V emulators and ISS (including Spike) have host transfer interface (HTIF) based console. This patch adds HTIF based console driver for RISC-V platforms which depends totally on DT node for HTIF register base address.

---
 drivers/serial/Kconfig       |   8 ++
 drivers/serial/Makefile      |   1 +
 drivers/serial/serial_htif.c | 178 +++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 drivers/serial/serial_htif.c
drivers/serial/Kconfig +8 -0
index 6c8fdda9a0..345d1881f5 100644
@@ -866,6 +866,14 @@ config PXA_SERIAL
 	  If you have a machine based on a Marvell XScale PXA2xx CPU you
 	  can enable its onboard serial ports by enabling this option.
 
+config HTIF_CONSOLE
+	bool "RISC-V HTIF console support"
+	depends on DM_SERIAL && 64BIT
+	help
+	  Select this to enable host transfer interface (HTIF) based serial
+	  console. The HTIF device is quite common in RISC-V emulators and
+	  RISC-V ISS so this driver allows using U-Boot on such platforms.
+
 config SIFIVE_SERIAL
 	bool "SiFive UART support"
 	depends on DM_SERIAL
drivers/serial/Makefile +1 -0
index 8168af640f..52e70aa191 100644
@@ -73,6 +73,7 @@ obj-$(CONFIG_OWL_SERIAL) += serial_owl.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_MTK_SERIAL) += serial_mtk.o
 obj-$(CONFIG_MT7620_SERIAL) += serial_mt7620.o
+obj-$(CONFIG_HTIF_CONSOLE) += serial_htif.o
 obj-$(CONFIG_SIFIVE_SERIAL) += serial_sifive.o
 obj-$(CONFIG_XEN_SERIAL) += serial_xen.o
 
drivers/serial/serial_htif.c new file +178 -0

178 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#8 lore raw

PATCH 2/3 riscv: qemu: Enable HTIF console support

In reply to Anup Patel

Enable support for HTIF console so that we can use QEMU RISC-V U-Boot on RISC-V emulators and ISS having it.

---
 board/emulation/qemu-riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
board/emulation/qemu-riscv/Kconfig +1 -0
index 1bbf1bc84a..f7538bc496 100644
@@ -56,6 +56,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply DM_SCSI
 	imply SYS_NS16550
 	imply SIFIVE_SERIAL
+	imply HTIF_CONSOLE if 64BIT
 	imply SYSRESET
 	imply SYSRESET_CMD_POWEROFF
 	imply SYSRESET_SYSCON
Signature · 1 line
2.25.1
author
#11 lore raw

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

In reply to Anup Patel

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")
---
 board/emulation/qemu-riscv/qemu-riscv.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
board/emulation/qemu-riscv/qemu-riscv.c +17 -0
index b0d9dd59b1..cd02dae1ab 100644
@@ -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)
 {
 	/*
Signature · 1 line
2.25.1
#18 lore raw
In reply to Anup Patel
Quoted 8 lines · Anup Patel

We can use same U-Boot binary compiled using qemu-riscv64_smode_defconfig on QEMU virt machine and QEMU spike machine. To achieve this, we need HTIF console support for U-Boot QEMU RISC-V board hence this series.

To test this series with latest OpenSBI, we can use the following command:
qemu-system-riscv64 -M spike -m 256M -display none -serial stdio \
-bios opensbi/build/platform/generic/firmware/fw_jump.bin -kernel \

I think you forgot to mention this needs an updated QEMU too, due to plain binary is now used for spike?

Quoted 10 lines

./u-boot/u-boot.bin

These patch can be found in qemu_riscv_htif_v1 branch at:
https://github.com/avpatel/u-boot.git

Anup Patel (3):
serial: Add RISC-V HTIF console driver
riscv: qemu: Enable HTIF console support
riscv: qemu: Implement is_flash_available() for MTD NOR

Quoted 8 lines
 board/emulation/qemu-riscv/Kconfig      |   1 +
 board/emulation/qemu-riscv/qemu-riscv.c |  17 +++
 drivers/serial/Kconfig                  |   8 ++
 drivers/serial/Makefile                 |   1 +
 drivers/serial/serial_htif.c            | 178 ++++++++++++++++++++++++
 5 files changed, 205 insertions(+)
 create mode 100644 drivers/serial/serial_htif.c

Regards,
Bin

#19 lore raw
Quoted 7 lines · Bin Meng
Quoted 5 lines · Anup Patel

We can use same U-Boot binary compiled using qemu-riscv64_smode_defconfig on QEMU virt machine and QEMU spike machine. To achieve this, we need HTIF console support for U-Boot QEMU RISC-V board hence this series.

Quoted 6 lines
Quoted 3 lines

To test this series with latest OpenSBI, we can use the following command:
qemu-system-riscv64 -M spike -m 256M -display none -serial stdio \
-bios opensbi/build/platform/generic/firmware/fw_jump.bin -kernel \

I think you forgot to mention this needs an updated QEMU too, due to plain binary is now used for spike?

Ahh, yes. I should have provided the link to the QEMU spike machine patch.

QEMU patch link:
https://lore.kernel.org/all/[email protected]/

Regards,
Anup

Quoted 22 lines
Quoted 11 lines

./u-boot/u-boot.bin

These patch can be found in qemu_riscv_htif_v1 branch at:
https://github.com/avpatel/u-boot.git

Anup Patel (3):
serial: Add RISC-V HTIF console driver
riscv: qemu: Enable HTIF console support
riscv: qemu: Implement is_flash_available() for MTD NOR

Quoted 8 lines
 board/emulation/qemu-riscv/Kconfig      |   1 +
 board/emulation/qemu-riscv/qemu-riscv.c |  17 +++
 drivers/serial/Kconfig                  |   8 ++
 drivers/serial/Makefile                 |   1 +
 drivers/serial/serial_htif.c            | 178 ++++++++++++++++++++++++
 5 files changed, 205 insertions(+)
 create mode 100644 drivers/serial/serial_htif.c

Regards,
Bin

Reviewed-by
#3 lore raw

Re: [PATCH 1/3] serial: Add RISC-V HTIF console driver

In reply to a message not in the archive
Quoted 8 lines

From: Anup Patel <[email protected]>
Sent: Saturday, January 15, 2022 12:20 AM
To: Rick Jian-Zhi Chen(陳建志) <[email protected]>; Bin Meng <[email protected]>
Cc: Atish Patra <[email protected]>; Alistair Francis <[email protected]>; Anup Patel <[email protected]>; U-Boot Mailing List <[email protected]>; Anup Patel <[email protected]>; Philipp Tomsich <[email protected]>
Subject: [PATCH 1/3] serial: Add RISC-V HTIF console driver

Quite a few RISC-V emulators and ISS (including Spike) have host transfer interface (HTIF) based console. This patch adds HTIF based console driver for RISC-V platforms which depends totally on DT node for HTIF register base address.

Quoted 7 lines
---
 drivers/serial/Kconfig       |   8 ++
 drivers/serial/Makefile      |   1 +
 drivers/serial/serial_htif.c | 178 +++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)
Reviewed-by
#10 lore raw

Re: [PATCH 2/3] riscv: qemu: Enable HTIF console support

In reply to a message not in the archive
Quoted 6 lines

From: Anup Patel <[email protected]>
Sent: Saturday, January 15, 2022 12:20 AM
To: Rick Jian-Zhi Chen(陳建志) <[email protected]>; Bin Meng <[email protected]>
Cc: Atish Patra <[email protected]>; Alistair Francis <[email protected]>; Anup Patel <[email protected]>; U-Boot Mailing List <[email protected]>; Anup Patel <[email protected]>; Philipp Tomsich <[email protected]>
Subject: [PATCH 2/3] riscv: qemu: Enable HTIF console support

Quoted 7 lines

Enable support for HTIF console so that we can use QEMU RISC-V U-Boot on RISC-V emulators and ISS having it.

---
 board/emulation/qemu-riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
Reviewed-by
#13 lore raw

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

In reply to a message not in the archive
Quoted 6 lines

From: Anup Patel <[email protected]>
Sent: Saturday, January 15, 2022 12:20 AM
To: Rick Jian-Zhi Chen(陳建志) <[email protected]>; Bin Meng <[email protected]>
Cc: Atish Patra <[email protected]>; Alistair Francis <[email protected]>; Anup Patel <[email protected]>; U-Boot Mailing List <[email protected]>; Anup Patel <[email protected]>
Subject: [PATCH 3/3] riscv: qemu: Implement is_flash_available() for MTD NOR

Quoted 7 lines

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")
---
 board/emulation/qemu-riscv/qemu-riscv.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
#4 lore raw

Re: [PATCH 1/3] serial: Add RISC-V HTIF console driver

In reply to Anup Patel
Quoted 20 lines · Anup Patel

Quite a few RISC-V emulators and ISS (including Spike) have host transfer interface (HTIF) based console. This patch adds HTIF based console driver for RISC-V platforms which depends totally on DT node for HTIF register base address.

---
 drivers/serial/Kconfig       |   8 ++
 drivers/serial/Makefile      |   1 +
 drivers/serial/serial_htif.c | 178 +++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 drivers/serial/serial_htif.c
drivers/serial/Kconfig +0 -0
index 6c8fdda9a0..345d1881f5 100644

drivers/serial/Kconfig config PXA_SERIAL · line 871

Quoted 6 lines
drivers/serial/Kconfig +3 -0
@@ -866,6 +866,14 @@ config PXA_SERIAL
          If you have a machine based on a Marvell XScale PXA2xx CPU you
          can enable its onboard serial ports by enabling this option.
 
+config HTIF_CONSOLE
+       bool "RISC-V HTIF console support"
+       depends on DM_SERIAL && 64BIT

Does this driver not work on 32-bit?

drivers/serial/Kconfig config PXA_SERIAL · line 879

Quoted 8 lines
drivers/serial/Kconfig +5 -0
+       help
+         Select this to enable host transfer interface (HTIF) based serial
+         console. The HTIF device is quite common in RISC-V emulators and
+         RISC-V ISS so this driver allows using U-Boot on such platforms.
+
 config SIFIVE_SERIAL
        bool "SiFive UART support"
        depends on DM_SERIAL

Regards,
Bin

#14 lore raw

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

In reply to Anup Patel
Quoted 27 lines · Anup Patel

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")
---
 board/emulation/qemu-riscv/qemu-riscv.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
board/emulation/qemu-riscv/qemu-riscv.c +1 -0
index b0d9dd59b1..cd02dae1ab 100644
@@ -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>

board/emulation/qemu-riscv/qemu-riscv.c line 23

Quoted 7 lines
board/emulation/qemu-riscv/qemu-riscv.c +4 -0
@@ -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)) {

Why is this if statement needed?

All QEMU riscv* defconfigs are using CONFIG_OF_BOARD, and there is no OF_SEPARATE use case since QEMU DTBs are always consumed by U-Boot.

Quoted 5 lines
board/emulation/qemu-riscv/qemu-riscv.c +5 -0
+               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)

board/emulation/qemu-riscv/qemu-riscv.c line 38

Quoted 10 lines
board/emulation/qemu-riscv/qemu-riscv.c +7 -0
+                       return 1;
+       }
+
+       return 0;
+}
+#endif
+
 int board_init(void)
 {
        /*

Regards,
Bin

#20 lore raw
In reply to Anup Patel
Quoted 13 lines · Anup Patel
Quoted 11 lines · Bin Meng
Quoted 8 lines · Anup Patel

We can use same U-Boot binary compiled using qemu-riscv64_smode_defconfig on QEMU virt machine and QEMU spike machine. To achieve this, we need HTIF console support for U-Boot QEMU RISC-V board hence this series.

To test this series with latest OpenSBI, we can use the following command:
qemu-system-riscv64 -M spike -m 256M -display none -serial stdio \
-bios opensbi/build/platform/generic/firmware/fw_jump.bin -kernel \

Quoted 8 lines
Quoted 2 lines

I think you forgot to mention this needs an updated QEMU too, due to plain binary is now used for spike?

Ahh, yes. I should have provided the link to the QEMU spike machine patch.

QEMU patch link:
https://lore.kernel.org/all/[email protected]/

Please also include a patch to update the QEMU riscv board doc, with the updated instructions on QEMU for Spike machine.

Regards,
Bin

author
#5 lore raw

Re: [PATCH 1/3] serial: Add RISC-V HTIF console driver

In reply to Bin Meng
Quoted 25 lines · Bin Meng
Quoted 23 lines · Anup Patel

Quite a few RISC-V emulators and ISS (including Spike) have host transfer interface (HTIF) based console. This patch adds HTIF based console driver for RISC-V platforms which depends totally on DT node for HTIF register base address.

---
 drivers/serial/Kconfig       |   8 ++
 drivers/serial/Makefile      |   1 +
 drivers/serial/serial_htif.c | 178 +++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 drivers/serial/serial_htif.c
drivers/serial/Kconfig +0 -0
index 6c8fdda9a0..345d1881f5 100644
@@ -866,6 +866,14 @@ config PXA_SERIAL
          If you have a machine based on a Marvell XScale PXA2xx CPU you
          can enable its onboard serial ports by enabling this option.
 
Quoted 5 lines

drivers/serial/Kconfig config PXA_SERIAL · line 871

Quoted 3 lines
drivers/serial/Kconfig +3 -0
+config HTIF_CONSOLE
+       bool "RISC-V HTIF console support"
+       depends on DM_SERIAL && 64BIT

Does this driver not work on 32-bit?

Only putc() works but getc() does not work on 32-bit. Same issue is there with OpenSBI and BBL as well. That's why I have restricted this driver to 64-bit only.

Quoted 10 lines

drivers/serial/Kconfig config PXA_SERIAL · line 879

Quoted 9 lines
drivers/serial/Kconfig +5 -0
+       help
+         Select this to enable host transfer interface (HTIF) based serial
+         console. The HTIF device is quite common in RISC-V emulators and
+         RISC-V ISS so this driver allows using U-Boot on such platforms.
+
 config SIFIVE_SERIAL
        bool "SiFive UART support"
        depends on DM_SERIAL
Quoted 2 lines

Regards,
Bin

Regards,
Anup

author
#15 lore raw

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

In reply to Bin Meng
Quoted 39 lines · Bin Meng
Quoted 27 lines · Anup Patel

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")
---
 board/emulation/qemu-riscv/qemu-riscv.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
board/emulation/qemu-riscv/qemu-riscv.c +1 -0
index b0d9dd59b1..cd02dae1ab 100644
@@ -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>

board/emulation/qemu-riscv/qemu-riscv.c line 23

Quoted 7 lines
board/emulation/qemu-riscv/qemu-riscv.c +4 -0
@@ -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)) {

Why is this if statement needed?

Quoted 2 lines

All QEMU riscv* defconfigs are using CONFIG_OF_BOARD, and there is no OF_SEPARATE use case since QEMU DTBs are always consumed by U-Boot.

I added the if statement for the case if someone disables CONFIG_OF_BOARD but I can remove it if you insist.

Quoted 11 lines
Quoted 11 lines
board/emulation/qemu-riscv/qemu-riscv.c +10 -0
+               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;
+}
Quoted 8 lines

board/emulation/qemu-riscv/qemu-riscv.c line 38

Quoted 5 lines
board/emulation/qemu-riscv/qemu-riscv.c +2 -0
+#endif
+
 int board_init(void)
 {
        /*

Regards,
Bin

Regards,
Anup

author
#21 lore raw
In reply to Bin Meng
Quoted 18 lines · Bin Meng
Quoted 16 lines · Anup Patel
Quoted 13 lines · Bin Meng
Quoted 8 lines · Anup Patel

We can use same U-Boot binary compiled using qemu-riscv64_smode_defconfig on QEMU virt machine and QEMU spike machine. To achieve this, we need HTIF console support for U-Boot QEMU RISC-V board hence this series.

To test this series with latest OpenSBI, we can use the following command:
qemu-system-riscv64 -M spike -m 256M -display none -serial stdio \
-bios opensbi/build/platform/generic/firmware/fw_jump.bin -kernel \

I think you forgot to mention this needs an updated QEMU too, due to plain binary is now used for spike?

Quoted 8 lines
Quoted 5 lines

Ahh, yes. I should have provided the link to the QEMU spike machine patch.

QEMU patch link:
https://lore.kernel.org/all/[email protected]/

Please also include a patch to update the QEMU riscv board doc, with the updated instructions on QEMU for Spike machine.

Okay, I will add a separate patch in the next revision.

Regards,
Anup

Quoted 3 lines

Regards,
Bin

#6 lore raw

Re: [PATCH 1/3] serial: Add RISC-V HTIF console driver

In reply to Anup Patel
Quoted 33 lines · Anup Patel
Quoted 25 lines · Bin Meng
Quoted 23 lines · Anup Patel

Quite a few RISC-V emulators and ISS (including Spike) have host transfer interface (HTIF) based console. This patch adds HTIF based console driver for RISC-V platforms which depends totally on DT node for HTIF register base address.

---
 drivers/serial/Kconfig       |   8 ++
 drivers/serial/Makefile      |   1 +
 drivers/serial/serial_htif.c | 178 +++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 drivers/serial/serial_htif.c
drivers/serial/Kconfig +0 -0
index 6c8fdda9a0..345d1881f5 100644
@@ -866,6 +866,14 @@ config PXA_SERIAL
          If you have a machine based on a Marvell XScale PXA2xx CPU you
          can enable its onboard serial ports by enabling this option.
 
Quoted 5 lines

drivers/serial/Kconfig config PXA_SERIAL · line 871

Quoted 3 lines
drivers/serial/Kconfig +3 -0
+config HTIF_CONSOLE
+       bool "RISC-V HTIF console support"
+       depends on DM_SERIAL && 64BIT

Does this driver not work on 32-bit?

Quoted 4 lines

Only putc() works but getc() does not work on 32-bit. Same issue is there with OpenSBI and BBL as well. That's why I have restricted this driver to 64-bit only.

I don't get it. Is this a QEMU riscv32 bug?

Regards,
Bin

#16 lore raw

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

In reply to Anup Patel
Quoted 41 lines · Anup Patel
Quoted 39 lines · Bin Meng
Quoted 27 lines · Anup Patel

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")
---
 board/emulation/qemu-riscv/qemu-riscv.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
board/emulation/qemu-riscv/qemu-riscv.c +1 -0
index b0d9dd59b1..cd02dae1ab 100644
@@ -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>

board/emulation/qemu-riscv/qemu-riscv.c line 23

Quoted 7 lines
board/emulation/qemu-riscv/qemu-riscv.c +4 -0
@@ -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)) {

Why is this if statement needed?

Quoted 6 lines
Quoted 2 lines

All QEMU riscv* defconfigs are using CONFIG_OF_BOARD, and there is no OF_SEPARATE use case since QEMU DTBs are always consumed by U-Boot.

I added the if statement for the case if someone disables CONFIG_OF_BOARD but I can remove it if you insist.

I see. But I if we give a dtb to QEMU without using CONFIG_OF_BOARD, the dtb may still contain a node for flash so the logic you added is still needed.

So I think you can just remove the if statement.

Also instead of using fdt_node_offset_by_compatible API please use ofnode_device_is_compatible.

Regards,
Bin

author
#7 lore raw

Re: [PATCH 1/3] serial: Add RISC-V HTIF console driver

In reply to Bin Meng
Quoted 35 lines · Bin Meng
Quoted 33 lines · Anup Patel
Quoted 30 lines · Bin Meng
Quoted 20 lines · Anup Patel

Quite a few RISC-V emulators and ISS (including Spike) have host transfer interface (HTIF) based console. This patch adds HTIF based console driver for RISC-V platforms which depends totally on DT node for HTIF register base address.

---
 drivers/serial/Kconfig       |   8 ++
 drivers/serial/Makefile      |   1 +
 drivers/serial/serial_htif.c | 178 +++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 drivers/serial/serial_htif.c
drivers/serial/Kconfig +0 -0
index 6c8fdda9a0..345d1881f5 100644

drivers/serial/Kconfig config PXA_SERIAL · line 871

Quoted 6 lines
drivers/serial/Kconfig +3 -0
@@ -866,6 +866,14 @@ config PXA_SERIAL
          If you have a machine based on a Marvell XScale PXA2xx CPU you
          can enable its onboard serial ports by enabling this option.
 
+config HTIF_CONSOLE
+       bool "RISC-V HTIF console support"
+       depends on DM_SERIAL && 64BIT

Does this driver not work on 32-bit?

Quoted 6 lines
Quoted 4 lines

Only putc() works but getc() does not work on 32-bit. Same issue is there with OpenSBI and BBL as well. That's why I have restricted this driver to 64-bit only.

I don't get it. Is this a QEMU riscv32 bug?

It's a bug in the HTIF device itself. There is no documentation of HTIF as well. All implementations (including QEMU spike) simply follow how Spike ISS implements HTIF.

In other words, HTIF is yet another undocumented device in RISC-V world.

Regards,
Anup

author
#17 lore raw

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

In reply to Bin Meng
Quoted 50 lines · Bin Meng
Quoted 41 lines · Anup Patel
Quoted 39 lines · Bin Meng
Quoted 27 lines · Anup Patel

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")
---
 board/emulation/qemu-riscv/qemu-riscv.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
board/emulation/qemu-riscv/qemu-riscv.c +1 -0
index b0d9dd59b1..cd02dae1ab 100644
@@ -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>

board/emulation/qemu-riscv/qemu-riscv.c line 23

Quoted 7 lines
board/emulation/qemu-riscv/qemu-riscv.c +4 -0
@@ -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)) {

Why is this if statement needed?

Quoted 6 lines
Quoted 2 lines

All QEMU riscv* defconfigs are using CONFIG_OF_BOARD, and there is no OF_SEPARATE use case since QEMU DTBs are always consumed by U-Boot.

I added the if statement for the case if someone disables CONFIG_OF_BOARD but I can remove it if you insist.

Quoted 5 lines

I see. But I if we give a dtb to QEMU without using CONFIG_OF_BOARD, the dtb may still contain a node for flash so the logic you added is still needed.

So I think you can just remove the if statement.

Okay, I will remove the "if ()" check.

Quoted 3 lines

Also instead of using fdt_node_offset_by_compatible API please use ofnode_device_is_compatible.

Sure, I will try ofnode_device_is_compatible().

Quoted 3 lines

Regards,
Bin

Regards,
Anup