## @file
# Global variables for GenFds
#
-# Copyright (c) 2007, Intel Corporation
+# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
#
-# All rights reserved. This program and the accompanying materials
+# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
from Common import EdkLogger
from Common.Misc import SaveFileOnChange
+from Common.TargetTxtClassObject import TargetTxtClassObject
+from Common.ToolDefClassObject import ToolDefClassObject
+from AutoGen.BuildEngine import BuildRule
+import Common.DataType as DataType
+from Common.Misc import PathClass
+
## Global variables
#
#
FdfFile = ''
FdfFileTimeStamp = 0
FixedLoadAddress = False
+ PlatformName = ''
+
+ BuildRuleFamily = "MSFT"
+ ToolChainFamily = "MSFT"
+ __BuildRuleDatabase = None
SectionHeader = struct.Struct("3B 1B")
+
+ ## LoadBuildRule
+ #
+ @staticmethod
+ def __LoadBuildRule():
+ if GenFdsGlobalVariable.__BuildRuleDatabase:
+ return GenFdsGlobalVariable.__BuildRuleDatabase
+ BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, "Conf/target.txt"))
+ TargetTxt = TargetTxtClassObject()
+ if os.path.isfile(BuildConfigurationFile) == True:
+ TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
+ if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:
+ BuildRuleFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]
+ if BuildRuleFile in [None, '']:
+ BuildRuleFile = 'Conf/build_rule.txt'
+ GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)
+ ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
+ if ToolDefinitionFile == '':
+ ToolDefinitionFile = "Conf/tools_def.txt"
+ if os.path.isfile(ToolDefinitionFile):
+ ToolDef = ToolDefClassObject()
+ ToolDef.LoadToolDefFile(ToolDefinitionFile)
+ ToolDefinition = ToolDef.ToolsDefTxtDatabase
+ if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \
+ and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \
+ and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:
+ GenFdsGlobalVariable.BuildRuleFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]
+
+ if DataType.TAB_TOD_DEFINES_FAMILY in ToolDefinition \
+ and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY] \
+ and ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]:
+ GenFdsGlobalVariable.ToolChainFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]
+ return GenFdsGlobalVariable.__BuildRuleDatabase
+
+ ## GetBuildRules
+ # @param Inf: object of InfBuildData
+ # @param Arch: current arch
+ #
+ @staticmethod
+ def GetBuildRules(Inf, Arch):
+ if not Arch:
+ Arch = 'COMMON'
+
+ if not Arch in GenFdsGlobalVariable.OutputDirDict:
+ return {}
+
+ BuildRuleDatabase = GenFdsGlobalVariable.__LoadBuildRule()
+ if not BuildRuleDatabase:
+ return {}
+
+ PathClassObj = PathClass(Inf.MetaFile.File,
+ GenFdsGlobalVariable.WorkSpaceDir)
+ Macro = {}
+ Macro["WORKSPACE" ] = GenFdsGlobalVariable.WorkSpaceDir
+ Macro["MODULE_NAME" ] = Inf.BaseName
+ Macro["MODULE_GUID" ] = Inf.Guid
+ Macro["MODULE_VERSION" ] = Inf.Version
+ Macro["MODULE_TYPE" ] = Inf.ModuleType
+ Macro["MODULE_FILE" ] = str(PathClassObj)
+ Macro["MODULE_FILE_BASE_NAME" ] = PathClassObj.BaseName
+ Macro["MODULE_RELATIVE_DIR" ] = PathClassObj.SubDir
+ Macro["MODULE_DIR" ] = PathClassObj.SubDir
+
+ Macro["BASE_NAME" ] = Inf.BaseName
+
+ Macro["ARCH" ] = Arch
+ Macro["TOOLCHAIN" ] = GenFdsGlobalVariable.ToolChainTag
+ Macro["TOOLCHAIN_TAG" ] = GenFdsGlobalVariable.ToolChainTag
+ Macro["TOOL_CHAIN_TAG" ] = GenFdsGlobalVariable.ToolChainTag
+ Macro["TARGET" ] = GenFdsGlobalVariable.TargetName
+
+ Macro["BUILD_DIR" ] = GenFdsGlobalVariable.OutputDirDict[Arch]
+ Macro["BIN_DIR" ] = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)
+ Macro["LIB_DIR" ] = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)
+ BuildDir = os.path.join(
+ GenFdsGlobalVariable.OutputDirDict[Arch],
+ Arch,
+ PathClassObj.SubDir,
+ PathClassObj.BaseName
+ )
+ Macro["MODULE_BUILD_DIR" ] = BuildDir
+ Macro["OUTPUT_DIR" ] = os.path.join(BuildDir, "OUTPUT")
+ Macro["DEBUG_DIR" ] = os.path.join(BuildDir, "DEBUG")
+
+ BuildRules = {}
+ for Type in BuildRuleDatabase.FileTypeList:
+ #first try getting build rule by BuildRuleFamily
+ RuleObject = BuildRuleDatabase[Type, Inf.BuildType, Arch, GenFdsGlobalVariable.BuildRuleFamily]
+ if not RuleObject:
+ # build type is always module type, but ...
+ if Inf.ModuleType != Inf.BuildType:
+ RuleObject = BuildRuleDatabase[Type, Inf.ModuleType, Arch, GenFdsGlobalVariable.BuildRuleFamily]
+ #second try getting build rule by ToolChainFamily
+ if not RuleObject:
+ RuleObject = BuildRuleDatabase[Type, Inf.BuildType, Arch, GenFdsGlobalVariable.ToolChainFamily]
+ if not RuleObject:
+ # build type is always module type, but ...
+ if Inf.ModuleType != Inf.BuildType:
+ RuleObject = BuildRuleDatabase[Type, Inf.ModuleType, Arch, GenFdsGlobalVariable.ToolChainFamily]
+ if not RuleObject:
+ continue
+ RuleObject = RuleObject.Instantiate(Macro)
+ BuildRules[Type] = RuleObject
+ for Ext in RuleObject.SourceFileExtList:
+ BuildRules[Ext] = RuleObject
+ return BuildRules
+
+ ## GetModuleCodaTargetList
+ #
+ # @param Inf: object of InfBuildData
+ # @param Arch: current arch
+ #
+ @staticmethod
+ def GetModuleCodaTargetList(Inf, Arch):
+ BuildRules = GenFdsGlobalVariable.GetBuildRules(Inf, Arch)
+ if not BuildRules:
+ return []
+
+ TargetList = set()
+ FileList = []
+ for File in Inf.Sources:
+ if File.TagName in ("", "*", GenFdsGlobalVariable.ToolChainTag) and \
+ File.ToolChainFamily in ("", "*", GenFdsGlobalVariable.ToolChainFamily):
+ FileList.append((File, DataType.TAB_UNKNOWN_FILE))
+
+ for File in Inf.Binaries:
+ if File.Target in ['COMMON', '*', GenFdsGlobalVariable.TargetName]:
+ FileList.append((File, File.Type))
+
+ for File, FileType in FileList:
+ LastTarget = None
+ RuleChain = []
+ SourceList = [File]
+ Index = 0
+ while Index < len(SourceList):
+ Source = SourceList[Index]
+ Index = Index + 1
+
+ if File.IsBinary and File == Source and Inf.Binaries != None and File in Inf.Binaries:
+ # Skip all files that are not binary libraries
+ if not Inf.LibraryClass:
+ continue
+ RuleObject = BuildRules[DataType.TAB_DEFAULT_BINARY_FILE]
+ elif FileType in BuildRules:
+ RuleObject = BuildRules[FileType]
+ elif Source.Ext in BuildRules:
+ RuleObject = BuildRules[Source.Ext]
+ else:
+ # stop at no more rules
+ if LastTarget:
+ TargetList.add(str(LastTarget))
+ break
+
+ FileType = RuleObject.SourceFileType
+
+ # stop at STATIC_LIBRARY for library
+ if Inf.LibraryClass and FileType == DataType.TAB_STATIC_LIBRARY:
+ if LastTarget:
+ TargetList.add(str(LastTarget))
+ break
+
+ Target = RuleObject.Apply(Source)
+ if not Target:
+ if LastTarget:
+ TargetList.add(str(LastTarget))
+ break
+ elif not Target.Outputs:
+ # Only do build for target with outputs
+ TargetList.add(str(Target))
+
+ # to avoid cyclic rule
+ if FileType in RuleChain:
+ break
+
+ RuleChain.append(FileType)
+ SourceList.extend(Target.Outputs)
+ LastTarget = Target
+ FileType = DataType.TAB_UNKNOWN_FILE
+
+ return list(TargetList)
## SetDir()
#
FvAddressFile.writelines("[options]" + T_CHAR_LF)
BsAddress = '0'
for Arch in ArchList:
- if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].BsBaseAddress:
- BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].BsBaseAddress
+ if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress:
+ BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress
break
FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
RtAddress = '0'
for Arch in ArchList:
- if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].RtBaseAddress:
- RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].RtBaseAddress
+ if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress:
+ RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress
FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
RtAddress + \
@staticmethod
def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,
- GuidHdrLen=None, GuidAttr=None, Ui=None, Ver=None):
- if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):
- return
- GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
-
+ GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None):
Cmd = ["GenSec"]
if Type not in [None, '']:
Cmd += ["-s", Type]
Cmd += ["-g", Guid]
if GuidHdrLen not in [None, '']:
Cmd += ["-l", GuidHdrLen]
- if GuidAttr not in [None, '']:
- Cmd += ["-r", GuidAttr]
-
+ if len(GuidAttr) != 0:
+ #Add each guided attribute
+ for Attr in GuidAttr:
+ Cmd += ["-r", Attr]
+ if InputAlign != None:
+ #Section Align is only for dummy section without section type
+ for SecAlign in InputAlign:
+ Cmd += ["--sectionalign", SecAlign]
+
+ CommandFile = Output + '.txt'
if Ui not in [None, '']:
#Cmd += ["-n", '"' + Ui + '"']
SectionData = array.array('B', [0,0,0,0])
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 += ["-j", Ver]
- SectionData = array.array('B', [0,0,0,0])
- SectionData.fromstring(Ver.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, 0x14)
- SaveFileOnChange(Output, SectionData.tostring())
+ Cmd += ["-n", Ver]
+ if BuildNumber:
+ Cmd += ["-j", BuildNumber]
+ Cmd += ["-o", Output]
+
+ SaveFileOnChange(CommandFile, ' '.join(Cmd), False)
+ 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 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 section")
+ @staticmethod
+ def GetAlignment (AlignString):
+ if AlignString == None:
+ return 0
+ if AlignString in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):\r
+ return int (AlignString.rstrip('K')) * 1024\r
+ else:\r
+ return int (AlignString)\r
+
@staticmethod
def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,
SectionAlign=None):
- if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):
- return
- GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
-
Cmd = ["GenFfs", "-t", Type, "-g", Guid]
if Fixed == True:
Cmd += ["-x"]
Cmd += ("-i", Input[I])
if SectionAlign not in [None, '', []] and SectionAlign[I] not in [None, '']:
Cmd += ("-n", SectionAlign[I])
+
+ 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")
@staticmethod
- def GenerateFirmwareVolume(Output, Input, BaseAddress=None, Capsule=False, Dump=False,
+ def GenerateFirmwareVolume(Output, Input, BaseAddress=None, ForceRebase=None, Capsule=False, Dump=False,
AddressFile=None, MapFile=None, FfsList=[]):
if not GenFdsGlobalVariable.NeedsUpdate(Output, Input+FfsList):
return
Cmd = ["GenFv"]
if BaseAddress not in [None, '']:
Cmd += ["-r", BaseAddress]
+
+ if ForceRebase == False:
+ Cmd +=["-F", "FALSE"]
+ elif ForceRebase == True:
+ Cmd +=["-F", "TRUE"]
+
if Capsule:
Cmd += ["-c"]
if Dump:
GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")
@staticmethod
- def GuidTool(Output, Input, ToolPath, Options=''):
+ def GuidTool(Output, Input, ToolPath, Options='', returnValue=[]):
if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):
return
GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
- Cmd = [ToolPath, Options]
+ Cmd = [ToolPath, ]
+ Cmd += Options.split(' ')
Cmd += ["-o", Output]
Cmd += Input
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath)
+ GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)
- def CallExternalTool (cmd, errorMess):
+ def CallExternalTool (cmd, errorMess, returnValue=[]):
if type(cmd) not in (tuple, list):
GenFdsGlobalVariable.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool")
sys.stdout.write('\n')
try:
- PopenObject = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr= subprocess.PIPE)
+ PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr= subprocess.PIPE, shell=True)
except Exception, X:
EdkLogger.error("GenFds", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0]))
(out, error) = PopenObject.communicate()
while PopenObject.returncode == None :
PopenObject.wait()
+ if returnValue != [] and returnValue[0] != 0:
+ #get command return value
+ returnValue[0] = PopenObject.returncode
+ return
if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:
GenFdsGlobalVariable.InfLogger ("Return Value = %d" %PopenObject.returncode)
GenFdsGlobalVariable.InfLogger (out)
TokenCName = PcdPair[1]
PcdValue = ''
- for Platform in GenFdsGlobalVariable.WorkSpace.PlatformList:
+ for Arch in GenFdsGlobalVariable.ArchList:
+ Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
PcdDict = Platform.Pcds
for Key in PcdDict:
PcdObj = PcdDict[Key]
PcdValue = PcdObj.DefaultValue
return PcdValue
-
- for Package in GenFdsGlobalVariable.WorkSpace.PackageList:
- PcdDict = Package.Pcds
- for Key in PcdDict:
- PcdObj = PcdDict[Key]
- if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):
- if PcdObj.Type != 'FixedAtBuild':
- EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)
- if PcdObj.DatumType != 'VOID*':
- EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)
-
- PcdValue = PcdObj.DefaultValue
- return PcdValue
+
+ for Package in GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,
+ Arch,
+ GenFdsGlobalVariable.TargetName,
+ GenFdsGlobalVariable.ToolChainTag):
+ PcdDict = Package.Pcds
+ for Key in PcdDict:
+ PcdObj = PcdDict[Key]
+ if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):
+ if PcdObj.Type != 'FixedAtBuild':
+ EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)
+ if PcdObj.DatumType != 'VOID*':
+ EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)
+
+ PcdValue = PcdObj.DefaultValue
+ return PcdValue
return PcdValue