2015-10-19 21:10:14 +02:00
|
|
|
/** @file
|
|
|
|
Locate the entry point for the PEI Core
|
|
|
|
|
2019-02-19 08:30:23 +01:00
|
|
|
Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:07:22 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2015-10-19 21:10:14 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
|
|
|
#include "SecMain.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Find core image base.
|
|
|
|
|
2019-02-19 08:30:23 +01:00
|
|
|
@param FirmwareVolumePtr Point to the firmware volume for finding core image.
|
|
|
|
@param FileType The FileType for searching, either SecCore or PeiCore.
|
|
|
|
@param CoreImageBase The base address of the core image.
|
2015-10-19 21:10:14 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FindImageBase (
|
2019-02-19 08:30:23 +01:00
|
|
|
IN EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumePtr,
|
|
|
|
IN EFI_FV_FILETYPE FileType,
|
|
|
|
OUT EFI_PHYSICAL_ADDRESS *CoreImageBase
|
2015-10-19 21:10:14 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_PHYSICAL_ADDRESS CurrentAddress;
|
|
|
|
EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;
|
|
|
|
EFI_FFS_FILE_HEADER *File;
|
|
|
|
UINT32 Size;
|
|
|
|
EFI_PHYSICAL_ADDRESS EndOfFile;
|
|
|
|
EFI_COMMON_SECTION_HEADER *Section;
|
|
|
|
EFI_PHYSICAL_ADDRESS EndOfSection;
|
|
|
|
|
2019-02-19 08:30:23 +01:00
|
|
|
*CoreImageBase = 0;
|
2015-10-19 21:10:14 +02:00
|
|
|
|
2019-02-19 08:30:23 +01:00
|
|
|
CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumePtr;
|
|
|
|
EndOfFirmwareVolume = CurrentAddress + FirmwareVolumePtr->FvLength;
|
2015-10-19 21:10:14 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Loop through the FFS files in the Boot Firmware Volume
|
|
|
|
//
|
2019-02-19 08:30:23 +01:00
|
|
|
for (EndOfFile = CurrentAddress + FirmwareVolumePtr->HeaderLength; ; ) {
|
2015-10-19 21:10:14 +02:00
|
|
|
CurrentAddress = (EndOfFile + 7) & 0xfffffffffffffff8ULL;
|
|
|
|
if (CurrentAddress > EndOfFirmwareVolume) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
File = (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress;
|
|
|
|
if (IS_FFS_FILE2 (File)) {
|
|
|
|
Size = FFS_FILE2_SIZE (File);
|
|
|
|
if (Size <= 0x00FFFFFF) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Size = FFS_FILE_SIZE (File);
|
|
|
|
if (Size < sizeof (EFI_FFS_FILE_HEADER)) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EndOfFile = CurrentAddress + Size;
|
|
|
|
if (EndOfFile > EndOfFirmwareVolume) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-02-19 08:30:23 +01:00
|
|
|
// Look for particular Core file (either SEC Core or PEI Core)
|
2015-10-19 21:10:14 +02:00
|
|
|
//
|
2019-02-19 08:30:23 +01:00
|
|
|
if (File->Type != FileType) {
|
2015-10-19 21:10:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Loop through the FFS file sections within the FFS file
|
|
|
|
//
|
|
|
|
if (IS_FFS_FILE2 (File)) {
|
|
|
|
EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)((UINT8 *)File + sizeof (EFI_FFS_FILE_HEADER2));
|
|
|
|
} else {
|
|
|
|
EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)((UINT8 *)File + sizeof (EFI_FFS_FILE_HEADER));
|
|
|
|
}
|
2021-12-05 23:54:17 +01:00
|
|
|
|
2015-10-19 21:10:14 +02:00
|
|
|
for ( ; ;) {
|
|
|
|
CurrentAddress = (EndOfSection + 3) & 0xfffffffffffffffcULL;
|
|
|
|
Section = (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress;
|
|
|
|
|
|
|
|
if (IS_SECTION2 (Section)) {
|
|
|
|
Size = SECTION2_SIZE (Section);
|
|
|
|
if (Size <= 0x00FFFFFF) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Size = SECTION_SIZE (Section);
|
|
|
|
if (Size < sizeof (EFI_COMMON_SECTION_HEADER)) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EndOfSection = CurrentAddress + Size;
|
|
|
|
if (EndOfSection > EndOfFile) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Look for executable sections
|
|
|
|
//
|
|
|
|
if ((Section->Type == EFI_SECTION_PE32) || (Section->Type == EFI_SECTION_TE)) {
|
2019-02-19 08:30:23 +01:00
|
|
|
if (File->Type == FileType) {
|
2015-10-19 21:10:14 +02:00
|
|
|
if (IS_SECTION2 (Section)) {
|
2019-02-19 08:30:23 +01:00
|
|
|
*CoreImageBase = (PHYSICAL_ADDRESS)(UINTN)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2));
|
2015-10-19 21:10:14 +02:00
|
|
|
} else {
|
2019-02-19 08:30:23 +01:00
|
|
|
*CoreImageBase = (PHYSICAL_ADDRESS)(UINTN)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER));
|
2015-10-19 21:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 23:54:17 +01:00
|
|
|
|
2015-10-19 21:10:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-02-19 08:30:23 +01:00
|
|
|
// Either SEC Core or PEI Core images found
|
2015-10-19 21:10:14 +02:00
|
|
|
//
|
2019-02-19 08:30:23 +01:00
|
|
|
if (*CoreImageBase != 0) {
|
2015-10-19 21:10:14 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Find and return Pei Core entry point.
|
|
|
|
|
|
|
|
It also find SEC and PEI Core file debug information. It will report them if
|
|
|
|
remote debug is enabled.
|
|
|
|
|
2019-02-19 08:30:23 +01:00
|
|
|
@param SecCoreFirmwareVolumePtr Point to the firmware volume for finding SecCore.
|
|
|
|
@param PeiCoreFirmwareVolumePtr Point to the firmware volume for finding PeiCore.
|
2015-10-19 21:10:14 +02:00
|
|
|
@param PeiCoreEntryPoint The entry point of the PEI core.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
FindAndReportEntryPoints (
|
2019-02-19 08:30:23 +01:00
|
|
|
IN EFI_FIRMWARE_VOLUME_HEADER *SecCoreFirmwareVolumePtr,
|
|
|
|
IN EFI_FIRMWARE_VOLUME_HEADER *PeiCoreFirmwareVolumePtr,
|
2015-10-19 21:10:14 +02:00
|
|
|
OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PHYSICAL_ADDRESS SecCoreImageBase;
|
|
|
|
EFI_PHYSICAL_ADDRESS PeiCoreImageBase;
|
|
|
|
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
|
|
|
|
|
|
|
|
//
|
2019-02-19 08:30:23 +01:00
|
|
|
// Find SEC Core image base
|
2015-10-19 21:10:14 +02:00
|
|
|
//
|
2019-02-19 08:30:23 +01:00
|
|
|
Status = FindImageBase (SecCoreFirmwareVolumePtr, EFI_FV_FILETYPE_SECURITY_CORE, &SecCoreImageBase);
|
2015-10-19 21:10:14 +02:00
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
ZeroMem ((VOID *)&ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));
|
|
|
|
//
|
|
|
|
// Report SEC Core debug information when remote debug is enabled
|
|
|
|
//
|
|
|
|
ImageContext.ImageAddress = SecCoreImageBase;
|
|
|
|
ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);
|
|
|
|
PeCoffLoaderRelocateImageExtraAction (&ImageContext);
|
|
|
|
|
2019-02-19 08:30:23 +01:00
|
|
|
//
|
|
|
|
// Find PEI Core image base
|
|
|
|
//
|
|
|
|
Status = FindImageBase (PeiCoreFirmwareVolumePtr, EFI_FV_FILETYPE_PEI_CORE, &PeiCoreImageBase);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2015-10-19 21:10:14 +02:00
|
|
|
//
|
|
|
|
// Report PEI Core debug information when remote debug is enabled
|
|
|
|
//
|
|
|
|
ImageContext.ImageAddress = PeiCoreImageBase;
|
|
|
|
ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);
|
|
|
|
PeCoffLoaderRelocateImageExtraAction (&ImageContext);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Find PEI Core entry point
|
|
|
|
//
|
|
|
|
Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)PeiCoreImageBase, (VOID **)PeiCoreEntryPoint);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
*PeiCoreEntryPoint = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|