Rename Crc32GuidedSectionExtractLib to DxeCrc32GuidedSectionExtractLib.
authorlgao4 <lgao4@de2fecce-e211-0410-80a6-f3fac2684e05>
Wed, 17 Oct 2007 07:52:02 +0000 (07:52 +0000)
committerlgao4 <lgao4@de2fecce-e211-0410-80a6-f3fac2684e05>
Wed, 17 Oct 2007 07:52:02 +0000 (07:52 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@4156 de2fecce-e211-0410-80a6-f3fac2684e05

edk2/MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.c [new file with mode: 0644]
edk2/MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf [new file with mode: 0644]

diff --git a/edk2/MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.c b/edk2/MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.c
new file mode 100644 (file)
index 0000000..6deb8dc
--- /dev/null
@@ -0,0 +1,166 @@
+/*++\r
+\r
+Copyright (c) 2007, Intel Corporation                                                         \r
+All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  DxeCrc32GuidedSectionExtractLib.c\r
+\r
+Abstract:\r
+\r
+  Implements GUIDed section extraction protocol interface with \r
+  a specific GUID: CRC32.\r
+\r
+  Please refer to the Framewokr Firmware Volume Specification 0.9.\r
+\r
+--*/\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/Crc32GuidedSectionExtraction.h>\r
+#include <Protocol/SecurityPolicy.h>\r
+#include <Library/ExtractGuidedSectionLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+typedef struct {\r
+  EFI_GUID_DEFINED_SECTION  GuidedSectionHeader;\r
+  UINT32                    CRC32Checksum;\r
+} CRC32_SECTION_HEADER;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+Crc32GuidedSectionGetInfo (\r
+  IN  CONST VOID  *InputSection,\r
+  OUT UINT32      *OutputBufferSize,\r
+  OUT UINT32      *ScratchBufferSize,\r
+  OUT UINT16      *SectionAttribute\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation of Crc32 guided section GetInfo().\r
+\r
+Arguments:\r
+  InputSection          Buffer containing the input GUIDed section to be processed. \r
+  OutputBufferSize      The size of OutputBuffer.\r
+  ScratchBufferSize     The size of ScratchBuffer.\r
+  SectionAttribute      The attribute of the input guided section.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+  //\r
+  // Retrieve the size and attribute of the input section data.\r
+  //\r
+  *SectionAttribute  = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
+  *ScratchBufferSize = 0;\r
+  *OutputBufferSize  = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff;\r
+  *OutputBufferSize  -= ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+Crc32GuidedSectionHandler (\r
+  IN CONST  VOID    *InputSection,\r
+  OUT       VOID    **OutputBuffer,\r
+  IN        VOID    *ScratchBuffer,        OPTIONAL\r
+  OUT       UINT32  *AuthenticationStatus\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation of Crc32 Guided section extraction.\r
+\r
+Arguments:\r
+  InputSection           Buffer containing the input GUIDed section to be processed. \r
+  OutputBuffer           OutputBuffer to point to the start of the section's contents.\r
+                         if guided data is not prcessed. Otherwise,\r
+                         OutputBuffer to contain the output data, which is allocated by the caller.\r
+  ScratchBuffer          A pointer to a caller-allocated buffer for function internal use. \r
+  AuthenticationStatus   A pointer to a caller-allocated UINT32 that indicates the\r
+                         authentication status of the output buffer. 
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Decompression is successfull\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  CRC32_SECTION_HEADER      *Crc32SectionHeader;\r
+  UINT32                    Crc32Checksum;\r
+  UINT32                    OutputBufferSize;\r
+  VOID                      *DummyInterface;\r
+\r
+  Crc32Checksum = 0;\r
+  //\r
+  // Points to the Crc32 section header\r
+  //\r
+  Crc32SectionHeader = (CRC32_SECTION_HEADER *) InputSection;\r
+  *OutputBuffer      = (UINT8 *) InputSection + Crc32SectionHeader->GuidedSectionHeader.DataOffset;\r
+  OutputBufferSize   = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff; \r
+  OutputBufferSize   -= Crc32SectionHeader->GuidedSectionHeader.DataOffset;\r
+\r
+  //\r
+  // Implictly CRC32 GUIDed section should have STATUS_VALID bit set\r
+  //\r
+  ASSERT (Crc32SectionHeader->GuidedSectionHeader.Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);\r
+  *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;\r
+\r
+  //\r
+  // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiSecurityPolicyProtocolGuid, NULL, &DummyInterface);\r
+  if (!EFI_ERROR (Status)) {\r
+    *AuthenticationStatus |= EFI_AUTH_STATUS_PLATFORM_OVERRIDE;\r
+  } else {\r
+    //\r
+    // Calculate CRC32 Checksum of Image\r
+    //\r
+    Status = gBS->CalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum);\r
+    if (Status == EFI_SUCCESS) {\r
+      if (Crc32Checksum != Crc32SectionHeader->CRC32Checksum) {\r
+        *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;\r
+      }\r
+    } else {\r
+      *AuthenticationStatus |= EFI_AUTH_STATUS_NOT_TESTED;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**
+  Register Crc32 section handler.\r
+
+  @retval  RETURN_SUCCESS            Register successfully.\r
+  @retval  RETURN_OUT_OF_RESOURCES   No enough memory to store this handler.
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeCrc32GuidedSectionExtractLibConstructor (\r
+  )\r
+{\r
+  return ExtractGuidedSectionRegisterHandlers (\r
+          &gEfiCrc32GuidedSectionExtractionProtocolGuid,\r
+          Crc32GuidedSectionGetInfo,\r
+          Crc32GuidedSectionHandler\r
+          );\r
+}\r
+\r
diff --git a/edk2/MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf b/edk2/MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf
new file mode 100644 (file)
index 0000000..d5f136d
--- /dev/null
@@ -0,0 +1,48 @@
+#/** @file\r
+# Component description file for Crc32SectionExtract library.\r
+#\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. 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
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeCrc32GuidedSectionExtractLib\r
+  FILE_GUID                      = 387A2490-81FC-4E7C-8E0A-3E58C30FCD0B\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = DxeCrc32GuidedSectionExtractLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  DxeCrc32GuidedSectionExtractLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  ExtractGuidedSectionLib\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+\r
+[Protocols]\r
+  gEfiCrc32GuidedSectionExtractionProtocolGuid\r
+  gEfiSecurityPolicyProtocolGuid\r
+  
\ No newline at end of file