From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.3200.1615341936729040701 for ; Tue, 09 Mar 2021 18:05:36 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: gregx.yeh@intel.com) IronPort-SDR: ab50UyPm7tiZEk/E6YchSsfGL5IfhW3A92Mby6TIrbnzWmtX948imxYoCY8XDH40jpCkylVyJ5 6GNVQFPO1mlA== X-IronPort-AV: E=McAfee;i="6000,8403,9917"; a="167637099" X-IronPort-AV: E=Sophos;i="5.81,236,1610438400"; d="scan'208";a="167637099" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2021 18:05:34 -0800 IronPort-SDR: 1g5N9umrNTQxOUmZ8HraUWdhjsZBx9upcXVwkjLkLBzmZUlq6igzFrTYKUDEki8P/X9pkj7Glv Xp7nQ/F6pG8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,236,1610438400"; d="scan'208";a="588650894" Received: from chinghux-desk1.gar.corp.intel.com ([10.5.215.141]) by orsmga005.jf.intel.com with ESMTP; 09 Mar 2021 18:05:33 -0800 From: "GregX Yeh" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao Subject: [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when FV level over 2 Date: Wed, 10 Mar 2021 10:05:28 +0800 Message-Id: <20210310020528.1924-1-gregx.yeh@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 Fixed replace file failure when FFS in multiple level FV and FV level over 2 Signed-off-by: GregX Yeh Cc: Bob Feng Cc: Liming Gao --- BaseTools/Source/C/FMMT/FmmtLib.c | 56 ++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/FmmtLib.c index b945e9b63d..26df0181c7 100644 --- a/BaseTools/Source/C/FMMT/FmmtLib.c +++ b/BaseTools/Source/C/FMMT/FmmtLib.c @@ -494,7 +494,7 @@ LibReadFvHeader ( if ((FvLevel -1) == 0) { printf ("\n%s :\n", FvName); } else { - printf ("%sChild FV named FV%d of %s\n", BlankSpace, FvCount, FvName); + printf ("\n%sChild FV named FV%d of %s\n", BlankSpace, FvCount, FvName); } } @@ -502,7 +502,7 @@ LibReadFvHeader ( // Print FV header information // if (ViewFlag) { - printf ("\n%sAttributes: %X\n", BlankSpace, (unsigned) VolumeHeader->Attributes); + printf ("%sAttributes: %X\n", BlankSpace, (unsigned) VolumeHeader->Attributes); printf ("%sTotal Volume Size: 0x%08X\n", BlankSpace, (unsigned) VolumeHeader->FvLength); printf ("%sFree Volume Size: 0x%08X\n", BlankSpace, (unsigned) (VolumeHeader->FvLength - GetFreeOffset(InputFv))); } @@ -789,7 +789,8 @@ LibParseSection ( UINT8 *FvCount, BOOLEAN ViewFlag, BOOLEAN ErasePolarity, - BOOLEAN *IsFfsGenerated + BOOLEAN *IsFfsGenerated, + BOOLEAN IsFfs ) { UINT32 ParsedLength; @@ -997,8 +998,12 @@ LibParseSection ( break; case EFI_SECTION_COMPRESSION: - if (FirstInFlag) { - Level ++; + if (IsFfs){ + Level ++; + } else { + if (FirstInFlag) { + Level ++; + } } NumberOfSections ++; @@ -1159,7 +1164,9 @@ LibParseSection ( FvCount, ViewFlag, ErasePolarity, - IsFfsGenerated); + IsFfsGenerated, + FALSE + ); if (CompressionType == EFI_STANDARD_COMPRESSION) { // @@ -1181,8 +1188,12 @@ LibParseSection ( // looks up the appropriate tool to use for extracting // a GUID defined FV section. // - if (FirstInFlag) { + if (IsFfs) { Level ++; + } else { + if (FirstInFlag) { + Level ++; + } } NumberOfSections++; EncapDataNeedUpdata = TRUE; @@ -1216,7 +1227,8 @@ LibParseSection ( FvCount, ViewFlag, ErasePolarity, - IsFfsGenerated + IsFfsGenerated, + FALSE ); if (EFI_ERROR(Status)) { Error(NULL, 0, 0003, "parse of decoded GUIDED section failed", NULL); @@ -1471,7 +1483,8 @@ LibParseSection ( FvCount, ViewFlag, ErasePolarity, - IsFfsGenerated + IsFfsGenerated, + FALSE ); if (EFI_ERROR (Status)) { Error (NULL, 0, 0003, "parse of decoded GUIDED section failed", NULL); @@ -1491,7 +1504,8 @@ LibParseSection ( FvCount, ViewFlag, ErasePolarity, - IsFfsGenerated + IsFfsGenerated, + FALSE ); if (ExtractionTool != NULL) { free (ExtractionTool); @@ -2016,7 +2030,7 @@ LibGetFileInfo ( LocalEncapData->Level = Level; LocalEncapData->Type = FMMT_ENCAP_TREE_FFS; - LocalEncapData->FvExtHeader = NULL; + LocalEncapData->FvExtHeader = NULL; LocalEncapData->Depex = NULL; LocalEncapData->DepexLen = 0; LocalEncapData->UiNameSize = 0; @@ -2099,7 +2113,8 @@ LibGetFileInfo ( FvCount, ViewFlag, ErasePolarity, - &IsGeneratedFfs + &IsGeneratedFfs, + TRUE ); } if (EFI_ERROR (Status)) { @@ -4198,10 +4213,13 @@ LibEncapNewFvFile( UINT32 header; UINT8 AlignN; UINT8 AlignV[1] = {0xFF}; + UINT32 EntryFvId; + AlignN = 0; Id = 0; InputFileSize = 0; TmpFileSize = 0; + AlignmentFileSize = 0; EncapFvIndex = 0; Index = 0; OuterIndex = 0; @@ -4224,7 +4242,7 @@ LibEncapNewFvFile( IsLargeFile = FALSE; OutputFileSize = 0; LargeFileSize = 0x1000000; - + EntryFvId = 0; OutputFileNameList = (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION)); if (OutputFileNameList == NULL) { @@ -4261,6 +4279,9 @@ LibEncapNewFvFile( LocalEncapData = CurrentEncapData; if (LocalEncapData == NULL) { LocalEncapData = FvInFd->EncapData; + EntryFvId = 0xFFFFFFFF; + } else { + EntryFvId = LocalEncapData->FvId; } Level = LocalEncapData->Level; Type = LocalEncapData->Type; @@ -4274,7 +4295,7 @@ LibEncapNewFvFile( LocalEncapDataNext = LocalEncapDataTemp->NextNode; if (LocalEncapDataNext != NULL && LocalEncapDataNext->NextNode != NULL) { - LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, 1, &ChildFileNameList); + LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp,LocalEncapDataTemp->Level - 1, &ChildFileNameList); ChildFileNameList->ParentLevel = LocalEncapDataTemp->Level -1; if (FvInFd->ChildFvFFS == NULL) { FvInFd->ChildFvFFS = ChildFileNameList; @@ -4329,7 +4350,7 @@ LibEncapNewFvFile( } else { LocalEncapData = CurrentEncapData; while (LocalEncapData != NULL) { - if (Level_Break > 1 && LocalEncapData->Type == FMMT_ENCAP_TREE_FFS) { + if ((LocalEncapData->FvId > EntryFvId) && (LocalEncapData->Type == FMMT_ENCAP_TREE_FFS)) { LocalEncapDataTemp = LocalEncapData->RightNode; while (LocalEncapDataTemp != NULL) { LocalEncapDataNext = LocalEncapDataTemp->NextNode; @@ -4818,6 +4839,7 @@ LibEncapNewFvFile( memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1); OutputFileNameList->IsFFS = TRUE; OutputFileNameList->ParentLevel = ParentLevel - 1; + OutputFileNameList->InFvId = Id; if (OutputFileNameList->Next == NULL){ break; } @@ -5077,10 +5099,6 @@ LibEncapNewFvFile( if (CurrentEncapData == NULL) { LocalEncapData = FvInFd->EncapData; } else { - if (OutputFileNameList != NULL && OutputFileNameList->FFSName != NULL && OutputFileNameList->IsFFS == TRUE) { - *OutputFile = OutputFileNameList; - return EFI_SUCCESS; - } LocalEncapData = CurrentEncapData; } ParentLevel -= 1; -- 2.16.2.windows.1