Skip to contentSkip to conversation

RISC-V: Add firmware loading support and default

RFC In review Alistair Francis 7 participants 30 messages Jun 19, 2019 – Jun 27, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover RISC-V: Add firmware loading support and default

This is an RFC as it will break ALL current users! See below for details.

This series consolidates the current RISC-V kernel loading impelementation while also adding support for the -bios option and more advanced kernel image types.

After consolidating the kernel loading we can extend the boot loader to support a -bios option. We can also extend the kernel loading options to support not just ELF files but other standard formats.

Finally we can include the OpenSBI firmware by default for QEMU users.

At the end of this series 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).

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Unfortunately this series (patch 5 specifically) results in all current Linux boots being broken as users are already loading in their own firmware, which overlaps with the now included default. They will see this error:

rom: requested regions overlap (rom phdr #0: ./images/qemuriscv64/fw_jump.elf. free=0x0000000080008090, addr=0x0000000080000000)
qemu-system-riscv64: rom check and register reset failed

If a current user specieifies "-bios none" their flow will continue working. A user can instead no longer load their firmware and use the default or they can load their firmware with the -bios option.

At the moment the best idea I have to not break all users is to only include the default firmware if the user specifies "-bios opensbi". That is change the default to not loading the firmware. Then we can work on updating documentation and maybe in future change the default to include a firmware and anyone who doesn't want a default firmware can specify "-bios none".

Any other ideas on how to not break everything?

Alistair Francis (5):
hw/riscv: Split out the boot functions
hw/riscv: Add support for loading a firmware
hw/riscv: Extend the kernel loading support
roms: Add OpenSBI version 0.3
hw/riscv: Load OpenSBI as the default firmware

 .gitmodules                         |   3 +
 Makefile                            |   3 +-
 configure                           |   1 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/boot.c                     | 143 ++++++++++++++++++++++++++++
 hw/riscv/sifive_e.c                 |  17 +---
 hw/riscv/sifive_u.c                 |  19 +---
 hw/riscv/spike.c                    |  21 +---
 hw/riscv/virt.c                     |  54 ++---------
 include/hw/riscv/boot.h             |  30 ++++++
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
 roms/Makefile                       |  17 ++++
 roms/opensbi                        |   1 +
 14 files changed, 216 insertions(+), 94 deletions(-)
 create mode 100644 hw/riscv/boot.c
 create mode 100644 include/hw/riscv/boot.h
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 create mode 160000 roms/opensbi
Signature · 1 line
2.22.0
#1 lore raw

RFC 1/5 hw/riscv: Split out the boot functions

Split the common RISC-V boot functions into a seperate file. This allows us to share the common code.

---
 hw/riscv/Makefile.objs  |  1 +
 hw/riscv/boot.c         | 69 +++++++++++++++++++++++++++++++++++++++++
 hw/riscv/sifive_e.c     | 17 ++--------
 hw/riscv/sifive_u.c     | 17 ++--------
 hw/riscv/spike.c        | 21 +++----------
 hw/riscv/virt.c         | 51 +++---------------------------
 include/hw/riscv/boot.h | 27 ++++++++++++++++
 7 files changed, 110 insertions(+), 93 deletions(-)
 create mode 100644 hw/riscv/boot.c
 create mode 100644 include/hw/riscv/boot.h
hw/riscv/Makefile.objs +1 -0
index a65027304a..eb9d4f9ffc 100644
@@ -1,3 +1,4 @@
+obj-y += boot.o
 obj-$(CONFIG_SPIKE) += riscv_htif.o
 obj-$(CONFIG_HART) += riscv_hart.o
 obj-$(CONFIG_SIFIVE_E) += sifive_e.o
hw/riscv/boot.c new file +69 -0

69 lines not on this page · raw message

hw/riscv/sifive_e.c +2 -15
index 80ac56fa7d..9d58ae362b 100644
@@ -44,10 +44,10 @@
 #include "hw/riscv/sifive_prci.h"
 #include "hw/riscv/sifive_uart.h"
 #include "hw/riscv/sifive_e.h"
+#include "hw/riscv/boot.h"
 #include "chardev/char.h"
 #include "sysemu/arch_init.h"
 #include "exec/address-spaces.h"
-#include "elf.h"
 
 static const struct MemmapEntry {
     hwaddr base;
@@ -74,19 +74,6 @@ static const struct MemmapEntry {
     [SIFIVE_E_DTIM] =     { 0x80000000,     0x4000 }
 };
 
-static target_ulong load_kernel(const char *kernel_filename)
-{
-    uint64_t kernel_entry, kernel_high;
-
-    if (load_elf(kernel_filename, NULL, NULL, NULL,
-                 &kernel_entry, NULL, &kernel_high,
-                 0, EM_RISCV, 1, 0) < 0) {
-        error_report("could not load kernel '%s'", kernel_filename);
-        exit(1);
-    }
-    return kernel_entry;
-}
-
 static void sifive_mmio_emulate(MemoryRegion *parent, const char *name,
                              uintptr_t offset, uintptr_t length)
 {
@@ -131,7 +118,7 @@ static void riscv_sifive_e_init(MachineState *machine)
                           memmap[SIFIVE_E_MROM].base, &address_space_memory);
 
     if (machine->kernel_filename) {
-        load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine->kernel_filename);
     }
 }
 
hw/riscv/sifive_u.c +2 -15
index 5ecc47cea3..1b9281bd4a 100644
@@ -41,11 +41,11 @@
 #include "hw/riscv/sifive_uart.h"
 #include "hw/riscv/sifive_prci.h"
 #include "hw/riscv/sifive_u.h"
+#include "hw/riscv/boot.h"
 #include "chardev/char.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/device_tree.h"
 #include "exec/address-spaces.h"
-#include "elf.h"
 
 #include <libfdt.h>
 
@@ -65,19 +65,6 @@ static const struct MemmapEntry {
 
 #define GEM_REVISION        0x10070109
 
-static target_ulong load_kernel(const char *kernel_filename)
-{
-    uint64_t kernel_entry, kernel_high;
-
-    if (load_elf(kernel_filename, NULL, NULL, NULL,
-                 &kernel_entry, NULL, &kernel_high,
-                 0, EM_RISCV, 1, 0) < 0) {
-        error_report("could not load kernel '%s'", kernel_filename);
-        exit(1);
-    }
-    return kernel_entry;
-}
-
 static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
     uint64_t mem_size, const char *cmdline)
 {
@@ -280,7 +267,7 @@ static void riscv_sifive_u_init(MachineState *machine)
     create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline);
 
     if (machine->kernel_filename) {
-        load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine->kernel_filename);
     }
 
     /* reset vector */
hw/riscv/spike.c +4 -17
index 5b33d4be3b..e68be00a5f 100644
@@ -36,12 +36,12 @@
 #include "hw/riscv/riscv_hart.h"
 #include "hw/riscv/sifive_clint.h"
 #include "hw/riscv/spike.h"
+#include "hw/riscv/boot.h"
 #include "chardev/char.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/device_tree.h"
 #include "sysemu/qtest.h"
 #include "exec/address-spaces.h"
-#include "elf.h"
 
 #include <libfdt.h>
 
@@ -54,19 +54,6 @@ static const struct MemmapEntry {
     [SPIKE_DRAM] =     { 0x80000000,        0x0 },
 };
 
-static target_ulong load_kernel(const char *kernel_filename)
-{
-    uint64_t kernel_entry, kernel_high;
-
-    if (load_elf_ram_sym(kernel_filename, NULL, NULL, NULL,
-            &kernel_entry, NULL, &kernel_high, 0, EM_RISCV, 1, 0,
-            NULL, true, htif_symbol_callback) < 0) {
-        error_report("could not load kernel '%s'", kernel_filename);
-        exit(1);
-    }
-    return kernel_entry;
-}
-
 static void create_fdt(SpikeState *s, const struct MemmapEntry *memmap,
     uint64_t mem_size, const char *cmdline)
 {
@@ -199,7 +186,7 @@ static void spike_board_init(MachineState *machine)
                                 mask_rom);
 
     if (machine->kernel_filename) {
-        load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine->kernel_filename);
     }
 
     /* reset vector */
@@ -287,7 +274,7 @@ static void spike_v1_10_0_board_init(MachineState *machine)
                                 mask_rom);
 
     if (machine->kernel_filename) {
-        load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine->kernel_filename);
     }
 
     /* reset vector */
@@ -372,7 +359,7 @@ static void spike_v1_09_1_board_init(MachineState *machine)
                                 mask_rom);
 
     if (machine->kernel_filename) {
-        load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine->kernel_filename);
     }
 
     /* reset vector */
hw/riscv/virt.c +5 -46

78 lines not on this page · raw message

include/hw/riscv/boot.h new file +27 -0
new file mode 100644
index 0000000000..f84fd6c2df
@@ -0,0 +1,27 @@
+/*
+ * QEMU RISC-V Boot Helper
+ *
+ * Copyright (c) 2017 SiFive, Inc.
+ * Copyright (c) 2019 Alistair Francis <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RISCV_BOOT_H
+#define RISCV_BOOT_H
+
+target_ulong riscv_load_kernel(const char *kernel_filename);
+hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,
+                         uint64_t kernel_entry, hwaddr *start);
+
+#endif /* RISCV_BOOT_H */
Signature · 1 line
2.22.0
Reviewed-by Tested-by on v1 1/5
#2 lore raw

Re: [Qemu-devel] [RFC v1 1/5] hw/riscv: Split out the boot functions

Quoted 69 lines · Alistair Francis

Split the common RISC-V boot functions into a seperate file. This allows us to share the common code.

---
 hw/riscv/Makefile.objs  |  1 +
 hw/riscv/boot.c         | 69 +++++++++++++++++++++++++++++++++++++++++
 hw/riscv/sifive_e.c     | 17 ++--------
 hw/riscv/sifive_u.c     | 17 ++--------
 hw/riscv/spike.c        | 21 +++----------
 hw/riscv/virt.c         | 51 +++---------------------------
 include/hw/riscv/boot.h | 27 ++++++++++++++++
 7 files changed, 110 insertions(+), 93 deletions(-)
 create mode 100644 hw/riscv/boot.c
 create mode 100644 include/hw/riscv/boot.h
hw/riscv/Makefile.objs +1 -0
index a65027304a..eb9d4f9ffc 100644
@@ -1,3 +1,4 @@
+obj-y += boot.o
 obj-$(CONFIG_SPIKE) += riscv_htif.o
 obj-$(CONFIG_HART) += riscv_hart.o
 obj-$(CONFIG_SIFIVE_E) += sifive_e.o
hw/riscv/boot.c new file +37 -0
new file mode 100644
index 0000000000..62f94aaf8a
@@ -0,0 +1,69 @@
+/*
+ * QEMU RISC-V Boot Helper
+ *
+ * Copyright (c) 2017 SiFive, Inc.
+ * Copyright (c) 2019 Alistair Francis <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "qemu/error-report.h"
+#include "exec/cpu-defs.h"
+#include "hw/loader.h"
+#include "hw/riscv/boot.h"
+#include "elf.h"
+
+target_ulong riscv_load_kernel(const char *kernel_filename)
+{
+    uint64_t kernel_entry, kernel_high;
+
+    if (load_elf(kernel_filename, NULL, NULL, NULL,
+                 &kernel_entry, NULL, &kernel_high,
+                 0, EM_RISCV, 1, 0) < 0) {
+        error_report("could not load kernel '%s'", kernel_filename);
+        exit(1);
+    }

hw/riscv/boot.c line 47

Quoted 10 lines
hw/riscv/boot.c new file +10 -0
+
+    return kernel_entry;
+}
+
+hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,
+                         uint64_t kernel_entry, hwaddr *start)
+{
+    int size;
+
+    /* We want to put the initrd far enough into RAM that when the

nits: /* should be on a separate line

Quoted 9 lines
hw/riscv/boot.c new file +9 -0
+     * kernel is uncompressed it will not clobber the initrd. However
+     * on boards without much RAM we must ensure that we still leave
+     * enough room for a decent sized initrd, and on boards with large
+     * amounts of RAM we must avoid the initrd being so far up in RAM
+     * that it is outside lowmem and inaccessible to the kernel.
+     * So for boards with less  than 256MB of RAM we put the initrd
+     * halfway into RAM, and for boards with 256MB of RAM or more we put
+     * the initrd at 128MB.
+     */

[snip]

#3 lore raw

Re: [Qemu-devel] [RFC v1 1/5] hw/riscv: Split out the boot functions

Quoted 76 lines · Bin Meng
Quoted 73 lines · Alistair Francis

Split the common RISC-V boot functions into a seperate file. This allows us to share the common code.

---
 hw/riscv/Makefile.objs  |  1 +
 hw/riscv/boot.c         | 69 +++++++++++++++++++++++++++++++++++++++++
 hw/riscv/sifive_e.c     | 17 ++--------
 hw/riscv/sifive_u.c     | 17 ++--------
 hw/riscv/spike.c        | 21 +++----------
 hw/riscv/virt.c         | 51 +++---------------------------
 include/hw/riscv/boot.h | 27 ++++++++++++++++
 7 files changed, 110 insertions(+), 93 deletions(-)
 create mode 100644 hw/riscv/boot.c
 create mode 100644 include/hw/riscv/boot.h
hw/riscv/Makefile.objs +1 -0
index a65027304a..eb9d4f9ffc 100644
@@ -1,3 +1,4 @@
+obj-y += boot.o
 obj-$(CONFIG_SPIKE) += riscv_htif.o
 obj-$(CONFIG_HART) += riscv_hart.o
 obj-$(CONFIG_SIFIVE_E) += sifive_e.o
hw/riscv/boot.c new file +41 -0
new file mode 100644
index 0000000000..62f94aaf8a
@@ -0,0 +1,69 @@
+/*
+ * QEMU RISC-V Boot Helper
+ *
+ * Copyright (c) 2017 SiFive, Inc.
+ * Copyright (c) 2019 Alistair Francis <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "qemu/error-report.h"
+#include "exec/cpu-defs.h"
+#include "hw/loader.h"
+#include "hw/riscv/boot.h"
+#include "elf.h"
+
+target_ulong riscv_load_kernel(const char *kernel_filename)
+{
+    uint64_t kernel_entry, kernel_high;
+
+    if (load_elf(kernel_filename, NULL, NULL, NULL,
+                 &kernel_entry, NULL, &kernel_high,
+                 0, EM_RISCV, 1, 0) < 0) {
+        error_report("could not load kernel '%s'", kernel_filename);
+        exit(1);
+    }
+
+    return kernel_entry;
+}
+
Quoted 8 lines

hw/riscv/boot.c line 47

Quoted 6 lines
hw/riscv/boot.c new file +6 -0
+hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,
+                         uint64_t kernel_entry, hwaddr *start)
+{
+    int size;
+
+    /* We want to put the initrd far enough into RAM that when the

nits: /* should be on a separate line

Fixed

Quoted 11 lines

hw/riscv/boot.c line 56

Quoted 10 lines
hw/riscv/boot.c new file +9 -0
+     * kernel is uncompressed it will not clobber the initrd. However
+     * on boards without much RAM we must ensure that we still leave
+     * enough room for a decent sized initrd, and on boards with large
+     * amounts of RAM we must avoid the initrd being so far up in RAM
+     * that it is outside lowmem and inaccessible to the kernel.
+     * So for boards with less  than 256MB of RAM we put the initrd
+     * halfway into RAM, and for boards with 256MB of RAM or more we put
+     * the initrd at 128MB.
+     */
Quoted 4 lines

[snip]

Thanks!

Alistair

#4 lore raw

RFC 2/5 hw/riscv: Add support for loading a firmware

In reply to Alistair Francis

Add support for loading a firmware file for the virt machine and the SiFive U. This can be run with the following command:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel vmlinux

---
 hw/riscv/boot.c         | 41 +++++++++++++++++++++++++++++++++++++++--
 hw/riscv/sifive_e.c     |  2 +-
 hw/riscv/sifive_u.c     |  6 +++++-
 hw/riscv/spike.c        |  6 +++---
 hw/riscv/virt.c         |  7 ++++++-
 include/hw/riscv/boot.h |  4 +++-
 6 files changed, 57 insertions(+), 9 deletions(-)
hw/riscv/boot.c +39 -2
index 62f94aaf8a..392ca0cb2e 100644
@@ -23,13 +23,50 @@
 #include "exec/cpu-defs.h"
 #include "hw/loader.h"
 #include "hw/riscv/boot.h"
+#include "hw/boards.h"
 #include "elf.h"
 
-target_ulong riscv_load_kernel(const char *kernel_filename)
+#if defined(TARGET_RISCV32)
+# define KERNEL_BOOT_ADDRESS 0x80400000
+#else
+# define KERNEL_BOOT_ADDRESS 0x80200000
+#endif
+
+static uint64_t kernel_translate(void *opaque, uint64_t addr)
+{
+    MachineState *machine = opaque;
+
+    /*
+     * If the user specified a firmware move the kernel to the offset
+     * start address.
+     */
+    if (machine->firmware) {
+        return (addr & 0x7fffffff) + KERNEL_BOOT_ADDRESS;
+    } else {
+        return addr;
+    }
+}
+
+target_ulong riscv_load_firmware(const char *firmware_filename)
+{
+    uint64_t firmware_entry, firmware_start, firmware_end;
+
+    if (load_elf(firmware_filename, NULL, NULL, NULL,
+                 &firmware_entry, &firmware_start, &firmware_end,
+                 0, EM_RISCV, 1, 0) < 0) {
+        error_report("could not load firmware '%s'", firmware_filename);
+        exit(1);
+    }
+
+    return firmware_entry;
+}
+
+target_ulong riscv_load_kernel(MachineState *machine,
+                               const char *kernel_filename)
 {
     uint64_t kernel_entry, kernel_high;
 
-    if (load_elf(kernel_filename, NULL, NULL, NULL,
+    if (load_elf(kernel_filename, NULL, kernel_translate, machine,
                  &kernel_entry, NULL, &kernel_high,
                  0, EM_RISCV, 1, 0) < 0) {
         error_report("could not load kernel '%s'", kernel_filename);
hw/riscv/sifive_e.c +1 -1
index 9d58ae362b..3695c686be 100644
@@ -118,7 +118,7 @@ static void riscv_sifive_e_init(MachineState *machine)
                           memmap[SIFIVE_E_MROM].base, &address_space_memory);
 
     if (machine->kernel_filename) {
-        riscv_load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine, machine->kernel_filename);
     }
 }
 
hw/riscv/sifive_u.c +5 -1
index 1b9281bd4a..03a6c64d04 100644
@@ -266,8 +266,12 @@ 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);
+    }
+
     if (machine->kernel_filename) {
-        riscv_load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine, machine->kernel_filename);
     }
 
     /* reset vector */
hw/riscv/spike.c +3 -3
index e68be00a5f..81cef0dcea 100644
@@ -186,7 +186,7 @@ static void spike_board_init(MachineState *machine)
                                 mask_rom);
 
     if (machine->kernel_filename) {
-        riscv_load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine, machine->kernel_filename);
     }
 
     /* reset vector */
@@ -274,7 +274,7 @@ static void spike_v1_10_0_board_init(MachineState *machine)
                                 mask_rom);
 
     if (machine->kernel_filename) {
-        riscv_load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine, machine->kernel_filename);
     }
 
     /* reset vector */
@@ -359,7 +359,7 @@ static void spike_v1_09_1_board_init(MachineState *machine)
                                 mask_rom);
 
     if (machine->kernel_filename) {
-        riscv_load_kernel(machine->kernel_filename);
+        riscv_load_kernel(machine, machine->kernel_filename);
     }
 
     /* reset vector */
hw/riscv/virt.c +6 -1
index 5f8c11471b..d3670b5a7c 100644
@@ -380,8 +380,13 @@ 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);
+    }
+
     if (machine->kernel_filename) {
-        uint64_t kernel_entry = riscv_load_kernel(machine->kernel_filename);
+        uint64_t kernel_entry = riscv_load_kernel(machine,
+                                                  machine->kernel_filename);
 
         if (machine->initrd_filename) {
             hwaddr start;
include/hw/riscv/boot.h +3 -1
index f84fd6c2df..6f586939c7 100644
@@ -20,7 +20,9 @@
 #ifndef RISCV_BOOT_H
 #define RISCV_BOOT_H
 
-target_ulong riscv_load_kernel(const char *kernel_filename);
+target_ulong riscv_load_firmware(const char *firmware_filename);
+target_ulong riscv_load_kernel(MachineState *machine,
+                               const char *kernel_filename);
 hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,
                          uint64_t kernel_entry, hwaddr *start);
 
Signature · 1 line
2.22.0
#5 lore raw

Re: [Qemu-devel] [RFC v1 2/5] hw/riscv: Add support for loading a firmware

Quoted 32 lines · Alistair Francis

Add support for loading a firmware file for the virt machine and the SiFive U. This can be run with the following command:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel vmlinux

---
 hw/riscv/boot.c         | 41 +++++++++++++++++++++++++++++++++++++++--
 hw/riscv/sifive_e.c     |  2 +-
 hw/riscv/sifive_u.c     |  6 +++++-
 hw/riscv/spike.c        |  6 +++---
 hw/riscv/virt.c         |  7 ++++++-
 include/hw/riscv/boot.h |  4 +++-
 6 files changed, 57 insertions(+), 9 deletions(-)
hw/riscv/boot.c +5 -1
index 62f94aaf8a..392ca0cb2e 100644
@@ -23,13 +23,50 @@
 #include "exec/cpu-defs.h"
 #include "hw/loader.h"
 #include "hw/riscv/boot.h"
+#include "hw/boards.h"
 #include "elf.h"
 
-target_ulong riscv_load_kernel(const char *kernel_filename)
+#if defined(TARGET_RISCV32)
+# define KERNEL_BOOT_ADDRESS 0x80400000
+#else
+# define KERNEL_BOOT_ADDRESS 0x80200000

hw/riscv/boot.c line 42

Quoted 10 lines
hw/riscv/boot.c +10 -0
+#endif
+
+static uint64_t kernel_translate(void *opaque, uint64_t addr)
+{
+    MachineState *machine = opaque;
+
+    /*
+     * If the user specified a firmware move the kernel to the offset
+     * start address.
+     */

Why?

hw/riscv/boot.c line 44

Quoted 2 lines
hw/riscv/boot.c +2 -0
+    if (machine->firmware) {
+        return (addr & 0x7fffffff) + KERNEL_BOOT_ADDRESS;

So with both "-bios" and "-kernel", the kernel address will be moved to another address other than 0x80200000 (for 64-bit). This does not look good to me.

hw/riscv/boot.c line 49

Quoted 5 lines
hw/riscv/boot.c +5 -0
+    } else {
+        return addr;
+    }
+}
+

[snip]

Regards,
Bin

#6 lore raw

Re: [Qemu-devel] [Qemu-riscv] [RFC v1 2/5] hw/riscv: Add support for loading a firmware

I was actually just writing up the same thing. Shifting all the addresses in the ELF file by 2 or 4MB is somewhat surprising behavior, especially because this will apply to segments that are mapped even at much higher addresses. If you want a segment aligned to a 1GB superpage boundary you now need to place it slightly below so that it will be bumped up to the right place. Further, ANDing all addresses with 0x7fffffff makes it impossible to map anything beyond the first 2GB of RAM.

Jonathan

Quoted 66 lines · Bin Meng
Quoted 32 lines · Alistair Francis

Add support for loading a firmware file for the virt machine and the SiFive U. This can be run with the following command:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel vmlinux

---
 hw/riscv/boot.c         | 41 +++++++++++++++++++++++++++++++++++++++--
 hw/riscv/sifive_e.c     |  2 +-
 hw/riscv/sifive_u.c     |  6 +++++-
 hw/riscv/spike.c        |  6 +++---
 hw/riscv/virt.c         |  7 ++++++-
 include/hw/riscv/boot.h |  4 +++-
 6 files changed, 57 insertions(+), 9 deletions(-)
hw/riscv/boot.c +5 -1
index 62f94aaf8a..392ca0cb2e 100644
@@ -23,13 +23,50 @@
 #include "exec/cpu-defs.h"
 #include "hw/loader.h"
 #include "hw/riscv/boot.h"
+#include "hw/boards.h"
 #include "elf.h"
 
-target_ulong riscv_load_kernel(const char *kernel_filename)
+#if defined(TARGET_RISCV32)
+# define KERNEL_BOOT_ADDRESS 0x80400000
+#else
+# define KERNEL_BOOT_ADDRESS 0x80200000

hw/riscv/boot.c line 42

Quoted 10 lines
hw/riscv/boot.c +10 -0
+#endif
+
+static uint64_t kernel_translate(void *opaque, uint64_t addr)
+{
+    MachineState *machine = opaque;
+
+    /*
+     * If the user specified a firmware move the kernel to the offset
+     * start address.
+     */

Why?

hw/riscv/boot.c line 44

Quoted 2 lines
hw/riscv/boot.c +2 -0
+    if (machine->firmware) {
+        return (addr & 0x7fffffff) + KERNEL_BOOT_ADDRESS;

So with both "-bios" and "-kernel", the kernel address will be moved to another address other than 0x80200000 (for 64-bit). This does not look good to me.

hw/riscv/boot.c line 49

Quoted 5 lines
hw/riscv/boot.c +5 -0
+    } else {
+        return addr;
+    }
+}
+

[snip]

Regards,
Bin

#7 lore raw

Re: [Qemu-devel] [Qemu-riscv] [RFC v1 2/5] hw/riscv: Add support for loading a firmware

Hi,

Quoted 3 lines · Jonathan Behrens

I was actually just writing up the same thing. Shifting all the addresses in the ELF file by 2 or 4MB is somewhat surprising behavior, especially because this will apply to segments that are mapped even at much higher addresses. If you want a segment aligned to a 1GB superpage boundary you now need to place it slightly below so that it will be bumped up to the right place. Further, ANDing all addresses with 0x7fffffff makes it impossible to map anything beyond the first 2GB of RAM.

Yes, current kernel_translate() logic is tightly coupled to the kernel entry VA, and if we link kernel at some other address it will just fail.

Quoted 58 lines

Jonathan

Quoted 55 lines · Bin Meng
Quoted 32 lines · Alistair Francis

Add support for loading a firmware file for the virt machine and the SiFive U. This can be run with the following command:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel vmlinux

---
 hw/riscv/boot.c         | 41 +++++++++++++++++++++++++++++++++++++++--
 hw/riscv/sifive_e.c     |  2 +-
 hw/riscv/sifive_u.c     |  6 +++++-
 hw/riscv/spike.c        |  6 +++---
 hw/riscv/virt.c         |  7 ++++++-
 include/hw/riscv/boot.h |  4 +++-
 6 files changed, 57 insertions(+), 9 deletions(-)
hw/riscv/boot.c +5 -1
index 62f94aaf8a..392ca0cb2e 100644
@@ -23,13 +23,50 @@
 #include "exec/cpu-defs.h"
 #include "hw/loader.h"
 #include "hw/riscv/boot.h"
+#include "hw/boards.h"
 #include "elf.h"
 
-target_ulong riscv_load_kernel(const char *kernel_filename)
+#if defined(TARGET_RISCV32)
+# define KERNEL_BOOT_ADDRESS 0x80400000
+#else
+# define KERNEL_BOOT_ADDRESS 0x80200000

hw/riscv/boot.c line 42

Quoted 10 lines
hw/riscv/boot.c +10 -0
+#endif
+
+static uint64_t kernel_translate(void *opaque, uint64_t addr)
+{
+    MachineState *machine = opaque;
+
+    /*
+     * If the user specified a firmware move the kernel to the offset
+     * start address.
+     */

Why?

hw/riscv/boot.c line 44

Quoted 2 lines
hw/riscv/boot.c +2 -0
+    if (machine->firmware) {
+        return (addr & 0x7fffffff) + KERNEL_BOOT_ADDRESS;

So with both "-bios" and "-kernel", the kernel address will be moved to another address other than 0x80200000 (for 64-bit). This does not look good to me.

So why not simply return KERNEL_BOOT_ADDRESS in kernel_translate()?

Regards,
Bin

#8 lore raw

Re: [Qemu-devel] [Qemu-riscv] [RFC v1 2/5] hw/riscv: Add support for loading a firmware

Quoted 11 lines · Bin Meng

Hi,

Quoted 3 lines · Jonathan Behrens

I was actually just writing up the same thing. Shifting all the addresses in the ELF file by 2 or 4MB is somewhat surprising behavior, especially because this will apply to segments that are mapped even at much higher addresses. If you want a segment aligned to a 1GB superpage boundary you now need to place it slightly below so that it will be bumped up to the right place. Further, ANDing all addresses with 0x7fffffff makes it impossible to map anything beyond the first 2GB of RAM.

Yes, current kernel_translate() logic is tightly coupled to the kernel entry VA, and if we link kernel at some other address it will just fail.

I thought this was required but it looks like it isn't. I have remove the kernel_translate() function.

Quoted 43 lines
Quoted 43 lines

Jonathan

Quoted 39 lines · Bin Meng
Quoted 36 lines · Alistair Francis

Add support for loading a firmware file for the virt machine and the SiFive U. This can be run with the following command:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel vmlinux

---
 hw/riscv/boot.c         | 41 +++++++++++++++++++++++++++++++++++++++--
 hw/riscv/sifive_e.c     |  2 +-
 hw/riscv/sifive_u.c     |  6 +++++-
 hw/riscv/spike.c        |  6 +++---
 hw/riscv/virt.c         |  7 ++++++-
 include/hw/riscv/boot.h |  4 +++-
 6 files changed, 57 insertions(+), 9 deletions(-)
hw/riscv/boot.c +9 -1
index 62f94aaf8a..392ca0cb2e 100644
@@ -23,13 +23,50 @@
 #include "exec/cpu-defs.h"
 #include "hw/loader.h"
 #include "hw/riscv/boot.h"
+#include "hw/boards.h"
 #include "elf.h"
 
-target_ulong riscv_load_kernel(const char *kernel_filename)
+#if defined(TARGET_RISCV32)
+# define KERNEL_BOOT_ADDRESS 0x80400000
+#else
+# define KERNEL_BOOT_ADDRESS 0x80200000
+#endif
+
+static uint64_t kernel_translate(void *opaque, uint64_t addr)
+{
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/riscv/boot.c line 42

Quoted 6 lines
hw/riscv/boot.c +6 -0
+    MachineState *machine = opaque;
+
+    /*
+     * If the user specified a firmware move the kernel to the offset
+     * start address.
+     */

Why?

Removed.

Quoted 10 lines
Quoted 8 lines
Quoted 8 lines

hw/riscv/boot.c line 44

Quoted 3 lines
hw/riscv/boot.c +2 -0
+    if (machine->firmware) {
+        return (addr & 0x7fffffff) + KERNEL_BOOT_ADDRESS;

So with both "-bios" and "-kernel", the kernel address will be moved to another address other than 0x80200000 (for 64-bit). This does not look good to me.

So why not simply return KERNEL_BOOT_ADDRESS in kernel_translate()?

That's what I am doing now.

Alistair

Quoted 3 lines

Regards,
Bin

#9 lore raw

RFC 3/5 hw/riscv: Extend the kernel loading support

In reply to Alistair Francis

Extend the RISC-V kernel loader to support uImage and Image files. A Linux kernel can now be booted with:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel Image

---
 hw/riscv/boot.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
hw/riscv/boot.c +14 -5
index 392ca0cb2e..7f68035a3f 100644
@@ -67,13 +67,22 @@ target_ulong riscv_load_kernel(MachineState *machine,
     uint64_t kernel_entry, kernel_high;
 
     if (load_elf(kernel_filename, NULL, kernel_translate, machine,
-                 &kernel_entry, NULL, &kernel_high,
-                 0, EM_RISCV, 1, 0) < 0) {
-        error_report("could not load kernel '%s'", kernel_filename);
-        exit(1);
+                 &kernel_entry, NULL, &kernel_high, 0, EM_RISCV, 1, 0) > 0) {
+        return kernel_entry;
+    }
+
+    if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL,
+                       kernel_translate, machine, NULL) > 0) {
+        return kernel_entry;
+    }
+
+    if (load_image_targphys_as(kernel_filename, KERNEL_BOOT_ADDRESS,
+                               ram_size, NULL) > 0) {
+        return kernel_entry;
     }
 
-    return kernel_entry;
+    error_report("could not load kernel '%s'", kernel_filename);
+    exit(1);
 }
 
 hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,
Signature · 1 line
2.22.0
#10 lore raw

Re: [Qemu-devel] [RFC v1 3/5] hw/riscv: Extend the kernel loading support

Quoted 19 lines · Alistair Francis

Extend the RISC-V kernel loader to support uImage and Image files. A Linux kernel can now be booted with:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel Image

---
 hw/riscv/boot.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
hw/riscv/boot.c +0 -0
index 392ca0cb2e..7f68035a3f 100644
@@ -67,13 +67,22 @@ target_ulong riscv_load_kernel(MachineState *machine,
     uint64_t kernel_entry, kernel_high;
 
     if (load_elf(kernel_filename, NULL, kernel_translate, machine,

hw/riscv/boot.c target_ulong riscv_load_kernel(MachineState *machine, · line 75

Quoted 10 lines
hw/riscv/boot.c +6 -4
-                 &kernel_entry, NULL, &kernel_high,
-                 0, EM_RISCV, 1, 0) < 0) {
-        error_report("could not load kernel '%s'", kernel_filename);
-        exit(1);
+                 &kernel_entry, NULL, &kernel_high, 0, EM_RISCV, 1, 0) > 0) {
+        return kernel_entry;
+    }
+
+    if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL,
+                       kernel_translate, machine, NULL) > 0) {

We should not set the 'kernel_translate' here for uImage.

In fact, the whole kernel_translate() is not necessary.

hw/riscv/boot.c target_ulong riscv_load_kernel(MachineState *machine, · line 73

Quoted 3 lines
hw/riscv/boot.c +3 -0
+        return kernel_entry;
+    }
+

Regards,
Bin

#11 lore raw

Re: [Qemu-devel] [RFC v1 3/5] hw/riscv: Extend the kernel loading support

Quoted 35 lines · Bin Meng
Quoted 19 lines · Alistair Francis

Extend the RISC-V kernel loader to support uImage and Image files. A Linux kernel can now be booted with:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel Image

---
 hw/riscv/boot.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
hw/riscv/boot.c +0 -0
index 392ca0cb2e..7f68035a3f 100644
@@ -67,13 +67,22 @@ target_ulong riscv_load_kernel(MachineState *machine,
     uint64_t kernel_entry, kernel_high;
 
     if (load_elf(kernel_filename, NULL, kernel_translate, machine,

hw/riscv/boot.c target_ulong riscv_load_kernel(MachineState *machine, · line 75

Quoted 10 lines
hw/riscv/boot.c +6 -4
-                 &kernel_entry, NULL, &kernel_high,
-                 0, EM_RISCV, 1, 0) < 0) {
-        error_report("could not load kernel '%s'", kernel_filename);
-        exit(1);
+                 &kernel_entry, NULL, &kernel_high, 0, EM_RISCV, 1, 0) > 0) {
+        return kernel_entry;
+    }
+
+    if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL,
+                       kernel_translate, machine, NULL) > 0) {

We should not set the 'kernel_translate' here for uImage.

Quoted 1 line

In fact, the whole kernel_translate() is not necessary.

I have removed the kernel_translate() function. I tested loading uImage files though and they don't seem to work as the image is loaded at the wrong address.

I have removed uImage loading support from this series. We can look at it in the future if we decide we want it.

Alistair

Quoted 7 lines

hw/riscv/boot.c target_ulong riscv_load_kernel(MachineState *machine, · line 73

Quoted 4 lines
hw/riscv/boot.c +3 -0
+        return kernel_entry;
+    }
+

Regards,
Bin

#12 lore raw

Re: [Qemu-devel] [RFC v1 3/5] hw/riscv: Extend the kernel loading support

Quoted 37 lines · Alistair Francis
Quoted 35 lines · Bin Meng
Quoted 19 lines · Alistair Francis

Extend the RISC-V kernel loader to support uImage and Image files. A Linux kernel can now be booted with:

qemu-system-riscv64 -machine virt -bios fw_jump.elf -kernel Image

---
 hw/riscv/boot.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
hw/riscv/boot.c +0 -0
index 392ca0cb2e..7f68035a3f 100644
@@ -67,13 +67,22 @@ target_ulong riscv_load_kernel(MachineState *machine,
     uint64_t kernel_entry, kernel_high;
 
     if (load_elf(kernel_filename, NULL, kernel_translate, machine,

hw/riscv/boot.c target_ulong riscv_load_kernel(MachineState *machine, · line 75

Quoted 10 lines
hw/riscv/boot.c +6 -4
-                 &kernel_entry, NULL, &kernel_high,
-                 0, EM_RISCV, 1, 0) < 0) {
-        error_report("could not load kernel '%s'", kernel_filename);
-        exit(1);
+                 &kernel_entry, NULL, &kernel_high, 0, EM_RISCV, 1, 0) > 0) {
+        return kernel_entry;
+    }
+
+    if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL,
+                       kernel_translate, machine, NULL) > 0) {

We should not set the 'kernel_translate' here for uImage.

Quoted 8 lines
Quoted 1 line

In fact, the whole kernel_translate() is not necessary.

I have removed the kernel_translate() function. I tested loading uImage files though and they don't seem to work as the image is loaded at the wrong address.

I have removed uImage loading support from this series. We can look at it in the future if we decide we want it.

Ah, my mistake, it looks like my uImage wasn't built correctly. I'll keep this in.

Alistair

Quoted 10 lines

Alistair

Quoted 7 lines

hw/riscv/boot.c target_ulong riscv_load_kernel(MachineState *machine, · line 73

Quoted 4 lines
hw/riscv/boot.c +3 -0
+        return kernel_entry;
+    }
+

Regards,
Bin

#13 lore raw

RFC 4/5 roms: Add OpenSBI version 0.3

In reply to Alistair Francis

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

---
 .gitmodules                         |   3 +++
 Makefile                            |   3 ++-
 configure                           |   1 +
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
 roms/Makefile                       |  17 +++++++++++++++++
 roms/opensbi                        |   1 +
 7 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 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
Makefile +2 -1
index cfb18f1525..fb6638f9ec 100644
@@ -761,7 +761,8 @@ palcode-clipper \
 u-boot.e500 u-boot-sam460-20100605.bin \
 qemu_vga.ndrv \
 edk2-licenses.txt \
-hppa-firmware.img
+hppa-firmware.img \
+opensbi-riscv32-fw_jump.elf opensbi-riscv64-fw_jump.elf
 
 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
configure +1 -0
index b091b82cb3..75372a7b4f 100755
@@ -7936,6 +7936,7 @@ for bios_file in \
     $source_path/pc-bios/*.rom \
     $source_path/pc-bios/*.dtb \
     $source_path/pc-bios/*.img \
+    $source_path/pc-bios/*.elf \
     $source_path/pc-bios/openbios-* \
     $source_path/pc-bios/u-boot.* \
     $source_path/pc-bios/edk2-*.fd.bz2 \
pc-bios/opensbi-riscv32-fw_jump.elf new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..e526b03eaad419953831f2114ea3aa0fdcc1924b
GIT binary patch
pc-bios/opensbi-riscv64-fw_jump.elf new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..f5926c1d80d8b82be68ac0e194b475e410d8b5ac
GIT binary patch
roms/Makefile +17 -0
index 078d3fb705..f79220791c 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"
@@ -62,6 +64,8 @@ default:
 	@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      -- update OpenSBI for 32-bit"
+	@echo "  opensbi64      -- update OpenSBI for 64-bit"
 	@echo "  clean          -- delete the files generated by the previous" \
 	                          "build targets"
 
@@ -162,6 +166,18 @@ skiboot:
 efi: edk2-basetools
 	$(MAKE) -f Makefile.edk2
 
+opensbi32:
+	$(MAKE) -C opensbi \
+		CROSS_COMPILE=$(riscv32_cross_prefix) \
+		PLATFORM="qemu/virt"
+	cp opensbi/build/platform/qemu/virt/firmware/fw_jump.elf ../pc-bios/opensbi-riscv32-fw_jump.elf
+
+opensbi64:
+	$(MAKE) -C opensbi \
+		CROSS_COMPILE=$(riscv64_cross_prefix) \
+		PLATFORM="qemu/virt"
+	cp opensbi/build/platform/qemu/virt/firmware/fw_jump.elf ../pc-bios/opensbi-riscv64-fw_jump.elf
+
 clean:
 	rm -rf seabios/.config seabios/out seabios/builds
 	$(MAKE) -C sgabios clean
@@ -173,3 +189,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..ca20ac0cd4
@@ -0,0 +1 @@
+Subproject commit ca20ac0cd4c099006d4eea4d9ac7bd7b58e2ae0f
Signature · 1 line
2.22.0
#14 lore raw

Re: [Qemu-devel] [Qemu-riscv] [RFC v1 4/5] roms: Add OpenSBI version 0.3

Quoted 4 lines · Alistair Francis

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

Quoted 13 lines
---
 .gitmodules                         |   3 +++
 Makefile                            |   3 ++-
 configure                           |   1 +
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
 roms/Makefile                       |  17 +++++++++++++++++
 roms/opensbi                        |   1 +
 7 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 create mode 160000 roms/opensbi

The OpenSBI firmwares are platform specific so we should have machine directory under pc-bios/ directory

So for virt machine we will have:
pc-bios/riscv32/virt/fw_jump.elf
pc-bios/riscv64/virt/fw_jump.elf

Regards,
Anup

#15 lore raw

Re: [Qemu-devel] [Qemu-riscv] [RFC v1 4/5] roms: Add OpenSBI version 0.3

Quoted 21 lines · Anup Patel
Quoted 4 lines · Alistair Francis

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

Quoted 13 lines
---
 .gitmodules                         |   3 +++
 Makefile                            |   3 ++-
 configure                           |   1 +
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
 roms/Makefile                       |  17 +++++++++++++++++
 roms/opensbi                        |   1 +
 7 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 create mode 160000 roms/opensbi
Quoted 6 lines

The OpenSBI firmwares are platform specific so we should have machine directory under pc-bios/ directory

So for virt machine we will have:
pc-bios/riscv32/virt/fw_jump.elf
pc-bios/riscv64/virt/fw_jump.elf

And we should only integrate plain binary image for "bios" images here.

pc-bios/riscv32/virt/fw_jump.bin
pc-bios/riscv64/virt/fw_jump.bin

Regards,
Bin

#16 lore raw

Re: [Qemu-devel] [Qemu-riscv] [RFC v1 4/5] roms: Add OpenSBI version 0.3

Quoted 23 lines · Bin Meng
Quoted 21 lines · Anup Patel
Quoted 17 lines · Alistair Francis

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

---
 .gitmodules                         |   3 +++
 Makefile                            |   3 ++-
 configure                           |   1 +
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
 roms/Makefile                       |  17 +++++++++++++++++
 roms/opensbi                        |   1 +
 7 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 create mode 160000 roms/opensbi
Quoted 6 lines
Quoted 6 lines

The OpenSBI firmwares are platform specific so we should have machine directory under pc-bios/ directory

So for virt machine we will have:
pc-bios/riscv32/virt/fw_jump.elf
pc-bios/riscv64/virt/fw_jump.elf

I have updated the names to indicate the machine. The pc-bios directly appears to be flat (at least for binaries) so I don't want to add subdirectories.

Quoted 5 lines

And we should only integrate plain binary image for "bios" images here.

pc-bios/riscv32/virt/fw_jump.bin
pc-bios/riscv64/virt/fw_jump.bin

Yep, fixed.

Alistair

Quoted 3 lines

Regards,
Bin

#17 lore raw

Re: [Qemu-devel] [Qemu-riscv] [RFC v1 4/5] roms: Add OpenSBI version 0.3

Quoted 28 lines · Alistair Francis
Quoted 26 lines · Bin Meng
Quoted 24 lines · Anup Patel
Quoted 4 lines · Alistair Francis

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

Quoted 13 lines
---
 .gitmodules                         |   3 +++
 Makefile                            |   3 ++-
 configure                           |   1 +
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
 roms/Makefile                       |  17 +++++++++++++++++
 roms/opensbi                        |   1 +
 7 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 create mode 160000 roms/opensbi

The OpenSBI firmwares are platform specific so we should have machine directory under pc-bios/ directory

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

So for virt machine we will have:
pc-bios/riscv32/virt/fw_jump.elf
pc-bios/riscv64/virt/fw_jump.elf

I have updated the names to indicate the machine. The pc-bios directly appears to be flat (at least for binaries) so I don't want to add subdirectories.

Should we include pre-built OpenSBI "bios" for "sifive_u" machine too?

Quoted 8 lines
Quoted 5 lines

And we should only integrate plain binary image for "bios" images here.

pc-bios/riscv32/virt/fw_jump.bin
pc-bios/riscv64/virt/fw_jump.bin

Yep, fixed.

Regards,
Bin

#18 lore raw

Re: [Qemu-devel] [Qemu-riscv] [RFC v1 4/5] roms: Add OpenSBI version 0.3

Quoted 34 lines · Bin Meng
Quoted 32 lines · Alistair Francis
Quoted 29 lines · Bin Meng
Quoted 27 lines · Anup Patel
Quoted 4 lines · Alistair Francis

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

Quoted 13 lines
---
 .gitmodules                         |   3 +++
 Makefile                            |   3 ++-
 configure                           |   1 +
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
 roms/Makefile                       |  17 +++++++++++++++++
 roms/opensbi                        |   1 +
 7 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 create mode 160000 roms/opensbi

The OpenSBI firmwares are platform specific so we should have machine directory under pc-bios/ directory

So for virt machine we will have:
pc-bios/riscv32/virt/fw_jump.elf
pc-bios/riscv64/virt/fw_jump.elf

Quoted 6 lines
Quoted 4 lines

I have updated the names to indicate the machine. The pc-bios directly appears to be flat (at least for binaries) so I don't want to add subdirectories.

Should we include pre-built OpenSBI "bios" for "sifive_u" machine too?

Yep, I am doing that now.

Alistair

Quoted 12 lines
Quoted 9 lines
Quoted 6 lines

And we should only integrate plain binary image for "bios" images here.

pc-bios/riscv32/virt/fw_jump.bin
pc-bios/riscv64/virt/fw_jump.bin

Yep, fixed.

Regards,
Bin

#19 lore raw

RFC 5/5 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         | 28 ++++++++++++++++++++++++++++
 hw/riscv/sifive_u.c     |  4 +---
 hw/riscv/virt.c         |  4 +---
 include/hw/riscv/boot.h |  1 +
 4 files changed, 31 insertions(+), 6 deletions(-)
hw/riscv/boot.c +28 -0
index 7f68035a3f..5f021591ed 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,12 @@
 # define KERNEL_BOOT_ADDRESS 0x80200000
 #endif
 
+#if defined(TARGET_RISCV32)
+# define BIOS_FILENAME "opensbi-riscv32-fw_jump.elf"
+#else
+# define BIOS_FILENAME "opensbi-riscv64-fw_jump.elf"
+#endif
+
 static uint64_t kernel_translate(void *opaque, uint64_t addr)
 {
     MachineState *machine = opaque;
@@ -47,6 +54,27 @@ static uint64_t kernel_translate(void *opaque, uint64_t addr)
     }
 }
 
+void riscv_find_and_load_firmware(MachineState *machine)
+{
+    char *firmware_filename;
+
+    if (!machine->firmware) {
+        /* The user didn't specify a firmware, default to OpenSBI */
+        firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BIOS_FILENAME);
+    } else {
+        firmware_filename = machine->firmware;
+    }
+
+    if (strcmp(firmware_filename, "none")) {
+        /* If not "none" load the firmware */
+        riscv_load_firmware(firmware_filename);
+    }
+
+    if (!machine->firmware) {
+        g_free(firmware_filename);
+    }
+}
+
 target_ulong riscv_load_firmware(const char *firmware_filename)
 {
     uint64_t firmware_entry, firmware_start, firmware_end;
hw/riscv/sifive_u.c +1 -3
index 03a6c64d04..77666d0f4d 100644
@@ -266,9 +266,7 @@ 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);
-    }
+    riscv_find_and_load_firmware(machine);
 
     if (machine->kernel_filename) {
         riscv_load_kernel(machine, machine->kernel_filename);
hw/riscv/virt.c +1 -3
index d3670b5a7c..2a7e850666 100644
@@ -380,9 +380,7 @@ 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);
-    }
+    riscv_find_and_load_firmware(machine);
 
     if (machine->kernel_filename) {
         uint64_t kernel_entry = riscv_load_kernel(machine,
include/hw/riscv/boot.h +1 -0
index 6f586939c7..df2e2480e6 100644
@@ -20,6 +20,7 @@
 #ifndef RISCV_BOOT_H
 #define RISCV_BOOT_H
 
+void riscv_find_and_load_firmware(MachineState *machine);
 target_ulong riscv_load_firmware(const char *firmware_filename);
 target_ulong riscv_load_kernel(MachineState *machine,
                                const char *kernel_filename);
Signature · 1 line
2.22.0
#20 lore raw

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

Quoted 26 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         | 28 ++++++++++++++++++++++++++++
 hw/riscv/sifive_u.c     |  4 +---
 hw/riscv/virt.c         |  4 +---
 include/hw/riscv/boot.h |  1 +
 4 files changed, 31 insertions(+), 6 deletions(-)
hw/riscv/boot.c +1 -0
index 7f68035a3f..5f021591ed 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"

hw/riscv/boot.c line 40

Quoted 8 lines
hw/riscv/boot.c +5 -0
@@ -32,6 +33,12 @@
 # define KERNEL_BOOT_ADDRESS 0x80200000
 #endif
 
+#if defined(TARGET_RISCV32)
+# define BIOS_FILENAME "opensbi-riscv32-fw_jump.elf"
+#else
+# define BIOS_FILENAME "opensbi-riscv64-fw_jump.elf"
+#endif

Based on my comment on PATCH4, BIOS_FILENAME should be derived from QEMU machine name and TARGET_RISCVx

Agree ??

Regards,
Anup

Quoted 78 lines
hw/riscv/boot.c +22 -0
+
 static uint64_t kernel_translate(void *opaque, uint64_t addr)
 {
     MachineState *machine = opaque;
@@ -47,6 +54,27 @@ static uint64_t kernel_translate(void *opaque, uint64_t addr)
     }
 }
 
+void riscv_find_and_load_firmware(MachineState *machine)
+{
+    char *firmware_filename;
+
+    if (!machine->firmware) {
+        /* The user didn't specify a firmware, default to OpenSBI */
+        firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BIOS_FILENAME);
+    } else {
+        firmware_filename = machine->firmware;
+    }
+
+    if (strcmp(firmware_filename, "none")) {
+        /* If not "none" load the firmware */
+        riscv_load_firmware(firmware_filename);
+    }
+
+    if (!machine->firmware) {
+        g_free(firmware_filename);
+    }
+}
+
 target_ulong riscv_load_firmware(const char *firmware_filename)
 {
     uint64_t firmware_entry, firmware_start, firmware_end;
hw/riscv/sifive_u.c +1 -3
index 03a6c64d04..77666d0f4d 100644
@@ -266,9 +266,7 @@ 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);
-    }
+    riscv_find_and_load_firmware(machine);
 
     if (machine->kernel_filename) {
         riscv_load_kernel(machine, machine->kernel_filename);
hw/riscv/virt.c +1 -3
index d3670b5a7c..2a7e850666 100644
@@ -380,9 +380,7 @@ 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);
-    }
+    riscv_find_and_load_firmware(machine);
 
     if (machine->kernel_filename) {
         uint64_t kernel_entry = riscv_load_kernel(machine,
include/hw/riscv/boot.h +1 -1
index 6f586939c7..df2e2480e6 100644
@@ -20,6 +20,7 @@
 #ifndef RISCV_BOOT_H
 #define RISCV_BOOT_H
 
+void riscv_find_and_load_firmware(MachineState *machine);
 target_ulong riscv_load_firmware(const char *firmware_filename);
 target_ulong riscv_load_kernel(MachineState *machine,
                                const char *kernel_filename);
--

2.22.0

#21 lore raw
In reply to Alistair Francis
Quoted 11 lines · Alistair Francis

This is an RFC as it will break ALL current users! See below for details.

This series consolidates the current RISC-V kernel loading impelementation while also adding support for the -bios option and more advanced kernel image types.

After consolidating the kernel loading we can extend the boot loader to support a -bios option. We can also extend the kernel loading options to support not just ELF files but other standard formats.

Quoted 5 lines

Finally we can include the OpenSBI firmware by default for QEMU users.

At the end of this series 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

This is great. I like booting kernel directly for testing without bothering the firmware stuff.

Quoted 35 lines

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).

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Unfortunately this series (patch 5 specifically) results in all current Linux boots being broken as users are already loading in their own firmware, which overlaps with the now included default. They will see this error:

rom: requested regions overlap (rom phdr #0: ./images/qemuriscv64/fw_jump.elf. free=0x0000000080008090, addr=0x0000000080000000)
qemu-system-riscv64: rom check and register reset failed

If a current user specieifies "-bios none" their flow will continue working. A user can instead no longer load their firmware and use the default or they can load their firmware with the -bios option.

At the moment the best idea I have to not break all users is to only include the default firmware if the user specifies "-bios opensbi". That is change the default to not loading the firmware. Then we can work on updating documentation and maybe in future change the default to include a firmware and anyone who doesn't want a default firmware can specify "-bios none".

Any other ideas on how to not break everything?

Alistair Francis (5):
hw/riscv: Split out the boot functions
hw/riscv: Add support for loading a firmware
hw/riscv: Extend the kernel loading support
roms: Add OpenSBI version 0.3
hw/riscv: Load OpenSBI as the default firmware

Quoted 12 lines
 .gitmodules                         |   3 +
 Makefile                            |   3 +-
 configure                           |   1 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/boot.c                     | 143 ++++++++++++++++++++++++++++
 hw/riscv/sifive_e.c                 |  17 +---
 hw/riscv/sifive_u.c                 |  19 +---
 hw/riscv/spike.c                    |  21 +---
 hw/riscv/virt.c                     |  54 ++---------
 include/hw/riscv/boot.h             |  30 ++++++
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes

Since we are considering adding "bios" images, I prefer to add the pure binary images instead of ELF images here.

Quoted 8 lines
 roms/Makefile                       |  17 ++++
 roms/opensbi                        |   1 +
 14 files changed, 216 insertions(+), 94 deletions(-)
 create mode 100644 hw/riscv/boot.c
 create mode 100644 include/hw/riscv/boot.h
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 create mode 160000 roms/opensbi

Regards,
Bin

#22 lore raw
Quoted 14 lines · Bin Meng
Quoted 11 lines · Alistair Francis

This is an RFC as it will break ALL current users! See below for details.

This series consolidates the current RISC-V kernel loading impelementation while also adding support for the -bios option and more advanced kernel image types.

After consolidating the kernel loading we can extend the boot loader to support a -bios option. We can also extend the kernel loading options to support not just ELF files but other standard formats.

Quoted 8 lines
Quoted 5 lines

Finally we can include the OpenSBI firmware by default for QEMU users.

At the end of this series 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

This is great. I like booting kernel directly for testing without bothering the firmware stuff.

That's the goal! Now we just need to not break everything.

Quoted 49 lines
Quoted 36 lines

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).

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Unfortunately this series (patch 5 specifically) results in all current Linux boots being broken as users are already loading in their own firmware, which overlaps with the now included default. They will see this error:

rom: requested regions overlap (rom phdr #0: ./images/qemuriscv64/fw_jump.elf. free=0x0000000080008090, addr=0x0000000080000000)
qemu-system-riscv64: rom check and register reset failed

If a current user specieifies "-bios none" their flow will continue working. A user can instead no longer load their firmware and use the default or they can load their firmware with the -bios option.

At the moment the best idea I have to not break all users is to only include the default firmware if the user specifies "-bios opensbi". That is change the default to not loading the firmware. Then we can work on updating documentation and maybe in future change the default to include a firmware and anyone who doesn't want a default firmware can specify "-bios none".

Any other ideas on how to not break everything?

Alistair Francis (5):
hw/riscv: Split out the boot functions
hw/riscv: Add support for loading a firmware
hw/riscv: Extend the kernel loading support
roms: Add OpenSBI version 0.3
hw/riscv: Load OpenSBI as the default firmware

Quoted 12 lines
 .gitmodules                         |   3 +
 Makefile                            |   3 +-
 configure                           |   1 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/boot.c                     | 143 ++++++++++++++++++++++++++++
 hw/riscv/sifive_e.c                 |  17 +---
 hw/riscv/sifive_u.c                 |  19 +---
 hw/riscv/spike.c                    |  21 +---
 hw/riscv/virt.c                     |  54 ++---------
 include/hw/riscv/boot.h             |  30 ++++++
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
Quoted 2 lines

Since we are considering adding "bios" images, I prefer to add the pure binary images instead of ELF images here.

I didn't think about that. Can we just boot them in QEMU like we do with the ELFs?

Alistair

Quoted 12 lines
Quoted 9 lines
 roms/Makefile                       |  17 ++++
 roms/opensbi                        |   1 +
 14 files changed, 216 insertions(+), 94 deletions(-)
 create mode 100644 hw/riscv/boot.c
 create mode 100644 include/hw/riscv/boot.h
 create mode 100644 pc-bios/opensbi-riscv32-fw_jump.elf
 create mode 100644 pc-bios/opensbi-riscv64-fw_jump.elf
 create mode 160000 roms/opensbi

Regards,
Bin

#23 lore raw
Quoted 76 lines · Alistair Francis
Quoted 14 lines · Bin Meng
Quoted 11 lines · Alistair Francis

This is an RFC as it will break ALL current users! See below for details.

This series consolidates the current RISC-V kernel loading impelementation while also adding support for the -bios option and more advanced kernel image types.

After consolidating the kernel loading we can extend the boot loader to support a -bios option. We can also extend the kernel loading options to support not just ELF files but other standard formats.

Quoted 8 lines
Quoted 5 lines

Finally we can include the OpenSBI firmware by default for QEMU users.

At the end of this series 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

This is great. I like booting kernel directly for testing without bothering the firmware stuff.

That's the goal! Now we just need to not break everything.

Quoted 49 lines
Quoted 48 lines

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).

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Unfortunately this series (patch 5 specifically) results in all current Linux boots being broken as users are already loading in their own firmware, which overlaps with the now included default. They will see this error:

rom: requested regions overlap (rom phdr #0: ./images/qemuriscv64/fw_jump.elf. free=0x0000000080008090, addr=0x0000000080000000)
qemu-system-riscv64: rom check and register reset failed

If a current user specieifies "-bios none" their flow will continue working. A user can instead no longer load their firmware and use the default or they can load their firmware with the -bios option.

At the moment the best idea I have to not break all users is to only include the default firmware if the user specifies "-bios opensbi". That is change the default to not loading the firmware. Then we can work on updating documentation and maybe in future change the default to include a firmware and anyone who doesn't want a default firmware can specify "-bios none".

Any other ideas on how to not break everything?

Alistair Francis (5):
hw/riscv: Split out the boot functions
hw/riscv: Add support for loading a firmware
hw/riscv: Extend the kernel loading support
roms: Add OpenSBI version 0.3
hw/riscv: Load OpenSBI as the default firmware

 .gitmodules                         |   3 +
 Makefile                            |   3 +-
 configure                           |   1 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/boot.c                     | 143 ++++++++++++++++++++++++++++
 hw/riscv/sifive_e.c                 |  17 +---
 hw/riscv/sifive_u.c                 |  19 +---
 hw/riscv/spike.c                    |  21 +---
 hw/riscv/virt.c                     |  54 ++---------
 include/hw/riscv/boot.h             |  30 ++++++
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
Quoted 5 lines
Quoted 2 lines

Since we are considering adding "bios" images, I prefer to add the pure binary images instead of ELF images here.

I didn't think about that. Can we just boot them in QEMU like we do with the ELFs?

Yes, use load_image_targphys() instead of load_elf().

Regards,
Bin

#24 lore raw
Quoted 78 lines · Bin Meng
Quoted 76 lines · Alistair Francis
Quoted 14 lines · Bin Meng
Quoted 11 lines · Alistair Francis

This is an RFC as it will break ALL current users! See below for details.

This series consolidates the current RISC-V kernel loading impelementation while also adding support for the -bios option and more advanced kernel image types.

After consolidating the kernel loading we can extend the boot loader to support a -bios option. We can also extend the kernel loading options to support not just ELF files but other standard formats.

Quoted 8 lines
Quoted 5 lines

Finally we can include the OpenSBI firmware by default for QEMU users.

At the end of this series 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

This is great. I like booting kernel directly for testing without bothering the firmware stuff.

That's the goal! Now we just need to not break everything.

Quoted 49 lines
Quoted 48 lines

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).

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Unfortunately this series (patch 5 specifically) results in all current Linux boots being broken as users are already loading in their own firmware, which overlaps with the now included default. They will see this error:

rom: requested regions overlap (rom phdr #0: ./images/qemuriscv64/fw_jump.elf. free=0x0000000080008090, addr=0x0000000080000000)
qemu-system-riscv64: rom check and register reset failed

If a current user specieifies "-bios none" their flow will continue working. A user can instead no longer load their firmware and use the default or they can load their firmware with the -bios option.

At the moment the best idea I have to not break all users is to only include the default firmware if the user specifies "-bios opensbi". That is change the default to not loading the firmware. Then we can work on updating documentation and maybe in future change the default to include a firmware and anyone who doesn't want a default firmware can specify "-bios none".

Any other ideas on how to not break everything?

Alistair Francis (5):
hw/riscv: Split out the boot functions
hw/riscv: Add support for loading a firmware
hw/riscv: Extend the kernel loading support
roms: Add OpenSBI version 0.3
hw/riscv: Load OpenSBI as the default firmware

 .gitmodules                         |   3 +
 Makefile                            |   3 +-
 configure                           |   1 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/boot.c                     | 143 ++++++++++++++++++++++++++++
 hw/riscv/sifive_e.c                 |  17 +---
 hw/riscv/sifive_u.c                 |  19 +---
 hw/riscv/spike.c                    |  21 +---
 hw/riscv/virt.c                     |  54 ++---------
 include/hw/riscv/boot.h             |  30 ++++++
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Since we are considering adding "bios" images, I prefer to add the pure binary images instead of ELF images here.

I didn't think about that. Can we just boot them in QEMU like we do with the ELFs?

Yes, use load_image_targphys() instead of load_elf().

Ah, that is obvious. I'll update it to use the bin files then.

Alistair

Quoted 3 lines

Regards,
Bin

#25 lore raw
Quoted 9 lines · Alistair Francis
Quoted 8 lines · Bin Meng
Quoted 7 lines · Alistair Francis
Quoted 5 lines · Bin Meng
Quoted 2 lines
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes

Since we are considering adding "bios" images, I prefer to add the pure binary images instead of ELF images here.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I didn't think about that. Can we just boot them in QEMU like we do with the ELFs?

Yes, use load_image_targphys() instead of load_elf().

Ah, that is obvious. I'll update it to use the bin files then.

I'm unclear on the advantages of using one format over the other, but one question comes to mind: once this is in, we will probably want to have OpenSBI packaged separately in distributions, the same way it already happens for SeaBIOS, SLOF and edk2-based firmwares.

Will using either of the formats prevent that from happening?

Signature · 1 line
Andrea Bolognani / Red Hat / Virtualization
#26 lore raw
Quoted 11 lines · Andrea Bolognani
Quoted 9 lines · Alistair Francis
Quoted 8 lines · Bin Meng
Quoted 7 lines · Alistair Francis
Quoted 5 lines · Bin Meng
Quoted 2 lines
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes

Since we are considering adding "bios" images, I prefer to add the pure binary images instead of ELF images here.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I didn't think about that. Can we just boot them in QEMU like we do with the ELFs?

Yes, use load_image_targphys() instead of load_elf().

Ah, that is obvious. I'll update it to use the bin files then.

I'm unclear on the advantages of using one format over the other,

The main one that I see is that everyone else is already using .bin and no one else is using .elf.

Quoted 5 lines

but one question comes to mind: once this is in, we will probably want to have OpenSBI packaged separately in distributions, the same way it already happens for SeaBIOS, SLOF and edk2-based firmwares.

Will using either of the formats prevent that from happening?

Both options allow this.

OE-Core already packages OpenSBI by default, Fedora and Debian are moving to OpenSBI for RISC-V targets as well.

Any distro that supports the RISC-V toolchain (which is all upstreamed) can build OpenSBI.

Alistair

Quoted 4 lines

--
Andrea Bolognani / Red Hat / Virtualization

#27 lore raw
Quoted 29 lines · Alistair Francis
Quoted 11 lines · Andrea Bolognani
Quoted 9 lines · Alistair Francis
Quoted 8 lines · Bin Meng
Quoted 7 lines · Alistair Francis
Quoted 5 lines · Bin Meng
Quoted 2 lines
 pc-bios/opensbi-riscv32-fw_jump.elf | Bin 0 -> 197988 bytes
 pc-bios/opensbi-riscv64-fw_jump.elf | Bin 0 -> 200192 bytes

Since we are considering adding "bios" images, I prefer to add the pure binary images instead of ELF images here.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I didn't think about that. Can we just boot them in QEMU like we do with the ELFs?

Yes, use load_image_targphys() instead of load_elf().

Ah, that is obvious. I'll update it to use the bin files then.

I'm unclear on the advantages of using one format over the other,

The main one that I see is that everyone else is already using .bin and no one else is using .elf.

Quoted 4 lines

but one question comes to mind: once this is in, we will probably want to have OpenSBI packaged separately in distributions, the same way it already happens for SeaBIOS, SLOF and edk2-based firmwares.

Quoted 6 lines
Quoted 1 line

Will using either of the formats prevent that from happening?

Both options allow this.

OE-Core already packages OpenSBI by default, Fedora and Debian are moving to OpenSBI for RISC-V targets as well.

Fedora uses OpenSBI for the last 2 or 3 months now. I don't plan to update BBL builds. OpenSBI packages in Fedora/RISCV isn't finalized, but it does ship *.elf and *.bin files.

Quoted 11 lines

Any distro that supports the RISC-V toolchain (which is all upstreamed) can build OpenSBI.

Alistair

Quoted 4 lines

--
Andrea Bolognani / Red Hat / Virtualization

#28 lore raw
Quoted 13 lines · David Abdurachmanov
Quoted 12 lines · Alistair Francis
Quoted 5 lines · Andrea Bolognani

but one question comes to mind: once this is in, we will probably want to have OpenSBI packaged separately in distributions, the same way it already happens for SeaBIOS, SLOF and edk2-based firmwares.

Will using either of the formats prevent that from happening?

Both options allow this.

OE-Core already packages OpenSBI by default, Fedora and Debian are moving to OpenSBI for RISC-V targets as well.

Quoted 6 lines
Quoted 2 lines

Any distro that supports the RISC-V toolchain (which is all upstreamed) can build OpenSBI.

Fedora uses OpenSBI for the last 2 or 3 months now. I don't plan to update BBL builds. OpenSBI packages in Fedora/RISCV isn't finalized, but it does ship *.elf and *.bin files.

Sounds good to me, thanks for confirming!

Signature · 1 line
Andrea Bolognani / Red Hat / Virtualization
#29 lore raw
Quoted 5 lines · Andrea Bolognani
Quoted 4 lines · David Abdurachmanov
Quoted 3 lines · Alistair Francis

OE-Core already packages OpenSBI by default, Fedora and Debian are moving to OpenSBI for RISC-V targets as well.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Any distro that supports the RISC-V toolchain (which is all upstreamed) can build OpenSBI.

Fedora uses OpenSBI for the last 2 or 3 months now. I don't plan to update BBL builds. OpenSBI packages in Fedora/RISCV isn't finalized, but it does ship *.elf and *.bin files.

Sounds good to me, thanks for confirming!

From further off-list discussion with David, I have learned that recent Fedora images include an OpenSBI build with embedded U-Boot payload, such that you only need to have that single file on the host and pass it to QEMU via -kernel[1] for RISC-V guest boot to work. I played with it over the past few days, and it works very nicely.

I think this is the result that we want to ultimately reach: a single RISC-V "firmware" binary installed on the host through an appropriate distro package, shared among guests, with everything else that is guest-specific being contained in the corresponding disk image.

This is what other architectures are already doing, with SeaBIOS and OVMF on x86_64, AAVMF on aarch64 and SLOF on ppc64 all being handled this way: RISC-V should, where it makes sense, follow suit.

QEMU also recently introduced a JSON-based specification that can be used to advertise guest firmwares and libvirt already supports it, which makes firmware configuration either extremely convenient or entirely automatic for the user: the OpenSBI support should also be advertised this way.

[1] I guess that'd be -bios after these patches?

Signature · 1 line
Andrea Bolognani / Red Hat / Virtualization