From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web08.1603.1604394580256495160 for ; Tue, 03 Nov 2020 01:09:40 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=EtSu8nvL; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: bob.c.feng@intel.com) IronPort-SDR: NIpLqlr+JkbEcDbOtN9/lscgjcCLFR54KWdB9fH0ScdkecrJ7Nhsn0aqS1Jw2R4Iy3Gak72DgZ RPLOrn9o7dBw== X-IronPort-AV: E=McAfee;i="6000,8403,9793"; a="168239679" X-IronPort-AV: E=Sophos;i="5.77,447,1596524400"; d="scan'208";a="168239679" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 01:09:39 -0800 IronPort-SDR: tIxHGq/+VULmV6jdiMPGBcTwoXDvEOwXIZ7pcApBmviyzCXDnjVqq5sapuklbQZmHmmbjXB2YF lAqT0CsQI27Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,447,1596524400"; d="scan'208";a="320359955" Received: from fmsmsx606.amr.corp.intel.com ([10.18.126.86]) by orsmga003.jf.intel.com with ESMTP; 03 Nov 2020 01:09:38 -0800 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 3 Nov 2020 01:09:38 -0800 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 3 Nov 2020 01:09:38 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 3 Nov 2020 01:09:37 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.173) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Tue, 3 Nov 2020 01:09:37 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nToHI97ovYgzVxXB+azNLeCnCyUJk7jfHefad1crv6ATsYW1hXIpyMwEbX0Svx8qoeny6fDhj0LEVKhiU/APedykcsJWFkJDSroBFqC7CU1JA0ppqGdrlL11NhsT+c09n2oPe6MfLJDM33su4YCEbHeLHnC+U3a8cbiZ+C97bTU3+rlHR0267dmspHZezdtMdABl+4hpljRsOSR6ayrePupwZWTY0DK8z2tdqGgoU6ocDh1ucfMA/l8qT0HVWEWfdmI42on/tcBv7MsldZ3jiphuz3kJAQCyrAYi7PZe4+GVInP3YP416sOjb3nnONaGmwagdWdjuqVbrRA9HQA5MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tcjwA+1/O33LtCELnYKyoAOVam6UYK+TDReCAAvECYU=; b=aRY3vjIbJug9rKufB2T0PkEkhA227bChqEeXym130jOhVd8iBV7vavlEECCfw2Mof5eOLALUSD60R9HRCwx7gwfhTq9jAKdEVl3Yt/Gq6Cx+CGEsZlXD0a1+Wyc+4BCUmwkd4YydCTOMZDjbNanhUx0jlxd3sLGm/MblvS4Qz2Z8vvde6hAKPB5iJ6VlIXbtGWJeSbRZy5bCN63+PkMP3PFF3oCxD406cpgMsRexPSfVX7rQmU4cg3QIlwraSw4RcOX44ukEik6TKaHXrWpJs3GzYk9D7xACgViqFyy2yVtfxzYQrO4etHQwhc1M6Bk2HMh4f0xzwsrybvQufKRlBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tcjwA+1/O33LtCELnYKyoAOVam6UYK+TDReCAAvECYU=; b=EtSu8nvLNnHBXQnB4yJZKXVXRd3YfMg8TxAUfRSUHxbtd0H58SZocVh9w+xXr5GmOOXg1hupW5c3hRKCGXUIlhEaffmvWqckZTCmzFH/xhDGZYh72mYrryKI5FGuh2JTIBdM+5Ykm1fGL5945acGg3IjPBsfXsZwd3FUeRS5uh4= Received: from DM6PR11MB4073.namprd11.prod.outlook.com (2603:10b6:5:19f::22) by DM5PR11MB1578.namprd11.prod.outlook.com (2603:10b6:4:e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Tue, 3 Nov 2020 09:09:36 +0000 Received: from DM6PR11MB4073.namprd11.prod.outlook.com ([fe80::cd42:ed68:e66a:1eaa]) by DM6PR11MB4073.namprd11.prod.outlook.com ([fe80::cd42:ed68:e66a:1eaa%7]) with mapi id 15.20.3499.032; Tue, 3 Nov 2020 09:09:36 +0000 From: "Bob Feng" To: "Yeh, GregX" , "devel@edk2.groups.io" CC: Liming Gao Subject: Re: [PATCH] BaseTools/FMMT: Replace file failure when FV level over 2 Thread-Topic: [PATCH] BaseTools/FMMT: Replace file failure when FV level over 2 Thread-Index: AQHWsaTV7DshF1jLrUWutdeVEFzn06m2HWig Date: Tue, 3 Nov 2020 09:09:35 +0000 Message-ID: References: <20201103054711.22836-1-gregx.yeh@intel.com> In-Reply-To: <20201103054711.22836-1-gregx.yeh@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.55.46.46] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6fe1dcfc-da36-4e04-2c7a-08d87fd82f99 x-ms-traffictypediagnostic: DM5PR11MB1578: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: NsTSqI1h+ZTblZX2c/2r0EDMQv0DPSvXha7aTREypiZ83vkrKMsmhhJE3Zyjy4fEwH9sGGLxoLsK3z+Kkb5eNE/OlUc4fLSa5JeakO7sTBMnPdy+Hf/hmWConqTNtmy7wf2e3Pvg1L0uFQgj+DfcspKMDCUIWlsCCpawN/aN3pw7rMe6mVwXqDmi1+ZVvS6Lh7lWMkUJJAnwogDLmY49Prr02N+P5ErkMYOhLdDwC2FDm3D9fIlVS1tGXc5pRfhuxzotrrjGDjLPmRGISd3vGb/68OoPDJ/gN2pSa1Sc0x1xHSM9F3T2X2cM6/ucNmcjrvFILowoKKCQzBIvHr1Vog== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4073.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(366004)(396003)(136003)(346002)(26005)(8676002)(33656002)(55016002)(2906002)(30864003)(8936002)(9686003)(83380400001)(110136005)(7696005)(53546011)(86362001)(186003)(6506007)(478600001)(71200400001)(5660300002)(66446008)(66476007)(64756008)(76116006)(316002)(52536014)(66946007)(66556008)(4326008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: mZ2eqRbEeHnJW54mgdN9gEVLocEpwZklsLIWsOo/yvmFJD4CDnVUxuFGySiKq7Xg68UICzkDVeGM+M4PjdFI1lx+02+gIWBXW21eVI/jQwJJqNCpIY7rvIL2xZkpn7lN4JuOdyqcQbHf+Ufi/M/Ao4CuXO+UL9nbi1G0Zakldj+gJGbbxomRfJ+R/HzCm9f5S74kjVCdGeJ52Li6wjPGZiP5RpApOVDp/uF08XFOVrOUstc1rJG9yvIR4Taiuowqj7uWaBbJdBHh3w04JBw6ApSAjAgmbqzmt+jTh+g2IjC6KVMIErl7o6HAYYw2CFCXKwKS9ZquuoatgIQWky3qyUBzryWcx83jrwvRCfy97k3AsEfHop33vAUmcMq3Zaw4wOMRZd5UerYQDztp0zX2BgfTKE7VwlWY87q/9itM2MMH/q39kDCfN5qx/y418Wqk6hC7VY40GmP80Hmm3QlDTcdl4/p1uWJU7J2LYYDEpHQn+RHtztoiOPID6HBblbOPy6KV2Lle8wi89XuNuUB0subtAozDGSSY7zM36NcBhYFKoxX3MgSTq/yxBaR9PQ6vClSltqralsobJWXyhOkz0oVUl+910mni87Fkx329BAeTMOlWAVtXkcvCbG+Hx2jQGT6yk4XmPzBWNRfzr/0JSA== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4073.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6fe1dcfc-da36-4e04-2c7a-08d87fd82f99 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Nov 2020 09:09:36.0066 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 5kGmwVjQAB3i6ZwPtD2Yl2rCe38ftK3ZA3tI5NaE/NXuktv1aLPEFGB9OtSD29l9wDNYkrOnuK7mmArwUY5adw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1578 Return-Path: bob.c.feng@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Greg, Could you provide more details about problems that this patch fix? It would= be great if you can share the test case. FMMT tool is in the edk2-staging repo, so the patch title for FMMT should a= dd [edk2-staging] tag. Thanks, Bob -----Original Message----- From: Yeh, GregX =20 Sent: Tuesday, November 3, 2020 1:47 PM To: devel@edk2.groups.io Cc: Feng, Bob C ; Liming Gao Subject: [PATCH] BaseTools/FMMT: Replace file failure when FV level over 2 Fixed replace file failure when FFS in multi level FV and FV level over 2. Signed-off-by: GregX Yeh Cc: Bob Feng Cc: Liming Gao --- BaseTools/Source/C/FMMT/FirmwareModuleManagement.c | 2 +- BaseTools/Source/C/FMMT/FirmwareModuleManagement.h | 3 +- BaseTools/Source/C/FMMT/FmmtLib.c | 171 ++++++++++++++---= ---- 3 files changed, 118 insertions(+), 58 deletions(-) diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c b/BaseTools= /Source/C/FMMT/FirmwareModuleManagement.c index 38056153fb..dfad02838b 100644 --- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c +++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c @@ -615,7 +615,7 @@ static UINT32 FindFile(FV_INFORMATION *FvInFd, UINT8 Fv= Level, CHAR8 *File, UINT3 return 0; } LibAscii2Unicode(File, UIName); - for (Index =3D 0; Index <=3D FvInFd->FfsNumbers; Index++) { + for (Index =3D 0; Index < FvInFd->FfsNumbers; Index++) { // // Compare the New File Name with UI Name of FFS // NOTE: The UI Name is Unicode, but the New File Name is Ascii. diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h b/BaseTools= /Source/C/FMMT/FirmwareModuleManagement.h index 9d09c9160a..da9eb1a4b9 100644 --- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h +++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h @@ -2,7 +2,7 @@ =20 Structures and functions declaration. =20 - Copyright (c) 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -284,6 +284,7 @@ typedef struct _FFS_INFOMATION{ UINT8 *Depex; UINT32 DepexLen; BOOLEAN FfsFoundFlag; + UINT8 FvLevel; struct _FFS_INFOMATION *Next; } FFS_INFORMATION; =20 diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/Fm= mtLib.c index b945e9b63d..9bccd634bb 100644 --- a/BaseTools/Source/C/FMMT/FmmtLib.c +++ b/BaseTools/Source/C/FMMT/FmmtLib.c @@ -523,7 +523,7 @@ LibReadFvHeader ( FvExtHeader->FvName.Data4[6], FvExtHeader->FvName.Data4[7]); LibExtractFvUiName(FvExtHeader, &FvUiName); - if (FvUiName !=3D NULL && FvLevel =3D=3D 1) { + if (FvUiName !=3D NULL && (FvLevel - 1) !=3D 0) { printf("%sFV UI Name: %s\n\n", BlankSpace, FvUiName); } free(FvUiName); @@ -709,10 +709,10 @@ LibGenFfsFile ( free(FfsFileName); FfsFileName =3D NULL; =20 - CurrentFv->FfsNumbers =3D *FfsCount; - *FfsCount +=3D 1; =20 + CurrentFv->FfsNumbers =3D *FfsCount; + if (ErasePolarity) { CurrentFile->State =3D (UINT8)~(CurrentFile->State); } @@ -789,7 +789,8 @@ LibParseSection ( UINT8 *FvCount, BOOLEAN ViewFlag, BOOLEAN ErasePolarity, - BOOLEAN *IsFfsGenerated + BOOLEAN *IsFfsGenerated, + UINT32 *FfsIndex ) { UINT32 ParsedLength; @@ -1147,19 +1148,21 @@ LibParseSection ( return EFI_SECTION_ERROR; } =20 - Status =3D LibParseSection ( UncompressedBuffer, - UncompressedLength, - CurrentFv, - FvName, - CurrentFile, - Level, - &LocalEncapData, - FfsLevel, - FfsCount, - FvCount, - ViewFlag, - ErasePolarity, - IsFfsGenerated); + Status =3D LibParseSection (UncompressedBuffer, + UncompressedLength, + CurrentFv, + FvName, + CurrentFile, + Level, + &LocalEncapData, + FfsLevel, + FfsCount, + FvCount, + ViewFlag, + ErasePolarity, + IsFfsGenerated, + FfsIndex + ); =20 if (CompressionType =3D=3D EFI_STANDARD_COMPRESSION) { // @@ -1216,7 +1219,8 @@ LibParseSection ( FvCount, ViewFlag, ErasePolarity, - IsFfsGenerated + IsFfsGenerated, + FfsIndex ); if (EFI_ERROR(Status)) { Error(NULL, 0, 0003, "parse of decoded GUIDED section failed", N= ULL); @@ -1471,7 +1475,8 @@ LibParseSection ( FvCount, ViewFlag, ErasePolarity, - IsFfsGenerated + IsFfsGenerated, + FfsIndex ); if (EFI_ERROR (Status)) { Error (NULL, 0, 0003, "parse of decoded GUIDED section failed", = NULL); @@ -1491,7 +1496,8 @@ LibParseSection ( FvCount, ViewFlag, ErasePolarity, - IsFfsGenerated + IsFfsGenerated, + FfsIndex ); if (ExtractionTool !=3D NULL) { free (ExtractionTool); @@ -1527,6 +1533,7 @@ LibParseSection ( if (!*IsFfsGenerated) { LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, E= rasePolarity); *IsFfsGenerated =3D TRUE; + *FfsIndex =3D *FfsCount; } } =20 @@ -1538,6 +1545,7 @@ LibParseSection ( if (!*IsFfsGenerated) { LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, E= rasePolarity); *IsFfsGenerated =3D TRUE; + *FfsIndex =3D *FfsCount; } } =20 @@ -1549,6 +1557,7 @@ LibParseSection ( if (!*IsFfsGenerated) { LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, E= rasePolarity); *IsFfsGenerated =3D TRUE; + *FfsIndex =3D *FfsCount; } } =20 @@ -1560,6 +1569,7 @@ LibParseSection ( if (!*IsFfsGenerated) { LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, E= rasePolarity); *IsFfsGenerated =3D TRUE; + *FfsIndex =3D *FfsCount; } } break; @@ -1571,6 +1581,7 @@ LibParseSection ( if (!*IsFfsGenerated) { LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, E= rasePolarity); *IsFfsGenerated =3D TRUE; + *FfsIndex =3D *FfsCount; } } break; @@ -1582,6 +1593,7 @@ LibParseSection ( if (!*IsFfsGenerated) { LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, E= rasePolarity); *IsFfsGenerated =3D TRUE; + *FfsIndex =3D *FfsCount; } } break; @@ -1665,11 +1677,11 @@ LibParseSection ( // If Ffs file has been generated, then the FfsCount should decrease= 1. // if (*IsFfsGenerated) { - memcpy (CurrentFv->FfsAttuibutes[*FfsCount -1].UiName, UIName, UIN= ameSize); - CurrentFv->FfsAttuibutes[*FfsCount -1].UiNameSize =3D UINameSize; + memcpy (CurrentFv->FfsAttuibutes[*FfsIndex - 1].UiName, UIName, UI= NameSize); + CurrentFv->FfsAttuibutes[*FfsIndex - 1].UiNameSize =3D=20 + UINameSize; } else { - memcpy (CurrentFv->FfsAttuibutes[*FfsCount].UiName, UIName, UIName= Size); - CurrentFv->FfsAttuibutes[*FfsCount].UiNameSize =3D UINameSize; + memcpy (CurrentFv->FfsAttuibutes[*FfsIndex].UiName, UIName, UIName= Size); + CurrentFv->FfsAttuibutes[*FfsIndex].UiNameSize =3D UINameSize; } =20 HasDepexSection =3D FALSE; @@ -1682,7 +1694,9 @@ LibParseSection ( } =20 ParsedLength +=3D SectionLength; - FirstInFlag =3D FALSE; + if (Type !=3D EFI_SECTION_PEI_DEPEX && Type !=3D EFI_SECTION_DXE_DEPEX= ) { + FirstInFlag =3D FALSE; + } // // We make then next section begin on a 4-byte boundary // @@ -1872,12 +1886,14 @@ LibGetFileInfo ( BOOLEAN IsGeneratedFfs; UINT32 FfsFileHeaderSize; CHAR8 *BlankChar; + UINT32 FfsIndex; =20 Status =3D EFI_SUCCESS; =20 LocalEncapData =3D NULL; EncapDataNeedUpdateFlag =3D TRUE; IsGeneratedFfs =3D FALSE; + FfsIndex =3D 0xFFFFFFFF; BlankChar =3D NULL; =20 FfsFileHeaderSize =3D GetFfsHeaderLength ((EFI_FFS_FILE_HEADER *) Curre= ntFile); @@ -2083,24 +2099,25 @@ LibGetFileInfo ( } else if( CurrentFile->Type =3D=3D EFI_FV_FILETYPE_FFS_PAD){ //EFI_FV_FILETYPE_FFS_PAD } else { - // - // All other files have sections - // - Status =3D LibParseSection ( - (UINT8 *) ((UINTN) CurrentFile + FfsFileHeaderSize), - FileLength - FfsFileHeaderSize, - CurrentFv, - FvName, - CurrentFile, - Level, - &LocalEncapData, - Level, - FfsCount, - FvCount, - ViewFlag, - ErasePolarity, - &IsGeneratedFfs - ); + // + // All other files have sections + // + Status =3D LibParseSection ( + (UINT8 *) ((UINTN) CurrentFile + FfsFileHeaderSize), + FileLength - FfsFileHeaderSize, + CurrentFv, + FvName, + CurrentFile, + Level, + &LocalEncapData, + Level, + FfsCount, + FvCount, + ViewFlag, + ErasePolarity, + &IsGeneratedFfs, + &FfsIndex + ); } if (EFI_ERROR (Status)) { printf ("ERROR: Parsing the FFS file.\n"); @@ -2144,6 +2161,7 @@ Lib= GetFvInfo ( EFI_FIRMWARE_VOLUME_EXT_HEADER *ExtHdrPtr; EFI_FIRMWARE_VOLUME_HEADER *FvHdr; UINT8 PreFvId; + UINT8 GuidBuffer[PRINTED_GUID_BUFFER_SIZE]; =20 NumberOfFiles =3D 0; Key =3D 0; @@ -2344,9 +2362,10 @@ LibGetFvInfo ( =20 CurrentFv->FfsAttuibutes[*FfsCount].FvLevel =3D CurrentFv->FvLevel; CurrentFv->FfsAttuibutes[*FfsCount].FvId =3D PreFvId; - if (CurrentFv->FvLevel > CurrentFv->MulFvLevel) { + if (CurrentFv->FvLevel > CurrentFv->MulFvLevel) { CurrentFv->MulFvLevel =3D CurrentFv->FvLevel; - } + } + PrintGuidToBuffer (&(CurrentFile->Name), GuidBuffer,=20 + PRINTED_GUID_BUFFER_SIZE, FALSE); // // Display info about this file // @@ -4198,10 +4217,13 @@ LibEncapNewFvFile( UINT32 header; UINT8 AlignN; UINT8 AlignV[1] =3D {0xFF}; + UINT32 EntryFvId; + AlignN =3D 0; Id =3D 0; InputFileSize =3D 0; TmpFileSize =3D 0; + AlignmentFileSize =3D 0; EncapFvIndex =3D 0; Index =3D 0; OuterIndex =3D 0; @@ -4224,7 +4246,7 @@ LibEncapNewFvFile( IsLargeFile =3D FALSE; OutputFileSize =3D 0; LargeFileSize =3D 0x1000000; - + EntryFvId =3D 0; =20 OutputFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION)= ); if (OutputFileNameList =3D=3D NULL) { @@ -4240,6 +4262,7 @@ LibEncapNewFvFile( OutputFileNameList->Depex =3D NULL; OutputFileNameList->DepexLen =3D 0; OutputFileNameList->FfsFoundFlag =3D FALSE; + OutputFileNameList->FvLevel =3D 0; =20 ChildFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION))= ; if (ChildFileNameList =3D=3D NULL) { @@ -4258,12 +4281,16 @@ LibEncapNewFvFile( // // Encapsulate from the lowest FFS file level. // - LocalEncapData =3D CurrentEncapData; - if (LocalEncapData =3D=3D NULL) { - LocalEncapData =3D FvInFd->EncapData; - } - Level =3D LocalEncapData->Level; - Type =3D LocalEncapData->Type; + LocalEncapData =3D CurrentEncapData; + if (LocalEncapData =3D=3D NULL) { + LocalEncapData =3D FvInFd->EncapData; + EntryFvId =3D 0xFFFFFFFF; + } else { + EntryFvId =3D LocalEncapData->FvId; + } + + Level =3D LocalEncapData->Level; + Type =3D LocalEncapData->Type; =20 if (CurrentEncapData =3D=3D NULL) { LocalEncapData =3D FvInFd->EncapData; @@ -4278,6 +4305,7 @@ LibEncapNe= wFvFile( ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Lev= el -1; if (FvInFd->ChildFvFFS =3D=3D NULL) { FvInFd->ChildFvFFS =3D ChildFileNameList; + NewFileNameList =3D FvInFd->ChildFvFFS; } else { NewFileNameList =3D FvInFd->ChildFvFFS; while (NewFileNameList->Next !=3D NULL) { @@ -4325,6 += 4353,12 @@ LibEncapNewFvFile( Type =3D LocalEncapData->Type; } LocalEncapData =3D LocalEncapData->NextNode; + if (LocalEncapData =3D=3D NULL) { + if (Type =3D=3D FMMT_ENCAP_TREE_FV) { + ParentLevel =3D Level; + ParentType =3D Type; + } + } } } else { LocalEncapData =3D CurrentEncapData; @@ -4349,6 +4383,28 @@ LibEncapNewFvFile( LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; } } + + if (LocalEncapData->FvId > EntryFvId && LocalEncapData->Type =3D=3D = FMMT_ENCAP_TREE_FFS) { + LocalEncapDataTemp =3D LocalEncapData->RightNode; + + while (LocalEncapDataTemp !=3D NULL) { + LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; + if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNode= !=3D NULL) { + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEnc= apDataTemp->Level - 1, &ChildFileNameList); + if (FvInFd->ChildFvFFS =3D=3D NULL) { + FvInFd->ChildFvFFS =3D ChildFileNameList; + } else { + NewFileNameList =3D FvInFd->ChildFvFFS; + while (NewFileNameList->Next !=3D NULL) { + NewFileNameList =3D NewFileNameList->Next; + } + NewFileNameList->Next =3D ChildFileNameList; + } + } + LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; + } + } + if (LocalEncapData->Level > Level) { if (LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_FFS) { ParentLevel =3D Level; @@ -4485,12 +4541,12 @@ LibEncapNewFvFile( // FfsFoundFlag =3D FALSE; IsRootFv =3D FALSE; - for (Index=3D0; Index <=3D FvInFd->FfsNumbers; Index++) { + for (Index=3D0; Index < FvInFd->FfsNumbers; Index++) { if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSNam= e !=3D NULL && OutputFileNameList->IsFFS =3D=3D FALSE){ break; } if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSNam= e !=3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE){ - if (Index =3D=3D EncapFvIndex) { + if (Index =3D=3D EncapFvStart) { if (FirstInFlag) { Status =3D LibAddFfsFileToFvInf (OutputFileNam= eList->FFSName, InfFile, TRUE); FirstInFlag =3D FALSE; @@ -4601,7 +4657,7 @@ L= ibEncapNewFvFile( } } // The Fv may has multiple level (> 2), when it is in the FvLevel = =3D=3D 2, we set the IsLastLevelFfs Flag - if (Index <=3DFvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].Fv= Level <=3D FvInFd->MulFvLevel) { + if (Index < FvInFd->FfsNumbers &&=20 + FvInFd->FfsAttuibutes[Index].FvLevel <=3D FvInFd->MulFvLevel) { if (FvInFd->FfsAttuibutes[Index].FvLevel =3D=3D 2) { IsLastLevelFfs =3D FALSE; } @@ -4777,6 +4833,7 @@ LibEncapNewFvFile( for (Id =3D FvInFd->FfsNumbers; Id <=3D FvInFd->FfsNumbers; Id--)= { if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(LocalEncap= Data->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) !=3D -1)= { + OutputFileNameList->FvLevel =3D=20 + FvInFd->FfsAttuibutes[Id].FvLevel; Status =3D LibFmmtDeleteFile(FvInFd->FfsAttuibutes[Id= ].FfsName); if (EFI_ERROR(Status)) { Error("FMMT", 0, 0004, "error while encapsulate F= D Image", "Delete the specified file failed!"); @@ -5079,7 +5136,9 @@ LibEn= capNewFvFile( } else { if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSName != =3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE) { *OutputFile =3D OutputFileNameList; - return EFI_SUCCESS; + if (OutputFileNameList->FvLevel < 2) { + return EFI_SUCCESS; + } } LocalEncapData =3D CurrentEncapData; } -- 2.16.2.windows.1