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.12925.1606438383337126041 for ; Thu, 26 Nov 2020 16:53:03 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=eVISzUn1; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: bob.c.feng@intel.com) IronPort-SDR: Jx82azl7YbqgPyGcSzs/MveFhbGIPunXgaZL3Zjc1nWArb6kyPkCTKtYhgD1MgGUwgrvriqEbL on93VjBzHu6A== X-IronPort-AV: E=McAfee;i="6000,8403,9817"; a="171555499" X-IronPort-AV: E=Sophos;i="5.78,373,1599548400"; d="scan'208";a="171555499" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2020 16:53:01 -0800 IronPort-SDR: X963O55GKAS7kjNdeXFjGiT57pharIrlV+83SiOLrbF6jEP3xI1NI+z2p7/Ux1ytxdGybIwEm3 L6pTAEY1CBqw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,373,1599548400"; d="scan'208";a="314159496" Received: from orsmsx604.amr.corp.intel.com ([10.22.229.17]) by fmsmga007.fm.intel.com with ESMTP; 26 Nov 2020 16:53:01 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) 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 16:53:00 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX611.amr.corp.intel.com (10.22.229.24) 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 16:53:00 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx609.amr.corp.intel.com (10.22.229.22) 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 16:53:00 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.102) 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 16:53:00 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Eq5lPRUmwaPkrWv2WLTx0MyLAK00jix71MsE20yASKYg3kHNjWuH1n7dct0gMNIaShJEHEQBdEg3eEQtzdNOAo0IkvwYEwVmpJAxrHVgr70eo3HoLEgVOpQ5ERRv8QIYf/tAgwT0bLn2/ppQg60zt0Z50Cx+qAwn8FFmL/aOnnE6aNPVbUAsViqRuapZaPc5UMpuJnwhYzIwaJW12puEkfcJEeB163ZT0I5dmkohUoanF4BvOvKuhVL002wxUUOs26xenOY+r/9WMUeiCcfy26kk3yzVJOMbiKJk+rKROoDyJtJ9yUH3JZIBlcDw4SEQ3QsMIJcQTY4IhUKp6Pj/bg== 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=Imi3BBv0ndWfOm6KF5PpunOsWQzzbM9131zYyM44kZQ=; b=PFuaJ9knWowK4do93hxKGDPw1iBe95IgPZGo7Kaua8ATzTQxXzOBiCeS9bPJ65jaIu9N3PwyQHlcg75SSnBivCIBso/k6cWgyuPMMxwTdT7havczLdWs++3e9GnWTYTFTk07yts61uWynfm8p012nF7RkKdEDrnzsjvGlUqYM1+HBK3S0KiJ+IE29yiaHTOS1O42PRqfpimvbDvdsTCChXg0VO21bT8zVaUVQ2/+Rq3XA6pYYJjspe5rBvjl3OWExSHL85iiGsEH75dUcRvydIarKeP2SHMDKCbb+JnWb9Gt6AeWzG6jDWeiiOz0Mbeh/7G95+TM1B0ewlz681Kj4w== 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=Imi3BBv0ndWfOm6KF5PpunOsWQzzbM9131zYyM44kZQ=; b=eVISzUn1rIZOad3LFTEHodKpzMruo4iFIGvni8BkEDO+xI39z2vTz3t2hgfwzLilmSHAkko+C04CCSHL/zJSTbTAeObxHy9z9fV+F948SS5/kZT5AVcGTbksGjJzWBHpsZOCQhRoNa9zDyA+nVKjD8cFU5PwJjKFvoUunqqVokw= Received: from DM6PR11MB4073.namprd11.prod.outlook.com (2603:10b6:5:19f::22) by DM6PR11MB4530.namprd11.prod.outlook.com (2603:10b6:5:2a4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.22; Fri, 27 Nov 2020 00:52:58 +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 00:52:58 +0000 From: "Bob Feng" To: "devel@edk2.groups.io" , "Yeh, GregX" CC: Liming Gao Subject: Re: [edk2-devel] [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when FV level over 2 Thread-Topic: [edk2-devel] [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when FV level over 2 Thread-Index: AQHWw8LQa16epwIKF0St6bU792DL5qnbJ0yQ Date: Fri, 27 Nov 2020 00:52:58 +0000 Message-ID: References: <20201126070701.14212-1-gregx.yeh@intel.com> In-Reply-To: <20201126070701.14212-1-gregx.yeh@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; 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: 1bb4d7f5-bb30-4b70-2f89-08d8926ec8a1 x-ms-traffictypediagnostic: DM6PR11MB4530: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2201; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5O3u3Iq4ZKg2zsM6qlhtFkMZAd+/tx9vLQiOZQDeSgTu92I/xys1NSQg8O1x++fUUcCWNbdgxc4UKJkdhIUKXZXJCVMO/eAqgQVB/ks71Lf6O1aa6PhQkMTnheBDsw261+AO85EFDYo8J5qnRe/WslfNBwCw/HBnri9SWZWM5w3zemst2c/leUZa16kHQIaiEZa5yGrfDqLIOvCpQJBQj8wV4AJ6cWxviUJGglunwMCy+tLt4/zhCLCF8WEd6Sq/mR/OghtWxDs+ekcSXHf54Ikp0gBMbkxr5QF5LzZ2RbZRf8uzHKOPfqXZok/+msz173h4ZN0ekMQOMLTV2aqmTeGNcJXzkhlfoAuEjNNfZ/Vt62UCNu5SHheX6vciFFGooFA5/7NYCueExsqShKt13g== 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)(39860400002)(376002)(136003)(346002)(396003)(366004)(186003)(30864003)(7696005)(26005)(8936002)(76116006)(2906002)(66946007)(4326008)(86362001)(83380400001)(71200400001)(966005)(478600001)(53546011)(6506007)(55016002)(316002)(8676002)(6636002)(64756008)(52536014)(66446008)(66476007)(5660300002)(9686003)(110136005)(66556008)(33656002)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?a3MsWFX0us6r+W/o6/+OllcyDZHioFttlo9kpF1ZVmu3yA0JLmU3Evo8R2V1?= =?us-ascii?Q?LITbmHn0O5XdtqcyEQpPayG0dloyOejSOzfDDPcugVSp+9u32u2LueGdlzlY?= =?us-ascii?Q?qpw7dB3oxy734hOrAFK58OdwYDxUQJ0smwCgK9QmptX1c/VxwODNUKc0X/+9?= =?us-ascii?Q?HLhJ48/Oz8ks+piQUAjezyrjFnIo0oJTXDKoTME1shFxa6ko0QfuqGlrc7ik?= =?us-ascii?Q?VzmAg9lzSgNZinKTyQ6MSnrM13oLUAh4baf0rIS2hAVyGGFz0nR6HynFl2W9?= =?us-ascii?Q?0CTw/J/kPNXUvKty3XEYiefXqR14vLa+8zUyq2f2nBXJ7PQ0hh1SYrNvN69T?= =?us-ascii?Q?9bgdUMc+MUzVuHaHb0iNbcsMqpNr2aSSe3wcEfPp4HQPnzNe3Pb3F78BF+G5?= =?us-ascii?Q?I4fO7dzEsfet9RRLlSHctit4wMkCcKqPbh+TJNJt19iUSJMSKIlulQSiUe1B?= =?us-ascii?Q?jB8dVytyRuya2SmmyNtY2mQp7bYZtilqa8ytv4F3pcl2WxP/RqpQADSYRLGD?= =?us-ascii?Q?WArzmowIF5S+/38Z8j2dxEDY8+iHF6hb4jQO5SLlinl5XQx4DPFOxX54OpKA?= =?us-ascii?Q?xsilkZNaKiISW5E0/u40xMOteU8SrK95Z8ZaxudVYNWLOfbJocphA4MPEOkp?= =?us-ascii?Q?XMu8AoIXkflf9x2ugHEDpk5WmLwCbqRF8+Sf9i1LV3mZEf4F0Q572zANibIn?= =?us-ascii?Q?l7FNNbNRhESg3bjqBEvWOo/twymU2yV9JreNzdzwlaNmjcKLUeVjqLqKSvqj?= =?us-ascii?Q?D8gS2yerd54P1ThxTLHwXktwOPVqnfFw7em5lg5296ZXw6st49yg3KH7XfTo?= =?us-ascii?Q?B+YPjelflhu9c9vGW0UKwWmLyfjN7y1oP6AmnkbYwxfgai2tFwP/zVIeiw8r?= =?us-ascii?Q?NMdcCqmSO/niP2ZPs/mHss+KinYYhoah3/x7q5oxN/f0dlU405KOh39znlhx?= =?us-ascii?Q?0+ltpu07GJA+v/fttsfXuZbKYDSttBVF7xk10dvNots=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: 1bb4d7f5-bb30-4b70-2f89-08d8926ec8a1 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Nov 2020 00:52:58.1960 (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: TGiCClaRe2yfsgrPr0lkjlM1hzP4WRVwEk5ZH5Qz3kRoxNEKxwoKwC2Hscn1onUA+4/R+2NsdYgkUAksx/kLWA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4530 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 Looks this patch include the previous patch. Please remove it. Thanks, Bob -----Original Message----- From: devel@edk2.groups.io On Behalf Of GregX Yeh Sent: Thursday, November 26, 2020 3:07 PM To: devel@edk2.groups.io Cc: Feng, Bob C ; Liming Gao Subject: [edk2-devel] [PATCH] [edk2-staging] 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 --- ...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.pat= ch 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/BaseToo= ls/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 = FvLevel, 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/BaseToo= ls/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/= FmmtLib.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 decrea= se 1. + // + if (*IsFfsGenerated) { +- memcpy (CurrentFv->FfsAttuibutes[*FfsCount -1].UiName, UIName, U= INameSize); +- CurrentFv->FfsAttuibutes[*FfsCount -1].UiNameSize =3D UINameSize= ; ++ memcpy (CurrentFv->FfsAttuibutes[*FfsIndex - 1].UiName, UIName, = UINameSize); ++ CurrentFv->FfsAttuibutes[*FfsIndex - 1].UiNameSize =3D UINameSiz= e; + } else { +- memcpy (CurrentFv->FfsAttuibutes[*FfsCount].UiName, UIName, UINa= meSize); +- CurrentFv->FfsAttuibutes[*FfsCount].UiNameSize =3D UINameSize; ++ memcpy (CurrentFv->FfsAttuibutes[*FfsIndex].UiName, UIName, UINa= meSize); ++ 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_DEP= EX) { ++ 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 *) Cur= rentFile); +@@ -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_BU= FFER_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_INFORMATIO= N)); + 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->L= evel -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->NextNo= de !=3D NULL) { ++ LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalE= ncapDataTemp->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->FFSN= ame !=3D NULL && OutputFileNameList->IsFFS =3D=3D FALSE){ + break; + } + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSN= ame !=3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE){ +- if (Index =3D=3D EncapFvIndex) { ++ if (Index =3D=3D EncapFvStart) { + if (FirstInFlag) { + Status =3D LibAddFfsFileToFvInf (OutputFileN= ameList->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].= FvLevel <=3D FvInFd->MulFvLevel) { ++ if (Index < FvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].Fv= Level <=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, &(LocalEnc= apData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ + if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) !=3D -= 1) { ++ OutputFileNameList->FvLevel =3D FvInFd->FfsAttuibut= es[Id].FvLevel; + Status =3D LibFmmtDeleteFile(FvInFd->FfsAttuibutes[= Id].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/BaseTool= s/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/F= mmtLib.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}; + 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->NextN= ode !=3D NULL) { - - LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, 1, = &ChildFileNameList); - ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Le= vel -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, LocalEn= capDataTemp->Level-1, &ChildFileNameList); + //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Leve= l -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_= FFS) { + 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->NextN= ode !=3D NULL) { - LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, Loc= alEncapDataTemp->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; + LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; + if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNod= e !=3D NULL) { + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEn= capDataTemp->Level-1, &ChildFileNameList); + //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Leve= l -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, &(Loc= alEncapData->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, &(LocalEn= capData->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->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 (FirstInFlag) { - Status =3D LibAddFfsFileToFvInf (OutputFileNa= meList->FFSName, InfFile, TRUE); - FirstInFlag =3D FALSE; - } else { - Status =3D LibAddFfsFileToFvInf (OutputFileNa= meList->FFSName, InfFile, FALSE); - } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsul= ate 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->FFSN= ame, InfFile, TRUE); + FirstInFlag =3D FALSE; + } else { + Status =3D LibAddFfsFileToFvInf (OutputFileNameList->FFSN= ame, 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 -> FFSNam= e !=3D NULL) { - if (NewFileNameList -> ParentLevel =3D=3D ParentLevel && = Index =3D=3D NewFileNameList->InFvId && NewFileNameList->FfsFoundFlag=3D=3D= TRUE) { - 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; + NewFileNameList =3D FvInFd->ChildFvFFS; + while (NewFileNameList !=3D NULL && NewFileNameList -> FFSName = !=3D NULL) { + if (NewFileNameList -> ParentLevel =3D=3D ParentLevel && Inde= x =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 c= are 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->Fv= Id && FvInFd->FfsAttuibutes[Index].Level >=3D ParentLevel + 1 && IsLeafFla= gIgnore) { if (FirstInFlag) { - if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) { - FfsFoundFlag =3D TRUE; - Status =3D LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Index].F= fsName, 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[In= dex].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 Ima= ge", "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 = FvInFd->MulFvLevel) && (FvInFd->FfsAttuibutes[Index+1].FvLevel <=3D FvInFd-= >MulFvLevel) && - (FvInFd->FfsAttuibutes[Index].FvLevel !=3D FvInFd->FfsAttu= ibutes[Index+1].FvLevel) && (ParentLevel !=3D 1) && (FvInFd->FfsAttuibutes[= Index].Level !=3D FvInFd->FfsAttuibutes[Index+1].Level) && - FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF && FvInFd->Ff= sAttuibutes[Index+1].Level !=3D 0xFF && FvInFd->FfsAttuibutes[Index+1].Leve= l !=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->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; + } } } - // 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; - } - } + } + // 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].= FvLevel <=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, s= trlen(OutputFileName)+1); - if (CurrentEncapData !=3D NULL) { - OutputFileNameList->InFvId =3D EncapFvIndex; - if (EncapFvIndex > 0) { + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileN= ame)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fai= led! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileNam= e, strlen(OutputFileName)+1); + if (CurrentEncapData !=3D NULL) { + OutputFileNameList->InFvId =3D EncapFvIndex; + if (EncapFvIndex > 0) { memcpy(OutputFileNameList->UiName,FvInFd->FfsAttuibutes[Encap= FvIndex - 1].UiName, FvInFd->FfsAttuibutes[EncapFvIndex - 1].UiNameSize); OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[Enca= pFvIndex - 1].UiNameSize; OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[EncapFvIn= dex - 1].Depex; @@ -4647,9 +4639,9 @@ LibEncapNewFvFile( OutputFileNameList->FfsFoundFlag =3D FfsFoundFlag; OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[EncapFvInd= ex - 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 s= tore 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 sto= re 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->DepexLe= n + 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 add= Depex section information! \n", ""); fclose(TmpFile); + fclose(InputFile); + free(Buffer); free (OutputFileNameList); free (ChildFileNameList); return EFI_ABORTED; + } + fwrite(Buffer, 1, InputFileSize + OutputFileNameList->DepexLe= n + 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, &(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].Ff= sName); + if (EFI_ERROR(Status)) { + Error("FMMT", 0, 0004, "error while encapsulate FD Im= age", "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->Depex= Len + AlignN); - memcpy(Buffer, OutputFileNameList->Depex, OutputFileNameLis= t->DepexLen); - if (AlignN !=3D 0) { - for (Index =3D 0; Index < AlignN; Index ++) { - memcpy(Buffer + OutputFileNameList->DepexLen + Inde= x, AlignV, 1); - } - } - if (fread(Buffer + OutputFileNameList->DepexLen + AlignN, 1= , InputFileSize, InputFile) !=3D InputFileSize) { - Error("FMMT", 0, 0004, "Could not open sec file %s to a= dd Depex section information! \n", ""); - fclose(TmpFile); - fclose(InputFile); - free(Buffer); - free (OutputFileNameList); - free (ChildFileNameList); - return EFI_ABORTED; - } - fwrite(Buffer, 1, InputFileSize + OutputFileNameList->Depex= Len + 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, &(LocalEnca= pData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ - if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) !=3D -1= ) { - 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!"); - 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_= SECTION) || (LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_COMPRESS_SECTI= ON)) { - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRM= WARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHead= er->FvName, FALSE, "1"); - } - else{ - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRM= WARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHead= er->FvName, FALSE, FvInFd->AlignmentStr); - } - } - else{ - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE= _VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->= FvName, FALSE, FvInFd->AlignmentStr); - } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gene= rate FFS file failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - free(LocalEncapData->FvExtHeader); - LocalEncapData->FvExtHeader =3D NULL; - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileNam= e)+1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation fai= led! \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_S= ECTION) || (LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_COMPRESS_SECTIO= N)) { + Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWAR= E_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader-= >FvName, FALSE, "1"); + } else{ + Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWAR= E_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader-= >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", "= Generate FFS file failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + + free(LocalEncapData->FvExtHeader); + LocalEncapData->FvExtHeader =3D NULL; + + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFil= eName)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation f= ailed! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileN= ame, 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, s= trlen(OutputFileName)+1); - - 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->FFSName =3D (char *)malloc(strlen(OutputFileN= ame)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fai= led! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileNam= e, strlen(OutputFileName)+1); + + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "G= enerate 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_SEC= TION_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", "Ge= nerate FV section failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } + Status =3D LibCreateFfsSection(NULL, InputFileName, NULL, EFI_S= ECTION_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", "= Generate FV section failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } =20 - // - // Make it alignment. - // - Status =3D LibCreateFfsSection(FvInFd, InputFileName, NULL, 0, Ou= tputFileName, 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"); + + // + // Make it alignment. + // + Status =3D LibCreateFfsSection(FvInFd, InputFileName, NULL, 0, = OutputFileName, 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; + } + + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFil= eName)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation f= ailed! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileN= ame, strlen(OutputFileName)+1); + + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "= Generate 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, s= trlen(OutputFileName)+1); - - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Ge= nerate 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, &(CurrentEnc= apData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ - FvInFd->FfsAttuibutes[Id].IsHandle =3D TRUE; - memcpy(OutputFileNameList->UiName, FvInFd->FfsAttuibutes[= Id].UiName, FvInFd->FfsAttuibutes[Id].UiNameSize); - OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[= Id].UiNameSize; - OutputFileNameList->FFSName =3D FvInFd->FfsAttuibutes[Id]= .FfsName; - OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[Id].D= epex; - 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].Fv= Id; - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - *OutputFile =3D OutputFileNameList; - return EFI_SUCCESS; - } + if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(CurrentEncap= Data->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ + FvInFd->FfsAttuibutes[Id].IsHandle =3D TRUE; + memcpy(OutputFileNameList->UiName, FvInFd->FfsAttuibutes[Id].= UiName, FvInFd->FfsAttuibutes[Id].UiNameSize); + OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[Id].= UiNameSize; + OutputFileNameList->FFSName =3D FvInFd->FfsAttuibutes[Id].Ffs= Name; + OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[Id].Depex= ; + OutputFileNameList->DepexLen =3D FvInFd->FfsAttuibutes[Id].De= pexLen; + 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; } + ParentLevel -=3D 1; =20 while (LocalEncapData->NextNode !=3D NULL) { --=20 2.16.2.windows.1