]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/Pei/Variable.c
MdeModulePkg Variable: Fix comment typo 'end' to 'start'
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / Pei / Variable.c
index c68a41ddfe7dcb57b8479d54241774c8ad49af6d..77b3eaeb210ddfcf91e249d6ce1304f0638098be 100644 (file)
@@ -2,7 +2,7 @@
   Implement ReadOnly Variable Services required by PEIM and install\r
   PEI ReadOnly Varaiable2 PPI. These services operates the non volatile storage space.\r
 \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 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
@@ -57,7 +57,7 @@ PeimInitializeVariableServices (
 \r
   @param VarStoreHeader  Pointer to the Variable Store Header.\r
 \r
-  @return Pointer to the first variable header\r
+  @return Pointer to the first variable header.\r
 \r
 **/\r
 VARIABLE_HEADER *\r
@@ -66,18 +66,22 @@ GetStartPointer (
   )\r
 {\r
   //\r
-  // The end of variable store\r
+  // The start of variable store\r
   //\r
   return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);\r
 }\r
 \r
 \r
 /**\r
-  This code gets the pointer to the last variable memory pointer byte.\r
 \r
-  @param  VarStoreHeader  Pointer to the Variable Store Header.\r
+  Gets the pointer to the end of the variable storage area.\r
+\r
+  This function gets pointer to the end of the variable storage\r
+  area, according to the input variable store header.\r
+\r
+  @param VarStoreHeader  Pointer to the Variable Store Header.\r
 \r
-  @return VARIABLE_HEADER* pointer to last unavailable Variable Header.\r
+  @return Pointer to the end of the variable storage area.\r
 \r
 **/\r
 VARIABLE_HEADER *\r
@@ -495,6 +499,58 @@ CompareWithValidVariable (
   return EFI_NOT_FOUND;\r
 }\r
 \r
+/**\r
+  Get HOB variable store.\r
+\r
+  @param[out] StoreInfo             Return the store info.\r
+  @param[out] VariableStoreHeader   Return variable store header.\r
+\r
+**/\r
+VOID\r
+GetHobVariableStore (\r
+  OUT VARIABLE_STORE_INFO        *StoreInfo,\r
+  OUT VARIABLE_STORE_HEADER      **VariableStoreHeader\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE              *GuidHob;\r
+\r
+  //\r
+  // Make sure there is no more than one Variable HOB.\r
+  //\r
+  DEBUG_CODE (\r
+    GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);\r
+    if (GuidHob != NULL) {\r
+      if ((GetNextGuidHob (&gEfiAuthenticatedVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {\r
+        DEBUG ((DEBUG_ERROR, "ERROR: Found two Auth Variable HOBs\n"));\r
+        ASSERT (FALSE);\r
+      } else if (GetFirstGuidHob (&gEfiVariableGuid) != NULL) {\r
+        DEBUG ((DEBUG_ERROR, "ERROR: Found one Auth + one Normal Variable HOBs\n"));\r
+        ASSERT (FALSE);\r
+      }\r
+    } else {\r
+      GuidHob = GetFirstGuidHob (&gEfiVariableGuid);\r
+      if (GuidHob != NULL) {\r
+        if ((GetNextGuidHob (&gEfiVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {\r
+          DEBUG ((DEBUG_ERROR, "ERROR: Found two Normal Variable HOBs\n"));\r
+          ASSERT (FALSE);\r
+        }\r
+      }\r
+    }\r
+  );\r
+\r
+  GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);\r
+  if (GuidHob != NULL) {\r
+    *VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
+    StoreInfo->AuthFlag = TRUE;\r
+  } else {\r
+    GuidHob = GetFirstGuidHob (&gEfiVariableGuid);\r
+    if (GuidHob != NULL) {\r
+      *VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
+      StoreInfo->AuthFlag = FALSE;\r
+    }\r
+  }\r
+}\r
+\r
 /**\r
   Return the variable store header and the store info based on the Index.\r
 \r
@@ -523,17 +579,8 @@ GetVariableStore (
   VariableStoreHeader = NULL;\r
   switch (Type) {\r
     case VariableStoreTypeHob:\r
-      GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);\r
-      if (GuidHob != NULL) {\r
-        VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
-        StoreInfo->AuthFlag = TRUE;\r
-      } else {\r
-        GuidHob = GetFirstGuidHob (&gEfiVariableGuid);\r
-        if (GuidHob != NULL) {\r
-          VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
-          StoreInfo->AuthFlag = FALSE;\r
-        }\r
-      }\r
+      GetHobVariableStore (StoreInfo, &VariableStoreHeader);\r
+\r
       break;\r
 \r
     case VariableStoreTypeNv:\r
@@ -947,9 +994,10 @@ FindVariable (
   @param  DataSize              On entry, points to the size in bytes of the Data buffer.\r
                                 On return, points to the size of the data returned in Data.\r
   @param  Data                  Points to the buffer which will hold the returned variable value.\r
+                                May be NULL with a zero DataSize in order to determine the size of the buffer needed.\r
 \r
   @retval EFI_SUCCESS           The variable was read successfully.\r
-  @retval EFI_NOT_FOUND         The variable could not be found.\r
+  @retval EFI_NOT_FOUND         The variable was be found.\r
   @retval EFI_BUFFER_TOO_SMALL  The DataSize is too small for the resulting data.\r
                                 DataSize is updated with the size required for\r
                                 the specified variable.\r
@@ -965,7 +1013,7 @@ PeiGetVariable (
   IN CONST  EFI_GUID                        *VariableGuid,\r
   OUT       UINT32                          *Attributes,\r
   IN OUT    UINTN                           *DataSize,\r
-  OUT       VOID                            *Data\r
+  OUT       VOID                            *Data OPTIONAL\r
   )\r
 {\r
   VARIABLE_POINTER_TRACK  Variable;\r
@@ -978,6 +1026,10 @@ PeiGetVariable (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (VariableName[0] == 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   VariableHeader = NULL;\r
 \r
   //\r