TianoCore EDK2 master
Loading...
Searching...
No Matches
FindPeiCore.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10
11#include "SecMain.h"
12
22EFIAPI
24 IN EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumePtr,
25 IN EFI_FV_FILETYPE FileType,
26 OUT EFI_PHYSICAL_ADDRESS *CoreImageBase
27 )
28{
29 EFI_PHYSICAL_ADDRESS CurrentAddress;
30 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;
32 UINT32 Size;
33 EFI_PHYSICAL_ADDRESS EndOfFile;
35 EFI_PHYSICAL_ADDRESS EndOfSection;
36
37 *CoreImageBase = 0;
38
39 CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumePtr;
40 EndOfFirmwareVolume = CurrentAddress + FirmwareVolumePtr->FvLength;
41
42 //
43 // Loop through the FFS files in the Boot Firmware Volume
44 //
45 for (EndOfFile = CurrentAddress + FirmwareVolumePtr->HeaderLength; ; ) {
46 CurrentAddress = (EndOfFile + 7) & 0xfffffffffffffff8ULL;
47 if (CurrentAddress > EndOfFirmwareVolume) {
48 return EFI_NOT_FOUND;
49 }
50
51 File = (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress;
52 if (IS_FFS_FILE2 (File)) {
53 Size = FFS_FILE2_SIZE (File);
54 if (Size <= 0x00FFFFFF) {
55 return EFI_NOT_FOUND;
56 }
57 } else {
58 Size = FFS_FILE_SIZE (File);
59 if (Size < sizeof (EFI_FFS_FILE_HEADER)) {
60 return EFI_NOT_FOUND;
61 }
62 }
63
64 EndOfFile = CurrentAddress + Size;
65 if (EndOfFile > EndOfFirmwareVolume) {
66 return EFI_NOT_FOUND;
67 }
68
69 //
70 // Look for particular Core file (either SEC Core or PEI Core)
71 //
72 if (File->Type != FileType) {
73 continue;
74 }
75
76 //
77 // Loop through the FFS file sections within the FFS file
78 //
79 if (IS_FFS_FILE2 (File)) {
80 EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)((UINT8 *)File + sizeof (EFI_FFS_FILE_HEADER2));
81 } else {
82 EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)((UINT8 *)File + sizeof (EFI_FFS_FILE_HEADER));
83 }
84
85 for ( ; ;) {
86 CurrentAddress = (EndOfSection + 3) & 0xfffffffffffffffcULL;
87 Section = (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress;
88
89 if (IS_SECTION2 (Section)) {
90 Size = SECTION2_SIZE (Section);
91 if (Size <= 0x00FFFFFF) {
92 return EFI_NOT_FOUND;
93 }
94 } else {
95 Size = SECTION_SIZE (Section);
96 if (Size < sizeof (EFI_COMMON_SECTION_HEADER)) {
97 return EFI_NOT_FOUND;
98 }
99 }
100
101 EndOfSection = CurrentAddress + Size;
102 if (EndOfSection > EndOfFile) {
103 return EFI_NOT_FOUND;
104 }
105
106 //
107 // Look for executable sections
108 //
109 if ((Section->Type == EFI_SECTION_PE32) || (Section->Type == EFI_SECTION_TE)) {
110 if (File->Type == FileType) {
111 if (IS_SECTION2 (Section)) {
112 *CoreImageBase = (PHYSICAL_ADDRESS)(UINTN)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2));
113 } else {
114 *CoreImageBase = (PHYSICAL_ADDRESS)(UINTN)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER));
115 }
116 }
117
118 break;
119 }
120 }
121
122 //
123 // Either SEC Core or PEI Core images found
124 //
125 if (*CoreImageBase != 0) {
126 return EFI_SUCCESS;
127 }
128 }
129}
130
142VOID
143EFIAPI
145 IN EFI_FIRMWARE_VOLUME_HEADER *SecCoreFirmwareVolumePtr,
146 IN EFI_FIRMWARE_VOLUME_HEADER *PeiCoreFirmwareVolumePtr,
147 OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint
148 )
149{
150 EFI_STATUS Status;
151 EFI_PHYSICAL_ADDRESS SecCoreImageBase;
152 EFI_PHYSICAL_ADDRESS PeiCoreImageBase;
153 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
154
155 //
156 // Find SEC Core image base
157 //
158 Status = FindImageBase (SecCoreFirmwareVolumePtr, EFI_FV_FILETYPE_SECURITY_CORE, &SecCoreImageBase);
159 ASSERT_EFI_ERROR (Status);
160
161 ZeroMem ((VOID *)&ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));
162 //
163 // Report SEC Core debug information when remote debug is enabled
164 //
165 ImageContext.ImageAddress = SecCoreImageBase;
166 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);
168
169 //
170 // Find PEI Core image base
171 //
172 Status = FindImageBase (PeiCoreFirmwareVolumePtr, EFI_FV_FILETYPE_PEI_CORE, &PeiCoreImageBase);
173 ASSERT_EFI_ERROR (Status);
174
175 //
176 // Report PEI Core debug information when remote debug is enabled
177 //
178 ImageContext.ImageAddress = PeiCoreImageBase;
179 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);
181
182 //
183 // Find PEI Core entry point
184 //
185 Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)PeiCoreImageBase, (VOID **)PeiCoreEntryPoint);
186 if (EFI_ERROR (Status)) {
187 *PeiCoreEntryPoint = 0;
188 }
189
190 return;
191}
UINT64 UINTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI PeCoffLoaderRelocateImageExtraAction(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext)
EFI_STATUS EFIAPI FindImageBase(IN EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumePtr, IN EFI_FV_FILETYPE FileType, OUT EFI_PHYSICAL_ADDRESS *CoreImageBase)
Definition: FindPeiCore.c:23
VOID EFIAPI FindAndReportEntryPoints(IN EFI_FIRMWARE_VOLUME_HEADER *SecCoreFirmwareVolumePtr, IN EFI_FIRMWARE_VOLUME_HEADER *PeiCoreFirmwareVolumePtr, OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint)
Definition: FindPeiCore.c:144
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define EFI_SECTION_PE32
#define FFS_FILE_SIZE(FfsFileHeaderPtr)
#define SECTION_SIZE(SectionHeaderPtr)
VOID(EFIAPI * EFI_PEI_CORE_ENTRY_POINT)(IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
Definition: PiPeiCis.h:1051
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_FV_FILETYPE Type
PHYSICAL_ADDRESS ImageAddress
Definition: PeCoffLib.h:79