]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/VariablePei/Variable.c
Reviewed the code comments in the Include/Protocol directory for typos, grammar issue...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / VariablePei / Variable.c
index 33363e67eaed69ae7deb920b7b8e741e1d7fac9c..3a747846b3c77a17171ad34ec3419e5a4c9ebd75 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Framework PEIM to provide the Variable functionality\r
   \r
-Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2009 Intel Corporation. <BR>\r
 All rights reserved. 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
@@ -47,11 +47,12 @@ EFI_GUID mEfiVariableIndexTableGuid = EFI_VARIABLE_INDEX_TABLE_GUID;
 /**\r
   Provide the functionality of the variable services.\r
 \r
-  @param  FileHandle  Handle of the file being invoked.\r
-  @param  PeiServices Describes the list of possible PEI Services.\r
+  @param  FileHandle      Handle of the file being invoked.\r
+  @param  PeiServices     Describes the list of possible PEI Services.\r
 \r
-  @return Status -  EFI_SUCCESS if the interface could be successfully\r
-          installed\r
+  @return EFI_SUCCESS     If the interface could be successfully installed.\r
+  @return EFI_UNSUPPORTED If current boot path is in recovery mode, then does not\r
+                          install this interface.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -61,9 +62,21 @@ PeimInitializeVariableServices (
   IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
+  EFI_BOOT_MODE BootMode;\r
+  EFI_STATUS    Status;\r
+\r
   //\r
-  // Publish the variable capability to other modules\r
-  //\r
+  // Check if this is recovery boot path. If no, publish the variable access capability\r
+  // to other modules. If yes, the content of variable area is not reliable. Therefore,\r
+  // in this case we should not provide variable service to other pei modules. \r
+  // \r
+  Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
   return (**PeiServices).InstallPpi (PeiServices, &mPpiListVariable[0]);\r
 \r
 }\r
@@ -264,7 +277,8 @@ GetVariableStoreStatus (
   )\r
 \r
 {\r
-  if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE &&\r
+       \r
+  if (CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid) &&\r
       VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
       VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
       ) {\r
@@ -272,7 +286,10 @@ GetVariableStoreStatus (
     return EfiValid;\r
   }\r
 \r
-  if (VarStoreHeader->Signature == 0xffffffff &&\r
+  if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&\r
+      ((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&\r
+      ((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&\r
+      ((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&\r
       VarStoreHeader->Size == 0xffffffff &&\r
       VarStoreHeader->Format == 0xff &&\r
       VarStoreHeader->State == 0xff\r
@@ -366,7 +383,7 @@ FindVariable (
   UINT32                  Count;\r
   UINT8                   *VariableBase;\r
 \r
-  if (VariableName != 0 && VendorGuid == NULL) {\r
+  if (VariableName[0] != 0 && VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   //\r
@@ -409,6 +426,14 @@ FindVariable (
       Variable = IndexTable->StartPtr;\r
     } else {\r
       VariableBase = (UINT8 *) (UINTN) PcdGet32 (PcdFlashNvStorageVariableBase);\r
+\r
+      //\r
+      // Check if FV header is valid.\r
+      //\r
+      if (((EFI_FIRMWARE_VOLUME_HEADER *) VariableBase)->Signature != EFI_FVH_SIGNATURE) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+\r
       VariableStoreHeader = (VARIABLE_STORE_HEADER *) (VariableBase + \\r
                             ((EFI_FIRMWARE_VOLUME_HEADER *) (VariableBase)) -> HeaderLength);\r
 \r
@@ -438,7 +463,7 @@ FindVariable (
   PtrTrack->StartPtr  = IndexTable->StartPtr;\r
   PtrTrack->EndPtr    = IndexTable->EndPtr;\r
 \r
-  while (IsValidVariableHeader (Variable) && (Variable <= IndexTable->EndPtr)) {\r
+  while ((Variable < IndexTable->EndPtr) && IsValidVariableHeader (Variable)) {\r
     if (Variable->State == VAR_ADDED) {\r
       //\r
       // Record Variable in VariableIndex HOB\r