Skip to contentSkip to conversation

QEMU spike machine support for U-Boot

PATCH In review Anup Patel 5 participants 12 messages Jan 27, 2022 – Feb 7, 2022 1 message not in the archive RISC-V

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v2 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_v2 branch at:
https://github.com/avpatel/u-boot.git

Changes since v1:
- Use ofnode_by_compatible() in PATCH3
- Updated QEMU RISC-V documentation in PATCH4

Anup Patel (4):
serial: Add RISC-V HTIF console driver
riscv: qemu: Enable HTIF console support
riscv: qemu: Implement is_flash_available() for MTD NOR
doc: qemu-riscv: Update documentation for QEMU spike machine

 board/emulation/qemu-riscv/Kconfig      |   1 +
 board/emulation/qemu-riscv/qemu-riscv.c |  12 ++
 doc/board/emulation/qemu-riscv.rst      |  48 ++++---
 drivers/serial/Kconfig                  |   8 ++
 drivers/serial/Makefile                 |   1 +
 drivers/serial/serial_htif.c            | 178 ++++++++++++++++++++++++
 6 files changed, 232 insertions(+), 16 deletions(-)
 create mode 100644 drivers/serial/serial_htif.c
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/4 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
Tested-by on v2 1/4
#2 lore raw

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

Quoted 9 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.

Quoted 7 lines
---
 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
author
#3 lore raw

PATCH v2 2/4 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
Reviewed-by Tested-by on v2 2/4
#4 lore raw

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

Quoted 11 lines · 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(+)
author
#5 lore raw

PATCH v2 3/4 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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)
board/emulation/qemu-riscv/qemu-riscv.c +12 -0
index b0d9dd59b1..ae3b7a3295 100644
@@ -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)
+int is_flash_available(void)
+{
+	if (!ofnode_equal(ofnode_by_compatible(ofnode_null(), "cfi-flash"),
+			  ofnode_null()))
+		return 1;
+
+	return 0;
+}
+#endif
+
 int board_init(void)
 {
 	/*
Signature · 1 line
2.25.1
Reviewed-by Tested-by on v2 3/4
#6 lore raw

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

Quoted 8 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.

Quoted 7 lines
Fixes d248627f9d42 ("riscv: qemu: Enable MTD NOR flash support")
---
 board/emulation/qemu-riscv/qemu-riscv.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
#7 lore raw

Re: [PATCH v2 3/4] 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 | 12 ++++++++++++
  1 file changed, 12 insertions(+)
board/emulation/qemu-riscv/qemu-riscv.c +1 -0
index b0d9dd59b1..ae3b7a3295 100644
@@ -5,6 +5,7 @@
 
  #include <common.h>
  #include <dm.h>
+#include <dm/ofnode.h>
  #include <env.h>
  #include <fdtdec.h>
  #include <image.h>

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

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

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

Quoted 1 line
board/emulation/qemu-riscv/qemu-riscv.c +1 -0
+int is_flash_available(void)

Currently there is no include defining the is_flash_available(). This needs to be fixed.

Best regards

Heinrich

Quoted 12 lines
board/emulation/qemu-riscv/qemu-riscv.c +9 -0
+{
+	if (!ofnode_equal(ofnode_by_compatible(ofnode_null(), "cfi-flash"),
+			  ofnode_null()))
+		return 1;
+
+	return 0;
+}
+#endif
+
  int board_init(void)
  {
  	/*
author
#8 lore raw

PATCH v2 4/4 doc: qemu-riscv: Update documentation for QEMU spike machine

In reply to Anup Patel

We can now use same U-Boot images on both QEMU virt machine and QEMU spike machine so let's update the QEMU RISC-V documentation.

---
 doc/board/emulation/qemu-riscv.rst | 48 ++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 16 deletions(-)
doc/board/emulation/qemu-riscv.rst +32 -16
index 4b8e104a21..0a4b121687 100644
@@ -4,16 +4,21 @@
 QEMU RISC-V
 ===========
 
-QEMU for RISC-V supports a special 'virt' machine designed for emulation and
-virtualization purposes. This document describes how to run U-Boot under it.
-Both 32-bit and 64-bit targets are supported, running in either machine or
-supervisor mode.
+QEMU for RISC-V supports a special 'virt' machine and 'spike' machine designed
+for emulation and virtualization purposes. This document describes how to run
+U-Boot under it. Both 32-bit and 64-bit targets are supported, running in
+either machine or supervisor mode.
 
 The QEMU virt machine models a generic RISC-V virtual machine with support for
 the VirtIO standard networking and block storage devices. It has CLINT, PLIC,
 16550A UART devices in addition to VirtIO and it also uses device-tree to pass
-configuration information to guest software. It implements RISC-V privileged
-architecture spec v1.10.
+configuration information to guest software. It implements the latest RISC-V
+privileged architecture.
+
+The QEMU spike machine models a minimalistic RISC-V virtual machine with
+only CLINT and HTIF devices. It also uses device-tree to pass configuration
+information to guest software and implements the latest RISC-V privileged
+architecture.
 
 Building U-Boot
 ---------------
@@ -38,13 +43,17 @@ Running U-Boot
 --------------
 The minimal QEMU command line to get U-Boot up and running is:
 
-- For 32-bit RISC-V::
+- For 32-bit RISC-V virt machine::
 
-    qemu-system-riscv32 -nographic -machine virt -bios u-boot
+    qemu-system-riscv32 -nographic -machine virt -bios u-boot.bin
 
-- For 64-bit RISC-V::
+- For 64-bit RISC-V virt machine::
+
+    qemu-system-riscv64 -nographic -machine virt -bios u-boot.bin
+
+- For 64-bit RISC-V spike machine::
 
-    qemu-system-riscv64 -nographic -machine virt -bios u-boot
+    qemu-system-riscv64 -nographic -machine spike -bios u-boot.bin
 
 The commands above create targets with 128MiB memory by default.
 A freely configurable amount of RAM can be created via the '-m'
@@ -55,6 +64,7 @@ the new setting.
 For instructions on how to run U-Boot in supervisor mode on QEMU
 with OpenSBI, see the documentation available with OpenSBI:
 https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
+https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
 
 These have been tested in QEMU 5.0.0.
 
@@ -77,8 +87,9 @@ supported by U-Boot. Clone the OpenSBI repository and run the following command.
 
 See the OpenSBI documentation for full details:
 https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
+https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
 
-To make the FW_DYNAMIC binary (build/platform/qemu/virt/firmware/fw_dynamic.bin)
+To make the FW_DYNAMIC binary (build/platform/generic/firmware/fw_dynamic.bin)
 available to U-Boot, either copy it into the U-Boot root directory or specify
 its location with the OPENSBI environment variable. Afterwards, compile U-Boot
 with the following commands.
@@ -96,17 +107,22 @@ with the following commands.
 The minimal QEMU commands to run U-Boot SPL in both 32-bit and 64-bit
 configurations are:
 
-- For 32-bit RISC-V::
+- For 32-bit RISC-V virt machine::
 
-    qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl \
+    qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl.bin \
     -device loader,file=u-boot.itb,addr=0x80200000
 
-- For 64-bit RISC-V::
+- For 64-bit RISC-V virt machine::
+
+    qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl.bin \
+    -device loader,file=u-boot.itb,addr=0x80200000
+
+- For 64-bit RISC-V spike machine::
 
-    qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl \
+    qemu-system-riscv64 -nographic -machine spike -bios spl/u-boot-spl.bin \
     -device loader,file=u-boot.itb,addr=0x80200000
 
-An attached disk can be emulated by adding::
+An attached disk can be emulated in RISC-V virt machine by adding::
 
     -device ich9-ahci,id=ahci \
     -drive if=none,file=riscv64.img,format=raw,id=mydisk \
Signature · 1 line
2.25.1
Reviewed-by on v2 4/4
#9 lore raw

Re: [PATCH v2 4/4] doc: qemu-riscv: Update documentation for QEMU spike machine

Quoted 9 lines · Anup Patel

We can now use same U-Boot images on both QEMU virt machine and QEMU spike machine so let's update the QEMU RISC-V documentation.

---
 doc/board/emulation/qemu-riscv.rst | 48 ++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 16 deletions(-)
#10 lore raw
In reply to Anup Patel

Hi Rick,

Quoted 17 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 \
./u-boot/u-boot.bin

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

Changes since v1:
- Use ofnode_by_compatible() in PATCH3
- Updated QEMU RISC-V documentation in PATCH4

Quoted 5 lines

Anup Patel (4):
serial: Add RISC-V HTIF console driver
riscv: qemu: Enable HTIF console support
riscv: qemu: Implement is_flash_available() for MTD NOR
doc: qemu-riscv: Update documentation for QEMU spike machine

Can this series be considered for the upcoming v2022.04 release ?

Best Regards,
Anup

Quoted 13 lines
 board/emulation/qemu-riscv/Kconfig      |   1 +
 board/emulation/qemu-riscv/qemu-riscv.c |  12 ++
 doc/board/emulation/qemu-riscv.rst      |  48 ++++---
 drivers/serial/Kconfig                  |   8 ++
 drivers/serial/Makefile                 |   1 +
 drivers/serial/serial_htif.c            | 178 ++++++++++++++++++++++++
 6 files changed, 232 insertions(+), 16 deletions(-)
 create mode 100644 drivers/serial/serial_htif.c

--
2.25.1

A message that is not in the archive (sent off-list or not yet received): HK0PR03MB2994AD37D80D204D94463A57C12C9@HK0PR03MB2994.apcprd03.prod.outlook.com

#12 lore raw

HI Anup,

Quoted 26 lines

From: Anup Patel <[email protected]>
Sent: Sunday, February 06, 2022 4:41 PM
To: Rick Jian-Zhi Chen(陳建志) <[email protected]>
Cc: Bin Meng <[email protected]>; Atish Patra <[email protected]>; Alistair Francis <[email protected]>; Anup Patel <[email protected]>; U-Boot Mailing List <[email protected]>
Subject: Re: [PATCH v2 0/4] QEMU spike machine support for U-Boot

Hi Rick,

Quoted 17 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 \
./u-boot/u-boot.bin

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

Changes since v1:
- Use ofnode_by_compatible() in PATCH3
- Updated QEMU RISC-V documentation in PATCH4

Quoted 7 lines
Quoted 5 lines

Anup Patel (4):
serial: Add RISC-V HTIF console driver
riscv: qemu: Enable HTIF console support
riscv: qemu: Implement is_flash_available() for MTD NOR
doc: qemu-riscv: Update documentation for QEMU spike machine

Can this series be considered for the upcoming v2022.04 release ?

Yes, cc Leo and he will follow this series and apply ASAP.

Thanks,
Rick