2008-03-19 10:01:03 +01:00
|
|
|
/** @file
|
2008-07-16 11:40:06 +02:00
|
|
|
Pei Core Firmware File System service routines.
|
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation
|
2007-07-04 09:51:48 +02:00
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
2008-03-19 10:01:03 +01:00
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-10-31 05:35:02 +01:00
|
|
|
#include "PeiMain.h"
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-10-30 07:05:06 +01:00
|
|
|
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList = {
|
2007-09-24 13:38:43 +02:00
|
|
|
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
|
|
|
&gEfiPeiFirmwareVolumeInfoPpiGuid,
|
|
|
|
FirmwareVolmeInfoPpiNotifyCallback
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
|
2008-08-08 05:33:16 +02:00
|
|
|
((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
2008-08-08 05:33:16 +02:00
|
|
|
Returns the file state set by the highest zero bit in the State field
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
@param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
|
|
|
|
in the Attributes field.
|
|
|
|
@param FfsHeader Pointer to FFS File Header.
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit
|
|
|
|
in the header State field.
|
2008-07-16 11:40:06 +02:00
|
|
|
**/
|
|
|
|
EFI_FFS_FILE_STATE
|
|
|
|
GetFileState(
|
|
|
|
IN UINT8 ErasePolarity,
|
|
|
|
IN EFI_FFS_FILE_HEADER *FfsHeader
|
|
|
|
)
|
2007-07-04 09:51:48 +02:00
|
|
|
{
|
|
|
|
EFI_FFS_FILE_STATE FileState;
|
|
|
|
EFI_FFS_FILE_STATE HighestBit;
|
|
|
|
|
|
|
|
FileState = FfsHeader->State;
|
|
|
|
|
|
|
|
if (ErasePolarity != 0) {
|
|
|
|
FileState = (EFI_FFS_FILE_STATE)~FileState;
|
|
|
|
}
|
2008-08-08 05:33:16 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get file state set by its highest none zero bit.
|
|
|
|
//
|
2007-07-04 09:51:48 +02:00
|
|
|
HighestBit = 0x80;
|
|
|
|
while (HighestBit != 0 && (HighestBit & FileState) == 0) {
|
|
|
|
HighestBit >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HighestBit;
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
Calculates the checksum of the header of a file.
|
|
|
|
|
|
|
|
@param FileHeader Pointer to FFS File Header.
|
|
|
|
|
|
|
|
@return Checksum of the header.
|
|
|
|
Zero means the header is good.
|
|
|
|
Non-zero means the header is bad.
|
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
UINT8
|
|
|
|
CalculateHeaderChecksum (
|
|
|
|
IN EFI_FFS_FILE_HEADER *FileHeader
|
|
|
|
)
|
|
|
|
{
|
2008-08-08 05:33:16 +02:00
|
|
|
EFI_FFS_FILE_HEADER TestFileHeader;
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
CopyMem (&TestFileHeader, FileHeader, sizeof (EFI_FFS_FILE_HEADER));
|
2007-07-04 09:51:48 +02:00
|
|
|
//
|
2008-08-08 05:33:16 +02:00
|
|
|
// Ingore State and File field in FFS header.
|
2007-07-04 09:51:48 +02:00
|
|
|
//
|
2008-08-08 05:33:16 +02:00
|
|
|
TestFileHeader.State = 0;
|
|
|
|
TestFileHeader.IntegrityCheck.Checksum.File = 0;
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
return CalculateSum8 ((CONST UINT8 *) &TestFileHeader, sizeof (EFI_FFS_FILE_HEADER));
|
2007-07-04 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
Find FV handler according some FileHandle in that FV.
|
|
|
|
|
|
|
|
@param FileHandle Handle of file image
|
2008-08-08 05:33:16 +02:00
|
|
|
@param VolumeHandle Handle of the found FV, if not found, NULL will be set.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@retval TRUE The corresponding FV handler is found.
|
|
|
|
@retval FALSE The corresponding FV handler is not found.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
|
|
|
**/
|
2007-09-24 13:38:43 +02:00
|
|
|
BOOLEAN
|
|
|
|
EFIAPI
|
|
|
|
PeiFileHandleToVolume (
|
|
|
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
|
|
|
OUT EFI_PEI_FV_HANDLE *VolumeHandle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
PEI_CORE_INSTANCE *PrivateData;
|
|
|
|
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
|
|
|
|
|
|
|
|
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
|
|
|
|
for (Index = 0; Index < PrivateData->FvCount; Index++) {
|
|
|
|
FwVolHeader = PrivateData->Fv[Index].FvHeader;
|
2007-10-09 11:30:52 +02:00
|
|
|
if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) && \
|
|
|
|
((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {
|
2007-09-24 13:38:43 +02:00
|
|
|
*VolumeHandle = (EFI_PEI_FV_HANDLE)FwVolHeader;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-08-08 05:33:16 +02:00
|
|
|
*VolumeHandle = NULL;
|
2007-09-24 13:38:43 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
2008-08-08 05:33:16 +02:00
|
|
|
Given the input file pointer, search for the first matching file in the
|
2008-07-16 11:40:06 +02:00
|
|
|
FFS volume as defined by SearchType. The search starts from FileHeader inside
|
|
|
|
the Firmware Volume defined by FwVolHeader.
|
2008-08-08 05:33:16 +02:00
|
|
|
If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.
|
|
|
|
If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
|
|
|
|
the first PEIM, or COMBINED PEIM or FV file type FFS file will return.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
|
|
|
@param FvHandle Pointer to the FV header of the volume to search
|
|
|
|
@param FileName File name
|
|
|
|
@param SearchType Filter to find only files of this type.
|
|
|
|
Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
|
|
|
|
@param FileHandle This parameter must point to a valid FFS volume.
|
|
|
|
@param AprioriFile Pointer to AprioriFile image in this FV if has
|
2007-09-24 13:38:43 +02:00
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
@return EFI_NOT_FOUND No files matching the search criteria were found
|
|
|
|
@retval EFI_SUCCESS Success to search given file
|
|
|
|
|
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
EFI_STATUS
|
2007-09-24 13:38:43 +02:00
|
|
|
PeiFindFileEx (
|
|
|
|
IN CONST EFI_PEI_FV_HANDLE FvHandle,
|
|
|
|
IN CONST EFI_GUID *FileName, OPTIONAL
|
|
|
|
IN EFI_FV_FILETYPE SearchType,
|
|
|
|
IN OUT EFI_PEI_FILE_HANDLE *FileHandle,
|
|
|
|
IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL
|
2007-07-04 09:51:48 +02:00
|
|
|
)
|
|
|
|
{
|
2007-09-24 13:38:43 +02:00
|
|
|
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
|
|
|
|
EFI_FFS_FILE_HEADER **FileHeader;
|
|
|
|
EFI_FFS_FILE_HEADER *FfsFileHeader;
|
|
|
|
EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;
|
|
|
|
UINT32 FileLength;
|
|
|
|
UINT32 FileOccupiedSize;
|
|
|
|
UINT32 FileOffset;
|
|
|
|
UINT64 FvLength;
|
|
|
|
UINT8 ErasePolarity;
|
|
|
|
UINT8 FileState;
|
|
|
|
|
|
|
|
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FvHandle;
|
|
|
|
FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle;
|
2007-07-04 09:51:48 +02:00
|
|
|
|
|
|
|
FvLength = FwVolHeader->FvLength;
|
2008-10-20 15:33:43 +02:00
|
|
|
if ((FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {
|
2007-07-04 09:51:48 +02:00
|
|
|
ErasePolarity = 1;
|
|
|
|
} else {
|
|
|
|
ErasePolarity = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2007-09-24 13:38:43 +02:00
|
|
|
// If FileHeader is not specified (NULL) or FileName is not NULL,
|
|
|
|
// start with the first file in the firmware volume. Otherwise,
|
|
|
|
// start from the FileHeader.
|
2007-07-04 09:51:48 +02:00
|
|
|
//
|
2007-09-24 13:38:43 +02:00
|
|
|
if ((*FileHeader == NULL) || (FileName != NULL)) {
|
2007-07-04 09:51:48 +02:00
|
|
|
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength);
|
2007-09-24 13:38:43 +02:00
|
|
|
if (FwVolHeader->ExtHeaderOffset != 0) {
|
|
|
|
FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(((UINT8 *)FwVolHeader) + FwVolHeader->ExtHeaderOffset);
|
|
|
|
FfsFileHeader = (EFI_FFS_FILE_HEADER *)(((UINT8 *)FwVolExHeaderInfo) + FwVolExHeaderInfo->ExtHeaderSize);
|
|
|
|
}
|
2007-07-04 09:51:48 +02:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Length is 24 bits wide so mask upper 8 bits
|
|
|
|
// FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
|
|
|
|
//
|
|
|
|
FileLength = *(UINT32 *)(*FileHeader)->Size & 0x00FFFFFF;
|
2007-09-24 13:38:43 +02:00
|
|
|
FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
|
2007-07-04 09:51:48 +02:00
|
|
|
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);
|
|
|
|
}
|
2007-10-31 12:46:42 +01:00
|
|
|
|
2007-07-04 09:51:48 +02:00
|
|
|
FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);
|
|
|
|
ASSERT (FileOffset <= 0xFFFFFFFF);
|
2007-10-31 12:46:42 +01:00
|
|
|
|
2007-09-24 13:38:43 +02:00
|
|
|
while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {
|
2007-07-04 09:51:48 +02:00
|
|
|
//
|
|
|
|
// Get FileState which is the highest bit of the State
|
|
|
|
//
|
|
|
|
FileState = GetFileState (ErasePolarity, FfsFileHeader);
|
|
|
|
switch (FileState) {
|
|
|
|
|
|
|
|
case EFI_FILE_HEADER_INVALID:
|
2008-07-23 11:15:14 +02:00
|
|
|
FileOffset += sizeof(EFI_FFS_FILE_HEADER);
|
|
|
|
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER));
|
2007-07-04 09:51:48 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EFI_FILE_DATA_VALID:
|
|
|
|
case EFI_FILE_MARKED_FOR_UPDATE:
|
2007-09-24 13:38:43 +02:00
|
|
|
if (CalculateHeaderChecksum (FfsFileHeader) != 0) {
|
2007-07-04 09:51:48 +02:00
|
|
|
ASSERT (FALSE);
|
2007-10-31 12:46:42 +01:00
|
|
|
*FileHeader = NULL;
|
2007-07-04 09:51:48 +02:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
2007-09-24 13:38:43 +02:00
|
|
|
|
2008-07-23 11:15:14 +02:00
|
|
|
FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;
|
2007-09-24 13:38:43 +02:00
|
|
|
FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);
|
|
|
|
|
|
|
|
if (FileName != NULL) {
|
|
|
|
if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {
|
|
|
|
*FileHeader = FfsFileHeader;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
} else if (SearchType == PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE) {
|
|
|
|
if ((FfsFileHeader->Type == EFI_FV_FILETYPE_PEIM) ||
|
2007-12-06 10:52:27 +01:00
|
|
|
(FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER) ||
|
|
|
|
(FfsFileHeader->Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) {
|
2007-09-24 13:38:43 +02:00
|
|
|
|
|
|
|
*FileHeader = FfsFileHeader;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
} else if (AprioriFile != NULL) {
|
|
|
|
if (FfsFileHeader->Type == EFI_FV_FILETYPE_FREEFORM) {
|
|
|
|
if (CompareGuid (&FfsFileHeader->Name, &gPeiAprioriFileNameGuid)) {
|
|
|
|
*AprioriFile = FfsFileHeader;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-19 09:02:39 +01:00
|
|
|
} else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) &&
|
|
|
|
(FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) {
|
2007-09-24 13:38:43 +02:00
|
|
|
*FileHeader = FfsFileHeader;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-07-23 11:15:14 +02:00
|
|
|
FileOffset += FileOccupiedSize;
|
|
|
|
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);
|
2007-07-04 09:51:48 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EFI_FILE_DELETED:
|
2008-07-23 11:15:14 +02:00
|
|
|
FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;
|
|
|
|
FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);
|
|
|
|
FileOffset += FileOccupiedSize;
|
|
|
|
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);
|
2007-07-04 09:51:48 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-10-31 12:46:42 +01:00
|
|
|
*FileHeader = NULL;
|
2007-07-04 09:51:48 +02:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
2007-10-31 12:46:42 +01:00
|
|
|
|
|
|
|
*FileHeader = NULL;
|
2007-07-04 09:51:48 +02:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
Initialize PeiCore Fv List.
|
|
|
|
|
|
|
|
@param PrivateData - Pointer to PEI_CORE_INSTANCE.
|
|
|
|
@param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
|
|
|
|
**/
|
2007-09-24 13:38:43 +02:00
|
|
|
VOID
|
|
|
|
PeiInitializeFv (
|
|
|
|
IN PEI_CORE_INSTANCE *PrivateData,
|
|
|
|
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
//
|
|
|
|
// The BFV must be the first entry. The Core FV support is stateless
|
|
|
|
// The AllFV list has a single entry per FV in PEI.
|
|
|
|
// The Fv list only includes FV that PEIMs will be dispatched from and
|
|
|
|
// its File System Format is PI 1.0 definition.
|
|
|
|
//
|
|
|
|
PrivateData->FvCount = 1;
|
|
|
|
PrivateData->Fv[0].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;
|
|
|
|
|
|
|
|
PrivateData->AllFvCount = 1;
|
|
|
|
PrivateData->AllFv[0] = (EFI_PEI_FV_HANDLE)PrivateData->Fv[0].FvHeader;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Post a call-back for the FvInfoPPI services to expose
|
|
|
|
// additional Fvs to PeiCore.
|
|
|
|
//
|
|
|
|
Status = PeiServicesNotifyPpi (&mNotifyOnFvInfoList);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
Process Firmware Volum Information once FvInfoPPI install.
|
2008-08-08 05:33:16 +02:00
|
|
|
The FV Info will be registered into PeiCore private data structure.
|
|
|
|
And search the inside FV image, if found, the new FV INFO PPI will be installed.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
|
2008-08-08 05:05:03 +02:00
|
|
|
@param NotifyDescriptor Address of the notification descriptor data structure.
|
|
|
|
@param Ppi Address of the PPI that was installed.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.
|
2008-09-03 08:25:35 +02:00
|
|
|
@return if not EFI_SUCESS, fail to verify FV.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
|
|
|
**/
|
2007-09-24 13:38:43 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FirmwareVolmeInfoPpiNotifyCallback (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT8 FvCount;
|
|
|
|
EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *Fv;
|
|
|
|
PEI_CORE_INSTANCE *PrivateData;
|
2007-12-06 10:52:27 +01:00
|
|
|
EFI_PEI_FILE_HANDLE FileHandle;
|
|
|
|
VOID *DepexData;
|
|
|
|
UINT32 AuthenticationStatus;
|
|
|
|
EFI_STATUS Status;
|
2007-09-24 13:38:43 +02:00
|
|
|
|
2007-12-06 10:52:27 +01:00
|
|
|
FileHandle = NULL;
|
|
|
|
DepexData = NULL;
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
|
2007-09-24 13:38:43 +02:00
|
|
|
|
2007-10-15 13:15:39 +02:00
|
|
|
if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {
|
2007-09-24 13:38:43 +02:00
|
|
|
ASSERT (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Fv = (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *)Ppi;
|
|
|
|
|
2007-12-06 10:52:27 +01:00
|
|
|
if (CompareGuid (&Fv->FvFormat, &gEfiFirmwareFileSystem2Guid)) {
|
|
|
|
for (FvCount = 0; FvCount < PrivateData->FvCount; FvCount ++) {
|
|
|
|
if ((UINTN)PrivateData->Fv[FvCount].FvHeader == (UINTN)Fv->FvInfo) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2008-09-03 08:25:35 +02:00
|
|
|
|
|
|
|
Status = VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER*)Fv->FvInfo);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "Fail to verify FV which address is 0x%11p", (VOID *) Fv->FvInfo));
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2007-09-24 13:38:43 +02:00
|
|
|
PrivateData->Fv[PrivateData->FvCount++].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Fv->FvInfo;
|
|
|
|
|
2007-12-06 10:52:27 +01:00
|
|
|
//
|
|
|
|
// Only add FileSystem2 Fv to the All list
|
|
|
|
//
|
|
|
|
PrivateData->AllFv[PrivateData->AllFvCount++] = (EFI_PEI_FV_HANDLE)Fv->FvInfo;
|
|
|
|
|
2008-12-18 09:48:36 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "The %dth FvImage start address is 0x%11p and size is 0x%08x\n", (UINT32)PrivateData->AllFvCount, (VOID *) Fv->FvInfo, Fv->FvInfoSize));
|
2007-12-06 10:52:27 +01:00
|
|
|
//
|
|
|
|
// Preprocess all FV type files in this new FileSystem2 Fv image
|
|
|
|
//
|
|
|
|
do {
|
|
|
|
Status = PeiFindFileEx (
|
|
|
|
(EFI_PEI_FV_HANDLE)Fv->FvInfo,
|
|
|
|
NULL,
|
|
|
|
EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,
|
|
|
|
&FileHandle,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = PeiFfsFindSectionData (
|
|
|
|
(CONST EFI_PEI_SERVICES **) PeiServices,
|
|
|
|
EFI_SECTION_PEI_DEPEX,
|
|
|
|
FileHandle,
|
|
|
|
(VOID **)&DepexData
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
if (!PeimDispatchReadiness (PeiServices, DepexData)) {
|
|
|
|
//
|
|
|
|
// Dependency is not satisfied.
|
|
|
|
//
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Process FvFile to install FvInfo ppi and build FvHob
|
|
|
|
//
|
2008-10-21 07:55:27 +02:00
|
|
|
ProcessFvFile ((CONST EFI_PEI_SERVICES **) PeiServices, FileHandle, &AuthenticationStatus);
|
2007-12-06 10:52:27 +01:00
|
|
|
}
|
|
|
|
} while (FileHandle != NULL);
|
|
|
|
}
|
2007-09-24 13:38:43 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
2008-08-08 05:33:16 +02:00
|
|
|
Go through the file to search SectionType section.
|
|
|
|
Search within encapsulation sections (compression and GUIDed) recursively,
|
|
|
|
until the match section is found.
|
|
|
|
|
|
|
|
@param PeiServices - An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
|
|
|
@param SectionType - Filter to find only section of this type.
|
|
|
|
@param Section - From where to search.
|
|
|
|
@param SectionSize - The file size to search.
|
|
|
|
@param OutputBuffer - A pointer to the discovered section, if successful.
|
|
|
|
NULL if section not found
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@return EFI_NOT_FOUND The match section is not found.
|
|
|
|
@return EFI_SUCCESS The match section is found.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
|
|
|
**/
|
2007-09-24 13:38:43 +02:00
|
|
|
EFI_STATUS
|
|
|
|
PeiFfsProcessSection (
|
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_SECTION_TYPE SectionType,
|
|
|
|
IN EFI_COMMON_SECTION_HEADER *Section,
|
|
|
|
IN UINTN SectionSize,
|
2007-12-06 10:52:27 +01:00
|
|
|
OUT VOID **OutputBuffer
|
2007-09-24 13:38:43 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 SectionLength;
|
|
|
|
UINT32 ParsedLength;
|
|
|
|
EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;
|
|
|
|
EFI_PEI_DECOMPRESS_PPI *DecompressPpi;
|
|
|
|
VOID *PpiOutput;
|
|
|
|
UINTN PpiOutputSize;
|
2007-12-06 10:52:27 +01:00
|
|
|
UINTN Index;
|
|
|
|
UINT32 Authentication;
|
|
|
|
PEI_CORE_INSTANCE *PrivateData;
|
2007-09-24 13:38:43 +02:00
|
|
|
|
2007-12-06 10:52:27 +01:00
|
|
|
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
|
2007-09-24 13:38:43 +02:00
|
|
|
*OutputBuffer = NULL;
|
2007-12-06 10:52:27 +01:00
|
|
|
ParsedLength = 0;
|
|
|
|
Index = 0;
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
PpiOutput = NULL;
|
|
|
|
PpiOutputSize = 0;
|
2007-09-24 13:38:43 +02:00
|
|
|
while (ParsedLength < SectionSize) {
|
|
|
|
if (Section->Type == SectionType) {
|
|
|
|
*OutputBuffer = (VOID *)(Section + 1);
|
|
|
|
return EFI_SUCCESS;
|
2007-12-06 10:52:27 +01:00
|
|
|
} else if ((Section->Type == EFI_SECTION_GUID_DEFINED) || (Section->Type == EFI_SECTION_COMPRESSION)) {
|
|
|
|
//
|
|
|
|
// Check the encapsulated section is extracted into the cache data.
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < PrivateData->CacheSection.AllSectionCount; Index ++) {
|
|
|
|
if (Section == PrivateData->CacheSection.Section[Index]) {
|
|
|
|
PpiOutput = PrivateData->CacheSection.SectionData[Index];
|
|
|
|
PpiOutputSize = PrivateData->CacheSection.SectionSize[Index];
|
|
|
|
//
|
|
|
|
// Search section directly from the cache data.
|
|
|
|
//
|
2007-09-24 13:38:43 +02:00
|
|
|
return PeiFfsProcessSection (
|
|
|
|
PeiServices,
|
|
|
|
SectionType,
|
|
|
|
PpiOutput,
|
|
|
|
PpiOutputSize,
|
2007-12-06 10:52:27 +01:00
|
|
|
OutputBuffer
|
2007-09-24 13:38:43 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2007-12-06 10:52:27 +01:00
|
|
|
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
if (Section->Type == EFI_SECTION_GUID_DEFINED) {
|
|
|
|
Status = PeiServicesLocatePpi (
|
|
|
|
&((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
(VOID **) &GuidSectionPpi
|
|
|
|
);
|
2007-09-24 13:38:43 +02:00
|
|
|
if (!EFI_ERROR (Status)) {
|
2007-12-06 10:52:27 +01:00
|
|
|
Status = GuidSectionPpi->ExtractSection (
|
|
|
|
GuidSectionPpi,
|
|
|
|
Section,
|
|
|
|
&PpiOutput,
|
|
|
|
&PpiOutputSize,
|
|
|
|
&Authentication
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if (Section->Type == EFI_SECTION_COMPRESSION) {
|
|
|
|
Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = DecompressPpi->Decompress (
|
|
|
|
DecompressPpi,
|
|
|
|
(CONST EFI_COMPRESSION_SECTION*) Section,
|
|
|
|
&PpiOutput,
|
|
|
|
&PpiOutputSize
|
|
|
|
);
|
2007-09-24 13:38:43 +02:00
|
|
|
}
|
|
|
|
}
|
2007-12-06 10:52:27 +01:00
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Update cache section data.
|
|
|
|
//
|
|
|
|
if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {
|
|
|
|
PrivateData->CacheSection.AllSectionCount ++;
|
|
|
|
}
|
|
|
|
PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;
|
|
|
|
PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;
|
|
|
|
PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;
|
|
|
|
PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;
|
|
|
|
|
|
|
|
return PeiFfsProcessSection (
|
|
|
|
PeiServices,
|
|
|
|
SectionType,
|
|
|
|
PpiOutput,
|
|
|
|
PpiOutputSize,
|
|
|
|
OutputBuffer
|
|
|
|
);
|
|
|
|
}
|
2007-09-24 13:38:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Size is 24 bits wide so mask upper 8 bits.
|
|
|
|
// SectionLength is adjusted it is 4 byte aligned.
|
|
|
|
// Go to the next section
|
|
|
|
//
|
|
|
|
SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;
|
|
|
|
SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);
|
|
|
|
ASSERT (SectionLength != 0);
|
|
|
|
ParsedLength += SectionLength;
|
|
|
|
Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
2008-08-08 05:33:16 +02:00
|
|
|
Given the input file pointer, search for the first matching section in the
|
2008-07-16 11:40:06 +02:00
|
|
|
FFS volume.
|
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
|
2008-07-16 11:40:06 +02:00
|
|
|
@param SectionType Filter to find only sections of this type.
|
|
|
|
@param FileHandle Pointer to the current file to search.
|
2008-08-08 05:33:16 +02:00
|
|
|
@param SectionData A pointer to the discovered section, if successful.
|
2008-07-16 11:40:06 +02:00
|
|
|
NULL if section not found
|
|
|
|
|
|
|
|
@retval EFI_NOT_FOUND No files matching the search criteria were found
|
|
|
|
@retval EFI_SUCCESS Success to find section data in given file
|
|
|
|
|
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PeiFfsFindSectionData (
|
2007-09-04 08:12:48 +02:00
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices,
|
2007-07-04 09:51:48 +02:00
|
|
|
IN EFI_SECTION_TYPE SectionType,
|
2007-09-04 08:12:48 +02:00
|
|
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
2007-07-04 09:51:48 +02:00
|
|
|
IN OUT VOID **SectionData
|
|
|
|
)
|
|
|
|
{
|
2007-09-24 13:38:43 +02:00
|
|
|
EFI_FFS_FILE_HEADER *FfsFileHeader;
|
|
|
|
UINT32 FileSize;
|
|
|
|
EFI_COMMON_SECTION_HEADER *Section;
|
|
|
|
|
|
|
|
FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);
|
2007-07-04 09:51:48 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Size is 24 bits wide so mask upper 8 bits.
|
2007-09-24 13:38:43 +02:00
|
|
|
// Does not include FfsFileHeader header size
|
2007-07-04 09:51:48 +02:00
|
|
|
// FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
|
|
|
|
//
|
|
|
|
Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);
|
|
|
|
FileSize = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;
|
2007-09-24 13:38:43 +02:00
|
|
|
FileSize -= sizeof (EFI_FFS_FILE_HEADER);
|
|
|
|
|
|
|
|
return PeiFfsProcessSection (
|
2007-12-06 10:52:27 +01:00
|
|
|
PeiServices,
|
2007-09-24 13:38:43 +02:00
|
|
|
SectionType,
|
|
|
|
Section,
|
|
|
|
FileSize,
|
2007-12-06 10:52:27 +01:00
|
|
|
SectionData
|
2007-09-24 13:38:43 +02:00
|
|
|
);
|
2007-07-04 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
Given the input file pointer, search for the next matching file in the
|
|
|
|
FFS volume as defined by SearchType. The search starts from FileHeader inside
|
|
|
|
the Firmware Volume defined by FwVolHeader.
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-08 05:22:23 +02:00
|
|
|
@param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
2008-07-16 11:40:06 +02:00
|
|
|
@param SearchType Filter to find only files of this type.
|
|
|
|
Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
|
|
|
|
@param VolumeHandle Pointer to the FV header of the volume to search.
|
|
|
|
@param FileHandle Pointer to the current file from which to begin searching.
|
|
|
|
This pointer will be updated upon return to reflect the file found.
|
|
|
|
@retval EFI_NOT_FOUND No files matching the search criteria were found
|
|
|
|
@retval EFI_SUCCESS Success to find next file in given volume
|
|
|
|
|
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PeiFfsFindNextFile (
|
2007-09-04 08:12:48 +02:00
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN UINT8 SearchType,
|
|
|
|
IN EFI_PEI_FV_HANDLE VolumeHandle,
|
|
|
|
IN OUT EFI_PEI_FILE_HANDLE *FileHandle
|
2007-07-04 09:51:48 +02:00
|
|
|
)
|
|
|
|
{
|
2007-09-24 13:38:43 +02:00
|
|
|
return PeiFindFileEx (VolumeHandle, NULL, SearchType, FileHandle, NULL);
|
2007-07-04 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2007-09-24 13:38:43 +02:00
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
2008-08-08 05:33:16 +02:00
|
|
|
Search the firmware volumes by index
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
|
2008-07-16 11:40:06 +02:00
|
|
|
@param Instance Instance of FV to find
|
|
|
|
@param VolumeHandle Pointer to found Volume.
|
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETER FwVolHeader is NULL
|
|
|
|
@retval EFI_SUCCESS Firmware volume instance successfully found.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PeiFvFindNextVolume (
|
2008-08-21 09:51:03 +02:00
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices,
|
2007-07-04 09:51:48 +02:00
|
|
|
IN UINTN Instance,
|
2007-09-04 08:12:48 +02:00
|
|
|
IN OUT EFI_PEI_FV_HANDLE *VolumeHandle
|
2007-07-04 09:51:48 +02:00
|
|
|
)
|
|
|
|
{
|
2008-08-21 09:51:03 +02:00
|
|
|
PEI_CORE_INSTANCE *Private;
|
|
|
|
UINTN Index;
|
|
|
|
BOOLEAN Match;
|
|
|
|
EFI_HOB_FIRMWARE_VOLUME *FvHob;
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2007-09-24 13:38:43 +02:00
|
|
|
Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
|
|
|
|
if (VolumeHandle == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
2008-08-21 09:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Handle Framework FvHob and Install FvInfo Ppi for it.
|
|
|
|
//
|
|
|
|
if (FeaturePcdGet (PcdFrameworkFvHobCompatibilitySupport)) {
|
|
|
|
//
|
|
|
|
// Loop to search the wanted FirmwareVolume which supports FFS
|
|
|
|
//
|
|
|
|
FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);
|
|
|
|
while (FvHob != NULL) {
|
|
|
|
for (Index = 0, Match = FALSE; Index < Private->AllFvCount; Index++) {
|
|
|
|
if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->AllFv[Index]) {
|
|
|
|
Match = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// If Not Found, Install FvInfo Ppi for it.
|
|
|
|
//
|
|
|
|
if (!Match) {
|
2008-11-13 10:17:38 +01:00
|
|
|
PeiServicesInstallFvInfoPpi (
|
2008-08-21 09:51:03 +02:00
|
|
|
NULL,
|
|
|
|
(VOID *)(UINTN)FvHob->BaseAddress,
|
|
|
|
(UINT32)FvHob->Length,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength));
|
|
|
|
}
|
|
|
|
}
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2007-09-24 13:38:43 +02:00
|
|
|
if (Instance >= Private->AllFvCount) {
|
|
|
|
VolumeHandle = NULL;
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2007-09-24 13:38:43 +02:00
|
|
|
*VolumeHandle = Private->AllFv[Instance];
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2007-07-04 09:51:48 +02:00
|
|
|
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
2008-08-08 05:33:16 +02:00
|
|
|
Find a file within a volume by its name.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@param FileName A pointer to the name of the file to find within the firmware volume.
|
|
|
|
@param VolumeHandle The firmware volume to search
|
|
|
|
@param FileHandle Upon exit, points to the found file's handle
|
|
|
|
or NULL if it could not be found.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-08 05:33:16 +02:00
|
|
|
@retval EFI_SUCCESS File was found.
|
|
|
|
@retval EFI_NOT_FOUND File was not found.
|
|
|
|
@retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
|
|
|
**/
|
2007-09-24 13:38:43 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PeiFfsFindFileByName (
|
|
|
|
IN CONST EFI_GUID *FileName,
|
|
|
|
IN EFI_PEI_FV_HANDLE VolumeHandle,
|
|
|
|
OUT EFI_PEI_FILE_HANDLE *FileHandle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {
|
2007-07-04 09:51:48 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2007-09-24 13:38:43 +02:00
|
|
|
Status = PeiFindFileEx (VolumeHandle, FileName, 0, FileHandle, NULL);
|
|
|
|
if (Status == EFI_NOT_FOUND) {
|
|
|
|
*FileHandle = NULL;
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
|
|
|
|
Returns information about a specific file.
|
|
|
|
|
|
|
|
|
|
|
|
@param FileHandle - The handle to file.
|
|
|
|
@param FileInfo - Pointer to the file information.
|
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETER Invalid FileHandle or FileInfo.
|
|
|
|
@retval EFI_SUCCESS Success to collect file info.
|
|
|
|
|
|
|
|
**/
|
2007-09-24 13:38:43 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PeiFfsGetFileInfo (
|
|
|
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
|
|
|
OUT EFI_FV_FILE_INFO *FileInfo
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT8 FileState;
|
|
|
|
UINT8 ErasePolarity;
|
|
|
|
EFI_FFS_FILE_HEADER *FileHeader;
|
|
|
|
EFI_PEI_FV_HANDLE VolumeHandle;
|
|
|
|
|
|
|
|
if ((FileHandle == NULL) || (FileInfo == NULL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-03-10 04:32:08 +01:00
|
|
|
VolumeHandle = 0;
|
2007-09-24 13:38:43 +02:00
|
|
|
//
|
|
|
|
// Retrieve the FirmwareVolume which the file resides in.
|
|
|
|
//
|
|
|
|
if (!PeiFileHandleToVolume(FileHandle, &VolumeHandle)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2007-12-10 04:47:56 +01:00
|
|
|
if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB2_ERASE_POLARITY) {
|
2007-09-24 13:38:43 +02:00
|
|
|
ErasePolarity = 1;
|
2007-07-04 09:51:48 +02:00
|
|
|
} else {
|
2007-09-24 13:38:43 +02:00
|
|
|
ErasePolarity = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get FileState which is the highest bit of the State
|
|
|
|
//
|
|
|
|
FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2007-09-24 13:38:43 +02:00
|
|
|
switch (FileState) {
|
|
|
|
case EFI_FILE_DATA_VALID:
|
|
|
|
case EFI_FILE_MARKED_FOR_UPDATE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return EFI_INVALID_PARAMETER;
|
2007-07-04 09:51:48 +02:00
|
|
|
}
|
2007-09-24 13:38:43 +02:00
|
|
|
|
|
|
|
FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;
|
|
|
|
CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));
|
|
|
|
FileInfo->FileType = FileHeader->Type;
|
|
|
|
FileInfo->FileAttributes = FileHeader->Attributes;
|
|
|
|
FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER);
|
|
|
|
FileInfo->Buffer = (FileHeader + 1);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
|
|
|
|
Collect information of given Fv Volume.
|
|
|
|
|
|
|
|
@param VolumeHandle - The handle to Fv Volume.
|
|
|
|
@param VolumeInfo - The pointer to volume information.
|
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETER VolumeInfo is NULL
|
|
|
|
@retval EFI_SUCCESS Success to collect fv info.
|
|
|
|
**/
|
2007-09-24 13:38:43 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PeiFfsGetVolumeInfo (
|
|
|
|
IN EFI_PEI_FV_HANDLE VolumeHandle,
|
|
|
|
OUT EFI_FV_INFO *VolumeInfo
|
|
|
|
)
|
|
|
|
{
|
2007-12-06 10:52:27 +01:00
|
|
|
EFI_FIRMWARE_VOLUME_HEADER FwVolHeader;
|
2007-09-24 13:38:43 +02:00
|
|
|
EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;
|
|
|
|
|
|
|
|
if (VolumeInfo == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
2007-07-04 09:51:48 +02:00
|
|
|
}
|
2007-12-06 10:52:27 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// VolumeHandle may not align at 8 byte,
|
|
|
|
// but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.
|
|
|
|
// So, Copy FvHeader into the local FvHeader structure.
|
|
|
|
//
|
|
|
|
CopyMem (&FwVolHeader, VolumeHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));
|
|
|
|
//
|
|
|
|
// Check Fv Image Signature
|
|
|
|
//
|
|
|
|
if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
VolumeInfo->FvAttributes = FwVolHeader.Attributes;
|
|
|
|
VolumeInfo->FvStart = (VOID *) VolumeHandle;
|
|
|
|
VolumeInfo->FvSize = FwVolHeader.FvLength;
|
|
|
|
CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));
|
2007-09-24 13:38:43 +02:00
|
|
|
|
2007-12-06 10:52:27 +01:00
|
|
|
if (FwVolHeader.ExtHeaderOffset != 0) {
|
|
|
|
FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset);
|
2007-09-24 13:38:43 +02:00
|
|
|
CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));
|
|
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
2007-07-04 09:51:48 +02:00
|
|
|
}
|
2007-09-24 13:38:43 +02:00
|
|
|
|
2008-09-03 09:26:40 +02:00
|
|
|
/**
|
|
|
|
Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.
|
|
|
|
|
|
|
|
@param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
|
|
|
@param FvFileHandle File handle of a Fv type file.
|
|
|
|
@param AuthenticationState Pointer to attestation authentication state of image.
|
|
|
|
|
|
|
|
|
|
|
|
@retval EFI_NOT_FOUND FV image can't be found.
|
|
|
|
@retval EFI_SUCCESS Successfully to process it.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image
|
|
|
|
@retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
ProcessFvFile (
|
2008-10-21 07:55:27 +02:00
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_FILE_HANDLE FvFileHandle,
|
|
|
|
OUT UINT32 *AuthenticationState
|
2008-09-03 09:26:40 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PEI_FV_HANDLE FvImageHandle;
|
|
|
|
EFI_FV_INFO FvImageInfo;
|
|
|
|
UINT32 FvAlignment;
|
|
|
|
VOID *FvBuffer;
|
|
|
|
EFI_PEI_HOB_POINTERS HobPtr;
|
|
|
|
|
|
|
|
FvBuffer = NULL;
|
|
|
|
*AuthenticationState = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
|
|
|
|
// been extracted.
|
|
|
|
//
|
|
|
|
HobPtr.Raw = GetHobList ();
|
|
|
|
while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {
|
|
|
|
if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {
|
|
|
|
//
|
|
|
|
// this FILE has been dispatched, it will not be dispatched again.
|
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
HobPtr.Raw = GET_NEXT_HOB (HobPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Find FvImage in FvFile
|
|
|
|
//
|
|
|
|
Status = PeiFfsFindSectionData (
|
2008-10-21 07:55:27 +02:00
|
|
|
PeiServices,
|
2008-09-03 09:26:40 +02:00
|
|
|
EFI_SECTION_FIRMWARE_VOLUME_IMAGE,
|
|
|
|
FvFileHandle,
|
|
|
|
(VOID **)&FvImageHandle
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Collect FvImage Info.
|
|
|
|
//
|
|
|
|
Status = PeiFfsGetVolumeInfo (FvImageHandle, &FvImageInfo);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// FvAlignment must be more than 8 bytes required by FvHeader structure.
|
|
|
|
//
|
|
|
|
FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16);
|
|
|
|
if (FvAlignment < 8) {
|
|
|
|
FvAlignment = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check FvImage
|
|
|
|
//
|
|
|
|
if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {
|
|
|
|
FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment);
|
|
|
|
if (FvBuffer == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize);
|
|
|
|
//
|
|
|
|
// Update FvImageInfo after reload FvImage to new aligned memory
|
|
|
|
//
|
|
|
|
PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install FvPpi and Build FvHob
|
|
|
|
//
|
2008-11-13 10:17:38 +01:00
|
|
|
PeiServicesInstallFvInfoPpi (
|
2008-09-03 09:26:40 +02:00
|
|
|
NULL,
|
|
|
|
FvImageInfo.FvStart,
|
|
|
|
(UINT32) FvImageInfo.FvSize,
|
|
|
|
&(FvImageInfo.FvName),
|
|
|
|
&(((EFI_FFS_FILE_HEADER*)FvFileHandle)->Name)
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase
|
|
|
|
//
|
2008-09-19 07:05:40 +02:00
|
|
|
BuildFvHob (
|
|
|
|
(EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,
|
|
|
|
FvImageInfo.FvSize
|
|
|
|
);
|
2008-09-03 09:26:40 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Makes the encapsulated volume show up in DXE phase to skip processing of
|
|
|
|
// encapsulated file again.
|
|
|
|
//
|
|
|
|
BuildFv2Hob (
|
|
|
|
(EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,
|
|
|
|
FvImageInfo.FvSize,
|
|
|
|
&FvImageInfo.FvName,
|
|
|
|
&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name)
|
|
|
|
);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|