2 Pei Core Firmware File System service routines.
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList
[] = {
19 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
20 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
21 FirmwareVolmeInfoPpiNotifyCallback
24 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
25 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
26 FirmwareVolmeInfoPpiNotifyCallback
30 PEI_FW_VOL_INSTANCE mPeiFfs2FwVol
= {
34 PeiFfsFvPpiProcessVolume
,
35 PeiFfsFvPpiFindFileByType
,
36 PeiFfsFvPpiFindFileByName
,
37 PeiFfsFvPpiGetFileInfo
,
38 PeiFfsFvPpiGetVolumeInfo
,
39 PeiFfsFvPpiFindSectionByType
,
40 PeiFfsFvPpiGetFileInfo2
,
41 PeiFfsFvPpiFindSectionByType2
,
42 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
43 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
47 PEI_FW_VOL_INSTANCE mPeiFfs3FwVol
= {
51 PeiFfsFvPpiProcessVolume
,
52 PeiFfsFvPpiFindFileByType
,
53 PeiFfsFvPpiFindFileByName
,
54 PeiFfsFvPpiGetFileInfo
,
55 PeiFfsFvPpiGetVolumeInfo
,
56 PeiFfsFvPpiFindSectionByType
,
57 PeiFfsFvPpiGetFileInfo2
,
58 PeiFfsFvPpiFindSectionByType2
,
59 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
60 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
64 EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList
= {
65 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
66 &gEfiFirmwareFileSystem2Guid
,
70 EFI_PEI_PPI_DESCRIPTOR mPeiFfs3FvPpiList
= {
71 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
72 &gEfiFirmwareFileSystem3Guid
,
77 Required Alignment Alignment Value in FFS Alignment Value in
78 (bytes) Attributes Field Firmware Volume Interfaces
88 UINT8 mFvAttributes
[] = {0, 4, 7, 9, 10, 12, 15, 16};
91 Convert the FFS File Attributes to FV File Attributes
93 @param FfsAttributes The attributes of UINT8 type.
95 @return The attributes of EFI_FV_FILE_ATTRIBUTES
98 EFI_FV_FILE_ATTRIBUTES
99 FfsAttributes2FvFileAttributes (
100 IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
104 EFI_FV_FILE_ATTRIBUTES FileAttribute
;
106 DataAlignment
= (UINT8
) ((FfsAttributes
& FFS_ATTRIB_DATA_ALIGNMENT
) >> 3);
107 ASSERT (DataAlignment
< 8);
109 FileAttribute
= (EFI_FV_FILE_ATTRIBUTES
) mFvAttributes
[DataAlignment
];
111 if ((FfsAttributes
& FFS_ATTRIB_FIXED
) == FFS_ATTRIB_FIXED
) {
112 FileAttribute
|= EFI_FV_FILE_ATTRIB_FIXED
;
115 return FileAttribute
;
119 Returns the file state set by the highest zero bit in the State field
121 @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
122 in the Attributes field.
123 @param FfsHeader Pointer to FFS File Header.
125 @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit
126 in the header State field.
130 IN UINT8 ErasePolarity
,
131 IN EFI_FFS_FILE_HEADER
*FfsHeader
134 EFI_FFS_FILE_STATE FileState
;
135 EFI_FFS_FILE_STATE HighestBit
;
137 FileState
= FfsHeader
->State
;
139 if (ErasePolarity
!= 0) {
140 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
144 // Get file state set by its highest none zero bit.
147 while (HighestBit
!= 0 && (HighestBit
& FileState
) == 0) {
155 Calculates the checksum of the header of a file.
157 @param FileHeader Pointer to FFS File Header.
159 @return Checksum of the header.
160 Zero means the header is good.
161 Non-zero means the header is bad.
164 CalculateHeaderChecksum (
165 IN EFI_FFS_FILE_HEADER
*FileHeader
168 EFI_FFS_FILE_HEADER2 TestFileHeader
;
170 if (IS_FFS_FILE2 (FileHeader
)) {
171 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
173 // Ingore State and File field in FFS header.
175 TestFileHeader
.State
= 0;
176 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
178 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
180 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
182 // Ingore State and File field in FFS header.
184 TestFileHeader
.State
= 0;
185 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
187 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
192 Find FV handler according to FileHandle in that FV.
194 @param FileHandle Handle of file image
196 @return Pointer to instance of PEI_CORE_FV_HANDLE.
200 IN EFI_PEI_FILE_HANDLE FileHandle
204 PEI_CORE_INSTANCE
*PrivateData
;
205 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
208 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
209 BestIndex
= PrivateData
->FvCount
;
212 // Find the best matched FV image that includes this FileHandle.
213 // FV may include the child FV, and they are in the same continuous space.
214 // If FileHandle is from the child FV, the updated logic can find its matched FV.
216 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
217 FwVolHeader
= PrivateData
->Fv
[Index
].FvHeader
;
218 if (((UINT64
) (UINTN
) FileHandle
> (UINT64
) (UINTN
) FwVolHeader
) && \
219 ((UINT64
) (UINTN
) FileHandle
<= ((UINT64
) (UINTN
) FwVolHeader
+ FwVolHeader
->FvLength
- 1))) {
220 if (BestIndex
== PrivateData
->FvCount
) {
223 if ((UINT64
) (UINTN
) PrivateData
->Fv
[BestIndex
].FvHeader
< (UINT64
) (UINTN
) FwVolHeader
) {
230 if (BestIndex
< PrivateData
->FvCount
) {
231 return &PrivateData
->Fv
[BestIndex
];
238 Given the input file pointer, search for the first matching file in the
239 FFS volume as defined by SearchType. The search starts from FileHeader inside
240 the Firmware Volume defined by FwVolHeader.
241 If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.
242 If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
243 the first PEIM, or COMBINED PEIM or FV file type FFS file will return.
245 @param FvHandle Pointer to the FV header of the volume to search
246 @param FileName File name
247 @param SearchType Filter to find only files of this type.
248 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
249 @param FileHandle This parameter must point to a valid FFS volume.
250 @param AprioriFile Pointer to AprioriFile image in this FV if has
252 @return EFI_NOT_FOUND No files matching the search criteria were found
253 @retval EFI_SUCCESS Success to search given file
258 IN CONST EFI_PEI_FV_HANDLE FvHandle
,
259 IN CONST EFI_GUID
*FileName
, OPTIONAL
260 IN EFI_FV_FILETYPE SearchType
,
261 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
,
262 IN OUT EFI_PEI_FILE_HANDLE
*AprioriFile OPTIONAL
265 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
266 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExtHeader
;
267 EFI_FFS_FILE_HEADER
**FileHeader
;
268 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
270 UINT32 FileOccupiedSize
;
279 // Convert the handle of FV to FV header for memory-mapped firmware volume
281 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvHandle
;
282 FileHeader
= (EFI_FFS_FILE_HEADER
**)FileHandle
;
284 IsFfs3Fv
= CompareGuid (&FwVolHeader
->FileSystemGuid
, &gEfiFirmwareFileSystem3Guid
);
286 FvLength
= FwVolHeader
->FvLength
;
287 if ((FwVolHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
294 // If FileHeader is not specified (NULL) or FileName is not NULL,
295 // start with the first file in the firmware volume. Otherwise,
296 // start from the FileHeader.
298 if ((*FileHeader
== NULL
) || (FileName
!= NULL
)) {
299 if (FwVolHeader
->ExtHeaderOffset
!= 0) {
301 // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
303 FwVolExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*) ((UINT8
*) FwVolHeader
+ FwVolHeader
->ExtHeaderOffset
);
304 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FwVolExtHeader
+ FwVolExtHeader
->ExtHeaderSize
);
305 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ALIGN_POINTER (FfsFileHeader
, 8);
307 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*) FwVolHeader
+ FwVolHeader
->HeaderLength
);
310 if (IS_FFS_FILE2 (*FileHeader
)) {
312 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &(*FileHeader
)->Name
));
314 FileLength
= FFS_FILE2_SIZE (*FileHeader
);
315 ASSERT (FileLength
> 0x00FFFFFF);
317 FileLength
= FFS_FILE_SIZE (*FileHeader
);
320 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
322 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
323 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)*FileHeader
+ FileOccupiedSize
);
326 FileOffset
= (UINT32
) ((UINT8
*)FfsFileHeader
- (UINT8
*)FwVolHeader
);
327 ASSERT (FileOffset
<= 0xFFFFFFFF);
329 while (FileOffset
< (FvLength
- sizeof (EFI_FFS_FILE_HEADER
))) {
331 // Get FileState which is the highest bit of the State
333 FileState
= GetFileState (ErasePolarity
, FfsFileHeader
);
336 case EFI_FILE_HEADER_CONSTRUCTION
:
337 case EFI_FILE_HEADER_INVALID
:
338 if (IS_FFS_FILE2 (FfsFileHeader
)) {
340 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
342 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER2
);
343 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
345 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER
);
346 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
350 case EFI_FILE_DATA_VALID
:
351 case EFI_FILE_MARKED_FOR_UPDATE
:
352 if (CalculateHeaderChecksum (FfsFileHeader
) != 0) {
355 return EFI_NOT_FOUND
;
358 if (IS_FFS_FILE2 (FfsFileHeader
)) {
359 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
360 ASSERT (FileLength
> 0x00FFFFFF);
361 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
363 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
364 FileOffset
+= FileOccupiedSize
;
365 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ FileOccupiedSize
);
369 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
370 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
373 DataCheckSum
= FFS_FIXED_CHECKSUM
;
374 if ((FfsFileHeader
->Attributes
& FFS_ATTRIB_CHECKSUM
) == FFS_ATTRIB_CHECKSUM
) {
375 if (IS_FFS_FILE2 (FfsFileHeader
)) {
376 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
), FileLength
- sizeof(EFI_FFS_FILE_HEADER2
));
378 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
), FileLength
- sizeof(EFI_FFS_FILE_HEADER
));
381 if (FfsFileHeader
->IntegrityCheck
.Checksum
.File
!= DataCheckSum
) {
384 return EFI_NOT_FOUND
;
387 if (FileName
!= NULL
) {
388 if (CompareGuid (&FfsFileHeader
->Name
, (EFI_GUID
*)FileName
)) {
389 *FileHeader
= FfsFileHeader
;
392 } else if (SearchType
== PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
) {
393 if ((FfsFileHeader
->Type
== EFI_FV_FILETYPE_PEIM
) ||
394 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
) ||
395 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
397 *FileHeader
= FfsFileHeader
;
399 } else if (AprioriFile
!= NULL
) {
400 if (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
401 if (CompareGuid (&FfsFileHeader
->Name
, &gPeiAprioriFileNameGuid
)) {
402 *AprioriFile
= FfsFileHeader
;
406 } else if (((SearchType
== FfsFileHeader
->Type
) || (SearchType
== EFI_FV_FILETYPE_ALL
)) &&
407 (FfsFileHeader
->Type
!= EFI_FV_FILETYPE_FFS_PAD
)) {
408 *FileHeader
= FfsFileHeader
;
412 FileOffset
+= FileOccupiedSize
;
413 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
416 case EFI_FILE_DELETED
:
417 if (IS_FFS_FILE2 (FfsFileHeader
)) {
419 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
421 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
422 ASSERT (FileLength
> 0x00FFFFFF);
424 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
426 FileOccupiedSize
= GET_OCCUPIED_SIZE(FileLength
, 8);
427 FileOffset
+= FileOccupiedSize
;
428 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
433 return EFI_NOT_FOUND
;
438 return EFI_NOT_FOUND
;
442 Initialize PeiCore Fv List.
444 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
445 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
449 IN PEI_CORE_INSTANCE
*PrivateData
,
450 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
454 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
455 EFI_PEI_FV_HANDLE FvHandle
;
456 EFI_FIRMWARE_VOLUME_HEADER
*BfvHeader
;
459 // Install FV_PPI for FFS2 file system.
461 PeiServicesInstallPpi (&mPeiFfs2FvPpiList
);
464 // Install FV_PPI for FFS3 file system.
466 PeiServicesInstallPpi (&mPeiFfs3FvPpiList
);
468 BfvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
471 // The FV_PPI in BFV's format should be installed.
473 Status
= PeiServicesLocatePpi (
474 &BfvHeader
->FileSystemGuid
,
479 ASSERT_EFI_ERROR (Status
);
484 FvPpi
->ProcessVolume (
486 SecCoreData
->BootFirmwareVolumeBase
,
487 (UINTN
)BfvHeader
->FvLength
,
492 // Update internal PEI_CORE_FV array.
494 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= BfvHeader
;
495 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
496 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
497 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= 0;
500 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
501 (UINT32
) PrivateData
->FvCount
,
506 PrivateData
->FvCount
++;
509 // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose
510 // additional Fvs to PeiCore.
512 Status
= PeiServicesNotifyPpi (mNotifyOnFvInfoList
);
513 ASSERT_EFI_ERROR (Status
);
518 Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.
519 The FV Info will be registered into PeiCore private data structure.
520 And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.
522 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
523 @param NotifyDescriptor Address of the notification descriptor data structure.
524 @param Ppi Address of the PPI that was installed.
526 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
527 @return if not EFI_SUCESS, fail to verify FV.
532 FirmwareVolmeInfoPpiNotifyCallback (
533 IN EFI_PEI_SERVICES
**PeiServices
,
534 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
538 EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI FvInfo2Ppi
;
539 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
540 PEI_CORE_INSTANCE
*PrivateData
;
542 EFI_PEI_FV_HANDLE FvHandle
;
544 EFI_PEI_FILE_HANDLE FileHandle
;
548 Status
= EFI_SUCCESS
;
549 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
551 if (CompareGuid (NotifyDescriptor
->Guid
, &gEfiPeiFirmwareVolumeInfo2PpiGuid
)) {
555 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
));
561 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
562 FvInfo2Ppi
.AuthenticationStatus
= 0;
567 // Locate the corresponding FV_PPI according to founded FV's format guid
569 Status
= PeiServicesLocatePpi (
570 &FvInfo2Ppi
.FvFormat
,
575 if (!EFI_ERROR (Status
)) {
577 // Process new found FV and get FV handle.
579 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo2Ppi
.FvInfo
, FvInfo2Ppi
.FvInfoSize
, &FvHandle
);
580 if (EFI_ERROR (Status
)) {
581 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!\n"));
586 // Check whether the FV has already been processed.
588 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
589 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
590 if (IsFvInfo2
&& (FvInfo2Ppi
.AuthenticationStatus
!= PrivateData
->Fv
[FvIndex
].AuthenticationStatus
)) {
591 PrivateData
->Fv
[FvIndex
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
592 DEBUG ((EFI_D_INFO
, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex
, FvInfo2Ppi
.AuthenticationStatus
));
594 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo2Ppi
.FvInfo
));
599 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
600 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
601 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
606 // Update internal PEI_CORE_FV array.
608 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
;
609 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
610 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
611 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
614 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
615 (UINT32
) PrivateData
->FvCount
,
616 (VOID
*) FvInfo2Ppi
.FvInfo
,
617 FvInfo2Ppi
.FvInfoSize
,
620 PrivateData
->FvCount
++;
623 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
627 Status
= FvPpi
->FindFileByType (
629 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
633 if (!EFI_ERROR (Status
)) {
634 Status
= FvPpi
->FindSectionByType (
636 EFI_SECTION_PEI_DEPEX
,
640 if (!EFI_ERROR (Status
)) {
641 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
643 // Dependency is not satisfied.
649 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
650 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
652 } while (FileHandle
!= NULL
);
654 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi
.FvInfo
));
656 AddUnknownFormatFvInfo (PrivateData
, &FvInfo2Ppi
);
663 Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.
665 @param GuidedSectionGuid The Guided Section GUID.
666 @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi
667 for the Guided Section.
669 @return TRUE The GuidedSectionGuid could be identified, and the pointer to
670 the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.
671 @return FALSE The GuidedSectionGuid could not be identified, or
672 the Guided Section Extraction Ppi has not been installed yet.
676 VerifyGuidedSectionGuid (
677 IN EFI_GUID
*GuidedSectionGuid
,
678 OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
**GuidedSectionExtraction
681 EFI_PEI_HOB_POINTERS Hob
;
682 EFI_GUID
*GuidRecorded
;
687 // Check if there is the Guided Section GUID HOB recorded the GUID itself.
689 Hob
.Raw
= GetFirstGuidHob (GuidedSectionGuid
);
690 if (Hob
.Raw
!= NULL
) {
691 GuidRecorded
= (EFI_GUID
*) GET_GUID_HOB_DATA (Hob
);
692 if (CompareGuid (GuidRecorded
, GuidedSectionGuid
)) {
694 // Found the recorded GuidedSectionGuid.
696 Status
= PeiServicesLocatePpi (GuidedSectionGuid
, 0, NULL
, (VOID
**) &Interface
);
697 if (!EFI_ERROR (Status
) && Interface
!= NULL
) {
699 // Found the supported Guided Section Extraction Ppi for the Guided Section.
701 *GuidedSectionExtraction
= (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*) Interface
;
712 Go through the file to search SectionType section.
713 Search within encapsulation sections (compression and GUIDed) recursively,
714 until the match section is found.
716 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
717 @param SectionType Filter to find only section of this type.
718 @param SectionInstance Pointer to the filter to find the specific instance of section.
719 @param Section From where to search.
720 @param SectionSize The file size to search.
721 @param OutputBuffer A pointer to the discovered section, if successful.
722 NULL if section not found
723 @param AuthenticationStatus Updated upon return to point to the authentication status for this section.
724 @param IsFfs3Fv Indicates the FV format.
726 @return EFI_NOT_FOUND The match section is not found.
727 @return EFI_SUCCESS The match section is found.
732 IN CONST EFI_PEI_SERVICES
**PeiServices
,
733 IN EFI_SECTION_TYPE SectionType
,
734 IN OUT UINTN
*SectionInstance
,
735 IN EFI_COMMON_SECTION_HEADER
*Section
,
736 IN UINTN SectionSize
,
737 OUT VOID
**OutputBuffer
,
738 OUT UINT32
*AuthenticationStatus
,
743 UINT32 SectionLength
;
745 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
746 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
750 UINT32 Authentication
;
751 PEI_CORE_INSTANCE
*PrivateData
;
752 EFI_GUID
*SectionDefinitionGuid
;
753 BOOLEAN SectionCached
;
754 VOID
*TempOutputBuffer
;
755 UINT32 TempAuthenticationStatus
;
756 UINT16 GuidedSectionAttributes
;
758 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
759 *OutputBuffer
= NULL
;
762 Status
= EFI_NOT_FOUND
;
765 while (ParsedLength
< SectionSize
) {
767 if (IS_SECTION2 (Section
)) {
768 ASSERT (SECTION2_SIZE (Section
) > 0x00FFFFFF);
770 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
771 SectionLength
= SECTION2_SIZE (Section
);
773 // SectionLength is adjusted it is 4 byte aligned.
774 // Go to the next section
776 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
777 ASSERT (SectionLength
!= 0);
778 ParsedLength
+= SectionLength
;
779 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ SectionLength
);
784 if (Section
->Type
== SectionType
) {
786 // The type matches, so check the instance count to see if it's the one we want.
788 (*SectionInstance
)--;
789 if (*SectionInstance
== 0) {
793 if (IS_SECTION2 (Section
)) {
794 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
796 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
800 if (IS_SECTION2 (Section
)) {
801 SectionLength
= SECTION2_SIZE (Section
);
803 SectionLength
= SECTION_SIZE (Section
);
806 // SectionLength is adjusted it is 4 byte aligned.
807 // Go to the next section
809 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
810 ASSERT (SectionLength
!= 0);
811 ParsedLength
+= SectionLength
;
812 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
815 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
817 // Check the encapsulated section is extracted into the cache data.
819 SectionCached
= FALSE
;
820 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
821 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
822 SectionCached
= TRUE
;
823 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
824 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
825 Authentication
= PrivateData
->CacheSection
.AuthenticationStatus
[Index
];
827 // Search section directly from the cache data.
829 TempAuthenticationStatus
= 0;
830 Status
= ProcessSection (
837 &TempAuthenticationStatus
,
840 if (!EFI_ERROR (Status
)) {
841 *OutputBuffer
= TempOutputBuffer
;
842 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
849 // If SectionCached is TRUE, the section data has been cached and scanned.
851 if (!SectionCached
) {
852 Status
= EFI_NOT_FOUND
;
854 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
855 if (IS_SECTION2 (Section
)) {
856 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION2
*)Section
)->SectionDefinitionGuid
;
857 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION2
*)Section
)->Attributes
;
859 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
;
860 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION
*)Section
)->Attributes
;
862 if (VerifyGuidedSectionGuid (SectionDefinitionGuid
, &GuidSectionPpi
)) {
863 Status
= GuidSectionPpi
->ExtractSection (
870 } else if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) == 0) {
872 // Figure out the proper authentication status for GUIDED section without processing required
874 Status
= EFI_SUCCESS
;
875 if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) {
876 Authentication
|= EFI_AUTH_STATUS_IMAGE_SIGNED
| EFI_AUTH_STATUS_NOT_TESTED
;
878 if (IS_SECTION2 (Section
)) {
879 PpiOutputSize
= SECTION2_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
880 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
882 PpiOutputSize
= SECTION_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
883 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
886 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
887 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
888 if (!EFI_ERROR (Status
)) {
889 Status
= DecompressPpi
->Decompress (
891 (CONST EFI_COMPRESSION_SECTION
*) Section
,
898 if (!EFI_ERROR (Status
)) {
900 // Update cache section data.
902 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
903 PrivateData
->CacheSection
.AllSectionCount
++;
905 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
906 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
907 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
908 PrivateData
->CacheSection
.AuthenticationStatus
[PrivateData
->CacheSection
.SectionIndex
] = Authentication
;
909 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
911 TempAuthenticationStatus
= 0;
912 Status
= ProcessSection (
919 &TempAuthenticationStatus
,
922 if (!EFI_ERROR (Status
)) {
923 *OutputBuffer
= TempOutputBuffer
;
924 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
931 if (IS_SECTION2 (Section
)) {
932 SectionLength
= SECTION2_SIZE (Section
);
934 SectionLength
= SECTION_SIZE (Section
);
937 // SectionLength is adjusted it is 4 byte aligned.
938 // Go to the next section
940 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
941 ASSERT (SectionLength
!= 0);
942 ParsedLength
+= SectionLength
;
943 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
946 return EFI_NOT_FOUND
;
951 Searches for the next matching section within the specified file.
953 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
954 @param SectionType Filter to find only sections of this type.
955 @param FileHandle Pointer to the current file to search.
956 @param SectionData A pointer to the discovered section, if successful.
957 NULL if section not found
959 @retval EFI_NOT_FOUND The section was not found.
960 @retval EFI_SUCCESS The section was found.
965 PeiFfsFindSectionData (
966 IN CONST EFI_PEI_SERVICES
**PeiServices
,
967 IN EFI_SECTION_TYPE SectionType
,
968 IN EFI_PEI_FILE_HANDLE FileHandle
,
969 OUT VOID
**SectionData
972 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
974 CoreFvHandle
= FileHandleToVolume (FileHandle
);
975 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
976 return EFI_NOT_FOUND
;
979 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
983 Searches for the next matching section within the specified file.
985 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
986 @param SectionType The value of the section type to find.
987 @param SectionInstance Section instance to find.
988 @param FileHandle Handle of the firmware file to search.
989 @param SectionData A pointer to the discovered section, if successful.
990 @param AuthenticationStatus A pointer to the authentication status for this section.
992 @retval EFI_SUCCESS The section was found.
993 @retval EFI_NOT_FOUND The section was not found.
998 PeiFfsFindSectionData3 (
999 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1000 IN EFI_SECTION_TYPE SectionType
,
1001 IN UINTN SectionInstance
,
1002 IN EFI_PEI_FILE_HANDLE FileHandle
,
1003 OUT VOID
**SectionData
,
1004 OUT UINT32
*AuthenticationStatus
1007 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1009 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1010 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1011 return EFI_NOT_FOUND
;
1014 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1015 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1016 return CoreFvHandle
->FvPpi
->FindSectionByType2 (CoreFvHandle
->FvPpi
, SectionType
, SectionInstance
, FileHandle
, SectionData
, AuthenticationStatus
);
1019 // The old FvPpi doesn't support to find section by section instance
1020 // and return authentication status, so return EFI_UNSUPPORTED.
1022 return EFI_UNSUPPORTED
;
1026 Searches for the next matching file in the firmware volume.
1028 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1029 @param SearchType Filter to find only files of this type.
1030 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
1031 @param FvHandle Handle of firmware volume in which to search.
1032 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
1033 at the beginning of the firmware volume. On exit, points the file handle of the next file
1034 in the volume or NULL if there are no more files.
1036 @retval EFI_NOT_FOUND The file was not found.
1037 @retval EFI_NOT_FOUND The header checksum was not zero.
1038 @retval EFI_SUCCESS The file was found.
1043 PeiFfsFindNextFile (
1044 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1045 IN UINT8 SearchType
,
1046 IN EFI_PEI_FV_HANDLE FvHandle
,
1047 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1050 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1052 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
1055 // To make backward compatiblity, if can not find corresponding the handle of FV
1056 // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed
1057 // to the address of first byte of FV.
1059 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1060 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1063 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
1064 return EFI_NOT_FOUND
;
1067 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
1072 Search the firmware volumes by index
1074 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1075 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
1077 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
1079 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
1080 @retval EFI_NOT_FOUND The volume was not found.
1081 @retval EFI_SUCCESS The volume was found.
1086 PeiFfsFindNextVolume (
1087 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1089 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
1092 PEI_CORE_INSTANCE
*Private
;
1093 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1095 if (VolumeHandle
== NULL
) {
1096 return EFI_INVALID_PARAMETER
;
1099 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1101 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
1102 if (CoreFvHandle
== NULL
) {
1103 *VolumeHandle
= NULL
;
1104 return EFI_NOT_FOUND
;
1107 *VolumeHandle
= CoreFvHandle
->FvHandle
;
1114 Find a file within a volume by its name.
1116 @param FileName A pointer to the name of the file to find within the firmware volume.
1117 @param VolumeHandle The firmware volume to search
1118 @param FileHandle Upon exit, points to the found file's handle
1119 or NULL if it could not be found.
1121 @retval EFI_SUCCESS File was found.
1122 @retval EFI_NOT_FOUND File was not found.
1123 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
1128 PeiFfsFindFileByName (
1129 IN CONST EFI_GUID
*FileName
,
1130 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1131 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1134 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1136 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1137 return EFI_INVALID_PARAMETER
;
1140 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
1141 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1142 return EFI_NOT_FOUND
;
1145 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
1149 Returns information about a specific file.
1151 @param FileHandle Handle of the file.
1152 @param FileInfo Upon exit, points to the file's information.
1154 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1155 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1156 @retval EFI_SUCCESS File information returned.
1162 IN EFI_PEI_FILE_HANDLE FileHandle
,
1163 OUT EFI_FV_FILE_INFO
*FileInfo
1166 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1168 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1169 return EFI_INVALID_PARAMETER
;
1173 // Retrieve the FirmwareVolume which the file resides in.
1175 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1176 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1177 return EFI_INVALID_PARAMETER
;
1180 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1184 Returns information about a specific file.
1186 @param FileHandle Handle of the file.
1187 @param FileInfo Upon exit, points to the file's information.
1189 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1190 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1191 @retval EFI_SUCCESS File information returned.
1196 PeiFfsGetFileInfo2 (
1197 IN EFI_PEI_FILE_HANDLE FileHandle
,
1198 OUT EFI_FV_FILE_INFO2
*FileInfo
1201 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1203 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1204 return EFI_INVALID_PARAMETER
;
1208 // Retrieve the FirmwareVolume which the file resides in.
1210 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1211 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1212 return EFI_INVALID_PARAMETER
;
1215 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1216 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1217 return CoreFvHandle
->FvPpi
->GetFileInfo2 (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1220 // The old FvPpi doesn't support to return file info with authentication status,
1221 // so return EFI_UNSUPPORTED.
1223 return EFI_UNSUPPORTED
;
1227 Returns information about the specified volume.
1229 This function returns information about a specific firmware
1230 volume, including its name, type, attributes, starting address
1233 @param VolumeHandle Handle of the volume.
1234 @param VolumeInfo Upon exit, points to the volume's information.
1236 @retval EFI_SUCCESS Volume information returned.
1237 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
1238 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
1239 @retval EFI_SUCCESS Information successfully returned.
1240 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
1245 PeiFfsGetVolumeInfo (
1246 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1247 OUT EFI_FV_INFO
*VolumeInfo
1250 PEI_CORE_FV_HANDLE
*CoreHandle
;
1252 if ((VolumeInfo
== NULL
) || (VolumeHandle
== NULL
)) {
1253 return EFI_INVALID_PARAMETER
;
1256 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
1258 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
1259 return EFI_INVALID_PARAMETER
;
1262 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
1266 Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.
1268 @param PrivateData PeiCore's private data structure
1269 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
1270 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
1272 @retval EFI_NOT_FOUND FV image can't be found.
1273 @retval EFI_SUCCESS Successfully to process it.
1274 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
1275 @retval EFI_SECURITY_VIOLATION Image is illegal
1276 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
1281 IN PEI_CORE_INSTANCE
*PrivateData
,
1282 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
1283 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
1287 EFI_FV_INFO ParentFvImageInfo
;
1290 EFI_PEI_HOB_POINTERS HobPtr
;
1291 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
1292 EFI_PEI_FV_HANDLE ParentFvHandle
;
1293 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
1294 EFI_FV_FILE_INFO FileInfo
;
1296 UINT32 AuthenticationStatus
;
1299 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1302 HobPtr
.Raw
= GetHobList ();
1303 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
1304 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
1306 // this FILE has been dispatched, it will not be dispatched again.
1308 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
1311 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
1314 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
1315 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
1318 // Find FvImage in FvFile
1320 AuthenticationStatus
= 0;
1321 if ((ParentFvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1322 (ParentFvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1323 Status
= ParentFvPpi
->FindSectionByType2 (
1325 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1329 &AuthenticationStatus
1332 Status
= ParentFvPpi
->FindSectionByType (
1334 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1339 if (EFI_ERROR (Status
)) {
1343 Status
= VerifyPeim (PrivateData
, ParentFvHandle
, ParentFvFileHandle
, AuthenticationStatus
);
1344 if (Status
== EFI_SECURITY_VIOLATION
) {
1349 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
1350 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
1351 // its initial linked location and maintain its alignment.
1353 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
1355 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
1357 FvAlignment
= 1 << ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ALIGNMENT
) >> 16);
1358 if (FvAlignment
< 8) {
1365 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
1366 FvLength
= ReadUnaligned64 (&FvHeader
->FvLength
);
1367 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvLength
), FvAlignment
);
1368 if (NewFvBuffer
== NULL
) {
1369 return EFI_OUT_OF_RESOURCES
;
1371 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvLength
);
1372 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
1376 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
1377 ASSERT_EFI_ERROR (Status
);
1379 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
1380 ASSERT_EFI_ERROR (Status
);
1383 // Install FvInfo(2) Ppi
1385 PeiServicesInstallFvInfoPpi (
1386 &FvHeader
->FileSystemGuid
,
1388 (UINT32
) FvHeader
->FvLength
,
1389 &ParentFvImageInfo
.FvName
,
1393 PeiServicesInstallFvInfo2Ppi (
1394 &FvHeader
->FileSystemGuid
,
1396 (UINT32
) FvHeader
->FvLength
,
1397 &ParentFvImageInfo
.FvName
,
1399 AuthenticationStatus
1403 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
1406 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1411 // Makes the encapsulated volume show up in DXE phase to skip processing of
1412 // encapsulated file again.
1415 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1417 &ParentFvImageInfo
.FvName
,
1425 Process a firmware volume and create a volume handle.
1427 Create a volume handle from the information in the buffer. For
1428 memory-mapped firmware volumes, Buffer and BufferSize refer to
1429 the start of the firmware volume and the firmware volume size.
1430 For non memory-mapped firmware volumes, this points to a
1431 buffer which contains the necessary information for creating
1432 the firmware volume handle. Normally, these values are derived
1433 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
1436 @param This Points to this instance of the
1437 EFI_PEI_FIRMWARE_VOLUME_PPI.
1438 @param Buffer Points to the start of the buffer.
1439 @param BufferSize Size of the buffer.
1440 @param FvHandle Points to the returned firmware volume
1441 handle. The firmware volume handle must
1442 be unique within the system.
1444 @retval EFI_SUCCESS Firmware volume handle created.
1445 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
1450 PeiFfsFvPpiProcessVolume (
1451 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1453 IN UINTN BufferSize
,
1454 OUT EFI_PEI_FV_HANDLE
*FvHandle
1459 ASSERT (FvHandle
!= NULL
);
1461 if (Buffer
== NULL
) {
1462 return EFI_VOLUME_CORRUPTED
;
1466 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped
1467 // FV image and the handle is pointed to Fv image's buffer.
1469 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
1472 // Do verify for given FV buffer.
1474 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1475 if (EFI_ERROR(Status
)) {
1476 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1477 return EFI_VOLUME_CORRUPTED
;
1484 Finds the next file of the specified type.
1486 This service enables PEI modules to discover additional firmware files.
1487 The FileHandle must be unique within the system.
1489 @param This Points to this instance of the
1490 EFI_PEI_FIRMWARE_VOLUME_PPI.
1491 @param SearchType A filter to find only files of this type. Type
1492 EFI_FV_FILETYPE_ALL causes no filtering to be
1494 @param FvHandle Handle of firmware volume in which to
1496 @param FileHandle Points to the current handle from which to
1497 begin searching or NULL to start at the
1498 beginning of the firmware volume. Updated
1499 upon return to reflect the file found.
1501 @retval EFI_SUCCESS The file was found.
1502 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1507 PeiFfsFvPpiFindFileByType (
1508 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1509 IN EFI_FV_FILETYPE SearchType
,
1510 IN EFI_PEI_FV_HANDLE FvHandle
,
1511 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1514 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1518 Find a file within a volume by its name.
1520 This service searches for files with a specific name, within
1521 either the specified firmware volume or all firmware volumes.
1523 @param This Points to this instance of the
1524 EFI_PEI_FIRMWARE_VOLUME_PPI.
1525 @param FileName A pointer to the name of the file to find
1526 within the firmware volume.
1527 @param FvHandle Upon entry, the pointer to the firmware
1528 volume to search or NULL if all firmware
1529 volumes should be searched. Upon exit, the
1530 actual firmware volume in which the file was
1532 @param FileHandle Upon exit, points to the found file's
1533 handle or NULL if it could not be found.
1535 @retval EFI_SUCCESS File was found.
1536 @retval EFI_NOT_FOUND File was not found.
1537 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1544 PeiFfsFvPpiFindFileByName (
1545 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1546 IN CONST EFI_GUID
*FileName
,
1547 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1548 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1552 PEI_CORE_INSTANCE
*PrivateData
;
1555 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1556 return EFI_INVALID_PARAMETER
;
1559 if (*FvHandle
!= NULL
) {
1560 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1561 if (Status
== EFI_NOT_FOUND
) {
1566 // If *FvHandle = NULL, so search all FV for given filename
1568 Status
= EFI_NOT_FOUND
;
1570 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1571 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1573 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1575 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1576 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1577 if (!EFI_ERROR (Status
)) {
1578 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1589 Returns information about a specific file.
1591 This function returns information about a specific
1592 file, including its file name, type, attributes, starting
1595 @param This Points to this instance of the
1596 EFI_PEI_FIRMWARE_VOLUME_PPI.
1597 @param FileHandle Handle of the file.
1598 @param FileInfo Upon exit, points to the file's
1601 @retval EFI_SUCCESS File information returned.
1602 @retval EFI_INVALID_PARAMETER If FileHandle does not
1603 represent a valid file.
1604 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1609 PeiFfsFvPpiGetFileInfo (
1610 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1611 IN EFI_PEI_FILE_HANDLE FileHandle
,
1612 OUT EFI_FV_FILE_INFO
*FileInfo
1616 UINT8 ErasePolarity
;
1617 EFI_FFS_FILE_HEADER
*FileHeader
;
1618 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1619 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1621 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1622 return EFI_INVALID_PARAMETER
;
1626 // Retrieve the FirmwareVolume which the file resides in.
1628 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1629 if (CoreFvHandle
== NULL
) {
1630 return EFI_INVALID_PARAMETER
;
1633 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1635 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
1642 // Get FileState which is the highest bit of the State
1644 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1646 switch (FileState
) {
1647 case EFI_FILE_DATA_VALID
:
1648 case EFI_FILE_MARKED_FOR_UPDATE
:
1651 return EFI_INVALID_PARAMETER
;
1654 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1655 if (IS_FFS_FILE2 (FileHeader
)) {
1656 ASSERT (FFS_FILE2_SIZE (FileHeader
) > 0x00FFFFFF);
1657 if (!FwVolInstance
->IsFfs3Fv
) {
1658 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader
->Name
));
1659 return EFI_INVALID_PARAMETER
;
1661 FileInfo
->BufferSize
= FFS_FILE2_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1662 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
);
1664 FileInfo
->BufferSize
= FFS_FILE_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1665 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER
);
1667 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1668 FileInfo
->FileType
= FileHeader
->Type
;
1669 FileInfo
->FileAttributes
= FfsAttributes2FvFileAttributes (FileHeader
->Attributes
);
1670 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_MEMORY_MAPPED
) == EFI_FVB2_MEMORY_MAPPED
) {
1671 FileInfo
->FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
1677 Returns information about a specific file.
1679 This function returns information about a specific
1680 file, including its file name, type, attributes, starting
1681 address, size and authentication status.
1683 @param This Points to this instance of the
1684 EFI_PEI_FIRMWARE_VOLUME_PPI.
1685 @param FileHandle Handle of the file.
1686 @param FileInfo Upon exit, points to the file's
1689 @retval EFI_SUCCESS File information returned.
1690 @retval EFI_INVALID_PARAMETER If FileHandle does not
1691 represent a valid file.
1692 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1697 PeiFfsFvPpiGetFileInfo2 (
1698 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1699 IN EFI_PEI_FILE_HANDLE FileHandle
,
1700 OUT EFI_FV_FILE_INFO2
*FileInfo
1704 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1706 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1707 return EFI_INVALID_PARAMETER
;
1711 // Retrieve the FirmwareVolume which the file resides in.
1713 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1714 if (CoreFvHandle
== NULL
) {
1715 return EFI_INVALID_PARAMETER
;
1718 Status
= PeiFfsFvPpiGetFileInfo (This
, FileHandle
, (EFI_FV_FILE_INFO
*) FileInfo
);
1719 if (!EFI_ERROR (Status
)) {
1720 FileInfo
->AuthenticationStatus
= CoreFvHandle
->AuthenticationStatus
;
1727 This function returns information about the firmware volume.
1729 @param This Points to this instance of the
1730 EFI_PEI_FIRMWARE_VOLUME_PPI.
1731 @param FvHandle Handle to the firmware handle.
1732 @param VolumeInfo Points to the returned firmware volume
1735 @retval EFI_SUCCESS Information returned successfully.
1736 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1737 firmware volume or VolumeInfo is NULL.
1742 PeiFfsFvPpiGetVolumeInfo (
1743 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1744 IN EFI_PEI_FV_HANDLE FvHandle
,
1745 OUT EFI_FV_INFO
*VolumeInfo
1748 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1749 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1751 if ((VolumeInfo
== NULL
) || (FvHandle
== NULL
)) {
1752 return EFI_INVALID_PARAMETER
;
1756 // VolumeHandle may not align at 8 byte,
1757 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1758 // So, Copy FvHeader into the local FvHeader structure.
1760 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1763 // Check Fv Image Signature
1765 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1766 return EFI_INVALID_PARAMETER
;
1769 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1770 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1771 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1772 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1773 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1775 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1776 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1777 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1784 Find the next matching section in the firmware file.
1786 This service enables PEI modules to discover sections
1787 of a given type within a valid file.
1789 @param This Points to this instance of the
1790 EFI_PEI_FIRMWARE_VOLUME_PPI.
1791 @param SearchType A filter to find only sections of this
1793 @param FileHandle Handle of firmware file in which to
1795 @param SectionData Updated upon return to point to the
1798 @retval EFI_SUCCESS Section was found.
1799 @retval EFI_NOT_FOUND Section of the specified type was not
1800 found. SectionData contains NULL.
1804 PeiFfsFvPpiFindSectionByType (
1805 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1806 IN EFI_SECTION_TYPE SearchType
,
1807 IN EFI_PEI_FILE_HANDLE FileHandle
,
1808 OUT VOID
**SectionData
1811 UINT32 AuthenticationStatus
;
1812 return PeiFfsFvPpiFindSectionByType2 (This
, SearchType
, 0, FileHandle
, SectionData
, &AuthenticationStatus
);
1816 Find the next matching section in the firmware file.
1818 This service enables PEI modules to discover sections
1819 of a given instance and type within a valid file.
1821 @param This Points to this instance of the
1822 EFI_PEI_FIRMWARE_VOLUME_PPI.
1823 @param SearchType A filter to find only sections of this
1825 @param SearchInstance A filter to find the specific instance
1827 @param FileHandle Handle of firmware file in which to
1829 @param SectionData Updated upon return to point to the
1831 @param AuthenticationStatus Updated upon return to point to the
1832 authentication status for this section.
1834 @retval EFI_SUCCESS Section was found.
1835 @retval EFI_NOT_FOUND Section of the specified type was not
1836 found. SectionData contains NULL.
1840 PeiFfsFvPpiFindSectionByType2 (
1841 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1842 IN EFI_SECTION_TYPE SearchType
,
1843 IN UINTN SearchInstance
,
1844 IN EFI_PEI_FILE_HANDLE FileHandle
,
1845 OUT VOID
**SectionData
,
1846 OUT UINT32
*AuthenticationStatus
1850 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
1852 EFI_COMMON_SECTION_HEADER
*Section
;
1853 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1854 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1856 UINT32 ExtractedAuthenticationStatus
;
1858 if (SectionData
== NULL
) {
1859 return EFI_NOT_FOUND
;
1862 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1865 // Retrieve the FirmwareVolume which the file resides in.
1867 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1868 if (CoreFvHandle
== NULL
) {
1869 return EFI_NOT_FOUND
;
1872 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
1874 if (IS_FFS_FILE2 (FfsFileHeader
)) {
1875 ASSERT (FFS_FILE2_SIZE (FfsFileHeader
) > 0x00FFFFFF);
1876 if (!FwVolInstance
->IsFfs3Fv
) {
1877 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
1878 return EFI_NOT_FOUND
;
1880 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
1881 FileSize
= FFS_FILE2_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1883 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
1884 FileSize
= FFS_FILE_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1887 Instance
= SearchInstance
+ 1;
1888 ExtractedAuthenticationStatus
= 0;
1889 Status
= ProcessSection (
1890 GetPeiServicesTablePointer (),
1896 &ExtractedAuthenticationStatus
,
1897 FwVolInstance
->IsFfs3Fv
1899 if (!EFI_ERROR (Status
)) {
1901 // Inherit the authentication status.
1903 *AuthenticationStatus
= ExtractedAuthenticationStatus
| CoreFvHandle
->AuthenticationStatus
;
1909 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
1911 @param FvHandle The handle of a FV.
1913 @retval NULL if can not find.
1914 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
1916 PEI_CORE_FV_HANDLE
*
1917 FvHandleToCoreHandle (
1918 IN EFI_PEI_FV_HANDLE FvHandle
1922 PEI_CORE_INSTANCE
*PrivateData
;
1924 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1925 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1926 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
1927 return &PrivateData
->Fv
[Index
];
1935 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
1937 This routine also will install FvInfo ppi for FV hob in PI ways.
1939 @param Private Pointer of PEI_CORE_INSTANCE
1940 @param Instance The index of FV want to be searched.
1942 @return Instance of PEI_CORE_FV_HANDLE.
1944 PEI_CORE_FV_HANDLE
*
1945 FindNextCoreFvHandle (
1946 IN PEI_CORE_INSTANCE
*Private
,
1952 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
1955 // Handle Framework FvHob and Install FvInfo Ppi for it.
1957 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1959 // Loop to search the wanted FirmwareVolume which supports FFS
1961 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
1962 while (FvHob
!= NULL
) {
1964 // Search whether FvHob has been installed into PeiCore's FV database.
1965 // If found, no need install new FvInfoPpi for it.
1967 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
1968 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
1975 // Search whether FvHob has been cached into PeiCore's Unknown FV database.
1976 // If found, no need install new FvInfoPpi for it.
1979 for (Index
= 0; Index
< Private
->UnknownFvInfoCount
; Index
++) {
1980 if ((UINTN
)FvHob
->BaseAddress
== (UINTN
)Private
->UnknownFvInfo
[Index
].FvInfo
) {
1988 // If the Fv in FvHob has not been installed into PeiCore's FV database and has
1989 // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi
1990 // for it then PeiCore will dispatch it in callback of FvInfoPpi.
1993 PeiServicesInstallFvInfoPpi (
1994 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
1995 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
1996 (UINT32
)FvHob
->Length
,
2002 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
2006 ASSERT (Private
->FvCount
<= PcdGet32 (PcdPeiCoreMaxFvSupported
));
2007 if (Instance
>= Private
->FvCount
) {
2011 return &Private
->Fv
[Instance
];
2015 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
2016 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
2017 PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant
2020 @param PrivateData Pointer to PEI_CORE_INSTANCE.
2024 IN PEI_CORE_INSTANCE
*PrivateData
2028 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
2033 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
2036 Status
= PeiServicesLocatePpi (
2037 &gEfiFirmwareFileSystem2Guid
,
2042 ASSERT_EFI_ERROR (Status
);
2045 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
2046 // which is shadowed from flash to permanent memory within PeiCore image.
2048 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
2049 ASSERT_EFI_ERROR (Status
);
2052 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2054 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2055 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2056 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FwVol
.Fv
;
2061 // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which
2064 Status
= PeiServicesLocatePpi (
2065 &gEfiFirmwareFileSystem3Guid
,
2070 ASSERT_EFI_ERROR (Status
);
2073 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3
2074 // which is shadowed from flash to permanent memory within PeiCore image.
2076 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs3FvPpiList
);
2077 ASSERT_EFI_ERROR (Status
);
2080 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2082 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2083 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2084 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs3FwVol
.Fv
;
2090 Report the information for a new discoveried FV in unknown third-party format.
2092 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but
2093 the FV in this format has been discoveried, then this FV's information will be cached into
2094 PEI_CORE_INSTANCE's UnknownFvInfo array.
2095 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI
2096 is installed later by platform's PEIM, the original unknown third-party FV will be processed by
2097 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2099 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2100 @param FvInfo2Ppi Point to FvInfo2 PPI.
2102 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
2103 @retval EFI_SUCCESS Success to add the information for unknown FV.
2106 AddUnknownFormatFvInfo (
2107 IN PEI_CORE_INSTANCE
*PrivateData
,
2108 IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
*FvInfo2Ppi
2111 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
2113 if (PrivateData
->UnknownFvInfoCount
+ 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2114 return EFI_OUT_OF_RESOURCES
;
2117 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
2118 PrivateData
->UnknownFvInfoCount
++;
2120 CopyGuid (&NewUnknownFv
->FvFormat
, &FvInfo2Ppi
->FvFormat
);
2121 NewUnknownFv
->FvInfo
= FvInfo2Ppi
->FvInfo
;
2122 NewUnknownFv
->FvInfoSize
= FvInfo2Ppi
->FvInfoSize
;
2123 NewUnknownFv
->AuthenticationStatus
= FvInfo2Ppi
->AuthenticationStatus
;
2124 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
2125 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
2126 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
2128 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
2133 Find the FV information according to third-party FV format guid.
2135 This routine also will remove the FV information found by given FV format guid from
2136 PrivateData->UnknownFvInfo[].
2138 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2139 @param Format Point to given FV format guid
2140 @param FvInfo On return, the pointer of FV information buffer
2141 @param FvInfoSize On return, the size of FV information buffer.
2142 @param AuthenticationStatus On return, the authentication status of FV information buffer.
2144 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
2145 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2148 FindUnknownFormatFvInfo (
2149 IN PEI_CORE_INSTANCE
*PrivateData
,
2150 IN EFI_GUID
*Format
,
2152 OUT UINT32
*FvInfoSize
,
2153 OUT UINT32
*AuthenticationStatus
2160 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
2161 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
2166 if (Index
== PrivateData
->UnknownFvInfoCount
) {
2167 return EFI_NOT_FOUND
;
2170 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
2171 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
2172 *AuthenticationStatus
= PrivateData
->UnknownFvInfo
[Index
].AuthenticationStatus
;
2175 // Remove an entry from UnknownFvInfo array.
2178 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
2179 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
2181 PrivateData
->UnknownFvInfoCount
--;
2186 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
2188 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
2189 routine is called to process all discoveried FVs in this format.
2191 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
2192 @param NotifyDescriptor Address of the notification descriptor data structure.
2193 @param Ppi Address of the PPI that was installed.
2195 @retval EFI_SUCCESS The notification callback is processed correctly.
2199 ThirdPartyFvPpiNotifyCallback (
2200 IN EFI_PEI_SERVICES
**PeiServices
,
2201 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
2205 PEI_CORE_INSTANCE
*PrivateData
;
2206 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
2209 UINT32 AuthenticationStatus
;
2211 EFI_PEI_FV_HANDLE FvHandle
;
2212 BOOLEAN IsProcessed
;
2214 EFI_PEI_FILE_HANDLE FileHandle
;
2217 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
2218 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
2221 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
, &AuthenticationStatus
);
2222 if (EFI_ERROR (Status
)) {
2227 // Process new found FV and get FV handle.
2229 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
2230 if (EFI_ERROR (Status
)) {
2231 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
2236 // Check whether the FV has already been processed.
2238 IsProcessed
= FALSE
;
2239 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
2240 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
2241 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo
));
2251 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2252 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
2253 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
2258 // Update internal PEI_CORE_FV array.
2260 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
2261 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
2262 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
2263 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= AuthenticationStatus
;
2266 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
2267 (UINT32
) PrivateData
->FvCount
,
2272 PrivateData
->FvCount
++;
2275 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
2279 Status
= FvPpi
->FindFileByType (
2281 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
2285 if (!EFI_ERROR (Status
)) {
2286 Status
= FvPpi
->FindSectionByType (
2288 EFI_SECTION_PEI_DEPEX
,
2292 if (!EFI_ERROR (Status
)) {
2293 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
2295 // Dependency is not satisfied.
2301 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
2302 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
2304 } while (FileHandle
!= NULL
);