From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com,
Bin Meng <bin.meng@windriver.com>,
Palmer Dabbelt <palmer@dabbelt.com>, Bin Meng <bmeng@tinylab.org>
Subject: Re: [PATCH v2 09/10] hw/riscv/boot.c: consolidate all kernel init in riscv_load_kernel()
Date: Wed, 28 Dec 2022 13:56:09 +0100 [thread overview]
Message-ID: <77a6f2da-e56e-a099-e0a1-6a99c4a9f7c9@linaro.org> (raw)
In-Reply-To: <20221228124242.184784-10-dbarboza@ventanamicro.com>
On 28/12/22 13:42, Daniel Henrique Barboza wrote:
> 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;
> }
Worth renaming as riscv_load_kernel_and_initrd()?
next prev parent reply other threads:[~2022-12-28 12:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-28 12:42 [PATCH v2 00/10] riscv: opensbi boot test and cleanups Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 01/10] tests/avocado: add RISC-V opensbi boot test Daniel Henrique Barboza
2022-12-28 12:59 ` Philippe Mathieu-Daudé
2022-12-28 13:03 ` Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 02/10] hw/riscv/spike: use 'fdt' from MachineState Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 03/10] hw/riscv/sifive_u: " Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 04/10] hw/riscv/spike.c: load initrd right after riscv_load_kernel() Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 05/10] hw/riscv: write initrd 'chosen' FDT inside riscv_load_initrd() Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 06/10] hw/riscv: write bootargs 'chosen' FDT after riscv_load_kernel() Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 07/10] hw/riscv/boot.c: use MachineState in riscv_load_initrd() Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 08/10] hw/riscv/boot.c: use MachineState in riscv_load_kernel() Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 09/10] hw/riscv/boot.c: consolidate all kernel init " Daniel Henrique Barboza
2022-12-28 12:56 ` Philippe Mathieu-Daudé [this message]
2022-12-28 13:01 ` Daniel Henrique Barboza
2022-12-28 12:42 ` [PATCH v2 10/10] hw/riscv/boot.c: make riscv_load_initrd() static Daniel Henrique Barboza
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=77a6f2da-e56e-a099-e0a1-6a99c4a9f7c9@linaro.org \
--to=philmd@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=bin.meng@windriver.com \
--cc=bmeng@tinylab.org \
--cc=dbarboza@ventanamicro.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).