From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web08.13559.1606442937321979664 for ; Thu, 26 Nov 2020 18:08:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=iK42ydDb; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: bob.c.feng@intel.com) IronPort-SDR: K5QwHqhCcu5YjP+HTtA1jSRzREt0kAVilNTMkWSQfdmxB9Gw++Q0XuLw11b/1qKQaV+Wr+chJ6 KTHOIZa60H/A== X-IronPort-AV: E=McAfee;i="6000,8403,9817"; a="172438902" X-IronPort-AV: E=Sophos;i="5.78,373,1599548400"; d="scan'208";a="172438902" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2020 18:08:56 -0800 IronPort-SDR: 3ATg/6Hqdz5AurQGoJGZd1P3eL8B0m0pUB8tUxT4IiWqqO7wS2f1MjsYH6tZYk0iLmUnomwjlM Gm7wWyO7ZQzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,373,1599548400"; d="scan'208";a="359667640" Received: from orsmsx604.amr.corp.intel.com ([10.22.229.17]) by orsmga008.jf.intel.com with ESMTP; 26 Nov 2020 18:08:56 -0800 Received: from orsmsx605.amr.corp.intel.com (10.22.229.18) by ORSMSX604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 26 Nov 2020 18:08:55 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Thu, 26 Nov 2020 18:08:55 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.105) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Thu, 26 Nov 2020 18:08:53 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jrjFwFp44ZLaGCt/wVyqEpOILmU+aI4fjYUARlBDNkWOZYmc2iWyNmScuHTROGeVmscFoTHYaCJQ9IU6/kQPDnLuZlspiT+s+tZTiDA1vXTnFdsXlCDSBD8TxMrgtv2dGgMMTFrnyXw8yfZO/TTzHCWYlHkv1xzX+Fxu3u+lSWKnjSYzxICV1Kyfm3tLRGf/Fi0vU+BR/vZ5IvWHpBaaXihlWD2tGL2hs6g0K+d8JQFwwLJ/uc4nEgNtNddGh9WxJlz72hFHhq8idmXGWWvK/6ym1GZ/MNNUaP60KqpdXIRb9FSvX5O8bc9dz2c1F7yZVfLryyrmKL5xRCBfDsjL4A== 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=s8sfQVv1S1GtRe/xUfPe0/wUOvA59bF4MhcBDc296r8=; b=TPPfp1mT/X9RPyE1QgHiwscJB9HdfhX4WpdcQUxU/16ELkqWz+SbBPpCGTsIzsb2VUaFD/w5JFgVhMUtiwTgKHr0B0kxvCCP0LNmy8zRz8wvXFt/XYz04GSn2UOloOcuh+FCo56+37n8kiqXKu4cePJn7qXMUv+9iXPA3yEG8SPzOthJHfb1cuoOswT7HfeUQy4UboLEUdKGwYmmJEN4Ot58BygTcNtg8C/2sAmDTNZB2JRyU9YFcU023mnZK9PO3RLL8QTO9bbts8nY6k3VKoOmQahGuYUT/2BoGGdPmj5oymjckQ4l6kPVC6M0VqQKjYQ/nN3NPGyA53A9ROHyIA== 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=s8sfQVv1S1GtRe/xUfPe0/wUOvA59bF4MhcBDc296r8=; b=iK42ydDbMJeTUYP6TecwA2PNum/huoit399B4/GnMndLEPwxm3FXe2btWicklVTbJsu5DXb4akfngLVwHE1Y90YZhWJFREx3FYRTIzLKmkgzT6fM2ldF+z6FHbF/34zf6mmCzBym7O53mqX4U9hSR8rdWJV3uZBGFCFiJqRDiV8= Received: from DM6PR11MB4073.namprd11.prod.outlook.com (2603:10b6:5:19f::22) by DM6PR11MB2539.namprd11.prod.outlook.com (2603:10b6:5:bf::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.28; Fri, 27 Nov 2020 02:08:51 +0000 Received: from DM6PR11MB4073.namprd11.prod.outlook.com ([fe80::c9f:47ea:6321:5ccb]) by DM6PR11MB4073.namprd11.prod.outlook.com ([fe80::c9f:47ea:6321:5ccb%3]) with mapi id 15.20.3589.030; Fri, 27 Nov 2020 02:08:51 +0000 From: "Bob Feng" To: "Yeh, GregX" , "devel@edk2.groups.io" CC: Liming Gao Subject: Re: [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when FV level over 2 Thread-Topic: [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when FV level over 2 Thread-Index: AQHWxF4Cq8HuV+oZDUq1VGcYn1so3anbO3/g Date: Fri, 27 Nov 2020 02:08:51 +0000 Message-ID: References: <20201127013808.9496-1-gregx.yeh@intel.com> In-Reply-To: <20201127013808.9496-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.39] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 47145d8e-0f36-4b02-986d-08d8927962b2 x-ms-traffictypediagnostic: DM6PR11MB2539: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:628; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5gaWMLaYcr3itY6/NWMurJmD2P3nZ+0fHArPz7UxG4D8laTGzmMWhoMjgcyRFszn+eU64uuq6CAHkycKb6Yi1GbD24ZsD7xtbg3DTcFtAF5U3pE8/7TMSj0EoT52NV0a3+kwBUGlGQqIfxy2ZublgFiSEaxkGFYvzgGE6JlnrBzj9l//N9MNNdQUgNLtOeRsj2ffVerbTm12nBdufHrDbgkEWhkDnrO7g7HvgyLCjIrCDN615oXYR1DfDDa6bQsDPNzs9DP0LjiAXSoQnZp06s3d23ukwYIsC+7EdoDJu/B5/OKUOEAs8t00Pwr5OmiVgZix6ixWWj6XtBeFTZMHJQ== 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)(396003)(346002)(366004)(39860400002)(136003)(64756008)(8676002)(316002)(66446008)(66946007)(478600001)(186003)(52536014)(66556008)(4326008)(26005)(83380400001)(53546011)(6506007)(9686003)(71200400001)(33656002)(7696005)(5660300002)(66476007)(76116006)(110136005)(8936002)(55016002)(30864003)(86362001)(2906002)(559001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?an3FLf9OI5/re/hHu+ZnzRr4qtI2yeYoPvU3m4gfvLO5la/mG7HbxCLcu/mg?= =?us-ascii?Q?itVK+hMQhqrFAMDPJNBPf8TuZ3glzZbtEMvljn1gIsN/Pl5TOpfZvr9tEFgg?= =?us-ascii?Q?nAGPdzDRRy0a29wtcow42qmM5zUl/O/T/+CdddfEuSFNv6vQg2vZFMhpmfOM?= =?us-ascii?Q?z0rTU29Ns2nXMk4CYlDmv7KSlxmVMFaPMYrb+gWUbIH+En2lElFjIIMIw12i?= =?us-ascii?Q?43W0LeZdb1wEp9a9o2O3EFVJYPTuA5akXXBAxAsQk2PTRMQtXN7B7Kc+kbM+?= =?us-ascii?Q?8rGkjj0XVu2f0PMGE0U86CX1v5/IAdgxAISNSOg76ZXKeE9r+Yjk5gTsuztQ?= =?us-ascii?Q?qQ/TM+ZVHL/O45eDtQpuKVddbsLuuT6VIXsPAlq36aOkS9HOWaZM1ExehIJN?= =?us-ascii?Q?9EuL57wtnsJjmZogrpOIBHrpYsq39DMsmtfPtGQthxqmwfKAXrYlipXT0EJo?= =?us-ascii?Q?8tXpBin3lABg8OqgnNCTIY1wGAJfth6XamuS5XG1e+rwqZwiJDQA45eSuOG0?= =?us-ascii?Q?k85kMSl74/i9L/CbVBw9Pfxloqq1TqOxIK0mzxteZ5wdb9z0wzOh2gi64gG9?= =?us-ascii?Q?OzLattyQjwq1kzH0LwPToSmUIavFHpmf4hRP6X1LSmgNelg4cbpuHEqncdt3?= =?us-ascii?Q?Eg8rCNzfbZsMNi/3R8IHDAjbHIUvaE419hy8tdIe36vWnI3HRAkf5tIjXNgW?= =?us-ascii?Q?wuwMVfYvUdCl6KdGzOIwk93lYB0rg/mcz8AjBIDmsWohASK4xoLg5XR7AKMZ?= =?us-ascii?Q?NDBq/anL0Z1vSSJff4iups5dUOOsrfVwW80Fm/FFy3R45SH0r9gRMb7Ft+nw?= =?us-ascii?Q?6iIbNLouHa+vYm0y+s3o+z3AfDSckYi8Bld58yXoIIOnPRlLwjMyitqLueh0?= =?us-ascii?Q?GLf6uxCuVRT5a1XMhsq8Z1WU3yqqU1q1RnmDvWzBNbEQt7Eitdxt8hncAEAs?= =?us-ascii?Q?yNCDBgCEU+dqygRxUBgLioEjChkD3IzXK0fH11jMuIw=3D?= 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: 47145d8e-0f36-4b02-986d-08d8927962b2 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Nov 2020 02:08:51.6565 (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: W6ROytYFntU9qt9GKg/d/EMzZ1h2jREErn2UPyrJ3KZuPlpfgjnC3OIPfaeqbU4XvdmeGFOqNQ6HKleXACDJzA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB2539 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 Still have other patch... ...MMT-Replace-file-failure-when-FV-level-ov.patch | 456 ++++++++++++++ Thanks, Bob -----Original Message----- From: Yeh, GregX =20 Sent: Friday, November 27, 2020 9:38 AM To: devel@edk2.groups.io Cc: Feng, Bob C ; Liming Gao Subject: [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when F= V 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 --- ...MMT-Replace-file-failure-when-FV-level-ov.patch | 456 ++++++++++++++ BaseTools/Source/C/FMMT/FirmwareModuleManagement.h | 4 +- BaseTools/Source/C/FMMT/FmmtLib.c | 654 ++++++++++-------= ---- 3 files changed, 782 insertions(+), 332 deletions(-) create mode 100644 0001-BaseTools-FMMT-Replace-file-failure-when-FV-level-= ov.patch diff --git a/0001-BaseTools-FMMT-Replace-file-failure-when-FV-level-ov.patc= h b/0001-BaseTools-FMMT-Replace-file-failure-when-FV-level-ov.patch new file mode 100644 index 0000000000..e42770c9e4 --- /dev/null +++ b/0001-BaseTools-FMMT-Replace-file-failure-when-FV-level-ov.patch @@ -0,0 +1,456 @@ +From eba4dd0899b011b0ac89723876be66a9d3f39251 Mon Sep 17 00:00:00 2001 +From: GregX Yeh +Date: Tue, 3 Nov 2020 10:57:00 +0800 +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/BaseTool= s/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 F= vLevel, 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/BaseTool= s/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/F= mmtLib.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", = NULL); +@@ -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, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } +=20 +@@ -1538,6 +1545,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } +=20 +@@ -1549,6 +1557,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } +=20 +@@ -1560,6 +1569,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } + break; +@@ -1571,6 +1581,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } + break; +@@ -1582,6 +1593,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } + break; +@@ -1665,11 +1677,11 @@ LibParseSection ( + // If Ffs file has been generated, then the FfsCount should decreas= e 1. + // + if (*IsFfsGenerated) { +- memcpy (CurrentFv->FfsAttuibutes[*FfsCount -1].UiName, UIName, UI= NameSize); +- CurrentFv->FfsAttuibutes[*FfsCount -1].UiNameSize =3D UINameSize; ++ memcpy (CurrentFv->FfsAttuibutes[*FfsIndex - 1].UiName, UIName, U= INameSize); ++ CurrentFv->FfsAttuibutes[*FfsIndex - 1].UiNameSize =3D UINameSize= ; + } else { +- memcpy (CurrentFv->FfsAttuibutes[*FfsCount].UiName, UIName, UINam= eSize); +- CurrentFv->FfsAttuibutes[*FfsCount].UiNameSize =3D UINameSize; ++ memcpy (CurrentFv->FfsAttuibutes[*FfsIndex].UiName, UIName, UINam= eSize); ++ 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_DEPE= X) { ++ 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 *) Curr= entFile); +@@ -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 @@ LibGetFvInfo ( + 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, PRINTED_GUID_BUF= FER_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 @@ LibEncapNewFvFile( + ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Le= vel -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->NextNod= e !=3D NULL) { ++ LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEn= capDataTemp->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->FFSNa= me !=3D NULL && OutputFileNameList->IsFFS =3D=3D FALSE){ + break; + } + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSNa= me !=3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE){ +- if (Index =3D=3D EncapFvIndex) { ++ if (Index =3D=3D EncapFvStart) { + if (FirstInFlag) { + Status =3D LibAddFfsFileToFvInf (OutputFileNa= meList->FFSName, InfFile, TRUE); + FirstInFlag =3D FALSE; +@@ -4601,7 +4657,7 @@ LibEncapNewFvFile( + } + } + // 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].F= vLevel <=3D FvInFd->MulFvLevel) { ++ if (Index < FvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].FvL= evel <=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, &(LocalEnca= pData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ + if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) !=3D -1= ) { ++ OutputFileNameList->FvLevel =3D FvInFd->FfsAttuibute= s[Id].FvLevel; + Status =3D LibFmmtDeleteFile(FvInFd->FfsAttuibutes[I= d].FfsName); + if (EFI_ERROR(Status)) { + Error("FMMT", 0, 0004, "error while encapsulate = FD Image", "Delete the specified file failed!"); +@@ -5079,7 +5136,9 @@ LibEncapNewFvFile( + } 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; + } +--=20 +2.16.2.windows.1 + diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h b/BaseTools= /Source/C/FMMT/FirmwareModuleManagement.h index 9d09c9160a..ccc8ba00be 100644 --- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h +++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h @@ -195,7 +195,7 @@ typedef struct { // UI Name for this FFS file, if has. // CHAR16 UiName[_MAX_PATH]; - UINT32 UiNameSize; + UINT32 UiNameSize; // // Total section number in this FFS. // @@ -208,7 +208,7 @@ typedef struct { // //Describe the belong to FV // - UINT8 FvId; + UINT8 FvId; // // If this FFS has no encapsulate section, this flag will set to True. // diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/Fm= mtLib.c index b945e9b63d..d6d43030fa 100644 --- a/BaseTools/Source/C/FMMT/FmmtLib.c +++ b/BaseTools/Source/C/FMMT/FmmtLib.c @@ -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); } @@ -833,7 +833,6 @@ LibParseSection ( CHAR8 *ToolInputFileName; CHAR8 *ToolOutputFileName; BOOLEAN HasUiSection; - BOOLEAN FirstInFlag; =20 DataOffset =3D 0; GuidAttr =3D 0; @@ -869,7 +868,6 @@ LibParseSection ( EncapDataNeedUpdata =3D TRUE; LargeHeaderOffset =3D 0; HasUiSection =3D FALSE; - FirstInFlag =3D TRUE; =20 =20 while (ParsedLength < BufferLength) { @@ -997,9 +995,7 @@ LibParseSection ( break; =20 case EFI_SECTION_COMPRESSION: - if (FirstInFlag) { - Level ++; - } + Level ++; NumberOfSections ++; =20 EncapDataNeedUpdata =3D TRUE; @@ -1181,9 +1177,7 @@ LibParseSection ( // looks up the appropriate tool to use for extracting // a GUID defined FV section. // - if (FirstInFlag) { - Level ++; - } + Level ++; NumberOfSections++; EncapDataNeedUpdata =3D TRUE; HasUiSection =3D TRUE; @@ -1682,7 +1676,6 @@ LibParseSection ( } =20 ParsedLength +=3D SectionLength; - FirstInFlag =3D FALSE; // // We make then next section begin on a 4-byte boundary // @@ -2016,7 +2009,7 @@ LibGetFileInfo ( =20 LocalEncapData->Level =3D Level; LocalEncapData->Type =3D FMMT_ENCAP_TREE_FFS; - LocalEncapData->FvExtHeader =3D NULL; + LocalEncapData->FvExtHeader =3D NULL; LocalEncapData->Depex =3D NULL; LocalEncapData->DepexLen =3D 0; LocalEncapData->UiNameSize =3D 0; @@ -4198,6 +4191,7 @@ LibEncapNewFvFile( UINT32 header; UINT8 AlignN; UINT8 AlignV[1] =3D {0xFF}; + =20 AlignN =3D 0; Id =3D 0; InputFileSize =3D 0; @@ -4225,7 +4219,6 @@ LibEncapNewFvFile( OutputFileSize =3D 0; LargeFileSize =3D 0x1000000; =20 - OutputFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION)= ); if (OutputFileNameList =3D=3D NULL) { Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n= ", ""); @@ -4258,12 +4251,12 @@ 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; + } + Level =3D LocalEncapData->Level; + Type =3D LocalEncapData->Type; =20 if (CurrentEncapData =3D=3D NULL) { LocalEncapData =3D FvInFd->EncapData; @@ -4271,22 +4264,21 @@ LibEncapNewFvFile( if (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->NextNo= de !=3D NULL) { - - LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, 1, &= ChildFileNameList); - ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Lev= el -1; - 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; + LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; + if(LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNode = !=3D NULL) { + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEnc= apDataTemp->Level-1, &ChildFileNameList); + //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Level= -1; + 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; + } + LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; } } =20 @@ -4329,24 +4321,24 @@ LibEncapNewFvFile( } else { LocalEncapData =3D CurrentEncapData; while (LocalEncapData !=3D NULL) { - if (Level_Break > 1 && LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_F= FS) { + if (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->NextNo= de !=3D NULL) { - LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, Loca= lEncapDataTemp->Level-1, &ChildFileNameList); - //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->L= evel -1; - 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; + LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; + if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNode= !=3D NULL) { + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEnc= apDataTemp->Level-1, &ChildFileNameList); + //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Level= -1; + 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; + } + LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; } } if (LocalEncapData->Level > Level) { @@ -4366,12 +4358,12 @@ LibEncapNewFvFile( case FMMT_ENCAP_TREE_FV: OutputFileNameListFlag =3D TRUE; EncapFvStart =3D 0; - for(OuterIndex=3D0;OutputFileNameListFlag;OuterIndex++){ + for(OuterIndex=3D0;OutputFileNameListFlag;OuterIndex++){ // // Generate FV.inf attributes. // InfFileName =3D LibFilenameStrExtended (strrchr(GenTempFile (),OS_= SEP), TemDir, "inf"); - FirstInFlag =3D TRUE; + FirstInFlag =3D TRUE; =20 InfFile =3D fopen (InfFileName, "wt+"); =20 @@ -4383,9 +4375,9 @@ LibEncapNewFvFile( } =20 if (CurrentEncapData =3D=3D NULL) { - LocalEncapData =3D FvInFd->EncapData; + LocalEncapData =3D FvInFd->EncapData; } else { - LocalEncapData =3D CurrentEncapData; + LocalEncapData =3D CurrentEncapData; } =20 while (LocalEncapData->NextNode !=3D NULL) { @@ -4456,6 +4448,7 @@ LibEncapNewFvFile( free (ChildFileNameList); return Status; } + if (LocalEncapData->FvExtHeader !=3D NULL) { Status =3D LibGenExtFile(LocalEncapData->FvExtHeader, InfFile); if (EFI_ERROR(Status)) { @@ -4473,93 +4466,93 @@ LibEncapNewFvFile( while (LocalEncapData->Level !=3D ParentLevel) { LocalEncapData =3D LocalEncapData->NextNode; } - for (Index =3D 0; Index <=3D FvInFd->FfsNumbers; Index++) { - if ((memcmp(&FvInFd->FfsAttuibutes[Index].GuidName, &(Loca= lEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)) { - SubFvId =3D Index; - break; - } + for (Index =3D 0; Index <=3D FvInFd->FfsNumbers; Index++) { + if ((memcmp(&FvInFd->FfsAttuibutes[Index].GuidName, &(LocalEnc= apData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)) { + SubFvId =3D Index; + break; } + } } // // Found FFSs from Fv structure. // FfsFoundFlag =3D FALSE; IsRootFv =3D FALSE; - for (Index=3D0; Index <=3D 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 (FirstInFlag) { - Status =3D LibAddFfsFileToFvInf (OutputFileNam= eList->FFSName, InfFile, TRUE); - FirstInFlag =3D FALSE; - } else { - Status =3D LibAddFfsFileToFvInf (OutputFileNam= eList->FFSName, InfFile, FALSE); - } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsula= te FD Image", "Generate FV inf file [files] section failed!"); - fclose (InfFile); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - } + for (Index =3D 0; Index < FvInFd->FfsNumbers; Index++) { + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSName = !=3D NULL && OutputFileNameList->IsFFS =3D=3D FALSE){ + break; + } + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSName = !=3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE){ + if (Index =3D=3D EncapFvIndex) { + if (FirstInFlag) { =20 + Status =3D LibAddFfsFileToFvInf (OutputFileNameList->FFSNa= me, InfFile, TRUE); + FirstInFlag =3D FALSE; + } else { + Status =3D LibAddFfsFileToFvInf (OutputFileNameList->FFSNa= me, InfFile, FALSE); + } + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image"= , "Generate FV inf file [files] section failed!"); + fclose (InfFile); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } } + } =20 - NewFileNameList =3D FvInFd->ChildFvFFS; - while (NewFileNameList !=3D NULL && NewFileNameList -> FFSName= !=3D NULL) { - if (NewFileNameList -> ParentLevel =3D=3D ParentLevel && I= ndex =3D=3D NewFileNameList->InFvId && NewFileNameList->FfsFoundFlag=3D=3DT= RUE) { - if (FirstInFlag) { - Status =3D LibAddFfsFileToFvInf (NewFileNameList->= FFSName, InfFile, TRUE); - FirstInFlag =3D FALSE; - } else { - Status =3D LibAddFfsFileToFvInf (NewFileNameList->= FFSName, InfFile, FALSE); - } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate F= D Image", "Generate FV inf file [files] section failed!"); - fclose (InfFile); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - NewFileNameList->FfsFoundFlag =3D FALSE; - } - NewFileNameList =3D NewFileNameList->Next; + NewFileNameList =3D FvInFd->ChildFvFFS; + while (NewFileNameList !=3D NULL && NewFileNameList -> FFSName != =3D NULL) { + if (NewFileNameList -> ParentLevel =3D=3D ParentLevel && Index= =3D=3D NewFileNameList->InFvId && NewFileNameList->FfsFoundFlag=3D=3DTRUE)= { + if (FirstInFlag) { + Status =3D LibAddFfsFileToFvInf (NewFileNameList->FFSName,= InfFile, TRUE); + FirstInFlag =3D FALSE; + } else { + Status =3D LibAddFfsFileToFvInf (NewFileNameList->FFSName,= InfFile, FALSE); + } + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image"= , "Generate FV inf file [files] section failed!"); + fclose (InfFile); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + NewFileNameList->FfsFoundFlag =3D FALSE; } + NewFileNameList =3D NewFileNameList->Next; + } =20 - if (FvInFd->FfsAttuibutes[Index].IsHandle=3D=3DTRUE) { - continue; - } - if (SubFvId > 0 && Index < SubFvId) { - continue; - } + if (FvInFd->FfsAttuibutes[Index].IsHandle=3D=3DTRUE) { + continue; + } + if (SubFvId > 0 && Index < SubFvId) { + continue; + } =20 // // For the last level FFS, the level below FFSs we should not ca= re the IsLeaf Flag. // if (IsLastLevelFfs) { IsLeafFlagIgnore =3D TRUE; - } else { - IsLeafFlagIgnore =3D FvInFd->FfsAttuibutes[Index].IsLeaf; - } + } else { + IsLeafFlagIgnore =3D FvInFd->FfsAttuibutes[Index].IsLeaf; + } =20 if (FvInFd->FfsAttuibutes[Index].FvId =3D=3D LocalEncapData->FvI= d && FvInFd->FfsAttuibutes[Index].Level >=3D ParentLevel + 1 && IsLeafFlag= Ignore) { if (FirstInFlag) { - if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) { - FfsFoundFlag =3D TRUE; - Status =3D LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Index].Ff= sName, InfFile, TRUE); - FirstInFlag =3D FALSE; - FvInFd->FfsAttuibutes[Index].IsHandle=3DTRUE; - EncapFvStart =3D Index; - } + if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) { + FfsFoundFlag =3D TRUE; + Status =3D LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Ind= ex].FfsName, InfFile, TRUE); + FirstInFlag =3D FALSE; + FvInFd->FfsAttuibutes[Index].IsHandle=3DTRUE; + EncapFvStart =3D Index; + } =20 if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Imag= e", "Generate FV inf file [files] section failed!"); - fclose (InfFile); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; + Error ("FMMT", 0, 0004, "error while encapsulate FD Image"= , "Generate FV inf file [files] section failed!"); + fclose (InfFile); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; } if (Index =3D=3D 0) { // Root FV need to include all FFS files. @@ -4586,33 +4579,32 @@ LibEncapNewFvFile( } =20 =20 - //avoid a FV contain too many ffs files - if ((!IsRootFv) && (FvInFd->FfsAttuibutes[Index].FvLevel <=3D F= vInFd->MulFvLevel) && (FvInFd->FfsAttuibutes[Index+1].FvLevel <=3D FvInFd->= MulFvLevel) && - (FvInFd->FfsAttuibutes[Index].FvLevel !=3D FvInFd->FfsAttui= butes[Index+1].FvLevel) && (ParentLevel !=3D 1) && (FvInFd->FfsAttuibutes[I= ndex].Level !=3D FvInFd->FfsAttuibutes[Index+1].Level) && - FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF && FvInFd->Ffs= Attuibutes[Index+1].Level !=3D 0xFF && FvInFd->FfsAttuibutes[Index+1].Level= !=3D 0x0){ - FvInFd->FfsAttuibutes[Index].Level =3D 0; - break; - }else{ - if (FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF){ - FvInFd->FfsAttuibutes[Index].Level =3D 0; - } - } - + //avoid a FV contain too many ffs files + if ((!IsRootFv) && (FvInFd->FfsAttuibutes[Index].FvLevel <=3D = FvInFd->MulFvLevel) && (FvInFd->FfsAttuibutes[Index+1].FvLevel <=3D FvInFd-= >MulFvLevel) && + (FvInFd->FfsAttuibutes[Index].FvLevel !=3D FvInFd->FfsAttuib= utes[Index+1].FvLevel) && (ParentLevel !=3D 1) && (FvInFd->FfsAttuibutes[In= dex].Level !=3D FvInFd->FfsAttuibutes[Index+1].Level) && + FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF && FvInFd->FfsA= ttuibutes[Index+1].Level !=3D 0xFF && FvInFd->FfsAttuibutes[Index+1].Level = !=3D 0x0){ + FvInFd->FfsAttuibutes[Index].Level =3D 0; + break; + } else { + if (FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF){ + FvInFd->FfsAttuibutes[Index].Level =3D 0; + } } } - // 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 (FvInFd->FfsAttuibutes[Index].FvLevel =3D=3D 2) { - IsLastLevelFfs =3D FALSE; - } - } - if (!FfsFoundFlag){ - OutputFileNameListFlag =3D FALSE; - if (OuterIndex > 0){ - fclose (InfFile); - break; - } - } + } + // 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].F= vLevel <=3D FvInFd->MulFvLevel) { + if (FvInFd->FfsAttuibutes[Index].FvLevel =3D=3D 2) { + IsLastLevelFfs =3D FALSE; + } + } + if (!FfsFoundFlag){ + OutputFileNameListFlag =3D FALSE; + if (OuterIndex > 0){ + fclose (InfFile); + break; + } + } // // Create FV // @@ -4631,15 +4623,15 @@ LibEncapNewFvFile( return Status; } =20 - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileName)+= 1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! = \n", ""); - return EFI_OUT_OF_RESOURCES; - } - memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, st= rlen(OutputFileName)+1); - if (CurrentEncapData !=3D NULL) { - OutputFileNameList->InFvId =3D EncapFvIndex; - if (EncapFvIndex > 0) { + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileNa= me)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fail= ed! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName= , strlen(OutputFileName)+1); + if (CurrentEncapData !=3D NULL) { + OutputFileNameList->InFvId =3D EncapFvIndex; + if (EncapFvIndex > 0) { memcpy(OutputFileNameList->UiName,FvInFd->FfsAttuibutes[EncapF= vIndex - 1].UiName, FvInFd->FfsAttuibutes[EncapFvIndex - 1].UiNameSize); OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[Encap= FvIndex - 1].UiNameSize; OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[EncapFvInd= ex - 1].Depex; @@ -4647,9 +4639,9 @@ LibEncapNewFvFile( OutputFileNameList->FfsFoundFlag =3D FfsFoundFlag; OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[EncapFvInde= x - 1].FvId; OutputFileNameList->ParentLevel =3D ParentLevel - 1; + } + } } - } - } break; case FMMT_ENCAP_TREE_FFS: =20 @@ -4662,13 +4654,13 @@ LibEncapNewFvFile( } while (LocalEncapData->NextNode !=3D NULL) { if (LocalEncapData->Level =3D=3D ParentLevel) { - for(;LocalEncapData->NextNode !=3D NULL;) { - if(LocalEncapData->FvExtHeader !=3D NULL) { - break; - } - LocalEncapData =3D LocalEncapData->NextNode; - } - break; + for(;LocalEncapData->NextNode !=3D NULL;) { + if(LocalEncapData->FvExtHeader !=3D NULL) { + break; + } + LocalEncapData =3D LocalEncapData->NextNode; + } + break; } LocalEncapData =3D LocalEncapData->NextNode; } @@ -4728,101 +4720,106 @@ LibEncapNewFvFile( InputFileName =3D TmpFileName; } if (OutputFileNameList->DepexLen > 0) { - TmpFileName =3D LibFilenameStrExtended(strrchr(GenTempFile (= ), OS_SEP), TemDir, "tmp"); - TmpFile =3D fopen(TmpFileName, "wb+"); - if (TmpFile =3D=3D NULL) { - Error("FMMT", 0, 0004, "Could not open tmp file %s to st= ore Depex section information! \n", ""); - free (OutputFileNameList); - free (ChildFileNameList); - return EFI_ABORTED; - } - InputFile =3D fopen(InputFileName, "rb+"); - if (InputFile =3D=3D NULL) { - Error("FMMT", 0, 0004, "Could not open input file %s! \n",= ""); + TmpFileName =3D LibFilenameStrExtended(strrchr(GenTempFile (),= OS_SEP), TemDir, "tmp"); + TmpFile =3D fopen(TmpFileName, "wb+"); + if (TmpFile =3D=3D NULL) { + Error("FMMT", 0, 0004, "Could not open tmp file %s to stor= e Depex section information! \n", ""); + free (OutputFileNameList); + free (ChildFileNameList); + return EFI_ABORTED; + } + InputFile =3D fopen(InputFileName, "rb+"); + if (InputFile =3D=3D NULL) { + Error("FMMT", 0, 0004, "Could not open input file %s! \n", "= "); + fclose(TmpFile); + free (OutputFileNameList); + free (ChildFileNameList); + return EFI_ABORTED; + } + fseek(InputFile, 0, SEEK_SET); + fseek(InputFile, 0, SEEK_END); + InputFileSize =3D ftell(InputFile); + fseek(InputFile, 0, SEEK_SET); + // make sure the section is 4 byte align + if (OutputFileNameList->DepexLen % 4 !=3D 0) { + AlignN =3D 4 - OutputFileNameList->DepexLen % 4; + } + Buffer =3D malloc(InputFileSize + OutputFileNameList->DepexLen= + AlignN); + memcpy(Buffer, OutputFileNameList->Depex, OutputFileNameList->= DepexLen); + if (AlignN !=3D 0) { + for (Index =3D 0; Index < AlignN; Index ++) { + memcpy(Buffer + OutputFileNameList->DepexLen + Index, = AlignV, 1); + } + } + if (fread(Buffer + OutputFileNameList->DepexLen + AlignN, 1, I= nputFileSize, InputFile) !=3D InputFileSize) { + Error("FMMT", 0, 0004, "Could not open sec file %s to add = Depex section information! \n", ""); fclose(TmpFile); + fclose(InputFile); + free(Buffer); free (OutputFileNameList); free (ChildFileNameList); return EFI_ABORTED; + } + fwrite(Buffer, 1, InputFileSize + OutputFileNameList->DepexLen= + AlignN, TmpFile); + free(Buffer); + fclose(TmpFile); + fclose(InputFile); + InputFileName =3D TmpFileName; + } + // + // Delete origin FFS + // + for (Id =3D FvInFd->FfsNumbers; Id <=3D FvInFd->FfsNumbers; Id--= ) { + if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(LocalEncapD= ata->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ + if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) !=3D -1) { + Status =3D LibFmmtDeleteFile(FvInFd->FfsAttuibutes[Id].Ffs= Name); + if (EFI_ERROR(Status)) { + Error("FMMT", 0, 0004, "error while encapsulate FD Ima= ge", "Delete the specified file failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + memset(FvInFd->FfsAttuibutes[Id].FfsName, '\0', _MAX_PATH)= ; + FvInFd->FfsAttuibutes[Id].Level =3D 0xFF; + break; } - fseek(InputFile, 0, SEEK_SET); - fseek(InputFile, 0, SEEK_END); - InputFileSize =3D ftell(InputFile); - fseek(InputFile, 0, SEEK_SET); - // make sure the section is 4 byte align - if (OutputFileNameList->DepexLen % 4 !=3D 0) { - AlignN =3D 4 - OutputFileNameList->DepexLen % 4; - } - Buffer =3D malloc(InputFileSize + OutputFileNameList->DepexL= en + AlignN); - memcpy(Buffer, OutputFileNameList->Depex, OutputFileNameList= ->DepexLen); - if (AlignN !=3D 0) { - for (Index =3D 0; Index < AlignN; Index ++) { - memcpy(Buffer + OutputFileNameList->DepexLen + Index= , AlignV, 1); - } - } - if (fread(Buffer + OutputFileNameList->DepexLen + AlignN, 1,= InputFileSize, InputFile) !=3D InputFileSize) { - Error("FMMT", 0, 0004, "Could not open sec file %s to ad= d Depex section information! \n", ""); - fclose(TmpFile); - fclose(InputFile); - free(Buffer); - free (OutputFileNameList); - free (ChildFileNameList); - return EFI_ABORTED; - } - fwrite(Buffer, 1, InputFileSize + OutputFileNameList->DepexL= en + AlignN, TmpFile); - free(Buffer); - fclose(TmpFile); - fclose(InputFile); - InputFileName =3D TmpFileName; - } - 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)= { - 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!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - memset(FvInFd->FfsAttuibutes[Id].FfsName, '\0', _MAX_= PATH); - FvInFd->FfsAttuibutes[Id].Level =3D 0xFF; - break; - } - } - } - if (LocalEncapData->NextNode !=3D NULL) { - LocalEncapDataTemp =3D LocalEncapData->NextNode; - if ((LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_GUIDED_S= ECTION) || (LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_COMPRESS_SECTIO= N)) { - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMW= ARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeade= r->FvName, FALSE, "1"); - } - else{ - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMW= ARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeade= r->FvName, FALSE, FvInFd->AlignmentStr); - } - } - else{ - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_= VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->F= vName, FALSE, FvInFd->AlignmentStr); - } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gener= ate FFS file failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - free(LocalEncapData->FvExtHeader); - LocalEncapData->FvExtHeader =3D NULL; - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileName= )+1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation fail= ed! \n", ""); - return EFI_OUT_OF_RESOURCES; - } - memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, = strlen(OutputFileName)+1); - OutputFileNameList->IsFFS =3D TRUE; - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - if (OutputFileNameList->Next =3D=3D NULL){ - break; - } - OutputFileNameList =3D OutputFileNameList->Next; - } + } + } + if (LocalEncapData->NextNode !=3D NULL) { + LocalEncapDataTemp =3D LocalEncapData->NextNode; + if ((LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_GUIDED_SE= CTION) || (LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_COMPRESS_SECTION= )) { + Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE= _VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->= FvName, FALSE, "1"); + } else{ + Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE= _VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->= FvName, FALSE, FvInFd->AlignmentStr); + } + } else{ + Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_V= OLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->Fv= Name, FALSE, FvInFd->AlignmentStr); + } + + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "G= enerate FFS file failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + =20 + free(LocalEncapData->FvExtHeader); + LocalEncapData->FvExtHeader =3D NULL; + =20 + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFile= Name)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fa= iled! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileNa= me, strlen(OutputFileName)+1); + OutputFileNameList->IsFFS =3D TRUE; + OutputFileNameList->ParentLevel =3D ParentLevel - 1; + OutputFileNameList->InFvId =3D Id; + if (OutputFileNameList->Next =3D=3D NULL){ + break; + } + OutputFileNameList =3D OutputFileNameList->Next; + } break; case FMMT_ENCAP_TREE_GUIDED_SECTION: while(OutputFileNameList!=3D NULL && OutputFileNameList->FFSName != =3D NULL){ @@ -4941,25 +4938,25 @@ LibEncapNewFvFile( if (OutputFileSize > LargeFileSize) { IsLargeFile =3D TRUE; } - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileName)+= 1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! = \n", ""); - return EFI_OUT_OF_RESOURCES; - } - memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, st= rlen(OutputFileName)+1); - - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gen= erate guided section failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileNa= me)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fail= ed! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName= , strlen(OutputFileName)+1); + =20 + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Ge= nerate guided section failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + OutputFileNameList->ParentLevel =3D ParentLevel - 1; + if (OutputFileNameList->Next =3D=3D NULL) { + break; + } + OutputFileNameList =3D OutputFileNameList->Next; } - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - if (OutputFileNameList->Next =3D=3D NULL){ - break; - } - OutputFileNameList =3D OutputFileNameList->Next; - } break; case FMMT_ENCAP_TREE_COMPRESS_SECTION: while(OutputFileNameList!=3D NULL && OutputFileNameList->FFSName != =3D NULL){ @@ -5000,89 +4997,86 @@ LibEncapNewFvFile( break; case FMMT_ENCAP_TREE_FV_SECTION: while(OutputFileNameList!=3D NULL && OutputFileNameList->FFSName != =3D NULL){ - InputFileName =3D OutputFileNameList->FFSName; - OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile (), = OS_SEP), TemDir, "sec"); - - Status =3D LibCreateFfsSection(NULL, InputFileName, NULL, EFI_SECT= ION_FIRMWARE_VOLUME_IMAGE, OutputFileName, NULL, NULL, NULL, 0, 0, NULL); + InputFileName =3D OutputFileNameList->FFSName; + OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile ()= , OS_SEP), TemDir, "sec"); =20 - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gen= erate FV section failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } + Status =3D LibCreateFfsSection(NULL, InputFileName, NULL, EFI_SE= CTION_FIRMWARE_VOLUME_IMAGE, OutputFileName, NULL, NULL, NULL, 0, 0, NULL); =20 - InputFileName =3D OutputFileName; - OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile (), = OS_SEP), TemDir, "sec"); + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "G= enerate FV section failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } =20 - // - // Make it alignment. - // - Status =3D LibCreateFfsSection(FvInFd, InputFileName, NULL, 0, Out= putFileName, NULL, NULL, NULL, 0, 0, NULL); - OutFile =3D fopen(OutputFileName, "rb+"); - if (OutFile =3D=3D NULL) { + InputFileName =3D OutputFileName; + OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile ()= , OS_SEP), TemDir, "sec"); + =20 + // + // Make it alignment. + // + Status =3D LibCreateFfsSection(FvInFd, InputFileName, NULL, 0, O= utputFileName, NULL, NULL, NULL, 0, 0, NULL); + OutFile =3D fopen(OutputFileName, "rb+"); + if (OutFile =3D=3D NULL) { Error("FMMT", 0, 0004, "Could not open the file %s! \n", ""); free (OutputFileNameList); free (ChildFileNameList); return EFI_ABORTED; - } - fseek(OutFile, 0, SEEK_SET); - fseek(OutFile, 0, SEEK_END); - OutputFileSize =3D ftell(OutFile); - fclose(OutFile); - if (OutputFileSize > LargeFileSize) { + } + fseek(OutFile, 0, SEEK_SET); + fseek(OutFile, 0, SEEK_END); + OutputFileSize =3D ftell(OutFile); + fclose(OutFile); + if (OutputFileSize > LargeFileSize) { IsLargeFile =3D TRUE; + } + =20 + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFile= Name)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fa= iled! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileNa= me, strlen(OutputFileName)+1); + =20 + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "G= enerate FV section failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + OutputFileNameList->ParentLevel =3D ParentLevel - 1; + if (OutputFileNameList->Next =3D=3D NULL){ + break; + } + OutputFileNameList =3D OutputFileNameList->Next; } - - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileName)+= 1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! = \n", ""); - return EFI_OUT_OF_RESOURCES; - } - memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, st= rlen(OutputFileName)+1); - - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gen= erate FV section failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - if (OutputFileNameList->Next =3D=3D NULL){ - break; - } - OutputFileNameList =3D OutputFileNameList->Next; - } break; default: for (Id =3D FvInFd->FfsNumbers; Id <=3D FvInFd->FfsNumbers; Id--) = { - if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(CurrentEnca= pData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ - FvInFd->FfsAttuibutes[Id].IsHandle =3D TRUE; - memcpy(OutputFileNameList->UiName, FvInFd->FfsAttuibutes[I= d].UiName, FvInFd->FfsAttuibutes[Id].UiNameSize); - OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[I= d].UiNameSize; - OutputFileNameList->FFSName =3D FvInFd->FfsAttuibutes[Id].= FfsName; - OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[Id].De= pex; - OutputFileNameList->DepexLen =3D FvInFd->FfsAttuibutes[Id]= .DepexLen; - OutputFileNameList->FfsFoundFlag =3D TRUE; - OutputFileNameList->IsFFS =3D TRUE; - OutputFileNameList->InFvId =3D Id; - OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[Id].FvI= d; - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - *OutputFile =3D OutputFileNameList; - return EFI_SUCCESS; - } + if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(CurrentEncapD= ata->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ + FvInFd->FfsAttuibutes[Id].IsHandle =3D TRUE; + memcpy(OutputFileNameList->UiName, FvInFd->FfsAttuibutes[Id].U= iName, FvInFd->FfsAttuibutes[Id].UiNameSize); + OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[Id].U= iNameSize; + OutputFileNameList->FFSName =3D FvInFd->FfsAttuibutes[Id].FfsN= ame; + OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[Id].Depex; + OutputFileNameList->DepexLen =3D FvInFd->FfsAttuibutes[Id].Dep= exLen; + OutputFileNameList->FfsFoundFlag =3D TRUE; + OutputFileNameList->IsFFS =3D TRUE; + OutputFileNameList->InFvId =3D Id; + OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[Id].FvId; + OutputFileNameList->ParentLevel =3D ParentLevel - 1; + *OutputFile =3D OutputFileNameList; + return EFI_SUCCESS; + } } } =20 if (CurrentEncapData =3D=3D NULL) { LocalEncapData =3D FvInFd->EncapData; } else { - if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSName != =3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE) { - *OutputFile =3D OutputFileNameList; - return EFI_SUCCESS; - } LocalEncapData =3D CurrentEncapData; } + =20 ParentLevel -=3D 1; =20 while (LocalEncapData->NextNode !=3D NULL) { --=20 2.16.2.windows.1