From nobody Wed May 8 01:30:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84574+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84574+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1639032702; cv=none; d=zohomail.com; s=zohoarc; b=nA92dhnpqYQuJYCe7gg3mui2uxC5d/CG7mZDnVWPnLPlQ27oDuP/vWnY2ezn9hzMzpr6YtDPLi+bam6TVnRb78utMWxZzI+SZyWkVu3XE+VMhAAUm3WO/aNzgzCiF/MDtF0mxR2vaAisYe1454DKzWxC+U3dIfixTCtTQLXDH9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639032702; h=Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=EnplEPThM4jK071ZrkD0cginc3qVT98gyLiTdpOw0+k=; b=jFPd9zGJO5Fy3Zf9mfx9sGgjUw9JVnh7n1Lqa/ZccVyiWK0jvPkP307lf45hj/5+W7BSla8Nb+K++oH6m5XGEV6bykUrmSU66KCHPZcAS0bSv/lmgIxq+miaDWXBiQGdGXzqcxcDJTwM+8mth3nA8IxnNFzQ3wm4t5rZ/XV+ao8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84574+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639032702367430.99341667292913; Wed, 8 Dec 2021 22:51:42 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id T0uPYY1788612xofknnWAA48; Wed, 08 Dec 2021 22:51:41 -0800 X-Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web09.8461.1639032700548149997 for ; Wed, 08 Dec 2021 22:51:40 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10192"; a="235544317" X-IronPort-AV: E=Sophos;i="5.88,191,1635231600"; d="scan'208";a="235544317" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2021 22:51:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,191,1635231600"; d="scan'208";a="516165840" X-Received: from shwdeopenpsi174.ccr.corp.intel.com ([10.239.157.25]) by orsmga008.jf.intel.com with ESMTP; 08 Dec 2021 22:51:37 -0800 From: "Xu, Wei6" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar , Jiewen Yao , Supreeth Venkatesh , Liming Gao Subject: [edk2-devel][Patch] StandaloneMmPkg/FvLib: Support large file with EFI_FFS_FILE_HEADER2. Date: Thu, 9 Dec 2021 14:51:33 +0800 Message-Id: <20211209065133.7748-1-wei6.xu@intel.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,wei6.xu@intel.com X-Gm-Message-State: uaog7PYetMxZaLL168aqgr61x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639032701; bh=et6zRcTVdDoAtMylbRaWp9/S/YsHzPiZ9hs6VZb9Oao=; h=Cc:Date:From:Reply-To:Subject:To; b=hxEGP1GOuZynzZ7O/epybB3yej40DscFbDcsHm4/dxRDYR6xuKma9BfBegWWj/0WSKO 6HT8mPG174YViQyKl29B/T60gG9RLdqFaae2FjshrsCd7QkWgTRv+XGHCShubwkxsUmAd WAQ2lwpbfSjk9Ihct+BRBJpiLxTlnGi9BlE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639032703029100002 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3769 Current FvLib will hit parse issue when encountering LARGE file, then ignore latter ffs/section, thus causing required drivers not being dispatched. Therefore, need to add support for EFI_FFS_FILE_HEADER2 and EFI_COMMON_SECTION_HEADER2 in FvLib to fix this issue. Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Jiewen Yao Cc: Supreeth Venkatesh Cc: Liming Gao Signed-off-by: Wei6 Xu Reviewed-by: Liming Gao --- StandaloneMmPkg/Library/FvLib/FvLib.c | 65 ++++++++++++++++++++++++-------= ---- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/StandaloneMmPkg/Library/FvLib/FvLib.c b/StandaloneMmPkg/Librar= y/FvLib/FvLib.c index aa36a35eff..89504b9ee9 100644 --- a/StandaloneMmPkg/Library/FvLib/FvLib.c +++ b/StandaloneMmPkg/Library/FvLib/FvLib.c @@ -1,8 +1,8 @@ /** @file =20 -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -61,22 +61,24 @@ CalculateHeaderChecksum ( ) { UINT8 *ptr; UINTN Index; UINT8 Sum; + UINTN Size; =20 - Sum =3D 0; - ptr =3D (UINT8 *)FileHeader; + Sum =3D 0; + ptr =3D (UINT8 *)FileHeader; + Size =3D IS_FFS_FILE2 (FileHeader) ? sizeof (EFI_FFS_FILE_HEADER2) : siz= eof (EFI_FFS_FILE_HEADER); =20 - for (Index =3D 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index +=3D 4= ) { + for (Index =3D 0; Index < Size - 3; Index +=3D 4) { Sum =3D (UINT8)(Sum + ptr[Index]); Sum =3D (UINT8)(Sum + ptr[Index + 1]); Sum =3D (UINT8)(Sum + ptr[Index + 2]); Sum =3D (UINT8)(Sum + ptr[Index + 3]); } =20 - for ( ; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) { + for ( ; Index < Size; Index++) { Sum =3D (UINT8)(Sum + ptr[Index]); } =20 // // State field (since this indicates the different state of file). @@ -155,11 +157,12 @@ FfsFindNextFile ( } else { // // Length is 24 bits wide so mask upper 8 bits // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned. // - FileLength =3D FFS_FILE_SIZE (*FileHeader); + FileLength =3D IS_FFS_FILE2 (*FileHeader) ? + FFS_FILE2_SIZE (*FileHeader) : FFS_FILE_SIZE (*FileHeader= ); FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + Fi= leOccupiedSize); } =20 FileOffset =3D (UINT32)((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader); @@ -170,18 +173,25 @@ FfsFindNextFile ( // FileState =3D GetFileState (ErasePolarity, FfsFileHeader); =20 switch (FileState) { case EFI_FILE_HEADER_INVALID: - FileOffset +=3D sizeof (EFI_FFS_FILE_HEADER); - FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader += sizeof (EFI_FFS_FILE_HEADER)); + if (IS_FFS_FILE2 (FfsFileHeader)) { + FileOffset +=3D sizeof (EFI_FFS_FILE_HEADER2); + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader= + sizeof (EFI_FFS_FILE_HEADER2)); + } else { + FileOffset +=3D sizeof (EFI_FFS_FILE_HEADER); + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader= + sizeof (EFI_FFS_FILE_HEADER)); + } + break; =20 case EFI_FILE_DATA_VALID: case EFI_FILE_MARKED_FOR_UPDATE: if (CalculateHeaderChecksum (FfsFileHeader) =3D=3D 0) { - FileLength =3D FFS_FILE_SIZE (FfsFileHeader); + FileLength =3D IS_FFS_FILE2 (FfsFileHeader) ? + FFS_FILE2_SIZE (FfsFileHeader) : FFS_FILE_SIZE (Ffs= FileHeader); FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); =20 if ((SearchType =3D=3D FfsFileHeader->Type) || (SearchType =3D= =3D EFI_FV_FILETYPE_ALL)) { *FileHeader =3D FfsFileHeader; =20 @@ -195,11 +205,12 @@ FfsFindNextFile ( } =20 break; =20 case EFI_FILE_DELETED: - FileLength =3D FFS_FILE_SIZE (FfsFileHeader); + FileLength =3D IS_FFS_FILE2 (FfsFileHeader) ? + FFS_FILE2_SIZE (FfsFileHeader) : FFS_FILE_SIZE (FfsFi= leHeader); FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); FileOffset +=3D FileOccupiedSize; FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeade= r + FileOccupiedSize); break; =20 @@ -251,11 +262,11 @@ FindFfsSectionInSections ( =20 CurrentAddress =3D EndOfSection; =20 Section =3D (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress; =20 - Size =3D SECTION_SIZE (Section); + Size =3D IS_SECTION2 (Section) ? SECTION2_SIZE (Section) : SECTION_SIZ= E (Section); if (Size < sizeof (*Section)) { return EFI_VOLUME_CORRUPTED; } =20 EndOfSection =3D CurrentAddress + Size; @@ -304,13 +315,17 @@ FfsFindSection ( // // Size is 24 bits wide so mask upper 8 bits. // Does not include FfsFileHeader header size // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. // - Section =3D (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); - FileSize =3D FFS_FILE_SIZE (FfsFileHeader); - FileSize -=3D sizeof (EFI_FFS_FILE_HEADER); + if (IS_FFS_FILE2 (FfsFileHeader)) { + Section =3D (EFI_COMMON_SECTION_HEADER *)((EFI_FFS_FILE_HEADER2 *)Ffs= FileHeader + 1); + FileSize =3D FFS_FILE2_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEA= DER2); + } else { + Section =3D (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); + FileSize =3D FFS_FILE_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEAD= ER); + } =20 Status =3D FindFfsSectionInSections ( Section, FileSize, SectionType, @@ -349,29 +364,39 @@ FfsFindSectionData ( // // Size is 24 bits wide so mask upper 8 bits. // Does not include FfsFileHeader header size // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. // - Section =3D (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); - FileSize =3D FFS_FILE_SIZE (FfsFileHeader); - FileSize -=3D sizeof (EFI_FFS_FILE_HEADER); + if (IS_FFS_FILE2 (FfsFileHeader)) { + Section =3D (EFI_COMMON_SECTION_HEADER *)((EFI_FFS_FILE_HEADER2 *)Ffs= FileHeader + 1); + FileSize =3D FFS_FILE2_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEA= DER2); + } else { + Section =3D (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); + FileSize =3D FFS_FILE_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEAD= ER); + } =20 *SectionData =3D NULL; ParsedLength =3D 0; while (ParsedLength < FileSize) { if (Section->Type =3D=3D SectionType) { - *SectionData =3D (VOID *)(Section + 1); - *SectionDataSize =3D SECTION_SIZE (Section); + if (IS_SECTION2 (Section)) { + *SectionData =3D (VOID *)((EFI_COMMON_SECTION_HEADER2 *)Sectio= n + 1); + *SectionDataSize =3D SECTION2_SIZE (Section); + } else { + *SectionData =3D (VOID *)(Section + 1); + *SectionDataSize =3D SECTION_SIZE (Section); + } + return EFI_SUCCESS; } =20 // // Size is 24 bits wide so mask upper 8 bits. // SectionLength is adjusted it is 4 byte aligned. // Go to the next section // - SectionLength =3D SECTION_SIZE (Section); + SectionLength =3D IS_SECTION2 (Section) ? SECTION2_SIZE (Section) : SE= CTION_SIZE (Section); SectionLength =3D GET_OCCUPIED_SIZE (SectionLength, 4); =20 ParsedLength +=3D SectionLength; Section =3D (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + Sec= tionLength); } --=20 2.16.2.windows.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 (#84574): https://edk2.groups.io/g/devel/message/84574 Mute This Topic: https://groups.io/mt/87607583/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-