public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] EmbeddedPkg/PrePiLib: add support for v2 sections
@ 2017-12-11  7:39 Michael Zimmermann
  2017-12-11 18:22 ` Ard Biesheuvel
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Zimmermann @ 2017-12-11  7:39 UTC (permalink / raw)
  To: edk2-devel-01; +Cc: Ard Biesheuvel, Leif Lindholm

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
---
 EmbeddedPkg/Library/PrePiLib/FwVol.c | 63 ++++++++++++++++----
 1 file changed, 51 insertions(+), 12 deletions(-)

diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c
b/EmbeddedPkg/Library/PrePiLib/FwVol.c
index 530fc15dc..d513de351 100644
--- a/EmbeddedPkg/Library/PrePiLib/FwVol.c
+++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c
@@ -296,35 +296,61 @@ FfsProcessSection (
   UINT32                                  SectionLength;
   UINT32                                  ParsedLength;
   EFI_COMPRESSION_SECTION                 *CompressionSection;
+  EFI_COMPRESSION_SECTION2                *CompressionSection2;
   UINT32                                  DstBufferSize;
   VOID                                    *ScratchBuffer;
   UINT32                                  ScratchBufferSize;
   VOID                                    *DstBuffer;
   UINT16                                  SectionAttribute;
   UINT32                                  AuthenticationStatus;
+  CHAR8                                   *CompressedData;
+  UINTN                                   CompressedDataLength;


   *OutputBuffer = NULL;
   ParsedLength  = 0;
   Status        = EFI_NOT_FOUND;
   while (ParsedLength < SectionSize) {
+    if (IS_SECTION2 (Section)) {
+      ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);
+    }
+
     if (Section->Type == SectionType) {
-      *OutputBuffer = (VOID *)(Section + 1);
+      if (IS_SECTION2 (Section)) {
+        *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof
(EFI_COMMON_SECTION_HEADER2));
+      } else {
+        *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof
(EFI_COMMON_SECTION_HEADER));
+      }

       return EFI_SUCCESS;
     } else if ((Section->Type == EFI_SECTION_COMPRESSION) ||
(Section->Type == EFI_SECTION_GUID_DEFINED)) {

       if (Section->Type == EFI_SECTION_COMPRESSION) {
-        CompressionSection  = (EFI_COMPRESSION_SECTION *) Section;
-        SectionLength       = *(UINT32 *)Section->Size & 0x00FFFFFF;
-
-        if (CompressionSection->CompressionType !=
EFI_STANDARD_COMPRESSION) {
-          return EFI_UNSUPPORTED;
+        if (IS_SECTION2 (Section)) {
+          CompressionSection2 = (EFI_COMPRESSION_SECTION2 *) Section;
+          SectionLength       = SECTION2_SIZE (Section);
+
+          if (CompressionSection2->CompressionType !=
EFI_STANDARD_COMPRESSION) {
+            return EFI_UNSUPPORTED;
+          }
+
+          CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Section
+ 1);
+          CompressedDataLength = (UINT32) SectionLength - sizeof
(EFI_COMPRESSION_SECTION2);
+        } else {
+          CompressionSection  = (EFI_COMPRESSION_SECTION *) Section;
+          SectionLength       = SECTION_SIZE (Section);
+
+          if (CompressionSection->CompressionType !=
EFI_STANDARD_COMPRESSION) {
+            return EFI_UNSUPPORTED;
+          }
+
+          CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section
+ 1);
+          CompressedDataLength = (UINT32) SectionLength - sizeof
(EFI_COMPRESSION_SECTION);
         }

         Status = UefiDecompressGetInfo (
-                   (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),
-                   (UINT32) SectionLength - sizeof
(EFI_COMPRESSION_SECTION),
+                   CompressedData,
+                   CompressedDataLength,
                    &DstBufferSize,
                    &ScratchBufferSize
                    );
@@ -362,13 +388,23 @@ FfsProcessSection (
       // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI
section header
       // to make section data at page alignment.
       //
-      DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof
(EFI_COMMON_SECTION_HEADER);
+      if (IS_SECTION2 (Section))
+        DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof
(EFI_COMMON_SECTION_HEADER2);
+      else
+        DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof
(EFI_COMMON_SECTION_HEADER);
       //
       // Call decompress function
       //
       if (Section->Type == EFI_SECTION_COMPRESSION) {
+        if (IS_SECTION2 (Section)) {
+          CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Section
+ 1);
+        }
+        else {
+          CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section
+ 1);
+        }
+
         Status = UefiDecompress (
-                    (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),
+                    CompressedData,
                     DstBuffer,
                     ScratchBuffer
                     );
@@ -397,12 +433,15 @@ FfsProcessSection (
        }
     }

+    if (IS_SECTION2 (Section)) {
+      SectionLength = SECTION2_SIZE (Section);
+    } else {
+      SectionLength = SECTION_SIZE (Section);
+    }
     //
-    // Size is 24 bits wide so mask upper 8 bits.
     // SectionLength is adjusted it is 4 byte aligned.
     // Go to the next section
     //
-    SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;
     SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);
     ASSERT (SectionLength != 0);
     ParsedLength += SectionLength;
-- 
2.15.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] EmbeddedPkg/PrePiLib: add support for v2 sections
@ 2017-12-12  6:52 M1cha
  2017-12-12 10:46 ` Ard Biesheuvel
  0 siblings, 1 reply; 5+ messages in thread
From: M1cha @ 2017-12-12  6:52 UTC (permalink / raw)
  To: edk2-devel; +Cc: Ard Biesheuvel, Leif Lindholm

From: Michael Zimmermann <sigmaepsilon92@gmail.com>

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
---
 EmbeddedPkg/Library/PrePiLib/FwVol.c | 61 ++++++++++++++++----
 1 file changed, 50 insertions(+), 11 deletions(-)

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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-12 10:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-11  7:39 [PATCH] EmbeddedPkg/PrePiLib: add support for v2 sections Michael Zimmermann
2017-12-11 18:22 ` Ard Biesheuvel
2017-12-11 21:17   ` Ard Biesheuvel
  -- strict thread matches above, loose matches on Subject: below --
2017-12-12  6:52 M1cha
2017-12-12 10:46 ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox