X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPei%2FFwVol%2FFwVol.c;h=941657c07f9d4b2e0ed2430b7571af08791d7299;hb=89cd8129f72bc2c445839efcddace560bfdfeb8f;hp=8bf096a67ebdc3bd880abbf6c939cb21bdabc997;hpb=dc05231352ec2c0f62f6a32a033a3323e19bc78d;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Pei/FwVol/FwVol.c b/MdeModulePkg/Core/Pei/FwVol/FwVol.c index 8bf096a67e..941657c07f 100644 --- a/MdeModulePkg/Core/Pei/FwVol/FwVol.c +++ b/MdeModulePkg/Core/Pei/FwVol/FwVol.c @@ -1,8 +1,8 @@ /** @file Pei Core Firmware File System service routines. -Copyright (c) 2006 - 2009, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2010, Intel Corporation. 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 @@ -162,6 +162,7 @@ FindFileEx ( UINT64 FvLength; UINT8 ErasePolarity; UINT8 FileState; + UINT8 DataCheckSum; // // Convert the handle of FV to FV header for memory-mapped firmware volume @@ -219,6 +220,16 @@ FindFileEx ( FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8); + DataCheckSum = FFS_FIXED_CHECKSUM; + if ((FfsFileHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) { + DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER), FileLength - sizeof(EFI_FFS_FILE_HEADER)); + } + if (FfsFileHeader->IntegrityCheck.Checksum.File != DataCheckSum) { + ASSERT (FALSE); + *FileHeader = NULL; + return EFI_NOT_FOUND; + } + if (FileName != NULL) { if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) { *FileHeader = FfsFileHeader; @@ -634,7 +645,7 @@ PeiFfsFindSectionData ( @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation. @param SearchType Filter to find only files of this type. Type EFI_FV_FILETYPE_ALL causes no filtering to be done. - @param VolumeHandle Handle of firmware volume in which to search. + @param FvHandle Handle of firmware volume in which to search. @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start at the beginning of the firmware volume. On exit, points the file handle of the next file in the volume or NULL if there are no more files. @@ -755,7 +766,7 @@ PeiFfsFindFileByName ( Returns information about a specific file. @param FileHandle Handle of the file. - @param FileInfo Upon exit, points to the file’s information. + @param FileInfo Upon exit, points to the file's information. @retval EFI_INVALID_PARAMETER If FileInfo is NULL. @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file. @@ -813,7 +824,7 @@ PeiFfsGetVolumeInfo ( { PEI_CORE_FV_HANDLE *CoreHandle; - if (VolumeInfo == NULL) { + if ((VolumeInfo == NULL) || (VolumeHandle == NULL)) { return EFI_INVALID_PARAMETER; } @@ -853,6 +864,7 @@ ProcessFvFile ( EFI_PEI_FV_HANDLE ParentFvHandle; EFI_FIRMWARE_VOLUME_HEADER *FvHeader; EFI_FV_FILE_INFO FileInfo; + UINT64 FvLength; // // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already @@ -890,7 +902,7 @@ ProcessFvFile ( // // FvAlignment must be more than 8 bytes required by FvHeader structure. // - FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16); + FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16); if (FvAlignment < 8) { FvAlignment = 8; } @@ -899,11 +911,12 @@ ProcessFvFile ( // Check FvImage // if ((UINTN) FvHeader % FvAlignment != 0) { - NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvHeader->FvLength), FvAlignment); + FvLength = ReadUnaligned64 (&FvHeader->FvLength); + NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment); if (NewFvBuffer == NULL) { return EFI_OUT_OF_RESOURCES; } - CopyMem (NewFvBuffer, FvHeader, (UINTN) FvHeader->FvLength); + CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength); FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer; } @@ -1101,6 +1114,7 @@ PeiFfs2FvPpiFindFileByName ( Status = FindFileEx (PrivateData->Fv[Index].FvHandle, FileName, 0, FileHandle, NULL); if (!EFI_ERROR (Status)) { *FvHandle = PrivateData->Fv[Index].FvHandle; + break; } } } @@ -1153,7 +1167,7 @@ PeiFfs2FvPpiGetFileInfo ( return EFI_INVALID_PARAMETER; } - if (CoreFvHandle->FvHeader->Attributes & EFI_FVB2_ERASE_POLARITY) { + if ((CoreFvHandle->FvHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) { ErasePolarity = 1; } else { ErasePolarity = 0; @@ -1206,7 +1220,7 @@ PeiFfs2FvPpiGetVolumeInfo ( EFI_FIRMWARE_VOLUME_HEADER FwVolHeader; EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo; - if (VolumeInfo == NULL) { + if ((VolumeInfo == NULL) || (FvHandle == NULL)) { return EFI_INVALID_PARAMETER; } @@ -1345,14 +1359,34 @@ FindNextCoreFvHandle ( // FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV); while (FvHob != NULL) { + // + // Search whether FvHob has been installed into PeiCore's FV database. + // If found, no need install new FvInfoPpi for it. + // for (Index = 0, Match = FALSE; Index < Private->FvCount; Index++) { if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->Fv[Index].FvHeader) { Match = TRUE; break; } } + + // + // Search whether FvHob has been cached into PeiCore's Unknown FV database. + // If found, no need install new FvInfoPpi for it. + // + if (!Match) { + for (Index = 0; Index < Private->UnknownFvInfoCount; Index ++) { + if ((UINTN)FvHob->BaseAddress == (UINTN)Private->UnknownFvInfo[Index].FvInfo) { + Match = TRUE; + break; + } + } + } + // - // If Not Found, Install FvInfo Ppi for it. + // If the Fv in FvHob has not been installed into PeiCore's FV database and has + // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi + // for it then PeiCore will dispatch it in callback of FvInfoPpi. // if (!Match) { PeiServicesInstallFvInfoPpi ( @@ -1363,10 +1397,12 @@ FindNextCoreFvHandle ( NULL ); } + FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength)); } } + ASSERT (Private->FvCount <= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)); if (Instance >= Private->FvCount) { return NULL; } @@ -1449,7 +1485,7 @@ AddUnknownFormatFvInfo ( { PEI_CORE_UNKNOW_FORMAT_FV_INFO *NewUnknownFv; - if (PrivateData->UnknownFvInfoCount + 1 >= FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) { + if (PrivateData->UnknownFvInfoCount + 1 >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) { return EFI_OUT_OF_RESOURCES; } @@ -1582,6 +1618,12 @@ ThirdPartyFvPpiNotifyCallback ( continue; } + if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) { + DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported))); + DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC")); + ASSERT (FALSE); + } + // // Update internal PEI_CORE_FV array. //