]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFds.py
BaseTools: Enhance BaseTools supports FixedAtBuild usage in VFR file
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFds.py
index 4fa4eda04a5fd7a8a8c36b49a9fad8d8d1b1c7ab..c2e9418b84caaa219e08fb257fd5cd797a1538ee 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # generate flash image\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -38,13 +38,14 @@ from Common.Misc import DirCache, PathClass
 from Common.Misc import SaveFileOnChange\r
 from Common.Misc import ClearDuplicatedInf\r
 from Common.Misc import GuidStructureStringToGuidString\r
+from Common.Misc import CheckPcdDatum\r
 from Common.BuildVersion import gBUILD_VERSION\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
 ## Version and Copyright\r
 versionNumber = "1.0" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + versionNumber\r
-__copyright__ = "Copyright (c) 2007 - 2014, Intel Corporation  All rights reserved."\r
+__copyright__ = "Copyright (c) 2007 - 2016, Intel Corporation  All rights reserved."\r
 \r
 ## Tool entrance method\r
 #\r
@@ -118,13 +119,9 @@ def main():
 \r
         if (Options.BuildTarget):\r
             GenFdsGlobalVariable.TargetName = Options.BuildTarget\r
-        else:\r
-            EdkLogger.error("GenFds", OPTION_MISSING, "Missing build target")\r
 \r
         if (Options.ToolChain):\r
             GenFdsGlobalVariable.ToolChainTag = Options.ToolChain\r
-        else:\r
-            EdkLogger.error("GenFds", OPTION_MISSING, "Missing tool chain tag")\r
 \r
         if (Options.activePlatform):\r
             ActivePlatform = Options.activePlatform\r
@@ -138,18 +135,10 @@ def main():
 \r
             if not os.path.exists(ActivePlatform)  :\r
                 EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!")\r
-\r
-            if os.path.normcase (ActivePlatform).find(Workspace) == 0:\r
-                ActivePlatform = mws.relpath(ActivePlatform, Workspace)\r
-            if len(ActivePlatform) > 0 :\r
-                if ActivePlatform[0] == '\\' or ActivePlatform[0] == '/':\r
-                    ActivePlatform = ActivePlatform[1:]\r
-            else:\r
-                EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!")\r
         else:\r
             EdkLogger.error("GenFds", OPTION_MISSING, "Missing active platform")\r
 \r
-        GenFdsGlobalVariable.ActivePlatform = PathClass(NormPath(ActivePlatform), Workspace)\r
+        GenFdsGlobalVariable.ActivePlatform = PathClass(NormPath(ActivePlatform))\r
 \r
         if (Options.ConfDirectory):\r
             # Get alternate Conf location, if it is absolute, then just use the absolute directory name\r
@@ -163,12 +152,31 @@ def main():
                 # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf\r
                 ConfDirectoryPath = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, ConfDirectoryPath)\r
         else:\r
-            # Get standard WORKSPACE/Conf, use the absolute path to the WORKSPACE/Conf\r
-            ConfDirectoryPath = mws.join(GenFdsGlobalVariable.WorkSpaceDir, 'Conf')\r
+            if "CONF_PATH" in os.environ.keys():\r
+                ConfDirectoryPath = os.path.normcase(os.environ["CONF_PATH"])\r
+            else:\r
+                # Get standard WORKSPACE/Conf, use the absolute path to the WORKSPACE/Conf\r
+                ConfDirectoryPath = mws.join(GenFdsGlobalVariable.WorkSpaceDir, 'Conf')\r
         GenFdsGlobalVariable.ConfDir = ConfDirectoryPath\r
         BuildConfigurationFile = os.path.normpath(os.path.join(ConfDirectoryPath, "target.txt"))\r
         if os.path.isfile(BuildConfigurationFile) == True:\r
-            TargetTxtClassObject.TargetTxtClassObject(BuildConfigurationFile)\r
+            TargetTxt = TargetTxtClassObject.TargetTxtClassObject()\r
+            TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)\r
+            # if no build target given in command line, get it from target.txt\r
+            if not GenFdsGlobalVariable.TargetName:\r
+                BuildTargetList = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET]\r
+                if len(BuildTargetList) != 1:\r
+                    EdkLogger.error("GenFds", OPTION_VALUE_INVALID, ExtraData="Only allows one instance for Target.")\r
+                GenFdsGlobalVariable.TargetName = BuildTargetList[0]\r
+\r
+            # if no tool chain given in command line, get it from target.txt\r
+            if not GenFdsGlobalVariable.ToolChainTag:\r
+                ToolChainList = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]\r
+                if ToolChainList == None or len(ToolChainList) == 0:\r
+                    EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE, ExtraData="No toolchain given. Don't know how to build.")\r
+                if len(ToolChainList) != 1:\r
+                    EdkLogger.error("GenFds", OPTION_VALUE_INVALID, ExtraData="Only allows one instance for ToolChain.")\r
+                GenFdsGlobalVariable.ToolChainTag = ToolChainList[0]\r
         else:\r
             EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=BuildConfigurationFile)\r
 \r
@@ -183,6 +191,8 @@ def main():
                     Pair = Pair[:-1]\r
                 List = Pair.split('=')\r
                 if len(List) == 2:\r
+                    if not List[1].strip():\r
+                        EdkLogger.error("GenFds", OPTION_VALUE_INVALID, ExtraData="No Value given for Macro %s" %List[0])\r
                     if List[0].strip() == "EFI_SOURCE":\r
                         GlobalData.gEfiSource = List[1].strip()\r
                         GlobalData.gGlobalDefines["EFI_SOURCE"] = GlobalData.gEfiSource\r
@@ -199,6 +209,14 @@ def main():
                     GlobalData.gCommandLineDefines[List[0].strip()] = "TRUE"\r
         os.environ["WORKSPACE"] = Workspace\r
 \r
+        # Use the -t and -b option as gGlobalDefines's TOOLCHAIN and TARGET if they are not defined\r
+        if "TARGET" not in GlobalData.gGlobalDefines.keys():\r
+            GlobalData.gGlobalDefines["TARGET"] = GenFdsGlobalVariable.TargetName\r
+        if "TOOLCHAIN" not in GlobalData.gGlobalDefines.keys():\r
+            GlobalData.gGlobalDefines["TOOLCHAIN"] = GenFdsGlobalVariable.ToolChainTag\r
+        if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines.keys():\r
+            GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = GenFdsGlobalVariable.ToolChainTag\r
+\r
         """call Workspace build create database"""\r
         GlobalData.gDatabasePath = os.path.normpath(os.path.join(ConfDirectoryPath, GlobalData.gDatabasePath))\r
         BuildWorkSpace = WorkspaceDatabase(GlobalData.gDatabasePath)\r
@@ -274,6 +292,14 @@ def main():
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
                                 "No such a Capsule in FDF file: %s" % Options.uiCapName)\r
 \r
+        GenFdsGlobalVariable.WorkSpace = BuildWorkSpace\r
+        if ArchList != None:\r
+            GenFdsGlobalVariable.ArchList = ArchList\r
+\r
+        if Options.OptionPcd:\r
+            GlobalData.BuildOptionPcd = Options.OptionPcd\r
+            CheckBuildOptionPcd()\r
+\r
         """Modify images from build output if the feature of loading driver at fixed address is on."""\r
         if GenFdsGlobalVariable.FixedLoadAddress:\r
             GenFds.PreprocessImage(BuildWorkSpace, GenFdsGlobalVariable.ActivePlatform)\r
@@ -300,7 +326,7 @@ def main():
                     "\nPython",\r
                     CODE_ERROR,\r
                     "Tools code failure",\r
-                    ExtraData="Please send email to edk2-devel@lists.sourceforge.net for help, attaching following call stack trace!\n",\r
+                    ExtraData="Please send email to edk2-devel@lists.01.org for help, attaching following call stack trace!\n",\r
                     RaiseError=False\r
                     )\r
         EdkLogger.quiet(traceback.format_exc())\r
@@ -316,7 +342,137 @@ def SingleCheckCallback(option, opt_str, value, parser):
         gParamCheck.append(option)\r
     else:\r
         parser.error("Option %s only allows one instance in command line!" % option)\r
-        \r
+\r
+def CheckBuildOptionPcd():\r
+    for Arch in GenFdsGlobalVariable.ArchList:\r
+        PkgList  = GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag)\r
+        for i, pcd in enumerate(GlobalData.BuildOptionPcd):\r
+            if type(pcd) is tuple:\r
+                continue\r
+            (pcdname, pcdvalue) = pcd.split('=')\r
+            if not pcdvalue:\r
+                EdkLogger.error('GenFds', OPTION_MISSING, "No Value specified for the PCD %s." % (pcdname))\r
+            if '.' in pcdname:\r
+                (TokenSpaceGuidCName, TokenCName) = pcdname.split('.')\r
+                HasTokenSpace = True\r
+            else:\r
+                TokenCName = pcdname\r
+                TokenSpaceGuidCName = ''\r
+                HasTokenSpace = False\r
+            TokenSpaceGuidCNameList = []\r
+            FoundFlag = False\r
+            PcdDatumType = ''\r
+            NewValue = ''\r
+            for package in PkgList:\r
+                for key in package.Pcds:\r
+                    PcdItem = package.Pcds[key]\r
+                    if HasTokenSpace:\r
+                        if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):\r
+                            PcdDatumType = PcdItem.DatumType\r
+                            NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
+                            FoundFlag = True\r
+                    else:\r
+                        if PcdItem.TokenCName == TokenCName:\r
+                            if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:\r
+                                if len (TokenSpaceGuidCNameList) < 1:\r
+                                    TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)\r
+                                    PcdDatumType = PcdItem.DatumType\r
+                                    TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName\r
+                                    NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
+                                    FoundFlag = True\r
+                                else:\r
+                                    EdkLogger.error(\r
+                                            'GenFds',\r
+                                            PCD_VALIDATION_INFO_ERROR,\r
+                                            "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])\r
+                                            )\r
+\r
+            GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)\r
+\r
+def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):\r
+    if PcdDatumType == 'VOID*':\r
+        if Value.startswith('L'):\r
+            if not Value[1]:\r
+                EdkLogger.error('GenFds', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
+            Value = Value[0] + '"' + Value[1:] + '"'\r
+        elif Value.startswith('B'):\r
+            if not Value[1]:\r
+                EdkLogger.error('GenFds', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
+            Value = Value[1:]\r
+        else:\r
+            if not Value[0]:\r
+                EdkLogger.error('GenFds', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
+            Value = '"' + Value + '"'\r
+\r
+    IsValid, Cause = CheckPcdDatum(PcdDatumType, Value)\r
+    if not IsValid:\r
+        EdkLogger.error('build', FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))\r
+    if PcdDatumType == 'BOOLEAN':\r
+        Value = Value.upper()\r
+        if Value == 'TRUE' or Value == '1':\r
+            Value = '1'\r
+        elif Value == 'FALSE' or Value == '0':\r
+            Value = '0'\r
+    return  Value\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
+    # if user not specify filter, try to deduce it from global data.\r
+    if KeyStringList == None or KeyStringList == []:\r
+        Target = GenFdsGlobalVariable.TargetName\r
+        ToolChain = GenFdsGlobalVariable.ToolChainTag\r
+        ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\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.keys():\r
+            return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]\r
+\r
+    ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
+    ToolPathTmp = None\r
+    ToolOption = None\r
+    for ToolDef in ToolDefinition.items():\r
+        if NameGuid == ToolDef[1]:\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] == 'GUID':\r
+\r
+                ToolPath = ToolDefinition.get(Key + \\r
+                                               '_' + \\r
+                                               KeyList[3] + \\r
+                                               '_' + \\r
+                                               'PATH')\r
+\r
+                ToolOption = ToolDefinition.get(Key + \\r
+                                                '_' + \\r
+                                                KeyList[3] + \\r
+                                                '_' + \\r
+                                                'FLAGS')\r
+                if ToolPathTmp == 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
+    GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
+    return ToolPathTmp, ToolOption\r
+\r
 ## Parse command line options\r
 #\r
 # Using standard Python module optparse to parse command line option of this tool.\r
@@ -349,6 +505,7 @@ def myOptionParser():
     Parser.add_option("-s", "--specifyaddress", dest="FixedAddress", action="store_true", type=None, help="Specify driver load address.")\r
     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
 \r
     (Options, args) = Parser.parse_args()\r
     return Options\r