TianoCore EDK2 master
Loading...
Searching...
No Matches
Image.c File Reference
#include "PeiMain.h"

Go to the source code of this file.

Functions

EFI_STATUS EFIAPI PeiImageRead (IN VOID *FileHandle, IN UINTN FileOffset, IN UINTN *ReadSize, OUT VOID *Buffer)
 
EFI_STATUS CheckAndMarkFixLoadingMemoryUsageBitMap (IN PEI_CORE_INSTANCE *Private, IN EFI_PHYSICAL_ADDRESS ImageBase, IN UINT32 ImageSize)
 
EFI_STATUS GetPeCoffImageFixLoadingAssignedAddress (IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, IN PEI_CORE_INSTANCE *Private)
 
EFI_STATUS LoadAndRelocatePeCoffImage (IN EFI_PEI_FILE_HANDLE FileHandle, IN VOID *Pe32Data, OUT EFI_PHYSICAL_ADDRESS *ImageAddress, OUT UINT64 *ImageSize, OUT EFI_PHYSICAL_ADDRESS *EntryPoint)
 
EFI_STATUS LoadAndRelocatePeCoffImageInPlace (IN VOID *Pe32Data, IN VOID *ImageAddress)
 
EFI_STATUS PeiGetPe32Data (IN EFI_PEI_FILE_HANDLE FileHandle, OUT VOID **Pe32Data)
 
EFI_STATUS PeiLoadImageLoadImage (IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_FILE_HANDLE FileHandle, OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg OPTIONAL, OUT UINT64 *ImageSizeArg OPTIONAL, OUT EFI_PHYSICAL_ADDRESS *EntryPoint, OUT UINT32 *AuthenticationState)
 
EFI_STATUS EFIAPI PeiLoadImageLoadImageWrapper (IN CONST EFI_PEI_LOAD_FILE_PPI *This, IN EFI_PEI_FILE_HANDLE FileHandle, OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg OPTIONAL, OUT UINT64 *ImageSizeArg OPTIONAL, OUT EFI_PHYSICAL_ADDRESS *EntryPoint, OUT UINT32 *AuthenticationState)
 
BOOLEAN RelocationIsStrip (IN VOID *Pe32Data)
 
EFI_STATUS PeiLoadImage (IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_FILE_HANDLE FileHandle, IN UINT8 PeimState, OUT EFI_PHYSICAL_ADDRESS *EntryPoint, OUT UINT32 *AuthenticationState)
 
VOID InitializeImageServices (IN PEI_CORE_INSTANCE *PrivateData, IN PEI_CORE_INSTANCE *OldCoreData)
 

Variables

EFI_PEI_LOAD_FILE_PPI mPeiLoadImagePpi
 
EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList
 

Detailed Description

Pei Core Load Image Support

Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Image.c.

Function Documentation

◆ CheckAndMarkFixLoadingMemoryUsageBitMap()

EFI_STATUS CheckAndMarkFixLoadingMemoryUsageBitMap ( IN PEI_CORE_INSTANCE Private,
IN EFI_PHYSICAL_ADDRESS  ImageBase,
IN UINT32  ImageSize 
)

To check memory usage bit map array to figure out if the memory range the image will be loaded in is available or not. If memory range is available, the function will mark the corresponding bits to 1 which indicates the memory range is used. The function is only invoked when load modules at fixed address feature is enabled.

Parameters
PrivatePointer to the private data passed in from caller
ImageBaseThe base address the image will be loaded at.
ImageSizeThe size of the image
Return values
EFI_SUCCESSThe memory range the image will be loaded in is available
EFI_NOT_FOUNDThe memory range the image will be loaded in is not available

Definition at line 68 of file Image.c.

◆ GetPeCoffImageFixLoadingAssignedAddress()

EFI_STATUS GetPeCoffImageFixLoadingAssignedAddress ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT ImageContext,
IN PEI_CORE_INSTANCE Private 
)

Get the fixed loading address from image header assigned by build tool. This function only be called when Loading module at Fixed address feature enabled.

Parameters
ImageContextPointer to the image context structure that describes the PE/COFF image that needs to be examined by this function.
PrivatePointer to the private data passed in from caller
Return values
EFI_SUCCESSAn fixed loading address is assigned to this image by build tools .
EFI_NOT_FOUNDThe image has no assigned fixed loading address.

Definition at line 138 of file Image.c.

◆ InitializeImageServices()

VOID InitializeImageServices ( IN PEI_CORE_INSTANCE PrivateData,
IN PEI_CORE_INSTANCE OldCoreData 
)

Install Pei Load File PPI.

Parameters
PrivateData- Pointer to PEI_CORE_INSTANCE.
OldCoreData- Pointer to PEI_CORE_INSTANCE.

Definition at line 959 of file Image.c.

◆ LoadAndRelocatePeCoffImage()

EFI_STATUS LoadAndRelocatePeCoffImage ( IN EFI_PEI_FILE_HANDLE  FileHandle,
IN VOID Pe32Data,
OUT EFI_PHYSICAL_ADDRESS ImageAddress,
OUT UINT64 *  ImageSize,
OUT EFI_PHYSICAL_ADDRESS EntryPoint 
)

Loads and relocates a PE/COFF image into memory. If the image is not relocatable, it will not be loaded into memory and be loaded as XIP image.

Parameters
FileHandle- Pointer to the FFS file header of the image.
Pe32Data- The base address of the PE/COFF file that is to be loaded and relocated
ImageAddress- The base address of the relocated PE/COFF image
ImageSize- The size of the relocated PE/COFF image
EntryPoint- The entry point of the relocated PE/COFF image
Return values
EFI_SUCCESSThe file was loaded and relocated
EFI_OUT_OF_RESOURCESThere was not enough memory to load and relocate the PE/COFF file
EFI_WARN_BUFFER_TOO_SMALLThere is not enough heap to allocate the requested size. This will not prevent the XIP image from being invoked.

Definition at line 265 of file Image.c.

◆ LoadAndRelocatePeCoffImageInPlace()

EFI_STATUS LoadAndRelocatePeCoffImageInPlace ( IN VOID Pe32Data,
IN VOID ImageAddress 
)

Loads and relocates a PE/COFF image in place.

Parameters
Pe32DataThe base address of the PE/COFF file that is to be loaded and relocated
ImageAddressThe base address of the relocated PE/COFF image
Return values
EFI_SUCCESSThe file was loaded and relocated.
OthersThe file not be loaded and error occurred.

Definition at line 482 of file Image.c.

◆ PeiGetPe32Data()

EFI_STATUS PeiGetPe32Data ( IN EFI_PEI_FILE_HANDLE  FileHandle,
OUT VOID **  Pe32Data 
)

Find the PE32 Data for an FFS file.

Parameters
FileHandlePointer to the FFS file header of the image.
Pe32DataPointer to a (VOID *) PE32 Data pointer.
Return values
EFI_SUCCESSImage is successfully loaded.
EFI_NOT_FOUNDFail to locate PE32 Data.

Definition at line 541 of file Image.c.

◆ PeiImageRead()

EFI_STATUS EFIAPI PeiImageRead ( IN VOID FileHandle,
IN UINTN  FileOffset,
IN UINTN ReadSize,
OUT VOID Buffer 
)

Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file. The function is used for XIP code to have optimized memory copy.

Parameters
FileHandle- The handle to the PE/COFF file
FileOffset- The offset, in bytes, into the file to read
ReadSize- The number of bytes to read from the file starting at FileOffset
Buffer- A pointer to the buffer to read the data into.
Returns
EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset

Definition at line 36 of file Image.c.

◆ PeiLoadImage()

EFI_STATUS PeiLoadImage ( IN CONST EFI_PEI_SERVICES **  PeiServices,
IN EFI_PEI_FILE_HANDLE  FileHandle,
IN UINT8  PeimState,
OUT EFI_PHYSICAL_ADDRESS EntryPoint,
OUT UINT32 *  AuthenticationState 
)

Routine to load image file for subsequent execution by LoadFile Ppi. If any LoadFile Ppi is not found, the build-in support function for the PE32+/TE XIP image format is used.

Parameters
PeiServices- An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
FileHandle- Pointer to the FFS file header of the image.
PeimState- The dispatch state of the input PEIM handle.
EntryPoint- Pointer to entry point of specified image file for output.
AuthenticationState- Pointer to attestation authentication state of image.
Return values
EFI_SUCCESS- Image is successfully loaded.
EFI_NOT_FOUND- Fail to locate necessary PPI
Others- Fail to load file.

Definition at line 881 of file Image.c.

◆ PeiLoadImageLoadImage()

EFI_STATUS PeiLoadImageLoadImage ( IN CONST EFI_PEI_SERVICES **  PeiServices,
IN EFI_PEI_FILE_HANDLE  FileHandle,
OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg  OPTIONAL,
OUT UINT64 *ImageSizeArg  OPTIONAL,
OUT EFI_PHYSICAL_ADDRESS EntryPoint,
OUT UINT32 *  AuthenticationState 
)

Loads a PEIM into memory for subsequent execution. If there are compressed images or images that need to be relocated into memory for performance reasons, this service performs that transformation.

Parameters
PeiServicesAn indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
FileHandlePointer to the FFS file header of the image.
ImageAddressArgPointer to PE/TE image.
ImageSizeArgSize of PE/TE image.
EntryPointPointer to entry point of specified image file for output.
AuthenticationState- Pointer to attestation authentication state of image.
Return values
EFI_SUCCESSImage is successfully loaded.
EFI_NOT_FOUNDFail to locate necessary PPI.
EFI_UNSUPPORTEDImage Machine Type is not supported.
EFI_WARN_BUFFER_TOO_SMALLThere is not enough heap to allocate the requested size. This will not prevent the XIP image from being invoked.

Definition at line 609 of file Image.c.

◆ PeiLoadImageLoadImageWrapper()

EFI_STATUS EFIAPI PeiLoadImageLoadImageWrapper ( IN CONST EFI_PEI_LOAD_FILE_PPI This,
IN EFI_PEI_FILE_HANDLE  FileHandle,
OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg  OPTIONAL,
OUT UINT64 *ImageSizeArg  OPTIONAL,
OUT EFI_PHYSICAL_ADDRESS EntryPoint,
OUT UINT32 *  AuthenticationState 
)

The wrapper function of PeiLoadImageLoadImage().

Parameters
This- Pointer to EFI_PEI_LOAD_FILE_PPI.
FileHandle- Pointer to the FFS file header of the image.
ImageAddressArg- Pointer to PE/TE image.
ImageSizeArg- Size of PE/TE image.
EntryPoint- Pointer to entry point of specified image file for output.
AuthenticationState- Pointer to attestation authentication state of image.
Returns
Status of PeiLoadImageLoadImage().

Definition at line 785 of file Image.c.

◆ RelocationIsStrip()

BOOLEAN RelocationIsStrip ( IN VOID Pe32Data)

Check whether the input image has the relocation.

Parameters
Pe32DataPointer to the PE/COFF or TE image.
Return values
TRUERelocation is stripped.
FALSERelocation is not stripped.

Definition at line 814 of file Image.c.

Variable Documentation

◆ gPpiLoadFilePpiList

EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList
Initial value:
= {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiLoadFilePpiGuid,
&mPeiLoadImagePpi
}

Definition at line 15 of file Image.c.

◆ mPeiLoadImagePpi

EFI_PEI_LOAD_FILE_PPI mPeiLoadImagePpi
Initial value:
= {
}
EFI_STATUS EFIAPI PeiLoadImageLoadImageWrapper(IN CONST EFI_PEI_LOAD_FILE_PPI *This, IN EFI_PEI_FILE_HANDLE FileHandle, OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg OPTIONAL, OUT UINT64 *ImageSizeArg OPTIONAL, OUT EFI_PHYSICAL_ADDRESS *EntryPoint, OUT UINT32 *AuthenticationState)
Definition: Image.c:785

Definition at line 11 of file Image.c.