From d8937ed6dfe814050b3ae15ec36565cc7e174a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Ha=CC=88user?= <8659494+mhaeuser@users.noreply.github.com> Date: Sun, 30 Apr 2023 19:06:40 +0200 Subject: [PATCH] BaseTools/Python: Replace GenFw with ImageTool --- BaseTools/Source/Python/GenFds/DataSection.py | 2 +- BaseTools/Source/Python/GenFds/EfiSection.py | 2 +- .../Source/Python/GenFds/FfsInfStatement.py | 4 +-- .../Python/GenFds/GenFdsGlobalVariable.py | 31 ++++--------------- BaseTools/Source/Python/build/BuildReport.py | 6 ++-- BaseTools/Source/Python/build/build.py | 10 +++--- 6 files changed, 18 insertions(+), 37 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/DataSection.py b/BaseTools/Source/Python/GenFds/DataSection.py index 748910991c..61d162f31b 100644 --- a/BaseTools/Source/Python/GenFds/DataSection.py +++ b/BaseTools/Source/Python/GenFds/DataSection.py @@ -94,7 +94,7 @@ class DataSection (DataSectionClassObject): StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped') GenFdsGlobalVariable.GenerateFirmwareImage( StrippedFile, - [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)], + GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict), Strip=True, IsMakefile = IsMakefile ) diff --git a/BaseTools/Source/Python/GenFds/EfiSection.py b/BaseTools/Source/Python/GenFds/EfiSection.py index 99bd258856..34ce17224a 100644 --- a/BaseTools/Source/Python/GenFds/EfiSection.py +++ b/BaseTools/Source/Python/GenFds/EfiSection.py @@ -289,7 +289,7 @@ class EfiSection (EfiSectionClassObject): StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped') GenFdsGlobalVariable.GenerateFirmwareImage( StrippedFile, - [File], + File, Strip=True, IsMakefile = IsMakefile ) diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py index f6f50cd1c8..90ac443a02 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -786,7 +786,7 @@ class FfsInfStatement(FfsInfStatementClassObject): StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped') GenFdsGlobalVariable.GenerateFirmwareImage( StrippedFile, - [File], + File, Strip=True, IsMakefile=IsMakefile ) @@ -820,7 +820,7 @@ class FfsInfStatement(FfsInfStatementClassObject): StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped') GenFdsGlobalVariable.GenerateFirmwareImage( StrippedFile, - [GenSecInputFile], + GenSecInputFile, Strip=True, IsMakefile=IsMakefile ) diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py index d7668ba681..68faace90f 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -607,36 +607,17 @@ class GenFdsGlobalVariable: GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FV") @staticmethod - def GenerateFirmwareImage(Output, Input, Type="efi", SubType=None, Zero=False, - Strip=False, Replace=False, TimeStamp=None, Join=False, - Align=None, Padding=None, Convert=False, IsMakefile=False): + def GenerateFirmwareImage(Output, Input, Format="Auto", Strip=False, IsMakefile=False): if not GenFdsGlobalVariable.NeedsUpdate(Output, Input) and not IsMakefile: return GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input)) - Cmd = ["GenFw"] - if Type.lower() == "te": - Cmd.append("-t") - if SubType: - Cmd += ("-e", SubType) - if TimeStamp: - Cmd += ("-s", TimeStamp) - if Align: - Cmd += ("-a", Align) - if Padding: - Cmd += ("-p", Padding) - if Zero: - Cmd.append("-z") + Cmd = ["ImageTool GenImage"] + if Format != "Auto": + Cmd += ("-c", Format) if Strip: - Cmd.append("-l") - if Replace: - Cmd.append("-r") - if Join: - Cmd.append("-j") - if Convert: - Cmd.append("-m") - Cmd += ("-o", Output) - Cmd += Input + Cmd.append("-s") + Cmd += ("-o", Output, Input) if IsMakefile: if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList: GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip()) diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Source/Python/build/BuildReport.py index ca9cb1cd8d..2171f08691 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -639,11 +639,11 @@ class ModuleReport(object): if os.path.isfile(DefaultEFIfile): Tempfile = os.path.join(OutputDir, self.ModuleName + "_hash.tmp") # rebase the efi image since its base address may not zero - cmd = ["GenFw", "--rebase", str(0), "-o", Tempfile, DefaultEFIfile] + cmd = ["ImageTool GenImage -b 0 -o", Tempfile, DefaultEFIfile] try: PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) except Exception as X: - EdkLogger.error("GenFw", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0])) + EdkLogger.error("ImageTool", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0])) EndOfProcedure = threading.Event() EndOfProcedure.clear() if PopenObject.stderr: @@ -656,7 +656,7 @@ class ModuleReport(object): if PopenObject.stderr: StdErrThread.join() if PopenObject.returncode != 0: - EdkLogger.error("GenFw", COMMAND_FAILURE, "Failed to generate firmware hash image for %s" % (DefaultEFIfile)) + EdkLogger.error("ImageTool", COMMAND_FAILURE, "Failed to generate firmware hash image for %s" % (DefaultEFIfile)) if os.path.isfile(Tempfile): self.Hash = hashlib.sha1() buf = open(Tempfile, 'rb').read() diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py index 1390a62178..c47da87378 100755 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -1522,18 +1522,18 @@ class Build(): BaseAddress = BaseAddress - ModuleInfo.Image.Size BaseAddress = AlignDown(BaseAddress, ModuleInfo.Image.SectionAlignment) # - # Update Image to new BaseAddress by GenFw tool + # Update Image to new BaseAddress by ImageTool tool # - LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir) - LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir) + LaunchCommand(["ImageTool", "GenImage", "-b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.OutputDir) + LaunchCommand(["ImageTool", "GenImage", "-b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.DebugDir) ## for SMM module in SMRAM, the SMRAM will be allocated from base to top. else: BaseAddress = AlignUp(BaseAddress, ModuleInfo.Image.SectionAlignment) # # Set new address to the section header only for SMM driver. # - LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir) - LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir) + LaunchCommand(["ImageTool", "GenImage", "-f -b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.OutputDir) + LaunchCommand(["ImageTool", "GenImage", "-f -b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.DebugDir) # # Collect function address from Map file #