]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/PrePiLib/FwVol.c
EmbeddedPkg/PrePiLib: Add FFS_CHECK_SECTION_HOOK when finding section
[mirror_edk2.git] / EmbeddedPkg / Library / PrePiLib / FwVol.c
index 0a6d6925b7eaabfb866e63a0383ea7c9acab0f23..778d8b13c33b100392280b4da3d9236017e3a07d 100644 (file)
@@ -264,16 +264,18 @@ FindFileEx (
   Go through the file to search SectionType section,\r
   when meeting an encapsuled section.\r
 \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 - Pointer to the section to search.\r
+  @param  SectionType       - Filter to find only section of this type.\r
+  @param  SectionCheckHook  - A hook which can check if the section is the target one.\r
+  @param  Section           - From where to search.\r
+  @param  SectionSize       - The file size to search.\r
+  @param  OutputBuffer      - Pointer to the section to search.\r
 \r
   @retval EFI_SUCCESS\r
 **/\r
 EFI_STATUS\r
 FfsProcessSection (\r
   IN EFI_SECTION_TYPE           SectionType,\r
+  IN FFS_CHECK_SECTION_HOOK     SectionCheckHook,\r
   IN EFI_COMMON_SECTION_HEADER  *Section,\r
   IN UINTN                      SectionSize,\r
   OUT VOID                      **OutputBuffer\r
@@ -292,7 +294,9 @@ FfsProcessSection (
   UINT32                    AuthenticationStatus;\r
   CHAR8                     *CompressedData;\r
   UINT32                    CompressedDataLength;\r
+  BOOLEAN                   Found;\r
 \r
+  Found         = FALSE;\r
   *OutputBuffer = NULL;\r
   ParsedLength  = 0;\r
   Status        = EFI_NOT_FOUND;\r
@@ -302,13 +306,23 @@ FfsProcessSection (
     }\r
 \r
     if (Section->Type == SectionType) {\r
-      if (IS_SECTION2 (Section)) {\r
-        *OutputBuffer = (VOID *)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r
+      if (SectionCheckHook != NULL) {\r
+        Found = SectionCheckHook (Section) == EFI_SUCCESS;\r
       } else {\r
-        *OutputBuffer = (VOID *)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
+        Found = TRUE;\r
       }\r
 \r
-      return EFI_SUCCESS;\r
+      if (Found) {\r
+        if (IS_SECTION2 (Section)) {\r
+          *OutputBuffer = (VOID *)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r
+        } else {\r
+          *OutputBuffer = (VOID *)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
+        }\r
+\r
+        return EFI_SUCCESS;\r
+      } else {\r
+        goto CheckNextSection;\r
+      }\r
     } else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) {\r
       if (Section->Type == EFI_SECTION_COMPRESSION) {\r
         if (IS_SECTION2 (Section)) {\r
@@ -415,6 +429,7 @@ FfsProcessSection (
       } else {\r
         return FfsProcessSection (\r
                  SectionType,\r
+                 SectionCheckHook,\r
                  DstBuffer,\r
                  DstBufferSize,\r
                  OutputBuffer\r
@@ -422,6 +437,7 @@ FfsProcessSection (
       }\r
     }\r
 \r
+CheckNextSection:\r
     if (IS_SECTION2 (Section)) {\r
       SectionLength = SECTION2_SIZE (Section);\r
     } else {\r
@@ -456,9 +472,10 @@ FfsProcessSection (
 EFI_STATUS\r
 EFIAPI\r
 FfsFindSectionData (\r
-  IN EFI_SECTION_TYPE     SectionType,\r
-  IN EFI_PEI_FILE_HANDLE  FileHandle,\r
-  OUT VOID                **SectionData\r
+  IN EFI_SECTION_TYPE        SectionType,\r
+  IN FFS_CHECK_SECTION_HOOK  SectionCheckHook,\r
+  IN EFI_PEI_FILE_HANDLE     FileHandle,\r
+  OUT VOID                   **SectionData\r
   )\r
 {\r
   EFI_FFS_FILE_HEADER        *FfsFileHeader;\r
@@ -478,6 +495,7 @@ FfsFindSectionData (
 \r
   return FfsProcessSection (\r
            SectionType,\r
+           SectionCheckHook,\r
            Section,\r
            FileSize,\r
            SectionData\r
@@ -799,7 +817,7 @@ FfsProcessFvFile (
   //\r
   // Find FvImage in FvFile\r
   //\r
-  Status = FfsFindSectionData (EFI_SECTION_FIRMWARE_VOLUME_IMAGE, FvFileHandle, (VOID **)&FvImageHandle);\r
+  Status = FfsFindSectionData (EFI_SECTION_FIRMWARE_VOLUME_IMAGE, NULL, FvFileHandle, (VOID **)&FvImageHandle);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r