]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/FwVol/FwVol.c
Add compatibility logic to handle framework fvhob and install FvInfo ppi. And remove...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
index 621fb16f185ceaea5ebb5c59b4057e4296f1a336..cf0cfe78c5c12e6aa7530298df3d695bd078fd1b 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
+/** @file\r
+  Pei Core Firmware File System service routines.\r
+  \r
+Copyright (c) 2006 - 2008, Intel Corporation                                                         \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
@@ -9,15 +10,7 @@ http://opensource.org/licenses/bsd-license.php
 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
-Module Name:\r
-\r
-  FwVol.c\r
-\r
-Abstract:\r
-\r
-  Pei Core Firmware File System service routines.\r
-\r
---*/\r
+**/\r
 \r
 #include <PeiMain.h>\r
 \r
@@ -29,30 +22,23 @@ STATIC EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList = {
 \r
 \r
 #define GET_OCCUPIED_SIZE(ActualSize, Alignment) \\r
-  (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))\r
+  ((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))\r
+\r
+/**\r
+  Returns the file state set by the highest zero bit in the State field\r
 \r
-STATIC\r
+  @param ErasePolarity   Erase Polarity  as defined by EFI_FVB2_ERASE_POLARITY\r
+                         in the Attributes field.\r
+  @param FfsHeader       Pointer to FFS File Header.\r
+\r
+  @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit \r
+                             in the header State field.\r
+**/\r
 EFI_FFS_FILE_STATE\r
 GetFileState(\r
   IN UINT8                ErasePolarity,\r
   IN EFI_FFS_FILE_HEADER  *FfsHeader\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Returns the highest bit set of the State field\r
-\r
-Arguments:\r
-\r
-  ErasePolarity   - Erase Polarity  as defined by EFI_FVB2_ERASE_POLARITY\r
-                    in the Attributes field.\r
-  FfsHeader       - Pointer to FFS File Header.\r
-\r
-Returns:\r
-  Returns the highest bit in the State field\r
-\r
---*/\r
 {\r
   EFI_FFS_FILE_STATE  FileState;\r
   EFI_FFS_FILE_STATE  HighestBit;\r
@@ -62,7 +48,10 @@ Returns:
   if (ErasePolarity != 0) {\r
     FileState = (EFI_FFS_FILE_STATE)~FileState;\r
   }\r
-\r
+  \r
+  //\r
+  // Get file state set by its highest none zero bit.\r
+  //\r
   HighestBit = 0x80;\r
   while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r
     HighestBit >>= 1;\r
@@ -71,63 +60,42 @@ Returns:
   return HighestBit;\r
 } \r
 \r
-STATIC\r
+/**\r
+  Calculates the checksum of the header of a file.\r
+\r
+  @param FileHeader      Pointer to FFS File Header.\r
+\r
+  @return Checksum of the header.\r
+          Zero means the header is good.\r
+          Non-zero means the header is bad.\r
+**/\r
 UINT8\r
 CalculateHeaderChecksum (\r
   IN EFI_FFS_FILE_HEADER  *FileHeader\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Calculates the checksum of the header of a file.\r
-\r
-Arguments:\r
-\r
-  FileHeader       - Pointer to FFS File Header.\r
-\r
-Returns:\r
-  Checksum of the header.\r
-  \r
-  The header is zero byte checksum.\r
-    - Zero means the header is good.\r
-    - Non-zero means the header is bad.\r
-    \r
-  \r
-Bugbug: For PEI performance reason, we comments this code at this time.\r
---*/\r
 {\r
-  UINT8   *ptr;\r
-  UINTN   Index;\r
-  UINT8   Sum;\r
-  \r
-  Sum = 0;\r
-  ptr = (UINT8 *)FileHeader;\r
-\r
-  for (Index = 0; Index < sizeof(EFI_FFS_FILE_HEADER) - 3; Index += 4) {\r
-    Sum = (UINT8)(Sum + ptr[Index]);\r
-    Sum = (UINT8)(Sum + ptr[Index+1]);\r
-    Sum = (UINT8)(Sum + ptr[Index+2]);\r
-    Sum = (UINT8)(Sum + ptr[Index+3]);\r
-  }\r
-\r
-  for (; Index < sizeof(EFI_FFS_FILE_HEADER); Index++) {\r
-    Sum = (UINT8)(Sum + ptr[Index]);\r
-  }\r
+  EFI_FFS_FILE_HEADER TestFileHeader;\r
   \r
+  CopyMem (&TestFileHeader, FileHeader, sizeof (EFI_FFS_FILE_HEADER));\r
   //\r
-  // State field (since this indicates the different state of file). \r
+  // Ingore State and File field in FFS header.\r
   //\r
-  Sum = (UINT8)(Sum - FileHeader->State);\r
-  //\r
-  // Checksum field of the file is not part of the header checksum.\r
-  //\r
-  Sum = (UINT8)(Sum - FileHeader->IntegrityCheck.Checksum.File);\r
+  TestFileHeader.State = 0;\r
+  TestFileHeader.IntegrityCheck.Checksum.File = 0;\r
 \r
-  return Sum;\r
+  return CalculateSum8 ((CONST UINT8 *) &TestFileHeader, sizeof (EFI_FFS_FILE_HEADER));\r
 }\r
 \r
-STATIC\r
+/**\r
+  Find FV handler according some FileHandle in that FV.\r
+\r
+  @param FileHandle      Handle of file image\r
+  @param VolumeHandle    Handle of the found FV, if not found, NULL will be set.\r
+\r
+  @retval TRUE           The corresponding FV handler is found.\r
+  @retval FALSE          The corresponding FV handler is not found.\r
+\r
+**/\r
 BOOLEAN\r
 EFIAPI\r
 PeiFileHandleToVolume (\r
@@ -148,10 +116,29 @@ PeiFileHandleToVolume (
       return TRUE;\r
     }\r
   }\r
+  *VolumeHandle = NULL;\r
   return FALSE;\r
 }\r
 \r
-\r
+/**\r
+  Given the input file pointer, search for the first matching file in the\r
+  FFS volume as defined by SearchType. The search starts from FileHeader inside\r
+  the Firmware Volume defined by FwVolHeader.\r
+  If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.\r
+  If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, \r
+  the first PEIM, or COMBINED PEIM or FV file type FFS file will return.  \r
+\r
+  @param FvHandle        Pointer to the FV header of the volume to search\r
+  @param FileName        File name\r
+  @param SearchType      Filter to find only files of this type.\r
+                         Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
+  @param FileHandle      This parameter must point to a valid FFS volume.\r
+  @param AprioriFile     Pointer to AprioriFile image in this FV if has\r
+\r
+  @return EFI_NOT_FOUND  No files matching the search criteria were found\r
+  @retval EFI_SUCCESS    Success to search given file\r
+\r
+**/\r
 EFI_STATUS\r
 PeiFindFileEx (\r
   IN  CONST EFI_PEI_FV_HANDLE        FvHandle,\r
@@ -160,28 +147,6 @@ PeiFindFileEx (
   IN OUT    EFI_PEI_FILE_HANDLE      *FileHandle,\r
   IN OUT    EFI_PEI_FV_HANDLE        *AprioriFile  OPTIONAL\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-    Given the input file pointer, search for the next matching file in the\r
-    FFS volume as defined by SearchType. The search starts from FileHeader inside\r
-    the Firmware Volume defined by FwVolHeader.\r
-\r
-Arguments:\r
-    PeiServices - Pointer to the PEI Core Services Table.\r
-    SearchType - Filter to find only files of this type.\r
-      Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
-    FwVolHeader - Pointer to the FV header of the volume to search.\r
-      This parameter must point to a valid FFS volume.\r
-    FileHeader  - Pointer to the current file from which to begin searching.\r
-      This pointer will be updated upon return to reflect the file found.\r
-    Flag        - Indicator for if this is for PEI Dispath search \r
-    \r
-Returns:\r
-    EFI_NOT_FOUND - No files matching the search criteria were found\r
-    EFI_SUCCESS\r
-\r
---*/\r
 {\r
   EFI_FIRMWARE_VOLUME_HEADER           *FwVolHeader;\r
   EFI_FFS_FILE_HEADER                   **FileHeader;\r
@@ -198,7 +163,7 @@ Returns:
   FileHeader  = (EFI_FFS_FILE_HEADER **)FileHandle;\r
 \r
   FvLength = FwVolHeader->FvLength;\r
-  if (FwVolHeader->Attributes & EFI_FVB_ERASE_POLARITY) {\r
+  if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
     ErasePolarity = 1;\r
   } else {\r
     ErasePolarity = 0;\r
@@ -236,8 +201,8 @@ Returns:
     switch (FileState) {\r
 \r
     case EFI_FILE_HEADER_INVALID:\r
-      FileOffset += sizeof(EFI_FFS_FILE_HEADER);\r
-      FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER));\r
+      FileOffset    += sizeof(EFI_FFS_FILE_HEADER);\r
+      FfsFileHeader =  (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER));\r
       break;\r
         \r
     case EFI_FILE_DATA_VALID:\r
@@ -248,7 +213,7 @@ Returns:
         return EFI_NOT_FOUND;\r
       }\r
 \r
-      FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
+      FileLength       = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
       FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r
 \r
       if (FileName != NULL) {\r
@@ -276,15 +241,15 @@ Returns:
         return EFI_SUCCESS;\r
       }\r
 \r
-      FileOffset += FileOccupiedSize; \r
-      FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r
+      FileOffset    += FileOccupiedSize; \r
+      FfsFileHeader =  (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r
       break;\r
     \r
     case EFI_FILE_DELETED:\r
-      FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
-      FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r
-      FileOffset += FileOccupiedSize;\r
-      FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r
+      FileLength       =  *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
+      FileOccupiedSize =  GET_OCCUPIED_SIZE(FileLength, 8);\r
+      FileOffset       += FileOccupiedSize;\r
+      FfsFileHeader    =  (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r
       break;\r
 \r
     default:\r
@@ -297,25 +262,17 @@ Returns:
   return EFI_NOT_FOUND;  \r
 }\r
 \r
+/**\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
+**/\r
 VOID \r
 PeiInitializeFv (\r
   IN  PEI_CORE_INSTANCE           *PrivateData,\r
   IN CONST EFI_SEC_PEI_HAND_OFF   *SecCoreData\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Initialize PeiCore Fv List.\r
-\r
-Arguments:\r
-  PrivateData     - Pointer to PEI_CORE_INSTANCE.\r
-  SecCoreData     - Pointer to EFI_SEC_PEI_HAND_OFF.\r
-\r
-Returns:\r
-  NONE  \r
-  \r
---*/  \r
 {\r
   EFI_STATUS  Status;\r
   //\r
@@ -340,6 +297,18 @@ Returns:
 \r
 }\r
 \r
+/**\r
+  Process Firmware Volum Information once FvInfoPPI 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 PPI will be installed.\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
+  @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
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FirmwareVolmeInfoPpiNotifyCallback (\r
@@ -347,22 +316,6 @@ FirmwareVolmeInfoPpiNotifyCallback (
   IN EFI_PEI_NOTIFY_DESCRIPTOR     *NotifyDescriptor,\r
   IN VOID                          *Ppi\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Process Firmware Volum Information once FvInfoPPI install.\r
-\r
-Arguments:\r
-\r
-  PeiServices - General purpose services available to every PEIM.\r
-    \r
-Returns:\r
-\r
-  Status -  EFI_SUCCESS if the interface could be successfully\r
-            installed\r
-\r
---*/\r
 {\r
   UINT8                                 FvCount;\r
   EFI_PEI_FIRMWARE_VOLUME_INFO_PPI      *Fv;\r
@@ -396,7 +349,7 @@ Returns:
     //\r
     PrivateData->AllFv[PrivateData->AllFvCount++] = (EFI_PEI_FV_HANDLE)Fv->FvInfo;\r
     \r
-    DEBUG ((EFI_D_INFO, "The %dth FvImage start address is 0x%10p and size is 0x%08x\n", PrivateData->AllFvCount, (VOID *) Fv->FvInfo, Fv->FvInfoSize));\r
+    DEBUG ((EFI_D_INFO, "The %dth FvImage start address is 0x%11p and size is 0x%08x\n", PrivateData->AllFvCount, (VOID *) Fv->FvInfo, Fv->FvInfoSize));\r
     //\r
     // Preprocess all FV type files in this new FileSystem2 Fv image\r
     //\r
@@ -434,6 +387,22 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Go through the file to search SectionType section. \r
+  Search within encapsulation sections (compression and GUIDed) recursively, \r
+  until the match section is found.\r
+  \r
+  @param PeiServices     - An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+  @param SectionType     - Filter to find only section of this type.\r
+  @param Section         - From where to search.\r
+  @param SectionSize     - The file size to search.\r
+  @param OutputBuffer    - A pointer to the discovered section, if successful.\r
+                           NULL if section not found\r
+\r
+  @return EFI_NOT_FOUND    The match section is not found.\r
+  @return EFI_SUCCESS      The match section is found.\r
+\r
+**/\r
 EFI_STATUS\r
 PeiFfsProcessSection (\r
   IN CONST EFI_PEI_SERVICES     **PeiServices,\r
@@ -442,24 +411,6 @@ PeiFfsProcessSection (
   IN UINTN                      SectionSize,\r
   OUT VOID                      **OutputBuffer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Go through the file to search SectionType section,\r
-  when meeting an encapsuled section. \r
-  \r
-Arguments:\r
-  PeiServices  - General purpose services available to every PEIM.\r
-  SearchType   - Filter to find only section of this type.\r
-  Section      - From where to search.\r
-  SectionSize  - The file size to search.\r
-  OutputBuffer - Pointer to the section to search.\r
-\r
-Returns:\r
-  EFI_STATUS\r
-  \r
---*/\r
 {\r
   EFI_STATUS                              Status;\r
   UINT32                                  SectionLength;\r
@@ -571,6 +522,20 @@ Returns:
 }\r
 \r
 \r
+/**\r
+  Given the input file pointer, search for the first matching section in the\r
+  FFS volume.\r
+\r
+  @param PeiServices     An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
+  @param SectionType     Filter to find only sections of this type.\r
+  @param FileHandle      Pointer to the current file to search.\r
+  @param SectionData     A pointer to the discovered section, if successful.\r
+                         NULL if section not found\r
+\r
+  @retval EFI_NOT_FOUND  No files matching the search criteria were found\r
+  @retval EFI_SUCCESS    Success to find section data in given file\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiFfsFindSectionData (\r
@@ -579,24 +544,6 @@ PeiFfsFindSectionData (
   IN     EFI_PEI_FILE_HANDLE   FileHandle,\r
   IN OUT VOID                  **SectionData\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-    Given the input file pointer, search for the next matching section in the\r
-    FFS volume.\r
-\r
-Arguments:\r
-    PeiServices - Pointer to the PEI Core Services Table.\r
-    SearchType - Filter to find only sections of this type.\r
-    FfsFileHeader  - Pointer to the current file to search.\r
-    SectionData - Pointer to the Section matching SectionType in FfsFileHeader.\r
-                - NULL if section not found\r
-\r
-Returns:\r
-    EFI_NOT_FOUND - No files matching the search criteria were found\r
-    EFI_SUCCESS\r
-\r
---*/\r
 {\r
   EFI_FFS_FILE_HEADER                     *FfsFileHeader;\r
   UINT32                                  FileSize;\r
@@ -622,7 +569,22 @@ Returns:
           );\r
 }\r
 \r
+/**\r
+  Given the input file pointer, search for the next matching file in the\r
+  FFS volume as defined by SearchType. The search starts from FileHeader inside\r
+  the Firmware Volume defined by FwVolHeader.\r
+\r
 \r
+  @param PeiServices     An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+  @param SearchType      Filter to find only files of this type.\r
+                         Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
+  @param VolumeHandle    Pointer to the FV header of the volume to search.\r
+  @param FileHandle      Pointer to the current file from which to begin searching.\r
+                         This pointer will be updated upon return to reflect the file found.\r
+  @retval EFI_NOT_FOUND  No files matching the search criteria were found\r
+  @retval EFI_SUCCESS    Success to find next file in given volume\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiFfsFindNextFile (\r
@@ -631,73 +593,70 @@ PeiFfsFindNextFile (
   IN EFI_PEI_FV_HANDLE           VolumeHandle,\r
   IN OUT EFI_PEI_FILE_HANDLE     *FileHandle\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-    Given the input file pointer, search for the next matching file in the\r
-    FFS volume as defined by SearchType. The search starts from FileHeader inside\r
-    the Firmware Volume defined by FwVolHeader.\r
-\r
-Arguments:\r
-    PeiServices - Pointer to the PEI Core Services Table.\r
-    \r
-    SearchType - Filter to find only files of this type.\r
-      Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
-      \r
-    FwVolHeader - Pointer to the FV header of the volume to search.\r
-      This parameter must point to a valid FFS volume.\r
-      \r
-    FileHeader  - Pointer to the current file from which to begin searching.\r
-      This pointer will be updated upon return to reflect the file found.\r
-  \r
-Returns:\r
-    EFI_NOT_FOUND - No files matching the search criteria were found\r
-    EFI_SUCCESS\r
-\r
---*/\r
 {\r
   return PeiFindFileEx (VolumeHandle, NULL, SearchType, FileHandle, NULL);\r
 }\r
 \r
 \r
+/**\r
+  Search the firmware volumes by index\r
+\r
+  @param PeiServices     An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
+  @param Instance        Instance of FV to find\r
+  @param VolumeHandle    Pointer to found Volume.\r
+\r
+  @retval EFI_INVALID_PARAMETER  FwVolHeader is NULL\r
+  @retval EFI_SUCCESS            Firmware volume instance successfully found.\r
+\r
+**/\r
 EFI_STATUS \r
 EFIAPI\r
 PeiFvFindNextVolume (\r
-  IN CONST EFI_PEI_SERVICES           **PeiServices,\r
+  IN CONST EFI_PEI_SERVICES         **PeiServices,\r
   IN     UINTN                      Instance,\r
   IN OUT EFI_PEI_FV_HANDLE          *VolumeHandle\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Return the firmware volumes.\r
-\r
-  BugBug -- Move this to the location of this code to where the\r
-  other FV and FFS support code lives.\r
-  Also, update to use FindFV for instances #'s >= 1.\r
-\r
-Arguments:\r
-\r
-  PeiServices - The PEI core services table.\r
-  Instance    - Instance of FV to find\r
-  FwVolHeader - Pointer to contain the data to return\r
-\r
-Returns:\r
-  Pointer to the Firmware Volume instance requested\r
-\r
-  EFI_INVALID_PARAMETER     - FwVolHeader is NULL\r
-  \r
-  EFI_SUCCESS               - Firmware volume instance successfully found.\r
-\r
---*/\r
 {\r
-  PEI_CORE_INSTANCE   *Private;\r
+  PEI_CORE_INSTANCE        *Private;\r
+  UINTN                    Index;\r
+  BOOLEAN                  Match;\r
+  EFI_HOB_FIRMWARE_VOLUME  *FvHob;\r
 \r
   Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
   if (VolumeHandle == NULL) {\r
    return EFI_INVALID_PARAMETER;\r
-  } \r
+  }\r
+  \r
+  //\r
+  // Handle Framework FvHob and Install FvInfo Ppi for it.\r
+  //\r
+  if (FeaturePcdGet (PcdFrameworkFvHobCompatibilitySupport)) {\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
+      for (Index = 0, Match = FALSE; Index < Private->AllFvCount; Index++) {\r
+        if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->AllFv[Index]) {\r
+          Match = TRUE;\r
+          break;\r
+        }\r
+      }\r
+      //\r
+      // If Not Found, Install FvInfo Ppi for it.\r
+      //\r
+      if (!Match) {\r
+        PiLibInstallFvInfoPpi (\r
+          NULL,\r
+          (VOID *)(UINTN)FvHob->BaseAddress,\r
+          (UINT32)FvHob->Length,\r
+          NULL,\r
+          NULL\r
+          );\r
+      }\r
+      FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength)); \r
+    }\r
+  }\r
 \r
   if (Instance >= Private->AllFvCount) {\r
    VolumeHandle = NULL;\r
@@ -709,6 +668,19 @@ Returns:
 }\r
 \r
 \r
+/**\r
+  Find a file within a volume by its name.\r
+\r
+  @param FileName        A pointer to the name of the file to find within the firmware volume.\r
+  @param VolumeHandle    The firmware volume to search\r
+  @param FileHandle      Upon exit, points to the found file's handle \r
+                         or NULL if it could not be found.\r
+\r
+  @retval EFI_SUCCESS            File was found.\r
+  @retval EFI_NOT_FOUND          File was not found.\r
+  @retval EFI_INVALID_PARAMETER  VolumeHandle or FileHandle or FileName was NULL.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI \r
 PeiFfsFindFileByName (\r
@@ -716,22 +688,6 @@ PeiFfsFindFileByName (
   IN  EFI_PEI_FV_HANDLE     VolumeHandle,\r
   OUT EFI_PEI_FILE_HANDLE   *FileHandle\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Given the input VolumeHandle, search for the next matching name file.\r
-\r
-Arguments:\r
-\r
-  FileName      - File name to search.\r
-  VolumeHandle  - The current FV to search.\r
-  FileHandle    - Pointer to the file matching name in VolumeHandle.\r
-                - NULL if file not found\r
-Returns:\r
-  EFI_STATUS\r
-  \r
---*/  \r
 {\r
   EFI_STATUS  Status;\r
   if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r
@@ -744,26 +700,24 @@ Returns:
   return Status;\r
 }\r
 \r
+/**\r
+\r
+  Returns information about a specific file.\r
+\r
+\r
+  @param FileHandle      - The handle to file.\r
+  @param FileInfo        - Pointer to the file information.\r
+\r
+  @retval EFI_INVALID_PARAMETER Invalid FileHandle or FileInfo.\r
+  @retval EFI_SUCCESS           Success to collect file info.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI \r
 PeiFfsGetFileInfo (\r
   IN EFI_PEI_FILE_HANDLE  FileHandle,\r
   OUT EFI_FV_FILE_INFO    *FileInfo\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Collect information of given file.\r
-\r
-Arguments:\r
-  FileHandle   - The handle to file.\r
-  FileInfo     - Pointer to the file information.\r
-\r
-Returns:\r
-  EFI_STATUS\r
-  \r
---*/    \r
 {\r
   UINT8                       FileState;\r
   UINT8                       ErasePolarity;\r
@@ -774,6 +728,7 @@ Returns:
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  VolumeHandle = 0;\r
   //\r
   // Retrieve the FirmwareVolume which the file resides in.\r
   //\r
@@ -781,7 +736,7 @@ Returns:
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB_ERASE_POLARITY) {\r
+  if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
     ErasePolarity = 1;\r
   } else {\r
     ErasePolarity = 0;\r
@@ -810,26 +765,22 @@ Returns:
 }\r
 \r
 \r
+/**\r
+\r
+  Collect information of given Fv Volume.\r
+\r
+  @param VolumeHandle    - The handle to Fv Volume.\r
+  @param VolumeInfo      - The pointer to volume information.\r
+\r
+  @retval EFI_INVALID_PARAMETER VolumeInfo is NULL\r
+  @retval EFI_SUCCESS           Success to collect fv info.\r
+**/\r
 EFI_STATUS\r
 EFIAPI \r
 PeiFfsGetVolumeInfo (\r
   IN EFI_PEI_FV_HANDLE  VolumeHandle,\r
   OUT EFI_FV_INFO       *VolumeInfo\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Collect information of given Fv Volume.\r
-\r
-Arguments:\r
-  VolumeHandle    - The handle to Fv Volume.\r
-  VolumeInfo      - The pointer to volume information.\r
-  \r
-Returns:\r
-  EFI_STATUS\r
-  \r
---*/    \r
 {\r
   EFI_FIRMWARE_VOLUME_HEADER             FwVolHeader;\r
   EFI_FIRMWARE_VOLUME_EXT_HEADER         *FwVolExHeaderInfo;\r