From 4234283c3acb8c35014acc1546621fbc2621b095 Mon Sep 17 00:00:00 2001 From: lgao4 Date: Fri, 26 Aug 2011 07:46:26 +0000 Subject: Sync BaseTools Branch (version r2271) to EDKII main trunk. BaseTool Branch: https://edk2-buildtools.svn.sourceforge.net/svnroot/edk2-buildtools/branches/Releases/BaseTools_r2100 Signed-off-by: lgao4 Reviewed-by: hchen30 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12214 6f19259b-4bc3-4df7-8a09-765794883524 --- BaseTools/Source/Python/GenFds/FdfParser.py | 30 +++ BaseTools/Source/Python/GenFds/FfsInfStatement.py | 16 +- BaseTools/Source/Python/GenFds/Fv.py | 6 +- BaseTools/Source/Python/GenFds/GenFds.py | 22 ++- .../Source/Python/GenFds/GenFdsGlobalVariable.py | 215 +++++++++++++++++++-- BaseTools/Source/Python/GenFds/Region.py | 2 +- BaseTools/Source/Python/GenFds/Section.py | 12 +- 7 files changed, 278 insertions(+), 25 deletions(-) (limited to 'BaseTools/Source/Python/GenFds') diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index 733935afe..5cdbe8888 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -1926,6 +1926,8 @@ class FdfParser: pass self.__GetSetStatements(FvObj) + + self.__GetFvBaseAddress(FvObj) self.__GetFvAlignment(FvObj) @@ -1979,6 +1981,34 @@ class FdfParser: raise Warning("Unknown alignment value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) Obj.FvAlignment = self.__Token return True + + ## __GetFvBaseAddress() method + # + # Get BaseAddress for FV + # + # @param self The object pointer + # @param Obj for whom FvBaseAddress is got + # @retval True Successfully find a FvBaseAddress statement + # @retval False Not able to find a FvBaseAddress statement + # + def __GetFvBaseAddress(self, Obj): + + if not self.__IsKeyword("FvBaseAddress"): + return False + + if not self.__IsToken( "="): + raise Warning("expected '='", self.FileName, self.CurrentLineNumber) + + if not self.__GetNextToken(): + raise Warning("expected FV base address value", self.FileName, self.CurrentLineNumber) + + IsValidBaseAddrValue = re.compile('^0[x|X][0-9a-fA-F]+') + + if not IsValidBaseAddrValue.match(self.__Token.upper()): + raise Warning("Unknown alignment value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) + Obj.FvBaseAddress = self.__Token + return True + ## __GetFvAttributes() method # diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py index 2b556135d..742b2162f 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -53,7 +53,19 @@ class FfsInfStatement(FfsInfStatementClassObject): self.InDsc = True self.OptRomDefs = {} self.PiSpecVersion = '0x00000000' - + self.InfModule = None + self.FinalBuildTargetList = [] + + ## GetFinalBuildTargetList() method + # + # Get final build target list + def GetFinalBuildTargetList(self): + if not self.InfModule or not self.CurrentArch: + return [] + if not self.FinalBuildTargetList: + self.FinalBuildTargetList = GenFdsGlobalVariable.GetModuleCodaTargetList(self.InfModule, self.CurrentArch) + return self.FinalBuildTargetList + ## __InfParse() method # # Parse inf file to get module information @@ -128,6 +140,8 @@ class FfsInfStatement(FfsInfStatementClassObject): if Inf._Defs != None and len(Inf._Defs) > 0: self.OptRomDefs.update(Inf._Defs) + + self.InfModule = Inf GenFdsGlobalVariable.VerboseLogger( "BaseName : %s" %self.BaseName) GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" %self.ModuleGuid) diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py index 7b6305b48..773b0efbe 100644 --- a/BaseTools/Source/Python/GenFds/Fv.py +++ b/BaseTools/Source/Python/GenFds/Fv.py @@ -46,6 +46,7 @@ class FV (FvClassObject): self.InfFileName = None self.FvAddressFileName = None self.CapsuleName = None + self.FvBaseAddress = None ## AddToBuffer() # @@ -84,7 +85,10 @@ class FV (FvClassObject): GenFdsGlobalVariable.ErrorLogger("Capsule %s in FD region can't contain a FV %s in FD region." % (self.CapsuleName, self.UiFvName.upper())) GenFdsGlobalVariable.InfLogger( "\nGenerating %s FV" %self.UiFvName) - + + if self.FvBaseAddress != None: + BaseAddress = self.FvBaseAddress + self.__InitializeInf__(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict) # # First Process the Apriori section diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py index 04af6e2c6..9088a876e 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -239,6 +239,13 @@ def main(): EdkLogger.error("GenFds", OPTION_VALUE_INVALID, "No such an FV in FDF file: %s" % Options.uiFvName) + if (Options.uiCapName) : + if Options.uiCapName.upper() in FdfParserObj.Profile.CapsuleDict.keys(): + GenFds.OnlyGenerateThisCap = Options.uiCapName + else: + EdkLogger.error("GenFds", OPTION_VALUE_INVALID, + "No such a Capsule in FDF file: %s" % Options.uiCapName) + """Modify images from build output if the feature of loading driver at fixed address is on.""" if GenFdsGlobalVariable.FixedLoadAddress: GenFds.PreprocessImage(BuildWorkSpace, GenFdsGlobalVariable.ActivePlatform) @@ -302,7 +309,8 @@ def myOptionParser(): Parser.add_option("-o", "--outputDir", type="string", dest="outputDir", help="Name of Build Output directory", action="callback", callback=SingleCheckCallback) Parser.add_option("-r", "--rom_image", dest="uiFdName", help="Build the image using the [FD] section named by FdUiName.") - Parser.add_option("-i", "--FvImage", dest="uiFvName", help="Buld the FV image using the [FV] section named by UiFvName") + Parser.add_option("-i", "--FvImage", dest="uiFvName", help="Build the FV image using the [FV] section named by UiFvName") + Parser.add_option("-C", "--CapsuleImage", dest="uiCapName", help="Build the Capsule image using the [Capsule] section named by UiCapName") Parser.add_option("-b", "--buildtarget", type="choice", choices=['DEBUG','RELEASE'], dest="BuildTarget", help="Build TARGET is one of list: DEBUG, RELEASE.", action="callback", callback=SingleCheckCallback) Parser.add_option("-t", "--tagname", type="string", dest="ToolChain", help="Using the tools: TOOL_CHAIN_TAG name to build the platform.", @@ -325,6 +333,7 @@ class GenFds : ImageBinDict = {} OnlyGenerateThisFd = None OnlyGenerateThisFv = None + OnlyGenerateThisCap = None ## GenFd() # @@ -337,11 +346,18 @@ class GenFds : GenFdsGlobalVariable.SetDir ('', FdfParser, WorkSpace, ArchList) GenFdsGlobalVariable.VerboseLogger(" Generate all Fd images and their required FV and Capsule images!") + if GenFds.OnlyGenerateThisCap != None and GenFds.OnlyGenerateThisCap.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys(): + CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.get(GenFds.OnlyGenerateThisCap.upper()) + if CapsuleObj != None: + CapsuleObj.GenCapsule() + return + if GenFds.OnlyGenerateThisFd != None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(GenFds.OnlyGenerateThisFd.upper()) if FdObj != None: FdObj.GenFd() - elif GenFds.OnlyGenerateThisFd == None: + return + elif GenFds.OnlyGenerateThisFd == None and GenFds.OnlyGenerateThisFv == None: for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName] FdObj.GenFd() @@ -361,7 +377,7 @@ class GenFds : FvObj.AddToBuffer(Buffer) Buffer.close() - if GenFds.OnlyGenerateThisFv == None and GenFds.OnlyGenerateThisFd == None: + if GenFds.OnlyGenerateThisFv == None and GenFds.OnlyGenerateThisFd == None and GenFds.OnlyGenerateThisCap == None: if GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict != {}: GenFdsGlobalVariable.VerboseLogger("\n Generate other Capsule images!") for CapsuleName in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys(): diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py index e9eace9c3..3abaef202 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -25,6 +25,12 @@ from Common.BuildToolError import * 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 # # @@ -55,8 +61,191 @@ class GenFdsGlobalVariable: 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(str(Inf.MetaFile).lstrip(GenFdsGlobalVariable.WorkSpaceDir), + 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["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() # @@ -459,17 +648,21 @@ class GenFdsGlobalVariable: PcdValue = '' for Platform in GenFdsGlobalVariable.WorkSpace.PlatformList: - PcdDict = Platform.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 + # + # Only process platform which match current build option. + # + if Platform.MetaFile == GenFdsGlobalVariable.ActivePlatform: + PcdDict = Platform.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.PackageList: PcdDict = Package.Pcds diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py index bfa65c805..7879a9e29 100644 --- a/BaseTools/Source/Python/GenFds/Region.py +++ b/BaseTools/Source/Python/GenFds/Region.py @@ -216,7 +216,7 @@ class Region(RegionClassObject): "Size of File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) GenFdsGlobalVariable.InfLogger(' Region File Name = %s'%RegionData) - BinFile = open (RegionData, 'r+b') + BinFile = open (RegionData, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength diff --git a/BaseTools/Source/Python/GenFds/Section.py b/BaseTools/Source/Python/GenFds/Section.py index a6d3c6319..d26f464ab 100644 --- a/BaseTools/Source/Python/GenFds/Section.py +++ b/BaseTools/Source/Python/GenFds/Section.py @@ -139,14 +139,10 @@ class Section (SectionClassObject): else: GenFdsGlobalVariable.InfLogger ("\nCurrent ARCH \'%s\' of File %s is not in the Support Arch Scope of %s specified by INF %s in FDF" %(FfsInf.CurrentArch, File.File, File.Arch, FfsInf.InfFileName)) - if Suffix != None and os.path.exists(FfsInf.EfiOutputPath): - # Update to search files with suffix in all sub-dirs. - Tuple = os.walk(FfsInf.EfiOutputPath) - for Dirpath, Dirnames, Filenames in Tuple: - for F in Filenames: - if os.path.splitext(F)[1] in (Suffix): - FullName = os.path.join(Dirpath, F) - FileList.append(FullName) + if Suffix != None: + for File in FfsInf.GetFinalBuildTargetList(): + if os.path.splitext(File)[1] in (Suffix): + FileList.append(File) #Process the file lists is alphabetical for a same section type if len (FileList) > 1: -- cgit v1.2.3