From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.4679.1681811583215487683 for ; Tue, 18 Apr 2023 02:53:03 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=GJ3UX6yB; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: yuwei.chen@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681811583; x=1713347583; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=+FYCek21qLH4XIUvjK4TUH0dIRFAsjebRV5hxnwBeyo=; b=GJ3UX6yBAKmEsxC38CX/REp1SebAs/QBf6pGXzOMEL3ZWP4i0nkFVOCN F5pIL+4K3iFSqOLoIhkmxpepLXbZyXzQ+mjt2dZTLXSRcPiuCfgw6nAnP MMGvlcEMJ3Ff2wUnWu4Fea7yRqonpPVDxuqx6VraWi6SWGnM4cLnXX5Ly +xi5+SXSVDpMwtc3qZS0CYgrUtuzqQju5TlE1LQ7rBCWeg0GyCL9vFhzG Gyd1V1xY5PNeMaTxV9zCzK3QqJtC3tSAltVj5OFdgMG78QRjoWkCx0N+p lKa0pdSEN6C35cCtJZ/bJ50M9JwDsMZJLSy81V0LR0Io6+V3t3t/VR1kP w==; X-IronPort-AV: E=McAfee;i="6600,9927,10683"; a="408025237" X-IronPort-AV: E=Sophos;i="5.99,206,1677571200"; d="scan'208";a="408025237" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2023 02:53:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10683"; a="865315998" X-IronPort-AV: E=Sophos;i="5.99,206,1677571200"; d="scan'208";a="865315998" Received: from yuweipc.ccr.corp.intel.com ([10.239.158.38]) by orsmga005.jf.intel.com with ESMTP; 18 Apr 2023 02:53:00 -0700 From: "Yuwei Chen" To: devel@edk2.groups.io Cc: Rebecca Cran , Bob Feng , Liming Gao Subject: [Patch V1 2/3] BaseTools: FMMT replace output file is not generated successfully Date: Tue, 18 Apr 2023 17:52:57 +0800 Message-Id: <20230418095257.1602-1-yuwei.chen@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit For replace function, when target Ffs and new ffs are with same size, the output file can not be generated successfully. This patch fixes this issue. Cc: Rebecca Cran Cc: Bob Feng Cc: Liming Gao Signed-off-by: Yuwei Chen --- BaseTools/Source/Python/FMMT/core/BiosTree.py | 4 ++-- BaseTools/Source/Python/FMMT/core/FvHandler.py | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/FMMT/core/BiosTree.py b/BaseTools/Source/Python/FMMT/core/BiosTree.py index d8fa474335..137f49748b 100644 --- a/BaseTools/Source/Python/FMMT/core/BiosTree.py +++ b/BaseTools/Source/Python/FMMT/core/BiosTree.py @@ -56,7 +56,7 @@ class BIOSTREE: if len(self.Child) == 0: self.Child.append(newNode) else: - if not pos: + if not pos or pos == len(self.Child): LastTree = self.Child[-1] self.Child.append(newNode) LastTree.NextRel = newNode @@ -195,4 +195,4 @@ class BIOSTREE: for item in self.Child: TreeInfo[key].setdefault('Files',[]).append( item.ExportTree()) - return TreeInfo \ No newline at end of file + return TreeInfo diff --git a/BaseTools/Source/Python/FMMT/core/FvHandler.py b/BaseTools/Source/Python/FMMT/core/FvHandler.py index b0cc1951a1..49bbc35baa 100644 --- a/BaseTools/Source/Python/FMMT/core/FvHandler.py +++ b/BaseTools/Source/Python/FMMT/core/FvHandler.py @@ -387,7 +387,21 @@ class FvHandler: if self.NewFfs.Data.Size >= self.TargetFfs.Data.Size: Needed_Space = self.NewFfs.Data.Size + len(self.NewFfs.Data.PadData) - self.TargetFfs.Data.Size - len(self.TargetFfs.Data.PadData) # If TargetFv have enough free space, just move part of the free space to NewFfs. - if TargetFv.Data.Free_Space >= Needed_Space: + if Needed_Space == 0: + Target_index = TargetFv.Child.index(self.TargetFfs) + TargetFv.Child.remove(self.TargetFfs) + TargetFv.insertChild(self.NewFfs, Target_index) + # Modify TargetFv Header and ExtHeader info. + TargetFv.Data.ModFvExt() + TargetFv.Data.ModFvSize() + TargetFv.Data.ModExtHeaderData() + ModifyFvExtData(TargetFv) + TargetFv.Data.ModCheckSum() + # Recompress from the Fv node to update all the related node data. + self.CompressData(TargetFv) + # return the Status + self.Status = True + elif TargetFv.Data.Free_Space >= Needed_Space: # Modify TargetFv Child info and BiosTree. TargetFv.Child[-1].Data.Data = b'\xff' * (TargetFv.Data.Free_Space - Needed_Space) TargetFv.Data.Free_Space -= Needed_Space @@ -450,7 +464,6 @@ class FvHandler: Target_index = TargetFv.Child.index(self.TargetFfs) TargetFv.Child.remove(self.TargetFfs) TargetFv.insertChild(self.NewFfs, Target_index) - self.Status = True # If TargetFv do not have free space, create free space for Fv. else: New_Free_Space_Tree = BIOSTREE('FREE_SPACE') @@ -461,7 +474,6 @@ class FvHandler: Target_index = TargetFv.Child.index(self.TargetFfs) TargetFv.Child.remove(self.TargetFfs) TargetFv.insertChild(self.NewFfs, Target_index) - self.Status = True # Modify TargetFv Header and ExtHeader info. TargetFv.Data.ModFvExt() TargetFv.Data.ModFvSize() @@ -470,6 +482,7 @@ class FvHandler: TargetFv.Data.ModCheckSum() # Recompress from the Fv node to update all the related node data. self.CompressData(TargetFv) + self.Status = True logger.debug('Done!') return self.Status -- 2.39.1.windows.1