]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
Revert BaseTools: PYTHON3 migration
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFdsGlobalVariable.py
index eeb3ec2197a8f9f468f848851f02fa7ab65f62d4..14578a92a9b19c6fdc6655fa42034f87723f8811 100644 (file)
@@ -27,7 +27,7 @@ from Common import EdkLogger
 from Common.Misc import SaveFileOnChange\r
 \r
 from Common.TargetTxtClassObject import TargetTxtClassObject\r
-from Common.ToolDefClassObject import ToolDefClassObject\r
+from Common.ToolDefClassObject import ToolDefClassObject, ToolDefDict\r
 from AutoGen.BuildEngine import BuildRule\r
 import Common.DataType as DataType\r
 from Common.Misc import PathClass\r
@@ -66,8 +66,8 @@ class GenFdsGlobalVariable:
     FixedLoadAddress = False\r
     PlatformName = ''\r
 \r
-    BuildRuleFamily = "MSFT"\r
-    ToolChainFamily = "MSFT"\r
+    BuildRuleFamily = DataType.TAB_COMPILER_MSFT\r
+    ToolChainFamily = DataType.TAB_COMPILER_MSFT\r
     __BuildRuleDatabase = None\r
     GuidToolDefinition = {}\r
     FfsCmdDict = {}\r
@@ -91,6 +91,9 @@ class GenFdsGlobalVariable:
 \r
     SectionHeader = struct.Struct("3B 1B")\r
 \r
+    # FvName, FdName, CapName in FDF, Image file name\r
+    ImageBinDict = {}\r
+\r
     ## LoadBuildRule\r
     #\r
     @staticmethod\r
@@ -509,14 +512,15 @@ class GenFdsGlobalVariable:
 \r
     @staticmethod\r
     def GetAlignment (AlignString):\r
-        if AlignString is None:\r
+        if not AlignString:\r
             return 0\r
-        if AlignString in ("1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K"):\r
+        if AlignString.endswith('K'):\r
             return int (AlignString.rstrip('K')) * 1024\r
-        elif AlignString in ("1M", "2M", "4M", "8M", "16M"):\r
+        if AlignString.endswith('M'):\r
             return int (AlignString.rstrip('M')) * 1024 * 1024\r
-        else:\r
-            return int (AlignString)\r
+        if AlignString.endswith('G'):\r
+            return int (AlignString.rstrip('G')) * 1024 * 1024 * 1024\r
+        return int (AlignString)\r
 \r
     @staticmethod\r
     def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
@@ -588,23 +592,6 @@ class GenFdsGlobalVariable:
 \r
         GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FV")\r
 \r
-    @staticmethod\r
-    def GenerateVtf(Output, Input, BaseAddress=None, FvSize=None):\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
-            return\r
-        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
-\r
-        Cmd = ["GenVtf"]\r
-        if BaseAddress and FvSize \\r
-            and len(BaseAddress) == len(FvSize):\r
-            for I in range(0, len(BaseAddress)):\r
-                Cmd += ("-r", BaseAddress[I], "-s", FvSize[I])\r
-        Cmd += ("-o", Output)\r
-        for F in Input:\r
-            Cmd += ("-f", F)\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate VTF")\r
-\r
     @staticmethod\r
     def GenerateFirmwareImage(Output, Input, Type="efi", SubType=None, Zero=False,\r
                               Strip=False, Replace=False, TimeStamp=None, Join=False,\r
@@ -843,3 +830,95 @@ class GenFdsGlobalVariable:
     DebugLogger = staticmethod(DebugLogger)\r
     MacroExtend = staticmethod (MacroExtend)\r
     GetPcdValue = staticmethod(GetPcdValue)\r
+\r
+## FindExtendTool()\r
+#\r
+#  Find location of tools to process data\r
+#\r
+#  @param  KeyStringList    Filter for inputs of section generation\r
+#  @param  CurrentArchList  Arch list\r
+#  @param  NameGuid         The Guid name\r
+#\r
+def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
+    ToolDb = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
+    # if user not specify filter, try to deduce it from global data.\r
+    if KeyStringList is None or KeyStringList == []:\r
+        Target = GenFdsGlobalVariable.TargetName\r
+        ToolChain = GenFdsGlobalVariable.ToolChainTag\r
+        if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:\r
+            EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)\r
+        KeyStringList = [Target + '_' + ToolChain + '_' + CurrentArchList[0]]\r
+        for Arch in CurrentArchList:\r
+            if Target + '_' + ToolChain + '_' + Arch not in KeyStringList:\r
+                KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)\r
+\r
+    if GenFdsGlobalVariable.GuidToolDefinition:\r
+        if NameGuid in GenFdsGlobalVariable.GuidToolDefinition:\r
+            return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]\r
+\r
+    ToolDefinition = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
+    ToolPathTmp = None\r
+    ToolOption = None\r
+    ToolPathKey = None\r
+    ToolOptionKey = None\r
+    KeyList = None\r
+    for ToolDef in ToolDefinition.items():\r
+        if NameGuid.lower() == ToolDef[1].lower() :\r
+            KeyList = ToolDef[0].split('_')\r
+            Key = KeyList[0] + \\r
+                  '_' + \\r
+                  KeyList[1] + \\r
+                  '_' + \\r
+                  KeyList[2]\r
+            if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID:\r
+                ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
+                ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
+                ToolPath = ToolDefinition.get(ToolPathKey)\r
+                ToolOption = ToolDefinition.get(ToolOptionKey)\r
+                if ToolPathTmp is None:\r
+                    ToolPathTmp = ToolPath\r
+                else:\r
+                    if ToolPathTmp != ToolPath:\r
+                        EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
+\r
+    BuildOption = {}\r
+    for Arch in CurrentArchList:\r
+        Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+        # key is (ToolChainFamily, ToolChain, CodeBase)\r
+        for item in Platform.BuildOptions:\r
+            if '_PATH' in item[1] or '_FLAGS' in item[1] or '_GUID' in item[1]:\r
+                if not item[0] or (item[0] and GenFdsGlobalVariable.ToolChainFamily== item[0]):\r
+                    if item[1] not in BuildOption:\r
+                        BuildOption[item[1]] = Platform.BuildOptions[item]\r
+        if BuildOption:\r
+            ToolList = [DataType.TAB_TOD_DEFINES_TARGET, DataType.TAB_TOD_DEFINES_TOOL_CHAIN_TAG, DataType.TAB_TOD_DEFINES_TARGET_ARCH]\r
+            for Index in range(2, -1, -1):\r
+                for Key in list(BuildOption.keys()):\r
+                    List = Key.split('_')\r
+                    if List[Index] == '*':\r
+                        for String in ToolDb[ToolList[Index]]:\r
+                            if String in [Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]:\r
+                                List[Index] = String\r
+                                NewKey = '%s_%s_%s_%s_%s' % tuple(List)\r
+                                if NewKey not in BuildOption:\r
+                                    BuildOption[NewKey] = BuildOption[Key]\r
+                                    continue\r
+                                del BuildOption[Key]\r
+                    elif List[Index] not in ToolDb[ToolList[Index]]:\r
+                        del BuildOption[Key]\r
+    if BuildOption:\r
+        if not KeyList:\r
+            for Op in BuildOption:\r
+                if NameGuid == BuildOption[Op]:\r
+                    KeyList = Op.split('_')\r
+                    Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]\r
+                    if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID:\r
+                        ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
+                        ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
+        if ToolPathKey in BuildOption:\r
+            ToolPathTmp = BuildOption[ToolPathKey]\r
+        if ToolOptionKey in BuildOption:\r
+            ToolOption = BuildOption[ToolOptionKey]\r
+\r
+    GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
+    return ToolPathTmp, ToolOption\r