From: "Leif Lindholm" <leif@nuviainc.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>, macarl@microsoft.com
Subject: [RFC 3/5] EmbeddedPkg/PrePiLib: refactor IS_SECTION2() handling
Date: Wed, 1 Jul 2020 21:01:16 +0100 [thread overview]
Message-ID: <20200701200118.3972-4-leif@nuviainc.com> (raw)
In-Reply-To: <20200701200118.3972-1-leif@nuviainc.com>
There are a bunch of IS_SECTION2() conditional statements in
FfsProcessSection, really breaking up the readability.
Add a set of static helper functions instead.
Signed-off-by: Leif Lindholm <leif@nuviainc.com>
---
EmbeddedPkg/Library/PrePiLib/FwVol.c | 101 ++++++++++++++++-----------
1 file changed, 61 insertions(+), 40 deletions(-)
diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/PrePiLib/FwVol.c
index fc40d8650be1..a0672c084471 100644
--- a/EmbeddedPkg/Library/PrePiLib/FwVol.c
+++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c
@@ -266,6 +266,57 @@ FindFileEx (
return EFI_NOT_FOUND;
}
+STATIC
+UINTN
+FfsSectionHeaderSize (
+ IN EFI_COMMON_SECTION_HEADER *Section
+ )
+{
+ if (IS_SECTION2 (Section)) {
+ return sizeof (EFI_COMMON_SECTION_HEADER2);
+ }
+
+ return sizeof (EFI_COMMON_SECTION_HEADER);
+}
+
+STATIC
+UINTN
+FfsSectionLength (
+ IN EFI_COMMON_SECTION_HEADER *Section
+ )
+{
+ if (IS_SECTION2 (Section)) {
+ return SECTION2_SIZE (Section);
+ }
+
+ return SECTION_SIZE (Section);
+}
+
+STATIC
+UINTN
+FfsSectionCompressionType (
+ IN EFI_COMMON_SECTION_HEADER *Section
+ )
+{
+ if (IS_SECTION2 (Section)) {
+ return ((EFI_COMPRESSION_SECTION2 *)Section)->CompressionType;
+ }
+
+ return ((EFI_COMPRESSION_SECTION *)Section)->CompressionType;
+}
+
+STATIC
+UINTN
+FfsCompressionSectionHeaderSize (
+ IN EFI_COMMON_SECTION_HEADER *Section
+ )
+{
+ if (IS_SECTION2 (Section)) {
+ return sizeof (EFI_COMPRESSION_SECTION2);
+ }
+
+ return sizeof (EFI_COMPRESSION_SECTION);
+}
/**
Go through the file to search SectionType section,
@@ -289,8 +340,6 @@ FfsProcessSection (
EFI_STATUS Status;
UINT32 SectionLength;
UINT32 ParsedLength;
- EFI_COMPRESSION_SECTION *CompressionSection;
- EFI_COMPRESSION_SECTION2 *CompressionSection2;
UINT32 DstBufferSize;
VOID *ScratchBuffer;
UINT32 ScratchBufferSize;
@@ -310,39 +359,22 @@ FfsProcessSection (
}
if (Section->Type == SectionType) {
- if (IS_SECTION2 (Section)) {
- *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));
- } else {
- *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));
- }
+ *OutputBuffer = (VOID *)((UINT8 *)Section + FfsSectionHeaderSize (Section));
return EFI_SUCCESS;
}
if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) {
if (Section->Type == EFI_SECTION_COMPRESSION) {
- if (IS_SECTION2 (Section)) {
- CompressionSection2 = (EFI_COMPRESSION_SECTION2 *) Section;
- SectionLength = SECTION2_SIZE (Section);
+ SectionLength = FfsSectionLength (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);
+ if (FfsSectionCompressionType (Section) != EFI_STANDARD_COMPRESSION) {
+ return EFI_UNSUPPORTED;
}
+ CompressedData = (VOID *)((UINTN)Section + FfsCompressionSectionHeaderSize (Section));
+ CompressedDataLength = SectionLength - FfsCompressionSectionHeaderSize (Section);
+
Status = UefiDecompressGetInfo (
CompressedData,
CompressedDataLength,
@@ -383,19 +415,12 @@ FfsProcessSection (
// DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header
// to make section data at page alignment.
//
- 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);
+ DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - FfsSectionHeaderSize (Section);
//
// 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);
- }
+ CompressedData = (VOID *)((UINTN)Section + FfsCompressionSectionHeaderSize (Section));
Status = UefiDecompress (
CompressedData,
@@ -427,11 +452,7 @@ FfsProcessSection (
}
}
- if (IS_SECTION2 (Section)) {
- SectionLength = SECTION2_SIZE (Section);
- } else {
- SectionLength = SECTION_SIZE (Section);
- }
+ SectionLength = FfsSectionLength (Section);
//
// SectionLength is adjusted it is 4 byte aligned.
// Go to the next section
--
2.20.1
next prev parent reply other threads:[~2020-07-01 20:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-01 20:01 [RFC 0/5] EmbeddedPkg/PrePiLib: rework FfsProcessSection Leif Lindholm
2020-07-01 20:01 ` [RFC 1/5] EmbeddedPkg/PrePiLib: style cleanup in FwVol.c Leif Lindholm
2020-07-01 20:01 ` [RFC 2/5] EmbeddedPkg/PrePiLib: drop else if after return Leif Lindholm
2020-07-01 20:01 ` Leif Lindholm [this message]
2020-07-01 20:01 ` [RFC 4/5] EmbeddedPkg/PrePiLib: drop spurious re-init of CompressedData Leif Lindholm
2020-07-01 20:01 ` [RFC 5/5] EmbeddedPkg/PrePiLib: break section extraction info into helper function Leif Lindholm
2020-07-02 6:22 ` [RFC 0/5] EmbeddedPkg/PrePiLib: rework FfsProcessSection Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200701200118.3972-4-leif@nuviainc.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox