BaseTools/Python: Replace GenFw with ImageTool

This commit is contained in:
Marvin Häuser 2023-04-30 19:06:40 +02:00 committed by Mikhail Krichanov
parent e446bbff25
commit d8937ed6df
6 changed files with 18 additions and 37 deletions

View File

@ -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
)

View File

@ -289,7 +289,7 @@ class EfiSection (EfiSectionClassObject):
StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')
GenFdsGlobalVariable.GenerateFirmwareImage(
StrippedFile,
[File],
File,
Strip=True,
IsMakefile = IsMakefile
)

View File

@ -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
)

View File

@ -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())

View File

@ -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()

View File

@ -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
#