2 Pei Core Firmware File System service routines.
4 Copyright (c) 2015 HP Development Company, L.P.
5 Copyright (c) 2006 - 2016, 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
;
550 Status
= EFI_SUCCESS
;
551 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
553 if (CompareGuid (NotifyDescriptor
->Guid
, &gEfiPeiFirmwareVolumeInfo2PpiGuid
)) {
557 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
));
563 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
564 FvInfo2Ppi
.AuthenticationStatus
= 0;
569 // Locate the corresponding FV_PPI according to founded FV's format guid
571 Status
= PeiServicesLocatePpi (
572 &FvInfo2Ppi
.FvFormat
,
577 if (!EFI_ERROR (Status
)) {
579 // Process new found FV and get FV handle.
581 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo2Ppi
.FvInfo
, FvInfo2Ppi
.FvInfoSize
, &FvHandle
);
582 if (EFI_ERROR (Status
)) {
583 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!\n"));
588 // Check whether the FV has already been processed.
590 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
591 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
592 if (IsFvInfo2
&& (FvInfo2Ppi
.AuthenticationStatus
!= PrivateData
->Fv
[FvIndex
].AuthenticationStatus
)) {
593 PrivateData
->Fv
[FvIndex
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
594 DEBUG ((EFI_D_INFO
, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex
, FvInfo2Ppi
.AuthenticationStatus
));
596 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo2Ppi
.FvInfo
));
601 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
602 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
603 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
608 // Update internal PEI_CORE_FV array.
610 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
;
611 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
612 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
613 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
614 CurFvCount
= PrivateData
->FvCount
;
617 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
619 (VOID
*) FvInfo2Ppi
.FvInfo
,
620 FvInfo2Ppi
.FvInfoSize
,
623 PrivateData
->FvCount
++;
626 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
630 Status
= FvPpi
->FindFileByType (
632 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
636 if (!EFI_ERROR (Status
)) {
637 Status
= FvPpi
->FindSectionByType (
639 EFI_SECTION_PEI_DEPEX
,
643 if (!EFI_ERROR (Status
)) {
644 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
646 // Dependency is not satisfied.
652 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, CurFvCount
, FvHandle
));
653 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[CurFvCount
], FileHandle
);
655 } while (FileHandle
!= NULL
);
657 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi
.FvInfo
));
659 AddUnknownFormatFvInfo (PrivateData
, &FvInfo2Ppi
);
666 Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.
668 @param GuidedSectionGuid The Guided Section GUID.
669 @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi
670 for the Guided Section.
672 @return TRUE The GuidedSectionGuid could be identified, and the pointer to
673 the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.
674 @return FALSE The GuidedSectionGuid could not be identified, or
675 the Guided Section Extraction Ppi has not been installed yet.
679 VerifyGuidedSectionGuid (
680 IN EFI_GUID
*GuidedSectionGuid
,
681 OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
**GuidedSectionExtraction
684 EFI_PEI_HOB_POINTERS Hob
;
685 EFI_GUID
*GuidRecorded
;
690 // Check if there is the Guided Section GUID HOB recorded the GUID itself.
692 Hob
.Raw
= GetFirstGuidHob (GuidedSectionGuid
);
693 if (Hob
.Raw
!= NULL
) {
694 GuidRecorded
= (EFI_GUID
*) GET_GUID_HOB_DATA (Hob
);
695 if (CompareGuid (GuidRecorded
, GuidedSectionGuid
)) {
697 // Found the recorded GuidedSectionGuid.
699 Status
= PeiServicesLocatePpi (GuidedSectionGuid
, 0, NULL
, (VOID
**) &Interface
);
700 if (!EFI_ERROR (Status
) && Interface
!= NULL
) {
702 // Found the supported Guided Section Extraction Ppi for the Guided Section.
704 *GuidedSectionExtraction
= (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*) Interface
;
715 Go through the file to search SectionType section.
716 Search within encapsulation sections (compression and GUIDed) recursively,
717 until the match section is found.
719 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
720 @param SectionType Filter to find only section of this type.
721 @param SectionInstance Pointer to the filter to find the specific instance of section.
722 @param Section From where to search.
723 @param SectionSize The file size to search.
724 @param OutputBuffer A pointer to the discovered section, if successful.
725 NULL if section not found
726 @param AuthenticationStatus Updated upon return to point to the authentication status for this section.
727 @param IsFfs3Fv Indicates the FV format.
729 @return EFI_NOT_FOUND The match section is not found.
730 @return EFI_SUCCESS The match section is found.
735 IN CONST EFI_PEI_SERVICES
**PeiServices
,
736 IN EFI_SECTION_TYPE SectionType
,
737 IN OUT UINTN
*SectionInstance
,
738 IN EFI_COMMON_SECTION_HEADER
*Section
,
739 IN UINTN SectionSize
,
740 OUT VOID
**OutputBuffer
,
741 OUT UINT32
*AuthenticationStatus
,
746 UINT32 SectionLength
;
748 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
749 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
753 UINT32 Authentication
;
754 PEI_CORE_INSTANCE
*PrivateData
;
755 EFI_GUID
*SectionDefinitionGuid
;
756 BOOLEAN SectionCached
;
757 VOID
*TempOutputBuffer
;
758 UINT32 TempAuthenticationStatus
;
759 UINT16 GuidedSectionAttributes
;
761 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
762 *OutputBuffer
= NULL
;
765 Status
= EFI_NOT_FOUND
;
768 while (ParsedLength
< SectionSize
) {
770 if (IS_SECTION2 (Section
)) {
771 ASSERT (SECTION2_SIZE (Section
) > 0x00FFFFFF);
773 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
774 SectionLength
= SECTION2_SIZE (Section
);
776 // SectionLength is adjusted it is 4 byte aligned.
777 // Go to the next section
779 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
780 ASSERT (SectionLength
!= 0);
781 ParsedLength
+= SectionLength
;
782 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ SectionLength
);
787 if (Section
->Type
== SectionType
) {
789 // The type matches, so check the instance count to see if it's the one we want.
791 (*SectionInstance
)--;
792 if (*SectionInstance
== 0) {
796 if (IS_SECTION2 (Section
)) {
797 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
799 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
803 if (IS_SECTION2 (Section
)) {
804 SectionLength
= SECTION2_SIZE (Section
);
806 SectionLength
= SECTION_SIZE (Section
);
809 // SectionLength is adjusted it is 4 byte aligned.
810 // Go to the next section
812 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
813 ASSERT (SectionLength
!= 0);
814 ParsedLength
+= SectionLength
;
815 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
818 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
820 // Check the encapsulated section is extracted into the cache data.
822 SectionCached
= FALSE
;
823 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
824 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
825 SectionCached
= TRUE
;
826 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
827 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
828 Authentication
= PrivateData
->CacheSection
.AuthenticationStatus
[Index
];
830 // Search section directly from the cache data.
832 TempAuthenticationStatus
= 0;
833 Status
= ProcessSection (
840 &TempAuthenticationStatus
,
843 if (!EFI_ERROR (Status
)) {
844 *OutputBuffer
= TempOutputBuffer
;
845 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
852 // If SectionCached is TRUE, the section data has been cached and scanned.
854 if (!SectionCached
) {
855 Status
= EFI_NOT_FOUND
;
857 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
858 if (IS_SECTION2 (Section
)) {
859 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION2
*)Section
)->SectionDefinitionGuid
;
860 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION2
*)Section
)->Attributes
;
862 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
;
863 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION
*)Section
)->Attributes
;
865 if (VerifyGuidedSectionGuid (SectionDefinitionGuid
, &GuidSectionPpi
)) {
866 Status
= GuidSectionPpi
->ExtractSection (
873 } else if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) == 0) {
875 // Figure out the proper authentication status for GUIDED section without processing required
877 Status
= EFI_SUCCESS
;
878 if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) {
879 Authentication
|= EFI_AUTH_STATUS_IMAGE_SIGNED
| EFI_AUTH_STATUS_NOT_TESTED
;
881 if (IS_SECTION2 (Section
)) {
882 PpiOutputSize
= SECTION2_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
883 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
885 PpiOutputSize
= SECTION_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
886 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
889 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
890 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
891 if (!EFI_ERROR (Status
)) {
892 Status
= DecompressPpi
->Decompress (
894 (CONST EFI_COMPRESSION_SECTION
*) Section
,
901 if (!EFI_ERROR (Status
)) {
903 // Update cache section data.
905 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
906 PrivateData
->CacheSection
.AllSectionCount
++;
908 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
909 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
910 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
911 PrivateData
->CacheSection
.AuthenticationStatus
[PrivateData
->CacheSection
.SectionIndex
] = Authentication
;
912 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
914 TempAuthenticationStatus
= 0;
915 Status
= ProcessSection (
922 &TempAuthenticationStatus
,
925 if (!EFI_ERROR (Status
)) {
926 *OutputBuffer
= TempOutputBuffer
;
927 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
934 if (IS_SECTION2 (Section
)) {
935 SectionLength
= SECTION2_SIZE (Section
);
937 SectionLength
= SECTION_SIZE (Section
);
940 // SectionLength is adjusted it is 4 byte aligned.
941 // Go to the next section
943 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
944 ASSERT (SectionLength
!= 0);
945 ParsedLength
+= SectionLength
;
946 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
949 return EFI_NOT_FOUND
;
954 Searches for the next matching section within the specified file.
956 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
957 @param SectionType Filter to find only sections of this type.
958 @param FileHandle Pointer to the current file to search.
959 @param SectionData A pointer to the discovered section, if successful.
960 NULL if section not found
962 @retval EFI_NOT_FOUND The section was not found.
963 @retval EFI_SUCCESS The section was found.
968 PeiFfsFindSectionData (
969 IN CONST EFI_PEI_SERVICES
**PeiServices
,
970 IN EFI_SECTION_TYPE SectionType
,
971 IN EFI_PEI_FILE_HANDLE FileHandle
,
972 OUT VOID
**SectionData
975 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
977 CoreFvHandle
= FileHandleToVolume (FileHandle
);
978 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
979 return EFI_NOT_FOUND
;
982 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
986 Searches for the next matching section within the specified file.
988 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
989 @param SectionType The value of the section type to find.
990 @param SectionInstance Section instance to find.
991 @param FileHandle Handle of the firmware file to search.
992 @param SectionData A pointer to the discovered section, if successful.
993 @param AuthenticationStatus A pointer to the authentication status for this section.
995 @retval EFI_SUCCESS The section was found.
996 @retval EFI_NOT_FOUND The section was not found.
1001 PeiFfsFindSectionData3 (
1002 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1003 IN EFI_SECTION_TYPE SectionType
,
1004 IN UINTN SectionInstance
,
1005 IN EFI_PEI_FILE_HANDLE FileHandle
,
1006 OUT VOID
**SectionData
,
1007 OUT UINT32
*AuthenticationStatus
1010 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1012 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1013 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1014 return EFI_NOT_FOUND
;
1017 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1018 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1019 return CoreFvHandle
->FvPpi
->FindSectionByType2 (CoreFvHandle
->FvPpi
, SectionType
, SectionInstance
, FileHandle
, SectionData
, AuthenticationStatus
);
1022 // The old FvPpi doesn't support to find section by section instance
1023 // and return authentication status, so return EFI_UNSUPPORTED.
1025 return EFI_UNSUPPORTED
;
1029 Searches for the next matching file in the firmware volume.
1031 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1032 @param SearchType Filter to find only files of this type.
1033 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
1034 @param FvHandle Handle of firmware volume in which to search.
1035 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
1036 at the beginning of the firmware volume. On exit, points the file handle of the next file
1037 in the volume or NULL if there are no more files.
1039 @retval EFI_NOT_FOUND The file was not found.
1040 @retval EFI_NOT_FOUND The header checksum was not zero.
1041 @retval EFI_SUCCESS The file was found.
1046 PeiFfsFindNextFile (
1047 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1048 IN UINT8 SearchType
,
1049 IN EFI_PEI_FV_HANDLE FvHandle
,
1050 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1053 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1055 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
1058 // To make backward compatiblity, if can not find corresponding the handle of FV
1059 // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed
1060 // to the address of first byte of FV.
1062 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1063 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1066 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
1067 return EFI_NOT_FOUND
;
1070 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
1075 Search the firmware volumes by index
1077 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1078 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
1080 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
1082 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
1083 @retval EFI_NOT_FOUND The volume was not found.
1084 @retval EFI_SUCCESS The volume was found.
1089 PeiFfsFindNextVolume (
1090 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1092 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
1095 PEI_CORE_INSTANCE
*Private
;
1096 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1098 if (VolumeHandle
== NULL
) {
1099 return EFI_INVALID_PARAMETER
;
1102 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1104 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
1105 if (CoreFvHandle
== NULL
) {
1106 *VolumeHandle
= NULL
;
1107 return EFI_NOT_FOUND
;
1110 *VolumeHandle
= CoreFvHandle
->FvHandle
;
1117 Find a file within a volume by its name.
1119 @param FileName A pointer to the name of the file to find within the firmware volume.
1120 @param VolumeHandle The firmware volume to search
1121 @param FileHandle Upon exit, points to the found file's handle
1122 or NULL if it could not be found.
1124 @retval EFI_SUCCESS File was found.
1125 @retval EFI_NOT_FOUND File was not found.
1126 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
1131 PeiFfsFindFileByName (
1132 IN CONST EFI_GUID
*FileName
,
1133 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1134 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1137 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1139 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1140 return EFI_INVALID_PARAMETER
;
1143 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
1144 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1145 return EFI_NOT_FOUND
;
1148 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
1152 Returns information about a specific file.
1154 @param FileHandle Handle of the file.
1155 @param FileInfo Upon exit, points to the file's information.
1157 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1158 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1159 @retval EFI_SUCCESS File information returned.
1165 IN EFI_PEI_FILE_HANDLE FileHandle
,
1166 OUT EFI_FV_FILE_INFO
*FileInfo
1169 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1171 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1172 return EFI_INVALID_PARAMETER
;
1176 // Retrieve the FirmwareVolume which the file resides in.
1178 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1179 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1180 return EFI_INVALID_PARAMETER
;
1183 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1187 Returns information about a specific file.
1189 @param FileHandle Handle of the file.
1190 @param FileInfo Upon exit, points to the file's information.
1192 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1193 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1194 @retval EFI_SUCCESS File information returned.
1199 PeiFfsGetFileInfo2 (
1200 IN EFI_PEI_FILE_HANDLE FileHandle
,
1201 OUT EFI_FV_FILE_INFO2
*FileInfo
1204 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1206 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1207 return EFI_INVALID_PARAMETER
;
1211 // Retrieve the FirmwareVolume which the file resides in.
1213 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1214 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1215 return EFI_INVALID_PARAMETER
;
1218 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1219 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1220 return CoreFvHandle
->FvPpi
->GetFileInfo2 (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1223 // The old FvPpi doesn't support to return file info with authentication status,
1224 // so return EFI_UNSUPPORTED.
1226 return EFI_UNSUPPORTED
;
1230 Returns information about the specified volume.
1232 This function returns information about a specific firmware
1233 volume, including its name, type, attributes, starting address
1236 @param VolumeHandle Handle of the volume.
1237 @param VolumeInfo Upon exit, points to the volume's information.
1239 @retval EFI_SUCCESS Volume information returned.
1240 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
1241 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
1242 @retval EFI_SUCCESS Information successfully returned.
1243 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
1248 PeiFfsGetVolumeInfo (
1249 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1250 OUT EFI_FV_INFO
*VolumeInfo
1253 PEI_CORE_FV_HANDLE
*CoreHandle
;
1255 if ((VolumeInfo
== NULL
) || (VolumeHandle
== NULL
)) {
1256 return EFI_INVALID_PARAMETER
;
1259 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
1261 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
1262 return EFI_INVALID_PARAMETER
;
1265 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
1269 Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.
1271 @param PrivateData PeiCore's private data structure
1272 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
1273 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
1275 @retval EFI_NOT_FOUND FV image can't be found.
1276 @retval EFI_SUCCESS Successfully to process it.
1277 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
1278 @retval EFI_SECURITY_VIOLATION Image is illegal
1279 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
1284 IN PEI_CORE_INSTANCE
*PrivateData
,
1285 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
1286 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
1290 EFI_FV_INFO ParentFvImageInfo
;
1293 EFI_PEI_HOB_POINTERS HobPtr
;
1294 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
1295 EFI_PEI_FV_HANDLE ParentFvHandle
;
1296 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
1297 EFI_FV_FILE_INFO FileInfo
;
1299 UINT32 AuthenticationStatus
;
1302 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1305 HobPtr
.Raw
= GetHobList ();
1306 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
1307 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
1309 // this FILE has been dispatched, it will not be dispatched again.
1311 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
1314 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
1317 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
1318 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
1321 // Find FvImage in FvFile
1323 AuthenticationStatus
= 0;
1324 if ((ParentFvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1325 (ParentFvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1326 Status
= ParentFvPpi
->FindSectionByType2 (
1328 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1332 &AuthenticationStatus
1335 Status
= ParentFvPpi
->FindSectionByType (
1337 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1342 if (EFI_ERROR (Status
)) {
1346 Status
= VerifyPeim (PrivateData
, ParentFvHandle
, ParentFvFileHandle
, AuthenticationStatus
);
1347 if (Status
== EFI_SECURITY_VIOLATION
) {
1352 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
1353 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
1354 // its initial linked location and maintain its alignment.
1356 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
1358 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
1360 FvAlignment
= 1 << ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ALIGNMENT
) >> 16);
1361 if (FvAlignment
< 8) {
1368 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
1369 FvLength
= ReadUnaligned64 (&FvHeader
->FvLength
);
1370 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvLength
), FvAlignment
);
1371 if (NewFvBuffer
== NULL
) {
1372 return EFI_OUT_OF_RESOURCES
;
1374 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvLength
);
1375 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
1379 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
1380 ASSERT_EFI_ERROR (Status
);
1382 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
1383 ASSERT_EFI_ERROR (Status
);
1386 // Install FvInfo(2) Ppi
1387 // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated
1388 // FVs inherit the proper AuthenticationStatus.
1390 PeiServicesInstallFvInfo2Ppi(
1391 &FvHeader
->FileSystemGuid
,
1393 (UINT32
)FvHeader
->FvLength
,
1394 &ParentFvImageInfo
.FvName
,
1396 AuthenticationStatus
1399 PeiServicesInstallFvInfoPpi (
1400 &FvHeader
->FileSystemGuid
,
1402 (UINT32
) FvHeader
->FvLength
,
1403 &ParentFvImageInfo
.FvName
,
1408 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
1411 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1416 // Makes the encapsulated volume show up in DXE phase to skip processing of
1417 // encapsulated file again.
1420 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1422 &ParentFvImageInfo
.FvName
,
1430 Process a firmware volume and create a volume handle.
1432 Create a volume handle from the information in the buffer. For
1433 memory-mapped firmware volumes, Buffer and BufferSize refer to
1434 the start of the firmware volume and the firmware volume size.
1435 For non memory-mapped firmware volumes, this points to a
1436 buffer which contains the necessary information for creating
1437 the firmware volume handle. Normally, these values are derived
1438 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
1441 @param This Points to this instance of the
1442 EFI_PEI_FIRMWARE_VOLUME_PPI.
1443 @param Buffer Points to the start of the buffer.
1444 @param BufferSize Size of the buffer.
1445 @param FvHandle Points to the returned firmware volume
1446 handle. The firmware volume handle must
1447 be unique within the system.
1449 @retval EFI_SUCCESS Firmware volume handle created.
1450 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
1455 PeiFfsFvPpiProcessVolume (
1456 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1458 IN UINTN BufferSize
,
1459 OUT EFI_PEI_FV_HANDLE
*FvHandle
1464 ASSERT (FvHandle
!= NULL
);
1466 if (Buffer
== NULL
) {
1467 return EFI_VOLUME_CORRUPTED
;
1471 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped
1472 // FV image and the handle is pointed to Fv image's buffer.
1474 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
1477 // Do verify for given FV buffer.
1479 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1480 if (EFI_ERROR(Status
)) {
1481 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1482 return EFI_VOLUME_CORRUPTED
;
1489 Finds the next file of the specified type.
1491 This service enables PEI modules to discover additional firmware files.
1492 The FileHandle must be unique within the system.
1494 @param This Points to this instance of the
1495 EFI_PEI_FIRMWARE_VOLUME_PPI.
1496 @param SearchType A filter to find only files of this type. Type
1497 EFI_FV_FILETYPE_ALL causes no filtering to be
1499 @param FvHandle Handle of firmware volume in which to
1501 @param FileHandle Points to the current handle from which to
1502 begin searching or NULL to start at the
1503 beginning of the firmware volume. Updated
1504 upon return to reflect the file found.
1506 @retval EFI_SUCCESS The file was found.
1507 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1512 PeiFfsFvPpiFindFileByType (
1513 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1514 IN EFI_FV_FILETYPE SearchType
,
1515 IN EFI_PEI_FV_HANDLE FvHandle
,
1516 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1519 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1523 Find a file within a volume by its name.
1525 This service searches for files with a specific name, within
1526 either the specified firmware volume or all firmware volumes.
1528 @param This Points to this instance of the
1529 EFI_PEI_FIRMWARE_VOLUME_PPI.
1530 @param FileName A pointer to the name of the file to find
1531 within the firmware volume.
1532 @param FvHandle Upon entry, the pointer to the firmware
1533 volume to search or NULL if all firmware
1534 volumes should be searched. Upon exit, the
1535 actual firmware volume in which the file was
1537 @param FileHandle Upon exit, points to the found file's
1538 handle or NULL if it could not be found.
1540 @retval EFI_SUCCESS File was found.
1541 @retval EFI_NOT_FOUND File was not found.
1542 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1549 PeiFfsFvPpiFindFileByName (
1550 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1551 IN CONST EFI_GUID
*FileName
,
1552 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1553 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1557 PEI_CORE_INSTANCE
*PrivateData
;
1560 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1561 return EFI_INVALID_PARAMETER
;
1564 if (*FvHandle
!= NULL
) {
1565 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1566 if (Status
== EFI_NOT_FOUND
) {
1571 // If *FvHandle = NULL, so search all FV for given filename
1573 Status
= EFI_NOT_FOUND
;
1575 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1576 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1578 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1580 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1581 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1582 if (!EFI_ERROR (Status
)) {
1583 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1594 Returns information about a specific file.
1596 This function returns information about a specific
1597 file, including its file name, type, attributes, starting
1600 @param This Points to this instance of the
1601 EFI_PEI_FIRMWARE_VOLUME_PPI.
1602 @param FileHandle Handle of the file.
1603 @param FileInfo Upon exit, points to the file's
1606 @retval EFI_SUCCESS File information returned.
1607 @retval EFI_INVALID_PARAMETER If FileHandle does not
1608 represent a valid file.
1609 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1614 PeiFfsFvPpiGetFileInfo (
1615 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1616 IN EFI_PEI_FILE_HANDLE FileHandle
,
1617 OUT EFI_FV_FILE_INFO
*FileInfo
1621 UINT8 ErasePolarity
;
1622 EFI_FFS_FILE_HEADER
*FileHeader
;
1623 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1624 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1626 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1627 return EFI_INVALID_PARAMETER
;
1631 // Retrieve the FirmwareVolume which the file resides in.
1633 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1634 if (CoreFvHandle
== NULL
) {
1635 return EFI_INVALID_PARAMETER
;
1638 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1640 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
1647 // Get FileState which is the highest bit of the State
1649 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1651 switch (FileState
) {
1652 case EFI_FILE_DATA_VALID
:
1653 case EFI_FILE_MARKED_FOR_UPDATE
:
1656 return EFI_INVALID_PARAMETER
;
1659 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1660 if (IS_FFS_FILE2 (FileHeader
)) {
1661 ASSERT (FFS_FILE2_SIZE (FileHeader
) > 0x00FFFFFF);
1662 if (!FwVolInstance
->IsFfs3Fv
) {
1663 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader
->Name
));
1664 return EFI_INVALID_PARAMETER
;
1666 FileInfo
->BufferSize
= FFS_FILE2_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1667 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
);
1669 FileInfo
->BufferSize
= FFS_FILE_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1670 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER
);
1672 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1673 FileInfo
->FileType
= FileHeader
->Type
;
1674 FileInfo
->FileAttributes
= FfsAttributes2FvFileAttributes (FileHeader
->Attributes
);
1675 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_MEMORY_MAPPED
) == EFI_FVB2_MEMORY_MAPPED
) {
1676 FileInfo
->FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
1682 Returns information about a specific file.
1684 This function returns information about a specific
1685 file, including its file name, type, attributes, starting
1686 address, size and authentication status.
1688 @param This Points to this instance of the
1689 EFI_PEI_FIRMWARE_VOLUME_PPI.
1690 @param FileHandle Handle of the file.
1691 @param FileInfo Upon exit, points to the file's
1694 @retval EFI_SUCCESS File information returned.
1695 @retval EFI_INVALID_PARAMETER If FileHandle does not
1696 represent a valid file.
1697 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1702 PeiFfsFvPpiGetFileInfo2 (
1703 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1704 IN EFI_PEI_FILE_HANDLE FileHandle
,
1705 OUT EFI_FV_FILE_INFO2
*FileInfo
1709 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1711 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1712 return EFI_INVALID_PARAMETER
;
1716 // Retrieve the FirmwareVolume which the file resides in.
1718 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1719 if (CoreFvHandle
== NULL
) {
1720 return EFI_INVALID_PARAMETER
;
1723 Status
= PeiFfsFvPpiGetFileInfo (This
, FileHandle
, (EFI_FV_FILE_INFO
*) FileInfo
);
1724 if (!EFI_ERROR (Status
)) {
1725 FileInfo
->AuthenticationStatus
= CoreFvHandle
->AuthenticationStatus
;
1732 This function returns information about the firmware volume.
1734 @param This Points to this instance of the
1735 EFI_PEI_FIRMWARE_VOLUME_PPI.
1736 @param FvHandle Handle to the firmware handle.
1737 @param VolumeInfo Points to the returned firmware volume
1740 @retval EFI_SUCCESS Information returned successfully.
1741 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1742 firmware volume or VolumeInfo is NULL.
1747 PeiFfsFvPpiGetVolumeInfo (
1748 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1749 IN EFI_PEI_FV_HANDLE FvHandle
,
1750 OUT EFI_FV_INFO
*VolumeInfo
1753 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1754 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1756 if ((VolumeInfo
== NULL
) || (FvHandle
== NULL
)) {
1757 return EFI_INVALID_PARAMETER
;
1761 // VolumeHandle may not align at 8 byte,
1762 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1763 // So, Copy FvHeader into the local FvHeader structure.
1765 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1768 // Check Fv Image Signature
1770 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1771 return EFI_INVALID_PARAMETER
;
1774 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1775 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1776 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1777 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1778 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1780 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1781 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1782 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1789 Find the next matching section in the firmware file.
1791 This service enables PEI modules to discover sections
1792 of a given type within a valid file.
1794 @param This Points to this instance of the
1795 EFI_PEI_FIRMWARE_VOLUME_PPI.
1796 @param SearchType A filter to find only sections of this
1798 @param FileHandle Handle of firmware file in which to
1800 @param SectionData Updated upon return to point to the
1803 @retval EFI_SUCCESS Section was found.
1804 @retval EFI_NOT_FOUND Section of the specified type was not
1805 found. SectionData contains NULL.
1809 PeiFfsFvPpiFindSectionByType (
1810 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1811 IN EFI_SECTION_TYPE SearchType
,
1812 IN EFI_PEI_FILE_HANDLE FileHandle
,
1813 OUT VOID
**SectionData
1816 UINT32 AuthenticationStatus
;
1817 return PeiFfsFvPpiFindSectionByType2 (This
, SearchType
, 0, FileHandle
, SectionData
, &AuthenticationStatus
);
1821 Find the next matching section in the firmware file.
1823 This service enables PEI modules to discover sections
1824 of a given instance and type within a valid file.
1826 @param This Points to this instance of the
1827 EFI_PEI_FIRMWARE_VOLUME_PPI.
1828 @param SearchType A filter to find only sections of this
1830 @param SearchInstance A filter to find the specific instance
1832 @param FileHandle Handle of firmware file in which to
1834 @param SectionData Updated upon return to point to the
1836 @param AuthenticationStatus Updated upon return to point to the
1837 authentication status for this section.
1839 @retval EFI_SUCCESS Section was found.
1840 @retval EFI_NOT_FOUND Section of the specified type was not
1841 found. SectionData contains NULL.
1845 PeiFfsFvPpiFindSectionByType2 (
1846 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1847 IN EFI_SECTION_TYPE SearchType
,
1848 IN UINTN SearchInstance
,
1849 IN EFI_PEI_FILE_HANDLE FileHandle
,
1850 OUT VOID
**SectionData
,
1851 OUT UINT32
*AuthenticationStatus
1855 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
1857 EFI_COMMON_SECTION_HEADER
*Section
;
1858 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1859 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1861 UINT32 ExtractedAuthenticationStatus
;
1863 if (SectionData
== NULL
) {
1864 return EFI_NOT_FOUND
;
1867 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1870 // Retrieve the FirmwareVolume which the file resides in.
1872 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1873 if (CoreFvHandle
== NULL
) {
1874 return EFI_NOT_FOUND
;
1877 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
1879 if (IS_FFS_FILE2 (FfsFileHeader
)) {
1880 ASSERT (FFS_FILE2_SIZE (FfsFileHeader
) > 0x00FFFFFF);
1881 if (!FwVolInstance
->IsFfs3Fv
) {
1882 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
1883 return EFI_NOT_FOUND
;
1885 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
1886 FileSize
= FFS_FILE2_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1888 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
1889 FileSize
= FFS_FILE_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1892 Instance
= SearchInstance
+ 1;
1893 ExtractedAuthenticationStatus
= 0;
1894 Status
= ProcessSection (
1895 GetPeiServicesTablePointer (),
1901 &ExtractedAuthenticationStatus
,
1902 FwVolInstance
->IsFfs3Fv
1904 if (!EFI_ERROR (Status
)) {
1906 // Inherit the authentication status.
1908 *AuthenticationStatus
= ExtractedAuthenticationStatus
| CoreFvHandle
->AuthenticationStatus
;
1914 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
1916 @param FvHandle The handle of a FV.
1918 @retval NULL if can not find.
1919 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
1921 PEI_CORE_FV_HANDLE
*
1922 FvHandleToCoreHandle (
1923 IN EFI_PEI_FV_HANDLE FvHandle
1927 PEI_CORE_INSTANCE
*PrivateData
;
1929 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1930 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1931 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
1932 return &PrivateData
->Fv
[Index
];
1940 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
1942 This routine also will install FvInfo ppi for FV hob in PI ways.
1944 @param Private Pointer of PEI_CORE_INSTANCE
1945 @param Instance The index of FV want to be searched.
1947 @return Instance of PEI_CORE_FV_HANDLE.
1949 PEI_CORE_FV_HANDLE
*
1950 FindNextCoreFvHandle (
1951 IN PEI_CORE_INSTANCE
*Private
,
1957 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
1960 // Handle Framework FvHob and Install FvInfo Ppi for it.
1962 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1964 // Loop to search the wanted FirmwareVolume which supports FFS
1966 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
1967 while (FvHob
!= NULL
) {
1969 // Search whether FvHob has been installed into PeiCore's FV database.
1970 // If found, no need install new FvInfoPpi for it.
1972 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
1973 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
1980 // Search whether FvHob has been cached into PeiCore's Unknown FV database.
1981 // If found, no need install new FvInfoPpi for it.
1984 for (Index
= 0; Index
< Private
->UnknownFvInfoCount
; Index
++) {
1985 if ((UINTN
)FvHob
->BaseAddress
== (UINTN
)Private
->UnknownFvInfo
[Index
].FvInfo
) {
1993 // If the Fv in FvHob has not been installed into PeiCore's FV database and has
1994 // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi
1995 // for it then PeiCore will dispatch it in callback of FvInfoPpi.
1998 PeiServicesInstallFvInfoPpi (
1999 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
2000 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
2001 (UINT32
)FvHob
->Length
,
2007 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
2011 ASSERT (Private
->FvCount
<= PcdGet32 (PcdPeiCoreMaxFvSupported
));
2012 if (Instance
>= Private
->FvCount
) {
2016 return &Private
->Fv
[Instance
];
2020 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
2021 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
2022 PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant
2025 @param PrivateData Pointer to PEI_CORE_INSTANCE.
2029 IN PEI_CORE_INSTANCE
*PrivateData
2033 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
2038 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
2041 Status
= PeiServicesLocatePpi (
2042 &gEfiFirmwareFileSystem2Guid
,
2047 ASSERT_EFI_ERROR (Status
);
2050 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
2051 // which is shadowed from flash to permanent memory within PeiCore image.
2053 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
2054 ASSERT_EFI_ERROR (Status
);
2057 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2059 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2060 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2061 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FwVol
.Fv
;
2066 // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which
2069 Status
= PeiServicesLocatePpi (
2070 &gEfiFirmwareFileSystem3Guid
,
2075 ASSERT_EFI_ERROR (Status
);
2078 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3
2079 // which is shadowed from flash to permanent memory within PeiCore image.
2081 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs3FvPpiList
);
2082 ASSERT_EFI_ERROR (Status
);
2085 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2087 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2088 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2089 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs3FwVol
.Fv
;
2095 Report the information for a new discoveried FV in unknown third-party format.
2097 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but
2098 the FV in this format has been discoveried, then this FV's information will be cached into
2099 PEI_CORE_INSTANCE's UnknownFvInfo array.
2100 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI
2101 is installed later by platform's PEIM, the original unknown third-party FV will be processed by
2102 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2104 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2105 @param FvInfo2Ppi Point to FvInfo2 PPI.
2107 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
2108 @retval EFI_SUCCESS Success to add the information for unknown FV.
2111 AddUnknownFormatFvInfo (
2112 IN PEI_CORE_INSTANCE
*PrivateData
,
2113 IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
*FvInfo2Ppi
2116 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
2118 if (PrivateData
->UnknownFvInfoCount
+ 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2119 return EFI_OUT_OF_RESOURCES
;
2122 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
2123 PrivateData
->UnknownFvInfoCount
++;
2125 CopyGuid (&NewUnknownFv
->FvFormat
, &FvInfo2Ppi
->FvFormat
);
2126 NewUnknownFv
->FvInfo
= FvInfo2Ppi
->FvInfo
;
2127 NewUnknownFv
->FvInfoSize
= FvInfo2Ppi
->FvInfoSize
;
2128 NewUnknownFv
->AuthenticationStatus
= FvInfo2Ppi
->AuthenticationStatus
;
2129 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
2130 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
2131 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
2133 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
2138 Find the FV information according to third-party FV format guid.
2140 This routine also will remove the FV information found by given FV format guid from
2141 PrivateData->UnknownFvInfo[].
2143 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2144 @param Format Point to given FV format guid
2145 @param FvInfo On return, the pointer of FV information buffer
2146 @param FvInfoSize On return, the size of FV information buffer.
2147 @param AuthenticationStatus On return, the authentication status of FV information buffer.
2149 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
2150 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2153 FindUnknownFormatFvInfo (
2154 IN PEI_CORE_INSTANCE
*PrivateData
,
2155 IN EFI_GUID
*Format
,
2157 OUT UINT32
*FvInfoSize
,
2158 OUT UINT32
*AuthenticationStatus
2165 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
2166 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
2171 if (Index
== PrivateData
->UnknownFvInfoCount
) {
2172 return EFI_NOT_FOUND
;
2175 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
2176 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
2177 *AuthenticationStatus
= PrivateData
->UnknownFvInfo
[Index
].AuthenticationStatus
;
2180 // Remove an entry from UnknownFvInfo array.
2183 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
2184 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
2186 PrivateData
->UnknownFvInfoCount
--;
2191 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
2193 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
2194 routine is called to process all discoveried FVs in this format.
2196 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
2197 @param NotifyDescriptor Address of the notification descriptor data structure.
2198 @param Ppi Address of the PPI that was installed.
2200 @retval EFI_SUCCESS The notification callback is processed correctly.
2204 ThirdPartyFvPpiNotifyCallback (
2205 IN EFI_PEI_SERVICES
**PeiServices
,
2206 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
2210 PEI_CORE_INSTANCE
*PrivateData
;
2211 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
2214 UINT32 AuthenticationStatus
;
2216 EFI_PEI_FV_HANDLE FvHandle
;
2217 BOOLEAN IsProcessed
;
2219 EFI_PEI_FILE_HANDLE FileHandle
;
2223 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
2224 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
2227 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
, &AuthenticationStatus
);
2228 if (EFI_ERROR (Status
)) {
2233 // Process new found FV and get FV handle.
2235 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
2236 if (EFI_ERROR (Status
)) {
2237 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
2242 // Check whether the FV has already been processed.
2244 IsProcessed
= FALSE
;
2245 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
2246 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
2247 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo
));
2257 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2258 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
2259 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
2264 // Update internal PEI_CORE_FV array.
2266 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
2267 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
2268 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
2269 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= AuthenticationStatus
;
2270 CurFvCount
= PrivateData
->FvCount
;
2273 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
2274 (UINT32
) CurFvCount
,
2279 PrivateData
->FvCount
++;
2282 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
2286 Status
= FvPpi
->FindFileByType (
2288 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
2292 if (!EFI_ERROR (Status
)) {
2293 Status
= FvPpi
->FindSectionByType (
2295 EFI_SECTION_PEI_DEPEX
,
2299 if (!EFI_ERROR (Status
)) {
2300 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
2302 // Dependency is not satisfied.
2308 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, CurFvCount
, FvHandle
));
2309 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[CurFvCount
], FileHandle
);
2311 } while (FileHandle
!= NULL
);