summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
diff options
context:
space:
mode:
authorYonghong Zhu <yonghong.zhu@intel.com>2017-11-22 15:42:25 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2017-12-05 09:26:22 +0800
commit37de70b764200718cc39a21abc491c335e3da7b3 (patch)
tree153e7a4fca9fe8edad1a8e730ba9a3791b8e612e /BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
parentb37b108d92aa08cc7eed5f52feea53b0e7563068 (diff)
downloadedk2-37de70b764200718cc39a21abc491c335e3da7b3.tar.gz
edk2-37de70b764200718cc39a21abc491c335e3da7b3.tar.bz2
edk2-37de70b764200718cc39a21abc491c335e3da7b3.zip
BaseTools: Update Makefile to support FFS file generation
Update Makefile to support FFS file generation with new build option --genfds-multi-thread. Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com> Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py')
-rw-r--r--BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py174
1 files changed, 141 insertions, 33 deletions
diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
index 83996beeea..371d5a8217 100644
--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
@@ -69,6 +69,11 @@ class GenFdsGlobalVariable:
ToolChainFamily = "MSFT"
__BuildRuleDatabase = None
GuidToolDefinition = {}
+ FfsCmdDict = {}
+ SecCmdList = []
+ CopyList = []
+ ModuleFile = ''
+ EnableGenfdsMultiThread = False
#
# The list whose element are flags to indicate if large FFS or SECTION files exist in FV.
@@ -264,6 +269,10 @@ class GenFdsGlobalVariable:
SourceList.extend(Target.Outputs)
LastTarget = Target
FileType = DataType.TAB_UNKNOWN_FILE
+ for Cmd in Target.Commands:
+ if "$(CP)" == Cmd.split()[0]:
+ CpTarget = Cmd.split()[2]
+ TargetList.add(CpTarget)
return list(TargetList)
@@ -317,6 +326,73 @@ class GenFdsGlobalVariable:
FvAddressFile.close()
+ def SetEnv(FdfParser, WorkSpace, ArchList, GlobalData):
+ GenFdsGlobalVariable.ModuleFile = WorkSpace.ModuleFile
+ GenFdsGlobalVariable.FdfParser = FdfParser
+ GenFdsGlobalVariable.WorkSpace = WorkSpace.Db
+ GenFdsGlobalVariable.ArchList = ArchList
+ GenFdsGlobalVariable.ToolChainTag = GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]
+ GenFdsGlobalVariable.TargetName = GlobalData.gGlobalDefines["TARGET"]
+ GenFdsGlobalVariable.ActivePlatform = GlobalData.gActivePlatform
+ GenFdsGlobalVariable.EdkSourceDir = GlobalData.gGlobalDefines["EDK_SOURCE"]
+ GenFdsGlobalVariable.ConfDir = GlobalData.gConfDirectory
+ GenFdsGlobalVariable.EnableGenfdsMultiThread = GlobalData.gEnableGenfdsMultiThread
+ for Arch in ArchList:
+ GenFdsGlobalVariable.OutputDirDict[Arch] = os.path.normpath(
+ os.path.join(GlobalData.gWorkspace,
+ WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,GlobalData.gGlobalDefines['TARGET'],
+ GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory,
+ GlobalData.gGlobalDefines['TARGET'] +'_' + GlobalData.gGlobalDefines['TOOLCHAIN']))
+ GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = os.path.normpath(
+ WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,
+ GlobalData.gGlobalDefines['TARGET'], GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory)
+ GenFdsGlobalVariable.PlatformName = WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,
+ GlobalData.gGlobalDefines['TARGET'],
+ GlobalData.gGlobalDefines['TOOLCHAIN']].PlatformName
+ GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], 'FV')
+ if not os.path.exists(GenFdsGlobalVariable.FvDir):
+ os.makedirs(GenFdsGlobalVariable.FvDir)
+ GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')
+ if not os.path.exists(GenFdsGlobalVariable.FfsDir):
+ os.makedirs(GenFdsGlobalVariable.FfsDir)
+
+ T_CHAR_LF = '\n'
+ #
+ # Create FV Address inf file
+ #
+ GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')
+ FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')
+ #
+ # Add [Options]
+ #
+ FvAddressFile.writelines("[options]" + T_CHAR_LF)
+ BsAddress = '0'
+ for Arch in ArchList:
+ BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,
+ GlobalData.gGlobalDefines['TARGET'],
+ GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].BsBaseAddress
+ if BsAddress:
+ break
+
+ FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
+ BsAddress + \
+ T_CHAR_LF)
+
+ RtAddress = '0'
+ for Arch in ArchList:
+ if GenFdsGlobalVariable.WorkSpace.BuildObject[
+ GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],
+ GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress:
+ RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[
+ GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],
+ GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress
+
+ FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
+ RtAddress + \
+ T_CHAR_LF)
+
+ FvAddressFile.close()
+
## ReplaceWorkspaceMacro()
#
# @param String String that may contain macro
@@ -363,7 +439,7 @@ class GenFdsGlobalVariable:
@staticmethod
def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,
- GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None):
+ GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None, DummyFile=None, IsMakefile=False):
Cmd = ["GenSec"]
if Type not in [None, '']:
Cmd += ["-s", Type]
@@ -371,6 +447,8 @@ class GenFdsGlobalVariable:
Cmd += ["-c", CompressionType]
if Guid != None:
Cmd += ["-g", Guid]
+ if DummyFile != None:
+ Cmd += ["--dummy", DummyFile]
if GuidHdrLen not in [None, '']:
Cmd += ["-l", GuidHdrLen]
if len(GuidAttr) != 0:
@@ -385,13 +463,21 @@ class GenFdsGlobalVariable:
CommandFile = Output + '.txt'
if Ui not in [None, '']:
#Cmd += ["-n", '"' + Ui + '"']
- SectionData = array.array('B', [0, 0, 0, 0])
- SectionData.fromstring(Ui.encode("utf_16_le"))
- SectionData.append(0)
- SectionData.append(0)
- Len = len(SectionData)
- GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)
- SaveFileOnChange(Output, SectionData.tostring())
+ if IsMakefile:
+ Cmd += ["-n", "$(MODULE_NAME)"]
+ Cmd += ["-o", Output]
+ #SaveFileOnChange(CommandFile, ' '.join(Cmd), False)
+ if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:
+ GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())
+ else:
+ SectionData = array.array('B', [0, 0, 0, 0])
+ SectionData.fromstring(Ui.encode("utf_16_le"))
+ SectionData.append(0)
+ SectionData.append(0)
+ Len = len(SectionData)
+ GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)
+ SaveFileOnChange(Output, SectionData.tostring())
+
elif Ver not in [None, '']:
Cmd += ["-n", Ver]
if BuildNumber:
@@ -399,22 +485,27 @@ class GenFdsGlobalVariable:
Cmd += ["-o", Output]
SaveFileOnChange(CommandFile, ' '.join(Cmd), False)
- if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):
- return
-
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")
+ if IsMakefile:
+ if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:
+ GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())
+ else:
+ if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):
+ return
+ GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")
else:
Cmd += ["-o", Output]
Cmd += Input
SaveFileOnChange(CommandFile, ' '.join(Cmd), False)
- if GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):
+ if IsMakefile:
+ if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:
+ GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())
+ elif GenFdsGlobalVariable.NeedsUpdate(Output, list(Input)):
GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")
-
- if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and
- GenFdsGlobalVariable.LargeFileInFvFlags):
- GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True
+ if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and
+ GenFdsGlobalVariable.LargeFileInFvFlags):
+ GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True
@staticmethod
def GetAlignment (AlignString):
@@ -429,7 +520,7 @@ class GenFdsGlobalVariable:
@staticmethod
def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,
- SectionAlign=None):
+ SectionAlign=None, MakefilePath=None):
Cmd = ["GenFfs", "-t", Type, "-g", Guid]
mFfsValidAlign = ["0", "8", "16", "128", "512", "1K", "4K", "32K", "64K", "128K", "256K", "512K", "1M", "2M", "4M", "8M", "16M"]
if Fixed == True:
@@ -453,11 +544,17 @@ class GenFdsGlobalVariable:
CommandFile = Output + '.txt'
SaveFileOnChange(CommandFile, ' '.join(Cmd), False)
- if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):
- return
- GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")
+ GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
+ if MakefilePath:
+ if (tuple(Cmd),tuple(GenFdsGlobalVariable.SecCmdList),tuple(GenFdsGlobalVariable.CopyList)) not in GenFdsGlobalVariable.FfsCmdDict.keys():
+ GenFdsGlobalVariable.FfsCmdDict[tuple(Cmd), tuple(GenFdsGlobalVariable.SecCmdList), tuple(GenFdsGlobalVariable.CopyList)] = MakefilePath
+ GenFdsGlobalVariable.SecCmdList = []
+ GenFdsGlobalVariable.CopyList = []
+ else:
+ if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input)):
+ return
+ GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")
@staticmethod
def GenerateFirmwareVolume(Output, Input, BaseAddress=None, ForceRebase=None, Capsule=False, Dump=False,
@@ -511,8 +608,8 @@ class GenFdsGlobalVariable:
@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):
- if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):
+ Align=None, Padding=None, Convert=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))
@@ -539,12 +636,15 @@ class GenFdsGlobalVariable:
Cmd += ["-m"]
Cmd += ["-o", Output]
Cmd += Input
-
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")
+ if IsMakefile:
+ if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:
+ GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())
+ else:
+ GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")
@staticmethod
def GenerateOptionRom(Output, EfiInput, BinaryInput, Compress=False, ClassCode=None,
- Revision=None, DeviceId=None, VendorId=None):
+ Revision=None, DeviceId=None, VendorId=None, IsMakefile=False):
InputList = []
Cmd = ["EfiRom"]
if len(EfiInput) > 0:
@@ -565,7 +665,7 @@ class GenFdsGlobalVariable:
InputList.append (BinFile)
# Check List
- if not GenFdsGlobalVariable.NeedsUpdate(Output, InputList):
+ if not GenFdsGlobalVariable.NeedsUpdate(Output, InputList) and not IsMakefile:
return
GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, InputList))
@@ -579,11 +679,15 @@ class GenFdsGlobalVariable:
Cmd += ["-f", VendorId]
Cmd += ["-o", Output]
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")
+ if IsMakefile:
+ if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:
+ GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())
+ else:
+ GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")
@staticmethod
- def GuidTool(Output, Input, ToolPath, Options='', returnValue=[]):
- if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):
+ def GuidTool(Output, Input, ToolPath, Options='', returnValue=[], 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))
@@ -591,8 +695,11 @@ class GenFdsGlobalVariable:
Cmd += Options.split(' ')
Cmd += ["-o", Output]
Cmd += Input
-
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)
+ if IsMakefile:
+ if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:
+ GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())
+ else:
+ GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)
def CallExternalTool (cmd, errorMess, returnValue=[]):
@@ -727,6 +834,7 @@ class GenFdsGlobalVariable:
return PcdValue
SetDir = staticmethod(SetDir)
+ SetEnv = staticmethod(SetEnv)
ReplaceWorkspaceMacro = staticmethod(ReplaceWorkspaceMacro)
CallExternalTool = staticmethod(CallExternalTool)
VerboseLogger = staticmethod(VerboseLogger)