[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/37] hw/riscv/boot.c: Introduce riscv_find_firmware()
From: |
Alistair Francis |
Subject: |
[PULL 11/37] hw/riscv/boot.c: Introduce riscv_find_firmware() |
Date: |
Fri, 20 Jan 2023 17:38:47 +1000 |
From: Bin Meng <bmeng@tinylab.org>
Rename previous riscv_find_firmware() to riscv_find_bios(), and
introduce a new riscv_find_firmware() to implement the first half
part of the work done in riscv_find_and_load_firmware().
This new API is helpful for machine that wants to know the final
chosen firmware file name but does not want to load it.
Signed-off-by: Bin Meng <bmeng@tinylab.org>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20221229091828.1945072-12-bmeng@tinylab.org>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
include/hw/riscv/boot.h | 2 ++
hw/riscv/boot.c | 39 +++++++++++++++++++++++++--------------
2 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h
index 60cf320c88..b273ab22f7 100644
--- a/include/hw/riscv/boot.h
+++ b/include/hw/riscv/boot.h
@@ -38,6 +38,8 @@ target_ulong riscv_find_and_load_firmware(MachineState
*machine,
hwaddr firmware_load_addr,
symbol_fn_t sym_cb);
const char *riscv_default_firmware_name(RISCVHartArrayState *harts);
+char *riscv_find_firmware(const char *firmware_filename,
+ const char *default_machine_firmware);
target_ulong riscv_load_firmware(const char *firmware_filename,
hwaddr firmware_load_addr,
symbol_fn_t sym_cb);
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index e1a544b1d9..98b80af51b 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -84,11 +84,11 @@ const char *riscv_default_firmware_name(RISCVHartArrayState
*harts)
return RISCV64_BIOS_BIN;
}
-static char *riscv_find_firmware(const char *firmware_filename)
+static char *riscv_find_bios(const char *bios_filename)
{
char *filename;
- filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware_filename);
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_filename);
if (filename == NULL) {
if (!qtest_enabled()) {
/*
@@ -97,8 +97,8 @@ static char *riscv_find_firmware(const char
*firmware_filename)
* running QEMU test will complain hence let's suppress the error
* report for QEMU testing.
*/
- error_report("Unable to load the RISC-V firmware \"%s\"",
- firmware_filename);
+ error_report("Unable to find the RISC-V BIOS \"%s\"",
+ bios_filename);
exit(1);
}
}
@@ -106,25 +106,36 @@ static char *riscv_find_firmware(const char
*firmware_filename)
return filename;
}
-target_ulong riscv_find_and_load_firmware(MachineState *machine,
- const char *default_machine_firmware,
- hwaddr firmware_load_addr,
- symbol_fn_t sym_cb)
+char *riscv_find_firmware(const char *firmware_filename,
+ const char *default_machine_firmware)
{
- char *firmware_filename = NULL;
- target_ulong firmware_end_addr = firmware_load_addr;
+ char *filename = NULL;
- if ((!machine->firmware) || (!strcmp(machine->firmware, "default"))) {
+ if ((!firmware_filename) || (!strcmp(firmware_filename, "default"))) {
/*
* The user didn't specify -bios, or has specified "-bios default".
* That means we are going to load the OpenSBI binary included in
* the QEMU source.
*/
- firmware_filename = riscv_find_firmware(default_machine_firmware);
- } else if (strcmp(machine->firmware, "none")) {
- firmware_filename = riscv_find_firmware(machine->firmware);
+ filename = riscv_find_bios(default_machine_firmware);
+ } else if (strcmp(firmware_filename, "none")) {
+ filename = riscv_find_bios(firmware_filename);
}
+ return filename;
+}
+
+target_ulong riscv_find_and_load_firmware(MachineState *machine,
+ const char *default_machine_firmware,
+ hwaddr firmware_load_addr,
+ symbol_fn_t sym_cb)
+{
+ char *firmware_filename;
+ target_ulong firmware_end_addr = firmware_load_addr;
+
+ firmware_filename = riscv_find_firmware(machine->firmware,
+ default_machine_firmware);
+
if (firmware_filename) {
/* If not "none" load the firmware */
firmware_end_addr = riscv_load_firmware(firmware_filename,
--
2.39.0
- [PULL 02/37] hw/char: riscv_htif: Drop {to, from}host_size in HTIFState, (continued)
- [PULL 02/37] hw/char: riscv_htif: Drop {to, from}host_size in HTIFState, Alistair Francis, 2023/01/20
- [PULL 01/37] hw/char: riscv_htif: Avoid using magic numbers, Alistair Francis, 2023/01/20
- [PULL 09/37] hw/riscv/boot.c: make riscv_find_firmware() static, Alistair Francis, 2023/01/20
- [PULL 06/37] hw/char: riscv_htif: Remove forward declarations for non-existent variables, Alistair Francis, 2023/01/20
- [PULL 10/37] hw/riscv/boot.c: introduce riscv_default_firmware_name(), Alistair Francis, 2023/01/20
- [PULL 03/37] hw/char: riscv_htif: Drop useless assignment of memory region, Alistair Francis, 2023/01/20
- [PULL 04/37] hw/char: riscv_htif: Use conventional 's' for HTIFState, Alistair Francis, 2023/01/20
- [PULL 05/37] hw/char: riscv_htif: Move registers from CPUArchState to HTIFState, Alistair Francis, 2023/01/20
- [PULL 07/37] hw/char: riscv_htif: Support console output via proxy syscall, Alistair Francis, 2023/01/20
- [PULL 08/37] hw/riscv: spike: Remove the out-of-date comments, Alistair Francis, 2023/01/20
- [PULL 11/37] hw/riscv/boot.c: Introduce riscv_find_firmware(),
Alistair Francis <=
- [PULL 12/37] hw/riscv: spike: Decouple create_fdt() dependency to ELF loading, Alistair Francis, 2023/01/20
- [PULL 13/37] target/riscv/cpu.c: Fix elen check, Alistair Francis, 2023/01/20
- [PULL 14/37] tests/avocado: add RISC-V OpenSBI boot test, Alistair Francis, 2023/01/20
- [PULL 16/37] hw/riscv/sifive_u: use 'fdt' from MachineState, Alistair Francis, 2023/01/20
- [PULL 15/37] hw/riscv/spike: use 'fdt' from MachineState, Alistair Francis, 2023/01/20
- [PULL 17/37] hw/riscv/boot.c: exit early if filename is NULL in load functions, Alistair Francis, 2023/01/20
- [PULL 18/37] hw/riscv/spike.c: load initrd right after riscv_load_kernel(), Alistair Francis, 2023/01/20
- [PULL 19/37] hw/riscv: write initrd 'chosen' FDT inside riscv_load_initrd(), Alistair Francis, 2023/01/20
- [PULL 20/37] hw/riscv: write bootargs 'chosen' FDT after riscv_load_kernel(), Alistair Francis, 2023/01/20
- [PULL 21/37] hw/riscv/boot.c: use MachineState in riscv_load_initrd(), Alistair Francis, 2023/01/20