From nobody Mon Feb 9 10:12:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61926+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61926+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1593633867; cv=none; d=zohomail.com; s=zohoarc; b=mqgPqItYgeIXXDI97OekyyOHIgPPR4CA4ebiv7aGLbkcJpJDzjeP4/onz3PRQ+5v8kyR+P0qJ6C3pbuCdWULbVegnnMoYZIt2e+anjAPjNQV9ugNIAO8CTEKr4zFGEGTbBgWfCXRXTO67EveIQvbdIaWeHlsALEXFbnnJ/MAVss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593633867; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ystYYBxqGrFoDMw6jyOdPQc2VhMYT4j3qkV0YDZJHoU=; b=jVMzalATlQ+6/I/4kRnxgBUp/riqpZsek1HuQ4uH2WsgYcM6N14K1j0joN4y8sKLV1er02icGR8GAg9YncdIFmS/evn+GwXi6YJkJ/ZLMr5ptHyWMVMPhGDG4Qv7N43NVvfR6AWi8xccqWYcKz3+HRdpFDjoj5ayh6hs63r3ius= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61926+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1593633867034549.5495901527582; Wed, 1 Jul 2020 13:04:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 71gNYY1788612xTb4EQgCFle; Wed, 01 Jul 2020 13:04:26 -0700 X-Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web11.6023.1593633685502234814 for ; Wed, 01 Jul 2020 13:01:25 -0700 X-Received: by mail-wr1-f68.google.com with SMTP id s10so25366965wrw.12 for ; Wed, 01 Jul 2020 13:01:25 -0700 (PDT) X-Gm-Message-State: jizVLzOOC2bDKj27YFM2gK4yx1787277AA= X-Google-Smtp-Source: ABdhPJwU8x/0xOcXIs2mi2KjYZ5/6/279HOy2s9azzSHo/carAaKN0sheQi2Zw5R5tTdBgSTifwukA== X-Received: by 2002:a05:6000:1c7:: with SMTP id t7mr28026184wrx.14.1593633683540; Wed, 01 Jul 2020 13:01:23 -0700 (PDT) X-Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id s8sm8519067wru.38.2020.07.01.13.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 13:01:23 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Ard Biesheuvel , macarl@microsoft.com Subject: [edk2-devel] [RFC 3/5] EmbeddedPkg/PrePiLib: refactor IS_SECTION2() handling Date: Wed, 1 Jul 2020 21:01:16 +0100 Message-Id: <20200701200118.3972-4-leif@nuviainc.com> In-Reply-To: <20200701200118.3972-1-leif@nuviainc.com> References: <20200701200118.3972-1-leif@nuviainc.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,leif@nuviainc.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1593633866; bh=hz4MapFZecIAdiORlB7+t1fCNsu1n2Y6VfS4yxS3D6k=; h=Cc:Date:From:Reply-To:Subject:To; b=tAydJomY05LCRHL8aHkFWxwzjxBTk39/tTJVR21fp+SAJTS2IyxArTx5Ucc5BIhDlkJ 6WBUHv4lLwF2IGZOAClWYXDLNtMHNoCTco/eJhBb+I+uk+HQIvkO/yuZG66wJgjoRaOJs geodv5TlygwsfWuH7ibtfriQ/i5z4w5Sf2I= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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 --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 101 ++++++++++++++++----------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/Pre= PiLib/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; } =20 +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); +} =20 /** 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 ( } =20 if (Section->Type =3D=3D SectionType) { - if (IS_SECTION2 (Section)) { - *OutputBuffer =3D (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_= SECTION_HEADER2)); - } else { - *OutputBuffer =3D (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_= SECTION_HEADER)); - } + *OutputBuffer =3D (VOID *)((UINT8 *)Section + FfsSectionHeaderSize (= Section)); =20 return EFI_SUCCESS; } =20 if ((Section->Type =3D=3D EFI_SECTION_COMPRESSION) || (Section->Type = =3D=3D EFI_SECTION_GUID_DEFINED)) { if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { - if (IS_SECTION2 (Section)) { - CompressionSection2 =3D (EFI_COMPRESSION_SECTION2 *) Section; - SectionLength =3D SECTION2_SIZE (Section); + SectionLength =3D FfsSectionLength (Section); =20 - if (CompressionSection2->CompressionType !=3D EFI_STANDARD_COMPR= ESSION) { - return EFI_UNSUPPORTED; - } - - CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Secti= on + 1); - CompressedDataLength =3D (UINT32) SectionLength - sizeof (EFI_CO= MPRESSION_SECTION2); - } else { - CompressionSection =3D (EFI_COMPRESSION_SECTION *) Section; - SectionLength =3D SECTION_SIZE (Section); - - if (CompressionSection->CompressionType !=3D EFI_STANDARD_COMPRE= SSION) { - return EFI_UNSUPPORTED; - } - - CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Sectio= n + 1); - CompressedDataLength =3D (UINT32) SectionLength - sizeof (EFI_CO= MPRESSION_SECTION); + if (FfsSectionCompressionType (Section) !=3D EFI_STANDARD_COMPRESS= ION) { + return EFI_UNSUPPORTED; } =20 + CompressedData =3D (VOID *)((UINTN)Section + FfsCompressionSection= HeaderSize (Section)); + CompressedDataLength =3D SectionLength - FfsCompressionSectionHead= erSize (Section); + Status =3D 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 =3D (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COM= MON_SECTION_HEADER2); - else - DstBuffer =3D (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COM= MON_SECTION_HEADER); + DstBuffer =3D (UINT8 *)DstBuffer + EFI_PAGE_SIZE - FfsSectionHeaderS= ize (Section); // // Call decompress function // if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { - if (IS_SECTION2 (Section)) { - CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Secti= on + 1); - } else { - CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Sectio= n + 1); - } + CompressedData =3D (VOID *)((UINTN)Section + FfsCompressionSection= HeaderSize (Section)); =20 Status =3D UefiDecompress ( CompressedData, @@ -427,11 +452,7 @@ FfsProcessSection ( } } =20 - if (IS_SECTION2 (Section)) { - SectionLength =3D SECTION2_SIZE (Section); - } else { - SectionLength =3D SECTION_SIZE (Section); - } + SectionLength =3D FfsSectionLength (Section); // // SectionLength is adjusted it is 4 byte aligned. // Go to the next section --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61926): https://edk2.groups.io/g/devel/message/61926 Mute This Topic: https://groups.io/mt/75244270/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-