3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Responsibility of this module is to load the DXE Core from a Firmware Volume.
25 BOOLEAN gInMemory
= FALSE
;
28 // Module Globals used in the DXE to PEI handoff
29 // These must be module globals, so the stack can be switched
31 static EFI_DXE_IPL_PPI mDxeIplPpi
= {
35 static EFI_PEI_FV_FILE_LOADER_PPI mLoadFilePpi
= {
39 static EFI_PEI_PPI_DESCRIPTOR mPpiList
[] = {
41 EFI_PEI_PPI_DESCRIPTOR_PPI
,
42 &gEfiPeiFvFileLoaderPpiGuid
,
46 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
52 static EFI_PEI_PPI_DESCRIPTOR mPpiSignal
= {
53 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
54 &gEfiEndOfPeiSignalPpiGuid
,
58 GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY gEfiDecompress
= {
59 UefiDecompressGetInfo
,
63 GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY gTianoDecompress
= {
64 TianoDecompressGetInfo
,
68 GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY gCustomDecompress
= {
69 CustomDecompressGetInfo
,
75 PeimInitializeDxeIpl (
76 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
77 IN EFI_PEI_SERVICES
**PeiServices
83 Initializes the Dxe Ipl PPI
87 FfsHeader - Pointer to FFS file header
88 PeiServices - General purpose services available to every PEIM.
97 EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
;
98 EFI_BOOT_MODE BootMode
;
100 Status
= PeiServicesGetBootMode (&BootMode
);
101 ASSERT_EFI_ERROR (Status
);
103 if (!gInMemory
&& (BootMode
!= BOOT_ON_S3_RESUME
)) {
105 // The DxeIpl has not yet been shadowed
107 PeiEfiPeiPeCoffLoader
= (EFI_PEI_PE_COFF_LOADER_PROTOCOL
*)GetPeCoffLoaderProtocol ();
110 // Shadow DxeIpl and then re-run its entry point
112 Status
= ShadowDxeIpl (FfsHeader
, PeiEfiPeiPeCoffLoader
);
115 // Install FvFileLoader and DxeIpl PPIs.
117 Status
= PeiServicesInstallPpi (mPpiList
);
118 ASSERT_EFI_ERROR(Status
);
127 IN EFI_DXE_IPL_PPI
*This
,
128 IN EFI_PEI_SERVICES
**PeiServices
,
129 IN EFI_PEI_HOB_POINTERS HobList
135 Main entry point to last PEIM
138 This - Entry point for DXE IPL PPI
139 PeiServices - General purpose services available to every PEIM.
140 HobList - Address to the Pei HOB list
144 EFI_SUCCESS - DEX core was successfully loaded.
145 EFI_OUT_OF_RESOURCES - There are not enough resources to load DXE core.
150 EFI_GUID DxeCoreFileName
;
151 EFI_GUID FirmwareFileName
;
154 EFI_PHYSICAL_ADDRESS DxeCoreAddress
;
156 EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint
;
157 EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
;
158 EFI_BOOT_MODE BootMode
;
159 EFI_PEI_RECOVERY_MODULE_PPI
*PeiRecovery
;
160 EFI_PEI_S3_RESUME_PPI
*S3Resume
;
162 // PERF_START (PeiServices, L"DxeIpl", NULL, 0);
165 // if in S3 Resume, restore configure
167 Status
= PeiServicesGetBootMode (&BootMode
);
168 ASSERT_EFI_ERROR(Status
);
170 if (BootMode
== BOOT_ON_S3_RESUME
) {
171 Status
= PeiServicesLocatePpi (
172 &gEfiPeiS3ResumePpiGuid
,
177 ASSERT_EFI_ERROR (Status
);
179 Status
= S3Resume
->S3RestoreConfig (PeiServices
);
180 ASSERT_EFI_ERROR (Status
);
181 } else if (BootMode
== BOOT_IN_RECOVERY_MODE
) {
183 Status
= PeiServicesLocatePpi (
184 &gEfiPeiRecoveryModulePpiGuid
,
187 (VOID
**)&PeiRecovery
189 ASSERT_EFI_ERROR (Status
);
191 Status
= PeiRecovery
->LoadRecoveryCapsule (PeiServices
, PeiRecovery
);
192 if (EFI_ERROR (Status
)) {
193 DEBUG ((EFI_D_ERROR
, "Load Recovery Capsule Failed.(Status = %r)\n", Status
));
198 // Now should have a HOB with the DXE core w/ the old HOB destroyed
203 // Install the PEI Protocols that are shared between PEI and DXE
205 PeiEfiPeiPeCoffLoader
= (EFI_PEI_PE_COFF_LOADER_PROTOCOL
*)GetPeCoffLoaderProtocol ();
206 ASSERT (PeiEfiPeiPeCoffLoader
!= NULL
);
210 // Find the EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE type compressed Firmware Volume file
211 // The file found will be processed by PeiProcessFile: It will first be decompressed to
212 // a normal FV, then a corresponding FV type hob will be built.
214 Status
= PeiFindFile (
215 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
216 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
222 // Find the DXE Core in a Firmware Volume
224 Status
= PeiFindFile (
225 EFI_FV_FILETYPE_DXE_CORE
,
230 ASSERT_EFI_ERROR (Status
);
233 // Load the DXE Core from a Firmware Volume
235 Status
= PeiLoadFile (
236 PeiEfiPeiPeCoffLoader
,
242 ASSERT_EFI_ERROR (Status
);
245 // Add HOB for the DXE Core
255 // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT
259 EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT
262 if (FeaturePcdGet (PcdDxeIplBuildShareCodeHobs
)) {
263 if (FeaturePcdGet (PcdDxeIplSupportEfiDecompress
)) {
265 // Add HOB for the EFI Decompress Protocol
268 &gEfiDecompressProtocolGuid
,
269 (VOID
*)&gEfiDecompress
,
270 sizeof (gEfiDecompress
)
273 if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress
)) {
275 // Add HOB for the Tiano Decompress Protocol
278 &gEfiTianoDecompressProtocolGuid
,
279 (VOID
*)&gTianoDecompress
,
280 sizeof (gTianoDecompress
)
283 if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress
)) {
285 // Add HOB for the user customized Decompress Protocol
288 &gEfiCustomizedDecompressProtocolGuid
,
289 (VOID
*)&gCustomDecompress
,
290 sizeof (gCustomDecompress
)
295 // Add HOB for the PE/COFF Loader Protocol
298 &gEfiPeiPeCoffLoaderGuid
,
299 (VOID
*)&PeiEfiPeiPeCoffLoader
,
305 // Transfer control to the DXE Core
306 // The handoff state is simply a pointer to the HOB list
309 DEBUG ((EFI_D_INFO
, "DXE Core Entry Point 0x%08x\n", (UINTN
) DxeCoreEntryPoint
));
310 HandOffToDxeCore (DxeCoreEntryPoint
, HobList
, &mPpiSignal
);
312 // If we get here, then the DXE Core returned. This is an error
313 // Dxe Core should not return.
318 return EFI_OUT_OF_RESOURCES
;
324 IN UINT16 SectionType
,
325 OUT EFI_GUID
*FileName
,
332 Finds a PE/COFF of a specific Type and SectionType in the Firmware Volumes
333 described in the HOB list. Able to search in a compression set in a FFS file.
334 But only one level of compression is supported, that is, not able to search
335 in a compression set that is within another compression set.
339 Type - The Type of file to retrieve
341 SectionType - The type of section to retrieve from a file
343 FileName - The name of the file found in the Firmware Volume
345 Pe32Data - Pointer to the beginning of the PE/COFF file found in the Firmware Volume
349 EFI_SUCCESS - The file was found, and the name is returned in FileName, and a pointer to
350 the PE/COFF image is returned in Pe32Data
352 EFI_NOT_FOUND - The file was not found in the Firmware Volumes present in the HOB List
356 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
357 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
359 EFI_PEI_HOB_POINTERS Hob
;
363 FfsFileHeader
= NULL
;
364 Status
= EFI_SUCCESS
;
367 // For each Firmware Volume, look for a specified type
368 // of file and break out until no one is found
370 Hob
.Raw
= GetHobList ();
371 while ((Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_FV
, Hob
.Raw
)) != NULL
) {
372 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) (Hob
.FirmwareVolume
->BaseAddress
);
374 // Make sure the FV HOB does not get corrupted.
376 ASSERT (FwVolHeader
->Signature
== EFI_FVH_SIGNATURE
);
378 Status
= PeiServicesFfsFindNextFile (
383 if (!EFI_ERROR (Status
)) {
384 Status
= PeiProcessFile (
390 CopyMem (FileName
, &FfsFileHeader
->Name
, sizeof (EFI_GUID
));
392 // Find all Fv type ffs to get all FvImage and add them into FvHob
394 if (!EFI_ERROR (Status
) && (Type
!= EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
398 Hob
.Raw
= GET_NEXT_HOB (Hob
);
400 return EFI_NOT_FOUND
;
405 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
,
407 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
408 OUT UINT64
*ImageSize
,
409 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
415 Loads and relocates a PE/COFF image into memory.
419 PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol
421 Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
423 ImageAddress - The base address of the relocated PE/COFF image
425 ImageSize - The size of the relocated PE/COFF image
427 EntryPoint - The entry point of the relocated PE/COFF image
431 EFI_SUCCESS - The file was loaded and relocated
433 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
438 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
440 ZeroMem (&ImageContext
, sizeof (ImageContext
));
441 ImageContext
.Handle
= Pe32Data
;
442 Status
= GetImageReadFunction (&ImageContext
);
444 ASSERT_EFI_ERROR (Status
);
446 Status
= PeiEfiPeiPeCoffLoader
->GetImageInfo (PeiEfiPeiPeCoffLoader
, &ImageContext
);
447 if (EFI_ERROR (Status
)) {
451 // Allocate Memory for the image
453 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32
) ImageContext
.ImageSize
));
454 ASSERT (ImageContext
.ImageAddress
!= 0);
457 // Load the image to our new buffer
459 Status
= PeiEfiPeiPeCoffLoader
->LoadImage (PeiEfiPeiPeCoffLoader
, &ImageContext
);
460 if (EFI_ERROR (Status
)) {
464 // Relocate the image in our new buffer
466 Status
= PeiEfiPeiPeCoffLoader
->RelocateImage (PeiEfiPeiPeCoffLoader
, &ImageContext
);
467 if (EFI_ERROR (Status
)) {
472 // Flush the instruction cache so the image data is written before we execute it
474 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)ImageContext
.ImageAddress
, (UINTN
)ImageContext
.ImageSize
);
476 *ImageAddress
= ImageContext
.ImageAddress
;
477 *ImageSize
= ImageContext
.ImageSize
;
478 *EntryPoint
= ImageContext
.EntryPoint
;
485 IN EFI_FFS_FILE_HEADER
*DxeIplFileHeader
,
486 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
492 Shadow the DXE IPL to a different memory location. This occurs after permanent
493 memory has been discovered.
497 DxeIplFileHeader - Pointer to the FFS file header of the DXE IPL driver
499 PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol
503 EFI_SUCCESS - DXE IPL was successfully shadowed to a different memory location.
505 EFI_ ERROR - The shadow was unsuccessful.
511 UINTN OccupiedSectionLength
;
512 EFI_PHYSICAL_ADDRESS DxeIplAddress
;
514 EFI_PHYSICAL_ADDRESS DxeIplEntryPoint
;
516 EFI_COMMON_SECTION_HEADER
*Section
;
518 Section
= (EFI_COMMON_SECTION_HEADER
*) (DxeIplFileHeader
+ 1);
520 while ((Section
->Type
!= EFI_SECTION_PE32
) && (Section
->Type
!= EFI_SECTION_TE
)) {
521 SectionLength
= *(UINT32
*) (Section
->Size
) & 0x00ffffff;
522 OccupiedSectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
523 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ OccupiedSectionLength
);
526 // Relocate DxeIpl into memory by using loadfile service
528 Status
= PeiLoadFile (
529 PeiEfiPeiPeCoffLoader
,
530 (VOID
*) (Section
+ 1),
536 if (Status
== EFI_SUCCESS
) {
538 // Set gInMemory global variable to TRUE to indicate the dxeipl is shadowed.
540 *(BOOLEAN
*) ((UINTN
) &gInMemory
+ (UINTN
) DxeIplEntryPoint
- (UINTN
) _ModuleEntryPoint
) = TRUE
;
541 Status
= ((EFI_PEIM_ENTRY_POINT
) (UINTN
) DxeIplEntryPoint
) (DxeIplFileHeader
, GetPeiServicesTablePointer());
550 IN EFI_PEI_FV_FILE_LOADER_PPI
*This
,
551 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
552 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
553 OUT UINT64
*ImageSize
,
554 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
560 Given a pointer to an FFS file containing a PE32 image, get the
561 information on the PE32 image, and then "load" it so that it
566 This - pointer to our file loader protocol
568 FfsHeader - pointer to the FFS file header of the FFS file that
569 contains the PE32 image we want to load
571 ImageAddress - returned address where the PE32 image is loaded
573 ImageSize - returned size of the loaded PE32 image
575 EntryPoint - entry point to the loaded PE32 image
579 EFI_SUCCESS - The FFS file was successfully loaded.
581 EFI_ERROR - Unable to load the FFS file.
585 EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
;
590 PeiEfiPeiPeCoffLoader
= (EFI_PEI_PE_COFF_LOADER_PROTOCOL
*)GetPeCoffLoaderProtocol ();
593 // Preprocess the FFS file to get a pointer to the PE32 information
594 // in the enclosed PE32 image.
596 Status
= PeiProcessFile (
603 if (EFI_ERROR (Status
)) {
607 // Load the PE image from the FFS file
609 Status
= PeiLoadFile (
610 PeiEfiPeiPeCoffLoader
,
622 IN UINT16 SectionType
,
623 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
625 IN EFI_PEI_HOB_POINTERS
*OrigHob
633 SectionType - The type of section in the FFS file to process.
635 FfsFileHeader - Pointer to the FFS file to process, looking for the
636 specified SectionType
638 Pe32Data - returned pointer to the start of the PE32 image found
643 EFI_SUCCESS - found the PE32 section in the FFS file
649 DECOMPRESS_LIBRARY
*DecompressLibrary
;
651 UINT8
*ScratchBuffer
;
652 UINT32 DstBufferSize
;
653 UINT32 ScratchBufferSize
;
654 EFI_COMMON_SECTION_HEADER
*CmpSection
;
655 UINTN CmpSectionLength
;
656 UINTN OccupiedCmpSectionLength
;
659 EFI_COMMON_SECTION_HEADER
*Section
;
661 UINTN OccupiedSectionLength
;
663 UINT32 AuthenticationStatus
;
664 EFI_PEI_SECTION_EXTRACTION_PPI
*SectionExtract
;
667 EFI_PEI_SECURITY_PPI
*Security
;
668 BOOLEAN StartCrisisRecovery
;
670 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
671 EFI_COMPRESSION_SECTION
*CompressionSection
;
674 // Initialize local variables.
676 DecompressLibrary
= NULL
;
680 Status
= PeiServicesFfsFindSectionData (
681 EFI_SECTION_COMPRESSION
,
687 // First process the compression section
689 if (!EFI_ERROR (Status
)) {
691 // Yes, there is a compression section, so extract the contents
692 // Decompress the image here
694 Section
= (EFI_COMMON_SECTION_HEADER
*) (UINTN
) (VOID
*) ((UINT8
*) (FfsFileHeader
) + (UINTN
) sizeof (EFI_FFS_FILE_HEADER
));
697 SectionLength
= *(UINT32
*) (Section
->Size
) & 0x00ffffff;
698 OccupiedSectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
701 // Was the DXE Core file encapsulated in a GUID'd section?
703 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
706 // This following code constitutes the addition of the security model
710 // Set a default authenticatino state
712 AuthenticationStatus
= 0;
714 Status
= PeiServicesLocatePpi (
715 &gEfiPeiSectionExtractionPpiGuid
,
718 (VOID
**)&SectionExtract
721 if (EFI_ERROR (Status
)) {
725 // Verify Authentication State
727 CopyMem (&TempGuid
, Section
+ 1, sizeof (EFI_GUID
));
729 Status
= SectionExtract
->PeiGetSection (
730 GetPeiServicesTablePointer(),
732 (EFI_SECTION_TYPE
*) &SectionType
,
737 &AuthenticationStatus
740 if (EFI_ERROR (Status
)) {
744 // If not ask the Security PPI, if exists, for disposition
747 Status
= PeiServicesLocatePpi (
748 &gEfiPeiSecurityPpiGuid
,
753 if (EFI_ERROR (Status
)) {
757 Status
= Security
->AuthenticationState (
758 GetPeiServicesTablePointer(),
759 (struct _EFI_PEI_SECURITY_PPI
*) Security
,
760 AuthenticationStatus
,
765 if (EFI_ERROR (Status
)) {
769 // If there is a security violation, report to caller and have
770 // the upper-level logic possible engender a crisis recovery
772 if (StartCrisisRecovery
) {
773 return EFI_SECURITY_VIOLATION
;
777 if (Section
->Type
== EFI_SECTION_PE32
) {
779 // This is what we want
781 *Pe32Data
= (VOID
*) (Section
+ 1);
783 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
785 // This is a compression set, expand it
787 CompressionSection
= (EFI_COMPRESSION_SECTION
*) Section
;
789 switch (CompressionSection
->CompressionType
) {
790 case EFI_STANDARD_COMPRESSION
:
792 // Load EFI standard compression.
794 if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress
)) {
795 DecompressLibrary
= &gEfiDecompress
;
798 return EFI_NOT_FOUND
;
802 case EFI_CUSTOMIZED_COMPRESSION
:
804 // Load user customized compression.
806 if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress
)) {
807 DecompressLibrary
= &gCustomDecompress
;
810 return EFI_NOT_FOUND
;
814 case EFI_NOT_COMPRESSED
:
816 // Allocate destination buffer
818 DstBufferSize
= CompressionSection
->UncompressedLength
;
819 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
820 if (DstBuffer
== NULL
) {
821 return EFI_OUT_OF_RESOURCES
;
824 // stream is not actually compressed, just encapsulated. So just copy it.
826 CopyMem (DstBuffer
, CompressionSection
+ 1, DstBufferSize
);
831 // Don't support other unknown compression type.
833 ASSERT_EFI_ERROR (Status
);
834 return EFI_NOT_FOUND
;
837 if (CompressionSection
->CompressionType
!= EFI_NOT_COMPRESSED
) {
839 // For compressed data, decompress them to dstbuffer.
841 Status
= DecompressLibrary
->GetInfo (
842 (UINT8
*) ((EFI_COMPRESSION_SECTION
*) Section
+ 1),
843 (UINT32
) SectionLength
- sizeof (EFI_COMPRESSION_SECTION
),
847 if (EFI_ERROR (Status
)) {
851 DEBUG ((EFI_D_ERROR
, "Decompress GetInfo Failed - %r\n", Status
));
852 return EFI_NOT_FOUND
;
856 // Allocate scratch buffer
858 ScratchBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize
));
859 if (ScratchBuffer
== NULL
) {
860 return EFI_OUT_OF_RESOURCES
;
864 // Allocate destination buffer
866 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
867 if (DstBuffer
== NULL
) {
868 return EFI_OUT_OF_RESOURCES
;
872 // Call decompress function
874 Status
= DecompressLibrary
->Decompress (
875 (CHAR8
*) ((EFI_COMPRESSION_SECTION
*) Section
+ 1),
879 if (EFI_ERROR (Status
)) {
883 DEBUG ((EFI_D_ERROR
, "Decompress Failed - %r\n", Status
));
884 return EFI_NOT_FOUND
;
889 // Decompress successfully.
890 // Loop the decompressed data searching for expected section.
892 CmpSection
= (EFI_COMMON_SECTION_HEADER
*) DstBuffer
;
893 CmpFileData
= (VOID
*) DstBuffer
;
894 CmpFileSize
= DstBufferSize
;
896 CmpSectionLength
= *(UINT32
*) (CmpSection
->Size
) & 0x00ffffff;
897 if (CmpSection
->Type
== SectionType
) {
899 // This is what we want
901 if (SectionType
== EFI_SECTION_PE32
) {
902 *Pe32Data
= (VOID
*) (CmpSection
+ 1);
904 } else if (SectionType
== EFI_SECTION_FIRMWARE_VOLUME_IMAGE
) {
906 // Firmware Volume Image in this Section
907 // Skip the section header to get FvHeader
909 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (CmpSection
+ 1);
911 if (FvHeader
->Signature
== EFI_FVH_SIGNATURE
) {
913 // Because FvLength in FvHeader is UINT64 type,
914 // so FvHeader must meed at least 8 bytes alignment.
915 // If current FvImage base address doesn't meet its alignment,
916 // we need to reload this FvImage to another correct memory address.
918 if (((UINTN
) FvHeader
% sizeof (UINT64
)) != 0) {
919 DstBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINTN
) CmpSectionLength
- sizeof (EFI_COMMON_SECTION_HEADER
)), sizeof (UINT64
));
920 if (DstBuffer
== NULL
) {
921 return EFI_OUT_OF_RESOURCES
;
923 CopyMem (DstBuffer
, FvHeader
, (UINTN
) CmpSectionLength
- sizeof (EFI_COMMON_SECTION_HEADER
));
924 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) DstBuffer
;
928 // Build new FvHob for new decompressed Fv image.
930 BuildFvHob ((EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
, FvHeader
->FvLength
);
933 // Set the original FvHob to unused.
935 if (OrigHob
!= NULL
) {
936 OrigHob
->Header
->HobType
= EFI_HOB_TYPE_UNUSED
;
940 // return found FvImage data.
942 *Pe32Data
= (VOID
*) FvHeader
;
947 OccupiedCmpSectionLength
= GET_OCCUPIED_SIZE (CmpSectionLength
, 4);
948 CmpSection
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) CmpSection
+ OccupiedCmpSectionLength
);
949 } while (CmpSection
->Type
!= 0 && (UINTN
) ((UINT8
*) CmpSection
- (UINT8
*) CmpFileData
) < CmpFileSize
);
952 // End of the decompression activity
955 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ OccupiedSectionLength
);
956 FileSize
= FfsFileHeader
->Size
[0] & 0xFF;
957 FileSize
+= (FfsFileHeader
->Size
[1] << 8) & 0xFF00;
958 FileSize
+= (FfsFileHeader
->Size
[2] << 16) & 0xFF0000;
959 FileSize
&= 0x00FFFFFF;
960 } while (Section
->Type
!= 0 && (UINTN
) ((UINT8
*) Section
- (UINT8
*) FfsFileHeader
) < FileSize
);
963 // search all sections (compression and non compression) in this FFS, don't
964 // find expected section.
966 return EFI_NOT_FOUND
;
969 // For those FFS that doesn't contain compression section, directly search
970 // PE or TE section in this FFS.
973 Status
= PeiServicesFfsFindSectionData (
979 if (EFI_ERROR (Status
)) {
980 Status
= PeiServicesFfsFindSectionData (
985 if (EFI_ERROR (Status
)) {
991 *Pe32Data
= SectionData
;