]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Library / DxeCrc32GuidedSectionExtractLib / DxeCrc32GuidedSectionExtractLib.c
index 6deb8dc6d26bbcbcfac6035628b0bea35c04fcd7..18aee70774515564bf038e402cce58e39797750f 100644 (file)
@@ -1,7 +1,11 @@
-/*++\r
+/** @file\r
 \r
-Copyright (c) 2007, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+  This library registers CRC32 guided section handler \r
+  to parse CRC32 encapsulation section and extract raw data.\r
+  It uses UEFI boot service CalculateCrc32 to authenticate 32 bit CRC value.\r
+\r
+Copyright (c) 2007 - 2008, 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
 http://opensource.org/licenses/bsd-license.php                                            \r
@@ -9,31 +13,42 @@ http://opensource.org/licenses/bsd-license.php
 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
 \r
 #include <PiDxe.h>\r
-#include <Protocol/Crc32GuidedSectionExtraction.h>\r
+#include <Guid/Crc32GuidedSectionExtraction.h>\r
 #include <Protocol/SecurityPolicy.h>\r
 #include <Library/ExtractGuidedSectionLib.h>\r
 #include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 \r
+#define EFI_SECITON_SIZE_MASK 0x00ffffff\r
+\r
+///\r
+/// CRC32 Guided Section header\r
+///\r
 typedef struct {\r
-  EFI_GUID_DEFINED_SECTION  GuidedSectionHeader;\r
-  UINT32                    CRC32Checksum;\r
+  EFI_GUID_DEFINED_SECTION  GuidedSectionHeader; ///< EFI guided section header\r
+  UINT32                    CRC32Checksum;       ///< 32bit CRC check sum\r
 } CRC32_SECTION_HEADER;\r
 \r
+/**\r
+\r
+  GetInfo gets raw data size and attribute of the input guided section.\r
+  It first checks whether the input guid section is supported. \r
+  If not, EFI_INVALID_PARAMETER will return.\r
+\r
+  @param InputSection       Buffer containing the input GUIDed section to be processed.\r
+  @param OutputBufferSize   The size of OutputBuffer.\r
+  @param ScratchBufferSize  The size of ScratchBuffer.\r
+  @param SectionAttribute   The attribute of the input guided section.\r
+\r
+  @retval EFI_SUCCESS            The size of destination buffer, the size of scratch buffer and \r
+                                 the attribute of the input section are successull retrieved.\r
+  @retval EFI_INVALID_PARAMETER  The GUID in InputSection does not match this instance guid.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 Crc32GuidedSectionGetInfo (\r
@@ -42,36 +57,43 @@ Crc32GuidedSectionGetInfo (
   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
+  // Check whether the input guid section is recognized.\r
+  //\r
+  if (!CompareGuid (\r
+        &gEfiCrc32GuidedSectionExtractionGuid, \r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    return EFI_INVALID_PARAMETER;\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  = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & EFI_SECITON_SIZE_MASK;\r
   *OutputBufferSize  -= ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+\r
+  Extraction handler tries to extract raw data from the input guided section.\r
+  It also does authentication check for 32bit CRC value in the input guided section.\r
+  It first checks whether the input guid section is supported. \r
+  If not, EFI_INVALID_PARAMETER will return.\r
+\r
+  @param InputSection    Buffer containing the input GUIDed section to be processed.\r
+  @param OutputBuffer    Buffer to contain the output raw data allocated by the caller.\r
+  @param ScratchBuffer   A pointer to a caller-allocated buffer for function internal use.\r
+  @param AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the\r
+                              authentication status of the output buffer.\r
+\r
+  @retval EFI_SUCCESS            Section Data and Auth Status is extracted successfully.\r
+  @retval EFI_INVALID_PARAMETER  The GUID in InputSection does not match this instance guid.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 Crc32GuidedSectionHandler (\r
@@ -80,27 +102,6 @@ Crc32GuidedSectionHandler (
   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
@@ -108,13 +109,25 @@ Returns:
   UINT32                    OutputBufferSize;\r
   VOID                      *DummyInterface;\r
 \r
+  //\r
+  // Check whether the input guid section is recognized.\r
+  //\r
+  if (!CompareGuid (\r
+        &gEfiCrc32GuidedSectionExtractionGuid, \r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // Init Checksum value to Zero.\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   = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & EFI_SECITON_SIZE_MASK\r
   OutputBufferSize   -= Crc32SectionHeader->GuidedSectionHeader.DataOffset;\r
 \r
   //\r
@@ -128,6 +141,9 @@ Returns:
   //\r
   Status = gBS->LocateProtocol (&gEfiSecurityPolicyProtocolGuid, NULL, &DummyInterface);\r
   if (!EFI_ERROR (Status)) {\r
+    //\r
+    // If SecurityPolicy Protocol exist, AUTH platform override bit is set.\r
+    //\r
     *AuthenticationStatus |= EFI_AUTH_STATUS_PLATFORM_OVERRIDE;\r
   } else {\r
     //\r
@@ -136,9 +152,15 @@ Returns:
     Status = gBS->CalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum);\r
     if (Status == EFI_SUCCESS) {\r
       if (Crc32Checksum != Crc32SectionHeader->CRC32Checksum) {\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
+      //\r
+      // If Crc32 checksum is not calculated, AUTH not tested bit is set.\r
+      //\r
       *AuthenticationStatus |= EFI_AUTH_STATUS_NOT_TESTED;\r
     }\r
   }\r
@@ -146,19 +168,24 @@ Returns:
   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
+  Register the handler to extract CRC32 guided section.\r
+\r
+  @param  ImageHandle  ImageHandle of the loaded driver.\r
+  @param  SystemTable  Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCCESS            Register successfully.\r
+  @retval  EFI_OUT_OF_RESOURCES   No enough memory to register this handler.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 DxeCrc32GuidedSectionExtractLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
   return ExtractGuidedSectionRegisterHandlers (\r
-          &gEfiCrc32GuidedSectionExtractionProtocolGuid,\r
+          &gEfiCrc32GuidedSectionExtractionGuid,\r
           Crc32GuidedSectionGetInfo,\r
           Crc32GuidedSectionHandler\r
           );\r