From a64b944942d828fe98e4843929662aad7f47bcca Mon Sep 17 00:00:00 2001 From: "Chen, Christine" Date: Thu, 28 Apr 2022 20:49:37 +0800 Subject: BaseTools: Add FMMT Python Tool The FMMT python tool is used for firmware files operation, which has the Fv/FFs-based 'View'&'Add'&'Delete'&'Replace' operation function: 1.Parse a FD(Firmware Device) / FV(Firmware Volume) / FFS(Firmware Files) 2.Add a new FFS into a FV file (both included in a FD file or not) 3.Replace an FFS in a FV file with a new FFS file 4.Delete an FFS in a FV file (both included in a FD file or not) 5.Extract the FFS from a FV file (both included in a FD file or not) This version of FMMT Python tool does not support PEIM rebase feature, this feature will be added in future update. Currently the FMMT C tool is saved in edk2-staging repo, but its quality and coding style can't meet the Edk2 quality, which is hard to maintain (Hard/Duplicate Code; Regression bugs; Restrict usage). The new Python version keeps same functions with origin C version. It has higher quality and better coding style, and it is much easier to extend new functions and to maintain. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1847 RFC Link: https://edk2.groups.io/g/devel/message/82877 Staging Link: https://github.com/tianocore/edk2-staging/tree/PyFMMT Cc: Bob Feng Cc: Liming Gao Signed-off-by: Yuwei Chen Reviewed-by: Bob Feng Acked-by: Liming Gao --- .../Source/Python/FMMT/utils/FvLayoutPrint.py | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 BaseTools/Source/Python/FMMT/utils/FvLayoutPrint.py (limited to 'BaseTools/Source/Python/FMMT/utils/FvLayoutPrint.py') diff --git a/BaseTools/Source/Python/FMMT/utils/FvLayoutPrint.py b/BaseTools/Source/Python/FMMT/utils/FvLayoutPrint.py new file mode 100644 index 0000000000..7dafcae3b5 --- /dev/null +++ b/BaseTools/Source/Python/FMMT/utils/FvLayoutPrint.py @@ -0,0 +1,55 @@ +## @file +# This file is used to define the printer for Bios layout. +# +# Copyright (c) 2021-, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## +from utils.FmmtLogger import FmmtLogger as logger + +def GetFormatter(layout_format: str): + if layout_format == 'json': + return JsonFormatter() + elif layout_format == 'yaml': + return YamlFormatter() + elif layout_format == 'html': + return HtmlFormatter() + else: + return TxtFormatter() + +class Formatter(object): + def dump(self, layoutdict, layoutlist, outputfile: str=None) -> None: + raise NotImplemented + +class JsonFormatter(Formatter): + def dump(self,layoutdict: dict, layoutlist: list, outputfile: str=None) -> None: + try: + import json + except: + TxtFormatter().dump(layoutdict, layoutlist, outputfile) + return + print(outputfile) + if outputfile: + with open(outputfile,"w") as fw: + json.dump(layoutdict, fw, indent=2) + else: + print(json.dumps(layoutdict,indent=2)) + +class TxtFormatter(Formatter): + def LogPrint(self,layoutlist: list) -> None: + for item in layoutlist: + print(item) + print('\n') + + def dump(self,layoutdict: dict, layoutlist: list, outputfile: str=None) -> None: + logger.info('Binary Layout Info is saved in {} file.'.format(outputfile)) + with open(outputfile, "w") as f: + for item in layoutlist: + f.writelines(item + '\n') + +class YamlFormatter(Formatter): + def dump(self,layoutdict, layoutlist, outputfile = None): + TxtFormatter().dump(layoutdict, layoutlist, outputfile) + +class HtmlFormatter(Formatter): + def dump(self,layoutdict, layoutlist, outputfile = None): + TxtFormatter().dump(layoutdict, layoutlist, outputfile) \ No newline at end of file -- cgit v1.2.3