public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] BaseTools: FMMT replace output file is not generated successfully
@ 2022-10-18  8:15 Yuwei Chen
  0 siblings, 0 replies; only message in thread
From: Yuwei Chen @ 2022-10-18  8:15 UTC (permalink / raw)
  To: devel; +Cc: Bob Feng, Liming Gao

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 <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
---
 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=None) -> None:
         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 @@ def ExportTree(self,TreeInfo: dict=None) -> dict:
         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/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 >= 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 @@ def ReplaceFfs(self) -> bool:
                 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 @@ def ReplaceFfs(self) -> bool:
                 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 @@ def ReplaceFfs(self) -> bool:
             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.26.1.windows.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-18  8:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-18  8:15 [PATCH] BaseTools: FMMT replace output file is not generated successfully Yuwei Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox