]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/PrePiLib/FwVol.c
EmbeddedPkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / EmbeddedPkg / Library / PrePiLib / FwVol.c
index 530fc15dca1c3761695cc599ca7493a8a6f26096..7b9853bab7360bbb3de44c70437c1001078c0af4 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
@@ -162,7 +156,7 @@ FileHandleToVolume (
 EFI_STATUS\r
 FindFileEx (\r
   IN  CONST EFI_PEI_FV_HANDLE        FvHandle,\r
-  IN  CONST EFI_GUID                 *FileName,   OPTIONAL\r
+  IN  CONST EFI_GUID                 *FileName    OPTIONAL,\r
   IN        EFI_FV_FILETYPE          SearchType,\r
   IN OUT    EFI_PEI_FILE_HANDLE      *FileHandle\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
@@ -341,7 +361,7 @@ FfsProcessSection (
         //\r
         // GetInfo failed\r
         //\r
-        DEBUG ((EFI_D_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r
+        DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r
         return EFI_NOT_FOUND;\r
       }\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
@@ -385,7 +415,7 @@ FfsProcessSection (
         //\r
         // Decompress failed\r
         //\r
-        DEBUG ((EFI_D_ERROR, "Decompress Failed - %r\n", Status));\r
+        DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));\r
         return EFI_NOT_FOUND;\r
       } else {\r
         return FfsProcessSection (\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
@@ -699,7 +732,7 @@ FfsGetVolumeInfo (
   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 Volumehandle    On success 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
@@ -824,7 +857,7 @@ FfsProcessFvFile (
 \r
 \r
   //\r
-  // Inform HOB consumer phase, i.e. DXE core, the existance of this FV\r
+  // Inform HOB consumer phase, i.e. DXE core, the existence of this FV\r
   //\r
   BuildFvHob ((EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart, FvImageInfo.FvSize);\r
 \r
@@ -841,5 +874,3 @@ FfsProcessFvFile (
 \r
   return EFI_SUCCESS;\r
 }\r
-\r
-\r