Change IPF version AuthVariable driver to support multiple-platform feature.
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / EsalVariableDxeSal / Variable.c
index 2be925d2366ad84b976f2d62aebf3606aaee288d..d0269c9da744d9e8112c99d2f1ee131592bdbc3b 100644 (file)
@@ -2938,6 +2938,58 @@ ReclaimForOS(
   }\r
 }\r
 \r
+/**\r
+  Flush the HOB variable to NV variable storage.\r
+**/\r
+VOID\r
+FlushHob2Nv (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  VOID                            *GuidHob;\r
+  VARIABLE_STORE_HEADER           *VariableStoreHeader;\r
+  VARIABLE_HEADER                 *VariableHeader;\r
+  //\r
+  // Get HOB variable store.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);\r
+  if (GuidHob != NULL) {\r
+    VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
+    if (CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid) &&\r
+        (VariableStoreHeader->Format == VARIABLE_STORE_FORMATTED) &&\r
+        (VariableStoreHeader->State == VARIABLE_STORE_HEALTHY)\r
+       ) {\r
+      DEBUG ((EFI_D_INFO, "HOB Variable Store appears to be valid.\n"));\r
+      //\r
+      // Flush the HOB variable to NV Variable storage.\r
+      //\r
+      for ( VariableHeader = (VARIABLE_HEADER *) HEADER_ALIGN (VariableStoreHeader + 1)\r
+          ; (VariableHeader < (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VariableStoreHeader + VariableStoreHeader->Size)\r
+            &&\r
+            (VariableHeader->StartId == VARIABLE_DATA))\r
+          ; VariableHeader = (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) (VariableHeader + 1)\r
+                           + VariableHeader->NameSize + GET_PAD_SIZE (VariableHeader->NameSize)\r
+                           + VariableHeader->DataSize + GET_PAD_SIZE (VariableHeader->DataSize)\r
+                           )\r
+          ) {\r
+        ASSERT (VariableHeader->State == VAR_ADDED);\r
+        ASSERT ((VariableHeader->Attributes & EFI_VARIABLE_NON_VOLATILE) != 0);\r
+        Status = EsalSetVariable (\r
+                   (CHAR16 *) (VariableHeader + 1),\r
+                   &VariableHeader->VendorGuid,\r
+                   VariableHeader->Attributes,\r
+                   VariableHeader->DataSize,\r
+                   (UINT8 *) (VariableHeader + 1) + VariableHeader->NameSize + GET_PAD_SIZE (VariableHeader->NameSize),\r
+                   Physical,\r
+                   mVariableModuleGlobal\r
+                   );\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
 /**\r
   Initializes variable store area for non-volatile and volatile variable.\r
 \r