]> 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 34ae0f59acce96ed1bd4fd38761f7056f21cd2ef..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
@@ -209,6 +203,9 @@ FindFileEx (
     FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);\r
   }\r
 \r
+  // FFS files begin with a header that is aligned on an 8-byte boundary\r
+  FfsFileHeader = ALIGN_POINTER (FfsFileHeader, 8);\r
+\r
   FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);\r
   ASSERT (FileOffset <= 0xFFFFFFFF);\r
 \r
@@ -293,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
@@ -359,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
@@ -394,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
@@ -695,12 +731,12 @@ FfsGetVolumeInfo (
 /**\r
   Search through every FV until you find a file of type FileType\r
 \r
-       @param FileType             File handle of a Fv type file.\r
-  @param Volumehandle   On succes Volume Handle of the match\r
-  @param FileHandle     On success File Handle of the match\r
+  @param FileType        File handle of a Fv type file.\r
+  @param Volumehandle    On succes Volume Handle of the match\r
+  @param FileHandle      On success File Handle of the match\r
 \r
-  @retval EFI_NOT_FOUND                                FV image can't be found.\r
-  @retval EFI_SUCCESS                                          Successfully found FileType\r
+  @retval EFI_NOT_FOUND  FV image can't be found.\r
+  @retval EFI_SUCCESS    Successfully found FileType\r
 \r
 **/\r
 EFI_STATUS\r
@@ -743,11 +779,11 @@ FfsAnyFvFindFirstFile (
 /**\r
   Get Fv image from the FV type file, then add FV & FV2 Hob.\r
 \r
-       @param FileHandle               File handle of a Fv type file.\r
+  @param FileHandle  File handle of a Fv type file.\r
 \r
 \r
-  @retval EFI_NOT_FOUND                                FV image can't be found.\r
-  @retval EFI_SUCCESS                                          Successfully to process it.\r
+  @retval EFI_NOT_FOUND  FV image can't be found.\r
+  @retval EFI_SUCCESS    Successfully to process it.\r
 \r
 **/\r
 EFI_STATUS\r