2 Pei Core Firmware File System service routines.
4 Copyright (c) 2015 HP Development Company, L.P.
5 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList
[] = {
14 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
15 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
16 FirmwareVolmeInfoPpiNotifyCallback
19 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
20 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
21 FirmwareVolmeInfoPpiNotifyCallback
25 PEI_FW_VOL_INSTANCE mPeiFfs2FwVol
= {
29 PeiFfsFvPpiProcessVolume
,
30 PeiFfsFvPpiFindFileByType
,
31 PeiFfsFvPpiFindFileByName
,
32 PeiFfsFvPpiGetFileInfo
,
33 PeiFfsFvPpiGetVolumeInfo
,
34 PeiFfsFvPpiFindSectionByType
,
35 PeiFfsFvPpiGetFileInfo2
,
36 PeiFfsFvPpiFindSectionByType2
,
37 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
38 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
42 PEI_FW_VOL_INSTANCE mPeiFfs3FwVol
= {
46 PeiFfsFvPpiProcessVolume
,
47 PeiFfsFvPpiFindFileByType
,
48 PeiFfsFvPpiFindFileByName
,
49 PeiFfsFvPpiGetFileInfo
,
50 PeiFfsFvPpiGetVolumeInfo
,
51 PeiFfsFvPpiFindSectionByType
,
52 PeiFfsFvPpiGetFileInfo2
,
53 PeiFfsFvPpiFindSectionByType2
,
54 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
55 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
59 EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList
= {
60 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
61 &gEfiFirmwareFileSystem2Guid
,
65 EFI_PEI_PPI_DESCRIPTOR mPeiFfs3FvPpiList
= {
66 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
67 &gEfiFirmwareFileSystem3Guid
,
72 Required Alignment Alignment Value in FFS FFS_ATTRIB_DATA_ALIGNMENT2 Alignment Value in
73 (bytes) Attributes Field in FFS Attributes Field Firmware Volume Interfaces
91 UINT8 mFvAttributes
[] = {0, 4, 7, 9, 10, 12, 15, 16};
92 UINT8 mFvAttributes2
[] = {17, 18, 19, 20, 21, 22, 23, 24};
95 Convert the FFS File Attributes to FV File Attributes
97 @param FfsAttributes The attributes of UINT8 type.
99 @return The attributes of EFI_FV_FILE_ATTRIBUTES
102 EFI_FV_FILE_ATTRIBUTES
103 FfsAttributes2FvFileAttributes (
104 IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
108 EFI_FV_FILE_ATTRIBUTES FileAttribute
;
110 DataAlignment
= (UINT8
) ((FfsAttributes
& FFS_ATTRIB_DATA_ALIGNMENT
) >> 3);
111 ASSERT (DataAlignment
< 8);
113 if ((FfsAttributes
& FFS_ATTRIB_DATA_ALIGNMENT_2
) != 0) {
114 FileAttribute
= (EFI_FV_FILE_ATTRIBUTES
) mFvAttributes2
[DataAlignment
];
116 FileAttribute
= (EFI_FV_FILE_ATTRIBUTES
) mFvAttributes
[DataAlignment
];
119 if ((FfsAttributes
& FFS_ATTRIB_FIXED
) == FFS_ATTRIB_FIXED
) {
120 FileAttribute
|= EFI_FV_FILE_ATTRIB_FIXED
;
123 return FileAttribute
;
127 Returns the file state set by the highest zero bit in the State field
129 @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
130 in the Attributes field.
131 @param FfsHeader Pointer to FFS File Header.
133 @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit
134 in the header State field.
138 IN UINT8 ErasePolarity
,
139 IN EFI_FFS_FILE_HEADER
*FfsHeader
142 EFI_FFS_FILE_STATE FileState
;
143 EFI_FFS_FILE_STATE HighestBit
;
145 FileState
= FfsHeader
->State
;
147 if (ErasePolarity
!= 0) {
148 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
152 // Get file state set by its highest none zero bit.
155 while (HighestBit
!= 0 && (HighestBit
& FileState
) == 0) {
163 Calculates the checksum of the header of a file.
165 @param FileHeader Pointer to FFS File Header.
167 @return Checksum of the header.
168 Zero means the header is good.
169 Non-zero means the header is bad.
172 CalculateHeaderChecksum (
173 IN EFI_FFS_FILE_HEADER
*FileHeader
176 EFI_FFS_FILE_HEADER2 TestFileHeader
;
178 if (IS_FFS_FILE2 (FileHeader
)) {
179 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
181 // Ingore State and File field in FFS header.
183 TestFileHeader
.State
= 0;
184 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
186 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
188 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
190 // Ingore State and File field in FFS header.
192 TestFileHeader
.State
= 0;
193 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
195 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
200 Find FV handler according to FileHandle in that FV.
202 @param FileHandle Handle of file image
204 @return Pointer to instance of PEI_CORE_FV_HANDLE.
208 IN EFI_PEI_FILE_HANDLE FileHandle
212 PEI_CORE_INSTANCE
*PrivateData
;
213 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
216 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
217 BestIndex
= PrivateData
->FvCount
;
220 // Find the best matched FV image that includes this FileHandle.
221 // FV may include the child FV, and they are in the same continuous space.
222 // If FileHandle is from the child FV, the updated logic can find its matched FV.
224 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
225 FwVolHeader
= PrivateData
->Fv
[Index
].FvHeader
;
226 if (((UINT64
) (UINTN
) FileHandle
> (UINT64
) (UINTN
) FwVolHeader
) && \
227 ((UINT64
) (UINTN
) FileHandle
<= ((UINT64
) (UINTN
) FwVolHeader
+ FwVolHeader
->FvLength
- 1))) {
228 if (BestIndex
== PrivateData
->FvCount
) {
231 if ((UINT64
) (UINTN
) PrivateData
->Fv
[BestIndex
].FvHeader
< (UINT64
) (UINTN
) FwVolHeader
) {
238 if (BestIndex
< PrivateData
->FvCount
) {
239 return &PrivateData
->Fv
[BestIndex
];
246 Given the input file pointer, search for the first matching file in the
247 FFS volume as defined by SearchType. The search starts from FileHeader inside
248 the Firmware Volume defined by FwVolHeader.
249 If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.
250 If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
251 the first PEIM, or COMBINED PEIM or FV file type FFS file will return.
253 @param FvHandle Pointer to the FV header of the volume to search
254 @param FileName File name
255 @param SearchType Filter to find only files of this type.
256 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
257 @param FileHandle This parameter must point to a valid FFS volume.
258 @param AprioriFile Pointer to AprioriFile image in this FV if has
260 @return EFI_NOT_FOUND No files matching the search criteria were found
261 @retval EFI_SUCCESS Success to search given file
266 IN CONST EFI_PEI_FV_HANDLE FvHandle
,
267 IN CONST EFI_GUID
*FileName
, OPTIONAL
268 IN EFI_FV_FILETYPE SearchType
,
269 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
,
270 IN OUT EFI_PEI_FILE_HANDLE
*AprioriFile OPTIONAL
273 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
274 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExtHeader
;
275 EFI_FFS_FILE_HEADER
**FileHeader
;
276 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
278 UINT32 FileOccupiedSize
;
287 // Convert the handle of FV to FV header for memory-mapped firmware volume
289 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvHandle
;
290 FileHeader
= (EFI_FFS_FILE_HEADER
**)FileHandle
;
292 IsFfs3Fv
= CompareGuid (&FwVolHeader
->FileSystemGuid
, &gEfiFirmwareFileSystem3Guid
);
294 FvLength
= FwVolHeader
->FvLength
;
295 if ((FwVolHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
302 // If FileHeader is not specified (NULL) or FileName is not NULL,
303 // start with the first file in the firmware volume. Otherwise,
304 // start from the FileHeader.
306 if ((*FileHeader
== NULL
) || (FileName
!= NULL
)) {
307 if (FwVolHeader
->ExtHeaderOffset
!= 0) {
309 // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
311 FwVolExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*) ((UINT8
*) FwVolHeader
+ FwVolHeader
->ExtHeaderOffset
);
312 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FwVolExtHeader
+ FwVolExtHeader
->ExtHeaderSize
);
314 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*) FwVolHeader
+ FwVolHeader
->HeaderLength
);
316 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ALIGN_POINTER (FfsFileHeader
, 8);
318 if (IS_FFS_FILE2 (*FileHeader
)) {
320 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &(*FileHeader
)->Name
));
322 FileLength
= FFS_FILE2_SIZE (*FileHeader
);
323 ASSERT (FileLength
> 0x00FFFFFF);
325 FileLength
= FFS_FILE_SIZE (*FileHeader
);
328 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
330 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
331 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)*FileHeader
+ FileOccupiedSize
);
334 FileOffset
= (UINT32
) ((UINT8
*)FfsFileHeader
- (UINT8
*)FwVolHeader
);
335 ASSERT (FileOffset
<= 0xFFFFFFFF);
337 while (FileOffset
< (FvLength
- sizeof (EFI_FFS_FILE_HEADER
))) {
339 // Get FileState which is the highest bit of the State
341 FileState
= GetFileState (ErasePolarity
, FfsFileHeader
);
344 case EFI_FILE_HEADER_CONSTRUCTION
:
345 case EFI_FILE_HEADER_INVALID
:
346 if (IS_FFS_FILE2 (FfsFileHeader
)) {
348 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
350 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER2
);
351 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
353 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER
);
354 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
358 case EFI_FILE_DATA_VALID
:
359 case EFI_FILE_MARKED_FOR_UPDATE
:
360 if (CalculateHeaderChecksum (FfsFileHeader
) != 0) {
363 return EFI_NOT_FOUND
;
366 if (IS_FFS_FILE2 (FfsFileHeader
)) {
367 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
368 ASSERT (FileLength
> 0x00FFFFFF);
369 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
371 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
372 FileOffset
+= FileOccupiedSize
;
373 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ FileOccupiedSize
);
377 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
378 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
381 DataCheckSum
= FFS_FIXED_CHECKSUM
;
382 if ((FfsFileHeader
->Attributes
& FFS_ATTRIB_CHECKSUM
) == FFS_ATTRIB_CHECKSUM
) {
383 if (IS_FFS_FILE2 (FfsFileHeader
)) {
384 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
), FileLength
- sizeof(EFI_FFS_FILE_HEADER2
));
386 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
), FileLength
- sizeof(EFI_FFS_FILE_HEADER
));
389 if (FfsFileHeader
->IntegrityCheck
.Checksum
.File
!= DataCheckSum
) {
392 return EFI_NOT_FOUND
;
395 if (FileName
!= NULL
) {
396 if (CompareGuid (&FfsFileHeader
->Name
, (EFI_GUID
*)FileName
)) {
397 *FileHeader
= FfsFileHeader
;
400 } else if (SearchType
== PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
) {
401 if ((FfsFileHeader
->Type
== EFI_FV_FILETYPE_PEIM
) ||
402 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
) ||
403 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
405 *FileHeader
= FfsFileHeader
;
407 } else if (AprioriFile
!= NULL
) {
408 if (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
409 if (CompareGuid (&FfsFileHeader
->Name
, &gPeiAprioriFileNameGuid
)) {
410 *AprioriFile
= FfsFileHeader
;
414 } else if (((SearchType
== FfsFileHeader
->Type
) || (SearchType
== EFI_FV_FILETYPE_ALL
)) &&
415 (FfsFileHeader
->Type
!= EFI_FV_FILETYPE_FFS_PAD
)) {
416 *FileHeader
= FfsFileHeader
;
420 FileOffset
+= FileOccupiedSize
;
421 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
424 case EFI_FILE_DELETED
:
425 if (IS_FFS_FILE2 (FfsFileHeader
)) {
427 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
429 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
430 ASSERT (FileLength
> 0x00FFFFFF);
432 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
434 FileOccupiedSize
= GET_OCCUPIED_SIZE(FileLength
, 8);
435 FileOffset
+= FileOccupiedSize
;
436 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
441 return EFI_NOT_FOUND
;
446 return EFI_NOT_FOUND
;
450 Initialize PeiCore Fv List.
452 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
453 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
457 IN PEI_CORE_INSTANCE
*PrivateData
,
458 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
462 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
463 EFI_PEI_FV_HANDLE FvHandle
;
464 EFI_FIRMWARE_VOLUME_HEADER
*BfvHeader
;
467 // Install FV_PPI for FFS2 file system.
469 PeiServicesInstallPpi (&mPeiFfs2FvPpiList
);
472 // Install FV_PPI for FFS3 file system.
474 PeiServicesInstallPpi (&mPeiFfs3FvPpiList
);
476 BfvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
479 // The FV_PPI in BFV's format should be installed.
481 Status
= PeiServicesLocatePpi (
482 &BfvHeader
->FileSystemGuid
,
487 ASSERT_EFI_ERROR (Status
);
492 Status
= FvPpi
->ProcessVolume (
494 SecCoreData
->BootFirmwareVolumeBase
,
495 (UINTN
)BfvHeader
->FvLength
,
498 ASSERT_EFI_ERROR (Status
);
500 PrivateData
->Fv
= AllocateZeroPool (sizeof (PEI_CORE_FV_HANDLE
) * FV_GROWTH_STEP
);
501 ASSERT (PrivateData
->Fv
!= NULL
);
502 PrivateData
->MaxFvCount
= FV_GROWTH_STEP
;
505 // Update internal PEI_CORE_FV array.
507 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= BfvHeader
;
508 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
509 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
510 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= 0;
513 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
514 (UINT32
) PrivateData
->FvCount
,
516 (UINT32
) BfvHeader
->FvLength
,
519 PrivateData
->FvCount
++;
522 // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose
523 // additional Fvs to PeiCore.
525 Status
= PeiServicesNotifyPpi (mNotifyOnFvInfoList
);
526 ASSERT_EFI_ERROR (Status
);
531 Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.
532 The FV Info will be registered into PeiCore private data structure.
533 And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.
535 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
536 @param NotifyDescriptor Address of the notification descriptor data structure.
537 @param Ppi Address of the PPI that was installed.
539 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
540 @return if not EFI_SUCESS, fail to verify FV.
545 FirmwareVolmeInfoPpiNotifyCallback (
546 IN EFI_PEI_SERVICES
**PeiServices
,
547 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
551 EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI FvInfo2Ppi
;
552 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
553 PEI_CORE_INSTANCE
*PrivateData
;
555 EFI_PEI_FV_HANDLE FvHandle
;
557 EFI_PEI_FILE_HANDLE FileHandle
;
563 Status
= EFI_SUCCESS
;
564 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
566 if (CompareGuid (NotifyDescriptor
->Guid
, &gEfiPeiFirmwareVolumeInfo2PpiGuid
)) {
570 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
));
576 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
577 FvInfo2Ppi
.AuthenticationStatus
= 0;
581 if (CompareGuid (&FvInfo2Ppi
.FvFormat
, &gEfiFirmwareFileSystem2Guid
)) {
583 // gEfiFirmwareFileSystem2Guid is specified for FvFormat, then here to check the
584 // FileSystemGuid pointed by FvInfo against gEfiFirmwareFileSystem2Guid to make sure
585 // FvInfo has the firmware file system 2 format.
587 // If the ASSERT really appears, FvFormat needs to be specified correctly, for example,
588 // gEfiFirmwareFileSystem3Guid can be used for firmware file system 3 format, or
589 // ((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid can be just used for both
590 // firmware file system 2 and 3 format.
592 ASSERT (CompareGuid (&(((EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
)->FileSystemGuid
), &gEfiFirmwareFileSystem2Guid
));
596 // Locate the corresponding FV_PPI according to founded FV's format guid
598 Status
= PeiServicesLocatePpi (
599 &FvInfo2Ppi
.FvFormat
,
604 if (!EFI_ERROR (Status
)) {
606 // Process new found FV and get FV handle.
608 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo2Ppi
.FvInfo
, FvInfo2Ppi
.FvInfoSize
, &FvHandle
);
609 if (EFI_ERROR (Status
)) {
610 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!\n"));
615 // Check whether the FV has already been processed.
617 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
618 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
619 if (IsFvInfo2
&& (FvInfo2Ppi
.AuthenticationStatus
!= PrivateData
->Fv
[FvIndex
].AuthenticationStatus
)) {
620 PrivateData
->Fv
[FvIndex
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
621 DEBUG ((EFI_D_INFO
, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex
, FvInfo2Ppi
.AuthenticationStatus
));
623 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo2Ppi
.FvInfo
));
628 if (PrivateData
->FvCount
>= PrivateData
->MaxFvCount
) {
630 // Run out of room, grow the buffer.
632 TempPtr
= AllocateZeroPool (
633 sizeof (PEI_CORE_FV_HANDLE
) * (PrivateData
->MaxFvCount
+ FV_GROWTH_STEP
)
635 ASSERT (TempPtr
!= NULL
);
639 sizeof (PEI_CORE_FV_HANDLE
) * PrivateData
->MaxFvCount
641 PrivateData
->Fv
= TempPtr
;
642 PrivateData
->MaxFvCount
= PrivateData
->MaxFvCount
+ FV_GROWTH_STEP
;
646 // Update internal PEI_CORE_FV array.
648 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
;
649 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
650 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
651 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
652 CurFvCount
= PrivateData
->FvCount
;
655 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
657 (VOID
*) FvInfo2Ppi
.FvInfo
,
658 FvInfo2Ppi
.FvInfoSize
,
661 PrivateData
->FvCount
++;
664 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
668 Status
= FvPpi
->FindFileByType (
670 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
674 if (!EFI_ERROR (Status
)) {
675 Status
= FvPpi
->FindSectionByType (
677 EFI_SECTION_PEI_DEPEX
,
681 if (!EFI_ERROR (Status
)) {
682 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
684 // Dependency is not satisfied.
690 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, CurFvCount
, FvHandle
));
691 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[CurFvCount
], FileHandle
);
693 } while (FileHandle
!= NULL
);
695 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi
.FvInfo
));
697 AddUnknownFormatFvInfo (PrivateData
, &FvInfo2Ppi
);
704 Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.
706 @param GuidedSectionGuid The Guided Section GUID.
707 @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi
708 for the Guided Section.
710 @return TRUE The GuidedSectionGuid could be identified, and the pointer to
711 the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.
712 @return FALSE The GuidedSectionGuid could not be identified, or
713 the Guided Section Extraction Ppi has not been installed yet.
717 VerifyGuidedSectionGuid (
718 IN EFI_GUID
*GuidedSectionGuid
,
719 OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
**GuidedSectionExtraction
722 EFI_PEI_HOB_POINTERS Hob
;
723 EFI_GUID
*GuidRecorded
;
728 // Check if there is the Guided Section GUID HOB recorded the GUID itself.
730 Hob
.Raw
= GetFirstGuidHob (GuidedSectionGuid
);
731 if (Hob
.Raw
!= NULL
) {
732 GuidRecorded
= (EFI_GUID
*) GET_GUID_HOB_DATA (Hob
);
733 if (CompareGuid (GuidRecorded
, GuidedSectionGuid
)) {
735 // Found the recorded GuidedSectionGuid.
737 Status
= PeiServicesLocatePpi (GuidedSectionGuid
, 0, NULL
, (VOID
**) &Interface
);
738 if (!EFI_ERROR (Status
) && Interface
!= NULL
) {
740 // Found the supported Guided Section Extraction Ppi for the Guided Section.
742 *GuidedSectionExtraction
= (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*) Interface
;
753 Go through the file to search SectionType section.
754 Search within encapsulation sections (compression and GUIDed) recursively,
755 until the match section is found.
757 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
758 @param SectionType Filter to find only section of this type.
759 @param SectionInstance Pointer to the filter to find the specific instance of section.
760 @param Section From where to search.
761 @param SectionSize The file size to search.
762 @param OutputBuffer A pointer to the discovered section, if successful.
763 NULL if section not found
764 @param AuthenticationStatus Updated upon return to point to the authentication status for this section.
765 @param IsFfs3Fv Indicates the FV format.
767 @return EFI_NOT_FOUND The match section is not found.
768 @return EFI_SUCCESS The match section is found.
773 IN CONST EFI_PEI_SERVICES
**PeiServices
,
774 IN EFI_SECTION_TYPE SectionType
,
775 IN OUT UINTN
*SectionInstance
,
776 IN EFI_COMMON_SECTION_HEADER
*Section
,
777 IN UINTN SectionSize
,
778 OUT VOID
**OutputBuffer
,
779 OUT UINT32
*AuthenticationStatus
,
784 UINT32 SectionLength
;
786 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
787 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
791 UINT32 Authentication
;
792 PEI_CORE_INSTANCE
*PrivateData
;
793 EFI_GUID
*SectionDefinitionGuid
;
794 BOOLEAN SectionCached
;
795 VOID
*TempOutputBuffer
;
796 UINT32 TempAuthenticationStatus
;
797 UINT16 GuidedSectionAttributes
;
799 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
800 *OutputBuffer
= NULL
;
803 Status
= EFI_NOT_FOUND
;
806 while (ParsedLength
< SectionSize
) {
808 if (IS_SECTION2 (Section
)) {
809 ASSERT (SECTION2_SIZE (Section
) > 0x00FFFFFF);
811 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
812 SectionLength
= SECTION2_SIZE (Section
);
814 // SectionLength is adjusted it is 4 byte aligned.
815 // Go to the next section
817 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
818 ASSERT (SectionLength
!= 0);
819 ParsedLength
+= SectionLength
;
820 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ SectionLength
);
825 if (Section
->Type
== SectionType
) {
827 // The type matches, so check the instance count to see if it's the one we want.
829 (*SectionInstance
)--;
830 if (*SectionInstance
== 0) {
834 if (IS_SECTION2 (Section
)) {
835 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
837 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
841 if (IS_SECTION2 (Section
)) {
842 SectionLength
= SECTION2_SIZE (Section
);
844 SectionLength
= SECTION_SIZE (Section
);
847 // SectionLength is adjusted it is 4 byte aligned.
848 // Go to the next section
850 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
851 ASSERT (SectionLength
!= 0);
852 ParsedLength
+= SectionLength
;
853 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
856 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
858 // Check the encapsulated section is extracted into the cache data.
860 SectionCached
= FALSE
;
861 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
862 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
863 SectionCached
= TRUE
;
864 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
865 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
866 Authentication
= PrivateData
->CacheSection
.AuthenticationStatus
[Index
];
868 // Search section directly from the cache data.
870 TempAuthenticationStatus
= 0;
871 Status
= ProcessSection (
878 &TempAuthenticationStatus
,
881 if (!EFI_ERROR (Status
)) {
882 *OutputBuffer
= TempOutputBuffer
;
883 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
890 // If SectionCached is TRUE, the section data has been cached and scanned.
892 if (!SectionCached
) {
893 Status
= EFI_NOT_FOUND
;
895 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
896 if (IS_SECTION2 (Section
)) {
897 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION2
*)Section
)->SectionDefinitionGuid
;
898 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION2
*)Section
)->Attributes
;
900 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
;
901 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION
*)Section
)->Attributes
;
903 if (VerifyGuidedSectionGuid (SectionDefinitionGuid
, &GuidSectionPpi
)) {
904 Status
= GuidSectionPpi
->ExtractSection (
911 } else if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) == 0) {
913 // Figure out the proper authentication status for GUIDED section without processing required
915 Status
= EFI_SUCCESS
;
916 if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) {
917 Authentication
|= EFI_AUTH_STATUS_IMAGE_SIGNED
| EFI_AUTH_STATUS_NOT_TESTED
;
919 if (IS_SECTION2 (Section
)) {
920 PpiOutputSize
= SECTION2_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
921 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
923 PpiOutputSize
= SECTION_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
924 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
927 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
928 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
929 if (!EFI_ERROR (Status
)) {
930 Status
= DecompressPpi
->Decompress (
932 (CONST EFI_COMPRESSION_SECTION
*) Section
,
939 if (!EFI_ERROR (Status
)) {
940 if ((Authentication
& EFI_AUTH_STATUS_NOT_TESTED
) == 0) {
942 // Update cache section data.
944 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
945 PrivateData
->CacheSection
.AllSectionCount
++;
947 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
948 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
949 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
950 PrivateData
->CacheSection
.AuthenticationStatus
[PrivateData
->CacheSection
.SectionIndex
] = Authentication
;
951 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
954 TempAuthenticationStatus
= 0;
955 Status
= ProcessSection (
962 &TempAuthenticationStatus
,
965 if (!EFI_ERROR (Status
)) {
966 *OutputBuffer
= TempOutputBuffer
;
967 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
974 if (IS_SECTION2 (Section
)) {
975 SectionLength
= SECTION2_SIZE (Section
);
977 SectionLength
= SECTION_SIZE (Section
);
980 // SectionLength is adjusted it is 4 byte aligned.
981 // Go to the next section
983 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
984 ASSERT (SectionLength
!= 0);
985 ParsedLength
+= SectionLength
;
986 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
989 return EFI_NOT_FOUND
;
994 Searches for the next matching section within the specified file.
996 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
997 @param SectionType Filter to find only sections of this type.
998 @param FileHandle Pointer to the current file to search.
999 @param SectionData A pointer to the discovered section, if successful.
1000 NULL if section not found
1002 @retval EFI_NOT_FOUND The section was not found.
1003 @retval EFI_SUCCESS The section was found.
1008 PeiFfsFindSectionData (
1009 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1010 IN EFI_SECTION_TYPE SectionType
,
1011 IN EFI_PEI_FILE_HANDLE FileHandle
,
1012 OUT VOID
**SectionData
1015 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1017 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1018 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1019 return EFI_NOT_FOUND
;
1022 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
1026 Searches for the next matching section within the specified file.
1028 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1029 @param SectionType The value of the section type to find.
1030 @param SectionInstance Section instance to find.
1031 @param FileHandle Handle of the firmware file to search.
1032 @param SectionData A pointer to the discovered section, if successful.
1033 @param AuthenticationStatus A pointer to the authentication status for this section.
1035 @retval EFI_SUCCESS The section was found.
1036 @retval EFI_NOT_FOUND The section was not found.
1041 PeiFfsFindSectionData3 (
1042 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1043 IN EFI_SECTION_TYPE SectionType
,
1044 IN UINTN SectionInstance
,
1045 IN EFI_PEI_FILE_HANDLE FileHandle
,
1046 OUT VOID
**SectionData
,
1047 OUT UINT32
*AuthenticationStatus
1050 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1052 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1053 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1054 return EFI_NOT_FOUND
;
1057 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1058 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1059 return CoreFvHandle
->FvPpi
->FindSectionByType2 (CoreFvHandle
->FvPpi
, SectionType
, SectionInstance
, FileHandle
, SectionData
, AuthenticationStatus
);
1062 // The old FvPpi doesn't support to find section by section instance
1063 // and return authentication status, so return EFI_UNSUPPORTED.
1065 return EFI_UNSUPPORTED
;
1069 Searches for the next matching file in the firmware volume.
1071 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1072 @param SearchType Filter to find only files of this type.
1073 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
1074 @param FvHandle Handle of firmware volume in which to search.
1075 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
1076 at the beginning of the firmware volume. On exit, points the file handle of the next file
1077 in the volume or NULL if there are no more files.
1079 @retval EFI_NOT_FOUND The file was not found.
1080 @retval EFI_NOT_FOUND The header checksum was not zero.
1081 @retval EFI_SUCCESS The file was found.
1086 PeiFfsFindNextFile (
1087 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1088 IN UINT8 SearchType
,
1089 IN EFI_PEI_FV_HANDLE FvHandle
,
1090 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1093 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1095 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
1098 // To make backward compatiblity, if can not find corresponding the handle of FV
1099 // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed
1100 // to the address of first byte of FV.
1102 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1103 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1106 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
1107 return EFI_NOT_FOUND
;
1110 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
1115 Search the firmware volumes by index
1117 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1118 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
1120 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
1122 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
1123 @retval EFI_NOT_FOUND The volume was not found.
1124 @retval EFI_SUCCESS The volume was found.
1129 PeiFfsFindNextVolume (
1130 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1132 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
1135 PEI_CORE_INSTANCE
*Private
;
1136 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1138 if (VolumeHandle
== NULL
) {
1139 return EFI_INVALID_PARAMETER
;
1142 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1144 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
1145 if (CoreFvHandle
== NULL
) {
1146 *VolumeHandle
= NULL
;
1147 return EFI_NOT_FOUND
;
1150 *VolumeHandle
= CoreFvHandle
->FvHandle
;
1157 Find a file within a volume by its name.
1159 @param FileName A pointer to the name of the file to find within the firmware volume.
1160 @param VolumeHandle The firmware volume to search
1161 @param FileHandle Upon exit, points to the found file's handle
1162 or NULL if it could not be found.
1164 @retval EFI_SUCCESS File was found.
1165 @retval EFI_NOT_FOUND File was not found.
1166 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
1171 PeiFfsFindFileByName (
1172 IN CONST EFI_GUID
*FileName
,
1173 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1174 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1177 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1179 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1180 return EFI_INVALID_PARAMETER
;
1183 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
1184 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1185 return EFI_NOT_FOUND
;
1188 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
1192 Returns information about a specific file.
1194 @param FileHandle Handle of the file.
1195 @param FileInfo Upon exit, points to the file's information.
1197 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1198 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1199 @retval EFI_SUCCESS File information returned.
1205 IN EFI_PEI_FILE_HANDLE FileHandle
,
1206 OUT EFI_FV_FILE_INFO
*FileInfo
1209 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1211 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1212 return EFI_INVALID_PARAMETER
;
1216 // Retrieve the FirmwareVolume which the file resides in.
1218 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1219 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1220 return EFI_INVALID_PARAMETER
;
1223 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1227 Returns information about a specific file.
1229 @param FileHandle Handle of the file.
1230 @param FileInfo Upon exit, points to the file's information.
1232 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1233 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1234 @retval EFI_SUCCESS File information returned.
1239 PeiFfsGetFileInfo2 (
1240 IN EFI_PEI_FILE_HANDLE FileHandle
,
1241 OUT EFI_FV_FILE_INFO2
*FileInfo
1244 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1246 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1247 return EFI_INVALID_PARAMETER
;
1251 // Retrieve the FirmwareVolume which the file resides in.
1253 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1254 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1255 return EFI_INVALID_PARAMETER
;
1258 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1259 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1260 return CoreFvHandle
->FvPpi
->GetFileInfo2 (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1263 // The old FvPpi doesn't support to return file info with authentication status,
1264 // so return EFI_UNSUPPORTED.
1266 return EFI_UNSUPPORTED
;
1270 Returns information about the specified volume.
1272 This function returns information about a specific firmware
1273 volume, including its name, type, attributes, starting address
1276 @param VolumeHandle Handle of the volume.
1277 @param VolumeInfo Upon exit, points to the volume's information.
1279 @retval EFI_SUCCESS Volume information returned.
1280 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
1281 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
1282 @retval EFI_SUCCESS Information successfully returned.
1283 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
1288 PeiFfsGetVolumeInfo (
1289 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1290 OUT EFI_FV_INFO
*VolumeInfo
1293 PEI_CORE_FV_HANDLE
*CoreHandle
;
1295 if ((VolumeInfo
== NULL
) || (VolumeHandle
== NULL
)) {
1296 return EFI_INVALID_PARAMETER
;
1299 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
1301 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
1302 return EFI_INVALID_PARAMETER
;
1305 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
1309 Find USED_SIZE FV_EXT_TYPE entry in FV extension header and get the FV used size.
1311 @param[in] FvHeader Pointer to FV header.
1312 @param[out] FvUsedSize Pointer to FV used size returned,
1313 only valid if USED_SIZE FV_EXT_TYPE entry is found.
1314 @param[out] EraseByte Pointer to erase byte returned,
1315 only valid if USED_SIZE FV_EXT_TYPE entry is found.
1317 @retval TRUE USED_SIZE FV_EXT_TYPE entry is found,
1318 FV used size and erase byte are returned.
1319 @retval FALSE No USED_SIZE FV_EXT_TYPE entry found.
1324 IN EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
,
1325 OUT UINT32
*FvUsedSize
,
1326 OUT UINT8
*EraseByte
1329 UINT16 ExtHeaderOffset
;
1330 EFI_FIRMWARE_VOLUME_EXT_HEADER
*ExtHeader
;
1331 EFI_FIRMWARE_VOLUME_EXT_ENTRY
*ExtEntryList
;
1332 EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE
*ExtEntryUsedSize
;
1334 ExtHeaderOffset
= ReadUnaligned16 (&FvHeader
->ExtHeaderOffset
);
1335 if (ExtHeaderOffset
!= 0) {
1336 ExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*) ((UINT8
*) FvHeader
+ ExtHeaderOffset
);
1337 ExtEntryList
= (EFI_FIRMWARE_VOLUME_EXT_ENTRY
*) (ExtHeader
+ 1);
1338 while ((UINTN
) ExtEntryList
< ((UINTN
) ExtHeader
+ ReadUnaligned32 (&ExtHeader
->ExtHeaderSize
))) {
1339 if (ReadUnaligned16 (&ExtEntryList
->ExtEntryType
) == EFI_FV_EXT_TYPE_USED_SIZE_TYPE
) {
1341 // USED_SIZE FV_EXT_TYPE entry is found.
1343 ExtEntryUsedSize
= (EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE
*) ExtEntryList
;
1344 *FvUsedSize
= ReadUnaligned32 (&ExtEntryUsedSize
->UsedSize
);
1345 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ERASE_POLARITY
) != 0) {
1352 "FV at 0x%x has 0x%x used size, and erase byte is 0x%02x\n",
1359 ExtEntryList
= (EFI_FIRMWARE_VOLUME_EXT_ENTRY
*)
1360 ((UINT8
*) ExtEntryList
+ ReadUnaligned16 (&ExtEntryList
->ExtEntrySize
));
1365 // No USED_SIZE FV_EXT_TYPE entry found.
1371 Get Fv image(s) from the FV type file, then install FV INFO(2) ppi, Build FV(2, 3) hob.
1373 @param PrivateData PeiCore's private data structure
1374 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
1375 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
1377 @retval EFI_NOT_FOUND FV image can't be found.
1378 @retval EFI_SUCCESS Successfully to process it.
1379 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
1380 @retval EFI_SECURITY_VIOLATION Image is illegal
1381 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
1386 IN PEI_CORE_INSTANCE
*PrivateData
,
1387 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
1388 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
1392 EFI_FV_INFO ParentFvImageInfo
;
1395 EFI_PEI_HOB_POINTERS HobPtr
;
1396 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
1397 EFI_PEI_FV_HANDLE ParentFvHandle
;
1398 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
1399 EFI_FV_FILE_INFO FileInfo
;
1401 UINT32 AuthenticationStatus
;
1407 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1410 HobPtr
.Raw
= GetHobList ();
1411 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
1412 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
1414 // this FILE has been dispatched, it will not be dispatched again.
1416 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
1419 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
1422 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
1423 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
1425 Status
= EFI_SUCCESS
;
1428 // Find FvImage(s) in FvFile
1432 AuthenticationStatus
= 0;
1433 if ((ParentFvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1434 (ParentFvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1435 Status
= ParentFvPpi
->FindSectionByType2 (
1437 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1441 &AuthenticationStatus
1445 // Old FvPpi has no parameter to input SearchInstance,
1446 // only one instance is supported.
1451 Status
= ParentFvPpi
->FindSectionByType (
1453 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1458 if (EFI_ERROR (Status
)) {
1462 Status
= VerifyPeim (PrivateData
, ParentFvHandle
, ParentFvFileHandle
, AuthenticationStatus
);
1463 if (Status
== EFI_SECURITY_VIOLATION
) {
1468 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
1469 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
1470 // its initial linked location and maintain its alignment.
1472 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
1474 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
1476 FvAlignment
= 1 << ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ALIGNMENT
) >> 16);
1477 if (FvAlignment
< 8) {
1483 "%a() FV at 0x%x, FvAlignment required is 0x%x\n",
1490 // Check FvImage alignment.
1492 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
1493 FvLength
= ReadUnaligned64 (&FvHeader
->FvLength
);
1494 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvLength
), FvAlignment
);
1495 if (NewFvBuffer
== NULL
) {
1496 Status
= EFI_OUT_OF_RESOURCES
;
1499 if (GetFvUsedSize (FvHeader
, &FvUsedSize
, &EraseByte
)) {
1501 // Copy the used bytes and fill the rest with the erase value.
1503 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvUsedSize
);
1505 (UINT8
*) NewFvBuffer
+ FvUsedSize
,
1506 (UINTN
) (FvLength
- FvUsedSize
),
1510 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvLength
);
1512 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
1516 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
1517 ASSERT_EFI_ERROR (Status
);
1519 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
1520 ASSERT_EFI_ERROR (Status
);
1523 // Install FvInfo(2) Ppi
1524 // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated
1525 // FVs inherit the proper AuthenticationStatus.
1527 PeiServicesInstallFvInfo2Ppi(
1528 &FvHeader
->FileSystemGuid
,
1530 (UINT32
)FvHeader
->FvLength
,
1531 &ParentFvImageInfo
.FvName
,
1533 AuthenticationStatus
1536 PeiServicesInstallFvInfoPpi (
1537 &FvHeader
->FileSystemGuid
,
1539 (UINT32
) FvHeader
->FvLength
,
1540 &ParentFvImageInfo
.FvName
,
1545 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
1548 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1553 // Makes the encapsulated volume show up in DXE phase to skip processing of
1554 // encapsulated file again.
1557 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1559 &ParentFvImageInfo
.FvName
,
1564 // Build FV3 HOB with authentication status to be propagated to DXE.
1567 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1569 AuthenticationStatus
,
1571 &ParentFvImageInfo
.FvName
,
1580 // At least one FvImage has been processed successfully.
1589 Process a firmware volume and create a volume handle.
1591 Create a volume handle from the information in the buffer. For
1592 memory-mapped firmware volumes, Buffer and BufferSize refer to
1593 the start of the firmware volume and the firmware volume size.
1594 For non memory-mapped firmware volumes, this points to a
1595 buffer which contains the necessary information for creating
1596 the firmware volume handle. Normally, these values are derived
1597 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
1600 @param This Points to this instance of the
1601 EFI_PEI_FIRMWARE_VOLUME_PPI.
1602 @param Buffer Points to the start of the buffer.
1603 @param BufferSize Size of the buffer.
1604 @param FvHandle Points to the returned firmware volume
1605 handle. The firmware volume handle must
1606 be unique within the system.
1608 @retval EFI_SUCCESS Firmware volume handle created.
1609 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
1614 PeiFfsFvPpiProcessVolume (
1615 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1617 IN UINTN BufferSize
,
1618 OUT EFI_PEI_FV_HANDLE
*FvHandle
1623 ASSERT (FvHandle
!= NULL
);
1625 if (Buffer
== NULL
) {
1626 return EFI_VOLUME_CORRUPTED
;
1630 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped
1631 // FV image and the handle is pointed to Fv image's buffer.
1633 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
1636 // Do verify for given FV buffer.
1638 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1639 if (EFI_ERROR(Status
)) {
1640 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1641 return EFI_VOLUME_CORRUPTED
;
1648 Finds the next file of the specified type.
1650 This service enables PEI modules to discover additional firmware files.
1651 The FileHandle must be unique within the system.
1653 @param This Points to this instance of the
1654 EFI_PEI_FIRMWARE_VOLUME_PPI.
1655 @param SearchType A filter to find only files of this type. Type
1656 EFI_FV_FILETYPE_ALL causes no filtering to be
1658 @param FvHandle Handle of firmware volume in which to
1660 @param FileHandle Points to the current handle from which to
1661 begin searching or NULL to start at the
1662 beginning of the firmware volume. Updated
1663 upon return to reflect the file found.
1665 @retval EFI_SUCCESS The file was found.
1666 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1671 PeiFfsFvPpiFindFileByType (
1672 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1673 IN EFI_FV_FILETYPE SearchType
,
1674 IN EFI_PEI_FV_HANDLE FvHandle
,
1675 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1678 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1682 Find a file within a volume by its name.
1684 This service searches for files with a specific name, within
1685 either the specified firmware volume or all firmware volumes.
1687 @param This Points to this instance of the
1688 EFI_PEI_FIRMWARE_VOLUME_PPI.
1689 @param FileName A pointer to the name of the file to find
1690 within the firmware volume.
1691 @param FvHandle Upon entry, the pointer to the firmware
1692 volume to search or NULL if all firmware
1693 volumes should be searched. Upon exit, the
1694 actual firmware volume in which the file was
1696 @param FileHandle Upon exit, points to the found file's
1697 handle or NULL if it could not be found.
1699 @retval EFI_SUCCESS File was found.
1700 @retval EFI_NOT_FOUND File was not found.
1701 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1708 PeiFfsFvPpiFindFileByName (
1709 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1710 IN CONST EFI_GUID
*FileName
,
1711 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1712 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1716 PEI_CORE_INSTANCE
*PrivateData
;
1719 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1720 return EFI_INVALID_PARAMETER
;
1723 if (*FvHandle
!= NULL
) {
1724 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1725 if (Status
== EFI_NOT_FOUND
) {
1730 // If *FvHandle = NULL, so search all FV for given filename
1732 Status
= EFI_NOT_FOUND
;
1734 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1735 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1737 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1739 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1740 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1741 if (!EFI_ERROR (Status
)) {
1742 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1753 Returns information about a specific file.
1755 This function returns information about a specific
1756 file, including its file name, type, attributes, starting
1759 @param This Points to this instance of the
1760 EFI_PEI_FIRMWARE_VOLUME_PPI.
1761 @param FileHandle Handle of the file.
1762 @param FileInfo Upon exit, points to the file's
1765 @retval EFI_SUCCESS File information returned.
1766 @retval EFI_INVALID_PARAMETER If FileHandle does not
1767 represent a valid file.
1768 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1773 PeiFfsFvPpiGetFileInfo (
1774 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1775 IN EFI_PEI_FILE_HANDLE FileHandle
,
1776 OUT EFI_FV_FILE_INFO
*FileInfo
1780 UINT8 ErasePolarity
;
1781 EFI_FFS_FILE_HEADER
*FileHeader
;
1782 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1783 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1785 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1786 return EFI_INVALID_PARAMETER
;
1790 // Retrieve the FirmwareVolume which the file resides in.
1792 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1793 if (CoreFvHandle
== NULL
) {
1794 return EFI_INVALID_PARAMETER
;
1797 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1799 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
1806 // Get FileState which is the highest bit of the State
1808 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1810 switch (FileState
) {
1811 case EFI_FILE_DATA_VALID
:
1812 case EFI_FILE_MARKED_FOR_UPDATE
:
1815 return EFI_INVALID_PARAMETER
;
1818 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1819 if (IS_FFS_FILE2 (FileHeader
)) {
1820 ASSERT (FFS_FILE2_SIZE (FileHeader
) > 0x00FFFFFF);
1821 if (!FwVolInstance
->IsFfs3Fv
) {
1822 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader
->Name
));
1823 return EFI_INVALID_PARAMETER
;
1825 FileInfo
->BufferSize
= FFS_FILE2_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1826 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
);
1828 FileInfo
->BufferSize
= FFS_FILE_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1829 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER
);
1831 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1832 FileInfo
->FileType
= FileHeader
->Type
;
1833 FileInfo
->FileAttributes
= FfsAttributes2FvFileAttributes (FileHeader
->Attributes
);
1834 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_MEMORY_MAPPED
) == EFI_FVB2_MEMORY_MAPPED
) {
1835 FileInfo
->FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
1841 Returns information about a specific file.
1843 This function returns information about a specific
1844 file, including its file name, type, attributes, starting
1845 address, size and authentication status.
1847 @param This Points to this instance of the
1848 EFI_PEI_FIRMWARE_VOLUME_PPI.
1849 @param FileHandle Handle of the file.
1850 @param FileInfo Upon exit, points to the file's
1853 @retval EFI_SUCCESS File information returned.
1854 @retval EFI_INVALID_PARAMETER If FileHandle does not
1855 represent a valid file.
1856 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1861 PeiFfsFvPpiGetFileInfo2 (
1862 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1863 IN EFI_PEI_FILE_HANDLE FileHandle
,
1864 OUT EFI_FV_FILE_INFO2
*FileInfo
1868 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1870 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1871 return EFI_INVALID_PARAMETER
;
1875 // Retrieve the FirmwareVolume which the file resides in.
1877 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1878 if (CoreFvHandle
== NULL
) {
1879 return EFI_INVALID_PARAMETER
;
1882 Status
= PeiFfsFvPpiGetFileInfo (This
, FileHandle
, (EFI_FV_FILE_INFO
*) FileInfo
);
1883 if (!EFI_ERROR (Status
)) {
1884 FileInfo
->AuthenticationStatus
= CoreFvHandle
->AuthenticationStatus
;
1891 This function returns information about the firmware volume.
1893 @param This Points to this instance of the
1894 EFI_PEI_FIRMWARE_VOLUME_PPI.
1895 @param FvHandle Handle to the firmware handle.
1896 @param VolumeInfo Points to the returned firmware volume
1899 @retval EFI_SUCCESS Information returned successfully.
1900 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1901 firmware volume or VolumeInfo is NULL.
1906 PeiFfsFvPpiGetVolumeInfo (
1907 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1908 IN EFI_PEI_FV_HANDLE FvHandle
,
1909 OUT EFI_FV_INFO
*VolumeInfo
1912 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1913 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1915 if ((VolumeInfo
== NULL
) || (FvHandle
== NULL
)) {
1916 return EFI_INVALID_PARAMETER
;
1920 // VolumeHandle may not align at 8 byte,
1921 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1922 // So, Copy FvHeader into the local FvHeader structure.
1924 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1927 // Check Fv Image Signature
1929 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1930 return EFI_INVALID_PARAMETER
;
1933 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1934 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1935 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1936 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1937 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1939 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1940 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1941 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1948 Find the next matching section in the firmware file.
1950 This service enables PEI modules to discover sections
1951 of a given type within a valid file.
1953 @param This Points to this instance of the
1954 EFI_PEI_FIRMWARE_VOLUME_PPI.
1955 @param SearchType A filter to find only sections of this
1957 @param FileHandle Handle of firmware file in which to
1959 @param SectionData Updated upon return to point to the
1962 @retval EFI_SUCCESS Section was found.
1963 @retval EFI_NOT_FOUND Section of the specified type was not
1964 found. SectionData contains NULL.
1968 PeiFfsFvPpiFindSectionByType (
1969 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1970 IN EFI_SECTION_TYPE SearchType
,
1971 IN EFI_PEI_FILE_HANDLE FileHandle
,
1972 OUT VOID
**SectionData
1975 UINT32 AuthenticationStatus
;
1976 return PeiFfsFvPpiFindSectionByType2 (This
, SearchType
, 0, FileHandle
, SectionData
, &AuthenticationStatus
);
1980 Find the next matching section in the firmware file.
1982 This service enables PEI modules to discover sections
1983 of a given instance and type within a valid file.
1985 @param This Points to this instance of the
1986 EFI_PEI_FIRMWARE_VOLUME_PPI.
1987 @param SearchType A filter to find only sections of this
1989 @param SearchInstance A filter to find the specific instance
1991 @param FileHandle Handle of firmware file in which to
1993 @param SectionData Updated upon return to point to the
1995 @param AuthenticationStatus Updated upon return to point to the
1996 authentication status for this section.
1998 @retval EFI_SUCCESS Section was found.
1999 @retval EFI_NOT_FOUND Section of the specified type was not
2000 found. SectionData contains NULL.
2004 PeiFfsFvPpiFindSectionByType2 (
2005 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
2006 IN EFI_SECTION_TYPE SearchType
,
2007 IN UINTN SearchInstance
,
2008 IN EFI_PEI_FILE_HANDLE FileHandle
,
2009 OUT VOID
**SectionData
,
2010 OUT UINT32
*AuthenticationStatus
2014 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
2016 EFI_COMMON_SECTION_HEADER
*Section
;
2017 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
2018 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
2020 UINT32 ExtractedAuthenticationStatus
;
2022 if (SectionData
== NULL
) {
2023 return EFI_NOT_FOUND
;
2026 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
2029 // Retrieve the FirmwareVolume which the file resides in.
2031 CoreFvHandle
= FileHandleToVolume (FileHandle
);
2032 if (CoreFvHandle
== NULL
) {
2033 return EFI_NOT_FOUND
;
2036 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
2038 if (IS_FFS_FILE2 (FfsFileHeader
)) {
2039 ASSERT (FFS_FILE2_SIZE (FfsFileHeader
) > 0x00FFFFFF);
2040 if (!FwVolInstance
->IsFfs3Fv
) {
2041 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
2042 return EFI_NOT_FOUND
;
2044 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
2045 FileSize
= FFS_FILE2_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
2047 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
2048 FileSize
= FFS_FILE_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
2051 Instance
= SearchInstance
+ 1;
2052 ExtractedAuthenticationStatus
= 0;
2053 Status
= ProcessSection (
2054 GetPeiServicesTablePointer (),
2060 &ExtractedAuthenticationStatus
,
2061 FwVolInstance
->IsFfs3Fv
2063 if (!EFI_ERROR (Status
)) {
2065 // Inherit the authentication status.
2067 *AuthenticationStatus
= ExtractedAuthenticationStatus
| CoreFvHandle
->AuthenticationStatus
;
2073 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
2075 @param FvHandle The handle of a FV.
2077 @retval NULL if can not find.
2078 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
2080 PEI_CORE_FV_HANDLE
*
2081 FvHandleToCoreHandle (
2082 IN EFI_PEI_FV_HANDLE FvHandle
2086 PEI_CORE_INSTANCE
*PrivateData
;
2088 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
2089 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
2090 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
2091 return &PrivateData
->Fv
[Index
];
2099 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
2101 This routine also will install FvInfo ppi for FV hob in PI ways.
2103 @param Private Pointer of PEI_CORE_INSTANCE
2104 @param Instance The index of FV want to be searched.
2106 @return Instance of PEI_CORE_FV_HANDLE.
2108 PEI_CORE_FV_HANDLE
*
2109 FindNextCoreFvHandle (
2110 IN PEI_CORE_INSTANCE
*Private
,
2116 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
2119 // Handle Framework FvHob and Install FvInfo Ppi for it.
2121 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
2123 // Loop to search the wanted FirmwareVolume which supports FFS
2125 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
2126 while (FvHob
!= NULL
) {
2128 // Search whether FvHob has been installed into PeiCore's FV database.
2129 // If found, no need install new FvInfoPpi for it.
2131 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
2132 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
2139 // Search whether FvHob has been cached into PeiCore's Unknown FV database.
2140 // If found, no need install new FvInfoPpi for it.
2143 for (Index
= 0; Index
< Private
->UnknownFvInfoCount
; Index
++) {
2144 if ((UINTN
)FvHob
->BaseAddress
== (UINTN
)Private
->UnknownFvInfo
[Index
].FvInfo
) {
2152 // If the Fv in FvHob has not been installed into PeiCore's FV database and has
2153 // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi
2154 // for it then PeiCore will dispatch it in callback of FvInfoPpi.
2157 PeiServicesInstallFvInfoPpi (
2158 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
2159 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
2160 (UINT32
)FvHob
->Length
,
2166 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
2170 if (Instance
>= Private
->FvCount
) {
2174 return &Private
->Fv
[Instance
];
2178 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
2179 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
2180 PrivateData->Fv[] array should be fixed up to be pointed to the one in permanent
2183 @param PrivateData Pointer to PEI_CORE_INSTANCE.
2187 IN PEI_CORE_INSTANCE
*PrivateData
2191 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
2196 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
2199 Status
= PeiServicesLocatePpi (
2200 &gEfiFirmwareFileSystem2Guid
,
2205 ASSERT_EFI_ERROR (Status
);
2208 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
2209 // which is shadowed from flash to permanent memory within PeiCore image.
2211 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
2212 ASSERT_EFI_ERROR (Status
);
2215 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2217 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
2218 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2219 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FwVol
.Fv
;
2224 // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which
2227 Status
= PeiServicesLocatePpi (
2228 &gEfiFirmwareFileSystem3Guid
,
2233 ASSERT_EFI_ERROR (Status
);
2236 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3
2237 // which is shadowed from flash to permanent memory within PeiCore image.
2239 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs3FvPpiList
);
2240 ASSERT_EFI_ERROR (Status
);
2243 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2245 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
2246 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2247 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs3FwVol
.Fv
;
2253 Report the information for a new discoveried FV in unknown third-party format.
2255 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but
2256 the FV in this format has been discoveried, then this FV's information will be cached into
2257 PEI_CORE_INSTANCE's UnknownFvInfo array.
2258 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI
2259 is installed later by platform's PEIM, the original unknown third-party FV will be processed by
2260 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2262 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2263 @param FvInfo2Ppi Point to FvInfo2 PPI.
2265 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
2266 @retval EFI_SUCCESS Success to add the information for unknown FV.
2269 AddUnknownFormatFvInfo (
2270 IN PEI_CORE_INSTANCE
*PrivateData
,
2271 IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
*FvInfo2Ppi
2274 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
2277 if (PrivateData
->UnknownFvInfoCount
>= PrivateData
->MaxUnknownFvInfoCount
) {
2279 // Run out of room, grow the buffer.
2281 TempPtr
= AllocateZeroPool (
2282 sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
) * (PrivateData
->MaxUnknownFvInfoCount
+ FV_GROWTH_STEP
)
2284 ASSERT (TempPtr
!= NULL
);
2287 PrivateData
->UnknownFvInfo
,
2288 sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
) * PrivateData
->MaxUnknownFvInfoCount
2290 PrivateData
->UnknownFvInfo
= TempPtr
;
2291 PrivateData
->MaxUnknownFvInfoCount
= PrivateData
->MaxUnknownFvInfoCount
+ FV_GROWTH_STEP
;
2294 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
2295 PrivateData
->UnknownFvInfoCount
++;
2297 CopyGuid (&NewUnknownFv
->FvFormat
, &FvInfo2Ppi
->FvFormat
);
2298 NewUnknownFv
->FvInfo
= FvInfo2Ppi
->FvInfo
;
2299 NewUnknownFv
->FvInfoSize
= FvInfo2Ppi
->FvInfoSize
;
2300 NewUnknownFv
->AuthenticationStatus
= FvInfo2Ppi
->AuthenticationStatus
;
2301 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
2302 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
2303 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
2305 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
2310 Find the FV information according to third-party FV format guid.
2312 This routine also will remove the FV information found by given FV format guid from
2313 PrivateData->UnknownFvInfo[].
2315 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2316 @param Format Point to given FV format guid
2317 @param FvInfo On return, the pointer of FV information buffer
2318 @param FvInfoSize On return, the size of FV information buffer.
2319 @param AuthenticationStatus On return, the authentication status of FV information buffer.
2321 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
2322 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2325 FindUnknownFormatFvInfo (
2326 IN PEI_CORE_INSTANCE
*PrivateData
,
2327 IN EFI_GUID
*Format
,
2329 OUT UINT32
*FvInfoSize
,
2330 OUT UINT32
*AuthenticationStatus
2337 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
2338 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
2343 if (Index
== PrivateData
->UnknownFvInfoCount
) {
2344 return EFI_NOT_FOUND
;
2347 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
2348 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
2349 *AuthenticationStatus
= PrivateData
->UnknownFvInfo
[Index
].AuthenticationStatus
;
2352 // Remove an entry from UnknownFvInfo array.
2355 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
2356 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
2358 PrivateData
->UnknownFvInfoCount
--;
2363 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
2365 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
2366 routine is called to process all discoveried FVs in this format.
2368 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
2369 @param NotifyDescriptor Address of the notification descriptor data structure.
2370 @param Ppi Address of the PPI that was installed.
2372 @retval EFI_SUCCESS The notification callback is processed correctly.
2376 ThirdPartyFvPpiNotifyCallback (
2377 IN EFI_PEI_SERVICES
**PeiServices
,
2378 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
2382 PEI_CORE_INSTANCE
*PrivateData
;
2383 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
2386 UINT32 AuthenticationStatus
;
2388 EFI_PEI_FV_HANDLE FvHandle
;
2389 BOOLEAN IsProcessed
;
2391 EFI_PEI_FILE_HANDLE FileHandle
;
2396 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
2397 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
2400 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
, &AuthenticationStatus
);
2401 if (EFI_ERROR (Status
)) {
2406 // Process new found FV and get FV handle.
2408 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
2409 if (EFI_ERROR (Status
)) {
2410 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
2415 // Check whether the FV has already been processed.
2417 IsProcessed
= FALSE
;
2418 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
2419 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
2420 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo
));
2430 if (PrivateData
->FvCount
>= PrivateData
->MaxFvCount
) {
2432 // Run out of room, grow the buffer.
2434 TempPtr
= AllocateZeroPool (
2435 sizeof (PEI_CORE_FV_HANDLE
) * (PrivateData
->MaxFvCount
+ FV_GROWTH_STEP
)
2437 ASSERT (TempPtr
!= NULL
);
2441 sizeof (PEI_CORE_FV_HANDLE
) * PrivateData
->MaxFvCount
2443 PrivateData
->Fv
= TempPtr
;
2444 PrivateData
->MaxFvCount
= PrivateData
->MaxFvCount
+ FV_GROWTH_STEP
;
2448 // Update internal PEI_CORE_FV array.
2450 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
2451 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
2452 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
2453 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= AuthenticationStatus
;
2454 CurFvCount
= PrivateData
->FvCount
;
2457 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
2458 (UINT32
) CurFvCount
,
2463 PrivateData
->FvCount
++;
2466 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
2470 Status
= FvPpi
->FindFileByType (
2472 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
2476 if (!EFI_ERROR (Status
)) {
2477 Status
= FvPpi
->FindSectionByType (
2479 EFI_SECTION_PEI_DEPEX
,
2483 if (!EFI_ERROR (Status
)) {
2484 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
2486 // Dependency is not satisfied.
2492 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, CurFvCount
, FvHandle
));
2493 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[CurFvCount
], FileHandle
);
2495 } while (FileHandle
!= NULL
);