public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Bob Feng" <bob.c.feng@intel.com>
To: "Chen, Christine" <yuwei.chen@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Rebecca Cran <rebecca@bsdio.com>,
	"Gao, Liming" <gaoliming@byosoft.com.cn>
Subject: Re: [Patch V2 2/4] BaseTools: FMMT replace output file is not generated successfully
Date: Thu, 29 Jun 2023 06:56:26 +0000	[thread overview]
Message-ID: <PH7PR11MB58638ECB89E93024E7F2240DC925A@PH7PR11MB5863.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20230629033448.452-1-yuwei.chen@intel.com>

Reviewed-by: Bob Feng <bob.c.feng@Intel.com>

-----Original Message-----
From: Chen, Christine <yuwei.chen@intel.com> 
Sent: Thursday, June 29, 2023 11:35 AM
To: devel@edk2.groups.io
Cc: Rebecca Cran <rebecca@bsdio.com>; Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>
Subject: [Patch V2 2/4] BaseTools: FMMT replace output file is not generated successfully

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 <rebecca@bsdio.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
---
 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 d8fa4743354a..137f49748b09 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 b0cc1951a1c6..49bbc35baa4d 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.27.0.windows.1


      reply	other threads:[~2023-06-29  6:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-29  3:34 [Patch V2 2/4] BaseTools: FMMT replace output file is not generated successfully Yuwei Chen
2023-06-29  6:56 ` Bob Feng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PH7PR11MB58638ECB89E93024E7F2240DC925A@PH7PR11MB5863.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox