]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/VariableAuthenticated/EsalVariableDxeSal/Variable.c
SecurityPkg: Clean up source files
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / EsalVariableDxeSal / Variable.c
index d6c66863512b58e0b65c865c541d3d91ab2a3443..b8a0af4b5cb2c9d088b724ffe581eb4c098cf121 100644 (file)
@@ -1,13 +1,13 @@
 /** @file\r
   The implementation of Extended SAL variable services.\r
 \r
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution.  The full text of the license may be found at \r
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
 \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
@@ -162,7 +162,7 @@ AccessVariableStore (
     if ((StartAddress + DataSize) > ((UINTN) ((UINT8 *) VolatileBase + VolatileBase->Size))) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-    \r
+\r
     //\r
     // For volatile variable, a simple memory copy is enough.\r
     //\r
@@ -181,13 +181,13 @@ AccessVariableStore (
   Status = (EFI_STATUS) EsalCall (\r
                           EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO,\r
                           EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI,\r
-                          GetPhysicalAddressFunctionId, \r
-                          Instance, \r
-                          (UINT64) &FvVolHdr, \r
-                          0, \r
-                          0, \r
-                          0, \r
-                          0, \r
+                          GetPhysicalAddressFunctionId,\r
+                          Instance,\r
+                          (UINT64) &FvVolHdr,\r
+                          0,\r
+                          0,\r
+                          0,\r
+                          0,\r
                           0\r
                           ).Status;\r
   ASSERT_EFI_ERROR (Status);\r
@@ -199,7 +199,7 @@ AccessVariableStore (
   if ((StartAddress + DataSize) > ((EFI_PHYSICAL_ADDRESS) (UINTN) ((CHAR8 *)VariableStoreHeader + VariableStoreHeader->Size))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   LinearOffset  = (UINTN) FwVolHeader;\r
   CurrWritePtr  = StartAddress;\r
   CurrWriteSize = DataSize;\r
@@ -227,26 +227,26 @@ AccessVariableStore (
             Status = (EFI_STATUS) EsalCall (\r
                                     EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO,\r
                                     EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI,\r
-                                    WriteFunctionId, \r
-                                    Instance, \r
-                                    LbaNumber, \r
-                                    (CurrWritePtr - LinearOffset), \r
-                                    (UINT64) &CurrWriteSize, \r
-                                    (UINT64) CurrBuffer, \r
-                                    0, \r
+                                    WriteFunctionId,\r
+                                    Instance,\r
+                                    LbaNumber,\r
+                                    (CurrWritePtr - LinearOffset),\r
+                                    (UINT64) &CurrWriteSize,\r
+                                    (UINT64) CurrBuffer,\r
+                                    0,\r
                                     0\r
                                     ).Status;\r
           } else {\r
             Status = (EFI_STATUS) EsalCall (\r
                                     EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO,\r
                                     EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI,\r
-                                    ReadFunctionId, \r
-                                    Instance, \r
-                                    LbaNumber, \r
-                                    (CurrWritePtr - LinearOffset), \r
-                                    (UINT64) &CurrWriteSize, \r
-                                    (UINT64) CurrBuffer, \r
-                                    0, \r
+                                    ReadFunctionId,\r
+                                    Instance,\r
+                                    LbaNumber,\r
+                                    (CurrWritePtr - LinearOffset),\r
+                                    (UINT64) &CurrWriteSize,\r
+                                    (UINT64) CurrBuffer,\r
+                                    0,\r
                                     0\r
                                     ).Status;\r
           }\r
@@ -260,26 +260,26 @@ AccessVariableStore (
             Status = (EFI_STATUS) EsalCall (\r
                                     EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO,\r
                                     EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI,\r
-                                    WriteFunctionId, \r
-                                    Instance, \r
-                                    LbaNumber, \r
-                                    (CurrWritePtr - LinearOffset), \r
-                                    (UINT64) &Size, \r
-                                    (UINT64) CurrBuffer, \r
-                                    0, \r
+                                    WriteFunctionId,\r
+                                    Instance,\r
+                                    LbaNumber,\r
+                                    (CurrWritePtr - LinearOffset),\r
+                                    (UINT64) &Size,\r
+                                    (UINT64) CurrBuffer,\r
+                                    0,\r
                                     0\r
                                     ).Status;\r
           } else {\r
             Status = (EFI_STATUS) EsalCall (\r
                                     EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO,\r
                                     EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI,\r
-                                    ReadFunctionId, \r
-                                    Instance, \r
-                                    LbaNumber, \r
-                                    (CurrWritePtr - LinearOffset), \r
-                                    (UINT64) &Size, \r
-                                    (UINT64) CurrBuffer, \r
-                                    0, \r
+                                    ReadFunctionId,\r
+                                    Instance,\r
+                                    LbaNumber,\r
+                                    (CurrWritePtr - LinearOffset),\r
+                                    (UINT64) &Size,\r
+                                    (UINT64) CurrBuffer,\r
+                                    0,\r
                                     0\r
                                     ).Status;\r
           }\r
@@ -332,7 +332,7 @@ GetVarStoreHeader (
              Instance,\r
              VarStoreAddress,\r
              sizeof (VARIABLE_STORE_HEADER),\r
-             VarStoreHeader    \r
+             VarStoreHeader\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
@@ -347,7 +347,7 @@ GetVarStoreHeader (
                                  FALSE - Variable is non-volatile.\r
   @param[in]  Global             Pointer to VARAIBLE_GLOBAL structure.\r
   @param[in]  Instance           Instance of FV Block services.\r
-  @param[out] VariableHeader     Pointer to VARIABLE_HEADER for output.\r
+  @param[out] VariableHeader     Pointer to AUTHENTICATED_VARIABLE_HEADER for output.\r
 \r
   @retval TRUE                   Variable header is valid.\r
   @retval FALSE                  Variable header is not valid.\r
@@ -355,15 +355,15 @@ GetVarStoreHeader (
 **/\r
 BOOLEAN\r
 IsValidVariableHeader (\r
-  IN  EFI_PHYSICAL_ADDRESS   VariableAddress,\r
-  IN  BOOLEAN                Volatile,\r
-  IN  VARIABLE_GLOBAL        *Global,\r
-  IN  UINTN                  Instance,\r
-  OUT VARIABLE_HEADER        *VariableHeader  OPTIONAL\r
+  IN  EFI_PHYSICAL_ADDRESS              VariableAddress,\r
+  IN  BOOLEAN                           Volatile,\r
+  IN  VARIABLE_GLOBAL                   *Global,\r
+  IN  UINTN                             Instance,\r
+  OUT AUTHENTICATED_VARIABLE_HEADER     *VariableHeader  OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  VARIABLE_HEADER       LocalVariableHeader;\r
+  EFI_STATUS                            Status;\r
+  AUTHENTICATED_VARIABLE_HEADER         LocalVariableHeader;\r
 \r
   Status = AccessVariableStore (\r
              FALSE,\r
@@ -371,8 +371,8 @@ IsValidVariableHeader (
              Volatile,\r
              Instance,\r
              VariableAddress,\r
-             sizeof (VARIABLE_HEADER),\r
-             &LocalVariableHeader    \r
+             sizeof (AUTHENTICATED_VARIABLE_HEADER),\r
+             &LocalVariableHeader\r
              );\r
 \r
   if (EFI_ERROR (Status) || LocalVariableHeader.StartId != VARIABLE_DATA) {\r
@@ -380,7 +380,7 @@ IsValidVariableHeader (
   }\r
 \r
   if (VariableHeader != NULL) {\r
-    CopyMem (VariableHeader, &LocalVariableHeader, sizeof (VARIABLE_HEADER));\r
+    CopyMem (VariableHeader, &LocalVariableHeader, sizeof (AUTHENTICATED_VARIABLE_HEADER));\r
   }\r
 \r
   return TRUE;\r
@@ -439,7 +439,7 @@ GetVariableStoreStatus (
 **/\r
 UINTN\r
 NameSizeOfVariable (\r
-  IN  VARIABLE_HEADER   *Variable\r
+  IN  AUTHENTICATED_VARIABLE_HEADER     *Variable\r
   )\r
 {\r
   if (Variable->State    == (UINT8) (-1) ||\r
@@ -465,7 +465,7 @@ NameSizeOfVariable (
 **/\r
 UINTN\r
 DataSizeOfVariable (\r
-  IN  VARIABLE_HEADER   *Variable\r
+  IN  AUTHENTICATED_VARIABLE_HEADER     *Variable\r
   )\r
 {\r
   if (Variable->State    == (UINT8)  -1 ||\r
@@ -500,10 +500,10 @@ GetVariableNamePtr (
   OUT CHAR16                 *VariableName\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  EFI_PHYSICAL_ADDRESS  Address;\r
-  VARIABLE_HEADER       VariableHeader;\r
-  BOOLEAN               IsValid;\r
+  EFI_STATUS                        Status;\r
+  EFI_PHYSICAL_ADDRESS              Address;\r
+  AUTHENTICATED_VARIABLE_HEADER     VariableHeader;\r
+  BOOLEAN                           IsValid;\r
 \r
   IsValid = IsValidVariableHeader (VariableAddress, Volatile, Global, Instance, &VariableHeader);\r
   ASSERT (IsValid);\r
@@ -511,7 +511,7 @@ GetVariableNamePtr (
   //\r
   // Name area follows variable header.\r
   //\r
-  Address = VariableAddress + sizeof (VARIABLE_HEADER);\r
+  Address = VariableAddress + sizeof (AUTHENTICATED_VARIABLE_HEADER);\r
 \r
   Status = AccessVariableStore (\r
              FALSE,\r
@@ -520,7 +520,7 @@ GetVariableNamePtr (
              Instance,\r
              Address,\r
              VariableHeader.NameSize,\r
-             VariableName    \r
+             VariableName\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
@@ -548,10 +548,10 @@ GetVariableDataPtr (
   OUT CHAR16                 *VariableData\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  EFI_PHYSICAL_ADDRESS  Address;\r
-  VARIABLE_HEADER       VariableHeader;\r
-  BOOLEAN               IsValid;\r
+  EFI_STATUS                        Status;\r
+  EFI_PHYSICAL_ADDRESS              Address;\r
+  AUTHENTICATED_VARIABLE_HEADER     VariableHeader;\r
+  BOOLEAN                           IsValid;\r
 \r
   IsValid = IsValidVariableHeader (VariableAddress, Volatile, Global, Instance, &VariableHeader);\r
   ASSERT (IsValid);\r
@@ -560,7 +560,7 @@ GetVariableDataPtr (
   // Data area follows variable name.\r
   // Be careful about pad size for alignment\r
   //\r
-  Address =  VariableAddress + sizeof (VARIABLE_HEADER);\r
+  Address =  VariableAddress + sizeof (AUTHENTICATED_VARIABLE_HEADER);\r
   Address += NameSizeOfVariable (&VariableHeader);\r
   Address += GET_PAD_SIZE (NameSizeOfVariable (&VariableHeader));\r
 \r
@@ -571,7 +571,7 @@ GetVariableDataPtr (
              Instance,\r
              Address,\r
              VariableHeader.DataSize,\r
-             VariableData    \r
+             VariableData\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
@@ -601,8 +601,8 @@ GetNextVariablePtr (
   IN  UINTN                  Instance\r
   )\r
 {\r
-  EFI_PHYSICAL_ADDRESS  Address;\r
-  VARIABLE_HEADER       VariableHeader;\r
+  EFI_PHYSICAL_ADDRESS              Address;\r
+  AUTHENTICATED_VARIABLE_HEADER     VariableHeader;\r
 \r
   if (!IsValidVariableHeader (VariableAddress, Volatile, Global, Instance, &VariableHeader)) {\r
     return 0x0;\r
@@ -611,7 +611,7 @@ GetNextVariablePtr (
   //\r
   // Header of next variable follows data area of this variable\r
   //\r
-  Address =  VariableAddress + sizeof (VARIABLE_HEADER);\r
+  Address =  VariableAddress + sizeof (AUTHENTICATED_VARIABLE_HEADER);\r
   Address += NameSizeOfVariable (&VariableHeader);\r
   Address += GET_PAD_SIZE (NameSizeOfVariable (&VariableHeader));\r
   Address += DataSizeOfVariable (&VariableHeader);\r
@@ -626,7 +626,7 @@ GetNextVariablePtr (
 /**\r
   Gets the pointer to the first variable header in given variable store area.\r
 \r
-  This function gets the pointer to the first variable header in given variable \r
+  This function gets the pointer to the first variable header in given variable\r
   store area. The variable store area is given by its start address.\r
 \r
   @param[in] VarStoreHeaderAddress  Pointer to the header of variable store area.\r
@@ -675,7 +675,7 @@ GetEndPointer (
              Instance,\r
              VarStoreHeaderAddress,\r
              sizeof (VARIABLE_STORE_HEADER),\r
-             &VariableStoreHeader    \r
+             &VariableStoreHeader\r
              );\r
 \r
   ASSERT_EFI_ERROR (Status);\r
@@ -685,12 +685,12 @@ GetEndPointer (
 /**\r
   Updates variable info entry in EFI system table for statistical information.\r
 \r
-  Routine used to track statistical information about variable usage. \r
+  Routine used to track statistical information about variable usage.\r
   The data is stored in the EFI system table so it can be accessed later.\r
-  VariableInfo.efi can dump out the table. Only Boot Services variable \r
+  VariableInfo.efi can dump out the table. Only Boot Services variable\r
   accesses are tracked by this code. The PcdVariableCollectStatistics\r
-  build flag controls if this feature is enabled. \r
-  A read that hits in the cache will have Read and Cache true for \r
+  build flag controls if this feature is enabled.\r
+  A read that hits in the cache will have Read and Cache true for\r
   the transaction. Data is allocated by this routine, but never\r
   freed.\r
 \r
@@ -736,13 +736,13 @@ UpdateVariableInfo (
       CopyGuid (&gVariableInfo->VendorGuid, VendorGuid);\r
       gVariableInfo->Name = AllocatePool (StrSize (VariableName));\r
       ASSERT (gVariableInfo->Name != NULL);\r
-      StrCpy (gVariableInfo->Name, VariableName);\r
+      StrCpyS (gVariableInfo->Name, StrSize (VariableName) / sizeof (CHAR16), VariableName);\r
       gVariableInfo->Volatile = Volatile;\r
 \r
       gBS->InstallConfigurationTable (&gEfiAuthenticatedVariableGuid, gVariableInfo);\r
     }\r
 \r
-    \r
+\r
     for (Entry = gVariableInfo; Entry != NULL; Entry = Entry->Next) {\r
       if (CompareGuid (VendorGuid, &Entry->VendorGuid)) {\r
         if (StrCmp (VariableName, Entry->Name) == 0) {\r
@@ -778,7 +778,7 @@ UpdateVariableInfo (
         CopyGuid (&Entry->Next->VendorGuid, VendorGuid);\r
         Entry->Next->Name = AllocatePool (StrSize (VariableName));\r
         ASSERT (Entry->Next->Name != NULL);\r
-        StrCpy (Entry->Next->Name, VariableName);\r
+        StrCpyS (Entry->Next->Name, StrSize (VariableName) / sizeof (CHAR16), VariableName);\r
         Entry->Next->Volatile = Volatile;\r
       }\r
 \r
@@ -826,7 +826,7 @@ UpdateVariableCache (
   //\r
   for (Index = 0, Entry = mVariableCache; Index < sizeof (mVariableCache)/sizeof (VARIABLE_CACHE_ENTRY); Index++, Entry++) {\r
     if (CompareGuid (VendorGuid, Entry->Guid)) {\r
-      if (StrCmp (VariableName, Entry->Name) == 0) { \r
+      if (StrCmp (VariableName, Entry->Name) == 0) {\r
         Entry->Attributes = Attributes;\r
         if (DataSize == 0) {\r
           //\r
@@ -846,6 +846,7 @@ UpdateVariableCache (
           // If size of data changes, allocate pool and copy data.\r
           //\r
           Entry->Data = AllocatePool (DataSize);\r
+          ASSERT (Entry->Data != NULL);\r
           Entry->DataSize = DataSize;\r
           CopyMem (Entry->Data, Data, DataSize);\r
         }\r
@@ -927,7 +928,7 @@ FindVariableInCache (
       }\r
     }\r
   }\r
-  \r
+\r
   return EFI_NOT_FOUND;\r
 }\r
 \r
@@ -963,14 +964,14 @@ FindVariable (
   IN  UINTN                   Instance\r
   )\r
 {\r
-  EFI_PHYSICAL_ADDRESS    Variable[2];\r
-  EFI_PHYSICAL_ADDRESS    InDeletedVariable;\r
-  EFI_PHYSICAL_ADDRESS    VariableStoreHeader[2];\r
-  UINTN                   InDeletedStorageIndex;\r
-  UINTN                   Index;\r
-  CHAR16                  LocalVariableName[MAX_NAME_SIZE];\r
-  BOOLEAN                 Volatile;\r
-  VARIABLE_HEADER         VariableHeader;\r
+  EFI_PHYSICAL_ADDRESS              Variable[2];\r
+  EFI_PHYSICAL_ADDRESS              InDeletedVariable;\r
+  EFI_PHYSICAL_ADDRESS              VariableStoreHeader[2];\r
+  UINTN                             InDeletedStorageIndex;\r
+  UINTN                             Index;\r
+  CHAR16                            LocalVariableName[MAX_NAME_SIZE];\r
+  BOOLEAN                           Volatile;\r
+  AUTHENTICATED_VARIABLE_HEADER     VariableHeader;\r
 \r
   //\r
   // 0: Volatile, 1: Non-Volatile\r
@@ -1002,7 +1003,7 @@ FindVariable (
       Volatile = FALSE;\r
     }\r
     while (IsValidVariableHeader (Variable[Index], Volatile, Global, Instance, &VariableHeader)) {\r
-      if (VariableHeader.State == VAR_ADDED || \r
+      if (VariableHeader.State == VAR_ADDED ||\r
           VariableHeader.State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)\r
          ) {\r
         if (!EfiAtRuntime () || ((VariableHeader.Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {\r
@@ -1119,24 +1120,24 @@ Reclaim (
   IN  EFI_PHYSICAL_ADDRESS  UpdatingVariable\r
   )\r
 {\r
-  EFI_PHYSICAL_ADDRESS  Variable;\r
-  EFI_PHYSICAL_ADDRESS  AddedVariable;\r
-  EFI_PHYSICAL_ADDRESS  NextVariable;\r
-  EFI_PHYSICAL_ADDRESS  NextAddedVariable;\r
-  VARIABLE_STORE_HEADER VariableStoreHeader;\r
-  VARIABLE_HEADER       VariableHeader;\r
-  VARIABLE_HEADER       AddedVariableHeader;\r
-  CHAR16                VariableName[MAX_NAME_SIZE];\r
-  CHAR16                AddedVariableName[MAX_NAME_SIZE];\r
-  UINT8                 *ValidBuffer;\r
-  UINTN                 MaximumBufferSize;\r
-  UINTN                 VariableSize;\r
-  UINTN                 NameSize;\r
-  UINT8                 *CurrPtr;\r
-  BOOLEAN               FoundAdded;\r
-  EFI_STATUS            Status;\r
-  VARIABLE_GLOBAL       *VariableGlobal;\r
-  UINT32                Instance;\r
+  EFI_PHYSICAL_ADDRESS              Variable;\r
+  EFI_PHYSICAL_ADDRESS              AddedVariable;\r
+  EFI_PHYSICAL_ADDRESS              NextVariable;\r
+  EFI_PHYSICAL_ADDRESS              NextAddedVariable;\r
+  VARIABLE_STORE_HEADER             VariableStoreHeader;\r
+  AUTHENTICATED_VARIABLE_HEADER     VariableHeader;\r
+  AUTHENTICATED_VARIABLE_HEADER     AddedVariableHeader;\r
+  CHAR16                            VariableName[MAX_NAME_SIZE];\r
+  CHAR16                            AddedVariableName[MAX_NAME_SIZE];\r
+  UINT8                             *ValidBuffer;\r
+  UINTN                             MaximumBufferSize;\r
+  UINTN                             VariableSize;\r
+  UINTN                             NameSize;\r
+  UINT8                             *CurrPtr;\r
+  BOOLEAN                           FoundAdded;\r
+  EFI_STATUS                        Status;\r
+  VARIABLE_GLOBAL                   *VariableGlobal;\r
+  UINT32                            Instance;\r
 \r
   VariableGlobal = &Global->VariableGlobal[VirtualMode];\r
   Instance = Global->FvbInstance;\r
@@ -1161,7 +1162,7 @@ Reclaim (
     //\r
     // Collect VAR_ADDED variables, and variables in delete transition status.\r
     //\r
-    if (VariableHeader.State == VAR_ADDED || \r
+    if (VariableHeader.State == VAR_ADDED ||\r
         VariableHeader.State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)\r
        ) {\r
       VariableSize = NextVariable - Variable;\r
@@ -1172,9 +1173,9 @@ Reclaim (
   }\r
 \r
   //\r
-  // Reserve the 1 Bytes with Oxff to identify the \r
-  // end of the variable buffer. \r
-  // \r
+  // Reserve the 1 Bytes with Oxff to identify the\r
+  // end of the variable buffer.\r
+  //\r
   MaximumBufferSize += 1;\r
   ValidBuffer = AllocatePool (MaximumBufferSize);\r
   if (ValidBuffer == NULL) {\r
@@ -1191,7 +1192,7 @@ Reclaim (
 \r
   //\r
   // Reinstall all ADDED variables\r
-  // \r
+  //\r
   Variable = GetStartPointer (VariableBase);\r
   while (IsValidVariableHeader (Variable, IsVolatile, VariableGlobal, Instance, &VariableHeader)) {\r
     NextVariable = GetNextVariablePtr (Variable, IsVolatile, VariableGlobal, Instance);\r
@@ -1199,9 +1200,9 @@ Reclaim (
       VariableSize = NextVariable - Variable;\r
       CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);\r
       CurrPtr += VariableSize;\r
-      if ((!IsVolatile) && ((((VARIABLE_HEADER*)Variable)->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
+      if ((!IsVolatile) && ((((AUTHENTICATED_VARIABLE_HEADER*)Variable)->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
         Global->HwErrVariableTotalSize += VariableSize;\r
-      } else if ((!IsVolatile) && ((((VARIABLE_HEADER*)Variable)->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
+      } else if ((!IsVolatile) && ((((AUTHENTICATED_VARIABLE_HEADER*)Variable)->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
         Global->CommonVariableTotalSize += VariableSize;\r
       }\r
     }\r
@@ -1209,17 +1210,17 @@ Reclaim (
   }\r
   //\r
   // Reinstall in delete transition variables\r
-  // \r
+  //\r
   Variable = GetStartPointer (VariableBase);\r
   while (IsValidVariableHeader (Variable, IsVolatile, VariableGlobal, Instance, &VariableHeader)) {\r
     NextVariable = GetNextVariablePtr (Variable, IsVolatile, VariableGlobal, Instance);\r
     if (VariableHeader.State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
 \r
       //\r
-      // Buffer has cached all ADDED variable. \r
+      // Buffer has cached all ADDED variable.\r
       // Per IN_DELETED variable, we have to guarantee that\r
-      // no ADDED one in previous buffer. \r
-      // \r
+      // no ADDED one in previous buffer.\r
+      //\r
       FoundAdded = FALSE;\r
       AddedVariable = GetStartPointer ((EFI_PHYSICAL_ADDRESS) ValidBuffer);\r
       while (IsValidVariableHeader (AddedVariable, IsVolatile, VariableGlobal, Instance, &AddedVariableHeader)) {\r
@@ -1253,12 +1254,12 @@ Reclaim (
           // 1. No valid instance of this variable exists.\r
           // 2. It is not the variable that is going to be updated.\r
           //\r
-          ((VARIABLE_HEADER *) CurrPtr)->State = VAR_ADDED;\r
+          ((AUTHENTICATED_VARIABLE_HEADER *) CurrPtr)->State = VAR_ADDED;\r
         }\r
         CurrPtr += VariableSize;\r
-        if ((!IsVolatile) && ((((VARIABLE_HEADER*)Variable)->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
+        if ((!IsVolatile) && ((((AUTHENTICATED_VARIABLE_HEADER*)Variable)->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
           Global->HwErrVariableTotalSize += VariableSize;\r
-        } else if ((!IsVolatile) && ((((VARIABLE_HEADER*)Variable)->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
+        } else if ((!IsVolatile) && ((((AUTHENTICATED_VARIABLE_HEADER*)Variable)->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
           Global->CommonVariableTotalSize += VariableSize;\r
         }\r
       }\r
@@ -1326,7 +1327,7 @@ GetIndexFromSupportedLangCodes(
   IN  CHAR8            *SupportedLang,\r
   IN  CHAR8            *Lang,\r
   IN  BOOLEAN          Iso639Language\r
-  ) \r
+  )\r
 {\r
   UINTN    Index;\r
   UINTN    CompareLength;\r
@@ -1361,8 +1362,8 @@ GetIndexFromSupportedLangCodes(
       // Determine the length of the next language code in SupportedLang\r
       //\r
       for (CompareLength = 0; SupportedLang[CompareLength] != '\0' && SupportedLang[CompareLength] != ';'; CompareLength++);\r
-      \r
-      if ((CompareLength == LanguageLength) && \r
+\r
+      if ((CompareLength == LanguageLength) &&\r
           (AsciiStrnCmp (Lang, SupportedLang, CompareLength) == 0)) {\r
         //\r
         // Successfully find the index of Lang string in SupportedLang string.\r
@@ -1464,10 +1465,10 @@ GetLangFromSupportedLangCodes (
 }\r
 \r
 /**\r
-  Returns a pointer to an allocated buffer that contains the best matching language \r
-  from a set of supported languages.  \r
-  \r
-  This function supports both ISO 639-2 and RFC 4646 language codes, but language \r
+  Returns a pointer to an allocated buffer that contains the best matching language\r
+  from a set of supported languages.\r
+\r
+  This function supports both ISO 639-2 and RFC 4646 language codes, but language\r
   code types may not be mixed in a single call to this function. This function\r
   supports a variable argument list that allows the caller to pass in a prioritized\r
   list of language codes to test against all the language codes in SupportedLanguages.\r
@@ -1475,37 +1476,37 @@ GetLangFromSupportedLangCodes (
   If SupportedLanguages is NULL, then ASSERT().\r
 \r
   @param[in]  SupportedLanguages  A pointer to a Null-terminated ASCII string that\r
-                                  contains a set of language codes in the format \r
+                                  contains a set of language codes in the format\r
                                   specified by Iso639Language.\r
   @param[in]  Iso639Language      If TRUE, then all language codes are assumed to be\r
                                   in ISO 639-2 format.  If FALSE, then all language\r
                                   codes are assumed to be in RFC 4646 language format.\r
   @param[in]  VirtualMode         Current calling mode for this function.\r
-  @param[in]  ...                 A variable argument list that contains pointers to \r
+  @param[in]  ...                 A variable argument list that contains pointers to\r
                                   Null-terminated ASCII strings that contain one or more\r
                                   language codes in the format specified by Iso639Language.\r
                                   The first language code from each of these language\r
                                   code lists is used to determine if it is an exact or\r
-                                  close match to any of the language codes in \r
+                                  close match to any of the language codes in\r
                                   SupportedLanguages.  Close matches only apply to RFC 4646\r
                                   language codes, and the matching algorithm from RFC 4647\r
-                                  is used to determine if a close match is present.  If \r
+                                  is used to determine if a close match is present.  If\r
                                   an exact or close match is found, then the matching\r
                                   language code from SupportedLanguages is returned.  If\r
                                   no matches are found, then the next variable argument\r
-                                  parameter is evaluated.  The variable argument list \r
+                                  parameter is evaluated.  The variable argument list\r
                                   is terminated by a NULL.\r
 \r
   @retval NULL   The best matching language could not be found in SupportedLanguages.\r
-  @retval NULL   There are not enough resources available to return the best matching \r
+  @retval NULL   There are not enough resources available to return the best matching\r
                  language.\r
-  @retval Other  A pointer to a Null-terminated ASCII string that is the best matching \r
+  @retval Other  A pointer to a Null-terminated ASCII string that is the best matching\r
                  language in SupportedLanguages.\r
 \r
 **/\r
 CHAR8 *\r
 VariableGetBestLanguage (\r
-  IN CONST CHAR8  *SupportedLanguages, \r
+  IN CONST CHAR8  *SupportedLanguages,\r
   IN BOOLEAN      Iso639Language,\r
   IN BOOLEAN      VirtualMode,\r
   ...\r
@@ -1581,7 +1582,7 @@ VariableGetBestLanguage (
         LanguageLength = 0;\r
       } else {\r
         //\r
-        // If RFC 4646 mode, then trim Language from the right to the next '-' character \r
+        // If RFC 4646 mode, then trim Language from the right to the next '-' character\r
         //\r
         for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] != '-'; LanguageLength--);\r
       }\r
@@ -1590,7 +1591,7 @@ VariableGetBestLanguage (
   VA_END (Args);\r
 \r
   //\r
-  // No matches were found \r
+  // No matches were found\r
   //\r
   return NULL;\r
 }\r
@@ -1660,10 +1661,10 @@ AutoUpdateLangVariable(
       FreePool (Global->PlatformLangCodes[VirtualMode]);\r
     }\r
     Global->PlatformLangCodes[VirtualMode] = AllocateRuntimeCopyPool (DataSize, Data);\r
-    ASSERT (mVariableModuleGlobal->PlatformLangCodes[VirtualMode] != NULL);\r
+    ASSERT (Global->PlatformLangCodes[VirtualMode] != NULL);\r
 \r
     //\r
-    // PlatformLang holds a single language from PlatformLangCodes, \r
+    // PlatformLang holds a single language from PlatformLangCodes,\r
     // so the size of PlatformLangCodes is enough for the PlatformLang.\r
     //\r
     if (Global->PlatformLang[VirtualMode] != NULL) {\r
@@ -1693,7 +1694,7 @@ AutoUpdateLangVariable(
     ASSERT (Global->LangCodes[VirtualMode] != NULL);\r
   }\r
 \r
-  if (SetLanguageCodes \r
+  if (SetLanguageCodes\r
       && (Global->PlatformLangCodes[VirtualMode] != NULL)\r
       && (Global->LangCodes[VirtualMode] != NULL)) {\r
     //\r
@@ -1728,10 +1729,10 @@ AutoUpdateLangVariable(
                VariableGlobal,\r
                Variable.Volatile,\r
                Instance,\r
-               (UINTN) &(((VARIABLE_HEADER *)Variable.CurrPtr)->DataSize),\r
+               (UINTN) &(((AUTHENTICATED_VARIABLE_HEADER *)Variable.CurrPtr)->DataSize),\r
                sizeof (DataSize),\r
                &DataSize\r
-               ); \r
+               );\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
@@ -1810,15 +1811,15 @@ AutoUpdateLangVariable(
         FindVariable (PredefinedVariableName[VAR_PLATFORM_LANG], Global->GlobalVariableGuid[VirtualMode], &Variable, VariableGlobal, Instance);\r
 \r
         Status = UpdateVariable (\r
-                   PredefinedVariableName[VAR_PLATFORM_LANG], \r
-                   Global->GlobalVariableGuid[VirtualMode], \r
-                   BestPlatformLang, \r
-                   AsciiStrSize (BestPlatformLang), \r
-                   Attributes, \r
+                   PredefinedVariableName[VAR_PLATFORM_LANG],\r
+                   Global->GlobalVariableGuid[VirtualMode],\r
+                   BestPlatformLang,\r
+                   AsciiStrSize (BestPlatformLang),\r
+                   Attributes,\r
                    0,\r
                    0,\r
-                   VirtualMode, \r
-                   Global, \r
+                   VirtualMode,\r
+                   Global,\r
                    &Variable\r
                    );\r
 \r
@@ -1830,7 +1831,7 @@ AutoUpdateLangVariable(
 }\r
 \r
 /**\r
-  Update the variable region with Variable information. These are the same \r
+  Update the variable region with Variable information. These are the same\r
   arguments as the EFI Variable services.\r
 \r
   @param[in] VariableName       Name of variable.\r
@@ -1839,7 +1840,7 @@ AutoUpdateLangVariable(
   @param[in] DataSize           Size of data. 0 means delete.\r
   @param[in] Attributes         Attributes of the variable.\r
   @param[in] KeyIndex           Index of associated public key.\r
-  @param[in] MonotonicCount     Value of associated monotonic count. \r
+  @param[in] MonotonicCount     Value of associated monotonic count.\r
   @param[in] VirtualMode        Current calling mode for this function.\r
   @param[in] Global             Context of this Extended SAL Variable Services Class call.\r
   @param[in] Variable           The variable information which is used to keep track of variable usage.\r
@@ -1855,7 +1856,7 @@ UpdateVariable (
   IN      EFI_GUID                *VendorGuid,\r
   IN      VOID                    *Data,\r
   IN      UINTN                   DataSize,\r
-  IN      UINT32                  Attributes OPTIONAL,  \r
+  IN      UINT32                  Attributes OPTIONAL,\r
   IN      UINT32                  KeyIndex  OPTIONAL,\r
   IN      UINT64                  MonotonicCount  OPTIONAL,\r
   IN      BOOLEAN                 VirtualMode,\r
@@ -1864,15 +1865,15 @@ UpdateVariable (
   )\r
 {\r
   EFI_STATUS                          Status;\r
-  VARIABLE_HEADER                     *NextVariable;\r
+  AUTHENTICATED_VARIABLE_HEADER       *NextVariable;\r
   UINTN                               VarNameOffset;\r
   UINTN                               VarDataOffset;\r
   UINTN                               VarNameSize;\r
   UINTN                               VarSize;\r
   BOOLEAN                             Volatile;\r
   UINT8                               State;\r
-  VARIABLE_HEADER                     VariableHeader;\r
-  VARIABLE_HEADER                     *NextVariableHeader;\r
+  AUTHENTICATED_VARIABLE_HEADER       VariableHeader;\r
+  AUTHENTICATED_VARIABLE_HEADER       *NextVariableHeader;\r
   BOOLEAN                             Valid;\r
   BOOLEAN                             Reclaimed;\r
   VARIABLE_STORE_HEADER               VariableStoreHeader;\r
@@ -1897,11 +1898,11 @@ UpdateVariable (
     // Update/Delete existing variable\r
     //\r
     Volatile = Variable->Volatile;\r
-    \r
-    if (EfiAtRuntime ()) {        \r
+\r
+    if (EfiAtRuntime ()) {\r
       //\r
-      // If EfiAtRuntime and the variable is Volatile and Runtime Access,  \r
-      // the volatile is ReadOnly, and SetVariable should be aborted and \r
+      // If EfiAtRuntime and the variable is Volatile and Runtime Access,\r
+      // the volatile is ReadOnly, and SetVariable should be aborted and\r
       // return EFI_WRITE_PROTECTED.\r
       //\r
       if (Variable->Volatile) {\r
@@ -1913,14 +1914,14 @@ UpdateVariable (
       //\r
       if ((VariableHeader.Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
         Status = EFI_INVALID_PARAMETER;\r
-        goto Done;      \r
+        goto Done;\r
       }\r
     }\r
     //\r
     // Setting a data variable with no access, or zero DataSize attributes\r
     // specified causes it to be deleted.\r
     //\r
-    if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {    \r
+    if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {\r
       State = VariableHeader.State;\r
       State &= VAR_DELETED;\r
 \r
@@ -1929,15 +1930,15 @@ UpdateVariable (
                  VariableGlobal,\r
                  Variable->Volatile,\r
                  Instance,\r
-                 (UINTN) &(((VARIABLE_HEADER *)Variable->CurrPtr)->State),\r
+                 (UINTN) &(((AUTHENTICATED_VARIABLE_HEADER *)Variable->CurrPtr)->State),\r
                  sizeof (UINT8),\r
                  &State\r
-                 ); \r
+                 );\r
       if (!EFI_ERROR (Status)) {\r
         UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, FALSE, TRUE, FALSE);\r
         UpdateVariableCache (VariableName, VendorGuid, Attributes, DataSize, Data);\r
       }\r
-      goto Done;     \r
+      goto Done;\r
     }\r
     //\r
     // Logic comes here to update variable.\r
@@ -1945,7 +1946,7 @@ UpdateVariable (
     // then return to the caller immediately.\r
     //\r
     if (DataSizeOfVariable (&VariableHeader) == DataSize) {\r
-      NextVariable = (VARIABLE_HEADER *)GetEndPointer (VariableGlobal->VolatileVariableBase, TRUE, VariableGlobal, Instance);\r
+      NextVariable = (AUTHENTICATED_VARIABLE_HEADER *)GetEndPointer (VariableGlobal->VolatileVariableBase, TRUE, VariableGlobal, Instance);\r
       GetVariableDataPtr (Variable->CurrPtr, Variable->Volatile, VariableGlobal, Instance, (CHAR16 *) NextVariable);\r
       if  (CompareMem (Data, (VOID *) NextVariable, DataSize) == 0) {\r
         UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TRUE, FALSE, FALSE);\r
@@ -1967,28 +1968,28 @@ UpdateVariable (
                  VariableGlobal,\r
                  Variable->Volatile,\r
                  Instance,\r
-                 (UINTN) &(((VARIABLE_HEADER *)Variable->CurrPtr)->State),\r
+                 (UINTN) &(((AUTHENTICATED_VARIABLE_HEADER *)Variable->CurrPtr)->State),\r
                  sizeof (UINT8),\r
                  &State\r
-                 );      \r
+                 );\r
       if (EFI_ERROR (Status)) {\r
-        goto Done;  \r
+        goto Done;\r
       }\r
-    }    \r
+    }\r
   } else {\r
     //\r
     // Create a new variable\r
-    //  \r
-    \r
+    //\r
+\r
     //\r
     // Make sure we are trying to create a new variable.\r
-    // Setting a data variable with no access, or zero DataSize attributes means to delete it.    \r
+    // Setting a data variable with no access, or zero DataSize attributes means to delete it.\r
     //\r
     if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {\r
       Status = EFI_NOT_FOUND;\r
       goto Done;\r
     }\r
-    \r
+\r
     //\r
     // Only variable have NV|RT attribute can be created in Runtime\r
     //\r
@@ -1996,7 +1997,7 @@ UpdateVariable (
         (((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) || ((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0))) {\r
       Status = EFI_INVALID_PARAMETER;\r
       goto Done;\r
-    }         \r
+    }\r
   }\r
 \r
   //\r
@@ -2006,9 +2007,9 @@ UpdateVariable (
   // Tricky part: Use scratch data area at the end of volatile variable store\r
   // as a temporary storage.\r
   //\r
-  NextVariable = (VARIABLE_HEADER *)GetEndPointer (VariableGlobal->VolatileVariableBase, TRUE, VariableGlobal, Instance);\r
+  NextVariable = (AUTHENTICATED_VARIABLE_HEADER *)GetEndPointer (VariableGlobal->VolatileVariableBase, TRUE, VariableGlobal, Instance);\r
   ScratchSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize));\r
-  NextVariableHeader = (VARIABLE_HEADER *) NextVariable;\r
+  NextVariableHeader = (AUTHENTICATED_VARIABLE_HEADER *) NextVariable;\r
 \r
   SetMem (NextVariableHeader, ScratchSize, 0xff);\r
 \r
@@ -2017,7 +2018,7 @@ UpdateVariable (
   NextVariableHeader->PubKeyIndex     = KeyIndex;\r
   NextVariableHeader->MonotonicCount  = MonotonicCount;\r
   NextVariableHeader->Reserved        = 0;\r
-  VarNameOffset                       = sizeof (VARIABLE_HEADER);\r
+  VarNameOffset                       = sizeof (AUTHENTICATED_VARIABLE_HEADER);\r
   VarNameSize                         = StrSize (VariableName);\r
   CopyMem (\r
     (UINT8 *) ((UINTN)NextVariable + VarNameOffset),\r
@@ -2049,11 +2050,11 @@ UpdateVariable (
     // Create a nonvolatile variable\r
     //\r
     Volatile = FALSE;\r
-    \r
+\r
     GetVarStoreHeader (VariableGlobal->NonVolatileVariableBase, FALSE, VariableGlobal, Instance, &VariableStoreHeader);\r
-    if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) \r
+    if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0)\r
              && ((HEADER_ALIGN (VarSize) + Global->HwErrVariableTotalSize) > PcdGet32(PcdHwErrStorageSize)))\r
-             || (((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == 0) \r
+             || (((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == 0)\r
              && ((HEADER_ALIGN (VarSize) + Global->CommonVariableTotalSize) > VariableStoreHeader.Size - sizeof (VARIABLE_STORE_HEADER) - PcdGet32(PcdHwErrStorageSize)))) {\r
       if (EfiAtRuntime ()) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
@@ -2071,9 +2072,9 @@ UpdateVariable (
       //\r
       // If still no enough space, return out of resources\r
       //\r
-      if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) \r
+      if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0)\r
                && ((HEADER_ALIGN (VarSize) + Global->HwErrVariableTotalSize) > PcdGet32(PcdHwErrStorageSize)))\r
-               || (((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == 0) \r
+               || (((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == 0)\r
                && ((HEADER_ALIGN (VarSize) + Global->CommonVariableTotalSize) > VariableStoreHeader.Size - sizeof (VARIABLE_STORE_HEADER) - PcdGet32(PcdHwErrStorageSize)))) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
         goto Done;\r
@@ -2082,7 +2083,7 @@ UpdateVariable (
     //\r
     // Four steps\r
     // 1. Write variable header\r
-    // 2. Set variable state to header valid  \r
+    // 2. Set variable state to header valid\r
     // 3. Write variable data\r
     // 4. Set variable state to valid\r
     //\r
@@ -2095,7 +2096,7 @@ UpdateVariable (
                FALSE,\r
                Instance,\r
                VariableGlobal->NonVolatileVariableBase + Global->NonVolatileLastVariableOffset,\r
-               sizeof (VARIABLE_HEADER),\r
+               sizeof (AUTHENTICATED_VARIABLE_HEADER),\r
                (UINT8 *) NextVariable\r
                );\r
 \r
@@ -2113,7 +2114,7 @@ UpdateVariable (
                FALSE,\r
                Instance,\r
                VariableGlobal->NonVolatileVariableBase + Global->NonVolatileLastVariableOffset,\r
-               sizeof (VARIABLE_HEADER),\r
+               sizeof (AUTHENTICATED_VARIABLE_HEADER),\r
                (UINT8 *) NextVariable\r
                );\r
 \r
@@ -2128,9 +2129,9 @@ UpdateVariable (
                VariableGlobal,\r
                FALSE,\r
                Instance,\r
-               VariableGlobal->NonVolatileVariableBase + Global->NonVolatileLastVariableOffset + sizeof (VARIABLE_HEADER),\r
-               (UINT32) VarSize - sizeof (VARIABLE_HEADER),\r
-               (UINT8 *) NextVariable + sizeof (VARIABLE_HEADER)\r
+               VariableGlobal->NonVolatileVariableBase + Global->NonVolatileLastVariableOffset + sizeof (AUTHENTICATED_VARIABLE_HEADER),\r
+               (UINT32) VarSize - sizeof (AUTHENTICATED_VARIABLE_HEADER),\r
+               (UINT8 *) NextVariable + sizeof (AUTHENTICATED_VARIABLE_HEADER)\r
                );\r
 \r
     if (EFI_ERROR (Status)) {\r
@@ -2146,7 +2147,7 @@ UpdateVariable (
                FALSE,\r
                Instance,\r
                VariableGlobal->NonVolatileVariableBase + Global->NonVolatileLastVariableOffset,\r
-               sizeof (VARIABLE_HEADER),\r
+               sizeof (AUTHENTICATED_VARIABLE_HEADER),\r
                (UINT8 *) NextVariable\r
                );\r
 \r
@@ -2164,7 +2165,7 @@ UpdateVariable (
   } else {\r
     //\r
     // Create a volatile variable\r
-    //      \r
+    //\r
     Volatile = TRUE;\r
 \r
     if ((UINT32) (HEADER_ALIGN(VarSize) + Global->VolatileLastVariableOffset) >\r
@@ -2211,7 +2212,7 @@ UpdateVariable (
   // has already been eliminated, so no need to delete it.\r
   //\r
   if (!Reclaimed && !EFI_ERROR (Status) && Variable->CurrPtr != 0) {\r
-    State = ((VARIABLE_HEADER *)Variable->CurrPtr)->State;\r
+    State = ((AUTHENTICATED_VARIABLE_HEADER *)Variable->CurrPtr)->State;\r
     State &= VAR_DELETED;\r
 \r
     Status = AccessVariableStore (\r
@@ -2219,7 +2220,7 @@ UpdateVariable (
                VariableGlobal,\r
                Variable->Volatile,\r
                Instance,\r
-               (UINTN) &(((VARIABLE_HEADER *)Variable->CurrPtr)->State),\r
+               (UINTN) &(((AUTHENTICATED_VARIABLE_HEADER *)Variable->CurrPtr)->State),\r
                sizeof (UINT8),\r
                &State\r
                );\r
@@ -2239,22 +2240,22 @@ Done:
 \r
   This function implements EsalGetVariable function of Extended SAL Variable Services Class.\r
   It is equivalent in functionality to the EFI Runtime Service GetVariable().\r
-  \r
+\r
   @param[in]      VariableName    A Null-terminated Unicode string that is the name of\r
                                   the vendor's variable.\r
   @param[in]      VendorGuid      A unique identifier for the vendor.\r
-  @param[out]     Attributes      If not NULL, a pointer to the memory location to return the \r
+  @param[out]     Attributes      If not NULL, a pointer to the memory location to return the\r
                                   attributes bitmask for the variable.\r
   @param[in, out] DataSize        Size of Data found. If size is less than the\r
                                   data, this value contains the required size.\r
-  @param[out]     Data            On input, the size in bytes of the return Data buffer.  \r
+  @param[out]     Data            On input, the size in bytes of the return Data buffer.\r
                                   On output, the size of data returned in Data.\r
   @param[in]      VirtualMode     Current calling mode for this function.\r
   @param[in]      Global          Context of this Extended SAL Variable Services Class call.\r
 \r
-  @retval EFI_SUCCESS            The function completed successfully. \r
+  @retval EFI_SUCCESS            The function completed successfully.\r
   @retval EFI_NOT_FOUND          The variable was not found.\r
-  @retval EFI_BUFFER_TOO_SMALL   DataSize is too small for the result.  DataSize has \r
+  @retval EFI_BUFFER_TOO_SMALL   DataSize is too small for the result.  DataSize has\r
                                  been updated with the size needed to complete the request.\r
   @retval EFI_INVALID_PARAMETER  VariableName is NULL.\r
   @retval EFI_INVALID_PARAMETER  VendorGuid is NULL.\r
@@ -2276,13 +2277,13 @@ EsalGetVariable (
   IN      ESAL_VARIABLE_GLOBAL  *Global\r
   )\r
 {\r
-  VARIABLE_POINTER_TRACK  Variable;\r
-  UINTN                   VarDataSize;\r
-  EFI_STATUS              Status;\r
-  VARIABLE_HEADER         VariableHeader;\r
-  BOOLEAN                 Valid;\r
-  VARIABLE_GLOBAL         *VariableGlobal;\r
-  UINT32                  Instance;\r
+  VARIABLE_POINTER_TRACK            Variable;\r
+  UINTN                             VarDataSize;\r
+  EFI_STATUS                        Status;\r
+  AUTHENTICATED_VARIABLE_HEADER     VariableHeader;\r
+  BOOLEAN                           Valid;\r
+  VARIABLE_GLOBAL                   *VariableGlobal;\r
+  UINT32                            Instance;\r
 \r
   if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2348,7 +2349,7 @@ EsalGetVariable (
     *DataSize = VarDataSize;\r
     UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, TRUE, FALSE, FALSE, FALSE);\r
     UpdateVariableCache (VariableName, VendorGuid, VariableHeader.Attributes, VarDataSize, Data);\r
\r
+\r
     Status = EFI_SUCCESS;\r
     goto Done;\r
   } else {\r
@@ -2370,18 +2371,18 @@ Done:
 \r
   This function implements EsalGetNextVariableName function of Extended SAL Variable Services Class.\r
   It is equivalent in functionality to the EFI Runtime Service GetNextVariableName().\r
-  \r
+\r
   @param[in, out] VariableNameSize Size of the variable\r
   @param[in, out] VariableName     On input, supplies the last VariableName that was returned by GetNextVariableName().\r
                                    On output, returns the Null-terminated Unicode string of the current variable.\r
   @param[in, out] VendorGuid       On input, supplies the last VendorGuid that was returned by GetNextVariableName().\r
-                                   On output, returns the VendorGuid of the current variable.  \r
+                                   On output, returns the VendorGuid of the current variable.\r
   @param[in]      VirtualMode      Current calling mode for this function.\r
   @param[in]      Global           Context of this Extended SAL Variable Services Class call.\r
 \r
-  @retval EFI_SUCCESS             The function completed successfully. \r
+  @retval EFI_SUCCESS             The function completed successfully.\r
   @retval EFI_NOT_FOUND           The next variable was not found.\r
-  @retval EFI_BUFFER_TOO_SMALL    VariableNameSize is too small for the result. \r
+  @retval EFI_BUFFER_TOO_SMALL    VariableNameSize is too small for the result.\r
                                   VariableNameSize has been updated with the size needed to complete the request.\r
   @retval EFI_INVALID_PARAMETER   VariableNameSize is NULL.\r
   @retval EFI_INVALID_PARAMETER   VariableName is NULL.\r
@@ -2399,12 +2400,12 @@ EsalGetNextVariableName (
   IN      ESAL_VARIABLE_GLOBAL  *Global\r
   )\r
 {\r
-  VARIABLE_POINTER_TRACK  Variable;\r
-  UINTN                   VarNameSize;\r
-  EFI_STATUS              Status;\r
-  VARIABLE_HEADER         VariableHeader;\r
-  VARIABLE_GLOBAL         *VariableGlobal;\r
-  UINT32                  Instance;\r
+  VARIABLE_POINTER_TRACK            Variable;\r
+  UINTN                             VarNameSize;\r
+  EFI_STATUS                        Status;\r
+  AUTHENTICATED_VARIABLE_HEADER     VariableHeader;\r
+  VARIABLE_GLOBAL                   *VariableGlobal;\r
+  UINT32                            Instance;\r
 \r
   if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2511,11 +2512,11 @@ Done:
 \r
   This function implements EsalSetVariable function of Extended SAL Variable Services Class.\r
   It is equivalent in functionality to the EFI Runtime Service SetVariable().\r
-  \r
+\r
   @param[in]  VariableName       A Null-terminated Unicode string that is the name of the vendor's\r
-                                 variable.  Each VariableName is unique for each \r
-                                 VendorGuid.  VariableName must contain 1 or more \r
-                                 Unicode characters.  If VariableName is an empty Unicode \r
+                                 variable.  Each VariableName is unique for each\r
+                                 VendorGuid.  VariableName must contain 1 or more\r
+                                 Unicode characters.  If VariableName is an empty Unicode\r
                                  string, then EFI_INVALID_PARAMETER is returned.\r
   @param[in]  VendorGuid         A unique identifier for the vendor.\r
   @param[in]  Attributes         Attributes bitmask to set for the variable.\r
@@ -2525,9 +2526,9 @@ Done:
   @param[in]  VirtualMode        Current calling mode for this function.\r
   @param[in]  Global             Context of this Extended SAL Variable Services Class call.\r
 \r
-  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as \r
+  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as\r
                                  defined by the Attributes.\r
-  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits was supplied, or the \r
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits was supplied, or the\r
                                  DataSize exceeds the maximum allowed.\r
   @retval EFI_INVALID_PARAMETER  VariableName is an empty Unicode string.\r
   @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.\r
@@ -2565,7 +2566,7 @@ EsalSetVariable (
   //\r
   if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
-  }  \r
+  }\r
 \r
   if (DataSize != 0 && Data == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2584,10 +2585,18 @@ EsalSetVariable (
       // Try to write Authencated Variable without AuthInfo\r
       //\r
       return EFI_SECURITY_VIOLATION;\r
-    } \r
-    PayloadSize = DataSize - AUTHINFO_SIZE; \r
+    }\r
+    PayloadSize = DataSize - AUTHINFO_SIZE;\r
   } else {\r
-    PayloadSize = DataSize; \r
+    PayloadSize = DataSize;\r
+  }\r
+\r
+\r
+  if ((UINTN)(~0) - PayloadSize < StrSize(VariableName)){\r
+    //\r
+    // Prevent whole variable size overflow\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   VariableGlobal = &Global->VariableGlobal[VirtualMode];\r
@@ -2598,8 +2607,7 @@ EsalSetVariable (
     // For variable for hardware error record, the size of the VariableName, including the Unicode Null\r
     // in bytes plus the DataSize is limited to maximum size of PcdGet32(PcdMaxHardwareErrorVariableSize) bytes.\r
     //\r
-    if ((PayloadSize > PcdGet32(PcdMaxHardwareErrorVariableSize)) ||                                                       \r
-        (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + PayloadSize > PcdGet32(PcdMaxHardwareErrorVariableSize))) {\r
+    if (StrSize (VariableName) + PayloadSize > PcdGet32(PcdMaxHardwareErrorVariableSize) - sizeof (AUTHENTICATED_VARIABLE_HEADER)) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
     //\r
@@ -2615,11 +2623,10 @@ EsalSetVariable (
     // For variable not for hardware error record, the size of the VariableName, including the\r
     // Unicode Null in bytes plus the DataSize is limited to maximum size of PcdGet32(PcdMaxVariableSize) bytes.\r
     //\r
-    if ((PayloadSize > PcdGet32(PcdMaxVariableSize)) ||\r
-        (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + PayloadSize > PcdGet32(PcdMaxVariableSize))) {\r
+    if (StrSize (VariableName) + PayloadSize > PcdGet32(PcdMaxVariableSize) - sizeof (AUTHENTICATED_VARIABLE_HEADER)) {\r
       return EFI_INVALID_PARAMETER;\r
-    }  \r
-  }  \r
+    }\r
+  }\r
 \r
   AcquireLockOnlyAtBootTime(&VariableGlobal->VariableServicesLock);\r
 \r
@@ -2669,31 +2676,31 @@ EsalSetVariable (
         // Cut the certificate size before set\r
         //\r
         Status = UpdateVariable (\r
-                   VariableName, \r
-                   VendorGuid, \r
-                   (UINT8*)Data + AUTHINFO_SIZE, \r
-                   DataSize - AUTHINFO_SIZE, \r
-                   Attributes, \r
-                   KeyIndex, \r
-                   MonotonicCount, \r
-                   VirtualMode, \r
-                   Global, \r
+                   VariableName,\r
+                   VendorGuid,\r
+                   (UINT8*)Data + AUTHINFO_SIZE,\r
+                   DataSize - AUTHINFO_SIZE,\r
+                   Attributes,\r
+                   KeyIndex,\r
+                   MonotonicCount,\r
+                   VirtualMode,\r
+                   Global,\r
                    &Variable\r
                    );\r
       } else {\r
         //\r
-        // Update variable as usual \r
+        // Update variable as usual\r
         //\r
         Status = UpdateVariable (\r
-                   VariableName, \r
-                   VendorGuid, \r
-                   Data, \r
-                   DataSize, \r
-                   Attributes, \r
-                   0, \r
-                   0, \r
-                   VirtualMode, \r
-                   Global, \r
+                   VariableName,\r
+                   VendorGuid,\r
+                   Data,\r
+                   DataSize,\r
+                   Attributes,\r
+                   0,\r
+                   0,\r
+                   VirtualMode,\r
+                   Global,\r
                    &Variable\r
                    );\r
       }\r
@@ -2713,19 +2720,19 @@ EsalSetVariable (
 \r
   @param[in]  Attributes                   Attributes bitmask to specify the type of variables\r
                                            on which to return information.\r
-  @param[out] MaximumVariableStorageSize   On output the maximum size of the storage space available for \r
-                                           the EFI variables associated with the attributes specified.  \r
-  @param[out] RemainingVariableStorageSize Returns the remaining size of the storage space available for EFI \r
+  @param[out] MaximumVariableStorageSize   On output the maximum size of the storage space available for\r
+                                           the EFI variables associated with the attributes specified.\r
+  @param[out] RemainingVariableStorageSize Returns the remaining size of the storage space available for EFI\r
                                            variables associated with the attributes specified.\r
-  @param[out] MaximumVariableSize          Returns the maximum size of an individual EFI variable \r
+  @param[out] MaximumVariableSize          Returns the maximum size of an individual EFI variable\r
                                            associated with the attributes specified.\r
   @param[in]  VirtualMode                  Current calling mode for this function\r
   @param[in]  Global                       Context of this Extended SAL Variable Services Class call\r
 \r
   @retval EFI_SUCCESS                      Valid answer returned.\r
   @retval EFI_INVALID_PARAMETER            An invalid combination of attribute bits was supplied.\r
-  @retval EFI_UNSUPPORTED                  The attribute is not supported on this platform, and the \r
-                                           MaximumVariableStorageSize, RemainingVariableStorageSize, \r
+  @retval EFI_UNSUPPORTED                  The attribute is not supported on this platform, and the\r
+                                           MaximumVariableStorageSize, RemainingVariableStorageSize,\r
                                            MaximumVariableSize are undefined.\r
 **/\r
 EFI_STATUS\r
@@ -2739,17 +2746,17 @@ EsalQueryVariableInfo (
   IN  ESAL_VARIABLE_GLOBAL   *Global\r
   )\r
 {\r
-  EFI_PHYSICAL_ADDRESS   Variable;\r
-  EFI_PHYSICAL_ADDRESS   NextVariable;\r
-  UINT64                 VariableSize;\r
-  EFI_PHYSICAL_ADDRESS   VariableStoreHeaderAddress;\r
-  BOOLEAN                Volatile;\r
-  VARIABLE_STORE_HEADER  VarStoreHeader;\r
-  VARIABLE_HEADER        VariableHeader;\r
-  UINT64                 CommonVariableTotalSize;\r
-  UINT64                 HwErrVariableTotalSize;\r
-  VARIABLE_GLOBAL        *VariableGlobal;\r
-  UINT32                 Instance;\r
+  EFI_PHYSICAL_ADDRESS              Variable;\r
+  EFI_PHYSICAL_ADDRESS              NextVariable;\r
+  UINT64                            VariableSize;\r
+  EFI_PHYSICAL_ADDRESS              VariableStoreHeaderAddress;\r
+  BOOLEAN                           Volatile;\r
+  VARIABLE_STORE_HEADER             VarStoreHeader;\r
+  AUTHENTICATED_VARIABLE_HEADER     VariableHeader;\r
+  UINT64                            CommonVariableTotalSize;\r
+  UINT64                            HwErrVariableTotalSize;\r
+  VARIABLE_GLOBAL                   *VariableGlobal;\r
+  UINT32                            Instance;\r
 \r
   CommonVariableTotalSize = 0;\r
   HwErrVariableTotalSize = 0;\r
@@ -2757,12 +2764,12 @@ EsalQueryVariableInfo (
   if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {\r
     //\r
     // Make sure the Attributes combination is supported by the platform.\r
     //\r
-    return EFI_UNSUPPORTED;  \r
+    return EFI_UNSUPPORTED;\r
   } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
     //\r
     // Make sure if runtime bit is set, boot service bit is set also.\r
@@ -2811,7 +2818,7 @@ EsalQueryVariableInfo (
   //\r
   if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
     *MaximumVariableStorageSize = PcdGet32(PcdHwErrStorageSize);\r
-    *MaximumVariableSize = PcdGet32(PcdMaxHardwareErrorVariableSize) - sizeof (VARIABLE_HEADER);\r
+    *MaximumVariableSize = PcdGet32(PcdMaxHardwareErrorVariableSize) - sizeof (AUTHENTICATED_VARIABLE_HEADER);\r
   } else {\r
     if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {\r
       ASSERT (PcdGet32(PcdHwErrStorageSize) < VarStoreHeader.Size);\r
@@ -2821,7 +2828,7 @@ EsalQueryVariableInfo (
     //\r
     // Let *MaximumVariableSize be PcdGet32(PcdMaxVariableSize) with the exception of the variable header size.\r
     //\r
-    *MaximumVariableSize = PcdGet32(PcdMaxVariableSize) - sizeof (VARIABLE_HEADER);\r
+    *MaximumVariableSize = PcdGet32(PcdMaxVariableSize) - sizeof (AUTHENTICATED_VARIABLE_HEADER);\r
   }\r
 \r
   //\r
@@ -2875,10 +2882,10 @@ EsalQueryVariableInfo (
     *RemainingVariableStorageSize = *MaximumVariableStorageSize - CommonVariableTotalSize;\r
   }\r
 \r
-  if (*RemainingVariableStorageSize < sizeof (VARIABLE_HEADER)) {\r
+  if (*RemainingVariableStorageSize < sizeof (AUTHENTICATED_VARIABLE_HEADER)) {\r
     *MaximumVariableSize = 0;\r
-  } else if ((*RemainingVariableStorageSize - sizeof (VARIABLE_HEADER)) < *MaximumVariableSize) {\r
-    *MaximumVariableSize = *RemainingVariableStorageSize - sizeof (VARIABLE_HEADER);\r
+  } else if ((*RemainingVariableStorageSize - sizeof (AUTHENTICATED_VARIABLE_HEADER)) < *MaximumVariableSize) {\r
+    *MaximumVariableSize = *RemainingVariableStorageSize - sizeof (AUTHENTICATED_VARIABLE_HEADER);\r
   }\r
 \r
   ReleaseLockOnlyAtBootTime (&VariableGlobal->VariableServicesLock);\r
@@ -2910,20 +2917,20 @@ ReclaimForOS(
   UINTN                           RemainingHwErrVariableSpace;\r
 \r
   VarSize = ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase))->Size;\r
-  Status  = EFI_SUCCESS; \r
+  Status  = EFI_SUCCESS;\r
   //\r
   //Allowable max size of common variable storage space\r
   //\r
   CommonVariableSpace = VarSize - sizeof (VARIABLE_STORE_HEADER) - PcdGet32(PcdHwErrStorageSize);\r
 \r
   RemainingCommonVariableSpace = CommonVariableSpace - mVariableModuleGlobal->CommonVariableTotalSize;\r
\r
+\r
   RemainingHwErrVariableSpace = PcdGet32 (PcdHwErrStorageSize) - mVariableModuleGlobal->HwErrVariableTotalSize;\r
   //\r
   // If the free area is below a threshold, then performs reclaim operation.\r
   //\r
   if ((RemainingCommonVariableSpace < PcdGet32 (PcdMaxVariableSize))\r
-    || ((PcdGet32 (PcdHwErrStorageSize) != 0) && \r
+    || ((PcdGet32 (PcdHwErrStorageSize) != 0) &&\r
        (RemainingHwErrVariableSpace < PcdGet32 (PcdMaxHardwareErrorVariableSize)))){\r
     Status = Reclaim (\r
                mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,\r
@@ -2937,6 +2944,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
+  AUTHENTICATED_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 = (AUTHENTICATED_VARIABLE_HEADER *) HEADER_ALIGN (VariableStoreHeader + 1)\r
+          ; (VariableHeader < (AUTHENTICATED_VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VariableStoreHeader + VariableStoreHeader->Size)\r
+            &&\r
+            (VariableHeader->StartId == VARIABLE_DATA))\r
+          ; VariableHeader = (AUTHENTICATED_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
@@ -2997,7 +3056,7 @@ VariableCommonInitialize (
   //\r
   // Note that in EdkII variable driver implementation, Hardware Error Record type variable\r
   // is stored with common variable in the same NV region. So the platform integrator should\r
-  // ensure that the value of PcdHwErrStorageSize is less than or equal to the value of \r
+  // ensure that the value of PcdHwErrStorageSize is less than or equal to the value of\r
   // PcdFlashNvStorageVariableSize.\r
   //\r
   ASSERT (PcdGet32(PcdHwErrStorageSize) <= PcdGet32 (PcdFlashNvStorageVariableSize));\r
@@ -3074,13 +3133,13 @@ VariableCommonInitialize (
     Status    = (EFI_STATUS) EsalCall (\r
                                EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO,\r
                                EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI,\r
-                               GetPhysicalAddressFunctionId, \r
-                               Instance, \r
-                               (UINT64) &FvVolHdr, \r
-                               0, \r
-                               0, \r
-                               0, \r
-                               0, \r
+                               GetPhysicalAddressFunctionId,\r
+                               Instance,\r
+                               (UINT64) &FvVolHdr,\r
+                               0,\r
+                               0,\r
+                               0,\r
+                               0,\r
                                0\r
                                ).Status;\r
     if (EFI_ERROR (Status)) {\r
@@ -3139,7 +3198,7 @@ VariableCommonInitialize (
                        Instance\r
                        );\r
       VariableSize = NextVariable - Variable;\r
-      if ((((VARIABLE_HEADER *)Variable)->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
+      if ((((AUTHENTICATED_VARIABLE_HEADER *)Variable)->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
         mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;\r
       } else {\r
         mVariableModuleGlobal->CommonVariableTotalSize += VariableSize;\r
@@ -3178,14 +3237,14 @@ VariableCommonInitialize (
     // Register the event handling function to reclaim variable for OS usage.\r
     //\r
     Status = EfiCreateEventReadyToBootEx (\r
-               TPL_NOTIFY, \r
-               ReclaimForOS, \r
-               NULL, \r
+               TPL_NOTIFY,\r
+               ReclaimForOS,\r
+               NULL,\r
                &ReadyToBootEvent\r
                );\r
   } else {\r
     Status = EFI_VOLUME_CORRUPTED;\r
-    DEBUG((EFI_D_INFO, "Variable Store header is corrupted\n"));\r
+    DEBUG((EFI_D_ERROR, "Variable Store header is corrupted\n"));\r
   }\r
 \r
 Done:\r