From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web08.4516.1666080931094848594 for ; Tue, 18 Oct 2022 01:15:31 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=T1HMBrwv; spf=pass (domain: intel.com, ip: 134.134.136.100, 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=1666080931; x=1697616931; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=CVUK8WshyzlJHpm5nCzkcDU9Ir+A8W/mHI3W40DQ7V8=; b=T1HMBrwvvReMjAUiQ5FheGIvpOWymBQomLevMFAQPwOHcry42qGFFEA6 oWgKAOByXBqn2yLr7RW4Wg3GDz6JNdC1V9LVYulkkDVrFW5xo8iZkPcAX B8GTuqaRQAuZvn6EF4niB+4M4TdhmdwCHkdPE17EAMoGV9jGt0HMAsZp/ pm5YTWkLMl83fu25cV2r7Ve7YoXgfHWNe6rDbOVj5hS+Y36emBrb+yDm8 KOTnUsMUzGasMupZUWa4qqQW7c5P598qLmc3QSh4OUo7mjlvlmFMS2cJs dOlgLl/oO/lKrlCh2gvTU9hFdJk/3UOLoxe8M43xZRqmYrz6xiUQrRwwI A==; X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="370235081" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="370235081" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 01:15:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="691694340" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="691694340" Received: from yuweipc.ccr.corp.intel.com ([10.239.158.38]) by fmsmga008.fm.intel.com with ESMTP; 18 Oct 2022 01:15:28 -0700 From: "Yuwei Chen" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao Subject: [PATCH] BaseTools: FMMT replace output file is not generated successfully Date: Tue, 18 Oct 2022 16:15:15 +0800 Message-Id: <20221018081515.138-1-yuwei.chen@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Bob Feng Cc: Liming Gao Signed-off-by: Yuwei Chen --- edk2basetools/FMMT/core/BiosTree.py | 4 ++-- edk2basetools/FMMT/core/FvHandler.py | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/edk2basetools/FMMT/core/BiosTree.py b/edk2basetools/FMMT/core/= BiosTree.py index ae889f6..14fb007 100644 --- a/edk2basetools/FMMT/core/BiosTree.py +++ b/edk2basetools/FMMT/core/BiosTree.py @@ -56,7 +56,7 @@ def insertChild(self, newNode, pos: int=3DNone) -> None: if len(self.Child) =3D=3D 0: self.Child.append(newNode) else: - if not pos: + if not pos or pos =3D=3D len(self.Child): LastTree =3D self.Child[-1] self.Child.append(newNode) LastTree.NextRel =3D newNode @@ -195,4 +195,4 @@ def ExportTree(self,TreeInfo: dict=3DNone) -> dict: for item in self.Child: TreeInfo[key].setdefault('Files',[]).append( item.ExportTree()) =20 - return TreeInfo=0D \ No newline at end of file + return TreeInfo diff --git a/edk2basetools/FMMT/core/FvHandler.py b/edk2basetools/FMMT/core= /FvHandler.py index dc303c2..25f0929 100644 --- a/edk2basetools/FMMT/core/FvHandler.py +++ b/edk2basetools/FMMT/core/FvHandler.py @@ -387,7 +387,21 @@ def ReplaceFfs(self) -> bool: if self.NewFfs.Data.Size >=3D self.TargetFfs.Data.Size: Needed_Space =3D 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 fr= ee space to NewFfs. - if TargetFv.Data.Free_Space >=3D Needed_Space: + if Needed_Space =3D=3D 0: + Target_index =3D 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 no= de data. + self.CompressData(TargetFv) + # return the Status + self.Status =3D True + elif TargetFv.Data.Free_Space >=3D Needed_Space: # Modify TargetFv Child info and BiosTree. TargetFv.Child[-1].Data.Data =3D b'\xff' * (TargetFv.Data.= Free_Space - Needed_Space) TargetFv.Data.Free_Space -=3D Needed_Space @@ -450,7 +464,6 @@ def ReplaceFfs(self) -> bool: Target_index =3D TargetFv.Child.index(self.TargetFfs) TargetFv.Child.remove(self.TargetFfs) TargetFv.insertChild(self.NewFfs, Target_index) - self.Status =3D True # If TargetFv do not have free space, create free space for Fv. else: New_Free_Space_Tree =3D BIOSTREE('FREE_SPACE') @@ -461,7 +474,6 @@ def ReplaceFfs(self) -> bool: Target_index =3D TargetFv.Child.index(self.TargetFfs) TargetFv.Child.remove(self.TargetFfs) TargetFv.insertChild(self.NewFfs, Target_index) - self.Status =3D True # Modify TargetFv Header and ExtHeader info. TargetFv.Data.ModFvExt() TargetFv.Data.ModFvSize() @@ -470,6 +482,7 @@ def ReplaceFfs(self) -> bool: TargetFv.Data.ModCheckSum() # Recompress from the Fv node to update all the related node d= ata. self.CompressData(TargetFv) + self.Status =3D True logger.debug('Done!') return self.Status =20 --=20 2.26.1.windows.1