def ProcessModuleFromPdf(self): if self.FdfProfile: for fvname in self.FvTargetList: if fvname.upper() not in self.FdfProfile.FvDict: EdkLogger.error("build", OPTION_VALUE_INVALID, "No such an FV in FDF file: %s" % fvname) # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key, # but the path (self.MetaFile.Path) is the real path for key in self.FdfProfile.InfDict: if key == 'ArchTBD': MetaFile_cache = defaultdict(set) for Arch in self.ArchList: Current_Platform_cache = self.BuildDatabase[ self.MetaFile, Arch, self.BuildTarget, self.ToolChain] for Pkey in Current_Platform_cache.Modules: MetaFile_cache[Arch].add( Current_Platform_cache.Modules[Pkey].MetaFile) for Inf in self.FdfProfile.InfDict[key]: ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch) for Arch in self.ArchList: if ModuleFile in MetaFile_cache[Arch]: break else: ModuleData = self.BuildDatabase[ModuleFile, Arch, self.BuildTarget, self.ToolChain] if not ModuleData.IsBinaryModule: EdkLogger.error( 'build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile) else: for Arch in self.ArchList: if Arch == key: Platform = self.BuildDatabase[self.MetaFile, Arch, self.BuildTarget, self.ToolChain] MetaFileList = set() for Pkey in Platform.Modules: MetaFileList.add( Platform.Modules[Pkey].MetaFile) for Inf in self.FdfProfile.InfDict[key]: ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch) if ModuleFile in MetaFileList: continue ModuleData = self.BuildDatabase[ ModuleFile, Arch, self.BuildTarget, self.ToolChain] if not ModuleData.IsBinaryModule: EdkLogger.error( 'build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)
def Instantiate(self, Macros={}): NewRuleObject = copy.copy(self) NewRuleObject.BuildTargets = {} NewRuleObject.DestFileList = [] for File in self.DestFileList: NewRuleObject.DestFileList.append(PathClass(NormPath(File, Macros))) return NewRuleObject
def PkgSet(self): if not self.FdfFile: self.FdfFile = self.Platform.FlashDefinition if self.FdfFile: ModuleList = self.FdfProfile.InfList else: ModuleList = [] Pkgs = {} for Arch in self.ArchList: Platform = self.BuildDatabase[self.MetaFile, Arch, self.BuildTarget, self.ToolChain] PkgSet = set() for mb in [ self.BuildDatabase[m, Arch, self.BuildTarget, self.ToolChain] for m in Platform.Modules ]: PkgSet.update(mb.Packages) for Inf in ModuleList: ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch) if ModuleFile in Platform.Modules: continue ModuleData = self.BuildDatabase[ModuleFile, Arch, self.BuildTarget, self.ToolChain] PkgSet.update(ModuleData.Packages) Pkgs[Arch] = list(PkgSet) return Pkgs
def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj): GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref") GuidXRefFile = [] PkgGuidDict = {} GuidDict = {} ModuleList = [] FileGuidList = [] VariableGuidSet = set() for Arch in ArchList: PlatformDataBase = BuildDb.BuildObject[ GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList( GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag) for P in PkgList: PkgGuidDict.update(P.Guids) for Name, Guid in PlatformDataBase.Pcds: Pcd = PlatformDataBase.Pcds[Name, Guid] if Pcd.Type in [TAB_PCDS_DYNAMIC_HII, TAB_PCDS_DYNAMIC_EX_HII]: for SkuId in Pcd.SkuInfoList: Sku = Pcd.SkuInfoList[SkuId] if Sku.VariableGuid in VariableGuidSet: continue VariableGuidSet.add(Sku.VariableGuid) if Sku.VariableGuid and Sku.VariableGuid in PkgGuidDict.keys( ): GuidDict[Sku.VariableGuid] = PkgGuidDict[ Sku.VariableGuid] for ModuleFile in PlatformDataBase.Modules: Module = BuildDb.BuildObject[ModuleFile, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] if Module in ModuleList: continue else: ModuleList.append(Module) if GlobalData.gGuidPattern.match(ModuleFile.BaseName): GuidXRefFile.append("%s %s\n" % (ModuleFile.BaseName, Module.BaseName)) else: GuidXRefFile.append("%s %s\n" % (Module.Guid, Module.BaseName)) GuidDict.update(Module.Protocols) GuidDict.update(Module.Guids) GuidDict.update(Module.Ppis) for FvName in FdfParserObj.Profile.FvDict: for FfsObj in FdfParserObj.Profile.FvDict[FvName].FfsList: if not isinstance(FfsObj, FileStatement): InfPath = PathClass( NormPath( mws.join(GenFdsGlobalVariable.WorkSpaceDir, FfsObj.InfFileName))) FdfModule = BuildDb.BuildObject[ InfPath, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] if FdfModule in ModuleList: continue else: ModuleList.append(FdfModule) GuidXRefFile.append( "%s %s\n" % (FdfModule.Guid, FdfModule.BaseName)) GuidDict.update(FdfModule.Protocols) GuidDict.update(FdfModule.Guids) GuidDict.update(FdfModule.Ppis) else: FileStatementGuid = FfsObj.NameGuid if FileStatementGuid in FileGuidList: continue else: FileGuidList.append(FileStatementGuid) Name = [] FfsPath = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs') FfsPath = glob( os.path.join(FfsPath, FileStatementGuid) + TAB_STAR) if not FfsPath: continue if not os.path.exists(FfsPath[0]): continue MatchDict = {} ReFileEnds = compile( '\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$' ) FileList = os.listdir(FfsPath[0]) for File in FileList: Match = ReFileEnds.search(File) if Match: for Index in range(1, 8): if Match.group(Index) and Match.group( Index) in MatchDict: MatchDict[Match.group(Index)].append( File) elif Match.group(Index): MatchDict[Match.group(Index)] = [File] if not MatchDict: continue if '.ui' in MatchDict: for File in MatchDict['.ui']: with open(os.path.join(FfsPath[0], File), 'rb') as F: F.read() length = F.tell() F.seek(4) TmpStr = unpack( '%dh' % ((length - 4) // 2), F.read()) Name = ''.join(chr(c) for c in TmpStr[:-1]) else: FileList = [] if 'fv.sec.txt' in MatchDict: FileList = MatchDict['fv.sec.txt'] elif '.pe32.txt' in MatchDict: FileList = MatchDict['.pe32.txt'] elif '.te.txt' in MatchDict: FileList = MatchDict['.te.txt'] elif '.pic.txt' in MatchDict: FileList = MatchDict['.pic.txt'] elif '.raw.txt' in MatchDict: FileList = MatchDict['.raw.txt'] elif '.ffs.txt' in MatchDict: FileList = MatchDict['.ffs.txt'] else: pass for File in FileList: with open(os.path.join(FfsPath[0], File), 'r') as F: Name.append((F.read().split()[-1])) if not Name: continue Name = ' '.join(Name) if isinstance(Name, type( [])) else Name GuidXRefFile.append("%s %s\n" % (FileStatementGuid, Name)) # Append GUIDs, Protocols, and PPIs to the Xref file GuidXRefFile.append("\n") for key, item in GuidDict.items(): GuidXRefFile.append( "%s %s\n" % (GuidStructureStringToGuidString(item).upper(), key)) if GuidXRefFile: GuidXRefFile = ''.join(GuidXRefFile) SaveFileOnChange(GuidXRefFileName, GuidXRefFile, False) GenFdsGlobalVariable.InfLogger( "\nGUID cross reference file can be found at %s" % GuidXRefFileName) elif os.path.exists(GuidXRefFileName): os.remove(GuidXRefFileName)
def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=None): global Workspace Workspace = "" ArchList = None ReturnCode = 0 resetFdsGlobalVariable() try: if FdsCommandDict.get("verbose"): EdkLogger.SetLevel(EdkLogger.VERBOSE) GenFdsGlobalVariable.VerboseMode = True if FdsCommandDict.get("FixedAddress"): GenFdsGlobalVariable.FixedLoadAddress = True if FdsCommandDict.get("quiet"): EdkLogger.SetLevel(EdkLogger.QUIET) if FdsCommandDict.get("debug"): EdkLogger.SetLevel(FdsCommandDict.get("debug") + 1) GenFdsGlobalVariable.DebugLevel = FdsCommandDict.get("debug") else: EdkLogger.SetLevel(EdkLogger.INFO) if not FdsCommandDict.get("Workspace", os.environ.get('WORKSPACE')): EdkLogger.error( "GenFds", OPTION_MISSING, "WORKSPACE not defined", ExtraData= "Please use '-w' switch to pass it or set the WORKSPACE environment variable." ) elif not os.path.exists( FdsCommandDict.get("Workspace", os.environ.get('WORKSPACE'))): EdkLogger.error( "GenFds", PARAMETER_INVALID, "WORKSPACE is invalid", ExtraData= "Please use '-w' switch to pass it or set the WORKSPACE environment variable." ) else: Workspace = os.path.normcase( FdsCommandDict.get("Workspace", os.environ.get('WORKSPACE'))) GenFdsGlobalVariable.WorkSpaceDir = Workspace if FdsCommandDict.get("debug"): GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace) if FdsCommandDict.get("GenfdsMultiThread"): GenFdsGlobalVariable.EnableGenfdsMultiThread = True else: GenFdsGlobalVariable.EnableGenfdsMultiThread = False os.chdir(GenFdsGlobalVariable.WorkSpaceDir) # set multiple workspace PackagesPath = os.getenv("PACKAGES_PATH") mws.setWs(GenFdsGlobalVariable.WorkSpaceDir, PackagesPath) if FdsCommandDict.get("fdf_file"): FdfFilename = FdsCommandDict.get("fdf_file")[0].Path FdfFilename = GenFdsGlobalVariable.ReplaceWorkspaceMacro( FdfFilename) if FdfFilename[0:2] == '..': FdfFilename = os.path.realpath(FdfFilename) if not os.path.isabs(FdfFilename): FdfFilename = mws.join(GenFdsGlobalVariable.WorkSpaceDir, FdfFilename) if not os.path.exists(FdfFilename): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=FdfFilename) GenFdsGlobalVariable.FdfFile = FdfFilename GenFdsGlobalVariable.FdfFileTimeStamp = os.path.getmtime( FdfFilename) else: EdkLogger.error("GenFds", OPTION_MISSING, "Missing FDF filename") if FdsCommandDict.get("build_target"): GenFdsGlobalVariable.TargetName = FdsCommandDict.get( "build_target") if FdsCommandDict.get("toolchain_tag"): GenFdsGlobalVariable.ToolChainTag = FdsCommandDict.get( "toolchain_tag") if FdsCommandDict.get("active_platform"): ActivePlatform = FdsCommandDict.get("active_platform") ActivePlatform = GenFdsGlobalVariable.ReplaceWorkspaceMacro( ActivePlatform) if ActivePlatform[0:2] == '..': ActivePlatform = os.path.realpath(ActivePlatform) if not os.path.isabs(ActivePlatform): ActivePlatform = mws.join(GenFdsGlobalVariable.WorkSpaceDir, ActivePlatform) if not os.path.exists(ActivePlatform): EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!") else: EdkLogger.error("GenFds", OPTION_MISSING, "Missing active platform") GenFdsGlobalVariable.ActivePlatform = PathClass( NormPath(ActivePlatform)) if FdsCommandDict.get("conf_directory"): # Get alternate Conf location, if it is absolute, then just use the absolute directory name ConfDirectoryPath = os.path.normpath( FdsCommandDict.get("conf_directory")) if ConfDirectoryPath.startswith('"'): ConfDirectoryPath = ConfDirectoryPath[1:] if ConfDirectoryPath.endswith('"'): ConfDirectoryPath = ConfDirectoryPath[:-1] if not os.path.isabs(ConfDirectoryPath): # Since alternate directory name is not absolute, the alternate directory is located within the WORKSPACE # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf ConfDirectoryPath = os.path.join( GenFdsGlobalVariable.WorkSpaceDir, ConfDirectoryPath) else: if "CONF_PATH" in os.environ: ConfDirectoryPath = os.path.normcase(os.environ["CONF_PATH"]) else: # Get standard WORKSPACE/Conf, use the absolute path to the WORKSPACE/Conf ConfDirectoryPath = mws.join(GenFdsGlobalVariable.WorkSpaceDir, 'Conf') GenFdsGlobalVariable.ConfDir = ConfDirectoryPath if not GlobalData.gConfDirectory: GlobalData.gConfDirectory = GenFdsGlobalVariable.ConfDir BuildConfigurationFile = os.path.normpath( os.path.join(ConfDirectoryPath, "target.txt")) if os.path.isfile(BuildConfigurationFile) == True: # if no build target given in command line, get it from target.txt TargetObj = TargetTxtDict() TargetTxt = TargetObj.Target if not GenFdsGlobalVariable.TargetName: BuildTargetList = TargetTxt.TargetTxtDictionary[ TAB_TAT_DEFINES_TARGET] if len(BuildTargetList) != 1: EdkLogger.error( "GenFds", OPTION_VALUE_INVALID, ExtraData="Only allows one instance for Target.") GenFdsGlobalVariable.TargetName = BuildTargetList[0] # if no tool chain given in command line, get it from target.txt if not GenFdsGlobalVariable.ToolChainTag: ToolChainList = TargetTxt.TargetTxtDictionary[ TAB_TAT_DEFINES_TOOL_CHAIN_TAG] if ToolChainList is None or len(ToolChainList) == 0: EdkLogger.error( "GenFds", RESOURCE_NOT_AVAILABLE, ExtraData="No toolchain given. Don't know how to build." ) if len(ToolChainList) != 1: EdkLogger.error( "GenFds", OPTION_VALUE_INVALID, ExtraData="Only allows one instance for ToolChain.") GenFdsGlobalVariable.ToolChainTag = ToolChainList[0] else: EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=BuildConfigurationFile) #Set global flag for build mode GlobalData.gIgnoreSource = FdsCommandDict.get("IgnoreSources") if FdsCommandDict.get("macro"): for Pair in FdsCommandDict.get("macro"): if Pair.startswith('"'): Pair = Pair[1:] if Pair.endswith('"'): Pair = Pair[:-1] List = Pair.split('=') if len(List) == 2: if not List[1].strip(): EdkLogger.error( "GenFds", OPTION_VALUE_INVALID, ExtraData="No Value given for Macro %s" % List[0]) if List[0].strip() in ["WORKSPACE", "TARGET", "TOOLCHAIN"]: GlobalData.gGlobalDefines[ List[0].strip()] = List[1].strip() else: GlobalData.gCommandLineDefines[ List[0].strip()] = List[1].strip() else: GlobalData.gCommandLineDefines[List[0].strip()] = "TRUE" os.environ["WORKSPACE"] = Workspace # Use the -t and -b option as gGlobalDefines's TOOLCHAIN and TARGET if they are not defined if "TARGET" not in GlobalData.gGlobalDefines: GlobalData.gGlobalDefines[ "TARGET"] = GenFdsGlobalVariable.TargetName if "TOOLCHAIN" not in GlobalData.gGlobalDefines: GlobalData.gGlobalDefines[ "TOOLCHAIN"] = GenFdsGlobalVariable.ToolChainTag if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines: GlobalData.gGlobalDefines[ 'TOOL_CHAIN_TAG'] = GenFdsGlobalVariable.ToolChainTag """call Workspace build create database""" GlobalData.gDatabasePath = os.path.normpath( os.path.join(ConfDirectoryPath, GlobalData.gDatabasePath)) if WorkSpaceDataBase: BuildWorkSpace = WorkSpaceDataBase else: BuildWorkSpace = WorkspaceDatabase() # # Get files real name in workspace dir # GlobalData.gAllFiles = DirCache(Workspace) GlobalData.gWorkspace = Workspace if FdsCommandDict.get("build_architecture_list"): ArchList = FdsCommandDict.get("build_architecture_list").split(',') else: ArchList = BuildWorkSpace.BuildObject[ GenFdsGlobalVariable.ActivePlatform, TAB_COMMON, FdsCommandDict.get("build_target"), FdsCommandDict.get("toolchain_tag")].SupArchList TargetArchList = set(BuildWorkSpace.BuildObject[ GenFdsGlobalVariable.ActivePlatform, TAB_COMMON, FdsCommandDict.get("build_target"), FdsCommandDict.get("toolchain_tag")].SupArchList) & set(ArchList) if len(TargetArchList) == 0: EdkLogger.error( "GenFds", GENFDS_ERROR, "Target ARCH %s not in platform supported ARCH %s" % (str(ArchList), str(BuildWorkSpace.BuildObject[ GenFdsGlobalVariable.ActivePlatform, TAB_COMMON].SupArchList))) for Arch in ArchList: GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath( BuildWorkSpace.BuildObject[ GenFdsGlobalVariable.ActivePlatform, Arch, FdsCommandDict.get("build_target"), FdsCommandDict.get("toolchain_tag")].OutputDirectory) # assign platform name based on last entry in ArchList GenFdsGlobalVariable.PlatformName = BuildWorkSpace.BuildObject[ GenFdsGlobalVariable.ActivePlatform, ArchList[-1], FdsCommandDict.get("build_target"), FdsCommandDict.get("toolchain_tag")].PlatformName if FdsCommandDict.get("platform_build_directory"): OutputDirFromCommandLine = GenFdsGlobalVariable.ReplaceWorkspaceMacro( FdsCommandDict.get("platform_build_directory")) if not os.path.isabs(OutputDirFromCommandLine): OutputDirFromCommandLine = os.path.join( GenFdsGlobalVariable.WorkSpaceDir, OutputDirFromCommandLine) for Arch in ArchList: GenFdsGlobalVariable.OutputDirDict[ Arch] = OutputDirFromCommandLine else: for Arch in ArchList: GenFdsGlobalVariable.OutputDirDict[Arch] = os.path.join( GenFdsGlobalVariable.OutputDirFromDscDict[Arch], GenFdsGlobalVariable.TargetName + '_' + GenFdsGlobalVariable.ToolChainTag) for Key in GenFdsGlobalVariable.OutputDirDict: OutputDir = GenFdsGlobalVariable.OutputDirDict[Key] if OutputDir[0:2] == '..': OutputDir = os.path.realpath(OutputDir) if OutputDir[1] != ':': OutputDir = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, OutputDir) if not os.path.exists(OutputDir): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=OutputDir) GenFdsGlobalVariable.OutputDirDict[Key] = OutputDir """ Parse Fdf file, has to place after build Workspace as FDF may contain macros from DSC file """ if WorkSpaceDataBase: FdfParserObj = GlobalData.gFdfParser else: FdfParserObj = FdfParser(FdfFilename) FdfParserObj.ParseFile() if FdfParserObj.CycleReferenceCheck(): EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Cycle Reference Detected in FDF file") if FdsCommandDict.get("fd"): if FdsCommandDict.get( "fd")[0].upper() in FdfParserObj.Profile.FdDict: GenFds.OnlyGenerateThisFd = FdsCommandDict.get("fd")[0] else: EdkLogger.error( "GenFds", OPTION_VALUE_INVALID, "No such an FD in FDF file: %s" % FdsCommandDict.get("fd")[0]) if FdsCommandDict.get("fv"): if FdsCommandDict.get( "fv")[0].upper() in FdfParserObj.Profile.FvDict: GenFds.OnlyGenerateThisFv = FdsCommandDict.get("fv")[0] else: EdkLogger.error( "GenFds", OPTION_VALUE_INVALID, "No such an FV in FDF file: %s" % FdsCommandDict.get("fv")[0]) if FdsCommandDict.get("cap"): if FdsCommandDict.get( "cap")[0].upper() in FdfParserObj.Profile.CapsuleDict: GenFds.OnlyGenerateThisCap = FdsCommandDict.get("cap")[0] else: EdkLogger.error( "GenFds", OPTION_VALUE_INVALID, "No such a Capsule in FDF file: %s" % FdsCommandDict.get("cap")[0]) GenFdsGlobalVariable.WorkSpace = BuildWorkSpace if ArchList: GenFdsGlobalVariable.ArchList = ArchList # Dsc Build Data will handle Pcd Settings from CommandLine. """Modify images from build output if the feature of loading driver at fixed address is on.""" if GenFdsGlobalVariable.FixedLoadAddress: GenFds.PreprocessImage(BuildWorkSpace, GenFdsGlobalVariable.ActivePlatform) # Record the FV Region info that may specific in the FD if FdfParserObj.Profile.FvDict and FdfParserObj.Profile.FdDict: for FvObj in FdfParserObj.Profile.FvDict.values(): for FdObj in FdfParserObj.Profile.FdDict.values(): for RegionObj in FdObj.RegionList: if RegionObj.RegionType != BINARY_FILE_TYPE_FV: continue for RegionData in RegionObj.RegionDataList: if FvObj.UiFvName.upper() == RegionData.upper(): if not FvObj.BaseAddress: FvObj.BaseAddress = '0x%x' % ( int(FdObj.BaseAddress, 0) + RegionObj.Offset) if FvObj.FvRegionInFD: if FvObj.FvRegionInFD != RegionObj.Size: EdkLogger.error( "GenFds", FORMAT_INVALID, "The FV %s's region is specified in multiple FD with different value." % FvObj.UiFvName) else: FvObj.FvRegionInFD = RegionObj.Size RegionObj.BlockInfoOfRegion( FdObj.BlockSizeList, FvObj) """Call GenFds""" GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList) """Generate GUID cross reference file""" GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList, FdfParserObj) """Display FV space info.""" GenFds.DisplayFvSpaceInfo(FdfParserObj) except Warning as X: EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError=False) ReturnCode = FORMAT_INVALID except FatalError as X: if FdsCommandDict.get("debug") is not None: import traceback EdkLogger.quiet(traceback.format_exc()) ReturnCode = X.args[0] except: import traceback EdkLogger.error( "\nPython", CODE_ERROR, "Tools code failure", ExtraData= "Please send email to %s for help, attaching following call stack trace!\n" % MSG_EDKII_MAIL_ADDR, RaiseError=False) EdkLogger.quiet(traceback.format_exc()) ReturnCode = CODE_ERROR finally: ClearDuplicatedInf() return ReturnCode
def IncludeToolDefFile(self, FileName): FileContent = [] if os.path.isfile(FileName): try: F = open(FileName, 'r') FileContent = F.readlines() except: EdkLogger.error("tools_def.txt parser", FILE_OPEN_FAILURE, ExtraData=FileName) else: EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=FileName) for Index in range(len(FileContent)): Line = FileContent[Index].strip() if Line == "" or Line[0] == '#': continue if Line.startswith("!include"): IncFile = Line[8:].strip() Done, IncFile = self.ExpandMacros(IncFile) if not Done: EdkLogger.error( "tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE, "Macro or Environment has not been defined", ExtraData=IncFile[4:-1], File=FileName, Line=Index + 1) IncFile = NormPath(IncFile) if not os.path.isabs(IncFile): # # try WORKSPACE # IncFileTmp = PathClass(IncFile, GlobalData.gWorkspace) ErrorCode = IncFileTmp.Validate()[0] if ErrorCode != 0: # # try PACKAGES_PATH # IncFileTmp = mws.join(GlobalData.gWorkspace, IncFile) if not os.path.exists(IncFileTmp): # # try directory of current file # IncFileTmp = PathClass(IncFile, os.path.dirname(FileName)) ErrorCode = IncFileTmp.Validate()[0] if ErrorCode != 0: EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=IncFile) if isinstance(IncFileTmp, PathClass): IncFile = IncFileTmp.Path else: IncFile = IncFileTmp self.IncludeToolDefFile(IncFile) continue NameValuePair = Line.split("=", 1) if len(NameValuePair) != 2: EdkLogger.warn( "tools_def.txt parser", "Line %d: not correct assignment statement, skipped" % (Index + 1)) continue Name = NameValuePair[0].strip() Value = NameValuePair[1].strip() if Name == "IDENTIFIER": EdkLogger.debug( EdkLogger.DEBUG_8, "Line %d: Found identifier statement, skipped: %s" % ((Index + 1), Value)) continue MacroDefinition = gMacroDefPattern.findall(Name) if MacroDefinition != []: Done, Value = self.ExpandMacros(Value) if not Done: EdkLogger.error( "tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE, "Macro or Environment has not been defined", ExtraData=Value[4:-1], File=FileName, Line=Index + 1) MacroName = MacroDefinition[0].strip() self.MacroDictionary["DEF(%s)" % MacroName] = Value EdkLogger.debug( EdkLogger.DEBUG_8, "Line %d: Found macro: %s = %s" % ((Index + 1), MacroName, Value)) continue Done, Value = self.ExpandMacros(Value) if not Done: EdkLogger.error("tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE, "Macro or Environment has not been defined", ExtraData=Value[4:-1], File=FileName, Line=Index + 1) List = Name.split('_') if len(List) != 5: EdkLogger.verbose( "Line %d: Not a valid name of definition: %s" % ((Index + 1), Name)) continue elif List[4] == TAB_STAR: EdkLogger.verbose( "Line %d: '*' is not allowed in last field: %s" % ((Index + 1), Name)) continue else: self.ToolsDefTxtDictionary[Name] = Value if List[0] != TAB_STAR: self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] += [ List[0] ] if List[1] != TAB_STAR: self.ToolsDefTxtDatabase[ TAB_TOD_DEFINES_TOOL_CHAIN_TAG] += [List[1]] if List[2] != TAB_STAR: self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] += [ List[2] ] if List[3] != TAB_STAR: self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] += [ List[3] ] if List[4] == TAB_TOD_DEFINES_FAMILY and List[ 2] == TAB_STAR and List[3] == TAB_STAR: if TAB_TOD_DEFINES_FAMILY not in self.ToolsDefTxtDatabase: self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY] = {} self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][ List[1]] = Value self.ToolsDefTxtDatabase[ TAB_TOD_DEFINES_BUILDRULEFAMILY] = {} self.ToolsDefTxtDatabase[ TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value elif List[1] not in self.ToolsDefTxtDatabase[ TAB_TOD_DEFINES_FAMILY]: self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][ List[1]] = Value self.ToolsDefTxtDatabase[ TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value elif self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][ List[1]] != Value: EdkLogger.verbose( "Line %d: No override allowed for the family of a tool chain: %s" % ((Index + 1), Name)) if List[4] == TAB_TOD_DEFINES_BUILDRULEFAMILY and List[ 2] == TAB_STAR and List[3] == TAB_STAR: if TAB_TOD_DEFINES_BUILDRULEFAMILY not in self.ToolsDefTxtDatabase \ or List[1] not in self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY]: EdkLogger.verbose( "Line %d: The family is not specified, but BuildRuleFamily is specified for the tool chain: %s" % ((Index + 1), Name)) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][ List[1]] = Value
def GenFfs(self, FvName, Dict=None, IsMakefile=False): if Dict is None: Dict = {} Buffer = BytesIO() if self.AprioriType == "PEI": AprioriFileGuid = PEI_APRIORI_GUID else: AprioriFileGuid = DXE_APRIORI_GUID OutputAprFilePath = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, \ GenFdsGlobalVariable.FfsDir,\ AprioriFileGuid + FvName) if not os.path.exists(OutputAprFilePath): os.makedirs(OutputAprFilePath) OutputAprFileName = os.path.join( OutputAprFilePath, \ AprioriFileGuid + FvName + '.Apri' ) AprFfsFileName = os.path.join (OutputAprFilePath,\ AprioriFileGuid + FvName + '.Ffs') Dict.update(self.DefineVarDict) InfFileName = None for FfsObj in self.FfsList: Guid = "" if isinstance(FfsObj, FileStatement): Guid = FfsObj.NameGuid else: InfFileName = NormPath(FfsObj.InfFileName) Arch = FfsObj.GetCurrentArch() if Arch: Dict['$(ARCH)'] = Arch InfFileName = GenFdsGlobalVariable.MacroExtend( InfFileName, Dict, Arch) if Arch: Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[ PathClass(InfFileName, GenFdsGlobalVariable. WorkSpaceDir), Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] Guid = Inf.Guid else: Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[ PathClass(InfFileName, GenFdsGlobalVariable. WorkSpaceDir), TAB_COMMON, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] Guid = Inf.Guid if not Inf.Module.Binaries: EdkLoggerError("GenFds", RESOURCE_NOT_AVAILABLE, "INF %s not found in build ARCH %s!" \ % (InfFileName, GenFdsGlobalVariable.ArchList)) GuidPart = Guid.split('-') Buffer.write(pack('I', int(GuidPart[0], 16))) Buffer.write(pack('H', int(GuidPart[1], 16))) Buffer.write(pack('H', int(GuidPart[2], 16))) for Num in range(2): Char = GuidPart[3][Num * 2:Num * 2 + 2] Buffer.write(pack('B', int(Char, 16))) for Num in range(6): Char = GuidPart[4][Num * 2:Num * 2 + 2] Buffer.write(pack('B', int(Char, 16))) SaveFileOnChange(OutputAprFileName, Buffer.getvalue()) RawSectionFileName = os.path.join( OutputAprFilePath, \ AprioriFileGuid + FvName + '.raw' ) MakefilePath = None if IsMakefile: if not InfFileName: return None MakefilePath = InfFileName, Arch GenFdsGlobalVariable.GenerateSection(RawSectionFileName, [OutputAprFileName], 'EFI_SECTION_RAW', IsMakefile=IsMakefile) GenFdsGlobalVariable.GenerateFfs(AprFfsFileName, [RawSectionFileName], 'EFI_FV_FILETYPE_FREEFORM', AprioriFileGuid, MakefilePath=MakefilePath) return AprFfsFileName