2 Pei Core Firmware File System service routines.
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. 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
= {
18 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
19 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
20 FirmwareVolmeInfoPpiNotifyCallback
23 EFI_PEI_FIRMWARE_VOLUME_PPI mPeiFfs2FvPpi
= {
24 PeiFfs2FvPpiProcessVolume
,
25 PeiFfs2FvPpiFindFileByType
,
26 PeiFfs2FvPpiFindFileByName
,
27 PeiFfs2FvPpiGetFileInfo
,
28 PeiFfs2FvPpiGetVolumeInfo
,
29 PeiFfs2FvPpiFindSectionByType
32 EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList
= {
33 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
34 &gEfiFirmwareFileSystem2Guid
,
39 Returns the file state set by the highest zero bit in the State field
41 @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
42 in the Attributes field.
43 @param FfsHeader Pointer to FFS File Header.
45 @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit
46 in the header State field.
50 IN UINT8 ErasePolarity
,
51 IN EFI_FFS_FILE_HEADER
*FfsHeader
54 EFI_FFS_FILE_STATE FileState
;
55 EFI_FFS_FILE_STATE HighestBit
;
57 FileState
= FfsHeader
->State
;
59 if (ErasePolarity
!= 0) {
60 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
64 // Get file state set by its highest none zero bit.
67 while (HighestBit
!= 0 && (HighestBit
& FileState
) == 0) {
75 Calculates the checksum of the header of a file.
77 @param FileHeader Pointer to FFS File Header.
79 @return Checksum of the header.
80 Zero means the header is good.
81 Non-zero means the header is bad.
84 CalculateHeaderChecksum (
85 IN EFI_FFS_FILE_HEADER
*FileHeader
88 EFI_FFS_FILE_HEADER TestFileHeader
;
90 CopyMem (&TestFileHeader
, FileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
92 // Ingore State and File field in FFS header.
94 TestFileHeader
.State
= 0;
95 TestFileHeader
.IntegrityCheck
.Checksum
.File
= 0;
97 return CalculateSum8 ((CONST UINT8
*) &TestFileHeader
, sizeof (EFI_FFS_FILE_HEADER
));
101 Find FV handler according to FileHandle in that FV.
103 @param FileHandle Handle of file image
105 @return Pointer to instance of PEI_CORE_FV_HANDLE.
109 IN EFI_PEI_FILE_HANDLE FileHandle
113 PEI_CORE_INSTANCE
*PrivateData
;
114 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
116 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
118 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
119 FwVolHeader
= PrivateData
->Fv
[Index
].FvHeader
;
120 if (((UINT64
) (UINTN
) FileHandle
> (UINT64
) (UINTN
) FwVolHeader
) && \
121 ((UINT64
) (UINTN
) FileHandle
<= ((UINT64
) (UINTN
) FwVolHeader
+ FwVolHeader
->FvLength
- 1))) {
122 return &PrivateData
->Fv
[Index
];
129 Given the input file pointer, search for the first matching file in the
130 FFS volume as defined by SearchType. The search starts from FileHeader inside
131 the Firmware Volume defined by FwVolHeader.
132 If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.
133 If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
134 the first PEIM, or COMBINED PEIM or FV file type FFS file will return.
136 @param FvHandle Pointer to the FV header of the volume to search
137 @param FileName File name
138 @param SearchType Filter to find only files of this type.
139 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
140 @param FileHandle This parameter must point to a valid FFS volume.
141 @param AprioriFile Pointer to AprioriFile image in this FV if has
143 @return EFI_NOT_FOUND No files matching the search criteria were found
144 @retval EFI_SUCCESS Success to search given file
149 IN CONST EFI_PEI_FV_HANDLE FvHandle
,
150 IN CONST EFI_GUID
*FileName
, OPTIONAL
151 IN EFI_FV_FILETYPE SearchType
,
152 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
,
153 IN OUT EFI_PEI_FV_HANDLE
*AprioriFile OPTIONAL
156 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
157 EFI_FFS_FILE_HEADER
**FileHeader
;
158 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
160 UINT32 FileOccupiedSize
;
167 // Convert the handle of FV to FV header for memory-mapped firmware volume
169 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvHandle
;
170 FileHeader
= (EFI_FFS_FILE_HEADER
**)FileHandle
;
172 FvLength
= FwVolHeader
->FvLength
;
173 if ((FwVolHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) != 0) {
180 // If FileHeader is not specified (NULL) or FileName is not NULL,
181 // start with the first file in the firmware volume. Otherwise,
182 // start from the FileHeader.
184 if ((*FileHeader
== NULL
) || (FileName
!= NULL
)) {
185 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FwVolHeader
+ FwVolHeader
->HeaderLength
);
188 // Length is 24 bits wide so mask upper 8 bits
189 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
191 FileLength
= *(UINT32
*)(*FileHeader
)->Size
& 0x00FFFFFF;
192 FileOccupiedSize
= GET_OCCUPIED_SIZE (FileLength
, 8);
193 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)*FileHeader
+ FileOccupiedSize
);
196 FileOffset
= (UINT32
) ((UINT8
*)FfsFileHeader
- (UINT8
*)FwVolHeader
);
197 ASSERT (FileOffset
<= 0xFFFFFFFF);
199 while (FileOffset
< (FvLength
- sizeof (EFI_FFS_FILE_HEADER
))) {
201 // Get FileState which is the highest bit of the State
203 FileState
= GetFileState (ErasePolarity
, FfsFileHeader
);
206 case EFI_FILE_HEADER_INVALID
:
207 FileOffset
+= sizeof(EFI_FFS_FILE_HEADER
);
208 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ sizeof(EFI_FFS_FILE_HEADER
));
211 case EFI_FILE_DATA_VALID
:
212 case EFI_FILE_MARKED_FOR_UPDATE
:
213 if (CalculateHeaderChecksum (FfsFileHeader
) != 0) {
216 return EFI_NOT_FOUND
;
219 FileLength
= *(UINT32
*)(FfsFileHeader
->Size
) & 0x00FFFFFF;
220 FileOccupiedSize
= GET_OCCUPIED_SIZE(FileLength
, 8);
222 if (FileName
!= NULL
) {
223 if (CompareGuid (&FfsFileHeader
->Name
, (EFI_GUID
*)FileName
)) {
224 *FileHeader
= FfsFileHeader
;
227 } else if (SearchType
== PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
) {
228 if ((FfsFileHeader
->Type
== EFI_FV_FILETYPE_PEIM
) ||
229 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
) ||
230 (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
)) {
232 *FileHeader
= FfsFileHeader
;
234 } else if (AprioriFile
!= NULL
) {
235 if (FfsFileHeader
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
236 if (CompareGuid (&FfsFileHeader
->Name
, &gPeiAprioriFileNameGuid
)) {
237 *AprioriFile
= FfsFileHeader
;
241 } else if (((SearchType
== FfsFileHeader
->Type
) || (SearchType
== EFI_FV_FILETYPE_ALL
)) &&
242 (FfsFileHeader
->Type
!= EFI_FV_FILETYPE_FFS_PAD
)) {
243 *FileHeader
= FfsFileHeader
;
247 FileOffset
+= FileOccupiedSize
;
248 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
251 case EFI_FILE_DELETED
:
252 FileLength
= *(UINT32
*)(FfsFileHeader
->Size
) & 0x00FFFFFF;
253 FileOccupiedSize
= GET_OCCUPIED_SIZE(FileLength
, 8);
254 FileOffset
+= FileOccupiedSize
;
255 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)((UINT8
*)FfsFileHeader
+ FileOccupiedSize
);
260 return EFI_NOT_FOUND
;
265 return EFI_NOT_FOUND
;
269 Initialize PeiCore Fv List.
271 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
272 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
276 IN PEI_CORE_INSTANCE
*PrivateData
,
277 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
281 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
282 EFI_PEI_FV_HANDLE FvHandle
;
283 EFI_FIRMWARE_VOLUME_HEADER
*BfvHeader
;
286 // Install FV_PPI for FFS2 file system.
288 PeiServicesInstallPpi (&mPeiFfs2FvPpiList
);
290 BfvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
293 // The FV_PPI in BFV's format should be installed.
295 Status
= PeiServicesLocatePpi (
296 &BfvHeader
->FileSystemGuid
,
301 ASSERT_EFI_ERROR (Status
);
306 FvPpi
->ProcessVolume (
308 SecCoreData
->BootFirmwareVolumeBase
,
309 (UINTN
)BfvHeader
->FvLength
,
314 // Update internal PEI_CORE_FV array.
316 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= BfvHeader
;
317 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
318 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
321 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
322 (UINT32
) PrivateData
->FvCount
,
327 PrivateData
->FvCount
++;
330 // Post a call-back for the FvInfoPPI services to expose
331 // additional Fvs to PeiCore.
333 Status
= PeiServicesNotifyPpi (&mNotifyOnFvInfoList
);
334 ASSERT_EFI_ERROR (Status
);
339 Process Firmware Volum Information once FvInfoPPI install.
340 The FV Info will be registered into PeiCore private data structure.
341 And search the inside FV image, if found, the new FV INFO PPI will be installed.
343 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
344 @param NotifyDescriptor Address of the notification descriptor data structure.
345 @param Ppi Address of the PPI that was installed.
347 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
348 @return if not EFI_SUCESS, fail to verify FV.
353 FirmwareVolmeInfoPpiNotifyCallback (
354 IN EFI_PEI_SERVICES
**PeiServices
,
355 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
359 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*FvInfoPpi
;
360 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
361 PEI_CORE_INSTANCE
*PrivateData
;
363 EFI_PEI_FV_HANDLE FvHandle
;
365 EFI_PEI_FILE_HANDLE FileHandle
;
368 Status
= EFI_SUCCESS
;
369 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
371 if (PrivateData
->FvCount
>= FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)) {
372 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)));
373 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
377 FvInfoPpi
= (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*)Ppi
;
380 // Locate the corresponding FV_PPI according to founded FV's format guid
382 Status
= PeiServicesLocatePpi (
383 &FvInfoPpi
->FvFormat
,
388 if (!EFI_ERROR (Status
)) {
390 // Process new found FV and get FV handle.
392 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfoPpi
->FvInfo
, FvInfoPpi
->FvInfoSize
, &FvHandle
);
393 if (EFI_ERROR (Status
)) {
394 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!\n"));
399 // Check whether the FV has already been processed.
401 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
402 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
403 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfoPpi
->FvInfo
));
409 // Update internal PEI_CORE_FV array.
411 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfoPpi
->FvInfo
;
412 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
413 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
416 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
417 (UINT32
) PrivateData
->FvCount
,
418 (VOID
*) FvInfoPpi
->FvInfo
,
419 FvInfoPpi
->FvInfoSize
,
422 PrivateData
->FvCount
++;
425 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
429 Status
= FvPpi
->FindFileByType (
431 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
435 if (!EFI_ERROR (Status
)) {
436 Status
= FvPpi
->FindSectionByType (
438 EFI_SECTION_PEI_DEPEX
,
442 if (!EFI_ERROR (Status
)) {
443 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
445 // Dependency is not satisfied.
451 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
452 ProcessFvFile (&PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
454 } while (FileHandle
!= NULL
);
456 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfoPpi
->FvInfo
));
458 AddUnknownFormatFvInfo (PrivateData
, &FvInfoPpi
->FvFormat
, FvInfoPpi
->FvInfo
, FvInfoPpi
->FvInfoSize
);
465 Go through the file to search SectionType section.
466 Search within encapsulation sections (compression and GUIDed) recursively,
467 until the match section is found.
469 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
470 @param SectionType Filter to find only section of this type.
471 @param Section From where to search.
472 @param SectionSize The file size to search.
473 @param OutputBuffer A pointer to the discovered section, if successful.
474 NULL if section not found
476 @return EFI_NOT_FOUND The match section is not found.
477 @return EFI_SUCCESS The match section is found.
482 IN CONST EFI_PEI_SERVICES
**PeiServices
,
483 IN EFI_SECTION_TYPE SectionType
,
484 IN EFI_COMMON_SECTION_HEADER
*Section
,
485 IN UINTN SectionSize
,
486 OUT VOID
**OutputBuffer
490 UINT32 SectionLength
;
492 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
493 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
497 UINT32 Authentication
;
498 PEI_CORE_INSTANCE
*PrivateData
;
500 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
501 *OutputBuffer
= NULL
;
504 Status
= EFI_NOT_FOUND
;
507 while (ParsedLength
< SectionSize
) {
508 if (Section
->Type
== SectionType
) {
509 *OutputBuffer
= (VOID
*)(Section
+ 1);
511 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
513 // Check the encapsulated section is extracted into the cache data.
515 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
516 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
517 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
518 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
520 // Search section directly from the cache data.
522 return ProcessSection (
532 Status
= EFI_NOT_FOUND
;
533 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
534 Status
= PeiServicesLocatePpi (
535 &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
,
538 (VOID
**) &GuidSectionPpi
540 if (!EFI_ERROR (Status
)) {
541 Status
= GuidSectionPpi
->ExtractSection (
549 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
550 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
551 if (!EFI_ERROR (Status
)) {
552 Status
= DecompressPpi
->Decompress (
554 (CONST EFI_COMPRESSION_SECTION
*) Section
,
561 if (!EFI_ERROR (Status
)) {
563 // Update cache section data.
565 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
566 PrivateData
->CacheSection
.AllSectionCount
++;
568 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
569 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
570 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
571 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
573 return ProcessSection (
584 // Size is 24 bits wide so mask upper 8 bits.
585 // SectionLength is adjusted it is 4 byte aligned.
586 // Go to the next section
588 SectionLength
= *(UINT32
*)Section
->Size
& 0x00FFFFFF;
589 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
590 ASSERT (SectionLength
!= 0);
591 ParsedLength
+= SectionLength
;
592 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
595 return EFI_NOT_FOUND
;
600 Searches for the next matching section within the specified file.
602 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
603 @param SectionType Filter to find only sections of this type.
604 @param FileHandle Pointer to the current file to search.
605 @param SectionData A pointer to the discovered section, if successful.
606 NULL if section not found
608 @retval EFI_NOT_FOUND The section was not found.
609 @retval EFI_SUCCESS The section was found.
614 PeiFfsFindSectionData (
615 IN CONST EFI_PEI_SERVICES
**PeiServices
,
616 IN EFI_SECTION_TYPE SectionType
,
617 IN EFI_PEI_FILE_HANDLE FileHandle
,
618 OUT VOID
**SectionData
621 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
623 CoreFvHandle
= FileHandleToVolume (FileHandle
);
624 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
625 return EFI_NOT_FOUND
;
628 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
632 Searches for the next matching file in the firmware volume.
634 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
635 @param SearchType Filter to find only files of this type.
636 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
637 @param VolumeHandle Handle of firmware volume in which to search.
638 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
639 at the beginning of the firmware volume. On exit, points the file handle of the next file
640 in the volume or NULL if there are no more files.
642 @retval EFI_NOT_FOUND The file was not found.
643 @retval EFI_NOT_FOUND The header checksum was not zero.
644 @retval EFI_SUCCESS The file was found.
650 IN CONST EFI_PEI_SERVICES
**PeiServices
,
652 IN EFI_PEI_FV_HANDLE FvHandle
,
653 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
656 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
658 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
661 // To make backward compatiblity, if can not find corresponding the handle of FV
662 // then treat FV as build-in FFS2 format and memory mapped FV that FV handle is pointed
663 // to the address of first byte of FV.
665 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
666 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
669 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
670 return EFI_NOT_FOUND
;
673 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
678 Search the firmware volumes by index
680 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
681 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
683 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
685 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
686 @retval EFI_NOT_FOUND The volume was not found.
687 @retval EFI_SUCCESS The volume was found.
692 PeiFfsFindNextVolume (
693 IN CONST EFI_PEI_SERVICES
**PeiServices
,
695 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
698 PEI_CORE_INSTANCE
*Private
;
699 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
701 if (VolumeHandle
== NULL
) {
702 return EFI_INVALID_PARAMETER
;
705 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
707 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
708 if (CoreFvHandle
== NULL
) {
709 *VolumeHandle
= NULL
;
710 return EFI_NOT_FOUND
;
713 *VolumeHandle
= CoreFvHandle
->FvHandle
;
720 Find a file within a volume by its name.
722 @param FileName A pointer to the name of the file to find within the firmware volume.
723 @param VolumeHandle The firmware volume to search
724 @param FileHandle Upon exit, points to the found file's handle
725 or NULL if it could not be found.
727 @retval EFI_SUCCESS File was found.
728 @retval EFI_NOT_FOUND File was not found.
729 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
734 PeiFfsFindFileByName (
735 IN CONST EFI_GUID
*FileName
,
736 IN EFI_PEI_FV_HANDLE VolumeHandle
,
737 OUT EFI_PEI_FILE_HANDLE
*FileHandle
740 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
742 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
743 return EFI_INVALID_PARAMETER
;
746 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
747 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
748 return EFI_NOT_FOUND
;
751 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
755 Returns information about a specific file.
757 @param FileHandle Handle of the file.
758 @param FileInfo Upon exit, points to the file’s information.
760 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
761 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
762 @retval EFI_SUCCESS File information returned.
768 IN EFI_PEI_FILE_HANDLE FileHandle
,
769 OUT EFI_FV_FILE_INFO
*FileInfo
772 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
774 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
775 return EFI_INVALID_PARAMETER
;
779 // Retrieve the FirmwareVolume which the file resides in.
781 CoreFvHandle
= FileHandleToVolume (FileHandle
);
782 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
783 return EFI_INVALID_PARAMETER
;
786 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
791 Returns information about the specified volume.
793 This function returns information about a specific firmware
794 volume, including its name, type, attributes, starting address
797 @param VolumeHandle Handle of the volume.
798 @param VolumeInfo Upon exit, points to the volume's information.
800 @retval EFI_SUCCESS Volume information returned.
801 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
802 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
803 @retval EFI_SUCCESS Information successfully returned.
804 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
809 PeiFfsGetVolumeInfo (
810 IN EFI_PEI_FV_HANDLE VolumeHandle
,
811 OUT EFI_FV_INFO
*VolumeInfo
814 PEI_CORE_FV_HANDLE
*CoreHandle
;
816 if (VolumeInfo
== NULL
) {
817 return EFI_INVALID_PARAMETER
;
820 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
822 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
823 return EFI_INVALID_PARAMETER
;
826 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
830 Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.
832 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
833 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
835 @retval EFI_NOT_FOUND FV image can't be found.
836 @retval EFI_SUCCESS Successfully to process it.
837 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
838 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
843 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
844 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
848 EFI_FV_INFO ParentFvImageInfo
;
851 EFI_PEI_HOB_POINTERS HobPtr
;
852 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
853 EFI_PEI_FV_HANDLE ParentFvHandle
;
854 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
855 EFI_FV_FILE_INFO FileInfo
;
858 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
861 HobPtr
.Raw
= GetHobList ();
862 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
863 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
865 // this FILE has been dispatched, it will not be dispatched again.
867 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
870 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
873 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
874 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
877 // Find FvImage in FvFile
879 Status
= ParentFvPpi
->FindSectionByType (
881 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
886 if (EFI_ERROR (Status
)) {
891 // FvAlignment must be more than 8 bytes required by FvHeader structure.
893 FvAlignment
= 1 << ((FvHeader
->Attributes
& EFI_FVB2_ALIGNMENT
) >> 16);
894 if (FvAlignment
< 8) {
901 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
902 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvHeader
->FvLength
), FvAlignment
);
903 if (NewFvBuffer
== NULL
) {
904 return EFI_OUT_OF_RESOURCES
;
906 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvHeader
->FvLength
);
907 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
910 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
911 ASSERT_EFI_ERROR (Status
);
913 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
914 ASSERT_EFI_ERROR (Status
);
917 // Install FvPpi and Build FvHob
919 PeiServicesInstallFvInfoPpi (
920 &FvHeader
->FileSystemGuid
,
922 (UINT32
) FvHeader
->FvLength
,
923 &ParentFvImageInfo
.FvName
,
928 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
931 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
936 // Makes the encapsulated volume show up in DXE phase to skip processing of
937 // encapsulated file again.
940 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
942 &ParentFvImageInfo
.FvName
,
950 Process a firmware volume and create a volume handle.
952 Create a volume handle from the information in the buffer. For
953 memory-mapped firmware volumes, Buffer and BufferSize refer to
954 the start of the firmware volume and the firmware volume size.
955 For non memory-mapped firmware volumes, this points to a
956 buffer which contains the necessary information for creating
957 the firmware volume handle. Normally, these values are derived
958 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
961 @param This Points to this instance of the
962 EFI_PEI_FIRMWARE_VOLUME_PPI.
963 @param Buffer Points to the start of the buffer.
964 @param BufferSize Size of the buffer.
965 @param FvHandle Points to the returned firmware volume
966 handle. The firmware volume handle must
967 be unique within the system.
969 @retval EFI_SUCCESS Firmware volume handle created.
970 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
975 PeiFfs2FvPpiProcessVolume (
976 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
979 OUT EFI_PEI_FV_HANDLE
*FvHandle
984 ASSERT (FvHandle
!= NULL
);
986 if (Buffer
== NULL
) {
987 return EFI_VOLUME_CORRUPTED
;
991 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2 support memory-mapped
992 // FV image and the handle is pointed to Fv image's buffer.
994 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
997 // Do verify for given FV buffer.
999 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
1000 if (EFI_ERROR(Status
)) {
1001 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
1002 return EFI_VOLUME_CORRUPTED
;
1009 Finds the next file of the specified type.
1011 This service enables PEI modules to discover additional firmware files.
1012 The FileHandle must be unique within the system.
1014 @param This Points to this instance of the
1015 EFI_PEI_FIRMWARE_VOLUME_PPI.
1016 @param SearchType A filter to find only files of this type. Type
1017 EFI_FV_FILETYPE_ALL causes no filtering to be
1019 @param FvHandle Handle of firmware volume in which to
1021 @param FileHandle Points to the current handle from which to
1022 begin searching or NULL to start at the
1023 beginning of the firmware volume. Updated
1024 upon return to reflect the file found.
1026 @retval EFI_SUCCESS The file was found.
1027 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1032 PeiFfs2FvPpiFindFileByType (
1033 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1034 IN EFI_FV_FILETYPE SearchType
,
1035 IN EFI_PEI_FV_HANDLE FvHandle
,
1036 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1039 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1043 Find a file within a volume by its name.
1045 This service searches for files with a specific name, within
1046 either the specified firmware volume or all firmware volumes.
1048 @param This Points to this instance of the
1049 EFI_PEI_FIRMWARE_VOLUME_PPI.
1050 @param FileName A pointer to the name of the file to find
1051 within the firmware volume.
1052 @param FvHandle Upon entry, the pointer to the firmware
1053 volume to search or NULL if all firmware
1054 volumes should be searched. Upon exit, the
1055 actual firmware volume in which the file was
1057 @param FileHandle Upon exit, points to the found file's
1058 handle or NULL if it could not be found.
1060 @retval EFI_SUCCESS File was found.
1061 @retval EFI_NOT_FOUND File was not found.
1062 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1069 PeiFfs2FvPpiFindFileByName (
1070 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1071 IN CONST EFI_GUID
*FileName
,
1072 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1073 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1077 PEI_CORE_INSTANCE
*PrivateData
;
1080 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1081 return EFI_INVALID_PARAMETER
;
1084 if (*FvHandle
!= NULL
) {
1085 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1086 if (Status
== EFI_NOT_FOUND
) {
1091 // If *FvHandle = NULL, so search all FV for given filename
1093 Status
= EFI_NOT_FOUND
;
1095 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1096 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1098 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1100 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1101 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1102 if (!EFI_ERROR (Status
)) {
1103 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1113 Returns information about a specific file.
1115 This function returns information about a specific
1116 file, including its file name, type, attributes, starting
1119 @param This Points to this instance of the
1120 EFI_PEI_FIRMWARE_VOLUME_PPI.
1121 @param FileHandle Handle of the file.
1122 @param FileInfo Upon exit, points to the file's
1125 @retval EFI_SUCCESS File information returned.
1126 @retval EFI_INVALID_PARAMETER If FileHandle does not
1127 represent a valid file.
1128 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1133 PeiFfs2FvPpiGetFileInfo (
1134 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1135 IN EFI_PEI_FILE_HANDLE FileHandle
,
1136 OUT EFI_FV_FILE_INFO
*FileInfo
1140 UINT8 ErasePolarity
;
1141 EFI_FFS_FILE_HEADER
*FileHeader
;
1142 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1144 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1145 return EFI_INVALID_PARAMETER
;
1149 // Retrieve the FirmwareVolume which the file resides in.
1151 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1152 if (CoreFvHandle
== NULL
) {
1153 return EFI_INVALID_PARAMETER
;
1156 if (CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) {
1163 // Get FileState which is the highest bit of the State
1165 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1167 switch (FileState
) {
1168 case EFI_FILE_DATA_VALID
:
1169 case EFI_FILE_MARKED_FOR_UPDATE
:
1172 return EFI_INVALID_PARAMETER
;
1175 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1176 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1177 FileInfo
->FileType
= FileHeader
->Type
;
1178 FileInfo
->FileAttributes
= FileHeader
->Attributes
;
1179 FileInfo
->BufferSize
= ((*(UINT32
*)FileHeader
->Size
) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER
);
1180 FileInfo
->Buffer
= (FileHeader
+ 1);
1185 This function returns information about the firmware volume.
1187 @param This Points to this instance of the
1188 EFI_PEI_FIRMWARE_VOLUME_PPI.
1189 @param FvHandle Handle to the firmware handle.
1190 @param VolumeInfo Points to the returned firmware volume
1193 @retval EFI_SUCCESS Information returned successfully.
1194 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1195 firmware volume or VolumeInfo is NULL.
1200 PeiFfs2FvPpiGetVolumeInfo (
1201 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1202 IN EFI_PEI_FV_HANDLE FvHandle
,
1203 OUT EFI_FV_INFO
*VolumeInfo
1206 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1207 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1209 if (VolumeInfo
== NULL
) {
1210 return EFI_INVALID_PARAMETER
;
1214 // VolumeHandle may not align at 8 byte,
1215 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1216 // So, Copy FvHeader into the local FvHeader structure.
1218 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1221 // Check Fv Image Signature
1223 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1224 return EFI_INVALID_PARAMETER
;
1227 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1228 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1229 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1230 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1231 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1233 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1234 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1235 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1242 Find the next matching section in the firmware file.
1244 This service enables PEI modules to discover sections
1245 of a given type within a valid file.
1247 @param This Points to this instance of the
1248 EFI_PEI_FIRMWARE_VOLUME_PPI.
1249 @param SearchType A filter to find only sections of this
1251 @param FileHandle Handle of firmware file in which to
1253 @param SectionData Updated upon return to point to the
1256 @retval EFI_SUCCESS Section was found.
1257 @retval EFI_NOT_FOUND Section of the specified type was not
1258 found. SectionData contains NULL.
1262 PeiFfs2FvPpiFindSectionByType (
1263 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1264 IN EFI_SECTION_TYPE SearchType
,
1265 IN EFI_PEI_FILE_HANDLE FileHandle
,
1266 OUT VOID
**SectionData
1269 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
1271 EFI_COMMON_SECTION_HEADER
*Section
;
1273 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
1276 // Size is 24 bits wide so mask upper 8 bits.
1277 // Does not include FfsFileHeader header size
1278 // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
1280 Section
= (EFI_COMMON_SECTION_HEADER
*)(FfsFileHeader
+ 1);
1281 FileSize
= *(UINT32
*)(FfsFileHeader
->Size
) & 0x00FFFFFF;
1282 FileSize
-= sizeof (EFI_FFS_FILE_HEADER
);
1284 return ProcessSection (
1285 GetPeiServicesTablePointer (),
1294 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
1296 @param FvHandle The handle of a FV.
1298 @retval NULL if can not find.
1299 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
1301 PEI_CORE_FV_HANDLE
*
1302 FvHandleToCoreHandle (
1303 IN EFI_PEI_FV_HANDLE FvHandle
1307 PEI_CORE_INSTANCE
*PrivateData
;
1309 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1310 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1311 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
1312 return &PrivateData
->Fv
[Index
];
1320 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
1322 This routine also will install FvInfo ppi for FV hob in PI ways.
1324 @param Private Pointer of PEI_CORE_INSTANCE
1325 @param Instance The index of FV want to be searched.
1327 @return Instance of PEI_CORE_FV_HANDLE.
1329 PEI_CORE_FV_HANDLE
*
1330 FindNextCoreFvHandle (
1331 IN PEI_CORE_INSTANCE
*Private
,
1337 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
1340 // Handle Framework FvHob and Install FvInfo Ppi for it.
1342 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1344 // Loop to search the wanted FirmwareVolume which supports FFS
1346 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
1347 while (FvHob
!= NULL
) {
1348 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
1349 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
1355 // If Not Found, Install FvInfo Ppi for it.
1358 PeiServicesInstallFvInfoPpi (
1359 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
1360 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
1361 (UINT32
)FvHob
->Length
,
1366 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
1370 if (Instance
>= Private
->FvCount
) {
1374 return &Private
->Fv
[Instance
];
1378 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
1379 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
1380 PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant
1383 @param PrivateData Pointer to PEI_CORE_INSTANCE.
1387 IN PEI_CORE_INSTANCE
*PrivateData
1391 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
1396 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
1399 Status
= PeiServicesLocatePpi (
1400 &gEfiFirmwareFileSystem2Guid
,
1405 ASSERT_EFI_ERROR (Status
);
1408 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
1409 // which is shadowed from flash to permanent memory within PeiCore image.
1411 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
1412 ASSERT_EFI_ERROR (Status
);
1415 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
1417 for (Index
= 0; Index
< FixedPcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
1418 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfs2FvPpi
) {
1419 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FvPpi
;
1425 Report the information for a new discoveried FV in unknown third-party format.
1427 If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but
1428 the FV in this format has been discoveried, then this FV's information will be cached into
1429 PEI_CORE_INSTANCE's UnknownFvInfo array.
1430 Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI
1431 is installed later by platform's PEIM, the original unknown third-party FV will be processed by
1432 using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
1434 @param PrivateData Point to instance of PEI_CORE_INSTANCE
1435 @param Format Point to the unknown third-party format guid.
1436 @param FvInfo Point to FvInfo buffer.
1437 @param FvInfoSize The size of FvInfo buffer.
1439 @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.
1440 @retval EFI_SUCCESS Success to add the information for unknown FV.
1443 AddUnknownFormatFvInfo (
1444 IN PEI_CORE_INSTANCE
*PrivateData
,
1445 IN EFI_GUID
*Format
,
1447 IN UINT32 FvInfoSize
1450 PEI_CORE_UNKNOW_FORMAT_FV_INFO
*NewUnknownFv
;
1452 if (PrivateData
->UnknownFvInfoCount
+ 1 >= FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) {
1453 return EFI_OUT_OF_RESOURCES
;
1456 NewUnknownFv
= &PrivateData
->UnknownFvInfo
[PrivateData
->UnknownFvInfoCount
];
1457 PrivateData
->UnknownFvInfoCount
++;
1459 CopyGuid (&NewUnknownFv
->FvFormat
, Format
);
1460 NewUnknownFv
->FvInfo
= FvInfo
;
1461 NewUnknownFv
->FvInfoSize
= FvInfoSize
;
1462 NewUnknownFv
->NotifyDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
1463 NewUnknownFv
->NotifyDescriptor
.Guid
= &NewUnknownFv
->FvFormat
;
1464 NewUnknownFv
->NotifyDescriptor
.Notify
= ThirdPartyFvPpiNotifyCallback
;
1466 PeiServicesNotifyPpi (&NewUnknownFv
->NotifyDescriptor
);
1471 Find the FV information according to third-party FV format guid.
1473 This routine also will remove the FV information found by given FV format guid from
1474 PrivateData->UnknownFvInfo[].
1476 @param PrivateData Point to instance of PEI_CORE_INSTANCE
1477 @param Format Point to given FV format guid
1478 @param FvInfo On return, the pointer of FV information buffer
1479 @param FvInfoSize On return, the size of FV information buffer.
1481 @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI
1482 @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.
1485 FindUnknownFormatFvInfo (
1486 IN PEI_CORE_INSTANCE
*PrivateData
,
1487 IN EFI_GUID
*Format
,
1489 OUT UINT32
*FvInfoSize
1496 for (; Index
< PrivateData
->UnknownFvInfoCount
; Index
++) {
1497 if (CompareGuid (Format
, &PrivateData
->UnknownFvInfo
[Index
].FvFormat
)) {
1502 if (Index
== PrivateData
->UnknownFvInfoCount
) {
1503 return EFI_NOT_FOUND
;
1506 *FvInfo
= PrivateData
->UnknownFvInfo
[Index
].FvInfo
;
1507 *FvInfoSize
= PrivateData
->UnknownFvInfo
[Index
].FvInfoSize
;
1510 // Remove an entry from UnknownFvInfo array.
1513 for (;Index2
< PrivateData
->UnknownFvInfoCount
; Index2
++, Index
++) {
1514 CopyMem (&PrivateData
->UnknownFvInfo
[Index
], &PrivateData
->UnknownFvInfo
[Index2
], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO
));
1516 PrivateData
->UnknownFvInfoCount
--;
1521 Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.
1523 When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this
1524 routine is called to process all discoveried FVs in this format.
1526 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
1527 @param NotifyDescriptor Address of the notification descriptor data structure.
1528 @param Ppi Address of the PPI that was installed.
1530 @retval EFI_SUCCESS The notification callback is processed correctly.
1534 ThirdPartyFvPpiNotifyCallback (
1535 IN EFI_PEI_SERVICES
**PeiServices
,
1536 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
1540 PEI_CORE_INSTANCE
*PrivateData
;
1541 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
1545 EFI_PEI_FV_HANDLE FvHandle
;
1546 BOOLEAN IsProcessed
;
1548 EFI_PEI_FILE_HANDLE FileHandle
;
1551 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
1552 FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) Ppi
;
1555 Status
= FindUnknownFormatFvInfo (PrivateData
, NotifyDescriptor
->Guid
, &FvInfo
, &FvInfoSize
);
1556 if (EFI_ERROR (Status
)) {
1561 // Process new found FV and get FV handle.
1563 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfo
, FvInfoSize
, &FvHandle
);
1564 if (EFI_ERROR (Status
)) {
1565 DEBUG ((EFI_D_ERROR
, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo
));
1570 // Check whether the FV has already been processed.
1572 IsProcessed
= FALSE
;
1573 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
1574 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
1575 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvInfo
));
1586 // Update internal PEI_CORE_FV array.
1588 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfo
;
1589 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= FvPpi
;
1590 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
1593 "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
1594 (UINT32
) PrivateData
->FvCount
,
1599 PrivateData
->FvCount
++;
1602 // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
1606 Status
= FvPpi
->FindFileByType (
1608 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
1612 if (!EFI_ERROR (Status
)) {
1613 Status
= FvPpi
->FindSectionByType (
1615 EFI_SECTION_PEI_DEPEX
,
1619 if (!EFI_ERROR (Status
)) {
1620 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
1622 // Dependency is not satisfied.
1628 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle
, PrivateData
->FvCount
- 1, FvHandle
));
1629 ProcessFvFile (&PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
1631 } while (FileHandle
!= NULL
);