summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/QemuFlashFvbServicesRuntimeDxe
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2023-06-01 08:08:03 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-06-01 09:00:00 +0000
commit578a715cfc6abc08ead8f585f096789374254b2a (patch)
tree9ecb31684b639121e75786fd76f8d7aff77af709 /OvmfPkg/QemuFlashFvbServicesRuntimeDxe
parent4e5a804222415ec7b2bec90ea0300b8a9f60f131 (diff)
downloadedk2-578a715cfc6abc08ead8f585f096789374254b2a.tar.gz
edk2-578a715cfc6abc08ead8f585f096789374254b2a.tar.bz2
edk2-578a715cfc6abc08ead8f585f096789374254b2a.zip
OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection
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. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'OvmfPkg/QemuFlashFvbServicesRuntimeDxe')
-rw-r--r--OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
index 54f859de9f..a577aea556 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;
+ }
}
}