]>
Commit | Line | Data |
---|---|---|
192f6d4c | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006 - 2007, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | Image.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Pei Core Load Image Support\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
192f6d4c | 22 | #include <PeiMain.h>\r |
23 | \r | |
b0d803fe | 24 | /*++\r |
25 | \r | |
26 | Routine Description:\r | |
27 | \r | |
28 | Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r | |
192f6d4c | 29 | \r |
b0d803fe | 30 | Arguments:\r |
31 | \r | |
32 | FileHandle - The handle to the PE/COFF file\r | |
33 | FileOffset - The offset, in bytes, into the file to read\r | |
34 | ReadSize - The number of bytes to read from the file starting at FileOffset\r | |
35 | Buffer - A pointer to the buffer to read the data into.\r | |
36 | \r | |
37 | Returns:\r | |
38 | \r | |
39 | EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r | |
40 | \r | |
41 | --*/ \r | |
192f6d4c | 42 | \r |
43 | EFI_STATUS\r | |
b0d803fe | 44 | PeiLoadImageLoadImage (\r |
45 | IN EFI_PEI_SERVICES **PeiServices,\r | |
46 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
47 | OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg, OPTIONAL\r | |
48 | OUT UINT64 *ImageSizeArg, OPTIONAL\r | |
49 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint,\r | |
50 | OUT UINT32 *AuthenticationState\r | |
192f6d4c | 51 | )\r |
52 | /*++\r | |
53 | \r | |
54 | Routine Description:\r | |
55 | \r | |
56 | Routine for loading file image.\r | |
57 | \r | |
58 | Arguments:\r | |
59 | \r | |
b0d803fe | 60 | PeiServices - The PEI core services table.\r |
61 | FileHandle - Pointer to the FFS file header of the image.\r | |
62 | ImageAddressArg - Pointer to PE/TE image.\r | |
63 | ImageSizeArg - Size of PE/TE image.\r | |
64 | EntryPoint - Pointer to entry point of specified image file for output.\r | |
65 | AuthenticationState - Pointer to attestation authentication state of image.\r | |
66 | \r | |
67 | Returns:\r | |
68 | \r | |
69 | Status - EFI_SUCCESS - Image is successfully loaded.\r | |
70 | EFI_NOT_FOUND - Fail to locate necessary PPI\r | |
71 | Others - Fail to load file.\r | |
72 | \r | |
73 | --*/\r | |
74 | ;\r | |
75 | \r | |
76 | EFI_STATUS\r | |
77 | EFIAPI\r | |
78 | PeiLoadImageLoadImageWrapper (\r | |
79 | IN CONST EFI_PEI_LOAD_FILE_PPI *This,\r | |
80 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
81 | OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg, OPTIONAL\r | |
82 | OUT UINT64 *ImageSizeArg, OPTIONAL\r | |
83 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint,\r | |
84 | OUT UINT32 *AuthenticationState\r | |
85 | )\r | |
86 | /*++\r | |
87 | \r | |
88 | Routine Description:\r | |
89 | \r | |
90 | The wrapper function of PeiLoadImageLoadImage().\r | |
91 | \r | |
92 | Arguments:\r | |
93 | \r | |
94 | This - Pointer to EFI_PEI_LOAD_FILE_PPI.\r | |
95 | PeiServices - The PEI core services table.\r | |
96 | FileHandle - Pointer to the FFS file header of the image.\r | |
97 | ImageAddressArg - Pointer to PE/TE image.\r | |
98 | ImageSizeArg - Size of PE/TE image.\r | |
99 | EntryPoint - Pointer to entry point of specified image file for output.\r | |
100 | AuthenticationState - Pointer to attestation authentication state of image.\r | |
101 | \r | |
102 | Returns:\r | |
103 | \r | |
104 | EFI_STATUS.\r | |
105 | \r | |
106 | --*/ \r | |
107 | ;\r | |
108 | \r | |
109 | STATIC EFI_PEI_LOAD_FILE_PPI mPeiLoadImagePpi = {\r | |
110 | PeiLoadImageLoadImageWrapper\r | |
111 | };\r | |
112 | \r | |
113 | \r | |
114 | STATIC EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList = {\r | |
115 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
116 | &gEfiPeiLoadFilePpiGuid,\r | |
117 | &mPeiLoadImagePpi\r | |
118 | };\r | |
119 | \r | |
120 | EFI_STATUS\r | |
121 | EFIAPI\r | |
122 | PeiImageRead (\r | |
123 | IN VOID *FileHandle,\r | |
124 | IN UINTN FileOffset,\r | |
125 | IN OUT UINTN *ReadSize,\r | |
126 | OUT VOID *Buffer\r | |
127 | )\r | |
128 | /*++\r | |
129 | \r | |
130 | Routine Description:\r | |
131 | \r | |
132 | Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r | |
133 | \r | |
134 | Arguments:\r | |
135 | \r | |
136 | FileHandle - The handle to the PE/COFF file\r | |
137 | FileOffset - The offset, in bytes, into the file to read\r | |
138 | ReadSize - The number of bytes to read from the file starting at FileOffset\r | |
139 | Buffer - A pointer to the buffer to read the data into.\r | |
140 | \r | |
141 | Returns:\r | |
142 | \r | |
143 | EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r | |
144 | \r | |
145 | --*/\r | |
146 | {\r | |
147 | CHAR8 *Destination8;\r | |
148 | CHAR8 *Source8;\r | |
149 | UINTN Length;\r | |
150 | \r | |
151 | Destination8 = Buffer;\r | |
152 | Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset);\r | |
153 | Length = *ReadSize;\r | |
154 | while (Length--) {\r | |
155 | *(Destination8++) = *(Source8++);\r | |
156 | }\r | |
157 | \r | |
158 | return EFI_SUCCESS;\r | |
159 | }\r | |
160 | \r | |
161 | EFI_STATUS\r | |
162 | GetImageReadFunction (\r | |
163 | IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
164 | )\r | |
165 | /*++\r | |
166 | \r | |
167 | Routine Description:\r | |
168 | \r | |
169 | Support routine to return the Image Read\r | |
170 | \r | |
171 | Arguments:\r | |
172 | \r | |
173 | PeiServices - PEI Services Table\r | |
174 | \r | |
175 | ImageContext - The context of the image being loaded\r | |
176 | \r | |
177 | Returns:\r | |
178 | \r | |
179 | EFI_SUCCESS - If Image function location is found\r | |
180 | \r | |
181 | --*/\r | |
182 | {\r | |
183 | VOID* MemoryBuffer;\r | |
184 | \r | |
185 | MemoryBuffer = AllocatePages (0x400 / EFI_PAGE_SIZE + 1);\r | |
186 | ASSERT (MemoryBuffer != NULL);\r | |
187 | \r | |
188 | CopyMem (MemoryBuffer, (CONST VOID *) (UINTN) PeiImageRead, 0x400);\r | |
189 | \r | |
190 | ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;\r | |
191 | \r | |
192 | return EFI_SUCCESS;\r | |
193 | }\r | |
194 | \r | |
195 | STATIC\r | |
196 | EFI_STATUS\r | |
197 | LoadAndRelocatePeCoffImage (\r | |
b0d803fe | 198 | IN VOID *Pe32Data,\r |
199 | OUT EFI_PHYSICAL_ADDRESS *ImageAddress,\r | |
200 | OUT UINT64 *ImageSize,\r | |
201 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint\r | |
202 | )\r | |
203 | /*++\r | |
204 | \r | |
205 | Routine Description:\r | |
206 | \r | |
207 | Loads and relocates a PE/COFF image into memory.\r | |
208 | \r | |
209 | Arguments:\r | |
210 | \r | |
b0d803fe | 211 | Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated\r |
212 | \r | |
213 | ImageAddress - The base address of the relocated PE/COFF image\r | |
214 | \r | |
215 | ImageSize - The size of the relocated PE/COFF image\r | |
216 | \r | |
217 | EntryPoint - The entry point of the relocated PE/COFF image\r | |
218 | \r | |
219 | Returns:\r | |
220 | \r | |
221 | EFI_SUCCESS - The file was loaded and relocated\r | |
222 | \r | |
223 | EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r | |
224 | \r | |
225 | --*/\r | |
226 | {\r | |
227 | EFI_STATUS Status;\r | |
228 | PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r | |
229 | \r | |
b0d803fe | 230 | ZeroMem (&ImageContext, sizeof (ImageContext));\r |
231 | ImageContext.Handle = Pe32Data;\r | |
232 | Status = GetImageReadFunction (&ImageContext);\r | |
233 | \r | |
234 | ASSERT_EFI_ERROR (Status);\r | |
235 | \r | |
3d7b0992 | 236 | Status = PeCoffLoaderGetImageInfo (&ImageContext);\r |
b0d803fe | 237 | if (EFI_ERROR (Status)) {\r |
238 | return Status;\r | |
239 | }\r | |
240 | //\r | |
9626a87e LG |
241 | // When Image has no reloc section, it can't be relocated into memory.\r |
242 | //\r | |
243 | if (ImageContext.RelocationsStripped) {\r | |
244 | DEBUG ((EFI_D_ERROR, "The image at 0x%08x without reloc section can't be loaded into memory", (UINTN) Pe32Data));\r | |
245 | return EFI_INVALID_PARAMETER;\r | |
246 | }\r | |
247 | //\r | |
b0d803fe | 248 | // Allocate Memory for the image\r |
249 | //\r | |
250 | ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize));\r | |
251 | ASSERT (ImageContext.ImageAddress != 0);\r | |
4e844595 LG |
252 | \r |
253 | //\r | |
254 | // Skip the reserved space for the stripped PeHeader when load TeImage into memory.\r | |
255 | //\r | |
256 | if (ImageContext.IsTeImage) {\r | |
257 | ImageContext.ImageAddress = ImageContext.ImageAddress + \r | |
258 | ((EFI_TE_IMAGE_HEADER *) Pe32Data)->StrippedSize -\r | |
259 | sizeof (EFI_TE_IMAGE_HEADER);\r | |
260 | }\r | |
b0d803fe | 261 | \r |
262 | //\r | |
263 | // Load the image to our new buffer\r | |
264 | //\r | |
3d7b0992 | 265 | Status = PeCoffLoaderLoadImage (&ImageContext);\r |
b0d803fe | 266 | if (EFI_ERROR (Status)) {\r |
267 | return Status;\r | |
268 | }\r | |
269 | //\r | |
270 | // Relocate the image in our new buffer\r | |
271 | //\r | |
3d7b0992 | 272 | Status = PeCoffLoaderRelocateImage (&ImageContext);\r |
b0d803fe | 273 | if (EFI_ERROR (Status)) {\r |
274 | return Status;\r | |
275 | }\r | |
276 | \r | |
277 | //\r | |
278 | // Flush the instruction cache so the image data is written before we execute it\r | |
279 | //\r | |
280 | InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);\r | |
281 | \r | |
282 | *ImageAddress = ImageContext.ImageAddress;\r | |
283 | *ImageSize = ImageContext.ImageSize;\r | |
284 | *EntryPoint = ImageContext.EntryPoint;\r | |
285 | \r | |
286 | return EFI_SUCCESS;\r | |
287 | }\r | |
288 | \r | |
289 | EFI_STATUS\r | |
290 | PeiLoadImageLoadImage (\r | |
291 | IN EFI_PEI_SERVICES **PeiServices,\r | |
292 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
293 | OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg, OPTIONAL\r | |
294 | OUT UINT64 *ImageSizeArg, OPTIONAL\r | |
295 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint,\r | |
296 | OUT UINT32 *AuthenticationState\r | |
297 | )\r | |
298 | /*++\r | |
299 | \r | |
300 | Routine Description:\r | |
301 | \r | |
302 | Routine for loading file image.\r | |
303 | \r | |
304 | Arguments:\r | |
305 | \r | |
306 | PeiServices - The PEI core services table.\r | |
307 | FileHandle - Pointer to the FFS file header of the image.\r | |
308 | ImageAddressArg - Pointer to PE/TE image.\r | |
309 | ImageSizeArg - Size of PE/TE image.\r | |
310 | EntryPoint - Pointer to entry point of specified image file for output.\r | |
311 | AuthenticationState - Pointer to attestation authentication state of image.\r | |
192f6d4c | 312 | \r |
313 | Returns:\r | |
314 | \r | |
315 | Status - EFI_SUCCESS - Image is successfully loaded.\r | |
316 | EFI_NOT_FOUND - Fail to locate necessary PPI\r | |
317 | Others - Fail to load file.\r | |
318 | \r | |
319 | --*/\r | |
320 | {\r | |
321 | EFI_STATUS Status;\r | |
322 | VOID *Pe32Data;\r | |
192f6d4c | 323 | EFI_PHYSICAL_ADDRESS ImageAddress;\r |
324 | UINT64 ImageSize;\r | |
325 | EFI_PHYSICAL_ADDRESS ImageEntryPoint;\r | |
192f6d4c | 326 | UINT16 Machine;\r |
b0d803fe | 327 | PEI_CORE_INSTANCE *Private;\r |
328 | VOID *EntryPointArg;\r | |
192f6d4c | 329 | \r |
3d7b0992 LG |
330 | *EntryPoint = 0;\r |
331 | ImageSize = 0;\r | |
b0d803fe | 332 | *AuthenticationState = 0;\r |
192f6d4c | 333 | \r |
334 | //\r | |
b0d803fe | 335 | // Try to find a TE section.\r |
192f6d4c | 336 | //\r |
337 | Status = PeiServicesFfsFindSectionData (\r | |
b0d803fe | 338 | EFI_SECTION_TE,\r |
339 | FileHandle,\r | |
192f6d4c | 340 | &Pe32Data\r |
341 | );\r | |
342 | //\r | |
3d7b0992 | 343 | // If we didn't find a TE section, try to find a PE32 section.\r |
192f6d4c | 344 | //\r |
345 | if (EFI_ERROR (Status)) {\r | |
346 | Status = PeiServicesFfsFindSectionData (\r | |
b0d803fe | 347 | EFI_SECTION_PE32,\r |
348 | FileHandle,\r | |
349 | &Pe32Data\r | |
192f6d4c | 350 | );\r |
b0d803fe | 351 | if (EFI_ERROR (Status)) {\r |
192f6d4c | 352 | //\r |
b0d803fe | 353 | // PEI core only carry the loader function fro TE and PE32 executables\r |
354 | // If this two section does not exist, just return.\r | |
192f6d4c | 355 | //\r |
b0d803fe | 356 | return Status;\r |
357 | }\r | |
358 | }\r | |
359 | \r | |
360 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r | |
192f6d4c | 361 | \r |
b0d803fe | 362 | if (Private->PeiMemoryInstalled && \r |
363 | (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r | |
3d7b0992 LG |
364 | //\r |
365 | // If memory is installed, perform the shadow operations\r | |
366 | //\r | |
367 | Status = LoadAndRelocatePeCoffImage (\r | |
368 | Pe32Data,\r | |
369 | &ImageAddress,\r | |
370 | &ImageSize,\r | |
371 | &ImageEntryPoint\r | |
372 | );\r | |
192f6d4c | 373 | \r |
3d7b0992 LG |
374 | if (EFI_ERROR (Status)) {\r |
375 | return Status;\r | |
b0d803fe | 376 | }\r |
3d7b0992 LG |
377 | \r |
378 | //\r | |
379 | // Got the entry point from the loaded Pe32Data\r | |
380 | //\r | |
381 | Pe32Data = (VOID *) ((UINTN) ImageAddress);\r | |
382 | *EntryPoint = ImageEntryPoint;\r | |
b0d803fe | 383 | } else {\r |
3d7b0992 LG |
384 | //\r |
385 | // Retrieve the entry point from the PE/COFF or TE image header\r | |
386 | //\r | |
387 | ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Pe32Data;\r | |
388 | Status = PeCoffLoaderGetEntryPoint (Pe32Data, &EntryPointArg);\r | |
389 | if (EFI_ERROR (Status)) {\r | |
390 | return Status;\r | |
192f6d4c | 391 | }\r |
3d7b0992 | 392 | *EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) EntryPointArg;\r |
192f6d4c | 393 | }\r |
3d7b0992 LG |
394 | \r |
395 | Machine = PeCoffLoaderGetMachineType (Pe32Data);\r | |
192f6d4c | 396 | \r |
397 | if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Machine)) {\r | |
398 | return EFI_UNSUPPORTED; \r | |
399 | }\r | |
400 | \r | |
b0d803fe | 401 | if (ImageAddressArg != NULL) {\r |
402 | *ImageAddressArg = ImageAddress;\r | |
403 | }\r | |
404 | \r | |
405 | if (ImageSizeArg != NULL) {\r | |
406 | *ImageSizeArg = ImageSize;\r | |
407 | }\r | |
408 | \r | |
192f6d4c | 409 | DEBUG_CODE_BEGIN ();\r |
3d7b0992 LG |
410 | CHAR8 *AsciiString;\r |
411 | CHAR8 AsciiBuffer[512];\r | |
412 | INT32 Index;\r | |
413 | INT32 Index1;\r | |
e98cd821 LG |
414 | \r |
415 | //\r | |
416 | // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi\r | |
417 | //\r | |
418 | if (Machine != IMAGE_FILE_MACHINE_IA64) {\r | |
419 | DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", (UINTN) ImageAddress, *EntryPoint));\r | |
420 | } else {\r | |
421 | //\r | |
422 | // For IPF Image, the real entry point should be print.\r | |
423 | //\r | |
424 | DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", (UINTN) ImageAddress, (UINTN) (*(UINT64 *)(UINTN)*EntryPoint)));\r | |
425 | }\r | |
192f6d4c | 426 | \r |
e98cd821 LG |
427 | //\r |
428 | // Print Module Name by PeImage PDB file name.\r | |
429 | //\r | |
3d7b0992 LG |
430 | AsciiString = PeCoffLoaderGetPdbPointer (Pe32Data);\r |
431 | \r | |
432 | if (AsciiString != NULL) {\r | |
19ea58a1 | 433 | for (Index = (INT32) AsciiStrLen (AsciiString) - 1; Index >= 0; Index --) {\r |
3d7b0992 LG |
434 | if (AsciiString[Index] == '\\') {\r |
435 | break;\r | |
436 | }\r | |
192f6d4c | 437 | }\r |
192f6d4c | 438 | \r |
3d7b0992 LG |
439 | if (Index != 0) {\r |
440 | for (Index1 = 0; AsciiString[Index + 1 + Index1] != '.'; Index1 ++) {\r | |
441 | AsciiBuffer [Index1] = AsciiString[Index + 1 + Index1];\r | |
192f6d4c | 442 | }\r |
3d7b0992 LG |
443 | AsciiBuffer [Index1] = '\0';\r |
444 | DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));\r | |
192f6d4c | 445 | }\r |
446 | }\r | |
3d7b0992 | 447 | \r |
192f6d4c | 448 | DEBUG_CODE_END ();\r |
449 | \r | |
450 | DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));\r | |
451 | \r | |
452 | return EFI_SUCCESS;\r | |
b0d803fe | 453 | \r |
454 | }\r | |
455 | \r | |
456 | \r | |
457 | EFI_STATUS\r | |
458 | EFIAPI\r | |
459 | PeiLoadImageLoadImageWrapper (\r | |
460 | IN CONST EFI_PEI_LOAD_FILE_PPI *This,\r | |
461 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
462 | OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg, OPTIONAL\r | |
463 | OUT UINT64 *ImageSizeArg, OPTIONAL\r | |
464 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint,\r | |
465 | OUT UINT32 *AuthenticationState\r | |
466 | )\r | |
467 | /*++\r | |
468 | \r | |
469 | Routine Description:\r | |
470 | \r | |
471 | The wrapper function of PeiLoadImageLoadImage().\r | |
472 | \r | |
473 | Arguments:\r | |
474 | \r | |
475 | This - Pointer to EFI_PEI_LOAD_FILE_PPI.\r | |
476 | PeiServices - The PEI core services table.\r | |
477 | FileHandle - Pointer to the FFS file header of the image.\r | |
478 | ImageAddressArg - Pointer to PE/TE image.\r | |
479 | ImageSizeArg - Size of PE/TE image.\r | |
480 | EntryPoint - Pointer to entry point of specified image file for output.\r | |
481 | AuthenticationState - Pointer to attestation authentication state of image.\r | |
482 | \r | |
483 | Returns:\r | |
484 | \r | |
485 | EFI_STATUS.\r | |
486 | \r | |
487 | --*/ \r | |
488 | {\r | |
489 | return PeiLoadImageLoadImage (\r | |
490 | GetPeiServicesTablePointer (),\r | |
491 | FileHandle,\r | |
492 | ImageAddressArg,\r | |
493 | ImageSizeArg,\r | |
494 | EntryPoint,\r | |
495 | AuthenticationState\r | |
496 | );\r | |
192f6d4c | 497 | }\r |
b0d803fe | 498 | \r |
499 | EFI_STATUS\r | |
500 | PeiLoadImage (\r | |
501 | IN EFI_PEI_SERVICES **PeiServices,\r | |
502 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
503 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint,\r | |
504 | OUT UINT32 *AuthenticationState\r | |
505 | )\r | |
506 | /*++\r | |
507 | \r | |
508 | Routine Description:\r | |
509 | \r | |
510 | Routine for load image file.\r | |
511 | \r | |
512 | Arguments:\r | |
513 | \r | |
514 | PeiServices - The PEI core services table.\r | |
515 | FileHandle - Pointer to the FFS file header of the image.\r | |
516 | EntryPoint - Pointer to entry point of specified image file for output.\r | |
517 | AuthenticationState - Pointer to attestation authentication state of image.\r | |
518 | \r | |
519 | Returns:\r | |
520 | \r | |
521 | Status - EFI_SUCCESS - Image is successfully loaded.\r | |
522 | EFI_NOT_FOUND - Fail to locate necessary PPI\r | |
523 | Others - Fail to load file.\r | |
524 | \r | |
525 | --*/ \r | |
526 | {\r | |
527 | EFI_STATUS PpiStatus;\r | |
528 | EFI_STATUS Status;\r | |
529 | UINTN Index;\r | |
530 | EFI_PEI_LOAD_FILE_PPI *LoadFile;\r | |
531 | EFI_PHYSICAL_ADDRESS ImageAddress;\r | |
532 | UINT64 ImageSize;\r | |
533 | \r | |
534 | //\r | |
535 | // If any instances of PEI_LOAD_FILE_PPI are installed, they are called.\r | |
536 | // one at a time, until one reports EFI_SUCCESS.\r | |
537 | //\r | |
538 | Index = 0;\r | |
539 | do {\r | |
540 | PpiStatus = PeiServicesLocatePpi (\r | |
541 | &gEfiPeiLoadFilePpiGuid,\r | |
542 | Index,\r | |
543 | NULL,\r | |
544 | (VOID **)&LoadFile\r | |
545 | );\r | |
546 | if (!EFI_ERROR (PpiStatus)) {\r | |
547 | Status = LoadFile->LoadFile (\r | |
548 | LoadFile, \r | |
549 | FileHandle, \r | |
550 | &ImageAddress, \r | |
551 | &ImageSize,\r | |
552 | EntryPoint,\r | |
553 | AuthenticationState\r | |
554 | );\r | |
555 | if (!EFI_ERROR (Status)) {\r | |
556 | return Status;\r | |
557 | }\r | |
558 | }\r | |
559 | Index++;\r | |
560 | } while (!EFI_ERROR (PpiStatus));\r | |
561 | \r | |
562 | //\r | |
563 | // If no instances reports EFI_SUCCESS, then build-in support for\r | |
564 | // the PE32+/TE XIP image format is used.\r | |
565 | //\r | |
566 | Status = PeiLoadImageLoadImage (\r | |
567 | PeiServices, \r | |
568 | FileHandle, \r | |
569 | NULL, \r | |
570 | NULL, \r | |
571 | EntryPoint, \r | |
572 | AuthenticationState\r | |
573 | );\r | |
574 | return Status;\r | |
575 | }\r | |
576 | \r | |
577 | \r | |
578 | VOID\r | |
579 | InitializeImageServices (\r | |
580 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
581 | IN PEI_CORE_INSTANCE *OldCoreData\r | |
582 | )\r | |
583 | /*++\r | |
584 | \r | |
585 | Routine Description:\r | |
586 | \r | |
c58cf83d | 587 | Install Pei Load File PPI.\r |
b0d803fe | 588 | \r |
589 | Arguments:\r | |
590 | \r | |
591 | PrivateData - Pointer to PEI_CORE_INSTANCE.\r | |
592 | OldCoreData - Pointer to PEI_CORE_INSTANCE.\r | |
593 | \r | |
594 | Returns:\r | |
595 | \r | |
596 | NONE.\r | |
597 | \r | |
598 | --*/ \r | |
599 | {\r | |
b0d803fe | 600 | if (OldCoreData == NULL) {\r |
601 | //\r | |
602 | // The first time we are XIP (running from FLASH). We need to remember the\r | |
603 | // FLASH address so we can reinstall the memory version that runs faster\r | |
604 | //\r | |
605 | PrivateData->XipLoadFile = &gPpiLoadFilePpiList;\r | |
606 | PeiServicesInstallPpi (PrivateData->XipLoadFile);\r | |
607 | } else {\r | |
608 | //\r | |
609 | // 2nd time we are running from memory so replace the XIP version with the \r | |
610 | // new memory version. \r | |
611 | //\r | |
612 | PeiServicesReInstallPpi (PrivateData->XipLoadFile, &gPpiLoadFilePpiList); \r | |
613 | }\r | |
614 | }\r | |
615 | \r | |
616 | \r | |
617 | \r |