From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=wNhR9ftr; spf=pass (domain: nuviainc.com, ip: 209.85.128.68, mailfrom: leif@nuviainc.com) Received: by mail-wm1-f68.google.com with SMTP id w3so12330687wmi.4 for ; Wed, 01 Jul 2020 13:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jh0k+DhneNSrwUIb9Z3ydAKtItiuQVgDS9br2NsuQqo=; b=wNhR9ftranMFPl0DuziRiq6bF35av9sdpS4SGiDPm9pTWa9/IomVk6IJ0wydx25XBe BbIY/prvN2sdGzuPWhCDXuqIQChnMK5OFG4bWc4SaSzNZCLyzalmv2PygWB3C/md8Abe bg6UVt4VLR4p2fQ8JfrVcpgMuATqlIZck17qkmqu4Rjm7G7ZkR62uCULdEfTgkgcicos jcQKDT++emucBs8g8LEp3x9WqBRK56kzWGKV3+P485wMzgqv2tAVh+Ir+96SD94wV+Iu a1w/HrvMdZZk6zpr6PGml3EdXPzaA8JGK9uVruzrVRxu0aYW+f0GdoEp/Y0+Yus111Cn NczQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jh0k+DhneNSrwUIb9Z3ydAKtItiuQVgDS9br2NsuQqo=; b=gOtEPel0T0qoyq6YdUyiijs+0tz49IuSY/cGkOLttQt1ouZE8zO76+QrZ4iME38cGb YTtUW405+G6KE9XpISpMW002d0a8XrAeeUzTRmwfy8Y3Vy/LhOvjsRZi8LR6m6mic5Hf YehJDjyngBypw8mcI9+1RckWQYDoXgUfyHtgMc7rxBII8OWZQHApGe5HGTcJP8lC+wll jgw9dsCniJTDLTqvC3xKs6jXDazZTEWRLQrL3awKXNH48FzM9iazKqHKtzXFMUaOS70j ezW4IoAzF/N0VBmNycr9dOef6dXw/ezpY3yRUAQvQlkYRLMOCuJkr0oWcnZ4E9jP2MYm FaHQ== X-Gm-Message-State: AOAM5325+o6QQjq3IkPbsrua/rZrfp/llTMwDrMB1uADV3QC/PB5Xkvg B8zvPWY2K5XNRggZAsx/cKlYD1GNyFQ7kFCcx7X/srFMOt/QE/Gxg1muoiR5rzmyMF//TmxsPa6 O/cKrmsWfbkkMeb7eusKvh0KNywqVSu5sYN11ttVa2p34ZisQDEkBGcegbiKGBMYiZw== 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200701200118.3972-1-leif@nuviainc.com> References: <20200701200118.3972-1-leif@nuviainc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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/PrePiLib/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); } +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 == EFI_SECTION_COMPRESSION) { + *SectionLength = FfsSectionLength (Section); + + if (FfsSectionCompressionType (Section) != EFI_STANDARD_COMPRESSION) { + return EFI_UNSUPPORTED; + } + + *SrcBuffer = (VOID *)((UINTN)Section + FfsCompressionSectionHeaderSize (Section)); + Status = UefiDecompressGetInfo ( + *SrcBuffer, + *SectionLength - FfsCompressionSectionHeaderSize (Section), + DstBufferSize, + ScratchBufferSize + ); + } else if (Section->Type == EFI_SECTION_GUID_DEFINED) { + UINT16 Ignored; + + *SrcBuffer = Section; + + Status = ExtractGuidedSectionGetInfo ( + *SrcBuffer, + DstBufferSize, + ScratchBufferSize, + &Ignored // SectionAttribute not used by this library + ); + } else { + Status = 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; *OutputBuffer = NULL; ParsedLength = 0; - Status = EFI_NOT_FOUND; + while (ParsedLength < SectionSize) { if (IS_SECTION2 (Section)) { ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF); @@ -364,32 +404,11 @@ FfsProcessSection ( return EFI_SUCCESS; } + SectionLength = FfsSectionLength (Section); + if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) { - if (Section->Type == EFI_SECTION_COMPRESSION) { - SectionLength = FfsSectionLength (Section); - - if (FfsSectionCompressionType (Section) != EFI_STANDARD_COMPRESSION) { - return EFI_UNSUPPORTED; - } - - CompressedData = (VOID *)((UINTN)Section + FfsCompressionSectionHeaderSize (Section)); - CompressedDataLength = SectionLength - FfsCompressionSectionHeaderSize (Section); - - Status = UefiDecompressGetInfo ( - CompressedData, - CompressedDataLength, - &DstBufferSize, - &ScratchBufferSize - ); - } else if (Section->Type == EFI_SECTION_GUID_DEFINED) { - Status = ExtractGuidedSectionGetInfo ( - Section, - &DstBufferSize, - &ScratchBufferSize, - &SectionAttribute - ); - } - + Status = FfsGetExtractionInfo (Section, &SectionLength, &SrcBuffer, + &DstBufferSize, &ScratchBufferSize); if (EFI_ERROR (Status)) { // // GetInfo failed @@ -421,16 +440,18 @@ FfsProcessSection ( // if (Section->Type == EFI_SECTION_COMPRESSION) { Status = UefiDecompress ( - CompressedData, + SrcBuffer, DstBuffer, ScratchBuffer ); } else if (Section->Type == EFI_SECTION_GUID_DEFINED) { + UINT32 Ignored; + Status = ExtractGuidedSectionDecode ( - Section, + SrcBuffer, &DstBuffer, ScratchBuffer, - &AuthenticationStatus + &Ignored // AuthenticationStatus not used by this library ); } @@ -450,7 +471,6 @@ FfsProcessSection ( } } - SectionLength = FfsSectionLength (Section); // // SectionLength is adjusted it is 4 byte aligned. // Go to the next section -- 2.20.1