From nobody Mon Feb 9 22:03:45 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+61928+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+61928+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1593633705; cv=none; d=zohomail.com; s=zohoarc; b=H6gF3Cb+DHIE81cmFepMbE8SUKlTRe10ifaMZS2+XYRUnNtVxVc2TiWlbKfINgOpAMHjEKchwjXTF3a39QVmZ6ieepuBYyt7MAhYErRi19Qj5HnHO2lGm6QP4J9msh+2pVSmvMtJD8gHQgTG3n+abIcXSGc0JfFxQaikgPEXpGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593633705; 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=oN5x5roW74A2zcGPKnCuB2sdEA08LHuuquDMwLok7IQ=; b=ACHxs2u4QeTSjCliBTV3Wd0MqyPSD+wVN5gGEr0p/z7Fi1iIODulb6sMGXrptqd18CFe3RkUlk2pGCGDLfoeHaQSTH4PrRDvpPbLYWliQR0dRQFxTv9V5XohLF5u1glJEbijyuPb6175F2yq/qTsRgUjipclSvMRDQw79tdVeeA= 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+61928+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1593633705680460.208691004666; Wed, 1 Jul 2020 13:01:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2YwDYY1788612x2wtKpMmRaE; Wed, 01 Jul 2020 13:01:45 -0700 X-Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by mx.groups.io with SMTP id smtpd.web10.5814.1593633687761712969 for ; Wed, 01 Jul 2020 13:01:28 -0700 X-Received: by mail-wm1-f68.google.com with SMTP id w3so12330687wmi.4 for ; Wed, 01 Jul 2020 13:01:27 -0700 (PDT) X-Gm-Message-State: aXeQmKhQcOePnz96BjvHc8zVx1787277AA= X-Google-Smtp-Source: ABdhPJya/g955SzOh/fSFTcWUTN1u4XSwXOAJeJFxjOM8kcxGqpRutkuKCFR313yXi513Nj8c197vg== X-Received: by 2002:a7b:c348:: with SMTP id l8mr30463530wmj.54.1593633685839; Wed, 01 Jul 2020 13:01:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 13:01:25 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Ard Biesheuvel , macarl@microsoft.com Subject: [edk2-devel] [RFC 5/5] EmbeddedPkg/PrePiLib: break section extraction info into helper function Date: Wed, 1 Jul 2020 21:01:18 +0100 Message-Id: <20200701200118.3972-6-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=1593633705; bh=qgZFpUd3jhtysKjFyChnF89CJlzmGZ3kiCnJYyYiUuA=; h=Cc:Date:From:Reply-To:Subject:To; b=enTTmvGmQI01yNYvxZ5aMioRjPJAJ5CyGMs9PywK6tTdsEzxWAPzd2NDSORjYbhJ+fJ CM3HHneWLd8fgmpHkPvUHXuyeXadV6PQRmd2J4rGxMAYoWv1W44gvz8re4VA3h2s+nXS8 35sGelvIM0XXEl1AgkHUXrc27RI1fARmks4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Create a new helper function FfsGetExtractionInfo, which handles figuring out the buffer sizes needed for extracting UefiCompressed or GuidedSection sections, and also hides away some of the differences between the two, getting rid of a bunch of local variables. Signed-off-by: Leif Lindholm --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 90 +++++++++++++++++----------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/Pre= PiLib/FwVol.c index 083bc27efead..d0f91efa77a1 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -318,6 +318,50 @@ FfsCompressionSectionHeaderSize ( return sizeof (EFI_COMPRESSION_SECTION); } =20 +STATIC +EFI_STATUS +FfsGetExtractionInfo ( + IN EFI_COMMON_SECTION_HEADER *Section, + OUT UINT32 *SectionLength, + IN OUT VOID **SrcBuffer, + OUT UINT32 *DstBufferSize, + OUT UINT32 *ScratchBufferSize + ) +{ + EFI_STATUS Status; + + if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { + *SectionLength =3D FfsSectionLength (Section); + + if (FfsSectionCompressionType (Section) !=3D EFI_STANDARD_COMPRESSION)= { + return EFI_UNSUPPORTED; + } + + *SrcBuffer =3D (VOID *)((UINTN)Section + FfsCompressionSectionHeaderSi= ze (Section)); + Status =3D UefiDecompressGetInfo ( + *SrcBuffer, + *SectionLength - FfsCompressionSectionHeaderSize (Section), + DstBufferSize, + ScratchBufferSize + ); + } else if (Section->Type =3D=3D EFI_SECTION_GUID_DEFINED) { + UINT16 Ignored; + + *SrcBuffer =3D Section; + + Status =3D ExtractGuidedSectionGetInfo ( + *SrcBuffer, + DstBufferSize, + ScratchBufferSize, + &Ignored // SectionAttribute not used by this library + ); + } else { + Status =3D EFI_UNSUPPORTED; + } + + return Status; +} + /** Go through the file to search SectionType section, when meeting an encapsuled section. @@ -344,15 +388,11 @@ FfsProcessSection ( VOID *ScratchBuffer; UINT32 ScratchBufferSize; VOID *DstBuffer; - UINT16 SectionAttribute; - UINT32 AuthenticationStatus; - CHAR8 *CompressedData; - UINTN CompressedDataLength; - + VOID *SrcBuffer; =20 *OutputBuffer =3D NULL; ParsedLength =3D 0; - Status =3D EFI_NOT_FOUND; + while (ParsedLength < SectionSize) { if (IS_SECTION2 (Section)) { ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF); @@ -364,32 +404,11 @@ FfsProcessSection ( return EFI_SUCCESS; } =20 + SectionLength =3D FfsSectionLength (Section); + if ((Section->Type =3D=3D EFI_SECTION_COMPRESSION) || (Section->Type = =3D=3D EFI_SECTION_GUID_DEFINED)) { - if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { - SectionLength =3D FfsSectionLength (Section); - - if (FfsSectionCompressionType (Section) !=3D EFI_STANDARD_COMPRESS= ION) { - return EFI_UNSUPPORTED; - } - - CompressedData =3D (VOID *)((UINTN)Section + FfsCompressionSection= HeaderSize (Section)); - CompressedDataLength =3D SectionLength - FfsCompressionSectionHead= erSize (Section); - - Status =3D UefiDecompressGetInfo ( - CompressedData, - CompressedDataLength, - &DstBufferSize, - &ScratchBufferSize - ); - } else if (Section->Type =3D=3D EFI_SECTION_GUID_DEFINED) { - Status =3D ExtractGuidedSectionGetInfo ( - Section, - &DstBufferSize, - &ScratchBufferSize, - &SectionAttribute - ); - } - + Status =3D FfsGetExtractionInfo (Section, &SectionLength, &SrcBuffer, + &DstBufferSize, &ScratchBufferSize); if (EFI_ERROR (Status)) { // // GetInfo failed @@ -421,16 +440,18 @@ FfsProcessSection ( // if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { Status =3D UefiDecompress ( - CompressedData, + SrcBuffer, DstBuffer, ScratchBuffer ); } else if (Section->Type =3D=3D EFI_SECTION_GUID_DEFINED) { + UINT32 Ignored; + Status =3D ExtractGuidedSectionDecode ( - Section, + SrcBuffer, &DstBuffer, ScratchBuffer, - &AuthenticationStatus + &Ignored // AuthenticationStatus not used by this libr= ary ); } =20 @@ -450,7 +471,6 @@ FfsProcessSection ( } } =20 - 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 (#61928): https://edk2.groups.io/g/devel/message/61928 Mute This Topic: https://groups.io/mt/75244275/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-