From 28c16cd9b76faadda2f33f9aa7395d74ff810021 Mon Sep 17 00:00:00 2001 From: jljusten Date: Mon, 7 Sep 2009 20:18:17 +0000 Subject: [PATCH] OVMF: Add support for more persistent NV variables which can survive a system reboot. Make use of EMU Variable driver's PcdEmuVariableNvStoreReserved to allow NV variables to persist a VM system reset. The contents of the NV variables will still be lost when the VM is shut down, but they appear to persist when the efi shell reset command is run. (Tested with QEMU 0.10.0.) git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9241 6f19259b-4bc3-4df7-8a09-765794883524 MU SOURCE COMMIT:77ba993c886a79b6199e941f4ddb7861ed3a211e --- Platforms/OvmfPkg/OvmfPkgIa32.dsc | 9 ++++-- Platforms/OvmfPkg/OvmfPkgIa32X64.dsc | 9 ++++-- Platforms/OvmfPkg/OvmfPkgX64.dsc | 11 +++++--- Platforms/OvmfPkg/PlatformPei/Platform.c | 28 +++++++++++++++++++ Platforms/OvmfPkg/PlatformPei/PlatformPei.inf | 2 +- 5 files changed, 50 insertions(+), 9 deletions(-) diff --git a/Platforms/OvmfPkg/OvmfPkgIa32.dsc b/Platforms/OvmfPkg/OvmfPkgIa32.dsc index 69bfd679..84e2b490 100644 --- a/Platforms/OvmfPkg/OvmfPkgIa32.dsc +++ b/Platforms/OvmfPkg/OvmfPkgIa32.dsc @@ -205,7 +205,8 @@ # ################################################################################ -[PcdsDynamicDefault.common.DEFAULT] +[PcdsDynamicDefault.common] + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0 ################################################################################ # @@ -231,7 +232,11 @@ NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf } - OvmfPkg/PlatformPei/PlatformPei.inf + + OvmfPkg/PlatformPei/PlatformPei.inf { + + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + } # # DXE Phase modules diff --git a/Platforms/OvmfPkg/OvmfPkgIa32X64.dsc b/Platforms/OvmfPkg/OvmfPkgIa32X64.dsc index a1ce53d0..66166183 100644 --- a/Platforms/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/Platforms/OvmfPkg/OvmfPkgIa32X64.dsc @@ -206,7 +206,8 @@ # ################################################################################ -[PcdsDynamicDefault.common.DEFAULT] +[PcdsDynamicDefault.common] + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0 ################################################################################ # @@ -232,7 +233,11 @@ NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf } - OvmfPkg/PlatformPei/PlatformPei.inf + + OvmfPkg/PlatformPei/PlatformPei.inf { + + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + } [Components.X64] # diff --git a/Platforms/OvmfPkg/OvmfPkgX64.dsc b/Platforms/OvmfPkg/OvmfPkgX64.dsc index 003cc75a..458f0ebf 100644 --- a/Platforms/OvmfPkg/OvmfPkgX64.dsc +++ b/Platforms/OvmfPkg/OvmfPkgX64.dsc @@ -57,8 +57,6 @@ UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf - S3Lib|MdeModulePkg/Library/PeiS3LibNull/PeiS3LibNull.inf - RecoveryLib|MdeModulePkg/Library/PeiRecoveryLibNull/PeiRecoveryLibNull.inf GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf @@ -208,7 +206,8 @@ # ################################################################################ -[PcdsDynamicDefault.common.DEFAULT] +[PcdsDynamicDefault.common] + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0 ################################################################################ # @@ -234,7 +233,11 @@ NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf } - OvmfPkg/PlatformPei/PlatformPei.inf + + OvmfPkg/PlatformPei/PlatformPei.inf { + + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + } # # DXE Phase modules diff --git a/Platforms/OvmfPkg/PlatformPei/Platform.c b/Platforms/OvmfPkg/PlatformPei/Platform.c index b6cf667a..9055fa53 100644 --- a/Platforms/OvmfPkg/PlatformPei/Platform.c +++ b/Platforms/OvmfPkg/PlatformPei/Platform.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -156,6 +158,30 @@ MiscInitialization ( } +VOID +ReserveEmuVariableNvStore ( + ) +{ + EFI_PHYSICAL_ADDRESS VariableStore; + + // + // Allocate storage for NV variables early on so it will be + // at a consistent address. Since VM memory is preserved + // across reboots, this allows the NV variable storage to survive + // a VM reboot. + // + VariableStore = + (EFI_PHYSICAL_ADDRESS)(UINTN) + AllocateRuntimePool (FixedPcdGet32(PcdVariableStoreSize)); + DEBUG ((EFI_D_INFO, + "Reserved variable store memory: 0x%lX; size: %dkb\n", + VariableStore, + FixedPcdGet32(PcdVariableStoreSize) / 1024 + )); + PcdSet64 (PcdEmuVariableNvStoreReserved, VariableStore); +} + + /** Perform Platform PEI initialization. @@ -176,6 +202,8 @@ InitializePlatform ( MemDetect (); + ReserveEmuVariableNvStore (); + PeiFvInitialization (); MemMapInitialization (); diff --git a/Platforms/OvmfPkg/PlatformPei/PlatformPei.inf b/Platforms/OvmfPkg/PlatformPei/PlatformPei.inf index 40e95477..990b2b83 100644 --- a/Platforms/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/Platforms/OvmfPkg/PlatformPei/PlatformPei.inf @@ -63,7 +63,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize [Pcd.common] - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved [Depex] TRUE