Example #1
0
    def GetCurrentArch(self):

        TargetArchList = GenFdsGlobalVariable.ArchList

        PlatformArchList = self.__GetPlatformArchList__()

        CurArchList = TargetArchList
        if PlatformArchList != []:
            CurArchList = list(set(TargetArchList) & set(PlatformArchList))
        GenFdsGlobalVariable.VerboseLogger(
            "Valid target architecture(s) is : " + " ".join(CurArchList))

        ArchList = []
        if self.KeyStringList != []:
            for Key in self.KeyStringList:
                Key = GenFdsGlobalVariable.MacroExtend(Key)
                Target, Tag, Arch = Key.split('_')
                if Arch in CurArchList:
                    ArchList.append(Arch)
                if Target not in self.TargetOverrideList:
                    self.TargetOverrideList.append(Target)
        else:
            ArchList = CurArchList

        UseArchList = TargetArchList
        if self.UseArch != None:
            UseArchList = []
            UseArchList.append(self.UseArch)
            ArchList = list(set(UseArchList) & set(ArchList))

        self.InfFileName = NormPath(self.InfFileName)
        if len(PlatformArchList) == 0:
            self.InDsc = False
            PathClassObj = PathClass(self.InfFileName,
                                     GenFdsGlobalVariable.WorkSpaceDir)
            ErrorCode, ErrorInfo = PathClassObj.Validate(".inf")
            if ErrorCode != 0:
                EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)
        if len(ArchList) == 1:
            Arch = ArchList[0]
            return Arch
        elif len(ArchList) > 1:
            if len(PlatformArchList) == 0:
                EdkLogger.error(
                    "GenFds", GENFDS_ERROR,
                    "GenFds command line option has multiple ARCHs %s. Not able to determine which ARCH is valid for Module %s !"
                    % (str(ArchList), self.InfFileName))
            else:
                EdkLogger.error(
                    "GenFds", GENFDS_ERROR,
                    "Module built under multiple ARCHs %s. Not able to determine which output to put into flash for Module %s !"
                    % (str(ArchList), self.InfFileName))
        else:
            EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s appears under ARCH %s in platform %s, but current deduced ARCH is %s, so NO build output could be put into flash." \
                            % (self.InfFileName, str(PlatformArchList), GenFdsGlobalVariable.ActivePlatform, str(set (UseArchList) & set (TargetArchList))))
Example #2
0
 def TargetFileList(self):
     """ Get a map of module's target name to a tuple of module's targets path and whose input file path """
     targets = {}
     targets["AutoGen.obj"] = (PathClass(
         os.path.join(self.module_autogen.OutputDir, "AutoGen.obj")),
                               PathClass(
                                   os.path.join(
                                       self.module_autogen.DebugDir,
                                       "AutoGen.c")))
     for item in self.module_autogen.Targets.values():
         for block in item:
             targets[block.Target.Path] = (block.Target, block.Inputs[0])
     return targets
Example #3
0
 def ApplyLibraryInstance(self, module):
     alldeps = self.DataPipe.Get("DEPS")
     if alldeps is None:
         alldeps = {}
     mod_libs = alldeps.get((module.MetaFile.File, module.MetaFile.Root,
                             module.Arch, module.MetaFile.Path), [])
     retVal = []
     for (file_path, root, arch, abs_path) in mod_libs:
         libMetaFile = PathClass(file_path, root)
         libMetaFile.OriginalPath = PathClass(file_path, root)
         libMetaFile.Path = abs_path
         retVal.append(self.Wa.BuildDatabase[libMetaFile, arch, self.Target,
                                             self.ToolChain])
     return retVal
Example #4
0
 def Instantiate(self, Macros={}):
     NewRuleObject = copy.copy(self)
     NewRuleObject.BuildTargets = {}
     NewRuleObject.DestFileList = []
     for File in self.DestFileList:
         NewRuleObject.DestFileList.append(PathClass(NormPath(File, Macros)))
     return NewRuleObject
Example #5
0
 def __FindGuidValue(self, CName):
     for Arch in GenFdsGlobalVariable.ArchList:
         PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,
                                                                 Arch,
                                                                 GenFdsGlobalVariable.TargetName,
                                                                 GenFdsGlobalVariable.ToolChainTag)
         for Inf in GenFdsGlobalVariable.FdfParser.Profile.InfList:
             ModuleFile = PathClass(Inf, GenFdsGlobalVariable.WorkSpaceDir)
             ModuleData = GenFdsGlobalVariable.WorkSpace.BuildObject[
                                                         ModuleFile,
                                                         Arch,
                                                         GenFdsGlobalVariable.TargetName,
                                                         GenFdsGlobalVariable.ToolChainTag
                                                         ]
             for Pkg in ModuleData.Packages:
                 if Pkg not in PkgList:
                     PkgList.append(Pkg)
         for PkgDb in PkgList:
             if CName in PkgDb.Ppis:
                 return PkgDb.Ppis[CName]
             if CName in PkgDb.Protocols:
                 return PkgDb.Protocols[CName]
             if CName in PkgDb.Guids:
                 return PkgDb.Guids[CName]
     return None
Example #6
0
 def EncodeToFile(self, encoding, string=None):
     if string is None:
         string = self.SampleData
     if encoding is not None:
         data = codecs.encode(string, encoding)
     else:
         data = string
     path = 'input.uni'
     self.WriteTmpFile(path, data)
     return PathClass(self.GetTmpFilePath(path))
Example #7
0
def OptionsToCommandDict(Options):
    FdsCommandDict = {}
    FdsCommandDict["verbose"] = Options.verbose
    FdsCommandDict["FixedAddress"] = Options.FixedAddress
    FdsCommandDict["quiet"] = Options.quiet
    FdsCommandDict["debug"] = Options.debug
    FdsCommandDict["Workspace"] = Options.Workspace
    FdsCommandDict["GenfdsMultiThread"] = Options.GenfdsMultiThread
    FdsCommandDict["fdf_file"] = [PathClass(Options.filename)] if Options.filename else []
    FdsCommandDict["build_target"] = Options.BuildTarget
    FdsCommandDict["toolchain_tag"] = Options.ToolChain
    FdsCommandDict["active_platform"] = Options.activePlatform
    FdsCommandDict["OptionPcd"] = Options.OptionPcd
    FdsCommandDict["conf_directory"] = Options.ConfDirectory
    FdsCommandDict["IgnoreSources"] = Options.IgnoreSources
    FdsCommandDict["macro"] = Options.Macros
    FdsCommandDict["build_architecture_list"] = Options.archList
    FdsCommandDict["platform_build_directory"] = Options.outputDir
    FdsCommandDict["fd"] = [Options.uiFdName] if Options.uiFdName else []
    FdsCommandDict["fv"] = [Options.uiFvName] if Options.uiFvName else []
    FdsCommandDict["cap"] = [Options.uiCapName] if Options.uiCapName else []
    return FdsCommandDict
            Line = Line.replace(u'\\t', u'\t')
            Line = Line.replace(u'''\"''', u'''"''')
            Line = Line.replace(u'\t', u' ')
            Line = Line.replace(u'\u0006', u'\\')
            Line = Line.replace(DOBULE_QUOTED_SPLASH, u'"')
            Line = Line.replace(SIGLE_QUOTED_SPLASH, u"'")
            Line = Line.replace(TAB_BACK_SLASH, u"/")

#           if Line.find(u'\\x'):
#               hex = Line[Line.find(u'\\x') + 2 : Line.find(u'\\x') + 6]
#               hex = "u'\\u" + hex + "'"

            IncList = gIncludePattern.findall(Line)
            if len(IncList) == 1:
                for Dir in [File.Dir] + self.IncludePathList:
                    IncFile = PathClass(str(IncList[0]), Dir)
                    if os.path.isfile(IncFile.Path):
                        Lines.extend(self.PreProcess(IncFile))
                        break
                else:
                    EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, Message="Cannot find include file", ExtraData=str(IncList[0]))
                continue

            Lines.append(Line)

        return Lines

    #
    # Load a .uni file
    #
    def LoadUniFile(self, File = None):
                                re.UNICODE):
                        EndStr = Line[EndPos:]
                        UniStr = ('\u' + (Line[StartPos + 2:EndPos])
                                  ).decode('unicode_escape')
                        if EndStr.startswith(u'\\x') and len(EndStr) >= 7:
                            if EndStr[6] == u'\\' and re.match(
                                    '[a-fA-F0-9]{4}', EndStr[2:6], re.UNICODE):
                                Line = Line[0:StartPos] + UniStr + EndStr
                        else:
                            Line = Line[0:StartPos] + UniStr + EndStr[1:]
                StartPos = Line.find(u'\\x', StartPos + 1)

            IncList = gIncludePattern.findall(Line)
            if len(IncList) == 1:
                for Dir in [File.Dir] + self.IncludePathList:
                    IncFile = PathClass(str(IncList[0]), Dir)
                    if os.path.isfile(IncFile.Path):
                        Lines.extend(self.PreProcess(IncFile))
                        break
                else:
                    EdkLogger.error("Unicode File Parser",
                                    FILE_NOT_FOUND,
                                    Message="Cannot find include file",
                                    ExtraData=str(IncList[0]))
                continue

            Lines.append(Line)

        return Lines

    #
Example #10
0
    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!")
Example #11
0
    def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):
        GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir,
                                        "Guid.xref")
        GuidXRefFile = []
        PkgGuidDict = {}
        GuidDict = {}
        ModuleList = []
        FileGuidList = []
        VariableGuidSet = set()
        for Arch in ArchList:
            PlatformDataBase = BuildDb.BuildObject[
                GenFdsGlobalVariable.ActivePlatform, Arch,
                GenFdsGlobalVariable.TargetName,
                GenFdsGlobalVariable.ToolChainTag]
            PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList(
                GenFdsGlobalVariable.ActivePlatform, Arch,
                GenFdsGlobalVariable.TargetName,
                GenFdsGlobalVariable.ToolChainTag)
            for P in PkgList:
                PkgGuidDict.update(P.Guids)
            for Name, Guid in PlatformDataBase.Pcds:
                Pcd = PlatformDataBase.Pcds[Name, Guid]
                if Pcd.Type in [TAB_PCDS_DYNAMIC_HII, TAB_PCDS_DYNAMIC_EX_HII]:
                    for SkuId in Pcd.SkuInfoList:
                        Sku = Pcd.SkuInfoList[SkuId]
                        if Sku.VariableGuid in VariableGuidSet: continue
                        VariableGuidSet.add(Sku.VariableGuid)
                        if Sku.VariableGuid and Sku.VariableGuid in PkgGuidDict.keys(
                        ):
                            GuidDict[Sku.VariableGuid] = PkgGuidDict[
                                Sku.VariableGuid]
            for ModuleFile in PlatformDataBase.Modules:
                Module = BuildDb.BuildObject[ModuleFile, Arch,
                                             GenFdsGlobalVariable.TargetName,
                                             GenFdsGlobalVariable.ToolChainTag]
                if Module in ModuleList:
                    continue
                else:
                    ModuleList.append(Module)
                if GlobalData.gGuidPattern.match(ModuleFile.BaseName):
                    GuidXRefFile.append("%s %s\n" %
                                        (ModuleFile.BaseName, Module.BaseName))
                else:
                    GuidXRefFile.append("%s %s\n" %
                                        (Module.Guid, Module.BaseName))
                GuidDict.update(Module.Protocols)
                GuidDict.update(Module.Guids)
                GuidDict.update(Module.Ppis)
            for FvName in FdfParserObj.Profile.FvDict:
                for FfsObj in FdfParserObj.Profile.FvDict[FvName].FfsList:
                    if not isinstance(FfsObj, FileStatement):
                        InfPath = PathClass(
                            NormPath(
                                mws.join(GenFdsGlobalVariable.WorkSpaceDir,
                                         FfsObj.InfFileName)))
                        FdfModule = BuildDb.BuildObject[
                            InfPath, Arch, GenFdsGlobalVariable.TargetName,
                            GenFdsGlobalVariable.ToolChainTag]
                        if FdfModule in ModuleList:
                            continue
                        else:
                            ModuleList.append(FdfModule)
                        GuidXRefFile.append(
                            "%s %s\n" % (FdfModule.Guid, FdfModule.BaseName))
                        GuidDict.update(FdfModule.Protocols)
                        GuidDict.update(FdfModule.Guids)
                        GuidDict.update(FdfModule.Ppis)
                    else:
                        FileStatementGuid = FfsObj.NameGuid
                        if FileStatementGuid in FileGuidList:
                            continue
                        else:
                            FileGuidList.append(FileStatementGuid)
                        Name = []
                        FfsPath = os.path.join(GenFdsGlobalVariable.FvDir,
                                               'Ffs')
                        FfsPath = glob(
                            os.path.join(FfsPath, FileStatementGuid) +
                            TAB_STAR)
                        if not FfsPath:
                            continue
                        if not os.path.exists(FfsPath[0]):
                            continue
                        MatchDict = {}
                        ReFileEnds = compile(
                            '\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$'
                        )
                        FileList = os.listdir(FfsPath[0])
                        for File in FileList:
                            Match = ReFileEnds.search(File)
                            if Match:
                                for Index in range(1, 8):
                                    if Match.group(Index) and Match.group(
                                            Index) in MatchDict:
                                        MatchDict[Match.group(Index)].append(
                                            File)
                                    elif Match.group(Index):
                                        MatchDict[Match.group(Index)] = [File]
                        if not MatchDict:
                            continue
                        if '.ui' in MatchDict:
                            for File in MatchDict['.ui']:
                                with open(os.path.join(FfsPath[0], File),
                                          'rb') as F:
                                    F.read()
                                    length = F.tell()
                                    F.seek(4)
                                    TmpStr = unpack(
                                        '%dh' % ((length - 4) // 2), F.read())
                                    Name = ''.join(chr(c) for c in TmpStr[:-1])
                        else:
                            FileList = []
                            if 'fv.sec.txt' in MatchDict:
                                FileList = MatchDict['fv.sec.txt']
                            elif '.pe32.txt' in MatchDict:
                                FileList = MatchDict['.pe32.txt']
                            elif '.te.txt' in MatchDict:
                                FileList = MatchDict['.te.txt']
                            elif '.pic.txt' in MatchDict:
                                FileList = MatchDict['.pic.txt']
                            elif '.raw.txt' in MatchDict:
                                FileList = MatchDict['.raw.txt']
                            elif '.ffs.txt' in MatchDict:
                                FileList = MatchDict['.ffs.txt']
                            else:
                                pass
                            for File in FileList:
                                with open(os.path.join(FfsPath[0], File),
                                          'r') as F:
                                    Name.append((F.read().split()[-1]))
                        if not Name:
                            continue

                        Name = ' '.join(Name) if isinstance(Name, type(
                            [])) else Name
                        GuidXRefFile.append("%s %s\n" %
                                            (FileStatementGuid, Name))

    # Append GUIDs, Protocols, and PPIs to the Xref file
        GuidXRefFile.append("\n")
        for key, item in GuidDict.items():
            GuidXRefFile.append(
                "%s %s\n" %
                (GuidStructureStringToGuidString(item).upper(), key))

        if GuidXRefFile:
            GuidXRefFile = ''.join(GuidXRefFile)
            SaveFileOnChange(GuidXRefFileName, GuidXRefFile, False)
            GenFdsGlobalVariable.InfLogger(
                "\nGUID cross reference file can be found at %s" %
                GuidXRefFileName)
        elif os.path.exists(GuidXRefFileName):
            os.remove(GuidXRefFileName)
Example #12
0
        UnRefToken = 0
        for Index in range (0, len (self.OrderedStringList[FirstLangName])):
            FirstLangItem = self.OrderedStringList[FirstLangName][Index]
            if FirstLangItem.Referenced == False:
                for LangNameItem in self.LanguageDef:
                    LangName = LangNameItem[0]
                    OtherLangItem = self.OrderedStringList[LangName][Index]
                    OtherLangItem.Token = RefToken + UnRefToken
                    self.OrderedStringListByToken[LangName][OtherLangItem.Token] = OtherLangItem
                UnRefToken = UnRefToken + 1

    #
    # Show the instance itself
    #
    def ShowMe(self):
        print(self.LanguageDef)
        #print self.OrderedStringList
        for Item in self.OrderedStringList:
            print(Item)
            for Member in self.OrderedStringList[Item]:
                print(str(Member))

# 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)
    a = UniFileClassObject([PathClass("C:\\Edk\\Strings.uni"), PathClass("C:\\Edk\\Strings2.uni")])
    a.ReToken()
    a.ShowMe()
Example #13
0
                    LangName = LangNameItem[0]
                    OtherLangItem = self.OrderedStringList[LangName][Index]
                    OtherLangItem.Token = RefToken + UnRefToken
                    self.OrderedStringListByToken[LangName][
                        OtherLangItem.Token] = OtherLangItem
                UnRefToken = UnRefToken + 1

    #
    # Show the instance itself
    #
    def ShowMe(self):
        print(self.LanguageDef)
        #print self.OrderedStringList
        for Item in self.OrderedStringList:
            print(Item)
            for Member in self.OrderedStringList[Item]:
                print(str(Member))


# 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)
    a = UniFileClassObject([
        PathClass("C:\\Edk\\Strings.uni"),
        PathClass("C:\\Edk\\Strings2.uni")
    ])
    a.ReToken()
    a.ShowMe()
Example #14
0
    def GetBuildRules(Inf, Arch):
        if not Arch:
            Arch = DataType.TAB_COMMON

        if not Arch in GenFdsGlobalVariable.OutputDirDict:
            return {}

        BuildRuleDatabase = GenFdsGlobalVariable.__LoadBuildRule()
        if not BuildRuleDatabase:
            return {}

        PathClassObj = PathClass(Inf.MetaFile.File,
                                 GenFdsGlobalVariable.WorkSpaceDir)
        Macro = {}
        Macro["WORKSPACE"] = GenFdsGlobalVariable.WorkSpaceDir
        Macro["MODULE_NAME"] = Inf.BaseName
        Macro["MODULE_GUID"] = Inf.Guid
        Macro["MODULE_VERSION"] = Inf.Version
        Macro["MODULE_TYPE"] = Inf.ModuleType
        Macro["MODULE_FILE"] = str(PathClassObj)
        Macro["MODULE_FILE_BASE_NAME"] = PathClassObj.BaseName
        Macro["MODULE_RELATIVE_DIR"] = PathClassObj.SubDir
        Macro["MODULE_DIR"] = PathClassObj.SubDir

        Macro["BASE_NAME"] = Inf.BaseName

        Macro["ARCH"] = Arch
        Macro["TOOLCHAIN"] = GenFdsGlobalVariable.ToolChainTag
        Macro["TOOLCHAIN_TAG"] = GenFdsGlobalVariable.ToolChainTag
        Macro["TOOL_CHAIN_TAG"] = GenFdsGlobalVariable.ToolChainTag
        Macro["TARGET"] = GenFdsGlobalVariable.TargetName

        Macro["BUILD_DIR"] = GenFdsGlobalVariable.OutputDirDict[Arch]
        Macro["BIN_DIR"] = os.path.join(
            GenFdsGlobalVariable.OutputDirDict[Arch], Arch)
        Macro["LIB_DIR"] = os.path.join(
            GenFdsGlobalVariable.OutputDirDict[Arch], Arch)
        BuildDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch,
                                PathClassObj.SubDir, PathClassObj.BaseName)
        Macro["MODULE_BUILD_DIR"] = BuildDir
        Macro["OUTPUT_DIR"] = os.path.join(BuildDir, "OUTPUT")
        Macro["DEBUG_DIR"] = os.path.join(BuildDir, "DEBUG")

        BuildRules = {}
        for Type in BuildRuleDatabase.FileTypeList:
            #first try getting build rule by BuildRuleFamily
            RuleObject = BuildRuleDatabase[
                Type, Inf.BuildType, Arch,
                GenFdsGlobalVariable.BuildRuleFamily]
            if not RuleObject:
                # build type is always module type, but ...
                if Inf.ModuleType != Inf.BuildType:
                    RuleObject = BuildRuleDatabase[
                        Type, Inf.ModuleType, Arch,
                        GenFdsGlobalVariable.BuildRuleFamily]
            #second try getting build rule by ToolChainFamily
            if not RuleObject:
                RuleObject = BuildRuleDatabase[
                    Type, Inf.BuildType, Arch,
                    GenFdsGlobalVariable.ToolChainFamily]
                if not RuleObject:
                    # build type is always module type, but ...
                    if Inf.ModuleType != Inf.BuildType:
                        RuleObject = BuildRuleDatabase[
                            Type, Inf.ModuleType, Arch,
                            GenFdsGlobalVariable.ToolChainFamily]
            if not RuleObject:
                continue
            RuleObject = RuleObject.Instantiate(Macro)
            BuildRules[Type] = RuleObject
            for Ext in RuleObject.SourceFileExtList:
                BuildRules[Ext] = RuleObject
        return BuildRules
Example #15
0
            Line = Line.replace(u'\\\\', u'\u0006')
            Line = Line.replace(u'\\r\\n', CR + LF)
            Line = Line.replace(u'\\n', CR + LF)
            Line = Line.replace(u'\\r', CR)
            Line = Line.replace(u'\\t', u'\t')
            Line = Line.replace(u'''\"''', u'''"''')
            Line = Line.replace(u'\t', u' ')
            Line = Line.replace(u'\u0006', u'\\')
            
#           if Line.find(u'\\x'):
#               hex = Line[Line.find(u'\\x') + 2 : Line.find(u'\\x') + 6]
#               hex = "u'\\u" + hex + "'"

            IncList = gIncludePattern.findall(Line)
            if len(IncList) == 1:
                Lines.extend(self.PreProcess(PathClass(str(IncList[0]), Dir)))
                continue

            Lines.append(Line)

        return Lines

    #
    # Load a .uni file
    #
    def LoadUniFile(self, File = None):
        if File == None:
            EdkLogger.error("Unicode File Parser", PARSER_ERROR, 'No unicode file is given')
        self.File = File
        #
        # Process special char in file
Example #16
0
    def Apply(self, SourceFile):
        if not self.CommandList or not self.DestFileList:
            return None

        # source file
        if self.IsMultipleInput:
            SrcFileName = ""
            SrcFileBase = ""
            SrcFileExt = ""
            SrcFileDir = ""
            SrcPath = ""
            # SourceFile must be a list
            SrcFile = "$(%s)" % self.FileListMacro
        else:
            SrcFileName, SrcFileBase, SrcFileExt = SourceFile.Name, SourceFile.BaseName, SourceFile.Ext
            if SourceFile.Root:
                SrcFileDir = SourceFile.SubDir
                if SrcFileDir == "":
                    SrcFileDir = "."
            else:
                SrcFileDir = "."
            SrcFile = SourceFile.Path
            SrcPath = SourceFile.Dir

        # destination file (the first one)
        if self.DestFileList:
            DestFile = self.DestFileList[0].Path
            DestPath = self.DestFileList[0].Dir
            DestFileName = self.DestFileList[0].Name
            DestFileBase, DestFileExt = self.DestFileList[0].BaseName, self.DestFileList[0].Ext
        else:
            DestFile = ""
            DestPath = ""
            DestFileName = ""
            DestFileBase = ""
            DestFileExt = ""

        BuildRulePlaceholderDict = {
            # source file
            "src"       :   SrcFile,
            "s_path"    :   SrcPath,
            "s_dir"     :   SrcFileDir,
            "s_name"    :   SrcFileName,
            "s_base"    :   SrcFileBase,
            "s_ext"     :   SrcFileExt,
            # destination file
            "dst"       :   DestFile,
            "d_path"    :   DestPath,
            "d_name"    :   DestFileName,
            "d_base"    :   DestFileBase,
            "d_ext"     :   DestFileExt,
        }

        DstFile = []
        for File in self.DestFileList:
            File = string.Template(str(File)).safe_substitute(BuildRulePlaceholderDict)
            File = string.Template(str(File)).safe_substitute(BuildRulePlaceholderDict)
            DstFile.append(PathClass(File, IsBinary=True))

        if DstFile[0] in self.BuildTargets:
            TargetDesc = self.BuildTargets[DstFile[0]]
            TargetDesc.AddInput(SourceFile)
        else:
            CommandList = []
            for CommandString in self.CommandList:
                CommandString = string.Template(CommandString).safe_substitute(BuildRulePlaceholderDict)
                CommandString = string.Template(CommandString).safe_substitute(BuildRulePlaceholderDict)
                CommandList.append(CommandString)
            TargetDesc = TargetDescBlock([SourceFile], DstFile, CommandList, self.ExtraSourceFileList)
            TargetDesc.ListFileMacro = self.ListFileMacro
            TargetDesc.FileListMacro = self.FileListMacro
            TargetDesc.IncListFileMacro = self.IncListFileMacro
            TargetDesc.GenFileListMacro = self.GenFileListMacro
            TargetDesc.GenListFile = self.GenListFile
            TargetDesc.GenIncListFile = self.GenIncListFile
            self.BuildTargets[DstFile[0]] = TargetDesc
        return TargetDesc
Example #17
0
    def Apply(self, SourceFile, BuildRuleOrder=None):
        if not self.CommandList or not self.DestFileList:
            return None

        # source file
        if self.IsMultipleInput:
            SrcFileName = ""
            SrcFileBase = ""
            SrcFileExt = ""
            SrcFileDir = ""
            SrcPath = ""
            # SourceFile must be a list
            SrcFile = "$(%s)" % self.FileListMacro
        else:
            SrcFileName, SrcFileBase, SrcFileExt = SourceFile.Name, SourceFile.BaseName, SourceFile.Ext
            if SourceFile.Root:
                SrcFileDir = SourceFile.SubDir
                if SrcFileDir == "":
                    SrcFileDir = "."
            else:
                SrcFileDir = "."
            SrcFile = SourceFile.Path
            SrcPath = SourceFile.Dir

        # destination file (the first one)
        if self.DestFileList:
            DestFile = self.DestFileList[0].Path
            DestPath = self.DestFileList[0].Dir
            DestFileName = self.DestFileList[0].Name
            DestFileBase, DestFileExt = self.DestFileList[
                0].BaseName, self.DestFileList[0].Ext
        else:
            DestFile = ""
            DestPath = ""
            DestFileName = ""
            DestFileBase = ""
            DestFileExt = ""

        BuildRulePlaceholderDict = {
            # source file
            "src": SrcFile,
            "s_path": SrcPath,
            "s_dir": SrcFileDir,
            "s_name": SrcFileName,
            "s_base": SrcFileBase,
            "s_ext": SrcFileExt,
            # destination file
            "dst": DestFile,
            "d_path": DestPath,
            "d_name": DestFileName,
            "d_base": DestFileBase,
            "d_ext": DestFileExt,
        }

        DstFile = []
        for File in self.DestFileList:
            File = string.Template(
                str(File)).safe_substitute(BuildRulePlaceholderDict)
            File = string.Template(
                str(File)).safe_substitute(BuildRulePlaceholderDict)
            DstFile.append(PathClass(File, IsBinary=True))

        if DstFile[0] in self.BuildTargets:
            TargetDesc = self.BuildTargets[DstFile[0]]
            if BuildRuleOrder and SourceFile.Ext in BuildRuleOrder:
                Index = BuildRuleOrder.index(SourceFile.Ext)
                for Input in TargetDesc.Inputs:
                    if Input.Ext not in BuildRuleOrder or BuildRuleOrder.index(
                            Input.Ext) > Index:
                        #
                        # Command line should be regenerated since some macros are different
                        #
                        CommandList = self._BuildCommand(
                            BuildRulePlaceholderDict)
                        TargetDesc.InitWorker([SourceFile], DstFile,
                                              CommandList,
                                              self.ExtraSourceFileList)
                        break
            else:
                TargetDesc.AddInput(SourceFile)
        else:
            CommandList = self._BuildCommand(BuildRulePlaceholderDict)
            TargetDesc = TargetDescBlock([SourceFile], DstFile, CommandList,
                                         self.ExtraSourceFileList)
            TargetDesc.ListFileMacro = self.ListFileMacro
            TargetDesc.FileListMacro = self.FileListMacro
            TargetDesc.IncListFileMacro = self.IncListFileMacro
            TargetDesc.GenFileListMacro = self.GenFileListMacro
            TargetDesc.GenListFile = self.GenListFile
            TargetDesc.GenIncListFile = self.GenIncListFile
            self.BuildTargets[DstFile[0]] = TargetDesc
        return TargetDesc
Example #18
0
    def __InfParse__(self, Dict = {}):

        GenFdsGlobalVariable.VerboseLogger( " Begine parsing INf file : %s" %self.InfFileName)

        self.InfFileName = self.InfFileName.replace('$(WORKSPACE)', '')
        if 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.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 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.InfModule = Inf
            
        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)
Example #19
0
 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
Example #20
0
    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)
Example #21
0
def main():
    global Options
    Options = myOptionParser()

    global Workspace
    Workspace = ""
    ArchList = None
    ReturnCode = 0

    EdkLogger.Initialize()
    try:
        if Options.verbose is not None:
            EdkLogger.SetLevel(EdkLogger.VERBOSE)
            GenFdsGlobalVariable.VerboseMode = True

        if Options.FixedAddress is not None:
            GenFdsGlobalVariable.FixedLoadAddress = True

        if Options.quiet is not None:
            EdkLogger.SetLevel(EdkLogger.QUIET)
        if Options.debug is not None:
            EdkLogger.SetLevel(Options.debug + 1)
            GenFdsGlobalVariable.DebugLevel = Options.debug
        else:
            EdkLogger.SetLevel(EdkLogger.INFO)

        if (Options.Workspace is 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:
                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:
                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 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 = 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:
            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))
        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, TAB_COMMON,
                Options.BuildTarget, Options.ToolChain].SupArchList

        TargetArchList = set(BuildWorkSpace.BuildObject[
            GenFdsGlobalVariable.ActivePlatform, TAB_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,
                     TAB_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:
                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:
                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:
                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 is not 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 != 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 FdfParser.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 Options.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
Example #22
0
    def run(self):
        try:
            taskname = "Init"
            with self.file_lock:
                try:
                    self.data_pipe = MemoryDataPipe()
                    self.data_pipe.load(self.data_pipe_file_path)
                except:
                    self.feedback_q.put(taskname + ":" +
                                        "load data pipe %s failed." %
                                        self.data_pipe_file_path)
            EdkLogger.LogClientInitialize(self.log_q)
            loglevel = self.data_pipe.Get("LogLevel")
            if not loglevel:
                loglevel = EdkLogger.INFO
            EdkLogger.SetLevel(loglevel)
            target = self.data_pipe.Get("P_Info").get("Target")
            toolchain = self.data_pipe.Get("P_Info").get("ToolChain")
            archlist = self.data_pipe.Get("P_Info").get("ArchList")

            active_p = self.data_pipe.Get("P_Info").get("ActivePlatform")
            workspacedir = self.data_pipe.Get("P_Info").get("WorkspaceDir")
            PackagesPath = os.getenv("PACKAGES_PATH")
            mws.setWs(workspacedir, PackagesPath)
            self.Wa = WorkSpaceInfo(workspacedir, active_p, target, toolchain,
                                    archlist)
            self.Wa._SrcTimeStamp = self.data_pipe.Get("Workspace_timestamp")
            GlobalData.gGlobalDefines = self.data_pipe.Get("G_defines")
            GlobalData.gCommandLineDefines = self.data_pipe.Get("CL_defines")
            os.environ._data = self.data_pipe.Get("Env_Var")
            GlobalData.gWorkspace = workspacedir
            GlobalData.gDisableIncludePathCheck = False
            GlobalData.gFdfParser = self.data_pipe.Get("FdfParser")
            GlobalData.gDatabasePath = self.data_pipe.Get("DatabasePath")

            GlobalData.gUseHashCache = self.data_pipe.Get("UseHashCache")
            GlobalData.gBinCacheSource = self.data_pipe.Get("BinCacheSource")
            GlobalData.gBinCacheDest = self.data_pipe.Get("BinCacheDest")
            GlobalData.gPlatformHashFile = self.data_pipe.Get(
                "PlatformHashFile")
            GlobalData.gModulePreMakeCacheStatus = dict()
            GlobalData.gModuleMakeCacheStatus = dict()
            GlobalData.gHashChainStatus = dict()
            GlobalData.gCMakeHashFile = dict()
            GlobalData.gModuleHashFile = dict()
            GlobalData.gFileHashDict = dict()
            GlobalData.gEnableGenfdsMultiThread = self.data_pipe.Get(
                "EnableGenfdsMultiThread")
            GlobalData.file_lock = self.file_lock
            CommandTarget = self.data_pipe.Get("CommandTarget")
            pcd_from_build_option = []
            for pcd_tuple in self.data_pipe.Get("BuildOptPcd"):
                pcd_id = ".".join((pcd_tuple[0], pcd_tuple[1]))
                if pcd_tuple[2].strip():
                    pcd_id = ".".join((pcd_id, pcd_tuple[2]))
                pcd_from_build_option.append("=".join((pcd_id, pcd_tuple[3])))
            GlobalData.BuildOptionPcd = pcd_from_build_option
            module_count = 0
            FfsCmd = self.data_pipe.Get("FfsCommand")
            if FfsCmd is None:
                FfsCmd = {}
            GlobalData.FfsCmd = FfsCmd
            PlatformMetaFile = self.GetPlatformMetaFile(
                self.data_pipe.Get("P_Info").get("ActivePlatform"),
                self.data_pipe.Get("P_Info").get("WorkspaceDir"))
            while True:
                if self.module_queue.empty():
                    break
                if self.error_event.is_set():
                    break
                module_count += 1
                module_file, module_root, module_path, module_basename, module_originalpath, module_arch, IsLib = self.module_queue.get_nowait(
                )
                modulefullpath = os.path.join(module_root, module_file)
                taskname = " : ".join((modulefullpath, module_arch))
                module_metafile = PathClass(module_file, module_root)
                if module_path:
                    module_metafile.Path = module_path
                if module_basename:
                    module_metafile.BaseName = module_basename
                if module_originalpath:
                    module_metafile.OriginalPath = PathClass(
                        module_originalpath, module_root)
                arch = module_arch
                target = self.data_pipe.Get("P_Info").get("Target")
                toolchain = self.data_pipe.Get("P_Info").get("ToolChain")
                Ma = ModuleAutoGen(self.Wa, module_metafile, target, toolchain,
                                   arch, PlatformMetaFile, self.data_pipe)
                Ma.IsLibrary = IsLib
                # SourceFileList calling sequence impact the makefile string sequence.
                # Create cached SourceFileList here to unify its calling sequence for both
                # CanSkipbyPreMakeCache and CreateCodeFile/CreateMakeFile.
                RetVal = Ma.SourceFileList
                if GlobalData.gUseHashCache and not GlobalData.gBinCacheDest and CommandTarget in [
                        None, "", "all"
                ]:
                    try:
                        CacheResult = Ma.CanSkipbyPreMakeCache()
                    except:
                        CacheResult = False
                        self.feedback_q.put(taskname)

                    if CacheResult:
                        self.cache_q.put(
                            (Ma.MetaFile.Path, Ma.Arch, "PreMakeCache", True))
                        continue
                    else:
                        self.cache_q.put(
                            (Ma.MetaFile.Path, Ma.Arch, "PreMakeCache", False))

                Ma.CreateCodeFile(False)
                Ma.CreateMakeFile(False,
                                  GenFfsList=FfsCmd.get(
                                      (Ma.MetaFile.Path, Ma.Arch), []))

                if GlobalData.gBinCacheSource and CommandTarget in [
                        None, "", "all"
                ]:
                    try:
                        CacheResult = Ma.CanSkipbyMakeCache()
                    except:
                        CacheResult = False
                        self.feedback_q.put(taskname)

                    if CacheResult:
                        self.cache_q.put(
                            (Ma.MetaFile.Path, Ma.Arch, "MakeCache", True))
                        continue
                    else:
                        self.cache_q.put(
                            (Ma.MetaFile.Path, Ma.Arch, "MakeCache", False))

        except Empty:
            pass
        except:
            self.feedback_q.put(taskname)
        finally:
            self.feedback_q.put("Done")
            self.cache_q.put("CacheDone")
Example #23
0
    def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):
        GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir,
                                        "Guid.xref")
        GuidXRefFile = BytesIO('')
        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 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()
Example #24
0
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)

        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 = os.path.join(GenFdsGlobalVariable.WorkSpaceDir,
                                           FdfFilename)
            if not os.path.exists(FdfFilename):
                EdkLogger.error("GenFds",
                                FILE_NOT_FOUND,
                                ExtraData=FdfFilename)
            if os.path.normcase(FdfFilename).find(Workspace) != 0:
                EdkLogger.error("GenFds", FILE_NOT_FOUND,
                                "FdfFile doesn't exist in Workspace!")

            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 = os.path.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:
                EdkLogger.error("GenFds", FILE_NOT_FOUND,
                                "ActivePlatform doesn't exist in Workspace!")

            ActivePlatform = ActivePlatform[len(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 = os.path.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
Example #25
0
    def PreProcess(self, File):
        if not os.path.exists(File.Path) or not os.path.isfile(File.Path):
            EdkLogger.error("Unicode File Parser",
                            FILE_NOT_FOUND,
                            ExtraData=File.Path)

        try:
            FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path))
        except UnicodeError as X:
            EdkLogger.error("build",
                            FILE_READ_FAILURE,
                            "File read failure: %s" % str(X),
                            ExtraData=File.Path)
        except:
            EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File.Path)

        Lines = []
        #
        # Use unique identifier
        #
        for Line in FileIn:
            Line = Line.strip()
            Line = Line.replace(u'\\\\', BACK_SLASH_PLACEHOLDER)
            Line = StripComments(Line)

            #
            # Ignore empty line
            #
            if len(Line) == 0:
                continue

            Line = Line.replace(u'/langdef', u'#langdef')
            Line = Line.replace(u'/string', u'#string')
            Line = Line.replace(u'/language', u'#language')
            Line = Line.replace(u'/include', u'#include')

            Line = Line.replace(UNICODE_WIDE_CHAR, WIDE_CHAR)
            Line = Line.replace(UNICODE_NARROW_CHAR, NARROW_CHAR)
            Line = Line.replace(UNICODE_NON_BREAKING_CHAR, NON_BREAKING_CHAR)

            Line = Line.replace(u'\\r\\n', CR + LF)
            Line = Line.replace(u'\\n', CR + LF)
            Line = Line.replace(u'\\r', CR)
            Line = Line.replace(u'\\t', u' ')
            Line = Line.replace(u'\t', u' ')
            Line = Line.replace(u'\\"', u'"')
            Line = Line.replace(u"\\'", u"'")
            Line = Line.replace(BACK_SLASH_PLACEHOLDER, u'\\')

            StartPos = Line.find(u'\\x')
            while (StartPos != -1):
                EndPos = Line.find(u'\\', StartPos + 1, StartPos + 7)
                if EndPos != -1 and EndPos - StartPos == 6:
                    if g4HexChar.match(Line[StartPos + 2:EndPos], re.UNICODE):
                        EndStr = Line[EndPos:]
                        UniStr = Line[StartPos + 2:EndPos]
                        if EndStr.startswith(u'\\x') and len(EndStr) >= 7:
                            if EndStr[6] == u'\\' and g4HexChar.match(
                                    EndStr[2:6], re.UNICODE):
                                Line = Line[0:StartPos] + UniStr + EndStr
                        else:
                            Line = Line[0:StartPos] + UniStr + EndStr[1:]
                StartPos = Line.find(u'\\x', StartPos + 1)

            IncList = gIncludePattern.findall(Line)
            if len(IncList) == 1:
                for Dir in [File.Dir] + self.IncludePathList:
                    IncFile = PathClass(str(IncList[0]), Dir)
                    if os.path.isfile(IncFile.Path):
                        Lines.extend(self.PreProcess(IncFile))
                        break
                else:
                    EdkLogger.error("Unicode File Parser",
                                    FILE_NOT_FOUND,
                                    Message="Cannot find include file",
                                    ExtraData=str(IncList[0]))
                continue

            Lines.append(Line)

        return Lines
Example #26
0
    def run(self):
        try:
            taskname = "Init"
            with self.file_lock:
                if not os.path.exists(self.data_pipe_file_path):
                    self.feedback_q.put(taskname + ":" +
                                        "load data pipe %s failed." %
                                        self.data_pipe_file_path)
                self.data_pipe = MemoryDataPipe()
                self.data_pipe.load(self.data_pipe_file_path)
            EdkLogger.LogClientInitialize(self.log_q)
            loglevel = self.data_pipe.Get("LogLevel")
            if not loglevel:
                loglevel = EdkLogger.INFO
            EdkLogger.SetLevel(loglevel)
            target = self.data_pipe.Get("P_Info").get("Target")
            toolchain = self.data_pipe.Get("P_Info").get("ToolChain")
            archlist = self.data_pipe.Get("P_Info").get("ArchList")

            active_p = self.data_pipe.Get("P_Info").get("ActivePlatform")
            workspacedir = self.data_pipe.Get("P_Info").get("WorkspaceDir")
            PackagesPath = os.getenv("PACKAGES_PATH")
            mws.setWs(workspacedir, PackagesPath)
            self.Wa = WorkSpaceInfo(workspacedir, active_p, target, toolchain,
                                    archlist)
            self.Wa._SrcTimeStamp = self.data_pipe.Get("Workspace_timestamp")
            GlobalData.gGlobalDefines = self.data_pipe.Get("G_defines")
            GlobalData.gCommandLineDefines = self.data_pipe.Get("CL_defines")
            os.environ._data = self.data_pipe.Get("Env_Var")
            GlobalData.gWorkspace = workspacedir
            GlobalData.gDisableIncludePathCheck = False
            GlobalData.gFdfParser = self.data_pipe.Get("FdfParser")
            GlobalData.gDatabasePath = self.data_pipe.Get("DatabasePath")
            GlobalData.gBinCacheSource = self.data_pipe.Get("BinCacheSource")
            GlobalData.gBinCacheDest = self.data_pipe.Get("BinCacheDest")
            GlobalData.gCacheIR = self.share_data
            GlobalData.gEnableGenfdsMultiThread = self.data_pipe.Get(
                "EnableGenfdsMultiThread")
            GlobalData.file_lock = self.file_lock
            GlobalData.cache_lock = self.cache_lock
            CommandTarget = self.data_pipe.Get("CommandTarget")
            pcd_from_build_option = []
            for pcd_tuple in self.data_pipe.Get("BuildOptPcd"):
                pcd_id = ".".join((pcd_tuple[0], pcd_tuple[1]))
                if pcd_tuple[2].strip():
                    pcd_id = ".".join((pcd_id, pcd_tuple[2]))
                pcd_from_build_option.append("=".join((pcd_id, pcd_tuple[3])))
            GlobalData.BuildOptionPcd = pcd_from_build_option
            module_count = 0
            FfsCmd = self.data_pipe.Get("FfsCommand")
            if FfsCmd is None:
                FfsCmd = {}
            GlobalData.FfsCmd = FfsCmd
            PlatformMetaFile = self.GetPlatformMetaFile(
                self.data_pipe.Get("P_Info").get("ActivePlatform"),
                self.data_pipe.Get("P_Info").get("WorkspaceDir"))
            libConstPcd = self.data_pipe.Get("LibConstPcd")
            Refes = self.data_pipe.Get("REFS")
            GlobalData.libConstPcd = libConstPcd
            GlobalData.Refes = Refes
            while True:
                if self.module_queue.empty():
                    break
                if self.error_event.is_set():
                    break
                module_count += 1
                module_file, module_root, module_path, module_basename, module_originalpath, module_arch, IsLib = self.module_queue.get_nowait(
                )
                modulefullpath = os.path.join(module_root, module_file)
                taskname = " : ".join((modulefullpath, module_arch))
                module_metafile = PathClass(module_file, module_root)
                if module_path:
                    module_metafile.Path = module_path
                if module_basename:
                    module_metafile.BaseName = module_basename
                if module_originalpath:
                    module_metafile.OriginalPath = PathClass(
                        module_originalpath, module_root)
                arch = module_arch
                target = self.data_pipe.Get("P_Info").get("Target")
                toolchain = self.data_pipe.Get("P_Info").get("ToolChain")
                Ma = ModuleAutoGen(self.Wa, module_metafile, target, toolchain,
                                   arch, PlatformMetaFile, self.data_pipe)
                Ma.IsLibrary = IsLib
                if IsLib:
                    if (Ma.MetaFile.File, Ma.MetaFile.Root, Ma.Arch,
                            Ma.MetaFile.Path) in libConstPcd:
                        Ma.ConstPcd = libConstPcd[(Ma.MetaFile.File,
                                                   Ma.MetaFile.Root, Ma.Arch,
                                                   Ma.MetaFile.Path)]
                    if (Ma.MetaFile.File, Ma.MetaFile.Root, Ma.Arch,
                            Ma.MetaFile.Path) in Refes:
                        Ma.ReferenceModules = Refes[(Ma.MetaFile.File,
                                                     Ma.MetaFile.Root, Ma.Arch,
                                                     Ma.MetaFile.Path)]
                if GlobalData.gBinCacheSource and CommandTarget in [
                        None, "", "all"
                ]:
                    Ma.GenModuleFilesHash(GlobalData.gCacheIR)
                    Ma.GenPreMakefileHash(GlobalData.gCacheIR)
                    if Ma.CanSkipbyPreMakefileCache(GlobalData.gCacheIR):
                        continue

                Ma.CreateCodeFile(False)
                Ma.CreateMakeFile(False,
                                  GenFfsList=FfsCmd.get(
                                      (Ma.MetaFile.File, Ma.Arch), []))

                if GlobalData.gBinCacheSource and CommandTarget in [
                        None, "", "all"
                ]:
                    Ma.GenMakeHeaderFilesHash(GlobalData.gCacheIR)
                    Ma.GenMakeHash(GlobalData.gCacheIR)
                    if Ma.CanSkipbyMakeCache(GlobalData.gCacheIR):
                        continue
                    else:
                        Ma.PrintFirstMakeCacheMissFile(GlobalData.gCacheIR)
        except Empty:
            pass
        except:
            traceback.print_exc(file=sys.stdout)
            self.feedback_q.put(taskname)
        finally:
            self.feedback_q.put("Done")
Example #27
0
    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
Example #28
0
    def IncludeToolDefFile(self, FileName):
        FileContent = []
        if os.path.isfile(FileName):
            try:
                F = open(FileName, 'r')
                FileContent = F.readlines()
            except:
                EdkLogger.error("tools_def.txt parser", FILE_OPEN_FAILURE, ExtraData=FileName)
        else:
            EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=FileName)

        for Index in range(len(FileContent)):
            Line = FileContent[Index].strip()
            if Line == "" or Line[0] == '#':
                continue

            if Line.startswith("!include"):
                IncFile = Line[8:].strip()
                Done, IncFile = self.ExpandMacros(IncFile)
                if not Done:
                    EdkLogger.error("tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE,
                                    "Macro or Environment has not been defined",
                                ExtraData=IncFile[4:-1], File=FileName, Line=Index+1)
                IncFile = NormPath(IncFile)

                if not os.path.isabs(IncFile):
                    #
                    # try WORKSPACE
                    #
                    IncFileTmp = PathClass(IncFile, GlobalData.gWorkspace)
                    ErrorCode = IncFileTmp.Validate()[0]
                    if ErrorCode != 0:
                        #
                        # try PACKAGES_PATH
                        #
                        IncFileTmp = mws.join(GlobalData.gWorkspace, IncFile)
                        if not os.path.exists(IncFileTmp):
                            #
                            # try directory of current file
                            #
                            IncFileTmp = PathClass(IncFile, os.path.dirname(FileName))
                            ErrorCode = IncFileTmp.Validate()[0]
                            if ErrorCode != 0:
                                EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=IncFile)

                    if type(IncFileTmp) is PathClass:
                        IncFile = IncFileTmp.Path
                    else:
                        IncFile = IncFileTmp

                self.IncludeToolDefFile(IncFile)
                continue

            NameValuePair = Line.split("=", 1)
            if len(NameValuePair) != 2:
                EdkLogger.warn("tools_def.txt parser", "Line %d: not correct assignment statement, skipped" % (Index + 1))
                continue

            Name = NameValuePair[0].strip()
            Value = NameValuePair[1].strip()

            if Name == "IDENTIFIER":
                EdkLogger.debug(EdkLogger.DEBUG_8, "Line %d: Found identifier statement, skipped: %s" % ((Index + 1), Value))
                continue

            MacroDefinition = gMacroDefPattern.findall(Name)
            if MacroDefinition != []:
                Done, Value = self.ExpandMacros(Value)
                if not Done:
                    EdkLogger.error("tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE,
                                    "Macro or Environment has not been defined",
                                ExtraData=Value[4:-1], File=FileName, Line=Index+1)

                MacroName = MacroDefinition[0].strip()
                self.MacroDictionary["DEF(%s)" % MacroName] = Value
                EdkLogger.debug(EdkLogger.DEBUG_8, "Line %d: Found macro: %s = %s" % ((Index + 1), MacroName, Value))
                continue

            Done, Value = self.ExpandMacros(Value)
            if not Done:
                EdkLogger.error("tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE,
                                "Macro or Environment has not been defined",
                                ExtraData=Value[4:-1], File=FileName, Line=Index+1)

            List = Name.split('_')
            if len(List) != 5:
                EdkLogger.verbose("Line %d: Not a valid name of definition: %s" % ((Index + 1), Name))
                continue
            elif List[4] == '*':
                EdkLogger.verbose("Line %d: '*' is not allowed in last field: %s" % ((Index + 1), Name))
                continue
            else:
                self.ToolsDefTxtDictionary[Name] = Value
                if List[0] != '*':
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] += [List[0]]
                if List[1] != '*':
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] += [List[1]]
                if List[2] != '*':
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] += [List[2]]
                if List[3] != '*':
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] += [List[3]]
                if List[4] == TAB_TOD_DEFINES_FAMILY and List[2] == '*' and List[3] == '*':
                    if TAB_TOD_DEFINES_FAMILY not in self.ToolsDefTxtDatabase:
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY] = {}
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][List[1]] = Value
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY] = {}
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value
                    elif List[1] not in self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY]:
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][List[1]] = Value
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value
                    elif self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][List[1]] != Value:
                        EdkLogger.verbose("Line %d: No override allowed for the family of a tool chain: %s" % ((Index + 1), Name))
                if List[4] == TAB_TOD_DEFINES_BUILDRULEFAMILY and List[2] == '*' and List[3] == '*':
                    if TAB_TOD_DEFINES_BUILDRULEFAMILY not in self.ToolsDefTxtDatabase \
                       or List[1] not in self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY]:
                        EdkLogger.verbose("Line %d: The family is not specified, but BuildRuleFamily is specified for the tool chain: %s" % ((Index + 1), Name))
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value

        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]