]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
BaseTools: refactor and remove un-needed use of .keys() on dictionaries
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFdsGlobalVariable.py
index 04bbc300ceda186a13e9fd8ba5c47188fbe470dc..6a3873940ec01452a2bdcdb8181cb27efcccdeaf 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 - 2018, 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
@@ -67,6 +68,12 @@ class GenFdsGlobalVariable:
     BuildRuleFamily = "MSFT"\r
     ToolChainFamily = "MSFT"\r
     __BuildRuleDatabase = None\r
     BuildRuleFamily = "MSFT"\r
     ToolChainFamily = "MSFT"\r
     __BuildRuleDatabase = None\r
+    GuidToolDefinition = {}\r
+    FfsCmdDict = {}\r
+    SecCmdList = []\r
+    CopyList   = []\r
+    ModuleFile = ''\r
+    EnableGenfdsMultiThread = False\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
@@ -123,7 +130,7 @@ class GenFdsGlobalVariable:
     @staticmethod\r
     def GetBuildRules(Inf, Arch):\r
         if not Arch:\r
     @staticmethod\r
     def GetBuildRules(Inf, Arch):\r
         if not Arch:\r
-            Arch = 'COMMON'\r
+            Arch = DataType.TAB_COMMON\r
 \r
         if not Arch in GenFdsGlobalVariable.OutputDirDict:\r
             return {}\r
 \r
         if not Arch in GenFdsGlobalVariable.OutputDirDict:\r
             return {}\r
@@ -210,7 +217,7 @@ class GenFdsGlobalVariable:
                     FileList.append((File, DataType.TAB_UNKNOWN_FILE))\r
 \r
         for File in Inf.Binaries:\r
                     FileList.append((File, DataType.TAB_UNKNOWN_FILE))\r
 \r
         for File in Inf.Binaries:\r
-            if File.Target in ['COMMON', '*', GenFdsGlobalVariable.TargetName]:\r
+            if File.Target in [DataType.TAB_COMMON, '*', GenFdsGlobalVariable.TargetName]:\r
                 FileList.append((File, File.Type))\r
 \r
         for File, FileType in FileList:\r
                 FileList.append((File, File.Type))\r
 \r
         for File, FileType in FileList:\r
@@ -222,7 +229,7 @@ class GenFdsGlobalVariable:
                 Source = SourceList[Index]\r
                 Index = Index + 1\r
     \r
                 Source = SourceList[Index]\r
                 Index = Index + 1\r
     \r
-                if File.IsBinary and File == Source and Inf.Binaries != None and File in Inf.Binaries:\r
+                if File.IsBinary and File == Source and Inf.Binaries is not None and File in Inf.Binaries:\r
                     # Skip all files that are not binary libraries\r
                     if not Inf.LibraryClass:\r
                         continue            \r
                     # Skip all files that are not binary libraries\r
                     if not Inf.LibraryClass:\r
                         continue            \r
@@ -262,6 +269,10 @@ class GenFdsGlobalVariable:
                 SourceList.extend(Target.Outputs)\r
                 LastTarget = Target\r
                 FileType = DataType.TAB_UNKNOWN_FILE\r
                 SourceList.extend(Target.Outputs)\r
                 LastTarget = Target\r
                 FileType = DataType.TAB_UNKNOWN_FILE\r
+                for Cmd in Target.Commands:\r
+                    if "$(CP)" == Cmd.split()[0]:\r
+                        CpTarget = Cmd.split()[2]\r
+                        TargetList.add(CpTarget)\r
 \r
         return list(TargetList)\r
 \r
 \r
         return list(TargetList)\r
 \r
@@ -273,7 +284,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
@@ -283,15 +294,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
@@ -303,7 +312,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
@@ -312,22 +321,90 @@ 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
 \r
                                        T_CHAR_LF)\r
 \r
         FvAddressFile.close()\r
 \r
+    def SetEnv(FdfParser, WorkSpace, ArchList, GlobalData):\r
+        GenFdsGlobalVariable.ModuleFile = WorkSpace.ModuleFile\r
+        GenFdsGlobalVariable.FdfParser = FdfParser\r
+        GenFdsGlobalVariable.WorkSpace = WorkSpace.Db\r
+        GenFdsGlobalVariable.ArchList = ArchList\r
+        GenFdsGlobalVariable.ToolChainTag = GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]\r
+        GenFdsGlobalVariable.TargetName = GlobalData.gGlobalDefines["TARGET"]\r
+        GenFdsGlobalVariable.ActivePlatform = GlobalData.gActivePlatform\r
+        GenFdsGlobalVariable.EdkSourceDir = GlobalData.gGlobalDefines["EDK_SOURCE"]\r
+        GenFdsGlobalVariable.ConfDir  = GlobalData.gConfDirectory\r
+        GenFdsGlobalVariable.EnableGenfdsMultiThread = GlobalData.gEnableGenfdsMultiThread\r
+        for Arch in ArchList:\r
+            GenFdsGlobalVariable.OutputDirDict[Arch] = os.path.normpath(\r
+                os.path.join(GlobalData.gWorkspace,\r
+                             WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,GlobalData.gGlobalDefines['TARGET'],\r
+                             GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory,\r
+                             GlobalData.gGlobalDefines['TARGET'] +'_' + GlobalData.gGlobalDefines['TOOLCHAIN']))\r
+            GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = os.path.normpath(\r
+                             WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
+                             GlobalData.gGlobalDefines['TARGET'], GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory)\r
+            GenFdsGlobalVariable.PlatformName = WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
+                                                                      GlobalData.gGlobalDefines['TARGET'],\r
+                                                                      GlobalData.gGlobalDefines['TOOLCHAIN']].PlatformName\r
+        GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], 'FV')\r
+        if not os.path.exists(GenFdsGlobalVariable.FvDir):\r
+            os.makedirs(GenFdsGlobalVariable.FvDir)\r
+        GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
+        if not os.path.exists(GenFdsGlobalVariable.FfsDir):\r
+            os.makedirs(GenFdsGlobalVariable.FfsDir)\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
+        #\r
+        # Add [Options]\r
+        #\r
+        FvAddressFile.writelines("[options]" + T_CHAR_LF)\r
+        BsAddress = '0'\r
+        for Arch in ArchList:\r
+            BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
+                                                                   GlobalData.gGlobalDefines['TARGET'],\r
+                                                                   GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].BsBaseAddress\r
+            if BsAddress:\r
+                break\r
+\r
+        FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
+                                 BsAddress + \\r
+                                 T_CHAR_LF)\r
+\r
+        RtAddress = '0'\r
+        for Arch in ArchList:\r
+            if GenFdsGlobalVariable.WorkSpace.BuildObject[\r
+                GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
+                GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress:\r
+                RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[\r
+                    GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
+                    GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress\r
+\r
+        FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
+                                 RtAddress + \\r
+                                 T_CHAR_LF)\r
+\r
+        FvAddressFile.close()\r
+\r
     ## ReplaceWorkspaceMacro()\r
     #\r
     #   @param  String           String that may contain macro\r
     #\r
     def ReplaceWorkspaceMacro(String):\r
     ## ReplaceWorkspaceMacro()\r
     #\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
@@ -343,7 +420,7 @@ class GenFdsGlobalVariable:
         if not os.path.exists(Output):\r
             return True\r
         # always update "Output" if no "Input" given\r
         if not os.path.exists(Output):\r
             return True\r
         # always update "Output" if no "Input" given\r
-        if Input == None or len(Input) == 0:\r
+        if Input is None or len(Input) == 0:\r
             return True\r
 \r
         # if fdf file is changed after the 'Output" is generated, update the 'Output'\r
             return True\r
 \r
         # if fdf file is changed after the 'Output" is generated, update the 'Output'\r
@@ -362,21 +439,23 @@ class GenFdsGlobalVariable:
 \r
     @staticmethod\r
     def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,\r
 \r
     @staticmethod\r
     def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,\r
-                        GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None):\r
+                        GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None, DummyFile=None, IsMakefile=False):\r
         Cmd = ["GenSec"]\r
         if Type not in [None, '']:\r
             Cmd += ["-s", Type]\r
         if CompressionType not in [None, '']:\r
             Cmd += ["-c", CompressionType]\r
         Cmd = ["GenSec"]\r
         if Type not in [None, '']:\r
             Cmd += ["-s", Type]\r
         if CompressionType not in [None, '']:\r
             Cmd += ["-c", CompressionType]\r
-        if Guid != None:\r
+        if Guid is not None:\r
             Cmd += ["-g", Guid]\r
             Cmd += ["-g", Guid]\r
+        if DummyFile is not None:\r
+            Cmd += ["--dummy", DummyFile]\r
         if GuidHdrLen not in [None, '']:\r
             Cmd += ["-l", GuidHdrLen]\r
         if len(GuidAttr) != 0:\r
             #Add each guided attribute\r
             for Attr in GuidAttr:\r
                 Cmd += ["-r", Attr]\r
         if GuidHdrLen not in [None, '']:\r
             Cmd += ["-l", GuidHdrLen]\r
         if len(GuidAttr) != 0:\r
             #Add each guided attribute\r
             for Attr in GuidAttr:\r
                 Cmd += ["-r", Attr]\r
-        if InputAlign != None:\r
+        if InputAlign is not None:\r
             #Section Align is only for dummy section without section type\r
             for SecAlign in InputAlign:\r
                 Cmd += ["--sectionalign", SecAlign]\r
             #Section Align is only for dummy section without section type\r
             for SecAlign in InputAlign:\r
                 Cmd += ["--sectionalign", SecAlign]\r
@@ -384,13 +463,23 @@ 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.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
+            if IsMakefile:\r
+                if Ui == "$(MODULE_NAME)":\r
+                    Cmd += ['-n', Ui]\r
+                else:\r
+                    Cmd += ["-n", '"' + Ui + '"']\r
+                Cmd += ["-o", Output]\r
+                if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                    GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
+            else:\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
+\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
@@ -398,41 +487,55 @@ class GenFdsGlobalVariable:
             Cmd += ["-o", Output]\r
 \r
             SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
             Cmd += ["-o", Output]\r
 \r
             SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
-            if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
-                return\r
-\r
-            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
+            if IsMakefile:\r
+                if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                    GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
+            else:\r
+                if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
+                    return\r
+                GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
         else:\r
             Cmd += ["-o", Output]\r
             Cmd += Input\r
 \r
             SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
         else:\r
             Cmd += ["-o", Output]\r
             Cmd += Input\r
 \r
             SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
-            if GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
+            if IsMakefile:\r
+                if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                    GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
+            elif GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
                 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
                 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
                 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
                 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
-\r
-            if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and\r
-                GenFdsGlobalVariable.LargeFileInFvFlags):\r
-                GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True \r
+                if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and\r
+                    GenFdsGlobalVariable.LargeFileInFvFlags):\r
+                    GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True\r
 \r
     @staticmethod\r
     def GetAlignment (AlignString):\r
 \r
     @staticmethod\r
     def GetAlignment (AlignString):\r
-        if AlignString == None:\r
+        if AlignString is None:\r
             return 0\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
     @staticmethod\r
     def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
         else:\r
             return int (AlignString)\r
 \r
     @staticmethod\r
     def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
-                    SectionAlign=None):\r
+                    SectionAlign=None, MakefilePath=None):\r
         Cmd = ["GenFfs", "-t", Type, "-g", Guid]\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
@@ -443,11 +546,17 @@ class GenFdsGlobalVariable:
 \r
         CommandFile = Output + '.txt'\r
         SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
 \r
         CommandFile = Output + '.txt'\r
         SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
-            return\r
-        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
 \r
 \r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")\r
+        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
+        if MakefilePath:\r
+            if (tuple(Cmd),tuple(GenFdsGlobalVariable.SecCmdList),tuple(GenFdsGlobalVariable.CopyList)) not in GenFdsGlobalVariable.FfsCmdDict:\r
+                GenFdsGlobalVariable.FfsCmdDict[tuple(Cmd), tuple(GenFdsGlobalVariable.SecCmdList), tuple(GenFdsGlobalVariable.CopyList)] = MakefilePath\r
+            GenFdsGlobalVariable.SecCmdList = []\r
+            GenFdsGlobalVariable.CopyList = []\r
+        else:\r
+            if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
+                return\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")\r
 \r
     @staticmethod\r
     def GenerateFirmwareVolume(Output, Input, BaseAddress=None, ForceRebase=None, Capsule=False, Dump=False,\r
 \r
     @staticmethod\r
     def GenerateFirmwareVolume(Output, Input, BaseAddress=None, ForceRebase=None, Capsule=False, Dump=False,\r
@@ -459,12 +568,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
@@ -501,8 +610,8 @@ class GenFdsGlobalVariable:
     @staticmethod\r
     def GenerateFirmwareImage(Output, Input, Type="efi", SubType=None, Zero=False,\r
                               Strip=False, Replace=False, TimeStamp=None, Join=False,\r
     @staticmethod\r
     def GenerateFirmwareImage(Output, Input, Type="efi", SubType=None, Zero=False,\r
                               Strip=False, Replace=False, TimeStamp=None, Join=False,\r
-                              Align=None, Padding=None, Convert=False):\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+                              Align=None, Padding=None, Convert=False, IsMakefile=False):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input) and not IsMakefile:\r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
 \r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
 \r
@@ -529,12 +638,15 @@ class GenFdsGlobalVariable:
             Cmd += ["-m"]\r
         Cmd += ["-o", Output]\r
         Cmd += Input\r
             Cmd += ["-m"]\r
         Cmd += ["-o", Output]\r
         Cmd += Input\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")\r
+        if IsMakefile:\r
+            if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
+        else:\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")\r
 \r
     @staticmethod\r
     def GenerateOptionRom(Output, EfiInput, BinaryInput, Compress=False, ClassCode=None,\r
 \r
     @staticmethod\r
     def GenerateOptionRom(Output, EfiInput, BinaryInput, Compress=False, ClassCode=None,\r
-                        Revision=None, DeviceId=None, VendorId=None):\r
+                        Revision=None, DeviceId=None, VendorId=None, IsMakefile=False):\r
         InputList = []   \r
         Cmd = ["EfiRom"]\r
         if len(EfiInput) > 0:\r
         InputList = []   \r
         Cmd = ["EfiRom"]\r
         if len(EfiInput) > 0:\r
@@ -555,25 +667,29 @@ class GenFdsGlobalVariable:
                 InputList.append (BinFile)\r
 \r
         # Check List\r
                 InputList.append (BinFile)\r
 \r
         # Check List\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, InputList):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, InputList) and not IsMakefile:\r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, InputList))\r
                         \r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, InputList))\r
                         \r
-        if ClassCode != None:\r
+        if ClassCode is not None:\r
             Cmd += ["-l", ClassCode]\r
             Cmd += ["-l", ClassCode]\r
-        if Revision != None:\r
+        if Revision is not None:\r
             Cmd += ["-r", Revision]\r
             Cmd += ["-r", Revision]\r
-        if DeviceId != None:\r
+        if DeviceId is not None:\r
             Cmd += ["-i", DeviceId]\r
             Cmd += ["-i", DeviceId]\r
-        if VendorId != None:\r
+        if VendorId is not None:\r
             Cmd += ["-f", VendorId]\r
 \r
             Cmd += ["-f", VendorId]\r
 \r
-        Cmd += ["-o", Output]    \r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
+        Cmd += ["-o", Output]\r
+        if IsMakefile:\r
+            if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
+        else:\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
 \r
     @staticmethod\r
 \r
     @staticmethod\r
-    def GuidTool(Output, Input, ToolPath, Options='', returnValue=[]):\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+    def GuidTool(Output, Input, ToolPath, Options='', returnValue=[], IsMakefile=False):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input) and not IsMakefile:\r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
 \r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
 \r
@@ -581,8 +697,11 @@ class GenFdsGlobalVariable:
         Cmd += Options.split(' ')\r
         Cmd += ["-o", Output]\r
         Cmd += Input\r
         Cmd += Options.split(' ')\r
         Cmd += ["-o", Output]\r
         Cmd += Input\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)\r
+        if IsMakefile:\r
+            if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
+        else:\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)\r
 \r
     def CallExternalTool (cmd, errorMess, returnValue=[]):\r
 \r
 \r
     def CallExternalTool (cmd, errorMess, returnValue=[]):\r
 \r
@@ -604,19 +723,19 @@ 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
 \r
         except Exception, X:\r
             EdkLogger.error("GenFds", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0]))\r
         (out, error) = PopenObject.communicate()\r
 \r
-        while PopenObject.returncode == None :\r
+        while PopenObject.returncode is None :\r
             PopenObject.wait()\r
         if returnValue != [] and returnValue[0] != 0:\r
             #get command return value\r
             returnValue[0] = PopenObject.returncode\r
             return\r
         if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:\r
             PopenObject.wait()\r
         if returnValue != [] and returnValue[0] != 0:\r
             #get command return value\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
@@ -629,7 +748,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
@@ -640,8 +759,8 @@ 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
-        if Str == None :\r
+    def MacroExtend (Str, MacroDict={}, Arch=DataType.TAB_COMMON):\r
+        if Str is None :\r
             return None\r
 \r
         Dict = {'$(WORKSPACE)'   : GenFdsGlobalVariable.WorkSpaceDir,\r
             return None\r
 \r
         Dict = {'$(WORKSPACE)'   : GenFdsGlobalVariable.WorkSpaceDir,\r
@@ -652,15 +771,15 @@ class GenFdsGlobalVariable:
                 '$(SPACE)' : ' '\r
                }\r
         OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
                 '$(SPACE)' : ' '\r
                }\r
         OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
-        if Arch != 'COMMON' and Arch in GenFdsGlobalVariable.ArchList:\r
+        if Arch != DataType.TAB_COMMON and Arch in GenFdsGlobalVariable.ArchList:\r
             OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[Arch]\r
 \r
         Dict['$(OUTPUT_DIRECTORY)'] = OutputDir\r
 \r
             OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[Arch]\r
 \r
         Dict['$(OUTPUT_DIRECTORY)'] = OutputDir\r
 \r
-        if MacroDict != None  and len (MacroDict) != 0:\r
+        if MacroDict is not None  and len (MacroDict) != 0:\r
             Dict.update(MacroDict)\r
 \r
             Dict.update(MacroDict)\r
 \r
-        for key in Dict.keys():\r
+        for key in Dict:\r
             if Str.find(key) >= 0 :\r
                 Str = Str.replace (key, Dict[key])\r
 \r
             if Str.find(key) >= 0 :\r
                 Str = Str.replace (key, Dict[key])\r
 \r
@@ -677,7 +796,7 @@ class GenFdsGlobalVariable:
     #   @param  PcdPattern           pattern that labels a PCD.\r
     #\r
     def GetPcdValue (PcdPattern):\r
     #   @param  PcdPattern           pattern that labels a PCD.\r
     #\r
     def GetPcdValue (PcdPattern):\r
-        if PcdPattern == None :\r
+        if PcdPattern is None :\r
             return None\r
         PcdPair = PcdPattern.lstrip('PCD(').rstrip(')').strip().split('.')\r
         TokenSpace = PcdPair[0]\r
             return None\r
         PcdPair = PcdPattern.lstrip('PCD(').rstrip(')').strip().split('.')\r
         TokenSpace = PcdPair[0]\r
@@ -697,10 +816,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
@@ -717,6 +836,7 @@ class GenFdsGlobalVariable:
         return PcdValue\r
 \r
     SetDir = staticmethod(SetDir)\r
         return PcdValue\r
 \r
     SetDir = staticmethod(SetDir)\r
+    SetEnv = staticmethod(SetEnv)\r
     ReplaceWorkspaceMacro = staticmethod(ReplaceWorkspaceMacro)\r
     CallExternalTool = staticmethod(CallExternalTool)\r
     VerboseLogger = staticmethod(VerboseLogger)\r
     ReplaceWorkspaceMacro = staticmethod(ReplaceWorkspaceMacro)\r
     CallExternalTool = staticmethod(CallExternalTool)\r
     VerboseLogger = staticmethod(VerboseLogger)\r