diff options
author | Chen, Christine <Yuwei.Chen@intel.com> | 2022-09-16 09:51:18 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2022-10-19 06:32:07 +0000 |
commit | 09e74b81ba7178588d4636762ffb852987f18525 (patch) | |
tree | f748b73b83394ef5bdf1a5ab4ec4a1d20c1403aa /BaseTools/Source/Python/FMMT/core/FMMTOperation.py | |
parent | 0e6db46b1be173e7207bfadc05221a20f9b0dd02 (diff) | |
download | edk2-09e74b81ba7178588d4636762ffb852987f18525.tar.gz edk2-09e74b81ba7178588d4636762ffb852987f18525.tar.bz2 edk2-09e74b81ba7178588d4636762ffb852987f18525.zip |
BaseTools/FMMT: Add Shrink Fv function
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3938
This function is used to remove the useless FV free space.
Usage: FMMT -s Inputfile 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.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/BaseTools/Source/Python/FMMT/core/FMMTOperation.py b/BaseTools/Source/Python/FMMT/core/FMMTOperation.py index 4e58c91b5c..a86f8dda9a 100644 --- a/BaseTools/Source/Python/FMMT/core/FMMTOperation.py +++ b/BaseTools/Source/Python/FMMT/core/FMMTOperation.py @@ -204,3 +204,29 @@ def ExtractFfs(inputfile: str, Ffs_name: str, outputfile: str, Fv_name: str=None logger.debug('Extract ffs data is saved in {}.'.format(outputfile))
else:
logger.error('Target Ffs/Fv not found!!!')
+
+def ShrinkFv(inputfile: str, outputfile: str) -> None:
+ if not os.path.exists(inputfile):
+ logger.error("Invalid inputfile, can not open {}.".format(inputfile))
+ raise Exception("Process Failed: Invalid inputfile!")
+ # 1. Data Prepare
+ with open(inputfile, "rb") as f:
+ whole_data = f.read()
+ FmmtParser = FMMTParser(inputfile, ROOT_TREE)
+ # 2. DataTree Create
+ logger.debug('Parsing inputfile data......')
+ FmmtParser.ParserFromRoot(FmmtParser.WholeFvTree, whole_data)
+ logger.debug('Done!')
+ TargetFv = FmmtParser.WholeFvTree.Child[0]
+ if TargetFv:
+ FvMod = FvHandler(TargetFv)
+ Status = FvMod.ShrinkFv()
+ else:
+ logger.error('Target Fv not found!!!')
+ # 4. Data Encapsulation
+ if Status:
+ logger.debug('Start encapsulating data......')
+ FmmtParser.Encapsulation(FmmtParser.WholeFvTree, False)
+ with open(outputfile, "wb") as f:
+ f.write(FmmtParser.FinalData)
+ logger.debug('Encapsulated data is saved in {}.'.format(outputfile))
|