From nobody Mon Apr 29 12:47:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+68034+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+68034+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1606441104; cv=none; d=zohomail.com; s=zohoarc; b=c4Qi999hxDh9GFLdBnFn773sxGvEccLAJ0aqwK52gjepmrQBP+jj3mHrkiSpRPzj/k/4VoMsqsC62g1fFeAffy2HjKFfHH14WamvRxjjHAAW4APVd0+anDM0Emr/wMa/iJJIx8uPs9D+7NzzfoZ83NubX6e3rfo+nwJW7mZPCOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606441104; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=Gc1AT35Y2BhuKtMHcNIZx78Lk7MWgz4MA1DBiZDryA8=; b=Sp+P1U7FbCgigsduXbGqB/da6FsMcG7U7TIkUfpN82laKa+TEc1E2QX4miJK7wZXmf20yB/Et8OfY3tvC28rRSbVfm9tJxdrXs1OHFXqi5//VYFlS7HW4LaH/bfqs8xHnY85e+nPG/67wOni5JL1vowi7FvZSADQlp+8VGDpT0k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+68034+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1606441104500778.9642427340119; Thu, 26 Nov 2020 17:38:24 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 62flYY1788612xFmZZsu18jV; Thu, 26 Nov 2020 17:38:24 -0800 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.13540.1606441102724484155 for ; Thu, 26 Nov 2020 17:38:22 -0800 IronPort-SDR: OoWyO5XlsdzUvpCrY4MSbbhI7o6knpXPtusfv9et+v/HEPkl2/a/VAEghW7AGSBbNaFL2HYUM3 BXZhWLoezAKQ== X-IronPort-AV: E=McAfee;i="6000,8403,9817"; a="152172502" X-IronPort-AV: E=Sophos;i="5.78,373,1599548400"; d="scan'208";a="152172502" 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 fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2020 17:38:22 -0800 IronPort-SDR: kyMjAoE+XnuKvxwImlrsQYSez8c/Lch7TbzF03cIRaGoCNuGov92LXhCwmx004c/zviTfyJGZd 8qLBIRB+1QDA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,373,1599548400"; d="scan'208";a="314166676" X-Received: from chinghux-desk1.gar.corp.intel.com ([10.5.215.141]) by fmsmga007.fm.intel.com with ESMTP; 26 Nov 2020 17:38:20 -0800 From: "GregX Yeh" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao Subject: [edk2-devel] [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when FV level over 2 Date: Fri, 27 Nov 2020 09:38:08 +0800 Message-Id: <20201127013808.9496-1-gregx.yeh@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,gregx.yeh@intel.com X-Gm-Message-State: kI7w6pDHQuNdco2HhAfikNswx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1606441104; bh=tFAhV6rQXULT4xNLiTOJtwTZ8JPqKJ7wuy8XYzBrnLU=; h=Cc:Date:From:Reply-To:Subject:To; b=Xwi/eY6eshVolaDslEQPNJVpdLSHItJDTDx5MgoBKiyNLRQtepKwTPrzKWu8QZJU2SD gDnbdvotVWIyEAGW8W35rhqaNMZBN9khvg10ImUUrh3stNxpoEwIHZ0LUfXRSi7bohG6g PN3QgxHCTBfOKoDT3RkdnbqVPNhwSNFVNGA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Fixed replace file failure when FFS in multi level FV and FV level over 2. Signed-off-by: GregX Yeh Cc: Bob Feng Cc: Liming Gao --- ...MMT-Replace-file-failure-when-FV-level-ov.patch | 456 ++++++++++++++ BaseTools/Source/C/FMMT/FirmwareModuleManagement.h | 4 +- BaseTools/Source/C/FMMT/FmmtLib.c | 654 ++++++++++-------= ---- 3 files changed, 782 insertions(+), 332 deletions(-) create mode 100644 0001-BaseTools-FMMT-Replace-file-failure-when-FV-level-= ov.patch diff --git a/0001-BaseTools-FMMT-Replace-file-failure-when-FV-level-ov.patc= h b/0001-BaseTools-FMMT-Replace-file-failure-when-FV-level-ov.patch new file mode 100644 index 0000000000..e42770c9e4 --- /dev/null +++ b/0001-BaseTools-FMMT-Replace-file-failure-when-FV-level-ov.patch @@ -0,0 +1,456 @@ +From eba4dd0899b011b0ac89723876be66a9d3f39251 Mon Sep 17 00:00:00 2001 +From: GregX Yeh +Date: Tue, 3 Nov 2020 10:57:00 +0800 +Subject: [PATCH] BaseTools/FMMT: Replace file failure when FV level over 2 + +Fixed replace file failure when FFS in multi level FV and FV level over 2. + +Signed-off-by: GregX Yeh +Cc: Bob Feng +Cc: Liming Gao +--- + BaseTools/Source/C/FMMT/FirmwareModuleManagement.c | 2 +- + BaseTools/Source/C/FMMT/FirmwareModuleManagement.h | 3 +- + BaseTools/Source/C/FMMT/FmmtLib.c | 171 ++++++++++++++--= ----- + 3 files changed, 118 insertions(+), 58 deletions(-) + +diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c b/BaseTool= s/Source/C/FMMT/FirmwareModuleManagement.c +index 38056153fb..dfad02838b 100644 +--- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c ++++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c +@@ -615,7 +615,7 @@ static UINT32 FindFile(FV_INFORMATION *FvInFd, UINT8 F= vLevel, CHAR8 *File, UINT3 + return 0; + } + LibAscii2Unicode(File, UIName); +- for (Index =3D 0; Index <=3D FvInFd->FfsNumbers; Index++) { ++ for (Index =3D 0; Index < FvInFd->FfsNumbers; Index++) { + // + // Compare the New File Name with UI Name of FFS + // NOTE: The UI Name is Unicode, but the New File Name is Ascii. +diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h b/BaseTool= s/Source/C/FMMT/FirmwareModuleManagement.h +index 9d09c9160a..da9eb1a4b9 100644 +--- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h ++++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h +@@ -2,7 +2,7 @@ +=20 + Structures and functions declaration. +=20 +- Copyright (c) 2019, Intel Corporation. All rights reserved.
++ Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +=20 + **/ +@@ -284,6 +284,7 @@ typedef struct _FFS_INFOMATION{ + UINT8 *Depex; + UINT32 DepexLen; + BOOLEAN FfsFoundFlag; ++ UINT8 FvLevel; + struct _FFS_INFOMATION *Next; + } FFS_INFORMATION; +=20 +diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/F= mmtLib.c +index b945e9b63d..9bccd634bb 100644 +--- a/BaseTools/Source/C/FMMT/FmmtLib.c ++++ b/BaseTools/Source/C/FMMT/FmmtLib.c +@@ -523,7 +523,7 @@ LibReadFvHeader ( + FvExtHeader->FvName.Data4[6], + FvExtHeader->FvName.Data4[7]); + LibExtractFvUiName(FvExtHeader, &FvUiName); +- if (FvUiName !=3D NULL && FvLevel =3D=3D 1) { ++ if (FvUiName !=3D NULL && (FvLevel - 1) !=3D 0) { + printf("%sFV UI Name: %s\n\n", BlankSpace, FvUiName); + } + free(FvUiName); +@@ -709,10 +709,10 @@ LibGenFfsFile ( + free(FfsFileName); + FfsFileName =3D NULL; +=20 +- CurrentFv->FfsNumbers =3D *FfsCount; +- + *FfsCount +=3D 1; +=20 ++ CurrentFv->FfsNumbers =3D *FfsCount; ++ + if (ErasePolarity) { + CurrentFile->State =3D (UINT8)~(CurrentFile->State); + } +@@ -789,7 +789,8 @@ LibParseSection ( + UINT8 *FvCount, + BOOLEAN ViewFlag, + BOOLEAN ErasePolarity, +- BOOLEAN *IsFfsGenerated ++ BOOLEAN *IsFfsGenerated, ++ UINT32 *FfsIndex + ) + { + UINT32 ParsedLength; +@@ -1147,19 +1148,21 @@ LibParseSection ( + return EFI_SECTION_ERROR; + } +=20 +- Status =3D LibParseSection ( UncompressedBuffer, +- UncompressedLength, +- CurrentFv, +- FvName, +- CurrentFile, +- Level, +- &LocalEncapData, +- FfsLevel, +- FfsCount, +- FvCount, +- ViewFlag, +- ErasePolarity, +- IsFfsGenerated); ++ Status =3D LibParseSection (UncompressedBuffer, ++ UncompressedLength, ++ CurrentFv, ++ FvName, ++ CurrentFile, ++ Level, ++ &LocalEncapData, ++ FfsLevel, ++ FfsCount, ++ FvCount, ++ ViewFlag, ++ ErasePolarity, ++ IsFfsGenerated, ++ FfsIndex ++ ); +=20 + if (CompressionType =3D=3D EFI_STANDARD_COMPRESSION) { + // +@@ -1216,7 +1219,8 @@ LibParseSection ( + FvCount, + ViewFlag, + ErasePolarity, +- IsFfsGenerated ++ IsFfsGenerated, ++ FfsIndex + ); + if (EFI_ERROR(Status)) { + Error(NULL, 0, 0003, "parse of decoded GUIDED section failed", = NULL); +@@ -1471,7 +1475,8 @@ LibParseSection ( + FvCount, + ViewFlag, + ErasePolarity, +- IsFfsGenerated ++ IsFfsGenerated, ++ FfsIndex + ); + if (EFI_ERROR (Status)) { + Error (NULL, 0, 0003, "parse of decoded GUIDED section failed",= NULL); +@@ -1491,7 +1496,8 @@ LibParseSection ( + FvCount, + ViewFlag, + ErasePolarity, +- IsFfsGenerated ++ IsFfsGenerated, ++ FfsIndex + ); + if (ExtractionTool !=3D NULL) { + free (ExtractionTool); +@@ -1527,6 +1533,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } +=20 +@@ -1538,6 +1545,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } +=20 +@@ -1549,6 +1557,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } +=20 +@@ -1560,6 +1569,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } + break; +@@ -1571,6 +1581,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } + break; +@@ -1582,6 +1593,7 @@ LibParseSection ( + if (!*IsFfsGenerated) { + LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, = ErasePolarity); + *IsFfsGenerated =3D TRUE; ++ *FfsIndex =3D *FfsCount; + } + } + break; +@@ -1665,11 +1677,11 @@ LibParseSection ( + // If Ffs file has been generated, then the FfsCount should decreas= e 1. + // + if (*IsFfsGenerated) { +- memcpy (CurrentFv->FfsAttuibutes[*FfsCount -1].UiName, UIName, UI= NameSize); +- CurrentFv->FfsAttuibutes[*FfsCount -1].UiNameSize =3D UINameSize; ++ memcpy (CurrentFv->FfsAttuibutes[*FfsIndex - 1].UiName, UIName, U= INameSize); ++ CurrentFv->FfsAttuibutes[*FfsIndex - 1].UiNameSize =3D UINameSize; + } else { +- memcpy (CurrentFv->FfsAttuibutes[*FfsCount].UiName, UIName, UINam= eSize); +- CurrentFv->FfsAttuibutes[*FfsCount].UiNameSize =3D UINameSize; ++ memcpy (CurrentFv->FfsAttuibutes[*FfsIndex].UiName, UIName, UINam= eSize); ++ CurrentFv->FfsAttuibutes[*FfsIndex].UiNameSize =3D UINameSize; + } +=20 + HasDepexSection =3D FALSE; +@@ -1682,7 +1694,9 @@ LibParseSection ( + } +=20 + ParsedLength +=3D SectionLength; +- FirstInFlag =3D FALSE; ++ if (Type !=3D EFI_SECTION_PEI_DEPEX && Type !=3D EFI_SECTION_DXE_DEPE= X) { ++ FirstInFlag =3D FALSE; ++ } + // + // We make then next section begin on a 4-byte boundary + // +@@ -1872,12 +1886,14 @@ LibGetFileInfo ( + BOOLEAN IsGeneratedFfs; + UINT32 FfsFileHeaderSize; + CHAR8 *BlankChar; ++ UINT32 FfsIndex; +=20 + Status =3D EFI_SUCCESS; +=20 + LocalEncapData =3D NULL; + EncapDataNeedUpdateFlag =3D TRUE; + IsGeneratedFfs =3D FALSE; ++ FfsIndex =3D 0xFFFFFFFF; + BlankChar =3D NULL; +=20 + FfsFileHeaderSize =3D GetFfsHeaderLength ((EFI_FFS_FILE_HEADER *) Curr= entFile); +@@ -2083,24 +2099,25 @@ LibGetFileInfo ( + } else if( CurrentFile->Type =3D=3D EFI_FV_FILETYPE_FFS_PAD){ + //EFI_FV_FILETYPE_FFS_PAD + } else { +- // +- // All other files have sections +- // +- Status =3D LibParseSection ( +- (UINT8 *) ((UINTN) CurrentFile + FfsFileHeaderSize), +- FileLength - FfsFileHeaderSize, +- CurrentFv, +- FvName, +- CurrentFile, +- Level, +- &LocalEncapData, +- Level, +- FfsCount, +- FvCount, +- ViewFlag, +- ErasePolarity, +- &IsGeneratedFfs +- ); ++ // ++ // All other files have sections ++ // ++ Status =3D LibParseSection ( ++ (UINT8 *) ((UINTN) CurrentFile + FfsFileHeaderSize), ++ FileLength - FfsFileHeaderSize, ++ CurrentFv, ++ FvName, ++ CurrentFile, ++ Level, ++ &LocalEncapData, ++ Level, ++ FfsCount, ++ FvCount, ++ ViewFlag, ++ ErasePolarity, ++ &IsGeneratedFfs, ++ &FfsIndex ++ ); + } + if (EFI_ERROR (Status)) { + printf ("ERROR: Parsing the FFS file.\n"); +@@ -2144,6 +2161,7 @@ LibGetFvInfo ( + EFI_FIRMWARE_VOLUME_EXT_HEADER *ExtHdrPtr; + EFI_FIRMWARE_VOLUME_HEADER *FvHdr; + UINT8 PreFvId; ++ UINT8 GuidBuffer[PRINTED_GUID_BUFFER_SIZE]; +=20 + NumberOfFiles =3D 0; + Key =3D 0; +@@ -2344,9 +2362,10 @@ LibGetFvInfo ( +=20 + CurrentFv->FfsAttuibutes[*FfsCount].FvLevel =3D CurrentFv->FvLevel; + CurrentFv->FfsAttuibutes[*FfsCount].FvId =3D PreFvId; +- if (CurrentFv->FvLevel > CurrentFv->MulFvLevel) { ++ if (CurrentFv->FvLevel > CurrentFv->MulFvLevel) { + CurrentFv->MulFvLevel =3D CurrentFv->FvLevel; +- } ++ } ++ PrintGuidToBuffer (&(CurrentFile->Name), GuidBuffer, PRINTED_GUID_BUF= FER_SIZE, FALSE); + // + // Display info about this file + // +@@ -4198,10 +4217,13 @@ LibEncapNewFvFile( + UINT32 header; + UINT8 AlignN; + UINT8 AlignV[1] =3D {0xFF}; ++ UINT32 EntryFvId; ++ + AlignN =3D 0; + Id =3D 0; + InputFileSize =3D 0; + TmpFileSize =3D 0; ++ AlignmentFileSize =3D 0; + EncapFvIndex =3D 0; + Index =3D 0; + OuterIndex =3D 0; +@@ -4224,7 +4246,7 @@ LibEncapNewFvFile( + IsLargeFile =3D FALSE; + OutputFileSize =3D 0; + LargeFileSize =3D 0x1000000; +- ++ EntryFvId =3D 0; +=20 + OutputFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION= )); + if (OutputFileNameList =3D=3D NULL) { +@@ -4240,6 +4262,7 @@ LibEncapNewFvFile( + OutputFileNameList->Depex =3D NULL; + OutputFileNameList->DepexLen =3D 0; + OutputFileNameList->FfsFoundFlag =3D FALSE; ++ OutputFileNameList->FvLevel =3D 0; +=20 + ChildFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION)= ); + if (ChildFileNameList =3D=3D NULL) { +@@ -4258,12 +4281,16 @@ LibEncapNewFvFile( + // + // Encapsulate from the lowest FFS file level. + // +- LocalEncapData =3D CurrentEncapData; +- if (LocalEncapData =3D=3D NULL) { +- LocalEncapData =3D FvInFd->EncapData; +- } +- Level =3D LocalEncapData->Level; +- Type =3D LocalEncapData->Type; ++ LocalEncapData =3D CurrentEncapData; ++ if (LocalEncapData =3D=3D NULL) { ++ LocalEncapData =3D FvInFd->EncapData; ++ EntryFvId =3D 0xFFFFFFFF; ++ } else { ++ EntryFvId =3D LocalEncapData->FvId; ++ } ++ ++ Level =3D LocalEncapData->Level; ++ Type =3D LocalEncapData->Type; +=20 + if (CurrentEncapData =3D=3D NULL) { + LocalEncapData =3D FvInFd->EncapData; +@@ -4278,6 +4305,7 @@ LibEncapNewFvFile( + ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Le= vel -1; + if (FvInFd->ChildFvFFS =3D=3D NULL) { + FvInFd->ChildFvFFS =3D ChildFileNameList; ++ NewFileNameList =3D FvInFd->ChildFvFFS; + } else { + NewFileNameList =3D FvInFd->ChildFvFFS; + while (NewFileNameList->Next !=3D NULL) { +@@ -4325,6 +4353,12 @@ LibEncapNewFvFile( + Type =3D LocalEncapData->Type; + } + LocalEncapData =3D LocalEncapData->NextNode; ++ if (LocalEncapData =3D=3D NULL) { ++ if (Type =3D=3D FMMT_ENCAP_TREE_FV) { ++ ParentLevel =3D Level; ++ ParentType =3D Type; ++ } ++ } + } + } else { + LocalEncapData =3D CurrentEncapData; +@@ -4349,6 +4383,28 @@ LibEncapNewFvFile( + LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; + } + } ++ ++ if (LocalEncapData->FvId > EntryFvId && LocalEncapData->Type =3D=3D= FMMT_ENCAP_TREE_FFS) { ++ LocalEncapDataTemp =3D LocalEncapData->RightNode; ++ ++ while (LocalEncapDataTemp !=3D NULL) { ++ LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; ++ if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNod= e !=3D NULL) { ++ LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEn= capDataTemp->Level - 1, &ChildFileNameList); ++ if (FvInFd->ChildFvFFS =3D=3D NULL) { ++ FvInFd->ChildFvFFS =3D ChildFileNameList; ++ } else { ++ NewFileNameList =3D FvInFd->ChildFvFFS; ++ while (NewFileNameList->Next !=3D NULL) { ++ NewFileNameList =3D NewFileNameList->Next; ++ } ++ NewFileNameList->Next =3D ChildFileNameList; ++ } ++ } ++ LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; ++ } ++ } ++ + if (LocalEncapData->Level > Level) { + if (LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_FFS) { + ParentLevel =3D Level; +@@ -4485,12 +4541,12 @@ LibEncapNewFvFile( + // + FfsFoundFlag =3D FALSE; + IsRootFv =3D FALSE; +- for (Index=3D0; Index <=3D FvInFd->FfsNumbers; Index++) { ++ for (Index=3D0; Index < FvInFd->FfsNumbers; Index++) { + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSNa= me !=3D NULL && OutputFileNameList->IsFFS =3D=3D FALSE){ + break; + } + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSNa= me !=3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE){ +- if (Index =3D=3D EncapFvIndex) { ++ if (Index =3D=3D EncapFvStart) { + if (FirstInFlag) { + Status =3D LibAddFfsFileToFvInf (OutputFileNa= meList->FFSName, InfFile, TRUE); + FirstInFlag =3D FALSE; +@@ -4601,7 +4657,7 @@ LibEncapNewFvFile( + } + } + // The Fv may has multiple level (> 2), when it is in the FvLevel = =3D=3D 2, we set the IsLastLevelFfs Flag +- if (Index <=3DFvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].F= vLevel <=3D FvInFd->MulFvLevel) { ++ if (Index < FvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].FvL= evel <=3D FvInFd->MulFvLevel) { + if (FvInFd->FfsAttuibutes[Index].FvLevel =3D=3D 2) { + IsLastLevelFfs =3D FALSE; + } +@@ -4777,6 +4833,7 @@ LibEncapNewFvFile( + for (Id =3D FvInFd->FfsNumbers; Id <=3D FvInFd->FfsNumbers; Id--= ) { + if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(LocalEnca= pData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ + if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) !=3D -1= ) { ++ OutputFileNameList->FvLevel =3D FvInFd->FfsAttuibute= s[Id].FvLevel; + Status =3D LibFmmtDeleteFile(FvInFd->FfsAttuibutes[I= d].FfsName); + if (EFI_ERROR(Status)) { + Error("FMMT", 0, 0004, "error while encapsulate = FD Image", "Delete the specified file failed!"); +@@ -5079,7 +5136,9 @@ LibEncapNewFvFile( + } else { + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSName != =3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE) { + *OutputFile =3D OutputFileNameList; +- return EFI_SUCCESS; ++ if (OutputFileNameList->FvLevel < 2) { ++ return EFI_SUCCESS; ++ } + } + LocalEncapData =3D CurrentEncapData; + } +--=20 +2.16.2.windows.1 + diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h b/BaseTools= /Source/C/FMMT/FirmwareModuleManagement.h index 9d09c9160a..ccc8ba00be 100644 --- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h +++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h @@ -195,7 +195,7 @@ typedef struct { // UI Name for this FFS file, if has. // CHAR16 UiName[_MAX_PATH]; - UINT32 UiNameSize; + UINT32 UiNameSize; // // Total section number in this FFS. // @@ -208,7 +208,7 @@ typedef struct { // //Describe the belong to FV // - UINT8 FvId; + UINT8 FvId; // // If this FFS has no encapsulate section, this flag will set to True. // diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/Fm= mtLib.c index b945e9b63d..d6d43030fa 100644 --- a/BaseTools/Source/C/FMMT/FmmtLib.c +++ b/BaseTools/Source/C/FMMT/FmmtLib.c @@ -709,10 +709,10 @@ LibGenFfsFile ( free(FfsFileName); FfsFileName =3D NULL; =20 - CurrentFv->FfsNumbers =3D *FfsCount; - *FfsCount +=3D 1; =20 + CurrentFv->FfsNumbers =3D *FfsCount; + if (ErasePolarity) { CurrentFile->State =3D (UINT8)~(CurrentFile->State); } @@ -833,7 +833,6 @@ LibParseSection ( CHAR8 *ToolInputFileName; CHAR8 *ToolOutputFileName; BOOLEAN HasUiSection; - BOOLEAN FirstInFlag; =20 DataOffset =3D 0; GuidAttr =3D 0; @@ -869,7 +868,6 @@ LibParseSection ( EncapDataNeedUpdata =3D TRUE; LargeHeaderOffset =3D 0; HasUiSection =3D FALSE; - FirstInFlag =3D TRUE; =20 =20 while (ParsedLength < BufferLength) { @@ -997,9 +995,7 @@ LibParseSection ( break; =20 case EFI_SECTION_COMPRESSION: - if (FirstInFlag) { - Level ++; - } + Level ++; NumberOfSections ++; =20 EncapDataNeedUpdata =3D TRUE; @@ -1181,9 +1177,7 @@ LibParseSection ( // looks up the appropriate tool to use for extracting // a GUID defined FV section. // - if (FirstInFlag) { - Level ++; - } + Level ++; NumberOfSections++; EncapDataNeedUpdata =3D TRUE; HasUiSection =3D TRUE; @@ -1682,7 +1676,6 @@ LibParseSection ( } =20 ParsedLength +=3D SectionLength; - FirstInFlag =3D FALSE; // // We make then next section begin on a 4-byte boundary // @@ -2016,7 +2009,7 @@ LibGetFileInfo ( =20 LocalEncapData->Level =3D Level; LocalEncapData->Type =3D FMMT_ENCAP_TREE_FFS; - LocalEncapData->FvExtHeader =3D NULL; + LocalEncapData->FvExtHeader =3D NULL; LocalEncapData->Depex =3D NULL; LocalEncapData->DepexLen =3D 0; LocalEncapData->UiNameSize =3D 0; @@ -4198,6 +4191,7 @@ LibEncapNewFvFile( UINT32 header; UINT8 AlignN; UINT8 AlignV[1] =3D {0xFF}; + =20 AlignN =3D 0; Id =3D 0; InputFileSize =3D 0; @@ -4225,7 +4219,6 @@ LibEncapNewFvFile( OutputFileSize =3D 0; LargeFileSize =3D 0x1000000; =20 - OutputFileNameList =3D (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION)= ); if (OutputFileNameList =3D=3D NULL) { Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n= ", ""); @@ -4258,12 +4251,12 @@ LibEncapNewFvFile( // // Encapsulate from the lowest FFS file level. // - LocalEncapData =3D CurrentEncapData; - if (LocalEncapData =3D=3D NULL) { - LocalEncapData =3D FvInFd->EncapData; - } - Level =3D LocalEncapData->Level; - Type =3D LocalEncapData->Type; + LocalEncapData =3D CurrentEncapData; + if (LocalEncapData =3D=3D NULL) { + LocalEncapData =3D FvInFd->EncapData; + } + Level =3D LocalEncapData->Level; + Type =3D LocalEncapData->Type; =20 if (CurrentEncapData =3D=3D NULL) { LocalEncapData =3D FvInFd->EncapData; @@ -4271,22 +4264,21 @@ LibEncapNewFvFile( if (LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_FFS) { LocalEncapDataTemp =3D LocalEncapData->RightNode; while (LocalEncapDataTemp !=3D NULL) { - LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; - if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNo= de !=3D NULL) { - - LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, 1, &= ChildFileNameList); - ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Lev= el -1; - if (FvInFd->ChildFvFFS =3D=3D NULL) { - FvInFd->ChildFvFFS =3D ChildFileNameList; - } else { - NewFileNameList =3D FvInFd->ChildFvFFS; - while (NewFileNameList->Next !=3D NULL) { - NewFileNameList =3D NewFileNameList->Next; - } - NewFileNameList->Next =3D ChildFileNameList; + LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; + if(LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNode = !=3D NULL) { + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEnc= apDataTemp->Level-1, &ChildFileNameList); + //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Level= -1; + if (FvInFd->ChildFvFFS =3D=3D NULL) { + FvInFd->ChildFvFFS =3D ChildFileNameList; + } else { + NewFileNameList =3D FvInFd->ChildFvFFS; + while (NewFileNameList->Next !=3D NULL) { + NewFileNameList =3D NewFileNameList->Next; } + NewFileNameList->Next =3D ChildFileNameList; } - LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; + } + LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; } } =20 @@ -4329,24 +4321,24 @@ LibEncapNewFvFile( } else { LocalEncapData =3D CurrentEncapData; while (LocalEncapData !=3D NULL) { - if (Level_Break > 1 && LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_F= FS) { + if (LocalEncapData->Type =3D=3D FMMT_ENCAP_TREE_FFS) { LocalEncapDataTemp =3D LocalEncapData->RightNode; while (LocalEncapDataTemp !=3D NULL) { - LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; - if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNo= de !=3D NULL) { - LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, Loca= lEncapDataTemp->Level-1, &ChildFileNameList); - //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->L= evel -1; - if (FvInFd->ChildFvFFS =3D=3D NULL) { - FvInFd->ChildFvFFS =3D ChildFileNameList; - } else { - NewFileNameList =3D FvInFd->ChildFvFFS; - while (NewFileNameList->Next !=3D NULL) { - NewFileNameList =3D NewFileNameList->Next; - } - NewFileNameList->Next =3D ChildFileNameList; + LocalEncapDataNext =3D LocalEncapDataTemp->NextNode; + if (LocalEncapDataNext !=3D NULL && LocalEncapDataNext->NextNode= !=3D NULL) { + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEnc= apDataTemp->Level-1, &ChildFileNameList); + //ChildFileNameList->ParentLevel =3D LocalEncapDataTemp->Level= -1; + if (FvInFd->ChildFvFFS =3D=3D NULL) { + FvInFd->ChildFvFFS =3D ChildFileNameList; + } else { + NewFileNameList =3D FvInFd->ChildFvFFS; + while (NewFileNameList->Next !=3D NULL) { + NewFileNameList =3D NewFileNameList->Next; } + NewFileNameList->Next =3D ChildFileNameList; } - LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; + } + LocalEncapDataTemp =3D LocalEncapDataTemp->RightNode; } } if (LocalEncapData->Level > Level) { @@ -4366,12 +4358,12 @@ LibEncapNewFvFile( case FMMT_ENCAP_TREE_FV: OutputFileNameListFlag =3D TRUE; EncapFvStart =3D 0; - for(OuterIndex=3D0;OutputFileNameListFlag;OuterIndex++){ + for(OuterIndex=3D0;OutputFileNameListFlag;OuterIndex++){ // // Generate FV.inf attributes. // InfFileName =3D LibFilenameStrExtended (strrchr(GenTempFile (),OS_= SEP), TemDir, "inf"); - FirstInFlag =3D TRUE; + FirstInFlag =3D TRUE; =20 InfFile =3D fopen (InfFileName, "wt+"); =20 @@ -4383,9 +4375,9 @@ LibEncapNewFvFile( } =20 if (CurrentEncapData =3D=3D NULL) { - LocalEncapData =3D FvInFd->EncapData; + LocalEncapData =3D FvInFd->EncapData; } else { - LocalEncapData =3D CurrentEncapData; + LocalEncapData =3D CurrentEncapData; } =20 while (LocalEncapData->NextNode !=3D NULL) { @@ -4456,6 +4448,7 @@ LibEncapNewFvFile( free (ChildFileNameList); return Status; } + if (LocalEncapData->FvExtHeader !=3D NULL) { Status =3D LibGenExtFile(LocalEncapData->FvExtHeader, InfFile); if (EFI_ERROR(Status)) { @@ -4473,93 +4466,93 @@ LibEncapNewFvFile( while (LocalEncapData->Level !=3D ParentLevel) { LocalEncapData =3D LocalEncapData->NextNode; } - for (Index =3D 0; Index <=3D FvInFd->FfsNumbers; Index++) { - if ((memcmp(&FvInFd->FfsAttuibutes[Index].GuidName, &(Loca= lEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)) { - SubFvId =3D Index; - break; - } + for (Index =3D 0; Index <=3D FvInFd->FfsNumbers; Index++) { + if ((memcmp(&FvInFd->FfsAttuibutes[Index].GuidName, &(LocalEnc= apData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)) { + SubFvId =3D Index; + break; } + } } // // Found FFSs from Fv structure. // FfsFoundFlag =3D FALSE; IsRootFv =3D FALSE; - for (Index=3D0; Index <=3D FvInFd->FfsNumbers; Index++) { - if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSNam= e !=3D NULL && OutputFileNameList->IsFFS =3D=3D FALSE){ - break; - } - if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSNam= e !=3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE){ - if (Index =3D=3D EncapFvIndex) { - if (FirstInFlag) { - Status =3D LibAddFfsFileToFvInf (OutputFileNam= eList->FFSName, InfFile, TRUE); - FirstInFlag =3D FALSE; - } else { - Status =3D LibAddFfsFileToFvInf (OutputFileNam= eList->FFSName, InfFile, FALSE); - } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsula= te FD Image", "Generate FV inf file [files] section failed!"); - fclose (InfFile); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - } + for (Index =3D 0; Index < FvInFd->FfsNumbers; Index++) { + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSName = !=3D NULL && OutputFileNameList->IsFFS =3D=3D FALSE){ + break; + } + if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSName = !=3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE){ + if (Index =3D=3D EncapFvIndex) { + if (FirstInFlag) { =20 + Status =3D LibAddFfsFileToFvInf (OutputFileNameList->FFSNa= me, InfFile, TRUE); + FirstInFlag =3D FALSE; + } else { + Status =3D LibAddFfsFileToFvInf (OutputFileNameList->FFSNa= me, InfFile, FALSE); + } + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image"= , "Generate FV inf file [files] section failed!"); + fclose (InfFile); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } } + } =20 - NewFileNameList =3D FvInFd->ChildFvFFS; - while (NewFileNameList !=3D NULL && NewFileNameList -> FFSName= !=3D NULL) { - if (NewFileNameList -> ParentLevel =3D=3D ParentLevel && I= ndex =3D=3D NewFileNameList->InFvId && NewFileNameList->FfsFoundFlag=3D=3DT= RUE) { - if (FirstInFlag) { - Status =3D LibAddFfsFileToFvInf (NewFileNameList->= FFSName, InfFile, TRUE); - FirstInFlag =3D FALSE; - } else { - Status =3D LibAddFfsFileToFvInf (NewFileNameList->= FFSName, InfFile, FALSE); - } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate F= D Image", "Generate FV inf file [files] section failed!"); - fclose (InfFile); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - NewFileNameList->FfsFoundFlag =3D FALSE; - } - NewFileNameList =3D NewFileNameList->Next; + NewFileNameList =3D FvInFd->ChildFvFFS; + while (NewFileNameList !=3D NULL && NewFileNameList -> FFSName != =3D NULL) { + if (NewFileNameList -> ParentLevel =3D=3D ParentLevel && Index= =3D=3D NewFileNameList->InFvId && NewFileNameList->FfsFoundFlag=3D=3DTRUE)= { + if (FirstInFlag) { + Status =3D LibAddFfsFileToFvInf (NewFileNameList->FFSName,= InfFile, TRUE); + FirstInFlag =3D FALSE; + } else { + Status =3D LibAddFfsFileToFvInf (NewFileNameList->FFSName,= InfFile, FALSE); + } + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image"= , "Generate FV inf file [files] section failed!"); + fclose (InfFile); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + NewFileNameList->FfsFoundFlag =3D FALSE; } + NewFileNameList =3D NewFileNameList->Next; + } =20 - if (FvInFd->FfsAttuibutes[Index].IsHandle=3D=3DTRUE) { - continue; - } - if (SubFvId > 0 && Index < SubFvId) { - continue; - } + if (FvInFd->FfsAttuibutes[Index].IsHandle=3D=3DTRUE) { + continue; + } + if (SubFvId > 0 && Index < SubFvId) { + continue; + } =20 // // For the last level FFS, the level below FFSs we should not ca= re the IsLeaf Flag. // if (IsLastLevelFfs) { IsLeafFlagIgnore =3D TRUE; - } else { - IsLeafFlagIgnore =3D FvInFd->FfsAttuibutes[Index].IsLeaf; - } + } else { + IsLeafFlagIgnore =3D FvInFd->FfsAttuibutes[Index].IsLeaf; + } =20 if (FvInFd->FfsAttuibutes[Index].FvId =3D=3D LocalEncapData->FvI= d && FvInFd->FfsAttuibutes[Index].Level >=3D ParentLevel + 1 && IsLeafFlag= Ignore) { if (FirstInFlag) { - if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) { - FfsFoundFlag =3D TRUE; - Status =3D LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Index].Ff= sName, InfFile, TRUE); - FirstInFlag =3D FALSE; - FvInFd->FfsAttuibutes[Index].IsHandle=3DTRUE; - EncapFvStart =3D Index; - } + if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) { + FfsFoundFlag =3D TRUE; + Status =3D LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Ind= ex].FfsName, InfFile, TRUE); + FirstInFlag =3D FALSE; + FvInFd->FfsAttuibutes[Index].IsHandle=3DTRUE; + EncapFvStart =3D Index; + } =20 if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Imag= e", "Generate FV inf file [files] section failed!"); - fclose (InfFile); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; + Error ("FMMT", 0, 0004, "error while encapsulate FD Image"= , "Generate FV inf file [files] section failed!"); + fclose (InfFile); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; } if (Index =3D=3D 0) { // Root FV need to include all FFS files. @@ -4586,33 +4579,32 @@ LibEncapNewFvFile( } =20 =20 - //avoid a FV contain too many ffs files - if ((!IsRootFv) && (FvInFd->FfsAttuibutes[Index].FvLevel <=3D F= vInFd->MulFvLevel) && (FvInFd->FfsAttuibutes[Index+1].FvLevel <=3D FvInFd->= MulFvLevel) && - (FvInFd->FfsAttuibutes[Index].FvLevel !=3D FvInFd->FfsAttui= butes[Index+1].FvLevel) && (ParentLevel !=3D 1) && (FvInFd->FfsAttuibutes[I= ndex].Level !=3D FvInFd->FfsAttuibutes[Index+1].Level) && - FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF && FvInFd->Ffs= Attuibutes[Index+1].Level !=3D 0xFF && FvInFd->FfsAttuibutes[Index+1].Level= !=3D 0x0){ - FvInFd->FfsAttuibutes[Index].Level =3D 0; - break; - }else{ - if (FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF){ - FvInFd->FfsAttuibutes[Index].Level =3D 0; - } - } - + //avoid a FV contain too many ffs files + if ((!IsRootFv) && (FvInFd->FfsAttuibutes[Index].FvLevel <=3D = FvInFd->MulFvLevel) && (FvInFd->FfsAttuibutes[Index+1].FvLevel <=3D FvInFd-= >MulFvLevel) && + (FvInFd->FfsAttuibutes[Index].FvLevel !=3D FvInFd->FfsAttuib= utes[Index+1].FvLevel) && (ParentLevel !=3D 1) && (FvInFd->FfsAttuibutes[In= dex].Level !=3D FvInFd->FfsAttuibutes[Index+1].Level) && + FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF && FvInFd->FfsA= ttuibutes[Index+1].Level !=3D 0xFF && FvInFd->FfsAttuibutes[Index+1].Level = !=3D 0x0){ + FvInFd->FfsAttuibutes[Index].Level =3D 0; + break; + } else { + if (FvInFd->FfsAttuibutes[Index].Level !=3D 0xFF){ + FvInFd->FfsAttuibutes[Index].Level =3D 0; + } } } - // The Fv may has multiple level (> 2), when it is in the FvLevel = =3D=3D 2, we set the IsLastLevelFfs Flag - if (Index <=3DFvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].Fv= Level <=3D FvInFd->MulFvLevel) { - if (FvInFd->FfsAttuibutes[Index].FvLevel =3D=3D 2) { - IsLastLevelFfs =3D FALSE; - } - } - if (!FfsFoundFlag){ - OutputFileNameListFlag =3D FALSE; - if (OuterIndex > 0){ - fclose (InfFile); - break; - } - } + } + // The Fv may has multiple level (> 2), when it is in the FvLevel = =3D=3D 2, we set the IsLastLevelFfs Flag + if (Index <=3DFvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].F= vLevel <=3D FvInFd->MulFvLevel) { + if (FvInFd->FfsAttuibutes[Index].FvLevel =3D=3D 2) { + IsLastLevelFfs =3D FALSE; + } + } + if (!FfsFoundFlag){ + OutputFileNameListFlag =3D FALSE; + if (OuterIndex > 0){ + fclose (InfFile); + break; + } + } // // Create FV // @@ -4631,15 +4623,15 @@ LibEncapNewFvFile( return Status; } =20 - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileName)+= 1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! = \n", ""); - return EFI_OUT_OF_RESOURCES; - } - memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, st= rlen(OutputFileName)+1); - if (CurrentEncapData !=3D NULL) { - OutputFileNameList->InFvId =3D EncapFvIndex; - if (EncapFvIndex > 0) { + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileNa= me)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fail= ed! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName= , strlen(OutputFileName)+1); + if (CurrentEncapData !=3D NULL) { + OutputFileNameList->InFvId =3D EncapFvIndex; + if (EncapFvIndex > 0) { memcpy(OutputFileNameList->UiName,FvInFd->FfsAttuibutes[EncapF= vIndex - 1].UiName, FvInFd->FfsAttuibutes[EncapFvIndex - 1].UiNameSize); OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[Encap= FvIndex - 1].UiNameSize; OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[EncapFvInd= ex - 1].Depex; @@ -4647,9 +4639,9 @@ LibEncapNewFvFile( OutputFileNameList->FfsFoundFlag =3D FfsFoundFlag; OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[EncapFvInde= x - 1].FvId; OutputFileNameList->ParentLevel =3D ParentLevel - 1; + } + } } - } - } break; case FMMT_ENCAP_TREE_FFS: =20 @@ -4662,13 +4654,13 @@ LibEncapNewFvFile( } while (LocalEncapData->NextNode !=3D NULL) { if (LocalEncapData->Level =3D=3D ParentLevel) { - for(;LocalEncapData->NextNode !=3D NULL;) { - if(LocalEncapData->FvExtHeader !=3D NULL) { - break; - } - LocalEncapData =3D LocalEncapData->NextNode; - } - break; + for(;LocalEncapData->NextNode !=3D NULL;) { + if(LocalEncapData->FvExtHeader !=3D NULL) { + break; + } + LocalEncapData =3D LocalEncapData->NextNode; + } + break; } LocalEncapData =3D LocalEncapData->NextNode; } @@ -4728,101 +4720,106 @@ LibEncapNewFvFile( InputFileName =3D TmpFileName; } if (OutputFileNameList->DepexLen > 0) { - TmpFileName =3D LibFilenameStrExtended(strrchr(GenTempFile (= ), OS_SEP), TemDir, "tmp"); - TmpFile =3D fopen(TmpFileName, "wb+"); - if (TmpFile =3D=3D NULL) { - Error("FMMT", 0, 0004, "Could not open tmp file %s to st= ore Depex section information! \n", ""); - free (OutputFileNameList); - free (ChildFileNameList); - return EFI_ABORTED; - } - InputFile =3D fopen(InputFileName, "rb+"); - if (InputFile =3D=3D NULL) { - Error("FMMT", 0, 0004, "Could not open input file %s! \n",= ""); + TmpFileName =3D LibFilenameStrExtended(strrchr(GenTempFile (),= OS_SEP), TemDir, "tmp"); + TmpFile =3D fopen(TmpFileName, "wb+"); + if (TmpFile =3D=3D NULL) { + Error("FMMT", 0, 0004, "Could not open tmp file %s to stor= e Depex section information! \n", ""); + free (OutputFileNameList); + free (ChildFileNameList); + return EFI_ABORTED; + } + InputFile =3D fopen(InputFileName, "rb+"); + if (InputFile =3D=3D NULL) { + Error("FMMT", 0, 0004, "Could not open input file %s! \n", "= "); + fclose(TmpFile); + free (OutputFileNameList); + free (ChildFileNameList); + return EFI_ABORTED; + } + fseek(InputFile, 0, SEEK_SET); + fseek(InputFile, 0, SEEK_END); + InputFileSize =3D ftell(InputFile); + fseek(InputFile, 0, SEEK_SET); + // make sure the section is 4 byte align + if (OutputFileNameList->DepexLen % 4 !=3D 0) { + AlignN =3D 4 - OutputFileNameList->DepexLen % 4; + } + Buffer =3D malloc(InputFileSize + OutputFileNameList->DepexLen= + AlignN); + memcpy(Buffer, OutputFileNameList->Depex, OutputFileNameList->= DepexLen); + if (AlignN !=3D 0) { + for (Index =3D 0; Index < AlignN; Index ++) { + memcpy(Buffer + OutputFileNameList->DepexLen + Index, = AlignV, 1); + } + } + if (fread(Buffer + OutputFileNameList->DepexLen + AlignN, 1, I= nputFileSize, InputFile) !=3D InputFileSize) { + Error("FMMT", 0, 0004, "Could not open sec file %s to add = Depex section information! \n", ""); fclose(TmpFile); + fclose(InputFile); + free(Buffer); free (OutputFileNameList); free (ChildFileNameList); return EFI_ABORTED; + } + fwrite(Buffer, 1, InputFileSize + OutputFileNameList->DepexLen= + AlignN, TmpFile); + free(Buffer); + fclose(TmpFile); + fclose(InputFile); + InputFileName =3D TmpFileName; + } + // + // Delete origin FFS + // + for (Id =3D FvInFd->FfsNumbers; Id <=3D FvInFd->FfsNumbers; Id--= ) { + if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(LocalEncapD= ata->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ + if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) !=3D -1) { + Status =3D LibFmmtDeleteFile(FvInFd->FfsAttuibutes[Id].Ffs= Name); + if (EFI_ERROR(Status)) { + Error("FMMT", 0, 0004, "error while encapsulate FD Ima= ge", "Delete the specified file failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + memset(FvInFd->FfsAttuibutes[Id].FfsName, '\0', _MAX_PATH); + FvInFd->FfsAttuibutes[Id].Level =3D 0xFF; + break; } - fseek(InputFile, 0, SEEK_SET); - fseek(InputFile, 0, SEEK_END); - InputFileSize =3D ftell(InputFile); - fseek(InputFile, 0, SEEK_SET); - // make sure the section is 4 byte align - if (OutputFileNameList->DepexLen % 4 !=3D 0) { - AlignN =3D 4 - OutputFileNameList->DepexLen % 4; - } - Buffer =3D malloc(InputFileSize + OutputFileNameList->DepexL= en + AlignN); - memcpy(Buffer, OutputFileNameList->Depex, OutputFileNameList= ->DepexLen); - if (AlignN !=3D 0) { - for (Index =3D 0; Index < AlignN; Index ++) { - memcpy(Buffer + OutputFileNameList->DepexLen + Index= , AlignV, 1); - } - } - if (fread(Buffer + OutputFileNameList->DepexLen + AlignN, 1,= InputFileSize, InputFile) !=3D InputFileSize) { - Error("FMMT", 0, 0004, "Could not open sec file %s to ad= d Depex section information! \n", ""); - fclose(TmpFile); - fclose(InputFile); - free(Buffer); - free (OutputFileNameList); - free (ChildFileNameList); - return EFI_ABORTED; - } - fwrite(Buffer, 1, InputFileSize + OutputFileNameList->DepexL= en + AlignN, TmpFile); - free(Buffer); - fclose(TmpFile); - fclose(InputFile); - InputFileName =3D TmpFileName; - } - for (Id =3D FvInFd->FfsNumbers; Id <=3D FvInFd->FfsNumbers; Id--)= { - if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(LocalEncap= Data->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ - if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) !=3D -1)= { - Status =3D LibFmmtDeleteFile(FvInFd->FfsAttuibutes[Id= ].FfsName); - if (EFI_ERROR(Status)) { - Error("FMMT", 0, 0004, "error while encapsulate F= D Image", "Delete the specified file failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - memset(FvInFd->FfsAttuibutes[Id].FfsName, '\0', _MAX_= PATH); - FvInFd->FfsAttuibutes[Id].Level =3D 0xFF; - break; - } - } - } - if (LocalEncapData->NextNode !=3D NULL) { - LocalEncapDataTemp =3D LocalEncapData->NextNode; - if ((LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_GUIDED_S= ECTION) || (LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_COMPRESS_SECTIO= N)) { - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMW= ARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeade= r->FvName, FALSE, "1"); - } - else{ - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMW= ARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeade= r->FvName, FALSE, FvInFd->AlignmentStr); - } - } - else{ - Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_= VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->F= vName, FALSE, FvInFd->AlignmentStr); - } - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gener= ate FFS file failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - free(LocalEncapData->FvExtHeader); - LocalEncapData->FvExtHeader =3D NULL; - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileName= )+1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation fail= ed! \n", ""); - return EFI_OUT_OF_RESOURCES; - } - memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, = strlen(OutputFileName)+1); - OutputFileNameList->IsFFS =3D TRUE; - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - if (OutputFileNameList->Next =3D=3D NULL){ - break; - } - OutputFileNameList =3D OutputFileNameList->Next; - } + } + } + if (LocalEncapData->NextNode !=3D NULL) { + LocalEncapDataTemp =3D LocalEncapData->NextNode; + if ((LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_GUIDED_SE= CTION) || (LocalEncapDataTemp->Type =3D=3D FMMT_ENCAP_TREE_COMPRESS_SECTION= )) { + Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE= _VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->= FvName, FALSE, "1"); + } else{ + Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE= _VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->= FvName, FALSE, FvInFd->AlignmentStr); + } + } else{ + Status =3D LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_V= OLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->Fv= Name, FALSE, FvInFd->AlignmentStr); + } + + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "G= enerate FFS file failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + =20 + free(LocalEncapData->FvExtHeader); + LocalEncapData->FvExtHeader =3D NULL; + =20 + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFile= Name)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fa= iled! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileNa= me, strlen(OutputFileName)+1); + OutputFileNameList->IsFFS =3D TRUE; + OutputFileNameList->ParentLevel =3D ParentLevel - 1; + OutputFileNameList->InFvId =3D Id; + if (OutputFileNameList->Next =3D=3D NULL){ + break; + } + OutputFileNameList =3D OutputFileNameList->Next; + } break; case FMMT_ENCAP_TREE_GUIDED_SECTION: while(OutputFileNameList!=3D NULL && OutputFileNameList->FFSName != =3D NULL){ @@ -4941,25 +4938,25 @@ LibEncapNewFvFile( if (OutputFileSize > LargeFileSize) { IsLargeFile =3D TRUE; } - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileName)+= 1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! = \n", ""); - return EFI_OUT_OF_RESOURCES; - } - memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, st= rlen(OutputFileName)+1); - - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gen= erate guided section failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileNa= me)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fail= ed! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName= , strlen(OutputFileName)+1); + =20 + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Ge= nerate guided section failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + OutputFileNameList->ParentLevel =3D ParentLevel - 1; + if (OutputFileNameList->Next =3D=3D NULL) { + break; + } + OutputFileNameList =3D OutputFileNameList->Next; } - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - if (OutputFileNameList->Next =3D=3D NULL){ - break; - } - OutputFileNameList =3D OutputFileNameList->Next; - } break; case FMMT_ENCAP_TREE_COMPRESS_SECTION: while(OutputFileNameList!=3D NULL && OutputFileNameList->FFSName != =3D NULL){ @@ -5000,89 +4997,86 @@ LibEncapNewFvFile( break; case FMMT_ENCAP_TREE_FV_SECTION: while(OutputFileNameList!=3D NULL && OutputFileNameList->FFSName != =3D NULL){ - InputFileName =3D OutputFileNameList->FFSName; - OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile (), = OS_SEP), TemDir, "sec"); - - Status =3D LibCreateFfsSection(NULL, InputFileName, NULL, EFI_SECT= ION_FIRMWARE_VOLUME_IMAGE, OutputFileName, NULL, NULL, NULL, 0, 0, NULL); + InputFileName =3D OutputFileNameList->FFSName; + OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile ()= , OS_SEP), TemDir, "sec"); =20 - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gen= erate FV section failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } + Status =3D LibCreateFfsSection(NULL, InputFileName, NULL, EFI_SE= CTION_FIRMWARE_VOLUME_IMAGE, OutputFileName, NULL, NULL, NULL, 0, 0, NULL); =20 - InputFileName =3D OutputFileName; - OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile (), = OS_SEP), TemDir, "sec"); + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "G= enerate FV section failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } =20 - // - // Make it alignment. - // - Status =3D LibCreateFfsSection(FvInFd, InputFileName, NULL, 0, Out= putFileName, NULL, NULL, NULL, 0, 0, NULL); - OutFile =3D fopen(OutputFileName, "rb+"); - if (OutFile =3D=3D NULL) { + InputFileName =3D OutputFileName; + OutputFileName=3D LibFilenameStrExtended (strrchr(GenTempFile ()= , OS_SEP), TemDir, "sec"); + =20 + // + // Make it alignment. + // + Status =3D LibCreateFfsSection(FvInFd, InputFileName, NULL, 0, O= utputFileName, NULL, NULL, NULL, 0, 0, NULL); + OutFile =3D fopen(OutputFileName, "rb+"); + if (OutFile =3D=3D NULL) { Error("FMMT", 0, 0004, "Could not open the file %s! \n", ""); free (OutputFileNameList); free (ChildFileNameList); return EFI_ABORTED; - } - fseek(OutFile, 0, SEEK_SET); - fseek(OutFile, 0, SEEK_END); - OutputFileSize =3D ftell(OutFile); - fclose(OutFile); - if (OutputFileSize > LargeFileSize) { + } + fseek(OutFile, 0, SEEK_SET); + fseek(OutFile, 0, SEEK_END); + OutputFileSize =3D ftell(OutFile); + fclose(OutFile); + if (OutputFileSize > LargeFileSize) { IsLargeFile =3D TRUE; + } + =20 + OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFile= Name)+1); + if (OutputFileNameList->FFSName =3D=3D NULL) { + Error ("FMMT", 0, 0004, "Out of resource, memory allocation fa= iled! \n", ""); + return EFI_OUT_OF_RESOURCES; + } + memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileNa= me, strlen(OutputFileName)+1); + =20 + if (EFI_ERROR (Status)) { + Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "G= enerate FV section failed!"); + free (OutputFileNameList); + free (ChildFileNameList); + return Status; + } + OutputFileNameList->ParentLevel =3D ParentLevel - 1; + if (OutputFileNameList->Next =3D=3D NULL){ + break; + } + OutputFileNameList =3D OutputFileNameList->Next; } - - OutputFileNameList->FFSName =3D (char *)malloc(strlen(OutputFileName)+= 1); - if (OutputFileNameList->FFSName =3D=3D NULL) { - Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! = \n", ""); - return EFI_OUT_OF_RESOURCES; - } - memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, st= rlen(OutputFileName)+1); - - if (EFI_ERROR (Status)) { - Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Gen= erate FV section failed!"); - free (OutputFileNameList); - free (ChildFileNameList); - return Status; - } - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - if (OutputFileNameList->Next =3D=3D NULL){ - break; - } - OutputFileNameList =3D OutputFileNameList->Next; - } break; default: for (Id =3D FvInFd->FfsNumbers; Id <=3D FvInFd->FfsNumbers; Id--) { - if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(CurrentEnca= pData->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ - FvInFd->FfsAttuibutes[Id].IsHandle =3D TRUE; - memcpy(OutputFileNameList->UiName, FvInFd->FfsAttuibutes[I= d].UiName, FvInFd->FfsAttuibutes[Id].UiNameSize); - OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[I= d].UiNameSize; - OutputFileNameList->FFSName =3D FvInFd->FfsAttuibutes[Id].= FfsName; - OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[Id].De= pex; - OutputFileNameList->DepexLen =3D FvInFd->FfsAttuibutes[Id]= .DepexLen; - OutputFileNameList->FfsFoundFlag =3D TRUE; - OutputFileNameList->IsFFS =3D TRUE; - OutputFileNameList->InFvId =3D Id; - OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[Id].FvI= d; - OutputFileNameList->ParentLevel =3D ParentLevel - 1; - *OutputFile =3D OutputFileNameList; - return EFI_SUCCESS; - } + if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(CurrentEncapD= ata->FvExtHeader->FvName), sizeof(EFI_GUID)) =3D=3D 0)){ + FvInFd->FfsAttuibutes[Id].IsHandle =3D TRUE; + memcpy(OutputFileNameList->UiName, FvInFd->FfsAttuibutes[Id].U= iName, FvInFd->FfsAttuibutes[Id].UiNameSize); + OutputFileNameList->UiNameSize =3D FvInFd->FfsAttuibutes[Id].U= iNameSize; + OutputFileNameList->FFSName =3D FvInFd->FfsAttuibutes[Id].FfsN= ame; + OutputFileNameList->Depex =3D FvInFd->FfsAttuibutes[Id].Depex; + OutputFileNameList->DepexLen =3D FvInFd->FfsAttuibutes[Id].Dep= exLen; + OutputFileNameList->FfsFoundFlag =3D TRUE; + OutputFileNameList->IsFFS =3D TRUE; + OutputFileNameList->InFvId =3D Id; + OutputFileNameList->FvId =3D FvInFd->FfsAttuibutes[Id].FvId; + OutputFileNameList->ParentLevel =3D ParentLevel - 1; + *OutputFile =3D OutputFileNameList; + return EFI_SUCCESS; + } } } =20 if (CurrentEncapData =3D=3D NULL) { LocalEncapData =3D FvInFd->EncapData; } else { - if (OutputFileNameList !=3D NULL && OutputFileNameList->FFSName != =3D NULL && OutputFileNameList->IsFFS =3D=3D TRUE) { - *OutputFile =3D OutputFileNameList; - return EFI_SUCCESS; - } LocalEncapData =3D CurrentEncapData; } + =20 ParentLevel -=3D 1; =20 while (LocalEncapData->NextNode !=3D NULL) { --=20 2.16.2.windows.1 -=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 (#68034): https://edk2.groups.io/g/devel/message/68034 Mute This Topic: https://groups.io/mt/78525275/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-