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 // porting note remove later
26 #include "DecompressLibrary.h"
27 #include "FrameworkPei.h"
28 // end of remove later
30 BOOLEAN gInMemory
= FALSE
;
33 // Module Globals used in the DXE to PEI handoff
34 // These must be module globals, so the stack can be switched
36 static EFI_DXE_IPL_PPI mDxeIplPpi
= {
40 static EFI_PEI_FV_FILE_LOADER_PPI mLoadFilePpi
= {
44 static EFI_PEI_PPI_DESCRIPTOR mPpiList
[] = {
46 EFI_PEI_PPI_DESCRIPTOR_PPI
,
47 &gEfiPeiFvFileLoaderPpiGuid
,
51 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
57 static EFI_PEI_PPI_DESCRIPTOR mPpiSignal
= {
58 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
59 &gEfiEndOfPeiSignalPpiGuid
,
63 GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY gEfiDecompress
= {
64 UefiDecompressGetInfo
,
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 (PcdDxeIplSupportCustomDecompress
)) {
275 // Add HOB for the user customized Decompress Protocol
278 &gEfiCustomizedDecompressProtocolGuid
,
279 (VOID
*)&gCustomDecompress
,
280 sizeof (gCustomDecompress
)
285 // Add HOB for the PE/COFF Loader Protocol
288 &gEfiPeiPeCoffLoaderGuid
,
289 (VOID
*)&PeiEfiPeiPeCoffLoader
,
295 // Transfer control to the DXE Core
296 // The handoff state is simply a pointer to the HOB list
299 DEBUG ((EFI_D_INFO
, "DXE Core Entry Point 0x%08x\n", (UINTN
) DxeCoreEntryPoint
));
300 HandOffToDxeCore (DxeCoreEntryPoint
, HobList
, &mPpiSignal
);
302 // If we get here, then the DXE Core returned. This is an error
303 // Dxe Core should not return.
308 return EFI_OUT_OF_RESOURCES
;
314 IN UINT16 SectionType
,
315 OUT EFI_GUID
*FileName
,
322 Finds a PE/COFF of a specific Type and SectionType in the Firmware Volumes
323 described in the HOB list. Able to search in a compression set in a FFS file.
324 But only one level of compression is supported, that is, not able to search
325 in a compression set that is within another compression set.
329 Type - The Type of file to retrieve
331 SectionType - The type of section to retrieve from a file
333 FileName - The name of the file found in the Firmware Volume
335 Pe32Data - Pointer to the beginning of the PE/COFF file found in the Firmware Volume
339 EFI_SUCCESS - The file was found, and the name is returned in FileName, and a pointer to
340 the PE/COFF image is returned in Pe32Data
342 EFI_NOT_FOUND - The file was not found in the Firmware Volumes present in the HOB List
346 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
347 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
349 EFI_PEI_HOB_POINTERS Hob
;
353 FfsFileHeader
= NULL
;
354 Status
= EFI_SUCCESS
;
357 // For each Firmware Volume, look for a specified type
358 // of file and break out until no one is found
360 Hob
.Raw
= GetHobList ();
361 while ((Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_FV
, Hob
.Raw
)) != NULL
) {
362 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) (Hob
.FirmwareVolume
->BaseAddress
);
364 // Make sure the FV HOB does not get corrupted.
366 ASSERT (FwVolHeader
->Signature
== EFI_FVH_SIGNATURE
);
368 Status
= PeiServicesFfsFindNextFile (
373 if (!EFI_ERROR (Status
)) {
374 Status
= PeiProcessFile (
380 CopyMem (FileName
, &FfsFileHeader
->Name
, sizeof (EFI_GUID
));
382 // Find all Fv type ffs to get all FvImage and add them into FvHob
384 if (!EFI_ERROR (Status
) && (Type
!= EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
388 Hob
.Raw
= GET_NEXT_HOB (Hob
);
390 return EFI_NOT_FOUND
;
395 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
,
397 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
398 OUT UINT64
*ImageSize
,
399 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
405 Loads and relocates a PE/COFF image into memory.
409 PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol
411 Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
413 ImageAddress - The base address of the relocated PE/COFF image
415 ImageSize - The size of the relocated PE/COFF image
417 EntryPoint - The entry point of the relocated PE/COFF image
421 EFI_SUCCESS - The file was loaded and relocated
423 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
428 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
430 ZeroMem (&ImageContext
, sizeof (ImageContext
));
431 ImageContext
.Handle
= Pe32Data
;
432 Status
= GetImageReadFunction (&ImageContext
);
434 ASSERT_EFI_ERROR (Status
);
436 Status
= PeiEfiPeiPeCoffLoader
->GetImageInfo (PeiEfiPeiPeCoffLoader
, &ImageContext
);
437 if (EFI_ERROR (Status
)) {
441 // Allocate Memory for the image
443 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32
) ImageContext
.ImageSize
));
444 ASSERT (ImageContext
.ImageAddress
!= 0);
447 // Load the image to our new buffer
449 Status
= PeiEfiPeiPeCoffLoader
->LoadImage (PeiEfiPeiPeCoffLoader
, &ImageContext
);
450 if (EFI_ERROR (Status
)) {
454 // Relocate the image in our new buffer
456 Status
= PeiEfiPeiPeCoffLoader
->RelocateImage (PeiEfiPeiPeCoffLoader
, &ImageContext
);
457 if (EFI_ERROR (Status
)) {
462 // Flush the instruction cache so the image data is written before we execute it
464 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)ImageContext
.ImageAddress
, (UINTN
)ImageContext
.ImageSize
);
466 *ImageAddress
= ImageContext
.ImageAddress
;
467 *ImageSize
= ImageContext
.ImageSize
;
468 *EntryPoint
= ImageContext
.EntryPoint
;
475 IN EFI_FFS_FILE_HEADER
*DxeIplFileHeader
,
476 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
482 Shadow the DXE IPL to a different memory location. This occurs after permanent
483 memory has been discovered.
487 DxeIplFileHeader - Pointer to the FFS file header of the DXE IPL driver
489 PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol
493 EFI_SUCCESS - DXE IPL was successfully shadowed to a different memory location.
495 EFI_ ERROR - The shadow was unsuccessful.
501 UINTN OccupiedSectionLength
;
502 EFI_PHYSICAL_ADDRESS DxeIplAddress
;
504 EFI_PHYSICAL_ADDRESS DxeIplEntryPoint
;
506 EFI_COMMON_SECTION_HEADER
*Section
;
508 Section
= (EFI_COMMON_SECTION_HEADER
*) (DxeIplFileHeader
+ 1);
510 while ((Section
->Type
!= EFI_SECTION_PE32
) && (Section
->Type
!= EFI_SECTION_TE
)) {
511 SectionLength
= *(UINT32
*) (Section
->Size
) & 0x00ffffff;
512 OccupiedSectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
513 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ OccupiedSectionLength
);
516 // Relocate DxeIpl into memory by using loadfile service
518 Status
= PeiLoadFile (
519 PeiEfiPeiPeCoffLoader
,
520 (VOID
*) (Section
+ 1),
526 if (Status
== EFI_SUCCESS
) {
528 // Set gInMemory global variable to TRUE to indicate the dxeipl is shadowed.
530 *(BOOLEAN
*) ((UINTN
) &gInMemory
+ (UINTN
) DxeIplEntryPoint
- (UINTN
) _ModuleEntryPoint
) = TRUE
;
531 Status
= ((EFI_PEIM_ENTRY_POINT
) (UINTN
) DxeIplEntryPoint
) ((EFI_PEI_FILE_HANDLE
*) DxeIplFileHeader
, GetPeiServicesTablePointer());
540 IN EFI_PEI_FV_FILE_LOADER_PPI
*This
,
541 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
542 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
543 OUT UINT64
*ImageSize
,
544 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
550 Given a pointer to an FFS file containing a PE32 image, get the
551 information on the PE32 image, and then "load" it so that it
556 This - pointer to our file loader protocol
558 FfsHeader - pointer to the FFS file header of the FFS file that
559 contains the PE32 image we want to load
561 ImageAddress - returned address where the PE32 image is loaded
563 ImageSize - returned size of the loaded PE32 image
565 EntryPoint - entry point to the loaded PE32 image
569 EFI_SUCCESS - The FFS file was successfully loaded.
571 EFI_ERROR - Unable to load the FFS file.
575 EFI_PEI_PE_COFF_LOADER_PROTOCOL
*PeiEfiPeiPeCoffLoader
;
580 PeiEfiPeiPeCoffLoader
= (EFI_PEI_PE_COFF_LOADER_PROTOCOL
*)GetPeCoffLoaderProtocol ();
583 // Preprocess the FFS file to get a pointer to the PE32 information
584 // in the enclosed PE32 image.
586 Status
= PeiProcessFile (
593 if (EFI_ERROR (Status
)) {
597 // Load the PE image from the FFS file
599 Status
= PeiLoadFile (
600 PeiEfiPeiPeCoffLoader
,
612 IN UINT16 SectionType
,
613 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
615 IN EFI_PEI_HOB_POINTERS
*OrigHob
623 SectionType - The type of section in the FFS file to process.
625 FfsFileHeader - Pointer to the FFS file to process, looking for the
626 specified SectionType
628 Pe32Data - returned pointer to the start of the PE32 image found
633 EFI_SUCCESS - found the PE32 section in the FFS file
639 DECOMPRESS_LIBRARY
*DecompressLibrary
;
641 UINT8
*ScratchBuffer
;
642 UINT32 DstBufferSize
;
643 UINT32 ScratchBufferSize
;
644 EFI_COMMON_SECTION_HEADER
*CmpSection
;
645 UINTN CmpSectionLength
;
646 UINTN OccupiedCmpSectionLength
;
649 EFI_COMMON_SECTION_HEADER
*Section
;
651 UINTN OccupiedSectionLength
;
653 UINT32 AuthenticationStatus
;
654 EFI_PEI_SECTION_EXTRACTION_PPI
*SectionExtract
;
657 EFI_PEI_SECURITY_PPI
*Security
;
658 BOOLEAN StartCrisisRecovery
;
660 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
661 EFI_COMPRESSION_SECTION
*CompressionSection
;
664 // Initialize local variables.
666 DecompressLibrary
= NULL
;
670 Status
= PeiServicesFfsFindSectionData (
671 EFI_SECTION_COMPRESSION
,
677 // First process the compression section
679 if (!EFI_ERROR (Status
)) {
681 // Yes, there is a compression section, so extract the contents
682 // Decompress the image here
684 Section
= (EFI_COMMON_SECTION_HEADER
*) (UINTN
) (VOID
*) ((UINT8
*) (FfsFileHeader
) + (UINTN
) sizeof (EFI_FFS_FILE_HEADER
));
687 SectionLength
= *(UINT32
*) (Section
->Size
) & 0x00ffffff;
688 OccupiedSectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
691 // Was the DXE Core file encapsulated in a GUID'd section?
693 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
696 // This following code constitutes the addition of the security model
700 // Set a default authenticatino state
702 AuthenticationStatus
= 0;
704 Status
= PeiServicesLocatePpi (
705 &gEfiPeiSectionExtractionPpiGuid
,
708 (VOID
**)&SectionExtract
711 if (EFI_ERROR (Status
)) {
715 // Verify Authentication State
717 CopyMem (&TempGuid
, Section
+ 1, sizeof (EFI_GUID
));
719 Status
= SectionExtract
->PeiGetSection (
720 GetPeiServicesTablePointer(),
722 (EFI_SECTION_TYPE
*) &SectionType
,
727 &AuthenticationStatus
730 if (EFI_ERROR (Status
)) {
734 // If not ask the Security PPI, if exists, for disposition
737 Status
= PeiServicesLocatePpi (
738 &gEfiPeiSecurityPpiGuid
,
743 if (EFI_ERROR (Status
)) {
747 Status
= Security
->AuthenticationState (
748 GetPeiServicesTablePointer(),
749 (struct _EFI_PEI_SECURITY_PPI
*) Security
,
750 AuthenticationStatus
,
755 if (EFI_ERROR (Status
)) {
759 // If there is a security violation, report to caller and have
760 // the upper-level logic possible engender a crisis recovery
762 if (StartCrisisRecovery
) {
763 return EFI_SECURITY_VIOLATION
;
767 if (Section
->Type
== EFI_SECTION_PE32
) {
769 // This is what we want
771 *Pe32Data
= (VOID
*) (Section
+ 1);
773 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
775 // This is a compression set, expand it
777 CompressionSection
= (EFI_COMPRESSION_SECTION
*) Section
;
779 switch (CompressionSection
->CompressionType
) {
780 case EFI_STANDARD_COMPRESSION
:
782 // Load EFI standard compression.
784 if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress
)) {
785 DecompressLibrary
= &gEfiDecompress
;
788 return EFI_NOT_FOUND
;
792 // porting note the original branch for customized compress is removed, it should be change to use GUID compress
794 case EFI_NOT_COMPRESSED
:
796 // Allocate destination buffer
798 DstBufferSize
= CompressionSection
->UncompressedLength
;
799 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
800 if (DstBuffer
== NULL
) {
801 return EFI_OUT_OF_RESOURCES
;
804 // stream is not actually compressed, just encapsulated. So just copy it.
806 CopyMem (DstBuffer
, CompressionSection
+ 1, DstBufferSize
);
811 // Don't support other unknown compression type.
813 ASSERT_EFI_ERROR (Status
);
814 return EFI_NOT_FOUND
;
817 if (CompressionSection
->CompressionType
!= EFI_NOT_COMPRESSED
) {
819 // For compressed data, decompress them to dstbuffer.
821 Status
= DecompressLibrary
->GetInfo (
822 (UINT8
*) ((EFI_COMPRESSION_SECTION
*) Section
+ 1),
823 (UINT32
) SectionLength
- sizeof (EFI_COMPRESSION_SECTION
),
827 if (EFI_ERROR (Status
)) {
831 DEBUG ((EFI_D_ERROR
, "Decompress GetInfo Failed - %r\n", Status
));
832 return EFI_NOT_FOUND
;
836 // Allocate scratch buffer
838 ScratchBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize
));
839 if (ScratchBuffer
== NULL
) {
840 return EFI_OUT_OF_RESOURCES
;
844 // Allocate destination buffer
846 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
847 if (DstBuffer
== NULL
) {
848 return EFI_OUT_OF_RESOURCES
;
852 // Call decompress function
854 Status
= DecompressLibrary
->Decompress (
855 (CHAR8
*) ((EFI_COMPRESSION_SECTION
*) Section
+ 1),
859 if (EFI_ERROR (Status
)) {
863 DEBUG ((EFI_D_ERROR
, "Decompress Failed - %r\n", Status
));
864 return EFI_NOT_FOUND
;
869 // Decompress successfully.
870 // Loop the decompressed data searching for expected section.
872 CmpSection
= (EFI_COMMON_SECTION_HEADER
*) DstBuffer
;
873 CmpFileData
= (VOID
*) DstBuffer
;
874 CmpFileSize
= DstBufferSize
;
876 CmpSectionLength
= *(UINT32
*) (CmpSection
->Size
) & 0x00ffffff;
877 if (CmpSection
->Type
== SectionType
) {
879 // This is what we want
881 if (SectionType
== EFI_SECTION_PE32
) {
882 *Pe32Data
= (VOID
*) (CmpSection
+ 1);
884 } else if (SectionType
== EFI_SECTION_FIRMWARE_VOLUME_IMAGE
) {
886 // Firmware Volume Image in this Section
887 // Skip the section header to get FvHeader
889 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (CmpSection
+ 1);
891 if (FvHeader
->Signature
== EFI_FVH_SIGNATURE
) {
893 // Because FvLength in FvHeader is UINT64 type,
894 // so FvHeader must meed at least 8 bytes alignment.
895 // If current FvImage base address doesn't meet its alignment,
896 // we need to reload this FvImage to another correct memory address.
898 if (((UINTN
) FvHeader
% sizeof (UINT64
)) != 0) {
899 DstBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINTN
) CmpSectionLength
- sizeof (EFI_COMMON_SECTION_HEADER
)), sizeof (UINT64
));
900 if (DstBuffer
== NULL
) {
901 return EFI_OUT_OF_RESOURCES
;
903 CopyMem (DstBuffer
, FvHeader
, (UINTN
) CmpSectionLength
- sizeof (EFI_COMMON_SECTION_HEADER
));
904 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) DstBuffer
;
908 // Build new FvHob for new decompressed Fv image.
910 BuildFvHob ((EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
, FvHeader
->FvLength
);
913 // Set the original FvHob to unused.
915 if (OrigHob
!= NULL
) {
916 OrigHob
->Header
->HobType
= EFI_HOB_TYPE_UNUSED
;
920 // return found FvImage data.
922 *Pe32Data
= (VOID
*) FvHeader
;
927 OccupiedCmpSectionLength
= GET_OCCUPIED_SIZE (CmpSectionLength
, 4);
928 CmpSection
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) CmpSection
+ OccupiedCmpSectionLength
);
929 } while (CmpSection
->Type
!= 0 && (UINTN
) ((UINT8
*) CmpSection
- (UINT8
*) CmpFileData
) < CmpFileSize
);
932 // End of the decompression activity
935 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ OccupiedSectionLength
);
936 FileSize
= FfsFileHeader
->Size
[0] & 0xFF;
937 FileSize
+= (FfsFileHeader
->Size
[1] << 8) & 0xFF00;
938 FileSize
+= (FfsFileHeader
->Size
[2] << 16) & 0xFF0000;
939 FileSize
&= 0x00FFFFFF;
940 } while (Section
->Type
!= 0 && (UINTN
) ((UINT8
*) Section
- (UINT8
*) FfsFileHeader
) < FileSize
);
943 // search all sections (compression and non compression) in this FFS, don't
944 // find expected section.
946 return EFI_NOT_FOUND
;
949 // For those FFS that doesn't contain compression section, directly search
950 // PE or TE section in this FFS.
953 Status
= PeiServicesFfsFindSectionData (
959 if (EFI_ERROR (Status
)) {
960 Status
= PeiServicesFfsFindSectionData (
965 if (EFI_ERROR (Status
)) {
971 *Pe32Data
= SectionData
;