def InitDatabase(self, NewDatabase = True): EdkLogger.verbose("\nInitialize ECC database started ...") # # Drop all old existing tables # if NewDatabase: if os.path.exists(self.DbPath): os.remove(self.DbPath) self.Conn = sqlite3.connect(self.DbPath, isolation_level = 'DEFERRED') self.Conn.execute("PRAGMA page_size=4096") self.Conn.execute("PRAGMA synchronous=OFF") # to avoid non-ascii charater conversion error self.Conn.text_factory = str self.Cur = self.Conn.cursor() self.TblDataModel = TableDataModel(self.Cur) self.TblFile = TableFile(self.Cur) self.TblFunction = TableFunction(self.Cur) self.TblIdentifier = TableIdentifier(self.Cur) self.TblPcd = TablePcd(self.Cur) self.TblReport = TableReport(self.Cur) self.TblInf = ModuleTable(self.Cur) self.TblDec = PackageTable(self.Cur) self.TblDsc = PlatformTable(self.Cur) self.TblFdf = TableFdf(self.Cur) # # Create new tables # if NewDatabase: self.TblDataModel.Create() self.TblFile.Create() self.TblFunction.Create() self.TblPcd.Create() self.TblReport.Create() self.TblInf.Create() self.TblDec.Create() self.TblDsc.Create() self.TblFdf.Create() # # Init each table's ID # self.TblDataModel.InitID() self.TblFile.InitID() self.TblFunction.InitID() self.TblPcd.InitID() self.TblReport.InitID() self.TblInf.InitID() self.TblDec.InitID() self.TblDsc.InitID() self.TblFdf.InitID() # # Initialize table DataModel # if NewDatabase: self.TblDataModel.InitTable() EdkLogger.verbose("Initialize ECC database ... DONE!")
def SetDir(OutputDir, FdfParser, WorkSpace, ArchList): GenFdsGlobalVariable.VerboseLogger("GenFdsGlobalVariable.OutputDir :%s" % OutputDir) # GenFdsGlobalVariable.OutputDirDict = OutputDir GenFdsGlobalVariable.FdfParser = FdfParser GenFdsGlobalVariable.WorkSpace = WorkSpace 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) if ArchList != None: GenFdsGlobalVariable.ArchList = ArchList 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: 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 = " + BsAddress + T_CHAR_LF) RtAddress = "0" for Arch in ArchList: 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 + T_CHAR_LF) FvAddressFile.close()
def GetRealPathCase(self, path): TmpPath = path.rstrip(os.sep) PathParts = TmpPath.split(os.sep) if len(PathParts) == 0: return path if len(PathParts) == 1: if PathParts[0].strip().endswith(':'): return PathParts[0].upper() # Relative dir, list . current dir Dirs = os.listdir('.') for Dir in Dirs: if Dir.upper() == PathParts[0].upper(): return Dir if PathParts[0].strip().endswith(':'): PathParts[0] = PathParts[0].upper() ParentDir = PathParts[0] RealPath = ParentDir if PathParts[0] == '': RealPath = os.sep ParentDir = os.sep PathParts.remove(PathParts[0]) # need to remove the parent for Part in PathParts: Dirs = os.listdir(ParentDir + os.sep) for Dir in Dirs: if Dir.upper() == Part.upper(): RealPath += os.sep RealPath += Dir break ParentDir += os.sep ParentDir += Dir return RealPath
def GenerateGuidXRefFile(BuildDb, ArchList): GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref") GuidXRefFile = StringIO.StringIO('') GuidDict = {} for Arch in ArchList: PlatformDataBase = BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] for ModuleFile in PlatformDataBase.Modules: Module = BuildDb.BuildObject[ModuleFile, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] GuidXRefFile.write("%s %s\n" % (Module.Guid, Module.BaseName)) for key, item in Module.Protocols.items(): GuidDict[key] = item for key, item in Module.Guids.items(): GuidDict[key] = item for key, item in Module.Ppis.items(): GuidDict[key] = item # Append GUIDs, Protocols, and PPIs to the Xref file GuidXRefFile.write("\n") for key, item in GuidDict.items(): GuidXRefFile.write("%s %s\n" % (GuidStructureStringToGuidString(item).upper(), key)) if GuidXRefFile.getvalue(): SaveFileOnChange(GuidXRefFileName, GuidXRefFile.getvalue(), False) GenFdsGlobalVariable.InfLogger("\nGUID cross reference file can be found at %s" % GuidXRefFileName) elif os.path.exists(GuidXRefFileName): os.remove(GuidXRefFileName) GuidXRefFile.close()
def __init__(self, DbPath): if os.path.exists(DbPath): os.remove(DbPath) self.Conn = sqlite3.connect(DbPath, isolation_level = 'DEFERRED') self.Conn.execute("PRAGMA page_size=8192") self.Conn.execute("PRAGMA synchronous=OFF") self.Cur = self.Conn.cursor() self.TblDataModel = TableDataModel(self.Cur) self.TblFile = TableFile(self.Cur) self.TblInf = TableInf(self.Cur) self.TblDec = TableDec(self.Cur) self.TblDsc = TableDsc(self.Cur)
def Main(): EdkLogger.Initialize() Option, Input = GetOptions() # Set log level if Option.quiet: EdkLogger.SetLevel(EdkLogger.QUIET) elif Option.verbose: EdkLogger.SetLevel(EdkLogger.VERBOSE) elif Option.debug is not None: EdkLogger.SetLevel(Option.debug + 1) else: EdkLogger.SetLevel(EdkLogger.INFO) try: if Option.ModuleType is None or Option.ModuleType not in gType2Phase: EdkLogger.error("GenDepex", OPTION_MISSING, "Module type is not specified or supported") DxsFile = '' if len(Input) > 0 and Option.Expression == "": DxsFile = Input[0] DxsString = open(DxsFile, 'r').read().replace("\n", " ").replace("\r", " ") DxsString = gStartClosePattern.sub("\\1", DxsString) elif Option.Expression != "": if Option.Expression[0] == '"': DxsString = Option.Expression[1:-1] else: DxsString = Option.Expression else: EdkLogger.error("GenDepex", OPTION_MISSING, "No expression string or file given") Dpx = DependencyExpression(DxsString, Option.ModuleType, Option.Optimize) if Option.OutputFile is not None: FileChangeFlag = Dpx.Generate(Option.OutputFile) if not FileChangeFlag and DxsFile: # # Touch the output file if its time stamp is older than the original # DXS file to avoid re-invoke this tool for the dependency check in build rule. # if os.stat(DxsFile)[8] > os.stat(Option.OutputFile)[8]: os.utime(Option.OutputFile, None) else: Dpx.Generate() except BaseException as X: EdkLogger.quiet("") if Option is not None and Option.debug is not None: EdkLogger.quiet(traceback.format_exc()) else: EdkLogger.quiet(str(X)) return 1 return 0
def SetLogFile(LogFile): if os.path.exists(LogFile): os.remove(LogFile) _Ch = logging.FileHandler(LogFile) _Ch.setFormatter(_DebugFormatter) _DebugLogger.addHandler(_Ch) _Ch= logging.FileHandler(LogFile) _Ch.setFormatter(_InfoFormatter) _InfoLogger.addHandler(_Ch) _Ch = logging.FileHandler(LogFile) _Ch.setFormatter(_ErrorFormatter) _ErrorLogger.addHandler(_Ch)
def __init__(self): # Version and Copyright self.VersionNumber = ("1.0" + " Build " + gBUILD_VERSION) self.Version = "%prog Version " + self.VersionNumber self.Copyright = "Copyright (c) 2009 - 2018, Intel Corporation All rights reserved." self.InitDefaultConfigIni() self.OutputFile = 'output.txt' self.ReportFile = 'Report.csv' self.ExceptionFile = 'exception.xml' self.IsInit = True self.ScanSourceCode = True self.ScanMetaData = True self.MetaFile = '' self.OnlyScan = None # Parse the options and args self.ParseOption() EdkLogger.info(time.strftime("%H:%M:%S, %b.%d %Y ", time.localtime()) + "[00:00]" + "\n") WorkspaceDir = os.path.normcase(os.path.normpath(os.environ["WORKSPACE"])) os.environ["WORKSPACE"] = WorkspaceDir # set multiple workspace PackagesPath = os.getenv("PACKAGES_PATH") mws.setWs(WorkspaceDir, PackagesPath) GlobalData.gWorkspace = WorkspaceDir GlobalData.gGlobalDefines["WORKSPACE"] = WorkspaceDir EdkLogger.info("Loading ECC configuration ... done") # Generate checkpoints list EccGlobalData.gConfig = Configuration(self.ConfigFile) # Generate exception list EccGlobalData.gException = ExceptionCheck(self.ExceptionFile) # Init Ecc database EccGlobalData.gDb = Database.Database(Database.DATABASE_PATH) EccGlobalData.gDb.InitDatabase(self.IsInit) # # Get files real name in workspace dir # GlobalData.gAllFiles = DirCache(GlobalData.gWorkspace) # Build ECC database # self.BuildDatabase() self.DetectOnlyScanDirs() # Start to check self.Check() # Show report self.GenReport() # Close Database EccGlobalData.gDb.Close()
def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile): VfrNameList = [] if os.path.isdir(DebugDir): for CurrentDir, Dirs, Files in os.walk(DebugDir): for FileName in Files: Name, Ext = os.path.splitext(FileName) if Ext == '.c' and Name != 'AutoGen': VfrNameList.append (Name + 'Bin') VfrNameList.append (ModuleName + 'Strings') EfiFileName = os.path.join(DebugDir, ModuleName + '.efi') MapFileName = os.path.join(DebugDir, ModuleName + '.map') VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, VfrNameList) if not VfrUniOffsetList: return try: fInputfile = open(OutputFile, "wb+") except: EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" %OutputFile, None) # Use a instance of BytesIO to cache data fStringIO = BytesIO() for Item in VfrUniOffsetList: if (Item[0].find("Strings") != -1): # # UNI offset in image. # GUID + Offset # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } } # UniGuid = b'\xe0\xc5\x13\x89\xf63\x86M\x9b\xf1C\xef\x89\xfc\x06f' fStringIO.write(UniGuid) UniValue = pack ('Q', int (Item[1], 16)) fStringIO.write (UniValue) else: # # VFR binary offset in image. # GUID + Offset # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } }; # VfrGuid = b'\xb4|\xbc\xd0Gj_I\xaa\x11q\x07F\xda\x06\xa2' fStringIO.write(VfrGuid) type (Item[1]) VfrValue = pack ('Q', int (Item[1], 16)) fStringIO.write (VfrValue) # # write data into file. # try : fInputfile.write (fStringIO.getvalue()) except: EdkLogger.error("Trim", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %OutputFile, None) fStringIO.close () fInputfile.close ()
def ParseOption(self): EdkLogger.quiet("Loading ECC configuration ... done") (Options, Target) = self.EccOptionParser() if Options.Workspace: os.environ["WORKSPACE"] = Options.Workspace # Check workspace envirnoment if "WORKSPACE" not in os.environ: EdkLogger.error("ECC", BuildToolError.ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found", ExtraData="WORKSPACE") else: EccGlobalData.gWorkspace = os.path.normpath(os.getenv("WORKSPACE")) if not os.path.exists(EccGlobalData.gWorkspace): EdkLogger.error("ECC", BuildToolError.FILE_NOT_FOUND, ExtraData="WORKSPACE = %s" % EccGlobalData.gWorkspace) os.environ["WORKSPACE"] = EccGlobalData.gWorkspace # Set log level self.SetLogLevel(Options) # Set other options if Options.ConfigFile != None: self.ConfigFile = Options.ConfigFile if Options.OutputFile != None: self.OutputFile = Options.OutputFile if Options.ReportFile != None: self.ReportFile = Options.ReportFile if Options.ExceptionFile != None: self.ExceptionFile = Options.ExceptionFile if Options.Target != None: if not os.path.isdir(Options.Target): EdkLogger.error("ECC", BuildToolError.OPTION_VALUE_INVALID, ExtraData="Target [%s] does NOT exist" % Options.Target) else: EccGlobalData.gTarget = self.GetRealPathCase(os.path.normpath(Options.Target)) else: EdkLogger.warn("Ecc", EdkLogger.ECC_ERROR, "The target source tree was not specified, using current WORKSPACE instead!") EccGlobalData.gTarget = os.path.normpath(os.getenv("WORKSPACE")) if Options.keepdatabase != None: self.IsInit = False if Options.metadata != None and Options.sourcecode != None: EdkLogger.error("ECC", BuildToolError.OPTION_CONFLICT, ExtraData="-m and -s can't be specified at one time") if Options.metadata != None: self.ScanSourceCode = False if Options.sourcecode != None: self.ScanMetaData = False if Options.folders != None: self.OnlyScan = True
def GetFileList(FfsInf, FileType, FileExtension, Dict = {}): if FileType in Section.SectFileType.keys() : IsSect = True else : IsSect = False if FileExtension != None: Suffix = FileExtension elif IsSect : Suffix = Section.SectionType.get(FileType) else: Suffix = Section.BinFileType.get(FileType) if FfsInf == None: EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!') FileList = [] if FileType != None: for File in FfsInf.BinFileList: if File.Arch == "COMMON" or FfsInf.CurrentArch == File.Arch: if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \ and FileType == 'DXE_DPEX'and File.Type == 'SMM_DEPEX') \ or (FileType == 'TE'and File.Type == 'PE32'): if '*' in FfsInf.TargetOverrideList or File.Target == '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []: FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type)) else: GenFdsGlobalVariable.InfLogger ("\nBuild Target \'%s\' of File %s is not in the Scope of %s specified by INF %s in FDF" %(File.Target, File.File, FfsInf.TargetOverrideList, FfsInf.InfFileName)) else: GenFdsGlobalVariable.VerboseLogger ("\nFile Type \'%s\' of File %s in %s is not same with file type \'%s\' from Rule in FDF" %(File.Type, File.File, FfsInf.InfFileName, FileType)) 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): # # Get Makefile path and time stamp # MakefileDir = FfsInf.EfiOutputPath[:-len('OUTPUT')] Makefile = os.path.join(MakefileDir, 'Makefile') if not os.path.exists(Makefile): Makefile = os.path.join(MakefileDir, 'GNUmakefile') if not os.path.exists(Makefile): SuffixMap = FfsInf.GetFinalTargetSuffixMap() if Suffix in SuffixMap: FileList.extend(SuffixMap[Suffix]) else: # 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) if os.path.getmtime(FullName) > os.path.getmtime(Makefile): FileList.append(FullName) #Process the file lists is alphabetical for a same section type if len (FileList) > 1: FileList.sort() return FileList, IsSect
def SetDir (OutputDir, FdfParser, WorkSpace, ArchList): GenFdsGlobalVariable.VerboseLogger("GenFdsGlobalVariable.OutputDir:%s" % OutputDir) GenFdsGlobalVariable.FdfParser = FdfParser GenFdsGlobalVariable.WorkSpace = WorkSpace GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], DataType.TAB_FV_DIRECTORY) 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) # # Create FV Address inf file # GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf') FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w') # # Add [Options] # FvAddressFile.writelines("[options]" + DataType.TAB_LINE_BREAK) BsAddress = '0' for Arch in ArchList: 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 = " + \ BsAddress + \ DataType.TAB_LINE_BREAK) RtAddress = '0' for Arch in reversed(ArchList): temp = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress if temp: RtAddress = temp break FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \ RtAddress + \ DataType.TAB_LINE_BREAK) FvAddressFile.close()
def RWFile(self, CommentCharacter, KeySplitCharacter, Num): try: fr = open(self.FileName, 'r') fw = open(os.path.normpath(os.path.join(self.WorkSpace, 'Conf\\targetnew.txt')), 'w') existKeys = [] for Line in fr: if Line.startswith(CommentCharacter) or Line.strip() == '': fw.write(Line) else: LineList = Line.split(KeySplitCharacter, 1) if len(LineList) >= 2: Key = LineList[0].strip() if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary: if Key not in existKeys: existKeys.append(Key) else: print("Warning: Found duplicate key item in original configuration files!") if Num == 0: Line = "%-30s = \n" % Key else: ret = GetConfigureKeyValue(self, Key) if ret is not None: Line = ret fw.write(Line) for key in self.TargetTxtDictionary: if key not in existKeys: print("Warning: %s does not exist in original configuration file" % key) Line = GetConfigureKeyValue(self, key) if Line is None: Line = "%-30s = " % key fw.write(Line) fr.close() fw.close() os.remove(self.FileName) os.rename(os.path.normpath(os.path.join(self.WorkSpace, 'Conf\\targetnew.txt')), self.FileName) except: last_type, last_value, last_tb = sys.exc_info() traceback.print_exception(last_type, last_value, last_tb)
def GetAllIncludeFiles(Db): IncludeList = GetAllIncludeDirs(Db) IncludeFileList = [] for Dir in IncludeList: if os.path.isdir(Dir): SubDir = os.listdir(Dir) for Item in SubDir: if os.path.isfile(Item): IncludeFileList.append(Item) return IncludeFileList
def GenerateSourceFileList(self, SourceFileList, IncludeFileList): EdkLogger.quiet("Generating source files list ... ") mSourceFileList = [] mInfFileList = [] mDecFileList = [] mFileList = {} mCurrentInfFile = "" mCurrentSourceFileList = [] if SourceFileList: sfl = open(SourceFileList, "rb") for line in sfl: line = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line.strip())) if line[-2:].upper() == ".C" or line[-2:].upper() == ".H": if line not in mCurrentSourceFileList: mCurrentSourceFileList.append(line) mSourceFileList.append(line) EotGlobalData.gOP_SOURCE_FILES.write("%s\n" % line) if line[-4:].upper() == ".INF": if mCurrentInfFile != "": mFileList[mCurrentInfFile] = mCurrentSourceFileList mCurrentSourceFileList = [] mCurrentInfFile = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line)) EotGlobalData.gOP_INF.write("%s\n" % mCurrentInfFile) if mCurrentInfFile not in mFileList: mFileList[mCurrentInfFile] = mCurrentSourceFileList # Get all include files from packages if IncludeFileList: ifl = open(IncludeFileList, "rb") for line in ifl: if not line.strip(): continue newline = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line.strip())) for Root, Dirs, Files in os.walk(str(newline)): for File in Files: FullPath = os.path.normpath(os.path.join(Root, File)) if FullPath not in mSourceFileList and File[-2:].upper() == ".H": mSourceFileList.append(FullPath) EotGlobalData.gOP_SOURCE_FILES.write("%s\n" % FullPath) if FullPath not in mDecFileList and File.upper().find(".DEC") > -1: mDecFileList.append(FullPath) EotGlobalData.gSOURCE_FILES = mSourceFileList EotGlobalData.gOP_SOURCE_FILES.close() EotGlobalData.gINF_FILES = mFileList EotGlobalData.gOP_INF.close() EotGlobalData.gDEC_FILES = mDecFileList
def __init__(self, opt, args): self.WorkSpace = os.path.normpath(os.getenv('WORKSPACE')) self.Opt = opt self.Arg = args[0] self.FileName = os.path.normpath(os.path.join(self.WorkSpace, 'Conf', 'target.txt')) if os.path.isfile(self.FileName) == False: print("%s does not exist." % self.FileName) sys.exit(1) self.TargetTxtDictionary = { TAB_TAT_DEFINES_ACTIVE_PLATFORM : None, TAB_TAT_DEFINES_TOOL_CHAIN_CONF : None, TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER : None, TAB_TAT_DEFINES_TARGET : None, TAB_TAT_DEFINES_TOOL_CHAIN_TAG : None, TAB_TAT_DEFINES_TARGET_ARCH : None, TAB_TAT_DEFINES_BUILD_RULE_CONF : None, } self.LoadTargetTxtFile(self.FileName)
def LoadToolDefFile(self, FileName): # set multiple workspace PackagesPath = os.getenv("PACKAGES_PATH") mws.setWs(GlobalData.gWorkspace, PackagesPath) self.ToolsDefTxtDatabase = { TAB_TOD_DEFINES_TARGET : [], TAB_TOD_DEFINES_TOOL_CHAIN_TAG : [], TAB_TOD_DEFINES_TARGET_ARCH : [], TAB_TOD_DEFINES_COMMAND_TYPE : [] } self.IncludeToolDefFile(FileName) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET])) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG])) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH])) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE])) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET].sort() self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].sort() self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH].sort() self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE].sort() KeyList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH, TAB_TOD_DEFINES_COMMAND_TYPE] for Index in range(3, -1, -1): # make a copy of the keys to enumerate over to prevent issues when # adding/removing items from the original dict. for Key in list(self.ToolsDefTxtDictionary.keys()): List = Key.split('_') if List[Index] == TAB_STAR: for String in self.ToolsDefTxtDatabase[KeyList[Index]]: List[Index] = String NewKey = '%s_%s_%s_%s_%s' % tuple(List) if NewKey not in self.ToolsDefTxtDictionary: self.ToolsDefTxtDictionary[NewKey] = self.ToolsDefTxtDictionary[Key] del self.ToolsDefTxtDictionary[Key] elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]: del self.ToolsDefTxtDictionary[Key]
def LoadToolDefFile(self, FileName): # set multiple workspace PackagesPath = os.getenv("PACKAGES_PATH") mws.setWs(GlobalData.gWorkspace, PackagesPath) self.ToolsDefTxtDatabase = { TAB_TOD_DEFINES_TARGET : [], TAB_TOD_DEFINES_TOOL_CHAIN_TAG : [], TAB_TOD_DEFINES_TARGET_ARCH : [], TAB_TOD_DEFINES_COMMAND_TYPE : [] } self.IncludeToolDefFile(FileName) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET])) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG])) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH])) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE])) self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET].sort() self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].sort() self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH].sort() self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE].sort() KeyList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH, TAB_TOD_DEFINES_COMMAND_TYPE] for Index in range(3, -1, -1): for Key in dict(self.ToolsDefTxtDictionary): List = Key.split('_') if List[Index] == '*': for String in self.ToolsDefTxtDatabase[KeyList[Index]]: List[Index] = String NewKey = '%s_%s_%s_%s_%s' % tuple(List) if NewKey not in self.ToolsDefTxtDictionary: self.ToolsDefTxtDictionary[NewKey] = self.ToolsDefTxtDictionary[Key] continue del self.ToolsDefTxtDictionary[Key] elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]: del self.ToolsDefTxtDictionary[Key]
def __init__(self): self.StartTime = time.time() self.PrintRunTime = False self.PrintRunStatus = False self.RunStatus = '' # # Check environment valiable 'WORKSPACE' # if os.environ.get('WORKSPACE') == None: print 'ERROR: WORKSPACE not defined. Please run EdkSetup from the EDK II install directory.' return False self.CurrentWorkingDir = os.getcwd() self.WorkspaceDir = os.path.realpath(os.environ.get('WORKSPACE')) (Drive, Path) = os.path.splitdrive(self.WorkspaceDir) if Drive == '': (Drive, CwdPath) = os.path.splitdrive(self.CurrentWorkingDir) if Drive != '': self.WorkspaceDir = Drive + Path else: self.WorkspaceDir = Drive.upper() + Path self.WorkspaceRelativeWorkingDir = self.WorkspaceRelativePath (self.CurrentWorkingDir) try: # # Load TianoCoreOrgLogo, used for GUI tool # self.Icon = wx.Icon(self.WorkspaceFile('tools/Python/TianoCoreOrgLogo.gif'), wx.BITMAP_TYPE_GIF) except: self.Icon = None self.Verbose = False for Arg in sys.argv: if Arg.lower() == '-v': self.Verbose = True
def TrimEdkSources(Source, Target): if os.path.isdir(Source): for CurrentDir, Dirs, Files in os.walk(Source): if '.svn' in Dirs: Dirs.remove('.svn') elif "CVS" in Dirs: Dirs.remove("CVS") for FileName in Files: Dummy, Ext = os.path.splitext(FileName) if Ext.upper() not in ['.C', '.H']: continue if Target == None or Target == '': TrimEdkSourceCode( os.path.join(CurrentDir, FileName), os.path.join(CurrentDir, FileName) ) else: TrimEdkSourceCode( os.path.join(CurrentDir, FileName), os.path.join(Target, CurrentDir[len(Source)+1:], FileName) ) else: TrimEdkSourceCode(Source, Target)
help="Specify the WORKSPACE relative path of tool_def.txt file, which replace target.txt's TOOL_CHAIN_CONF definition. 0 will clear this setting in target.txt and can't combine with other value.") parser.add_option("-t", "--target", action="append", type="choice", choices=['DEBUG', 'RELEASE', '0'], dest="TARGET", help="TARGET is one of list: DEBUG, RELEASE, which replaces target.txt's TARGET definition. To specify more TARGET, please repeat this option. 0 will clear this setting in target.txt and can't combine with other value.") parser.add_option("-n", "--tagname", action="callback", type="string", dest="TOOL_CHAIN_TAG", callback=SingleCheckCallback, help="Specify the Tool Chain Tagname, which replaces target.txt's TOOL_CHAIN_TAG definition. 0 will clear this setting in target.txt and can't combine with other value.") parser.add_option("-r", "--buildrule", action="callback", type="string", dest="BUILD_RULE_FILE", callback=SingleCheckCallback, help="Specify the build rule configure file, which replaces target.txt's BUILD_RULE_CONF definition. If not specified, the default value Conf/build_rule.txt will be set.") parser.add_option("-m", "--multithreadnum", action="callback", type="int", dest="NUM", callback=RangeCheckCallback, help="Specify the multi-thread number which replace target.txt's MAX_CONCURRENT_THREAD_NUMBER. If the value is less than 2, MULTIPLE_THREAD will be disabled. If the value is larger than 1, MULTIPLE_THREAD will be enabled.") (opt, args)=parser.parse_args() return (opt, args) if __name__ == '__main__': EdkLogger.Initialize() EdkLogger.SetLevel(EdkLogger.QUIET) if os.getenv('WORKSPACE') is None: print("ERROR: WORKSPACE should be specified or edksetup script should be executed before run TargetTool") sys.exit(1) (opt, args) = MyOptionParser() if len(args) != 1 or (args[0].lower() != 'print' and args[0].lower() != 'clean' and args[0].lower() != 'set'): print("The number of args isn't 1 or the value of args is invalid.") sys.exit(1) if opt.NUM is not None and opt.NUM < 1: print("The MAX_CONCURRENT_THREAD_NUMBER must be larger than 0.") sys.exit(1) if opt.TARGET is not None and len(opt.TARGET) > 1: for elem in opt.TARGET: if elem == '0': print("0 will clear the TARGET setting in target.txt and can't combine with other value.") sys.exit(1)
def BuildMetaDataFileDatabase(self, SpecificDirs = None): ScanFolders = [] if SpecificDirs == None: ScanFolders.append(EccGlobalData.gTarget) else: for specificDir in SpecificDirs: ScanFolders.append(os.path.join(EccGlobalData.gTarget, specificDir)) EdkLogger.quiet("Building database for meta data files ...") Op = open(EccGlobalData.gConfig.MetaDataFileCheckPathOfGenerateFileList, 'w+') #SkipDirs = Read from config file SkipDirs = EccGlobalData.gConfig.SkipDirList SkipDirString = string.join(SkipDirs, '|') # p = re.compile(r'.*[\\/](?:%s)[\\/]?.*' % SkipDirString) p = re.compile(r'.*[\\/](?:%s^\S)[\\/]?.*' % SkipDirString) for scanFolder in ScanFolders: for Root, Dirs, Files in os.walk(scanFolder): if p.match(Root.upper()): continue for Dir in Dirs: Dirname = os.path.join(Root, Dir) if os.path.islink(Dirname): Dirname = os.path.realpath(Dirname) if os.path.isdir(Dirname): # symlinks to directories are treated as directories Dirs.remove(Dir) Dirs.append(Dirname) for File in Files: if len(File) > 4 and File[-4:].upper() == ".DEC": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) #Dec(Filename, True, True, EccGlobalData.gWorkspace, EccGlobalData.gDb) self.MetaFile = DecParser(Filename, MODEL_FILE_DEC, EccGlobalData.gDb.TblDec) self.MetaFile.Start() continue if len(File) > 4 and File[-4:].upper() == ".DSC": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) #Dsc(Filename, True, True, EccGlobalData.gWorkspace, EccGlobalData.gDb) self.MetaFile = DscParser(PathClass(Filename, Root), MODEL_FILE_DSC, MetaFileStorage(EccGlobalData.gDb.TblDsc.Cur, Filename, MODEL_FILE_DSC, True)) # alwasy do post-process, in case of macros change self.MetaFile.DoPostProcess() self.MetaFile.Start() self.MetaFile._PostProcess() continue if len(File) > 4 and File[-4:].upper() == ".INF": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) #Inf(Filename, True, True, EccGlobalData.gWorkspace, EccGlobalData.gDb) self.MetaFile = InfParser(Filename, MODEL_FILE_INF, EccGlobalData.gDb.TblInf) self.MetaFile.Start() continue if len(File) > 4 and File[-4:].upper() == ".FDF": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) Fdf(Filename, True, EccGlobalData.gWorkspace, EccGlobalData.gDb) continue if len(File) > 4 and File[-4:].upper() == ".UNI": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) EccGlobalData.gDb.TblFile.InsertFile(Filename, MODEL_FILE_UNI) continue Op.close() # Commit to database EccGlobalData.gDb.Conn.commit() EdkLogger.quiet("Building database for meta data files done!")
def GetFileList(FfsInf, FileType, FileExtension, Dict=None, IsMakefile=False, SectionType=None): IsSect = FileType in Section.SectFileType if FileExtension is not None: Suffix = FileExtension elif IsSect: Suffix = Section.SectionType.get(FileType) else: Suffix = Section.BinFileType.get(FileType) if FfsInf is None: EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!') FileList = [] if FileType is not None: for File in FfsInf.BinFileList: if File.Arch == TAB_ARCH_COMMON or FfsInf.CurrentArch == File.Arch: if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \ and FileType == 'DXE_DPEX' and File.Type == BINARY_FILE_TYPE_SMM_DEPEX) \ or (FileType == BINARY_FILE_TYPE_TE and File.Type == BINARY_FILE_TYPE_PE32): if TAB_STAR in FfsInf.TargetOverrideList or File.Target == TAB_STAR or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []: FileList.append( FfsInf.PatchEfiFile(File.Path, File.Type)) else: GenFdsGlobalVariable.InfLogger( "\nBuild Target \'%s\' of File %s is not in the Scope of %s specified by INF %s in FDF" % (File.Target, File.File, FfsInf.TargetOverrideList, FfsInf.InfFileName)) else: GenFdsGlobalVariable.VerboseLogger( "\nFile Type \'%s\' of File %s in %s is not same with file type \'%s\' from Rule in FDF" % (File.Type, File.File, FfsInf.InfFileName, FileType)) 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)) elif FileType is None and SectionType == BINARY_FILE_TYPE_RAW: for File in FfsInf.BinFileList: if File.Ext == Suffix: FileList.append(File.Path) if (not IsMakefile and Suffix is not None and os.path.exists( FfsInf.EfiOutputPath)) or (IsMakefile and Suffix is not None): # # Get Makefile path and time stamp # MakefileDir = FfsInf.EfiOutputPath[:-len('OUTPUT')] Makefile = os.path.join(MakefileDir, 'Makefile') if not os.path.exists(Makefile): Makefile = os.path.join(MakefileDir, 'GNUmakefile') if os.path.exists(Makefile): # 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] == Suffix: FullName = os.path.join(Dirpath, F) if os.path.getmtime(FullName) > os.path.getmtime( Makefile): FileList.append(FullName) if not FileList: SuffixMap = FfsInf.GetFinalTargetSuffixMap() if Suffix in SuffixMap: FileList.extend(SuffixMap[Suffix]) #Process the file lists is alphabetical for a same section type if len(FileList) > 1: FileList.sort() return FileList, IsSect
def main(): global Options Options = myOptionParser() global Workspace Workspace = "" ArchList = None ReturnCode = 0 EdkLogger.Initialize() try: if Options.verbose != None: EdkLogger.SetLevel(EdkLogger.VERBOSE) GenFdsGlobalVariable.VerboseMode = True if Options.FixedAddress != None: GenFdsGlobalVariable.FixedLoadAddress = True if Options.quiet != None: EdkLogger.SetLevel(EdkLogger.QUIET) if Options.debug != None: EdkLogger.SetLevel(Options.debug + 1) GenFdsGlobalVariable.DebugLevel = Options.debug else: EdkLogger.SetLevel(EdkLogger.INFO) if (Options.Workspace == None): 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(Options.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(Options.Workspace) GenFdsGlobalVariable.WorkSpaceDir = Workspace if 'EDK_SOURCE' in os.environ.keys(): GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE']) if (Options.debug): GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace) if Options.GenfdsMultiThread: GenFdsGlobalVariable.EnableGenfdsMultiThread = True os.chdir(GenFdsGlobalVariable.WorkSpaceDir) # set multiple workspace PackagesPath = os.getenv("PACKAGES_PATH") mws.setWs(GenFdsGlobalVariable.WorkSpaceDir, PackagesPath) if (Options.filename): FdfFilename = Options.filename 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 (Options.BuildTarget): GenFdsGlobalVariable.TargetName = Options.BuildTarget if (Options.ToolChain): GenFdsGlobalVariable.ToolChainTag = Options.ToolChain if (Options.activePlatform): ActivePlatform = Options.activePlatform 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") GlobalData.BuildOptionPcd = Options.OptionPcd if Options.OptionPcd else {} GenFdsGlobalVariable.ActivePlatform = PathClass(NormPath(ActivePlatform)) if (Options.ConfDirectory): # Get alternate Conf location, if it is absolute, then just use the absolute directory name ConfDirectoryPath = os.path.normpath(Options.ConfDirectory) 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.keys(): 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: TargetTxt = TargetTxtClassObject.TargetTxtClassObject() TargetTxt.LoadTargetTxtFile(BuildConfigurationFile) # if no build target given in command line, get it from target.txt if not GenFdsGlobalVariable.TargetName: BuildTargetList = TargetTxt.TargetTxtDictionary[DataType.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[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG] if ToolChainList == 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 = Options.IgnoreSources if Options.Macros: for Pair in Options.Macros: 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() == "EFI_SOURCE": GlobalData.gEfiSource = List[1].strip() GlobalData.gGlobalDefines["EFI_SOURCE"] = GlobalData.gEfiSource continue elif List[0].strip() == "EDK_SOURCE": GlobalData.gEdkSource = List[1].strip() GlobalData.gGlobalDefines["EDK_SOURCE"] = GlobalData.gEdkSource continue elif 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.keys(): GlobalData.gGlobalDefines["TARGET"] = GenFdsGlobalVariable.TargetName if "TOOLCHAIN" not in GlobalData.gGlobalDefines.keys(): GlobalData.gGlobalDefines["TOOLCHAIN"] = GenFdsGlobalVariable.ToolChainTag if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines.keys(): GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = GenFdsGlobalVariable.ToolChainTag """call Workspace build create database""" GlobalData.gDatabasePath = os.path.normpath(os.path.join(ConfDirectoryPath, GlobalData.gDatabasePath)) BuildWorkSpace = WorkspaceDatabase(GlobalData.gDatabasePath) BuildWorkSpace.InitDatabase() # # Get files real name in workspace dir # GlobalData.gAllFiles = DirCache(Workspace) GlobalData.gWorkspace = Workspace if (Options.archList) : ArchList = Options.archList.split(',') else: # EdkLogger.error("GenFds", OPTION_MISSING, "Missing build ARCH") ArchList = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON', Options.BuildTarget, Options.ToolChain].SupArchList TargetArchList = set(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON', Options.BuildTarget, Options.ToolChain].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, 'COMMON'].SupArchList))) for Arch in ArchList: GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, Options.BuildTarget, Options.ToolChain].OutputDirectory) GenFdsGlobalVariable.PlatformName = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, Options.BuildTarget, Options.ToolChain].PlatformName if (Options.outputDir): OutputDirFromCommandLine = GenFdsGlobalVariable.ReplaceWorkspaceMacro(Options.outputDir) 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 """ FdfParserObj = FdfParser.FdfParser(FdfFilename) FdfParserObj.ParseFile() if FdfParserObj.CycleReferenceCheck(): EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Cycle Reference Detected in FDF file") if (Options.uiFdName) : if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict.keys(): GenFds.OnlyGenerateThisFd = Options.uiFdName else: EdkLogger.error("GenFds", OPTION_VALUE_INVALID, "No such an FD in FDF file: %s" % Options.uiFdName) if (Options.uiFvName) : if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict.keys(): GenFds.OnlyGenerateThisFv = Options.uiFvName else: 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) GenFdsGlobalVariable.WorkSpace = BuildWorkSpace if ArchList != None: 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 Fv in FdfParserObj.Profile.FvDict: FvObj = FdfParserObj.Profile.FvDict[Fv] for Fd in FdfParserObj.Profile.FdDict: FdObj = FdfParserObj.Profile.FdDict[Fd] for RegionObj in FdObj.RegionList: if RegionObj.RegionType != 'FV': continue for RegionData in RegionObj.RegionDataList: if FvObj.UiFvName.upper() == RegionData.upper(): 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 FdfParser.Warning, X: EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError=False) ReturnCode = FORMAT_INVALID
def BuildMetaDataFileDatabase(self, SpecificDirs=None): ScanFolders = [] if SpecificDirs == None: ScanFolders.append(EccGlobalData.gTarget) else: for specificDir in SpecificDirs: ScanFolders.append( os.path.join(EccGlobalData.gTarget, specificDir)) EdkLogger.quiet("Building database for meta data files ...") Op = open( EccGlobalData.gConfig.MetaDataFileCheckPathOfGenerateFileList, 'w+') #SkipDirs = Read from config file SkipDirs = EccGlobalData.gConfig.SkipDirList SkipDirString = string.join(SkipDirs, '|') # p = re.compile(r'.*[\\/](?:%s)[\\/]?.*' % SkipDirString) p = re.compile(r'.*[\\/](?:%s^\S)[\\/]?.*' % SkipDirString) for scanFolder in ScanFolders: for Root, Dirs, Files in os.walk(scanFolder): if p.match(Root.upper()): continue for Dir in Dirs: Dirname = os.path.join(Root, Dir) if os.path.islink(Dirname): Dirname = os.path.realpath(Dirname) if os.path.isdir(Dirname): # symlinks to directories are treated as directories Dirs.remove(Dir) Dirs.append(Dirname) for File in Files: if len(File) > 4 and File[-4:].upper() == ".DEC": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) #Dec(Filename, True, True, EccGlobalData.gWorkspace, EccGlobalData.gDb) self.MetaFile = DecParser(Filename, MODEL_FILE_DEC, EccGlobalData.gDb.TblDec) self.MetaFile.Start() continue if len(File) > 4 and File[-4:].upper() == ".DSC": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) #Dsc(Filename, True, True, EccGlobalData.gWorkspace, EccGlobalData.gDb) self.MetaFile = DscParser( PathClass(Filename, Root), MODEL_FILE_DSC, MetaFileStorage(EccGlobalData.gDb.TblDsc.Cur, Filename, MODEL_FILE_DSC, True)) # alwasy do post-process, in case of macros change self.MetaFile.DoPostProcess() self.MetaFile.Start() self.MetaFile._PostProcess() continue if len(File) > 4 and File[-4:].upper() == ".INF": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) #Inf(Filename, True, True, EccGlobalData.gWorkspace, EccGlobalData.gDb) self.MetaFile = InfParser(Filename, MODEL_FILE_INF, EccGlobalData.gDb.TblInf) self.MetaFile.Start() continue if len(File) > 4 and File[-4:].upper() == ".FDF": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) Fdf(Filename, True, EccGlobalData.gWorkspace, EccGlobalData.gDb) continue if len(File) > 4 and File[-4:].upper() == ".UNI": Filename = os.path.normpath(os.path.join(Root, File)) EdkLogger.quiet("Parsing %s" % Filename) Op.write("%s\r" % Filename) EccGlobalData.gDb.TblFile.InsertFile( Filename, MODEL_FILE_UNI) continue Op.close() # Commit to database EccGlobalData.gDb.Conn.commit() EdkLogger.quiet("Building database for meta data files done!")
print '\nPpis =', M.PpiDeclarations for Item in M.PpiDeclarations: print Item.CName, Item.Guid, Item.SupArchList print '\nLibraryClasses =', M.LibraryClassDeclarations for Item in M.LibraryClassDeclarations: print Item.LibraryClass, Item.RecommendedInstance, Item.SupModuleList, Item.SupArchList print '\nPcds =', M.PcdDeclarations for Item in M.PcdDeclarations: print 'CName=', Item.CName, 'TokenSpaceGuidCName=', Item.TokenSpaceGuidCName, 'DefaultValue=', Item.DefaultValue, 'ItemType=', Item.ItemType, 'Token=', Item.Token, 'DatumType=', Item.DatumType, Item.SupArchList ## # # This acts like the main() function for the script, unless it is 'import'ed into another # script. # if __name__ == '__main__': EdkLogger.Initialize() EdkLogger.SetLevel(EdkLogger.DEBUG_0) W = os.getenv('WORKSPACE') F = os.path.join(W, 'Nt32Pkg/Nt32Pkg.dec') Db = Database.Database('Dec.db') Db.InitDatabase() P = Dec(os.path.normpath(F), True, True, W, Db) P.ShowPackage() Db.Close()
def __InfParse__(self, Dict = {}): GenFdsGlobalVariable.VerboseLogger( " Begine parsing INf file : %s" %self.InfFileName) self.InfFileName = self.InfFileName.replace('$(WORKSPACE)', '') if len(self.InfFileName) > 1 and self.InfFileName[0] == '\\' and self.InfFileName[1] == '\\': pass elif self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' : self.InfFileName = self.InfFileName[1:] if self.InfFileName.find('$') == -1: InfPath = NormPath(self.InfFileName) if not os.path.exists(InfPath): InfPath = GenFdsGlobalVariable.ReplaceWorkspaceMacro(InfPath) if not os.path.exists(InfPath): EdkLogger.error("GenFds", GENFDS_ERROR, "Non-existant Module %s !" % (self.InfFileName)) self.CurrentArch = self.GetCurrentArch() # # Get the InfClass object # PathClassObj = PathClass(self.InfFileName, GenFdsGlobalVariable.WorkSpaceDir) ErrorCode, ErrorInfo = PathClassObj.Validate(".inf") if ErrorCode != 0: EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo) if self.OverrideGuid: PathClassObj = ProcessDuplicatedInf(PathClassObj, self.OverrideGuid, GenFdsGlobalVariable.WorkSpaceDir) if self.CurrentArch != None: Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] # # Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath # self.BaseName = Inf.BaseName self.ModuleGuid = Inf.Guid self.ModuleType = Inf.ModuleType if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification: self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION'] if Inf.AutoGenVersion < 0x00010005: self.ModuleType = Inf.ComponentType self.VersionString = Inf.Version self.BinFileList = Inf.Binaries self.SourceFileList = Inf.Sources if self.KeepReloc == None and Inf.Shadow: self.ShadowFromInfFile = Inf.Shadow else: Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] self.BaseName = Inf.BaseName self.ModuleGuid = Inf.Guid self.ModuleType = Inf.ModuleType if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification: self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION'] self.VersionString = Inf.Version self.BinFileList = Inf.Binaries self.SourceFileList = Inf.Sources if self.BinFileList == []: EdkLogger.error("GenFds", GENFDS_ERROR, "INF %s specified in FDF could not be found in build ARCH %s!" \ % (self.InfFileName, GenFdsGlobalVariable.ArchList)) if self.OverrideGuid: self.ModuleGuid = self.OverrideGuid if len(self.SourceFileList) != 0 and not self.InDsc: EdkLogger.warn("GenFds", GENFDS_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % (self.InfFileName)) if self.ModuleType == 'SMM_CORE' and int(self.PiSpecVersion, 16) < 0x0001000A: EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File=self.InfFileName) if Inf._Defs != None and len(Inf._Defs) > 0: self.OptRomDefs.update(Inf._Defs) self.PatchPcds = [] InfPcds = Inf.Pcds Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] FdfPcdDict = GenFdsGlobalVariable.FdfParser.Profile.PcdDict # Workaround here: both build and GenFds tool convert the workspace path to lower case # But INF file path in FDF and DSC file may have real case characters. # Try to convert the path to lower case to see if PCDs value are override by DSC. DscModules = {} for DscModule in Platform.Modules: DscModules[str(DscModule).lower()] = Platform.Modules[DscModule] for PcdKey in InfPcds: Pcd = InfPcds[PcdKey] if not hasattr(Pcd, 'Offset'): continue if Pcd.Type != 'PatchableInModule': continue # Override Patchable PCD value by the value from DSC PatchPcd = None InfLowerPath = str(PathClassObj).lower() if InfLowerPath in DscModules and PcdKey in DscModules[InfLowerPath].Pcds: PatchPcd = DscModules[InfLowerPath].Pcds[PcdKey] elif PcdKey in Platform.Pcds: PatchPcd = Platform.Pcds[PcdKey] DscOverride = False if PatchPcd and Pcd.Type == PatchPcd.Type: DefaultValue = PatchPcd.DefaultValue DscOverride = True # Override Patchable PCD value by the value from FDF FdfOverride = False if PcdKey in FdfPcdDict: DefaultValue = FdfPcdDict[PcdKey] FdfOverride = True if not DscOverride and not FdfOverride: continue # Check value, if value are equal, no need to patch if Pcd.DatumType == "VOID*": if Pcd.DefaultValue == DefaultValue or DefaultValue in [None, '']: continue # Get the string size from FDF or DSC if DefaultValue[0] == 'L': # Remove L"", but the '\0' must be appended MaxDatumSize = str((len(DefaultValue) - 2) * 2) elif DefaultValue[0] == '{': MaxDatumSize = str(len(DefaultValue.split(','))) else: MaxDatumSize = str(len(DefaultValue) - 1) if DscOverride: Pcd.MaxDatumSize = PatchPcd.MaxDatumSize # If no defined the maximum size in DSC, try to get current size from INF if Pcd.MaxDatumSize in ['', None]: Pcd.MaxDatumSize = str(len(Pcd.DefaultValue.split(','))) else: Base1 = Base2 = 10 if Pcd.DefaultValue.upper().startswith('0X'): Base1 = 16 if DefaultValue.upper().startswith('0X'): Base2 = 16 try: PcdValueInImg = int(Pcd.DefaultValue, Base1) PcdValueInDscOrFdf = int(DefaultValue, Base2) if PcdValueInImg == PcdValueInDscOrFdf: continue except: continue # Check the Pcd size and data type if Pcd.DatumType == "VOID*": if int(MaxDatumSize) > int(Pcd.MaxDatumSize): EdkLogger.error("GenFds", GENFDS_ERROR, "The size of VOID* type PCD '%s.%s' exceeds its maximum size %d bytes." \ % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, int(MaxDatumSize) - int(Pcd.MaxDatumSize))) else: if PcdValueInDscOrFdf > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType] \ or PcdValueInImg > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType]: EdkLogger.error("GenFds", GENFDS_ERROR, "The size of %s type PCD '%s.%s' doesn't match its data type." \ % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)) self.PatchPcds.append((Pcd, DefaultValue)) self.InfModule = Inf self.PcdIsDriver = Inf.PcdIsDriver self.IsBinaryModule = Inf.IsBinaryModule GenFdsGlobalVariable.VerboseLogger("BaseName : %s" % self.BaseName) GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" % self.ModuleGuid) GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" % self.ModuleType) GenFdsGlobalVariable.VerboseLogger("VersionString : %s" % self.VersionString) GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" % self.InfFileName) # # Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\ # self.OutputPath = os.path.join(GenFdsGlobalVariable.FfsDir, \ self.ModuleGuid + self.BaseName) if not os.path.exists(self.OutputPath) : os.makedirs(self.OutputPath) self.EfiOutputPath = self.__GetEFIOutPutPath__() GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: " + self.EfiOutputPath)
def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, vtfDict=None, MacroDict={}, Flag=False): Size = self.Size if not Flag: GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset) GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size) GenFdsGlobalVariable.SharpCounter = 0 if Flag and (self.RegionType != BINARY_FILE_TYPE_FV): return if self.RegionType == BINARY_FILE_TYPE_FV: # # Get Fv from FvDict # self.FvAddress = int(BaseAddress, 16) + self.Offset FvBaseAddress = '0x%X' % self.FvAddress FvOffset = 0 for RegionData in self.RegionDataList: FileName = None if RegionData.endswith(".fv"): RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) if not Flag: GenFdsGlobalVariable.InfLogger( ' Region FV File Name = .fv : %s' % RegionData) if RegionData[1] != ':': RegionData = mws.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'fv' in ImageBinDict: if not Flag: GenFdsGlobalVariable.InfLogger(' Region Name = FV') FileName = ImageBinDict[RegionData.upper() + 'fv'] else: # # Generate FvImage. # FvObj = None if RegionData.upper( ) in GenFdsGlobalVariable.FdfParser.Profile.FvDict: FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[ RegionData.upper()] if FvObj is not None: if not Flag: GenFdsGlobalVariable.InfLogger( ' Region Name = FV') # # Call GenFv tool # self.BlockInfoOfRegion(BlockSizeList, FvObj) self.FvAddress = self.FvAddress + FvOffset FvAlignValue = GenFdsGlobalVariable.GetAlignment( FvObj.FvAlignment) if self.FvAddress % FvAlignValue != 0: EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment)) FvBuffer = BytesIO('') FvBaseAddress = '0x%X' % self.FvAddress BlockSize = None BlockNum = None FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict, Flag=Flag) if Flag: continue FvBufferLen = len(FvBuffer.getvalue()) if FvBufferLen > Size: FvBuffer.close() EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size)) # # Put the generated image into FD buffer. # Buffer.write(FvBuffer.getvalue()) FvBuffer.close() FvOffset = FvOffset + FvBufferLen Size = Size - FvBufferLen continue else: EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData)) # # Add the exist Fv image into FD buffer # if not Flag: if FileName is not None: FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of FV File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) BinFile = open(FileName, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if not Flag: self.PadBuffer(Buffer, ErasePolarity, Size) if self.RegionType == 'CAPSULE': # # Get Capsule from Capsule Dict # for RegionData in self.RegionDataList: if RegionData.endswith(".cap"): RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) GenFdsGlobalVariable.InfLogger( ' Region CAPSULE Image Name = .cap : %s' % RegionData) if RegionData[1] != ':': RegionData = mws.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'cap' in ImageBinDict: GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE') FileName = ImageBinDict[RegionData.upper() + 'cap'] else: # # Generate Capsule image and Put it into FD buffer # CapsuleObj = None if RegionData.upper( ) in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict: CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[ RegionData.upper()] if CapsuleObj is not None: CapsuleObj.CapsuleName = RegionData.upper() GenFdsGlobalVariable.InfLogger( ' Region Name = CAPSULE') # # Call GenFv tool to generate Capsule Image # FileName = CapsuleObj.GenCapsule() CapsuleObj.CapsuleName = None else: EdkLogger.error( "GenFds", GENFDS_ERROR, "Capsule (%s) is NOT described in FDF file!" % (RegionData)) # # Add the capsule image into FD buffer # FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \ % (FileLength, RegionData, Size)) BinFile = open(FileName, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # self.PadBuffer(Buffer, ErasePolarity, Size) if self.RegionType in ('FILE', 'INF'): for RegionData in self.RegionDataList: if self.RegionType == 'INF': RegionData.__InfParse__(None) if len(RegionData.BinFileList) != 1: EdkLogger.error( 'GenFds', GENFDS_ERROR, 'INF in FD region can only contain one binary: %s' % RegionData) File = RegionData.BinFileList[0] RegionData = RegionData.PatchEfiFile(File.Path, File.Type) else: RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) if RegionData[1] != ':': RegionData = mws.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) # # Add the file image into FD buffer # FileLength = os.stat(RegionData)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) GenFdsGlobalVariable.InfLogger(' Region File Name = %s' % RegionData) BinFile = open(RegionData, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # self.PadBuffer(Buffer, ErasePolarity, Size) if self.RegionType == 'DATA': GenFdsGlobalVariable.InfLogger(' Region Name = DATA') DataSize = 0 for RegionData in self.RegionDataList: Data = RegionData.split(',') DataSize = DataSize + len(Data) if DataSize > Size: EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of DATA is larger than Region Size ") else: for item in Data: Buffer.write(pack('B', int(item, 16))) Size = Size - DataSize # # Pad the left buffer # self.PadBuffer(Buffer, ErasePolarity, Size) if self.RegionType is None: GenFdsGlobalVariable.InfLogger(' Region Name = None') self.PadBuffer(Buffer, ErasePolarity, Size)
def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, vtfDict=None, MacroDict={}): Size = self.Size GenFdsGlobalVariable.InfLogger("\nGenerate Region at Offset 0x%X" % self.Offset) GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size) GenFdsGlobalVariable.SharpCounter = 0 if self.RegionType == "FV": # # Get Fv from FvDict # self.FvAddress = int(BaseAddress, 16) + self.Offset FvBaseAddress = "0x%X" % self.FvAddress FvOffset = 0 for RegionData in self.RegionDataList: FileName = None if RegionData.endswith(".fv"): RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) GenFdsGlobalVariable.InfLogger(" Region FV File Name = .fv : %s" % RegionData) if RegionData[1] != ":": RegionData = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + "fv" in ImageBinDict.keys(): GenFdsGlobalVariable.InfLogger(" Region Name = FV") FileName = ImageBinDict[RegionData.upper() + "fv"] else: # # Generate FvImage. # FvObj = None if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(RegionData.upper()) if FvObj != None: GenFdsGlobalVariable.InfLogger(" Region Name = FV") # # Call GenFv tool # self.BlockInfoOfRegion(BlockSizeList, FvObj) self.FvAddress = self.FvAddress + FvOffset FvAlignValue = self.GetFvAlignValue(FvObj.FvAlignment) if self.FvAddress % FvAlignValue != 0: EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment), ) FvBuffer = StringIO.StringIO("") FvBaseAddress = "0x%X" % self.FvAddress BlockSize = None BlockNum = None FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict) if FvBuffer.len > Size: FvBuffer.close() EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size), ) # # Put the generated image into FD buffer. # Buffer.write(FvBuffer.getvalue()) FvBuffer.close() FvOffset = FvOffset + FvBuffer.len Size = Size - FvBuffer.len continue else: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData)) # # Add the exist Fv image into FD buffer # if FileName != None: FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of FV File (%s) is larger than Region Size 0x%X specified." % (RegionData, Size), ) BinFile = open(FileName, "r+b") Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if ErasePolarity == "1": PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack("B", PadData)) if self.RegionType == "CAPSULE": # # Get Capsule from Capsule Dict # for RegionData in self.RegionDataList: if RegionData.endswith(".cap"): RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) GenFdsGlobalVariable.InfLogger(" Region CAPSULE Image Name = .cap : %s" % RegionData) if RegionData[1] != ":": RegionData = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + "cap" in ImageBinDict.keys(): GenFdsGlobalVariable.InfLogger(" Region Name = CAPSULE") FileName = ImageBinDict[RegionData.upper() + "cap"] else: # # Generate Capsule image and Put it into FD buffer # CapsuleObj = None if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys(): CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[RegionData.upper()] if CapsuleObj != None: CapsuleObj.CapsuleName = RegionData.upper() GenFdsGlobalVariable.InfLogger(" Region Name = CAPSULE") # # Call GenFv tool to generate Capsule Image # FileName = CapsuleObj.GenCapsule() CapsuleObj.CapsuleName = None else: EdkLogger.error( "GenFds", GENFDS_ERROR, "Capsule (%s) is NOT described in FDF file!" % (RegionData) ) # # Add the capsule image into FD buffer # FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error( "GenFds", GENFDS_ERROR, "Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." % (FileLength, RegionData, Size), ) BinFile = open(FileName, "r+b") Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if ErasePolarity == "1": PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack("B", PadData)) if self.RegionType == "FILE": for RegionData in self.RegionDataList: RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) if RegionData[1] != ":": RegionData = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) # # Add the file image into FD buffer # FileLength = os.stat(RegionData)[ST_SIZE] if FileLength > Size: EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of File (%s) is larger than Region Size 0x%X specified." % (RegionData, Size), ) GenFdsGlobalVariable.InfLogger(" Region File Name = %s" % RegionData) BinFile = open(RegionData, "rb") Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if ErasePolarity == "1": PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack("B", PadData)) if self.RegionType == "DATA": GenFdsGlobalVariable.InfLogger(" Region Name = DATA") DataSize = 0 for RegionData in self.RegionDataList: Data = RegionData.split(",") DataSize = DataSize + len(Data) if DataSize > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of DATA is larger than Region Size ") else: for item in Data: Buffer.write(pack("B", int(item, 16))) Size = Size - DataSize # # Pad the left buffer # if Size > 0: if ErasePolarity == "1": PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack("B", PadData)) if self.RegionType == None: GenFdsGlobalVariable.InfLogger(" Region Name = None") if ErasePolarity == "1": PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack("B", PadData))
def main(): global Options Options = myOptionParser() global Workspace Workspace = "" ArchList = None ReturnCode = 0 EdkLogger.Initialize() try: if Options.verbose != None: EdkLogger.SetLevel(EdkLogger.VERBOSE) GenFdsGlobalVariable.VerboseMode = True if Options.FixedAddress != None: GenFdsGlobalVariable.FixedLoadAddress = True if Options.quiet != None: EdkLogger.SetLevel(EdkLogger.QUIET) if Options.debug != None: EdkLogger.SetLevel(Options.debug + 1) GenFdsGlobalVariable.DebugLevel = Options.debug else: EdkLogger.SetLevel(EdkLogger.INFO) if (Options.Workspace == None): 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(Options.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(Options.Workspace) GenFdsGlobalVariable.WorkSpaceDir = Workspace if 'EDK_SOURCE' in os.environ.keys(): GenFdsGlobalVariable.EdkSourceDir = os.path.normcase( os.environ['EDK_SOURCE']) if (Options.debug): GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace) os.chdir(GenFdsGlobalVariable.WorkSpaceDir) # set multiple workspace PackagesPath = os.getenv("PACKAGES_PATH") mws.setWs(GenFdsGlobalVariable.WorkSpaceDir, PackagesPath) if (Options.filename): FdfFilename = Options.filename 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 (Options.BuildTarget): GenFdsGlobalVariable.TargetName = Options.BuildTarget else: EdkLogger.error("GenFds", OPTION_MISSING, "Missing build target") if (Options.ToolChain): GenFdsGlobalVariable.ToolChainTag = Options.ToolChain else: EdkLogger.error("GenFds", OPTION_MISSING, "Missing tool chain tag") if (Options.activePlatform): ActivePlatform = Options.activePlatform 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!") if os.path.normcase(ActivePlatform).find(Workspace) == 0: ActivePlatform = mws.relpath(ActivePlatform, Workspace) if len(ActivePlatform) > 0: if ActivePlatform[0] == '\\' or ActivePlatform[0] == '/': ActivePlatform = ActivePlatform[1:] else: EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!") else: EdkLogger.error("GenFds", OPTION_MISSING, "Missing active platform") GenFdsGlobalVariable.ActivePlatform = PathClass( NormPath(ActivePlatform), Workspace) if (Options.ConfDirectory): # Get alternate Conf location, if it is absolute, then just use the absolute directory name ConfDirectoryPath = os.path.normpath(Options.ConfDirectory) 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: # Get standard WORKSPACE/Conf, use the absolute path to the WORKSPACE/Conf ConfDirectoryPath = mws.join(GenFdsGlobalVariable.WorkSpaceDir, 'Conf') GenFdsGlobalVariable.ConfDir = ConfDirectoryPath BuildConfigurationFile = os.path.normpath( os.path.join(ConfDirectoryPath, "target.txt")) if os.path.isfile(BuildConfigurationFile) == True: TargetTxtClassObject.TargetTxtClassObject(BuildConfigurationFile) else: EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=BuildConfigurationFile) #Set global flag for build mode GlobalData.gIgnoreSource = Options.IgnoreSources if Options.Macros: for Pair in Options.Macros: if Pair.startswith('"'): Pair = Pair[1:] if Pair.endswith('"'): Pair = Pair[:-1] List = Pair.split('=') if len(List) == 2: if List[0].strip() == "EFI_SOURCE": GlobalData.gEfiSource = List[1].strip() GlobalData.gGlobalDefines[ "EFI_SOURCE"] = GlobalData.gEfiSource continue elif List[0].strip() == "EDK_SOURCE": GlobalData.gEdkSource = List[1].strip() GlobalData.gGlobalDefines[ "EDK_SOURCE"] = GlobalData.gEdkSource continue elif 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 """call Workspace build create database""" GlobalData.gDatabasePath = os.path.normpath( os.path.join(ConfDirectoryPath, GlobalData.gDatabasePath)) BuildWorkSpace = WorkspaceDatabase(GlobalData.gDatabasePath) BuildWorkSpace.InitDatabase() # # Get files real name in workspace dir # GlobalData.gAllFiles = DirCache(Workspace) GlobalData.gWorkspace = Workspace if (Options.archList): ArchList = Options.archList.split(',') else: # EdkLogger.error("GenFds", OPTION_MISSING, "Missing build ARCH") ArchList = BuildWorkSpace.BuildObject[ GenFdsGlobalVariable.ActivePlatform, 'COMMON', Options.BuildTarget, Options.ToolChain].SupArchList TargetArchList = set(BuildWorkSpace.BuildObject[ GenFdsGlobalVariable.ActivePlatform, 'COMMON', Options.BuildTarget, Options.ToolChain].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, 'COMMON'].SupArchList))) for Arch in ArchList: GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath( BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, Options.BuildTarget, Options.ToolChain].OutputDirectory) GenFdsGlobalVariable.PlatformName = BuildWorkSpace.BuildObject[ GenFdsGlobalVariable.ActivePlatform, Arch, Options.BuildTarget, Options.ToolChain].PlatformName if (Options.outputDir): OutputDirFromCommandLine = GenFdsGlobalVariable.ReplaceWorkspaceMacro( Options.outputDir) 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 """ FdfParserObj = FdfParser.FdfParser(FdfFilename) FdfParserObj.ParseFile() if FdfParserObj.CycleReferenceCheck(): EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Cycle Reference Detected in FDF file") if (Options.uiFdName): if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict.keys(): GenFds.OnlyGenerateThisFd = Options.uiFdName else: EdkLogger.error( "GenFds", OPTION_VALUE_INVALID, "No such an FD in FDF file: %s" % Options.uiFdName) if (Options.uiFvName): if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict.keys(): GenFds.OnlyGenerateThisFv = Options.uiFvName else: 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) """Call GenFds""" GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList) """Generate GUID cross reference file""" GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList) """Display FV space info.""" GenFds.DisplayFvSpaceInfo(FdfParserObj) except FdfParser.Warning, X: EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError=False) ReturnCode = FORMAT_INVALID
def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj): GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref") GuidXRefFile = BytesIO('') PkgGuidDict = {} GuidDict = {} ModuleList = [] FileGuidList = [] 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 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.write("%s %s\n" % (ModuleFile.BaseName, Module.BaseName)) else: GuidXRefFile.write("%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.write("%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.write("%s %s\n" %(FileStatementGuid, Name)) # Append GUIDs, Protocols, and PPIs to the Xref file GuidXRefFile.write("\n") for key, item in GuidDict.items(): GuidXRefFile.write("%s %s\n" % (GuidStructureStringToGuidString(item).upper(), key)) if GuidXRefFile.getvalue(): SaveFileOnChange(GuidXRefFileName, GuidXRefFile.getvalue(), False) GenFdsGlobalVariable.InfLogger("\nGUID cross reference file can be found at %s" % GuidXRefFileName) elif os.path.exists(GuidXRefFileName): os.remove(GuidXRefFileName) GuidXRefFile.close()
def __InitializeInf__ (self, BaseAddress = None, BlockSize= None, BlockNum = None, ErasePloarity='1', VtfDict=None) : # # Create FV inf file # self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.inf') self.FvInfFile = StringIO.StringIO() # # Add [Options] # self.FvInfFile.writelines("[options]" + T_CHAR_LF) if BaseAddress != None : self.FvInfFile.writelines("EFI_BASE_ADDRESS = " + \ BaseAddress + \ T_CHAR_LF) if BlockSize != None: self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \ '0x%X' %BlockSize + \ T_CHAR_LF) if BlockNum != None: self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \ ' 0x%X' %BlockNum + \ T_CHAR_LF) else: if self.BlockSizeList == []: if not self._GetBlockSize(): #set default block size is 1 self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x1" + T_CHAR_LF) for BlockSize in self.BlockSizeList : if BlockSize[0] != None: self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \ '0x%X' %BlockSize[0] + \ T_CHAR_LF) if BlockSize[1] != None: self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \ ' 0x%X' %BlockSize[1] + \ T_CHAR_LF) if self.BsBaseAddress != None: self.FvInfFile.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \ '0x%X' %self.BsBaseAddress) if self.RtBaseAddress != None: self.FvInfFile.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = ' + \ '0x%X' %self.RtBaseAddress) # # Add attribute # self.FvInfFile.writelines("[attributes]" + T_CHAR_LF) self.FvInfFile.writelines("EFI_ERASE_POLARITY = " + \ ' %s' %ErasePloarity + \ T_CHAR_LF) if not (self.FvAttributeDict == None): for FvAttribute in self.FvAttributeDict.keys() : self.FvInfFile.writelines("EFI_" + \ FvAttribute + \ ' = ' + \ self.FvAttributeDict[FvAttribute] + \ T_CHAR_LF ) if self.FvAlignment != None: self.FvInfFile.writelines("EFI_FVB2_ALIGNMENT_" + \ self.FvAlignment.strip() + \ " = TRUE" + \ T_CHAR_LF) # # Generate FV extension header file # if self.FvNameGuid == None or self.FvNameGuid == '': if len(self.FvExtEntryType) > 0: GenFdsGlobalVariable.ErrorLogger("FV Extension Header Entries declared for %s with no FvNameGuid declaration." % (self.UiFvName)) if self.FvNameGuid <> None and self.FvNameGuid <> '': TotalSize = 16 + 4 Buffer = '' if self.FvNameString == 'TRUE': # # Create EXT entry for FV UI name # This GUID is used: A67DF1FA-8DE8-4E98-AF09-4BDF2EFFBC7C # FvUiLen = len(self.UiFvName) TotalSize += (FvUiLen + 16 + 4) Guid = FV_UI_EXT_ENTY_GUID.split('-') # # Layout: # EFI_FIRMWARE_VOLUME_EXT_ENTRY : size 4 # GUID : size 16 # FV UI name # Buffer += (pack('HH', (FvUiLen + 16 + 4), 0x0002) + pack('=LHHBBBBBBBB', int(Guid[0], 16), int(Guid[1], 16), int(Guid[2], 16), int(Guid[3][-4:-2], 16), int(Guid[3][-2:], 16), int(Guid[4][-12:-10], 16), int(Guid[4][-10:-8], 16), int(Guid[4][-8:-6], 16), int(Guid[4][-6:-4], 16), int(Guid[4][-4:-2], 16), int(Guid[4][-2:], 16)) + self.UiFvName) for Index in range (0, len(self.FvExtEntryType)): if self.FvExtEntryType[Index] == 'FILE': # check if the path is absolute or relative if os.path.isabs(self.FvExtEntryData[Index]): FileFullPath = os.path.normpath(self.FvExtEntryData[Index]) else: FileFullPath = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.FvExtEntryData[Index])) # check if the file path exists or not if not os.path.isfile(FileFullPath): GenFdsGlobalVariable.ErrorLogger("Error opening FV Extension Header Entry file %s." % (self.FvExtEntryData[Index])) FvExtFile = open (FileFullPath,'rb') FvExtFile.seek(0,2) Size = FvExtFile.tell() if Size >= 0x10000: GenFdsGlobalVariable.ErrorLogger("The size of FV Extension Header Entry file %s exceeds 0x10000." % (self.FvExtEntryData[Index])) TotalSize += (Size + 4) FvExtFile.seek(0) Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16)) Buffer += FvExtFile.read() FvExtFile.close() if self.FvExtEntryType[Index] == 'DATA': ByteList = self.FvExtEntryData[Index].split(',') Size = len (ByteList) if Size >= 0x10000: GenFdsGlobalVariable.ErrorLogger("The size of FV Extension Header Entry data %s exceeds 0x10000." % (self.FvExtEntryData[Index])) TotalSize += (Size + 4) Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16)) for Index1 in range (0, Size): Buffer += pack('B', int(ByteList[Index1], 16)) Guid = self.FvNameGuid.split('-') Buffer = pack('=LHHBBBBBBBBL', int(Guid[0], 16), int(Guid[1], 16), int(Guid[2], 16), int(Guid[3][-4:-2], 16), int(Guid[3][-2:], 16), int(Guid[4][-12:-10], 16), int(Guid[4][-10:-8], 16), int(Guid[4][-8:-6], 16), int(Guid[4][-6:-4], 16), int(Guid[4][-4:-2], 16), int(Guid[4][-2:], 16), TotalSize ) + Buffer # # Generate FV extension header file if the total size is not zero # if TotalSize > 0: FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.ext') FvExtHeaderFile = StringIO.StringIO() FvExtHeaderFile.write(Buffer) Changed = SaveFileOnChange(FvExtHeaderFileName, FvExtHeaderFile.getvalue(), True) FvExtHeaderFile.close() if Changed: if os.path.exists (self.InfFileName): os.remove (self.InfFileName) self.FvInfFile.writelines("EFI_FV_EXT_HEADER_FILE_NAME = " + \ FvExtHeaderFileName + \ T_CHAR_LF) # # Add [Files] # self.FvInfFile.writelines("[files]" + T_CHAR_LF) if VtfDict != None and self.UiFvName in VtfDict.keys(): self.FvInfFile.writelines("EFI_FILE_NAME = " + \ VtfDict.get(self.UiFvName) + \ T_CHAR_LF)
print Item ## TargetTxtDict # # Load target.txt in input Conf dir # # @param ConfDir: Conf dir # # @retval Target An instance of TargetTxtClassObject() with loaded target.txt # def TargetTxtDict(ConfDir): Target = TargetTxtClassObject() Target.LoadTargetTxtFile( os.path.normpath(os.path.join(ConfDir, gDefaultTargetTxtFile))) return Target ## # # This acts like the main() function for the script, unless it is 'import'ed into another # script. # if __name__ == '__main__': pass Target = TargetTxtDict(os.getenv("WORKSPACE")) print Target.TargetTxtDictionary[ DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER] print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET] print Target.TargetTxtDictionary
def InitDatabase(self, NewDatabase=True): EdkLogger.verbose("\nInitialize EOT database started ...") # # Drop all old existing tables # if NewDatabase: if os.path.exists(self.DbPath): os.remove(self.DbPath) self.Conn = sqlite3.connect(self.DbPath, isolation_level='DEFERRED') self.Conn.execute("PRAGMA page_size=8192") self.Conn.execute("PRAGMA synchronous=OFF") # to avoid non-ascii charater conversion error self.Conn.text_factory = str self.Cur = self.Conn.cursor() self.TblDataModel = TableDataModel(self.Cur) self.TblFile = TableFile(self.Cur) self.TblFunction = TableFunction(self.Cur) self.TblIdentifier = TableIdentifier(self.Cur) self.TblReport = TableEotReport(self.Cur) self.TblInf = TableInf(self.Cur) self.TblDec = TableDec(self.Cur) self.TblDsc = TableDsc(self.Cur) self.TblFdf = TableFdf(self.Cur) self.TblQuery = TableQuery(self.Cur) self.TblQuery2 = TableQuery(self.Cur) self.TblQuery2.Table = 'Query2' # Create new tables if NewDatabase: self.TblDataModel.Create() self.TblFile.Create() self.TblFunction.Create() self.TblReport.Create() self.TblInf.Create() self.TblDec.Create() self.TblDsc.Create() self.TblFdf.Create() self.TblQuery.Create() self.TblQuery2.Create() # Init each table's ID self.TblDataModel.InitID() self.TblFile.InitID() self.TblFunction.InitID() self.TblReport.InitID() self.TblInf.InitID() self.TblDec.InitID() self.TblDsc.InitID() self.TblFdf.InitID() self.TblQuery.Drop() self.TblQuery.Create() self.TblQuery.InitID() self.TblQuery2.Drop() self.TblQuery2.Create() self.TblQuery2.InitID() # Initialize table DataModel if NewDatabase: self.TblDataModel.InitTable() EdkLogger.verbose("Initialize EOT database ... DONE!")
def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None): if self.NameGuid is not None and self.NameGuid.startswith('PCD('): PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid) if len(PcdValue) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \ % (self.NameGuid)) if PcdValue.startswith('{'): PcdValue = GuidStructureByteArrayToGuidString(PcdValue) RegistryGuidStr = PcdValue if len(RegistryGuidStr) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \ % (self.NameGuid)) self.NameGuid = RegistryGuidStr Str = self.NameGuid if FvName: Str += FvName OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, Str) if not os.path.exists(OutputDir): os.makedirs(OutputDir) Dict.update(self.DefineVarDict) SectionAlignments = None if self.FvName is not None : Buffer = BytesIO('') if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName)) Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper()) FileName = Fv.AddToBuffer(Buffer) SectionFiles = [FileName] elif self.FdName is not None: if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict: EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName)) Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper()) FileName = Fd.GenFd() SectionFiles = [FileName] elif self.FileName is not None: if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW': if isinstance(self.FileName, list) and isinstance(self.SubAlignment, list) and len(self.FileName) == len(self.SubAlignment): FileContent = '' MaxAlignIndex = 0 MaxAlignValue = 1 for Index, File in enumerate(self.FileName): try: f = open(File, 'rb') except: GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File)) Content = f.read() f.close() AlignValue = 1 if self.SubAlignment[Index] is not None: AlignValue = GenFdsGlobalVariable.GetAlignment(self.SubAlignment[Index]) if AlignValue > MaxAlignValue: MaxAlignIndex = Index MaxAlignValue = AlignValue FileContent += Content if len(FileContent) % AlignValue != 0: Size = AlignValue - len(FileContent) % AlignValue for i in range(0, Size): FileContent += pack('B', 0xFF) if FileContent: OutputRAWFile = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid, self.NameGuid + '.raw') SaveFileOnChange(OutputRAWFile, FileContent, True) self.FileName = OutputRAWFile self.SubAlignment = self.SubAlignment[MaxAlignIndex] if self.Alignment and self.SubAlignment: if GenFdsGlobalVariable.GetAlignment (self.Alignment) < GenFdsGlobalVariable.GetAlignment (self.SubAlignment): self.Alignment = self.SubAlignment elif self.SubAlignment: self.Alignment = self.SubAlignment self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) #Replace $(SAPCE) with real space self.FileName = self.FileName.replace('$(SPACE)', ' ') SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)] else: SectionFiles = [] Index = 0 SectionAlignments = [] for section in self.SectionList : Index = Index + 1 SecIndex = '%d' %Index # process the inside FvImage from FvSection or GuidSection if FvChildAddr != []: if isinstance(section, FvImageSection): section.FvAddr = FvChildAddr.pop(0) elif isinstance(section, GuidSection): section.FvAddr = FvChildAddr if FvParentAddr is not None and isinstance(section, GuidSection): section.FvParentAddr = FvParentAddr if self.KeepReloc == False: section.KeepReloc = False sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict) if sectList != []: for sect in sectList: SectionFiles.append(sect) SectionAlignments.append(align) # # Prepare the parameter # FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs') GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles, Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType), self.NameGuid, Fixed=self.Fixed, CheckSum=self.CheckSum, Align=self.Alignment, SectionAlign=SectionAlignments ) return FfsFileOutput
def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None): if self.NameGuid != None and self.NameGuid.startswith('PCD('): PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid) if len(PcdValue) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \ % (self.NameGuid)) if PcdValue.startswith('{'): PcdValue = GuidStructureByteArrayToGuidString(PcdValue) RegistryGuidStr = PcdValue if len(RegistryGuidStr) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \ % (self.NameGuid)) self.NameGuid = RegistryGuidStr OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid) if not os.path.exists(OutputDir): os.makedirs(OutputDir) Dict.update(self.DefineVarDict) SectionAlignments = None if self.FvName != None : Buffer = StringIO.StringIO('') if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName)) Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper()) FileName = Fv.AddToBuffer(Buffer) SectionFiles = [FileName] elif self.FdName != None: if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName)) Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper()) FileName = Fd.GenFd() SectionFiles = [FileName] elif self.FileName != None: self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) #Replace $(SAPCE) with real space self.FileName = self.FileName.replace('$(SPACE)', ' ') SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)] else: SectionFiles = [] Index = 0 SectionAlignments = [] for section in self.SectionList : Index = Index + 1 SecIndex = '%d' %Index # process the inside FvImage from FvSection or GuidSection if FvChildAddr != []: if isinstance(section, FvImageSection): section.FvAddr = FvChildAddr.pop(0) elif isinstance(section, GuidSection): section.FvAddr = FvChildAddr if FvParentAddr != None and isinstance(section, GuidSection): section.FvParentAddr = FvParentAddr if self.KeepReloc == False: section.KeepReloc = False sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict) if sectList != []: for sect in sectList: SectionFiles.append(sect) SectionAlignments.append(align) # # Prepare the parameter # FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs') GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles, Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType), self.NameGuid, Fixed=self.Fixed, CheckSum=self.CheckSum, Align=self.Alignment, SectionAlign=SectionAlignments ) return FfsFileOutput
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]], DataType.TAB_FV_DIRECTORY) 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()
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()
def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr): if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'): if Rule.KeepReloc != None: self.KeepRelocFromRule = Rule.KeepReloc SectFiles = [] SectAlignments = [] Index = 1 HasGneratedFlag = False if self.PcdIsDriver == 'PEI_PCD_DRIVER': if self.IsBinaryModule: PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "PEIPcdDataBase.raw") else: PcdExDbFileName = os.path.join(self.EfiOutputPath, "PEIPcdDataBase.raw") PcdExDbSecName = os.path.join(self.OutputPath, "PEIPcdDataBaseSec.raw") GenFdsGlobalVariable.GenerateSection(PcdExDbSecName, [PcdExDbFileName], "EFI_SECTION_RAW", ) SectFiles.append(PcdExDbSecName) SectAlignments.append(None) elif self.PcdIsDriver == 'DXE_PCD_DRIVER': if self.IsBinaryModule: PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "DXEPcdDataBase.raw") else: PcdExDbFileName = os.path.join(self.EfiOutputPath, "DXEPcdDataBase.raw") PcdExDbSecName = os.path.join(self.OutputPath, "DXEPcdDataBaseSec.raw") GenFdsGlobalVariable.GenerateSection(PcdExDbSecName, [PcdExDbFileName], "EFI_SECTION_RAW", ) SectFiles.append(PcdExDbSecName) SectAlignments.append(None) for Sect in Rule.SectionList: SecIndex = '%d' %Index SectList = [] # # Convert Fv Section Type for PI1.1 SMM driver. # if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 0x0001000A: if Sect.SectionType == 'DXE_DEPEX': Sect.SectionType = 'SMM_DEPEX' # # Framework SMM Driver has no SMM_DEPEX section type # if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 0x0001000A: if Sect.SectionType == 'SMM_DEPEX': EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName) # # process the inside FvImage from FvSection or GuidSection # if FvChildAddr != []: if isinstance(Sect, FvImageSection): Sect.FvAddr = FvChildAddr.pop(0) elif isinstance(Sect, GuidSection): Sect.FvAddr = FvChildAddr if FvParentAddr != None and isinstance(Sect, GuidSection): Sect.FvParentAddr = FvParentAddr if Rule.KeyStringList != []: SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self) else : SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self) if not HasGneratedFlag: UniVfrOffsetFileSection = "" ModuleFileName = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName) InfData = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClass(ModuleFileName), self.CurrentArch] # # Search the source list in InfData to find if there are .vfr file exist. # VfrUniBaseName = {} VfrUniOffsetList = [] for SourceFile in InfData.Sources: if SourceFile.Type.upper() == ".VFR" : # # search the .map file to find the offset of vfr binary in the PE32+/TE file. # VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin") if SourceFile.Type.upper() == ".UNI" : # # search the .map file to find the offset of Uni strings binary in the PE32+/TE file. # VfrUniBaseName["UniOffsetName"] = (self.BaseName + "Strings") if len(VfrUniBaseName) > 0: VfrUniOffsetList = self.__GetBuildOutputMapFileVfrUniInfo(VfrUniBaseName) # # Generate the Raw data of raw section # os.path.join( self.OutputPath, self.BaseName + '.offset') UniVfrOffsetFileName = os.path.join( self.OutputPath, self.BaseName + '.offset') UniVfrOffsetFileSection = os.path.join( self.OutputPath, self.BaseName + 'Offset' + '.raw') self.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName) UniVfrOffsetFileNameList = [] UniVfrOffsetFileNameList.append(UniVfrOffsetFileName) """Call GenSection""" GenFdsGlobalVariable.GenerateSection(UniVfrOffsetFileSection, UniVfrOffsetFileNameList, "EFI_SECTION_RAW" ) os.remove(UniVfrOffsetFileName) SectList.append(UniVfrOffsetFileSection) HasGneratedFlag = True for SecName in SectList : SectFiles.append(SecName) SectAlignments.append(Align) Index = Index + 1 return SectFiles, SectAlignments
def GenFfs(self, Dict={}, FvChildAddr=[], FvParentAddr=None): if self.NameGuid != None and self.NameGuid.startswith('PCD('): PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid) if len(PcdValue) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \ % (self.NameGuid)) if PcdValue.startswith('{'): PcdValue = GuidStructureByteArrayToGuidString(PcdValue) RegistryGuidStr = PcdValue if len(RegistryGuidStr) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \ % (self.NameGuid)) self.NameGuid = RegistryGuidStr OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid) if not os.path.exists(OutputDir): os.makedirs(OutputDir) Dict.update(self.DefineVarDict) SectionAlignments = None if self.FvName != None: Buffer = StringIO.StringIO('') if self.FvName.upper( ) not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName)) Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get( self.FvName.upper()) FileName = Fv.AddToBuffer(Buffer) SectionFiles = [FileName] elif self.FdName != None: if self.FdName.upper( ) not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): EdkLogger.error( "GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName)) Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get( self.FdName.upper()) FileName = Fd.GenFd() SectionFiles = [FileName] elif self.FileName != None: self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro( self.FileName) #Replace $(SAPCE) with real space self.FileName = self.FileName.replace('$(SPACE)', ' ') SectionFiles = [ GenFdsGlobalVariable.MacroExtend(self.FileName, Dict) ] else: SectionFiles = [] Index = 0 SectionAlignments = [] for section in self.SectionList: Index = Index + 1 SecIndex = '%d' % Index # process the inside FvImage from FvSection or GuidSection if FvChildAddr != []: if isinstance(section, FvImageSection): section.FvAddr = FvChildAddr.pop(0) elif isinstance(section, GuidSection): section.FvAddr = FvChildAddr if FvParentAddr != None and isinstance(section, GuidSection): section.FvParentAddr = FvParentAddr if self.KeepReloc == False: section.KeepReloc = False sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict) if sectList != []: for sect in sectList: SectionFiles.append(sect) SectionAlignments.append(align) # # Prepare the parameter # FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs') GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles, Ffs.Ffs.FdfFvFileTypeToFileType.get( self.FvFileType), self.NameGuid, Fixed=self.Fixed, CheckSum=self.CheckSum, Align=self.Alignment, SectionAlign=SectionAlignments) return FfsFileOutput
def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj): GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref") GuidXRefFile = StringIO.StringIO('') GuidDict = {} ModuleList = [] FileGuidList = [] for Arch in ArchList: PlatformDataBase = BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] for ModuleFile in PlatformDataBase.Modules: Module = BuildDb.BuildObject[ModuleFile, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] if Module in ModuleList: continue else: ModuleList.append(Module) GuidXRefFile.write("%s %s\n" % (Module.Guid, Module.BaseName)) for key, item in Module.Protocols.items(): GuidDict[key] = item for key, item in Module.Guids.items(): GuidDict[key] = item for key, item in Module.Ppis.items(): GuidDict[key] = item for FvName in FdfParserObj.Profile.FvDict: for FfsObj in FdfParserObj.Profile.FvDict[FvName].FfsList: if not isinstance(FfsObj, FfsFileStatement.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.write("%s %s\n" % (FdfModule.Guid, FdfModule.BaseName)) for key, item in FdfModule.Protocols.items(): GuidDict[key] = item for key, item in FdfModule.Guids.items(): GuidDict[key] = item for key, item in FdfModule.Ppis.items(): GuidDict[key] = item else: FileStatementGuid = FfsObj.NameGuid if FileStatementGuid in FileGuidList: continue else: FileGuidList.append(FileStatementGuid) Name = [] FfsPath = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs') FfsPath = glob.glob(os.path.join(FfsPath, FileStatementGuid) + '*') if not FfsPath: continue if not os.path.exists(FfsPath[0]): continue MatchDict = {} ReFileEnds = re.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 type(Name) == type([]) else Name GuidXRefFile.write("%s %s\n" %(FileStatementGuid, Name)) # Append GUIDs, Protocols, and PPIs to the Xref file GuidXRefFile.write("\n") for key, item in GuidDict.items(): GuidXRefFile.write("%s %s\n" % (GuidStructureStringToGuidString(item).upper(), key)) if GuidXRefFile.getvalue(): SaveFileOnChange(GuidXRefFileName, GuidXRefFile.getvalue(), False) GenFdsGlobalVariable.InfLogger("\nGUID cross reference file can be found at %s" % GuidXRefFileName) elif os.path.exists(GuidXRefFileName): os.remove(GuidXRefFileName) GuidXRefFile.close()
def CreateDirectory(Directory): if not os.access(Directory, os.F_OK): os.makedirs(Directory)
def ParseOption(self): EdkLogger.quiet("Loading ECC configuration ... done") (Options, Target) = self.EccOptionParser() if Options.Workspace: os.environ["WORKSPACE"] = Options.Workspace # Check workspace envirnoment if "WORKSPACE" not in os.environ: EdkLogger.error("ECC", BuildToolError.ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found", ExtraData="WORKSPACE") else: EccGlobalData.gWorkspace = os.path.normpath(os.getenv("WORKSPACE")) if not os.path.exists(EccGlobalData.gWorkspace): EdkLogger.error("ECC", BuildToolError.FILE_NOT_FOUND, ExtraData="WORKSPACE = %s" % EccGlobalData.gWorkspace) os.environ["WORKSPACE"] = EccGlobalData.gWorkspace # Set log level self.SetLogLevel(Options) # Set other options if Options.ConfigFile != None: self.ConfigFile = Options.ConfigFile if Options.OutputFile != None: self.OutputFile = Options.OutputFile if Options.ReportFile != None: self.ReportFile = Options.ReportFile if Options.ExceptionFile != None: self.ExceptionFile = Options.ExceptionFile if Options.Target != None: if not os.path.isdir(Options.Target): EdkLogger.error("ECC", BuildToolError.OPTION_VALUE_INVALID, ExtraData="Target [%s] does NOT exist" % Options.Target) else: EccGlobalData.gTarget = self.GetRealPathCase( os.path.normpath(Options.Target)) else: EdkLogger.warn( "Ecc", EdkLogger.ECC_ERROR, "The target source tree was not specified, using current WORKSPACE instead!" ) EccGlobalData.gTarget = os.path.normpath(os.getenv("WORKSPACE")) if Options.keepdatabase != None: self.IsInit = False if Options.metadata != None and Options.sourcecode != None: EdkLogger.error( "ECC", BuildToolError.OPTION_CONFLICT, ExtraData="-m and -s can't be specified at one time") if Options.metadata != None: self.ScanSourceCode = False if Options.sourcecode != None: self.ScanMetaData = False if Options.folders != None: self.OnlyScan = True
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile=False): # # Generate all section # self.KeyStringList = KeyStringList self.CurrentArchList = GenFdsGlobalVariable.ArchList if FfsInf is not None: self.Alignment = FfsInf.__ExtendMacro__(self.Alignment) self.NameGuid = FfsInf.__ExtendMacro__(self.NameGuid) self.SectionType = FfsInf.__ExtendMacro__(self.SectionType) self.CurrentArchList = [FfsInf.CurrentArch] SectFile = tuple() SectAlign = [] Index = 0 MaxAlign = None if self.FvAddr != []: FvAddrIsSet = True else: FvAddrIsSet = False if self.ProcessRequired in ("TRUE", "1"): if self.FvAddr != []: #no use FvAddr when the image is processed. self.FvAddr = [] if self.FvParentAddr is not None: #no use Parent Addr when the image is processed. self.FvParentAddr = None for Sect in self.SectionList: Index = Index + 1 SecIndex = '%s.%d' % (SecNum, Index) # set base address for inside FvImage if isinstance(Sect, FvImageSection): if self.FvAddr != []: Sect.FvAddr = self.FvAddr.pop(0) self.IncludeFvSection = True elif isinstance(Sect, GuidSection): Sect.FvAddr = self.FvAddr Sect.FvParentAddr = self.FvParentAddr ReturnSectList, align = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList, FfsInf, Dict, IsMakefile=IsMakefile) if isinstance(Sect, GuidSection): if Sect.IncludeFvSection: self.IncludeFvSection = Sect.IncludeFvSection if align is not None: if MaxAlign is None: MaxAlign = align if GenFdsGlobalVariable.GetAlignment( align) > GenFdsGlobalVariable.GetAlignment(MaxAlign): MaxAlign = align if ReturnSectList != []: if align is None: align = "1" for file in ReturnSectList: SectFile += (file, ) SectAlign.append(align) if MaxAlign is not None: if self.Alignment is None: self.Alignment = MaxAlign else: if GenFdsGlobalVariable.GetAlignment( MaxAlign) > GenFdsGlobalVariable.GetAlignment( self.Alignment): self.Alignment = MaxAlign OutputFile = OutputPath + \ os.sep + \ ModuleName + \ SUP_MODULE_SEC + \ SecNum + \ Ffs.SectionSuffix['GUIDED'] OutputFile = os.path.normpath(OutputFile) ExternalTool = None ExternalOption = None if self.NameGuid is not None: ExternalTool, ExternalOption = FindExtendTool( self.KeyStringList, self.CurrentArchList, self.NameGuid) # # If not have GUID , call default # GENCRC32 section # if self.NameGuid is None: GenFdsGlobalVariable.VerboseLogger( "Use GenSection function Generate CRC32 Section") GenFdsGlobalVariable.GenerateSection( OutputFile, SectFile, Section.Section.SectionType[self.SectionType], InputAlign=SectAlign, IsMakefile=IsMakefile) OutputFileList = [] OutputFileList.append(OutputFile) return OutputFileList, self.Alignment #or GUID not in External Tool List elif ExternalTool is None: EdkLogger.error("GenFds", GENFDS_ERROR, "No tool found with GUID %s" % self.NameGuid) else: DummyFile = OutputFile + ".dummy" # # Call GenSection with DUMMY section type. # GenFdsGlobalVariable.GenerateSection(DummyFile, SectFile, InputAlign=SectAlign, IsMakefile=IsMakefile) # # Use external tool process the Output # TempFile = OutputPath + \ os.sep + \ ModuleName + \ SUP_MODULE_SEC + \ SecNum + \ '.tmp' TempFile = os.path.normpath(TempFile) # # Remove temp file if its time stamp is older than dummy file # Just in case the external tool fails at this time but succeeded before # Error should be reported if the external tool does not generate a new output based on new input # if os.path.exists(TempFile) and os.path.exists( DummyFile ) and os.path.getmtime(TempFile) < os.path.getmtime(DummyFile): os.remove(TempFile) FirstCall = False CmdOption = '-e' if ExternalOption is not None: CmdOption = CmdOption + ' ' + ExternalOption if not GenFdsGlobalVariable.EnableGenfdsMultiThread: if self.ProcessRequired not in ( "TRUE", "1" ) and self.IncludeFvSection and not FvAddrIsSet and self.FvParentAddr is not None: #FirstCall is only set for the encapsulated flash FV image without process required attribute. FirstCall = True # # Call external tool # ReturnValue = [1] if FirstCall: #first try to call the guided tool with -z option and CmdOption for the no process required guided tool. GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, '-z' + ' ' + CmdOption, ReturnValue) # # when no call or first call failed, ReturnValue are not 1. # Call the guided tool with CmdOption # if ReturnValue[0] != 0: FirstCall = False ReturnValue[0] = 0 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption) # # There is external tool which does not follow standard rule which return nonzero if tool fails # The output file has to be checked # if not os.path.exists(TempFile): EdkLogger.error( "GenFds", COMMAND_FAILURE, 'Fail to call %s, no output file was generated' % ExternalTool) FileHandleIn = open(DummyFile, 'rb') FileHandleIn.seek(0, 2) InputFileSize = FileHandleIn.tell() FileHandleOut = open(TempFile, 'rb') FileHandleOut.seek(0, 2) TempFileSize = FileHandleOut.tell() Attribute = [] HeaderLength = None if self.ExtraHeaderSize != -1: HeaderLength = str(self.ExtraHeaderSize) if self.ProcessRequired == "NONE" and HeaderLength is None: if TempFileSize > InputFileSize: FileHandleIn.seek(0) BufferIn = FileHandleIn.read() FileHandleOut.seek(0) BufferOut = FileHandleOut.read() if BufferIn == BufferOut[TempFileSize - InputFileSize:]: HeaderLength = str(TempFileSize - InputFileSize) #auto sec guided attribute with process required if HeaderLength is None: Attribute.append('PROCESSING_REQUIRED') FileHandleIn.close() FileHandleOut.close() if FirstCall and 'PROCESSING_REQUIRED' in Attribute: # Guided data by -z option on first call is the process required data. Call the guided tool with the real option. GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption) # # Call Gensection Add Section Header # if self.ProcessRequired in ("TRUE", "1"): if 'PROCESSING_REQUIRED' not in Attribute: Attribute.append('PROCESSING_REQUIRED') if self.AuthStatusValid in ("TRUE", "1"): Attribute.append('AUTH_STATUS_VALID') GenFdsGlobalVariable.GenerateSection( OutputFile, [TempFile], Section.Section.SectionType['GUIDED'], Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength) else: #add input file for GenSec get PROCESSING_REQUIRED GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption, IsMakefile=IsMakefile) Attribute = [] HeaderLength = None if self.ExtraHeaderSize != -1: HeaderLength = str(self.ExtraHeaderSize) if self.AuthStatusValid in ("TRUE", "1"): Attribute.append('AUTH_STATUS_VALID') if self.ProcessRequired == "NONE" and HeaderLength is None: GenFdsGlobalVariable.GenerateSection( OutputFile, [TempFile], Section.Section.SectionType['GUIDED'], Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength, DummyFile=DummyFile, IsMakefile=IsMakefile) else: if self.ProcessRequired in ("TRUE", "1"): if 'PROCESSING_REQUIRED' not in Attribute: Attribute.append('PROCESSING_REQUIRED') GenFdsGlobalVariable.GenerateSection( OutputFile, [TempFile], Section.Section.SectionType['GUIDED'], Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength, IsMakefile=IsMakefile) OutputFileList = [] OutputFileList.append(OutputFile) if 'PROCESSING_REQUIRED' in Attribute: # reset guided section alignment to none for the processed required guided data self.Alignment = None self.IncludeFvSection = False self.ProcessRequired = "TRUE" if IsMakefile and self.Alignment is not None and self.Alignment.strip( ) == '0': self.Alignment = '1' return OutputFileList, self.Alignment
def AddToBuffer(self, Buffer): GenFdsGlobalVariable.InfLogger("\nGenerating %s Option ROM ..." % self.DriverName) EfiFileList = [] BinFileList = [] # Process Modules in FfsList for FfsFile in self.FfsList: if isinstance(FfsFile, OptRomInfStatement.OptRomInfStatement): FilePathNameList = FfsFile.GenFfs() if len(FilePathNameList) == 0: EdkLogger.error( "GenFds", GENFDS_ERROR, "Module %s not produce .efi files, so NO file could be put into option ROM." % (FfsFile.InfFileName)) if FfsFile.OverrideAttribs == None: EfiFileList.extend(FilePathNameList) else: FileName = os.path.basename(FilePathNameList[0]) TmpOutputDir = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName) if not os.path.exists(TmpOutputDir): os.makedirs(TmpOutputDir) TmpOutputFile = os.path.join(TmpOutputDir, FileName + '.tmp') GenFdsGlobalVariable.GenerateOptionRom( TmpOutputFile, FilePathNameList, [], FfsFile.OverrideAttribs.NeedCompress, FfsFile.OverrideAttribs.PciClassCode, FfsFile.OverrideAttribs.PciRevision, FfsFile.OverrideAttribs.PciDeviceId, FfsFile.OverrideAttribs.PciVendorId) BinFileList.append(TmpOutputFile) else: FilePathName = FfsFile.GenFfs() if FfsFile.OverrideAttribs != None: FileName = os.path.basename(FilePathName) TmpOutputDir = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName) if not os.path.exists(TmpOutputDir): os.makedirs(TmpOutputDir) TmpOutputFile = os.path.join(TmpOutputDir, FileName + '.tmp') GenFdsGlobalVariable.GenerateOptionRom( TmpOutputFile, [FilePathName], [], FfsFile.OverrideAttribs.NeedCompress, FfsFile.OverrideAttribs.PciClassCode, FfsFile.OverrideAttribs.PciRevision, FfsFile.OverrideAttribs.PciDeviceId, FfsFile.OverrideAttribs.PciVendorId) BinFileList.append(TmpOutputFile) else: if FfsFile.FileType == 'EFI': EfiFileList.append(FilePathName) else: BinFileList.append(FilePathName) # # Call EfiRom tool # OutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName) OutputFile = OutputFile + '.rom' GenFdsGlobalVariable.GenerateOptionRom(OutputFile, EfiFileList, BinFileList) GenFdsGlobalVariable.InfLogger( "\nGenerate %s Option ROM Successfully" % self.DriverName) GenFdsGlobalVariable.SharpCounter = 0 return OutputFile
# # Load tools_def.txt in input Conf dir # # @param ConfDir: Conf dir # # @retval ToolDef An instance of ToolDefClassObject() with loaded tools_def.txt # def ToolDefDict(ConfDir): Target = TargetTxt ToolDef = ToolDefClassObject() if TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary: ToolsDefFile = Target.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF] if ToolsDefFile: ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile)) else: ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile))) else: ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile))) return ToolDef ToolDef = ToolDefDict((os.path.join(os.getenv("WORKSPACE"),"Conf"))) ## # # This acts like the main() function for the script, unless it is 'import'ed into another # script. # if __name__ == '__main__': ToolDef = ToolDefDict(os.getenv("WORKSPACE")) pass
def GenFfs (self, FvName, Dict = {}, IsMakefile = False): DXE_GUID = "FC510EE7-FFDC-11D4-BD41-0080C73C8881" PEI_GUID = "1B45CC0A-156A-428A-AF62-49864DA0E6E6" Buffer = BytesIO() AprioriFileGuid = DXE_GUID if self.AprioriType == "PEI": AprioriFileGuid = PEI_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, FfsFileStatement.FileStatement): Guid = FfsObj.NameGuid else: InfFileName = NormPath(FfsObj.InfFileName) Arch = FfsObj.GetCurrentArch() if Arch is not None: Dict['$(ARCH)'] = Arch InfFileName = GenFdsGlobalVariable.MacroExtend(InfFileName, Dict, Arch) if Arch is not None: 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 self.BinFileList = Inf.Module.Binaries if self.BinFileList == []: EdkLogger.error("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
def InsertFile(self, FileFullPath, Model): (Filepath, Name) = os.path.split(FileFullPath) (Root, Ext) = os.path.splitext(FileFullPath) TimeStamp = os.stat(FileFullPath)[8] File = FileClass(-1, Name, Ext, Filepath, FileFullPath, Model, '', [], [], []) return self.Insert(File.Name, File.ExtName, File.Path, File.FullPath, File.Model, TimeStamp)
# # @param ConfDir: Conf dir # # @retval ToolDef An instance of ToolDefClassObject() with loaded tools_def.txt # def ToolDefDict(ConfDir): Target = TargetTxtDict(ConfDir) ToolDef = ToolDefClassObject() if DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary: ToolsDefFile = Target.TargetTxtDictionary[ DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF] if ToolsDefFile: ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile)) else: ToolDef.LoadToolDefFile( os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile))) else: ToolDef.LoadToolDefFile( os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile))) return ToolDef ## # # This acts like the main() function for the script, unless it is 'import'ed into another # script. # if __name__ == '__main__': ToolDef = ToolDefDict(os.getenv("WORKSPACE")) pass
def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=None): global Workspace Workspace = "" ArchList = None ReturnCode = 0 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 'EDK_SOURCE' in os.environ: GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE']) if FdsCommandDict.get("debug"): GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace) if FdsCommandDict.get("GenfdsMultiThread"): GenFdsGlobalVariable.EnableGenfdsMultiThread = True 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") GlobalData.BuildOptionPcd = FdsCommandDict.get("OptionPcd") if FdsCommandDict.get("OptionPcd") else {} 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: TargetTxt = TargetTxtClassObject() TargetTxt.LoadTargetTxtFile(BuildConfigurationFile) # if no build target given in command line, get it from target.txt 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() == "EFI_SOURCE": GlobalData.gEfiSource = List[1].strip() GlobalData.gGlobalDefines["EFI_SOURCE"] = GlobalData.gEfiSource continue elif List[0].strip() == "EDK_SOURCE": GlobalData.gEdkSource = List[1].strip() GlobalData.gGlobalDefines["EDK_SOURCE"] = GlobalData.gEdkSource continue elif 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 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 [email protected] for help, attaching following call stack trace!\n", RaiseError=False ) EdkLogger.quiet(traceback.format_exc()) ReturnCode = CODE_ERROR finally: ClearDuplicatedInf() return ReturnCode
def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile): VfrNameList = [] if os.path.isdir(DebugDir): for CurrentDir, Dirs, Files in os.walk(DebugDir): for FileName in Files: Name, Ext = os.path.splitext(FileName) if Ext == '.c' and Name != 'AutoGen': VfrNameList.append(Name + 'Bin') VfrNameList.append(ModuleName + 'Strings') EfiFileName = os.path.join(DebugDir, ModuleName + '.efi') MapFileName = os.path.join(DebugDir, ModuleName + '.map') VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, VfrNameList) if not VfrUniOffsetList: return try: fInputfile = open(OutputFile, "wb+", 0) except: EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" % OutputFile, None) # Use a instance of BytesIO to cache data fStringIO = BytesIO() for Item in VfrUniOffsetList: if (Item[0].find("Strings") != -1): # # UNI offset in image. # GUID + Offset # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } } # UniGuid = [ 0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 ] fStringIO.write(bytes(UniGuid)) UniValue = pack('Q', int(Item[1], 16)) fStringIO.write(UniValue) else: # # VFR binary offset in image. # GUID + Offset # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } }; # VfrGuid = [ 0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 ] fStringIO.write(bytes(VfrGuid)) VfrValue = pack('Q', int(Item[1], 16)) fStringIO.write(VfrValue) # # write data into file. # try: fInputfile.write(fStringIO.getvalue()) except: EdkLogger.error( "Trim", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." % OutputFile, None) fStringIO.close() fInputfile.close()
"--multithreadnum", action="callback", type="int", dest="NUM", callback=RangeCheckCallback, help= "Specify the multi-thread number which replace target.txt's MAX_CONCURRENT_THREAD_NUMBER. If the value is less than 2, MULTIPLE_THREAD will be disabled. If the value is larger than 1, MULTIPLE_THREAD will be enabled." ) (opt, args) = parser.parse_args() return (opt, args) if __name__ == '__main__': EdkLogger.Initialize() EdkLogger.SetLevel(EdkLogger.QUIET) if os.getenv('WORKSPACE') == None: print "ERROR: WORKSPACE should be specified or edksetup script should be executed before run TargetTool" sys.exit(1) (opt, args) = MyOptionParser() if len(args) != 1 or (args[0].lower() != 'print' and args[0].lower() != 'clean' and args[0].lower() != 'set'): print "The number of args isn't 1 or the value of args is invalid." sys.exit(1) if opt.NUM != None and opt.NUM < 1: print "The MAX_CONCURRENT_THREAD_NUMBER must be larger than 0." sys.exit(1) if opt.TARGET != None and len(opt.TARGET) > 1: for elem in opt.TARGET: if elem == '0':
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}): # # Generate all section # self.KeyStringList = KeyStringList self.CurrentArchList = GenFdsGlobalVariable.ArchList if FfsInf != None: self.Alignment = FfsInf.__ExtendMacro__(self.Alignment) self.NameGuid = FfsInf.__ExtendMacro__(self.NameGuid) self.SectionType = FfsInf.__ExtendMacro__(self.SectionType) self.CurrentArchList = [FfsInf.CurrentArch] SectFile = tuple() SectAlign = [] Index = 0 MaxAlign = None if self.FvAddr != []: FvAddrIsSet = True else: FvAddrIsSet = False if self.ProcessRequired in ("TRUE", "1"): if self.FvAddr != []: #no use FvAddr when the image is processed. self.FvAddr = [] if self.FvParentAddr != None: #no use Parent Addr when the image is processed. self.FvParentAddr = None for Sect in self.SectionList: Index = Index + 1 SecIndex = '%s.%d' % (SecNum, Index) # set base address for inside FvImage if isinstance(Sect, FvImageSection): if self.FvAddr != []: Sect.FvAddr = self.FvAddr.pop(0) self.IncludeFvSection = True elif isinstance(Sect, GuidSection): Sect.FvAddr = self.FvAddr Sect.FvParentAddr = self.FvParentAddr ReturnSectList, align = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList, FfsInf, Dict) if isinstance(Sect, GuidSection): if Sect.IncludeFvSection: self.IncludeFvSection = Sect.IncludeFvSection if align != None: if MaxAlign == None: MaxAlign = align if GenFdsGlobalVariable.GetAlignment (align) > GenFdsGlobalVariable.GetAlignment (MaxAlign): MaxAlign = align if ReturnSectList != []: if align == None: align = "1" for file in ReturnSectList: SectFile += (file,) SectAlign.append(align) if MaxAlign != None: if self.Alignment == None: self.Alignment = MaxAlign else: if GenFdsGlobalVariable.GetAlignment (MaxAlign) > GenFdsGlobalVariable.GetAlignment (self.Alignment): self.Alignment = MaxAlign OutputFile = OutputPath + \ os.sep + \ ModuleName + \ 'SEC' + \ SecNum + \ Ffs.SectionSuffix['GUIDED'] OutputFile = os.path.normpath(OutputFile) ExternalTool = None ExternalOption = None if self.NameGuid != None: ExternalTool, ExternalOption = FindExtendTool(self.KeyStringList, self.CurrentArchList, self.NameGuid) # # If not have GUID , call default # GENCRC32 section # if self.NameGuid == None : GenFdsGlobalVariable.VerboseLogger("Use GenSection function Generate CRC32 Section") GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType], InputAlign=SectAlign) OutputFileList = [] OutputFileList.append(OutputFile) return OutputFileList, self.Alignment #or GUID not in External Tool List elif ExternalTool == None: EdkLogger.error("GenFds", GENFDS_ERROR, "No tool found with GUID %s" % self.NameGuid) else: DummyFile = OutputFile + ".dummy" # # Call GenSection with DUMMY section type. # GenFdsGlobalVariable.GenerateSection(DummyFile, SectFile, InputAlign=SectAlign) # # Use external tool process the Output # TempFile = OutputPath + \ os.sep + \ ModuleName + \ 'SEC' + \ SecNum + \ '.tmp' TempFile = os.path.normpath(TempFile) # # Remove temp file if its time stamp is older than dummy file # Just in case the external tool fails at this time but succeeded before # Error should be reported if the external tool does not generate a new output based on new input # if os.path.exists(TempFile) and os.path.exists(DummyFile) and os.path.getmtime(TempFile) < os.path.getmtime(DummyFile): os.remove(TempFile) FirstCall = False CmdOption = '-e' if ExternalOption != None: CmdOption = CmdOption + ' ' + ExternalOption if self.ProcessRequired not in ("TRUE", "1") and self.IncludeFvSection and not FvAddrIsSet and self.FvParentAddr != None: #FirstCall is only set for the encapsulated flash FV image without process required attribute. FirstCall = True # # Call external tool # ReturnValue = [1] if FirstCall: #first try to call the guided tool with -z option and CmdOption for the no process required guided tool. GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, '-z' + ' ' + CmdOption, ReturnValue) # # when no call or first call failed, ReturnValue are not 1. # Call the guided tool with CmdOption # if ReturnValue[0] != 0: FirstCall = False ReturnValue[0] = 0 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption) # # There is external tool which does not follow standard rule which return nonzero if tool fails # The output file has to be checked # if not os.path.exists(TempFile): EdkLogger.error("GenFds", COMMAND_FAILURE, 'Fail to call %s, no output file was generated' % ExternalTool) FileHandleIn = open(DummyFile, 'rb') FileHandleIn.seek(0, 2) InputFileSize = FileHandleIn.tell() FileHandleOut = open(TempFile, 'rb') FileHandleOut.seek(0, 2) TempFileSize = FileHandleOut.tell() Attribute = [] HeaderLength = None if self.ExtraHeaderSize != -1: HeaderLength = str(self.ExtraHeaderSize) if self.ProcessRequired == "NONE" and HeaderLength == None: if TempFileSize > InputFileSize: FileHandleIn.seek(0) BufferIn = FileHandleIn.read() FileHandleOut.seek(0) BufferOut = FileHandleOut.read() if BufferIn == BufferOut[TempFileSize - InputFileSize:]: HeaderLength = str(TempFileSize - InputFileSize) #auto sec guided attribute with process required if HeaderLength == None: Attribute.append('PROCESSING_REQUIRED') FileHandleIn.close() FileHandleOut.close() if FirstCall and 'PROCESSING_REQUIRED' in Attribute: # Guided data by -z option on first call is the process required data. Call the guided tool with the real option. GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption) # # Call Gensection Add Section Header # if self.ProcessRequired in ("TRUE", "1"): if 'PROCESSING_REQUIRED' not in Attribute: Attribute.append('PROCESSING_REQUIRED') if self.AuthStatusValid in ("TRUE", "1"): Attribute.append('AUTH_STATUS_VALID') GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'], Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength) OutputFileList = [] OutputFileList.append(OutputFile) if 'PROCESSING_REQUIRED' in Attribute: # reset guided section alignment to none for the processed required guided data self.Alignment = None self.IncludeFvSection = False self.ProcessRequired = "TRUE" return OutputFileList, self.Alignment
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 AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, vtfDict=None, MacroDict={}): Size = self.Size GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset) GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size) GenFdsGlobalVariable.SharpCounter = 0 if self.RegionType == 'FV': # # Get Fv from FvDict # self.FvAddress = int(BaseAddress, 16) + self.Offset FvBaseAddress = '0x%X' % self.FvAddress FvOffset = 0 for RegionData in self.RegionDataList: FileName = None if RegionData.endswith(".fv"): RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) GenFdsGlobalVariable.InfLogger(' Region FV File Name = .fv : %s' % RegionData) if RegionData[1] != ':' : RegionData = mws.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'fv' in ImageBinDict.keys(): GenFdsGlobalVariable.InfLogger(' Region Name = FV') FileName = ImageBinDict[RegionData.upper() + 'fv'] else: # # Generate FvImage. # FvObj = None if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(RegionData.upper()) if FvObj != None : GenFdsGlobalVariable.InfLogger(' Region Name = FV') # # Call GenFv tool # self.BlockInfoOfRegion(BlockSizeList, FvObj) self.FvAddress = self.FvAddress + FvOffset FvAlignValue = self.GetFvAlignValue(FvObj.FvAlignment) if self.FvAddress % FvAlignValue != 0: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment)) FvBuffer = StringIO.StringIO('') FvBaseAddress = '0x%X' % self.FvAddress BlockSize = None BlockNum = None FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict) if FvBuffer.len > Size: FvBuffer.close() EdkLogger.error("GenFds", GENFDS_ERROR, "Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size)) # # Put the generated image into FD buffer. # Buffer.write(FvBuffer.getvalue()) FvBuffer.close() FvOffset = FvOffset + FvBuffer.len Size = Size - FvBuffer.len continue else: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData)) # # Add the exist Fv image into FD buffer # if FileName != None: FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of FV File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) BinFile = open(FileName, 'r+b') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == 'CAPSULE': # # Get Capsule from Capsule Dict # for RegionData in self.RegionDataList: if RegionData.endswith(".cap"): RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) GenFdsGlobalVariable.InfLogger(' Region CAPSULE Image Name = .cap : %s' % RegionData) if RegionData[1] != ':' : RegionData = mws.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'cap' in ImageBinDict.keys(): GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE') FileName = ImageBinDict[RegionData.upper() + 'cap'] else: # # Generate Capsule image and Put it into FD buffer # CapsuleObj = None if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys(): CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[RegionData.upper()] if CapsuleObj != None : CapsuleObj.CapsuleName = RegionData.upper() GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE') # # Call GenFv tool to generate Capsule Image # FileName = CapsuleObj.GenCapsule() CapsuleObj.CapsuleName = None else: EdkLogger.error("GenFds", GENFDS_ERROR, "Capsule (%s) is NOT described in FDF file!" % (RegionData)) # # Add the capsule image into FD buffer # FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \ % (FileLength, RegionData, Size)) BinFile = open(FileName, 'r+b') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType in ('FILE', 'INF'): for RegionData in self.RegionDataList: if self.RegionType == 'INF': RegionData.__InfParse__(None) if len(RegionData.BinFileList) != 1: EdkLogger.error('GenFds', GENFDS_ERROR, 'INF in FD region can only contain one binary: %s' % RegionData) File = RegionData.BinFileList[0] RegionData = RegionData.PatchEfiFile(File.Path, File.Type) else: RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) if RegionData[1] != ':' : RegionData = mws.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) # # Add the file image into FD buffer # FileLength = os.stat(RegionData)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) GenFdsGlobalVariable.InfLogger(' Region File Name = %s' % RegionData) BinFile = open(RegionData, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == 'DATA' : GenFdsGlobalVariable.InfLogger(' Region Name = DATA') DataSize = 0 for RegionData in self.RegionDataList: Data = RegionData.split(',') DataSize = DataSize + len(Data) if DataSize > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of DATA is larger than Region Size ") else: for item in Data : Buffer.write(pack('B', int(item, 16))) Size = Size - DataSize # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == None: GenFdsGlobalVariable.InfLogger(' Region Name = None') if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData))
def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, vtfDict = None, MacroDict = {}): Size = self.Size GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset) GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" %Size) GenFdsGlobalVariable.SharpCounter = 0 if self.RegionType == 'FV': # # Get Fv from FvDict # self.FvAddress = int(BaseAddress, 16) + self.Offset FvBaseAddress = '0x%X' %self.FvAddress FvOffset = 0 for RegionData in self.RegionDataList: FileName = None if RegionData.endswith(".fv"): RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) GenFdsGlobalVariable.InfLogger(' Region FV File Name = .fv : %s'%RegionData) if RegionData[1] != ':' : RegionData = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'fv' in ImageBinDict.keys(): GenFdsGlobalVariable.InfLogger(' Region Name = FV') FileName = ImageBinDict[RegionData.upper() + 'fv'] else: # # Generate FvImage. # FvObj = None if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(RegionData.upper()) if FvObj != None : GenFdsGlobalVariable.InfLogger(' Region Name = FV') # # Call GenFv tool # self.BlockInfoOfRegion(BlockSizeList, FvObj) self.FvAddress = self.FvAddress + FvOffset FvAlignValue = self.GetFvAlignValue(FvObj.FvAlignment) if self.FvAddress % FvAlignValue != 0: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment)) FvBuffer = StringIO.StringIO('') FvBaseAddress = '0x%X' %self.FvAddress BlockSize = None BlockNum = None FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict) if FvBuffer.len > Size: FvBuffer.close() EdkLogger.error("GenFds", GENFDS_ERROR, "Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size)) # # Put the generated image into FD buffer. # Buffer.write(FvBuffer.getvalue()) FvBuffer.close() FvOffset = FvOffset + FvBuffer.len Size = Size - FvBuffer.len continue else: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData)) # # Add the exist Fv image into FD buffer # if FileName != None: FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of FV File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) BinFile = open (FileName, 'r+b') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == 'CAPSULE': # # Get Capsule from Capsule Dict # for RegionData in self.RegionDataList: if RegionData.endswith(".cap"): RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) GenFdsGlobalVariable.InfLogger(' Region CAPSULE Image Name = .cap : %s'%RegionData) if RegionData[1] != ':' : RegionData = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'cap' in ImageBinDict.keys(): GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE') FileName = ImageBinDict[RegionData.upper() + 'cap'] else: # # Generate Capsule image and Put it into FD buffer # CapsuleObj = None if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys(): CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[RegionData.upper()] if CapsuleObj != None : CapsuleObj.CapsuleName = RegionData.upper() GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE') # # Call GenFv tool to generate Capsule Image # FileName = CapsuleObj.GenCapsule() CapsuleObj.CapsuleName = None else: EdkLogger.error("GenFds", GENFDS_ERROR, "Capsule (%s) is NOT described in FDF file!" % (RegionData)) # # Add the capsule image into FD buffer # FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \ % (FileLength, RegionData, Size)) BinFile = open (FileName, 'r+b') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == 'FILE': for RegionData in self.RegionDataList: RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict) if RegionData[1] != ':' : RegionData = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) # # Add the file image into FD buffer # FileLength = os.stat(RegionData)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) GenFdsGlobalVariable.InfLogger(' Region File Name = %s'%RegionData) BinFile = open (RegionData, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == 'DATA' : GenFdsGlobalVariable.InfLogger(' Region Name = DATA') DataSize = 0 for RegionData in self.RegionDataList: Data = RegionData.split(',') DataSize = DataSize + len(Data) if DataSize > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of DATA is larger than Region Size ") else: for item in Data : Buffer.write(pack('B', int(item, 16))) Size = Size - DataSize # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == None: GenFdsGlobalVariable.InfLogger(' Region Name = None') if (ErasePolarity == '1') : PadData = 0xFF else : PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData))
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.QuietLogger("\nGUID cross reference file can be found at %s" % GuidXRefFileName) # VBox: We want this info in -quiet builds too. elif os.path.exists(GuidXRefFileName): os.remove(GuidXRefFileName)
def __InitializeInf__(self, BaseAddress=None, BlockSize=None, BlockNum=None, ErasePloarity='1', VtfDict=None): # # Create FV inf file # self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.inf') self.FvInfFile = StringIO() # # Add [Options] # self.FvInfFile.writelines("[options]" + TAB_LINE_BREAK) if BaseAddress is not None: self.FvInfFile.writelines("EFI_BASE_ADDRESS = " + \ BaseAddress + \ TAB_LINE_BREAK) if BlockSize is not None: self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \ '0x%X' %BlockSize + \ TAB_LINE_BREAK) if BlockNum is not None: self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \ ' 0x%X' %BlockNum + \ TAB_LINE_BREAK) else: if self.BlockSizeList == []: if not self._GetBlockSize(): #set default block size is 1 self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x1" + TAB_LINE_BREAK) for BlockSize in self.BlockSizeList: if BlockSize[0] is not None: self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \ '0x%X' %BlockSize[0] + \ TAB_LINE_BREAK) if BlockSize[1] is not None: self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \ ' 0x%X' %BlockSize[1] + \ TAB_LINE_BREAK) if self.BsBaseAddress is not None: self.FvInfFile.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \ '0x%X' %self.BsBaseAddress) if self.RtBaseAddress is not None: self.FvInfFile.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = ' + \ '0x%X' %self.RtBaseAddress) # # Add attribute # self.FvInfFile.writelines("[attributes]" + TAB_LINE_BREAK) self.FvInfFile.writelines("EFI_ERASE_POLARITY = " + \ ' %s' %ErasePloarity + \ TAB_LINE_BREAK) if not (self.FvAttributeDict is None): for FvAttribute in self.FvAttributeDict.keys(): if FvAttribute == "FvUsedSizeEnable": if self.FvAttributeDict[FvAttribute].upper() in ('TRUE', '1'): self.UsedSizeEnable = True continue self.FvInfFile.writelines("EFI_" + \ FvAttribute + \ ' = ' + \ self.FvAttributeDict[FvAttribute] + \ TAB_LINE_BREAK ) if self.FvAlignment is not None: self.FvInfFile.writelines("EFI_FVB2_ALIGNMENT_" + \ self.FvAlignment.strip() + \ " = TRUE" + \ TAB_LINE_BREAK) # # Generate FV extension header file # if not self.FvNameGuid: if len(self.FvExtEntryType) > 0 or self.UsedSizeEnable: GenFdsGlobalVariable.ErrorLogger( "FV Extension Header Entries declared for %s with no FvNameGuid declaration." % (self.UiFvName)) else: TotalSize = 16 + 4 Buffer = bytearray() if self.UsedSizeEnable: TotalSize += (4 + 4) ## define EFI_FV_EXT_TYPE_USED_SIZE_TYPE 0x03 #typedef struct # { # EFI_FIRMWARE_VOLUME_EXT_ENTRY Hdr; # UINT32 UsedSize; # } EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE; Buffer += pack('HHL', 8, 3, 0) if self.FvNameString == 'TRUE': # # Create EXT entry for FV UI name # This GUID is used: A67DF1FA-8DE8-4E98-AF09-4BDF2EFFBC7C # FvUiLen = len(self.UiFvName) TotalSize += (FvUiLen + 16 + 4) Guid = FV_UI_EXT_ENTY_GUID.split('-') # # Layout: # EFI_FIRMWARE_VOLUME_EXT_ENTRY : size 4 # GUID : size 16 # FV UI name # Buffer += (pack('HH', (FvUiLen + 16 + 4), 0x0002) + PackGUID(Guid) + bytes(self.UiFvName, 'utf-8')) for Index in range(0, len(self.FvExtEntryType)): if self.FvExtEntryType[Index] == 'FILE': # check if the path is absolute or relative if os.path.isabs(self.FvExtEntryData[Index]): FileFullPath = os.path.normpath( self.FvExtEntryData[Index]) else: FileFullPath = os.path.normpath( os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.FvExtEntryData[Index])) # check if the file path exists or not if not os.path.isfile(FileFullPath): GenFdsGlobalVariable.ErrorLogger( "Error opening FV Extension Header Entry file %s." % (self.FvExtEntryData[Index])) FvExtFile = open(FileFullPath, 'rb') FvExtFile.seek(0, 2) Size = FvExtFile.tell() if Size >= 0x10000: GenFdsGlobalVariable.ErrorLogger( "The size of FV Extension Header Entry file %s exceeds 0x10000." % (self.FvExtEntryData[Index])) TotalSize += (Size + 4) FvExtFile.seek(0) Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16)) Buffer += FvExtFile.read() FvExtFile.close() if self.FvExtEntryType[Index] == 'DATA': ByteList = self.FvExtEntryData[Index].split(',') Size = len(ByteList) if Size >= 0x10000: GenFdsGlobalVariable.ErrorLogger( "The size of FV Extension Header Entry data %s exceeds 0x10000." % (self.FvExtEntryData[Index])) TotalSize += (Size + 4) Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16)) for Index1 in range(0, Size): Buffer += pack('B', int(ByteList[Index1], 16)) Guid = self.FvNameGuid.split('-') Buffer = PackGUID(Guid) + pack('=L', TotalSize) + Buffer # # Generate FV extension header file if the total size is not zero # if TotalSize > 0: FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.ext') FvExtHeaderFile = BytesIO() FvExtHeaderFile.write(Buffer) Changed = SaveFileOnChange(FvExtHeaderFileName, FvExtHeaderFile.getvalue(), True) FvExtHeaderFile.close() if Changed: if os.path.exists(self.InfFileName): os.remove(self.InfFileName) self.FvInfFile.writelines("EFI_FV_EXT_HEADER_FILE_NAME = " + \ FvExtHeaderFileName + \ TAB_LINE_BREAK) # # Add [Files] # self.FvInfFile.writelines("[files]" + TAB_LINE_BREAK) if VtfDict and self.UiFvName in VtfDict: self.FvInfFile.writelines("EFI_FILE_NAME = " + \ VtfDict[self.UiFvName] + \ TAB_LINE_BREAK)