From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.36344.1675067048677476027 for ; Mon, 30 Jan 2023 00:24:09 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=BVPVB+ew; spf=pass (domain: intel.com, ip: 134.134.136.20, 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=1675067048; x=1706603048; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gt20I50yuC7q0A9jGsCwwUVVpPoELwFi3hOigtTuckw=; b=BVPVB+ewKp3zsOpNKPvuCwWn2z1s31avfxdqvOcmB7hvyWMSf9xd6qgj ML63iAkR/Eg0zEU08jbPnEhgwg+UcUW19aMJirwiA7Ze2CeisuEYHln0n /qZFHnERXDlcjrDfamIXBDt+QY/nrkwG5wyepJLa2C/vfWKi+Vr/yzvGJ D6PIZiZ2/kc1zQVnEt2YlxyvTCPq6+5l64arN2BljpFvLNL5Bekf8EB7n /Zm5u+nvmZyasW+TT6QQ2wPl6OckcNqoNZGAiJzFpfYH1MRZv7eK7E612 mDgyX7azODjY906Um8B4nPMHMjXahfuYULGMK4qzGdDrnOibDqxh1QWMH g==; X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="315462685" X-IronPort-AV: E=Sophos;i="5.97,257,1669104000"; d="scan'208";a="315462685" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2023 00:24:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="837898477" X-IronPort-AV: E=Sophos;i="5.97,257,1669104000"; d="scan'208";a="837898477" Received: from yuweipc.ccr.corp.intel.com ([10.239.158.38]) by orsmga005.jf.intel.com with ESMTP; 30 Jan 2023 00:24:06 -0800 From: "Yuwei Chen" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao Subject: [Patch V1 1/2] BaseTools: Fix FMMT FvHandler replace status bug Date: Mon, 30 Jan 2023 16:24:03 +0800 Message-Id: <20230130082403.593-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 | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/edk2basetools/FMMT/core/BiosTree.py b/edk2basetools/FMMT/core/= BiosTree.py index ae889f68da..14fb007b14 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 dc303c2c44..0ce573091e 100644 --- a/edk2basetools/FMMT/core/FvHandler.py +++ b/edk2basetools/FMMT/core/FvHandler.py @@ -387,7 +387,22 @@ 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. # 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 +465,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 +475,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 +483,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.27.0.windows.1