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 // Post a call-back for the FvInfoPPI services to expose
315 // additional Fvs to PeiCore.
317 Status
= PeiServicesNotifyPpi (&mNotifyOnFvInfoList
);
318 ASSERT_EFI_ERROR (Status
);
323 Process Firmware Volum Information once FvInfoPPI install.
324 The FV Info will be registered into PeiCore private data structure.
325 And search the inside FV image, if found, the new FV INFO PPI will be installed.
327 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
328 @param NotifyDescriptor Address of the notification descriptor data structure.
329 @param Ppi Address of the PPI that was installed.
331 @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
332 @return if not EFI_SUCESS, fail to verify FV.
337 FirmwareVolmeInfoPpiNotifyCallback (
338 IN EFI_PEI_SERVICES
**PeiServices
,
339 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
343 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*FvInfoPpi
;
344 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
345 PEI_CORE_INSTANCE
*PrivateData
;
347 EFI_PEI_FV_HANDLE FvHandle
;
350 Status
= EFI_SUCCESS
;
351 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
353 if (PrivateData
->FvCount
>= FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)) {
354 DEBUG ((EFI_D_ERROR
, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData
->FvCount
+ 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported
)));
355 DEBUG ((EFI_D_ERROR
, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
359 FvInfoPpi
= (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*)Ppi
;
362 // Locate the corresponding FV_PPI according to founded FV's format guid
364 Status
= PeiServicesLocatePpi (
365 &FvInfoPpi
->FvFormat
,
370 if (!EFI_ERROR (Status
)) {
372 // Process new found FV and get FV handle.
374 Status
= FvPpi
->ProcessVolume (FvPpi
, FvInfoPpi
->FvInfo
, FvInfoPpi
->FvInfoSize
, &FvHandle
);
375 if (EFI_ERROR (Status
)) {
376 DEBUG ((EFI_D_ERROR
, "Fail to process new found FV, FV may be corrupted!"));
379 DEBUG ((EFI_D_INFO
, "Found and process new FV %p, all fv's count is %d\n", FvHandle
, PrivateData
->FvCount
));
381 DEBUG ((EFI_D_ERROR
, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfoPpi
->FvInfo
));
384 // If can not find EFI_FIRMWARE_VOLUME_PPI to process firmware to get FvHandle,
385 // use the address of FV buffer as its handle.
387 FvHandle
= FvInfoPpi
->FvInfo
;
390 // Check whether the FV has already been processed.
392 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
393 if (PrivateData
->Fv
[FvIndex
].FvHandle
== FvHandle
) {
394 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!\n", FvHandle
));
399 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) FvInfoPpi
->FvInfo
;
400 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= NULL
;
401 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= FvHandle
;
402 PrivateData
->FvCount
++;
409 Go through the file to search SectionType section.
410 Search within encapsulation sections (compression and GUIDed) recursively,
411 until the match section is found.
413 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
414 @param SectionType Filter to find only section of this type.
415 @param Section From where to search.
416 @param SectionSize The file size to search.
417 @param OutputBuffer A pointer to the discovered section, if successful.
418 NULL if section not found
420 @return EFI_NOT_FOUND The match section is not found.
421 @return EFI_SUCCESS The match section is found.
426 IN CONST EFI_PEI_SERVICES
**PeiServices
,
427 IN EFI_SECTION_TYPE SectionType
,
428 IN EFI_COMMON_SECTION_HEADER
*Section
,
429 IN UINTN SectionSize
,
430 OUT VOID
**OutputBuffer
434 UINT32 SectionLength
;
436 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*GuidSectionPpi
;
437 EFI_PEI_DECOMPRESS_PPI
*DecompressPpi
;
441 UINT32 Authentication
;
442 PEI_CORE_INSTANCE
*PrivateData
;
444 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
445 *OutputBuffer
= NULL
;
448 Status
= EFI_NOT_FOUND
;
451 while (ParsedLength
< SectionSize
) {
452 if (Section
->Type
== SectionType
) {
453 *OutputBuffer
= (VOID
*)(Section
+ 1);
455 } else if ((Section
->Type
== EFI_SECTION_GUID_DEFINED
) || (Section
->Type
== EFI_SECTION_COMPRESSION
)) {
457 // Check the encapsulated section is extracted into the cache data.
459 for (Index
= 0; Index
< PrivateData
->CacheSection
.AllSectionCount
; Index
++) {
460 if (Section
== PrivateData
->CacheSection
.Section
[Index
]) {
461 PpiOutput
= PrivateData
->CacheSection
.SectionData
[Index
];
462 PpiOutputSize
= PrivateData
->CacheSection
.SectionSize
[Index
];
464 // Search section directly from the cache data.
466 return ProcessSection (
476 Status
= EFI_NOT_FOUND
;
477 if (Section
->Type
== EFI_SECTION_GUID_DEFINED
) {
478 Status
= PeiServicesLocatePpi (
479 &((EFI_GUID_DEFINED_SECTION
*)Section
)->SectionDefinitionGuid
,
482 (VOID
**) &GuidSectionPpi
484 if (!EFI_ERROR (Status
)) {
485 Status
= GuidSectionPpi
->ExtractSection (
493 } else if (Section
->Type
== EFI_SECTION_COMPRESSION
) {
494 Status
= PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid
, 0, NULL
, (VOID
**) &DecompressPpi
);
495 if (!EFI_ERROR (Status
)) {
496 Status
= DecompressPpi
->Decompress (
498 (CONST EFI_COMPRESSION_SECTION
*) Section
,
505 if (!EFI_ERROR (Status
)) {
507 // Update cache section data.
509 if (PrivateData
->CacheSection
.AllSectionCount
< CACHE_SETION_MAX_NUMBER
) {
510 PrivateData
->CacheSection
.AllSectionCount
++;
512 PrivateData
->CacheSection
.Section
[PrivateData
->CacheSection
.SectionIndex
] = Section
;
513 PrivateData
->CacheSection
.SectionData
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutput
;
514 PrivateData
->CacheSection
.SectionSize
[PrivateData
->CacheSection
.SectionIndex
] = PpiOutputSize
;
515 PrivateData
->CacheSection
.SectionIndex
= (PrivateData
->CacheSection
.SectionIndex
+ 1)%CACHE_SETION_MAX_NUMBER
;
517 return ProcessSection (
528 // Size is 24 bits wide so mask upper 8 bits.
529 // SectionLength is adjusted it is 4 byte aligned.
530 // Go to the next section
532 SectionLength
= *(UINT32
*)Section
->Size
& 0x00FFFFFF;
533 SectionLength
= GET_OCCUPIED_SIZE (SectionLength
, 4);
534 ASSERT (SectionLength
!= 0);
535 ParsedLength
+= SectionLength
;
536 Section
= (EFI_COMMON_SECTION_HEADER
*)((UINT8
*)Section
+ SectionLength
);
539 return EFI_NOT_FOUND
;
544 Searches for the next matching section within the specified file.
546 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
547 @param SectionType Filter to find only sections of this type.
548 @param FileHandle Pointer to the current file to search.
549 @param SectionData A pointer to the discovered section, if successful.
550 NULL if section not found
552 @retval EFI_NOT_FOUND The section was not found.
553 @retval EFI_SUCCESS The section was found.
558 PeiFfsFindSectionData (
559 IN CONST EFI_PEI_SERVICES
**PeiServices
,
560 IN EFI_SECTION_TYPE SectionType
,
561 IN EFI_PEI_FILE_HANDLE FileHandle
,
562 OUT VOID
**SectionData
565 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
567 CoreFvHandle
= FileHandleToVolume (FileHandle
);
568 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
569 return EFI_NOT_FOUND
;
572 return CoreFvHandle
->FvPpi
->FindSectionByType (CoreFvHandle
->FvPpi
, SectionType
, FileHandle
, SectionData
);
576 Searches for the next matching file in the firmware volume.
578 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
579 @param SearchType Filter to find only files of this type.
580 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
581 @param VolumeHandle Handle of firmware volume in which to search.
582 @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start
583 at the beginning of the firmware volume. On exit, points the file handle of the next file
584 in the volume or NULL if there are no more files.
586 @retval EFI_NOT_FOUND The file was not found.
587 @retval EFI_NOT_FOUND The header checksum was not zero.
588 @retval EFI_SUCCESS The file was found.
594 IN CONST EFI_PEI_SERVICES
**PeiServices
,
596 IN EFI_PEI_FV_HANDLE FvHandle
,
597 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
600 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
602 CoreFvHandle
= FvHandleToCoreHandle (FvHandle
);
605 // To make backward compatiblity, if can not find corresponding the handle of FV
606 // then treat FV as build-in FFS2 format and memory mapped FV that FV handle is pointed
607 // to the address of first byte of FV.
609 if ((CoreFvHandle
== NULL
) && FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
610 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
613 if ((CoreFvHandle
== NULL
) || CoreFvHandle
->FvPpi
== NULL
) {
614 return EFI_NOT_FOUND
;
617 return CoreFvHandle
->FvPpi
->FindFileByType (CoreFvHandle
->FvPpi
, SearchType
, FvHandle
, FileHandle
);
622 Search the firmware volumes by index
624 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
625 @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware
627 @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.
629 @retval EFI_INVALID_PARAMETER VolumeHandle is NULL
630 @retval EFI_NOT_FOUND The volume was not found.
631 @retval EFI_SUCCESS The volume was found.
636 PeiFfsFindNextVolume (
637 IN CONST EFI_PEI_SERVICES
**PeiServices
,
639 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
642 PEI_CORE_INSTANCE
*Private
;
643 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
645 if (VolumeHandle
== NULL
) {
646 return EFI_INVALID_PARAMETER
;
649 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
651 CoreFvHandle
= FindNextCoreFvHandle (Private
, Instance
);
652 if (CoreFvHandle
== NULL
) {
653 *VolumeHandle
= NULL
;
654 return EFI_NOT_FOUND
;
657 *VolumeHandle
= CoreFvHandle
->FvHandle
;
664 Find a file within a volume by its name.
666 @param FileName A pointer to the name of the file to find within the firmware volume.
667 @param VolumeHandle The firmware volume to search
668 @param FileHandle Upon exit, points to the found file's handle
669 or NULL if it could not be found.
671 @retval EFI_SUCCESS File was found.
672 @retval EFI_NOT_FOUND File was not found.
673 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
678 PeiFfsFindFileByName (
679 IN CONST EFI_GUID
*FileName
,
680 IN EFI_PEI_FV_HANDLE VolumeHandle
,
681 OUT EFI_PEI_FILE_HANDLE
*FileHandle
684 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
686 if ((VolumeHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
687 return EFI_INVALID_PARAMETER
;
690 CoreFvHandle
= FvHandleToCoreHandle (VolumeHandle
);
691 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
692 return EFI_NOT_FOUND
;
695 return CoreFvHandle
->FvPpi
->FindFileByName (CoreFvHandle
->FvPpi
, FileName
, &VolumeHandle
, FileHandle
);
699 Returns information about a specific file.
701 @param FileHandle Handle of the file.
702 @param FileInfo Upon exit, points to the file’s information.
704 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
705 @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.
706 @retval EFI_SUCCESS File information returned.
712 IN EFI_PEI_FILE_HANDLE FileHandle
,
713 OUT EFI_FV_FILE_INFO
*FileInfo
716 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
718 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
719 return EFI_INVALID_PARAMETER
;
723 // Retrieve the FirmwareVolume which the file resides in.
725 CoreFvHandle
= FileHandleToVolume (FileHandle
);
726 if ((CoreFvHandle
== NULL
) || (CoreFvHandle
->FvPpi
== NULL
)) {
727 return EFI_INVALID_PARAMETER
;
730 return CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, FileHandle
, FileInfo
);
735 Returns information about the specified volume.
737 This function returns information about a specific firmware
738 volume, including its name, type, attributes, starting address
741 @param VolumeHandle Handle of the volume.
742 @param VolumeInfo Upon exit, points to the volume's information.
744 @retval EFI_SUCCESS Volume information returned.
745 @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.
746 @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.
747 @retval EFI_SUCCESS Information successfully returned.
748 @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.
753 PeiFfsGetVolumeInfo (
754 IN EFI_PEI_FV_HANDLE VolumeHandle
,
755 OUT EFI_FV_INFO
*VolumeInfo
758 PEI_CORE_FV_HANDLE
*CoreHandle
;
760 if (VolumeInfo
== NULL
) {
761 return EFI_INVALID_PARAMETER
;
764 CoreHandle
= FvHandleToCoreHandle (VolumeHandle
);
766 if ((CoreHandle
== NULL
) || (CoreHandle
->FvPpi
== NULL
)) {
767 return EFI_INVALID_PARAMETER
;
770 return CoreHandle
->FvPpi
->GetVolumeInfo (CoreHandle
->FvPpi
, VolumeHandle
, VolumeInfo
);
774 Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.
776 @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.
777 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
779 @retval EFI_NOT_FOUND FV image can't be found.
780 @retval EFI_SUCCESS Successfully to process it.
781 @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
782 @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
787 IN PEI_CORE_FV_HANDLE
*ParentFvCoreHandle
,
788 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle
792 EFI_FV_INFO ParentFvImageInfo
;
795 EFI_PEI_HOB_POINTERS HobPtr
;
796 EFI_PEI_FIRMWARE_VOLUME_PPI
*ParentFvPpi
;
797 EFI_PEI_FV_HANDLE ParentFvHandle
;
798 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
799 EFI_FV_FILE_INFO FileInfo
;
802 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
805 HobPtr
.Raw
= GetHobList ();
806 while ((HobPtr
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobPtr
.Raw
)) != NULL
) {
807 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)ParentFvFileHandle
)->Name
), &HobPtr
.FirmwareVolume2
->FileName
)) {
809 // this FILE has been dispatched, it will not be dispatched again.
811 DEBUG ((EFI_D_INFO
, "FV file %p has been dispatched!\r\n", ParentFvFileHandle
));
814 HobPtr
.Raw
= GET_NEXT_HOB (HobPtr
);
817 ParentFvHandle
= ParentFvCoreHandle
->FvHandle
;
818 ParentFvPpi
= ParentFvCoreHandle
->FvPpi
;
821 // Find FvImage in FvFile
823 Status
= ParentFvPpi
->FindSectionByType (
825 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
830 if (EFI_ERROR (Status
)) {
835 // FvAlignment must be more than 8 bytes required by FvHeader structure.
837 FvAlignment
= 1 << ((FvHeader
->Attributes
& EFI_FVB2_ALIGNMENT
) >> 16);
838 if (FvAlignment
< 8) {
845 if ((UINTN
) FvHeader
% FvAlignment
!= 0) {
846 NewFvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvHeader
->FvLength
), FvAlignment
);
847 if (NewFvBuffer
== NULL
) {
848 return EFI_OUT_OF_RESOURCES
;
850 CopyMem (NewFvBuffer
, FvHeader
, (UINTN
) FvHeader
->FvLength
);
851 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) NewFvBuffer
;
854 Status
= ParentFvPpi
->GetVolumeInfo (ParentFvPpi
, ParentFvHandle
, &ParentFvImageInfo
);
855 ASSERT_EFI_ERROR (Status
);
857 Status
= ParentFvPpi
->GetFileInfo (ParentFvPpi
, ParentFvFileHandle
, &FileInfo
);
858 ASSERT_EFI_ERROR (Status
);
861 // Install FvPpi and Build FvHob
863 PeiServicesInstallFvInfoPpi (
864 &FvHeader
->FileSystemGuid
,
866 (UINT32
) FvHeader
->FvLength
,
867 &ParentFvImageInfo
.FvName
,
872 // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
875 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
880 // Makes the encapsulated volume show up in DXE phase to skip processing of
881 // encapsulated file again.
884 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvHeader
,
886 &ParentFvImageInfo
.FvName
,
894 Process a firmware volume and create a volume handle.
896 Create a volume handle from the information in the buffer. For
897 memory-mapped firmware volumes, Buffer and BufferSize refer to
898 the start of the firmware volume and the firmware volume size.
899 For non memory-mapped firmware volumes, this points to a
900 buffer which contains the necessary information for creating
901 the firmware volume handle. Normally, these values are derived
902 from the EFI_FIRMWARE_VOLUME_INFO_PPI.
905 @param This Points to this instance of the
906 EFI_PEI_FIRMWARE_VOLUME_PPI.
907 @param Buffer Points to the start of the buffer.
908 @param BufferSize Size of the buffer.
909 @param FvHandle Points to the returned firmware volume
910 handle. The firmware volume handle must
911 be unique within the system.
913 @retval EFI_SUCCESS Firmware volume handle created.
914 @retval EFI_VOLUME_CORRUPTED Volume was corrupt.
919 PeiFfs2FvPpiProcessVolume (
920 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
923 OUT EFI_PEI_FV_HANDLE
*FvHandle
927 PEI_CORE_INSTANCE
*PrivateData
;
928 EFI_PEI_FILE_HANDLE FileHandle
;
930 EFI_PEI_SERVICES
**PeiServices
;
933 PeiServices
= (EFI_PEI_SERVICES
**) GetPeiServicesTablePointer ();
934 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
937 // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2 support memory-mapped
938 // FV image and the handle is pointed to Fv image's buffer.
940 *FvHandle
= (EFI_PEI_FV_HANDLE
) Buffer
;
943 // Do verify for given FV buffer.
945 Status
= VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
);
946 if (EFI_ERROR(Status
)) {
947 DEBUG ((EFI_D_ERROR
, "Fail to verify FV which address is 0x%11p", Buffer
));
948 return EFI_VOLUME_CORRUPTED
;
952 // Check whether the FV has already been processed.
954 for (FvIndex
= 0; FvIndex
< PrivateData
->FvCount
; FvIndex
++) {
955 if (PrivateData
->Fv
[FvIndex
].FvHandle
== *FvHandle
) {
956 DEBUG ((EFI_D_INFO
, "The Fv %p has already been processed!", Buffer
));
962 // Update internal PEI_CORE_FV array.
964 PrivateData
->Fv
[PrivateData
->FvCount
].FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
;
965 PrivateData
->Fv
[PrivateData
->FvCount
].FvPpi
= (EFI_PEI_FIRMWARE_VOLUME_PPI
*) This
;
966 PrivateData
->Fv
[PrivateData
->FvCount
].FvHandle
= *FvHandle
;
969 "The %dth FV start address is 0x%11p and size is 0x%08x\n",
970 (UINT32
) PrivateData
->FvCount
,
974 PrivateData
->FvCount
++;
979 Status
= This
->FindFileByType (
981 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
985 if (!EFI_ERROR (Status
)) {
986 Status
= This
->FindSectionByType (
988 EFI_SECTION_PEI_DEPEX
,
992 if (!EFI_ERROR (Status
)) {
993 if (!PeimDispatchReadiness (PeiServices
, DepexData
)) {
995 // Dependency is not satisfied.
1001 DEBUG ((EFI_D_INFO
, "Found firmware volume Image File %p in FV[%d] %p", FileHandle
, PrivateData
->FvCount
- 1, *FvHandle
));
1002 ProcessFvFile (&PrivateData
->Fv
[PrivateData
->FvCount
- 1], FileHandle
);
1004 } while (FileHandle
!= NULL
);
1010 Finds the next file of the specified type.
1012 This service enables PEI modules to discover additional firmware files.
1013 The FileHandle must be unique within the system.
1015 @param This Points to this instance of the
1016 EFI_PEI_FIRMWARE_VOLUME_PPI.
1017 @param SearchType A filter to find only files of this type. Type
1018 EFI_FV_FILETYPE_ALL causes no filtering to be
1020 @param FvHandle Handle of firmware volume in which to
1022 @param FileHandle Points to the current handle from which to
1023 begin searching or NULL to start at the
1024 beginning of the firmware volume. Updated
1025 upon return to reflect the file found.
1027 @retval EFI_SUCCESS The file was found.
1028 @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.
1033 PeiFfs2FvPpiFindFileByType (
1034 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1035 IN EFI_FV_FILETYPE SearchType
,
1036 IN EFI_PEI_FV_HANDLE FvHandle
,
1037 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
1040 return FindFileEx (FvHandle
, NULL
, SearchType
, FileHandle
, NULL
);
1044 Find a file within a volume by its name.
1046 This service searches for files with a specific name, within
1047 either the specified firmware volume or all firmware volumes.
1049 @param This Points to this instance of the
1050 EFI_PEI_FIRMWARE_VOLUME_PPI.
1051 @param FileName A pointer to the name of the file to find
1052 within the firmware volume.
1053 @param FvHandle Upon entry, the pointer to the firmware
1054 volume to search or NULL if all firmware
1055 volumes should be searched. Upon exit, the
1056 actual firmware volume in which the file was
1058 @param FileHandle Upon exit, points to the found file's
1059 handle or NULL if it could not be found.
1061 @retval EFI_SUCCESS File was found.
1062 @retval EFI_NOT_FOUND File was not found.
1063 @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or
1070 PeiFfs2FvPpiFindFileByName (
1071 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1072 IN CONST EFI_GUID
*FileName
,
1073 IN EFI_PEI_FV_HANDLE
*FvHandle
,
1074 OUT EFI_PEI_FILE_HANDLE
*FileHandle
1078 PEI_CORE_INSTANCE
*PrivateData
;
1081 if ((FvHandle
== NULL
) || (FileName
== NULL
) || (FileHandle
== NULL
)) {
1082 return EFI_INVALID_PARAMETER
;
1085 if (*FvHandle
!= NULL
) {
1086 Status
= FindFileEx (*FvHandle
, FileName
, 0, FileHandle
, NULL
);
1087 if (Status
== EFI_NOT_FOUND
) {
1092 // If *FvHandle = NULL, so search all FV for given filename
1094 Status
= EFI_NOT_FOUND
;
1096 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1097 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1099 // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.
1101 if (PrivateData
->Fv
[Index
].FvPpi
!= NULL
) {
1102 Status
= FindFileEx (PrivateData
->Fv
[Index
].FvHandle
, FileName
, 0, FileHandle
, NULL
);
1103 if (!EFI_ERROR (Status
)) {
1104 *FvHandle
= PrivateData
->Fv
[Index
].FvHandle
;
1114 Returns information about a specific file.
1116 This function returns information about a specific
1117 file, including its file name, type, attributes, starting
1120 @param This Points to this instance of the
1121 EFI_PEI_FIRMWARE_VOLUME_PPI.
1122 @param FileHandle Handle of the file.
1123 @param FileInfo Upon exit, points to the file's
1126 @retval EFI_SUCCESS File information returned.
1127 @retval EFI_INVALID_PARAMETER If FileHandle does not
1128 represent a valid file.
1129 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
1134 PeiFfs2FvPpiGetFileInfo (
1135 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1136 IN EFI_PEI_FILE_HANDLE FileHandle
,
1137 OUT EFI_FV_FILE_INFO
*FileInfo
1141 UINT8 ErasePolarity
;
1142 EFI_FFS_FILE_HEADER
*FileHeader
;
1143 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
1145 if ((FileHandle
== NULL
) || (FileInfo
== NULL
)) {
1146 return EFI_INVALID_PARAMETER
;
1150 // Retrieve the FirmwareVolume which the file resides in.
1152 CoreFvHandle
= FileHandleToVolume (FileHandle
);
1153 if (CoreFvHandle
== NULL
) {
1154 return EFI_INVALID_PARAMETER
;
1157 if (CoreFvHandle
->FvHeader
->Attributes
& EFI_FVB2_ERASE_POLARITY
) {
1164 // Get FileState which is the highest bit of the State
1166 FileState
= GetFileState (ErasePolarity
, (EFI_FFS_FILE_HEADER
*)FileHandle
);
1168 switch (FileState
) {
1169 case EFI_FILE_DATA_VALID
:
1170 case EFI_FILE_MARKED_FOR_UPDATE
:
1173 return EFI_INVALID_PARAMETER
;
1176 FileHeader
= (EFI_FFS_FILE_HEADER
*)FileHandle
;
1177 CopyMem (&FileInfo
->FileName
, &FileHeader
->Name
, sizeof(EFI_GUID
));
1178 FileInfo
->FileType
= FileHeader
->Type
;
1179 FileInfo
->FileAttributes
= FileHeader
->Attributes
;
1180 FileInfo
->BufferSize
= ((*(UINT32
*)FileHeader
->Size
) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER
);
1181 FileInfo
->Buffer
= (FileHeader
+ 1);
1186 This function returns information about the firmware volume.
1188 @param This Points to this instance of the
1189 EFI_PEI_FIRMWARE_VOLUME_PPI.
1190 @param FvHandle Handle to the firmware handle.
1191 @param VolumeInfo Points to the returned firmware volume
1194 @retval EFI_SUCCESS Information returned successfully.
1195 @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid
1196 firmware volume or VolumeInfo is NULL.
1201 PeiFfs2FvPpiGetVolumeInfo (
1202 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1203 IN EFI_PEI_FV_HANDLE FvHandle
,
1204 OUT EFI_FV_INFO
*VolumeInfo
1207 EFI_FIRMWARE_VOLUME_HEADER FwVolHeader
;
1208 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FwVolExHeaderInfo
;
1210 if (VolumeInfo
== NULL
) {
1211 return EFI_INVALID_PARAMETER
;
1215 // VolumeHandle may not align at 8 byte,
1216 // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
1217 // So, Copy FvHeader into the local FvHeader structure.
1219 CopyMem (&FwVolHeader
, FvHandle
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
));
1222 // Check Fv Image Signature
1224 if (FwVolHeader
.Signature
!= EFI_FVH_SIGNATURE
) {
1225 return EFI_INVALID_PARAMETER
;
1228 ZeroMem (VolumeInfo
, sizeof (EFI_FV_INFO
));
1229 VolumeInfo
->FvAttributes
= FwVolHeader
.Attributes
;
1230 VolumeInfo
->FvStart
= (VOID
*) FvHandle
;
1231 VolumeInfo
->FvSize
= FwVolHeader
.FvLength
;
1232 CopyMem (&VolumeInfo
->FvFormat
, &FwVolHeader
.FileSystemGuid
, sizeof(EFI_GUID
));
1234 if (FwVolHeader
.ExtHeaderOffset
!= 0) {
1235 FwVolExHeaderInfo
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(((UINT8
*)FvHandle
) + FwVolHeader
.ExtHeaderOffset
);
1236 CopyMem (&VolumeInfo
->FvName
, &FwVolExHeaderInfo
->FvName
, sizeof(EFI_GUID
));
1243 Find the next matching section in the firmware file.
1245 This service enables PEI modules to discover sections
1246 of a given type within a valid file.
1248 @param This Points to this instance of the
1249 EFI_PEI_FIRMWARE_VOLUME_PPI.
1250 @param SearchType A filter to find only sections of this
1252 @param FileHandle Handle of firmware file in which to
1254 @param SectionData Updated upon return to point to the
1257 @retval EFI_SUCCESS Section was found.
1258 @retval EFI_NOT_FOUND Section of the specified type was not
1259 found. SectionData contains NULL.
1263 PeiFfs2FvPpiFindSectionByType (
1264 IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI
*This
,
1265 IN EFI_SECTION_TYPE SearchType
,
1266 IN EFI_PEI_FILE_HANDLE FileHandle
,
1267 OUT VOID
**SectionData
1270 EFI_FFS_FILE_HEADER
*FfsFileHeader
;
1272 EFI_COMMON_SECTION_HEADER
*Section
;
1274 FfsFileHeader
= (EFI_FFS_FILE_HEADER
*)(FileHandle
);
1277 // Size is 24 bits wide so mask upper 8 bits.
1278 // Does not include FfsFileHeader header size
1279 // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
1281 Section
= (EFI_COMMON_SECTION_HEADER
*)(FfsFileHeader
+ 1);
1282 FileSize
= *(UINT32
*)(FfsFileHeader
->Size
) & 0x00FFFFFF;
1283 FileSize
-= sizeof (EFI_FFS_FILE_HEADER
);
1285 return ProcessSection (
1286 GetPeiServicesTablePointer (),
1295 Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.
1297 @param FvHandle The handle of a FV.
1299 @retval NULL if can not find.
1300 @return Pointer of corresponding PEI_CORE_FV_HANDLE.
1302 PEI_CORE_FV_HANDLE
*
1303 FvHandleToCoreHandle (
1304 IN EFI_PEI_FV_HANDLE FvHandle
1308 PEI_CORE_INSTANCE
*PrivateData
;
1310 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());
1311 for (Index
= 0; Index
< PrivateData
->FvCount
; Index
++) {
1312 if (FvHandle
== PrivateData
->Fv
[Index
].FvHandle
) {
1313 return &PrivateData
->Fv
[Index
];
1321 Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.
1323 This routine also will install FvInfo ppi for FV hob in PI ways.
1325 @param Private Pointer of PEI_CORE_INSTANCE
1326 @param Instance The index of FV want to be searched.
1328 @return Instance of PEI_CORE_FV_HANDLE.
1330 PEI_CORE_FV_HANDLE
*
1331 FindNextCoreFvHandle (
1332 IN PEI_CORE_INSTANCE
*Private
,
1338 EFI_HOB_FIRMWARE_VOLUME
*FvHob
;
1341 // Handle Framework FvHob and Install FvInfo Ppi for it.
1343 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
1345 // Loop to search the wanted FirmwareVolume which supports FFS
1347 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetFirstHob (EFI_HOB_TYPE_FV
);
1348 while (FvHob
!= NULL
) {
1349 for (Index
= 0, Match
= FALSE
; Index
< Private
->FvCount
; Index
++) {
1350 if ((EFI_PEI_FV_HANDLE
)(UINTN
)FvHob
->BaseAddress
== Private
->Fv
[Index
].FvHeader
) {
1356 // If Not Found, Install FvInfo Ppi for it.
1359 PeiServicesInstallFvInfoPpi (
1360 &(((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvHob
->BaseAddress
)->FileSystemGuid
),
1361 (VOID
*)(UINTN
)FvHob
->BaseAddress
,
1362 (UINT32
)FvHob
->Length
,
1367 FvHob
= (EFI_HOB_FIRMWARE_VOLUME
*)GetNextHob (EFI_HOB_TYPE_FV
, (VOID
*)((UINTN
)FvHob
+ FvHob
->Header
.HobLength
));
1371 if (Instance
>= Private
->FvCount
) {
1375 return &Private
->Fv
[Instance
];
1379 After PeiCore image is shadowed into permanent memory, all build-in FvPpi should
1380 be re-installed with the instance in permanent memory and all cached FvPpi pointers in
1381 PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant
1384 @param PrivateData Pointer to PEI_CORE_INSTANCE.
1388 IN PEI_CORE_INSTANCE
*PrivateData
1392 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
1397 // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which
1400 Status
= PeiServicesLocatePpi (
1401 &gEfiFirmwareFileSystem2Guid
,
1406 ASSERT_EFI_ERROR (Status
);
1409 // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2
1410 // which is shadowed from flash to permanent memory within PeiCore image.
1412 Status
= PeiServicesReInstallPpi (OldDescriptor
, &mPeiFfs2FvPpiList
);
1413 ASSERT_EFI_ERROR (Status
);
1416 // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
1418 for (Index
= 0; Index
< FixedPcdGet32 (PcdPeiCoreMaxFvSupported
); Index
++) {
1419 if (PrivateData
->Fv
[Index
].FvPpi
== OldFfs2FvPpi
) {
1420 PrivateData
->Fv
[Index
].FvPpi
= &mPeiFfs2FvPpi
;