]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/FwVol/FwVol.c
Remove unnecessary use of FixedPcdxxx() functions and [FixedPcd] INF sections. These...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
CommitLineData
615c6dd0 1/** @file\r
b1f6a7c6 2 Pei Core Firmware File System service routines.\r
3 \r
1c738c8f 4Copyright (c) 2006 - 2010, Intel Corporation \r
192f6d4c 5All rights reserved. This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
9 \r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
615c6dd0 13**/\r
192f6d4c 14\r
3b428ade 15#include "FwVol.h"\r
192f6d4c 16\r
fe1e36e5 17EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList = {\r
b0d803fe 18 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
19 &gEfiPeiFirmwareVolumeInfoPpiGuid,\r
20 FirmwareVolmeInfoPpiNotifyCallback \r
21};\r
22\r
3b428ade 23EFI_PEI_FIRMWARE_VOLUME_PPI mPeiFfs2FvPpi = {\r
24 PeiFfs2FvPpiProcessVolume,\r
25 PeiFfs2FvPpiFindFileByType,\r
26 PeiFfs2FvPpiFindFileByName,\r
27 PeiFfs2FvPpiGetFileInfo,\r
28 PeiFfs2FvPpiGetVolumeInfo,\r
29 PeiFfs2FvPpiFindSectionByType\r
30};\r
31 \r
32EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList = {\r
33 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
34 &gEfiFirmwareFileSystem2Guid,\r
35 &mPeiFfs2FvPpi\r
36};\r
37 \r
b1f6a7c6 38/**\r
ed299e3c 39 Returns the file state set by the highest zero bit in the State field\r
192f6d4c 40\r
b1f6a7c6 41 @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY\r
42 in the Attributes field.\r
43 @param FfsHeader Pointer to FFS File Header.\r
192f6d4c 44\r
ed299e3c
LG
45 @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit \r
46 in the header State field.\r
b1f6a7c6 47**/\r
48EFI_FFS_FILE_STATE\r
49GetFileState(\r
50 IN UINT8 ErasePolarity,\r
51 IN EFI_FFS_FILE_HEADER *FfsHeader\r
52 )\r
192f6d4c 53{\r
54 EFI_FFS_FILE_STATE FileState;\r
55 EFI_FFS_FILE_STATE HighestBit;\r
56\r
57 FileState = FfsHeader->State;\r
58\r
59 if (ErasePolarity != 0) {\r
60 FileState = (EFI_FFS_FILE_STATE)~FileState;\r
61 }\r
ed299e3c
LG
62 \r
63 //\r
64 // Get file state set by its highest none zero bit.\r
65 //\r
192f6d4c 66 HighestBit = 0x80;\r
67 while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r
68 HighestBit >>= 1;\r
69 }\r
70\r
71 return HighestBit;\r
72} \r
73\r
b1f6a7c6 74/**\r
75 Calculates the checksum of the header of a file.\r
76\r
77 @param FileHeader Pointer to FFS File Header.\r
78\r
79 @return Checksum of the header.\r
b1f6a7c6 80 Zero means the header is good.\r
81 Non-zero means the header is bad.\r
82**/\r
192f6d4c 83UINT8\r
84CalculateHeaderChecksum (\r
85 IN EFI_FFS_FILE_HEADER *FileHeader\r
86 )\r
192f6d4c 87{\r
ed299e3c 88 EFI_FFS_FILE_HEADER TestFileHeader;\r
192f6d4c 89 \r
ed299e3c 90 CopyMem (&TestFileHeader, FileHeader, sizeof (EFI_FFS_FILE_HEADER));\r
192f6d4c 91 //\r
ed299e3c 92 // Ingore State and File field in FFS header.\r
192f6d4c 93 //\r
ed299e3c
LG
94 TestFileHeader.State = 0;\r
95 TestFileHeader.IntegrityCheck.Checksum.File = 0;\r
192f6d4c 96\r
ed299e3c 97 return CalculateSum8 ((CONST UINT8 *) &TestFileHeader, sizeof (EFI_FFS_FILE_HEADER));\r
192f6d4c 98}\r
99\r
b1f6a7c6 100/**\r
3b428ade 101 Find FV handler according to FileHandle in that FV.\r
b1f6a7c6 102\r
103 @param FileHandle Handle of file image\r
3b428ade 104 \r
105 @return Pointer to instance of PEI_CORE_FV_HANDLE.\r
b1f6a7c6 106**/\r
3b428ade 107PEI_CORE_FV_HANDLE*\r
108FileHandleToVolume (\r
109 IN EFI_PEI_FILE_HANDLE FileHandle\r
b0d803fe 110 )\r
111{\r
112 UINTN Index;\r
113 PEI_CORE_INSTANCE *PrivateData;\r
114 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
115\r
116 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
3b428ade 117 \r
b0d803fe 118 for (Index = 0; Index < PrivateData->FvCount; Index++) {\r
119 FwVolHeader = PrivateData->Fv[Index].FvHeader;\r
67a58d0f 120 if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) && \\r
121 ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {\r
3b428ade 122 return &PrivateData->Fv[Index];\r
b0d803fe 123 }\r
124 }\r
3b428ade 125 return NULL;\r
b0d803fe 126}\r
127\r
b1f6a7c6 128/**\r
ed299e3c 129 Given the input file pointer, search for the first matching file in the\r
b1f6a7c6 130 FFS volume as defined by SearchType. The search starts from FileHeader inside\r
131 the Firmware Volume defined by FwVolHeader.\r
ed299e3c
LG
132 If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.\r
133 If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, \r
134 the first PEIM, or COMBINED PEIM or FV file type FFS file will return. \r
b1f6a7c6 135\r
136 @param FvHandle Pointer to the FV header of the volume to search\r
137 @param FileName File name\r
138 @param SearchType Filter to find only files of this type.\r
139 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
140 @param FileHandle This parameter must point to a valid FFS volume.\r
141 @param AprioriFile Pointer to AprioriFile image in this FV if has\r
b0d803fe 142\r
b1f6a7c6 143 @return EFI_NOT_FOUND No files matching the search criteria were found\r
144 @retval EFI_SUCCESS Success to search given file\r
145\r
146**/\r
192f6d4c 147EFI_STATUS\r
3b428ade 148FindFileEx (\r
b0d803fe 149 IN CONST EFI_PEI_FV_HANDLE FvHandle,\r
150 IN CONST EFI_GUID *FileName, OPTIONAL\r
151 IN EFI_FV_FILETYPE SearchType,\r
152 IN OUT EFI_PEI_FILE_HANDLE *FileHandle,\r
153 IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL\r
192f6d4c 154 )\r
192f6d4c 155{\r
b0d803fe 156 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
157 EFI_FFS_FILE_HEADER **FileHeader;\r
158 EFI_FFS_FILE_HEADER *FfsFileHeader;\r
b0d803fe 159 UINT32 FileLength;\r
160 UINT32 FileOccupiedSize;\r
161 UINT32 FileOffset;\r
162 UINT64 FvLength;\r
163 UINT8 ErasePolarity;\r
164 UINT8 FileState;\r
3b428ade 165 \r
166 //\r
167 // Convert the handle of FV to FV header for memory-mapped firmware volume\r
168 //\r
169 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FvHandle;\r
b0d803fe 170 FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle;\r
192f6d4c 171\r
172 FvLength = FwVolHeader->FvLength;\r
d976bf31 173 if ((FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r
192f6d4c 174 ErasePolarity = 1;\r
175 } else {\r
176 ErasePolarity = 0;\r
177 }\r
178 \r
179 //\r
b0d803fe 180 // If FileHeader is not specified (NULL) or FileName is not NULL,\r
181 // start with the first file in the firmware volume. Otherwise,\r
182 // start from the FileHeader.\r
192f6d4c 183 //\r
b0d803fe 184 if ((*FileHeader == NULL) || (FileName != NULL)) {\r
192f6d4c 185 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength);\r
186 } else {\r
187 //\r
188 // Length is 24 bits wide so mask upper 8 bits\r
189 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
190 //\r
191 FileLength = *(UINT32 *)(*FileHeader)->Size & 0x00FFFFFF;\r
b0d803fe 192 FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);\r
192f6d4c 193 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);\r
194 }\r
e98cd821 195 \r
192f6d4c 196 FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);\r
197 ASSERT (FileOffset <= 0xFFFFFFFF);\r
e98cd821 198\r
b0d803fe 199 while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r
192f6d4c 200 //\r
201 // Get FileState which is the highest bit of the State \r
202 //\r
203 FileState = GetFileState (ErasePolarity, FfsFileHeader);\r
192f6d4c 204 switch (FileState) {\r
205\r
206 case EFI_FILE_HEADER_INVALID:\r
40f26b8f 207 FileOffset += sizeof(EFI_FFS_FILE_HEADER);\r
208 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER));\r
192f6d4c 209 break;\r
210 \r
211 case EFI_FILE_DATA_VALID:\r
212 case EFI_FILE_MARKED_FOR_UPDATE:\r
b0d803fe 213 if (CalculateHeaderChecksum (FfsFileHeader) != 0) {\r
192f6d4c 214 ASSERT (FALSE);\r
e98cd821 215 *FileHeader = NULL;\r
192f6d4c 216 return EFI_NOT_FOUND;\r
217 }\r
b0d803fe 218\r
40f26b8f 219 FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
b0d803fe 220 FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r
221\r
222 if (FileName != NULL) {\r
223 if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {\r
224 *FileHeader = FfsFileHeader;\r
225 return EFI_SUCCESS;\r
226 }\r
227 } else if (SearchType == PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE) {\r
228 if ((FfsFileHeader->Type == EFI_FV_FILETYPE_PEIM) || \r
288f9b38
LG
229 (FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER) ||\r
230 (FfsFileHeader->Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) { \r
b0d803fe 231 \r
232 *FileHeader = FfsFileHeader;\r
233 return EFI_SUCCESS;\r
234 } else if (AprioriFile != NULL) {\r
235 if (FfsFileHeader->Type == EFI_FV_FILETYPE_FREEFORM) {\r
236 if (CompareGuid (&FfsFileHeader->Name, &gPeiAprioriFileNameGuid)) {\r
237 *AprioriFile = FfsFileHeader;\r
238 } \r
239 } \r
240 }\r
7e181f2f 241 } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) && \r
242 (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) { \r
b0d803fe 243 *FileHeader = FfsFileHeader;\r
244 return EFI_SUCCESS;\r
245 }\r
246\r
40f26b8f 247 FileOffset += FileOccupiedSize; \r
248 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r
192f6d4c 249 break;\r
250 \r
251 case EFI_FILE_DELETED:\r
40f26b8f 252 FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
253 FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r
254 FileOffset += FileOccupiedSize;\r
255 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r
192f6d4c 256 break;\r
257\r
258 default:\r
e98cd821 259 *FileHeader = NULL;\r
192f6d4c 260 return EFI_NOT_FOUND;\r
192f6d4c 261 } \r
262 }\r
e98cd821
LG
263 \r
264 *FileHeader = NULL;\r
192f6d4c 265 return EFI_NOT_FOUND; \r
266}\r
267\r
b1f6a7c6 268/**\r
b1f6a7c6 269 Initialize PeiCore Fv List.\r
270\r
b1f6a7c6 271 @param PrivateData - Pointer to PEI_CORE_INSTANCE.\r
272 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.\r
b1f6a7c6 273**/\r
b0d803fe 274VOID \r
275PeiInitializeFv (\r
276 IN PEI_CORE_INSTANCE *PrivateData,\r
277 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
278 )\r
b0d803fe 279{\r
3b428ade 280 EFI_STATUS Status;\r
281 EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r
282 EFI_PEI_FV_HANDLE FvHandle;\r
283 EFI_FIRMWARE_VOLUME_HEADER *BfvHeader;\r
284 \r
b0d803fe 285 //\r
3b428ade 286 // Install FV_PPI for FFS2 file system.\r
b0d803fe 287 //\r
3b428ade 288 PeiServicesInstallPpi (&mPeiFfs2FvPpiList);\r
289 \r
290 BfvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;\r
291 \r
292 //\r
293 // The FV_PPI in BFV's format should be installed.\r
294 //\r
295 Status = PeiServicesLocatePpi (\r
296 &BfvHeader->FileSystemGuid,\r
297 0,\r
298 NULL,\r
299 (VOID**)&FvPpi\r
300 );\r
301 ASSERT_EFI_ERROR (Status);\r
302 \r
303 //\r
304 // Get handle of BFV\r
305 //\r
306 FvPpi->ProcessVolume (\r
307 FvPpi, \r
308 SecCoreData->BootFirmwareVolumeBase,\r
309 (UINTN)BfvHeader->FvLength,\r
310 &FvHandle\r
311 );\r
dc6f9b35 312\r
313 //\r
314 // Update internal PEI_CORE_FV array.\r
315 //\r
316 PrivateData->Fv[PrivateData->FvCount].FvHeader = BfvHeader;\r
317 PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r
318 PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
319 DEBUG ((\r
320 EFI_D_INFO, \r
321 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
322 (UINT32) PrivateData->FvCount, \r
323 (VOID *) BfvHeader, \r
324 BfvHeader->FvLength,\r
325 FvHandle\r
326 )); \r
327 PrivateData->FvCount ++;\r
328 \r
b0d803fe 329 //\r
330 // Post a call-back for the FvInfoPPI services to expose\r
331 // additional Fvs to PeiCore.\r
332 //\r
333 Status = PeiServicesNotifyPpi (&mNotifyOnFvInfoList);\r
334 ASSERT_EFI_ERROR (Status);\r
335\r
336}\r
3b428ade 337 \r
b1f6a7c6 338/**\r
339 Process Firmware Volum Information once FvInfoPPI install.\r
ed299e3c
LG
340 The FV Info will be registered into PeiCore private data structure.\r
341 And search the inside FV image, if found, the new FV INFO PPI will be installed.\r
b1f6a7c6 342\r
ed299e3c 343 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
731bd38e 344 @param NotifyDescriptor Address of the notification descriptor data structure.\r
345 @param Ppi Address of the PPI that was installed.\r
b1f6a7c6 346\r
ed299e3c 347 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.\r
6a1ae84a 348 @return if not EFI_SUCESS, fail to verify FV.\r
b1f6a7c6 349\r
350**/\r
b0d803fe 351EFI_STATUS\r
352EFIAPI\r
353FirmwareVolmeInfoPpiNotifyCallback (\r
354 IN EFI_PEI_SERVICES **PeiServices,\r
355 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
356 IN VOID *Ppi\r
357 )\r
b0d803fe 358{\r
3b428ade 359 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *FvInfoPpi;\r
360 EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r
b0d803fe 361 PEI_CORE_INSTANCE *PrivateData;\r
288f9b38 362 EFI_STATUS Status;\r
3b428ade 363 EFI_PEI_FV_HANDLE FvHandle;\r
364 UINTN FvIndex;\r
dc6f9b35 365 EFI_PEI_FILE_HANDLE FileHandle;\r
366 VOID *DepexData;\r
b0d803fe 367 \r
288f9b38
LG
368 Status = EFI_SUCCESS;\r
369 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
b0d803fe 370\r
188e4e84 371 if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
372 DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));\r
97b2c9b5 373 DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r
b0d803fe 374 ASSERT (FALSE);\r
375 }\r
376\r
3b428ade 377 FvInfoPpi = (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *)Ppi;\r
b0d803fe 378\r
97b2c9b5 379 //\r
3b428ade 380 // Locate the corresponding FV_PPI according to founded FV's format guid\r
97b2c9b5 381 //\r
3b428ade 382 Status = PeiServicesLocatePpi (\r
383 &FvInfoPpi->FvFormat, \r
384 0, \r
385 NULL,\r
386 (VOID**)&FvPpi\r
387 );\r
388 if (!EFI_ERROR (Status)) {\r
389 //\r
390 // Process new found FV and get FV handle.\r
391 //\r
392 Status = FvPpi->ProcessVolume (FvPpi, FvInfoPpi->FvInfo, FvInfoPpi->FvInfoSize, &FvHandle);\r
393 if (EFI_ERROR (Status)) {\r
dc6f9b35 394 DEBUG ((EFI_D_ERROR, "Fail to process new found FV, FV may be corrupted!\n"));\r
6a1ae84a 395 return Status;\r
396 }\r
dc6f9b35 397\r
398 //\r
399 // Check whether the FV has already been processed.\r
400 //\r
401 for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r
402 if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r
403 DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfoPpi->FvInfo));\r
404 return EFI_SUCCESS;\r
405 }\r
406 }\r
407\r
408 //\r
409 // Update internal PEI_CORE_FV array.\r
410 //\r
411 PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfoPpi->FvInfo;\r
412 PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r
413 PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
414 DEBUG ((\r
415 EFI_D_INFO, \r
416 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
417 (UINT32) PrivateData->FvCount, \r
418 (VOID *) FvInfoPpi->FvInfo, \r
419 FvInfoPpi->FvInfoSize,\r
420 FvHandle\r
421 )); \r
422 PrivateData->FvCount ++;\r
423\r
424 //\r
425 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \r
426 //\r
427 FileHandle = NULL;\r
428 do {\r
429 Status = FvPpi->FindFileByType (\r
430 FvPpi,\r
431 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r
432 FvHandle,\r
433 &FileHandle\r
434 );\r
435 if (!EFI_ERROR (Status)) {\r
436 Status = FvPpi->FindSectionByType (\r
437 FvPpi,\r
438 EFI_SECTION_PEI_DEPEX,\r
439 FileHandle,\r
440 (VOID**)&DepexData\r
441 );\r
442 if (!EFI_ERROR (Status)) {\r
443 if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r
444 //\r
445 // Dependency is not satisfied.\r
446 //\r
447 continue;\r
448 }\r
449 }\r
450 \r
451 DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r
452 ProcessFvFile (&PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r
453 }\r
454 } while (FileHandle != NULL);\r
3b428ade 455 } else {\r
456 DEBUG ((EFI_D_ERROR, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfoPpi->FvInfo));\r
6a1ae84a 457 \r
f3358329 458 AddUnknownFormatFvInfo (PrivateData, &FvInfoPpi->FvFormat, FvInfoPpi->FvInfo, FvInfoPpi->FvInfoSize);\r
288f9b38 459 }\r
3b428ade 460 \r
b0d803fe 461 return EFI_SUCCESS;\r
462}\r
463\r
b1f6a7c6 464/**\r
ed299e3c
LG
465 Go through the file to search SectionType section. \r
466 Search within encapsulation sections (compression and GUIDed) recursively, \r
467 until the match section is found.\r
468 \r
3b428ade 469 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
470 @param SectionType Filter to find only section of this type.\r
471 @param Section From where to search.\r
472 @param SectionSize The file size to search.\r
473 @param OutputBuffer A pointer to the discovered section, if successful.\r
ed299e3c 474 NULL if section not found\r
b1f6a7c6 475\r
ed299e3c
LG
476 @return EFI_NOT_FOUND The match section is not found.\r
477 @return EFI_SUCCESS The match section is found.\r
b1f6a7c6 478\r
479**/\r
b0d803fe 480EFI_STATUS\r
3b428ade 481ProcessSection (\r
b0d803fe 482 IN CONST EFI_PEI_SERVICES **PeiServices,\r
483 IN EFI_SECTION_TYPE SectionType,\r
484 IN EFI_COMMON_SECTION_HEADER *Section,\r
485 IN UINTN SectionSize,\r
288f9b38 486 OUT VOID **OutputBuffer\r
b0d803fe 487 )\r
b0d803fe 488{\r
489 EFI_STATUS Status;\r
490 UINT32 SectionLength;\r
491 UINT32 ParsedLength;\r
b0d803fe 492 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;\r
b0d803fe 493 EFI_PEI_DECOMPRESS_PPI *DecompressPpi;\r
494 VOID *PpiOutput;\r
495 UINTN PpiOutputSize;\r
288f9b38
LG
496 UINTN Index;\r
497 UINT32 Authentication;\r
498 PEI_CORE_INSTANCE *PrivateData;\r
b0d803fe 499\r
288f9b38 500 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
b0d803fe 501 *OutputBuffer = NULL;\r
288f9b38
LG
502 ParsedLength = 0;\r
503 Index = 0;\r
504 Status = EFI_NOT_FOUND;\r
505 PpiOutput = NULL;\r
506 PpiOutputSize = 0;\r
b0d803fe 507 while (ParsedLength < SectionSize) {\r
508 if (Section->Type == SectionType) {\r
509 *OutputBuffer = (VOID *)(Section + 1);\r
510 return EFI_SUCCESS;\r
288f9b38
LG
511 } else if ((Section->Type == EFI_SECTION_GUID_DEFINED) || (Section->Type == EFI_SECTION_COMPRESSION)) {\r
512 //\r
513 // Check the encapsulated section is extracted into the cache data.\r
514 //\r
515 for (Index = 0; Index < PrivateData->CacheSection.AllSectionCount; Index ++) {\r
516 if (Section == PrivateData->CacheSection.Section[Index]) {\r
517 PpiOutput = PrivateData->CacheSection.SectionData[Index];\r
518 PpiOutputSize = PrivateData->CacheSection.SectionSize[Index];\r
519 //\r
520 // Search section directly from the cache data.\r
521 //\r
3b428ade 522 return ProcessSection (\r
523 PeiServices,\r
524 SectionType, \r
525 PpiOutput, \r
526 PpiOutputSize, \r
527 OutputBuffer \r
528 );\r
b0d803fe 529 }\r
530 }\r
288f9b38
LG
531 \r
532 Status = EFI_NOT_FOUND;\r
533 if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r
534 Status = PeiServicesLocatePpi (\r
535 &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid, \r
536 0, \r
537 NULL, \r
538 (VOID **) &GuidSectionPpi\r
539 );\r
b0d803fe 540 if (!EFI_ERROR (Status)) {\r
288f9b38 541 Status = GuidSectionPpi->ExtractSection (\r
3b428ade 542 GuidSectionPpi,\r
543 Section,\r
544 &PpiOutput,\r
545 &PpiOutputSize,\r
546 &Authentication\r
547 );\r
288f9b38
LG
548 }\r
549 } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r
550 Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r
551 if (!EFI_ERROR (Status)) {\r
552 Status = DecompressPpi->Decompress (\r
553 DecompressPpi,\r
554 (CONST EFI_COMPRESSION_SECTION*) Section,\r
555 &PpiOutput,\r
556 &PpiOutputSize\r
557 );\r
b0d803fe 558 }\r
559 }\r
288f9b38
LG
560 \r
561 if (!EFI_ERROR (Status)) {\r
562 //\r
563 // Update cache section data.\r
564 //\r
565 if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r
566 PrivateData->CacheSection.AllSectionCount ++;\r
567 }\r
568 PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r
569 PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r
570 PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r
571 PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r
572 \r
3b428ade 573 return ProcessSection (\r
574 PeiServices,\r
575 SectionType, \r
576 PpiOutput, \r
577 PpiOutputSize, \r
578 OutputBuffer \r
579 );\r
288f9b38 580 }\r
b0d803fe 581 }\r
582\r
583 //\r
584 // Size is 24 bits wide so mask upper 8 bits. \r
585 // SectionLength is adjusted it is 4 byte aligned.\r
586 // Go to the next section\r
587 //\r
588 SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;\r
589 SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r
590 ASSERT (SectionLength != 0);\r
591 ParsedLength += SectionLength;\r
592 Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r
593 }\r
594 \r
595 return EFI_NOT_FOUND;\r
596}\r
597\r
192f6d4c 598\r
b1f6a7c6 599/**\r
3b428ade 600 Searches for the next matching section within the specified file.\r
b1f6a7c6 601\r
ed299e3c 602 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
b1f6a7c6 603 @param SectionType Filter to find only sections of this type.\r
604 @param FileHandle Pointer to the current file to search.\r
ed299e3c 605 @param SectionData A pointer to the discovered section, if successful.\r
b1f6a7c6 606 NULL if section not found\r
607\r
3b428ade 608 @retval EFI_NOT_FOUND The section was not found.\r
609 @retval EFI_SUCCESS The section was found.\r
b1f6a7c6 610\r
611**/\r
192f6d4c 612EFI_STATUS\r
613EFIAPI\r
614PeiFfsFindSectionData (\r
3b428ade 615 IN CONST EFI_PEI_SERVICES **PeiServices,\r
192f6d4c 616 IN EFI_SECTION_TYPE SectionType,\r
0c2b5da8 617 IN EFI_PEI_FILE_HANDLE FileHandle,\r
3b428ade 618 OUT VOID **SectionData\r
192f6d4c 619 )\r
192f6d4c 620{\r
3b428ade 621 PEI_CORE_FV_HANDLE *CoreFvHandle;\r
622 \r
623 CoreFvHandle = FileHandleToVolume (FileHandle);\r
624 if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r
625 return EFI_NOT_FOUND;\r
626 }\r
627 \r
628 return CoreFvHandle->FvPpi->FindSectionByType (CoreFvHandle->FvPpi, SectionType, FileHandle, SectionData);\r
192f6d4c 629}\r
630\r
b1f6a7c6 631/**\r
3b428ade 632 Searches for the next matching file in the firmware volume.\r
b1f6a7c6 633\r
d73d93c3 634 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
b1f6a7c6 635 @param SearchType Filter to find only files of this type.\r
636 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
aa75dfec 637 @param FvHandle Handle of firmware volume in which to search.\r
3b428ade 638 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start\r
639 at the beginning of the firmware volume. On exit, points the file handle of the next file\r
640 in the volume or NULL if there are no more files.\r
641\r
642 @retval EFI_NOT_FOUND The file was not found.\r
643 @retval EFI_NOT_FOUND The header checksum was not zero.\r
644 @retval EFI_SUCCESS The file was found.\r
b1f6a7c6 645\r
646**/\r
192f6d4c 647EFI_STATUS\r
648EFIAPI\r
649PeiFfsFindNextFile (\r
0c2b5da8 650 IN CONST EFI_PEI_SERVICES **PeiServices,\r
651 IN UINT8 SearchType,\r
3b428ade 652 IN EFI_PEI_FV_HANDLE FvHandle,\r
0c2b5da8 653 IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r
192f6d4c 654 )\r
192f6d4c 655{\r
3b428ade 656 PEI_CORE_FV_HANDLE *CoreFvHandle;\r
657 \r
658 CoreFvHandle = FvHandleToCoreHandle (FvHandle);\r
659 \r
2f016ba8 660 //\r
661 // To make backward compatiblity, if can not find corresponding the handle of FV\r
662 // then treat FV as build-in FFS2 format and memory mapped FV that FV handle is pointed\r
663 // to the address of first byte of FV.\r
664 //\r
665 if ((CoreFvHandle == NULL) && FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r
666 return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r
667 } \r
668 \r
3b428ade 669 if ((CoreFvHandle == NULL) || CoreFvHandle->FvPpi == NULL) {\r
670 return EFI_NOT_FOUND;\r
671 }\r
672 \r
673 return CoreFvHandle->FvPpi->FindFileByType (CoreFvHandle->FvPpi, SearchType, FvHandle, FileHandle);\r
192f6d4c 674}\r
675\r
b0d803fe 676\r
b1f6a7c6 677/**\r
ed299e3c 678 Search the firmware volumes by index\r
b1f6a7c6 679\r
ed299e3c 680 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
3b428ade 681 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware\r
682 Volume (BFV).\r
683 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.\r
b1f6a7c6 684\r
3b428ade 685 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL\r
686 @retval EFI_NOT_FOUND The volume was not found.\r
687 @retval EFI_SUCCESS The volume was found.\r
b1f6a7c6 688\r
689**/\r
192f6d4c 690EFI_STATUS \r
691EFIAPI\r
3b428ade 692PeiFfsFindNextVolume (\r
2a00326e 693 IN CONST EFI_PEI_SERVICES **PeiServices,\r
192f6d4c 694 IN UINTN Instance,\r
0c2b5da8 695 IN OUT EFI_PEI_FV_HANDLE *VolumeHandle\r
192f6d4c 696 )\r
192f6d4c 697{\r
3b428ade 698 PEI_CORE_INSTANCE *Private;\r
699 PEI_CORE_FV_HANDLE *CoreFvHandle;\r
700 \r
3e4c5b49 701 if (VolumeHandle == NULL) {\r
702 return EFI_INVALID_PARAMETER;\r
703 }\r
704 \r
b0d803fe 705 Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
2a00326e 706 \r
3b428ade 707 CoreFvHandle = FindNextCoreFvHandle (Private, Instance);\r
708 if (CoreFvHandle == NULL) {\r
709 *VolumeHandle = NULL;\r
710 return EFI_NOT_FOUND;\r
2a00326e 711 }\r
3b428ade 712 \r
713 *VolumeHandle = CoreFvHandle->FvHandle;\r
714 \r
b0d803fe 715 return EFI_SUCCESS;\r
716}\r
192f6d4c 717\r
192f6d4c 718\r
b1f6a7c6 719/**\r
ed299e3c 720 Find a file within a volume by its name.\r
b1f6a7c6 721\r
ed299e3c
LG
722 @param FileName A pointer to the name of the file to find within the firmware volume.\r
723 @param VolumeHandle The firmware volume to search\r
724 @param FileHandle Upon exit, points to the found file's handle \r
725 or NULL if it could not be found.\r
b1f6a7c6 726\r
ed299e3c
LG
727 @retval EFI_SUCCESS File was found.\r
728 @retval EFI_NOT_FOUND File was not found.\r
729 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.\r
b1f6a7c6 730\r
b1f6a7c6 731**/\r
b0d803fe 732EFI_STATUS\r
733EFIAPI \r
734PeiFfsFindFileByName (\r
735 IN CONST EFI_GUID *FileName,\r
736 IN EFI_PEI_FV_HANDLE VolumeHandle,\r
737 OUT EFI_PEI_FILE_HANDLE *FileHandle\r
738 )\r
b0d803fe 739{\r
3b428ade 740 PEI_CORE_FV_HANDLE *CoreFvHandle;\r
741 \r
b0d803fe 742 if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r
192f6d4c 743 return EFI_INVALID_PARAMETER;\r
744 }\r
3b428ade 745 \r
746 CoreFvHandle = FvHandleToCoreHandle (VolumeHandle);\r
747 if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r
748 return EFI_NOT_FOUND;\r
b0d803fe 749 }\r
3b428ade 750 \r
751 return CoreFvHandle->FvPpi->FindFileByName (CoreFvHandle->FvPpi, FileName, &VolumeHandle, FileHandle);\r
b0d803fe 752}\r
753\r
b1f6a7c6 754/**\r
b1f6a7c6 755 Returns information about a specific file.\r
756\r
3b428ade 757 @param FileHandle Handle of the file.\r
758 @param FileInfo Upon exit, points to the file’s information.\r
b1f6a7c6 759\r
3b428ade 760 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r
761 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.\r
762 @retval EFI_SUCCESS File information returned.\r
b1f6a7c6 763\r
764**/\r
b0d803fe 765EFI_STATUS\r
766EFIAPI \r
767PeiFfsGetFileInfo (\r
768 IN EFI_PEI_FILE_HANDLE FileHandle,\r
769 OUT EFI_FV_FILE_INFO *FileInfo\r
770 )\r
b0d803fe 771{\r
3b428ade 772 PEI_CORE_FV_HANDLE *CoreFvHandle;\r
773 \r
b0d803fe 774 if ((FileHandle == NULL) || (FileInfo == NULL)) {\r
775 return EFI_INVALID_PARAMETER;\r
776 }\r
777\r
778 //\r
779 // Retrieve the FirmwareVolume which the file resides in.\r
780 //\r
3b428ade 781 CoreFvHandle = FileHandleToVolume (FileHandle);\r
782 if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r
b0d803fe 783 return EFI_INVALID_PARAMETER;\r
784 }\r
785\r
3b428ade 786 return CoreFvHandle->FvPpi->GetFileInfo (CoreFvHandle->FvPpi, FileHandle, FileInfo);\r
b0d803fe 787}\r
788\r
789\r
b1f6a7c6 790/**\r
3b428ade 791 Returns information about the specified volume.\r
b1f6a7c6 792\r
5a9403b8 793 This function returns information about a specific firmware\r
794 volume, including its name, type, attributes, starting address\r
795 and size.\r
796\r
797 @param VolumeHandle Handle of the volume.\r
798 @param VolumeInfo Upon exit, points to the volume's information.\r
799\r
800 @retval EFI_SUCCESS Volume information returned.\r
801 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.\r
802 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.\r
803 @retval EFI_SUCCESS Information successfully returned.\r
804 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.\r
b1f6a7c6 805\r
b1f6a7c6 806**/\r
b0d803fe 807EFI_STATUS\r
808EFIAPI \r
809PeiFfsGetVolumeInfo (\r
810 IN EFI_PEI_FV_HANDLE VolumeHandle,\r
811 OUT EFI_FV_INFO *VolumeInfo\r
812 )\r
b0d803fe 813{\r
3b428ade 814 PEI_CORE_FV_HANDLE *CoreHandle;\r
815 \r
8fdcc412 816 if ((VolumeInfo == NULL) || (VolumeHandle == NULL)) {\r
b0d803fe 817 return EFI_INVALID_PARAMETER;\r
192f6d4c 818 }\r
288f9b38 819 \r
3b428ade 820 CoreHandle = FvHandleToCoreHandle (VolumeHandle);\r
821 \r
822 if ((CoreHandle == NULL) || (CoreHandle->FvPpi == NULL)) {\r
288f9b38
LG
823 return EFI_INVALID_PARAMETER;\r
824 }\r
3b428ade 825 \r
826 return CoreHandle->FvPpi->GetVolumeInfo (CoreHandle->FvPpi, VolumeHandle, VolumeInfo);\r
192f6d4c 827}\r
b0d803fe 828\r
4c6486b9 829/**\r
830 Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r
831\r
3b428ade 832 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.\r
97b2c9b5 833 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.\r
4c6486b9 834\r
835 @retval EFI_NOT_FOUND FV image can't be found.\r
836 @retval EFI_SUCCESS Successfully to process it.\r
837 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image\r
838 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section\r
839 \r
840**/\r
841EFI_STATUS\r
842ProcessFvFile (\r
3b428ade 843 IN PEI_CORE_FV_HANDLE *ParentFvCoreHandle,\r
844 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle\r
4c6486b9 845 )\r
846{\r
3b428ade 847 EFI_STATUS Status;\r
848 EFI_FV_INFO ParentFvImageInfo;\r
849 UINT32 FvAlignment;\r
850 VOID *NewFvBuffer;\r
851 EFI_PEI_HOB_POINTERS HobPtr;\r
852 EFI_PEI_FIRMWARE_VOLUME_PPI *ParentFvPpi;\r
853 EFI_PEI_FV_HANDLE ParentFvHandle;\r
854 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r
855 EFI_FV_FILE_INFO FileInfo;\r
b4d856a6 856 UINT64 FvLength;\r
3b428ade 857 \r
4c6486b9 858 //\r
859 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
860 // been extracted.\r
861 //\r
862 HobPtr.Raw = GetHobList ();\r
863 while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {\r
97b2c9b5 864 if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)ParentFvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {\r
4c6486b9 865 //\r
866 // this FILE has been dispatched, it will not be dispatched again.\r
867 //\r
3b428ade 868 DEBUG ((EFI_D_INFO, "FV file %p has been dispatched!\r\n", ParentFvFileHandle));\r
4c6486b9 869 return EFI_SUCCESS;\r
870 }\r
871 HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r
872 }\r
873\r
3b428ade 874 ParentFvHandle = ParentFvCoreHandle->FvHandle;\r
875 ParentFvPpi = ParentFvCoreHandle->FvPpi;\r
876 \r
4c6486b9 877 //\r
878 // Find FvImage in FvFile\r
879 //\r
3b428ade 880 Status = ParentFvPpi->FindSectionByType (\r
881 ParentFvPpi,\r
882 EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r
883 ParentFvFileHandle,\r
884 (VOID **)&FvHeader\r
885 );\r
886 \r
4c6486b9 887 if (EFI_ERROR (Status)) {\r
888 return Status;\r
889 }\r
97b2c9b5
LG
890\r
891 //\r
3b428ade 892 // FvAlignment must be more than 8 bytes required by FvHeader structure.\r
4c6486b9 893 //\r
b4d856a6 894 FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
4c6486b9 895 if (FvAlignment < 8) {\r
896 FvAlignment = 8;\r
897 }\r
898 \r
899 //\r
900 // Check FvImage\r
901 //\r
3b428ade 902 if ((UINTN) FvHeader % FvAlignment != 0) {\r
b4d856a6 903 FvLength = ReadUnaligned64 (&FvHeader->FvLength);\r
904 NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment);\r
3b428ade 905 if (NewFvBuffer == NULL) {\r
4c6486b9 906 return EFI_OUT_OF_RESOURCES;\r
907 }\r
b4d856a6 908 CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
3b428ade 909 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r
4c6486b9 910 }\r
3b428ade 911 \r
912 Status = ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, &ParentFvImageInfo);\r
913 ASSERT_EFI_ERROR (Status);\r
914 \r
915 Status = ParentFvPpi->GetFileInfo (ParentFvPpi, ParentFvFileHandle, &FileInfo);\r
916 ASSERT_EFI_ERROR (Status);\r
917 \r
4c6486b9 918 //\r
919 // Install FvPpi and Build FvHob\r
920 //\r
187f1a5b 921 PeiServicesInstallFvInfoPpi (\r
3b428ade 922 &FvHeader->FileSystemGuid,\r
923 (VOID**) FvHeader,\r
924 (UINT32) FvHeader->FvLength,\r
97b2c9b5 925 &ParentFvImageInfo.FvName,\r
3b428ade 926 &FileInfo.FileName\r
4c6486b9 927 );\r
928\r
929 //\r
930 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r
4c6486b9 931 //\r
223c22d8 932 BuildFvHob (\r
3b428ade 933 (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
934 FvHeader->FvLength\r
18fcd6a7 935 );\r
4c6486b9 936\r
937 //\r
938 // Makes the encapsulated volume show up in DXE phase to skip processing of\r
939 // encapsulated file again.\r
940 //\r
941 BuildFv2Hob (\r
3b428ade 942 (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
943 FvHeader->FvLength,\r
97b2c9b5 944 &ParentFvImageInfo.FvName,\r
3b428ade 945 &FileInfo.FileName\r
4c6486b9 946 );\r
947\r
948 return EFI_SUCCESS;\r
949}\r
950\r
3b428ade 951/**\r
952 Process a firmware volume and create a volume handle.\r
953\r
954 Create a volume handle from the information in the buffer. For\r
955 memory-mapped firmware volumes, Buffer and BufferSize refer to\r
956 the start of the firmware volume and the firmware volume size.\r
957 For non memory-mapped firmware volumes, this points to a\r
958 buffer which contains the necessary information for creating\r
959 the firmware volume handle. Normally, these values are derived\r
960 from the EFI_FIRMWARE_VOLUME_INFO_PPI.\r
961 \r
962 \r
963 @param This Points to this instance of the\r
964 EFI_PEI_FIRMWARE_VOLUME_PPI.\r
965 @param Buffer Points to the start of the buffer.\r
966 @param BufferSize Size of the buffer.\r
967 @param FvHandle Points to the returned firmware volume\r
968 handle. The firmware volume handle must\r
969 be unique within the system. \r
970\r
971 @retval EFI_SUCCESS Firmware volume handle created.\r
972 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.\r
973\r
974**/\r
975EFI_STATUS\r
976EFIAPI\r
977PeiFfs2FvPpiProcessVolume (\r
978 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r
979 IN VOID *Buffer,\r
980 IN UINTN BufferSize,\r
981 OUT EFI_PEI_FV_HANDLE *FvHandle\r
982 )\r
983{\r
984 EFI_STATUS Status;\r
3b428ade 985 \r
dc6f9b35 986 ASSERT (FvHandle != NULL);\r
987 \r
988 if (Buffer == NULL) {\r
989 return EFI_VOLUME_CORRUPTED;\r
990 }\r
3b428ade 991 \r
992 //\r
993 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2 support memory-mapped\r
994 // FV image and the handle is pointed to Fv image's buffer.\r
995 //\r
996 *FvHandle = (EFI_PEI_FV_HANDLE) Buffer;\r
997 \r
998 //\r
999 // Do verify for given FV buffer.\r
1000 //\r
1001 Status = VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER*) Buffer);\r
1002 if (EFI_ERROR(Status)) {\r
1003 DEBUG ((EFI_D_ERROR, "Fail to verify FV which address is 0x%11p", Buffer));\r
1004 return EFI_VOLUME_CORRUPTED;\r
1005 }\r
1006\r
3b428ade 1007 return EFI_SUCCESS;\r
1008} \r
1009\r
1010/**\r
1011 Finds the next file of the specified type.\r
1012\r
1013 This service enables PEI modules to discover additional firmware files. \r
1014 The FileHandle must be unique within the system.\r
1015\r
1016 @param This Points to this instance of the\r
1017 EFI_PEI_FIRMWARE_VOLUME_PPI.\r
1018 @param SearchType A filter to find only files of this type. Type\r
1019 EFI_FV_FILETYPE_ALL causes no filtering to be\r
1020 done.\r
1021 @param FvHandle Handle of firmware volume in which to\r
1022 search.\r
1023 @param FileHandle Points to the current handle from which to\r
1024 begin searching or NULL to start at the\r
1025 beginning of the firmware volume. Updated\r
1026 upon return to reflect the file found.\r
1027\r
1028 @retval EFI_SUCCESS The file was found.\r
1029 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.\r
1030\r
1031**/\r
1032EFI_STATUS\r
1033EFIAPI\r
1034PeiFfs2FvPpiFindFileByType (\r
1035 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r
1036 IN EFI_FV_FILETYPE SearchType,\r
1037 IN EFI_PEI_FV_HANDLE FvHandle,\r
1038 IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r
1039 )\r
1040{ \r
1041 return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r
1042}\r
1043\r
1044/**\r
1045 Find a file within a volume by its name. \r
1046 \r
1047 This service searches for files with a specific name, within\r
1048 either the specified firmware volume or all firmware volumes.\r
1049\r
1050 @param This Points to this instance of the\r
1051 EFI_PEI_FIRMWARE_VOLUME_PPI.\r
1052 @param FileName A pointer to the name of the file to find\r
1053 within the firmware volume.\r
1054 @param FvHandle Upon entry, the pointer to the firmware\r
1055 volume to search or NULL if all firmware\r
1056 volumes should be searched. Upon exit, the\r
1057 actual firmware volume in which the file was\r
1058 found.\r
1059 @param FileHandle Upon exit, points to the found file's\r
1060 handle or NULL if it could not be found.\r
1061\r
1062 @retval EFI_SUCCESS File was found.\r
1063 @retval EFI_NOT_FOUND File was not found.\r
1064 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or\r
1065 FileName was NULL.\r
1066\r
1067\r
1068**/\r
1069EFI_STATUS\r
1070EFIAPI\r
1071PeiFfs2FvPpiFindFileByName (\r
1072 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r
1073 IN CONST EFI_GUID *FileName,\r
1074 IN EFI_PEI_FV_HANDLE *FvHandle,\r
1075 OUT EFI_PEI_FILE_HANDLE *FileHandle \r
1076 )\r
1077{\r
1078 EFI_STATUS Status;\r
1079 PEI_CORE_INSTANCE *PrivateData;\r
1080 UINTN Index;\r
1081 \r
1082 if ((FvHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r
1083 return EFI_INVALID_PARAMETER;\r
1084 }\r
1085 \r
1086 if (*FvHandle != NULL) {\r
1087 Status = FindFileEx (*FvHandle, FileName, 0, FileHandle, NULL);\r
1088 if (Status == EFI_NOT_FOUND) {\r
1089 *FileHandle = NULL;\r
1090 }\r
1091 } else { \r
1092 //\r
1093 // If *FvHandle = NULL, so search all FV for given filename\r
1094 //\r
1095 Status = EFI_NOT_FOUND;\r
1096 \r
1097 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());\r
1098 for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r
1099 //\r
1100 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.\r
1101 //\r
1102 if (PrivateData->Fv[Index].FvPpi != NULL) {\r
1103 Status = FindFileEx (PrivateData->Fv[Index].FvHandle, FileName, 0, FileHandle, NULL);\r
1104 if (!EFI_ERROR (Status)) {\r
1105 *FvHandle = PrivateData->Fv[Index].FvHandle;\r
1c738c8f 1106 break;\r
3b428ade 1107 }\r
1108 }\r
1109 }\r
1110 }\r
1111 \r
1112 return Status; \r
1113} \r
1114\r
1115/**\r
1116 Returns information about a specific file.\r
1117\r
1118 This function returns information about a specific\r
1119 file, including its file name, type, attributes, starting\r
1120 address and size. \r
1121 \r
1122 @param This Points to this instance of the\r
1123 EFI_PEI_FIRMWARE_VOLUME_PPI.\r
1124 @param FileHandle Handle of the file.\r
1125 @param FileInfo Upon exit, points to the file's\r
1126 information.\r
1127\r
1128 @retval EFI_SUCCESS File information returned.\r
1129 @retval EFI_INVALID_PARAMETER If FileHandle does not\r
1130 represent a valid file.\r
1131 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r
1132 \r
1133**/ \r
1134EFI_STATUS\r
1135EFIAPI\r
1136PeiFfs2FvPpiGetFileInfo (\r
1137 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This, \r
1138 IN EFI_PEI_FILE_HANDLE FileHandle, \r
1139 OUT EFI_FV_FILE_INFO *FileInfo\r
1140 )\r
1141{\r
1142 UINT8 FileState;\r
1143 UINT8 ErasePolarity;\r
1144 EFI_FFS_FILE_HEADER *FileHeader;\r
1145 PEI_CORE_FV_HANDLE *CoreFvHandle;\r
1146 \r
1147 if ((FileHandle == NULL) || (FileInfo == NULL)) {\r
1148 return EFI_INVALID_PARAMETER;\r
1149 }\r
1150\r
1151 //\r
1152 // Retrieve the FirmwareVolume which the file resides in.\r
1153 //\r
1154 CoreFvHandle = FileHandleToVolume (FileHandle);\r
1155 if (CoreFvHandle == NULL) {\r
1156 return EFI_INVALID_PARAMETER;\r
1157 }\r
1158\r
1159 if (CoreFvHandle->FvHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
1160 ErasePolarity = 1;\r
1161 } else {\r
1162 ErasePolarity = 0;\r
1163 }\r
1164\r
1165 //\r
1166 // Get FileState which is the highest bit of the State \r
1167 //\r
1168 FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);\r
1169\r
1170 switch (FileState) {\r
1171 case EFI_FILE_DATA_VALID:\r
1172 case EFI_FILE_MARKED_FOR_UPDATE:\r
1173 break; \r
1174 default:\r
1175 return EFI_INVALID_PARAMETER;\r
1176 }\r
1177\r
1178 FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;\r
1179 CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));\r
1180 FileInfo->FileType = FileHeader->Type;\r
1181 FileInfo->FileAttributes = FileHeader->Attributes;\r
1182 FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER);\r
1183 FileInfo->Buffer = (FileHeader + 1);\r
1184 return EFI_SUCCESS; \r
1185} \r
1186 \r
1187/**\r
1188 This function returns information about the firmware volume.\r
1189 \r
1190 @param This Points to this instance of the\r
1191 EFI_PEI_FIRMWARE_VOLUME_PPI.\r
1192 @param FvHandle Handle to the firmware handle.\r
1193 @param VolumeInfo Points to the returned firmware volume\r
1194 information.\r
1195\r
1196 @retval EFI_SUCCESS Information returned successfully.\r
1197 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid\r
1198 firmware volume or VolumeInfo is NULL.\r
1199\r
1200**/ \r
1201EFI_STATUS\r
1202EFIAPI\r
1203PeiFfs2FvPpiGetVolumeInfo (\r
1204 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This, \r
1205 IN EFI_PEI_FV_HANDLE FvHandle, \r
1206 OUT EFI_FV_INFO *VolumeInfo\r
1207 )\r
1208{\r
1209 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader;\r
1210 EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;\r
1211\r
8fdcc412 1212 if ((VolumeInfo == NULL) || (FvHandle == NULL)) {\r
3b428ade 1213 return EFI_INVALID_PARAMETER;\r
1214 }\r
1215 \r
1216 //\r
1217 // VolumeHandle may not align at 8 byte, \r
1218 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. \r
1219 // So, Copy FvHeader into the local FvHeader structure.\r
1220 //\r
1221 CopyMem (&FwVolHeader, FvHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r
1222\r
1223 //\r
1224 // Check Fv Image Signature\r
1225 //\r
1226 if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r
1227 return EFI_INVALID_PARAMETER;\r
1228 }\r
1229\r
1230 ZeroMem (VolumeInfo, sizeof (EFI_FV_INFO));\r
1231 VolumeInfo->FvAttributes = FwVolHeader.Attributes;\r
1232 VolumeInfo->FvStart = (VOID *) FvHandle;\r
1233 VolumeInfo->FvSize = FwVolHeader.FvLength;\r
1234 CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));\r
1235\r
1236 if (FwVolHeader.ExtHeaderOffset != 0) {\r
1237 FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)FvHandle) + FwVolHeader.ExtHeaderOffset);\r
1238 CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));\r
1239 }\r
1240 \r
1241 return EFI_SUCCESS; \r
1242} \r
1243\r
1244/**\r
1245 Find the next matching section in the firmware file.\r
1246 \r
1247 This service enables PEI modules to discover sections\r
1248 of a given type within a valid file.\r
1249 \r
1250 @param This Points to this instance of the\r
1251 EFI_PEI_FIRMWARE_VOLUME_PPI.\r
1252 @param SearchType A filter to find only sections of this\r
1253 type.\r
1254 @param FileHandle Handle of firmware file in which to\r
1255 search.\r
1256 @param SectionData Updated upon return to point to the\r
1257 section found.\r
1258 \r
1259 @retval EFI_SUCCESS Section was found.\r
1260 @retval EFI_NOT_FOUND Section of the specified type was not\r
1261 found. SectionData contains NULL.\r
1262**/\r
1263EFI_STATUS\r
1264EFIAPI\r
1265PeiFfs2FvPpiFindSectionByType (\r
1266 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r
1267 IN EFI_SECTION_TYPE SearchType,\r
1268 IN EFI_PEI_FILE_HANDLE FileHandle,\r
1269 OUT VOID **SectionData\r
1270 )\r
1271{\r
1272 EFI_FFS_FILE_HEADER *FfsFileHeader;\r
1273 UINT32 FileSize;\r
1274 EFI_COMMON_SECTION_HEADER *Section;\r
1275 \r
1276 FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);\r
1277\r
1278 //\r
1279 // Size is 24 bits wide so mask upper 8 bits. \r
1280 // Does not include FfsFileHeader header size\r
1281 // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
1282 //\r
1283 Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);\r
1284 FileSize = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
1285 FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r
1286\r
1287 return ProcessSection (\r
1288 GetPeiServicesTablePointer (),\r
1289 SearchType, \r
1290 Section, \r
1291 FileSize, \r
1292 SectionData\r
1293 ); \r
1294} \r
1295\r
1296/**\r
1297 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.\r
1298 \r
1299 @param FvHandle The handle of a FV.\r
1300 \r
1301 @retval NULL if can not find.\r
1302 @return Pointer of corresponding PEI_CORE_FV_HANDLE. \r
1303**/\r
1304PEI_CORE_FV_HANDLE *\r
1305FvHandleToCoreHandle (\r
1306 IN EFI_PEI_FV_HANDLE FvHandle\r
1307 )\r
1308{\r
1309 UINTN Index;\r
1310 PEI_CORE_INSTANCE *PrivateData;\r
1311 \r
1312 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer()); \r
1313 for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r
1314 if (FvHandle == PrivateData->Fv[Index].FvHandle) {\r
1315 return &PrivateData->Fv[Index];\r
1316 }\r
1317 }\r
1318 \r
1319 return NULL;\r
1320} \r
1321\r
1322/**\r
1323 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.\r
1324 \r
1325 This routine also will install FvInfo ppi for FV hob in PI ways.\r
1326 \r
1327 @param Private Pointer of PEI_CORE_INSTANCE\r
1328 @param Instance The index of FV want to be searched.\r
1329 \r
1330 @return Instance of PEI_CORE_FV_HANDLE.\r
1331**/\r
1332PEI_CORE_FV_HANDLE *\r
1333FindNextCoreFvHandle (\r
1334 IN PEI_CORE_INSTANCE *Private,\r
1335 IN UINTN Instance\r
1336 )\r
1337{\r
1338 UINTN Index;\r
1339 BOOLEAN Match;\r
1340 EFI_HOB_FIRMWARE_VOLUME *FvHob;\r
1341 \r
1342 //\r
1343 // Handle Framework FvHob and Install FvInfo Ppi for it.\r
1344 //\r
1345 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r
1346 //\r
1347 // Loop to search the wanted FirmwareVolume which supports FFS\r
1348 //\r
1349 FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);\r
1350 while (FvHob != NULL) {\r
1351 for (Index = 0, Match = FALSE; Index < Private->FvCount; Index++) {\r
1352 if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->Fv[Index].FvHeader) {\r
1353 Match = TRUE;\r
1354 break;\r
1355 }\r
1356 }\r
1357 //\r
1358 // If Not Found, Install FvInfo Ppi for it.\r
1359 //\r
1360 if (!Match) {\r
1361 PeiServicesInstallFvInfoPpi (\r
1362 &(((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHob->BaseAddress)->FileSystemGuid),\r
1363 (VOID *)(UINTN)FvHob->BaseAddress,\r
1364 (UINT32)FvHob->Length,\r
1365 NULL,\r
1366 NULL\r
1367 );\r
1368 }\r
1369 FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength)); \r
1370 }\r
1371 }\r
1372\r
1373 if (Instance >= Private->FvCount) {\r
1374 return NULL;\r
1375 }\r
4c6486b9 1376\r
3b428ade 1377 return &Private->Fv[Instance];\r
1378} \r
8e0e40ed 1379\r
1380/**\r
1381 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should\r
1382 be re-installed with the instance in permanent memory and all cached FvPpi pointers in \r
1383 PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant\r
1384 memory.\r
1385 \r
1386 @param PrivateData Pointer to PEI_CORE_INSTANCE.\r
1387**/ \r
1388VOID\r
1389PeiReinitializeFv (\r
1390 IN PEI_CORE_INSTANCE *PrivateData\r
1391 )\r
1392{\r
7ec93917 1393 VOID *OldFfs2FvPpi;\r
1394 EFI_PEI_PPI_DESCRIPTOR *OldDescriptor;\r
1395 UINTN Index;\r
1396 EFI_STATUS Status;\r
1397\r
1398 //\r
1399 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which\r
1400 // in flash.\r
1401 //\r
1402 Status = PeiServicesLocatePpi (\r
1403 &gEfiFirmwareFileSystem2Guid,\r
1404 0,\r
1405 &OldDescriptor,\r
1406 &OldFfs2FvPpi\r
1407 );\r
1408 ASSERT_EFI_ERROR (Status);\r
1409\r
1410 //\r
1411 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2\r
1412 // which is shadowed from flash to permanent memory within PeiCore image.\r
1413 //\r
1414 Status = PeiServicesReInstallPpi (OldDescriptor, &mPeiFfs2FvPpiList);\r
1415 ASSERT_EFI_ERROR (Status);\r
1416 \r
1417 //\r
1418 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r
1419 //\r
188e4e84 1420 for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
7ec93917 1421 if (PrivateData->Fv[Index].FvPpi == OldFfs2FvPpi) {\r
1422 PrivateData->Fv[Index].FvPpi = &mPeiFfs2FvPpi;\r
1423 }\r
1424 }\r
8e0e40ed 1425} \r
1426\r
f3358329 1427/**\r
1428 Report the information for a new discoveried FV in unknown third-party format.\r
1429 \r
1430 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but\r
1431 the FV in this format has been discoveried, then this FV's information will be cached into \r
1432 PEI_CORE_INSTANCE's UnknownFvInfo array.\r
1433 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI\r
1434 is installed later by platform's PEIM, the original unknown third-party FV will be processed by\r
1435 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r
1436 \r
1437 @param PrivateData Point to instance of PEI_CORE_INSTANCE\r
1438 @param Format Point to the unknown third-party format guid.\r
1439 @param FvInfo Point to FvInfo buffer.\r
1440 @param FvInfoSize The size of FvInfo buffer.\r
1441 \r
1442 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.\r
1443 @retval EFI_SUCCESS Success to add the information for unknown FV.\r
1444**/\r
1445EFI_STATUS\r
1446AddUnknownFormatFvInfo (\r
1447 IN PEI_CORE_INSTANCE *PrivateData,\r
1448 IN EFI_GUID *Format,\r
1449 IN VOID *FvInfo,\r
1450 IN UINT32 FvInfoSize\r
1451 )\r
1452{\r
1453 PEI_CORE_UNKNOW_FORMAT_FV_INFO *NewUnknownFv;\r
1454 \r
188e4e84 1455 if (PrivateData->UnknownFvInfoCount + 1 >= PcdGet32 (PcdPeiCoreMaxPeimPerFv)) {\r
f3358329 1456 return EFI_OUT_OF_RESOURCES;\r
1457 }\r
1458 \r
1459 NewUnknownFv = &PrivateData->UnknownFvInfo[PrivateData->UnknownFvInfoCount];\r
1460 PrivateData->UnknownFvInfoCount ++;\r
1461 \r
1462 CopyGuid (&NewUnknownFv->FvFormat, Format);\r
1463 NewUnknownFv->FvInfo = FvInfo;\r
1464 NewUnknownFv->FvInfoSize = FvInfoSize;\r
1465 NewUnknownFv->NotifyDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);\r
1466 NewUnknownFv->NotifyDescriptor.Guid = &NewUnknownFv->FvFormat;\r
1467 NewUnknownFv->NotifyDescriptor.Notify = ThirdPartyFvPpiNotifyCallback;\r
1468 \r
1469 PeiServicesNotifyPpi (&NewUnknownFv->NotifyDescriptor);\r
1470 return EFI_SUCCESS;\r
1471}\r
1472\r
1473/**\r
1474 Find the FV information according to third-party FV format guid.\r
1475 \r
1476 This routine also will remove the FV information found by given FV format guid from\r
1477 PrivateData->UnknownFvInfo[].\r
1478 \r
1479 @param PrivateData Point to instance of PEI_CORE_INSTANCE\r
1480 @param Format Point to given FV format guid\r
1481 @param FvInfo On return, the pointer of FV information buffer\r
1482 @param FvInfoSize On return, the size of FV information buffer.\r
1483 \r
1484 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI\r
1485 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r
1486**/\r
1487EFI_STATUS\r
1488FindUnknownFormatFvInfo (\r
1489 IN PEI_CORE_INSTANCE *PrivateData,\r
1490 IN EFI_GUID *Format,\r
1491 OUT VOID **FvInfo,\r
1492 OUT UINT32 *FvInfoSize\r
1493 )\r
1494{\r
1495 UINTN Index;\r
1496 UINTN Index2;\r
1497\r
1498 Index = 0;\r
1499 for (; Index < PrivateData->UnknownFvInfoCount; Index ++) {\r
1500 if (CompareGuid (Format, &PrivateData->UnknownFvInfo[Index].FvFormat)) {\r
1501 break;\r
1502 }\r
1503 }\r
1504 \r
1505 if (Index == PrivateData->UnknownFvInfoCount) {\r
1506 return EFI_NOT_FOUND;\r
1507 }\r
1508 \r
1509 *FvInfo = PrivateData->UnknownFvInfo[Index].FvInfo;\r
1510 *FvInfoSize = PrivateData->UnknownFvInfo[Index].FvInfoSize;\r
1511 \r
1512 //\r
1513 // Remove an entry from UnknownFvInfo array.\r
1514 //\r
1515 Index2 = Index + 1;\r
1516 for (;Index2 < PrivateData->UnknownFvInfoCount; Index2 ++, Index ++) {\r
1517 CopyMem (&PrivateData->UnknownFvInfo[Index], &PrivateData->UnknownFvInfo[Index2], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO));\r
1518 }\r
1519 PrivateData->UnknownFvInfoCount --;\r
1520 return EFI_SUCCESS;\r
1521} \r
1522\r
1523/**\r
1524 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.\r
1525 \r
1526 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this \r
1527 routine is called to process all discoveried FVs in this format.\r
1528 \r
1529 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
1530 @param NotifyDescriptor Address of the notification descriptor data structure.\r
1531 @param Ppi Address of the PPI that was installed.\r
1532 \r
1533 @retval EFI_SUCCESS The notification callback is processed correctly.\r
1534**/\r
1535EFI_STATUS\r
1536EFIAPI\r
1537ThirdPartyFvPpiNotifyCallback (\r
1538 IN EFI_PEI_SERVICES **PeiServices,\r
1539 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
1540 IN VOID *Ppi\r
1541 )\r
1542{\r
1543 PEI_CORE_INSTANCE *PrivateData;\r
1544 EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r
1545 VOID *FvInfo;\r
1546 UINT32 FvInfoSize;\r
1547 EFI_STATUS Status;\r
1548 EFI_PEI_FV_HANDLE FvHandle;\r
1549 BOOLEAN IsProcessed;\r
1550 UINTN FvIndex;\r
1551 EFI_PEI_FILE_HANDLE FileHandle;\r
1552 VOID *DepexData; \r
1553 \r
1554 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
1555 FvPpi = (EFI_PEI_FIRMWARE_VOLUME_PPI*) Ppi;\r
1556 \r
1557 do {\r
1558 Status = FindUnknownFormatFvInfo (PrivateData, NotifyDescriptor->Guid, &FvInfo, &FvInfoSize);\r
1559 if (EFI_ERROR (Status)) {\r
1560 return EFI_SUCCESS;\r
1561 }\r
1562 \r
1563 //\r
1564 // Process new found FV and get FV handle.\r
1565 //\r
1566 Status = FvPpi->ProcessVolume (FvPpi, FvInfo, FvInfoSize, &FvHandle);\r
1567 if (EFI_ERROR (Status)) {\r
1568 DEBUG ((EFI_D_ERROR, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo));\r
1569 continue;\r
1570 }\r
1571\r
1572 //\r
1573 // Check whether the FV has already been processed.\r
1574 //\r
1575 IsProcessed = FALSE;\r
1576 for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r
1577 if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r
1578 DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfo));\r
1579 IsProcessed = TRUE;\r
1580 break;\r
1581 }\r
1582 }\r
1583 \r
1584 if (IsProcessed) {\r
1585 continue;\r
1586 }\r
1587 \r
1588 //\r
1589 // Update internal PEI_CORE_FV array.\r
1590 //\r
1591 PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfo;\r
1592 PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r
1593 PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
1594 DEBUG ((\r
1595 EFI_D_INFO, \r
1596 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
1597 (UINT32) PrivateData->FvCount, \r
1598 (VOID *) FvInfo, \r
1599 FvInfoSize,\r
1600 FvHandle\r
1601 )); \r
1602 PrivateData->FvCount ++;\r
1603\r
1604 //\r
1605 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \r
1606 //\r
1607 FileHandle = NULL;\r
1608 do {\r
1609 Status = FvPpi->FindFileByType (\r
1610 FvPpi,\r
1611 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r
1612 FvHandle,\r
1613 &FileHandle\r
1614 );\r
1615 if (!EFI_ERROR (Status)) {\r
1616 Status = FvPpi->FindSectionByType (\r
1617 FvPpi,\r
1618 EFI_SECTION_PEI_DEPEX,\r
1619 FileHandle,\r
1620 (VOID**)&DepexData\r
1621 );\r
1622 if (!EFI_ERROR (Status)) {\r
1623 if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r
1624 //\r
1625 // Dependency is not satisfied.\r
1626 //\r
1627 continue;\r
1628 }\r
1629 }\r
1630 \r
1631 DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r
1632 ProcessFvFile (&PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r
1633 }\r
1634 } while (FileHandle != NULL);\r
1635 } while (TRUE);\r
f3358329 1636}\r