From nobody Thu Dec 26 13:54:19 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1504847930054894.91528450084; Thu, 7 Sep 2017 22:18:50 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id ADECE21D2E62B; Thu, 7 Sep 2017 22:15:52 -0700 (PDT) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E964220945BE6 for ; Thu, 7 Sep 2017 22:15:50 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Sep 2017 22:18:42 -0700 Received: from shwde7172.ccr.corp.intel.com ([10.239.9.14]) by fmsmga002.fm.intel.com with ESMTP; 07 Sep 2017 22:18:42 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,360,1500966000"; d="scan'208";a="1216212602" From: Liming Gao To: edk2-devel@lists.01.org Date: Fri, 8 Sep 2017 13:18:25 +0800 Message-Id: <1504847905-384-3-git-send-email-liming.gao@intel.com> X-Mailer: git-send-email 2.8.0.windows.1 In-Reply-To: <1504847905-384-1-git-send-email-liming.gao@intel.com> References: <1504847905-384-1-git-send-email-liming.gao@intel.com> Subject: [edk2] [Patch 2/2] MdeModulePkg: Update modules to consume CalculateCrc32() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao --- MdeModulePkg/Core/RuntimeDxe/Crc32.c | 74 +------------- MdeModulePkg/Core/RuntimeDxe/Runtime.c | 5 - MdeModulePkg/Core/RuntimeDxe/Runtime.h | 9 -- .../PeiCrc32GuidedSectionExtractLib.c | 108 ++---------------= ---- .../PeiCrc32GuidedSectionExtractLib.inf | 3 +- 5 files changed, 11 insertions(+), 188 deletions(-) diff --git a/MdeModulePkg/Core/RuntimeDxe/Crc32.c b/MdeModulePkg/Core/Runti= meDxe/Crc32.c index a6fe77f..3e91e08 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. =20 -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. =20 =20 #include - -UINT32 mCrcTable[256]; +#include =20 /** Calculate CRC32 for target data. @@ -43,73 +42,6 @@ RuntimeDriverCalculateCrc32 ( OUT UINT32 *CrcOut ) { - UINT32 Crc; - UINTN Index; - UINT8 *Ptr; - - if (Data =3D=3D NULL || DataSize =3D=3D 0 || CrcOut =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - Crc =3D 0xffffffff; - for (Index =3D 0, Ptr =3D Data; Index < DataSize; Index++, Ptr++) { - Crc =3D (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr]; - } - - *CrcOut =3D Crc ^ 0xffffffff; + *CrcOut =3D 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 =3D 0; - for (Index =3D 0; Index < 32; Index++) { - if ((Value & (1 << Index)) !=3D 0) { - NewValue =3D NewValue | (1 << (31 - Index)); - } - } - - return NewValue; -} - -/** - Initialize CRC32 table. - -**/ -VOID -RuntimeDriverInitializeCrc32Table ( - VOID - ) -{ - UINTN TableEntry; - UINTN Index; - UINT32 Value; - - for (TableEntry =3D 0; TableEntry < 256; TableEntry++) { - Value =3D ReverseBits ((UINT32) TableEntry); - for (Index =3D 0; Index < 8; Index++) { - if ((Value & 0x80000000) !=3D 0) { - Value =3D (Value << 1) ^ 0x04c11db7; - } else { - Value =3D Value << 1; - } - } - - mCrcTable[TableEntry] =3D ReverseBits (Value); - } -} diff --git a/MdeModulePkg/Core/RuntimeDxe/Runtime.c b/MdeModulePkg/Core/Run= timeDxe/Runtime.c index c61301c..0557457 100644 --- a/MdeModulePkg/Core/RuntimeDxe/Runtime.c +++ b/MdeModulePkg/Core/RuntimeDxe/Runtime.c @@ -401,11 +401,6 @@ RuntimeDriverInitialize ( mMyImageBase =3D MyLoadedImage->ImageBase; =20 // - // Initialize the table used to compute 32-bit CRCs - // - RuntimeDriverInitializeCrc32Table (); - - // // Fill in the entries of the EFI Boot Services and EFI Runtime Services= Tables // gBS->CalculateCrc32 =3D RuntimeDriverCalculateCrc32; diff --git a/MdeModulePkg/Core/RuntimeDxe/Runtime.h b/MdeModulePkg/Core/Run= timeDxe/Runtime.h index f2cee9c..506915e 100644 --- a/MdeModulePkg/Core/RuntimeDxe/Runtime.h +++ b/MdeModulePkg/Core/RuntimeDxe/Runtime.h @@ -104,15 +104,6 @@ RuntimeDriverSetVirtualAddressMap ( ); =20 /** - Initialize CRC32 table. - -**/ -VOID -RuntimeDriverInitializeCrc32Table ( - VOID - ); - -/** Install Runtime AP. This code includes the EfiRuntimeLib, but it only functions at RT in physical mode. =20 diff --git a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32G= uidedSectionExtractLib.c b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtrac= tLib/PeiCrc32GuidedSectionExtractLib.c index f979bdf..34f1e17 100644 --- a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSe= ctionExtractLib.c +++ b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSe= ctionExtractLib.c @@ -3,7 +3,7 @@ This library registers CRC32 guided section handler=20 to parse CRC32 encapsulation section and extract raw data. =20 -Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials =20 are licensed and made available under the terms and conditions of the BSD = License =20 which accompanies this distribution. The full text of the license may be = found at =20 @@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. =20 #include #include +#include #include #include #include @@ -34,90 +35,6 @@ typedef struct { } CRC32_SECTION2_HEADER; =20 /** - 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 =3D 0; - for (Index =3D 0; Index < 32; Index++) { - if ((Value & (1 << Index)) !=3D 0) { - NewValue =3D 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 su= ccessfully. - @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 =3D=3D NULL || DataSize =3D=3D 0 || CrcOut =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - =20 - // - // Initialize CRC32 table. - // - for (TableEntry =3D 0; TableEntry < 256; TableEntry++) { - Value =3D PeiCrc32GuidedSectionExtractLibReverseBits ((UINT32) TableEn= try); - for (Index =3D 0; Index < 8; Index++) { - if ((Value & 0x80000000) !=3D 0) { - Value =3D (Value << 1) ^ 0x04c11db7; - } else { - Value =3D Value << 1; - } - } - CrcTable[TableEntry] =3D PeiCrc32GuidedSectionExtractLibReverseBits (V= alue); - } - - // - // Compute CRC - // - Crc =3D 0xffffffff; - for (Index =3D 0, Ptr =3D Data; Index < DataSize; Index++, Ptr++) { - Crc =3D (Crc >> 8) ^ CrcTable[(UINT8) Crc ^ *Ptr]; - } - - *CrcOut =3D Crc ^ 0xffffffff; - return EFI_SUCCESS; -} - -/** =20 GetInfo gets raw data size and attribute of the input guided section. It first checks whether the input guid section is supported.=20 @@ -203,7 +120,6 @@ Crc32GuidedSectionHandler ( OUT UINT32 *AuthenticationStatus ) { - EFI_STATUS Status; UINT32 SectionCrc32Checksum; UINT32 Crc32Checksum; UINT32 OutputBufferSize; @@ -255,26 +171,14 @@ Crc32GuidedSectionHandler ( } =20 // - // Init Checksum value to Zero. - // - Crc32Checksum =3D 0; - - // // Calculate CRC32 Checksum of Image // - Status =3D PeiCrc32GuidedSectionExtractLibCalculateCrc32 (*OutputBuffer,= OutputBufferSize, &Crc32Checksum); - if (Status =3D=3D EFI_SUCCESS) { - if (Crc32Checksum !=3D SectionCrc32Checksum) { - // - // If Crc32 checksum is not matched, AUTH tested failed bit is set. - // - *AuthenticationStatus |=3D EFI_AUTH_STATUS_TEST_FAILED; - } - } else { + Crc32Checksum =3D CalculateCrc32 (*OutputBuffer, OutputBufferSize); + if (Crc32Checksum !=3D 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 |=3D EFI_AUTH_STATUS_NOT_TESTED; + *AuthenticationStatus |=3D EFI_AUTH_STATUS_TEST_FAILED; } =20 // diff --git a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32G= uidedSectionExtractLib.inf b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtr= actLib/PeiCrc32GuidedSectionExtractLib.inf index 7134810..45fd141 100644 --- a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSe= ctionExtractLib.inf +++ b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSe= ctionExtractLib.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 B= SD License @@ -43,6 +43,7 @@ ExtractGuidedSectionLib DebugLib BaseMemoryLib + BaseLib =20 [Guids] gEfiCrc32GuidedSectionExtractionGuid ## PRODUCES ## UNDEFINED --=20 2.8.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel