]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/FwVol/FwVol.c
MdeModulePkg PeiCore: Improve comment semantics
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
index 65c485549718430eb50253adfe52d4790cd4fc20..b3661146f29c8acb1a4e47f1b6471ef60bfe612d 100644 (file)
@@ -2,14 +2,8 @@
   Pei Core Firmware File System service routines.\r
 \r
 Copyright (c) 2015 HP Development Company, L.P.\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
-http://opensource.org/licenses/bsd-license.php\r
-\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
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -19,12 +13,12 @@ EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList[] = {
   {\r
     EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
     &gEfiPeiFirmwareVolumeInfoPpiGuid,\r
-    FirmwareVolmeInfoPpiNotifyCallback\r
+    FirmwareVolumeInfoPpiNotifyCallback\r
   },\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
     &gEfiPeiFirmwareVolumeInfo2PpiGuid,\r
-    FirmwareVolmeInfoPpiNotifyCallback\r
+    FirmwareVolumeInfoPpiNotifyCallback\r
   }\r
 };\r
 \r
@@ -316,10 +310,10 @@ FindFileEx (
       //\r
       FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->ExtHeaderOffset);\r
       FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolExtHeader + FwVolExtHeader->ExtHeaderSize);\r
-      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ALIGN_POINTER (FfsFileHeader, 8);\r
     } else {\r
       FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);\r
     }\r
+    FfsFileHeader = (EFI_FFS_FILE_HEADER *) ALIGN_POINTER (FfsFileHeader, 8);\r
   } else {\r
     if (IS_FFS_FILE2 (*FileHeader)) {\r
       if (!IsFfs3Fv) {\r
@@ -413,7 +407,7 @@ FindFileEx (
         } else if (AprioriFile != NULL) {\r
           if (FfsFileHeader->Type == EFI_FV_FILETYPE_FREEFORM) {\r
             if (CompareGuid (&FfsFileHeader->Name, &gPeiAprioriFileNameGuid)) {\r
-              *AprioriFile = FfsFileHeader;\r
+              *AprioriFile = (EFI_PEI_FILE_HANDLE)FfsFileHeader;\r
             }\r
           }\r
         }\r
@@ -453,7 +447,7 @@ FindFileEx (
 }\r
 \r
 /**\r
-  Initialize PeiCore Fv List.\r
+  Initialize PeiCore FV List.\r
 \r
   @param PrivateData     - Pointer to PEI_CORE_INSTANCE.\r
   @param SecCoreData     - Pointer to EFI_SEC_PEI_HAND_OFF.\r
@@ -503,6 +497,10 @@ PeiInitializeFv (
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  PrivateData->Fv = AllocateZeroPool (sizeof (PEI_CORE_FV_HANDLE) * FV_GROWTH_STEP);\r
+  ASSERT (PrivateData->Fv != NULL);\r
+  PrivateData->MaxFvCount = FV_GROWTH_STEP;\r
+\r
   //\r
   // Update internal PEI_CORE_FV array.\r
   //\r
@@ -522,7 +520,7 @@ PeiInitializeFv (
 \r
   //\r
   // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose\r
-  // additional Fvs to PeiCore.\r
+  // additional FVs to PeiCore.\r
   //\r
   Status = PeiServicesNotifyPpi (mNotifyOnFvInfoList);\r
   ASSERT_EFI_ERROR (Status);\r
@@ -530,7 +528,7 @@ PeiInitializeFv (
 }\r
 \r
 /**\r
-  Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.\r
+  Process Firmware Volume Information once FvInfoPPI or FvInfo2PPI install.\r
   The FV Info will be registered into PeiCore private data structure.\r
   And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.\r
 \r
@@ -539,12 +537,12 @@ PeiInitializeFv (
   @param Ppi               Address of the PPI that was installed.\r
 \r
   @retval EFI_SUCCESS    The FV Info is registered into PeiCore private data structure.\r
-  @return if not EFI_SUCESS, fail to verify FV.\r
+  @return if not EFI_SUCCESS, fail to verify FV.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-FirmwareVolmeInfoPpiNotifyCallback (\r
+FirmwareVolumeInfoPpiNotifyCallback (\r
   IN EFI_PEI_SERVICES              **PeiServices,\r
   IN EFI_PEI_NOTIFY_DESCRIPTOR     *NotifyDescriptor,\r
   IN VOID                          *Ppi\r
@@ -560,6 +558,7 @@ FirmwareVolmeInfoPpiNotifyCallback (
   VOID                                  *DepexData;\r
   BOOLEAN                               IsFvInfo2;\r
   UINTN                                 CurFvCount;\r
+  VOID                                  *TempPtr;\r
 \r
   Status       = EFI_SUCCESS;\r
   PrivateData  = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
@@ -594,7 +593,7 @@ FirmwareVolmeInfoPpiNotifyCallback (
   }\r
 \r
   //\r
-  // Locate the corresponding FV_PPI according to founded FV's format guid\r
+  // Locate the corresponding FV_PPI according to the format GUID of the FV found\r
   //\r
   Status = PeiServicesLocatePpi (\r
              &FvInfo2Ppi.FvFormat,\r
@@ -621,15 +620,26 @@ FirmwareVolmeInfoPpiNotifyCallback (
           PrivateData->Fv[FvIndex].AuthenticationStatus = FvInfo2Ppi.AuthenticationStatus;\r
           DEBUG ((EFI_D_INFO, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex, FvInfo2Ppi.AuthenticationStatus));\r
         }\r
-        DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfo2Ppi.FvInfo));\r
+        DEBUG ((DEBUG_INFO, "The FV %p has already been processed!\n", FvInfo2Ppi.FvInfo));\r
         return EFI_SUCCESS;\r
       }\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
+    if (PrivateData->FvCount >= PrivateData->MaxFvCount) {\r
+      //\r
+      // Run out of room, grow the buffer.\r
+      //\r
+      TempPtr = AllocateZeroPool (\r
+                  sizeof (PEI_CORE_FV_HANDLE) * (PrivateData->MaxFvCount + FV_GROWTH_STEP)\r
+                  );\r
+      ASSERT (TempPtr != NULL);\r
+      CopyMem (\r
+        TempPtr,\r
+        PrivateData->Fv,\r
+        sizeof (PEI_CORE_FV_HANDLE) * PrivateData->MaxFvCount\r
+        );\r
+      PrivateData->Fv = TempPtr;\r
+      PrivateData->MaxFvCount = PrivateData->MaxFvCount + FV_GROWTH_STEP;\r
     }\r
 \r
     //\r
@@ -651,7 +661,7 @@ FirmwareVolmeInfoPpiNotifyCallback (
     PrivateData->FvCount ++;\r
 \r
     //\r
-    // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r
+    // Scan and process the new discovered FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r
     //\r
     FileHandle = NULL;\r
     do {\r
@@ -1084,15 +1094,6 @@ PeiFfsFindNextFile (
 \r
   CoreFvHandle = FvHandleToCoreHandle (FvHandle);\r
 \r
-  //\r
-  // To make backward compatiblity, if can not find corresponding the handle of FV\r
-  // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed\r
-  // to the address of first byte of FV.\r
-  //\r
-  if ((CoreFvHandle == NULL) && FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r
-    return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r
-  }\r
-\r
   if ((CoreFvHandle == NULL) || CoreFvHandle->FvPpi == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r
@@ -1358,11 +1359,11 @@ GetFvUsedSize (
 }\r
 \r
 /**\r
-  Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.\r
+  Get FV image(s) from the FV type file, then install FV INFO(2) PPI, Build FV(2, 3) HOB.\r
 \r
   @param PrivateData          PeiCore's private data structure\r
-  @param ParentFvCoreHandle   Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.\r
-  @param ParentFvFileHandle   File handle of a Fv type file that contain this Fv image.\r
+  @param ParentFvCoreHandle   Pointer of EFI_CORE_FV_HANDLE to parent FV image that contain this FV image.\r
+  @param ParentFvFileHandle   File handle of a FV type file that contain this FV image.\r
 \r
   @retval EFI_NOT_FOUND         FV image can't be found.\r
   @retval EFI_SUCCESS           Successfully to process it.\r
@@ -1391,6 +1392,7 @@ ProcessFvFile (
   UINT32                        AuthenticationStatus;\r
   UINT32                        FvUsedSize;\r
   UINT8                         EraseByte;\r
+  UINTN                         Index;\r
 \r
   //\r
   // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
@@ -1411,145 +1413,167 @@ ProcessFvFile (
   ParentFvHandle = ParentFvCoreHandle->FvHandle;\r
   ParentFvPpi    = ParentFvCoreHandle->FvPpi;\r
 \r
-  //\r
-  // Find FvImage in FvFile\r
-  //\r
-  AuthenticationStatus = 0;\r
-  if ((ParentFvPpi->Signature == EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) &&\r
-      (ParentFvPpi->Revision == EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) {\r
-    Status = ParentFvPpi->FindSectionByType2 (\r
-                            ParentFvPpi,\r
-                            EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r
-                            0,\r
-                            ParentFvFileHandle,\r
-                            (VOID **)&FvHeader,\r
-                            &AuthenticationStatus\r
-                            );\r
-  } else {\r
-    Status = ParentFvPpi->FindSectionByType (\r
-                            ParentFvPpi,\r
-                            EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r
-                            ParentFvFileHandle,\r
-                            (VOID **)&FvHeader\r
-                            );\r
-  }\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = VerifyPeim (PrivateData, ParentFvHandle, ParentFvFileHandle, AuthenticationStatus);\r
-  if (Status == EFI_SECURITY_VIOLATION) {\r
-    return Status;\r
-  }\r
+  Status = EFI_SUCCESS;\r
 \r
   //\r
-  // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r
-  // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r
-  // its initial linked location and maintain its alignment.\r
+  // Find FvImage(s) in FvFile\r
   //\r
-  if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
-    //\r
-    // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
-    //\r
-    FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
-    if (FvAlignment < 8) {\r
-      FvAlignment = 8;\r
+  Index = 0;\r
+  do {\r
+    AuthenticationStatus = 0;\r
+    if ((ParentFvPpi->Signature == EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) &&\r
+        (ParentFvPpi->Revision == EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) {\r
+      Status = ParentFvPpi->FindSectionByType2 (\r
+                              ParentFvPpi,\r
+                              EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r
+                              Index,\r
+                              ParentFvFileHandle,\r
+                              (VOID **)&FvHeader,\r
+                              &AuthenticationStatus\r
+                              );\r
+    } else {\r
+      //\r
+      // Old FvPpi has no parameter to input SearchInstance,\r
+      // only one instance is supported.\r
+      //\r
+      if (Index > 0) {\r
+        break;\r
+      }\r
+      Status = ParentFvPpi->FindSectionByType (\r
+                              ParentFvPpi,\r
+                              EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r
+                              ParentFvFileHandle,\r
+                              (VOID **)&FvHeader\r
+                              );\r
+    }\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
     }\r
 \r
-    DEBUG ((\r
-      DEBUG_INFO,\r
-      "%a() FV at 0x%x, FvAlignment required is 0x%x\n",\r
-      __FUNCTION__,\r
-      FvHeader,\r
-      FvAlignment\r
-      ));\r
+    Status = VerifyPeim (PrivateData, ParentFvHandle, ParentFvFileHandle, AuthenticationStatus);\r
+    if (Status == EFI_SECURITY_VIOLATION) {\r
+      break;\r
+    }\r
 \r
     //\r
-    // Check FvImage alignment.\r
+    // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r
+    // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r
+    // its initial linked location and maintain its alignment.\r
     //\r
-    if ((UINTN) FvHeader % FvAlignment != 0) {\r
-      FvLength    = ReadUnaligned64 (&FvHeader->FvLength);\r
-      NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment);\r
-      if (NewFvBuffer == NULL) {\r
-        return EFI_OUT_OF_RESOURCES;\r
+    if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
+      //\r
+      // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
+      //\r
+      FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
+      if (FvAlignment < 8) {\r
+        FvAlignment = 8;\r
       }\r
-      if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) {\r
-        //\r
-        // Copy the used bytes and fill the rest with the erase value.\r
-        //\r
-        CopyMem (NewFvBuffer, FvHeader, (UINTN) FvUsedSize);\r
-        SetMem (\r
-          (UINT8 *) NewFvBuffer + FvUsedSize,\r
-          (UINTN) (FvLength - FvUsedSize),\r
-          EraseByte\r
-          );\r
-      } else {\r
-        CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
+\r
+      DEBUG ((\r
+        DEBUG_INFO,\r
+        "%a() FV at 0x%x, FvAlignment required is 0x%x\n",\r
+        __FUNCTION__,\r
+        FvHeader,\r
+        FvAlignment\r
+        ));\r
+\r
+      //\r
+      // Check FvImage alignment.\r
+      //\r
+      if ((UINTN) FvHeader % FvAlignment != 0) {\r
+        FvLength    = ReadUnaligned64 (&FvHeader->FvLength);\r
+        NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment);\r
+        if (NewFvBuffer == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
+        if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) {\r
+          //\r
+          // Copy the used bytes and fill the rest with the erase value.\r
+          //\r
+          CopyMem (NewFvBuffer, FvHeader, (UINTN) FvUsedSize);\r
+          SetMem (\r
+            (UINT8 *) NewFvBuffer + FvUsedSize,\r
+            (UINTN) (FvLength - FvUsedSize),\r
+            EraseByte\r
+            );\r
+        } else {\r
+          CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
+        }\r
+        FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r
       }\r
-      FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r
     }\r
-  }\r
 \r
-  Status = ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, &ParentFvImageInfo);\r
-  ASSERT_EFI_ERROR (Status);\r
+    Status = ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, &ParentFvImageInfo);\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
-  Status = ParentFvPpi->GetFileInfo (ParentFvPpi, ParentFvFileHandle, &FileInfo);\r
-  ASSERT_EFI_ERROR (Status);\r
+    Status = ParentFvPpi->GetFileInfo (ParentFvPpi, ParentFvFileHandle, &FileInfo);\r
+    ASSERT_EFI_ERROR (Status);\r
 \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
-  PeiServicesInstallFvInfo2Ppi(\r
-    &FvHeader->FileSystemGuid,\r
-    (VOID**)FvHeader,\r
-    (UINT32)FvHeader->FvLength,\r
-    &ParentFvImageInfo.FvName,\r
-    &FileInfo.FileName,\r
-    AuthenticationStatus\r
-    );\r
-\r
-  PeiServicesInstallFvInfoPpi (\r
-    &FvHeader->FileSystemGuid,\r
-    (VOID**) FvHeader,\r
-    (UINT32) FvHeader->FvLength,\r
-    &ParentFvImageInfo.FvName,\r
-    &FileInfo.FileName\r
-    );\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
+    PeiServicesInstallFvInfo2Ppi(\r
+      &FvHeader->FileSystemGuid,\r
+      (VOID**)FvHeader,\r
+      (UINT32)FvHeader->FvLength,\r
+      &ParentFvImageInfo.FvName,\r
+      &FileInfo.FileName,\r
+      AuthenticationStatus\r
+      );\r
+\r
+    PeiServicesInstallFvInfoPpi (\r
+      &FvHeader->FileSystemGuid,\r
+      (VOID**) FvHeader,\r
+      (UINT32) FvHeader->FvLength,\r
+      &ParentFvImageInfo.FvName,\r
+      &FileInfo.FileName\r
+      );\r
 \r
-  //\r
-  // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r
-  //\r
-  BuildFvHob (\r
-    (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
-    FvHeader->FvLength\r
-    );\r
+    //\r
+    // Expose the extracted FvImage to the FV HOB consumer phase, i.e. DXE phase\r
+    //\r
+    BuildFvHob (\r
+      (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
+      FvHeader->FvLength\r
+      );\r
 \r
-  //\r
-  // Makes the encapsulated volume show up in DXE phase to skip processing of\r
-  // encapsulated file again.\r
-  //\r
-  BuildFv2Hob (\r
-    (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
-    FvHeader->FvLength,\r
-    &ParentFvImageInfo.FvName,\r
-    &FileInfo.FileName\r
-    );\r
+    //\r
+    // Makes the encapsulated volume show up in DXE phase to skip processing of\r
+    // encapsulated file again.\r
+    //\r
+    BuildFv2Hob (\r
+      (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
+      FvHeader->FvLength,\r
+      &ParentFvImageInfo.FvName,\r
+      &FileInfo.FileName\r
+      );\r
 \r
-  //\r
-  // Build FV3 HOB with authentication status to be propagated to DXE.\r
-  //\r
-  BuildFv3Hob (\r
-    (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
-    FvHeader->FvLength,\r
-    AuthenticationStatus,\r
-    TRUE,\r
-    &ParentFvImageInfo.FvName,\r
-    &FileInfo.FileName\r
-    );\r
+    //\r
+    // Build FV3 HOB with authentication status to be propagated to DXE.\r
+    //\r
+    BuildFv3Hob (\r
+      (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
+      FvHeader->FvLength,\r
+      AuthenticationStatus,\r
+      TRUE,\r
+      &ParentFvImageInfo.FvName,\r
+      &FileInfo.FileName\r
+      );\r
+\r
+    Index++;\r
+  } while (TRUE);\r
 \r
-  return EFI_SUCCESS;\r
+  if (Index > 0) {\r
+    //\r
+    // At least one FvImage has been processed successfully.\r
+    //\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return Status;\r
+  }\r
 }\r
 \r
 /**\r
@@ -1595,7 +1619,7 @@ PeiFfsFvPpiProcessVolume (
 \r
   //\r
   // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped\r
-  // FV image and the handle is pointed to Fv image's buffer.\r
+  // FV image and the handle is pointed to FV image's buffer.\r
   //\r
   *FvHandle = (EFI_PEI_FV_HANDLE) Buffer;\r
 \r
@@ -1891,7 +1915,7 @@ PeiFfsFvPpiGetVolumeInfo (
   CopyMem (&FwVolHeader, FvHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r
 \r
   //\r
-  // Check Fv Image Signature\r
+  // Check FV Image Signature\r
   //\r
   if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2063,12 +2087,13 @@ FvHandleToCoreHandle (
 }\r
 \r
 /**\r
-  Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.\r
+  Gets a PEI_CORE_FV_HANDLE instance for the next volume according to the given index.\r
 \r
-  This routine also will install FvInfo ppi for FV hob in PI ways.\r
+  This routine also will install an instance of the FvInfo PPI for the FV HOB\r
+  as defined in the PI specification.\r
 \r
   @param Private    Pointer of PEI_CORE_INSTANCE\r
-  @param Instance   The index of FV want to be searched.\r
+  @param Instance   Index of the FV to search\r
 \r
   @return Instance of PEI_CORE_FV_HANDLE.\r
 **/\r
@@ -2078,63 +2103,6 @@ FindNextCoreFvHandle (
   IN UINTN              Instance\r
   )\r
 {\r
-  UINTN                    Index;\r
-  BOOLEAN                  Match;\r
-  EFI_HOB_FIRMWARE_VOLUME  *FvHob;\r
-\r
-  //\r
-  // Handle Framework FvHob and Install FvInfo Ppi for it.\r
-  //\r
-  if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r
-    //\r
-    // Loop to search the wanted FirmwareVolume which supports FFS\r
-    //\r
-    FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);\r
-    while (FvHob != NULL) {\r
-      //\r
-      // Search whether FvHob has been installed into PeiCore's FV database.\r
-      // If found, no need install new FvInfoPpi for it.\r
-      //\r
-      for (Index = 0, Match = FALSE; Index < Private->FvCount; Index++) {\r
-        if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->Fv[Index].FvHeader) {\r
-          Match = TRUE;\r
-          break;\r
-        }\r
-      }\r
-\r
-      //\r
-      // Search whether FvHob has been cached into PeiCore's Unknown FV database.\r
-      // If found, no need install new FvInfoPpi for it.\r
-      //\r
-      if (!Match) {\r
-        for (Index = 0; Index < Private->UnknownFvInfoCount; Index ++) {\r
-          if ((UINTN)FvHob->BaseAddress == (UINTN)Private->UnknownFvInfo[Index].FvInfo) {\r
-            Match = TRUE;\r
-            break;\r
-          }\r
-        }\r
-      }\r
-\r
-      //\r
-      // If the Fv in FvHob has not been installed into PeiCore's FV database and has\r
-      // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi\r
-      // for it then PeiCore will dispatch it in callback of FvInfoPpi.\r
-      //\r
-      if (!Match) {\r
-        PeiServicesInstallFvInfoPpi (\r
-          &(((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHob->BaseAddress)->FileSystemGuid),\r
-          (VOID *)(UINTN)FvHob->BaseAddress,\r
-          (UINT32)FvHob->Length,\r
-          NULL,\r
-          NULL\r
-          );\r
-      }\r
-\r
-      FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength));\r
-    }\r
-  }\r
-\r
-  ASSERT (Private->FvCount <= PcdGet32 (PcdPeiCoreMaxFvSupported));\r
   if (Instance >= Private->FvCount) {\r
     return NULL;\r
   }\r
@@ -2182,7 +2150,7 @@ PeiReinitializeFv (
   //\r
   // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r
   //\r
-  for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
+  for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r
     if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {\r
       PrivateData->Fv[Index].FvPpi = &mPeiFfs2FwVol.Fv;\r
     }\r
@@ -2210,7 +2178,7 @@ PeiReinitializeFv (
   //\r
   // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r
   //\r
-  for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
+  for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r
     if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {\r
       PrivateData->Fv[Index].FvPpi = &mPeiFfs3FwVol.Fv;\r
     }\r
@@ -2218,13 +2186,14 @@ PeiReinitializeFv (
 }\r
 \r
 /**\r
-  Report the information for a new discoveried FV in unknown third-party format.\r
+  Report the information for a newly discovered FV in an unknown format.\r
+\r
+  If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for a third-party FV format, but\r
+  the FV has been discovered, then the information of this FV will be cached into PEI_CORE_INSTANCE's\r
+  UnknownFvInfo array.\r
 \r
-  If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but\r
-  the FV in this format has been discoveried, then this FV's information will be cached into\r
-  PEI_CORE_INSTANCE's UnknownFvInfo array.\r
-  Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI\r
-  is installed later by platform's PEIM, the original unknown third-party FV will be processed by\r
+  Also a notification would be installed for unknown FV format GUID, if EFI_PEI_FIRMWARE_VOLUME_PPI\r
+  is installed later by platform's PEIM, the original unknown FV will be processed by\r
   using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r
 \r
   @param PrivateData  Point to instance of PEI_CORE_INSTANCE\r
@@ -2240,9 +2209,23 @@ AddUnknownFormatFvInfo (
   )\r
 {\r
   PEI_CORE_UNKNOW_FORMAT_FV_INFO    *NewUnknownFv;\r
+  VOID                              *TempPtr;\r
 \r
-  if (PrivateData->UnknownFvInfoCount + 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  if (PrivateData->UnknownFvInfoCount >= PrivateData->MaxUnknownFvInfoCount) {\r
+    //\r
+    // Run out of room, grow the buffer.\r
+    //\r
+    TempPtr = AllocateZeroPool (\r
+                sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO) * (PrivateData->MaxUnknownFvInfoCount + FV_GROWTH_STEP)\r
+                );\r
+    ASSERT (TempPtr != NULL);\r
+    CopyMem (\r
+      TempPtr,\r
+      PrivateData->UnknownFvInfo,\r
+      sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO) * PrivateData->MaxUnknownFvInfoCount\r
+      );\r
+    PrivateData->UnknownFvInfo = TempPtr;\r
+    PrivateData->MaxUnknownFvInfoCount = PrivateData->MaxUnknownFvInfoCount + FV_GROWTH_STEP;\r
   }\r
 \r
   NewUnknownFv = &PrivateData->UnknownFvInfo[PrivateData->UnknownFvInfoCount];\r
@@ -2261,13 +2244,13 @@ AddUnknownFormatFvInfo (
 }\r
 \r
 /**\r
-  Find the FV information according to third-party FV format guid.\r
+  Find the FV information according to third-party FV format GUID.\r
 \r
-  This routine also will remove the FV information found by given FV format guid from\r
+  This routine also will remove the FV information found by given FV format GUID from\r
   PrivateData->UnknownFvInfo[].\r
 \r
   @param PrivateData      Point to instance of PEI_CORE_INSTANCE\r
-  @param Format           Point to given FV format guid\r
+  @param Format           Point to given FV format GUID\r
   @param FvInfo           On return, the pointer of FV information buffer\r
   @param FvInfoSize       On return, the size of FV information buffer.\r
   @param AuthenticationStatus On return, the authentication status of FV information buffer.\r
@@ -2317,7 +2300,7 @@ FindUnknownFormatFvInfo (
   Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.\r
 \r
   When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this\r
-  routine is called to process all discoveried FVs in this format.\r
+  routine is called to process all discovered FVs in this format.\r
 \r
   @param PeiServices       An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
   @param NotifyDescriptor  Address of the notification descriptor data structure.\r
@@ -2345,6 +2328,7 @@ ThirdPartyFvPpiNotifyCallback (
   EFI_PEI_FILE_HANDLE          FileHandle;\r
   VOID                         *DepexData;\r
   UINTN                        CurFvCount;\r
+  VOID                         *TempPtr;\r
 \r
   PrivateData  = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
   FvPpi = (EFI_PEI_FIRMWARE_VOLUME_PPI*) Ppi;\r
@@ -2370,7 +2354,7 @@ ThirdPartyFvPpiNotifyCallback (
     IsProcessed = FALSE;\r
     for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r
       if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r
-        DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfo));\r
+        DEBUG ((DEBUG_INFO, "The FV %p has already been processed!\n", FvInfo));\r
         IsProcessed = TRUE;\r
         break;\r
       }\r
@@ -2380,10 +2364,21 @@ ThirdPartyFvPpiNotifyCallback (
       continue;\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
+    if (PrivateData->FvCount >= PrivateData->MaxFvCount) {\r
+      //\r
+      // Run out of room, grow the buffer.\r
+      //\r
+      TempPtr = AllocateZeroPool (\r
+                  sizeof (PEI_CORE_FV_HANDLE) * (PrivateData->MaxFvCount + FV_GROWTH_STEP)\r
+                  );\r
+      ASSERT (TempPtr != NULL);\r
+      CopyMem (\r
+        TempPtr,\r
+        PrivateData->Fv,\r
+        sizeof (PEI_CORE_FV_HANDLE) * PrivateData->MaxFvCount\r
+        );\r
+      PrivateData->Fv = TempPtr;\r
+      PrivateData->MaxFvCount = PrivateData->MaxFvCount + FV_GROWTH_STEP;\r
     }\r
 \r
     //\r
@@ -2405,7 +2400,7 @@ ThirdPartyFvPpiNotifyCallback (
     PrivateData->FvCount ++;\r
 \r
     //\r
-    // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r
+    // Scan and process the new discovered FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r
     //\r
     FileHandle = NULL;\r
     do {\r