Skip to contentSkip to conversation

RISC-V: Add default OpenSBI ROM

PATCH Superseded Alistair Francis 6 participants 9 messages Jul 8, 2019 – Jul 10, 2019

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover RISC-V: Add default OpenSBI ROM

This series includes the OpenSBI firmware for QEMU RISC-V users.

To avoid breakages we have not changed the default behaviour of QEMU. The plan is to change the default though, which is why an entry to the qemu-deprecated.texi file has been added as well as a new warning.

After this series QEMU 4.1 has three options:
1. ``-bios none`` - This is the current default behavior if no -bios option is included. QEMU will not automatically load any firmware. It is up to the user to load all the images they need.
2. ``-bios default`` - In a future QEMU release this will become the default behaviour if no -bios option is specified. This option will load the default OpenSBI firmware automatically. The firmware is included with the QEMU release and no user interaction is required. All a user needs to do is specify the kernel they want to boot with the -kernel option
3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae.

All users should transition to using a -bios option. We can start updating all documentation after the release of 4.1.

At the end of this series and the transition period we are in the good place of no longer requiring users to build firmware to boot a kernel. Instead users can just run QEMU with the -kernel option and everything will work. They can also override the firmware with their own using the -bios option. Using "-bios none" will result in no firmware being loaded (as it is today).

This is based on my original series adding OpenSBI support but now has improved documentation changes around the license.

Alistair Francis (2):
roms: Add OpenSBI version 0.4
hw/riscv: Load OpenSBI as the default firmware

 .gitmodules                                  |   3 ++
 LICENSE                                      |  21 +++++---
 Makefile                                     |   5 +-
 hw/riscv/boot.c                              |  49 +++++++++++++++++++
 hw/riscv/sifive_u.c                          |   7 +--
 hw/riscv/virt.c                              |  11 +++--
 include/hw/riscv/boot.h                      |   3 ++
 pc-bios/README                               |  11 +++++
 pc-bios/opensbi-riscv32-virt-fw_jump.bin     | Bin 0 -> 36888 bytes
 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 40968 bytes
 pc-bios/opensbi-riscv64-virt-fw_jump.bin     | Bin 0 -> 40968 bytes
 qemu-deprecated.texi                         |  20 ++++++++
 roms/Makefile                                |  48 +++++++++++++-----
 roms/opensbi                                 |   1 +
 14 files changed, 152 insertions(+), 27 deletions(-)
 create mode 100755 pc-bios/opensbi-riscv32-virt-fw_jump.bin
 create mode 100755 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin
 create mode 100755 pc-bios/opensbi-riscv64-virt-fw_jump.bin
 create mode 160000 roms/opensbi
Signature · 1 line
2.22.0
#1 lore raw

PATCH 1/2 roms: Add OpenSBI version 0.4

Add OpenSBI version 0.4 as a git submodule and as a prebult binary.

OpenSBI (https://github.com/riscv/opensbi) aims to provide an open-source reference implementation of the RISC-V Supervisor Binary Interface (SBI) specifications for platform-specific firmwares executing in M-mode. For all supported platforms, OpenSBI provides several runtime firmware examples. These example firmwares can be used to replace the legacy riscv-pk bootloader and enable the use of well-known bootloaders such as U-Boot.

OpenSBI is distributed under the terms of the BSD 2-clause license ("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). OpenSBI source code also contains code reused from other projects desribed here:
https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md.

In this case all of the code we are using from OpenSBI is BSD 2-clause as we aren't using the Kendryte code (Apache-2.0) with QEMU and libfdt is dual licensed as BSD 2-clause (and GPL-2.0+). OpenSBI isn't being linked with QEMU either it is just being included with QEMU.

---
 .gitmodules                                  |   3 ++
 LICENSE                                      |  21 ++++----
 Makefile                                     |   5 +-
 pc-bios/README                               |  11 +++++
 pc-bios/opensbi-riscv32-virt-fw_jump.bin     | Bin 0 -> 36888 bytes
 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 40968 bytes
 pc-bios/opensbi-riscv64-virt-fw_jump.bin     | Bin 0 -> 40968 bytes
 roms/Makefile                                |  48 ++++++++++++++-----
 roms/opensbi                                 |   1 +
 9 files changed, 68 insertions(+), 21 deletions(-)
 create mode 100755 pc-bios/opensbi-riscv32-virt-fw_jump.bin
 create mode 100755 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin
 create mode 100755 pc-bios/opensbi-riscv64-virt-fw_jump.bin
 create mode 160000 roms/opensbi
.gitmodules +3 -0
index 2857eec763..7a10e72e09 100644
@@ -55,3 +55,6 @@
 [submodule "slirp"]
 	path = slirp
 	url = https://git.qemu.org/git/libslirp.git
+[submodule "roms/opensbi"]
+	path = roms/opensbi
+	url = https://github.com/riscv/opensbi.git
LICENSE +13 -8
index 0e0b4b9553..9389ba614f 100644
@@ -1,13 +1,18 @@
-The following points clarify the QEMU license:
+The QEMU distribution includes both the QEMU emulator and
+various firmware files.  These are separate programs that are
+distributed together for our users' convenience, and they have
+separate licenses.
 
-1) QEMU as a whole is released under the GNU General Public License,
-version 2.
+The following points clarify the license of the QEMU emulator:
 
-2) Parts of QEMU have specific licenses which are compatible with the
-GNU General Public License, version 2. Hence each source file contains
-its own licensing information.  Source files with no licensing information
-are released under the GNU General Public License, version 2 or (at your
-option) any later version.
+1) The QEMU emulator as a whole is released under the GNU General
+Public License, version 2.
+
+2) Parts of the QEMU emulator have specific licenses which are compatible
+with the GNU General Public License, version 2. Hence each source file
+contains its own licensing information.  Source files with no licensing
+information are released under the GNU General Public License, version
+2 or (at your option) any later version.
 
 As of July 2013, contributions under version 2 of the GNU General Public
 License (and no later version) are only accepted for the following files
Makefile +4 -1
index c63de4e36c..f75b495cab 100644
@@ -768,7 +768,10 @@ palcode-clipper \
 u-boot.e500 u-boot-sam460-20100605.bin \
 qemu_vga.ndrv \
 edk2-licenses.txt \
-hppa-firmware.img
+hppa-firmware.img \
+opensbi-riscv32-virt-fw_jump.bin \
+opensbi-riscv64-sifive_u-fw_jump.bin opensbi-riscv64-virt-fw_jump.bin
+
 
 DESCS=50-edk2-i386-secure.json 50-edk2-x86_64-secure.json \
 60-edk2-aarch64.json 60-edk2-arm.json 60-edk2-i386.json 60-edk2-x86_64.json
pc-bios/README +11 -0
index 180795a55b..eacb97043d 100644
@@ -63,3 +63,14 @@
   ARM. Licensing information is given in "edk2-licenses.txt". The image files
   are described by the JSON documents in the "pc-bios/descriptors" directory,
   which conform to the "docs/interop/firmware.json" schema.
+
+- OpenSBI (https://github.com/riscv/opensbi) aims to provide an open-source
+  reference implementation of the RISC-V Supervisor Binary Interface (SBI)
+  specifications for platform-specific firmwares executing in M-mode. For all
+  supported platforms, OpenSBI provides several runtime firmware examples.
+  These example firmwares can be used to replace the legacy riscv-pk bootloader
+  and enable the use of well-known bootloaders such as U-Boot.
+  OpenSBI is distributed under the terms of the BSD 2-clause license
+  ("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). OpenSBI
+  source code also contains code reused from other projects desribed here:
+  https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md.
pc-bios/opensbi-riscv32-virt-fw_jump.bin new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..f5bcaa56954c860d09acc0cb337c1666d88b6efb
GIT binary patch
pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..5d7a1ef6818994bac4a36818ad36043b592ce309
GIT binary patch
pc-bios/opensbi-riscv64-virt-fw_jump.bin new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..4cec6f0210f31969ac232123ce101ce71bbf9f2b
GIT binary patch
roms/Makefile +36 -12

69 lines not on this page · raw message

roms/opensbi new file +1 -0
new file mode 160000
index 0000000000..ce228ee091
@@ -0,0 +1 @@
+Subproject commit ce228ee0919deb9957192d723eecc8aaae2697c6
Signature · 1 line
2.22.0
#2 lore raw

Re: [Qemu-devel] [PATCH v1 1/2] roms: Add OpenSBI version 0.4

Quoted 42 lines · Alistair Francis

Add OpenSBI version 0.4 as a git submodule and as a prebult binary.

OpenSBI (https://github.com/riscv/opensbi) aims to provide an open-source reference implementation of the RISC-V Supervisor Binary Interface (SBI) specifications for platform-specific firmwares executing in M-mode. For all supported platforms, OpenSBI provides several runtime firmware examples. These example firmwares can be used to replace the legacy riscv-pk bootloader and enable the use of well-known bootloaders such as U-Boot.

OpenSBI is distributed under the terms of the BSD 2-clause license ("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). OpenSBI source code also contains code reused from other projects desribed here:
https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md.

In this case all of the code we are using from OpenSBI is BSD 2-clause as we aren't using the Kendryte code (Apache-2.0) with QEMU and libfdt is dual licensed as BSD 2-clause (and GPL-2.0+). OpenSBI isn't being linked with QEMU either it is just being included with QEMU.

---
 .gitmodules                                  |   3 ++
 LICENSE                                      |  21 ++++----
 Makefile                                     |   5 +-
 pc-bios/README                               |  11 +++++
 pc-bios/opensbi-riscv32-virt-fw_jump.bin     | Bin 0 -> 36888 bytes
 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 40968 bytes
 pc-bios/opensbi-riscv64-virt-fw_jump.bin     | Bin 0 -> 40968 bytes
 roms/Makefile                                |  48 ++++++++++++++-----
 roms/opensbi                                 |   1 +
 9 files changed, 68 insertions(+), 21 deletions(-)
 create mode 100755 pc-bios/opensbi-riscv32-virt-fw_jump.bin
 create mode 100755 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin
 create mode 100755 pc-bios/opensbi-riscv64-virt-fw_jump.bin
 create mode 160000 roms/opensbi
.gitmodules +0 -0
index 2857eec763..7a10e72e09 100644

.gitmodules line 60

Quoted 6 lines
.gitmodules +3 -0
@@ -55,3 +55,6 @@
 [submodule "slirp"]
 	path = slirp
 	url = https://git.qemu.org/git/libslirp.git
+[submodule "roms/opensbi"]
+	path = roms/opensbi
+	url = https://github.com/riscv/opensbi.git

It seems we prefer to use mirrors on git.qemu.org, but this can be fixed in a later patch.

Quoted 1,417 lines
LICENSE +13 -8
index 0e0b4b9553..9389ba614f 100644
@@ -1,13 +1,18 @@
-The following points clarify the QEMU license:
+The QEMU distribution includes both the QEMU emulator and
+various firmware files.  These are separate programs that are
+distributed together for our users' convenience, and they have
+separate licenses.
 
-1) QEMU as a whole is released under the GNU General Public License,
-version 2.
+The following points clarify the license of the QEMU emulator:
 
-2) Parts of QEMU have specific licenses which are compatible with the
-GNU General Public License, version 2. Hence each source file contains
-its own licensing information.  Source files with no licensing information
-are released under the GNU General Public License, version 2 or (at your
-option) any later version.
+1) The QEMU emulator as a whole is released under the GNU General
+Public License, version 2.
+
+2) Parts of the QEMU emulator have specific licenses which are compatible
+with the GNU General Public License, version 2. Hence each source file
+contains its own licensing information.  Source files with no licensing
+information are released under the GNU General Public License, version
+2 or (at your option) any later version.
 
 As of July 2013, contributions under version 2 of the GNU General Public
 License (and no later version) are only accepted for the following files
Makefile +4 -1
index c63de4e36c..f75b495cab 100644
@@ -768,7 +768,10 @@ palcode-clipper \
 u-boot.e500 u-boot-sam460-20100605.bin \
 qemu_vga.ndrv \
 edk2-licenses.txt \
-hppa-firmware.img
+hppa-firmware.img \
+opensbi-riscv32-virt-fw_jump.bin \
+opensbi-riscv64-sifive_u-fw_jump.bin opensbi-riscv64-virt-fw_jump.bin
+
 
 DESCS=50-edk2-i386-secure.json 50-edk2-x86_64-secure.json \
 60-edk2-aarch64.json 60-edk2-arm.json 60-edk2-i386.json 60-edk2-x86_64.json
pc-bios/README +11 -0
index 180795a55b..eacb97043d 100644
@@ -63,3 +63,14 @@
   ARM. Licensing information is given in "edk2-licenses.txt". The image files
   are described by the JSON documents in the "pc-bios/descriptors" directory,
   which conform to the "docs/interop/firmware.json" schema.
+
+- OpenSBI (https://github.com/riscv/opensbi) aims to provide an open-source
+  reference implementation of the RISC-V Supervisor Binary Interface (SBI)
+  specifications for platform-specific firmwares executing in M-mode. For all
+  supported platforms, OpenSBI provides several runtime firmware examples.
+  These example firmwares can be used to replace the legacy riscv-pk bootloader
+  and enable the use of well-known bootloaders such as U-Boot.
+  OpenSBI is distributed under the terms of the BSD 2-clause license
+  ("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). OpenSBI
+  source code also contains code reused from other projects desribed here:
+  https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md.
pc-bios/opensbi-riscv32-virt-fw_jump.bin new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..f5bcaa56954c860d09acc0cb337c1666d88b6efb
GIT binary patch
pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..5d7a1ef6818994bac4a36818ad36043b592ce309
GIT binary patch
pc-bios/opensbi-riscv64-virt-fw_jump.bin new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..4cec6f0210f31969ac232123ce101ce71bbf9f2b
GIT binary patch
roms/Makefile +36 -12
index 078d3fb705..dc70fb5aea 100644
@@ -37,6 +37,8 @@ find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1))))
 powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
 powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
 x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+riscv32_cross_prefix := $(call find-cross-prefix,riscv32)
+riscv64_cross_prefix := $(call find-cross-prefix,riscv64)
 
 # tag our seabios builds
 SEABIOS_EXTRAVERSION="-prebuilt.qemu.org"
@@ -52,18 +54,21 @@ EDK2_EFIROM = edk2/BaseTools/Source/C/bin/EfiRom
 default:
 	@echo "nothing is build by default"
 	@echo "available build targets:"
-	@echo "  bios           -- update bios.bin (seabios)"
-	@echo "  vgabios        -- update vgabios binaries (seabios)"
-	@echo "  sgabios        -- update sgabios binaries"
-	@echo "  pxerom         -- update nic roms (bios only)"
-	@echo "  efirom         -- update nic roms (bios+efi)"
-	@echo "  slof           -- update slof.bin"
-	@echo "  skiboot        -- update skiboot.lid"
-	@echo "  u-boot.e500    -- update u-boot.e500"
-	@echo "  u-boot.sam460  -- update u-boot.sam460"
-	@echo "  efi            -- update UEFI (edk2) platform firmware"
-	@echo "  clean          -- delete the files generated by the previous" \
-	                          "build targets"
+	@echo "  bios               -- update bios.bin (seabios)"
+	@echo "  vgabios            -- update vgabios binaries (seabios)"
+	@echo "  sgabios            -- update sgabios binaries"
+	@echo "  pxerom             -- update nic roms (bios only)"
+	@echo "  efirom             -- update nic roms (bios+efi)"
+	@echo "  slof               -- update slof.bin"
+	@echo "  skiboot            -- update skiboot.lid"
+	@echo "  u-boot.e500        -- update u-boot.e500"
+	@echo "  u-boot.sam460      -- update u-boot.sam460"
+	@echo "  efi                -- update UEFI (edk2) platform firmware"
+	@echo "  opensbi32-virt     -- update OpenSBI for 32-bit virt machine"
+	@echo "  opensbi64-virt     -- update OpenSBI for 64-bit virt machine"
+	@echo "  opensbi64-sifive_u -- update OpenSBI for 64-bit sifive_u machine"
+	@echo "  clean              -- delete the files generated by the previous" \
+	                              "build targets"
 
 bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
 	cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
@@ -162,6 +167,24 @@ skiboot:
 efi: edk2-basetools
 	$(MAKE) -f Makefile.edk2
 
+opensbi32-virt:
+	$(MAKE) -C opensbi \
+		CROSS_COMPILE=$(riscv32_cross_prefix) \
+		PLATFORM="qemu/virt"
+	cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv32-virt-fw_jump.bin
+
+opensbi64-virt:
+	$(MAKE) -C opensbi \
+		CROSS_COMPILE=$(riscv64_cross_prefix) \
+		PLATFORM="qemu/virt"
+	cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-virt-fw_jump.bin
+
+opensbi64-sifive_u:
+	$(MAKE) -C opensbi \
+		CROSS_COMPILE=$(riscv64_cross_prefix) \
+		PLATFORM="qemu/sifive_u"
+	cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin
+
 clean:
 	rm -rf seabios/.config seabios/out seabios/builds
 	$(MAKE) -C sgabios clean
@@ -173,3 +196,4 @@ clean:
 	$(MAKE) -C u-boot-sam460ex distclean
 	$(MAKE) -C skiboot clean
 	$(MAKE) -f Makefile.edk2 clean
+	$(MAKE) -C opensbi clean
roms/opensbi new file +1 -0
new file mode 160000
index 0000000000..ce228ee091
@@ -0,0 +1 @@
+Subproject commit ce228ee0919deb9957192d723eecc8aaae2697c6
#3 lore raw

PATCH 2/2 hw/riscv: Load OpenSBI as the default firmware

In reply to Alistair Francis

If the user hasn't specified a firmware to load (with -bios) or specified no bios (with -bios none) then load OpenSBI by default. This allows users to boot a RISC-V kernel with just -kernel.

---
 hw/riscv/boot.c         | 49 +++++++++++++++++++++++++++++++++++++++++
 hw/riscv/sifive_u.c     |  7 +++---
 hw/riscv/virt.c         | 11 ++++++---
 include/hw/riscv/boot.h |  3 +++
 qemu-deprecated.texi    | 20 +++++++++++++++++
 5 files changed, 84 insertions(+), 6 deletions(-)
hw/riscv/boot.c +49 -0
index ff023f42d0..c7d72f682f 100644
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "exec/cpu-defs.h"
@@ -32,6 +33,54 @@
 # define KERNEL_BOOT_ADDRESS 0x80200000
 #endif
 
+void riscv_find_and_load_firmware(MachineState *machine,
+                                  const char *default_machine_firmware,
+                                  hwaddr firmware_load_addr)
+{
+    char *firmware_filename;
+
+    if (!machine->firmware) {
+        /*
+         * The user didn't specify -bios.
+         * At the moment we default to loading nothing when this hapens.
+         * In the future this defaul will change to loading the prebuilt
+         * OpenSBI firmware. Let's warn the user and then continue.
+        */
+        warn_report("No -bios option specified. Not loading a firmware.");
+        warn_report("This default will change in QEMU 4.3. Please use the " \
+                    "-bios option to aviod breakages when this happens.");
+        warn_report("See QEMU's deprecation documentation for details");
+        return;
+    }
+
+    if (!strcmp(machine->firmware, "default")) {
+        /*
+         * The user has specified "-bios default". That means we are going to
+         * load the OpenSBI binary included in the QEMU source.
+         *
+         * We can't load the binary by default as it will break existing users
+         * as users are already loading their own firmware.
+         *
+         * Let's try to get everyone to specify the -bios option at all times,
+         * so then in the future we can make "-bios default" the default option
+         * if no -bios option is set without breaking anything.
+         */
+        firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
+                                           default_machine_firmware);
+    } else {
+        firmware_filename = machine->firmware;
+    }
+
+    if (strcmp(firmware_filename, "none")) {
+        /* If not "none" load the firmware */
+        riscv_load_firmware(firmware_filename, firmware_load_addr);
+    }
+
+    if (!strcmp(machine->firmware, "default")) {
+        g_free(firmware_filename);
+    }
+}
+
 target_ulong riscv_load_firmware(const char *firmware_filename,
                                  hwaddr firmware_load_addr)
 {
hw/riscv/sifive_u.c +4 -3
index ca53a9290d..71b8083c05 100644
@@ -49,6 +49,8 @@
 
 #include <libfdt.h>
 
+#define BIOS_FILENAME "opensbi-riscv64-sifive_u-fw_jump.bin"
+
 static const struct MemmapEntry {
     hwaddr base;
     hwaddr size;
@@ -269,9 +271,8 @@ static void riscv_sifive_u_init(MachineState *machine)
     /* create device tree */
     create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline);
 
-    if (machine->firmware) {
-        riscv_load_firmware(machine->firmware, memmap[SIFIVE_U_DRAM].base);
-    }
+    riscv_find_and_load_firmware(machine, BIOS_FILENAME,
+                                 memmap[SIFIVE_U_DRAM].base);
 
     if (machine->kernel_filename) {
         riscv_load_kernel(machine->kernel_filename);
hw/riscv/virt.c +8 -3
index ecdc77d728..25faf3b417 100644
@@ -44,6 +44,12 @@
 
 #include <libfdt.h>
 
+#if defined(TARGET_RISCV32)
+# define BIOS_FILENAME "opensbi-riscv32-virt-fw_jump.bin"
+#else
+# define BIOS_FILENAME "opensbi-riscv64-virt-fw_jump.bin"
+#endif
+
 static const struct MemmapEntry {
     hwaddr base;
     hwaddr size;
@@ -399,9 +405,8 @@ static void riscv_virt_board_init(MachineState *machine)
     memory_region_add_subregion(system_memory, memmap[VIRT_MROM].base,
                                 mask_rom);
 
-    if (machine->firmware) {
-        riscv_load_firmware(machine->firmware, memmap[VIRT_DRAM].base);
-    }
+    riscv_find_and_load_firmware(machine, BIOS_FILENAME,
+                                 memmap[VIRT_DRAM].base);
 
     if (machine->kernel_filename) {
         uint64_t kernel_entry = riscv_load_kernel(machine->kernel_filename);
include/hw/riscv/boot.h +3 -0
index daa179b600..d56f2ae3eb 100644
@@ -20,6 +20,9 @@
 #ifndef RISCV_BOOT_H
 #define RISCV_BOOT_H
 
+void riscv_find_and_load_firmware(MachineState *machine,
+                                  const char *default_machine_firmware,
+                                  hwaddr firmware_load_addr);
 target_ulong riscv_load_firmware(const char *firmware_filename,
                                  hwaddr firmware_load_addr);
 target_ulong riscv_load_kernel(const char *kernel_filename);
qemu-deprecated.texi +20 -0
index c90b08d553..fff07bb2a3 100644
@@ -121,6 +121,26 @@ the backing storage specified with @option{-mem-path} can actually provide
 the guest RAM configured with @option{-m} and QEMU will fail to start up if
 RAM allocation is unsuccessful.
 
+@subsection RISC-V -bios (since 4.1)
+
+QEMU 4.1 introduced support for the -bios option in QEMU for RISC-V for the
+RISC-V virt machine and sifive_u machine.
+
+QEMU 4.1 has no changes to the default behaviour to avoid breakages. This
+default will change in a future QEMU release, so please prepare now. All users
+of the virt or sifive_u machine must change their command line usage.
+
+QEMU 4.1 has three options, please migrate to one of these three:
+ 1. ``-bios none`` - This is the current default behavior if no -bios option
+      is included. QEMU will not automatically load any firmware. It is up
+      to the user to load all the images they need.
+ 2. ``-bios default`` - In a future QEMU release this will become the default
+      behaviour if no -bios option is specified. This option will load the
+      default OpenSBI firmware automatically. The firmware is included with
+      the QEMU release and no user interaction is required. All a user needs
+      to do is specify the kernel they want to boot with the -kernel option
+ 3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae.
+
 @section QEMU Machine Protocol (QMP) commands
 
 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
Signature · 1 line
2.22.0
#4 lore raw

Re: [Qemu-devel] [PATCH v1 2/2] hw/riscv: Load OpenSBI as the default firmware

Quoted 55 lines · Alistair Francis

If the user hasn't specified a firmware to load (with -bios) or specified no bios (with -bios none) then load OpenSBI by default. This allows users to boot a RISC-V kernel with just -kernel.

---
 hw/riscv/boot.c         | 49 +++++++++++++++++++++++++++++++++++++++++
 hw/riscv/sifive_u.c     |  7 +++---
 hw/riscv/virt.c         | 11 ++++++---
 include/hw/riscv/boot.h |  3 +++
 qemu-deprecated.texi    | 20 +++++++++++++++++
 5 files changed, 84 insertions(+), 6 deletions(-)
hw/riscv/boot.c +25 -0
index ff023f42d0..c7d72f682f 100644
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "exec/cpu-defs.h"
@@ -32,6 +33,54 @@
 # define KERNEL_BOOT_ADDRESS 0x80200000
 #endif
 
+void riscv_find_and_load_firmware(MachineState *machine,
+                                  const char *default_machine_firmware,
+                                  hwaddr firmware_load_addr)
+{
+    char *firmware_filename;
+
+    if (!machine->firmware) {
+        /*
+         * The user didn't specify -bios.
+         * At the moment we default to loading nothing when this hapens.
+         * In the future this defaul will change to loading the prebuilt
+         * OpenSBI firmware. Let's warn the user and then continue.
+        */
+        warn_report("No -bios option specified. Not loading a firmware.");
+        warn_report("This default will change in QEMU 4.3. Please use the " \
+                    "-bios option to aviod breakages when this happens.");
+        warn_report("See QEMU's deprecation documentation for details");
+        return;
+    }
+
+    if (!strcmp(machine->firmware, "default")) {
+        /*
+         * The user has specified "-bios default". That means we are going to
+         * load the OpenSBI binary included in the QEMU source.

hw/riscv/boot.c line 69

Quoted 10 lines
hw/riscv/boot.c +10 -0
+         *
+         * We can't load the binary by default as it will break existing users
+         * as users are already loading their own firmware.
+         *
+         * Let's try to get everyone to specify the -bios option at all times,
+         * so then in the future we can make "-bios default" the default option
+         * if no -bios option is set without breaking anything.
+         */
+        firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
+                                           default_machine_firmware);

This can return NULL if the file is not found (such as after a bad install) ...

hw/riscv/boot.c line 74

Quoted 5 lines
hw/riscv/boot.c +5 -0
+    } else {
+        firmware_filename = machine->firmware;
+    }
+
+    if (strcmp(firmware_filename, "none")) {

... which will then crash here.

Quoted 111 lines
hw/riscv/boot.c +9 -0
+        /* If not "none" load the firmware */
+        riscv_load_firmware(firmware_filename, firmware_load_addr);
+    }
+
+    if (!strcmp(machine->firmware, "default")) {
+        g_free(firmware_filename);
+    }
+}
+
 target_ulong riscv_load_firmware(const char *firmware_filename,
                                  hwaddr firmware_load_addr)
 {
hw/riscv/sifive_u.c +4 -3
index ca53a9290d..71b8083c05 100644
@@ -49,6 +49,8 @@
 
 #include <libfdt.h>
 
+#define BIOS_FILENAME "opensbi-riscv64-sifive_u-fw_jump.bin"
+
 static const struct MemmapEntry {
     hwaddr base;
     hwaddr size;
@@ -269,9 +271,8 @@ static void riscv_sifive_u_init(MachineState *machine)
     /* create device tree */
     create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline);
 
-    if (machine->firmware) {
-        riscv_load_firmware(machine->firmware, memmap[SIFIVE_U_DRAM].base);
-    }
+    riscv_find_and_load_firmware(machine, BIOS_FILENAME,
+                                 memmap[SIFIVE_U_DRAM].base);
 
     if (machine->kernel_filename) {
         riscv_load_kernel(machine->kernel_filename);
hw/riscv/virt.c +8 -3
index ecdc77d728..25faf3b417 100644
@@ -44,6 +44,12 @@
 
 #include <libfdt.h>
 
+#if defined(TARGET_RISCV32)
+# define BIOS_FILENAME "opensbi-riscv32-virt-fw_jump.bin"
+#else
+# define BIOS_FILENAME "opensbi-riscv64-virt-fw_jump.bin"
+#endif
+
 static const struct MemmapEntry {
     hwaddr base;
     hwaddr size;
@@ -399,9 +405,8 @@ static void riscv_virt_board_init(MachineState *machine)
     memory_region_add_subregion(system_memory, memmap[VIRT_MROM].base,
                                 mask_rom);
 
-    if (machine->firmware) {
-        riscv_load_firmware(machine->firmware, memmap[VIRT_DRAM].base);
-    }
+    riscv_find_and_load_firmware(machine, BIOS_FILENAME,
+                                 memmap[VIRT_DRAM].base);
 
     if (machine->kernel_filename) {
         uint64_t kernel_entry = riscv_load_kernel(machine->kernel_filename);
include/hw/riscv/boot.h +3 -0
index daa179b600..d56f2ae3eb 100644
@@ -20,6 +20,9 @@
 #ifndef RISCV_BOOT_H
 #define RISCV_BOOT_H
 
+void riscv_find_and_load_firmware(MachineState *machine,
+                                  const char *default_machine_firmware,
+                                  hwaddr firmware_load_addr);
 target_ulong riscv_load_firmware(const char *firmware_filename,
                                  hwaddr firmware_load_addr);
 target_ulong riscv_load_kernel(const char *kernel_filename);
qemu-deprecated.texi +20 -0
index c90b08d553..fff07bb2a3 100644
@@ -121,6 +121,26 @@ the backing storage specified with @option{-mem-path} can actually provide
 the guest RAM configured with @option{-m} and QEMU will fail to start up if
 RAM allocation is unsuccessful.
 
+@subsection RISC-V -bios (since 4.1)
+
+QEMU 4.1 introduced support for the -bios option in QEMU for RISC-V for the
+RISC-V virt machine and sifive_u machine.
+
+QEMU 4.1 has no changes to the default behaviour to avoid breakages. This
+default will change in a future QEMU release, so please prepare now. All users
+of the virt or sifive_u machine must change their command line usage.
+
+QEMU 4.1 has three options, please migrate to one of these three:
+ 1. ``-bios none`` - This is the current default behavior if no -bios option
+      is included. QEMU will not automatically load any firmware. It is up
+      to the user to load all the images they need.
+ 2. ``-bios default`` - In a future QEMU release this will become the default
+      behaviour if no -bios option is specified. This option will load the
+      default OpenSBI firmware automatically. The firmware is included with
+      the QEMU release and no user interaction is required. All a user needs
+      to do is specify the kernel they want to boot with the -kernel option
+ 3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae.
+
 @section QEMU Machine Protocol (QMP) commands
 
 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
#5 lore raw

Re: [Qemu-devel] [PATCH v1 2/2] hw/riscv: Load OpenSBI as the default firmware

Quoted 70 lines · Guenter Roeck
Quoted 55 lines · Alistair Francis

If the user hasn't specified a firmware to load (with -bios) or specified no bios (with -bios none) then load OpenSBI by default. This allows users to boot a RISC-V kernel with just -kernel.

---
 hw/riscv/boot.c         | 49 +++++++++++++++++++++++++++++++++++++++++
 hw/riscv/sifive_u.c     |  7 +++---
 hw/riscv/virt.c         | 11 ++++++---
 include/hw/riscv/boot.h |  3 +++
 qemu-deprecated.texi    | 20 +++++++++++++++++
 5 files changed, 84 insertions(+), 6 deletions(-)
hw/riscv/boot.c +25 -0
index ff023f42d0..c7d72f682f 100644
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "exec/cpu-defs.h"
@@ -32,6 +33,54 @@
 # define KERNEL_BOOT_ADDRESS 0x80200000
 #endif
 
+void riscv_find_and_load_firmware(MachineState *machine,
+                                  const char *default_machine_firmware,
+                                  hwaddr firmware_load_addr)
+{
+    char *firmware_filename;
+
+    if (!machine->firmware) {
+        /*
+         * The user didn't specify -bios.
+         * At the moment we default to loading nothing when this hapens.
+         * In the future this defaul will change to loading the prebuilt
+         * OpenSBI firmware. Let's warn the user and then continue.
+        */
+        warn_report("No -bios option specified. Not loading a firmware.");
+        warn_report("This default will change in QEMU 4.3. Please use the " \
+                    "-bios option to aviod breakages when this happens.");
+        warn_report("See QEMU's deprecation documentation for details");
+        return;
+    }
+
+    if (!strcmp(machine->firmware, "default")) {
+        /*
+         * The user has specified "-bios default". That means we are going to
+         * load the OpenSBI binary included in the QEMU source.

hw/riscv/boot.c line 69

Quoted 10 lines
hw/riscv/boot.c +10 -0
+         *
+         * We can't load the binary by default as it will break existing users
+         * as users are already loading their own firmware.
+         *
+         * Let's try to get everyone to specify the -bios option at all times,
+         * so then in the future we can make "-bios default" the default option
+         * if no -bios option is set without breaking anything.
+         */
+        firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
+                                           default_machine_firmware);

This can return NULL if the file is not found (such as after a bad install) ...

Quoted 7 lines

hw/riscv/boot.c line 74

Quoted 5 lines
hw/riscv/boot.c +5 -0
+    } else {
+        firmware_filename = machine->firmware;
+    }
+
+    if (strcmp(firmware_filename, "none")) {

... which will then crash here.

Yep, you are right. I'll send a v2

Alistair

Quoted 112 lines
Quoted 112 lines
hw/riscv/boot.c +9 -0
+        /* If not "none" load the firmware */
+        riscv_load_firmware(firmware_filename, firmware_load_addr);
+    }
+
+    if (!strcmp(machine->firmware, "default")) {
+        g_free(firmware_filename);
+    }
+}
+
 target_ulong riscv_load_firmware(const char *firmware_filename,
                                  hwaddr firmware_load_addr)
 {
hw/riscv/sifive_u.c +4 -3
index ca53a9290d..71b8083c05 100644
@@ -49,6 +49,8 @@
 
 #include <libfdt.h>
 
+#define BIOS_FILENAME "opensbi-riscv64-sifive_u-fw_jump.bin"
+
 static const struct MemmapEntry {
     hwaddr base;
     hwaddr size;
@@ -269,9 +271,8 @@ static void riscv_sifive_u_init(MachineState *machine)
     /* create device tree */
     create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline);
 
-    if (machine->firmware) {
-        riscv_load_firmware(machine->firmware, memmap[SIFIVE_U_DRAM].base);
-    }
+    riscv_find_and_load_firmware(machine, BIOS_FILENAME,
+                                 memmap[SIFIVE_U_DRAM].base);
 
     if (machine->kernel_filename) {
         riscv_load_kernel(machine->kernel_filename);
hw/riscv/virt.c +8 -3
index ecdc77d728..25faf3b417 100644
@@ -44,6 +44,12 @@
 
 #include <libfdt.h>
 
+#if defined(TARGET_RISCV32)
+# define BIOS_FILENAME "opensbi-riscv32-virt-fw_jump.bin"
+#else
+# define BIOS_FILENAME "opensbi-riscv64-virt-fw_jump.bin"
+#endif
+
 static const struct MemmapEntry {
     hwaddr base;
     hwaddr size;
@@ -399,9 +405,8 @@ static void riscv_virt_board_init(MachineState *machine)
     memory_region_add_subregion(system_memory, memmap[VIRT_MROM].base,
                                 mask_rom);
 
-    if (machine->firmware) {
-        riscv_load_firmware(machine->firmware, memmap[VIRT_DRAM].base);
-    }
+    riscv_find_and_load_firmware(machine, BIOS_FILENAME,
+                                 memmap[VIRT_DRAM].base);
 
     if (machine->kernel_filename) {
         uint64_t kernel_entry = riscv_load_kernel(machine->kernel_filename);
include/hw/riscv/boot.h +3 -0
index daa179b600..d56f2ae3eb 100644
@@ -20,6 +20,9 @@
 #ifndef RISCV_BOOT_H
 #define RISCV_BOOT_H
 
+void riscv_find_and_load_firmware(MachineState *machine,
+                                  const char *default_machine_firmware,
+                                  hwaddr firmware_load_addr);
 target_ulong riscv_load_firmware(const char *firmware_filename,
                                  hwaddr firmware_load_addr);
 target_ulong riscv_load_kernel(const char *kernel_filename);
qemu-deprecated.texi +20 -0
index c90b08d553..fff07bb2a3 100644
@@ -121,6 +121,26 @@ the backing storage specified with @option{-mem-path} can actually provide
 the guest RAM configured with @option{-m} and QEMU will fail to start up if
 RAM allocation is unsuccessful.
 
+@subsection RISC-V -bios (since 4.1)
+
+QEMU 4.1 introduced support for the -bios option in QEMU for RISC-V for the
+RISC-V virt machine and sifive_u machine.
+
+QEMU 4.1 has no changes to the default behaviour to avoid breakages. This
+default will change in a future QEMU release, so please prepare now. All users
+of the virt or sifive_u machine must change their command line usage.
+
+QEMU 4.1 has three options, please migrate to one of these three:
+ 1. ``-bios none`` - This is the current default behavior if no -bios option
+      is included. QEMU will not automatically load any firmware. It is up
+      to the user to load all the images they need.
+ 2. ``-bios default`` - In a future QEMU release this will become the default
+      behaviour if no -bios option is specified. This option will load the
+      default OpenSBI firmware automatically. The firmware is included with
+      the QEMU release and no user interaction is required. All a user needs
+      to do is specify the kernel they want to boot with the -kernel option
+ 3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae.
+
 @section QEMU Machine Protocol (QMP) commands
 
 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
#6 lore raw
In reply to Alistair Francis
Quoted 17 lines · Alistair Francis

This series includes the OpenSBI firmware for QEMU RISC-V users.

To avoid breakages we have not changed the default behaviour of QEMU. The plan is to change the default though, which is why an entry to the qemu-deprecated.texi file has been added as well as a new warning.

After this series QEMU 4.1 has three options:
1. ``-bios none`` - This is the current default behavior if no -bios option is included. QEMU will not automatically load any firmware. It is up to the user to load all the images they need.
2. ``-bios default`` - In a future QEMU release this will become the default behaviour if no -bios option is specified. This option will load the default OpenSBI firmware automatically. The firmware is included with the QEMU release and no user interaction is required. All a user needs to do is specify the kernel they want to boot with the -kernel option
3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae.

Quoted 2 lines

All users should transition to using a -bios option. We can start updating all documentation after the release of 4.1.

I haven't looked at the code yet, but as the last one was fine it's probably OK. My only issue here is the timing: it's after the soft freeze so if I understand correctly we're not supposed to take any new features into 4.1. That's kind of unfortunate because it's somewhat unobtrusive and super useful.

Peter: would you be OK taking this some time later this week? I'd want to dig through it and then bang on it a bit first. If not then I'll queue it up for 4.2.

Quoted 33 lines

At the end of this series and the transition period we are in the good place of no longer requiring users to build firmware to boot a kernel. Instead users can just run QEMU with the -kernel option and everything will work. They can also override the firmware with their own using the -bios option. Using "-bios none" will result in no firmware being loaded (as it is today).

This is based on my original series adding OpenSBI support but now has improved documentation changes around the license.

Alistair Francis (2):
roms: Add OpenSBI version 0.4
hw/riscv: Load OpenSBI as the default firmware

 .gitmodules                                  |   3 ++
 LICENSE                                      |  21 +++++---
 Makefile                                     |   5 +-
 hw/riscv/boot.c                              |  49 +++++++++++++++++++
 hw/riscv/sifive_u.c                          |   7 +--
 hw/riscv/virt.c                              |  11 +++--
 include/hw/riscv/boot.h                      |   3 ++
 pc-bios/README                               |  11 +++++
 pc-bios/opensbi-riscv32-virt-fw_jump.bin     | Bin 0 -> 36888 bytes
 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 40968 bytes
 pc-bios/opensbi-riscv64-virt-fw_jump.bin     | Bin 0 -> 40968 bytes
 qemu-deprecated.texi                         |  20 ++++++++
 roms/Makefile                                |  48 +++++++++++++-----
 roms/opensbi                                 |   1 +
 14 files changed, 152 insertions(+), 27 deletions(-)
 create mode 100755 pc-bios/opensbi-riscv32-virt-fw_jump.bin
 create mode 100755 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin
 create mode 100755 pc-bios/opensbi-riscv64-virt-fw_jump.bin
 create mode 160000 roms/opensbi
#7 lore raw
Quoted 8 lines · Palmer Dabbelt

I haven't looked at the code yet, but as the last one was fine it's probably OK. My only issue here is the timing: it's after the soft freeze so if I understand correctly we're not supposed to take any new features into 4.1. That's kind of unfortunate because it's somewhat unobtrusive and super useful.

Peter: would you be OK taking this some time later this week? I'd want to dig through it and then bang on it a bit first. If not then I'll queue it up for 4.2.

The first attempt at putting this into master got onto the list before freeze, so it's OK. Plus this clearly will only affect users using the riscv boards, so it's a limited-scope change. So I think we're better off putting it into 4.1 rather than not, assuming you're happy with the level of testing it's had.

thanks
-- PMM

#8 lore raw
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Palmer Dabbelt

I haven't looked at the code yet, but as the last one was fine it's probably OK. My only issue here is the timing: it's after the soft freeze so if I understand correctly we're not supposed to take any new features into 4.1. That's kind of unfortunate because it's somewhat unobtrusive and super useful.

Peter: would you be OK taking this some time later this week? I'd want to dig through it and then bang on it a bit first. If not then I'll queue it up for 4.2.

Quoted 5 lines

The first attempt at putting this into master got onto the list before freeze, so it's OK. Plus this clearly will only affect users using the riscv boards, so it's a limited-scope change. So I think we're better off putting it into 4.1 rather than not, assuming you're happy with the level of testing it's had.

Awesome. I always test stuff myself a bit, but with any luck I should be able to get a good look at it over the next few days.