Commit 1f7678fa authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/palmer/tags/riscv-for-master-4.1-rc2' into staging



RISC-V Patches for 4.2-rc2

This contains a pair of patches that add OpenSBI support to QEMU on
RISC-V targets.  The patches have been floating around for a bit, but
everything seems solid now.  These pass my standard test of booting
OpenEmbedded, and also works when I swap around the various command-line
arguments to use the new boot method.

# gpg: Signature made Fri 19 Jul 2019 00:54:27 BST
# gpg:                using RSA key 00CE76D1834960DFCE886DF8EF4CA1502CCBAB41
# gpg:                issuer "palmer@dabbelt.com"
# gpg: Good signature from "Palmer Dabbelt <palmer@dabbelt.com>" [unknown]
# gpg:                 aka "Palmer Dabbelt <palmer@sifive.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 00CE 76D1 8349 60DF CE88  6DF8 EF4C A150 2CCB AB41

* remotes/palmer/tags/riscv-for-master-4.1-rc2:
  hw/riscv: Load OpenSBI as the default firmware
  roms: Add OpenSBI version 0.4

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents 0274f45b fdd1bda4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -55,3 +55,6 @@
[submodule "slirp"]
	path = slirp
	url = https://git.qemu.org/git/libslirp.git
[submodule "roms/opensbi"]
	path = roms/opensbi
	url = 	https://git.qemu.org/git/opensbi.git
+13 −8
Original line number Diff line number Diff line
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
+4 −1
Original line number Diff line number Diff line
@@ -770,7 +770,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
+54 −0
Original line number Diff line number Diff line
@@ -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,59 @@
# 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);
        if (firmware_filename == NULL) {
            error_report("Unable to load the default RISC-V firmware \"%s\"",
                         default_machine_firmware);
            exit(1);
        }
    } 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)
{
+4 −3
Original line number Diff line number Diff line
@@ -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);
Loading