]> 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 04bbc300ceda186a13e9fd8ba5c47188fbe470dc..83996beeea958f8518430909fc4cf4f99503328c 100644 (file)
@@ -1,7 +1,7 @@
 ## @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
@@ -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
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
 ## Global variables\r
 #\r
@@ -67,6 +68,7 @@ class GenFdsGlobalVariable:
     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
@@ -273,7 +275,7 @@ class GenFdsGlobalVariable:
     #   @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
@@ -283,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
-        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
-        FvAddressFile = open (GenFdsGlobalVariable.FvAddressFileName, 'w')\r
+        FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')\r
         #\r
         # Add [Options]\r
         #\r
@@ -303,7 +303,7 @@ class GenFdsGlobalVariable:
                 break\r
 \r
         FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
-                                       BsAddress          + \\r
+                                       BsAddress + \\r
                                        T_CHAR_LF)\r
 \r
         RtAddress = '0'\r
@@ -312,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          + \\r
+                                       RtAddress + \\r
                                        T_CHAR_LF)\r
 \r
         FvAddressFile.close()\r
@@ -322,12 +322,13 @@ class GenFdsGlobalVariable:
     #   @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 = 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
@@ -384,13 +385,13 @@ class GenFdsGlobalVariable:
         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
-            SaveFileOnChange(Output,  SectionData.tostring())\r
+            SaveFileOnChange(Output, SectionData.tostring())\r
         elif Ver not in [None, '']:\r
             Cmd += ["-n", Ver]\r
             if BuildNumber:\r
@@ -419,8 +420,10 @@ class GenFdsGlobalVariable:
     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
+        elif AlignString in ("1M", "2M", "4M", "8M", "16M"):\r
+            return int (AlignString.rstrip('M')) * 1024 * 1024\r
         else:\r
             return int (AlignString)\r
 \r
@@ -428,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
+        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 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
@@ -459,12 +469,12 @@ class GenFdsGlobalVariable:
         Cmd = ["GenFv"]\r
         if BaseAddress not in [None, '']:\r
             Cmd += ["-r", BaseAddress]\r
-        \r
+\r
         if ForceRebase == False:\r
-            Cmd +=["-F", "FALSE"]\r
+            Cmd += ["-F", "FALSE"]\r
         elif ForceRebase == True:\r
-            Cmd +=["-F", "TRUE"]\r
-            \r
+            Cmd += ["-F", "TRUE"]\r
+\r
         if Capsule:\r
             Cmd += ["-c"]\r
         if Dump:\r
@@ -568,7 +578,7 @@ class GenFdsGlobalVariable:
         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
@@ -604,7 +614,7 @@ class GenFdsGlobalVariable:
                 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
@@ -616,7 +626,7 @@ class GenFdsGlobalVariable:
             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
@@ -629,7 +639,7 @@ class GenFdsGlobalVariable:
     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
@@ -640,7 +650,7 @@ class GenFdsGlobalVariable:
     #   @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
@@ -697,10 +707,10 @@ class GenFdsGlobalVariable:
                         \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