2 Pei Core Firmware File System service routines.
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList
[] = {
19 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
20 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
21 FirmwareVolmeInfoPpiNotifyCallback
24 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
25 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
26 FirmwareVolmeInfoPpiNotifyCallback
30 PEI_FW_VOL_INSTANCE mPeiFfs2FwVol
= {
34 PeiFfsFvPpiProcessVolume
,
35 PeiFfsFvPpiFindFileByType
,
36 PeiFfsFvPpiFindFileByName
,
37 PeiFfsFvPpiGetFileInfo
,
38 PeiFfsFvPpiGetVolumeInfo
,
39 PeiFfsFvPpiFindSectionByType
,
40 PeiFfsFvPpiGetFileInfo2
,
41 PeiFfsFvPpiFindSectionByType2
,
42 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
43 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
47 PEI_FW_VOL_INSTANCE mPeiFfs3FwVol
= {
51 PeiFfsFvPpiProcessVolume
,
52 PeiFfsFvPpiFindFileByType
,
53 PeiFfsFvPpiFindFileByName
,
54 PeiFfsFvPpiGetFileInfo
,
55 PeiFfsFvPpiGetVolumeInfo
,
56 PeiFfsFvPpiFindSectionByType
,
57 PeiFfsFvPpiGetFileInfo2
,
58 PeiFfsFvPpiFindSectionByType2
,
59 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
60 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
64 EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList
= {
65 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
66 &gEfiFirmwareFileSystem2Guid
,
70 EFI_PEI_PPI_DESCRIPTOR mPeiFfs3FvPpiList
= {
71 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
72 &gEfiFirmwareFileSystem3Guid
,
77 Required Alignment Alignment Value in FFS Alignment Value in
78 (bytes) Attributes Field Firmware Volume Interfaces
88 UINT8 mFvAttributes
[] = {0, 4, 7, 9, 10, 12, 15, 16};
91 Convert the FFS File Attributes to FV File Attributes
93 @param FfsAttributes The attributes of UINT8 type.
95 @return The attributes of EFI_FV_FILE_ATTRIBUTES
98 EFI_FV_FILE_ATTRIBUTES
99 FfsAttributes2FvFileAttributes (
100 IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
104 EFI_FV_FILE_ATTRIBUTES FileAttribute
;
106 DataAlignment
= (UINT8
) ((FfsAttributes
& FFS_ATTRIB_DATA_ALIGNMENT
) >> 3);
107 ASSERT (DataAlignment
< 8);
109 FileAttribute
= (EFI_FV_FILE_ATTRIBUTES
) mFvAttributes
[DataAlignment
];
111 if ((FfsAttributes
& FFS_ATTRIB_FIXED
) == FFS_ATTRIB_FIXED
) {
112 FileAttribute
|= EFI_FV_FILE_ATTRIB_FIXED
;
115 return FileAttribute
;
119 Returns the file state set by the highest zero bit in the State field
121 @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
122 in the Attributes field.
123 @param FfsHeader Pointer to FFS File Header.
125 @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit
126 in the header State field.
130 IN UINT8 ErasePolarity
,
131 IN EFI_FFS_FILE_HEADER
*FfsHeader
134 EFI_FFS_FILE_STATE FileState
;
135 EFI_FFS_FILE_STATE HighestBit
;
137 FileState
= FfsHeader
->State
;
139 if (ErasePolarity
!= 0) {
140 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
144 // Get file state set by its highest none zero bit.
147 while (HighestBit
!= 0 && (HighestBit
& FileState
) == 0) {
155 Calculates the checksum of the header of a file.
157 @param FileHeader Pointer to FFS File Header.
159 @return Checksum of the header.
160 Zero means the header is good.
161 Non-zero means the header is bad.
164 CalculateHeaderChecksum (
165 IN EFI_FFS_FILE_HEADER
*FileHeader
168 EFI_FFS_FILE_HEADER2 TestFileHeader
;
170 if (IS_FFS_FILE2 (FileHeader
)) {
171 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
173 // Ingore State and File field in FFS header.
175 TestFileHeader
.State
= 0;
176 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
178 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
180 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
182 // Ingore State and File field in FFS header.
184 TestFileHeader
.State
= 0;
185 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
187 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
192 Find FV handler according to FileHandle in that FV.
194 @param FileHandle Handle of file image
196 @return Pointer to instance of PEI_CORE_FV_HANDLE.
200 IN EFI_PEI_FILE_HANDLE FileHandle
204 PEI_CORE_INSTANCE
*PrivateData
;
205 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
207 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
209 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
210 FwVolHeader
= PrivateData
->Fv
[Index
].FvHeader
;
211 if (((UINT64
) (UINTN
) FileHandle
> (UINT64
) (UINTN
) FwVolHeader
) && \
212 ((UINT64
) (UINTN
) FileHandle
<= ((UINT64
) (UINTN
) FwVolHeader
+ FwVolHeader
->FvLength
- 1))) {
213 return &PrivateData
->Fv
[Index
];
220 Given the input file pointer, search for the first matching file in the
221 FFS volume as defined by SearchType. The search starts from FileHeader inside
222 the Firmware Volume defined by FwVolHeader.
223 If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.
224 If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
225 the first PEIM, or COMBINED PEIM or FV file type FFS file will return.
227 @param FvHandle Pointer to the FV header of the volume to search
228 @param FileName File name
229 @param SearchType Filter to find only files of this type.
230 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
231 @param FileHandle This parameter must point to a valid FFS volume.
232 @param AprioriFile Pointer to AprioriFile image in this FV if has
234 @return EFI_NOT_FOUND No files matching the search criteria were found
235 @retval EFI_SUCCESS Success to search given file
240 IN CONST EFI_PEI_FV_HANDLE FvHandle
,
241 IN CONST EFI_GUID
*FileName
, OPTIONAL
242 IN EFI_FV_FILETYPE SearchType
,
243 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
,
244 IN OUT EFI_PEI_FILE_HANDLE
*AprioriFile OPTIONAL
247 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
248 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExtHeader
;
249 EFI_FFS_FILE_HEADER
**FileHeader
;
250 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
252 UINT32 FileOccupiedSize
;
261 // Convert the handle of FV to FV header for memory-mapped firmware volume
263 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvHandle
;
264 FileHeader
= (EFI_FFS_FILE_HEADER
**)FileHandle
;
266 IsFfs3Fv
= CompareGuid (&FwVolHeader
->FileSystemGuid
, &gEfiFirmwareFileSystem3Guid
);
268 FvLength
= FwVolHeader
->FvLength
;
269 if ((FwVolHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
276 // If FileHeader is not specified (NULL) or FileName is not NULL,
277 // start with the first file in the firmware volume. Otherwise,
278 // start from the FileHeader.
280 if ((*FileHeader
== NULL
) || (FileName
!= NULL
)) {
281 if (FwVolHeader
->ExtHeaderOffset
!= 0) {
283 // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
285 FwVolExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*) ((UINT8
*) FwVolHeader
+ FwVolHeader
->ExtHeaderOffset
);
286 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FwVolExtHeader
+ FwVolExtHeader
->ExtHeaderSize
);
287 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ALIGN_POINTER (FfsFileHeader
, 8);
289 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*) FwVolHeader
+ FwVolHeader
->HeaderLength
);
292 if (IS_FFS_FILE2 (*FileHeader
)) {
294 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &(*FileHeader
)->Name
));
296 FileLength
= FFS_FILE2_SIZE (*FileHeader
);
297 ASSERT (FileLength
> 0x00FFFFFF);
299 FileLength
= FFS_FILE_SIZE (*FileHeader
);
302 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
304 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
305 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)*FileHeader
+ FileOccupiedSize
);
308 FileOffset
= (UINT32
) ((UINT8
*)FfsFileHeader
- (UINT8
*)FwVolHeader
);
309 ASSERT (FileOffset
<= 0xFFFFFFFF);
311 while (FileOffset
< (FvLength
- sizeof (EFI_FFS_FILE_HEADER
))) {
313 // Get FileState which is the highest bit of the State
315 FileState
= GetFileState (ErasePolarity
, FfsFileHeader
);
318 case EFI_FILE_HEADER_CONSTRUCTION
:
319 case EFI_FILE_HEADER_INVALID
:
320 if (IS_FFS_FILE2 (FfsFileHeader
)) {
322 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
324 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER2
);
325 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
327 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER
);
328 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
332 case EFI_FILE_DATA_VALID
:
333 case EFI_FILE_MARKED_FOR_UPDATE
:
334 if (CalculateHeaderChecksum (FfsFileHeader
) != 0) {
337 return EFI_NOT_FOUND
;
340 if (IS_FFS_FILE2 (FfsFileHeader
)) {
341 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
342 ASSERT (FileLength
> 0x00FFFFFF);
343 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
345 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
346 FileOffset
+= FileOccupiedSize
;
347 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ FileOccupiedSize
);
351 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
352 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
355 DataCheckSum
= FFS_FIXED_CHECKSUM
;
356 if ((FfsFileHeader
->Attributes
& FFS_ATTRIB_CHECKSUM
) == FFS_ATTRIB_CHECKSUM
) {
357 if (IS_FFS_FILE2 (FfsFileHeader
)) {
358 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
), FileLength
- sizeof(EFI_FFS_FILE_HEADER2
));
360 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
), FileLength
- sizeof(EFI_FFS_FILE_HEADER
));
363 if (FfsFileHeader
->IntegrityCheck
.Checksum
.File
!= DataCheckSum
) {
366 return EFI_NOT_FOUND
;
369 if (FileName
!= NULL
) {
370 if (CompareGuid (&FfsFileHeader
->Name
, (EFI_GUID
*)FileName
)) {
371 *FileHeader
= FfsFileHeader
;
374 } else if (SearchType
== PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
) {
375 if ((FfsFileHeader
->Type
== EFI_FV_FILETYPE_PEIM
) ||
376 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
) ||
377 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
379 *FileHeader
= FfsFileHeader
;
381 } else if (AprioriFile
!= NULL
) {
382 if (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
383 if (CompareGuid (&FfsFileHeader
->Name
, &gPeiAprioriFileNameGuid
)) {
384 *AprioriFile
= FfsFileHeader
;
388 } else if (((SearchType
== FfsFileHeader
->Type
) || (SearchType
== EFI_FV_FILETYPE_ALL
)) &&
389 (FfsFileHeader
->Type
!= EFI_FV_FILETYPE_FFS_PAD
)) {
390 *FileHeader
= FfsFileHeader
;
394 FileOffset
+= FileOccupiedSize
;
395 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
398 case EFI_FILE_DELETED
:
399 if (IS_FFS_FILE2 (FfsFileHeader
)) {
401 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
403 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
404 ASSERT (FileLength
> 0x00FFFFFF);
406 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
408 FileOccupiedSize
= GET_OCCUPIED_SIZE(FileLength
, 8);
409 FileOffset
+= FileOccupiedSize
;
410 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
415 return EFI_NOT_FOUND
;
420 return EFI_NOT_FOUND
;
424 Initialize PeiCore Fv List.
426 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
427 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
431 IN PEI_CORE_INSTANCE
*PrivateData
,
432 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
436 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
437 EFI_PEI_FV_HANDLE FvHandle
;
438 EFI_FIRMWARE_VOLUME_HEADER
*BfvHeader
;
441 // Install FV_PPI for FFS2 file system.
443 PeiServicesInstallPpi (&mPeiFfs2FvPpiList
);
446 // Install FV_PPI for FFS3 file system.
448 PeiServicesInstallPpi (&mPeiFfs3FvPpiList
);
450 BfvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
453 // The FV_PPI in BFV's format should be installed.
455 Status
= PeiServicesLocatePpi (
456 &BfvHeader
->FileSystemGuid
,
461 ASSERT_EFI_ERROR (Status
);
466 FvPpi
->ProcessVolume (
468 SecCoreData
->BootFirmwareVolumeBase
,
469 (UINTN
)BfvHeader
->FvLength
,
474 // Update internal PEI_CORE_FV array.
476 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= BfvHeader
;
477 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
478 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
479 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= 0;
482 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
483 (UINT32
) PrivateData
->FvCount
,
488 PrivateData
->FvCount
++;
491 // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose
492 // additional Fvs to PeiCore.
494 Status
= PeiServicesNotifyPpi (mNotifyOnFvInfoList
);
495 ASSERT_EFI_ERROR (Status
);
500 Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.
501 The FV Info will be registered into PeiCore private data structure.
502 And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.
504 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
505 @param NotifyDescriptor Address of the notification descriptor data structure.
506 @param Ppi Address of the PPI that was installed.
508 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
509 @return if not EFI_SUCESS, fail to verify FV.
514 FirmwareVolmeInfoPpiNotifyCallback (
515 IN EFI_PEI_SERVICES
**PeiServices
,
516 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
520 EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI FvInfo2Ppi
;
521 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
522 PEI_CORE_INSTANCE
*PrivateData
;
524 EFI_PEI_FV_HANDLE FvHandle
;
526 EFI_PEI_FILE_HANDLE FileHandle
;
529 Status
= EFI_SUCCESS
;
530 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
532 if (PrivateData
->FvCount
>= FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)) {
533 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)));
534 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
538 if (CompareGuid (NotifyDescriptor
->Guid
, &gEfiPeiFirmwareVolumeInfo2PpiGuid
)) {
542 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
));
547 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
548 FvInfo2Ppi
.AuthenticationStatus
= 0;
552 // Locate the corresponding FV_PPI according to founded FV's format guid
554 Status
= PeiServicesLocatePpi (
555 &FvInfo2Ppi
.FvFormat
,
560 if (!EFI_ERROR (Status
)) {
562 // Process new found FV and get FV handle.
564 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo2Ppi
.FvInfo
, FvInfo2Ppi
.FvInfoSize
, &FvHandle
);
565 if (EFI_ERROR (Status
)) {
566 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!\n"));
571 // Check whether the FV has already been processed.
573 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
574 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
575 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo2Ppi
.FvInfo
));
581 // Update internal PEI_CORE_FV array.
583 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
;
584 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
585 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
586 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
589 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
590 (UINT32
) PrivateData
->FvCount
,
591 (VOID
*) FvInfo2Ppi
.FvInfo
,
592 FvInfo2Ppi
.FvInfoSize
,
595 PrivateData
->FvCount
++;
598 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
602 Status
= FvPpi
->FindFileByType (
604 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
608 if (!EFI_ERROR (Status
)) {
609 Status
= FvPpi
->FindSectionByType (
611 EFI_SECTION_PEI_DEPEX
,
615 if (!EFI_ERROR (Status
)) {
616 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
618 // Dependency is not satisfied.
624 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
625 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
627 } while (FileHandle
!= NULL
);
629 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi
.FvInfo
));
631 AddUnknownFormatFvInfo (PrivateData
, &FvInfo2Ppi
);
638 Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.
640 @param GuidedSectionGuid The Guided Section GUID.
641 @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi
642 for the Guided Section.
644 @return TRUE The GuidedSectionGuid could be identified, and the pointer to
645 the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.
646 @return FALSE The GuidedSectionGuid could not be identified, or
647 the Guided Section Extraction Ppi has not been installed yet.
651 VerifyGuidedSectionGuid (
652 IN EFI_GUID
*GuidedSectionGuid
,
653 OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
**GuidedSectionExtraction
656 EFI_PEI_HOB_POINTERS Hob
;
657 EFI_GUID
*GuidRecorded
;
662 // Check if there is the Guided Section GUID HOB recorded the GUID itself.
664 Hob
.Raw
= GetFirstGuidHob (GuidedSectionGuid
);
665 if (Hob
.Raw
!= NULL
) {
666 GuidRecorded
= (EFI_GUID
*) GET_GUID_HOB_DATA (Hob
);
667 if (CompareGuid (GuidRecorded
, GuidedSectionGuid
)) {
669 // Found the recorded GuidedSectionGuid.
671 Status
= PeiServicesLocatePpi (GuidedSectionGuid
, 0, NULL
, (VOID
**) &Interface
);
672 if (!EFI_ERROR (Status
) && Interface
!= NULL
) {
674 // Found the supported Guided Section Extraction Ppi for the Guided Section.
676 *GuidedSectionExtraction
= (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*) Interface
;
687 Go through the file to search SectionType section.
688 Search within encapsulation sections (compression and GUIDed) recursively,
689 until the match section is found.
691 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
692 @param SectionType Filter to find only section of this type.
693 @param SectionInstance Pointer to the filter to find the specific instance of section.
694 @param Section From where to search.
695 @param SectionSize The file size to search.
696 @param OutputBuffer A pointer to the discovered section, if successful.
697 NULL if section not found
698 @param AuthenticationStatus Updated upon return to point to the authentication status for this section.
699 @param IsFfs3Fv Indicates the FV format.
701 @return EFI_NOT_FOUND The match section is not found.
702 @return EFI_SUCCESS The match section is found.
707 IN CONST EFI_PEI_SERVICES
**PeiServices
,
708 IN EFI_SECTION_TYPE SectionType
,
709 IN OUT UINTN
*SectionInstance
,
710 IN EFI_COMMON_SECTION_HEADER
*Section
,
711 IN UINTN SectionSize
,
712 OUT VOID
**OutputBuffer
,
713 OUT UINT32
*AuthenticationStatus
,
718 UINT32 SectionLength
;
720 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
721 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
725 UINT32 Authentication
;
726 PEI_CORE_INSTANCE
*PrivateData
;
727 EFI_GUID
*SectionDefinitionGuid
;
728 BOOLEAN SectionCached
;
729 VOID
*TempOutputBuffer
;
730 UINT32 TempAuthenticationStatus
;
732 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
733 *OutputBuffer
= NULL
;
736 Status
= EFI_NOT_FOUND
;
739 while (ParsedLength
< SectionSize
) {
741 if (IS_SECTION2 (Section
)) {
742 ASSERT (SECTION2_SIZE (Section
) > 0x00FFFFFF);
744 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
745 SectionLength
= SECTION2_SIZE (Section
);
747 // SectionLength is adjusted it is 4 byte aligned.
748 // Go to the next section
750 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
751 ASSERT (SectionLength
!= 0);
752 ParsedLength
+= SectionLength
;
753 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ SectionLength
);
758 if (Section
->Type
== SectionType
) {
760 // The type matches, so check the instance count to see if it's the one we want.
762 (*SectionInstance
)--;
763 if (*SectionInstance
== 0) {
767 if (IS_SECTION2 (Section
)) {
768 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
770 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
774 if (IS_SECTION2 (Section
)) {
775 SectionLength
= SECTION2_SIZE (Section
);
777 SectionLength
= SECTION_SIZE (Section
);
780 // SectionLength is adjusted it is 4 byte aligned.
781 // Go to the next section
783 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
784 ASSERT (SectionLength
!= 0);
785 ParsedLength
+= SectionLength
;
786 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
789 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
791 // Check the encapsulated section is extracted into the cache data.
793 SectionCached
= FALSE
;
794 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
795 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
796 SectionCached
= TRUE
;
797 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
798 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
799 Authentication
= PrivateData
->CacheSection
.AuthenticationStatus
[Index
];
801 // Search section directly from the cache data.
803 TempAuthenticationStatus
= 0;
804 Status
= ProcessSection (
811 &TempAuthenticationStatus
,
814 if (!EFI_ERROR (Status
)) {
815 *OutputBuffer
= TempOutputBuffer
;
816 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
823 // If SectionCached is TRUE, the section data has been cached and scanned.
825 if (!SectionCached
) {
826 Status
= EFI_NOT_FOUND
;
828 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
829 if (IS_SECTION2 (Section
)) {
830 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION2
*)Section
)->SectionDefinitionGuid
;
832 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
;
834 if (VerifyGuidedSectionGuid (SectionDefinitionGuid
, &GuidSectionPpi
)) {
835 Status
= GuidSectionPpi
->ExtractSection (
843 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
844 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
845 if (!EFI_ERROR (Status
)) {
846 Status
= DecompressPpi
->Decompress (
848 (CONST EFI_COMPRESSION_SECTION
*) Section
,
855 if (!EFI_ERROR (Status
)) {
857 // Update cache section data.
859 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
860 PrivateData
->CacheSection
.AllSectionCount
++;
862 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
863 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
864 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
865 PrivateData
->CacheSection
.AuthenticationStatus
[PrivateData
->CacheSection
.SectionIndex
] = Authentication
;
866 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
868 TempAuthenticationStatus
= 0;
869 Status
= ProcessSection (
876 &TempAuthenticationStatus
,
879 if (!EFI_ERROR (Status
)) {
880 *OutputBuffer
= TempOutputBuffer
;
881 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
888 if (IS_SECTION2 (Section
)) {
889 SectionLength
= SECTION2_SIZE (Section
);
891 SectionLength
= SECTION_SIZE (Section
);
894 // SectionLength is adjusted it is 4 byte aligned.
895 // Go to the next section
897 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
898 ASSERT (SectionLength
!= 0);
899 ParsedLength
+= SectionLength
;
900 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
903 return EFI_NOT_FOUND
;
908 Searches for the next matching section within the specified file.
910 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
911 @param SectionType Filter to find only sections of this type.
912 @param FileHandle Pointer to the current file to search.
913 @param SectionData A pointer to the discovered section, if successful.
914 NULL if section not found
916 @retval EFI_NOT_FOUND The section was not found.
917 @retval EFI_SUCCESS The section was found.
922 PeiFfsFindSectionData (
923 IN CONST EFI_PEI_SERVICES
**PeiServices
,
924 IN EFI_SECTION_TYPE SectionType
,
925 IN EFI_PEI_FILE_HANDLE FileHandle
,
926 OUT VOID
**SectionData
929 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
931 CoreFvHandle
= FileHandleToVolume (FileHandle
);
932 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
933 return EFI_NOT_FOUND
;
936 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
940 Searches for the next matching section within the specified file.
942 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
943 @param SectionType The value of the section type to find.
944 @param SectionInstance Section instance to find.
945 @param FileHandle Handle of the firmware file to search.
946 @param SectionData A pointer to the discovered section, if successful.
947 @param AuthenticationStatus A pointer to the authentication status for this section.
949 @retval EFI_SUCCESS The section was found.
950 @retval EFI_NOT_FOUND The section was not found.
955 PeiFfsFindSectionData3 (
956 IN CONST EFI_PEI_SERVICES
**PeiServices
,
957 IN EFI_SECTION_TYPE SectionType
,
958 IN UINTN SectionInstance
,
959 IN EFI_PEI_FILE_HANDLE FileHandle
,
960 OUT VOID
**SectionData
,
961 OUT UINT32
*AuthenticationStatus
964 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
966 CoreFvHandle
= FileHandleToVolume (FileHandle
);
967 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
968 return EFI_NOT_FOUND
;
971 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
972 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
973 return CoreFvHandle
->FvPpi
->FindSectionByType2 (CoreFvHandle
->FvPpi
, SectionType
, SectionInstance
, FileHandle
, SectionData
, AuthenticationStatus
);
976 // The old FvPpi doesn't support to find section by section instance
977 // and return authentication status, so return EFI_UNSUPPORTED.
979 return EFI_UNSUPPORTED
;
983 Searches for the next matching file in the firmware volume.
985 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
986 @param SearchType Filter to find only files of this type.
987 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
988 @param FvHandle Handle of firmware volume in which to search.
989 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
990 at the beginning of the firmware volume. On exit, points the file handle of the next file
991 in the volume or NULL if there are no more files.
993 @retval EFI_NOT_FOUND The file was not found.
994 @retval EFI_NOT_FOUND The header checksum was not zero.
995 @retval EFI_SUCCESS The file was found.
1000 PeiFfsFindNextFile (
1001 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1002 IN UINT8 SearchType
,
1003 IN EFI_PEI_FV_HANDLE FvHandle
,
1004 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1007 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1009 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
1012 // To make backward compatiblity, if can not find corresponding the handle of FV
1013 // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed
1014 // to the address of first byte of FV.
1016 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1017 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1020 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
1021 return EFI_NOT_FOUND
;
1024 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
1029 Search the firmware volumes by index
1031 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1032 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
1034 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
1036 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
1037 @retval EFI_NOT_FOUND The volume was not found.
1038 @retval EFI_SUCCESS The volume was found.
1043 PeiFfsFindNextVolume (
1044 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1046 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
1049 PEI_CORE_INSTANCE
*Private
;
1050 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1052 if (VolumeHandle
== NULL
) {
1053 return EFI_INVALID_PARAMETER
;
1056 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1058 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
1059 if (CoreFvHandle
== NULL
) {
1060 *VolumeHandle
= NULL
;
1061 return EFI_NOT_FOUND
;
1064 *VolumeHandle
= CoreFvHandle
->FvHandle
;
1071 Find a file within a volume by its name.
1073 @param FileName A pointer to the name of the file to find within the firmware volume.
1074 @param VolumeHandle The firmware volume to search
1075 @param FileHandle Upon exit, points to the found file's handle
1076 or NULL if it could not be found.
1078 @retval EFI_SUCCESS File was found.
1079 @retval EFI_NOT_FOUND File was not found.
1080 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
1085 PeiFfsFindFileByName (
1086 IN CONST EFI_GUID
*FileName
,
1087 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1088 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1091 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1093 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1094 return EFI_INVALID_PARAMETER
;
1097 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
1098 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1099 return EFI_NOT_FOUND
;
1102 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
1106 Returns information about a specific file.
1108 @param FileHandle Handle of the file.
1109 @param FileInfo Upon exit, points to the file's information.
1111 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1112 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1113 @retval EFI_SUCCESS File information returned.
1119 IN EFI_PEI_FILE_HANDLE FileHandle
,
1120 OUT EFI_FV_FILE_INFO
*FileInfo
1123 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1125 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1126 return EFI_INVALID_PARAMETER
;
1130 // Retrieve the FirmwareVolume which the file resides in.
1132 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1133 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1134 return EFI_INVALID_PARAMETER
;
1137 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1141 Returns information about a specific file.
1143 @param FileHandle Handle of the file.
1144 @param FileInfo Upon exit, points to the file's information.
1146 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1147 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1148 @retval EFI_SUCCESS File information returned.
1153 PeiFfsGetFileInfo2 (
1154 IN EFI_PEI_FILE_HANDLE FileHandle
,
1155 OUT EFI_FV_FILE_INFO2
*FileInfo
1158 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1160 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1161 return EFI_INVALID_PARAMETER
;
1165 // Retrieve the FirmwareVolume which the file resides in.
1167 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1168 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1169 return EFI_INVALID_PARAMETER
;
1172 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1173 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1174 return CoreFvHandle
->FvPpi
->GetFileInfo2 (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1177 // The old FvPpi doesn't support to return file info with authentication status,
1178 // so return EFI_UNSUPPORTED.
1180 return EFI_UNSUPPORTED
;
1184 Returns information about the specified volume.
1186 This function returns information about a specific firmware
1187 volume, including its name, type, attributes, starting address
1190 @param VolumeHandle Handle of the volume.
1191 @param VolumeInfo Upon exit, points to the volume's information.
1193 @retval EFI_SUCCESS Volume information returned.
1194 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
1195 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
1196 @retval EFI_SUCCESS Information successfully returned.
1197 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
1202 PeiFfsGetVolumeInfo (
1203 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1204 OUT EFI_FV_INFO
*VolumeInfo
1207 PEI_CORE_FV_HANDLE
*CoreHandle
;
1209 if ((VolumeInfo
== NULL
) || (VolumeHandle
== NULL
)) {
1210 return EFI_INVALID_PARAMETER
;
1213 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
1215 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
1216 return EFI_INVALID_PARAMETER
;
1219 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
1223 Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.
1225 @param PrivateData PeiCore's private data structure
1226 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
1227 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
1229 @retval EFI_NOT_FOUND FV image can't be found.
1230 @retval EFI_SUCCESS Successfully to process it.
1231 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
1232 @retval EFI_SECURITY_VIOLATION Image is illegal
1233 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
1238 IN PEI_CORE_INSTANCE
*PrivateData
,
1239 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
1240 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
1244 EFI_FV_INFO ParentFvImageInfo
;
1247 EFI_PEI_HOB_POINTERS HobPtr
;
1248 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
1249 EFI_PEI_FV_HANDLE ParentFvHandle
;
1250 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
1251 EFI_FV_FILE_INFO FileInfo
;
1253 UINT32 AuthenticationStatus
;
1256 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1259 HobPtr
.Raw
= GetHobList ();
1260 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
1261 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
1263 // this FILE has been dispatched, it will not be dispatched again.
1265 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
1268 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
1271 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
1272 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
1275 // Find FvImage in FvFile
1277 AuthenticationStatus
= 0;
1278 if ((ParentFvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1279 (ParentFvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1280 Status
= ParentFvPpi
->FindSectionByType2 (
1282 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1286 &AuthenticationStatus
1289 Status
= ParentFvPpi
->FindSectionByType (
1291 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1296 if (EFI_ERROR (Status
)) {
1300 Status
= VerifyPeim (PrivateData
, ParentFvHandle
, ParentFvFileHandle
, AuthenticationStatus
);
1301 if (Status
== EFI_SECURITY_VIOLATION
) {
1306 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
1307 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
1308 // its initial linked location and maintain its alignment.
1310 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
1312 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
1314 FvAlignment
= 1 << ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ALIGNMENT
) >> 16);
1315 if (FvAlignment
< 8) {
1322 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
1323 FvLength
= ReadUnaligned64 (&FvHeader
->FvLength
);
1324 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvLength
), FvAlignment
);
1325 if (NewFvBuffer
== NULL
) {
1326 return EFI_OUT_OF_RESOURCES
;
1328 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvLength
);
1329 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
1333 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
1334 ASSERT_EFI_ERROR (Status
);
1336 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
1337 ASSERT_EFI_ERROR (Status
);
1340 // Install FvInfo2 Ppi and Build FvHob
1342 PeiServicesInstallFvInfo2Ppi (
1343 &FvHeader
->FileSystemGuid
,
1345 (UINT32
) FvHeader
->FvLength
,
1346 &ParentFvImageInfo
.FvName
,
1348 AuthenticationStatus
1352 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
1355 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1360 // Makes the encapsulated volume show up in DXE phase to skip processing of
1361 // encapsulated file again.
1364 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1366 &ParentFvImageInfo
.FvName
,
1374 Process a firmware volume and create a volume handle.
1376 Create a volume handle from the information in the buffer. For
1377 memory-mapped firmware volumes, Buffer and BufferSize refer to
1378 the start of the firmware volume and the firmware volume size.
1379 For non memory-mapped firmware volumes, this points to a
1380 buffer which contains the necessary information for creating
1381 the firmware volume handle. Normally, these values are derived
1382 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
1385 @param This Points to this instance of the
1386 EFI_PEI_FIRMWARE_VOLUME_PPI.
1387 @param Buffer Points to the start of the buffer.
1388 @param BufferSize Size of the buffer.
1389 @param FvHandle Points to the returned firmware volume
1390 handle. The firmware volume handle must
1391 be unique within the system.
1393 @retval EFI_SUCCESS Firmware volume handle created.
1394 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
1399 PeiFfsFvPpiProcessVolume (
1400 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1402 IN UINTN BufferSize
,
1403 OUT EFI_PEI_FV_HANDLE
*FvHandle
1408 ASSERT (FvHandle
!= NULL
);
1410 if (Buffer
== NULL
) {
1411 return EFI_VOLUME_CORRUPTED
;
1415 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped
1416 // FV image and the handle is pointed to Fv image's buffer.
1418 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
1421 // Do verify for given FV buffer.
1423 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1424 if (EFI_ERROR(Status
)) {
1425 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1426 return EFI_VOLUME_CORRUPTED
;
1433 Finds the next file of the specified type.
1435 This service enables PEI modules to discover additional firmware files.
1436 The FileHandle must be unique within the system.
1438 @param This Points to this instance of the
1439 EFI_PEI_FIRMWARE_VOLUME_PPI.
1440 @param SearchType A filter to find only files of this type. Type
1441 EFI_FV_FILETYPE_ALL causes no filtering to be
1443 @param FvHandle Handle of firmware volume in which to
1445 @param FileHandle Points to the current handle from which to
1446 begin searching or NULL to start at the
1447 beginning of the firmware volume. Updated
1448 upon return to reflect the file found.
1450 @retval EFI_SUCCESS The file was found.
1451 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1456 PeiFfsFvPpiFindFileByType (
1457 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1458 IN EFI_FV_FILETYPE SearchType
,
1459 IN EFI_PEI_FV_HANDLE FvHandle
,
1460 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1463 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1467 Find a file within a volume by its name.
1469 This service searches for files with a specific name, within
1470 either the specified firmware volume or all firmware volumes.
1472 @param This Points to this instance of the
1473 EFI_PEI_FIRMWARE_VOLUME_PPI.
1474 @param FileName A pointer to the name of the file to find
1475 within the firmware volume.
1476 @param FvHandle Upon entry, the pointer to the firmware
1477 volume to search or NULL if all firmware
1478 volumes should be searched. Upon exit, the
1479 actual firmware volume in which the file was
1481 @param FileHandle Upon exit, points to the found file's
1482 handle or NULL if it could not be found.
1484 @retval EFI_SUCCESS File was found.
1485 @retval EFI_NOT_FOUND File was not found.
1486 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1493 PeiFfsFvPpiFindFileByName (
1494 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1495 IN CONST EFI_GUID
*FileName
,
1496 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1497 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1501 PEI_CORE_INSTANCE
*PrivateData
;
1504 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1505 return EFI_INVALID_PARAMETER
;
1508 if (*FvHandle
!= NULL
) {
1509 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1510 if (Status
== EFI_NOT_FOUND
) {
1515 // If *FvHandle = NULL, so search all FV for given filename
1517 Status
= EFI_NOT_FOUND
;
1519 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1520 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1522 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1524 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1525 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1526 if (!EFI_ERROR (Status
)) {
1527 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1538 Returns information about a specific file.
1540 This function returns information about a specific
1541 file, including its file name, type, attributes, starting
1544 @param This Points to this instance of the
1545 EFI_PEI_FIRMWARE_VOLUME_PPI.
1546 @param FileHandle Handle of the file.
1547 @param FileInfo Upon exit, points to the file's
1550 @retval EFI_SUCCESS File information returned.
1551 @retval EFI_INVALID_PARAMETER If FileHandle does not
1552 represent a valid file.
1553 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1558 PeiFfsFvPpiGetFileInfo (
1559 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1560 IN EFI_PEI_FILE_HANDLE FileHandle
,
1561 OUT EFI_FV_FILE_INFO
*FileInfo
1565 UINT8 ErasePolarity
;
1566 EFI_FFS_FILE_HEADER
*FileHeader
;
1567 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1568 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1570 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1571 return EFI_INVALID_PARAMETER
;
1575 // Retrieve the FirmwareVolume which the file resides in.
1577 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1578 if (CoreFvHandle
== NULL
) {
1579 return EFI_INVALID_PARAMETER
;
1582 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1584 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
1591 // Get FileState which is the highest bit of the State
1593 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1595 switch (FileState
) {
1596 case EFI_FILE_DATA_VALID
:
1597 case EFI_FILE_MARKED_FOR_UPDATE
:
1600 return EFI_INVALID_PARAMETER
;
1603 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1604 if (IS_FFS_FILE2 (FileHeader
)) {
1605 ASSERT (FFS_FILE2_SIZE (FileHeader
) > 0x00FFFFFF);
1606 if (!FwVolInstance
->IsFfs3Fv
) {
1607 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader
->Name
));
1608 return EFI_INVALID_PARAMETER
;
1610 FileInfo
->BufferSize
= FFS_FILE2_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1611 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
);
1613 FileInfo
->BufferSize
= FFS_FILE_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1614 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER
);
1616 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1617 FileInfo
->FileType
= FileHeader
->Type
;
1618 FileInfo
->FileAttributes
= FfsAttributes2FvFileAttributes (FileHeader
->Attributes
);
1619 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_MEMORY_MAPPED
) == EFI_FVB2_MEMORY_MAPPED
) {
1620 FileInfo
->FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
1626 Returns information about a specific file.
1628 This function returns information about a specific
1629 file, including its file name, type, attributes, starting
1630 address, size and authentication status.
1632 @param This Points to this instance of the
1633 EFI_PEI_FIRMWARE_VOLUME_PPI.
1634 @param FileHandle Handle of the file.
1635 @param FileInfo Upon exit, points to the file's
1638 @retval EFI_SUCCESS File information returned.
1639 @retval EFI_INVALID_PARAMETER If FileHandle does not
1640 represent a valid file.
1641 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1646 PeiFfsFvPpiGetFileInfo2 (
1647 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1648 IN EFI_PEI_FILE_HANDLE FileHandle
,
1649 OUT EFI_FV_FILE_INFO2
*FileInfo
1653 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1655 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1656 return EFI_INVALID_PARAMETER
;
1660 // Retrieve the FirmwareVolume which the file resides in.
1662 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1663 if (CoreFvHandle
== NULL
) {
1664 return EFI_INVALID_PARAMETER
;
1667 Status
= PeiFfsFvPpiGetFileInfo (This
, FileHandle
, (EFI_FV_FILE_INFO
*) FileInfo
);
1668 if (!EFI_ERROR (Status
)) {
1669 FileInfo
->AuthenticationStatus
= CoreFvHandle
->AuthenticationStatus
;
1676 This function returns information about the firmware volume.
1678 @param This Points to this instance of the
1679 EFI_PEI_FIRMWARE_VOLUME_PPI.
1680 @param FvHandle Handle to the firmware handle.
1681 @param VolumeInfo Points to the returned firmware volume
1684 @retval EFI_SUCCESS Information returned successfully.
1685 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1686 firmware volume or VolumeInfo is NULL.
1691 PeiFfsFvPpiGetVolumeInfo (
1692 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1693 IN EFI_PEI_FV_HANDLE FvHandle
,
1694 OUT EFI_FV_INFO
*VolumeInfo
1697 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1698 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1700 if ((VolumeInfo
== NULL
) || (FvHandle
== NULL
)) {
1701 return EFI_INVALID_PARAMETER
;
1705 // VolumeHandle may not align at 8 byte,
1706 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1707 // So, Copy FvHeader into the local FvHeader structure.
1709 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1712 // Check Fv Image Signature
1714 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1715 return EFI_INVALID_PARAMETER
;
1718 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1719 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1720 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1721 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1722 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1724 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1725 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1726 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1733 Find the next matching section in the firmware file.
1735 This service enables PEI modules to discover sections
1736 of a given type within a valid file.
1738 @param This Points to this instance of the
1739 EFI_PEI_FIRMWARE_VOLUME_PPI.
1740 @param SearchType A filter to find only sections of this
1742 @param FileHandle Handle of firmware file in which to
1744 @param SectionData Updated upon return to point to the
1747 @retval EFI_SUCCESS Section was found.
1748 @retval EFI_NOT_FOUND Section of the specified type was not
1749 found. SectionData contains NULL.
1753 PeiFfsFvPpiFindSectionByType (
1754 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1755 IN EFI_SECTION_TYPE SearchType
,
1756 IN EFI_PEI_FILE_HANDLE FileHandle
,
1757 OUT VOID
**SectionData
1760 UINT32 AuthenticationStatus
;
1761 return PeiFfsFvPpiFindSectionByType2 (This
, SearchType
, 0, FileHandle
, SectionData
, &AuthenticationStatus
);
1765 Find the next matching section in the firmware file.
1767 This service enables PEI modules to discover sections
1768 of a given instance and type within a valid file.
1770 @param This Points to this instance of the
1771 EFI_PEI_FIRMWARE_VOLUME_PPI.
1772 @param SearchType A filter to find only sections of this
1774 @param SearchInstance A filter to find the specific instance
1776 @param FileHandle Handle of firmware file in which to
1778 @param SectionData Updated upon return to point to the
1780 @param AuthenticationStatus Updated upon return to point to the
1781 authentication status for this section.
1783 @retval EFI_SUCCESS Section was found.
1784 @retval EFI_NOT_FOUND Section of the specified type was not
1785 found. SectionData contains NULL.
1789 PeiFfsFvPpiFindSectionByType2 (
1790 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1791 IN EFI_SECTION_TYPE SearchType
,
1792 IN UINTN SearchInstance
,
1793 IN EFI_PEI_FILE_HANDLE FileHandle
,
1794 OUT VOID
**SectionData
,
1795 OUT UINT32
*AuthenticationStatus
1799 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
1801 EFI_COMMON_SECTION_HEADER
*Section
;
1802 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1803 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1805 UINT32 ExtractedAuthenticationStatus
;
1807 if (SectionData
== NULL
) {
1808 return EFI_NOT_FOUND
;
1811 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1814 // Retrieve the FirmwareVolume which the file resides in.
1816 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1817 if (CoreFvHandle
== NULL
) {
1818 return EFI_NOT_FOUND
;
1821 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
1823 if (IS_FFS_FILE2 (FfsFileHeader
)) {
1824 ASSERT (FFS_FILE2_SIZE (FfsFileHeader
) > 0x00FFFFFF);
1825 if (!FwVolInstance
->IsFfs3Fv
) {
1826 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
1827 return EFI_NOT_FOUND
;
1829 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
1830 FileSize
= FFS_FILE2_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1832 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
1833 FileSize
= FFS_FILE_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1836 Instance
= SearchInstance
+ 1;
1837 ExtractedAuthenticationStatus
= 0;
1838 Status
= ProcessSection (
1839 GetPeiServicesTablePointer (),
1845 &ExtractedAuthenticationStatus
,
1846 FwVolInstance
->IsFfs3Fv
1848 if (!EFI_ERROR (Status
)) {
1850 // Inherit the authentication status.
1852 *AuthenticationStatus
= ExtractedAuthenticationStatus
| CoreFvHandle
->AuthenticationStatus
;
1858 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
1860 @param FvHandle The handle of a FV.
1862 @retval NULL if can not find.
1863 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
1865 PEI_CORE_FV_HANDLE
*
1866 FvHandleToCoreHandle (
1867 IN EFI_PEI_FV_HANDLE FvHandle
1871 PEI_CORE_INSTANCE
*PrivateData
;
1873 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1874 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1875 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
1876 return &PrivateData
->Fv
[Index
];
1884 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
1886 This routine also will install FvInfo ppi for FV hob in PI ways.
1888 @param Private Pointer of PEI_CORE_INSTANCE
1889 @param Instance The index of FV want to be searched.
1891 @return Instance of PEI_CORE_FV_HANDLE.
1893 PEI_CORE_FV_HANDLE
*
1894 FindNextCoreFvHandle (
1895 IN PEI_CORE_INSTANCE
*Private
,
1901 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
1904 // Handle Framework FvHob and Install FvInfo Ppi for it.
1906 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1908 // Loop to search the wanted FirmwareVolume which supports FFS
1910 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
1911 while (FvHob
!= NULL
) {
1913 // Search whether FvHob has been installed into PeiCore's FV database.
1914 // If found, no need install new FvInfoPpi for it.
1916 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
1917 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
1924 // Search whether FvHob has been cached into PeiCore's Unknown FV database.
1925 // If found, no need install new FvInfoPpi for it.
1928 for (Index
= 0; Index
< Private
->UnknownFvInfoCount
; Index
++) {
1929 if ((UINTN
)FvHob
->BaseAddress
== (UINTN
)Private
->UnknownFvInfo
[Index
].FvInfo
) {
1937 // If the Fv in FvHob has not been installed into PeiCore's FV database and has
1938 // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi
1939 // for it then PeiCore will dispatch it in callback of FvInfoPpi.
1942 PeiServicesInstallFvInfoPpi (
1943 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
1944 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
1945 (UINT32
)FvHob
->Length
,
1951 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
1955 ASSERT (Private
->FvCount
<= FixedPcdGet32 (PcdPeiCoreMaxFvSupported
));
1956 if (Instance
>= Private
->FvCount
) {
1960 return &Private
->Fv
[Instance
];
1964 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
1965 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
1966 PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant
1969 @param PrivateData Pointer to PEI_CORE_INSTANCE.
1973 IN PEI_CORE_INSTANCE
*PrivateData
1977 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
1982 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
1985 Status
= PeiServicesLocatePpi (
1986 &gEfiFirmwareFileSystem2Guid
,
1991 ASSERT_EFI_ERROR (Status
);
1994 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
1995 // which is shadowed from flash to permanent memory within PeiCore image.
1997 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
1998 ASSERT_EFI_ERROR (Status
);
2001 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2003 for (Index
= 0; Index
< FixedPcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2004 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2005 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FwVol
.Fv
;
2010 // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which
2013 Status
= PeiServicesLocatePpi (
2014 &gEfiFirmwareFileSystem3Guid
,
2019 ASSERT_EFI_ERROR (Status
);
2022 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3
2023 // which is shadowed from flash to permanent memory within PeiCore image.
2025 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs3FvPpiList
);
2026 ASSERT_EFI_ERROR (Status
);
2029 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2031 for (Index
= 0; Index
< FixedPcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2032 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2033 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs3FwVol
.Fv
;
2039 Report the information for a new discoveried FV in unknown third-party format.
2041 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but
2042 the FV in this format has been discoveried, then this FV's information will be cached into
2043 PEI_CORE_INSTANCE's UnknownFvInfo array.
2044 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI
2045 is installed later by platform's PEIM, the original unknown third-party FV will be processed by
2046 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2048 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2049 @param FvInfo2Ppi Point to FvInfo2 PPI.
2051 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
2052 @retval EFI_SUCCESS Success to add the information for unknown FV.
2055 AddUnknownFormatFvInfo (
2056 IN PEI_CORE_INSTANCE
*PrivateData
,
2057 IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
*FvInfo2Ppi
2060 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
2062 if (PrivateData
->UnknownFvInfoCount
+ 1 >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2063 return EFI_OUT_OF_RESOURCES
;
2066 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
2067 PrivateData
->UnknownFvInfoCount
++;
2069 CopyGuid (&NewUnknownFv
->FvFormat
, &FvInfo2Ppi
->FvFormat
);
2070 NewUnknownFv
->FvInfo
= FvInfo2Ppi
->FvInfo
;
2071 NewUnknownFv
->FvInfoSize
= FvInfo2Ppi
->FvInfoSize
;
2072 NewUnknownFv
->AuthenticationStatus
= FvInfo2Ppi
->AuthenticationStatus
;
2073 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
2074 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
2075 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
2077 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
2082 Find the FV information according to third-party FV format guid.
2084 This routine also will remove the FV information found by given FV format guid from
2085 PrivateData->UnknownFvInfo[].
2087 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2088 @param Format Point to given FV format guid
2089 @param FvInfo On return, the pointer of FV information buffer
2090 @param FvInfoSize On return, the size of FV information buffer.
2091 @param AuthenticationStatus On return, the authentication status of FV information buffer.
2093 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
2094 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2097 FindUnknownFormatFvInfo (
2098 IN PEI_CORE_INSTANCE
*PrivateData
,
2099 IN EFI_GUID
*Format
,
2101 OUT UINT32
*FvInfoSize
,
2102 OUT UINT32
*AuthenticationStatus
2109 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
2110 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
2115 if (Index
== PrivateData
->UnknownFvInfoCount
) {
2116 return EFI_NOT_FOUND
;
2119 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
2120 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
2121 *AuthenticationStatus
= PrivateData
->UnknownFvInfo
[Index
].AuthenticationStatus
;
2124 // Remove an entry from UnknownFvInfo array.
2127 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
2128 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
2130 PrivateData
->UnknownFvInfoCount
--;
2135 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
2137 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
2138 routine is called to process all discoveried FVs in this format.
2140 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
2141 @param NotifyDescriptor Address of the notification descriptor data structure.
2142 @param Ppi Address of the PPI that was installed.
2144 @retval EFI_SUCCESS The notification callback is processed correctly.
2148 ThirdPartyFvPpiNotifyCallback (
2149 IN EFI_PEI_SERVICES
**PeiServices
,
2150 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
2154 PEI_CORE_INSTANCE
*PrivateData
;
2155 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
2158 UINT32 AuthenticationStatus
;
2160 EFI_PEI_FV_HANDLE FvHandle
;
2161 BOOLEAN IsProcessed
;
2163 EFI_PEI_FILE_HANDLE FileHandle
;
2166 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
2167 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
2170 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
, &AuthenticationStatus
);
2171 if (EFI_ERROR (Status
)) {
2176 // Process new found FV and get FV handle.
2178 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
2179 if (EFI_ERROR (Status
)) {
2180 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
2185 // Check whether the FV has already been processed.
2187 IsProcessed
= FALSE
;
2188 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
2189 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
2190 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo
));
2200 if (PrivateData
->FvCount
>= FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2201 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)));
2202 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
2207 // Update internal PEI_CORE_FV array.
2209 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
2210 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
2211 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
2212 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= AuthenticationStatus
;
2215 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
2216 (UINT32
) PrivateData
->FvCount
,
2221 PrivateData
->FvCount
++;
2224 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
2228 Status
= FvPpi
->FindFileByType (
2230 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
2234 if (!EFI_ERROR (Status
)) {
2235 Status
= FvPpi
->FindSectionByType (
2237 EFI_SECTION_PEI_DEPEX
,
2241 if (!EFI_ERROR (Status
)) {
2242 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
2244 // Dependency is not satisfied.
2250 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
2251 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
2253 } while (FileHandle
!= NULL
);