From: Liming Gao Date: Fri, 8 Sep 2017 05:18:25 +0000 (+0800) Subject: MdeModulePkg: Update modules to consume CalculateCrc32() X-Git-Tag: edk2-stable201903~3260 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=05542f49877f9047c536b61fd8f15dd4c4496b4b MdeModulePkg: Update modules to consume CalculateCrc32() Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao Reviewed-by: Star Zeng --- diff --git a/MdeModulePkg/Core/RuntimeDxe/Crc32.c b/MdeModulePkg/Core/RuntimeDxe/Crc32.c index a6fe77fa34..3e91e08049 100644 --- a/MdeModulePkg/Core/RuntimeDxe/Crc32.c +++ b/MdeModulePkg/Core/RuntimeDxe/Crc32.c @@ -7,7 +7,7 @@ EFI Runtime Services Table are converted from physical address to virtual addresses. This requires that the 32-bit CRC be recomputed. -Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, 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 @@ -20,8 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include - -UINT32 mCrcTable[256]; +#include /** Calculate CRC32 for target data. @@ -43,73 +42,6 @@ RuntimeDriverCalculateCrc32 ( OUT UINT32 *CrcOut ) { - UINT32 Crc; - UINTN Index; - UINT8 *Ptr; - - if (Data == NULL || DataSize == 0 || CrcOut == NULL) { - return EFI_INVALID_PARAMETER; - } - - Crc = 0xffffffff; - for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) { - Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr]; - } - - *CrcOut = Crc ^ 0xffffffff; + *CrcOut = CalculateCrc32 (Data, DataSize); return EFI_SUCCESS; } - - -/** - This internal function reverses bits for 32bit data. - - @param Value The data to be reversed. - - @return Data reversed. - -**/ -UINT32 -ReverseBits ( - UINT32 Value - ) -{ - UINTN Index; - UINT32 NewValue; - - NewValue = 0; - for (Index = 0; Index < 32; Index++) { - if ((Value & (1 << Index)) != 0) { - NewValue = NewValue | (1 << (31 - Index)); - } - } - - return NewValue; -} - -/** - Initialize CRC32 table. - -**/ -VOID -RuntimeDriverInitializeCrc32Table ( - VOID - ) -{ - UINTN TableEntry; - UINTN Index; - UINT32 Value; - - for (TableEntry = 0; TableEntry < 256; TableEntry++) { - Value = ReverseBits ((UINT32) TableEntry); - for (Index = 0; Index < 8; Index++) { - if ((Value & 0x80000000) != 0) { - Value = (Value << 1) ^ 0x04c11db7; - } else { - Value = Value << 1; - } - } - - mCrcTable[TableEntry] = ReverseBits (Value); - } -} diff --git a/MdeModulePkg/Core/RuntimeDxe/Runtime.c b/MdeModulePkg/Core/RuntimeDxe/Runtime.c index c61301cf80..0557457e04 100644 --- a/MdeModulePkg/Core/RuntimeDxe/Runtime.c +++ b/MdeModulePkg/Core/RuntimeDxe/Runtime.c @@ -400,11 +400,6 @@ RuntimeDriverInitialize ( ASSERT_EFI_ERROR (Status); mMyImageBase = MyLoadedImage->ImageBase; - // - // Initialize the table used to compute 32-bit CRCs - // - RuntimeDriverInitializeCrc32Table (); - // // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables // diff --git a/MdeModulePkg/Core/RuntimeDxe/Runtime.h b/MdeModulePkg/Core/RuntimeDxe/Runtime.h index f2cee9c7c6..506915e112 100644 --- a/MdeModulePkg/Core/RuntimeDxe/Runtime.h +++ b/MdeModulePkg/Core/RuntimeDxe/Runtime.h @@ -103,15 +103,6 @@ RuntimeDriverSetVirtualAddressMap ( IN EFI_MEMORY_DESCRIPTOR *VirtualMap ); -/** - Initialize CRC32 table. - -**/ -VOID -RuntimeDriverInitializeCrc32Table ( - VOID - ); - /** Install Runtime AP. This code includes the EfiRuntimeLib, but it only functions at RT in physical mode. diff --git a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c index f979bdf42b..34f1e17006 100644 --- a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c +++ b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c @@ -3,7 +3,7 @@ This library registers CRC32 guided section handler to parse CRC32 encapsulation section and extract raw data. -Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2017, 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 @@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +#include #include #include #include @@ -33,90 +34,6 @@ typedef struct { UINT32 CRC32Checksum; ///< 32bit CRC check sum } CRC32_SECTION2_HEADER; -/** - This internal function reverses bits for 32bit data. - - @param Value The data to be reversed. - - @return Data reversed. - -**/ -UINT32 -PeiCrc32GuidedSectionExtractLibReverseBits ( - UINT32 Value - ) -{ - UINTN Index; - UINT32 NewValue; - - NewValue = 0; - for (Index = 0; Index < 32; Index++) { - if ((Value & (1 << Index)) != 0) { - NewValue = NewValue | (1 << (31 - Index)); - } - } - - return NewValue; -} - -/** - Calculate CRC32 for target data. - - @param Data The target data. - @param DataSize The target data size. - @param CrcOut The CRC32 for target data. - - @retval EFI_SUCCESS The CRC32 for target data is calculated successfully. - @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not - calculated. - -**/ -EFI_STATUS -EFIAPI -PeiCrc32GuidedSectionExtractLibCalculateCrc32 ( - IN VOID *Data, - IN UINTN DataSize, - OUT UINT32 *CrcOut - ) -{ - UINT32 CrcTable[256]; - UINTN TableEntry; - UINTN Index; - UINT32 Value; - UINT32 Crc; - UINT8 *Ptr; - - if (Data == NULL || DataSize == 0 || CrcOut == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Initialize CRC32 table. - // - for (TableEntry = 0; TableEntry < 256; TableEntry++) { - Value = PeiCrc32GuidedSectionExtractLibReverseBits ((UINT32) TableEntry); - for (Index = 0; Index < 8; Index++) { - if ((Value & 0x80000000) != 0) { - Value = (Value << 1) ^ 0x04c11db7; - } else { - Value = Value << 1; - } - } - CrcTable[TableEntry] = PeiCrc32GuidedSectionExtractLibReverseBits (Value); - } - - // - // Compute CRC - // - Crc = 0xffffffff; - for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) { - Crc = (Crc >> 8) ^ CrcTable[(UINT8) Crc ^ *Ptr]; - } - - *CrcOut = Crc ^ 0xffffffff; - return EFI_SUCCESS; -} - /** GetInfo gets raw data size and attribute of the input guided section. @@ -203,7 +120,6 @@ Crc32GuidedSectionHandler ( OUT UINT32 *AuthenticationStatus ) { - EFI_STATUS Status; UINT32 SectionCrc32Checksum; UINT32 Crc32Checksum; UINT32 OutputBufferSize; @@ -254,27 +170,15 @@ Crc32GuidedSectionHandler ( *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED; } - // - // Init Checksum value to Zero. - // - Crc32Checksum = 0; - // // Calculate CRC32 Checksum of Image // - Status = PeiCrc32GuidedSectionExtractLibCalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum); - if (Status == EFI_SUCCESS) { - if (Crc32Checksum != SectionCrc32Checksum) { - // - // If Crc32 checksum is not matched, AUTH tested failed bit is set. - // - *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED; - } - } else { + Crc32Checksum = CalculateCrc32 (*OutputBuffer, OutputBufferSize); + if (Crc32Checksum != SectionCrc32Checksum) { // - // If Crc32 checksum is not calculated, AUTH not tested bit is set. + // If Crc32 checksum is not matched, AUTH tested failed bit is set. // - *AuthenticationStatus |= EFI_AUTH_STATUS_NOT_TESTED; + *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED; } // diff --git a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf index 7134810040..45fd141f01 100644 --- a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf +++ b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf @@ -5,7 +5,7 @@ # ExtractGuidedSectionLib service to register CRC32 guided section handler # that parses CRC32 encapsulation section and extracts raw data. # -# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2006 - 2017, 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 @@ -43,6 +43,7 @@ ExtractGuidedSectionLib DebugLib BaseMemoryLib + BaseLib [Guids] gEfiCrc32GuidedSectionExtractionGuid ## PRODUCES ## UNDEFINED