]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFds.py
BaseTools: Fix GenSec can't found the depex file
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFds.py
index 277da357af0164b75584c347ddc570eb51f4853b..4a5d6f476abdd2bdc3cffaee86f4c790f812c603 100644 (file)
@@ -42,6 +42,9 @@ from Common.Misc import CheckPcdDatum
 from Common.Misc import BuildOptionPcdValueFormat\r
 from Common.BuildVersion import gBUILD_VERSION\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
+import FfsFileStatement\r
+import glob\r
+from struct import unpack\r
 \r
 ## Version and Copyright\r
 versionNumber = "1.0" + ' ' + gBUILD_VERSION\r
@@ -96,6 +99,8 @@ def main():
                 GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE'])\r
             if (Options.debug):\r
                 GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace)\r
+            if Options.GenfdsMultiThread:\r
+                GenFdsGlobalVariable.EnableGenfdsMultiThread = True\r
         os.chdir(GenFdsGlobalVariable.WorkSpaceDir)\r
         \r
         # set multiple workspace\r
@@ -327,7 +332,7 @@ def main():
         GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList)\r
 \r
         """Generate GUID cross reference file"""\r
-        GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList)\r
+        GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList, FdfParserObj)\r
 \r
         """Display FV space info."""\r
         GenFds.DisplayFvSpaceInfo(FdfParserObj)\r
@@ -535,6 +540,7 @@ def myOptionParser():
     Parser.add_option("--conf", action="store", type="string", dest="ConfDirectory", help="Specify the customized Conf directory.")\r
     Parser.add_option("--ignore-sources", action="store_true", dest="IgnoreSources", default=False, help="Focus to a binary build and ignore all source files")\r
     Parser.add_option("--pcd", action="append", dest="OptionPcd", help="Set PCD value by command line. Format: \"PcdName=Value\" ")\r
+    Parser.add_option("--genfds-multi-thread", action="store_true", dest="GenfdsMultiThread", default=False, help="Enable GenFds multi thread to generate ffs file.")\r
 \r
     (Options, args) = Parser.parse_args()\r
     return Options\r
@@ -608,6 +614,23 @@ class GenFds :
                 for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys():\r
                     OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName]\r
                     OptRomObj.AddToBuffer(None)\r
+    @staticmethod\r
+    def GenFfsMakefile(OutputDir, FdfParser, WorkSpace, ArchList, GlobalData):\r
+        GenFdsGlobalVariable.SetEnv(FdfParser, WorkSpace, ArchList, GlobalData)\r
+        for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
+            FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]\r
+            FdObj.GenFd(Flag=True)\r
+\r
+        for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
+            FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName]\r
+            FvObj.AddToBuffer(Buffer=None, Flag=True)\r
+\r
+        if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}:\r
+            for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys():\r
+                OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName]\r
+                OptRomObj.AddToBuffer(Buffer=None, Flag=True)\r
+\r
+        return GenFdsGlobalVariable.FfsCmdDict\r
 \r
     ## GetFvBlockSize()\r
     #\r
@@ -724,14 +747,20 @@ class GenFds :
             ModuleObj = BuildDb.BuildObject[Key, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
             print ModuleObj.BaseName + ' ' + ModuleObj.ModuleType\r
 \r
-    def GenerateGuidXRefFile(BuildDb, ArchList):\r
+    def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):\r
         GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")\r
         GuidXRefFile = StringIO.StringIO('')\r
         GuidDict = {}\r
+        ModuleList = []\r
+        FileGuidList = []\r
         for Arch in ArchList:\r
             PlatformDataBase = BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
             for ModuleFile in PlatformDataBase.Modules:\r
                 Module = BuildDb.BuildObject[ModuleFile, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+                if Module in ModuleList:\r
+                    continue\r
+                else:\r
+                    ModuleList.append(Module)\r
                 GuidXRefFile.write("%s %s\n" % (Module.Guid, Module.BaseName))\r
                 for key, item in Module.Protocols.items():\r
                     GuidDict[key] = item\r
@@ -739,6 +768,81 @@ class GenFds :
                     GuidDict[key] = item\r
                 for key, item in Module.Ppis.items():\r
                     GuidDict[key] = item\r
+            for FvName in FdfParserObj.Profile.FvDict:\r
+                for FfsObj in FdfParserObj.Profile.FvDict[FvName].FfsList:\r
+                    if not isinstance(FfsObj, FfsFileStatement.FileStatement):\r
+                        InfPath = PathClass(NormPath(mws.join(GenFdsGlobalVariable.WorkSpaceDir, FfsObj.InfFileName)))\r
+                        FdfModule = BuildDb.BuildObject[InfPath, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+                        if FdfModule in ModuleList:\r
+                            continue\r
+                        else:\r
+                            ModuleList.append(FdfModule)\r
+                        GuidXRefFile.write("%s %s\n" % (FdfModule.Guid, FdfModule.BaseName))\r
+                        for key, item in FdfModule.Protocols.items():\r
+                            GuidDict[key] = item\r
+                        for key, item in FdfModule.Guids.items():\r
+                            GuidDict[key] = item\r
+                        for key, item in FdfModule.Ppis.items():\r
+                            GuidDict[key] = item\r
+                    else:\r
+                        FileStatementGuid = FfsObj.NameGuid\r
+                        if FileStatementGuid in FileGuidList:\r
+                            continue\r
+                        else:\r
+                            FileGuidList.append(FileStatementGuid)\r
+                        Name = []\r
+                        FfsPath = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
+                        FfsPath = glob.glob(os.path.join(FfsPath, FileStatementGuid) + '*')\r
+                        if not FfsPath:\r
+                            continue\r
+                        if not os.path.exists(FfsPath[0]):\r
+                            continue\r
+                        MatchDict = {}\r
+                        ReFileEnds = re.compile('\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$')\r
+                        FileList = os.listdir(FfsPath[0])\r
+                        for File in FileList:\r
+                            Match = ReFileEnds.search(File)\r
+                            if Match:\r
+                                for Index in range(1, 8):\r
+                                    if Match.group(Index) and Match.group(Index) in MatchDict:\r
+                                        MatchDict[Match.group(Index)].append(File)\r
+                                    elif Match.group(Index):\r
+                                        MatchDict[Match.group(Index)] = [File]\r
+                        if not MatchDict:\r
+                            continue\r
+                        if '.ui' in MatchDict:\r
+                            for File in MatchDict['.ui']:\r
+                                with open(os.path.join(FfsPath[0], File), 'rb') as F:\r
+                                    F.read()\r
+                                    length = F.tell()\r
+                                    F.seek(4)\r
+                                    TmpStr = unpack('%dh' % ((length - 4) / 2), F.read())\r
+                                    Name = ''.join([chr(c) for c in TmpStr[:-1]])\r
+                        else:\r
+                            FileList = []\r
+                            if 'fv.sec.txt' in MatchDict:\r
+                                FileList = MatchDict['fv.sec.txt']\r
+                            elif '.pe32.txt' in MatchDict:\r
+                                FileList = MatchDict['.pe32.txt']\r
+                            elif '.te.txt' in MatchDict:\r
+                                FileList = MatchDict['.te.txt']\r
+                            elif '.pic.txt' in MatchDict:\r
+                                FileList = MatchDict['.pic.txt']\r
+                            elif '.raw.txt' in MatchDict:\r
+                                FileList = MatchDict['.raw.txt']\r
+                            elif '.ffs.txt' in MatchDict:\r
+                                FileList = MatchDict['.ffs.txt']\r
+                            else:\r
+                                pass\r
+                            for File in FileList:\r
+                                with open(os.path.join(FfsPath[0], File), 'r') as F:\r
+                                    Name.append((F.read().split()[-1]))\r
+                        if not Name:\r
+                            continue\r
+\r
+                        Name = ' '.join(Name) if type(Name) == type([]) else Name\r
+                        GuidXRefFile.write("%s %s\n" %(FileStatementGuid, Name))\r
+\r
        # Append GUIDs, Protocols, and PPIs to the Xref file\r
         GuidXRefFile.write("\n")\r
         for key, item in GuidDict.items():\r