]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OVMF: Add support for saving the NV variables to disk following each SetVariable...
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 26 Sep 2009 07:15:55 +0000 (07:15 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 26 Sep 2009 07:15:55 +0000 (07:15 +0000)
Note:
* This only works before ExitBootServices
* For OVMF, variables are only preserved on the disk if there
  is a hard disk connected which has a writeable FAT file system.

The Ovmf/Library/EmuVariableFvbLib library will look for the
gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent PCD to be set to
a non-zero value.  If set, it is treated as an event handle, and
each write to the EmuVariableFvb will cause the event to be
signaled.

In this change, the OVMF platform BDS library sets up this event,
and sets the PCD so that after each write to the EMU Variable FVB,
the non-volatile variables will be saved out to the file system.

The end result is that NV variables that are written prior to the
ExitBootServices call should be preserved by storing them on the
disk.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9318 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/Include/Library/NvVarsFileLib.h
OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c
OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c
OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf

index 63b1642f541dd2d0b139894b29a5ac3c119a9920..1a14b3fe9cb1be6eafc846a8723015bab5d62270 100644 (file)
@@ -31,5 +31,21 @@ ConnectNvVarsToFileSystem (
   IN EFI_HANDLE    FsHandle\r
   );\r
 \r
+\r
+/**\r
+  Update non-volatile variables stored on the file system.\r
+\r
+  @return     The EFI_STATUS while attempting to update the variable on\r
+              the connected file system.\r
+  @retval     EFI_SUCCESS - The non-volatile variables were saved to the disk\r
+  @retval     EFI_NOT_STARTED - A file system has not been connected\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UpdateNvVarsOnFileSystem (\r
+  );\r
+\r
+\r
 #endif\r
 \r
index 94e00e0bdb8eb5acdf485f300e60502b7a05a1ed..62fee6f03136eddf55135a359942311f6ca8ddc5 100644 (file)
@@ -16,6 +16,8 @@
 #include <Library/DebugLib.h>
 #include <Library/NvVarsFileLib.h>
 
+EFI_HANDLE    mNvVarsFileLibFsHandle = NULL;
+
 
 /**
   Attempts to connect the NvVarsFileLib to the specified file system.
@@ -46,8 +48,36 @@ ConnectNvVarsToFileSystem (
   // to have connected successfully.
   //
   Status = SaveNvVarsToFs (FsHandle);
+  if (!EFI_ERROR (Status)) {
+    mNvVarsFileLibFsHandle = FsHandle;
+  }
 
   return Status;
 }
 
 
+/**
+  Update non-volatile variables stored on the file system.
+
+  @return     The EFI_STATUS while attempting to update the variable on
+              the connected file system.
+  @retval     EFI_SUCCESS - The non-volatile variables were saved to the disk
+  @retval     EFI_NOT_STARTED - A file system has not been connected
+
+**/
+EFI_STATUS
+EFIAPI
+UpdateNvVarsOnFileSystem (
+  )
+{
+  if (mNvVarsFileLibFsHandle == NULL) {
+    //
+    // A file system had not been connected to the library.
+    //
+    return EFI_NOT_STARTED;
+  } else {
+    return SaveNvVarsToFs (mNvVarsFileLibFsHandle);
+  }
+}
+
+
index e4d1d4acbd9df5d162beb46133f76cf8a0faa4c2..f3781b4b55b3af68f91c0f08ac73971ac9c55294 100644 (file)
@@ -21,6 +21,8 @@
 \r
 VOID          *mEfiDevPathNotifyReg;\r
 EFI_EVENT     mEfiDevPathEvent;\r
+VOID          *mEmuVariableEventReg;\r
+EFI_EVENT     mEmuVariableEvent;\r
 BOOLEAN       mDetectVgaOnly;\r
 \r
 \r
@@ -815,6 +817,26 @@ ConnectRecursivelyIfPciMassStorage (
 }\r
 \r
 \r
+/**\r
+  This notification function is invoked when the\r
+  EMU Variable FVB has been changed.\r
+\r
+  @param  Event                 The event that occured\r
+  @param  Context               For EFI compatiblity.  Not used.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EmuVariablesUpdatedCallback (\r
+  IN  EFI_EVENT Event,\r
+  IN  VOID      *Context\r
+  )\r
+{\r
+  DEBUG ((EFI_D_INFO, "EmuVariablesUpdatedCallback\n"));\r
+  UpdateNvVarsOnFileSystem ();\r
+}\r
+\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 VisitingFileSystemInstance (\r
@@ -836,6 +858,16 @@ VisitingFileSystemInstance (
   }\r
 \r
   ConnectedToFileSystem = TRUE;\r
+  mEmuVariableEvent =\r
+    EfiCreateProtocolNotifyEvent (\r
+      &gEfiDevicePathProtocolGuid,\r
+      TPL_CALLBACK,\r
+      EmuVariablesUpdatedCallback,\r
+      NULL,\r
+      &mEmuVariableEventReg\r
+      );\r
+  PcdSet64 (PcdEmuVariableEvent, (UINT64)(UINTN) mEmuVariableEvent);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
index f8b64473bd40760da6f03d964200c6143f9ca63c..7d856f31777a32fa257f52ec60a6eacb10b39ad3 100644 (file)
   PciLib\r
   NvVarsFileLib\r
 \r
-[Pcd.common]\r
+[Pcd]\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPlatformBootTimeOut\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent\r
 \r
 [Pcd.IA32, Pcd.X64]\r
   gEfiMdePkgTokenSpaceGuid.PcdFSBClock\r