diff mbox series

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

Message ID 20220905042940.146913-1-sunilvl@ventanamicro.com (mailing list archive)
State New, archived
Headers show
Series hw/riscv: virt: Enable booting S-mode firmware from pflash | expand

Commit Message

Sunil V L Sept. 5, 2022, 4:29 a.m. UTC
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(+)

Comments

Andrew Jones Sept. 5, 2022, 8:07 a.m. UTC | #1
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
Sunil V L Sept. 5, 2022, 11:16 a.m. UTC | #2
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
diff mbox series

Patch

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.