From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web09.13498.1606441088580159405 for ; Thu, 26 Nov 2020 17:38:08 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=H2p86H/G; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: gregx.yeh@intel.com) IronPort-SDR: f4eztbQM9jIK6BKCPN4H8e2dc8/L6Vd0qi9edh4uwEM1uQjwc67drN6epGmq+7muM1gVUoEp7o CpHMiOmlCE7w== X-IronPort-AV: E=McAfee;i="6000,8403,9817"; a="190494775" X-IronPort-AV: E=Sophos;i="5.78,373,1599548400"; d="scan'208";a="190494775" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2020 17:38:07 -0800 IronPort-SDR: Zmb8MCSZQ/WpALxZsR1nQ9tUyLmU3grA+ktGZSzmnFOK0YTi5k7urbBJciVv3LG2AiCyzGj2S7 0RCg/xAbbwow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,373,1599548400"; d="scan'208";a="535902188" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by fmsmga006.fm.intel.com with ESMTP; 26 Nov 2020 17:38:07 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) 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; Thu, 26 Nov 2020 17:38:06 -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 17:38:06 -0800 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (104.47.37.53) 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 17:38:06 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DE5ULW5GKgqgDDYNZrSvGmdcWf0XB4HS32Kb3BcUskhFDrwNsIOkpCRjIg2dViDjs6sfwpKBYcaN1Ni94YQmmZDsuwCxQm1c1U0hLZ0Ot6TTQvE0WGsGgJG3GDaJmmBIZMolLRxmoEX/fHioDMJ1Jg/bNI5xUal3RSl95o8uULgUnTsyrTVvlY/8HSE8OMcltQzY8Ch1vo5DauAbwNZakmgeC9NGCTA0/nQIfIBbkcLRx7jSfa1C4aqpbn4VbiYqLtyL8GWYspyjhjbwJlnd3orHmbwaXUUjlyknfARyioNFOPyXrtHtJTwc3tObup7UgjFLd8GnqGTyaKnCX7ZzMA== 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=bFhN5zSF3wzNCBmht/ZyWx4Nk6uxFVWMcs2IYy+afHo=; b=Ui0MNVNVJOKopc8U5FnL+eOipsEPB6udGhSl+uWejV+TSmcPVZHG0W0TqhnqeLyE3mJ+W24+9RfjhOjwQsTuPJwRcwbdRtPaMg1kTKbK6gxm/Ayf8MzGHFcOUTHgacwASyQlvR9dJ0jrqNPptnswnSnEO3Fh28dXYGURlFRuPN7mVXJsPFa8k2tTMSbAJVpaiag3ja3xAdcl+hkoI3jvuVvrNCrrw9CTX6rnds06BfUgKMl27dzlpmAUoTSEbgeNIVnqsicDlKlWlwwHFh5NLQV0IFx8QvQFNfoVECJl+9II4AYKcPVcrrgUUglL07LGvx1EFOn3r8zr36KeSLF8bg== 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=bFhN5zSF3wzNCBmht/ZyWx4Nk6uxFVWMcs2IYy+afHo=; b=H2p86H/GTS7N7oXmZXRuCbUFdmFvrxZbAFpTQ+wgoTotesKNyciP/3P42Dp7V6C0dmbOHMm0GtNa5OhmiNPp8oL6B1w9nGxm9UrBhfOu2AZB6dpfgNjvIzX9Dj2+B+twKH2LwSafhx53At5QIgAXFukWD0+739GWu2H1F9u6fMk= Received: from BYAPR11MB3368.namprd11.prod.outlook.com (2603:10b6:a03:1b::13) by BYAPR11MB3637.namprd11.prod.outlook.com (2603:10b6:a03:f9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.21; Fri, 27 Nov 2020 01:38:04 +0000 Received: from BYAPR11MB3368.namprd11.prod.outlook.com ([fe80::6db6:f8b4:7402:8dd3]) by BYAPR11MB3368.namprd11.prod.outlook.com ([fe80::6db6:f8b4:7402:8dd3%6]) with mapi id 15.20.3589.025; Fri, 27 Nov 2020 01:38:04 +0000 From: "GregX Yeh" To: "Feng, Bob C" , "devel@edk2.groups.io" 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: AQHWw8LQa16epwIKF0St6bU792DL5qnbJ0yQgAAKpOA= Date: Fri, 27 Nov 2020 01:38:04 +0000 Message-ID: References: <20201126070701.14212-1-gregx.yeh@intel.com> In-Reply-To: Accept-Language: zh-TW, 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.52.220] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 05719e3a-a6e7-414b-b84f-08d8927515a5 x-ms-traffictypediagnostic: BYAPR11MB3637: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:655; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: KZ4OUF23eH1YBoUjwfelCTQ/iVGjBGiWXfqPQXH39tDgpKVQqmC3gjlSIv1TtWXL5rT6zZGA30NM9vzwkmq0E80kGglM/3FRbo7egBRAoFkwhdpuF0nGYmdIbcn+wl04G8ux89zPtII4CEbl93shO2KwQbFCHsgErBZMPVXd2JHHV+6j0dfenja2F248vYkPoWy3jRBxYJABhLw32YyAEMoRwVwD//6XByww453pCdOkMHYUOwwSCG/HPHXyJREzyvLuoSEpXR3YEQEvS1TzUe6aOs3VPtL9OGOcsnWYcMPeuodZ3FJGokg2D4KBdazyGDm4R0jvgPrS9KdEzlGrX4SXp4rJAKDKx5m9ty4hdLYDqsPMeQJZ0UeooPZoiIbOkgFF5Nh1Ei5QlAzf0odquQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR11MB3368.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(366004)(346002)(136003)(376002)(8936002)(2906002)(7696005)(8676002)(33656002)(6506007)(83380400001)(53546011)(186003)(26005)(110136005)(55016002)(9686003)(316002)(71200400001)(86362001)(66946007)(64756008)(66446008)(76116006)(4326008)(66476007)(66556008)(478600001)(30864003)(5660300002)(52536014)(966005)(559001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?jYp/A5m/y6Db2fxbHF5bQ4Lj9nhOhHAvjD/xMRUj2HuH5In6v0e/I9qyKamU?= =?us-ascii?Q?BVlPtGikWZ1SBu6v8Y4BkENUuxybntdM9jO969U8N1+DbU0VQKBv+tuuaffF?= =?us-ascii?Q?hj+/3zZTlLKUzlVu7vKINQVeJaQyGISVGvzgPLlt+xlAC9/A27xQUCi4pHWW?= =?us-ascii?Q?k3PRz1uhiuVvH6MfylM2tYnN20lqV9XPT2ExPdqWh9i8kwBm8HgFelakkHQE?= =?us-ascii?Q?iJRafh6CayZlp9YJcM7GRqO+RJvObbi6Z+j7pKQ6TaXn3FQM7fzKBtye15kl?= =?us-ascii?Q?WlE5x+abZBrfGeFgEdHUuNN3dAlI+lnXRSwfe2cHk+if9S6IGiwKkuFsBRlu?= =?us-ascii?Q?Ye+aET0TU0/7tDZOSxPQFKVBqHtlQpZ7W+BTuM/ZbJhfdc3ZLrTHSJryuB+R?= =?us-ascii?Q?ETjSHvER1sfCNbAG5Ml+2SojjkFzEQHn97N4mBuNG94p7ri8vV9uc/SEHgUu?= =?us-ascii?Q?xydmMIffdh/2phnqyhNjHMEWYZSEcAUtgcBDeDqJaTBmDiY9YgVhzaBl9Bk6?= =?us-ascii?Q?e6Y2drVbPpl6klLywpEg26K47d9AcDmRxerhsi30q7LEhUJibnHKdbdIjGT0?= =?us-ascii?Q?ppryqd1Zpa6yIbQIFOS3+KhRA+K+8sqg3OUVmlukOf6BokcVJLX4oaZcEKbt?= =?us-ascii?Q?dhD5G8YyKYPr9sGEO/8iXvwQv1Xesxj7olkVnFSLfKGCYzILQvic+Yt3cFoI?= =?us-ascii?Q?Vcqs+NLf9fL9JdVZFr4pb5jqA6M543wI+cTFZkYi5KW9Jv++EP0MWZNA5nhn?= =?us-ascii?Q?ui9NG4u3NqVIDW5tv7NKs5NczzXWx56UxQpnrAPrZAkYbAjUrgEADALTGyf9?= =?us-ascii?Q?Yi1qgLMc0vXZuNeGWnDL8CuKtc0+ZA3N6/xn0NdYqHinz3ofdbDzu+Xbg+vS?= =?us-ascii?Q?DQhPrU7v/v/FitY8ztRx9P4py3C7XigaMtdFS2jCJSS0oxFGLFJcpUJfSsLV?= =?us-ascii?Q?DRyfiyS7QwQG2EWLpKQIqkKE8tCW/wuOH2+MJWPK3Xg=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3368.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05719e3a-a6e7-414b-b84f-08d8927515a5 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Nov 2020 01:38:04.4026 (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: oMJY7fZ5oaziY4QFrjE7c+3ojxbv9eWtIEKrFq1tgo5Ph2AP6lZtq256uQPJf9hvW0Yo0Sr9AUjx3xAs2JyNrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3637 Return-Path: gregx.yeh@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Bob, Sorry for mistake patch. I will send correct patch. Greg =09 -----Original Message----- From: Feng, Bob C =20 Sent: Friday, November 27, 2020 8:53 AM To: devel@edk2.groups.io; Yeh, GregX Cc: Liming Gao Subject: RE: [edk2-devel] [PATCH] [edk2-staging] BaseTools/FMMT: Replace f= ile failure when FV level over 2 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