diff options
author | Liming Gao <liming.gao@intel.com> | 2017-09-08 13:18:25 +0800 |
---|---|---|
committer | Liming Gao <liming.gao@intel.com> | 2017-10-10 18:10:16 +0800 |
commit | 05542f49877f9047c536b61fd8f15dd4c4496b4b (patch) | |
tree | a1dff968108f1ad46936a501cff7c03009f8dd58 /MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib | |
parent | 0a8e6f7971ad778897cacee2be09016d4366a4a1 (diff) | |
download | edk2-05542f49877f9047c536b61fd8f15dd4c4496b4b.tar.gz edk2-05542f49877f9047c536b61fd8f15dd4c4496b4b.tar.bz2 edk2-05542f49877f9047c536b61fd8f15dd4c4496b4b.zip |
MdeModulePkg: Update modules to consume CalculateCrc32()
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Diffstat (limited to 'MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib')
-rw-r--r-- | MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c | 108 | ||||
-rw-r--r-- | MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf | 3 |
2 files changed, 8 insertions, 103 deletions
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.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
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 <PiPei.h>
#include <Guid/Crc32GuidedSectionExtraction.h>
+#include <Library/BaseLib.h>
#include <Library/ExtractGuidedSectionLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
@@ -34,90 +35,6 @@ typedef struct { } 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.
It first checks whether the input guid section is supported.
@@ -203,7 +120,6 @@ Crc32GuidedSectionHandler ( OUT UINT32 *AuthenticationStatus
)
{
- EFI_STATUS Status;
UINT32 SectionCrc32Checksum;
UINT32 Crc32Checksum;
UINT32 OutputBufferSize;
@@ -255,26 +171,14 @@ Crc32GuidedSectionHandler ( }
//
- // 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.<BR>
+# Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
#
# 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
|