]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/PrePiLib/FwVol.c
EmbeddedPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmbeddedPkg / Library / PrePiLib / FwVol.c
index 530fc15dca1c3761695cc599ca7493a8a6f26096..797779f84525872a45197f335164be9ce9e13641 100644 (file)
@@ -5,13 +5,7 @@
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 \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
-\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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -296,35 +290,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 +382,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 +427,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