Make DxeIpl loop find the required section type in peiprocessfile functions.
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplPeim / DxeLoad.c
index 4d9ec52..cd38a03 100644 (file)
@@ -383,7 +383,10 @@ Returns:
                  &Hob\r
                  );\r
       CopyMem (FileName, &FfsFileHeader->Name, sizeof (EFI_GUID));\r
-      if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Find all Fv type ffs to get all FvImage and add them into FvHob\r
+      //\r
+      if (!EFI_ERROR (Status) && (Type != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) {\r
         return EFI_SUCCESS;\r
       }\r
     }\r
@@ -661,7 +664,6 @@ Returns:
   EFI_GUID                        TempGuid;\r
   EFI_FIRMWARE_VOLUME_HEADER      *FvHeader;\r
   EFI_COMPRESSION_SECTION         *CompressionSection;\r
-  UINT32                          FvAlignment;\r
 \r
   //\r
   // Initialize local variables.\r
@@ -877,83 +879,66 @@ Returns:
             return EFI_NOT_FOUND;\r
           }\r
         }\r
-        \r
-        CmpSection = (EFI_COMMON_SECTION_HEADER *) DstBuffer;\r
-        if (CmpSection->Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {\r
-          // \r
-          // Firmware Volume Image in this Section\r
-          // Skip the section header to get FvHeader\r
-          //\r
-          FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (CmpSection + 1);\r
 \r
-          if (FvHeader->Signature == EFI_FVH_SIGNATURE) {            \r
-            //\r
-            // Adjust Fv Base Address Alignment based on Align Attributes in Fv Header\r
-            //\r
-            \r
-            //\r
-            // When FvImage support Alignment, we need to check whether \r
-            // its alignment is correct. \r
-            //\r
-            if (FvHeader->Attributes | EFI_FVB_ALIGNMENT_CAP) {\r
-              \r
-              //\r
-              // Calculate the mini alignment for this FvImage\r
-              //\r
-              FvAlignment = 1 << (LowBitSet32 (FvHeader->Attributes >> 16) + 1);\r
-              \r
-              //\r
-              // If current FvImage base address doesn't meet the its alignment,\r
-              // we need to reload this FvImage to another correct memory address.\r
-              //\r
-              if (((UINTN) FvHeader % FvAlignment) != 0) {\r
-                DstBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINTN) FvHeader->FvLength), FvAlignment);\r
-                if (DstBuffer == NULL) {\r
-                  return EFI_OUT_OF_RESOURCES;\r
-                }\r
-                CopyMem (DstBuffer, FvHeader, (UINTN) FvHeader->FvLength);\r
-                FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) DstBuffer;  \r
-              }\r
-            }\r
-            //\r
-            // Build new FvHob for new decompressed Fv image.\r
-            //\r
-            BuildFvHob ((EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, FvHeader->FvLength);\r
-            \r
-            //\r
-            // Set the original FvHob to unused.\r
-            //\r
-            if (OrigHob != NULL) {\r
-              OrigHob->Header->HobType = EFI_HOB_TYPE_UNUSED;\r
-            }\r
-            \r
-            //\r
-            // when search FvImage Section return true.\r
-            //\r
-            if (SectionType == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {\r
-              *Pe32Data = (VOID *) FvHeader;\r
-              return EFI_SUCCESS;\r
-            } else {\r
-              return EFI_NOT_FOUND;\r
-            }\r
-          }\r
-        }\r
         //\r
         // Decompress successfully.\r
         // Loop the decompressed data searching for expected section.\r
         //\r
+        CmpSection = (EFI_COMMON_SECTION_HEADER *) DstBuffer;\r
         CmpFileData = (VOID *) DstBuffer;\r
         CmpFileSize = DstBufferSize;\r
         do {\r
           CmpSectionLength = *(UINT32 *) (CmpSection->Size) & 0x00ffffff;\r
-          if (CmpSection->Type == EFI_SECTION_PE32) {\r
+          if (CmpSection->Type == SectionType) {\r
             //\r
             // This is what we want\r
             //\r
-            *Pe32Data = (VOID *) (CmpSection + 1);\r
-            return EFI_SUCCESS;\r
-          }\r
+            if (SectionType == EFI_SECTION_PE32) {\r
+              *Pe32Data = (VOID *) (CmpSection + 1);\r
+              return EFI_SUCCESS;\r
+            } else if (SectionType == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {\r
+              // \r
+              // Firmware Volume Image in this Section\r
+              // Skip the section header to get FvHeader\r
+              //\r
+              FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (CmpSection + 1);\r
+    \r
+              if (FvHeader->Signature == EFI_FVH_SIGNATURE) {\r
+                //\r
+                // Because FvLength in FvHeader is UINT64 type, \r
+                // so FvHeader must meed at least 8 bytes alignment.\r
+                // If current FvImage base address doesn't meet its alignment,\r
+                // we need to reload this FvImage to another correct memory address.\r
+                //\r
+                if (((UINTN) FvHeader % sizeof (UINT64)) != 0) {\r
+                  DstBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINTN) CmpSectionLength - sizeof (EFI_COMMON_SECTION_HEADER)), sizeof (UINT64));\r
+                  if (DstBuffer == NULL) {\r
+                    return EFI_OUT_OF_RESOURCES;\r
+                  }\r
+                  CopyMem (DstBuffer, FvHeader, (UINTN) CmpSectionLength - sizeof (EFI_COMMON_SECTION_HEADER));\r
+                  FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) DstBuffer;  \r
+                }\r
 \r
+                //\r
+                // Build new FvHob for new decompressed Fv image.\r
+                //\r
+                BuildFvHob ((EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, FvHeader->FvLength);\r
+                \r
+                //\r
+                // Set the original FvHob to unused.\r
+                //\r
+                if (OrigHob != NULL) {\r
+                  OrigHob->Header->HobType = EFI_HOB_TYPE_UNUSED;\r
+                }\r
+                \r
+                //\r
+                // return found FvImage data.\r
+                //\r
+                *Pe32Data = (VOID *) FvHeader;\r
+                return EFI_SUCCESS;\r
+              }\r
+            }\r
+          }\r
           OccupiedCmpSectionLength  = GET_OCCUPIED_SIZE (CmpSectionLength, 4);\r
           CmpSection                = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) CmpSection + OccupiedCmpSectionLength);\r
         } while (CmpSection->Type != 0 && (UINTN) ((UINT8 *) CmpSection - (UINT8 *) CmpFileData) < CmpFileSize);\r