2 Pei Core Firmware File System service routines.
4 Copyright (c) 2015 HP Development Company, L.P.
5 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList
[] = {
20 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
21 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
22 FirmwareVolmeInfoPpiNotifyCallback
25 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
26 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
27 FirmwareVolmeInfoPpiNotifyCallback
31 PEI_FW_VOL_INSTANCE mPeiFfs2FwVol
= {
35 PeiFfsFvPpiProcessVolume
,
36 PeiFfsFvPpiFindFileByType
,
37 PeiFfsFvPpiFindFileByName
,
38 PeiFfsFvPpiGetFileInfo
,
39 PeiFfsFvPpiGetVolumeInfo
,
40 PeiFfsFvPpiFindSectionByType
,
41 PeiFfsFvPpiGetFileInfo2
,
42 PeiFfsFvPpiFindSectionByType2
,
43 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
44 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
48 PEI_FW_VOL_INSTANCE mPeiFfs3FwVol
= {
52 PeiFfsFvPpiProcessVolume
,
53 PeiFfsFvPpiFindFileByType
,
54 PeiFfsFvPpiFindFileByName
,
55 PeiFfsFvPpiGetFileInfo
,
56 PeiFfsFvPpiGetVolumeInfo
,
57 PeiFfsFvPpiFindSectionByType
,
58 PeiFfsFvPpiGetFileInfo2
,
59 PeiFfsFvPpiFindSectionByType2
,
60 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
61 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
65 EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList
= {
66 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
67 &gEfiFirmwareFileSystem2Guid
,
71 EFI_PEI_PPI_DESCRIPTOR mPeiFfs3FvPpiList
= {
72 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
73 &gEfiFirmwareFileSystem3Guid
,
78 Required Alignment Alignment Value in FFS Alignment Value in
79 (bytes) Attributes Field Firmware Volume Interfaces
89 UINT8 mFvAttributes
[] = {0, 4, 7, 9, 10, 12, 15, 16};
92 Convert the FFS File Attributes to FV File Attributes
94 @param FfsAttributes The attributes of UINT8 type.
96 @return The attributes of EFI_FV_FILE_ATTRIBUTES
99 EFI_FV_FILE_ATTRIBUTES
100 FfsAttributes2FvFileAttributes (
101 IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
105 EFI_FV_FILE_ATTRIBUTES FileAttribute
;
107 DataAlignment
= (UINT8
) ((FfsAttributes
& FFS_ATTRIB_DATA_ALIGNMENT
) >> 3);
108 ASSERT (DataAlignment
< 8);
110 FileAttribute
= (EFI_FV_FILE_ATTRIBUTES
) mFvAttributes
[DataAlignment
];
112 if ((FfsAttributes
& FFS_ATTRIB_FIXED
) == FFS_ATTRIB_FIXED
) {
113 FileAttribute
|= EFI_FV_FILE_ATTRIB_FIXED
;
116 return FileAttribute
;
120 Returns the file state set by the highest zero bit in the State field
122 @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
123 in the Attributes field.
124 @param FfsHeader Pointer to FFS File Header.
126 @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit
127 in the header State field.
131 IN UINT8 ErasePolarity
,
132 IN EFI_FFS_FILE_HEADER
*FfsHeader
135 EFI_FFS_FILE_STATE FileState
;
136 EFI_FFS_FILE_STATE HighestBit
;
138 FileState
= FfsHeader
->State
;
140 if (ErasePolarity
!= 0) {
141 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
145 // Get file state set by its highest none zero bit.
148 while (HighestBit
!= 0 && (HighestBit
& FileState
) == 0) {
156 Calculates the checksum of the header of a file.
158 @param FileHeader Pointer to FFS File Header.
160 @return Checksum of the header.
161 Zero means the header is good.
162 Non-zero means the header is bad.
165 CalculateHeaderChecksum (
166 IN EFI_FFS_FILE_HEADER
*FileHeader
169 EFI_FFS_FILE_HEADER2 TestFileHeader
;
171 if (IS_FFS_FILE2 (FileHeader
)) {
172 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
174 // Ingore State and File field in FFS header.
176 TestFileHeader
.State
= 0;
177 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
179 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
181 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
183 // Ingore State and File field in FFS header.
185 TestFileHeader
.State
= 0;
186 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
188 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
193 Find FV handler according to FileHandle in that FV.
195 @param FileHandle Handle of file image
197 @return Pointer to instance of PEI_CORE_FV_HANDLE.
201 IN EFI_PEI_FILE_HANDLE FileHandle
205 PEI_CORE_INSTANCE
*PrivateData
;
206 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
209 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
210 BestIndex
= PrivateData
->FvCount
;
213 // Find the best matched FV image that includes this FileHandle.
214 // FV may include the child FV, and they are in the same continuous space.
215 // If FileHandle is from the child FV, the updated logic can find its matched FV.
217 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
218 FwVolHeader
= PrivateData
->Fv
[Index
].FvHeader
;
219 if (((UINT64
) (UINTN
) FileHandle
> (UINT64
) (UINTN
) FwVolHeader
) && \
220 ((UINT64
) (UINTN
) FileHandle
<= ((UINT64
) (UINTN
) FwVolHeader
+ FwVolHeader
->FvLength
- 1))) {
221 if (BestIndex
== PrivateData
->FvCount
) {
224 if ((UINT64
) (UINTN
) PrivateData
->Fv
[BestIndex
].FvHeader
< (UINT64
) (UINTN
) FwVolHeader
) {
231 if (BestIndex
< PrivateData
->FvCount
) {
232 return &PrivateData
->Fv
[BestIndex
];
239 Given the input file pointer, search for the first matching file in the
240 FFS volume as defined by SearchType. The search starts from FileHeader inside
241 the Firmware Volume defined by FwVolHeader.
242 If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.
243 If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
244 the first PEIM, or COMBINED PEIM or FV file type FFS file will return.
246 @param FvHandle Pointer to the FV header of the volume to search
247 @param FileName File name
248 @param SearchType Filter to find only files of this type.
249 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
250 @param FileHandle This parameter must point to a valid FFS volume.
251 @param AprioriFile Pointer to AprioriFile image in this FV if has
253 @return EFI_NOT_FOUND No files matching the search criteria were found
254 @retval EFI_SUCCESS Success to search given file
259 IN CONST EFI_PEI_FV_HANDLE FvHandle
,
260 IN CONST EFI_GUID
*FileName
, OPTIONAL
261 IN EFI_FV_FILETYPE SearchType
,
262 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
,
263 IN OUT EFI_PEI_FILE_HANDLE
*AprioriFile OPTIONAL
266 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
267 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExtHeader
;
268 EFI_FFS_FILE_HEADER
**FileHeader
;
269 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
271 UINT32 FileOccupiedSize
;
280 // Convert the handle of FV to FV header for memory-mapped firmware volume
282 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvHandle
;
283 FileHeader
= (EFI_FFS_FILE_HEADER
**)FileHandle
;
285 IsFfs3Fv
= CompareGuid (&FwVolHeader
->FileSystemGuid
, &gEfiFirmwareFileSystem3Guid
);
287 FvLength
= FwVolHeader
->FvLength
;
288 if ((FwVolHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
295 // If FileHeader is not specified (NULL) or FileName is not NULL,
296 // start with the first file in the firmware volume. Otherwise,
297 // start from the FileHeader.
299 if ((*FileHeader
== NULL
) || (FileName
!= NULL
)) {
300 if (FwVolHeader
->ExtHeaderOffset
!= 0) {
302 // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
304 FwVolExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*) ((UINT8
*) FwVolHeader
+ FwVolHeader
->ExtHeaderOffset
);
305 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FwVolExtHeader
+ FwVolExtHeader
->ExtHeaderSize
);
306 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ALIGN_POINTER (FfsFileHeader
, 8);
308 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*) FwVolHeader
+ FwVolHeader
->HeaderLength
);
311 if (IS_FFS_FILE2 (*FileHeader
)) {
313 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &(*FileHeader
)->Name
));
315 FileLength
= FFS_FILE2_SIZE (*FileHeader
);
316 ASSERT (FileLength
> 0x00FFFFFF);
318 FileLength
= FFS_FILE_SIZE (*FileHeader
);
321 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
323 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
324 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)*FileHeader
+ FileOccupiedSize
);
327 FileOffset
= (UINT32
) ((UINT8
*)FfsFileHeader
- (UINT8
*)FwVolHeader
);
328 ASSERT (FileOffset
<= 0xFFFFFFFF);
330 while (FileOffset
< (FvLength
- sizeof (EFI_FFS_FILE_HEADER
))) {
332 // Get FileState which is the highest bit of the State
334 FileState
= GetFileState (ErasePolarity
, FfsFileHeader
);
337 case EFI_FILE_HEADER_CONSTRUCTION
:
338 case EFI_FILE_HEADER_INVALID
:
339 if (IS_FFS_FILE2 (FfsFileHeader
)) {
341 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
343 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER2
);
344 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
346 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER
);
347 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
351 case EFI_FILE_DATA_VALID
:
352 case EFI_FILE_MARKED_FOR_UPDATE
:
353 if (CalculateHeaderChecksum (FfsFileHeader
) != 0) {
356 return EFI_NOT_FOUND
;
359 if (IS_FFS_FILE2 (FfsFileHeader
)) {
360 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
361 ASSERT (FileLength
> 0x00FFFFFF);
362 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
364 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
365 FileOffset
+= FileOccupiedSize
;
366 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ FileOccupiedSize
);
370 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
371 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
374 DataCheckSum
= FFS_FIXED_CHECKSUM
;
375 if ((FfsFileHeader
->Attributes
& FFS_ATTRIB_CHECKSUM
) == FFS_ATTRIB_CHECKSUM
) {
376 if (IS_FFS_FILE2 (FfsFileHeader
)) {
377 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
), FileLength
- sizeof(EFI_FFS_FILE_HEADER2
));
379 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
), FileLength
- sizeof(EFI_FFS_FILE_HEADER
));
382 if (FfsFileHeader
->IntegrityCheck
.Checksum
.File
!= DataCheckSum
) {
385 return EFI_NOT_FOUND
;
388 if (FileName
!= NULL
) {
389 if (CompareGuid (&FfsFileHeader
->Name
, (EFI_GUID
*)FileName
)) {
390 *FileHeader
= FfsFileHeader
;
393 } else if (SearchType
== PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
) {
394 if ((FfsFileHeader
->Type
== EFI_FV_FILETYPE_PEIM
) ||
395 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
) ||
396 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
398 *FileHeader
= FfsFileHeader
;
400 } else if (AprioriFile
!= NULL
) {
401 if (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
402 if (CompareGuid (&FfsFileHeader
->Name
, &gPeiAprioriFileNameGuid
)) {
403 *AprioriFile
= FfsFileHeader
;
407 } else if (((SearchType
== FfsFileHeader
->Type
) || (SearchType
== EFI_FV_FILETYPE_ALL
)) &&
408 (FfsFileHeader
->Type
!= EFI_FV_FILETYPE_FFS_PAD
)) {
409 *FileHeader
= FfsFileHeader
;
413 FileOffset
+= FileOccupiedSize
;
414 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
417 case EFI_FILE_DELETED
:
418 if (IS_FFS_FILE2 (FfsFileHeader
)) {
420 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
422 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
423 ASSERT (FileLength
> 0x00FFFFFF);
425 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
427 FileOccupiedSize
= GET_OCCUPIED_SIZE(FileLength
, 8);
428 FileOffset
+= FileOccupiedSize
;
429 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
434 return EFI_NOT_FOUND
;
439 return EFI_NOT_FOUND
;
443 Initialize PeiCore Fv List.
445 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
446 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
450 IN PEI_CORE_INSTANCE
*PrivateData
,
451 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
455 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
456 EFI_PEI_FV_HANDLE FvHandle
;
457 EFI_FIRMWARE_VOLUME_HEADER
*BfvHeader
;
460 // Install FV_PPI for FFS2 file system.
462 PeiServicesInstallPpi (&mPeiFfs2FvPpiList
);
465 // Install FV_PPI for FFS3 file system.
467 PeiServicesInstallPpi (&mPeiFfs3FvPpiList
);
469 BfvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
472 // The FV_PPI in BFV's format should be installed.
474 Status
= PeiServicesLocatePpi (
475 &BfvHeader
->FileSystemGuid
,
480 ASSERT_EFI_ERROR (Status
);
485 FvPpi
->ProcessVolume (
487 SecCoreData
->BootFirmwareVolumeBase
,
488 (UINTN
)BfvHeader
->FvLength
,
493 // Update internal PEI_CORE_FV array.
495 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= BfvHeader
;
496 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
497 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
498 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= 0;
501 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
502 (UINT32
) PrivateData
->FvCount
,
507 PrivateData
->FvCount
++;
510 // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose
511 // additional Fvs to PeiCore.
513 Status
= PeiServicesNotifyPpi (mNotifyOnFvInfoList
);
514 ASSERT_EFI_ERROR (Status
);
519 Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.
520 The FV Info will be registered into PeiCore private data structure.
521 And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.
523 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
524 @param NotifyDescriptor Address of the notification descriptor data structure.
525 @param Ppi Address of the PPI that was installed.
527 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
528 @return if not EFI_SUCESS, fail to verify FV.
533 FirmwareVolmeInfoPpiNotifyCallback (
534 IN EFI_PEI_SERVICES
**PeiServices
,
535 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
539 EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI FvInfo2Ppi
;
540 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
541 PEI_CORE_INSTANCE
*PrivateData
;
543 EFI_PEI_FV_HANDLE FvHandle
;
545 EFI_PEI_FILE_HANDLE FileHandle
;
550 Status
= EFI_SUCCESS
;
551 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
553 if (CompareGuid (NotifyDescriptor
->Guid
, &gEfiPeiFirmwareVolumeInfo2PpiGuid
)) {
557 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
));
563 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
564 FvInfo2Ppi
.AuthenticationStatus
= 0;
568 if (CompareGuid (&FvInfo2Ppi
.FvFormat
, &gEfiFirmwareFileSystem2Guid
)) {
570 // gEfiFirmwareFileSystem2Guid is specified for FvFormat, then here to check the
571 // FileSystemGuid pointed by FvInfo against gEfiFirmwareFileSystem2Guid to make sure
572 // FvInfo has the firmware file system 2 format.
574 // If the ASSERT really appears, FvFormat needs to be specified correctly, for example,
575 // gEfiFirmwareFileSystem3Guid can be used for firmware file system 3 format, or
576 // ((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid can be just used for both
577 // firmware file system 2 and 3 format.
579 ASSERT (CompareGuid (&(((EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
)->FileSystemGuid
), &gEfiFirmwareFileSystem2Guid
));
583 // Locate the corresponding FV_PPI according to founded FV's format guid
585 Status
= PeiServicesLocatePpi (
586 &FvInfo2Ppi
.FvFormat
,
591 if (!EFI_ERROR (Status
)) {
593 // Process new found FV and get FV handle.
595 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo2Ppi
.FvInfo
, FvInfo2Ppi
.FvInfoSize
, &FvHandle
);
596 if (EFI_ERROR (Status
)) {
597 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!\n"));
602 // Check whether the FV has already been processed.
604 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
605 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
606 if (IsFvInfo2
&& (FvInfo2Ppi
.AuthenticationStatus
!= PrivateData
->Fv
[FvIndex
].AuthenticationStatus
)) {
607 PrivateData
->Fv
[FvIndex
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
608 DEBUG ((EFI_D_INFO
, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex
, FvInfo2Ppi
.AuthenticationStatus
));
610 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo2Ppi
.FvInfo
));
615 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
616 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
617 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
622 // Update internal PEI_CORE_FV array.
624 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
;
625 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
626 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
627 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
628 CurFvCount
= PrivateData
->FvCount
;
631 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
633 (VOID
*) FvInfo2Ppi
.FvInfo
,
634 FvInfo2Ppi
.FvInfoSize
,
637 PrivateData
->FvCount
++;
640 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
644 Status
= FvPpi
->FindFileByType (
646 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
650 if (!EFI_ERROR (Status
)) {
651 Status
= FvPpi
->FindSectionByType (
653 EFI_SECTION_PEI_DEPEX
,
657 if (!EFI_ERROR (Status
)) {
658 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
660 // Dependency is not satisfied.
666 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, CurFvCount
, FvHandle
));
667 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[CurFvCount
], FileHandle
);
669 } while (FileHandle
!= NULL
);
671 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi
.FvInfo
));
673 AddUnknownFormatFvInfo (PrivateData
, &FvInfo2Ppi
);
680 Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.
682 @param GuidedSectionGuid The Guided Section GUID.
683 @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi
684 for the Guided Section.
686 @return TRUE The GuidedSectionGuid could be identified, and the pointer to
687 the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.
688 @return FALSE The GuidedSectionGuid could not be identified, or
689 the Guided Section Extraction Ppi has not been installed yet.
693 VerifyGuidedSectionGuid (
694 IN EFI_GUID
*GuidedSectionGuid
,
695 OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
**GuidedSectionExtraction
698 EFI_PEI_HOB_POINTERS Hob
;
699 EFI_GUID
*GuidRecorded
;
704 // Check if there is the Guided Section GUID HOB recorded the GUID itself.
706 Hob
.Raw
= GetFirstGuidHob (GuidedSectionGuid
);
707 if (Hob
.Raw
!= NULL
) {
708 GuidRecorded
= (EFI_GUID
*) GET_GUID_HOB_DATA (Hob
);
709 if (CompareGuid (GuidRecorded
, GuidedSectionGuid
)) {
711 // Found the recorded GuidedSectionGuid.
713 Status
= PeiServicesLocatePpi (GuidedSectionGuid
, 0, NULL
, (VOID
**) &Interface
);
714 if (!EFI_ERROR (Status
) && Interface
!= NULL
) {
716 // Found the supported Guided Section Extraction Ppi for the Guided Section.
718 *GuidedSectionExtraction
= (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*) Interface
;
729 Go through the file to search SectionType section.
730 Search within encapsulation sections (compression and GUIDed) recursively,
731 until the match section is found.
733 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
734 @param SectionType Filter to find only section of this type.
735 @param SectionInstance Pointer to the filter to find the specific instance of section.
736 @param Section From where to search.
737 @param SectionSize The file size to search.
738 @param OutputBuffer A pointer to the discovered section, if successful.
739 NULL if section not found
740 @param AuthenticationStatus Updated upon return to point to the authentication status for this section.
741 @param IsFfs3Fv Indicates the FV format.
743 @return EFI_NOT_FOUND The match section is not found.
744 @return EFI_SUCCESS The match section is found.
749 IN CONST EFI_PEI_SERVICES
**PeiServices
,
750 IN EFI_SECTION_TYPE SectionType
,
751 IN OUT UINTN
*SectionInstance
,
752 IN EFI_COMMON_SECTION_HEADER
*Section
,
753 IN UINTN SectionSize
,
754 OUT VOID
**OutputBuffer
,
755 OUT UINT32
*AuthenticationStatus
,
760 UINT32 SectionLength
;
762 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
763 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
767 UINT32 Authentication
;
768 PEI_CORE_INSTANCE
*PrivateData
;
769 EFI_GUID
*SectionDefinitionGuid
;
770 BOOLEAN SectionCached
;
771 VOID
*TempOutputBuffer
;
772 UINT32 TempAuthenticationStatus
;
773 UINT16 GuidedSectionAttributes
;
775 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
776 *OutputBuffer
= NULL
;
779 Status
= EFI_NOT_FOUND
;
782 while (ParsedLength
< SectionSize
) {
784 if (IS_SECTION2 (Section
)) {
785 ASSERT (SECTION2_SIZE (Section
) > 0x00FFFFFF);
787 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
788 SectionLength
= SECTION2_SIZE (Section
);
790 // SectionLength is adjusted it is 4 byte aligned.
791 // Go to the next section
793 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
794 ASSERT (SectionLength
!= 0);
795 ParsedLength
+= SectionLength
;
796 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ SectionLength
);
801 if (Section
->Type
== SectionType
) {
803 // The type matches, so check the instance count to see if it's the one we want.
805 (*SectionInstance
)--;
806 if (*SectionInstance
== 0) {
810 if (IS_SECTION2 (Section
)) {
811 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
813 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
817 if (IS_SECTION2 (Section
)) {
818 SectionLength
= SECTION2_SIZE (Section
);
820 SectionLength
= SECTION_SIZE (Section
);
823 // SectionLength is adjusted it is 4 byte aligned.
824 // Go to the next section
826 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
827 ASSERT (SectionLength
!= 0);
828 ParsedLength
+= SectionLength
;
829 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
832 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
834 // Check the encapsulated section is extracted into the cache data.
836 SectionCached
= FALSE
;
837 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
838 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
839 SectionCached
= TRUE
;
840 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
841 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
842 Authentication
= PrivateData
->CacheSection
.AuthenticationStatus
[Index
];
844 // Search section directly from the cache data.
846 TempAuthenticationStatus
= 0;
847 Status
= ProcessSection (
854 &TempAuthenticationStatus
,
857 if (!EFI_ERROR (Status
)) {
858 *OutputBuffer
= TempOutputBuffer
;
859 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
866 // If SectionCached is TRUE, the section data has been cached and scanned.
868 if (!SectionCached
) {
869 Status
= EFI_NOT_FOUND
;
871 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
872 if (IS_SECTION2 (Section
)) {
873 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION2
*)Section
)->SectionDefinitionGuid
;
874 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION2
*)Section
)->Attributes
;
876 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
;
877 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION
*)Section
)->Attributes
;
879 if (VerifyGuidedSectionGuid (SectionDefinitionGuid
, &GuidSectionPpi
)) {
880 Status
= GuidSectionPpi
->ExtractSection (
887 } else if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) == 0) {
889 // Figure out the proper authentication status for GUIDED section without processing required
891 Status
= EFI_SUCCESS
;
892 if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) {
893 Authentication
|= EFI_AUTH_STATUS_IMAGE_SIGNED
| EFI_AUTH_STATUS_NOT_TESTED
;
895 if (IS_SECTION2 (Section
)) {
896 PpiOutputSize
= SECTION2_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
897 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
899 PpiOutputSize
= SECTION_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
900 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
903 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
904 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
905 if (!EFI_ERROR (Status
)) {
906 Status
= DecompressPpi
->Decompress (
908 (CONST EFI_COMPRESSION_SECTION
*) Section
,
915 if (!EFI_ERROR (Status
)) {
917 // Update cache section data.
919 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
920 PrivateData
->CacheSection
.AllSectionCount
++;
922 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
923 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
924 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
925 PrivateData
->CacheSection
.AuthenticationStatus
[PrivateData
->CacheSection
.SectionIndex
] = Authentication
;
926 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
928 TempAuthenticationStatus
= 0;
929 Status
= ProcessSection (
936 &TempAuthenticationStatus
,
939 if (!EFI_ERROR (Status
)) {
940 *OutputBuffer
= TempOutputBuffer
;
941 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
948 if (IS_SECTION2 (Section
)) {
949 SectionLength
= SECTION2_SIZE (Section
);
951 SectionLength
= SECTION_SIZE (Section
);
954 // SectionLength is adjusted it is 4 byte aligned.
955 // Go to the next section
957 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
958 ASSERT (SectionLength
!= 0);
959 ParsedLength
+= SectionLength
;
960 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
963 return EFI_NOT_FOUND
;
968 Searches for the next matching section within the specified file.
970 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
971 @param SectionType Filter to find only sections of this type.
972 @param FileHandle Pointer to the current file to search.
973 @param SectionData A pointer to the discovered section, if successful.
974 NULL if section not found
976 @retval EFI_NOT_FOUND The section was not found.
977 @retval EFI_SUCCESS The section was found.
982 PeiFfsFindSectionData (
983 IN CONST EFI_PEI_SERVICES
**PeiServices
,
984 IN EFI_SECTION_TYPE SectionType
,
985 IN EFI_PEI_FILE_HANDLE FileHandle
,
986 OUT VOID
**SectionData
989 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
991 CoreFvHandle
= FileHandleToVolume (FileHandle
);
992 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
993 return EFI_NOT_FOUND
;
996 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
1000 Searches for the next matching section within the specified file.
1002 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1003 @param SectionType The value of the section type to find.
1004 @param SectionInstance Section instance to find.
1005 @param FileHandle Handle of the firmware file to search.
1006 @param SectionData A pointer to the discovered section, if successful.
1007 @param AuthenticationStatus A pointer to the authentication status for this section.
1009 @retval EFI_SUCCESS The section was found.
1010 @retval EFI_NOT_FOUND The section was not found.
1015 PeiFfsFindSectionData3 (
1016 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1017 IN EFI_SECTION_TYPE SectionType
,
1018 IN UINTN SectionInstance
,
1019 IN EFI_PEI_FILE_HANDLE FileHandle
,
1020 OUT VOID
**SectionData
,
1021 OUT UINT32
*AuthenticationStatus
1024 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1026 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1027 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1028 return EFI_NOT_FOUND
;
1031 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1032 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1033 return CoreFvHandle
->FvPpi
->FindSectionByType2 (CoreFvHandle
->FvPpi
, SectionType
, SectionInstance
, FileHandle
, SectionData
, AuthenticationStatus
);
1036 // The old FvPpi doesn't support to find section by section instance
1037 // and return authentication status, so return EFI_UNSUPPORTED.
1039 return EFI_UNSUPPORTED
;
1043 Searches for the next matching file in the firmware volume.
1045 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1046 @param SearchType Filter to find only files of this type.
1047 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
1048 @param FvHandle Handle of firmware volume in which to search.
1049 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
1050 at the beginning of the firmware volume. On exit, points the file handle of the next file
1051 in the volume or NULL if there are no more files.
1053 @retval EFI_NOT_FOUND The file was not found.
1054 @retval EFI_NOT_FOUND The header checksum was not zero.
1055 @retval EFI_SUCCESS The file was found.
1060 PeiFfsFindNextFile (
1061 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1062 IN UINT8 SearchType
,
1063 IN EFI_PEI_FV_HANDLE FvHandle
,
1064 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1067 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1069 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
1072 // To make backward compatiblity, if can not find corresponding the handle of FV
1073 // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed
1074 // to the address of first byte of FV.
1076 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1077 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1080 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
1081 return EFI_NOT_FOUND
;
1084 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
1089 Search the firmware volumes by index
1091 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1092 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
1094 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
1096 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
1097 @retval EFI_NOT_FOUND The volume was not found.
1098 @retval EFI_SUCCESS The volume was found.
1103 PeiFfsFindNextVolume (
1104 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1106 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
1109 PEI_CORE_INSTANCE
*Private
;
1110 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1112 if (VolumeHandle
== NULL
) {
1113 return EFI_INVALID_PARAMETER
;
1116 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1118 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
1119 if (CoreFvHandle
== NULL
) {
1120 *VolumeHandle
= NULL
;
1121 return EFI_NOT_FOUND
;
1124 *VolumeHandle
= CoreFvHandle
->FvHandle
;
1131 Find a file within a volume by its name.
1133 @param FileName A pointer to the name of the file to find within the firmware volume.
1134 @param VolumeHandle The firmware volume to search
1135 @param FileHandle Upon exit, points to the found file's handle
1136 or NULL if it could not be found.
1138 @retval EFI_SUCCESS File was found.
1139 @retval EFI_NOT_FOUND File was not found.
1140 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
1145 PeiFfsFindFileByName (
1146 IN CONST EFI_GUID
*FileName
,
1147 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1148 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1151 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1153 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1154 return EFI_INVALID_PARAMETER
;
1157 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
1158 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1159 return EFI_NOT_FOUND
;
1162 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
1166 Returns information about a specific file.
1168 @param FileHandle Handle of the file.
1169 @param FileInfo Upon exit, points to the file's information.
1171 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1172 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1173 @retval EFI_SUCCESS File information returned.
1179 IN EFI_PEI_FILE_HANDLE FileHandle
,
1180 OUT EFI_FV_FILE_INFO
*FileInfo
1183 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1185 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1186 return EFI_INVALID_PARAMETER
;
1190 // Retrieve the FirmwareVolume which the file resides in.
1192 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1193 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1194 return EFI_INVALID_PARAMETER
;
1197 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1201 Returns information about a specific file.
1203 @param FileHandle Handle of the file.
1204 @param FileInfo Upon exit, points to the file's information.
1206 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1207 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1208 @retval EFI_SUCCESS File information returned.
1213 PeiFfsGetFileInfo2 (
1214 IN EFI_PEI_FILE_HANDLE FileHandle
,
1215 OUT EFI_FV_FILE_INFO2
*FileInfo
1218 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1220 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1221 return EFI_INVALID_PARAMETER
;
1225 // Retrieve the FirmwareVolume which the file resides in.
1227 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1228 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1229 return EFI_INVALID_PARAMETER
;
1232 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1233 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1234 return CoreFvHandle
->FvPpi
->GetFileInfo2 (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1237 // The old FvPpi doesn't support to return file info with authentication status,
1238 // so return EFI_UNSUPPORTED.
1240 return EFI_UNSUPPORTED
;
1244 Returns information about the specified volume.
1246 This function returns information about a specific firmware
1247 volume, including its name, type, attributes, starting address
1250 @param VolumeHandle Handle of the volume.
1251 @param VolumeInfo Upon exit, points to the volume's information.
1253 @retval EFI_SUCCESS Volume information returned.
1254 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
1255 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
1256 @retval EFI_SUCCESS Information successfully returned.
1257 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
1262 PeiFfsGetVolumeInfo (
1263 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1264 OUT EFI_FV_INFO
*VolumeInfo
1267 PEI_CORE_FV_HANDLE
*CoreHandle
;
1269 if ((VolumeInfo
== NULL
) || (VolumeHandle
== NULL
)) {
1270 return EFI_INVALID_PARAMETER
;
1273 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
1275 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
1276 return EFI_INVALID_PARAMETER
;
1279 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
1283 Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.
1285 @param PrivateData PeiCore's private data structure
1286 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
1287 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
1289 @retval EFI_NOT_FOUND FV image can't be found.
1290 @retval EFI_SUCCESS Successfully to process it.
1291 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
1292 @retval EFI_SECURITY_VIOLATION Image is illegal
1293 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
1298 IN PEI_CORE_INSTANCE
*PrivateData
,
1299 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
1300 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
1304 EFI_FV_INFO ParentFvImageInfo
;
1307 EFI_PEI_HOB_POINTERS HobPtr
;
1308 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
1309 EFI_PEI_FV_HANDLE ParentFvHandle
;
1310 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
1311 EFI_FV_FILE_INFO FileInfo
;
1313 UINT32 AuthenticationStatus
;
1316 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1319 HobPtr
.Raw
= GetHobList ();
1320 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
1321 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
1323 // this FILE has been dispatched, it will not be dispatched again.
1325 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
1328 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
1331 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
1332 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
1335 // Find FvImage in FvFile
1337 AuthenticationStatus
= 0;
1338 if ((ParentFvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1339 (ParentFvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1340 Status
= ParentFvPpi
->FindSectionByType2 (
1342 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1346 &AuthenticationStatus
1349 Status
= ParentFvPpi
->FindSectionByType (
1351 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1356 if (EFI_ERROR (Status
)) {
1360 Status
= VerifyPeim (PrivateData
, ParentFvHandle
, ParentFvFileHandle
, AuthenticationStatus
);
1361 if (Status
== EFI_SECURITY_VIOLATION
) {
1366 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
1367 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
1368 // its initial linked location and maintain its alignment.
1370 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
1372 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
1374 FvAlignment
= 1 << ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ALIGNMENT
) >> 16);
1375 if (FvAlignment
< 8) {
1382 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
1383 FvLength
= ReadUnaligned64 (&FvHeader
->FvLength
);
1384 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvLength
), FvAlignment
);
1385 if (NewFvBuffer
== NULL
) {
1386 return EFI_OUT_OF_RESOURCES
;
1388 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvLength
);
1389 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
1393 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
1394 ASSERT_EFI_ERROR (Status
);
1396 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
1397 ASSERT_EFI_ERROR (Status
);
1400 // Install FvInfo(2) Ppi
1401 // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated
1402 // FVs inherit the proper AuthenticationStatus.
1404 PeiServicesInstallFvInfo2Ppi(
1405 &FvHeader
->FileSystemGuid
,
1407 (UINT32
)FvHeader
->FvLength
,
1408 &ParentFvImageInfo
.FvName
,
1410 AuthenticationStatus
1413 PeiServicesInstallFvInfoPpi (
1414 &FvHeader
->FileSystemGuid
,
1416 (UINT32
) FvHeader
->FvLength
,
1417 &ParentFvImageInfo
.FvName
,
1422 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
1425 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1430 // Makes the encapsulated volume show up in DXE phase to skip processing of
1431 // encapsulated file again.
1434 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1436 &ParentFvImageInfo
.FvName
,
1444 Process a firmware volume and create a volume handle.
1446 Create a volume handle from the information in the buffer. For
1447 memory-mapped firmware volumes, Buffer and BufferSize refer to
1448 the start of the firmware volume and the firmware volume size.
1449 For non memory-mapped firmware volumes, this points to a
1450 buffer which contains the necessary information for creating
1451 the firmware volume handle. Normally, these values are derived
1452 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
1455 @param This Points to this instance of the
1456 EFI_PEI_FIRMWARE_VOLUME_PPI.
1457 @param Buffer Points to the start of the buffer.
1458 @param BufferSize Size of the buffer.
1459 @param FvHandle Points to the returned firmware volume
1460 handle. The firmware volume handle must
1461 be unique within the system.
1463 @retval EFI_SUCCESS Firmware volume handle created.
1464 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
1469 PeiFfsFvPpiProcessVolume (
1470 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1472 IN UINTN BufferSize
,
1473 OUT EFI_PEI_FV_HANDLE
*FvHandle
1478 ASSERT (FvHandle
!= NULL
);
1480 if (Buffer
== NULL
) {
1481 return EFI_VOLUME_CORRUPTED
;
1485 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped
1486 // FV image and the handle is pointed to Fv image's buffer.
1488 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
1491 // Do verify for given FV buffer.
1493 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1494 if (EFI_ERROR(Status
)) {
1495 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1496 return EFI_VOLUME_CORRUPTED
;
1503 Finds the next file of the specified type.
1505 This service enables PEI modules to discover additional firmware files.
1506 The FileHandle must be unique within the system.
1508 @param This Points to this instance of the
1509 EFI_PEI_FIRMWARE_VOLUME_PPI.
1510 @param SearchType A filter to find only files of this type. Type
1511 EFI_FV_FILETYPE_ALL causes no filtering to be
1513 @param FvHandle Handle of firmware volume in which to
1515 @param FileHandle Points to the current handle from which to
1516 begin searching or NULL to start at the
1517 beginning of the firmware volume. Updated
1518 upon return to reflect the file found.
1520 @retval EFI_SUCCESS The file was found.
1521 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1526 PeiFfsFvPpiFindFileByType (
1527 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1528 IN EFI_FV_FILETYPE SearchType
,
1529 IN EFI_PEI_FV_HANDLE FvHandle
,
1530 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1533 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1537 Find a file within a volume by its name.
1539 This service searches for files with a specific name, within
1540 either the specified firmware volume or all firmware volumes.
1542 @param This Points to this instance of the
1543 EFI_PEI_FIRMWARE_VOLUME_PPI.
1544 @param FileName A pointer to the name of the file to find
1545 within the firmware volume.
1546 @param FvHandle Upon entry, the pointer to the firmware
1547 volume to search or NULL if all firmware
1548 volumes should be searched. Upon exit, the
1549 actual firmware volume in which the file was
1551 @param FileHandle Upon exit, points to the found file's
1552 handle or NULL if it could not be found.
1554 @retval EFI_SUCCESS File was found.
1555 @retval EFI_NOT_FOUND File was not found.
1556 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1563 PeiFfsFvPpiFindFileByName (
1564 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1565 IN CONST EFI_GUID
*FileName
,
1566 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1567 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1571 PEI_CORE_INSTANCE
*PrivateData
;
1574 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1575 return EFI_INVALID_PARAMETER
;
1578 if (*FvHandle
!= NULL
) {
1579 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1580 if (Status
== EFI_NOT_FOUND
) {
1585 // If *FvHandle = NULL, so search all FV for given filename
1587 Status
= EFI_NOT_FOUND
;
1589 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1590 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1592 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1594 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1595 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1596 if (!EFI_ERROR (Status
)) {
1597 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1608 Returns information about a specific file.
1610 This function returns information about a specific
1611 file, including its file name, type, attributes, starting
1614 @param This Points to this instance of the
1615 EFI_PEI_FIRMWARE_VOLUME_PPI.
1616 @param FileHandle Handle of the file.
1617 @param FileInfo Upon exit, points to the file's
1620 @retval EFI_SUCCESS File information returned.
1621 @retval EFI_INVALID_PARAMETER If FileHandle does not
1622 represent a valid file.
1623 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1628 PeiFfsFvPpiGetFileInfo (
1629 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1630 IN EFI_PEI_FILE_HANDLE FileHandle
,
1631 OUT EFI_FV_FILE_INFO
*FileInfo
1635 UINT8 ErasePolarity
;
1636 EFI_FFS_FILE_HEADER
*FileHeader
;
1637 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1638 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1640 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1641 return EFI_INVALID_PARAMETER
;
1645 // Retrieve the FirmwareVolume which the file resides in.
1647 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1648 if (CoreFvHandle
== NULL
) {
1649 return EFI_INVALID_PARAMETER
;
1652 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1654 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
1661 // Get FileState which is the highest bit of the State
1663 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1665 switch (FileState
) {
1666 case EFI_FILE_DATA_VALID
:
1667 case EFI_FILE_MARKED_FOR_UPDATE
:
1670 return EFI_INVALID_PARAMETER
;
1673 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1674 if (IS_FFS_FILE2 (FileHeader
)) {
1675 ASSERT (FFS_FILE2_SIZE (FileHeader
) > 0x00FFFFFF);
1676 if (!FwVolInstance
->IsFfs3Fv
) {
1677 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader
->Name
));
1678 return EFI_INVALID_PARAMETER
;
1680 FileInfo
->BufferSize
= FFS_FILE2_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1681 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
);
1683 FileInfo
->BufferSize
= FFS_FILE_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1684 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER
);
1686 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1687 FileInfo
->FileType
= FileHeader
->Type
;
1688 FileInfo
->FileAttributes
= FfsAttributes2FvFileAttributes (FileHeader
->Attributes
);
1689 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_MEMORY_MAPPED
) == EFI_FVB2_MEMORY_MAPPED
) {
1690 FileInfo
->FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
1696 Returns information about a specific file.
1698 This function returns information about a specific
1699 file, including its file name, type, attributes, starting
1700 address, size and authentication status.
1702 @param This Points to this instance of the
1703 EFI_PEI_FIRMWARE_VOLUME_PPI.
1704 @param FileHandle Handle of the file.
1705 @param FileInfo Upon exit, points to the file's
1708 @retval EFI_SUCCESS File information returned.
1709 @retval EFI_INVALID_PARAMETER If FileHandle does not
1710 represent a valid file.
1711 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1716 PeiFfsFvPpiGetFileInfo2 (
1717 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1718 IN EFI_PEI_FILE_HANDLE FileHandle
,
1719 OUT EFI_FV_FILE_INFO2
*FileInfo
1723 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1725 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1726 return EFI_INVALID_PARAMETER
;
1730 // Retrieve the FirmwareVolume which the file resides in.
1732 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1733 if (CoreFvHandle
== NULL
) {
1734 return EFI_INVALID_PARAMETER
;
1737 Status
= PeiFfsFvPpiGetFileInfo (This
, FileHandle
, (EFI_FV_FILE_INFO
*) FileInfo
);
1738 if (!EFI_ERROR (Status
)) {
1739 FileInfo
->AuthenticationStatus
= CoreFvHandle
->AuthenticationStatus
;
1746 This function returns information about the firmware volume.
1748 @param This Points to this instance of the
1749 EFI_PEI_FIRMWARE_VOLUME_PPI.
1750 @param FvHandle Handle to the firmware handle.
1751 @param VolumeInfo Points to the returned firmware volume
1754 @retval EFI_SUCCESS Information returned successfully.
1755 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1756 firmware volume or VolumeInfo is NULL.
1761 PeiFfsFvPpiGetVolumeInfo (
1762 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1763 IN EFI_PEI_FV_HANDLE FvHandle
,
1764 OUT EFI_FV_INFO
*VolumeInfo
1767 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1768 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1770 if ((VolumeInfo
== NULL
) || (FvHandle
== NULL
)) {
1771 return EFI_INVALID_PARAMETER
;
1775 // VolumeHandle may not align at 8 byte,
1776 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1777 // So, Copy FvHeader into the local FvHeader structure.
1779 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1782 // Check Fv Image Signature
1784 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1785 return EFI_INVALID_PARAMETER
;
1788 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1789 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1790 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1791 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1792 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1794 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1795 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1796 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1803 Find the next matching section in the firmware file.
1805 This service enables PEI modules to discover sections
1806 of a given type within a valid file.
1808 @param This Points to this instance of the
1809 EFI_PEI_FIRMWARE_VOLUME_PPI.
1810 @param SearchType A filter to find only sections of this
1812 @param FileHandle Handle of firmware file in which to
1814 @param SectionData Updated upon return to point to the
1817 @retval EFI_SUCCESS Section was found.
1818 @retval EFI_NOT_FOUND Section of the specified type was not
1819 found. SectionData contains NULL.
1823 PeiFfsFvPpiFindSectionByType (
1824 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1825 IN EFI_SECTION_TYPE SearchType
,
1826 IN EFI_PEI_FILE_HANDLE FileHandle
,
1827 OUT VOID
**SectionData
1830 UINT32 AuthenticationStatus
;
1831 return PeiFfsFvPpiFindSectionByType2 (This
, SearchType
, 0, FileHandle
, SectionData
, &AuthenticationStatus
);
1835 Find the next matching section in the firmware file.
1837 This service enables PEI modules to discover sections
1838 of a given instance and type within a valid file.
1840 @param This Points to this instance of the
1841 EFI_PEI_FIRMWARE_VOLUME_PPI.
1842 @param SearchType A filter to find only sections of this
1844 @param SearchInstance A filter to find the specific instance
1846 @param FileHandle Handle of firmware file in which to
1848 @param SectionData Updated upon return to point to the
1850 @param AuthenticationStatus Updated upon return to point to the
1851 authentication status for this section.
1853 @retval EFI_SUCCESS Section was found.
1854 @retval EFI_NOT_FOUND Section of the specified type was not
1855 found. SectionData contains NULL.
1859 PeiFfsFvPpiFindSectionByType2 (
1860 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1861 IN EFI_SECTION_TYPE SearchType
,
1862 IN UINTN SearchInstance
,
1863 IN EFI_PEI_FILE_HANDLE FileHandle
,
1864 OUT VOID
**SectionData
,
1865 OUT UINT32
*AuthenticationStatus
1869 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
1871 EFI_COMMON_SECTION_HEADER
*Section
;
1872 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1873 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1875 UINT32 ExtractedAuthenticationStatus
;
1877 if (SectionData
== NULL
) {
1878 return EFI_NOT_FOUND
;
1881 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1884 // Retrieve the FirmwareVolume which the file resides in.
1886 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1887 if (CoreFvHandle
== NULL
) {
1888 return EFI_NOT_FOUND
;
1891 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
1893 if (IS_FFS_FILE2 (FfsFileHeader
)) {
1894 ASSERT (FFS_FILE2_SIZE (FfsFileHeader
) > 0x00FFFFFF);
1895 if (!FwVolInstance
->IsFfs3Fv
) {
1896 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
1897 return EFI_NOT_FOUND
;
1899 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
1900 FileSize
= FFS_FILE2_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1902 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
1903 FileSize
= FFS_FILE_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1906 Instance
= SearchInstance
+ 1;
1907 ExtractedAuthenticationStatus
= 0;
1908 Status
= ProcessSection (
1909 GetPeiServicesTablePointer (),
1915 &ExtractedAuthenticationStatus
,
1916 FwVolInstance
->IsFfs3Fv
1918 if (!EFI_ERROR (Status
)) {
1920 // Inherit the authentication status.
1922 *AuthenticationStatus
= ExtractedAuthenticationStatus
| CoreFvHandle
->AuthenticationStatus
;
1928 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
1930 @param FvHandle The handle of a FV.
1932 @retval NULL if can not find.
1933 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
1935 PEI_CORE_FV_HANDLE
*
1936 FvHandleToCoreHandle (
1937 IN EFI_PEI_FV_HANDLE FvHandle
1941 PEI_CORE_INSTANCE
*PrivateData
;
1943 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1944 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1945 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
1946 return &PrivateData
->Fv
[Index
];
1954 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
1956 This routine also will install FvInfo ppi for FV hob in PI ways.
1958 @param Private Pointer of PEI_CORE_INSTANCE
1959 @param Instance The index of FV want to be searched.
1961 @return Instance of PEI_CORE_FV_HANDLE.
1963 PEI_CORE_FV_HANDLE
*
1964 FindNextCoreFvHandle (
1965 IN PEI_CORE_INSTANCE
*Private
,
1971 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
1974 // Handle Framework FvHob and Install FvInfo Ppi for it.
1976 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1978 // Loop to search the wanted FirmwareVolume which supports FFS
1980 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
1981 while (FvHob
!= NULL
) {
1983 // Search whether FvHob has been installed into PeiCore's FV database.
1984 // If found, no need install new FvInfoPpi for it.
1986 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
1987 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
1994 // Search whether FvHob has been cached into PeiCore's Unknown FV database.
1995 // If found, no need install new FvInfoPpi for it.
1998 for (Index
= 0; Index
< Private
->UnknownFvInfoCount
; Index
++) {
1999 if ((UINTN
)FvHob
->BaseAddress
== (UINTN
)Private
->UnknownFvInfo
[Index
].FvInfo
) {
2007 // If the Fv in FvHob has not been installed into PeiCore's FV database and has
2008 // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi
2009 // for it then PeiCore will dispatch it in callback of FvInfoPpi.
2012 PeiServicesInstallFvInfoPpi (
2013 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
2014 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
2015 (UINT32
)FvHob
->Length
,
2021 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
2025 ASSERT (Private
->FvCount
<= PcdGet32 (PcdPeiCoreMaxFvSupported
));
2026 if (Instance
>= Private
->FvCount
) {
2030 return &Private
->Fv
[Instance
];
2034 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
2035 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
2036 PrivateData->Fv[] array should be fixed up to be pointed to the one in permanent
2039 @param PrivateData Pointer to PEI_CORE_INSTANCE.
2043 IN PEI_CORE_INSTANCE
*PrivateData
2047 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
2052 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
2055 Status
= PeiServicesLocatePpi (
2056 &gEfiFirmwareFileSystem2Guid
,
2061 ASSERT_EFI_ERROR (Status
);
2064 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
2065 // which is shadowed from flash to permanent memory within PeiCore image.
2067 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
2068 ASSERT_EFI_ERROR (Status
);
2071 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2073 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2074 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2075 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FwVol
.Fv
;
2080 // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which
2083 Status
= PeiServicesLocatePpi (
2084 &gEfiFirmwareFileSystem3Guid
,
2089 ASSERT_EFI_ERROR (Status
);
2092 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3
2093 // which is shadowed from flash to permanent memory within PeiCore image.
2095 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs3FvPpiList
);
2096 ASSERT_EFI_ERROR (Status
);
2099 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2101 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2102 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2103 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs3FwVol
.Fv
;
2109 Report the information for a new discoveried FV in unknown third-party format.
2111 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but
2112 the FV in this format has been discoveried, then this FV's information will be cached into
2113 PEI_CORE_INSTANCE's UnknownFvInfo array.
2114 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI
2115 is installed later by platform's PEIM, the original unknown third-party FV will be processed by
2116 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2118 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2119 @param FvInfo2Ppi Point to FvInfo2 PPI.
2121 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
2122 @retval EFI_SUCCESS Success to add the information for unknown FV.
2125 AddUnknownFormatFvInfo (
2126 IN PEI_CORE_INSTANCE
*PrivateData
,
2127 IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
*FvInfo2Ppi
2130 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
2132 if (PrivateData
->UnknownFvInfoCount
+ 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2133 return EFI_OUT_OF_RESOURCES
;
2136 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
2137 PrivateData
->UnknownFvInfoCount
++;
2139 CopyGuid (&NewUnknownFv
->FvFormat
, &FvInfo2Ppi
->FvFormat
);
2140 NewUnknownFv
->FvInfo
= FvInfo2Ppi
->FvInfo
;
2141 NewUnknownFv
->FvInfoSize
= FvInfo2Ppi
->FvInfoSize
;
2142 NewUnknownFv
->AuthenticationStatus
= FvInfo2Ppi
->AuthenticationStatus
;
2143 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
2144 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
2145 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
2147 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
2152 Find the FV information according to third-party FV format guid.
2154 This routine also will remove the FV information found by given FV format guid from
2155 PrivateData->UnknownFvInfo[].
2157 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2158 @param Format Point to given FV format guid
2159 @param FvInfo On return, the pointer of FV information buffer
2160 @param FvInfoSize On return, the size of FV information buffer.
2161 @param AuthenticationStatus On return, the authentication status of FV information buffer.
2163 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
2164 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2167 FindUnknownFormatFvInfo (
2168 IN PEI_CORE_INSTANCE
*PrivateData
,
2169 IN EFI_GUID
*Format
,
2171 OUT UINT32
*FvInfoSize
,
2172 OUT UINT32
*AuthenticationStatus
2179 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
2180 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
2185 if (Index
== PrivateData
->UnknownFvInfoCount
) {
2186 return EFI_NOT_FOUND
;
2189 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
2190 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
2191 *AuthenticationStatus
= PrivateData
->UnknownFvInfo
[Index
].AuthenticationStatus
;
2194 // Remove an entry from UnknownFvInfo array.
2197 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
2198 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
2200 PrivateData
->UnknownFvInfoCount
--;
2205 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
2207 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
2208 routine is called to process all discoveried FVs in this format.
2210 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
2211 @param NotifyDescriptor Address of the notification descriptor data structure.
2212 @param Ppi Address of the PPI that was installed.
2214 @retval EFI_SUCCESS The notification callback is processed correctly.
2218 ThirdPartyFvPpiNotifyCallback (
2219 IN EFI_PEI_SERVICES
**PeiServices
,
2220 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
2224 PEI_CORE_INSTANCE
*PrivateData
;
2225 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
2228 UINT32 AuthenticationStatus
;
2230 EFI_PEI_FV_HANDLE FvHandle
;
2231 BOOLEAN IsProcessed
;
2233 EFI_PEI_FILE_HANDLE FileHandle
;
2237 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
2238 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
2241 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
, &AuthenticationStatus
);
2242 if (EFI_ERROR (Status
)) {
2247 // Process new found FV and get FV handle.
2249 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
2250 if (EFI_ERROR (Status
)) {
2251 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
2256 // Check whether the FV has already been processed.
2258 IsProcessed
= FALSE
;
2259 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
2260 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
2261 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo
));
2271 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2272 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
2273 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
2278 // Update internal PEI_CORE_FV array.
2280 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
2281 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
2282 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
2283 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= AuthenticationStatus
;
2284 CurFvCount
= PrivateData
->FvCount
;
2287 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
2288 (UINT32
) CurFvCount
,
2293 PrivateData
->FvCount
++;
2296 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
2300 Status
= FvPpi
->FindFileByType (
2302 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
2306 if (!EFI_ERROR (Status
)) {
2307 Status
= FvPpi
->FindSectionByType (
2309 EFI_SECTION_PEI_DEPEX
,
2313 if (!EFI_ERROR (Status
)) {
2314 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
2316 // Dependency is not satisfied.
2322 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, CurFvCount
, FvHandle
));
2323 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[CurFvCount
], FileHandle
);
2325 } while (FileHandle
!= NULL
);