public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection
@ 2023-05-02  5:59 Gerd Hoffmann
  2023-05-25 15:53 ` Ard Biesheuvel
  0 siblings, 1 reply; 3+ messages in thread
From: Gerd Hoffmann @ 2023-05-02  5:59 UTC (permalink / raw)
  To: devel
  Cc: Pawel Polawski, Gerd Hoffmann, Jiewen Yao, Ard Biesheuvel,
	Oliver Steffen, Jordan Justen

Check whenever flash is actually writable.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
index 54f859de9ff9..a577aea55614 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
@@ -114,9 +114,17 @@ QemuFlashDetected (
       DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as RAM\n"));
       *Ptr = OriginalUint8;
     } else if (ProbeUint8 == CLEARED_ARRAY_STATUS) {
-      DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH\n"));
-      FlashDetected = TRUE;
-      *Ptr          = READ_ARRAY_CMD;
+      *Ptr       = WRITE_BYTE_CMD;
+      *Ptr       = OriginalUint8;
+      *Ptr       = READ_STATUS_CMD;
+      ProbeUint8 = *Ptr;
+      *Ptr       = READ_ARRAY_CMD;
+      if (ProbeUint8 & 0x10 /* programming error */) {
+        DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH, write-protected\n"));
+      } else {
+        DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH, writable\n"));
+        FlashDetected = TRUE;
+      }
     }
   }
 
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection
  2023-05-02  5:59 [PATCH 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection Gerd Hoffmann
@ 2023-05-25 15:53 ` Ard Biesheuvel
  2023-05-31  6:40   ` Gerd Hoffmann
  0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2023-05-25 15:53 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: devel, Pawel Polawski, Jiewen Yao, Ard Biesheuvel, Oliver Steffen,
	Jordan Justen

On Tue, 2 May 2023 at 07:59, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> Check whenever flash is actually writable.
>

This is a bit too terse. Could you explain why this is needed, and why
this approach is suitable?

> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
> index 54f859de9ff9..a577aea55614 100644
> --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
> +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
> @@ -114,9 +114,17 @@ QemuFlashDetected (
>        DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as RAM\n"));
>        *Ptr = OriginalUint8;
>      } else if (ProbeUint8 == CLEARED_ARRAY_STATUS) {
> -      DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH\n"));
> -      FlashDetected = TRUE;
> -      *Ptr          = READ_ARRAY_CMD;
> +      *Ptr       = WRITE_BYTE_CMD;
> +      *Ptr       = OriginalUint8;
> +      *Ptr       = READ_STATUS_CMD;
> +      ProbeUint8 = *Ptr;
> +      *Ptr       = READ_ARRAY_CMD;
> +      if (ProbeUint8 & 0x10 /* programming error */) {
> +        DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH, write-protected\n"));
> +      } else {
> +        DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH, writable\n"));
> +        FlashDetected = TRUE;
> +      }
>      }
>    }
>
> --
> 2.40.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection
  2023-05-25 15:53 ` Ard Biesheuvel
@ 2023-05-31  6:40   ` Gerd Hoffmann
  0 siblings, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2023-05-31  6:40 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: devel, Pawel Polawski, Jiewen Yao, Ard Biesheuvel, Oliver Steffen,
	Jordan Justen

On Thu, May 25, 2023 at 05:53:27PM +0200, Ard Biesheuvel wrote:
> On Tue, 2 May 2023 at 07:59, Gerd Hoffmann <kraxel@redhat.com> wrote:
> >
> > Check whenever flash is actually writable.
> >
> 
> This is a bit too terse. Could you explain why this is needed, and why
> this approach is suitable?

Flash can be write-protected in qemu (which is usually the case for
code).  In case the variable store flash block is configured read-only
ovmf wouldn't be able to store EFI variables there, so not setting up
fvb in that case (and fallhack to emulation) is the better option.
It'll avoid problems later due to flash writes failing.

The patch tries to write back the original value read earlier, so flash
content doesn't change in case the write succeeds.  But the status we
read back after the attempt to write will tell us whenever flash is
writable or not.

take care,
  Gerd


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-31  6:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-02  5:59 [PATCH 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection Gerd Hoffmann
2023-05-25 15:53 ` Ard Biesheuvel
2023-05-31  6:40   ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox