]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
MdeModulePkg Variable: Introduce PcdReclaimVariableSpaceAtEndOfDxe
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / Variable.c
index 0cf367404f92646949cd9fad2a3436313b662052..b3c36992e36a181af3c831d60dcea6f4907c8dee 100644 (file)
@@ -55,6 +55,10 @@ BOOLEAN                mEndOfDxe              = FALSE;
 ///\r
 BOOLEAN                mEnableLocking         = TRUE;\r
 \r
+//\r
+// It will record the current boot error flag before EndOfDxe.\r
+//\r
+VAR_ERROR_FLAG         mCurrentBootVarErrFlag = VAR_ERROR_FLAG_NO_ERROR;\r
 \r
 /**\r
   Routine used to track statistical information about variable usage. \r
@@ -561,6 +565,17 @@ RecordVarErrorFlag (
     }\r
   );\r
 \r
+  if (!mEndOfDxe) {\r
+    //\r
+    // Before EndOfDxe, just record the current boot variable error flag to local variable,\r
+    // and leave the variable error flag in NV flash as the last boot variable error flag.\r
+    // After EndOfDxe in InitializeVarErrorFlag (), the variable error flag in NV flash\r
+    // will be initialized to this local current boot variable error flag.\r
+    //\r
+    mCurrentBootVarErrFlag &= Flag;\r
+    return;\r
+  }\r
+\r
   //\r
   // Record error flag (it should have be initialized).\r
   //\r
@@ -619,7 +634,7 @@ InitializeVarErrorFlag (
     return;\r
   }\r
 \r
-  Flag = VAR_ERROR_FLAG_NO_ERROR;\r
+  Flag = mCurrentBootVarErrFlag;\r
   DEBUG ((EFI_D_INFO, "Initialize variable error flag (%02x)\n", Flag));\r
 \r
   Status = FindVariable (\r
@@ -3109,6 +3124,15 @@ ReclaimForOS(
   EFI_STATUS                     Status;\r
   UINTN                          RemainingCommonRuntimeVariableSpace;\r
   UINTN                          RemainingHwErrVariableSpace;\r
+  STATIC BOOLEAN                 Reclaimed;\r
+\r
+  //\r
+  // This function will be called only once at EndOfDxe or ReadyToBoot event.\r
+  //\r
+  if (Reclaimed) {\r
+    return;\r
+  }\r
+  Reclaimed = TRUE;\r
 \r
   Status  = EFI_SUCCESS;\r
 \r