X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FFwVol%2FFfs.c;h=5eb22d0ac5ffa70e02409e43078a15505323006f;hb=89cd8129f72bc2c445839efcddace560bfdfeb8f;hp=00d07567f79e6518d39593d89402af9c7bbbe06d;hpb=e94a9ff7271367e649ee4f9a86da1f1bea6d112e;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Dxe/FwVol/Ffs.c b/MdeModulePkg/Core/Dxe/FwVol/Ffs.c index 00d07567f7..5eb22d0ac5 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/Ffs.c +++ b/MdeModulePkg/Core/Dxe/FwVol/Ffs.c @@ -1,8 +1,8 @@ /** @file FFS file access utilities. -Copyright (c) 2006 - 2008, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2008, 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 @@ -13,14 +13,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ -#include +#include "DxeMain.h" +#include "FwVolDriver.h" /** Get the FFS file state by checking the highest bit set in the header's state field. - @param ErasePolarity Erase polarity attribute of the firmware volume - @param FfsHeader Points to the FFS file header + @param ErasePolarity Erase polarity attribute of the firmware volume + @param FfsHeader Points to the FFS file header @return FFS File state @@ -53,11 +54,11 @@ GetFileState ( /** Check if a block of buffer is erased. - @param ErasePolarity Erase polarity attribute of the firmware volume - @param InBuffer The buffer to be checked - @param BufferSize Size of the buffer in bytes + @param ErasePolarity Erase polarity attribute of the firmware volume + @param InBuffer The buffer to be checked + @param BufferSize Size of the buffer in bytes - @retval TRUE The block of buffer is erased + @retval TRUE The block of buffer is erased @retval FALSE The block of buffer is not erased **/ @@ -93,9 +94,9 @@ IsBufferErased ( /** Verify checksum of the firmware volume header. - @param FvHeader Points to the firmware volume header to be checked + @param FvHeader Points to the firmware volume header to be checked - @retval TRUE Checksum verification passed + @retval TRUE Checksum verification passed @retval FALSE Checksum verification failed **/ @@ -128,9 +129,9 @@ VerifyFvHeaderChecksum ( /** Verify checksum of the FFS file header. - @param FfsHeader Points to the FFS file header to be checked + @param FfsHeader Points to the FFS file header to be checked - @retval TRUE Checksum verification passed + @retval TRUE Checksum verification passed @retval FALSE Checksum verification failed **/ @@ -163,11 +164,11 @@ VerifyHeaderChecksum ( /** Check if it's a valid FFS file header. - @param ErasePolarity Erase polarity attribute of the firmware volume - @param FfsHeader Points to the FFS file header to be checked - @param FileState FFS file state to be returned + @param ErasePolarity Erase polarity attribute of the firmware volume + @param FfsHeader Points to the FFS file header to be checked + @param FileState FFS file state to be returned - @retval TRUE Valid FFS file header + @retval TRUE Valid FFS file header @retval FALSE Invalid FFS file header **/ @@ -189,7 +190,7 @@ IsValidFfsHeader ( // Here we need to verify header checksum // return VerifyHeaderChecksum (FfsHeader); - + case EFI_FILE_HEADER_CONSTRUCTION: case EFI_FILE_HEADER_INVALID: default: @@ -202,10 +203,10 @@ IsValidFfsHeader ( Check if it's a valid FFS file. Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first. - @param ErasePolarity Erase polarity attribute of the firmware volume - @param FfsHeader Points to the FFS file to be checked + @param ErasePolarity Erase polarity attribute of the firmware volume + @param FfsHeader Points to the FFS file to be checked - @retval TRUE Valid FFS file + @retval TRUE Valid FFS file @retval FALSE Invalid FFS file **/ @@ -216,6 +217,8 @@ IsValidFfsFile ( ) { EFI_FFS_FILE_STATE FileState; + UINT8 DataCheckSum; + UINT32 FileLength; FileState = GetFileState (ErasePolarity, FfsHeader); switch (FileState) { @@ -223,11 +226,14 @@ IsValidFfsFile ( case EFI_FILE_DELETED: case EFI_FILE_DATA_VALID: case EFI_FILE_MARKED_FOR_UPDATE: - // - // Some other vliadation like file content checksum might be done here. - // For performance issue, Tiano only do FileState check. - // - return TRUE; + DataCheckSum = FFS_FIXED_CHECKSUM; + FileLength = *(UINT32 *)(FfsHeader->Size) & 0x00FFFFFF; + if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) { + DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsHeader + sizeof(EFI_FFS_FILE_HEADER), FileLength - sizeof(EFI_FFS_FILE_HEADER)); + } + if (FfsHeader->IntegrityCheck.Checksum.File == DataCheckSum) { + return TRUE; + } default: return FALSE;