diff mbox series

[v6,3/3] docs/system: riscv: Add pflash usage details

Message ID 20230531142300.9114-4-sunilvl@ventanamicro.com (mailing list archive)
State New, archived
Headers show
Series hw/riscv/virt: pflash improvements | expand

Commit Message

Sunil V L May 31, 2023, 2:23 p.m. UTC
pflash devices can be used in virt machine for different
purposes like for ROM code or S-mode FW payload. Add a
section in the documentation on how to use pflash devices
for different purposes.

Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 docs/system/riscv/virt.rst | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Comments

Andrea Bolognani May 31, 2023, 4:43 p.m. UTC | #1
On Wed, May 31, 2023 at 07:53:00PM +0530, Sunil V L wrote:
> +Using flash devices
> +-------------------
> +
> +When KVM is not enabled, the first flash device (pflash0) can contain either
> +the ROM code or S-mode payload firmware code. If the pflash0 contains the
> +ROM code, -bios should be set to none. If -bios is not set to
> +none, pflash0 is assumed to contain S-mode payload code.
> +
> +When KVM is enabled, pflash0 is always assumed to contain the S-mode payload
> +firmware.
> +
> +Firmware images used for pflash should be of size 32 MiB.
> +
> +To boot as ROM code:
> +
> +.. code-block:: bash
> +
> +  $ qemu-system-riscv64 -bios none \
> +     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<rom_code> \
> +     -M virt,pflash0=pflash0 \
> +     ... other args ....
> +
> +To boot as read-only S-mode payload:
> +
> +.. code-block:: bash
> +
> +  $ qemu-system-riscv64 \
> +     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<s-mode_fw_code> \
> +     -blockdev node-name=pflash1,driver=file,filename=<s-mode_fw_vars> \
> +     -M virt,pflash0=pflash0,pflash1=pflash1 \
> +     ... other args ....
> +
> +To boot as read-only S-mode payload in KVM guest:
> +
> +.. code-block:: bash
> +
> +  $ qemu-system-riscv64 \
> +     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<s-mode_fw_code> \
> +     -blockdev node-name=pflash1,driver=file,filename=<s-mode_fw_vars> \
> +     -M virt,pflash0=pflash0,pflash1=pflash1 \
> +     --enable-kvm \
> +     ... other args ....

I feel that this, while accurate, has gotten more complicated than it
needs to be. We're also putting the least common scenario front and
center instead of opening with the one that most people are going to
be using.

Below is how I suggest reworking it. What do you think?



Using flash devices
-------------------

By default, the first flash device (pflash0) is expected to contain
S-mode firmware code. It can be configured as read-only, with the
second flash device (pflash1) available to store configuration data.

For example, booting edk2 looks like

..code-block:: bash

  $ qemu-system-riscv64 \
     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<edk2_code> \
     -blockdev node-name=pflash1,driver=file,filename=<edk2_vars> \
     -M virt,pflash0=pflash0,pflash1=pflash1 \
     ... other args ....

For TCG guests only, it is also possible to boot M-mode firmware from
the first flash device (pflash0) by additionally passing ``-bios
none``, as in

..code-block:: bash

  $ qemu-system-riscv64 \
     -bios none \
     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<m_mode_code>
\
     -M virt,pflash0=pflash0 \
     ... other args ....

Firmware images used for pflash must be exactly 32 MiB in size.
Sunil V L May 31, 2023, 5:19 p.m. UTC | #2
On Wed, May 31, 2023 at 09:43:39AM -0700, Andrea Bolognani wrote:
> On Wed, May 31, 2023 at 07:53:00PM +0530, Sunil V L wrote:
> > +Using flash devices
> > +-------------------
> > +
> > +When KVM is not enabled, the first flash device (pflash0) can contain either
> > +the ROM code or S-mode payload firmware code. If the pflash0 contains the
> > +ROM code, -bios should be set to none. If -bios is not set to
> > +none, pflash0 is assumed to contain S-mode payload code.
> > +
> > +When KVM is enabled, pflash0 is always assumed to contain the S-mode payload
> > +firmware.
> > +
> > +Firmware images used for pflash should be of size 32 MiB.
> > +
> > +To boot as ROM code:
> > +
> > +.. code-block:: bash
> > +
> > +  $ qemu-system-riscv64 -bios none \
> > +     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<rom_code> \
> > +     -M virt,pflash0=pflash0 \
> > +     ... other args ....
> > +
> > +To boot as read-only S-mode payload:
> > +
> > +.. code-block:: bash
> > +
> > +  $ qemu-system-riscv64 \
> > +     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<s-mode_fw_code> \
> > +     -blockdev node-name=pflash1,driver=file,filename=<s-mode_fw_vars> \
> > +     -M virt,pflash0=pflash0,pflash1=pflash1 \
> > +     ... other args ....
> > +
> > +To boot as read-only S-mode payload in KVM guest:
> > +
> > +.. code-block:: bash
> > +
> > +  $ qemu-system-riscv64 \
> > +     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<s-mode_fw_code> \
> > +     -blockdev node-name=pflash1,driver=file,filename=<s-mode_fw_vars> \
> > +     -M virt,pflash0=pflash0,pflash1=pflash1 \
> > +     --enable-kvm \
> > +     ... other args ....
> 
> I feel that this, while accurate, has gotten more complicated than it
> needs to be. We're also putting the least common scenario front and
> center instead of opening with the one that most people are going to
> be using.
> 
> Below is how I suggest reworking it. What do you think?
> 
> 
> 
> Using flash devices
> -------------------
> 
> By default, the first flash device (pflash0) is expected to contain
> S-mode firmware code. It can be configured as read-only, with the
> second flash device (pflash1) available to store configuration data.
> 
> For example, booting edk2 looks like
> 
> ..code-block:: bash
> 
>   $ qemu-system-riscv64 \
>      -blockdev node-name=pflash0,driver=file,read-only=on,filename=<edk2_code> \
>      -blockdev node-name=pflash1,driver=file,filename=<edk2_vars> \
>      -M virt,pflash0=pflash0,pflash1=pflash1 \
>      ... other args ....
> 
> For TCG guests only, it is also possible to boot M-mode firmware from
> the first flash device (pflash0) by additionally passing ``-bios
> none``, as in
> 
> ..code-block:: bash
> 
>   $ qemu-system-riscv64 \
>      -bios none \
>      -blockdev node-name=pflash0,driver=file,read-only=on,filename=<m_mode_code>
> \
>      -M virt,pflash0=pflash0 \
>      ... other args ....
> 
> Firmware images used for pflash must be exactly 32 MiB in size.
> 
Hi Andrea,

This looks great! Thank you very much. Unless I see an objection, I will
use this text in the next revision of the series tomorrow.

Thanks!
Sunil
diff mbox series

Patch

diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst
index 4b16e41d7f..6c1d4fed3e 100644
--- a/docs/system/riscv/virt.rst
+++ b/docs/system/riscv/virt.rst
@@ -53,6 +53,49 @@  with the default OpenSBI firmware image as the -bios. It also supports
 the recommended RISC-V bootflow: U-Boot SPL (M-mode) loads OpenSBI fw_dynamic
 firmware and U-Boot proper (S-mode), using the standard -bios functionality.
 
+Using flash devices
+-------------------
+
+When KVM is not enabled, the first flash device (pflash0) can contain either
+the ROM code or S-mode payload firmware code. If the pflash0 contains the
+ROM code, -bios should be set to none. If -bios is not set to
+none, pflash0 is assumed to contain S-mode payload code.
+
+When KVM is enabled, pflash0 is always assumed to contain the S-mode payload
+firmware.
+
+Firmware images used for pflash should be of size 32 MiB.
+
+To boot as ROM code:
+
+.. code-block:: bash
+
+  $ qemu-system-riscv64 -bios none \
+     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<rom_code> \
+     -M virt,pflash0=pflash0 \
+     ... other args ....
+
+To boot as read-only S-mode payload:
+
+.. code-block:: bash
+
+  $ qemu-system-riscv64 \
+     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<s-mode_fw_code> \
+     -blockdev node-name=pflash1,driver=file,filename=<s-mode_fw_vars> \
+     -M virt,pflash0=pflash0,pflash1=pflash1 \
+     ... other args ....
+
+To boot as read-only S-mode payload in KVM guest:
+
+.. code-block:: bash
+
+  $ qemu-system-riscv64 \
+     -blockdev node-name=pflash0,driver=file,read-only=on,filename=<s-mode_fw_code> \
+     -blockdev node-name=pflash1,driver=file,filename=<s-mode_fw_vars> \
+     -M virt,pflash0=pflash0,pflash1=pflash1 \
+     --enable-kvm \
+     ... other args ....
+
 Machine-specific options
 ------------------------