From nobody Tue Feb 10 02:45:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1561415059; cv=none; d=zoho.com; s=zohoarc; b=ed+gnWEseMS+5ltzzQ6gCBPVJ4enU3VJCRF3aqTza0SBiGklGe1WMx/PNXp0AGu6/8t73veFkI1T5kV5Th2imB2iDRv4J1Mls3YrRT0nYK6oCRzoMwVdAenAGc/09UYT835zwZigectXK9PkPrbNI9tskjWuiKfMTnNFlI71B8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561415059; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HWyl4gBP4rABnZOLSvcDYSpE69UoUSC7vuUKrtOi1OU=; b=JQb2UZH29Yx/xh4Q9DdiV/yAvu2LFU0NJIOOWP42n8r7q0t09IBHdHGq5atzu1/ZpTxkaF2XiyUurJXaAnZWxzU/ebIwa5x/RQnly7q9VwUzSQ9DpOerFPExcjvDCmLDaQBTHXdxkgtpg7A7iUTNbaq7DfTKkAWYaL4fNXj/7f4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561415059235371.23011613572703; Mon, 24 Jun 2019 15:24:19 -0700 (PDT) Received: from localhost ([::1]:55036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfXNe-0001fP-VE for importer@patchew.org; Mon, 24 Jun 2019 18:24:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58815) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfXES-0002KL-TX for qemu-devel@nongnu.org; Mon, 24 Jun 2019 18:14:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfXEO-00005F-Oz for qemu-devel@nongnu.org; Mon, 24 Jun 2019 18:14:34 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:7996) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hfXEM-0008U3-JI; Mon, 24 Jun 2019 18:14:32 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 25 Jun 2019 06:15:14 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 24 Jun 2019 15:13:47 -0700 Received: from risc6-mainframe.sdcorp.global.sandisk.com (HELO risc6-mainframe.int.fusionio.com) ([10.196.157.140]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Jun 2019 15:14:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1561414516; x=1592950516; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CqeGaTwLwtSj5t8Bw5VBD9Fwg69+EafHOWkeml/LuM8=; b=N3ZGZfEtGPok2+/f8cE+a7dKd0m/GTvskmYauZTKETJLv1TpQdWJ2/GQ 5XMMbUpVJxjEKDwniIFOJDULYJrSkjpx0u4B81vtcHelIURUeyWAcX7r1 dj+0m+K05PJRSRbCNZlUs/7lJVvgiLNUOamIW/4CnY1ytOzuzmsEzJRgG 9qG2k1jJP5BusL8Rldp6Onc3iSaOlG9lPkwi7Fqznmoh5zmT+j5noiqcI We5T21MR/TnZpI+A7HtwA1XQ4WRXrCPf04g5UcKW72AMSBLUT/a3xdOuX 2TQa+jFxsbTOKhmHa2pGGmI2beiI8vcD5Uu8rh3lDWkTXM6wIUpczlJdd A==; X-IronPort-AV: E=Sophos;i="5.63,413,1557158400"; d="scan'208";a="211210932" IronPort-SDR: s6zFBDL4cMDhcbrf0NEwupcZfAd4ZXWz5hqBkNCoyEcyLgtyV2yy95oBDrvrWSJ+OcwuHKtuJN k01DcN5wyQhI0J0VUDNVpZmN+wWqo4MNMHlvu96P2UIJclK6ViqBfAnRKdfULD05n9vJW/BipF e8/EcwEDrIjZy4QcVFHzd1PrkdkGBoVeEmFXpvP0nUzASQgngIAHSNzRd99r/cQoaMb3JCWLf2 o/0GGe+xvZ/VojHYWvD/styiC9lonxI5mCsMBqrNorixi/yfhUYc8lDkDTfBD3UGCyIXfnOJAK CA009eT3Fu4UkApv7S+k42DW IronPort-SDR: Rj8S4SVPXB5XQRWwVqB5psbA9bYHP8YrCOSi0TWkdPYPbhQ1w09IvFgiPK5uQkkJ9m/9RNiWY+ JYIeUyW4xlmJNOaWdF9aFsiCy8NtmiFCH1EY5rQ9mjqg47WYMboONNHBehYu5TvGzjymnATVet J/XGG9rFdhhgiPpKOZjKQEl44ZBISAWMY4umXJyQ9Ax6PD8p0NeZMeRLFsKn+sZjRflKMDPVU8 0NJ1rvxIdpafBgHQRFJYWcIQ5Jlw8FVe7iN4giDepsPIo68pXXOJNsuRCSkq+cfXDo4MicsLS7 Euk= From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Date: Mon, 24 Jun 2019 15:12:00 -0700 Message-Id: <7f51ed96a93bf46f76dbdfac61e4d14002d40e08.1561414240.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 68.232.143.124 Subject: [Qemu-devel] [PATCH v1 5/5] hw/riscv: Load OpenSBI as the default firmware X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair23@gmail.com, palmer@sifive.com, alistair.francis@wdc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng --- 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(-) diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index ff023f42d0..c7d72f682f 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -18,6 +18,7 @@ */ =20 #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 =20 +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 u= sers + * as users are already loading their own firmware. + * + * Let's try to get everyone to specify the -bios option at all ti= mes, + * so then in the future we can make "-bios default" the default o= ption + * if no -bios option is set without breaking anything. + */ + firmware_filename =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, + default_machine_firmware); + } else { + firmware_filename =3D 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) { diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index a04f2d0754..d308aec592 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -49,6 +49,8 @@ =20 #include =20 +#define BIOS_FILENAME "opensbi-riscv64-sifive_u-fw_jump.bin" + static const struct MemmapEntry { hwaddr base; hwaddr size; @@ -266,9 +268,8 @@ static void riscv_sifive_u_init(MachineState *machine) /* create device tree */ create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline); =20 - 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); =20 if (machine->kernel_filename) { riscv_load_kernel(machine->kernel_filename); diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 7fcc8c03b5..260e6e8e4d 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -44,6 +44,12 @@ =20 #include =20 +#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; @@ -380,9 +386,8 @@ static void riscv_virt_board_init(MachineState *machine) memory_region_add_subregion(system_memory, memmap[VIRT_MROM].base, mask_rom); =20 - if (machine->firmware) { - riscv_load_firmware(machine->firmware, memmap[VIRT_DRAM].base); - } + riscv_find_and_load_firmware(machine, BIOS_FILENAME, + memmap[VIRT_DRAM].base); =20 if (machine->kernel_filename) { uint64_t kernel_entry =3D riscv_load_kernel(machine->kernel_filena= me); diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h index daa179b600..d56f2ae3eb 100644 --- a/include/hw/riscv/boot.h +++ b/include/hw/riscv/boot.h @@ -20,6 +20,9 @@ #ifndef RISCV_BOOT_H #define RISCV_BOOT_H =20 +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); diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index df04f2840b..b0494c3350 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -88,6 +88,26 @@ The @code{-realtime mlock=3Don|off} argument has been re= placed by the The ``-virtfs_synth'' argument is now deprecated. Please use ``-fsdev synt= h'' and ``-device virtio-9p-...'' instead. =20 +@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 u= sers +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 opti= on + 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 defa= ult + 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 nee= ds + to do is specify the kernel they want to boot with the -kernel option + 3. ``-bios `` - Tells QEMU to load the specified file as the firmwr= ae. + @section QEMU Machine Protocol (QMP) commands =20 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0) --=20 2.22.0