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 deps_files(self): """ Get all .deps file under module build folder. """ deps_files = [] for root, _, files in os.walk(self.d_folder, topdown=False): for name in files: if not name.endswith(".deps"): continue abspath = os.path.join(root, name) deps_files.append(abspath) return deps_files
def BuildMetaDataFileDatabase(self, SpecificDirs=None): ScanFolders = [] if SpecificDirs is 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 = '|'.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)) # always 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) FileID = EccGlobalData.gDb.TblFile.InsertFile( Filename, MODEL_FILE_UNI) EccGlobalData.gDb.TblReport.UpdateBelongsToItemByFile( FileID, File) 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