]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.c
MdeModulePkg SmmMemoryAttribute.h: Refine some comments
[mirror_edk2.git] / MdeModulePkg / Library / DxeCrc32GuidedSectionExtractLib / DxeCrc32GuidedSectionExtractLib.c
index b87af37a91b9de76f1b12713d671d9d6d803609d..5f2892823b5017a52fa7d98da7eacfe82320083e 100644 (file)
@@ -4,8 +4,8 @@
   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                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2007 - 2011, 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
@@ -16,15 +16,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\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
@@ -33,6 +31,11 @@ typedef struct {
   UINT32                    CRC32Checksum;       ///< 32bit CRC check sum\r
 } CRC32_SECTION_HEADER;\r
 \r
+typedef struct {\r
+  EFI_GUID_DEFINED_SECTION2 GuidedSectionHeader; ///< EFI guided section header\r
+  UINT32                    CRC32Checksum;       ///< 32bit CRC check sum\r
+} CRC32_SECTION2_HEADER;\r
+\r
 /**\r
 \r
   GetInfo gets raw data size and attribute of the input guided section.\r
@@ -45,7 +48,7 @@ typedef struct {
   @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
+                                 the attribute of the input section are successfully retrieved.\r
   @retval EFI_INVALID_PARAMETER  The GUID in InputSection does not match this instance guid.\r
 \r
 **/\r
@@ -58,21 +61,37 @@ Crc32GuidedSectionGetInfo (
   OUT UINT16      *SectionAttribute\r
   )\r
 {\r
-  //\r
-  // Check whether the input guid section is recognized.\r
-  //\r
-  if (!CompareGuid (\r
-        &gEfiCrc32GuidedSectionExtractionProtocolGuid, \r
+  if (IS_SECTION2 (InputSection)) {\r
+    //\r
+    // Check whether the input guid section is recognized.\r
+    //\r
+    if (!CompareGuid (\r
+        &gEfiCrc32GuidedSectionExtractionGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) 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_SECTION2 *) InputSection)->Attributes;\r
+    *ScratchBufferSize = 0;\r
+    *OutputBufferSize  = SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;\r
+  } else {\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
+      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  = SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\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) & EFI_SECITON_SIZE_MASK;\r
-  *OutputBufferSize  -= ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -104,37 +123,61 @@ Crc32GuidedSectionHandler (
   )\r
 {\r
   EFI_STATUS                Status;\r
-  CRC32_SECTION_HEADER      *Crc32SectionHeader;\r
+  UINT32                    SectionCrc32Checksum;\r
   UINT32                    Crc32Checksum;\r
   UINT32                    OutputBufferSize;\r
   VOID                      *DummyInterface;\r
 \r
-  //\r
-  // Check whether the input guid section is recognized.\r
-  //\r
-  if (!CompareGuid (\r
-        &gEfiCrc32GuidedSectionExtractionProtocolGuid, \r
+  if (IS_SECTION2 (InputSection)) {\r
+    //\r
+    // Check whether the input guid section is recognized.\r
+    //\r
+    if (!CompareGuid (\r
+        &gEfiCrc32GuidedSectionExtractionGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  \r
+    //\r
+    // Get section Crc32 checksum.\r
+    //\r
+    SectionCrc32Checksum = ((CRC32_SECTION2_HEADER *) InputSection)->CRC32Checksum;\r
+    *OutputBuffer      = (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;\r
+    OutputBufferSize   = SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;\r
+\r
+    //\r
+    // Implicitly CRC32 GUIDed section should have STATUS_VALID bit set\r
+    //\r
+    ASSERT (((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);\r
+    *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;\r
+  } else {\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
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   \r
+    //\r
+    // Get section Crc32 checksum.\r
+    //\r
+    SectionCrc32Checksum = ((CRC32_SECTION_HEADER *) InputSection)->CRC32Checksum;\r
+    *OutputBuffer      = (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
+    OutputBufferSize   = SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
+\r
+    //\r
+    // Implicitly CRC32 GUIDed section should have STATUS_VALID bit set\r
+    //\r
+    ASSERT (((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);\r
+    *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;\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) & EFI_SECITON_SIZE_MASK; \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
@@ -151,7 +194,7 @@ Crc32GuidedSectionHandler (
     //\r
     Status = gBS->CalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum);\r
     if (Status == EFI_SUCCESS) {\r
-      if (Crc32Checksum != Crc32SectionHeader->CRC32Checksum) {\r
+      if (Crc32Checksum != SectionCrc32Checksum) {\r
         //\r
         // If Crc32 checksum is not matched, AUTH tested failed bit is set.\r
         //\r
@@ -185,7 +228,7 @@ DxeCrc32GuidedSectionExtractLibConstructor (
   )\r
 {\r
   return ExtractGuidedSectionRegisterHandlers (\r
-          &gEfiCrc32GuidedSectionExtractionProtocolGuid,\r
+          &gEfiCrc32GuidedSectionExtractionGuid,\r
           Crc32GuidedSectionGetInfo,\r
           Crc32GuidedSectionHandler\r
           );\r