2 Pei Core Firmware File System service routines.
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList
[] = {
19 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
20 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
21 FirmwareVolmeInfoPpiNotifyCallback
24 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
25 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
26 FirmwareVolmeInfoPpiNotifyCallback
30 PEI_FW_VOL_INSTANCE mPeiFfs2FwVol
= {
34 PeiFfsFvPpiProcessVolume
,
35 PeiFfsFvPpiFindFileByType
,
36 PeiFfsFvPpiFindFileByName
,
37 PeiFfsFvPpiGetFileInfo
,
38 PeiFfsFvPpiGetVolumeInfo
,
39 PeiFfsFvPpiFindSectionByType
,
40 PeiFfsFvPpiGetFileInfo2
,
41 PeiFfsFvPpiFindSectionByType2
,
42 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
43 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
47 PEI_FW_VOL_INSTANCE mPeiFfs3FwVol
= {
51 PeiFfsFvPpiProcessVolume
,
52 PeiFfsFvPpiFindFileByType
,
53 PeiFfsFvPpiFindFileByName
,
54 PeiFfsFvPpiGetFileInfo
,
55 PeiFfsFvPpiGetVolumeInfo
,
56 PeiFfsFvPpiFindSectionByType
,
57 PeiFfsFvPpiGetFileInfo2
,
58 PeiFfsFvPpiFindSectionByType2
,
59 EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
,
60 EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
64 EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList
= {
65 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
66 &gEfiFirmwareFileSystem2Guid
,
70 EFI_PEI_PPI_DESCRIPTOR mPeiFfs3FvPpiList
= {
71 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
72 &gEfiFirmwareFileSystem3Guid
,
77 Required Alignment Alignment Value in FFS Alignment Value in
78 (bytes) Attributes Field Firmware Volume Interfaces
88 UINT8 mFvAttributes
[] = {0, 4, 7, 9, 10, 12, 15, 16};
91 Convert the FFS File Attributes to FV File Attributes
93 @param FfsAttributes The attributes of UINT8 type.
95 @return The attributes of EFI_FV_FILE_ATTRIBUTES
98 EFI_FV_FILE_ATTRIBUTES
99 FfsAttributes2FvFileAttributes (
100 IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
104 EFI_FV_FILE_ATTRIBUTES FileAttribute
;
106 DataAlignment
= (UINT8
) ((FfsAttributes
& FFS_ATTRIB_DATA_ALIGNMENT
) >> 3);
107 ASSERT (DataAlignment
< 8);
109 FileAttribute
= (EFI_FV_FILE_ATTRIBUTES
) mFvAttributes
[DataAlignment
];
111 if ((FfsAttributes
& FFS_ATTRIB_FIXED
) == FFS_ATTRIB_FIXED
) {
112 FileAttribute
|= EFI_FV_FILE_ATTRIB_FIXED
;
115 return FileAttribute
;
119 Returns the file state set by the highest zero bit in the State field
121 @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
122 in the Attributes field.
123 @param FfsHeader Pointer to FFS File Header.
125 @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit
126 in the header State field.
130 IN UINT8 ErasePolarity
,
131 IN EFI_FFS_FILE_HEADER
*FfsHeader
134 EFI_FFS_FILE_STATE FileState
;
135 EFI_FFS_FILE_STATE HighestBit
;
137 FileState
= FfsHeader
->State
;
139 if (ErasePolarity
!= 0) {
140 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
144 // Get file state set by its highest none zero bit.
147 while (HighestBit
!= 0 && (HighestBit
& FileState
) == 0) {
155 Calculates the checksum of the header of a file.
157 @param FileHeader Pointer to FFS File Header.
159 @return Checksum of the header.
160 Zero means the header is good.
161 Non-zero means the header is bad.
164 CalculateHeaderChecksum (
165 IN EFI_FFS_FILE_HEADER
*FileHeader
168 EFI_FFS_FILE_HEADER2 TestFileHeader
;
170 if (IS_FFS_FILE2 (FileHeader
)) {
171 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
173 // Ingore State and File field in FFS header.
175 TestFileHeader
.State
= 0;
176 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
178 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER2
));
180 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
182 // Ingore State and File field in FFS header.
184 TestFileHeader
.State
= 0;
185 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
187 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
192 Find FV handler according to FileHandle in that FV.
194 @param FileHandle Handle of file image
196 @return Pointer to instance of PEI_CORE_FV_HANDLE.
200 IN EFI_PEI_FILE_HANDLE FileHandle
204 PEI_CORE_INSTANCE
*PrivateData
;
205 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
207 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
209 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
210 FwVolHeader
= PrivateData
->Fv
[Index
].FvHeader
;
211 if (((UINT64
) (UINTN
) FileHandle
> (UINT64
) (UINTN
) FwVolHeader
) && \
212 ((UINT64
) (UINTN
) FileHandle
<= ((UINT64
) (UINTN
) FwVolHeader
+ FwVolHeader
->FvLength
- 1))) {
213 return &PrivateData
->Fv
[Index
];
220 Given the input file pointer, search for the first matching file in the
221 FFS volume as defined by SearchType. The search starts from FileHeader inside
222 the Firmware Volume defined by FwVolHeader.
223 If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.
224 If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
225 the first PEIM, or COMBINED PEIM or FV file type FFS file will return.
227 @param FvHandle Pointer to the FV header of the volume to search
228 @param FileName File name
229 @param SearchType Filter to find only files of this type.
230 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
231 @param FileHandle This parameter must point to a valid FFS volume.
232 @param AprioriFile Pointer to AprioriFile image in this FV if has
234 @return EFI_NOT_FOUND No files matching the search criteria were found
235 @retval EFI_SUCCESS Success to search given file
240 IN CONST EFI_PEI_FV_HANDLE FvHandle
,
241 IN CONST EFI_GUID
*FileName
, OPTIONAL
242 IN EFI_FV_FILETYPE SearchType
,
243 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
,
244 IN OUT EFI_PEI_FILE_HANDLE
*AprioriFile OPTIONAL
247 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
248 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExtHeader
;
249 EFI_FFS_FILE_HEADER
**FileHeader
;
250 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
252 UINT32 FileOccupiedSize
;
261 // Convert the handle of FV to FV header for memory-mapped firmware volume
263 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvHandle
;
264 FileHeader
= (EFI_FFS_FILE_HEADER
**)FileHandle
;
266 IsFfs3Fv
= CompareGuid (&FwVolHeader
->FileSystemGuid
, &gEfiFirmwareFileSystem3Guid
);
268 FvLength
= FwVolHeader
->FvLength
;
269 if ((FwVolHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
276 // If FileHeader is not specified (NULL) or FileName is not NULL,
277 // start with the first file in the firmware volume. Otherwise,
278 // start from the FileHeader.
280 if ((*FileHeader
== NULL
) || (FileName
!= NULL
)) {
281 if (FwVolHeader
->ExtHeaderOffset
!= 0) {
283 // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
285 FwVolExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*) ((UINT8
*) FwVolHeader
+ FwVolHeader
->ExtHeaderOffset
);
286 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FwVolExtHeader
+ FwVolExtHeader
->ExtHeaderSize
);
287 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ALIGN_POINTER (FfsFileHeader
, 8);
289 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*) FwVolHeader
+ FwVolHeader
->HeaderLength
);
292 if (IS_FFS_FILE2 (*FileHeader
)) {
294 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &(*FileHeader
)->Name
));
296 FileLength
= FFS_FILE2_SIZE (*FileHeader
);
297 ASSERT (FileLength
> 0x00FFFFFF);
299 FileLength
= FFS_FILE_SIZE (*FileHeader
);
302 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
304 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
305 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)*FileHeader
+ FileOccupiedSize
);
308 FileOffset
= (UINT32
) ((UINT8
*)FfsFileHeader
- (UINT8
*)FwVolHeader
);
309 ASSERT (FileOffset
<= 0xFFFFFFFF);
311 while (FileOffset
< (FvLength
- sizeof (EFI_FFS_FILE_HEADER
))) {
313 // Get FileState which is the highest bit of the State
315 FileState
= GetFileState (ErasePolarity
, FfsFileHeader
);
318 case EFI_FILE_HEADER_CONSTRUCTION
:
319 case EFI_FILE_HEADER_INVALID
:
320 if (IS_FFS_FILE2 (FfsFileHeader
)) {
322 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
324 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER2
);
325 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
327 FileOffset
+= sizeof (EFI_FFS_FILE_HEADER
);
328 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
332 case EFI_FILE_DATA_VALID
:
333 case EFI_FILE_MARKED_FOR_UPDATE
:
334 if (CalculateHeaderChecksum (FfsFileHeader
) != 0) {
337 return EFI_NOT_FOUND
;
340 if (IS_FFS_FILE2 (FfsFileHeader
)) {
341 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
342 ASSERT (FileLength
> 0x00FFFFFF);
343 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
345 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
346 FileOffset
+= FileOccupiedSize
;
347 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*) ((UINT8
*) FfsFileHeader
+ FileOccupiedSize
);
351 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
352 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
355 DataCheckSum
= FFS_FIXED_CHECKSUM
;
356 if ((FfsFileHeader
->Attributes
& FFS_ATTRIB_CHECKSUM
) == FFS_ATTRIB_CHECKSUM
) {
357 if (IS_FFS_FILE2 (FfsFileHeader
)) {
358 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
), FileLength
- sizeof(EFI_FFS_FILE_HEADER2
));
360 DataCheckSum
= CalculateCheckSum8 ((CONST UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
), FileLength
- sizeof(EFI_FFS_FILE_HEADER
));
363 if (FfsFileHeader
->IntegrityCheck
.Checksum
.File
!= DataCheckSum
) {
366 return EFI_NOT_FOUND
;
369 if (FileName
!= NULL
) {
370 if (CompareGuid (&FfsFileHeader
->Name
, (EFI_GUID
*)FileName
)) {
371 *FileHeader
= FfsFileHeader
;
374 } else if (SearchType
== PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
) {
375 if ((FfsFileHeader
->Type
== EFI_FV_FILETYPE_PEIM
) ||
376 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
) ||
377 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
379 *FileHeader
= FfsFileHeader
;
381 } else if (AprioriFile
!= NULL
) {
382 if (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
383 if (CompareGuid (&FfsFileHeader
->Name
, &gPeiAprioriFileNameGuid
)) {
384 *AprioriFile
= FfsFileHeader
;
388 } else if (((SearchType
== FfsFileHeader
->Type
) || (SearchType
== EFI_FV_FILETYPE_ALL
)) &&
389 (FfsFileHeader
->Type
!= EFI_FV_FILETYPE_FFS_PAD
)) {
390 *FileHeader
= FfsFileHeader
;
394 FileOffset
+= FileOccupiedSize
;
395 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
398 case EFI_FILE_DELETED
:
399 if (IS_FFS_FILE2 (FfsFileHeader
)) {
401 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
403 FileLength
= FFS_FILE2_SIZE (FfsFileHeader
);
404 ASSERT (FileLength
> 0x00FFFFFF);
406 FileLength
= FFS_FILE_SIZE (FfsFileHeader
);
408 FileOccupiedSize
= GET_OCCUPIED_SIZE(FileLength
, 8);
409 FileOffset
+= FileOccupiedSize
;
410 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
415 return EFI_NOT_FOUND
;
420 return EFI_NOT_FOUND
;
424 Initialize PeiCore Fv List.
426 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
427 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
431 IN PEI_CORE_INSTANCE
*PrivateData
,
432 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
436 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
437 EFI_PEI_FV_HANDLE FvHandle
;
438 EFI_FIRMWARE_VOLUME_HEADER
*BfvHeader
;
441 // Install FV_PPI for FFS2 file system.
443 PeiServicesInstallPpi (&mPeiFfs2FvPpiList
);
446 // Install FV_PPI for FFS3 file system.
448 PeiServicesInstallPpi (&mPeiFfs3FvPpiList
);
450 BfvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
453 // The FV_PPI in BFV's format should be installed.
455 Status
= PeiServicesLocatePpi (
456 &BfvHeader
->FileSystemGuid
,
461 ASSERT_EFI_ERROR (Status
);
466 FvPpi
->ProcessVolume (
468 SecCoreData
->BootFirmwareVolumeBase
,
469 (UINTN
)BfvHeader
->FvLength
,
474 // Update internal PEI_CORE_FV array.
476 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= BfvHeader
;
477 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
478 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
479 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= 0;
482 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
483 (UINT32
) PrivateData
->FvCount
,
488 PrivateData
->FvCount
++;
491 // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose
492 // additional Fvs to PeiCore.
494 Status
= PeiServicesNotifyPpi (mNotifyOnFvInfoList
);
495 ASSERT_EFI_ERROR (Status
);
500 Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.
501 The FV Info will be registered into PeiCore private data structure.
502 And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.
504 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
505 @param NotifyDescriptor Address of the notification descriptor data structure.
506 @param Ppi Address of the PPI that was installed.
508 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
509 @return if not EFI_SUCESS, fail to verify FV.
514 FirmwareVolmeInfoPpiNotifyCallback (
515 IN EFI_PEI_SERVICES
**PeiServices
,
516 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
520 EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI FvInfo2Ppi
;
521 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
522 PEI_CORE_INSTANCE
*PrivateData
;
524 EFI_PEI_FV_HANDLE FvHandle
;
526 EFI_PEI_FILE_HANDLE FileHandle
;
530 Status
= EFI_SUCCESS
;
531 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
533 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
534 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
535 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
539 if (CompareGuid (NotifyDescriptor
->Guid
, &gEfiPeiFirmwareVolumeInfo2PpiGuid
)) {
543 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
));
549 CopyMem (&FvInfo2Ppi
, Ppi
, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
550 FvInfo2Ppi
.AuthenticationStatus
= 0;
555 // Locate the corresponding FV_PPI according to founded FV's format guid
557 Status
= PeiServicesLocatePpi (
558 &FvInfo2Ppi
.FvFormat
,
563 if (!EFI_ERROR (Status
)) {
565 // Process new found FV and get FV handle.
567 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo2Ppi
.FvInfo
, FvInfo2Ppi
.FvInfoSize
, &FvHandle
);
568 if (EFI_ERROR (Status
)) {
569 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!\n"));
574 // Check whether the FV has already been processed.
576 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
577 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
578 if (IsFvInfo2
&& (FvInfo2Ppi
.AuthenticationStatus
!= PrivateData
->Fv
[FvIndex
].AuthenticationStatus
)) {
579 PrivateData
->Fv
[FvIndex
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
580 DEBUG ((EFI_D_INFO
, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex
, FvInfo2Ppi
.AuthenticationStatus
));
582 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo2Ppi
.FvInfo
));
588 // Update internal PEI_CORE_FV array.
590 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo2Ppi
.FvInfo
;
591 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
592 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
593 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= FvInfo2Ppi
.AuthenticationStatus
;
596 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
597 (UINT32
) PrivateData
->FvCount
,
598 (VOID
*) FvInfo2Ppi
.FvInfo
,
599 FvInfo2Ppi
.FvInfoSize
,
602 PrivateData
->FvCount
++;
605 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
609 Status
= FvPpi
->FindFileByType (
611 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
615 if (!EFI_ERROR (Status
)) {
616 Status
= FvPpi
->FindSectionByType (
618 EFI_SECTION_PEI_DEPEX
,
622 if (!EFI_ERROR (Status
)) {
623 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
625 // Dependency is not satisfied.
631 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
632 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
634 } while (FileHandle
!= NULL
);
636 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi
.FvInfo
));
638 AddUnknownFormatFvInfo (PrivateData
, &FvInfo2Ppi
);
645 Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.
647 @param GuidedSectionGuid The Guided Section GUID.
648 @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi
649 for the Guided Section.
651 @return TRUE The GuidedSectionGuid could be identified, and the pointer to
652 the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.
653 @return FALSE The GuidedSectionGuid could not be identified, or
654 the Guided Section Extraction Ppi has not been installed yet.
658 VerifyGuidedSectionGuid (
659 IN EFI_GUID
*GuidedSectionGuid
,
660 OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
**GuidedSectionExtraction
663 EFI_PEI_HOB_POINTERS Hob
;
664 EFI_GUID
*GuidRecorded
;
669 // Check if there is the Guided Section GUID HOB recorded the GUID itself.
671 Hob
.Raw
= GetFirstGuidHob (GuidedSectionGuid
);
672 if (Hob
.Raw
!= NULL
) {
673 GuidRecorded
= (EFI_GUID
*) GET_GUID_HOB_DATA (Hob
);
674 if (CompareGuid (GuidRecorded
, GuidedSectionGuid
)) {
676 // Found the recorded GuidedSectionGuid.
678 Status
= PeiServicesLocatePpi (GuidedSectionGuid
, 0, NULL
, (VOID
**) &Interface
);
679 if (!EFI_ERROR (Status
) && Interface
!= NULL
) {
681 // Found the supported Guided Section Extraction Ppi for the Guided Section.
683 *GuidedSectionExtraction
= (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*) Interface
;
694 Go through the file to search SectionType section.
695 Search within encapsulation sections (compression and GUIDed) recursively,
696 until the match section is found.
698 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
699 @param SectionType Filter to find only section of this type.
700 @param SectionInstance Pointer to the filter to find the specific instance of section.
701 @param Section From where to search.
702 @param SectionSize The file size to search.
703 @param OutputBuffer A pointer to the discovered section, if successful.
704 NULL if section not found
705 @param AuthenticationStatus Updated upon return to point to the authentication status for this section.
706 @param IsFfs3Fv Indicates the FV format.
708 @return EFI_NOT_FOUND The match section is not found.
709 @return EFI_SUCCESS The match section is found.
714 IN CONST EFI_PEI_SERVICES
**PeiServices
,
715 IN EFI_SECTION_TYPE SectionType
,
716 IN OUT UINTN
*SectionInstance
,
717 IN EFI_COMMON_SECTION_HEADER
*Section
,
718 IN UINTN SectionSize
,
719 OUT VOID
**OutputBuffer
,
720 OUT UINT32
*AuthenticationStatus
,
725 UINT32 SectionLength
;
727 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
728 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
732 UINT32 Authentication
;
733 PEI_CORE_INSTANCE
*PrivateData
;
734 EFI_GUID
*SectionDefinitionGuid
;
735 BOOLEAN SectionCached
;
736 VOID
*TempOutputBuffer
;
737 UINT32 TempAuthenticationStatus
;
738 UINT16 GuidedSectionAttributes
;
740 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
741 *OutputBuffer
= NULL
;
744 Status
= EFI_NOT_FOUND
;
747 while (ParsedLength
< SectionSize
) {
749 if (IS_SECTION2 (Section
)) {
750 ASSERT (SECTION2_SIZE (Section
) > 0x00FFFFFF);
752 DEBUG ((EFI_D_ERROR
, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
753 SectionLength
= SECTION2_SIZE (Section
);
755 // SectionLength is adjusted it is 4 byte aligned.
756 // Go to the next section
758 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
759 ASSERT (SectionLength
!= 0);
760 ParsedLength
+= SectionLength
;
761 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) Section
+ SectionLength
);
766 if (Section
->Type
== SectionType
) {
768 // The type matches, so check the instance count to see if it's the one we want.
770 (*SectionInstance
)--;
771 if (*SectionInstance
== 0) {
775 if (IS_SECTION2 (Section
)) {
776 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
778 *OutputBuffer
= (VOID
*)((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
782 if (IS_SECTION2 (Section
)) {
783 SectionLength
= SECTION2_SIZE (Section
);
785 SectionLength
= SECTION_SIZE (Section
);
788 // SectionLength is adjusted it is 4 byte aligned.
789 // Go to the next section
791 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
792 ASSERT (SectionLength
!= 0);
793 ParsedLength
+= SectionLength
;
794 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
797 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
799 // Check the encapsulated section is extracted into the cache data.
801 SectionCached
= FALSE
;
802 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
803 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
804 SectionCached
= TRUE
;
805 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
806 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
807 Authentication
= PrivateData
->CacheSection
.AuthenticationStatus
[Index
];
809 // Search section directly from the cache data.
811 TempAuthenticationStatus
= 0;
812 Status
= ProcessSection (
819 &TempAuthenticationStatus
,
822 if (!EFI_ERROR (Status
)) {
823 *OutputBuffer
= TempOutputBuffer
;
824 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
831 // If SectionCached is TRUE, the section data has been cached and scanned.
833 if (!SectionCached
) {
834 Status
= EFI_NOT_FOUND
;
836 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
837 if (IS_SECTION2 (Section
)) {
838 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION2
*)Section
)->SectionDefinitionGuid
;
839 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION2
*)Section
)->Attributes
;
841 SectionDefinitionGuid
= &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
;
842 GuidedSectionAttributes
= ((EFI_GUID_DEFINED_SECTION
*)Section
)->Attributes
;
844 if (VerifyGuidedSectionGuid (SectionDefinitionGuid
, &GuidSectionPpi
)) {
845 Status
= GuidSectionPpi
->ExtractSection (
852 } else if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) == 0) {
854 // Figure out the proper authentication status for GUIDED section without processing required
856 Status
= EFI_SUCCESS
;
857 if ((GuidedSectionAttributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) {
858 Authentication
|= EFI_AUTH_STATUS_IMAGE_SIGNED
| EFI_AUTH_STATUS_NOT_TESTED
;
860 if (IS_SECTION2 (Section
)) {
861 PpiOutputSize
= SECTION2_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
862 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION2
*) Section
)->DataOffset
;
864 PpiOutputSize
= SECTION_SIZE (Section
) - ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
865 PpiOutput
= (UINT8
*) Section
+ ((EFI_GUID_DEFINED_SECTION
*) Section
)->DataOffset
;
868 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
869 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
870 if (!EFI_ERROR (Status
)) {
871 Status
= DecompressPpi
->Decompress (
873 (CONST EFI_COMPRESSION_SECTION
*) Section
,
880 if (!EFI_ERROR (Status
)) {
882 // Update cache section data.
884 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
885 PrivateData
->CacheSection
.AllSectionCount
++;
887 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
888 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
889 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
890 PrivateData
->CacheSection
.AuthenticationStatus
[PrivateData
->CacheSection
.SectionIndex
] = Authentication
;
891 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
893 TempAuthenticationStatus
= 0;
894 Status
= ProcessSection (
901 &TempAuthenticationStatus
,
904 if (!EFI_ERROR (Status
)) {
905 *OutputBuffer
= TempOutputBuffer
;
906 *AuthenticationStatus
= TempAuthenticationStatus
| Authentication
;
913 if (IS_SECTION2 (Section
)) {
914 SectionLength
= SECTION2_SIZE (Section
);
916 SectionLength
= SECTION_SIZE (Section
);
919 // SectionLength is adjusted it is 4 byte aligned.
920 // Go to the next section
922 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
923 ASSERT (SectionLength
!= 0);
924 ParsedLength
+= SectionLength
;
925 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
928 return EFI_NOT_FOUND
;
933 Searches for the next matching section within the specified file.
935 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
936 @param SectionType Filter to find only sections of this type.
937 @param FileHandle Pointer to the current file to search.
938 @param SectionData A pointer to the discovered section, if successful.
939 NULL if section not found
941 @retval EFI_NOT_FOUND The section was not found.
942 @retval EFI_SUCCESS The section was found.
947 PeiFfsFindSectionData (
948 IN CONST EFI_PEI_SERVICES
**PeiServices
,
949 IN EFI_SECTION_TYPE SectionType
,
950 IN EFI_PEI_FILE_HANDLE FileHandle
,
951 OUT VOID
**SectionData
954 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
956 CoreFvHandle
= FileHandleToVolume (FileHandle
);
957 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
958 return EFI_NOT_FOUND
;
961 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
965 Searches for the next matching section within the specified file.
967 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
968 @param SectionType The value of the section type to find.
969 @param SectionInstance Section instance to find.
970 @param FileHandle Handle of the firmware file to search.
971 @param SectionData A pointer to the discovered section, if successful.
972 @param AuthenticationStatus A pointer to the authentication status for this section.
974 @retval EFI_SUCCESS The section was found.
975 @retval EFI_NOT_FOUND The section was not found.
980 PeiFfsFindSectionData3 (
981 IN CONST EFI_PEI_SERVICES
**PeiServices
,
982 IN EFI_SECTION_TYPE SectionType
,
983 IN UINTN SectionInstance
,
984 IN EFI_PEI_FILE_HANDLE FileHandle
,
985 OUT VOID
**SectionData
,
986 OUT UINT32
*AuthenticationStatus
989 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
991 CoreFvHandle
= FileHandleToVolume (FileHandle
);
992 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
993 return EFI_NOT_FOUND
;
996 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
997 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
998 return CoreFvHandle
->FvPpi
->FindSectionByType2 (CoreFvHandle
->FvPpi
, SectionType
, SectionInstance
, FileHandle
, SectionData
, AuthenticationStatus
);
1001 // The old FvPpi doesn't support to find section by section instance
1002 // and return authentication status, so return EFI_UNSUPPORTED.
1004 return EFI_UNSUPPORTED
;
1008 Searches for the next matching file in the firmware volume.
1010 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1011 @param SearchType Filter to find only files of this type.
1012 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
1013 @param FvHandle Handle of firmware volume in which to search.
1014 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
1015 at the beginning of the firmware volume. On exit, points the file handle of the next file
1016 in the volume or NULL if there are no more files.
1018 @retval EFI_NOT_FOUND The file was not found.
1019 @retval EFI_NOT_FOUND The header checksum was not zero.
1020 @retval EFI_SUCCESS The file was found.
1025 PeiFfsFindNextFile (
1026 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1027 IN UINT8 SearchType
,
1028 IN EFI_PEI_FV_HANDLE FvHandle
,
1029 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1032 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1034 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
1037 // To make backward compatiblity, if can not find corresponding the handle of FV
1038 // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed
1039 // to the address of first byte of FV.
1041 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1042 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1045 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
1046 return EFI_NOT_FOUND
;
1049 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
1054 Search the firmware volumes by index
1056 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1057 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
1059 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
1061 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
1062 @retval EFI_NOT_FOUND The volume was not found.
1063 @retval EFI_SUCCESS The volume was found.
1068 PeiFfsFindNextVolume (
1069 IN CONST EFI_PEI_SERVICES
**PeiServices
,
1071 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
1074 PEI_CORE_INSTANCE
*Private
;
1075 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1077 if (VolumeHandle
== NULL
) {
1078 return EFI_INVALID_PARAMETER
;
1081 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1083 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
1084 if (CoreFvHandle
== NULL
) {
1085 *VolumeHandle
= NULL
;
1086 return EFI_NOT_FOUND
;
1089 *VolumeHandle
= CoreFvHandle
->FvHandle
;
1096 Find a file within a volume by its name.
1098 @param FileName A pointer to the name of the file to find within the firmware volume.
1099 @param VolumeHandle The firmware volume to search
1100 @param FileHandle Upon exit, points to the found file's handle
1101 or NULL if it could not be found.
1103 @retval EFI_SUCCESS File was found.
1104 @retval EFI_NOT_FOUND File was not found.
1105 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
1110 PeiFfsFindFileByName (
1111 IN CONST EFI_GUID
*FileName
,
1112 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1113 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1116 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1118 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1119 return EFI_INVALID_PARAMETER
;
1122 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
1123 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1124 return EFI_NOT_FOUND
;
1127 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
1131 Returns information about a specific file.
1133 @param FileHandle Handle of the file.
1134 @param FileInfo Upon exit, points to the file's information.
1136 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1137 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
1138 @retval EFI_SUCCESS File information returned.
1144 IN EFI_PEI_FILE_HANDLE FileHandle
,
1145 OUT EFI_FV_FILE_INFO
*FileInfo
1148 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1150 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1151 return EFI_INVALID_PARAMETER
;
1155 // Retrieve the FirmwareVolume which the file resides in.
1157 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1158 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
1159 return EFI_INVALID_PARAMETER
;
1162 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
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.
1178 PeiFfsGetFileInfo2 (
1179 IN EFI_PEI_FILE_HANDLE FileHandle
,
1180 OUT EFI_FV_FILE_INFO2
*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 if ((CoreFvHandle
->FvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1198 (CoreFvHandle
->FvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1199 return CoreFvHandle
->FvPpi
->GetFileInfo2 (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
1202 // The old FvPpi doesn't support to return file info with authentication status,
1203 // so return EFI_UNSUPPORTED.
1205 return EFI_UNSUPPORTED
;
1209 Returns information about the specified volume.
1211 This function returns information about a specific firmware
1212 volume, including its name, type, attributes, starting address
1215 @param VolumeHandle Handle of the volume.
1216 @param VolumeInfo Upon exit, points to the volume's information.
1218 @retval EFI_SUCCESS Volume information returned.
1219 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
1220 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
1221 @retval EFI_SUCCESS Information successfully returned.
1222 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
1227 PeiFfsGetVolumeInfo (
1228 IN EFI_PEI_FV_HANDLE VolumeHandle
,
1229 OUT EFI_FV_INFO
*VolumeInfo
1232 PEI_CORE_FV_HANDLE
*CoreHandle
;
1234 if ((VolumeInfo
== NULL
) || (VolumeHandle
== NULL
)) {
1235 return EFI_INVALID_PARAMETER
;
1238 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
1240 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
1241 return EFI_INVALID_PARAMETER
;
1244 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
1248 Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.
1250 @param PrivateData PeiCore's private data structure
1251 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
1252 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
1254 @retval EFI_NOT_FOUND FV image can't be found.
1255 @retval EFI_SUCCESS Successfully to process it.
1256 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
1257 @retval EFI_SECURITY_VIOLATION Image is illegal
1258 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
1263 IN PEI_CORE_INSTANCE
*PrivateData
,
1264 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
1265 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
1269 EFI_FV_INFO ParentFvImageInfo
;
1272 EFI_PEI_HOB_POINTERS HobPtr
;
1273 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
1274 EFI_PEI_FV_HANDLE ParentFvHandle
;
1275 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
1276 EFI_FV_FILE_INFO FileInfo
;
1278 UINT32 AuthenticationStatus
;
1281 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1284 HobPtr
.Raw
= GetHobList ();
1285 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
1286 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
1288 // this FILE has been dispatched, it will not be dispatched again.
1290 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
1293 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
1296 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
1297 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
1300 // Find FvImage in FvFile
1302 AuthenticationStatus
= 0;
1303 if ((ParentFvPpi
->Signature
== EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE
) &&
1304 (ParentFvPpi
->Revision
== EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION
)) {
1305 Status
= ParentFvPpi
->FindSectionByType2 (
1307 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1311 &AuthenticationStatus
1314 Status
= ParentFvPpi
->FindSectionByType (
1316 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
1321 if (EFI_ERROR (Status
)) {
1325 Status
= VerifyPeim (PrivateData
, ParentFvHandle
, ParentFvFileHandle
, AuthenticationStatus
);
1326 if (Status
== EFI_SECURITY_VIOLATION
) {
1331 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
1332 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
1333 // its initial linked location and maintain its alignment.
1335 if ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
1337 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
1339 FvAlignment
= 1 << ((ReadUnaligned32 (&FvHeader
->Attributes
) & EFI_FVB2_ALIGNMENT
) >> 16);
1340 if (FvAlignment
< 8) {
1347 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
1348 FvLength
= ReadUnaligned64 (&FvHeader
->FvLength
);
1349 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvLength
), FvAlignment
);
1350 if (NewFvBuffer
== NULL
) {
1351 return EFI_OUT_OF_RESOURCES
;
1353 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvLength
);
1354 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
1358 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
1359 ASSERT_EFI_ERROR (Status
);
1361 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
1362 ASSERT_EFI_ERROR (Status
);
1365 // Install FvInfo(2) Ppi
1367 PeiServicesInstallFvInfoPpi (
1368 &FvHeader
->FileSystemGuid
,
1370 (UINT32
) FvHeader
->FvLength
,
1371 &ParentFvImageInfo
.FvName
,
1375 PeiServicesInstallFvInfo2Ppi (
1376 &FvHeader
->FileSystemGuid
,
1378 (UINT32
) FvHeader
->FvLength
,
1379 &ParentFvImageInfo
.FvName
,
1381 AuthenticationStatus
1385 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
1388 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1393 // Makes the encapsulated volume show up in DXE phase to skip processing of
1394 // encapsulated file again.
1397 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
1399 &ParentFvImageInfo
.FvName
,
1407 Process a firmware volume and create a volume handle.
1409 Create a volume handle from the information in the buffer. For
1410 memory-mapped firmware volumes, Buffer and BufferSize refer to
1411 the start of the firmware volume and the firmware volume size.
1412 For non memory-mapped firmware volumes, this points to a
1413 buffer which contains the necessary information for creating
1414 the firmware volume handle. Normally, these values are derived
1415 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
1418 @param This Points to this instance of the
1419 EFI_PEI_FIRMWARE_VOLUME_PPI.
1420 @param Buffer Points to the start of the buffer.
1421 @param BufferSize Size of the buffer.
1422 @param FvHandle Points to the returned firmware volume
1423 handle. The firmware volume handle must
1424 be unique within the system.
1426 @retval EFI_SUCCESS Firmware volume handle created.
1427 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
1432 PeiFfsFvPpiProcessVolume (
1433 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1435 IN UINTN BufferSize
,
1436 OUT EFI_PEI_FV_HANDLE
*FvHandle
1441 ASSERT (FvHandle
!= NULL
);
1443 if (Buffer
== NULL
) {
1444 return EFI_VOLUME_CORRUPTED
;
1448 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped
1449 // FV image and the handle is pointed to Fv image's buffer.
1451 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
1454 // Do verify for given FV buffer.
1456 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1457 if (EFI_ERROR(Status
)) {
1458 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1459 return EFI_VOLUME_CORRUPTED
;
1466 Finds the next file of the specified type.
1468 This service enables PEI modules to discover additional firmware files.
1469 The FileHandle must be unique within the system.
1471 @param This Points to this instance of the
1472 EFI_PEI_FIRMWARE_VOLUME_PPI.
1473 @param SearchType A filter to find only files of this type. Type
1474 EFI_FV_FILETYPE_ALL causes no filtering to be
1476 @param FvHandle Handle of firmware volume in which to
1478 @param FileHandle Points to the current handle from which to
1479 begin searching or NULL to start at the
1480 beginning of the firmware volume. Updated
1481 upon return to reflect the file found.
1483 @retval EFI_SUCCESS The file was found.
1484 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1489 PeiFfsFvPpiFindFileByType (
1490 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1491 IN EFI_FV_FILETYPE SearchType
,
1492 IN EFI_PEI_FV_HANDLE FvHandle
,
1493 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1496 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1500 Find a file within a volume by its name.
1502 This service searches for files with a specific name, within
1503 either the specified firmware volume or all firmware volumes.
1505 @param This Points to this instance of the
1506 EFI_PEI_FIRMWARE_VOLUME_PPI.
1507 @param FileName A pointer to the name of the file to find
1508 within the firmware volume.
1509 @param FvHandle Upon entry, the pointer to the firmware
1510 volume to search or NULL if all firmware
1511 volumes should be searched. Upon exit, the
1512 actual firmware volume in which the file was
1514 @param FileHandle Upon exit, points to the found file's
1515 handle or NULL if it could not be found.
1517 @retval EFI_SUCCESS File was found.
1518 @retval EFI_NOT_FOUND File was not found.
1519 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1526 PeiFfsFvPpiFindFileByName (
1527 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1528 IN CONST EFI_GUID
*FileName
,
1529 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1530 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1534 PEI_CORE_INSTANCE
*PrivateData
;
1537 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1538 return EFI_INVALID_PARAMETER
;
1541 if (*FvHandle
!= NULL
) {
1542 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1543 if (Status
== EFI_NOT_FOUND
) {
1548 // If *FvHandle = NULL, so search all FV for given filename
1550 Status
= EFI_NOT_FOUND
;
1552 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1553 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1555 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1557 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1558 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1559 if (!EFI_ERROR (Status
)) {
1560 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1571 Returns information about a specific file.
1573 This function returns information about a specific
1574 file, including its file name, type, attributes, starting
1577 @param This Points to this instance of the
1578 EFI_PEI_FIRMWARE_VOLUME_PPI.
1579 @param FileHandle Handle of the file.
1580 @param FileInfo Upon exit, points to the file's
1583 @retval EFI_SUCCESS File information returned.
1584 @retval EFI_INVALID_PARAMETER If FileHandle does not
1585 represent a valid file.
1586 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1591 PeiFfsFvPpiGetFileInfo (
1592 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1593 IN EFI_PEI_FILE_HANDLE FileHandle
,
1594 OUT EFI_FV_FILE_INFO
*FileInfo
1598 UINT8 ErasePolarity
;
1599 EFI_FFS_FILE_HEADER
*FileHeader
;
1600 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1601 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1603 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1604 return EFI_INVALID_PARAMETER
;
1608 // Retrieve the FirmwareVolume which the file resides in.
1610 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1611 if (CoreFvHandle
== NULL
) {
1612 return EFI_INVALID_PARAMETER
;
1615 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1617 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
1624 // Get FileState which is the highest bit of the State
1626 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1628 switch (FileState
) {
1629 case EFI_FILE_DATA_VALID
:
1630 case EFI_FILE_MARKED_FOR_UPDATE
:
1633 return EFI_INVALID_PARAMETER
;
1636 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1637 if (IS_FFS_FILE2 (FileHeader
)) {
1638 ASSERT (FFS_FILE2_SIZE (FileHeader
) > 0x00FFFFFF);
1639 if (!FwVolInstance
->IsFfs3Fv
) {
1640 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader
->Name
));
1641 return EFI_INVALID_PARAMETER
;
1643 FileInfo
->BufferSize
= FFS_FILE2_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1644 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
);
1646 FileInfo
->BufferSize
= FFS_FILE_SIZE (FileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1647 FileInfo
->Buffer
= (UINT8
*) FileHeader
+ sizeof (EFI_FFS_FILE_HEADER
);
1649 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1650 FileInfo
->FileType
= FileHeader
->Type
;
1651 FileInfo
->FileAttributes
= FfsAttributes2FvFileAttributes (FileHeader
->Attributes
);
1652 if ((CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_MEMORY_MAPPED
) == EFI_FVB2_MEMORY_MAPPED
) {
1653 FileInfo
->FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
1659 Returns information about a specific file.
1661 This function returns information about a specific
1662 file, including its file name, type, attributes, starting
1663 address, size and authentication status.
1665 @param This Points to this instance of the
1666 EFI_PEI_FIRMWARE_VOLUME_PPI.
1667 @param FileHandle Handle of the file.
1668 @param FileInfo Upon exit, points to the file's
1671 @retval EFI_SUCCESS File information returned.
1672 @retval EFI_INVALID_PARAMETER If FileHandle does not
1673 represent a valid file.
1674 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1679 PeiFfsFvPpiGetFileInfo2 (
1680 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1681 IN EFI_PEI_FILE_HANDLE FileHandle
,
1682 OUT EFI_FV_FILE_INFO2
*FileInfo
1686 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1688 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1689 return EFI_INVALID_PARAMETER
;
1693 // Retrieve the FirmwareVolume which the file resides in.
1695 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1696 if (CoreFvHandle
== NULL
) {
1697 return EFI_INVALID_PARAMETER
;
1700 Status
= PeiFfsFvPpiGetFileInfo (This
, FileHandle
, (EFI_FV_FILE_INFO
*) FileInfo
);
1701 if (!EFI_ERROR (Status
)) {
1702 FileInfo
->AuthenticationStatus
= CoreFvHandle
->AuthenticationStatus
;
1709 This function returns information about the firmware volume.
1711 @param This Points to this instance of the
1712 EFI_PEI_FIRMWARE_VOLUME_PPI.
1713 @param FvHandle Handle to the firmware handle.
1714 @param VolumeInfo Points to the returned firmware volume
1717 @retval EFI_SUCCESS Information returned successfully.
1718 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1719 firmware volume or VolumeInfo is NULL.
1724 PeiFfsFvPpiGetVolumeInfo (
1725 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1726 IN EFI_PEI_FV_HANDLE FvHandle
,
1727 OUT EFI_FV_INFO
*VolumeInfo
1730 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1731 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1733 if ((VolumeInfo
== NULL
) || (FvHandle
== NULL
)) {
1734 return EFI_INVALID_PARAMETER
;
1738 // VolumeHandle may not align at 8 byte,
1739 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1740 // So, Copy FvHeader into the local FvHeader structure.
1742 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1745 // Check Fv Image Signature
1747 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1748 return EFI_INVALID_PARAMETER
;
1751 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1752 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1753 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1754 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1755 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1757 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1758 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1759 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1766 Find the next matching section in the firmware file.
1768 This service enables PEI modules to discover sections
1769 of a given type within a valid file.
1771 @param This Points to this instance of the
1772 EFI_PEI_FIRMWARE_VOLUME_PPI.
1773 @param SearchType A filter to find only sections of this
1775 @param FileHandle Handle of firmware file in which to
1777 @param SectionData Updated upon return to point to the
1780 @retval EFI_SUCCESS Section was found.
1781 @retval EFI_NOT_FOUND Section of the specified type was not
1782 found. SectionData contains NULL.
1786 PeiFfsFvPpiFindSectionByType (
1787 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1788 IN EFI_SECTION_TYPE SearchType
,
1789 IN EFI_PEI_FILE_HANDLE FileHandle
,
1790 OUT VOID
**SectionData
1793 UINT32 AuthenticationStatus
;
1794 return PeiFfsFvPpiFindSectionByType2 (This
, SearchType
, 0, FileHandle
, SectionData
, &AuthenticationStatus
);
1798 Find the next matching section in the firmware file.
1800 This service enables PEI modules to discover sections
1801 of a given instance and type within a valid file.
1803 @param This Points to this instance of the
1804 EFI_PEI_FIRMWARE_VOLUME_PPI.
1805 @param SearchType A filter to find only sections of this
1807 @param SearchInstance A filter to find the specific instance
1809 @param FileHandle Handle of firmware file in which to
1811 @param SectionData Updated upon return to point to the
1813 @param AuthenticationStatus Updated upon return to point to the
1814 authentication status for this section.
1816 @retval EFI_SUCCESS Section was found.
1817 @retval EFI_NOT_FOUND Section of the specified type was not
1818 found. SectionData contains NULL.
1822 PeiFfsFvPpiFindSectionByType2 (
1823 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1824 IN EFI_SECTION_TYPE SearchType
,
1825 IN UINTN SearchInstance
,
1826 IN EFI_PEI_FILE_HANDLE FileHandle
,
1827 OUT VOID
**SectionData
,
1828 OUT UINT32
*AuthenticationStatus
1832 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
1834 EFI_COMMON_SECTION_HEADER
*Section
;
1835 PEI_FW_VOL_INSTANCE
*FwVolInstance
;
1836 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1838 UINT32 ExtractedAuthenticationStatus
;
1840 if (SectionData
== NULL
) {
1841 return EFI_NOT_FOUND
;
1844 FwVolInstance
= PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This
);
1847 // Retrieve the FirmwareVolume which the file resides in.
1849 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1850 if (CoreFvHandle
== NULL
) {
1851 return EFI_NOT_FOUND
;
1854 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
1856 if (IS_FFS_FILE2 (FfsFileHeader
)) {
1857 ASSERT (FFS_FILE2_SIZE (FfsFileHeader
) > 0x00FFFFFF);
1858 if (!FwVolInstance
->IsFfs3Fv
) {
1859 DEBUG ((EFI_D_ERROR
, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader
->Name
));
1860 return EFI_NOT_FOUND
;
1862 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER2
));
1863 FileSize
= FFS_FILE2_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER2
);
1865 Section
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) FfsFileHeader
+ sizeof (EFI_FFS_FILE_HEADER
));
1866 FileSize
= FFS_FILE_SIZE (FfsFileHeader
) - sizeof (EFI_FFS_FILE_HEADER
);
1869 Instance
= SearchInstance
+ 1;
1870 ExtractedAuthenticationStatus
= 0;
1871 Status
= ProcessSection (
1872 GetPeiServicesTablePointer (),
1878 &ExtractedAuthenticationStatus
,
1879 FwVolInstance
->IsFfs3Fv
1881 if (!EFI_ERROR (Status
)) {
1883 // Inherit the authentication status.
1885 *AuthenticationStatus
= ExtractedAuthenticationStatus
| CoreFvHandle
->AuthenticationStatus
;
1891 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
1893 @param FvHandle The handle of a FV.
1895 @retval NULL if can not find.
1896 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
1898 PEI_CORE_FV_HANDLE
*
1899 FvHandleToCoreHandle (
1900 IN EFI_PEI_FV_HANDLE FvHandle
1904 PEI_CORE_INSTANCE
*PrivateData
;
1906 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1907 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1908 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
1909 return &PrivateData
->Fv
[Index
];
1917 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
1919 This routine also will install FvInfo ppi for FV hob in PI ways.
1921 @param Private Pointer of PEI_CORE_INSTANCE
1922 @param Instance The index of FV want to be searched.
1924 @return Instance of PEI_CORE_FV_HANDLE.
1926 PEI_CORE_FV_HANDLE
*
1927 FindNextCoreFvHandle (
1928 IN PEI_CORE_INSTANCE
*Private
,
1934 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
1937 // Handle Framework FvHob and Install FvInfo Ppi for it.
1939 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1941 // Loop to search the wanted FirmwareVolume which supports FFS
1943 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
1944 while (FvHob
!= NULL
) {
1946 // Search whether FvHob has been installed into PeiCore's FV database.
1947 // If found, no need install new FvInfoPpi for it.
1949 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
1950 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
1957 // Search whether FvHob has been cached into PeiCore's Unknown FV database.
1958 // If found, no need install new FvInfoPpi for it.
1961 for (Index
= 0; Index
< Private
->UnknownFvInfoCount
; Index
++) {
1962 if ((UINTN
)FvHob
->BaseAddress
== (UINTN
)Private
->UnknownFvInfo
[Index
].FvInfo
) {
1970 // If the Fv in FvHob has not been installed into PeiCore's FV database and has
1971 // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi
1972 // for it then PeiCore will dispatch it in callback of FvInfoPpi.
1975 PeiServicesInstallFvInfoPpi (
1976 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
1977 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
1978 (UINT32
)FvHob
->Length
,
1984 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
1988 ASSERT (Private
->FvCount
<= PcdGet32 (PcdPeiCoreMaxFvSupported
));
1989 if (Instance
>= Private
->FvCount
) {
1993 return &Private
->Fv
[Instance
];
1997 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
1998 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
1999 PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant
2002 @param PrivateData Pointer to PEI_CORE_INSTANCE.
2006 IN PEI_CORE_INSTANCE
*PrivateData
2010 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
2015 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
2018 Status
= PeiServicesLocatePpi (
2019 &gEfiFirmwareFileSystem2Guid
,
2024 ASSERT_EFI_ERROR (Status
);
2027 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
2028 // which is shadowed from flash to permanent memory within PeiCore image.
2030 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
2031 ASSERT_EFI_ERROR (Status
);
2034 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2036 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2037 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2038 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FwVol
.Fv
;
2043 // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which
2046 Status
= PeiServicesLocatePpi (
2047 &gEfiFirmwareFileSystem3Guid
,
2052 ASSERT_EFI_ERROR (Status
);
2055 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3
2056 // which is shadowed from flash to permanent memory within PeiCore image.
2058 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs3FvPpiList
);
2059 ASSERT_EFI_ERROR (Status
);
2062 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
2064 for (Index
= 0; Index
< PcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
2065 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfsFvPpi
) {
2066 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs3FwVol
.Fv
;
2072 Report the information for a new discoveried FV in unknown third-party format.
2074 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but
2075 the FV in this format has been discoveried, then this FV's information will be cached into
2076 PEI_CORE_INSTANCE's UnknownFvInfo array.
2077 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI
2078 is installed later by platform's PEIM, the original unknown third-party FV will be processed by
2079 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2081 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2082 @param FvInfo2Ppi Point to FvInfo2 PPI.
2084 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
2085 @retval EFI_SUCCESS Success to add the information for unknown FV.
2088 AddUnknownFormatFvInfo (
2089 IN PEI_CORE_INSTANCE
*PrivateData
,
2090 IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI
*FvInfo2Ppi
2093 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
2095 if (PrivateData
->UnknownFvInfoCount
+ 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2096 return EFI_OUT_OF_RESOURCES
;
2099 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
2100 PrivateData
->UnknownFvInfoCount
++;
2102 CopyGuid (&NewUnknownFv
->FvFormat
, &FvInfo2Ppi
->FvFormat
);
2103 NewUnknownFv
->FvInfo
= FvInfo2Ppi
->FvInfo
;
2104 NewUnknownFv
->FvInfoSize
= FvInfo2Ppi
->FvInfoSize
;
2105 NewUnknownFv
->AuthenticationStatus
= FvInfo2Ppi
->AuthenticationStatus
;
2106 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
2107 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
2108 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
2110 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
2115 Find the FV information according to third-party FV format guid.
2117 This routine also will remove the FV information found by given FV format guid from
2118 PrivateData->UnknownFvInfo[].
2120 @param PrivateData Point to instance of PEI_CORE_INSTANCE
2121 @param Format Point to given FV format guid
2122 @param FvInfo On return, the pointer of FV information buffer
2123 @param FvInfoSize On return, the size of FV information buffer.
2124 @param AuthenticationStatus On return, the authentication status of FV information buffer.
2126 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
2127 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
2130 FindUnknownFormatFvInfo (
2131 IN PEI_CORE_INSTANCE
*PrivateData
,
2132 IN EFI_GUID
*Format
,
2134 OUT UINT32
*FvInfoSize
,
2135 OUT UINT32
*AuthenticationStatus
2142 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
2143 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
2148 if (Index
== PrivateData
->UnknownFvInfoCount
) {
2149 return EFI_NOT_FOUND
;
2152 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
2153 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
2154 *AuthenticationStatus
= PrivateData
->UnknownFvInfo
[Index
].AuthenticationStatus
;
2157 // Remove an entry from UnknownFvInfo array.
2160 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
2161 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
2163 PrivateData
->UnknownFvInfoCount
--;
2168 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
2170 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
2171 routine is called to process all discoveried FVs in this format.
2173 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
2174 @param NotifyDescriptor Address of the notification descriptor data structure.
2175 @param Ppi Address of the PPI that was installed.
2177 @retval EFI_SUCCESS The notification callback is processed correctly.
2181 ThirdPartyFvPpiNotifyCallback (
2182 IN EFI_PEI_SERVICES
**PeiServices
,
2183 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
2187 PEI_CORE_INSTANCE
*PrivateData
;
2188 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
2191 UINT32 AuthenticationStatus
;
2193 EFI_PEI_FV_HANDLE FvHandle
;
2194 BOOLEAN IsProcessed
;
2196 EFI_PEI_FILE_HANDLE FileHandle
;
2199 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
2200 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
2203 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
, &AuthenticationStatus
);
2204 if (EFI_ERROR (Status
)) {
2209 // Process new found FV and get FV handle.
2211 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
2212 if (EFI_ERROR (Status
)) {
2213 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
2218 // Check whether the FV has already been processed.
2220 IsProcessed
= FALSE
;
2221 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
2222 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
2223 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo
));
2233 if (PrivateData
->FvCount
>= PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
2234 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, PcdGet32 (PcdPeiCoreMaxFvSupported
)));
2235 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
2240 // Update internal PEI_CORE_FV array.
2242 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
2243 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
2244 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
2245 PrivateData
->Fv
[PrivateData
->FvCount
].AuthenticationStatus
= AuthenticationStatus
;
2248 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
2249 (UINT32
) PrivateData
->FvCount
,
2254 PrivateData
->FvCount
++;
2257 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
2261 Status
= FvPpi
->FindFileByType (
2263 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
2267 if (!EFI_ERROR (Status
)) {
2268 Status
= FvPpi
->FindSectionByType (
2270 EFI_SECTION_PEI_DEPEX
,
2274 if (!EFI_ERROR (Status
)) {
2275 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
2277 // Dependency is not satisfied.
2283 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
2284 ProcessFvFile (PrivateData
, &PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
2286 } while (FileHandle
!= NULL
);