[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 09/10] hw/riscv/boot.c: consolidate all kernel init in riscv_l
From: |
Daniel Henrique Barboza |
Subject: |
[PATCH v2 09/10] hw/riscv/boot.c: consolidate all kernel init in riscv_load_kernel() |
Date: |
Wed, 28 Dec 2022 09:42:41 -0300 |
The microchip_icicle_kit, sifive_u, spike and virt boards are now doing
the same steps when '-kernel' is used:
- execute load_kernel()
- load init_rd()
- write kernel_cmdline
Let's fold everything inside riscv_load_kernel() to avoid code
repetition. Every other board that uses riscv_load_kernel() will have
this same behavior, including boards that doesn't have a valid FDT, so
we need to take care to not do FDT operations without checking it first.
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Bin Meng <bmeng@tinylab.org>
---
hw/riscv/boot.c | 21 ++++++++++++++++++---
hw/riscv/microchip_pfsoc.c | 9 ---------
hw/riscv/sifive_u.c | 9 ---------
hw/riscv/spike.c | 9 ---------
hw/riscv/virt.c | 9 ---------
5 files changed, 18 insertions(+), 39 deletions(-)
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index cd9c989edb..95f780a228 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -177,6 +177,7 @@ target_ulong riscv_load_kernel(MachineState *machine,
{
const char *kernel_filename = machine->kernel_filename;
uint64_t kernel_load_base, kernel_entry;
+ void *fdt = machine->fdt;
/*
* NB: Use low address not ELF entry point to ensure that the fw_dynamic
@@ -188,21 +189,35 @@ target_ulong riscv_load_kernel(MachineState *machine,
if (load_elf_ram_sym(kernel_filename, NULL, NULL, NULL,
NULL, &kernel_load_base, NULL, NULL, 0,
EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) {
- return kernel_load_base;
+ kernel_entry = kernel_load_base;
+ goto out;
}
if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL,
NULL, NULL, NULL) > 0) {
- return kernel_entry;
+ goto out;
}
if (load_image_targphys_as(kernel_filename, kernel_start_addr,
current_machine->ram_size, NULL) > 0) {
- return kernel_start_addr;
+ kernel_entry = kernel_start_addr;
+ goto out;
}
error_report("could not load kernel '%s'", kernel_filename);
exit(1);
+
+out:
+ if (machine->initrd_filename) {
+ riscv_load_initrd(machine, kernel_entry);
+ }
+
+ if (fdt && machine->kernel_cmdline && *machine->kernel_cmdline) {
+ qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
+ machine->kernel_cmdline);
+ }
+
+ return kernel_entry;
}
void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
index 82ae5e7023..57fd6739a5 100644
--- a/hw/riscv/microchip_pfsoc.c
+++ b/hw/riscv/microchip_pfsoc.c
@@ -631,15 +631,6 @@ static void microchip_icicle_kit_machine_init(MachineState
*machine)
kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL);
- if (machine->initrd_filename) {
- riscv_load_initrd(machine, kernel_entry);
- }
-
- if (machine->kernel_cmdline && *machine->kernel_cmdline) {
- qemu_fdt_setprop_string(machine->fdt, "/chosen",
- "bootargs", machine->kernel_cmdline);
- }
-
/* Compute the fdt load address in dram */
fdt_load_addr = riscv_load_fdt(memmap[MICROCHIP_PFSOC_DRAM_LO].base,
machine->ram_size, machine->fdt);
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index bac394c959..0c9bf7fe6a 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -599,15 +599,6 @@ static void sifive_u_machine_init(MachineState *machine)
firmware_end_addr);
kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL);
-
- if (machine->initrd_filename) {
- riscv_load_initrd(machine, kernel_entry);
- }
-
- if (machine->kernel_cmdline && *machine->kernel_cmdline) {
- qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs",
- machine->kernel_cmdline);
- }
} else {
/*
* If dynamic firmware is used, it doesn't know where is the next mode
diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
index 0bba5c1640..48d004802b 100644
--- a/hw/riscv/spike.c
+++ b/hw/riscv/spike.c
@@ -304,15 +304,6 @@ static void spike_board_init(MachineState *machine)
kernel_entry = riscv_load_kernel(machine, kernel_start_addr,
htif_symbol_callback);
-
- if (machine->initrd_filename) {
- riscv_load_initrd(machine, kernel_entry);
- }
-
- if (machine->kernel_cmdline && *machine->kernel_cmdline) {
- qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs",
- machine->kernel_cmdline);
- }
} else {
/*
* If dynamic firmware is used, it doesn't know where is the next mode
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index c8e35f861e..11c903a212 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -1282,15 +1282,6 @@ static void virt_machine_done(Notifier *notifier, void
*data)
firmware_end_addr);
kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL);
-
- if (machine->initrd_filename) {
- riscv_load_initrd(machine, kernel_entry);
- }
-
- if (machine->kernel_cmdline && *machine->kernel_cmdline) {
- qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs",
- machine->kernel_cmdline);
- }
} else {
/*
* If dynamic firmware is used, it doesn't know where is the next mode
--
2.38.1
- Re: [PATCH v2 01/10] tests/avocado: add RISC-V opensbi boot test, (continued)
- [PATCH v2 04/10] hw/riscv/spike.c: load initrd right after riscv_load_kernel(), Daniel Henrique Barboza, 2022/12/28
- [PATCH v2 03/10] hw/riscv/sifive_u: use 'fdt' from MachineState, Daniel Henrique Barboza, 2022/12/28
- [PATCH v2 06/10] hw/riscv: write bootargs 'chosen' FDT after riscv_load_kernel(), Daniel Henrique Barboza, 2022/12/28
- [PATCH v2 02/10] hw/riscv/spike: use 'fdt' from MachineState, Daniel Henrique Barboza, 2022/12/28
- [PATCH v2 05/10] hw/riscv: write initrd 'chosen' FDT inside riscv_load_initrd(), Daniel Henrique Barboza, 2022/12/28
- [PATCH v2 07/10] hw/riscv/boot.c: use MachineState in riscv_load_initrd(), Daniel Henrique Barboza, 2022/12/28
- [PATCH v2 10/10] hw/riscv/boot.c: make riscv_load_initrd() static, Daniel Henrique Barboza, 2022/12/28
- [PATCH v2 08/10] hw/riscv/boot.c: use MachineState in riscv_load_kernel(), Daniel Henrique Barboza, 2022/12/28
- [PATCH v2 09/10] hw/riscv/boot.c: consolidate all kernel init in riscv_load_kernel(),
Daniel Henrique Barboza <=