]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/PrePiLib: Add FFS_CHECK_SECTION_HOOK when finding section
authorMin M Xu <min.m.xu@intel.com>
Mon, 16 Jan 2023 23:31:55 +0000 (07:31 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 18 Jan 2023 03:04:27 +0000 (03:04 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4152

EmbeddedPkg/PrePiLib provides the service of finding sections based on
the input SectionType. But sometimes there maybe multiple sections
with the same SectionType. FFS_CHECK_SECTION_HOOK is a hook which can
be called to do additional check.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Daniel Schaefer <git@danielschaefer.me>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Ard Biesheuvel <ardb+tianocore@kernel.org>
Signed-off-by: Min Xu <min.m.xu@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
EmbeddedPkg/Include/Library/PrePiLib.h
EmbeddedPkg/Library/PrePiLib/FwVol.c
EmbeddedPkg/Library/PrePiLib/PrePiLib.c

index 3741b08c44780d4eafff37a5df645d82160420f7..f60b6678185ac11dad8625aec038d896ad1a6168 100644 (file)
@@ -52,11 +52,23 @@ FfsFindNextFile (
   IN OUT EFI_PEI_FILE_HANDLE  *FileHandle\r
   );\r
 \r
+/**\r
+ * This is a hook which is used to check if the section is the target one.\r
+ *\r
+ */\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *FFS_CHECK_SECTION_HOOK)(\r
+  IN EFI_COMMON_SECTION_HEADER *Section\r
+  );\r
+\r
 /**\r
   This service enables discovery sections of a given type within a valid FFS file.\r
+  Caller also can provide a SectionCheckHook to do additional checking.\r
 \r
-  @param  SearchType            The value of the section type to find.\r
-  @param  FfsFileHeader         A pointer to the file header that contains the set of sections to\r
+  @param  SectionType           The value of the section type to find.\r
+  @param  SectionCheckHook      A hook which can check if the section is the target one.\r
+  @param  FileHeader            A pointer to the file header that contains the set of sections to\r
                                 be searched.\r
   @param  SectionData           A pointer to the discovered section, if successful.\r
 \r
@@ -67,9 +79,10 @@ FfsFindNextFile (
 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
 /**\r
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
index a0c5d02debd0bfc2078634bdbedcaf0300165f64..3b6fc4f0eba86b4b754dfb234800f1e81284c4ac 100644 (file)
@@ -131,7 +131,7 @@ LoadDxeCoreFromFfsFile (
   VOID                  *Hob;\r
   EFI_FV_FILE_INFO      FvFileInfo;\r
 \r
-  Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage);\r
+  Status = FfsFindSectionData (EFI_SECTION_PE32, NULL, FileHandle, &PeCoffImage);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r