From: Alistair Francis <alistair23@gmail.com>
To: Sunil V L <sunilvl@ventanamicro.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Xiaojuan Yang" <yangxiaojuan@loongson.cn>,
"Song Gao" <gaosong@loongson.cn>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Bin Meng" <bin.meng@windriver.com>,
qemu-arm@nongnu.org, qemu-devel@nongnu.org,
qemu-riscv@nongnu.org, "Andrew Jones" <ajones@ventanamicro.com>
Subject: Re: [PATCH V5 3/3] hw/riscv: virt: Enable booting S-mode firmware from pflash
Date: Mon, 10 Oct 2022 11:24:13 +1000 [thread overview]
Message-ID: <CAKmqyKMtqAoo2s_UOdT=WeMHxXxgHBHqP_TFVbFdfSH=_jrarQ@mail.gmail.com> (raw)
In-Reply-To: <20221004092351.18209-4-sunilvl@ventanamicro.com>
On Tue, Oct 4, 2022 at 7:28 PM Sunil V L <sunilvl@ventanamicro.com> wrote:
>
> To boot S-mode firmware payload like EDK2 from persistent
> flash storage, qemu needs to pass the flash address as the
> next_addr in fw_dynamic_info to the opensbi.
>
> When both -kernel and -pflash options are provided in command line,
> the kernel (and initrd if -initrd) will be copied to fw_cfg table.
> The S-mode FW will load the kernel/initrd from fw_cfg table.
>
> If only pflash is given but not -kernel, then it is the job of
> of the S-mode firmware to locate and load the kernel.
>
> In either case, update the kernel_entry with the flash address
> so that the opensbi can jump to the entry point of the S-mode
> firmware.
>
> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> hw/riscv/boot.c | 29 +++++++++++++++++++++++++++++
> hw/riscv/virt.c | 18 +++++++++++++++++-
> include/hw/riscv/boot.h | 1 +
> 3 files changed, 47 insertions(+), 1 deletion(-)
>
> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> index 1ae7596873..fa8ad27da2 100644
> --- a/hw/riscv/boot.c
> +++ b/hw/riscv/boot.c
> @@ -338,3 +338,32 @@ void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr)
> riscv_cpu->env.fdt_addr = fdt_addr;
> }
> }
> +
> +void riscv_setup_firmware_boot(MachineState *machine)
> +{
> + if (machine->kernel_filename) {
> + FWCfgState *fw_cfg;
> + fw_cfg = fw_cfg_find();
> +
> + assert(fw_cfg);
> + /*
> + * Expose the kernel, the command line, and the initrd in fw_cfg.
> + * We don't process them here at all, it's all left to the
> + * firmware.
> + */
> + load_image_to_fw_cfg(fw_cfg,
> + FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA,
> + machine->kernel_filename,
> + true);
> + load_image_to_fw_cfg(fw_cfg,
> + FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA,
> + machine->initrd_filename, false);
> +
> + if (machine->kernel_cmdline) {
> + fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
> + strlen(machine->kernel_cmdline) + 1);
> + fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA,
> + machine->kernel_cmdline);
> + }
> + }
> +}
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index de2efccebf..a5bc7353b4 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -1274,7 +1274,23 @@ static void virt_machine_done(Notifier *notifier, void *data)
> s->fw_cfg = create_fw_cfg(machine);
> rom_set_fw(s->fw_cfg);
>
> - if (machine->kernel_filename) {
> + if (drive_get(IF_PFLASH, 0, 1)) {
> + /*
> + * S-mode FW like EDK2 will be kept in second plash (unit 1).
> + * When both kernel, initrd and pflash options are provided in the
> + * command line, the kernel and initrd will be copied to the fw_cfg
> + * table and opensbi will jump to the flash address which is the
> + * entry point of S-mode FW. It is the job of the S-mode FW to load
> + * the kernel and initrd using fw_cfg table.
> + *
> + * If only pflash is given but not -kernel, then it is the job of
> + * of the S-mode firmware to locate and load the kernel.
> + * In either case, the next_addr for opensbi will be the flash address.
> + */
> + riscv_setup_firmware_boot(machine);
> + kernel_entry = virt_memmap[VIRT_FLASH].base +
> + virt_memmap[VIRT_FLASH].size / 2;
> + } else if (machine->kernel_filename) {
> kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0],
> firmware_end_addr);
>
> diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h
> index a36f7618f5..93e5f8760d 100644
> --- a/include/hw/riscv/boot.h
> +++ b/include/hw/riscv/boot.h
> @@ -57,5 +57,6 @@ void riscv_rom_copy_firmware_info(MachineState *machine, hwaddr rom_base,
> uint32_t reset_vec_size,
> uint64_t kernel_entry);
> void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr);
> +void riscv_setup_firmware_boot(MachineState *machine);
>
> #endif /* RISCV_BOOT_H */
> --
> 2.25.1
>
>
next prev parent reply other threads:[~2022-10-10 1:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-04 9:23 [PATCH V5 0/3] hw/riscv: virt: Enable booting S-mode firmware from pflash Sunil V L
2022-10-04 9:23 ` [PATCH V5 1/3] hw/arm, loongarch: Move load_image_to_fw_cfg() to common location Sunil V L
2022-10-04 9:23 ` [PATCH V5 2/3] hw/riscv: virt: Move create_fw_cfg() prior to loading kernel Sunil V L
2022-10-04 9:23 ` [PATCH V5 3/3] hw/riscv: virt: Enable booting S-mode firmware from pflash Sunil V L
2022-10-10 1:24 ` Alistair Francis [this message]
2022-10-11 21:56 ` Bernhard Beschow
2022-10-11 22:39 ` [PATCH V5 0/3] " Alistair Francis
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='CAKmqyKMtqAoo2s_UOdT=WeMHxXxgHBHqP_TFVbFdfSH=_jrarQ@mail.gmail.com' \
--to=alistair23@gmail.com \
--cc=ajones@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=bin.meng@windriver.com \
--cc=f4bug@amsat.org \
--cc=gaosong@loongson.cn \
--cc=kraxel@redhat.com \
--cc=palmer@dabbelt.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=sunilvl@ventanamicro.com \
--cc=yangxiaojuan@loongson.cn \
/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).