summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Mujawar <sami.mujawar@arm.com>2023-05-11 14:52:17 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-05-29 15:14:00 +0000
commit84d0b21d18db479236b6f8143eaa2e874e4efa99 (patch)
tree3c3484a210594ed8d4b6268c67663bdf635e0868
parent0e5aecfed12da337c766a152a47c35ac1ec35818 (diff)
downloadedk2-84d0b21d18db479236b6f8143eaa2e874e4efa99.tar.gz
edk2-84d0b21d18db479236b6f8143eaa2e874e4efa99.tar.bz2
edk2-84d0b21d18db479236b6f8143eaa2e874e4efa99.zip
ArmVirtPkg: Fallback to variable emulation if no CFI is found
The kvmtool option '--flash <flash filename>' is used to launch a guests VM with a CFI flash device that maps the flash file specified at the command line. However, kvmtool allows guest VMs to be launched without a CFI flash device. In such scenarios the firmware can utilize the emulated variable storage for UEFI variables. To support this the PCD gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable must be set to TRUE. Therefore, update the NorFlashKvmtoolLib to fallback to variable emulation if a CFI device is not detected. Also improve the error logging. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
-rw-r--r--ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c38
-rw-r--r--ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf3
2 files changed, 36 insertions, 5 deletions
diff --git a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c
index 43f5858644..2beeefdd27 100644
--- a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c
+++ b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c
@@ -1,7 +1,7 @@
/** @file
An instance of the NorFlashPlatformLib for Kvmtool platform.
- Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2020 - 2023, Arm Ltd. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -228,7 +228,7 @@ NorFlashPlatformLibConstructor (
CONST CHAR8 *Label;
UINT32 LabelLen;
- if (mNorFlashDeviceCount != 0) {
+ if ((mNorFlashDeviceCount != 0) || PcdGetBool (PcdEmuVariableNvModeEnable)) {
return EFI_SUCCESS;
}
@@ -337,9 +337,39 @@ NorFlashPlatformLibConstructor (
}
if (mNorFlashDevices[UefiVarStoreIndex].DeviceBaseAddress != 0) {
- return SetupVariableStore (&mNorFlashDevices[UefiVarStoreIndex]);
+ Status = SetupVariableStore (&mNorFlashDevices[UefiVarStoreIndex]);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: Failed to setup variable store, Status = %r\n",
+ Status
+ ));
+ ASSERT (0);
+ }
+ } else {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: Invalid Flash device Base address\n"
+ ));
+ ASSERT (0);
+ Status = EFI_NOT_FOUND;
+ }
+ } else {
+ // No Flash device found fallback to Runtime Variable Emulation.
+ DEBUG ((
+ DEBUG_INFO,
+ "INFO: No Flash device found fallback to Runtime Variable Emulation.\n"
+ ));
+ Status = PcdSetBoolS (PcdEmuVariableNvModeEnable, TRUE);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: Failed to set PcdEmuVariableNvModeEnable, Status = %r\n",
+ Status
+ ));
+ ASSERT (0);
}
}
- return EFI_NOT_FOUND;
+ return Status;
}
diff --git a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf
index b5f35d4782..fba1245e41 100644
--- a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf
+++ b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf
@@ -1,7 +1,7 @@
## @file
# Nor Flash library for Kvmtool.
#
-# Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
+# Copyright (c) 2020 - 2023, Arm Ltd. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
@@ -39,6 +39,7 @@
gArmTokenSpaceGuid.PcdFvBaseAddress
gArmTokenSpaceGuid.PcdFvSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase