[PATCH] hw/riscv: virt: Enable booting S-mode firmware from pflash

Sunil V L posted 1 patch 1 year, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220905042940.146913-1-sunilvl@ventanamicro.com
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bin.meng@windriver.com>
There is a newer version of this series
hw/riscv/virt.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
[PATCH] hw/riscv: virt: Enable booting S-mode firmware from pflash
Posted by Sunil V L 1 year, 7 months ago
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.

Update the kernel_entry with the flash address when no kernel
is specified via QEMU command line  so that opensbi
can jump to the flash address. This assumes flash drive unit 1 is
used to keep dynamic payload similar to other architectures.

Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
---
 hw/riscv/virt.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index ff8c0df5cd..1ee855fded 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -1284,6 +1284,18 @@ static void virt_machine_done(Notifier *notifier, void *data)
         start_addr = virt_memmap[VIRT_FLASH].base;
     }
 
+    if (drive_get(IF_PFLASH, 0, 1)) {
+        /*
+         * Assume second pflash unit (unit=1) to hold the S-mode firmware
+         * like EDK2. Set kernel_entry to flash address if kernel argument
+         * is not set and pflash unit 1 is configured.
+         */
+        if (!kernel_entry) {
+            kernel_entry = virt_memmap[VIRT_FLASH].base +
+                             virt_memmap[VIRT_FLASH].size / 2;
+        }
+    }
+
     /*
      * Init fw_cfg.  Must be done before riscv_load_fdt, otherwise the device
      * tree cannot be altered and we get FDT_ERR_NOSPACE.
-- 
2.25.1
Re: [PATCH] hw/riscv: virt: Enable booting S-mode firmware from pflash
Posted by Andrew Jones 1 year, 7 months ago
On Mon, Sep 05, 2022 at 09:59:40AM +0530, Sunil V L 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.
> 
> Update the kernel_entry with the flash address when no kernel
> is specified via QEMU command line  so that opensbi
> can jump to the flash address. This assumes flash drive unit 1 is
> used to keep dynamic payload similar to other architectures.
> 
> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
> ---
>  hw/riscv/virt.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index ff8c0df5cd..1ee855fded 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -1284,6 +1284,18 @@ static void virt_machine_done(Notifier *notifier, void *data)
>          start_addr = virt_memmap[VIRT_FLASH].base;
>      }
>  
> +    if (drive_get(IF_PFLASH, 0, 1)) {
> +        /*
> +         * Assume second pflash unit (unit=1) to hold the S-mode firmware
> +         * like EDK2. Set kernel_entry to flash address if kernel argument
> +         * is not set and pflash unit 1 is configured.
> +         */
> +        if (!kernel_entry) {
> +            kernel_entry = virt_memmap[VIRT_FLASH].base +
> +                             virt_memmap[VIRT_FLASH].size / 2;
> +        }
> +    }
> +
>      /*
>       * Init fw_cfg.  Must be done before riscv_load_fdt, otherwise the device
>       * tree cannot be altered and we get FDT_ERR_NOSPACE.
> -- 
> 2.25.1
> 
>

Hi Sunil,

We should ensure we can use both edk2 and the '-kernel' option. For
example, guest installation will typically do direct kernel boot,
and when it's desired / necessary to boot that kernel with ACPI, then
we'll also need edk2.

Thanks,
drew
Re: [PATCH] hw/riscv: virt: Enable booting S-mode firmware from pflash
Posted by Sunil V L 1 year, 7 months ago
On Mon, Sep 05, 2022 at 10:07:22AM +0200, Andrew Jones wrote:
> On Mon, Sep 05, 2022 at 09:59:40AM +0530, Sunil V L 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.
> > 
> > Update the kernel_entry with the flash address when no kernel
> > is specified via QEMU command line  so that opensbi
> > can jump to the flash address. This assumes flash drive unit 1 is
> > used to keep dynamic payload similar to other architectures.
> > 
> > Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
> > ---
> >  hw/riscv/virt.c | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> > 
> > diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> > index ff8c0df5cd..1ee855fded 100644
> > --- a/hw/riscv/virt.c
> > +++ b/hw/riscv/virt.c
> > @@ -1284,6 +1284,18 @@ static void virt_machine_done(Notifier *notifier, void *data)
> >          start_addr = virt_memmap[VIRT_FLASH].base;
> >      }
> >  
> > +    if (drive_get(IF_PFLASH, 0, 1)) {
> > +        /*
> > +         * Assume second pflash unit (unit=1) to hold the S-mode firmware
> > +         * like EDK2. Set kernel_entry to flash address if kernel argument
> > +         * is not set and pflash unit 1 is configured.
> > +         */
> > +        if (!kernel_entry) {
> > +            kernel_entry = virt_memmap[VIRT_FLASH].base +
> > +                             virt_memmap[VIRT_FLASH].size / 2;
> > +        }
> > +    }
> > +
> >      /*
> >       * Init fw_cfg.  Must be done before riscv_load_fdt, otherwise the device
> >       * tree cannot be altered and we get FDT_ERR_NOSPACE.
> > -- 
> > 2.25.1
> > 
> >
> 
> Hi Sunil,
> 
> We should ensure we can use both edk2 and the '-kernel' option. For
> example, guest installation will typically do direct kernel boot,
> and when it's desired / necessary to boot that kernel with ACPI, then
> we'll also need edk2.

Thank you very much, Drew. Let me revise the patch and send.

Thanks
Sunil
> 
> Thanks,
> drew