Update CustomDecompress library to support algorithm guid and Update DxeIpl and DxeCo...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / SectionExtraction / CoreSectionExtraction.c
index 1c328be..b86f273 100644 (file)
@@ -212,7 +212,15 @@ IsValidSectionStream (
   IN  VOID                                    *SectionStream,\r
   IN  UINTN                                   SectionStreamLength\r
   );\r
-  \r
+\r
+EFI_STATUS\r
+CustomDecompressExtractSection (\r
+  IN CONST  EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
+  IN CONST  VOID                                   *InputSection,\r
+  OUT       VOID                                   **OutputBuffer,\r
+  OUT       UINTN                                  *OutputSize,\r
+  OUT       UINT32                                 *AuthenticationStatus\r
+  );  \r
 //\r
 // Module globals\r
 //\r
@@ -226,6 +234,9 @@ EFI_SECTION_EXTRACTION_PROTOCOL mSectionExtraction = {
   CloseSectionStream\r
 };\r
 \r
+EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomDecompressExtraction = {\r
+  CustomDecompressExtractSection\r
+};\r
                                              \r
 EFI_STATUS\r
 EFIAPI\r
@@ -250,6 +261,8 @@ Returns:
 --*/\r
 {\r
   EFI_STATUS                         Status;\r
+  EFI_GUID                           **DecompressGuidList;\r
+  UINT32                             DecompressMethodNumber;\r
 \r
   //\r
   // Install SEP to a new handle\r
@@ -262,6 +275,34 @@ Returns:
             );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Get custom decompress method guid list \r
+  //\r
+  DecompressGuidList     = NULL;\r
+  DecompressMethodNumber = 0;\r
+  Status = CustomDecompressGetAlgorithms (DecompressGuidList, &DecompressMethodNumber);\r
+  if (Status == EFI_OUT_OF_RESOURCES) {\r
+    DecompressGuidList = (EFI_GUID **) CoreAllocateBootServicesPool (DecompressMethodNumber * sizeof (EFI_GUID *));\r
+    ASSERT (DecompressGuidList != NULL);\r
+    Status = CustomDecompressGetAlgorithms (DecompressGuidList, &DecompressMethodNumber);\r
+  }\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  //\r
+  // Install custom decompress guided extraction protocol \r
+  //\r
+  while (DecompressMethodNumber-- > 0) {\r
+    Status = CoreInstallProtocolInterface (\r
+              &mSectionExtractionHandle,\r
+              DecompressGuidList [DecompressMethodNumber],\r
+              EFI_NATIVE_INTERFACE,\r
+              &mCustomDecompressExtraction\r
+              );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+  \r
+  CoreFreePool (DecompressGuidList);\r
+\r
   return Status;\r
 }\r
 \r
@@ -742,7 +783,7 @@ Returns:
   EFI_COMMON_SECTION_HEADER                    *SectionHeader;\r
   EFI_COMPRESSION_SECTION                      *CompressionHeader;\r
   EFI_GUID_DEFINED_SECTION                     *GuidedHeader;\r
-  EFI_TIANO_DECOMPRESS_PROTOCOL                *Decompress;\r
+  EFI_DECOMPRESS_PROTOCOL                      *Decompress;\r
   EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL       *GuidedExtraction;\r
   VOID                                         *NewStreamBuffer;\r
   VOID                                         *ScratchBuffer;\r
@@ -1339,3 +1380,168 @@ Returns:
   ASSERT (FALSE);\r
   return FALSE;\r
 }\r
+\r
+/**\r
+  The ExtractSection() function processes the input section and\r
+  allocates a buffer from the pool in which it returns the section\r
+  contents. If the section being extracted contains\r
+  authentication information (the section's\r
+  GuidedSectionHeader.Attributes field has the\r
+  EFI_GUIDED_SECTION_AUTH_STATUS_VALID bit set), the values\r
+  returned in AuthenticationStatus must reflect the results of\r
+  the authentication operation. Depending on the algorithm and\r
+  size of the encapsulated data, the time that is required to do\r
+  a full authentication may be prohibitively long for some\r
+  classes of systems. To indicate this, use\r
+  EFI_SECURITY_POLICY_PROTOCOL_GUID, which may be published by\r
+  the security policy driver (see the Platform Initialization\r
+  Driver Execution Environment Core Interface Specification for\r
+  more details and the GUID definition). If the\r
+  EFI_SECURITY_POLICY_PROTOCOL_GUID exists in the handle\r
+  database, then, if possible, full authentication should be\r
+  skipped and the section contents simply returned in the\r
+  OutputBuffer. In this case, the\r
+  EFI_AUTH_STATUS_PLATFORM_OVERRIDE bit AuthenticationStatus\r
+  must be set on return. ExtractSection() is callable only from\r
+  TPL_NOTIFY and below. Behavior of ExtractSection() at any\r
+  EFI_TPL above TPL_NOTIFY is undefined. Type EFI_TPL is\r
+  defined in RaiseTPL() in the UEFI 2.0 specification.\r
+\r
+  \r
+  @param This   Indicates the\r
+                EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL instance.\r
+  \r
+  @param InputSection Buffer containing the input GUIDed section\r
+                      to be processed. OutputBuffer OutputBuffer\r
+                      is allocated from boot services pool\r
+                      memory and contains the new section\r
+                      stream. The caller is responsible for\r
+                      freeing this buffer.\r
+\r
+  @param OutputSize   A pointer to a caller-allocated UINTN in\r
+                      which the size of OutputBuffer allocation\r
+                      is stored. If the function returns\r
+                      anything other than EFI_SUCCESS, the value\r
+                      of OutputSize is undefined.\r
+\r
+  @param AuthenticationStatus A pointer to a caller-allocated\r
+                              UINT32 that indicates the\r
+                              authentication status of the\r
+                              output buffer. If the input\r
+                              section's\r
+                              GuidedSectionHeader.Attributes\r
+                              field has the\r
+                              EFI_GUIDED_SECTION_AUTH_STATUS_VAL\r
+                              bit as clear, AuthenticationStatus\r
+                              must return zero. Both local bits\r
+                              (19:16) and aggregate bits (3:0)\r
+                              in AuthenticationStatus are\r
+                              returned by ExtractSection().\r
+                              These bits reflect the status of\r
+                              the extraction operation. The bit\r
+                              pattern in both regions must be\r
+                              the same, as the local and\r
+                              aggregate authentication statuses\r
+                              have equivalent meaning at this\r
+                              level. If the function returns\r
+                              anything other than EFI_SUCCESS,\r
+                              the value of AuthenticationStatus\r
+                              is undefined.\r
+\r
+\r
+  @retval EFI_SUCCESS The InputSection was successfully\r
+                      processed and the section contents were\r
+                      returned.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  The system has insufficient\r
+                                resources to process the\r
+                                request.\r
+\r
+  @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r
+                                not match this instance of the\r
+                                GUIDed Section Extraction\r
+                                Protocol.\r
+\r
+**/\r
+EFI_STATUS\r
+CustomDecompressExtractSection (\r
+  IN CONST  EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
+  IN CONST  VOID                                   *InputSection,\r
+  OUT       VOID                                   **OutputBuffer,\r
+  OUT       UINTN                                  *OutputSize,\r
+  OUT       UINT32                                 *AuthenticationStatus\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  UINT8           *ScratchBuffer;\r
+  UINT32          ScratchSize;\r
+  UINT32          SectionLength;  \r
+  \r
+  //\r
+  // Set authentic value to zero.\r
+  //\r
+  *AuthenticationStatus = 0;\r
+  //\r
+  // Calculate Section data Size\r
+  //\r
+  SectionLength   = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff;\r
+  //\r
+  // Get compressed data information\r
+  //\r
+  Status = CustomDecompressGetInfo (\r
+             (GUID *) ((UINT8 *) InputSection + sizeof (EFI_COMMON_SECTION_HEADER)),\r
+             (UINT8 *) InputSection + sizeof (EFI_GUID_DEFINED_SECTION),\r
+             SectionLength - sizeof (EFI_GUID_DEFINED_SECTION),\r
+             OutputSize,\r
+             &ScratchSize\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // GetInfo failed\r
+    //\r
+    DEBUG ((EFI_D_ERROR, "Extract guided section Failed - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Allocate scratch buffer\r
+  //\r
+  ScratchBuffer = CoreAllocateBootServicesPool (ScratchSize);\r
+  if (ScratchBuffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Allocate destination buffer\r
+  //\r
+  *OutputBuffer = CoreAllocateBootServicesPool (*OutputSize);\r
+  if (*OutputBuffer == NULL) {\r
+    CoreFreePool (ScratchBuffer);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Call decompress function\r
+  //\r
+  Status = CustomDecompress (\r
+             (GUID *) ((UINT8 *) InputSection + sizeof (EFI_COMMON_SECTION_HEADER)),\r
+             (UINT8 *) InputSection + sizeof (EFI_GUID_DEFINED_SECTION),\r
+             *OutputBuffer,\r
+             ScratchBuffer\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Decompress failed\r
+    //\r
+    CoreFreePool (ScratchBuffer);\r
+    CoreFreePool (*OutputBuffer);\r
+    DEBUG ((EFI_D_ERROR, "Extract guided section Failed - %r\n", Status));\r
+    return Status;\r
+  }\r
+  \r
+  //\r
+  // Free unused scratch buffer.\r
+  //\r
+  CoreFreePool (ScratchBuffer);\r
+  \r
+  return EFI_SUCCESS;\r
+}
\ No newline at end of file