]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Update modules to consume CalculateCrc32()
authorLiming Gao <liming.gao@intel.com>
Fri, 8 Sep 2017 05:18:25 +0000 (13:18 +0800)
committerLiming Gao <liming.gao@intel.com>
Tue, 10 Oct 2017 10:10:16 +0000 (18:10 +0800)
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Core/RuntimeDxe/Crc32.c
MdeModulePkg/Core/RuntimeDxe/Runtime.c
MdeModulePkg/Core/RuntimeDxe/Runtime.h
MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c
MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf

index a6fe77fa349b0bdf42237518c149ac04f30ca915..3e91e0804965c43429aed2c55fee41290253a701 100644 (file)
@@ -7,7 +7,7 @@
   EFI Runtime Services Table are converted from physical address to\r
   virtual addresses.  This requires that the 32-bit CRC be recomputed.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -20,8 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 \r
 #include <Uefi.h>\r
-\r
-UINT32  mCrcTable[256];\r
+#include <Library/BaseLib.h>\r
 \r
 /**\r
   Calculate CRC32 for target data.\r
@@ -43,73 +42,6 @@ RuntimeDriverCalculateCrc32 (
   OUT UINT32  *CrcOut\r
   )\r
 {\r
-  UINT32  Crc;\r
-  UINTN   Index;\r
-  UINT8   *Ptr;\r
-\r
-  if (Data == NULL || DataSize == 0 || CrcOut == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  Crc = 0xffffffff;\r
-  for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {\r
-    Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr];\r
-  }\r
-\r
-  *CrcOut = Crc ^ 0xffffffff;\r
+  *CrcOut = CalculateCrc32 (Data, DataSize);\r
   return EFI_SUCCESS;\r
 }\r
-\r
-\r
-/**\r
-  This internal function reverses bits for 32bit data.\r
-\r
-  @param  Value                 The data to be reversed.\r
-\r
-  @return                       Data reversed.\r
-\r
-**/\r
-UINT32\r
-ReverseBits (\r
-  UINT32  Value\r
-  )\r
-{\r
-  UINTN   Index;\r
-  UINT32  NewValue;\r
-\r
-  NewValue = 0;\r
-  for (Index = 0; Index < 32; Index++) {\r
-    if ((Value & (1 << Index)) != 0) {\r
-      NewValue = NewValue | (1 << (31 - Index));\r
-    }\r
-  }\r
-\r
-  return NewValue;\r
-}\r
-\r
-/**\r
-  Initialize CRC32 table.\r
-\r
-**/\r
-VOID\r
-RuntimeDriverInitializeCrc32Table (\r
-  VOID\r
-  )\r
-{\r
-  UINTN   TableEntry;\r
-  UINTN   Index;\r
-  UINT32  Value;\r
-\r
-  for (TableEntry = 0; TableEntry < 256; TableEntry++) {\r
-    Value = ReverseBits ((UINT32) TableEntry);\r
-    for (Index = 0; Index < 8; Index++) {\r
-      if ((Value & 0x80000000) != 0) {\r
-        Value = (Value << 1) ^ 0x04c11db7;\r
-      } else {\r
-        Value = Value << 1;\r
-      }\r
-    }\r
-\r
-    mCrcTable[TableEntry] = ReverseBits (Value);\r
-  }\r
-}\r
index c61301cf80d849fd0873d7209eab2ab80c0c9c86..0557457e04ff5faa15308d544797a03444ef962b 100644 (file)
@@ -400,11 +400,6 @@ RuntimeDriverInitialize (
   ASSERT_EFI_ERROR (Status);\r
   mMyImageBase = MyLoadedImage->ImageBase;\r
 \r
-  //\r
-  // Initialize the table used to compute 32-bit CRCs\r
-  //\r
-  RuntimeDriverInitializeCrc32Table ();\r
-\r
   //\r
   // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables\r
   //\r
index f2cee9c7c687e6582397501df6b8adef908615b7..506915e112a5fb251ee762f44fabec31ef3600fc 100644 (file)
@@ -103,15 +103,6 @@ RuntimeDriverSetVirtualAddressMap (
   IN EFI_MEMORY_DESCRIPTOR  *VirtualMap\r
   );\r
 \r
-/**\r
-  Initialize CRC32 table.\r
-\r
-**/\r
-VOID\r
-RuntimeDriverInitializeCrc32Table (\r
-  VOID\r
-  );\r
-\r
 /**\r
   Install Runtime AP. This code includes the EfiRuntimeLib, but it only\r
   functions at RT in physical mode.\r
index f979bdf42b199e648a1f5b29b7548e9890ba979b..34f1e170067c2e52ebd1b3581abeea8fbeee8969 100644 (file)
@@ -3,7 +3,7 @@
   This library registers CRC32 guided section handler \r
   to parse CRC32 encapsulation section and extract raw data.\r
 \r
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <PiPei.h>\r
 #include <Guid/Crc32GuidedSectionExtraction.h>\r
+#include <Library/BaseLib.h>\r
 #include <Library/ExtractGuidedSectionLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
@@ -33,90 +34,6 @@ typedef struct {
   UINT32                    CRC32Checksum;       ///< 32bit CRC check sum\r
 } CRC32_SECTION2_HEADER;\r
 \r
-/**\r
-  This internal function reverses bits for 32bit data.\r
-\r
-  @param  Value                 The data to be reversed.\r
-\r
-  @return                       Data reversed.\r
-\r
-**/\r
-UINT32\r
-PeiCrc32GuidedSectionExtractLibReverseBits (\r
-  UINT32  Value\r
-  )\r
-{\r
-  UINTN   Index;\r
-  UINT32  NewValue;\r
-\r
-  NewValue = 0;\r
-  for (Index = 0; Index < 32; Index++) {\r
-    if ((Value & (1 << Index)) != 0) {\r
-      NewValue = NewValue | (1 << (31 - Index));\r
-    }\r
-  }\r
-\r
-  return NewValue;\r
-}\r
-\r
-/**\r
-  Calculate CRC32 for target data.\r
-\r
-  @param  Data                  The target data.\r
-  @param  DataSize              The target data size.\r
-  @param  CrcOut                The CRC32 for target data.\r
-\r
-  @retval EFI_SUCCESS           The CRC32 for target data is calculated successfully.\r
-  @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not\r
-                                calculated.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PeiCrc32GuidedSectionExtractLibCalculateCrc32 (\r
-  IN  VOID    *Data,\r
-  IN  UINTN   DataSize,\r
-  OUT UINT32  *CrcOut\r
-  )\r
-{\r
-  UINT32  CrcTable[256];\r
-  UINTN   TableEntry;\r
-  UINTN   Index;\r
-  UINT32  Value;\r
-  UINT32  Crc;\r
-  UINT8   *Ptr;\r
-\r
-  if (Data == NULL || DataSize == 0 || CrcOut == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  //\r
-  // Initialize CRC32 table.\r
-  //\r
-  for (TableEntry = 0; TableEntry < 256; TableEntry++) {\r
-    Value = PeiCrc32GuidedSectionExtractLibReverseBits ((UINT32) TableEntry);\r
-    for (Index = 0; Index < 8; Index++) {\r
-      if ((Value & 0x80000000) != 0) {\r
-        Value = (Value << 1) ^ 0x04c11db7;\r
-      } else {\r
-        Value = Value << 1;\r
-      }\r
-    }\r
-    CrcTable[TableEntry] = PeiCrc32GuidedSectionExtractLibReverseBits (Value);\r
-  }\r
-\r
-  //\r
-  // Compute CRC\r
-  //\r
-  Crc = 0xffffffff;\r
-  for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {\r
-    Crc = (Crc >> 8) ^ CrcTable[(UINT8) Crc ^ *Ptr];\r
-  }\r
-\r
-  *CrcOut = Crc ^ 0xffffffff;\r
-  return EFI_SUCCESS;\r
-}\r
-\r
 /**\r
 \r
   GetInfo gets raw data size and attribute of the input guided section.\r
@@ -203,7 +120,6 @@ Crc32GuidedSectionHandler (
   OUT       UINT32  *AuthenticationStatus\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
   UINT32      SectionCrc32Checksum;\r
   UINT32      Crc32Checksum;\r
   UINT32      OutputBufferSize;\r
@@ -254,27 +170,15 @@ Crc32GuidedSectionHandler (
     *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;\r
   }\r
 \r
-  //\r
-  // Init Checksum value to Zero.\r
-  //\r
-  Crc32Checksum = 0;\r
-\r
   //\r
   // Calculate CRC32 Checksum of Image\r
   //\r
-  Status = PeiCrc32GuidedSectionExtractLibCalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum);\r
-  if (Status == EFI_SUCCESS) {\r
-    if (Crc32Checksum != SectionCrc32Checksum) {\r
-      //\r
-      // If Crc32 checksum is not matched, AUTH tested failed bit is set.\r
-      //\r
-      *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;\r
-    }\r
-  } else {\r
+  Crc32Checksum = CalculateCrc32 (*OutputBuffer, OutputBufferSize);\r
+  if (Crc32Checksum != SectionCrc32Checksum) {\r
     //\r
-    // If Crc32 checksum is not calculated, AUTH not tested bit is set.\r
+    // If Crc32 checksum is not matched, AUTH tested failed bit is set.\r
     //\r
-    *AuthenticationStatus |= EFI_AUTH_STATUS_NOT_TESTED;\r
+    *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;\r
   }\r
 \r
   //\r
index 71348100404fa1d29d71da168e75f4562f749777..45fd141f01ddd26f04ac0b49e8e58e10cfd2ba94 100644 (file)
@@ -5,7 +5,7 @@
 #  ExtractGuidedSectionLib service to register CRC32 guided section handler\r
 #  that parses CRC32 encapsulation section and extracts raw data.\r
 #\r
-# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -43,6 +43,7 @@
   ExtractGuidedSectionLib\r
   DebugLib\r
   BaseMemoryLib\r
+  BaseLib\r
 \r
 [Guids]\r
   gEfiCrc32GuidedSectionExtractionGuid             ## PRODUCES ## UNDEFINED\r