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 FirmwareVolumeInfoPpiNotifyCallback
19 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
20 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
21 FirmwareVolumeInfoPpiNotifyCallback
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 // Ignore 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 // Ignore 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
= (EFI_PEI_FILE_HANDLE
)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 Volume 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_SUCCESS, fail to verify FV.
545 FirmwareVolumeInfoPpiNotifyCallback (
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 the format GUID of the FV found
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 ((DEBUG_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 discovered 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
);
1097 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
1098 return EFI_NOT_FOUND
;
1101 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
1106 Search the firmware volumes by index
1108 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1109 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
1111 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
1113 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
1114 @retval EFI_NOT_FOUND The volume was not found.
1115 @retval EFI_SUCCESS The volume was found.
1120 PeiFfsFindNextVolume (
1121 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1123 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
1126 PEI_CORE_INSTANCE
*Private
;
1127 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1129 if (VolumeHandle
== NULL
) {
1130 return EFI_INVALID_PARAMETER
;
1133 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1135 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
1136 if (CoreFvHandle
== NULL
) {
1137 *VolumeHandle
= NULL
;
1138 return EFI_NOT_FOUND
;
1141 *VolumeHandle
= CoreFvHandle
->FvHandle
;
1148 Find a file within a volume by its name.
1150 @param FileName A pointer to the name of the file to find within the firmware volume.
1151 @param VolumeHandle The firmware volume to search
1152 @param FileHandle Upon exit, points to the found file's handle
1153 or NULL if it could not be found.
1155 @retval EFI_SUCCESS File was found.
1156 @retval EFI_NOT_FOUND File was not found.
1157 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
1162 PeiFfsFindFileByName (
1163 IN CONST EFI_GUID
*FileName
,
1164 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1165 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1168 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1170 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1171 return EFI_INVALID_PARAMETER
;
1174 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
1175 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1176 return EFI_NOT_FOUND
;
1179 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
1183 Returns information about a specific file.
1185 @param FileHandle Handle of the file.
1186 @param FileInfo Upon exit, points to the file's information.
1188 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1189 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1190 @retval EFI_SUCCESS File information returned.
1196 IN EFI_PEI_FILE_HANDLE FileHandle
,
1197 OUT EFI_FV_FILE_INFO
*FileInfo
1200 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1202 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1203 return EFI_INVALID_PARAMETER
;
1207 // Retrieve the FirmwareVolume which the file resides in.
1209 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1210 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1211 return EFI_INVALID_PARAMETER
;
1214 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1218 Returns information about a specific file.
1220 @param FileHandle Handle of the file.
1221 @param FileInfo Upon exit, points to the file's information.
1223 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1224 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1225 @retval EFI_SUCCESS File information returned.
1230 PeiFfsGetFileInfo2 (
1231 IN EFI_PEI_FILE_HANDLE FileHandle
,
1232 OUT EFI_FV_FILE_INFO2
*FileInfo
1235 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1237 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1238 return EFI_INVALID_PARAMETER
;
1242 // Retrieve the FirmwareVolume which the file resides in.
1244 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1245 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1246 return EFI_INVALID_PARAMETER
;
1249 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1250 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1251 return CoreFvHandle
->FvPpi
->GetFileInfo2 (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1254 // The old FvPpi doesn't support to return file info with authentication status,
1255 // so return EFI_UNSUPPORTED.
1257 return EFI_UNSUPPORTED
;
1261 Returns information about the specified volume.
1263 This function returns information about a specific firmware
1264 volume, including its name, type, attributes, starting address
1267 @param VolumeHandle Handle of the volume.
1268 @param VolumeInfo Upon exit, points to the volume's information.
1270 @retval EFI_SUCCESS Volume information returned.
1271 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
1272 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
1273 @retval EFI_SUCCESS Information successfully returned.
1274 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
1279 PeiFfsGetVolumeInfo (
1280 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1281 OUT EFI_FV_INFO
*VolumeInfo
1284 PEI_CORE_FV_HANDLE
*CoreHandle
;
1286 if ((VolumeInfo
== NULL
) || (VolumeHandle
== NULL
)) {
1287 return EFI_INVALID_PARAMETER
;
1290 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
1292 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
1293 return EFI_INVALID_PARAMETER
;
1296 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
1300 Find USED_SIZE FV_EXT_TYPE entry in FV extension header and get the FV used size.
1302 @param[in] FvHeader Pointer to FV header.
1303 @param[out] FvUsedSize Pointer to FV used size returned,
1304 only valid if USED_SIZE FV_EXT_TYPE entry is found.
1305 @param[out] EraseByte Pointer to erase byte returned,
1306 only valid if USED_SIZE FV_EXT_TYPE entry is found.
1308 @retval TRUE USED_SIZE FV_EXT_TYPE entry is found,
1309 FV used size and erase byte are returned.
1310 @retval FALSE No USED_SIZE FV_EXT_TYPE entry found.
1315 IN EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
,
1316 OUT UINT32
*FvUsedSize
,
1317 OUT UINT8
*EraseByte
1320 UINT16 ExtHeaderOffset
;
1321 EFI_FIRMWARE_VOLUME_EXT_HEADER
*ExtHeader
;
1322 EFI_FIRMWARE_VOLUME_EXT_ENTRY
*ExtEntryList
;
1323 EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE
*ExtEntryUsedSize
;
1325 ExtHeaderOffset
= ReadUnaligned16 (&FvHeader
->ExtHeaderOffset
);
1326 if (ExtHeaderOffset
!= 0) {
1327 ExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*) ((UINT8
*) FvHeader
+ ExtHeaderOffset
);
1328 ExtEntryList
= (EFI_FIRMWARE_VOLUME_EXT_ENTRY
*) (ExtHeader
+ 1);
1329 while ((UINTN
) ExtEntryList
< ((UINTN
) ExtHeader
+ ReadUnaligned32 (&ExtHeader
->ExtHeaderSize
))) {
1330 if (ReadUnaligned16 (&ExtEntryList
->ExtEntryType
) == EFI_FV_EXT_TYPE_USED_SIZE_TYPE
) {
1332 // USED_SIZE FV_EXT_TYPE entry is found.
1334 ExtEntryUsedSize
= (EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE
*) ExtEntryList
;
1335 *FvUsedSize
= ReadUnaligned32 (&ExtEntryUsedSize
->UsedSize
);
1336 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ERASE_POLARITY
) != 0) {
1343 "FV at 0x%x has 0x%x used size, and erase byte is 0x%02x\n",
1350 ExtEntryList
= (EFI_FIRMWARE_VOLUME_EXT_ENTRY
*)
1351 ((UINT8
*) ExtEntryList
+ ReadUnaligned16 (&ExtEntryList
->ExtEntrySize
));
1356 // No USED_SIZE FV_EXT_TYPE entry found.
1362 Get FV image(s) from the FV type file, then install FV INFO(2) PPI, Build FV(2, 3) HOB.
1364 @param PrivateData PeiCore's private data structure
1365 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent FV image that contain this FV image.
1366 @param ParentFvFileHandle File handle of a FV type file that contain this FV image.
1368 @retval EFI_NOT_FOUND FV image can't be found.
1369 @retval EFI_SUCCESS Successfully to process it.
1370 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
1371 @retval EFI_SECURITY_VIOLATION Image is illegal
1372 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
1377 IN PEI_CORE_INSTANCE
*PrivateData
,
1378 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
1379 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
1383 EFI_FV_INFO ParentFvImageInfo
;
1386 EFI_PEI_HOB_POINTERS HobPtr
;
1387 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
1388 EFI_PEI_FV_HANDLE ParentFvHandle
;
1389 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
1390 EFI_FV_FILE_INFO FileInfo
;
1392 UINT32 AuthenticationStatus
;
1398 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1401 HobPtr
.Raw
= GetHobList ();
1402 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
1403 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
1405 // this FILE has been dispatched, it will not be dispatched again.
1407 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
1410 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
1413 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
1414 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
1416 Status
= EFI_SUCCESS
;
1419 // Find FvImage(s) in FvFile
1423 AuthenticationStatus
= 0;
1424 if ((ParentFvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1425 (ParentFvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1426 Status
= ParentFvPpi
->FindSectionByType2 (
1428 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1432 &AuthenticationStatus
1436 // Old FvPpi has no parameter to input SearchInstance,
1437 // only one instance is supported.
1442 Status
= ParentFvPpi
->FindSectionByType (
1444 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1449 if (EFI_ERROR (Status
)) {
1453 Status
= VerifyPeim (PrivateData
, ParentFvHandle
, ParentFvFileHandle
, AuthenticationStatus
);
1454 if (Status
== EFI_SECURITY_VIOLATION
) {
1459 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
1460 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
1461 // its initial linked location and maintain its alignment.
1463 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
1465 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
1467 FvAlignment
= 1 << ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ALIGNMENT
) >> 16);
1468 if (FvAlignment
< 8) {
1474 "%a() FV at 0x%x, FvAlignment required is 0x%x\n",
1481 // Check FvImage alignment.
1483 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
1484 FvLength
= ReadUnaligned64 (&FvHeader
->FvLength
);
1485 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvLength
), FvAlignment
);
1486 if (NewFvBuffer
== NULL
) {
1487 Status
= EFI_OUT_OF_RESOURCES
;
1490 if (GetFvUsedSize (FvHeader
, &FvUsedSize
, &EraseByte
)) {
1492 // Copy the used bytes and fill the rest with the erase value.
1494 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvUsedSize
);
1496 (UINT8
*) NewFvBuffer
+ FvUsedSize
,
1497 (UINTN
) (FvLength
- FvUsedSize
),
1501 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvLength
);
1503 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
1507 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
1508 ASSERT_EFI_ERROR (Status
);
1510 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
1511 ASSERT_EFI_ERROR (Status
);
1514 // Install FvInfo(2) Ppi
1515 // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated
1516 // FVs inherit the proper AuthenticationStatus.
1518 PeiServicesInstallFvInfo2Ppi(
1519 &FvHeader
->FileSystemGuid
,
1521 (UINT32
)FvHeader
->FvLength
,
1522 &ParentFvImageInfo
.FvName
,
1524 AuthenticationStatus
1527 PeiServicesInstallFvInfoPpi (
1528 &FvHeader
->FileSystemGuid
,
1530 (UINT32
) FvHeader
->FvLength
,
1531 &ParentFvImageInfo
.FvName
,
1536 // Expose the extracted FvImage to the FV HOB consumer phase, i.e. DXE phase
1539 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1544 // Makes the encapsulated volume show up in DXE phase to skip processing of
1545 // encapsulated file again.
1548 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1550 &ParentFvImageInfo
.FvName
,
1555 // Build FV3 HOB with authentication status to be propagated to DXE.
1558 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1560 AuthenticationStatus
,
1562 &ParentFvImageInfo
.FvName
,
1571 // At least one FvImage has been processed successfully.
1580 Process a firmware volume and create a volume handle.
1582 Create a volume handle from the information in the buffer. For
1583 memory-mapped firmware volumes, Buffer and BufferSize refer to
1584 the start of the firmware volume and the firmware volume size.
1585 For non memory-mapped firmware volumes, this points to a
1586 buffer which contains the necessary information for creating
1587 the firmware volume handle. Normally, these values are derived
1588 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
1591 @param This Points to this instance of the
1592 EFI_PEI_FIRMWARE_VOLUME_PPI.
1593 @param Buffer Points to the start of the buffer.
1594 @param BufferSize Size of the buffer.
1595 @param FvHandle Points to the returned firmware volume
1596 handle. The firmware volume handle must
1597 be unique within the system.
1599 @retval EFI_SUCCESS Firmware volume handle created.
1600 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
1605 PeiFfsFvPpiProcessVolume (
1606 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1608 IN UINTN BufferSize
,
1609 OUT EFI_PEI_FV_HANDLE
*FvHandle
1614 ASSERT (FvHandle
!= NULL
);
1616 if (Buffer
== NULL
) {
1617 return EFI_VOLUME_CORRUPTED
;
1621 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped
1622 // FV image and the handle is pointed to FV image's buffer.
1624 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
1627 // Do verify for given FV buffer.
1629 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1630 if (EFI_ERROR(Status
)) {
1631 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1632 return EFI_VOLUME_CORRUPTED
;
1639 Finds the next file of the specified type.
1641 This service enables PEI modules to discover additional firmware files.
1642 The FileHandle must be unique within the system.
1644 @param This Points to this instance of the
1645 EFI_PEI_FIRMWARE_VOLUME_PPI.
1646 @param SearchType A filter to find only files of this type. Type
1647 EFI_FV_FILETYPE_ALL causes no filtering to be
1649 @param FvHandle Handle of firmware volume in which to
1651 @param FileHandle Points to the current handle from which to
1652 begin searching or NULL to start at the
1653 beginning of the firmware volume. Updated
1654 upon return to reflect the file found.
1656 @retval EFI_SUCCESS The file was found.
1657 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1662 PeiFfsFvPpiFindFileByType (
1663 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1664 IN EFI_FV_FILETYPE SearchType
,
1665 IN EFI_PEI_FV_HANDLE FvHandle
,
1666 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1669 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1673 Find a file within a volume by its name.
1675 This service searches for files with a specific name, within
1676 either the specified firmware volume or all firmware volumes.
1678 @param This Points to this instance of the
1679 EFI_PEI_FIRMWARE_VOLUME_PPI.
1680 @param FileName A pointer to the name of the file to find
1681 within the firmware volume.
1682 @param FvHandle Upon entry, the pointer to the firmware
1683 volume to search or NULL if all firmware
1684 volumes should be searched. Upon exit, the
1685 actual firmware volume in which the file was
1687 @param FileHandle Upon exit, points to the found file's
1688 handle or NULL if it could not be found.
1690 @retval EFI_SUCCESS File was found.
1691 @retval EFI_NOT_FOUND File was not found.
1692 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1699 PeiFfsFvPpiFindFileByName (
1700 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1701 IN CONST EFI_GUID
*FileName
,
1702 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1703 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1707 PEI_CORE_INSTANCE
*PrivateData
;
1710 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1711 return EFI_INVALID_PARAMETER
;
1714 if (*FvHandle
!= NULL
) {
1715 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1716 if (Status
== EFI_NOT_FOUND
) {
1721 // If *FvHandle = NULL, so search all FV for given filename
1723 Status
= EFI_NOT_FOUND
;
1725 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1726 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1728 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1730 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1731 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1732 if (!EFI_ERROR (Status
)) {
1733 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1744 Returns information about a specific file.
1746 This function returns information about a specific
1747 file, including its file name, type, attributes, starting
1750 @param This Points to this instance of the
1751 EFI_PEI_FIRMWARE_VOLUME_PPI.
1752 @param FileHandle Handle of the file.
1753 @param FileInfo Upon exit, points to the file's
1756 @retval EFI_SUCCESS File information returned.
1757 @retval EFI_INVALID_PARAMETER If FileHandle does not
1758 represent a valid file.
1759 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1764 PeiFfsFvPpiGetFileInfo (
1765 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1766 IN EFI_PEI_FILE_HANDLE FileHandle
,
1767 OUT EFI_FV_FILE_INFO
*FileInfo
1771 UINT8 ErasePolarity
;
1772 EFI_FFS_FILE_HEADER
*FileHeader
;
1773 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1774 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1776 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1777 return EFI_INVALID_PARAMETER
;
1781 // Retrieve the FirmwareVolume which the file resides in.
1783 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1784 if (CoreFvHandle
== NULL
) {
1785 return EFI_INVALID_PARAMETER
;
1788 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1790 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
1797 // Get FileState which is the highest bit of the State
1799 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1801 switch (FileState
) {
1802 case EFI_FILE_DATA_VALID
:
1803 case EFI_FILE_MARKED_FOR_UPDATE
:
1806 return EFI_INVALID_PARAMETER
;
1809 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1810 if (IS_FFS_FILE2 (FileHeader
)) {
1811 ASSERT (FFS_FILE2_SIZE (FileHeader
) > 0x00FFFFFF);
1812 if (!FwVolInstance
->IsFfs3Fv
) {
1813 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader
->Name
));
1814 return EFI_INVALID_PARAMETER
;
1816 FileInfo
->BufferSize
= FFS_FILE2_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1817 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
);
1819 FileInfo
->BufferSize
= FFS_FILE_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1820 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER
);
1822 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1823 FileInfo
->FileType
= FileHeader
->Type
;
1824 FileInfo
->FileAttributes
= FfsAttributes2FvFileAttributes (FileHeader
->Attributes
);
1825 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_MEMORY_MAPPED
) == EFI_FVB2_MEMORY_MAPPED
) {
1826 FileInfo
->FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
1832 Returns information about a specific file.
1834 This function returns information about a specific
1835 file, including its file name, type, attributes, starting
1836 address, size and authentication status.
1838 @param This Points to this instance of the
1839 EFI_PEI_FIRMWARE_VOLUME_PPI.
1840 @param FileHandle Handle of the file.
1841 @param FileInfo Upon exit, points to the file's
1844 @retval EFI_SUCCESS File information returned.
1845 @retval EFI_INVALID_PARAMETER If FileHandle does not
1846 represent a valid file.
1847 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1852 PeiFfsFvPpiGetFileInfo2 (
1853 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1854 IN EFI_PEI_FILE_HANDLE FileHandle
,
1855 OUT EFI_FV_FILE_INFO2
*FileInfo
1859 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1861 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1862 return EFI_INVALID_PARAMETER
;
1866 // Retrieve the FirmwareVolume which the file resides in.
1868 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1869 if (CoreFvHandle
== NULL
) {
1870 return EFI_INVALID_PARAMETER
;
1873 Status
= PeiFfsFvPpiGetFileInfo (This
, FileHandle
, (EFI_FV_FILE_INFO
*) FileInfo
);
1874 if (!EFI_ERROR (Status
)) {
1875 FileInfo
->AuthenticationStatus
= CoreFvHandle
->AuthenticationStatus
;
1882 This function returns information about the firmware volume.
1884 @param This Points to this instance of the
1885 EFI_PEI_FIRMWARE_VOLUME_PPI.
1886 @param FvHandle Handle to the firmware handle.
1887 @param VolumeInfo Points to the returned firmware volume
1890 @retval EFI_SUCCESS Information returned successfully.
1891 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1892 firmware volume or VolumeInfo is NULL.
1897 PeiFfsFvPpiGetVolumeInfo (
1898 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1899 IN EFI_PEI_FV_HANDLE FvHandle
,
1900 OUT EFI_FV_INFO
*VolumeInfo
1903 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1904 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1906 if ((VolumeInfo
== NULL
) || (FvHandle
== NULL
)) {
1907 return EFI_INVALID_PARAMETER
;
1911 // VolumeHandle may not align at 8 byte,
1912 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1913 // So, Copy FvHeader into the local FvHeader structure.
1915 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1918 // Check FV Image Signature
1920 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1921 return EFI_INVALID_PARAMETER
;
1924 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1925 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1926 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1927 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1928 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1930 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1931 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1932 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1939 Find the next matching section in the firmware file.
1941 This service enables PEI modules to discover sections
1942 of a given type within a valid file.
1944 @param This Points to this instance of the
1945 EFI_PEI_FIRMWARE_VOLUME_PPI.
1946 @param SearchType A filter to find only sections of this
1948 @param FileHandle Handle of firmware file in which to
1950 @param SectionData Updated upon return to point to the
1953 @retval EFI_SUCCESS Section was found.
1954 @retval EFI_NOT_FOUND Section of the specified type was not
1955 found. SectionData contains NULL.
1959 PeiFfsFvPpiFindSectionByType (
1960 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1961 IN EFI_SECTION_TYPE SearchType
,
1962 IN EFI_PEI_FILE_HANDLE FileHandle
,
1963 OUT VOID
**SectionData
1966 UINT32 AuthenticationStatus
;
1967 return PeiFfsFvPpiFindSectionByType2 (This
, SearchType
, 0, FileHandle
, SectionData
, &AuthenticationStatus
);
1971 Find the next matching section in the firmware file.
1973 This service enables PEI modules to discover sections
1974 of a given instance and type within a valid file.
1976 @param This Points to this instance of the
1977 EFI_PEI_FIRMWARE_VOLUME_PPI.
1978 @param SearchType A filter to find only sections of this
1980 @param SearchInstance A filter to find the specific instance
1982 @param FileHandle Handle of firmware file in which to
1984 @param SectionData Updated upon return to point to the
1986 @param AuthenticationStatus Updated upon return to point to the
1987 authentication status for this section.
1989 @retval EFI_SUCCESS Section was found.
1990 @retval EFI_NOT_FOUND Section of the specified type was not
1991 found. SectionData contains NULL.
1995 PeiFfsFvPpiFindSectionByType2 (
1996 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1997 IN EFI_SECTION_TYPE SearchType
,
1998 IN UINTN SearchInstance
,
1999 IN EFI_PEI_FILE_HANDLE FileHandle
,
2000 OUT VOID
**SectionData
,
2001 OUT UINT32
*AuthenticationStatus
2005 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
2007 EFI_COMMON_SECTION_HEADER
*Section
;
2008 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
2009 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
2011 UINT32 ExtractedAuthenticationStatus
;
2013 if (SectionData
== NULL
) {
2014 return EFI_NOT_FOUND
;
2017 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
2020 // Retrieve the FirmwareVolume which the file resides in.
2022 CoreFvHandle
= FileHandleToVolume (FileHandle
);
2023 if (CoreFvHandle
== NULL
) {
2024 return EFI_NOT_FOUND
;
2027 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
2029 if (IS_FFS_FILE2 (FfsFileHeader
)) {
2030 ASSERT (FFS_FILE2_SIZE (FfsFileHeader
) > 0x00FFFFFF);
2031 if (!FwVolInstance
->IsFfs3Fv
) {
2032 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
2033 return EFI_NOT_FOUND
;
2035 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
2036 FileSize
= FFS_FILE2_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
2038 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
2039 FileSize
= FFS_FILE_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
2042 Instance
= SearchInstance
+ 1;
2043 ExtractedAuthenticationStatus
= 0;
2044 Status
= ProcessSection (
2045 GetPeiServicesTablePointer (),
2051 &ExtractedAuthenticationStatus
,
2052 FwVolInstance
->IsFfs3Fv
2054 if (!EFI_ERROR (Status
)) {
2056 // Inherit the authentication status.
2058 *AuthenticationStatus
= ExtractedAuthenticationStatus
| CoreFvHandle
->AuthenticationStatus
;
2064 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
2066 @param FvHandle The handle of a FV.
2068 @retval NULL if can not find.
2069 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
2071 PEI_CORE_FV_HANDLE
*
2072 FvHandleToCoreHandle (
2073 IN EFI_PEI_FV_HANDLE FvHandle
2077 PEI_CORE_INSTANCE
*PrivateData
;
2079 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
2080 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
2081 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
2082 return &PrivateData
->Fv
[Index
];
2090 Gets a PEI_CORE_FV_HANDLE instance for the next volume according to the given index.
2092 This routine also will install an instance of the FvInfo PPI for the FV HOB
2093 as defined in the PI specification.
2095 @param Private Pointer of PEI_CORE_INSTANCE
2096 @param Instance Index of the FV to search
2098 @return Instance of PEI_CORE_FV_HANDLE.
2100 PEI_CORE_FV_HANDLE
*
2101 FindNextCoreFvHandle (
2102 IN PEI_CORE_INSTANCE
*Private
,
2106 if (Instance
>= Private
->FvCount
) {
2110 return &Private
->Fv
[Instance
];
2114 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
2115 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
2116 PrivateData->Fv[] array should be fixed up to be pointed to the one in permanent
2119 @param PrivateData Pointer to PEI_CORE_INSTANCE.
2123 IN PEI_CORE_INSTANCE
*PrivateData
2127 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
2132 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
2135 Status
= PeiServicesLocatePpi (
2136 &gEfiFirmwareFileSystem2Guid
,
2141 ASSERT_EFI_ERROR (Status
);
2144 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
2145 // which is shadowed from flash to permanent memory within PeiCore image.
2147 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
2148 ASSERT_EFI_ERROR (Status
);
2151 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2153 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
2154 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2155 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FwVol
.Fv
;
2160 // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which
2163 Status
= PeiServicesLocatePpi (
2164 &gEfiFirmwareFileSystem3Guid
,
2169 ASSERT_EFI_ERROR (Status
);
2172 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3
2173 // which is shadowed from flash to permanent memory within PeiCore image.
2175 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs3FvPpiList
);
2176 ASSERT_EFI_ERROR (Status
);
2179 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2181 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
2182 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2183 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs3FwVol
.Fv
;
2189 Report the information for a newly discovered FV in an unknown format.
2191 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for a third-party FV format, but
2192 the FV has been discovered, then the information of this FV will be cached into PEI_CORE_INSTANCE's
2193 UnknownFvInfo array.
2195 Also a notification would be installed for unknown FV format GUID, if EFI_PEI_FIRMWARE_VOLUME_PPI
2196 is installed later by platform's PEIM, the original unknown FV will be processed by
2197 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2199 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2200 @param FvInfo2Ppi Point to FvInfo2 PPI.
2202 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
2203 @retval EFI_SUCCESS Success to add the information for unknown FV.
2206 AddUnknownFormatFvInfo (
2207 IN PEI_CORE_INSTANCE
*PrivateData
,
2208 IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
*FvInfo2Ppi
2211 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
2214 if (PrivateData
->UnknownFvInfoCount
>= PrivateData
->MaxUnknownFvInfoCount
) {
2216 // Run out of room, grow the buffer.
2218 TempPtr
= AllocateZeroPool (
2219 sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
) * (PrivateData
->MaxUnknownFvInfoCount
+ FV_GROWTH_STEP
)
2221 ASSERT (TempPtr
!= NULL
);
2224 PrivateData
->UnknownFvInfo
,
2225 sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
) * PrivateData
->MaxUnknownFvInfoCount
2227 PrivateData
->UnknownFvInfo
= TempPtr
;
2228 PrivateData
->MaxUnknownFvInfoCount
= PrivateData
->MaxUnknownFvInfoCount
+ FV_GROWTH_STEP
;
2231 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
2232 PrivateData
->UnknownFvInfoCount
++;
2234 CopyGuid (&NewUnknownFv
->FvFormat
, &FvInfo2Ppi
->FvFormat
);
2235 NewUnknownFv
->FvInfo
= FvInfo2Ppi
->FvInfo
;
2236 NewUnknownFv
->FvInfoSize
= FvInfo2Ppi
->FvInfoSize
;
2237 NewUnknownFv
->AuthenticationStatus
= FvInfo2Ppi
->AuthenticationStatus
;
2238 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
2239 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
2240 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
2242 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
2247 Find the FV information according to third-party FV format GUID.
2249 This routine also will remove the FV information found by given FV format GUID from
2250 PrivateData->UnknownFvInfo[].
2252 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2253 @param Format Point to given FV format GUID
2254 @param FvInfo On return, the pointer of FV information buffer
2255 @param FvInfoSize On return, the size of FV information buffer.
2256 @param AuthenticationStatus On return, the authentication status of FV information buffer.
2258 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
2259 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2262 FindUnknownFormatFvInfo (
2263 IN PEI_CORE_INSTANCE
*PrivateData
,
2264 IN EFI_GUID
*Format
,
2266 OUT UINT32
*FvInfoSize
,
2267 OUT UINT32
*AuthenticationStatus
2274 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
2275 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
2280 if (Index
== PrivateData
->UnknownFvInfoCount
) {
2281 return EFI_NOT_FOUND
;
2284 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
2285 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
2286 *AuthenticationStatus
= PrivateData
->UnknownFvInfo
[Index
].AuthenticationStatus
;
2289 // Remove an entry from UnknownFvInfo array.
2292 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
2293 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
2295 PrivateData
->UnknownFvInfoCount
--;
2300 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
2302 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
2303 routine is called to process all discovered FVs in this format.
2305 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
2306 @param NotifyDescriptor Address of the notification descriptor data structure.
2307 @param Ppi Address of the PPI that was installed.
2309 @retval EFI_SUCCESS The notification callback is processed correctly.
2313 ThirdPartyFvPpiNotifyCallback (
2314 IN EFI_PEI_SERVICES
**PeiServices
,
2315 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
2319 PEI_CORE_INSTANCE
*PrivateData
;
2320 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
2323 UINT32 AuthenticationStatus
;
2325 EFI_PEI_FV_HANDLE FvHandle
;
2326 BOOLEAN IsProcessed
;
2328 EFI_PEI_FILE_HANDLE FileHandle
;
2333 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
2334 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
2337 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
, &AuthenticationStatus
);
2338 if (EFI_ERROR (Status
)) {
2343 // Process new found FV and get FV handle.
2345 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
2346 if (EFI_ERROR (Status
)) {
2347 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
2352 // Check whether the FV has already been processed.
2354 IsProcessed
= FALSE
;
2355 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
2356 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
2357 DEBUG ((DEBUG_INFO
, "The FV %p has already been processed!\n", FvInfo
));
2367 if (PrivateData
->FvCount
>= PrivateData
->MaxFvCount
) {
2369 // Run out of room, grow the buffer.
2371 TempPtr
= AllocateZeroPool (
2372 sizeof (PEI_CORE_FV_HANDLE
) * (PrivateData
->MaxFvCount
+ FV_GROWTH_STEP
)
2374 ASSERT (TempPtr
!= NULL
);
2378 sizeof (PEI_CORE_FV_HANDLE
) * PrivateData
->MaxFvCount
2380 PrivateData
->Fv
= TempPtr
;
2381 PrivateData
->MaxFvCount
= PrivateData
->MaxFvCount
+ FV_GROWTH_STEP
;
2385 // Update internal PEI_CORE_FV array.
2387 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
2388 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
2389 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
2390 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= AuthenticationStatus
;
2391 CurFvCount
= PrivateData
->FvCount
;
2394 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
2395 (UINT32
) CurFvCount
,
2400 PrivateData
->FvCount
++;
2403 // Scan and process the new discovered FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
2407 Status
= FvPpi
->FindFileByType (
2409 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
2413 if (!EFI_ERROR (Status
)) {
2414 Status
= FvPpi
->FindSectionByType (
2416 EFI_SECTION_PEI_DEPEX
,
2420 if (!EFI_ERROR (Status
)) {
2421 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
2423 // Dependency is not satisfied.
2429 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, CurFvCount
, FvHandle
));
2430 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[CurFvCount
], FileHandle
);
2432 } while (FileHandle
!= NULL
);