From nobody Mon Apr 29 09:34:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+60716+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60716+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159126242235613.654472110058236; Thu, 4 Jun 2020 02:20:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id cQ7fYY1788612xfvAnRoImoN; Thu, 04 Jun 2020 02:20:21 -0700 X-Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web10.10322.1591262420642671537 for ; Thu, 04 Jun 2020 02:20:21 -0700 IronPort-SDR: gB94X7hdLNO5UOSO3HhNLEvovCoASgpVZKZTXR+0ABdrrdhxhRr+XIUaxepkzOoxsTwNxaOl16 aQhRUBKRrodw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jun 2020 02:20:06 -0700 IronPort-SDR: bKuhN6O3SdYb678F+ltQfozVlshruk2BH/cG0Ulz8OYa+Xki6hhR2x3xli3tOxcp0i32HDZxDf MB7fEb1eXdGg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,471,1583222400"; d="scan'208";a="257679318" X-Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga007.fm.intel.com with ESMTP; 04 Jun 2020 02:20:06 -0700 X-Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 4 Jun 2020 02:20:05 -0700 X-Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 4 Jun 2020 02:20:05 -0700 X-Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Thu, 4 Jun 2020 02:20:04 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.171) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 4 Jun 2020 02:20:04 -0700 X-Received: from BN8PR11MB3793.namprd11.prod.outlook.com (2603:10b6:408:86::23) by BN8PR11MB3649.namprd11.prod.outlook.com (2603:10b6:408:84::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20; Thu, 4 Jun 2020 09:20:02 +0000 X-Received: from BN8PR11MB3793.namprd11.prod.outlook.com ([fe80::b10c:8c87:61fd:23c4]) by BN8PR11MB3793.namprd11.prod.outlook.com ([fe80::b10c:8c87:61fd:23c4%6]) with mapi id 15.20.3066.019; Thu, 4 Jun 2020 09:20:02 +0000 From: "Feng, YunhuaX" To: "devel@edk2.groups.io" CC: "Gao, Liming" , "Feng, Bob C" Subject: [edk2-devel] [PATCH] [edk2-staging]BaseTools/Fmmt: Replace FFS in FV include multiple GUID section Thread-Topic: [PATCH] [edk2-staging]BaseTools/Fmmt: Replace FFS in FV include multiple GUID section Thread-Index: AdY6UVCEwDP1gW4rTiu/fLoa8Livkw== Date: Thu, 4 Jun 2020 09:20:02 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.102.204.38] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8ee6226f-b029-47c2-b7db-08d808687609 x-ms-traffictypediagnostic: BN8PR11MB3649: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3631; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: sx/QOerPF5Luxl6GqOz/W1zSwW0h5utXf8qu3WY9vBw0KJfRZRueOXzQV7/PMNwOVVJI6UTmiVnaT0iyB0qniRrTMl9A5p+q0SGowjy3ourVzwIUN6SWKTSxiWM8eqC58QVpMISgBrQaDYCJOl9hV/TMFSnMURkVDrptVkgFbXxUH6cs17vMgagUIEjhX6VFakdPRzD9soYu+fV1EKz+6K9mqhbICWqwN1cOCESMJVUXBHLNp9yZIVl9vviidXBLITibTMwBMZik0IJ3dH1gPWztRokl/Yes0QFns7MyW77p3n66mJqhedO9LAugoakWupq2llju0H732c0kbHf0+Q== x-ms-exchange-antispam-messagedata: 1phBva8l0BaShYy1XI9z3trhm3ewoOhbZAMvHyVrW9xVzaCd3vZq+xaJbS9Y9h3QqYZh3oacW/JMxTm1b85nH0Wkz7/C5ILjTerp5w0lANChhUtWmn+1cHbXo04Ej5ToSPckmDHbubi9Wj9QF+eWEOzBYYkc1DsYP36+WL/9t3sASu2/m+9bo00fsj86rPhKGXT/oE6B/TThte16Rd0AChhHiURv+zC6/i4N7VYg2v9uPhruvwJdalvcHGAHC8JscyQvs6OJh3A54M/dfIM13Gsxq1BtkohBK2UMgyvt8OMe4uP6oxbbWIhIf1+j9KxYTVHL1SaJI+NhjW8eTt0ZumHgbAeqhUZZazxxpsTvdB6LEyNfhnxFs2UqSFeK7dXHdJbnr4E6lJwhbqnAPlu5yxthfDwcqOUi3+WphtA8bGLGnu/Cw32jQU6l3AYBTWL1sJ4zl/PHee+0JGecsm+qq2Qv1dlFf/5nyDQo+Vl/h3cMhUyLCIqnXzk9Sa78fUnj arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mslP9kMZGXmwbHO7UUFLqD6MsVNJqx49C5smD6P+RQ8T5CUwjsBJBKb7CiCGMGdNlTRmy4mS+xtfJuPdhoih24jbqMfL6W2pcD/qI1VQZfsrTK6OloUTq+yHU1MN8TdmtPRximkj0JBwnyA75FQegWDmMxBmaOCkLK23Ko+AeY8Xn9k2CTRM80/VQTYlCjhTAxh1SPh4RG/UuMdIoqDrKp4c+mqqrbTAROUYIXmGZEtikpwkmT2u4XIci+DNrSBzkm+ifWlb7gK3CWIKCIpYulv4gm+HQQ5sy4a6NEoOtwTbH+kw7hRIbQnc6i4bRG+bIN10dnWcGu6mWJHQa0yBtg== 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=HtbV5XJxQhxwyY3ThS+jkXTl/O6m7DLhHjliqN1aS4Q=; b=NTCvsob7OB+qgsjzUl8FmlHnWcdrqP0FWjvQUt2qowPIVL/oqpQsjFOZs2mwo92AqHVIgj7Els+qh4sb/cNn8r2xhKBz+6Wy4Yj6hImR7apiVnlqnXU9LzRdsfaqYFDe+9T/vK71+qQttqQYRXezNxeqpHx6ZOSMBsXnHm4/K06J6gek7V1RDoxlpIPoPOby6og0QZGBParbVotoPBdOkhRjwtJoNC4Otudoyx2wn2sDwLEl7hZecOmqFzDKv0JOuY1/mvyyIouAQIP6cSejMiXGqg5H51s8ag8F+mTSG70WF43mKIW0NqzcUQGtPUZjZY/HFbb4gGUlFuRi6qi39g== 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 x-ms-exchange-crosstenant-network-message-id: 8ee6226f-b029-47c2-b7db-08d808687609 x-ms-exchange-crosstenant-originalarrivaltime: 04 Jun 2020 09:20:02.0845 (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: V7ZsT98ppmJI3ofhQWW1uwD3ylzRjnNKda052dqTwbynu1YUvJtnznBBzLPOjRjhPK+ZLlzeTIyKqYuJt/aJhw== x-ms-exchange-transport-crosstenantheadersstamped: BN8PR11MB3649 MIME-Version: 1.0 X-OriginatorOrg: intel.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yunhuax.feng@intel.com X-Gm-Message-State: LouUalqKlR5C5FHYdDvFuGc3x1787277AA= Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591262421; bh=AN0ZufA3lJa0yUkSfRvmjx7ep6LgfxjpqfLkXrPa2MM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=JwPhSTcIFxL/HbfRhJasHRt550UGhvw7YbTpamr/6SkGan6k1HpIZMSJNXRlGkSlOD7 esJpzQvn848HlQJVlxAC9LlwOznCGS2bHqNeVyO5avv50VrGcZ0Mexgu3WSCp3Jcxcit9 ITTC+Qjly11yHANodVLhv0cVceM0lxlePNA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Fmmt replace case like as below: One Fv include one GUID section, and the GUID section include multiple sub GUID section. This patch will support the replace case. Change-Id: I78f015e00f2b73e4e0e9ee36d03d24c697783a9c Cc: Bob Feng Cc: Liming Gao Signed-off-by: Yunhua Feng --- BaseTools/Source/C/FMMT/FirmwareModuleManagement.h | 6 + BaseTools/Source/C/FMMT/FmmtLib.c | 206 +++++++++++++++++= ---- 2 files changed, 181 insertions(+), 31 deletions(-) diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h b/BaseTools= /Source/C/FMMT/FirmwareModuleManagement.h index 601682c2ad..9d09c9160a 100644 --- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h +++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h @@ -204,10 +204,14 @@ typedef struct { // // Describe the position of the FFS file. // UINT8 Level; // + //Describe the belong to FV + // + UINT8 FvId; + // // If this FFS has no encapsulate section, this flag will set to True. // BOOLEAN IsLeaf; // // Section type for each section in FFS. @@ -270,10 +274,11 @@ typedef struct __ENCAP_INFO_DATA{ } ENCAP_INFO_DATA; typedef struct _FFS_INFOMATION{ CHAR8 *FFSName; UINT32 InFvId; + UINT8 FvId; UINT8 ParentLevel; BOOLEAN IsFFS; CHAR16 UiName[_MAX_PATH]; UINT32 UiNameSize; UINT8 *Depex; @@ -299,10 +304,11 @@ typedef struct _FV_INFOMATION{ UINT8 FvLevel; CHAR8 *FvUiName; UINT8 MulFvLevel; CHAR8 AlignmentStr[16]; FFS_INFORMATION *ChildFvFFS; + FFS_INFORMATION *ChildGuid; } FV_INFORMATION; typedef struct _FIRMWARE_DEVICE { /// /// Size of FD file diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/Fm= mtLib.c index 401db5a48e..2c3529680e 100644 --- a/BaseTools/Source/C/FMMT/FmmtLib.c +++ b/BaseTools/Source/C/FMMT/FmmtLib.c @@ -167,10 +167,11 @@ LibInitializeFvStruct ( Fv->FfsAttuibutes[Index].Depex =3D NULL; Fv->FfsAttuibutes[Index].DepexLen =3D 0; Fv->FfsAttuibutes[Index].IsHandle =3D FALSE; Fv->FfsAttuibutes[Index].IsFvStart =3D FALSE; Fv->FfsAttuibutes[Index].IsFvEnd =3D FALSE; + Fv->FfsAttuibutes[Index].FvId =3D 0; } Fv->EncapData =3D NULL; Fv->FvNext =3D NULL; Fv->ChildFvFFS =3D NULL; @@ -830,10 +831,11 @@ LibParseSection ( UINT16 DataOffset; CHAR8 *UIFileName; CHAR8 *ToolInputFileName; CHAR8 *ToolOutputFileName; BOOLEAN HasUiSection; + BOOLEAN FirstInFlag; DataOffset =3D 0; GuidAttr =3D 0; ParsedLength =3D 0; ToolOutputLength =3D 0; @@ -865,10 +867,11 @@ LibParseSection ( ToolOutputFileFullName =3D NULL; HasDepexSection =3D FALSE; EncapDataNeedUpdata =3D TRUE; LargeHeaderOffset =3D 0; HasUiSection =3D FALSE; + FirstInFlag =3D TRUE; while (ParsedLength < BufferLength) { Ptr =3D SectionBuffer + ParsedLength; @@ -897,11 +900,13 @@ LibParseSection ( case EFI_SECTION_FIRMWARE_VOLUME_IMAGE: EncapDataNeedUpdata =3D TRUE; HasUiSection =3D TRUE; - Level ++; + if (FirstInFlag) { + Level ++; + } NumberOfSections ++; CurrentFv->FfsAttuibutes[*FfsCount].IsLeaf =3D FALSE; CurrentFv->FfsAttuibutes[*FfsCount].IsFvStart =3D TRUE; // @@ -992,11 +997,13 @@ LibParseSection ( CurrentFv->FfsAttuibutes[*FfsCount -1].IsFvEnd =3D TRUE; } break; case EFI_SECTION_COMPRESSION: - Level ++; + if (FirstInFlag) { + Level ++; + } NumberOfSections ++; EncapDataNeedUpdata =3D TRUE; HasUiSection =3D TRUE; // @@ -1027,10 +1034,11 @@ LibParseSection ( LocalEncapData =3D LocalEncapData->NextNode; LocalEncapData->Level =3D Level; LocalEncapData->Type =3D FMMT_ENCAP_TREE_COMPRESS_SECTION; + LocalEncapData->FvId =3D *FvCount; // // Store the compress type // LocalEncapData->Data =3D malloc (sizeof (UINT8)); @@ -1052,10 +1060,11 @@ LibParseSection ( } LocalEncapData =3D LocalEncapData->RightNode; LocalEncapData->Level =3D Level; LocalEncapData->Type =3D FMMT_ENCAP_TREE_COMPRESS_SECTION; + LocalEncapData->FvId =3D *FvCount; // // Store the compress type // LocalEncapData->Data =3D malloc (sizeof (UINT8)); @@ -1172,20 +1181,25 @@ LibParseSection ( // // Process GUID defined // looks up the appropriate tool to use for extracting // a GUID defined FV section. // - Level ++; + if (FirstInFlag) { + Level ++; + } NumberOfSections++; EncapDataNeedUpdata =3D TRUE; HasUiSection =3D TRUE; // // Put in encapsulate data information. // LocalEncapData =3D *CurrentFvEncapData; if (LocalEncapData->NextNode !=3D NULL) { EncapDataNeedUpdata =3D FALSE; + while (Level !=3D LocalEncapData->Level) { + LocalEncapData =3D LocalEncapData->NextNode; + } while (LocalEncapData->RightNode !=3D NULL) { LocalEncapData =3D LocalEncapData->RightNode; } } GuidAttr =3D ((EFI_GUID_DEFINED_SECTION *)(Ptr + LargeHeaderOffset))= ->Attributes; @@ -1237,10 +1251,11 @@ LibParseSection ( LocalEncapData->Level =3D Level; LocalEncapData->Type =3D FMMT_ENCAP_TREE_GUIDED_SECTION; LocalEncapData->Depex =3D NULL; LocalEncapData->DepexLen =3D 0; LocalEncapData->UiNameSize =3D 0; + LocalEncapData->FvId =3D *FvCount; // // We don't need additional data for encapsulate this FFS but type. // include DataOffset + Attributes // @@ -1269,10 +1284,11 @@ LibParseSection ( LocalEncapData->Level =3D Level; LocalEncapData->Type =3D FMMT_ENCAP_TREE_GUIDED_SECTION; LocalEncapData->Depex =3D NULL; LocalEncapData->DepexLen =3D 0; LocalEncapData->UiNameSize =3D 0; + LocalEncapData->FvId =3D *FvCount; // // We don't need additional data for encapsulate this FFS but type. // include DataOffset + Attributes // @@ -1508,10 +1524,13 @@ LibParseSection ( // //Leaf sections // case EFI_SECTION_RAW: + if (FirstInFlag) { + Level++; + } NumberOfSections ++; CurrentFv->FfsAttuibutes[*FfsCount].Level =3D Level; if (!ViewFlag) { if (!*IsFfsGenerated) { LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, E= rasePolarity); @@ -1669,10 +1688,11 @@ LibParseSection ( default: break; } ParsedLength +=3D SectionLength; + FirstInFlag =3D FALSE; // // We make then next section begin on a 4-byte boundary // ParsedLength =3D GetOccupiedSize (ParsedLength, 4); } @@ -1958,10 +1978,11 @@ LibGetFileInfo ( LocalEncapData->Type =3D FMMT_ENCAP_TREE_FFS; LocalEncapData->FvExtHeader =3D NULL; LocalEncapData->Depex =3D NULL; LocalEncapData->DepexLen =3D 0; LocalEncapData->UiNameSize =3D 0; + LocalEncapData->FvId =3D *FvCount; // // Store the header of FFS file. // LocalEncapData->Data =3D malloc (FfsFileHeaderSize); if (LocalEncapData->Data =3D=3D NULL) { @@ -2005,10 +2026,11 @@ LibGetFileInfo ( LocalEncapData->Type =3D FMMT_ENCAP_TREE_FFS; LocalEncapData->FvExtHeader =3D NULL; LocalEncapData->Depex =3D NULL; LocalEncapData->DepexLen =3D 0; LocalEncapData->UiNameSize =3D 0; + LocalEncapData->FvId =3D *FvCount; // // Store the header of FFS file. // LocalEncapData->Data =3D malloc (FfsFileHeaderSize); if (LocalEncapData->Data =3D=3D NULL) { @@ -2325,10 +2347,11 @@ LibGetFvInfo ( CurrentFv->FfsHeader[*FfsCount].Type =3D CurrentFile->Type; CurrentFv->FfsHeader[*FfsCount].ExtendedSize =3D CurrentFile->Exte= ndedSize; CurrentFv->FfsAttuibutes[*FfsCount].Offset =3D Key - GetFfsFileLength = ((EFI_FFS_FILE_HEADER *) CurrentFile); CurrentFv->FfsAttuibutes[*FfsCount].FvLevel =3D CurrentFv->FvLevel; + CurrentFv->FfsAttuibutes[*FfsCount].FvId =3D *FvCount; if (CurrentFv->FvLevel > CurrentFv->MulFvLevel) { CurrentFv->MulFvLevel =3D CurrentFv->FvLevel; } // // Display info about this file @@ -4170,20 +4193,23 @@ LibEncapNewFvFile( FILE *InputFile; FILE *OutFile; UINT32 InputFileSize; UINT32 OutputFileSize; UINT32 LargeFileSize; + UINT32 TmpFileSize; + UINT32 AlignmentFileSize; UINT8 *Buffer =3D NULL; UINT8 SectionHeader[4] =3D { 0x00, 0x00, 0x00, 0x0= 0 }; UINT32 Id; UINT32 SubFvId; UINT32 header; UINT8 AlignN; UINT8 AlignV[1] =3D {0xFF}; AlignN =3D 0; Id =3D 0; InputFileSize =3D 0; + TmpFileSize =3D 0; EncapFvIndex =3D 0; Index =3D 0; OuterIndex =3D 0; ParentType =3D 0; ParentLevel =3D 0; @@ -4204,11 +4230,11 @@ LibEncapNewFvFile( IsLargeFile =3D FALSE; OutputFileSize =3D 0; LargeFileSize =3D 0x1000000; - OutputFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FV_INFORMATION)); + OutputFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION)= ); if (OutputFileNameList =3D=3D NULL) { Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n= ", ""); return EFI_OUT_OF_RESOURCES; } OutputFileNameList->FFSName =3D NULL; @@ -4219,11 +4245,11 @@ LibEncapNewFvFile( OutputFileNameList->UiNameSize =3D 0; OutputFileNameList->Depex =3D NULL; OutputFileNameList->DepexLen =3D 0; OutputFileNameList->FfsFoundFlag =3D FALSE; - ChildFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FV_INFORMATION)); + ChildFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION)); if (ChildFileNameList =3D=3D NULL) { Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n= ", ""); return EFI_OUT_OF_RESOURCES; } ChildFileNameList->FFSName =3D NULL; @@ -4268,10 +4294,36 @@ LibEncapNewFvFile( } LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; } } + // + //One Fv include multiple GUIDED SECTION + // + if (LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_GUIDED_SECTION) { + LocalEncapDataTemp =3D LocalEncapData->RightNode; + while (LocalEncapDataTemp !=3D NULL) { + LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; + if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNode= !=3D NULL) { + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEnc= apDataTemp->Level-1, &ChildFileNameList); + ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Level -= 1; + ChildFileNameList->FfsFoundFlag =3D FALSE; + ChildFileNameList->InFvId =3D 0; + if (FvInFd->ChildGuid =3D=3D NULL) { + FvInFd->ChildGuid =3D ChildFileNameList; + } else { + NewFileNameList =3D FvInFd->ChildGuid; + 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; ParentType =3D Type; } @@ -4281,19 +4333,39 @@ LibEncapNewFvFile( LocalEncapData =3D LocalEncapData->NextNode; } } else { LocalEncapData =3D CurrentEncapData; while (LocalEncapData !=3D NULL) { - if (LocalEncapData->Level > Level) { - if (LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_FFS) { - ParentLevel =3D Level; - ParentType =3D Type; + if (LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_FFS) { + LocalEncapDataTemp =3D LocalEncapData->RightNode; + while (LocalEncapDataTemp !=3D NULL) { + LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; + if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNo= de !=3D NULL) { + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, Loca= lEncapDataTemp->Level-1, &ChildFileNameList); + //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->L= evel -1; + if (FvInFd->ChildFvFFS =3D=3D NULL) { + FvInFd->ChildFvFFS =3D ChildFileNameList; + } else { + NewFileNameList =3D FvInFd->ChildFvFFS; + while (NewFileNameList->Next !=3D NULL) { + NewFileNameList =3D NewFileNameList->Next; + } + NewFileNameList->Next =3D ChildFileNameList; + } } - Level =3D LocalEncapData->Level; - Type =3D LocalEncapData->Type; + LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; } - LocalEncapData =3D LocalEncapData->NextNode; + } + if (LocalEncapData->Level > Level) { + if (LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_FFS) { + ParentLevel =3D Level; + ParentType =3D Type; + } + Level =3D LocalEncapData->Level; + Type =3D LocalEncapData->Type; + } + LocalEncapData =3D LocalEncapData->NextNode; } } do { switch (ParentType) { @@ -4401,12 +4473,16 @@ LibEncapNewFvFile( } FvGuidName =3D NULL; } if (CurrentEncapData !=3D NULL) { + LocalEncapData =3D CurrentEncapData; + while (LocalEncapData->Level !=3D ParentLevel) { + LocalEncapData =3D LocalEncapData->NextNode; + } for (Index =3D 0; Index <=3D FvInFd->FfsNumbers; Index++) { - if ((memcmp(&FvInFd->FfsAttuibutes[Index].GuidName, &(Curr= entEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)) { + if ((memcmp(&FvInFd->FfsAttuibutes[Index].GuidName, &(Loca= lEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)) { SubFvId =3D Index; break; } } } @@ -4437,11 +4513,11 @@ LibEncapNewFvFile( } } NewFileNameList =3D FvInFd->ChildFvFFS; while (NewFileNameList !=3D NULL && NewFileNameList -> FFSName= !=3D NULL) { - if (NewFileNameList -> ParentLevel =3D=3D ParentLevel && I= ndex =3D=3D NewFileNameList->InFvId && NewFileNameList->FfsFoundFlag=3D=3DT= RUE) { + if (NewFileNameList->FvId =3D=3D LocalEncapData->FvId && N= ewFileNameList -> ParentLevel =3D=3D ParentLevel && Index =3D=3D NewFileNam= eList->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); @@ -4451,10 +4527,11 @@ LibEncapNewFvFile( fclose (InfFile); free (OutputFileNameList); free (ChildFileNameList); return Status; } + NewFileNameList->FfsFoundFlag =3D FALSE; } NewFileNameList =3D NewFileNameList->Next; } if (FvInFd->FfsAttuibutes[Index].IsHandle=3D=3DTRUE) { @@ -4471,11 +4548,11 @@ LibEncapNewFvFile( IsLeafFlagIgnore =3D TRUE; } else { IsLeafFlagIgnore =3D FvInFd->FfsAttuibutes[Index].IsLeaf; } - if (FvInFd->FfsAttuibutes[Index].Level >=3D ParentLevel + 1 && I= sLeafFlagIgnore) { + if (FvInFd->FfsAttuibutes[Index].FvId =3D=3D LocalEncapData->FvI= d && FvInFd->FfsAttuibutes[Index].Level >=3D ParentLevel + 1 && IsLeafFlag= Ignore) { if (FirstInFlag) { if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) { FfsFoundFlag =3D TRUE; Status =3D LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Index].Ff= sName, InfFile, TRUE); FirstInFlag =3D FALSE; @@ -4493,28 +4570,28 @@ LibEncapNewFvFile( if (Index =3D=3D 0) { // Root FV need to include all FFS files. IsRootFv =3D TRUE; } } else { - if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) { - FfsFoundFlag =3D TRUE; - Status =3D LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Index].Ff= sName, InfFile, FALSE); - FvInFd->FfsAttuibutes[Index].IsHandle=3DTRUE; - } + if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) { + FfsFoundFlag =3D TRUE; + Status =3D LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Ind= ex].FfsName, InfFile, FALSE); + FvInFd->FfsAttuibutes[Index].IsHandle=3DTRUE; + } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Imag= e", "Generate FV inf file [files] section failed!"); - fclose (InfFile); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - if (Index =3D=3D 0) { - // Root FV need to include all FFS files. - IsRootFv =3D TRUE; - } + 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; } + if (Index =3D=3D 0) { + // Root FV need to include all FFS files. + IsRootFv =3D TRUE; + } + } //avoid a FV contain too many ffs files if ((!IsRootFv) && (FvInFd->FfsAttuibutes[Index].FvLevel <=3D F= vInFd->MulFvLevel) && (FvInFd->FfsAttuibutes[Index+1].FvLevel <=3D FvInFd->= MulFvLevel) && (FvInFd->FfsAttuibutes[Index].FvLevel !=3D FvInFd->FfsAttui= butes[Index+1].FvLevel) && (ParentLevel !=3D 1) && (FvInFd->FfsAttuibutes[I= ndex].Level !=3D FvInFd->FfsAttuibutes[Index+1].Level) && @@ -4572,10 +4649,12 @@ LibEncapNewFvFile( memcpy(OutputFileNameList->UiName,FvInFd->FfsAttuibutes[EncapF= vIndex - 1].UiName, FvInFd->FfsAttuibutes[EncapFvIndex - 1].UiNameSize); OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[Encap= FvIndex - 1].UiNameSize; OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[EncapFvInd= ex - 1].Depex; OutputFileNameList->DepexLen =3D FvInFd->FfsAttuibutes[EncapFv= Index - 1].DepexLen; OutputFileNameList->FfsFoundFlag =3D FfsFoundFlag; + OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[EncapFvInde= x - 1].FvId; + OutputFileNameList->ParentLevel =3D ParentLevel - 1; } } } break; case FMMT_ENCAP_TREE_FFS: @@ -4742,10 +4821,11 @@ LibEncapNewFvFile( Error ("FMMT", 0, 0004, "Out of resource, memory allocation fail= ed! \n", ""); return EFI_OUT_OF_RESOURCES; } memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, = strlen(OutputFileName)+1); OutputFileNameList->IsFFS =3D TRUE; + OutputFileNameList->ParentLevel =3D ParentLevel - 1; if (OutputFileNameList->Next =3D=3D NULL){ break; } OutputFileNameList =3D OutputFileNameList->Next; } @@ -4754,10 +4834,69 @@ LibEncapNewFvFile( while(OutputFileNameList!=3D NULL && OutputFileNameList->FFSName != =3D NULL){ // // Create the guided section original data, do compress operation. // InputFileName =3D OutputFileNameList->FFSName; + // + //Fv include multiple Guided section + // + if (CurrentEncapData =3D=3D NULL && FvInFd->ChildGuid !=3D NULL) { + NewFileNameList =3D FvInFd->ChildGuid; + while (NewFileNameList !=3D NULL) { + if (NewFileNameList->FFSName !=3D NULL && NewFileNameList->Par= entLevel =3D=3D ParentLevel) { + InputFile =3D fopen(InputFileName, "rb+"); + if (InputFile =3D=3D NULL) { + Error("FMMT", 0, 0004, "Could not open input file %s! \n",= InputFileName); + return EFI_ABORTED; + } + fseek(InputFile, 0, SEEK_SET); + fseek(InputFile, 0, SEEK_END); + InputFileSize =3D ftell(InputFile); + fseek(InputFile, 0, SEEK_SET); + TmpFile =3D fopen(NewFileNameList->FFSName, "rb+"); + if (TmpFile =3D=3D NULL) { + Error("FMMT", 0, 0004, "Could not open input file %s! \n",= NewFileNameList->FFSName); + return EFI_ABORTED; + } + fseek(TmpFile, 0, SEEK_SET); + fseek(TmpFile, 0, SEEK_END); + TmpFileSize =3D ftell(TmpFile); + fseek(TmpFile, 0, SEEK_SET); + // + //Guided section need 4 bytes alignment + // + AlignmentFileSize =3D (InputFileSize + 3) & (UINT32)~3; + Buffer =3D malloc(AlignmentFileSize + TmpFileSize); + // + //Alignment filled 00 + // + memset(Buffer, 0, AlignmentFileSize+ TmpFileSize); + if (fread (Buffer, 1, InputFileSize, InputFile) !=3D InputFi= leSize) { + Error("FMMT", 0, 0004, "Could not open guided file %s to a= dd GUIDED section information! \n", InputFileName); + fclose(InputFile); + fclose(TmpFile); + free (Buffer); + return EFI_ABORTED; + } + fseek(InputFile, 0, SEEK_SET); + if (fread (Buffer + AlignmentFileSize, 1, TmpFileSize, TmpFi= le) !=3D TmpFileSize) { + Error("FMMT", 0, 0004, "Could not open guided file %s to a= dd GUIDED section information! \n", NewFileNameList->FFSName); + fclose(InputFile); + fclose(TmpFile); + free (Buffer); + return EFI_ABORTED; + } + fwrite(Buffer, 1, AlignmentFileSize + TmpFileSize, InputFile= ); + free(NewFileNameList->FFSName); + NewFileNameList->FFSName =3D NULL; + free(Buffer); + fclose(TmpFile); + fclose(InputFile); + } + NewFileNameList =3D NewFileNameList->Next; + } + } OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile (), = OS_SEP), TemDir, "compressed"); // // Use the guided section header guid to find out compress applica= tion name. // @@ -4819,10 +4958,11 @@ LibEncapNewFvFile( Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gen= erate 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; } @@ -4855,10 +4995,11 @@ LibEncapNewFvFile( Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "G= enerate compressed section failed!"); free (OutputFileNameList); free (ChildFileNameList); return Status; } + OutputFileNameList->ParentLevel =3D ParentLevel - 1; if (OutputFileNameList->Next =3D=3D NULL){ break; } OutputFileNameList =3D OutputFileNameList->Next; } @@ -4910,10 +5051,11 @@ LibEncapNewFvFile( Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gen= erate FV section failed!"); free (OutputFileNameList); free (ChildFileNameList); return Status; } + OutputFileNameList->ParentLevel =3D ParentLevel - 1; if (OutputFileNameList->Next =3D=3D NULL){ break; } OutputFileNameList =3D OutputFileNameList->Next; } @@ -4928,10 +5070,12 @@ LibEncapNewFvFile( OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[Id].De= pex; OutputFileNameList->DepexLen =3D FvInFd->FfsAttuibutes[Id]= .DepexLen; OutputFileNameList->FfsFoundFlag =3D TRUE; OutputFileNameList->IsFFS =3D TRUE; OutputFileNameList->InFvId =3D Id; + OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[Id].FvI= d; + OutputFileNameList->ParentLevel =3D ParentLevel - 1; *OutputFile =3D OutputFileNameList; return EFI_SUCCESS; } } } -- 2.12.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#60716): https://edk2.groups.io/g/devel/message/60716 Mute This Topic: https://groups.io/mt/74667780/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-