2 Pei Core Firmware File System service routines.
4 Copyright (c) 2015 HP Development Company, L.P.
5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList
[] = {
20 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
21 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
22 FirmwareVolmeInfoPpiNotifyCallback
25 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
26 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
27 FirmwareVolmeInfoPpiNotifyCallback
31 PEI_FW_VOL_INSTANCE mPeiFfs2FwVol
= {
35 PeiFfsFvPpiProcessVolume
,
36 PeiFfsFvPpiFindFileByType
,
37 PeiFfsFvPpiFindFileByName
,
38 PeiFfsFvPpiGetFileInfo
,
39 PeiFfsFvPpiGetVolumeInfo
,
40 PeiFfsFvPpiFindSectionByType
,
41 PeiFfsFvPpiGetFileInfo2
,
42 PeiFfsFvPpiFindSectionByType2
,
43 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
44 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
48 PEI_FW_VOL_INSTANCE mPeiFfs3FwVol
= {
52 PeiFfsFvPpiProcessVolume
,
53 PeiFfsFvPpiFindFileByType
,
54 PeiFfsFvPpiFindFileByName
,
55 PeiFfsFvPpiGetFileInfo
,
56 PeiFfsFvPpiGetVolumeInfo
,
57 PeiFfsFvPpiFindSectionByType
,
58 PeiFfsFvPpiGetFileInfo2
,
59 PeiFfsFvPpiFindSectionByType2
,
60 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
61 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
65 EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList
= {
66 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
67 &gEfiFirmwareFileSystem2Guid
,
71 EFI_PEI_PPI_DESCRIPTOR mPeiFfs3FvPpiList
= {
72 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
73 &gEfiFirmwareFileSystem3Guid
,
78 Required Alignment Alignment Value in FFS Alignment Value in
79 (bytes) Attributes Field Firmware Volume Interfaces
89 UINT8 mFvAttributes
[] = {0, 4, 7, 9, 10, 12, 15, 16};
92 Convert the FFS File Attributes to FV File Attributes
94 @param FfsAttributes The attributes of UINT8 type.
96 @return The attributes of EFI_FV_FILE_ATTRIBUTES
99 EFI_FV_FILE_ATTRIBUTES
100 FfsAttributes2FvFileAttributes (
101 IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
105 EFI_FV_FILE_ATTRIBUTES FileAttribute
;
107 DataAlignment
= (UINT8
) ((FfsAttributes
& FFS_ATTRIB_DATA_ALIGNMENT
) >> 3);
108 ASSERT (DataAlignment
< 8);
110 FileAttribute
= (EFI_FV_FILE_ATTRIBUTES
) mFvAttributes
[DataAlignment
];
112 if ((FfsAttributes
& FFS_ATTRIB_FIXED
) == FFS_ATTRIB_FIXED
) {
113 FileAttribute
|= EFI_FV_FILE_ATTRIB_FIXED
;
116 return FileAttribute
;
120 Returns the file state set by the highest zero bit in the State field
122 @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
123 in the Attributes field.
124 @param FfsHeader Pointer to FFS File Header.
126 @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit
127 in the header State field.
131 IN UINT8 ErasePolarity
,
132 IN EFI_FFS_FILE_HEADER
*FfsHeader
135 EFI_FFS_FILE_STATE FileState
;
136 EFI_FFS_FILE_STATE HighestBit
;
138 FileState
= FfsHeader
->State
;
140 if (ErasePolarity
!= 0) {
141 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
145 // Get file state set by its highest none zero bit.
148 while (HighestBit
!= 0 && (HighestBit
& FileState
) == 0) {
156 Calculates the checksum of the header of a file.
158 @param FileHeader Pointer to FFS File Header.
160 @return Checksum of the header.
161 Zero means the header is good.
162 Non-zero means the header is bad.
165 CalculateHeaderChecksum (
166 IN EFI_FFS_FILE_HEADER
*FileHeader
169 EFI_FFS_FILE_HEADER2 TestFileHeader
;
171 if (IS_FFS_FILE2 (FileHeader
)) {
172 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
174 // Ingore State and File field in FFS header.
176 TestFileHeader
.State
= 0;
177 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
179 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
181 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
183 // Ingore State and File field in FFS header.
185 TestFileHeader
.State
= 0;
186 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
188 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
193 Find FV handler according to FileHandle in that FV.
195 @param FileHandle Handle of file image
197 @return Pointer to instance of PEI_CORE_FV_HANDLE.
201 IN EFI_PEI_FILE_HANDLE FileHandle
205 PEI_CORE_INSTANCE
*PrivateData
;
206 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
209 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
210 BestIndex
= PrivateData
->FvCount
;
213 // Find the best matched FV image that includes this FileHandle.
214 // FV may include the child FV, and they are in the same continuous space.
215 // If FileHandle is from the child FV, the updated logic can find its matched FV.
217 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
218 FwVolHeader
= PrivateData
->Fv
[Index
].FvHeader
;
219 if (((UINT64
) (UINTN
) FileHandle
> (UINT64
) (UINTN
) FwVolHeader
) && \
220 ((UINT64
) (UINTN
) FileHandle
<= ((UINT64
) (UINTN
) FwVolHeader
+ FwVolHeader
->FvLength
- 1))) {
221 if (BestIndex
== PrivateData
->FvCount
) {
224 if ((UINT64
) (UINTN
) PrivateData
->Fv
[BestIndex
].FvHeader
< (UINT64
) (UINTN
) FwVolHeader
) {
231 if (BestIndex
< PrivateData
->FvCount
) {
232 return &PrivateData
->Fv
[BestIndex
];
239 Given the input file pointer, search for the first matching file in the
240 FFS volume as defined by SearchType. The search starts from FileHeader inside
241 the Firmware Volume defined by FwVolHeader.
242 If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.
243 If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
244 the first PEIM, or COMBINED PEIM or FV file type FFS file will return.
246 @param FvHandle Pointer to the FV header of the volume to search
247 @param FileName File name
248 @param SearchType Filter to find only files of this type.
249 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
250 @param FileHandle This parameter must point to a valid FFS volume.
251 @param AprioriFile Pointer to AprioriFile image in this FV if has
253 @return EFI_NOT_FOUND No files matching the search criteria were found
254 @retval EFI_SUCCESS Success to search given file
259 IN CONST EFI_PEI_FV_HANDLE FvHandle
,
260 IN CONST EFI_GUID
*FileName
, OPTIONAL
261 IN EFI_FV_FILETYPE SearchType
,
262 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
,
263 IN OUT EFI_PEI_FILE_HANDLE
*AprioriFile OPTIONAL
266 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
267 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExtHeader
;
268 EFI_FFS_FILE_HEADER
**FileHeader
;
269 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
271 UINT32 FileOccupiedSize
;
280 // Convert the handle of FV to FV header for memory-mapped firmware volume
282 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvHandle
;
283 FileHeader
= (EFI_FFS_FILE_HEADER
**)FileHandle
;
285 IsFfs3Fv
= CompareGuid (&FwVolHeader
->FileSystemGuid
, &gEfiFirmwareFileSystem3Guid
);
287 FvLength
= FwVolHeader
->FvLength
;
288 if ((FwVolHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
295 // If FileHeader is not specified (NULL) or FileName is not NULL,
296 // start with the first file in the firmware volume. Otherwise,
297 // start from the FileHeader.
299 if ((*FileHeader
== NULL
) || (FileName
!= NULL
)) {
300 if (FwVolHeader
->ExtHeaderOffset
!= 0) {
302 // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
304 FwVolExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*) ((UINT8
*) FwVolHeader
+ FwVolHeader
->ExtHeaderOffset
);
305 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FwVolExtHeader
+ FwVolExtHeader
->ExtHeaderSize
);
306 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ALIGN_POINTER (FfsFileHeader
, 8);
308 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*) FwVolHeader
+ FwVolHeader
->HeaderLength
);
311 if (IS_FFS_FILE2 (*FileHeader
)) {
313 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &(*FileHeader
)->Name
));
315 FileLength
= FFS_FILE2_SIZE (*FileHeader
);
316 ASSERT (FileLength
> 0x00FFFFFF);
318 FileLength
= FFS_FILE_SIZE (*FileHeader
);
321 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
323 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
324 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)*FileHeader
+ FileOccupiedSize
);
327 FileOffset
= (UINT32
) ((UINT8
*)FfsFileHeader
- (UINT8
*)FwVolHeader
);
328 ASSERT (FileOffset
<= 0xFFFFFFFF);
330 while (FileOffset
< (FvLength
- sizeof (EFI_FFS_FILE_HEADER
))) {
332 // Get FileState which is the highest bit of the State
334 FileState
= GetFileState (ErasePolarity
, FfsFileHeader
);
337 case EFI_FILE_HEADER_CONSTRUCTION
:
338 case EFI_FILE_HEADER_INVALID
:
339 if (IS_FFS_FILE2 (FfsFileHeader
)) {
341 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
343 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER2
);
344 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
346 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER
);
347 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
351 case EFI_FILE_DATA_VALID
:
352 case EFI_FILE_MARKED_FOR_UPDATE
:
353 if (CalculateHeaderChecksum (FfsFileHeader
) != 0) {
356 return EFI_NOT_FOUND
;
359 if (IS_FFS_FILE2 (FfsFileHeader
)) {
360 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
361 ASSERT (FileLength
> 0x00FFFFFF);
362 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
364 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
365 FileOffset
+= FileOccupiedSize
;
366 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ FileOccupiedSize
);
370 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
371 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
374 DataCheckSum
= FFS_FIXED_CHECKSUM
;
375 if ((FfsFileHeader
->Attributes
& FFS_ATTRIB_CHECKSUM
) == FFS_ATTRIB_CHECKSUM
) {
376 if (IS_FFS_FILE2 (FfsFileHeader
)) {
377 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
), FileLength
- sizeof(EFI_FFS_FILE_HEADER2
));
379 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
), FileLength
- sizeof(EFI_FFS_FILE_HEADER
));
382 if (FfsFileHeader
->IntegrityCheck
.Checksum
.File
!= DataCheckSum
) {
385 return EFI_NOT_FOUND
;
388 if (FileName
!= NULL
) {
389 if (CompareGuid (&FfsFileHeader
->Name
, (EFI_GUID
*)FileName
)) {
390 *FileHeader
= FfsFileHeader
;
393 } else if (SearchType
== PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
) {
394 if ((FfsFileHeader
->Type
== EFI_FV_FILETYPE_PEIM
) ||
395 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
) ||
396 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
398 *FileHeader
= FfsFileHeader
;
400 } else if (AprioriFile
!= NULL
) {
401 if (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
402 if (CompareGuid (&FfsFileHeader
->Name
, &gPeiAprioriFileNameGuid
)) {
403 *AprioriFile
= FfsFileHeader
;
407 } else if (((SearchType
== FfsFileHeader
->Type
) || (SearchType
== EFI_FV_FILETYPE_ALL
)) &&
408 (FfsFileHeader
->Type
!= EFI_FV_FILETYPE_FFS_PAD
)) {
409 *FileHeader
= FfsFileHeader
;
413 FileOffset
+= FileOccupiedSize
;
414 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
417 case EFI_FILE_DELETED
:
418 if (IS_FFS_FILE2 (FfsFileHeader
)) {
420 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
422 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
423 ASSERT (FileLength
> 0x00FFFFFF);
425 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
427 FileOccupiedSize
= GET_OCCUPIED_SIZE(FileLength
, 8);
428 FileOffset
+= FileOccupiedSize
;
429 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
434 return EFI_NOT_FOUND
;
439 return EFI_NOT_FOUND
;
443 Initialize PeiCore Fv List.
445 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
446 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
450 IN PEI_CORE_INSTANCE
*PrivateData
,
451 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
455 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
456 EFI_PEI_FV_HANDLE FvHandle
;
457 EFI_FIRMWARE_VOLUME_HEADER
*BfvHeader
;
460 // Install FV_PPI for FFS2 file system.
462 PeiServicesInstallPpi (&mPeiFfs2FvPpiList
);
465 // Install FV_PPI for FFS3 file system.
467 PeiServicesInstallPpi (&mPeiFfs3FvPpiList
);
469 BfvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
472 // The FV_PPI in BFV's format should be installed.
474 Status
= PeiServicesLocatePpi (
475 &BfvHeader
->FileSystemGuid
,
480 ASSERT_EFI_ERROR (Status
);
485 FvPpi
->ProcessVolume (
487 SecCoreData
->BootFirmwareVolumeBase
,
488 (UINTN
)BfvHeader
->FvLength
,
493 // Update internal PEI_CORE_FV array.
495 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= BfvHeader
;
496 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
497 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
498 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= 0;
501 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
502 (UINT32
) PrivateData
->FvCount
,
507 PrivateData
->FvCount
++;
510 // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose
511 // additional Fvs to PeiCore.
513 Status
= PeiServicesNotifyPpi (mNotifyOnFvInfoList
);
514 ASSERT_EFI_ERROR (Status
);
519 Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.
520 The FV Info will be registered into PeiCore private data structure.
521 And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.
523 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
524 @param NotifyDescriptor Address of the notification descriptor data structure.
525 @param Ppi Address of the PPI that was installed.
527 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
528 @return if not EFI_SUCESS, fail to verify FV.
533 FirmwareVolmeInfoPpiNotifyCallback (
534 IN EFI_PEI_SERVICES
**PeiServices
,
535 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
539 EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI FvInfo2Ppi
;
540 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
541 PEI_CORE_INSTANCE
*PrivateData
;
543 EFI_PEI_FV_HANDLE FvHandle
;
545 EFI_PEI_FILE_HANDLE FileHandle
;
549 Status
= EFI_SUCCESS
;
550 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
552 if (CompareGuid (NotifyDescriptor
->Guid
, &gEfiPeiFirmwareVolumeInfo2PpiGuid
)) {
556 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
));
562 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
563 FvInfo2Ppi
.AuthenticationStatus
= 0;
568 // Locate the corresponding FV_PPI according to founded FV's format guid
570 Status
= PeiServicesLocatePpi (
571 &FvInfo2Ppi
.FvFormat
,
576 if (!EFI_ERROR (Status
)) {
578 // Process new found FV and get FV handle.
580 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo2Ppi
.FvInfo
, FvInfo2Ppi
.FvInfoSize
, &FvHandle
);
581 if (EFI_ERROR (Status
)) {
582 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!\n"));
587 // Check whether the FV has already been processed.
589 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
590 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
591 if (IsFvInfo2
&& (FvInfo2Ppi
.AuthenticationStatus
!= PrivateData
->Fv
[FvIndex
].AuthenticationStatus
)) {
592 PrivateData
->Fv
[FvIndex
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
593 DEBUG ((EFI_D_INFO
, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex
, FvInfo2Ppi
.AuthenticationStatus
));
595 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo2Ppi
.FvInfo
));
600 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
601 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
602 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
607 // Update internal PEI_CORE_FV array.
609 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
;
610 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
611 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
612 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
615 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
616 (UINT32
) PrivateData
->FvCount
,
617 (VOID
*) FvInfo2Ppi
.FvInfo
,
618 FvInfo2Ppi
.FvInfoSize
,
621 PrivateData
->FvCount
++;
624 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
628 Status
= FvPpi
->FindFileByType (
630 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
634 if (!EFI_ERROR (Status
)) {
635 Status
= FvPpi
->FindSectionByType (
637 EFI_SECTION_PEI_DEPEX
,
641 if (!EFI_ERROR (Status
)) {
642 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
644 // Dependency is not satisfied.
650 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
651 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
653 } while (FileHandle
!= NULL
);
655 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi
.FvInfo
));
657 AddUnknownFormatFvInfo (PrivateData
, &FvInfo2Ppi
);
664 Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.
666 @param GuidedSectionGuid The Guided Section GUID.
667 @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi
668 for the Guided Section.
670 @return TRUE The GuidedSectionGuid could be identified, and the pointer to
671 the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.
672 @return FALSE The GuidedSectionGuid could not be identified, or
673 the Guided Section Extraction Ppi has not been installed yet.
677 VerifyGuidedSectionGuid (
678 IN EFI_GUID
*GuidedSectionGuid
,
679 OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
**GuidedSectionExtraction
682 EFI_PEI_HOB_POINTERS Hob
;
683 EFI_GUID
*GuidRecorded
;
688 // Check if there is the Guided Section GUID HOB recorded the GUID itself.
690 Hob
.Raw
= GetFirstGuidHob (GuidedSectionGuid
);
691 if (Hob
.Raw
!= NULL
) {
692 GuidRecorded
= (EFI_GUID
*) GET_GUID_HOB_DATA (Hob
);
693 if (CompareGuid (GuidRecorded
, GuidedSectionGuid
)) {
695 // Found the recorded GuidedSectionGuid.
697 Status
= PeiServicesLocatePpi (GuidedSectionGuid
, 0, NULL
, (VOID
**) &Interface
);
698 if (!EFI_ERROR (Status
) && Interface
!= NULL
) {
700 // Found the supported Guided Section Extraction Ppi for the Guided Section.
702 *GuidedSectionExtraction
= (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*) Interface
;
713 Go through the file to search SectionType section.
714 Search within encapsulation sections (compression and GUIDed) recursively,
715 until the match section is found.
717 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
718 @param SectionType Filter to find only section of this type.
719 @param SectionInstance Pointer to the filter to find the specific instance of section.
720 @param Section From where to search.
721 @param SectionSize The file size to search.
722 @param OutputBuffer A pointer to the discovered section, if successful.
723 NULL if section not found
724 @param AuthenticationStatus Updated upon return to point to the authentication status for this section.
725 @param IsFfs3Fv Indicates the FV format.
727 @return EFI_NOT_FOUND The match section is not found.
728 @return EFI_SUCCESS The match section is found.
733 IN CONST EFI_PEI_SERVICES
**PeiServices
,
734 IN EFI_SECTION_TYPE SectionType
,
735 IN OUT UINTN
*SectionInstance
,
736 IN EFI_COMMON_SECTION_HEADER
*Section
,
737 IN UINTN SectionSize
,
738 OUT VOID
**OutputBuffer
,
739 OUT UINT32
*AuthenticationStatus
,
744 UINT32 SectionLength
;
746 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
747 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
751 UINT32 Authentication
;
752 PEI_CORE_INSTANCE
*PrivateData
;
753 EFI_GUID
*SectionDefinitionGuid
;
754 BOOLEAN SectionCached
;
755 VOID
*TempOutputBuffer
;
756 UINT32 TempAuthenticationStatus
;
757 UINT16 GuidedSectionAttributes
;
759 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
760 *OutputBuffer
= NULL
;
763 Status
= EFI_NOT_FOUND
;
766 while (ParsedLength
< SectionSize
) {
768 if (IS_SECTION2 (Section
)) {
769 ASSERT (SECTION2_SIZE (Section
) > 0x00FFFFFF);
771 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
772 SectionLength
= SECTION2_SIZE (Section
);
774 // SectionLength is adjusted it is 4 byte aligned.
775 // Go to the next section
777 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
778 ASSERT (SectionLength
!= 0);
779 ParsedLength
+= SectionLength
;
780 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ SectionLength
);
785 if (Section
->Type
== SectionType
) {
787 // The type matches, so check the instance count to see if it's the one we want.
789 (*SectionInstance
)--;
790 if (*SectionInstance
== 0) {
794 if (IS_SECTION2 (Section
)) {
795 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
797 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
801 if (IS_SECTION2 (Section
)) {
802 SectionLength
= SECTION2_SIZE (Section
);
804 SectionLength
= SECTION_SIZE (Section
);
807 // SectionLength is adjusted it is 4 byte aligned.
808 // Go to the next section
810 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
811 ASSERT (SectionLength
!= 0);
812 ParsedLength
+= SectionLength
;
813 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
816 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
818 // Check the encapsulated section is extracted into the cache data.
820 SectionCached
= FALSE
;
821 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
822 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
823 SectionCached
= TRUE
;
824 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
825 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
826 Authentication
= PrivateData
->CacheSection
.AuthenticationStatus
[Index
];
828 // Search section directly from the cache data.
830 TempAuthenticationStatus
= 0;
831 Status
= ProcessSection (
838 &TempAuthenticationStatus
,
841 if (!EFI_ERROR (Status
)) {
842 *OutputBuffer
= TempOutputBuffer
;
843 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
850 // If SectionCached is TRUE, the section data has been cached and scanned.
852 if (!SectionCached
) {
853 Status
= EFI_NOT_FOUND
;
855 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
856 if (IS_SECTION2 (Section
)) {
857 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION2
*)Section
)->SectionDefinitionGuid
;
858 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION2
*)Section
)->Attributes
;
860 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
;
861 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION
*)Section
)->Attributes
;
863 if (VerifyGuidedSectionGuid (SectionDefinitionGuid
, &GuidSectionPpi
)) {
864 Status
= GuidSectionPpi
->ExtractSection (
871 } else if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) == 0) {
873 // Figure out the proper authentication status for GUIDED section without processing required
875 Status
= EFI_SUCCESS
;
876 if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) {
877 Authentication
|= EFI_AUTH_STATUS_IMAGE_SIGNED
| EFI_AUTH_STATUS_NOT_TESTED
;
879 if (IS_SECTION2 (Section
)) {
880 PpiOutputSize
= SECTION2_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
881 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
883 PpiOutputSize
= SECTION_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
884 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
887 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
888 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
889 if (!EFI_ERROR (Status
)) {
890 Status
= DecompressPpi
->Decompress (
892 (CONST EFI_COMPRESSION_SECTION
*) Section
,
899 if (!EFI_ERROR (Status
)) {
901 // Update cache section data.
903 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
904 PrivateData
->CacheSection
.AllSectionCount
++;
906 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
907 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
908 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
909 PrivateData
->CacheSection
.AuthenticationStatus
[PrivateData
->CacheSection
.SectionIndex
] = Authentication
;
910 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
912 TempAuthenticationStatus
= 0;
913 Status
= ProcessSection (
920 &TempAuthenticationStatus
,
923 if (!EFI_ERROR (Status
)) {
924 *OutputBuffer
= TempOutputBuffer
;
925 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
932 if (IS_SECTION2 (Section
)) {
933 SectionLength
= SECTION2_SIZE (Section
);
935 SectionLength
= SECTION_SIZE (Section
);
938 // SectionLength is adjusted it is 4 byte aligned.
939 // Go to the next section
941 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
942 ASSERT (SectionLength
!= 0);
943 ParsedLength
+= SectionLength
;
944 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
947 return EFI_NOT_FOUND
;
952 Searches for the next matching section within the specified file.
954 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
955 @param SectionType Filter to find only sections of this type.
956 @param FileHandle Pointer to the current file to search.
957 @param SectionData A pointer to the discovered section, if successful.
958 NULL if section not found
960 @retval EFI_NOT_FOUND The section was not found.
961 @retval EFI_SUCCESS The section was found.
966 PeiFfsFindSectionData (
967 IN CONST EFI_PEI_SERVICES
**PeiServices
,
968 IN EFI_SECTION_TYPE SectionType
,
969 IN EFI_PEI_FILE_HANDLE FileHandle
,
970 OUT VOID
**SectionData
973 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
975 CoreFvHandle
= FileHandleToVolume (FileHandle
);
976 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
977 return EFI_NOT_FOUND
;
980 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
984 Searches for the next matching section within the specified file.
986 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
987 @param SectionType The value of the section type to find.
988 @param SectionInstance Section instance to find.
989 @param FileHandle Handle of the firmware file to search.
990 @param SectionData A pointer to the discovered section, if successful.
991 @param AuthenticationStatus A pointer to the authentication status for this section.
993 @retval EFI_SUCCESS The section was found.
994 @retval EFI_NOT_FOUND The section was not found.
999 PeiFfsFindSectionData3 (
1000 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1001 IN EFI_SECTION_TYPE SectionType
,
1002 IN UINTN SectionInstance
,
1003 IN EFI_PEI_FILE_HANDLE FileHandle
,
1004 OUT VOID
**SectionData
,
1005 OUT UINT32
*AuthenticationStatus
1008 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1010 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1011 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1012 return EFI_NOT_FOUND
;
1015 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1016 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1017 return CoreFvHandle
->FvPpi
->FindSectionByType2 (CoreFvHandle
->FvPpi
, SectionType
, SectionInstance
, FileHandle
, SectionData
, AuthenticationStatus
);
1020 // The old FvPpi doesn't support to find section by section instance
1021 // and return authentication status, so return EFI_UNSUPPORTED.
1023 return EFI_UNSUPPORTED
;
1027 Searches for the next matching file in the firmware volume.
1029 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1030 @param SearchType Filter to find only files of this type.
1031 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
1032 @param FvHandle Handle of firmware volume in which to search.
1033 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
1034 at the beginning of the firmware volume. On exit, points the file handle of the next file
1035 in the volume or NULL if there are no more files.
1037 @retval EFI_NOT_FOUND The file was not found.
1038 @retval EFI_NOT_FOUND The header checksum was not zero.
1039 @retval EFI_SUCCESS The file was found.
1044 PeiFfsFindNextFile (
1045 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1046 IN UINT8 SearchType
,
1047 IN EFI_PEI_FV_HANDLE FvHandle
,
1048 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1051 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1053 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
1056 // To make backward compatiblity, if can not find corresponding the handle of FV
1057 // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed
1058 // to the address of first byte of FV.
1060 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1061 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1064 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
1065 return EFI_NOT_FOUND
;
1068 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
1073 Search the firmware volumes by index
1075 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1076 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
1078 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
1080 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
1081 @retval EFI_NOT_FOUND The volume was not found.
1082 @retval EFI_SUCCESS The volume was found.
1087 PeiFfsFindNextVolume (
1088 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1090 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
1093 PEI_CORE_INSTANCE
*Private
;
1094 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1096 if (VolumeHandle
== NULL
) {
1097 return EFI_INVALID_PARAMETER
;
1100 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1102 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
1103 if (CoreFvHandle
== NULL
) {
1104 *VolumeHandle
= NULL
;
1105 return EFI_NOT_FOUND
;
1108 *VolumeHandle
= CoreFvHandle
->FvHandle
;
1115 Find a file within a volume by its name.
1117 @param FileName A pointer to the name of the file to find within the firmware volume.
1118 @param VolumeHandle The firmware volume to search
1119 @param FileHandle Upon exit, points to the found file's handle
1120 or NULL if it could not be found.
1122 @retval EFI_SUCCESS File was found.
1123 @retval EFI_NOT_FOUND File was not found.
1124 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
1129 PeiFfsFindFileByName (
1130 IN CONST EFI_GUID
*FileName
,
1131 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1132 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1135 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1137 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1138 return EFI_INVALID_PARAMETER
;
1141 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
1142 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1143 return EFI_NOT_FOUND
;
1146 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
1150 Returns information about a specific file.
1152 @param FileHandle Handle of the file.
1153 @param FileInfo Upon exit, points to the file's information.
1155 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1156 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1157 @retval EFI_SUCCESS File information returned.
1163 IN EFI_PEI_FILE_HANDLE FileHandle
,
1164 OUT EFI_FV_FILE_INFO
*FileInfo
1167 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1169 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1170 return EFI_INVALID_PARAMETER
;
1174 // Retrieve the FirmwareVolume which the file resides in.
1176 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1177 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1178 return EFI_INVALID_PARAMETER
;
1181 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1185 Returns information about a specific file.
1187 @param FileHandle Handle of the file.
1188 @param FileInfo Upon exit, points to the file's information.
1190 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1191 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1192 @retval EFI_SUCCESS File information returned.
1197 PeiFfsGetFileInfo2 (
1198 IN EFI_PEI_FILE_HANDLE FileHandle
,
1199 OUT EFI_FV_FILE_INFO2
*FileInfo
1202 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1204 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1205 return EFI_INVALID_PARAMETER
;
1209 // Retrieve the FirmwareVolume which the file resides in.
1211 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1212 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1213 return EFI_INVALID_PARAMETER
;
1216 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1217 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1218 return CoreFvHandle
->FvPpi
->GetFileInfo2 (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1221 // The old FvPpi doesn't support to return file info with authentication status,
1222 // so return EFI_UNSUPPORTED.
1224 return EFI_UNSUPPORTED
;
1228 Returns information about the specified volume.
1230 This function returns information about a specific firmware
1231 volume, including its name, type, attributes, starting address
1234 @param VolumeHandle Handle of the volume.
1235 @param VolumeInfo Upon exit, points to the volume's information.
1237 @retval EFI_SUCCESS Volume information returned.
1238 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
1239 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
1240 @retval EFI_SUCCESS Information successfully returned.
1241 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
1246 PeiFfsGetVolumeInfo (
1247 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1248 OUT EFI_FV_INFO
*VolumeInfo
1251 PEI_CORE_FV_HANDLE
*CoreHandle
;
1253 if ((VolumeInfo
== NULL
) || (VolumeHandle
== NULL
)) {
1254 return EFI_INVALID_PARAMETER
;
1257 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
1259 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
1260 return EFI_INVALID_PARAMETER
;
1263 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
1267 Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.
1269 @param PrivateData PeiCore's private data structure
1270 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
1271 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
1273 @retval EFI_NOT_FOUND FV image can't be found.
1274 @retval EFI_SUCCESS Successfully to process it.
1275 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
1276 @retval EFI_SECURITY_VIOLATION Image is illegal
1277 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
1282 IN PEI_CORE_INSTANCE
*PrivateData
,
1283 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
1284 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
1288 EFI_FV_INFO ParentFvImageInfo
;
1291 EFI_PEI_HOB_POINTERS HobPtr
;
1292 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
1293 EFI_PEI_FV_HANDLE ParentFvHandle
;
1294 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
1295 EFI_FV_FILE_INFO FileInfo
;
1297 UINT32 AuthenticationStatus
;
1300 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1303 HobPtr
.Raw
= GetHobList ();
1304 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
1305 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
1307 // this FILE has been dispatched, it will not be dispatched again.
1309 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
1312 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
1315 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
1316 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
1319 // Find FvImage in FvFile
1321 AuthenticationStatus
= 0;
1322 if ((ParentFvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1323 (ParentFvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1324 Status
= ParentFvPpi
->FindSectionByType2 (
1326 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1330 &AuthenticationStatus
1333 Status
= ParentFvPpi
->FindSectionByType (
1335 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1340 if (EFI_ERROR (Status
)) {
1344 Status
= VerifyPeim (PrivateData
, ParentFvHandle
, ParentFvFileHandle
, AuthenticationStatus
);
1345 if (Status
== EFI_SECURITY_VIOLATION
) {
1350 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
1351 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
1352 // its initial linked location and maintain its alignment.
1354 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
1356 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
1358 FvAlignment
= 1 << ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ALIGNMENT
) >> 16);
1359 if (FvAlignment
< 8) {
1366 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
1367 FvLength
= ReadUnaligned64 (&FvHeader
->FvLength
);
1368 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvLength
), FvAlignment
);
1369 if (NewFvBuffer
== NULL
) {
1370 return EFI_OUT_OF_RESOURCES
;
1372 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvLength
);
1373 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
1377 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
1378 ASSERT_EFI_ERROR (Status
);
1380 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
1381 ASSERT_EFI_ERROR (Status
);
1384 // Install FvInfo(2) Ppi
1385 // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated
1386 // FVs inherit the proper AuthenticationStatus.
1388 PeiServicesInstallFvInfo2Ppi(
1389 &FvHeader
->FileSystemGuid
,
1391 (UINT32
)FvHeader
->FvLength
,
1392 &ParentFvImageInfo
.FvName
,
1394 AuthenticationStatus
1397 PeiServicesInstallFvInfoPpi (
1398 &FvHeader
->FileSystemGuid
,
1400 (UINT32
) FvHeader
->FvLength
,
1401 &ParentFvImageInfo
.FvName
,
1406 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
1409 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1414 // Makes the encapsulated volume show up in DXE phase to skip processing of
1415 // encapsulated file again.
1418 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1420 &ParentFvImageInfo
.FvName
,
1428 Process a firmware volume and create a volume handle.
1430 Create a volume handle from the information in the buffer. For
1431 memory-mapped firmware volumes, Buffer and BufferSize refer to
1432 the start of the firmware volume and the firmware volume size.
1433 For non memory-mapped firmware volumes, this points to a
1434 buffer which contains the necessary information for creating
1435 the firmware volume handle. Normally, these values are derived
1436 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
1439 @param This Points to this instance of the
1440 EFI_PEI_FIRMWARE_VOLUME_PPI.
1441 @param Buffer Points to the start of the buffer.
1442 @param BufferSize Size of the buffer.
1443 @param FvHandle Points to the returned firmware volume
1444 handle. The firmware volume handle must
1445 be unique within the system.
1447 @retval EFI_SUCCESS Firmware volume handle created.
1448 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
1453 PeiFfsFvPpiProcessVolume (
1454 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1456 IN UINTN BufferSize
,
1457 OUT EFI_PEI_FV_HANDLE
*FvHandle
1462 ASSERT (FvHandle
!= NULL
);
1464 if (Buffer
== NULL
) {
1465 return EFI_VOLUME_CORRUPTED
;
1469 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped
1470 // FV image and the handle is pointed to Fv image's buffer.
1472 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
1475 // Do verify for given FV buffer.
1477 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1478 if (EFI_ERROR(Status
)) {
1479 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1480 return EFI_VOLUME_CORRUPTED
;
1487 Finds the next file of the specified type.
1489 This service enables PEI modules to discover additional firmware files.
1490 The FileHandle must be unique within the system.
1492 @param This Points to this instance of the
1493 EFI_PEI_FIRMWARE_VOLUME_PPI.
1494 @param SearchType A filter to find only files of this type. Type
1495 EFI_FV_FILETYPE_ALL causes no filtering to be
1497 @param FvHandle Handle of firmware volume in which to
1499 @param FileHandle Points to the current handle from which to
1500 begin searching or NULL to start at the
1501 beginning of the firmware volume. Updated
1502 upon return to reflect the file found.
1504 @retval EFI_SUCCESS The file was found.
1505 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1510 PeiFfsFvPpiFindFileByType (
1511 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1512 IN EFI_FV_FILETYPE SearchType
,
1513 IN EFI_PEI_FV_HANDLE FvHandle
,
1514 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1517 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1521 Find a file within a volume by its name.
1523 This service searches for files with a specific name, within
1524 either the specified firmware volume or all firmware volumes.
1526 @param This Points to this instance of the
1527 EFI_PEI_FIRMWARE_VOLUME_PPI.
1528 @param FileName A pointer to the name of the file to find
1529 within the firmware volume.
1530 @param FvHandle Upon entry, the pointer to the firmware
1531 volume to search or NULL if all firmware
1532 volumes should be searched. Upon exit, the
1533 actual firmware volume in which the file was
1535 @param FileHandle Upon exit, points to the found file's
1536 handle or NULL if it could not be found.
1538 @retval EFI_SUCCESS File was found.
1539 @retval EFI_NOT_FOUND File was not found.
1540 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1547 PeiFfsFvPpiFindFileByName (
1548 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1549 IN CONST EFI_GUID
*FileName
,
1550 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1551 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1555 PEI_CORE_INSTANCE
*PrivateData
;
1558 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1559 return EFI_INVALID_PARAMETER
;
1562 if (*FvHandle
!= NULL
) {
1563 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1564 if (Status
== EFI_NOT_FOUND
) {
1569 // If *FvHandle = NULL, so search all FV for given filename
1571 Status
= EFI_NOT_FOUND
;
1573 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1574 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1576 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1578 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1579 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1580 if (!EFI_ERROR (Status
)) {
1581 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1592 Returns information about a specific file.
1594 This function returns information about a specific
1595 file, including its file name, type, attributes, starting
1598 @param This Points to this instance of the
1599 EFI_PEI_FIRMWARE_VOLUME_PPI.
1600 @param FileHandle Handle of the file.
1601 @param FileInfo Upon exit, points to the file's
1604 @retval EFI_SUCCESS File information returned.
1605 @retval EFI_INVALID_PARAMETER If FileHandle does not
1606 represent a valid file.
1607 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1612 PeiFfsFvPpiGetFileInfo (
1613 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1614 IN EFI_PEI_FILE_HANDLE FileHandle
,
1615 OUT EFI_FV_FILE_INFO
*FileInfo
1619 UINT8 ErasePolarity
;
1620 EFI_FFS_FILE_HEADER
*FileHeader
;
1621 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1622 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1624 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1625 return EFI_INVALID_PARAMETER
;
1629 // Retrieve the FirmwareVolume which the file resides in.
1631 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1632 if (CoreFvHandle
== NULL
) {
1633 return EFI_INVALID_PARAMETER
;
1636 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1638 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
1645 // Get FileState which is the highest bit of the State
1647 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1649 switch (FileState
) {
1650 case EFI_FILE_DATA_VALID
:
1651 case EFI_FILE_MARKED_FOR_UPDATE
:
1654 return EFI_INVALID_PARAMETER
;
1657 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1658 if (IS_FFS_FILE2 (FileHeader
)) {
1659 ASSERT (FFS_FILE2_SIZE (FileHeader
) > 0x00FFFFFF);
1660 if (!FwVolInstance
->IsFfs3Fv
) {
1661 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader
->Name
));
1662 return EFI_INVALID_PARAMETER
;
1664 FileInfo
->BufferSize
= FFS_FILE2_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1665 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
);
1667 FileInfo
->BufferSize
= FFS_FILE_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1668 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER
);
1670 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1671 FileInfo
->FileType
= FileHeader
->Type
;
1672 FileInfo
->FileAttributes
= FfsAttributes2FvFileAttributes (FileHeader
->Attributes
);
1673 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_MEMORY_MAPPED
) == EFI_FVB2_MEMORY_MAPPED
) {
1674 FileInfo
->FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
1680 Returns information about a specific file.
1682 This function returns information about a specific
1683 file, including its file name, type, attributes, starting
1684 address, size and authentication status.
1686 @param This Points to this instance of the
1687 EFI_PEI_FIRMWARE_VOLUME_PPI.
1688 @param FileHandle Handle of the file.
1689 @param FileInfo Upon exit, points to the file's
1692 @retval EFI_SUCCESS File information returned.
1693 @retval EFI_INVALID_PARAMETER If FileHandle does not
1694 represent a valid file.
1695 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1700 PeiFfsFvPpiGetFileInfo2 (
1701 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1702 IN EFI_PEI_FILE_HANDLE FileHandle
,
1703 OUT EFI_FV_FILE_INFO2
*FileInfo
1707 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1709 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1710 return EFI_INVALID_PARAMETER
;
1714 // Retrieve the FirmwareVolume which the file resides in.
1716 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1717 if (CoreFvHandle
== NULL
) {
1718 return EFI_INVALID_PARAMETER
;
1721 Status
= PeiFfsFvPpiGetFileInfo (This
, FileHandle
, (EFI_FV_FILE_INFO
*) FileInfo
);
1722 if (!EFI_ERROR (Status
)) {
1723 FileInfo
->AuthenticationStatus
= CoreFvHandle
->AuthenticationStatus
;
1730 This function returns information about the firmware volume.
1732 @param This Points to this instance of the
1733 EFI_PEI_FIRMWARE_VOLUME_PPI.
1734 @param FvHandle Handle to the firmware handle.
1735 @param VolumeInfo Points to the returned firmware volume
1738 @retval EFI_SUCCESS Information returned successfully.
1739 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1740 firmware volume or VolumeInfo is NULL.
1745 PeiFfsFvPpiGetVolumeInfo (
1746 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1747 IN EFI_PEI_FV_HANDLE FvHandle
,
1748 OUT EFI_FV_INFO
*VolumeInfo
1751 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1752 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1754 if ((VolumeInfo
== NULL
) || (FvHandle
== NULL
)) {
1755 return EFI_INVALID_PARAMETER
;
1759 // VolumeHandle may not align at 8 byte,
1760 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1761 // So, Copy FvHeader into the local FvHeader structure.
1763 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1766 // Check Fv Image Signature
1768 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1769 return EFI_INVALID_PARAMETER
;
1772 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1773 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1774 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1775 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1776 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1778 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1779 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1780 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1787 Find the next matching section in the firmware file.
1789 This service enables PEI modules to discover sections
1790 of a given type within a valid file.
1792 @param This Points to this instance of the
1793 EFI_PEI_FIRMWARE_VOLUME_PPI.
1794 @param SearchType A filter to find only sections of this
1796 @param FileHandle Handle of firmware file in which to
1798 @param SectionData Updated upon return to point to the
1801 @retval EFI_SUCCESS Section was found.
1802 @retval EFI_NOT_FOUND Section of the specified type was not
1803 found. SectionData contains NULL.
1807 PeiFfsFvPpiFindSectionByType (
1808 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1809 IN EFI_SECTION_TYPE SearchType
,
1810 IN EFI_PEI_FILE_HANDLE FileHandle
,
1811 OUT VOID
**SectionData
1814 UINT32 AuthenticationStatus
;
1815 return PeiFfsFvPpiFindSectionByType2 (This
, SearchType
, 0, FileHandle
, SectionData
, &AuthenticationStatus
);
1819 Find the next matching section in the firmware file.
1821 This service enables PEI modules to discover sections
1822 of a given instance and type within a valid file.
1824 @param This Points to this instance of the
1825 EFI_PEI_FIRMWARE_VOLUME_PPI.
1826 @param SearchType A filter to find only sections of this
1828 @param SearchInstance A filter to find the specific instance
1830 @param FileHandle Handle of firmware file in which to
1832 @param SectionData Updated upon return to point to the
1834 @param AuthenticationStatus Updated upon return to point to the
1835 authentication status for this section.
1837 @retval EFI_SUCCESS Section was found.
1838 @retval EFI_NOT_FOUND Section of the specified type was not
1839 found. SectionData contains NULL.
1843 PeiFfsFvPpiFindSectionByType2 (
1844 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1845 IN EFI_SECTION_TYPE SearchType
,
1846 IN UINTN SearchInstance
,
1847 IN EFI_PEI_FILE_HANDLE FileHandle
,
1848 OUT VOID
**SectionData
,
1849 OUT UINT32
*AuthenticationStatus
1853 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
1855 EFI_COMMON_SECTION_HEADER
*Section
;
1856 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1857 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1859 UINT32 ExtractedAuthenticationStatus
;
1861 if (SectionData
== NULL
) {
1862 return EFI_NOT_FOUND
;
1865 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1868 // Retrieve the FirmwareVolume which the file resides in.
1870 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1871 if (CoreFvHandle
== NULL
) {
1872 return EFI_NOT_FOUND
;
1875 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
1877 if (IS_FFS_FILE2 (FfsFileHeader
)) {
1878 ASSERT (FFS_FILE2_SIZE (FfsFileHeader
) > 0x00FFFFFF);
1879 if (!FwVolInstance
->IsFfs3Fv
) {
1880 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
1881 return EFI_NOT_FOUND
;
1883 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
1884 FileSize
= FFS_FILE2_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1886 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
1887 FileSize
= FFS_FILE_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1890 Instance
= SearchInstance
+ 1;
1891 ExtractedAuthenticationStatus
= 0;
1892 Status
= ProcessSection (
1893 GetPeiServicesTablePointer (),
1899 &ExtractedAuthenticationStatus
,
1900 FwVolInstance
->IsFfs3Fv
1902 if (!EFI_ERROR (Status
)) {
1904 // Inherit the authentication status.
1906 *AuthenticationStatus
= ExtractedAuthenticationStatus
| CoreFvHandle
->AuthenticationStatus
;
1912 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
1914 @param FvHandle The handle of a FV.
1916 @retval NULL if can not find.
1917 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
1919 PEI_CORE_FV_HANDLE
*
1920 FvHandleToCoreHandle (
1921 IN EFI_PEI_FV_HANDLE FvHandle
1925 PEI_CORE_INSTANCE
*PrivateData
;
1927 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1928 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1929 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
1930 return &PrivateData
->Fv
[Index
];
1938 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
1940 This routine also will install FvInfo ppi for FV hob in PI ways.
1942 @param Private Pointer of PEI_CORE_INSTANCE
1943 @param Instance The index of FV want to be searched.
1945 @return Instance of PEI_CORE_FV_HANDLE.
1947 PEI_CORE_FV_HANDLE
*
1948 FindNextCoreFvHandle (
1949 IN PEI_CORE_INSTANCE
*Private
,
1955 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
1958 // Handle Framework FvHob and Install FvInfo Ppi for it.
1960 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1962 // Loop to search the wanted FirmwareVolume which supports FFS
1964 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
1965 while (FvHob
!= NULL
) {
1967 // Search whether FvHob has been installed into PeiCore's FV database.
1968 // If found, no need install new FvInfoPpi for it.
1970 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
1971 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
1978 // Search whether FvHob has been cached into PeiCore's Unknown FV database.
1979 // If found, no need install new FvInfoPpi for it.
1982 for (Index
= 0; Index
< Private
->UnknownFvInfoCount
; Index
++) {
1983 if ((UINTN
)FvHob
->BaseAddress
== (UINTN
)Private
->UnknownFvInfo
[Index
].FvInfo
) {
1991 // If the Fv in FvHob has not been installed into PeiCore's FV database and has
1992 // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi
1993 // for it then PeiCore will dispatch it in callback of FvInfoPpi.
1996 PeiServicesInstallFvInfoPpi (
1997 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
1998 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
1999 (UINT32
)FvHob
->Length
,
2005 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
2009 ASSERT (Private
->FvCount
<= PcdGet32 (PcdPeiCoreMaxFvSupported
));
2010 if (Instance
>= Private
->FvCount
) {
2014 return &Private
->Fv
[Instance
];
2018 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
2019 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
2020 PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant
2023 @param PrivateData Pointer to PEI_CORE_INSTANCE.
2027 IN PEI_CORE_INSTANCE
*PrivateData
2031 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
2036 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
2039 Status
= PeiServicesLocatePpi (
2040 &gEfiFirmwareFileSystem2Guid
,
2045 ASSERT_EFI_ERROR (Status
);
2048 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
2049 // which is shadowed from flash to permanent memory within PeiCore image.
2051 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
2052 ASSERT_EFI_ERROR (Status
);
2055 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2057 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2058 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2059 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FwVol
.Fv
;
2064 // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which
2067 Status
= PeiServicesLocatePpi (
2068 &gEfiFirmwareFileSystem3Guid
,
2073 ASSERT_EFI_ERROR (Status
);
2076 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3
2077 // which is shadowed from flash to permanent memory within PeiCore image.
2079 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs3FvPpiList
);
2080 ASSERT_EFI_ERROR (Status
);
2083 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2085 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2086 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2087 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs3FwVol
.Fv
;
2093 Report the information for a new discoveried FV in unknown third-party format.
2095 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but
2096 the FV in this format has been discoveried, then this FV's information will be cached into
2097 PEI_CORE_INSTANCE's UnknownFvInfo array.
2098 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI
2099 is installed later by platform's PEIM, the original unknown third-party FV will be processed by
2100 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2102 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2103 @param FvInfo2Ppi Point to FvInfo2 PPI.
2105 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
2106 @retval EFI_SUCCESS Success to add the information for unknown FV.
2109 AddUnknownFormatFvInfo (
2110 IN PEI_CORE_INSTANCE
*PrivateData
,
2111 IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
*FvInfo2Ppi
2114 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
2116 if (PrivateData
->UnknownFvInfoCount
+ 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2117 return EFI_OUT_OF_RESOURCES
;
2120 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
2121 PrivateData
->UnknownFvInfoCount
++;
2123 CopyGuid (&NewUnknownFv
->FvFormat
, &FvInfo2Ppi
->FvFormat
);
2124 NewUnknownFv
->FvInfo
= FvInfo2Ppi
->FvInfo
;
2125 NewUnknownFv
->FvInfoSize
= FvInfo2Ppi
->FvInfoSize
;
2126 NewUnknownFv
->AuthenticationStatus
= FvInfo2Ppi
->AuthenticationStatus
;
2127 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
2128 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
2129 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
2131 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
2136 Find the FV information according to third-party FV format guid.
2138 This routine also will remove the FV information found by given FV format guid from
2139 PrivateData->UnknownFvInfo[].
2141 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2142 @param Format Point to given FV format guid
2143 @param FvInfo On return, the pointer of FV information buffer
2144 @param FvInfoSize On return, the size of FV information buffer.
2145 @param AuthenticationStatus On return, the authentication status of FV information buffer.
2147 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
2148 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2151 FindUnknownFormatFvInfo (
2152 IN PEI_CORE_INSTANCE
*PrivateData
,
2153 IN EFI_GUID
*Format
,
2155 OUT UINT32
*FvInfoSize
,
2156 OUT UINT32
*AuthenticationStatus
2163 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
2164 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
2169 if (Index
== PrivateData
->UnknownFvInfoCount
) {
2170 return EFI_NOT_FOUND
;
2173 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
2174 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
2175 *AuthenticationStatus
= PrivateData
->UnknownFvInfo
[Index
].AuthenticationStatus
;
2178 // Remove an entry from UnknownFvInfo array.
2181 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
2182 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
2184 PrivateData
->UnknownFvInfoCount
--;
2189 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
2191 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
2192 routine is called to process all discoveried FVs in this format.
2194 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
2195 @param NotifyDescriptor Address of the notification descriptor data structure.
2196 @param Ppi Address of the PPI that was installed.
2198 @retval EFI_SUCCESS The notification callback is processed correctly.
2202 ThirdPartyFvPpiNotifyCallback (
2203 IN EFI_PEI_SERVICES
**PeiServices
,
2204 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
2208 PEI_CORE_INSTANCE
*PrivateData
;
2209 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
2212 UINT32 AuthenticationStatus
;
2214 EFI_PEI_FV_HANDLE FvHandle
;
2215 BOOLEAN IsProcessed
;
2217 EFI_PEI_FILE_HANDLE FileHandle
;
2220 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
2221 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
2224 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
, &AuthenticationStatus
);
2225 if (EFI_ERROR (Status
)) {
2230 // Process new found FV and get FV handle.
2232 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
2233 if (EFI_ERROR (Status
)) {
2234 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
2239 // Check whether the FV has already been processed.
2241 IsProcessed
= FALSE
;
2242 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
2243 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
2244 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo
));
2254 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2255 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
2256 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
2261 // Update internal PEI_CORE_FV array.
2263 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
2264 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
2265 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
2266 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= AuthenticationStatus
;
2269 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
2270 (UINT32
) PrivateData
->FvCount
,
2275 PrivateData
->FvCount
++;
2278 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
2282 Status
= FvPpi
->FindFileByType (
2284 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
2288 if (!EFI_ERROR (Status
)) {
2289 Status
= FvPpi
->FindSectionByType (
2291 EFI_SECTION_PEI_DEPEX
,
2295 if (!EFI_ERROR (Status
)) {
2296 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
2298 // Dependency is not satisfied.
2304 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
2305 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
2307 } while (FileHandle
!= NULL
);