]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
UefiCpuPkg/CpuCommonFeaturesLib: Add check for input parameter.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFdsGlobalVariable.py
index f97b41b834eb6da24077319ca2a15ecb7aa4e050..83996beeea958f8518430909fc4cf4f99503328c 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Global variables for GenFds\r
 #\r
 ## @file\r
 # Global variables for GenFds\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2017, 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
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -31,6 +31,7 @@ from AutoGen.BuildEngine import BuildRule
 import Common.DataType as DataType\r
 from Common.Misc import PathClass\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 import Common.DataType as DataType\r
 from Common.Misc import PathClass\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
 ## Global variables\r
 #\r
 \r
 ## Global variables\r
 #\r
@@ -45,6 +46,7 @@ class GenFdsGlobalVariable:
     LibDir = ''\r
     WorkSpace = None\r
     WorkSpaceDir = ''\r
     LibDir = ''\r
     WorkSpace = None\r
     WorkSpaceDir = ''\r
+    ConfDir = ''\r
     EdkSourceDir = ''\r
     OutputDirFromDscDict = {}\r
     TargetName = ''\r
     EdkSourceDir = ''\r
     OutputDirFromDscDict = {}\r
     TargetName = ''\r
@@ -66,6 +68,7 @@ class GenFdsGlobalVariable:
     BuildRuleFamily = "MSFT"\r
     ToolChainFamily = "MSFT"\r
     __BuildRuleDatabase = None\r
     BuildRuleFamily = "MSFT"\r
     ToolChainFamily = "MSFT"\r
     __BuildRuleDatabase = None\r
+    GuidToolDefinition = {}\r
     \r
     #\r
     # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.\r
     \r
     #\r
     # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.\r
@@ -88,7 +91,7 @@ class GenFdsGlobalVariable:
     def __LoadBuildRule():\r
         if GenFdsGlobalVariable.__BuildRuleDatabase:\r
             return GenFdsGlobalVariable.__BuildRuleDatabase\r
     def __LoadBuildRule():\r
         if GenFdsGlobalVariable.__BuildRuleDatabase:\r
             return GenFdsGlobalVariable.__BuildRuleDatabase\r
-        BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, "Conf/target.txt"))\r
+        BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.ConfDir, "target.txt"))\r
         TargetTxt = TargetTxtClassObject()\r
         if os.path.isfile(BuildConfigurationFile) == True:\r
             TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)\r
         TargetTxt = TargetTxtClassObject()\r
         if os.path.isfile(BuildConfigurationFile) == True:\r
             TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)\r
@@ -201,11 +204,13 @@ class GenFdsGlobalVariable:
 \r
         TargetList = set()\r
         FileList = []\r
 \r
         TargetList = set()\r
         FileList = []\r
-        for File in Inf.Sources:\r
-            if File.TagName in ("", "*", GenFdsGlobalVariable.ToolChainTag) and \\r
-                File.ToolChainFamily in ("", "*", GenFdsGlobalVariable.ToolChainFamily):\r
-                FileList.append((File, DataType.TAB_UNKNOWN_FILE))\r
-        \r
+\r
+        if not Inf.IsBinaryModule:\r
+            for File in Inf.Sources:\r
+                if File.TagName in ("", "*", GenFdsGlobalVariable.ToolChainTag) and \\r
+                    File.ToolChainFamily in ("", "*", GenFdsGlobalVariable.ToolChainFamily):\r
+                    FileList.append((File, DataType.TAB_UNKNOWN_FILE))\r
+\r
         for File in Inf.Binaries:\r
             if File.Target in ['COMMON', '*', GenFdsGlobalVariable.TargetName]:\r
                 FileList.append((File, File.Type))\r
         for File in Inf.Binaries:\r
             if File.Target in ['COMMON', '*', GenFdsGlobalVariable.TargetName]:\r
                 FileList.append((File, File.Type))\r
@@ -270,7 +275,7 @@ class GenFdsGlobalVariable:
     #   @param  ArchList            The Arch list of platform\r
     #\r
     def SetDir (OutputDir, FdfParser, WorkSpace, ArchList):\r
     #   @param  ArchList            The Arch list of platform\r
     #\r
     def SetDir (OutputDir, FdfParser, WorkSpace, ArchList):\r
-        GenFdsGlobalVariable.VerboseLogger( "GenFdsGlobalVariable.OutputDir :%s" %OutputDir)\r
+        GenFdsGlobalVariable.VerboseLogger("GenFdsGlobalVariable.OutputDir :%s" % OutputDir)\r
 #        GenFdsGlobalVariable.OutputDirDict = OutputDir\r
         GenFdsGlobalVariable.FdfParser = FdfParser\r
         GenFdsGlobalVariable.WorkSpace = WorkSpace\r
 #        GenFdsGlobalVariable.OutputDirDict = OutputDir\r
         GenFdsGlobalVariable.FdfParser = FdfParser\r
         GenFdsGlobalVariable.WorkSpace = WorkSpace\r
@@ -280,15 +285,13 @@ class GenFdsGlobalVariable:
         GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
         if not os.path.exists(GenFdsGlobalVariable.FfsDir) :\r
             os.makedirs(GenFdsGlobalVariable.FfsDir)\r
         GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
         if not os.path.exists(GenFdsGlobalVariable.FfsDir) :\r
             os.makedirs(GenFdsGlobalVariable.FfsDir)\r
-        if ArchList != None:\r
-            GenFdsGlobalVariable.ArchList = ArchList\r
 \r
         T_CHAR_LF = '\n'\r
         #\r
         # Create FV Address inf file\r
         #\r
         GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')\r
 \r
         T_CHAR_LF = '\n'\r
         #\r
         # Create FV Address inf file\r
         #\r
         GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')\r
-        FvAddressFile = open (GenFdsGlobalVariable.FvAddressFileName, 'w')\r
+        FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')\r
         #\r
         # Add [Options]\r
         #\r
         #\r
         # Add [Options]\r
         #\r
@@ -300,7 +303,7 @@ class GenFdsGlobalVariable:
                 break\r
 \r
         FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
                 break\r
 \r
         FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
-                                       BsAddress          + \\r
+                                       BsAddress + \\r
                                        T_CHAR_LF)\r
 \r
         RtAddress = '0'\r
                                        T_CHAR_LF)\r
 \r
         RtAddress = '0'\r
@@ -309,7 +312,7 @@ class GenFdsGlobalVariable:
                 RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress\r
 \r
         FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
                 RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress\r
 \r
         FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
-                                       RtAddress          + \\r
+                                       RtAddress + \\r
                                        T_CHAR_LF)\r
 \r
         FvAddressFile.close()\r
                                        T_CHAR_LF)\r
 \r
         FvAddressFile.close()\r
@@ -319,12 +322,13 @@ class GenFdsGlobalVariable:
     #   @param  String           String that may contain macro\r
     #\r
     def ReplaceWorkspaceMacro(String):\r
     #   @param  String           String that may contain macro\r
     #\r
     def ReplaceWorkspaceMacro(String):\r
+        String = mws.handleWsMacro(String)\r
         Str = String.replace('$(WORKSPACE)', GenFdsGlobalVariable.WorkSpaceDir)\r
         if os.path.exists(Str):\r
             if not os.path.isabs(Str):\r
                 Str = os.path.abspath(Str)\r
         else:\r
         Str = String.replace('$(WORKSPACE)', GenFdsGlobalVariable.WorkSpaceDir)\r
         if os.path.exists(Str):\r
             if not os.path.isabs(Str):\r
                 Str = os.path.abspath(Str)\r
         else:\r
-            Str = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, String)\r
+            Str = mws.join(GenFdsGlobalVariable.WorkSpaceDir, String)\r
         return os.path.normpath(Str)\r
 \r
     ## Check if the input files are newer than output files\r
         return os.path.normpath(Str)\r
 \r
     ## Check if the input files are newer than output files\r
@@ -381,13 +385,13 @@ class GenFdsGlobalVariable:
         CommandFile = Output + '.txt'\r
         if Ui not in [None, '']:\r
             #Cmd += ["-n", '"' + Ui + '"']\r
         CommandFile = Output + '.txt'\r
         if Ui not in [None, '']:\r
             #Cmd += ["-n", '"' + Ui + '"']\r
-            SectionData = array.array('B', [0,0,0,0])\r
+            SectionData = array.array('B', [0, 0, 0, 0])\r
             SectionData.fromstring(Ui.encode("utf_16_le"))\r
             SectionData.append(0)\r
             SectionData.append(0)\r
             Len = len(SectionData)\r
             GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
             SectionData.fromstring(Ui.encode("utf_16_le"))\r
             SectionData.append(0)\r
             SectionData.append(0)\r
             Len = len(SectionData)\r
             GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
-            SaveFileOnChange(Output,  SectionData.tostring())\r
+            SaveFileOnChange(Output, SectionData.tostring())\r
         elif Ver not in [None, '']:\r
             Cmd += ["-n", Ver]\r
             if BuildNumber:\r
         elif Ver not in [None, '']:\r
             Cmd += ["-n", Ver]\r
             if BuildNumber:\r
@@ -416,8 +420,10 @@ class GenFdsGlobalVariable:
     def GetAlignment (AlignString):\r
         if AlignString == None:\r
             return 0\r
     def GetAlignment (AlignString):\r
         if AlignString == None:\r
             return 0\r
-        if AlignString in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):\r
+        if AlignString in ("1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K"):\r
             return int (AlignString.rstrip('K')) * 1024\r
             return int (AlignString.rstrip('K')) * 1024\r
+        elif AlignString in ("1M", "2M", "4M", "8M", "16M"):\r
+            return int (AlignString.rstrip('M')) * 1024 * 1024\r
         else:\r
             return int (AlignString)\r
 \r
         else:\r
             return int (AlignString)\r
 \r
@@ -425,11 +431,18 @@ class GenFdsGlobalVariable:
     def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
                     SectionAlign=None):\r
         Cmd = ["GenFfs", "-t", Type, "-g", Guid]\r
     def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
                     SectionAlign=None):\r
         Cmd = ["GenFfs", "-t", Type, "-g", Guid]\r
+        mFfsValidAlign = ["0", "8", "16", "128", "512", "1K", "4K", "32K", "64K", "128K", "256K", "512K", "1M", "2M", "4M", "8M", "16M"]\r
         if Fixed == True:\r
             Cmd += ["-x"]\r
         if CheckSum:\r
             Cmd += ["-s"]\r
         if Align not in [None, '']:\r
         if Fixed == True:\r
             Cmd += ["-x"]\r
         if CheckSum:\r
             Cmd += ["-s"]\r
         if Align not in [None, '']:\r
+            if Align not in mFfsValidAlign:\r
+                Align = GenFdsGlobalVariable.GetAlignment (Align)\r
+                for index in range(0, len(mFfsValidAlign) - 1):\r
+                    if ((Align > GenFdsGlobalVariable.GetAlignment(mFfsValidAlign[index])) and (Align <= GenFdsGlobalVariable.GetAlignment(mFfsValidAlign[index + 1]))):\r
+                        break\r
+                Align = mFfsValidAlign[index + 1]\r
             Cmd += ["-a", Align]\r
 \r
         Cmd += ["-o", Output]\r
             Cmd += ["-a", Align]\r
 \r
         Cmd += ["-o", Output]\r
@@ -456,12 +469,12 @@ class GenFdsGlobalVariable:
         Cmd = ["GenFv"]\r
         if BaseAddress not in [None, '']:\r
             Cmd += ["-r", BaseAddress]\r
         Cmd = ["GenFv"]\r
         if BaseAddress not in [None, '']:\r
             Cmd += ["-r", BaseAddress]\r
-        \r
+\r
         if ForceRebase == False:\r
         if ForceRebase == False:\r
-            Cmd +=["-F", "FALSE"]\r
+            Cmd += ["-F", "FALSE"]\r
         elif ForceRebase == True:\r
         elif ForceRebase == True:\r
-            Cmd +=["-F", "TRUE"]\r
-            \r
+            Cmd += ["-F", "TRUE"]\r
+\r
         if Capsule:\r
             Cmd += ["-c"]\r
         if Dump:\r
         if Capsule:\r
             Cmd += ["-c"]\r
         if Dump:\r
@@ -565,7 +578,7 @@ class GenFdsGlobalVariable:
         if VendorId != None:\r
             Cmd += ["-f", VendorId]\r
 \r
         if VendorId != None:\r
             Cmd += ["-f", VendorId]\r
 \r
-        Cmd += ["-o", Output]    \r
+        Cmd += ["-o", Output]\r
         GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
 \r
     @staticmethod\r
         GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
 \r
     @staticmethod\r
@@ -601,7 +614,7 @@ class GenFdsGlobalVariable:
                 sys.stdout.write('\n')\r
 \r
         try:\r
                 sys.stdout.write('\n')\r
 \r
         try:\r
-            PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr= subprocess.PIPE, shell=True)\r
+            PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\r
         except Exception, X:\r
             EdkLogger.error("GenFds", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0]))\r
         (out, error) = PopenObject.communicate()\r
         except Exception, X:\r
             EdkLogger.error("GenFds", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0]))\r
         (out, error) = PopenObject.communicate()\r
@@ -613,7 +626,7 @@ class GenFdsGlobalVariable:
             returnValue[0] = PopenObject.returncode\r
             return\r
         if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:\r
             returnValue[0] = PopenObject.returncode\r
             return\r
         if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:\r
-            GenFdsGlobalVariable.InfLogger ("Return Value = %d" %PopenObject.returncode)\r
+            GenFdsGlobalVariable.InfLogger ("Return Value = %d" % PopenObject.returncode)\r
             GenFdsGlobalVariable.InfLogger (out)\r
             GenFdsGlobalVariable.InfLogger (error)\r
             if PopenObject.returncode != 0:\r
             GenFdsGlobalVariable.InfLogger (out)\r
             GenFdsGlobalVariable.InfLogger (error)\r
             if PopenObject.returncode != 0:\r
@@ -626,7 +639,7 @@ class GenFdsGlobalVariable:
     def InfLogger (msg):\r
         EdkLogger.info(msg)\r
 \r
     def InfLogger (msg):\r
         EdkLogger.info(msg)\r
 \r
-    def ErrorLogger (msg, File = None, Line = None, ExtraData = None):\r
+    def ErrorLogger (msg, File=None, Line=None, ExtraData=None):\r
         EdkLogger.error('GenFds', GENFDS_ERROR, msg, File, Line, ExtraData)\r
 \r
     def DebugLogger (Level, msg):\r
         EdkLogger.error('GenFds', GENFDS_ERROR, msg, File, Line, ExtraData)\r
 \r
     def DebugLogger (Level, msg):\r
@@ -637,7 +650,7 @@ class GenFdsGlobalVariable:
     #   @param  Str           String that may contain macro\r
     #   @param  MacroDict     Dictionary that contains macro value pair\r
     #\r
     #   @param  Str           String that may contain macro\r
     #   @param  MacroDict     Dictionary that contains macro value pair\r
     #\r
-    def MacroExtend (Str, MacroDict = {}, Arch = 'COMMON'):\r
+    def MacroExtend (Str, MacroDict={}, Arch='COMMON'):\r
         if Str == None :\r
             return None\r
 \r
         if Str == None :\r
             return None\r
 \r
@@ -645,7 +658,8 @@ class GenFdsGlobalVariable:
                 '$(EDK_SOURCE)'  : GenFdsGlobalVariable.EdkSourceDir,\r
 #                '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,\r
                 '$(TARGET)' : GenFdsGlobalVariable.TargetName,\r
                 '$(EDK_SOURCE)'  : GenFdsGlobalVariable.EdkSourceDir,\r
 #                '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,\r
                 '$(TARGET)' : GenFdsGlobalVariable.TargetName,\r
-                '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable.ToolChainTag\r
+                '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable.ToolChainTag,\r
+                '$(SPACE)' : ' '\r
                }\r
         OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
         if Arch != 'COMMON' and Arch in GenFdsGlobalVariable.ArchList:\r
                }\r
         OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
         if Arch != 'COMMON' and Arch in GenFdsGlobalVariable.ArchList:\r
@@ -693,10 +707,10 @@ class GenFdsGlobalVariable:
                         \r
                     PcdValue = PcdObj.DefaultValue\r
                     return PcdValue\r
                         \r
                     PcdValue = PcdObj.DefaultValue\r
                     return PcdValue\r
-                \r
-            for Package in GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform, \r
-                                                                         Arch, \r
-                                                                         GenFdsGlobalVariable.TargetName, \r
+\r
+            for Package in GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,\r
+                                                                         Arch,\r
+                                                                         GenFdsGlobalVariable.TargetName,\r
                                                                          GenFdsGlobalVariable.ToolChainTag):\r
                 PcdDict = Package.Pcds\r
                 for Key in PcdDict:\r
                                                                          GenFdsGlobalVariable.ToolChainTag):\r
                 PcdDict = Package.Pcds\r
                 for Key in PcdDict:\r