-/*++\r
-\r
+/** @file\r
+ Pei Core Firmware File System service routines.\r
+ \r
Copyright (c) 2006 - 2007, Intel Corporation \r
All rights reserved. This program and the accompanying materials \r
are licensed and made available under the terms and conditions of the BSD License \r
\r
Abstract:\r
\r
- Pei Core Firmware File System service routines.\r
+ \r
\r
---*/\r
+**/\r
\r
#include <PeiMain.h>\r
\r
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \\r
(ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))\r
\r
-STATIC\r
-EFI_FFS_FILE_STATE\r
-GetFileState(\r
- IN UINT8 ErasePolarity,\r
- IN EFI_FFS_FILE_HEADER *FfsHeader\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
+/**\r
Returns the highest bit set of the State field\r
\r
-Arguments:\r
\r
- ErasePolarity - Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY\r
- in the Attributes field.\r
- FfsHeader - Pointer to FFS File Header.\r
+ @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY\r
+ in the Attributes field.\r
+ @param FfsHeader Pointer to FFS File Header.\r
\r
-Returns:\r
- Returns the highest bit in the State field\r
+ @return Returns the highest bit in the State field\r
\r
---*/\r
+**/\r
+EFI_FFS_FILE_STATE\r
+GetFileState(\r
+ IN UINT8 ErasePolarity,\r
+ IN EFI_FFS_FILE_HEADER *FfsHeader\r
+ )\r
{\r
EFI_FFS_FILE_STATE FileState;\r
EFI_FFS_FILE_STATE HighestBit;\r
return HighestBit;\r
} \r
\r
-STATIC\r
+/**\r
+ Calculates the checksum of the header of a file.\r
+\r
+ @param FileHeader Pointer to FFS File Header.\r
+\r
+ @return Checksum of the header.\r
+ The header is zero byte checksum.\r
+ Zero means the header is good.\r
+ Non-zero means the header is bad.\r
+**/\r
UINT8\r
CalculateHeaderChecksum (\r
IN EFI_FFS_FILE_HEADER *FileHeader\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Calculates the checksum of the header of a file.\r
-\r
-Arguments:\r
-\r
- FileHeader - Pointer to FFS File Header.\r
-\r
-Returns:\r
- Checksum of the header.\r
- \r
- The header is zero byte checksum.\r
- - Zero means the header is good.\r
- - Non-zero means the header is bad.\r
- \r
- \r
-Bugbug: For PEI performance reason, we comments this code at this time.\r
---*/\r
{\r
- UINT8 *ptr;\r
+ UINT8 *Ptr;\r
UINTN Index;\r
UINT8 Sum;\r
\r
Sum = 0;\r
- ptr = (UINT8 *)FileHeader;\r
+ Ptr = (UINT8 *)FileHeader;\r
\r
for (Index = 0; Index < sizeof(EFI_FFS_FILE_HEADER) - 3; Index += 4) {\r
- Sum = (UINT8)(Sum + ptr[Index]);\r
- Sum = (UINT8)(Sum + ptr[Index+1]);\r
- Sum = (UINT8)(Sum + ptr[Index+2]);\r
- Sum = (UINT8)(Sum + ptr[Index+3]);\r
+ Sum = (UINT8)(Sum + Ptr[Index]);\r
+ Sum = (UINT8)(Sum + Ptr[Index+1]);\r
+ Sum = (UINT8)(Sum + Ptr[Index+2]);\r
+ Sum = (UINT8)(Sum + Ptr[Index+3]);\r
}\r
\r
for (; Index < sizeof(EFI_FFS_FILE_HEADER); Index++) {\r
- Sum = (UINT8)(Sum + ptr[Index]);\r
+ Sum = (UINT8)(Sum + Ptr[Index]);\r
}\r
\r
//\r
return Sum;\r
}\r
\r
-STATIC\r
+/**\r
+ Find FV handler according some FileHandle in that FV.\r
+\r
+ @param FileHandle Handle of file image\r
+ @param VolumeHandle Handle of FV\r
+\r
+ @return EDES_TODO: Add description for return value\r
+\r
+**/\r
BOOLEAN\r
EFIAPI\r
PeiFileHandleToVolume (\r
return FALSE;\r
}\r
\r
+/**\r
+ Given the input file pointer, search for the next matching file in the\r
+ FFS volume as defined by SearchType. The search starts from FileHeader inside\r
+ the Firmware Volume defined by FwVolHeader.\r
+\r
\r
+ @param FvHandle Pointer to the FV header of the volume to search\r
+ @param FileName File name\r
+ @param SearchType Filter to find only files of this type.\r
+ Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
+ @param FileHandle This parameter must point to a valid FFS volume.\r
+ @param AprioriFile Pointer to AprioriFile image in this FV if has\r
+\r
+ @return EFI_NOT_FOUND No files matching the search criteria were found\r
+ @retval EFI_SUCCESS Success to search given file\r
+\r
+**/\r
EFI_STATUS\r
PeiFindFileEx (\r
IN CONST EFI_PEI_FV_HANDLE FvHandle,\r
IN OUT EFI_PEI_FILE_HANDLE *FileHandle,\r
IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL\r
)\r
-/*++\r
-\r
-Routine Description:\r
- Given the input file pointer, search for the next matching file in the\r
- FFS volume as defined by SearchType. The search starts from FileHeader inside\r
- the Firmware Volume defined by FwVolHeader.\r
-\r
-Arguments:\r
- PeiServices - Pointer to the PEI Core Services Table.\r
- SearchType - Filter to find only files of this type.\r
- Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
- FwVolHeader - Pointer to the FV header of the volume to search.\r
- This parameter must point to a valid FFS volume.\r
- FileHeader - Pointer to the current file from which to begin searching.\r
- This pointer will be updated upon return to reflect the file found.\r
- Flag - Indicator for if this is for PEI Dispath search \r
- \r
-Returns:\r
- EFI_NOT_FOUND - No files matching the search criteria were found\r
- EFI_SUCCESS\r
-\r
---*/\r
{\r
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
EFI_FFS_FILE_HEADER **FileHeader;\r
FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle;\r
\r
FvLength = FwVolHeader->FvLength;\r
- if (FwVolHeader->Attributes & EFI_FVB_ERASE_POLARITY) {\r
+ if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
ErasePolarity = 1;\r
} else {\r
ErasePolarity = 0;\r
FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);\r
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);\r
}\r
-\r
+ \r
FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);\r
ASSERT (FileOffset <= 0xFFFFFFFF);\r
- \r
+\r
while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r
//\r
// Get FileState which is the highest bit of the State \r
case EFI_FILE_MARKED_FOR_UPDATE:\r
if (CalculateHeaderChecksum (FfsFileHeader) != 0) {\r
ASSERT (FALSE);\r
+ *FileHeader = NULL;\r
return EFI_NOT_FOUND;\r
}\r
\r
}\r
} else if (SearchType == PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE) {\r
if ((FfsFileHeader->Type == EFI_FV_FILETYPE_PEIM) || \r
- (FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER)) { \r
+ (FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER) ||\r
+ (FfsFileHeader->Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) { \r
\r
*FileHeader = FfsFileHeader;\r
return EFI_SUCCESS;\r
} \r
} \r
}\r
- } else if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) { \r
+ } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) && \r
+ (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) { \r
*FileHeader = FfsFileHeader;\r
return EFI_SUCCESS;\r
}\r
break;\r
\r
default:\r
+ *FileHeader = NULL;\r
return EFI_NOT_FOUND;\r
-\r
} \r
}\r
-\r
+ \r
+ *FileHeader = NULL;\r
return EFI_NOT_FOUND; \r
}\r
\r
+/**\r
+\r
+ Initialize PeiCore Fv List.\r
+\r
+\r
+ @param PrivateData - Pointer to PEI_CORE_INSTANCE.\r
+ @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.\r
+\r
+ @return NONE\r
+\r
+**/\r
VOID \r
PeiInitializeFv (\r
IN PEI_CORE_INSTANCE *PrivateData,\r
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Initialize PeiCore Fv List.\r
-\r
-Arguments:\r
- PrivateData - Pointer to PEI_CORE_INSTANCE.\r
- SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.\r
-\r
-Returns:\r
- NONE \r
- \r
---*/ \r
{\r
EFI_STATUS Status;\r
//\r
\r
}\r
\r
+/**\r
+ Process Firmware Volum Information once FvInfoPPI install.\r
+\r
+\r
+ @param PeiServices - General purpose services available to every PEIM.\r
+ @param NotifyDescriptor EDES_TODO: Add parameter description\r
+ @param Ppi EDES_TODO: Add parameter description\r
+\r
+ @retval EFI_SUCCESS if the interface could be successfully installed\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
FirmwareVolmeInfoPpiNotifyCallback (\r
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
IN VOID *Ppi\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Process Firmware Volum Information once FvInfoPPI install.\r
-\r
-Arguments:\r
-\r
- PeiServices - General purpose services available to every PEIM.\r
- \r
-Returns:\r
-\r
- Status - EFI_SUCCESS if the interface could be successfully\r
- installed\r
-\r
---*/\r
{\r
UINT8 FvCount;\r
EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *Fv;\r
PEI_CORE_INSTANCE *PrivateData;\r
+ EFI_PEI_FILE_HANDLE FileHandle;\r
+ VOID *DepexData;\r
+ UINT32 AuthenticationStatus;\r
+ EFI_STATUS Status;\r
\r
- PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
+ FileHandle = NULL;\r
+ DepexData = NULL;\r
+ Status = EFI_SUCCESS;\r
+ PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
\r
- if (PrivateData->FvCount >= PEI_CORE_MAX_FV_SUPPORTED) {\r
+ if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
ASSERT (FALSE);\r
}\r
\r
Fv = (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *)Ppi;\r
\r
- if (CompareGuid (&Fv->FvFormat, &gEfiFirmwareFileSystem2Guid)) {\r
- for (FvCount = 0; FvCount < PrivateData->FvCount; FvCount ++) {\r
- if ((UINTN)PrivateData->Fv[FvCount].FvHeader == (UINTN)Fv->FvInfo) {\r
- return EFI_SUCCESS;\r
- }\r
- }\r
+ if (CompareGuid (&Fv->FvFormat, &gEfiFirmwareFileSystem2Guid)) {\r
+ for (FvCount = 0; FvCount < PrivateData->FvCount; FvCount ++) {\r
+ if ((UINTN)PrivateData->Fv[FvCount].FvHeader == (UINTN)Fv->FvInfo) {\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
PrivateData->Fv[PrivateData->FvCount++].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Fv->FvInfo;\r
- BuildFvHob ((EFI_PHYSICAL_ADDRESS) (UINTN) Fv->FvInfo, (UINT64) Fv->FvInfoSize);\r
- }\r
\r
- //\r
- // Allways add to the All list\r
- //\r
- PrivateData->AllFv[PrivateData->AllFvCount++] = (EFI_PEI_FV_HANDLE)Fv->FvInfo;\r
+ //\r
+ // Only add FileSystem2 Fv to the All list\r
+ //\r
+ PrivateData->AllFv[PrivateData->AllFvCount++] = (EFI_PEI_FV_HANDLE)Fv->FvInfo;\r
+ \r
+ DEBUG ((EFI_D_INFO, "The %dth FvImage start address is 0x%10p and size is 0x%08x\n", PrivateData->AllFvCount, (VOID *) Fv->FvInfo, Fv->FvInfoSize));\r
+ //\r
+ // Preprocess all FV type files in this new FileSystem2 Fv image\r
+ //\r
+ do {\r
+ Status = PeiFindFileEx (\r
+ (EFI_PEI_FV_HANDLE)Fv->FvInfo, \r
+ NULL, \r
+ EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, \r
+ &FileHandle, \r
+ NULL\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ Status = PeiFfsFindSectionData (\r
+ (CONST EFI_PEI_SERVICES **) PeiServices,\r
+ EFI_SECTION_PEI_DEPEX,\r
+ FileHandle, \r
+ (VOID **)&DepexData\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r
+ //\r
+ // Dependency is not satisfied.\r
+ //\r
+ continue;\r
+ }\r
+ }\r
+ //\r
+ // Process FvFile to install FvInfo ppi and build FvHob\r
+ // \r
+ ProcessFvFile (PeiServices, FileHandle, &AuthenticationStatus);\r
+ }\r
+ } while (FileHandle != NULL);\r
+ }\r
\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+\r
+ Go through the file to search SectionType section,\r
+ when meeting an encapsuled section.\r
+\r
+\r
+ @param PeiServices - General purpose services available to every PEIM.\r
+ SearchType - Filter to find only section of this type.\r
+ @param SectionType EDES_TODO: Add parameter description\r
+ @param Section - From where to search.\r
+ @param SectionSize - The file size to search.\r
+ @param OutputBuffer - Pointer to the section to search.\r
+\r
+ @return EFI_STATUS\r
+\r
+**/\r
EFI_STATUS\r
PeiFfsProcessSection (\r
IN CONST EFI_PEI_SERVICES **PeiServices,\r
IN EFI_SECTION_TYPE SectionType,\r
IN EFI_COMMON_SECTION_HEADER *Section,\r
IN UINTN SectionSize,\r
- OUT VOID **OutputBuffer,\r
- OUT UINTN *OutputSize,\r
- OUT UINT32 *Authentication\r
+ OUT VOID **OutputBuffer\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Go through the file to search SectionType section,\r
- when meeting an encapsuled section, search recursively. \r
- \r
-Arguments:\r
- PeiServices - Pointer to the PEI Core Services Table.\r
- SearchType - Filter to find only section of this type.\r
- Section - From where to search.\r
- SectionSize - The file size to search.\r
- OutputBuffer - Pointer to the section to search.\r
- OutputSize - The size of the section to search.\r
- Authentication - Authenticate the section.\r
-\r
-Returns:\r
- EFI_STATUS\r
- \r
---*/\r
{\r
EFI_STATUS Status;\r
UINT32 SectionLength;\r
UINT32 ParsedLength;\r
- EFI_GUID_DEFINED_SECTION *GuidSection; \r
EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;\r
- EFI_COMPRESSION_SECTION *CompressionSection;\r
EFI_PEI_DECOMPRESS_PPI *DecompressPpi;\r
VOID *PpiOutput;\r
UINTN PpiOutputSize;\r
+ UINTN Index;\r
+ UINT32 Authentication;\r
+ PEI_CORE_INSTANCE *PrivateData;\r
\r
+ PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
*OutputBuffer = NULL;\r
- ParsedLength = 0;\r
+ ParsedLength = 0;\r
+ Index = 0;\r
+ Status = EFI_NOT_FOUND;\r
+ PpiOutput = NULL;\r
+ PpiOutputSize = 0;\r
while (ParsedLength < SectionSize) {\r
if (Section->Type == SectionType) {\r
*OutputBuffer = (VOID *)(Section + 1);\r
return EFI_SUCCESS;\r
- } else if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r
- GuidSection = (EFI_GUID_DEFINED_SECTION *)Section;\r
- Status = PeiServicesLocatePpi (&GuidSection->SectionDefinitionGuid, 0, NULL, (VOID **) &GuidSectionPpi);\r
- if (!EFI_ERROR (Status)) {\r
- Status = GuidSectionPpi->ExtractSection (\r
- GuidSectionPpi,\r
- Section,\r
- &PpiOutput,\r
- &PpiOutputSize,\r
- Authentication\r
- );\r
- if (!EFI_ERROR (Status)) {\r
+ } else if ((Section->Type == EFI_SECTION_GUID_DEFINED) || (Section->Type == EFI_SECTION_COMPRESSION)) {\r
+ //\r
+ // Check the encapsulated section is extracted into the cache data.\r
+ //\r
+ for (Index = 0; Index < PrivateData->CacheSection.AllSectionCount; Index ++) {\r
+ if (Section == PrivateData->CacheSection.Section[Index]) {\r
+ PpiOutput = PrivateData->CacheSection.SectionData[Index];\r
+ PpiOutputSize = PrivateData->CacheSection.SectionSize[Index];\r
+ //\r
+ // Search section directly from the cache data.\r
+ //\r
return PeiFfsProcessSection (\r
PeiServices,\r
SectionType, \r
PpiOutput, \r
PpiOutputSize, \r
- OutputBuffer, \r
- OutputSize, \r
- Authentication\r
+ OutputBuffer \r
);\r
}\r
}\r
- } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r
- CompressionSection = (EFI_COMPRESSION_SECTION *)Section;\r
- Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r
- if (!EFI_ERROR (Status)) {\r
- Status = DecompressPpi->Decompress (\r
- DecompressPpi,\r
- CompressionSection,\r
- &PpiOutput,\r
- &PpiOutputSize\r
- );\r
+ \r
+ Status = EFI_NOT_FOUND;\r
+ if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r
+ Status = PeiServicesLocatePpi (\r
+ &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid, \r
+ 0, \r
+ NULL, \r
+ (VOID **) &GuidSectionPpi\r
+ );\r
if (!EFI_ERROR (Status)) {\r
- return PeiFfsProcessSection (\r
- PeiServices, SectionType, PpiOutput, PpiOutputSize, OutputBuffer, OutputSize, Authentication\r
- );\r
+ Status = GuidSectionPpi->ExtractSection (\r
+ GuidSectionPpi,\r
+ Section,\r
+ &PpiOutput,\r
+ &PpiOutputSize,\r
+ &Authentication\r
+ );\r
+ }\r
+ } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r
+ Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r
+ if (!EFI_ERROR (Status)) {\r
+ Status = DecompressPpi->Decompress (\r
+ DecompressPpi,\r
+ (CONST EFI_COMPRESSION_SECTION*) Section,\r
+ &PpiOutput,\r
+ &PpiOutputSize\r
+ );\r
}\r
}\r
+ \r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Update cache section data.\r
+ //\r
+ if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r
+ PrivateData->CacheSection.AllSectionCount ++;\r
+ }\r
+ PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r
+ PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r
+ PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r
+ PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r
+ \r
+ return PeiFfsProcessSection (\r
+ PeiServices,\r
+ SectionType, \r
+ PpiOutput, \r
+ PpiOutputSize, \r
+ OutputBuffer \r
+ );\r
+ }\r
}\r
\r
//\r
}\r
\r
\r
+/**\r
+ Given the input file pointer, search for the next matching section in the\r
+ FFS volume.\r
+\r
+\r
+ @param PeiServices Pointer to the PEI Core Services Table.\r
+ @param SectionType Filter to find only sections of this type.\r
+ @param FileHandle Pointer to the current file to search.\r
+ @param SectionData Pointer to the Section matching SectionType in FfsFileHeader.\r
+ NULL if section not found\r
+\r
+ @retval EFI_NOT_FOUND No files matching the search criteria were found\r
+ @retval EFI_SUCCESS Success to find section data in given file\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiFfsFindSectionData (\r
IN EFI_PEI_FILE_HANDLE FileHandle,\r
IN OUT VOID **SectionData\r
)\r
-/*++\r
-\r
-Routine Description:\r
- Given the input file pointer, search for the next matching section in the\r
- FFS volume.\r
-\r
-Arguments:\r
- PeiServices - Pointer to the PEI Core Services Table.\r
- SearchType - Filter to find only sections of this type.\r
- FfsFileHeader - Pointer to the current file to search.\r
- SectionData - Pointer to the Section matching SectionType in FfsFileHeader.\r
- - NULL if section not found\r
-\r
-Returns:\r
- EFI_NOT_FOUND - No files matching the search criteria were found\r
- EFI_SUCCESS\r
-\r
---*/\r
{\r
EFI_FFS_FILE_HEADER *FfsFileHeader;\r
UINT32 FileSize;\r
EFI_COMMON_SECTION_HEADER *Section;\r
- UINTN OutputSize;\r
- UINT32 AuthenticationStatus;\r
-\r
\r
FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);\r
\r
FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r
\r
return PeiFfsProcessSection (\r
- PeiServices, \r
+ PeiServices,\r
SectionType, \r
Section, \r
FileSize, \r
- SectionData, \r
- &OutputSize, \r
- &AuthenticationStatus\r
+ SectionData\r
);\r
}\r
\r
+/**\r
+ Given the input file pointer, search for the next matching file in the\r
+ FFS volume as defined by SearchType. The search starts from FileHeader inside\r
+ the Firmware Volume defined by FwVolHeader.\r
\r
-EFI_STATUS\r
-FindNextPeim (\r
- IN EFI_PEI_SERVICES **PeiServices,\r
- IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r
- IN OUT EFI_FFS_FILE_HEADER **PeimFileHeader\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Given the input file pointer, search for the next matching file in the\r
- FFS volume. The search starts from FileHeader inside\r
- the Firmware Volume defined by FwVolHeader.\r
-\r
-Arguments:\r
- PeiServices - Pointer to the PEI Core Services Table.\r
\r
- FwVolHeader - Pointer to the FV header of the volume to search.\r
- This parameter must point to a valid FFS volume.\r
- \r
- PeimFileHeader - Pointer to the current file from which to begin searching.\r
- This pointer will be updated upon return to reflect the file found.\r
-\r
-Returns:\r
- EFI_NOT_FOUND - No files matching the search criteria were found\r
- EFI_SUCCESS\r
-\r
---*/\r
-{\r
- return PeiFindFileEx (\r
- (EFI_PEI_FV_HANDLE) FwVolHeader, \r
- NULL, \r
- EFI_FV_FILETYPE_PEIM, \r
- (EFI_PEI_FILE_HANDLE *)PeimFileHeader, \r
- NULL\r
- );\r
-}\r
+ @param PeiServices Pointer to the PEI Core Services Table.\r
+ @param SearchType Filter to find only files of this type.\r
+ Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
+ @param VolumeHandle Pointer to the FV header of the volume to search.\r
+ @param FileHandle Pointer to the current file from which to begin searching.\r
+ This pointer will be updated upon return to reflect the file found.\r
+ @retval EFI_NOT_FOUND No files matching the search criteria were found\r
+ @retval EFI_SUCCESS Success to find next file in given volume\r
\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiFfsFindNextFile (\r
IN EFI_PEI_FV_HANDLE VolumeHandle,\r
IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r
)\r
-/*++\r
-\r
-Routine Description:\r
- Given the input file pointer, search for the next matching file in the\r
- FFS volume as defined by SearchType. The search starts from FileHeader inside\r
- the Firmware Volume defined by FwVolHeader.\r
-\r
-Arguments:\r
- PeiServices - Pointer to the PEI Core Services Table.\r
- \r
- SearchType - Filter to find only files of this type.\r
- Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
- \r
- FwVolHeader - Pointer to the FV header of the volume to search.\r
- This parameter must point to a valid FFS volume.\r
- \r
- FileHeader - Pointer to the current file from which to begin searching.\r
- This pointer will be updated upon return to reflect the file found.\r
- \r
-Returns:\r
- EFI_NOT_FOUND - No files matching the search criteria were found\r
- EFI_SUCCESS\r
-\r
---*/\r
{\r
return PeiFindFileEx (VolumeHandle, NULL, SearchType, FileHandle, NULL);\r
}\r
\r
\r
+/**\r
+ search the firmware volumes by index\r
+\r
+ @param PeiServices The PEI core services table.\r
+ @param Instance Instance of FV to find\r
+ @param VolumeHandle Pointer to found Volume.\r
+\r
+ @retval EFI_INVALID_PARAMETER FwVolHeader is NULL\r
+ @retval EFI_SUCCESS Firmware volume instance successfully found.\r
+\r
+**/\r
EFI_STATUS \r
EFIAPI\r
PeiFvFindNextVolume (\r
IN UINTN Instance,\r
IN OUT EFI_PEI_FV_HANDLE *VolumeHandle\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Return the BFV location\r
-\r
- BugBug -- Move this to the location of this code to where the\r
- other FV and FFS support code lives.\r
- Also, update to use FindFV for instances #'s >= 1.\r
-\r
-Arguments:\r
-\r
- PeiServices - The PEI core services table.\r
- Instance - Instance of FV to find\r
- FwVolHeader - Pointer to contain the data to return\r
-\r
-Returns:\r
- Pointer to the Firmware Volume instance requested\r
-\r
- EFI_INVALID_PARAMETER - FwVolHeader is NULL\r
- \r
- EFI_SUCCESS - Firmware volume instance successfully found.\r
-\r
---*/\r
{\r
PEI_CORE_INSTANCE *Private;\r
\r
}\r
\r
\r
+/**\r
+\r
+ Given the input VolumeHandle, search for the next matching name file.\r
+\r
+\r
+ @param FileName - File name to search.\r
+ @param VolumeHandle - The current FV to search.\r
+ @param FileHandle - Pointer to the file matching name in VolumeHandle.\r
+ - NULL if file not found\r
+\r
+ @return EFI_STATUS\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI \r
PeiFfsFindFileByName (\r
IN EFI_PEI_FV_HANDLE VolumeHandle,\r
OUT EFI_PEI_FILE_HANDLE *FileHandle\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Given the input VolumeHandle, search for the next matching name file.\r
-\r
-Arguments:\r
-\r
- FileName - File name to search.\r
- VolumeHandle - The current FV to search.\r
- FileHandle - Pointer to the file matching name in VolumeHandle.\r
- - NULL if file not found\r
-Returns:\r
- EFI_STATUS\r
- \r
---*/ \r
{\r
EFI_STATUS Status;\r
if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r
return Status;\r
}\r
\r
+/**\r
+\r
+ Returns information about a specific file.\r
+\r
+\r
+ @param FileHandle - The handle to file.\r
+ @param FileInfo - Pointer to the file information.\r
+\r
+ @retval EFI_INVALID_PARAMETER Invalid FileHandle or FileInfo.\r
+ @retval EFI_SUCCESS Success to collect file info.\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI \r
PeiFfsGetFileInfo (\r
IN EFI_PEI_FILE_HANDLE FileHandle,\r
OUT EFI_FV_FILE_INFO *FileInfo\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Collect information of given file.\r
-\r
-Arguments:\r
- FileHandle - The handle to file.\r
- FileInfo - Pointer to the file information.\r
-\r
-Returns:\r
- EFI_STATUS\r
- \r
---*/ \r
{\r
UINT8 FileState;\r
UINT8 ErasePolarity;\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ VolumeHandle = 0;\r
//\r
// Retrieve the FirmwareVolume which the file resides in.\r
//\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB_ERASE_POLARITY) {\r
+ if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
ErasePolarity = 1;\r
} else {\r
ErasePolarity = 0;\r
}\r
\r
\r
+/**\r
+\r
+ Collect information of given Fv Volume.\r
+\r
+ @param VolumeHandle - The handle to Fv Volume.\r
+ @param VolumeInfo - The pointer to volume information.\r
+\r
+ @retval EFI_INVALID_PARAMETER VolumeInfo is NULL\r
+ @retval EFI_SUCCESS Success to collect fv info.\r
+**/\r
EFI_STATUS\r
EFIAPI \r
PeiFfsGetVolumeInfo (\r
IN EFI_PEI_FV_HANDLE VolumeHandle,\r
OUT EFI_FV_INFO *VolumeInfo\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Collect information of given Fv Volume.\r
-\r
-Arguments:\r
- VolumeHandle - The handle to Fv Volume.\r
- VolumeInfo - The pointer to volume information.\r
- \r
-Returns:\r
- EFI_STATUS\r
- \r
---*/ \r
{\r
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
+ EFI_FIRMWARE_VOLUME_HEADER FwVolHeader;\r
EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;\r
\r
if (VolumeInfo == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
+ \r
+ //\r
+ // VolumeHandle may not align at 8 byte, \r
+ // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. \r
+ // So, Copy FvHeader into the local FvHeader structure.\r
+ //\r
+ CopyMem (&FwVolHeader, VolumeHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r
+ //\r
+ // Check Fv Image Signature\r
+ //\r
+ if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ VolumeInfo->FvAttributes = FwVolHeader.Attributes;\r
+ VolumeInfo->FvStart = (VOID *) VolumeHandle;\r
+ VolumeInfo->FvSize = FwVolHeader.FvLength;\r
+ CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));\r
\r
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(VolumeHandle);\r
- VolumeInfo->FvAttributes = FwVolHeader->Attributes;\r
- VolumeInfo->FvStart = FwVolHeader;\r
- VolumeInfo->FvSize = FwVolHeader->FvLength;\r
- CopyMem (&VolumeInfo->FvFormat, &FwVolHeader->FileSystemGuid,sizeof(EFI_GUID));\r
-\r
- if (FwVolHeader->ExtHeaderOffset != 0) {\r
- FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)FwVolHeader) + FwVolHeader->ExtHeaderOffset);\r
+ if (FwVolHeader.ExtHeaderOffset != 0) {\r
+ FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset);\r
CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));\r
}\r
return EFI_SUCCESS;\r