]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/PrePiLib: add support for v2 sections
authorMichael Zimmermann <sigmaepsilon92@gmail.com>
Tue, 12 Dec 2017 06:49:28 +0000 (07:49 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 12 Dec 2017 10:43:28 +0000 (10:43 +0000)
Implement the missing support for FFS files whose size equals
or exceeds 16 MiB.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
EmbeddedPkg/Library/PrePiLib/FwVol.c

index 530fc15dca1c3761695cc599ca7493a8a6f26096..d513de351ff59284cb731dd2f5daa2e9c47dadfe 100644 (file)
@@ -296,35 +296,61 @@ FfsProcessSection (
   UINT32                                  SectionLength;\r
   UINT32                                  ParsedLength;\r
   EFI_COMPRESSION_SECTION                 *CompressionSection;\r
+  EFI_COMPRESSION_SECTION2                *CompressionSection2;\r
   UINT32                                  DstBufferSize;\r
   VOID                                    *ScratchBuffer;\r
   UINT32                                  ScratchBufferSize;\r
   VOID                                    *DstBuffer;\r
   UINT16                                  SectionAttribute;\r
   UINT32                                  AuthenticationStatus;\r
+  CHAR8                                   *CompressedData;\r
+  UINTN                                   CompressedDataLength;\r
 \r
 \r
   *OutputBuffer = NULL;\r
   ParsedLength  = 0;\r
   Status        = EFI_NOT_FOUND;\r
   while (ParsedLength < SectionSize) {\r
+    if (IS_SECTION2 (Section)) {\r
+      ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);\r
+    }\r
+\r
     if (Section->Type == SectionType) {\r
-      *OutputBuffer = (VOID *)(Section + 1);\r
+      if (IS_SECTION2 (Section)) {\r
+        *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r
+      } else {\r
+        *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
+      }\r
 \r
       return EFI_SUCCESS;\r
     } else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) {\r
 \r
       if (Section->Type == EFI_SECTION_COMPRESSION) {\r
-        CompressionSection  = (EFI_COMPRESSION_SECTION *) Section;\r
-        SectionLength       = *(UINT32 *)Section->Size & 0x00FFFFFF;\r
-\r
-        if (CompressionSection->CompressionType != EFI_STANDARD_COMPRESSION) {\r
-          return EFI_UNSUPPORTED;\r
+        if (IS_SECTION2 (Section)) {\r
+          CompressionSection2 = (EFI_COMPRESSION_SECTION2 *) Section;\r
+          SectionLength       = SECTION2_SIZE (Section);\r
+\r
+          if (CompressionSection2->CompressionType != EFI_STANDARD_COMPRESSION) {\r
+            return EFI_UNSUPPORTED;\r
+          }\r
+\r
+          CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Section + 1);\r
+          CompressedDataLength = (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION2);\r
+        } else {\r
+          CompressionSection  = (EFI_COMPRESSION_SECTION *) Section;\r
+          SectionLength       = SECTION_SIZE (Section);\r
+\r
+          if (CompressionSection->CompressionType != EFI_STANDARD_COMPRESSION) {\r
+            return EFI_UNSUPPORTED;\r
+          }\r
+\r
+          CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1);\r
+          CompressedDataLength = (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION);\r
         }\r
 \r
         Status = UefiDecompressGetInfo (\r
-                   (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
-                   (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
+                   CompressedData,\r
+                   CompressedDataLength,\r
                    &DstBufferSize,\r
                    &ScratchBufferSize\r
                    );\r
@@ -362,13 +388,23 @@ FfsProcessSection (
       // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header\r
       // to make section data at page alignment.\r
       //\r
-      DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r
+      if (IS_SECTION2 (Section))\r
+        DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER2);\r
+      else\r
+        DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r
       //\r
       // Call decompress function\r
       //\r
       if (Section->Type == EFI_SECTION_COMPRESSION) {\r
+        if (IS_SECTION2 (Section)) {\r
+          CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Section + 1);\r
+        }\r
+        else {\r
+          CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1);\r
+        }\r
+\r
         Status = UefiDecompress (\r
-                    (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                    CompressedData,\r
                     DstBuffer,\r
                     ScratchBuffer\r
                     );\r
@@ -397,12 +433,15 @@ FfsProcessSection (
        }\r
     }\r
 \r
+    if (IS_SECTION2 (Section)) {\r
+      SectionLength = SECTION2_SIZE (Section);\r
+    } else {\r
+      SectionLength = SECTION_SIZE (Section);\r
+    }\r
     //\r
-    // Size is 24 bits wide so mask upper 8 bits.\r
     // SectionLength is adjusted it is 4 byte aligned.\r
     // Go to the next section\r
     //\r
-    SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;\r
     SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r
     ASSERT (SectionLength != 0);\r
     ParsedLength += SectionLength;\r