summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/FMMT/core/FMMTOperation.py
diff options
context:
space:
mode:
authorChen, Christine <Yuwei.Chen@intel.com>2022-09-16 09:50:56 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2022-10-19 06:32:07 +0000
commit0e6db46b1be173e7207bfadc05221a20f9b0dd02 (patch)
treefa22c572ee5c6e373d6dae753f67ee6a2122e7ef /BaseTools/Source/Python/FMMT/core/FMMTOperation.py
parentb03dceb87f400e2e5437f775427fab5338532ee7 (diff)
downloadedk2-0e6db46b1be173e7207bfadc05221a20f9b0dd02.tar.gz
edk2-0e6db46b1be173e7207bfadc05221a20f9b0dd02.tar.bz2
edk2-0e6db46b1be173e7207bfadc05221a20f9b0dd02.zip
BaseTools/FMMT: Add Extract FV function
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3938 With this patch "-e" parameter supports extract FV function. Usage: FMMT -e Inputfile TargetFv Outputfile Cc: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Signed-off-by: Yuwei Chen <yuwei.chen@intel.com> Reviewed-by: Bob Feng <bob.c.feng@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/FMMT/core/FMMTOperation.py')
-rw-r--r--BaseTools/Source/Python/FMMT/core/FMMTOperation.py45
1 files changed, 27 insertions, 18 deletions
diff --git a/BaseTools/Source/Python/FMMT/core/FMMTOperation.py b/BaseTools/Source/Python/FMMT/core/FMMTOperation.py
index c2cc2e2467..4e58c91b5c 100644
--- a/BaseTools/Source/Python/FMMT/core/FMMTOperation.py
+++ b/BaseTools/Source/Python/FMMT/core/FMMTOperation.py
@@ -63,9 +63,10 @@ def DeleteFfs(inputfile: str, TargetFfs_name: str, outputfile: str, Fv_name: str
FmmtParser.WholeFvTree.FindNode(TargetFfs_name, FmmtParser.WholeFvTree.Findlist)
# Choose the Specfic DeleteFfs with Fv info
if Fv_name:
- for item in FmmtParser.WholeFvTree.Findlist:
- if item.Parent.key != Fv_name and item.Parent.Data.Name != Fv_name:
- FmmtParser.WholeFvTree.Findlist.remove(item)
+ FindNum = len(FmmtParser.WholeFvTree.Findlist)
+ for index in range(FindNum-1, -1, -1):
+ if FmmtParser.WholeFvTree.Findlist[index].Parent.key != Fv_name and FmmtParser.WholeFvTree.Findlist[index].Parent.Data.Name != Fv_name:
+ FmmtParser.WholeFvTree.Findlist.remove(FmmtParser.WholeFvTree.Findlist[index])
Status = False
if FmmtParser.WholeFvTree.Findlist != []:
for Delete_Ffs in FmmtParser.WholeFvTree.Findlist:
@@ -149,9 +150,10 @@ def ReplaceFfs(inputfile: str, Ffs_name: str, newffsfile: str, outputfile: str,
new_ffs.Data.PadData = GetPadSize(new_ffs.Data.Size, FFS_COMMON_ALIGNMENT) * b'\xff'
FmmtParser.WholeFvTree.FindNode(Ffs_name, FmmtParser.WholeFvTree.Findlist)
if Fv_name:
- for item in FmmtParser.WholeFvTree.Findlist:
- if item.Parent.key != Fv_name and item.Parent.Data.Name != Fv_name:
- FmmtParser.WholeFvTree.Findlist.remove(item)
+ FindNum = len(FmmtParser.WholeFvTree.Findlist)
+ for index in range(FindNum-1, -1, -1):
+ if FmmtParser.WholeFvTree.Findlist[index].Parent.key != Fv_name and FmmtParser.WholeFvTree.Findlist[index].Parent.Data.Name != Fv_name:
+ FmmtParser.WholeFvTree.Findlist.remove(FmmtParser.WholeFvTree.Findlist[index])
if FmmtParser.WholeFvTree.Findlist != []:
for TargetFfs in FmmtParser.WholeFvTree.Findlist:
FfsMod = FvHandler(newFmmtParser.WholeFvTree.Child[0], TargetFfs)
@@ -180,18 +182,25 @@ def ExtractFfs(inputfile: str, Ffs_name: str, outputfile: str, Fv_name: str=None
logger.debug('Done!')
FmmtParser.WholeFvTree.FindNode(Ffs_name, FmmtParser.WholeFvTree.Findlist)
if Fv_name:
- for item in FmmtParser.WholeFvTree.Findlist:
- if item.Parent.key != Fv_name and item.Parent.Data.Name != Fv_name:
- FmmtParser.WholeFvTree.Findlist.remove(item)
+ FindNum = len(FmmtParser.WholeFvTree.Findlist)
+ for index in range(FindNum-1, -1, -1):
+ if FmmtParser.WholeFvTree.Findlist[index].Parent.key != Fv_name and FmmtParser.WholeFvTree.Findlist[index].Parent.Data.Name != Fv_name:
+ FmmtParser.WholeFvTree.Findlist.remove(FmmtParser.WholeFvTree.Findlist[index])
if FmmtParser.WholeFvTree.Findlist != []:
TargetNode = FmmtParser.WholeFvTree.Findlist[0]
- TargetFv = TargetNode.Parent
- if TargetFv.Data.Header.Attributes & EFI_FVB2_ERASE_POLARITY:
- TargetNode.Data.Header.State = c_uint8(
- ~TargetNode.Data.Header.State)
- FinalData = struct2stream(TargetNode.Data.Header) + TargetNode.Data.Data
- with open(outputfile, "wb") as f:
- f.write(FinalData)
- logger.debug('Extract ffs data is saved in {}.'.format(outputfile))
+ if TargetNode.type == FV_TREE or SEC_FV_TREE or DATA_FV_TREE:
+ FinalData = struct2stream(TargetNode.Data.Header) + TargetNode.Data.Data
+ with open(outputfile, "wb") as f:
+ f.write(FinalData)
+ logger.debug('Extract fv data is saved in {}.'.format(outputfile))
+ else:
+ TargetFv = TargetNode.Parent
+ if TargetFv.Data.Header.Attributes & EFI_FVB2_ERASE_POLARITY:
+ TargetNode.Data.Header.State = c_uint8(
+ ~TargetNode.Data.Header.State)
+ FinalData = struct2stream(TargetNode.Data.Header) + TargetNode.Data.Data
+ with open(outputfile, "wb") as f:
+ f.write(FinalData)
+ logger.debug('Extract ffs data is saved in {}.'.format(outputfile))
else:
- logger.error('Target Ffs not found!!!')
+ logger.error('Target Ffs/Fv not found!!!')