2 Pei Core Load Image Support
4 Copyright (c) 2006 - 2010, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_PEI_LOAD_FILE_PPI mPeiLoadImagePpi
= {
19 PeiLoadImageLoadImageWrapper
23 EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList
= {
24 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
25 &gEfiPeiLoadFilePpiGuid
,
31 Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
34 @param FileHandle - The handle to the PE/COFF file
35 @param FileOffset - The offset, in bytes, into the file to read
36 @param ReadSize - The number of bytes to read from the file starting at FileOffset
37 @param Buffer - A pointer to the buffer to read the data into.
39 @return EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
55 Destination8
= Buffer
;
56 Source8
= (CHAR8
*) ((UINTN
) FileHandle
+ FileOffset
);
57 if (Destination8
!= Source8
) {
59 while ((Length
--) > 0) {
60 *(Destination8
++) = *(Source8
++);
69 Support routine to get the Image read file function.
71 @param ImageContext - The context of the image being loaded
73 @retval EFI_SUCCESS - If Image function location is found
77 GetImageReadFunction (
78 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
81 PEI_CORE_INSTANCE
*Private
;
84 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
86 if (!Private
->PeiMemoryInstalled
|| (Private
->HobList
.HandoffInformationTable
->BootMode
== BOOT_ON_S3_RESUME
)) {
87 ImageContext
->ImageRead
= PeiImageRead
;
89 MemoryBuffer
= AllocatePages (0x400 / EFI_PAGE_SIZE
+ 1);
90 ASSERT (MemoryBuffer
!= NULL
);
92 CopyMem (MemoryBuffer
, (CONST VOID
*) (UINTN
) PeiImageRead
, 0x400);
94 ImageContext
->ImageRead
= (PE_COFF_LOADER_READ_FILE
) (UINTN
) MemoryBuffer
;
100 To check memory usage bit map arry to figure out if the memory range the image will be loaded in is available or not. If
101 memory range is avaliable, the function will mark the correponding bits to 1 which indicates the memory range is used.
102 The function is only invoked when load modules at fixed address feature is enabled.
104 @param Private Pointer to the private data passed in from caller
105 @param ImageBase The base addres the image will be loaded at.
106 @param ImageSize The size of the image
108 @retval EFI_SUCCESS The memory range the image will be loaded in is available
109 @retval EFI_NOT_FOUND The memory range the image will be loaded in is not available
112 CheckAndMarkFixLoadingMemoryUsageBitMap (
113 IN PEI_CORE_INSTANCE
*Private
,
114 IN EFI_PHYSICAL_ADDRESS ImageBase
,
118 UINT32 DxeCodePageNumber
;
119 UINT64 ReservedCodeSize
;
120 EFI_PHYSICAL_ADDRESS PeiCodeBase
;
121 UINT32 BaseOffsetPageNumber
;
122 UINT32 TopOffsetPageNumber
;
124 UINT64
*MemoryUsageBitMap
;
128 // The reserved code range includes RuntimeCodePage range, Boot time code range and PEI code range.
130 DxeCodePageNumber
= PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber
);
131 DxeCodePageNumber
+= PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber
);
132 ReservedCodeSize
= EFI_PAGES_TO_SIZE(DxeCodePageNumber
+ PcdGet32(PcdLoadFixAddressPeiCodePageNumber
));
133 PeiCodeBase
= Private
->LoadModuleAtFixAddressTopAddress
- ReservedCodeSize
;
136 // Test the memory range for loading the image in the PEI code range.
138 if ((Private
->LoadModuleAtFixAddressTopAddress
- EFI_PAGES_TO_SIZE(DxeCodePageNumber
)) < (ImageBase
+ ImageSize
) ||
139 (PeiCodeBase
> ImageBase
)) {
140 return EFI_NOT_FOUND
;
144 // Test if the memory is avalaible or not.
146 MemoryUsageBitMap
= Private
->PeiCodeMemoryRangeUsageBitMap
;
147 BaseOffsetPageNumber
= EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
- PeiCodeBase
));
148 TopOffsetPageNumber
= EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
+ ImageSize
- PeiCodeBase
));
149 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
150 if ((MemoryUsageBitMap
[Index
/ 64] & LShiftU64(1, (Index
% 64))) != 0) {
152 // This page is already used.
154 return EFI_NOT_FOUND
;
159 // Being here means the memory range is available. So mark the bits for the memory range
161 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
162 MemoryUsageBitMap
[Index
/ 64] |= LShiftU64(1, (Index
% 64));
168 Get the fixed loadding address from image header assigned by build tool. This function only be called
169 when Loading module at Fixed address feature enabled.
171 @param ImageContext Pointer to the image context structure that describes the PE/COFF
172 image that needs to be examined by this function.
173 @param Private Pointer to the private data passed in from caller
175 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
176 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
180 GetPeCoffImageFixLoadingAssignedAddress(
181 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
182 IN PEI_CORE_INSTANCE
*Private
185 UINTN SectionHeaderOffset
;
187 EFI_IMAGE_SECTION_HEADER SectionHeader
;
188 EFI_IMAGE_OPTIONAL_HEADER_UNION
*ImgHdr
;
189 EFI_PHYSICAL_ADDRESS FixLoaddingAddress
;
192 UINT16 NumberOfSections
;
193 UINT64 ValueInSectionHeader
;
196 FixLoaddingAddress
= 0;
197 Status
= EFI_NOT_FOUND
;
200 // Get PeHeader pointer
202 ImgHdr
= (EFI_IMAGE_OPTIONAL_HEADER_UNION
*)((CHAR8
* )ImageContext
->Handle
+ ImageContext
->PeCoffHeaderOffset
);
203 if (ImageContext
->IsTeImage
) {
205 // for TE image, the fix loadding address is saved in first section header that doesn't point
208 SectionHeaderOffset
= sizeof (EFI_TE_IMAGE_HEADER
);
209 NumberOfSections
= ImgHdr
->Te
.NumberOfSections
;
211 SectionHeaderOffset
= (UINTN
)(
212 ImageContext
->PeCoffHeaderOffset
+
214 sizeof (EFI_IMAGE_FILE_HEADER
) +
215 ImgHdr
->Pe32
.FileHeader
.SizeOfOptionalHeader
217 NumberOfSections
= ImgHdr
->Pe32
.FileHeader
.NumberOfSections
;
220 // Get base address from the first section header that doesn't point to code section.
222 for (Index
= 0; Index
< NumberOfSections
; Index
++) {
224 // Read section header from file
226 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
227 Status
= ImageContext
->ImageRead (
228 ImageContext
->Handle
,
233 if (EFI_ERROR (Status
)) {
237 Status
= EFI_NOT_FOUND
;
239 if ((SectionHeader
.Characteristics
& EFI_IMAGE_SCN_CNT_CODE
) == 0) {
241 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
242 // that doesn't point to code section in image header, as well as ImageBase field of image header. A notable thing is
243 // that for PEIM, the value in ImageBase field may not be equal to the value in PointerToRelocations & PointerToLineNumbers because
244 // for XIP PEIM, ImageBase field holds the image base address running on the Flash. And PointerToRelocations & PointerToLineNumbers
245 // hold the image base address when it is shadow to the memory. And there is an assumption that when the feature is enabled, if a
246 // module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers fields should NOT be Zero, or
247 // else, these 2 fileds should be set to Zero
249 ValueInSectionHeader
= ReadUnaligned64((UINT64
*)&SectionHeader
.PointerToRelocations
);
250 if (ValueInSectionHeader
!= 0) {
252 // Found first section header that doesn't point to code section.
254 if ((INT64
)FixedPcdGet64(PcdLoadModuleAtFixAddressEnable
) > 0) {
256 // When LMFA feature is configured as Load Module at Fixed Absolute Address mode, PointerToRelocations & PointerToLineNumbers field
257 // hold the absolute address of image base runing in memory
259 FixLoaddingAddress
= ValueInSectionHeader
;
262 // When LMFA feature is configured as Load Module at Fixed offset mode, PointerToRelocations & PointerToLineNumbers field
263 // hold the offset relative to a platform-specific top address.
265 FixLoaddingAddress
= (EFI_PHYSICAL_ADDRESS
)(Private
->LoadModuleAtFixAddressTopAddress
+ (INT64
)ValueInSectionHeader
);
268 // Check if the memory range is avaliable.
270 Status
= CheckAndMarkFixLoadingMemoryUsageBitMap (Private
, FixLoaddingAddress
, (UINT32
) ImageContext
->ImageSize
);
271 if (!EFI_ERROR(Status
)) {
273 // The assigned address is valid. Return the specified loadding address
275 ImageContext
->ImageAddress
= FixLoaddingAddress
;
280 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
282 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED INFO: Loading module at fixed address %lx. Status= %r \n", FixLoaddingAddress
, Status
));
287 Loads and relocates a PE/COFF image into memory.
288 If the image is not relocatable, it will not be loaded into memory and be loaded as XIP image.
290 @param Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
291 @param ImageAddress - The base address of the relocated PE/COFF image
292 @param ImageSize - The size of the relocated PE/COFF image
293 @param EntryPoint - The entry point of the relocated PE/COFF image
295 @retval EFI_SUCCESS The file was loaded and relocated
296 @retval EFI_OUT_OF_RESOURCES There was not enough memory to load and relocate the PE/COFF file
300 LoadAndRelocatePeCoffImage (
302 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
303 OUT UINT64
*ImageSize
,
304 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
308 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
309 PEI_CORE_INSTANCE
*Private
;
311 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
313 ZeroMem (&ImageContext
, sizeof (ImageContext
));
314 ImageContext
.Handle
= Pe32Data
;
315 Status
= GetImageReadFunction (&ImageContext
);
317 ASSERT_EFI_ERROR (Status
);
319 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
320 if (EFI_ERROR (Status
)) {
324 // When Image has no reloc section, it can't be relocated into memory.
326 if (ImageContext
.RelocationsStripped
&& (Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
327 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN
) Pe32Data
));
331 // Set default base address to current image address.
333 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) Pe32Data
;
336 // Allocate Memory for the image when memory is ready, boot mode is not S3, and image is relocatable.
338 if ((!ImageContext
.RelocationsStripped
) && (Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
339 if (FixedPcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0) {
340 Status
= GetPeCoffImageFixLoadingAssignedAddress(&ImageContext
, Private
);
341 if (EFI_ERROR (Status
)){
342 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED ERROR: Failed to load module at fixed address. \n"));
344 // The PEIM is not assiged valid address, try to allocate page to load it.
346 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32
) ImageContext
.ImageSize
));
349 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32
) ImageContext
.ImageSize
));
351 ASSERT (ImageContext
.ImageAddress
!= 0);
352 if (ImageContext
.ImageAddress
== 0) {
353 return EFI_OUT_OF_RESOURCES
;
357 // Skip the reserved space for the stripped PeHeader when load TeImage into memory.
359 if (ImageContext
.IsTeImage
) {
360 ImageContext
.ImageAddress
= ImageContext
.ImageAddress
+
361 ((EFI_TE_IMAGE_HEADER
*) Pe32Data
)->StrippedSize
-
362 sizeof (EFI_TE_IMAGE_HEADER
);
367 // Load the image to our new buffer
369 Status
= PeCoffLoaderLoadImage (&ImageContext
);
370 if (EFI_ERROR (Status
)) {
374 // Relocate the image in our new buffer
376 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
377 if (EFI_ERROR (Status
)) {
382 // Flush the instruction cache so the image data is written before we execute it
384 if ((!ImageContext
.RelocationsStripped
) && (Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
385 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)ImageContext
.ImageAddress
, (UINTN
)ImageContext
.ImageSize
);
388 *ImageAddress
= ImageContext
.ImageAddress
;
389 *ImageSize
= ImageContext
.ImageSize
;
390 *EntryPoint
= ImageContext
.EntryPoint
;
396 Loads a PEIM into memory for subsequent execution. If there are compressed
397 images or images that need to be relocated into memory for performance reasons,
398 this service performs that transformation.
400 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
401 @param FileHandle Pointer to the FFS file header of the image.
402 @param ImageAddressArg Pointer to PE/TE image.
403 @param ImageSizeArg Size of PE/TE image.
404 @param EntryPoint Pointer to entry point of specified image file for output.
405 @param AuthenticationState - Pointer to attestation authentication state of image.
407 @retval EFI_SUCCESS Image is successfully loaded.
408 @retval EFI_NOT_FOUND Fail to locate necessary PPI.
409 @retval EFI_UNSUPPORTED Image Machine Type is not supported.
413 PeiLoadImageLoadImage (
414 IN CONST EFI_PEI_SERVICES
**PeiServices
,
415 IN EFI_PEI_FILE_HANDLE FileHandle
,
416 OUT EFI_PHYSICAL_ADDRESS
*ImageAddressArg
, OPTIONAL
417 OUT UINT64
*ImageSizeArg
, OPTIONAL
418 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
,
419 OUT UINT32
*AuthenticationState
424 EFI_PHYSICAL_ADDRESS ImageAddress
;
426 EFI_PHYSICAL_ADDRESS ImageEntryPoint
;
428 EFI_SECTION_TYPE SearchType1
;
429 EFI_SECTION_TYPE SearchType2
;
433 *AuthenticationState
= 0;
435 if (FeaturePcdGet (PcdPeiCoreImageLoaderSearchTeSectionFirst
)) {
436 SearchType1
= EFI_SECTION_TE
;
437 SearchType2
= EFI_SECTION_PE32
;
439 SearchType1
= EFI_SECTION_PE32
;
440 SearchType2
= EFI_SECTION_TE
;
444 // Try to find a first exe section (if PcdPeiCoreImageLoaderSearchTeSectionFirst
445 // is true, TE will be searched first).
447 Status
= PeiServicesFfsFindSectionData (
453 // If we didn't find a first exe section, try to find the second exe section.
455 if (EFI_ERROR (Status
)) {
456 Status
= PeiServicesFfsFindSectionData (
461 if (EFI_ERROR (Status
)) {
463 // PEI core only carry the loader function fro TE and PE32 executables
464 // If this two section does not exist, just return.
471 // If memory is installed, perform the shadow operations
473 Status
= LoadAndRelocatePeCoffImage (
480 ASSERT_EFI_ERROR (Status
);
483 if (EFI_ERROR (Status
)) {
488 // Got the entry point from the loaded Pe32Data
490 Pe32Data
= (VOID
*) ((UINTN
) ImageAddress
);
491 *EntryPoint
= ImageEntryPoint
;
493 Machine
= PeCoffLoaderGetMachineType (Pe32Data
);
495 if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Machine
)) {
496 if (!EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED (Machine
)) {
497 return EFI_UNSUPPORTED
;
501 if (ImageAddressArg
!= NULL
) {
502 *ImageAddressArg
= ImageAddress
;
505 if (ImageSizeArg
!= NULL
) {
506 *ImageSizeArg
= ImageSize
;
511 CHAR8 AsciiBuffer
[512];
516 // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
518 if (Machine
!= EFI_IMAGE_MACHINE_IA64
) {
519 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID
*)(UINTN
)ImageAddress
, (VOID
*)(UINTN
)*EntryPoint
));
522 // For IPF Image, the real entry point should be print.
524 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID
*)(UINTN
)ImageAddress
, (VOID
*)(UINTN
)(*(UINT64
*)(UINTN
)*EntryPoint
)));
528 // Print Module Name by PeImage PDB file name.
530 AsciiString
= PeCoffLoaderGetPdbPointer (Pe32Data
);
532 if (AsciiString
!= NULL
) {
533 for (Index
= (INT32
) AsciiStrLen (AsciiString
) - 1; Index
>= 0; Index
--) {
534 if (AsciiString
[Index
] == '\\') {
540 for (Index1
= 0; AsciiString
[Index
+ 1 + Index1
] != '.'; Index1
++) {
541 AsciiBuffer
[Index1
] = AsciiString
[Index
+ 1 + Index1
];
543 AsciiBuffer
[Index1
] = '\0';
544 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "%a.efi", AsciiBuffer
));
550 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "\n"));
558 The wrapper function of PeiLoadImageLoadImage().
560 @param This - Pointer to EFI_PEI_LOAD_FILE_PPI.
561 @param FileHandle - Pointer to the FFS file header of the image.
562 @param ImageAddressArg - Pointer to PE/TE image.
563 @param ImageSizeArg - Size of PE/TE image.
564 @param EntryPoint - Pointer to entry point of specified image file for output.
565 @param AuthenticationState - Pointer to attestation authentication state of image.
567 @return Status of PeiLoadImageLoadImage().
572 PeiLoadImageLoadImageWrapper (
573 IN CONST EFI_PEI_LOAD_FILE_PPI
*This
,
574 IN EFI_PEI_FILE_HANDLE FileHandle
,
575 OUT EFI_PHYSICAL_ADDRESS
*ImageAddressArg
, OPTIONAL
576 OUT UINT64
*ImageSizeArg
, OPTIONAL
577 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
,
578 OUT UINT32
*AuthenticationState
581 return PeiLoadImageLoadImage (
582 GetPeiServicesTablePointer (),
592 Check whether the input image has the relocation.
594 @param Pe32Data Pointer to the PE/COFF or TE image.
596 @retval TRUE Relocation is stripped.
597 @retval FALSE Relocation is not stripped.
605 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
606 EFI_IMAGE_DOS_HEADER
*DosHdr
;
608 ASSERT (Pe32Data
!= NULL
);
610 DosHdr
= (EFI_IMAGE_DOS_HEADER
*)Pe32Data
;
611 if (DosHdr
->e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
613 // DOS image header is present, so read the PE header after the DOS image header.
615 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)((UINTN
) Pe32Data
+ (UINTN
) ((DosHdr
->e_lfanew
) & 0x0ffff));
618 // DOS image header is not present, so PE header is at the image base.
620 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)Pe32Data
;
624 // Three cases with regards to relocations:
625 // - Image has base relocs, RELOCS_STRIPPED==0 => image is relocatable
626 // - Image has no base relocs, RELOCS_STRIPPED==1 => Image is not relocatable
627 // - Image has no base relocs, RELOCS_STRIPPED==0 => Image is relocatable but
628 // has no base relocs to apply
629 // Obviously having base relocations with RELOCS_STRIPPED==1 is invalid.
631 // Look at the file header to determine if relocations have been stripped, and
632 // save this info in the image context for later use.
634 if (Hdr
.Te
->Signature
== EFI_TE_IMAGE_HEADER_SIGNATURE
) {
635 if ((Hdr
.Te
->DataDirectory
[0].Size
== 0) && (Hdr
.Te
->DataDirectory
[0].VirtualAddress
== 0)) {
640 } else if (Hdr
.Pe32
->Signature
== EFI_IMAGE_NT_SIGNATURE
) {
641 if ((Hdr
.Pe32
->FileHeader
.Characteristics
& EFI_IMAGE_FILE_RELOCS_STRIPPED
) != 0) {
652 Routine to load image file for subsequent execution by LoadFile Ppi.
653 If any LoadFile Ppi is not found, the build-in support function for the PE32+/TE
654 XIP image format is used.
656 @param PeiServices - An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
657 @param FileHandle - Pointer to the FFS file header of the image.
658 @param PeimState - The dispatch state of the input PEIM handle.
659 @param EntryPoint - Pointer to entry point of specified image file for output.
660 @param AuthenticationState - Pointer to attestation authentication state of image.
662 @retval EFI_SUCCESS - Image is successfully loaded.
663 @retval EFI_NOT_FOUND - Fail to locate necessary PPI
664 @retval Others - Fail to load file.
669 IN CONST EFI_PEI_SERVICES
**PeiServices
,
670 IN EFI_PEI_FILE_HANDLE FileHandle
,
672 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
,
673 OUT UINT32
*AuthenticationState
676 EFI_STATUS PpiStatus
;
679 EFI_PEI_LOAD_FILE_PPI
*LoadFile
;
680 EFI_PHYSICAL_ADDRESS ImageAddress
;
686 // If any instances of PEI_LOAD_FILE_PPI are installed, they are called.
687 // one at a time, until one reports EFI_SUCCESS.
691 PpiStatus
= PeiServicesLocatePpi (
692 &gEfiPeiLoadFilePpiGuid
,
697 if (!EFI_ERROR (PpiStatus
)) {
698 Status
= LoadFile
->LoadFile (
706 if (!EFI_ERROR (Status
)) {
708 // The shadowed PEIM must be relocatable.
710 if (PeimState
== PEIM_STATE_REGISITER_FOR_SHADOW
) {
711 IsStrip
= RelocationIsStrip ((VOID
*) (UINTN
) ImageAddress
);
714 return EFI_UNSUPPORTED
;
719 // The image to be started must have the machine type supported by PeiCore.
721 ASSERT (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCoffLoaderGetMachineType ((VOID
*) (UINTN
) ImageAddress
)));
722 if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCoffLoaderGetMachineType ((VOID
*) (UINTN
) ImageAddress
))) {
723 return EFI_UNSUPPORTED
;
729 } while (!EFI_ERROR (PpiStatus
));
737 Install Pei Load File PPI.
740 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
741 @param OldCoreData - Pointer to PEI_CORE_INSTANCE.
745 InitializeImageServices (
746 IN PEI_CORE_INSTANCE
*PrivateData
,
747 IN PEI_CORE_INSTANCE
*OldCoreData
750 if (OldCoreData
== NULL
) {
752 // The first time we are XIP (running from FLASH). We need to remember the
753 // FLASH address so we can reinstall the memory version that runs faster
755 PrivateData
->XipLoadFile
= &gPpiLoadFilePpiList
;
756 PeiServicesInstallPpi (PrivateData
->XipLoadFile
);
759 // 2nd time we are running from memory so replace the XIP version with the
760 // new memory version.
762 PeiServicesReInstallPpi (PrivateData
->XipLoadFile
, &gPpiLoadFilePpiList
);