]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/FwVol/FwVol.c
MdeModulePkg/Core: Fix typos in comments
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
index fe876ed393a9357bca3d689ab4be8401637ff3b1..d2eb0bc35b6250845f0c78044471d207cacd12e2 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Pei Core Firmware File System service routines.\r
   \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 HP Development Company, L.P.\r
+Copyright (c) 2006 - 2016, 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
@@ -203,16 +204,34 @@ FileHandleToVolume (
   UINTN                       Index;\r
   PEI_CORE_INSTANCE           *PrivateData;\r
   EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;\r
+  UINTN                       BestIndex;\r
 \r
   PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
+  BestIndex   = PrivateData->FvCount;\r
   \r
+  //\r
+  // Find the best matched FV image that includes this FileHandle.\r
+  // FV may include the child FV, and they are in the same continuous space. \r
+  // If FileHandle is from the child FV, the updated logic can find its matched FV.\r
+  //\r
   for (Index = 0; Index < PrivateData->FvCount; Index++) {\r
     FwVolHeader = PrivateData->Fv[Index].FvHeader;\r
     if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) &&   \\r
         ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {\r
-      return &PrivateData->Fv[Index];\r
+      if (BestIndex == PrivateData->FvCount) {\r
+        BestIndex = Index;\r
+      } else {\r
+        if ((UINT64) (UINTN) PrivateData->Fv[BestIndex].FvHeader < (UINT64) (UINTN) FwVolHeader) {\r
+          BestIndex = Index;\r
+        }\r
+      }\r
     }\r
   }\r
+\r
+  if (BestIndex < PrivateData->FvCount) {\r
+    return &PrivateData->Fv[BestIndex];\r
+  }\r
+\r
   return NULL;\r
 }\r
 \r
@@ -526,16 +545,11 @@ FirmwareVolmeInfoPpiNotifyCallback (
   EFI_PEI_FILE_HANDLE                   FileHandle;\r
   VOID                                  *DepexData;\r
   BOOLEAN                               IsFvInfo2;\r
-  \r
+  UINTN                                 CurFvCount;\r
+\r
   Status       = EFI_SUCCESS;\r
   PrivateData  = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
 \r
-  if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
-    DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported)));\r
-    DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r
-    ASSERT (FALSE);\r
-  }\r
-\r
   if (CompareGuid (NotifyDescriptor->Guid, &gEfiPeiFirmwareVolumeInfo2PpiGuid)) {\r
     //\r
     // It is FvInfo2PPI.\r
@@ -584,6 +598,12 @@ FirmwareVolmeInfoPpiNotifyCallback (
       }\r
     }\r
 \r
+    if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
+      DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));\r
+      DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r
+      ASSERT (FALSE);\r
+    }\r
+\r
     //\r
     // Update internal PEI_CORE_FV array.\r
     //\r
@@ -591,10 +611,11 @@ FirmwareVolmeInfoPpiNotifyCallback (
     PrivateData->Fv[PrivateData->FvCount].FvPpi    = FvPpi;\r
     PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
     PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = FvInfo2Ppi.AuthenticationStatus;\r
+    CurFvCount = PrivateData->FvCount;\r
     DEBUG ((\r
       EFI_D_INFO, \r
       "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
-      (UINT32) PrivateData->FvCount, \r
+      (UINT32) CurFvCount,\r
       (VOID *) FvInfo2Ppi.FvInfo, \r
       FvInfo2Ppi.FvInfoSize,\r
       FvHandle\r
@@ -628,8 +649,8 @@ FirmwareVolmeInfoPpiNotifyCallback (
           }\r
         }\r
         \r
-        DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r
-        ProcessFvFile (PrivateData, &PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r
+        DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));\r
+        ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);\r
       }\r
     } while (FileHandle != NULL);\r
   } else {\r
@@ -735,6 +756,7 @@ ProcessSection (
   BOOLEAN                                 SectionCached;\r
   VOID                                    *TempOutputBuffer;\r
   UINT32                                  TempAuthenticationStatus;\r
+  UINT16                                  GuidedSectionAttributes;\r
 \r
   PrivateData   = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
   *OutputBuffer = NULL;\r
@@ -834,9 +856,11 @@ ProcessSection (
         Authentication = 0;\r
         if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r
           if (IS_SECTION2 (Section)) {\r
-            SectionDefinitionGuid = &((EFI_GUID_DEFINED_SECTION2 *)Section)->SectionDefinitionGuid;\r
+            SectionDefinitionGuid   = &((EFI_GUID_DEFINED_SECTION2 *)Section)->SectionDefinitionGuid;\r
+            GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *)Section)->Attributes;\r
           } else {\r
-            SectionDefinitionGuid = &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid;\r
+            SectionDefinitionGuid   = &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid;\r
+            GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION *)Section)->Attributes;\r
           }\r
           if (VerifyGuidedSectionGuid (SectionDefinitionGuid, &GuidSectionPpi)) {\r
             Status = GuidSectionPpi->ExtractSection (\r
@@ -846,6 +870,21 @@ ProcessSection (
                                        &PpiOutputSize,\r
                                        &Authentication\r
                                        );\r
+          } else if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) == 0) {\r
+            //\r
+            // Figure out the proper authentication status for GUIDED section without processing required\r
+            //\r
+            Status = EFI_SUCCESS;\r
+            if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {\r
+              Authentication |= EFI_AUTH_STATUS_IMAGE_SIGNED | EFI_AUTH_STATUS_NOT_TESTED;\r
+            }\r
+            if (IS_SECTION2 (Section)) {\r
+              PpiOutputSize = SECTION2_SIZE (Section) - ((EFI_GUID_DEFINED_SECTION2 *) Section)->DataOffset;\r
+              PpiOutput     = (UINT8 *) Section + ((EFI_GUID_DEFINED_SECTION2 *) Section)->DataOffset;\r
+            } else {\r
+              PpiOutputSize = SECTION_SIZE (Section) - ((EFI_GUID_DEFINED_SECTION *) Section)->DataOffset;\r
+              PpiOutput     = (UINT8 *) Section + ((EFI_GUID_DEFINED_SECTION *) Section)->DataOffset;\r
+            }\r
           }\r
         } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r
           Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r
@@ -1345,22 +1384,24 @@ ProcessFvFile (
   \r
   //\r
   // Install FvInfo(2) Ppi\r
+  // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated\r
+  // FVs inherit the proper AuthenticationStatus.\r
   //\r
-  PeiServicesInstallFvInfoPpi (\r
+  PeiServicesInstallFvInfo2Ppi(\r
     &FvHeader->FileSystemGuid,\r
-    (VOID**) FvHeader,\r
-    (UINT32) FvHeader->FvLength,\r
+    (VOID**)FvHeader,\r
+    (UINT32)FvHeader->FvLength,\r
     &ParentFvImageInfo.FvName,\r
-    &FileInfo.FileName\r
+    &FileInfo.FileName,\r
+    AuthenticationStatus\r
     );\r
 \r
-  PeiServicesInstallFvInfo2Ppi (\r
+  PeiServicesInstallFvInfoPpi (\r
     &FvHeader->FileSystemGuid,\r
     (VOID**) FvHeader,\r
     (UINT32) FvHeader->FvLength,\r
     &ParentFvImageInfo.FvName,\r
-    &FileInfo.FileName,\r
-    AuthenticationStatus\r
+    &FileInfo.FileName\r
     );\r
 \r
   //\r
@@ -1967,7 +2008,7 @@ FindNextCoreFvHandle (
     }\r
   }\r
 \r
-  ASSERT (Private->FvCount <= FixedPcdGet32 (PcdPeiCoreMaxFvSupported));\r
+  ASSERT (Private->FvCount <= PcdGet32 (PcdPeiCoreMaxFvSupported));\r
   if (Instance >= Private->FvCount) {\r
     return NULL;\r
   }\r
@@ -1978,7 +2019,7 @@ FindNextCoreFvHandle (
 /**\r
   After PeiCore image is shadowed into permanent memory, all build-in FvPpi should\r
   be re-installed with the instance in permanent memory and all cached FvPpi pointers in \r
-  PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant\r
+  PrivateData->Fv[] array should be fixed up to be pointed to the one in permanent\r
   memory.\r
   \r
   @param PrivateData   Pointer to PEI_CORE_INSTANCE.\r
@@ -2015,7 +2056,7 @@ PeiReinitializeFv (
   //\r
   // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r
   //\r
-  for (Index = 0; Index < FixedPcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
+  for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
     if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {\r
       PrivateData->Fv[Index].FvPpi = &mPeiFfs2FwVol.Fv;\r
     }\r
@@ -2043,7 +2084,7 @@ PeiReinitializeFv (
   //\r
   // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r
   //\r
-  for (Index = 0; Index < FixedPcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
+  for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
     if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {\r
       PrivateData->Fv[Index].FvPpi = &mPeiFfs3FwVol.Fv;\r
     }\r
@@ -2074,7 +2115,7 @@ AddUnknownFormatFvInfo (
 {\r
   PEI_CORE_UNKNOW_FORMAT_FV_INFO    *NewUnknownFv;\r
   \r
-  if (PrivateData->UnknownFvInfoCount + 1 >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
+  if (PrivateData->UnknownFvInfoCount + 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   \r
@@ -2177,7 +2218,8 @@ ThirdPartyFvPpiNotifyCallback (
   UINTN                        FvIndex;\r
   EFI_PEI_FILE_HANDLE          FileHandle;\r
   VOID                         *DepexData;  \r
-  \r
+  UINTN                        CurFvCount;\r
+\r
   PrivateData  = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
   FvPpi = (EFI_PEI_FIRMWARE_VOLUME_PPI*) Ppi;\r
   \r
@@ -2212,8 +2254,8 @@ ThirdPartyFvPpiNotifyCallback (
       continue;\r
     }\r
     \r
-    if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
-      DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported)));\r
+    if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
+      DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));\r
       DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r
       ASSERT (FALSE);\r
     }\r
@@ -2225,10 +2267,11 @@ ThirdPartyFvPpiNotifyCallback (
     PrivateData->Fv[PrivateData->FvCount].FvPpi    = FvPpi;\r
     PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
     PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = AuthenticationStatus;\r
+    CurFvCount = PrivateData->FvCount;\r
     DEBUG ((\r
       EFI_D_INFO, \r
       "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
-      (UINT32) PrivateData->FvCount, \r
+      (UINT32) CurFvCount,\r
       (VOID *) FvInfo, \r
       FvInfoSize,\r
       FvHandle\r
@@ -2262,8 +2305,8 @@ ThirdPartyFvPpiNotifyCallback (
           }\r
         }\r
         \r
-        DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r
-        ProcessFvFile (PrivateData, &PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r
+        DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));\r
+        ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);\r
       }\r
     } while (FileHandle != NULL);\r
   } while (TRUE);\r