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 #pragma warning( disable : 4305 )
27 BOOLEAN gInMemory
= FALSE
;
30 // Module Globals used in the DXE to PEI handoff
31 // These must be module globals, so the stack can be switched
33 static EFI_DXE_IPL_PPI mDxeIplPpi
= {
37 static EFI_PEI_FV_FILE_LOADER_PPI mLoadFilePpi
= {
41 static EFI_PEI_PPI_DESCRIPTOR mPpiLoadFile
= {
42 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
43 &gEfiPeiFvFileLoaderPpiGuid
,
47 static EFI_PEI_PPI_DESCRIPTOR mPpiList
= {
48 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
53 static EFI_PEI_PPI_DESCRIPTOR mPpiPeiInMemory
= {
54 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
59 static EFI_PEI_PPI_DESCRIPTOR mPpiSignal
= {
60 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
61 &gEfiEndOfPeiSignalPpiGuid
,
65 GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY gEfiDecompress
= {
66 UefiDecompressGetInfo
,
70 GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY gTianoDecompress
= {
71 TianoDecompressGetInfo
,
75 GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY gCustomDecompress
= {
76 CustomDecompressGetInfo
,
89 OccupiedSize
= ActualSize
;
90 while ((OccupiedSize
& (Alignment
- 1)) != 0) {
99 PeimInitializeDxeIpl (
100 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
101 IN EFI_PEI_SERVICES
**PeiServices
107 Initializes the Dxe Ipl PPI
111 FfsHeader - Pointer to FFS file header
112 PeiServices - General purpose services available to every PEIM.
121 EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
;
122 EFI_BOOT_MODE BootMode
;
124 Status
= PeiServicesGetBootMode (&BootMode
);
126 ASSERT_EFI_ERROR (Status
);
128 Status
= PeiServicesLocatePpi (
135 if (EFI_ERROR (Status
) && (BootMode
!= BOOT_ON_S3_RESUME
)) {
137 // The DxeIpl has not yet been shadowed
139 PeiEfiPeiPeCoffLoader
= (EFI_PEI_PE_COFF_LOADER_PROTOCOL
*)GetPeCoffLoaderProtocol ();
142 // Shadow DxeIpl and then re-run its entry point
144 Status
= ShadowDxeIpl (FfsHeader
, PeiEfiPeiPeCoffLoader
);
145 if (EFI_ERROR (Status
)) {
150 if (BootMode
!= BOOT_ON_S3_RESUME
) {
152 // The DxeIpl has been shadowed
157 // Install LoadFile PPI
159 Status
= PeiServicesInstallPpi (&mPpiLoadFile
);
161 if (EFI_ERROR (Status
)) {
166 // Install DxeIpl PPI
168 PeiServicesInstallPpi (&mPpiList
);
170 if (EFI_ERROR (Status
)) {
182 IN EFI_DXE_IPL_PPI
*This
,
183 IN EFI_PEI_SERVICES
**PeiServices
,
184 IN EFI_PEI_HOB_POINTERS HobList
190 Main entry point to last PEIM
194 This - Entry point for DXE IPL PPI
195 PeiServices - General purpose services available to every PEIM.
196 HobList - Address to the Pei HOB list
200 EFI_SUCCESS - DEX core was successfully loaded.
201 EFI_OUT_OF_RESOURCES - There are not enough resources to load DXE core.
206 EFI_PHYSICAL_ADDRESS TopOfStack
;
207 EFI_PHYSICAL_ADDRESS BaseOfStack
;
208 EFI_PHYSICAL_ADDRESS BspStore
;
209 EFI_GUID DxeCoreFileName
;
210 VOID
*DxeCorePe32Data
;
211 EFI_PHYSICAL_ADDRESS DxeCoreAddress
;
213 EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint
;
214 EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
;
215 EFI_BOOT_MODE BootMode
;
216 EFI_PEI_RECOVERY_MODULE_PPI
*PeiRecovery
;
217 EFI_PEI_S3_RESUME_PPI
*S3Resume
;
218 EFI_PHYSICAL_ADDRESS PageTables
;
223 Status
= EFI_SUCCESS
;
226 // if in S3 Resume, restore configure
228 Status
= PeiServicesGetBootMode (&BootMode
);
230 if (!EFI_ERROR (Status
) && (BootMode
== BOOT_ON_S3_RESUME
)) {
231 Status
= PeiServicesLocatePpi (
232 &gEfiPeiS3ResumePpiGuid
,
238 ASSERT_EFI_ERROR (Status
);
240 Status
= S3Resume
->S3RestoreConfig (PeiServices
);
242 ASSERT_EFI_ERROR (Status
);
245 Status
= EFI_SUCCESS
;
248 // Install the PEI Protocols that are shared between PEI and DXE
250 PeiEfiPeiPeCoffLoader
= (EFI_PEI_PE_COFF_LOADER_PROTOCOL
*)GetPeCoffLoaderProtocol ();
251 ASSERT (PeiEfiPeiPeCoffLoader
!= NULL
);
254 // Allocate 128KB for the Stack
256 PeiServicesAllocatePages (EfiBootServicesData
, EFI_SIZE_TO_PAGES (STACK_SIZE
), &BaseOfStack
);
257 ASSERT (BaseOfStack
!= 0);
260 // Compute the top of the stack we were allocated. Pre-allocate a 32 bytes
261 // for safety (PpisNeededByDxe and DxeCore).
263 TopOfStack
= BaseOfStack
+ EFI_SIZE_TO_PAGES (STACK_SIZE
) * EFI_PAGE_SIZE
- 32;
266 // Add architecture-specifc HOBs (including the BspStore HOB)
268 Status
= CreateArchSpecificHobs (&BspStore
);
269 ASSERT_EFI_ERROR (Status
);
272 // See if we are in crisis recovery
274 Status
= PeiServicesGetBootMode (&BootMode
);
275 if (!EFI_ERROR (Status
) && (BootMode
== BOOT_IN_RECOVERY_MODE
)) {
276 Status
= PeiServicesLocatePpi (
277 &gEfiPeiRecoveryModulePpiGuid
,
280 (VOID
**)&PeiRecovery
283 ASSERT_EFI_ERROR (Status
);
284 Status
= PeiRecovery
->LoadRecoveryCapsule (PeiServices
, PeiRecovery
);
285 if (EFI_ERROR (Status
)) {
286 DEBUG ((EFI_D_ERROR
, "Load Recovery Capsule Failed.(Status = %r)\n", Status
));
292 // Find the DXE Core in a Firmware Volume
294 Status
= PeiFindFile (
295 EFI_FV_FILETYPE_DXE_CORE
,
300 ASSERT_EFI_ERROR (Status
);
303 // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA \
304 // memory, it may be corrupted when copying FV to high-end memory
308 // Limit to 36 bits of addressing for debug. Should get it from CPU
310 PageTables
= CreateIdentityMappingPageTables (36);
314 // Load the DXE Core from a Firmware Volume
316 Status
= PeiLoadPeImage (
317 PeiEfiPeiPeCoffLoader
,
324 ASSERT_EFI_ERROR (Status
);
327 // Transfer control to the DXE Core
328 // The handoff state is simply a pointer to the HOB list
331 Status
= PeiServicesInstallPpi (&mPpiSignal
);
332 ASSERT_EFI_ERROR (Status
);
336 // Add HOB for the DXE Core
346 // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT
350 EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT
353 DEBUG ((EFI_D_INFO
, "DXE Core Entry\n"));
355 // Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.
356 // Call x64 drivers passing in single argument, a pointer to the HOBs.
360 (EFI_PHYSICAL_ADDRESS
)(UINTN
)(HobList
.Raw
),
367 // If we get here, then the DXE Core returned. This is an error
368 // Dxe Core should not return.
373 return EFI_OUT_OF_RESOURCES
;
379 IN UINT16 SectionType
,
380 OUT EFI_GUID
*FileName
,
387 Finds a PE/COFF of a specific Type and SectionType in the Firmware Volumes
388 described in the HOB list. Able to search in a compression set in a FFS file.
389 But only one level of compression is supported, that is, not able to search
390 in a compression set that is within another compression set.
394 Type - The Type of file to retrieve
396 SectionType - The type of section to retrieve from a file
398 FileName - The name of the file found in the Firmware Volume
400 Pe32Data - Pointer to the beginning of the PE/COFF file found in the Firmware Volume
404 EFI_SUCCESS - The file was found, and the name is returned in FileName, and a pointer to
405 the PE/COFF image is returned in Pe32Data
407 EFI_NOT_FOUND - The file was not found in the Firmware Volumes present in the HOB List
411 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
412 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
415 EFI_PEI_HOB_POINTERS Hob
;
419 FfsFileHeader
= NULL
;
423 // Foreach Firmware Volume, look for a specified type
424 // of file and break out when one is found
426 Hob
.Raw
= GetHobList ();
427 while ((Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_FV
, Hob
.Raw
)) != NULL
) {
428 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) (Hob
.FirmwareVolume
->BaseAddress
);
429 Status
= PeiServicesFfsFindNextFile (
434 if (!EFI_ERROR (Status
)) {
435 Status
= PeiProcessFile (
441 CopyMem (FileName
, &FfsFileHeader
->Name
, sizeof (EFI_GUID
));
444 Hob
.Raw
= GET_NEXT_HOB (Hob
);
446 return EFI_NOT_FOUND
;
451 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
,
453 IN EFI_MEMORY_TYPE MemoryType
,
454 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
455 OUT UINT64
*ImageSize
,
456 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
462 Loads and relocates a PE/COFF image into memory.
466 PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol
468 Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
470 ImageAddress - The base address of the relocated PE/COFF image
472 ImageSize - The size of the relocated PE/COFF image
474 EntryPoint - The entry point of the relocated PE/COFF image
478 EFI_SUCCESS - The file was loaded and relocated
479 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
484 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
485 EFI_PHYSICAL_ADDRESS MemoryBuffer
;
487 ZeroMem (&ImageContext
, sizeof (ImageContext
));
488 ImageContext
.Handle
= Pe32Data
;
489 Status
= GetImageReadFunction (&ImageContext
);
491 ASSERT_EFI_ERROR (Status
);
493 Status
= PeiEfiPeiPeCoffLoader
->GetImageInfo (PeiEfiPeiPeCoffLoader
, &ImageContext
);
494 if (EFI_ERROR (Status
)) {
498 // Allocate Memory for the image
501 // Allocate Memory for the image
503 PeiServicesAllocatePages (MemoryType
, EFI_SIZE_TO_PAGES ((UINT32
) ImageContext
.ImageSize
), &MemoryBuffer
);
504 ImageContext
.ImageAddress
= MemoryBuffer
;
505 ASSERT (ImageContext
.ImageAddress
!= 0);
508 // Load the image to our new buffer
511 Status
= PeiEfiPeiPeCoffLoader
->LoadImage (PeiEfiPeiPeCoffLoader
, &ImageContext
);
512 if (EFI_ERROR (Status
)) {
517 // Relocate the image in our new buffer
519 Status
= PeiEfiPeiPeCoffLoader
->RelocateImage (PeiEfiPeiPeCoffLoader
, &ImageContext
);
520 if (EFI_ERROR (Status
)) {
525 // Flush the instruction cache so the image data is written before we execute it
527 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)ImageContext
.ImageAddress
, (UINTN
)ImageContext
.ImageSize
);
529 *ImageAddress
= ImageContext
.ImageAddress
;
530 *ImageSize
= ImageContext
.ImageSize
;
531 *EntryPoint
= ImageContext
.EntryPoint
;
538 IN EFI_FFS_FILE_HEADER
*DxeIplFileHeader
,
539 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
545 Shadow the DXE IPL to a different memory location. This occurs after permanent
546 memory has been discovered.
550 DxeIplFileHeader - Pointer to the FFS file header of the DXE IPL driver
552 PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol
556 EFI_SUCCESS - DXE IPL was successfully shadowed to a different memory location.
558 EFI_ ERROR - The shadow was unsuccessful.
564 UINTN OccupiedSectionLength
;
565 EFI_PHYSICAL_ADDRESS DxeIplAddress
;
567 EFI_PHYSICAL_ADDRESS DxeIplEntryPoint
;
569 EFI_COMMON_SECTION_HEADER
*Section
;
571 Section
= (EFI_COMMON_SECTION_HEADER
*) (DxeIplFileHeader
+ 1);
573 while ((Section
->Type
!= EFI_SECTION_PE32
) && (Section
->Type
!= EFI_SECTION_TE
)) {
574 SectionLength
= *(UINT32
*) (Section
->Size
) & 0x00ffffff;
575 OccupiedSectionLength
= GetOccupiedSize (SectionLength
, 4);
576 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ OccupiedSectionLength
);
580 // Relocate DxeIpl into memory by using loadfile service
582 Status
= PeiLoadPeImage (
583 PeiEfiPeiPeCoffLoader
,
584 (VOID
*) (Section
+ 1),
591 if (Status
== EFI_SUCCESS
) {
593 // Install PeiInMemory to indicate the Dxeipl is shadowed
595 Status
= PeiServicesInstallPpi (&mPpiPeiInMemory
);
597 if (EFI_ERROR (Status
)) {
601 Status
= ((EFI_PEIM_ENTRY_POINT
) (UINTN
) DxeIplEntryPoint
) (DxeIplFileHeader
, GetPeiServicesTablePointer());
610 IN EFI_PEI_FV_FILE_LOADER_PPI
*This
,
611 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
612 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
613 OUT UINT64
*ImageSize
,
614 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
620 Given a pointer to an FFS file containing a PE32 image, get the
621 information on the PE32 image, and then "load" it so that it
626 This - pointer to our file loader protocol
627 FfsHeader - pointer to the FFS file header of the FFS file that
628 contains the PE32 image we want to load
629 ImageAddress - returned address where the PE32 image is loaded
630 ImageSize - returned size of the loaded PE32 image
631 EntryPoint - entry point to the loaded PE32 image
635 EFI_SUCCESS - The FFS file was successfully loaded.
636 EFI_ERROR - Unable to load the FFS file.
640 EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
;
645 PeiEfiPeiPeCoffLoader
= (EFI_PEI_PE_COFF_LOADER_PROTOCOL
*)GetPeCoffLoaderProtocol ();
648 // Preprocess the FFS file to get a pointer to the PE32 information
649 // in the enclosed PE32 image.
651 Status
= PeiProcessFile (
658 if (EFI_ERROR (Status
)) {
662 // Load the PE image from the FFS file
664 Status
= PeiLoadPeImage (
665 PeiEfiPeiPeCoffLoader
,
678 IN UINT16 SectionType
,
679 IN OUT EFI_FFS_FILE_HEADER
**RealFfsFileHeader
,
681 IN EFI_PEI_HOB_POINTERS
*OrigHob
689 SectionType - The type of section in the FFS file to process.
691 FfsFileHeader - Pointer to the FFS file to process, looking for the
692 specified SectionType
694 Pe32Data - returned pointer to the start of the PE32 image found
699 EFI_SUCCESS - found the PE32 section in the FFS file
705 DECOMPRESS_LIBRARY
*DecompressLibrary
;
707 UINT8
*ScratchBuffer
;
708 UINT32 DstBufferSize
;
709 UINT32 ScratchBufferSize
;
710 EFI_COMMON_SECTION_HEADER
*CmpSection
;
711 UINTN CmpSectionLength
;
712 UINTN OccupiedCmpSectionLength
;
715 EFI_COMMON_SECTION_HEADER
*Section
;
717 UINTN OccupiedSectionLength
;
719 EFI_GUID_DEFINED_SECTION
*GuidedSectionHeader
;
720 UINT32 AuthenticationStatus
;
721 EFI_PEI_SECTION_EXTRACTION_PPI
*SectionExtract
;
724 EFI_PEI_SECURITY_PPI
*Security
;
725 BOOLEAN StartCrisisRecovery
;
727 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
728 EFI_COMPRESSION_SECTION
*CompressionSection
;
729 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
731 FfsFileHeader
= *RealFfsFileHeader
;
733 Status
= PeiServicesFfsFindSectionData (
734 EFI_SECTION_COMPRESSION
,
740 // Upon finding a DXE Core file, see if there is first a compression section
742 if (!EFI_ERROR (Status
)) {
744 // Yes, there is a compression section, so extract the contents
745 // Decompress the image here
747 Section
= (EFI_COMMON_SECTION_HEADER
*) (UINTN
) (VOID
*) ((UINT8
*) (FfsFileHeader
) + (UINTN
) sizeof (EFI_FFS_FILE_HEADER
));
750 SectionLength
= *(UINT32
*) (Section
->Size
) & 0x00ffffff;
751 OccupiedSectionLength
= GetOccupiedSize (SectionLength
, 4);
754 // Was the DXE Core file encapsulated in a GUID'd section?
756 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
758 // Locate the GUID'd Section Extractor
760 GuidedSectionHeader
= (VOID
*) (Section
+ 1);
763 // This following code constitutes the addition of the security model
767 // Set a default authenticatino state
769 AuthenticationStatus
= 0;
771 Status
= PeiServicesLocatePpi (
772 &gEfiPeiSectionExtractionPpiGuid
,
775 (VOID
**)&SectionExtract
778 if (EFI_ERROR (Status
)) {
782 // Verify Authentication State
784 CopyMem (&TempGuid
, Section
+ 1, sizeof (EFI_GUID
));
786 Status
= SectionExtract
->PeiGetSection (
787 GetPeiServicesTablePointer(),
789 (EFI_SECTION_TYPE
*) &SectionType
,
794 &AuthenticationStatus
797 if (EFI_ERROR (Status
)) {
801 // If not ask the Security PPI, if exists, for disposition
804 Status
= PeiServicesLocatePpi (
805 &gEfiPeiSecurityPpiGuid
,
810 if (EFI_ERROR (Status
)) {
814 Status
= Security
->AuthenticationState (
815 GetPeiServicesTablePointer(),
816 (struct _EFI_PEI_SECURITY_PPI
*) Security
,
817 AuthenticationStatus
,
822 if (EFI_ERROR (Status
)) {
826 // If there is a security violation, report to caller and have
827 // the upper-level logic possible engender a crisis recovery
829 if (StartCrisisRecovery
) {
830 return EFI_SECURITY_VIOLATION
;
834 if (Section
->Type
== EFI_SECTION_PE32
) {
836 // This is what we want
838 *Pe32Data
= (VOID
*) (Section
+ 1);
840 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
842 // This is a compression set, expand it
844 CompressionSection
= (EFI_COMPRESSION_SECTION
*) Section
;
846 switch (CompressionSection
->CompressionType
) {
847 case EFI_STANDARD_COMPRESSION
:
848 if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress
)) {
849 DecompressLibrary
= &gTianoDecompress
;
852 return EFI_NOT_FOUND
;
856 case EFI_CUSTOMIZED_COMPRESSION
:
858 // Load user customized compression protocol.
860 if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress
)) {
861 DecompressLibrary
= &gCustomDecompress
;
864 return EFI_NOT_FOUND
;
868 case EFI_NOT_COMPRESSED
:
871 // Need to support not compressed file
873 ASSERT_EFI_ERROR (Status
);
874 return EFI_NOT_FOUND
;
877 Status
= DecompressLibrary
->GetInfo (
878 (UINT8
*) ((EFI_COMPRESSION_SECTION
*) Section
+ 1),
879 (UINT32
) SectionLength
- sizeof (EFI_COMPRESSION_SECTION
),
883 if (EFI_ERROR (Status
)) {
887 return EFI_NOT_FOUND
;
891 // Allocate scratch buffer
893 ScratchBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize
));
894 if (ScratchBuffer
== NULL
) {
895 return EFI_OUT_OF_RESOURCES
;
899 // Allocate destination buffer
901 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
902 if (DstBuffer
== NULL
) {
903 return EFI_OUT_OF_RESOURCES
;
907 // Call decompress function
909 Status
= DecompressLibrary
->Decompress (
910 (CHAR8
*) ((EFI_COMPRESSION_SECTION
*) Section
+ 1),
915 CmpSection
= (EFI_COMMON_SECTION_HEADER
*) DstBuffer
;
916 if (CmpSection
->Type
== EFI_SECTION_RAW
) {
918 // Skip the section header and
919 // adjust the pointer alignment to 16
921 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (DstBuffer
+ 16);
923 if (FvHeader
->Signature
== EFI_FVH_SIGNATURE
) {
924 FfsFileHeader
= NULL
;
925 BuildFvHob ((EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
, FvHeader
->FvLength
);
926 Status
= PeiServicesFfsFindNextFile (
927 EFI_FV_FILETYPE_DXE_CORE
,
932 if (EFI_ERROR (Status
)) {
933 return EFI_NOT_FOUND
;
936 if (OrigHob
!= NULL
) {
939 OrigHob
->Header
->HobType
= EFI_HOB_TYPE_UNUSED
;
943 // Reture the FfsHeader that contain Pe32Data.
945 *RealFfsFileHeader
= FfsFileHeader
;
946 return PeiProcessFile (SectionType
, RealFfsFileHeader
, Pe32Data
, OrigHob
);
950 // Decompress successfully.
951 // Loop the decompressed data searching for expected section.
953 CmpFileData
= (VOID
*) DstBuffer
;
954 CmpFileSize
= DstBufferSize
;
956 CmpSectionLength
= *(UINT32
*) (CmpSection
->Size
) & 0x00ffffff;
957 if (CmpSection
->Type
== EFI_SECTION_PE32
) {
959 // This is what we want
961 *Pe32Data
= (VOID
*) (CmpSection
+ 1);
965 OccupiedCmpSectionLength
= GetOccupiedSize (CmpSectionLength
, 4);
966 CmpSection
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) CmpSection
+ OccupiedCmpSectionLength
);
967 } while (CmpSection
->Type
!= 0 && (UINTN
) ((UINT8
*) CmpSection
- (UINT8
*) CmpFileData
) < CmpFileSize
);
970 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ OccupiedSectionLength
);
971 FileSize
= FfsFileHeader
->Size
[0] & 0xFF;
972 FileSize
+= (FfsFileHeader
->Size
[1] << 8) & 0xFF00;
973 FileSize
+= (FfsFileHeader
->Size
[2] << 16) & 0xFF0000;
974 FileSize
&= 0x00FFFFFF;
975 } while (Section
->Type
!= 0 && (UINTN
) ((UINT8
*) Section
- (UINT8
*) FfsFileHeader
) < FileSize
);
978 // End of the decompression activity
982 Status
= PeiServicesFfsFindSectionData (
988 if (EFI_ERROR (Status
)) {
989 Status
= PeiServicesFfsFindSectionData (
994 if (EFI_ERROR (Status
)) {
1000 *Pe32Data
= SectionData
;