]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFds.py
BaseTools: Use absolute import in GenFds
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFds.py
index 4a5d6f476abdd2bdc3cffaee86f4c790f812c603..c0b60b9b3c1fdfb0139d1a583dedecf58ec4370e 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # generate flash image\r
 #\r
 ## @file\r
 # generate flash image\r
 #\r
-#  Copyright (c) 2007 - 2017, 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
 ##\r
 # Import Modules\r
 #\r
 ##\r
 # Import Modules\r
 #\r
+from __future__ import print_function\r
+from __future__ import absolute_import\r
 from optparse import OptionParser\r
 import sys\r
 import Common.LongFilePathOs as os\r
 import linecache\r
 from optparse import OptionParser\r
 import sys\r
 import Common.LongFilePathOs as os\r
 import linecache\r
-import FdfParser\r
+from . import FdfParser\r
 import Common.BuildToolError as BuildToolError\r
 import Common.BuildToolError as BuildToolError\r
-from GenFdsGlobalVariable import GenFdsGlobalVariable\r
+from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
 from Workspace.WorkspaceDatabase import WorkspaceDatabase\r
 from Workspace.BuildClassObject import PcdClassObject\r
 from Workspace.WorkspaceDatabase import WorkspaceDatabase\r
 from Workspace.BuildClassObject import PcdClassObject\r
-from Workspace.BuildClassObject import ModuleBuildClassObject\r
-import RuleComplexFile\r
-from EfiSection import EfiSection\r
-import StringIO\r
+from . import RuleComplexFile\r
+from .EfiSection import EfiSection\r
+from io import BytesIO\r
 import Common.TargetTxtClassObject as TargetTxtClassObject\r
 import Common.ToolDefClassObject as ToolDefClassObject\r
 from Common.DataType import *\r
 import Common.GlobalData as GlobalData\r
 from Common import EdkLogger\r
 import Common.TargetTxtClassObject as TargetTxtClassObject\r
 import Common.ToolDefClassObject as ToolDefClassObject\r
 from Common.DataType import *\r
 import Common.GlobalData as GlobalData\r
 from Common import EdkLogger\r
-from Common.String import *\r
+from Common.StringUtils import *\r
 from Common.Misc import DirCache, PathClass\r
 from Common.Misc import SaveFileOnChange\r
 from Common.Misc import ClearDuplicatedInf\r
 from Common.Misc import GuidStructureStringToGuidString\r
 from Common.Misc import DirCache, PathClass\r
 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.Misc import BuildOptionPcdValueFormat\r
 from Common.BuildVersion import gBUILD_VERSION\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 from Common.BuildVersion import gBUILD_VERSION\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
-import FfsFileStatement\r
+from . import FfsFileStatement\r
 import glob\r
 from struct import unpack\r
 \r
 ## Version and Copyright\r
 versionNumber = "1.0" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + versionNumber\r
 import glob\r
 from struct import unpack\r
 \r
 ## Version and Copyright\r
 versionNumber = "1.0" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + versionNumber\r
-__copyright__ = "Copyright (c) 2007 - 2017, Intel Corporation  All rights reserved."\r
+__copyright__ = "Copyright (c) 2007 - 2018, Intel Corporation  All rights reserved."\r
 \r
 ## Tool entrance method\r
 #\r
 \r
 ## Tool entrance method\r
 #\r
@@ -71,22 +70,22 @@ def main():
 \r
     EdkLogger.Initialize()\r
     try:\r
 \r
     EdkLogger.Initialize()\r
     try:\r
-        if Options.verbose != None:\r
+        if Options.verbose is not None:\r
             EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
             GenFdsGlobalVariable.VerboseMode = True\r
             EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
             GenFdsGlobalVariable.VerboseMode = True\r
-            \r
-        if Options.FixedAddress != None:\r
+\r
+        if Options.FixedAddress is not None:\r
             GenFdsGlobalVariable.FixedLoadAddress = True\r
             GenFdsGlobalVariable.FixedLoadAddress = True\r
-            \r
-        if Options.quiet != None:\r
+\r
+        if Options.quiet is not None:\r
             EdkLogger.SetLevel(EdkLogger.QUIET)\r
             EdkLogger.SetLevel(EdkLogger.QUIET)\r
-        if Options.debug != None:\r
+        if Options.debug is not None:\r
             EdkLogger.SetLevel(Options.debug + 1)\r
             GenFdsGlobalVariable.DebugLevel = Options.debug\r
         else:\r
             EdkLogger.SetLevel(EdkLogger.INFO)\r
 \r
             EdkLogger.SetLevel(Options.debug + 1)\r
             GenFdsGlobalVariable.DebugLevel = Options.debug\r
         else:\r
             EdkLogger.SetLevel(EdkLogger.INFO)\r
 \r
-        if (Options.Workspace == None):\r
+        if (Options.Workspace is None):\r
             EdkLogger.error("GenFds", OPTION_MISSING, "WORKSPACE not defined",\r
                             ExtraData="Please use '-w' switch to pass it or set the WORKSPACE environment variable.")\r
         elif not os.path.exists(Options.Workspace):\r
             EdkLogger.error("GenFds", OPTION_MISSING, "WORKSPACE not defined",\r
                             ExtraData="Please use '-w' switch to pass it or set the WORKSPACE environment variable.")\r
         elif not os.path.exists(Options.Workspace):\r
@@ -95,14 +94,14 @@ def main():
         else:\r
             Workspace = os.path.normcase(Options.Workspace)\r
             GenFdsGlobalVariable.WorkSpaceDir = Workspace\r
         else:\r
             Workspace = os.path.normcase(Options.Workspace)\r
             GenFdsGlobalVariable.WorkSpaceDir = Workspace\r
-            if 'EDK_SOURCE' in os.environ.keys():\r
+            if 'EDK_SOURCE' in os.environ:\r
                 GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE'])\r
             if (Options.debug):\r
                 GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace)\r
             if Options.GenfdsMultiThread:\r
                 GenFdsGlobalVariable.EnableGenfdsMultiThread = True\r
         os.chdir(GenFdsGlobalVariable.WorkSpaceDir)\r
                 GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE'])\r
             if (Options.debug):\r
                 GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace)\r
             if Options.GenfdsMultiThread:\r
                 GenFdsGlobalVariable.EnableGenfdsMultiThread = True\r
         os.chdir(GenFdsGlobalVariable.WorkSpaceDir)\r
-        \r
+\r
         # set multiple workspace\r
         PackagesPath = os.getenv("PACKAGES_PATH")\r
         mws.setWs(GenFdsGlobalVariable.WorkSpaceDir, PackagesPath)\r
         # set multiple workspace\r
         PackagesPath = os.getenv("PACKAGES_PATH")\r
         mws.setWs(GenFdsGlobalVariable.WorkSpaceDir, PackagesPath)\r
@@ -144,6 +143,7 @@ def main():
         else:\r
             EdkLogger.error("GenFds", OPTION_MISSING, "Missing active platform")\r
 \r
         else:\r
             EdkLogger.error("GenFds", OPTION_MISSING, "Missing active platform")\r
 \r
+        GlobalData.BuildOptionPcd     = Options.OptionPcd if Options.OptionPcd else {}\r
         GenFdsGlobalVariable.ActivePlatform = PathClass(NormPath(ActivePlatform))\r
 \r
         if (Options.ConfDirectory):\r
         GenFdsGlobalVariable.ActivePlatform = PathClass(NormPath(ActivePlatform))\r
 \r
         if (Options.ConfDirectory):\r
@@ -158,12 +158,14 @@ 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
                 # 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
-            if "CONF_PATH" in os.environ.keys():\r
+            if "CONF_PATH" in os.environ:\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
                 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
+        if not GlobalData.gConfDirectory:\r
+            GlobalData.gConfDirectory = GenFdsGlobalVariable.ConfDir\r
         BuildConfigurationFile = os.path.normpath(os.path.join(ConfDirectoryPath, "target.txt"))\r
         if os.path.isfile(BuildConfigurationFile) == True:\r
             TargetTxt = TargetTxtClassObject.TargetTxtClassObject()\r
         BuildConfigurationFile = os.path.normpath(os.path.join(ConfDirectoryPath, "target.txt"))\r
         if os.path.isfile(BuildConfigurationFile) == True:\r
             TargetTxt = TargetTxtClassObject.TargetTxtClassObject()\r
@@ -178,7 +180,7 @@ def main():
             # 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 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
+                if ToolChainList is 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
                     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
@@ -216,18 +218,18 @@ def main():
         os.environ["WORKSPACE"] = Workspace\r
 \r
         # Use the -t and -b option as gGlobalDefines's TOOLCHAIN and TARGET if they are not defined\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
+        if "TARGET" not in GlobalData.gGlobalDefines:\r
             GlobalData.gGlobalDefines["TARGET"] = GenFdsGlobalVariable.TargetName\r
             GlobalData.gGlobalDefines["TARGET"] = GenFdsGlobalVariable.TargetName\r
-        if "TOOLCHAIN" not in GlobalData.gGlobalDefines.keys():\r
+        if "TOOLCHAIN" not in GlobalData.gGlobalDefines:\r
             GlobalData.gGlobalDefines["TOOLCHAIN"] = GenFdsGlobalVariable.ToolChainTag\r
             GlobalData.gGlobalDefines["TOOLCHAIN"] = GenFdsGlobalVariable.ToolChainTag\r
-        if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines.keys():\r
+        if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines:\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
         BuildWorkSpace.InitDatabase()\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
         BuildWorkSpace.InitDatabase()\r
-        \r
+\r
         #\r
         # Get files real name in workspace dir\r
         #\r
         #\r
         # Get files real name in workspace dir\r
         #\r
@@ -238,12 +240,12 @@ def main():
             ArchList = Options.archList.split(',')\r
         else:\r
 #            EdkLogger.error("GenFds", OPTION_MISSING, "Missing build ARCH")\r
             ArchList = Options.archList.split(',')\r
         else:\r
 #            EdkLogger.error("GenFds", OPTION_MISSING, "Missing build ARCH")\r
-            ArchList = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON', Options.BuildTarget, Options.ToolChain].SupArchList\r
+            ArchList = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, TAB_COMMON, Options.BuildTarget, Options.ToolChain].SupArchList\r
 \r
 \r
-        TargetArchList = set(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON', Options.BuildTarget, Options.ToolChain].SupArchList) & set(ArchList)\r
+        TargetArchList = set(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, TAB_COMMON, Options.BuildTarget, Options.ToolChain].SupArchList) & set(ArchList)\r
         if len(TargetArchList) == 0:\r
         if len(TargetArchList) == 0:\r
-            EdkLogger.error("GenFds", GENFDS_ERROR, "Target ARCH %s not in platform supported ARCH %s" % (str(ArchList), str(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON'].SupArchList)))\r
-        \r
+            EdkLogger.error("GenFds", GENFDS_ERROR, "Target ARCH %s not in platform supported ARCH %s" % (str(ArchList), str(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, TAB_COMMON].SupArchList)))\r
+\r
         for Arch in ArchList:\r
             GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, Options.BuildTarget, Options.ToolChain].OutputDirectory)\r
             GenFdsGlobalVariable.PlatformName = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, Options.BuildTarget, Options.ToolChain].PlatformName\r
         for Arch in ArchList:\r
             GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, Options.BuildTarget, Options.ToolChain].OutputDirectory)\r
             GenFdsGlobalVariable.PlatformName = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, Options.BuildTarget, Options.ToolChain].PlatformName\r
@@ -278,33 +280,31 @@ def main():
             EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Cycle Reference Detected in FDF file")\r
 \r
         if (Options.uiFdName) :\r
             EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Cycle Reference Detected in FDF file")\r
 \r
         if (Options.uiFdName) :\r
-            if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict.keys():\r
+            if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict:\r
                 GenFds.OnlyGenerateThisFd = Options.uiFdName\r
             else:\r
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
                                 "No such an FD in FDF file: %s" % Options.uiFdName)\r
 \r
         if (Options.uiFvName) :\r
                 GenFds.OnlyGenerateThisFd = Options.uiFdName\r
             else:\r
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
                                 "No such an FD in FDF file: %s" % Options.uiFdName)\r
 \r
         if (Options.uiFvName) :\r
-            if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict.keys():\r
+            if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict:\r
                 GenFds.OnlyGenerateThisFv = Options.uiFvName\r
             else:\r
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
                                 "No such an FV in FDF file: %s" % Options.uiFvName)\r
 \r
         if (Options.uiCapName) :\r
                 GenFds.OnlyGenerateThisFv = Options.uiFvName\r
             else:\r
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
                                 "No such an FV in FDF file: %s" % Options.uiFvName)\r
 \r
         if (Options.uiCapName) :\r
-            if Options.uiCapName.upper() in FdfParserObj.Profile.CapsuleDict.keys():\r
+            if Options.uiCapName.upper() in FdfParserObj.Profile.CapsuleDict:\r
                 GenFds.OnlyGenerateThisCap = Options.uiCapName\r
             else:\r
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
                                 "No such a Capsule in FDF file: %s" % Options.uiCapName)\r
 \r
         GenFdsGlobalVariable.WorkSpace = BuildWorkSpace\r
                 GenFds.OnlyGenerateThisCap = Options.uiCapName\r
             else:\r
                 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
+        if ArchList is not None:\r
             GenFdsGlobalVariable.ArchList = ArchList\r
 \r
             GenFdsGlobalVariable.ArchList = ArchList\r
 \r
-        if Options.OptionPcd:\r
-            GlobalData.BuildOptionPcd = Options.OptionPcd\r
-            CheckBuildOptionPcd()\r
+        # Dsc Build Data will handle Pcd Settings from CommandLine.\r
 \r
         """Modify images from build output if the feature of loading driver at fixed address is on."""\r
         if GenFdsGlobalVariable.FixedLoadAddress:\r
 \r
         """Modify images from build output if the feature of loading driver at fixed address is on."""\r
         if GenFdsGlobalVariable.FixedLoadAddress:\r
@@ -317,7 +317,7 @@ def main():
                 for Fd in FdfParserObj.Profile.FdDict:\r
                     FdObj = FdfParserObj.Profile.FdDict[Fd]\r
                     for RegionObj in FdObj.RegionList:\r
                 for Fd in FdfParserObj.Profile.FdDict:\r
                     FdObj = FdfParserObj.Profile.FdDict[Fd]\r
                     for RegionObj in FdObj.RegionList:\r
-                        if RegionObj.RegionType != 'FV':\r
+                        if RegionObj.RegionType != BINARY_FILE_TYPE_FV:\r
                             continue\r
                         for RegionData in RegionObj.RegionDataList:\r
                             if FvObj.UiFvName.upper() == RegionData.upper():\r
                             continue\r
                         for RegionData in RegionObj.RegionDataList:\r
                             if FvObj.UiFvName.upper() == RegionData.upper():\r
@@ -337,11 +337,11 @@ def main():
         """Display FV space info."""\r
         GenFds.DisplayFvSpaceInfo(FdfParserObj)\r
 \r
         """Display FV space info."""\r
         GenFds.DisplayFvSpaceInfo(FdfParserObj)\r
 \r
-    except FdfParser.Warning, X:\r
+    except FdfParser.Warning as X:\r
         EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError=False)\r
         ReturnCode = FORMAT_INVALID\r
         EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError=False)\r
         ReturnCode = FORMAT_INVALID\r
-    except FatalError, X:\r
-        if Options.debug != None:\r
+    except FatalError as X:\r
+        if Options.debug is not None:\r
             import traceback\r
             EdkLogger.quiet(traceback.format_exc())\r
         ReturnCode = X.args[0]\r
             import traceback\r
             EdkLogger.quiet(traceback.format_exc())\r
         ReturnCode = X.args[0]\r
@@ -368,53 +368,6 @@ def SingleCheckCallback(option, opt_str, value, parser):
     else:\r
         parser.error("Option %s only allows one instance in command line!" % option)\r
 \r
     else:\r
         parser.error("Option %s only allows one instance in command line!" % option)\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
-\r
 ## FindExtendTool()\r
 #\r
 #  Find location of tools to process data\r
 ## FindExtendTool()\r
 #\r
 #  Find location of tools to process data\r
@@ -426,7 +379,7 @@ def CheckBuildOptionPcd():
 def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
     ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
     # if user not specify filter, try to deduce it from global data.\r
 def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
     ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
     # if user not specify filter, try to deduce it from global data.\r
-    if KeyStringList == None or KeyStringList == []:\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
         Target = GenFdsGlobalVariable.TargetName\r
         ToolChain = GenFdsGlobalVariable.ToolChainTag\r
         if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:\r
@@ -437,7 +390,7 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
                 KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)\r
 \r
     if GenFdsGlobalVariable.GuidToolDefinition:\r
                 KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)\r
 \r
     if GenFdsGlobalVariable.GuidToolDefinition:\r
-        if NameGuid in GenFdsGlobalVariable.GuidToolDefinition.keys():\r
+        if NameGuid in GenFdsGlobalVariable.GuidToolDefinition:\r
             return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]\r
 \r
     ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
             return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]\r
 \r
     ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
@@ -447,19 +400,19 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
     ToolOptionKey = None\r
     KeyList = None\r
     for ToolDef in ToolDefinition.items():\r
     ToolOptionKey = None\r
     KeyList = None\r
     for ToolDef in ToolDefinition.items():\r
-        if NameGuid == ToolDef[1]:\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
             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
+            if Key in KeyStringList and KeyList[4] == 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
                 ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
                 ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
                 ToolPath = ToolDefinition.get(ToolPathKey)\r
                 ToolOption = ToolDefinition.get(ToolOptionKey)\r
-                if ToolPathTmp == None:\r
+                if ToolPathTmp is None:\r
                     ToolPathTmp = ToolPath\r
                 else:\r
                     if ToolPathTmp != ToolPath:\r
                     ToolPathTmp = ToolPath\r
                 else:\r
                     if ToolPathTmp != ToolPath:\r
@@ -477,7 +430,7 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
         if BuildOption:\r
             ToolList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH]\r
             for Index in range(2, -1, -1):\r
         if BuildOption:\r
             ToolList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH]\r
             for Index in range(2, -1, -1):\r
-                for Key in dict(BuildOption):\r
+                for Key in list(BuildOption.keys()):\r
                     List = Key.split('_')\r
                     if List[Index] == '*':\r
                         for String in ToolDb[ToolList[Index]]:\r
                     List = Key.split('_')\r
                     if List[Index] == '*':\r
                         for String in ToolDb[ToolList[Index]]:\r
@@ -496,13 +449,13 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
                 if NameGuid == BuildOption[Op]:\r
                     KeyList = Op.split('_')\r
                     Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]\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] == 'GUID':\r
+                    if Key in KeyStringList and KeyList[4] == TAB_GUID:\r
                         ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
                         ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
                         ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
                         ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
-        if ToolPathKey in BuildOption.keys():\r
-            ToolPathTmp = BuildOption.get(ToolPathKey)\r
-        if ToolOptionKey in BuildOption.keys():\r
-            ToolOption = BuildOption.get(ToolOptionKey)\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
 \r
     GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
     return ToolPathTmp, ToolOption\r
@@ -571,63 +524,56 @@ class GenFds :
         GenFdsGlobalVariable.SetDir ('', FdfParser, WorkSpace, ArchList)\r
 \r
         GenFdsGlobalVariable.VerboseLogger(" Generate all Fd images and their required FV and Capsule images!")\r
         GenFdsGlobalVariable.SetDir ('', FdfParser, WorkSpace, ArchList)\r
 \r
         GenFdsGlobalVariable.VerboseLogger(" Generate all Fd images and their required FV and Capsule images!")\r
-        if GenFds.OnlyGenerateThisCap != None and GenFds.OnlyGenerateThisCap.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys():\r
-            CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.get(GenFds.OnlyGenerateThisCap.upper())\r
-            if CapsuleObj != None:\r
+        if GenFds.OnlyGenerateThisCap is not None and GenFds.OnlyGenerateThisCap.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict:\r
+            CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[GenFds.OnlyGenerateThisCap.upper()]\r
+            if CapsuleObj is not None:\r
                 CapsuleObj.GenCapsule()\r
                 return\r
 \r
                 CapsuleObj.GenCapsule()\r
                 return\r
 \r
-        if GenFds.OnlyGenerateThisFd != None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
-            FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(GenFds.OnlyGenerateThisFd.upper())\r
-            if FdObj != None:\r
+        if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict:\r
+            FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()]\r
+            if FdObj is not None:\r
                 FdObj.GenFd()\r
                 return\r
                 FdObj.GenFd()\r
                 return\r
-        elif GenFds.OnlyGenerateThisFd == None and GenFds.OnlyGenerateThisFv == None:\r
-            for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
-                FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]\r
+        elif GenFds.OnlyGenerateThisFd is None and GenFds.OnlyGenerateThisFv is None:\r
+            for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r
                 FdObj.GenFd()\r
 \r
         GenFdsGlobalVariable.VerboseLogger("\n Generate other FV images! ")\r
                 FdObj.GenFd()\r
 \r
         GenFdsGlobalVariable.VerboseLogger("\n Generate other FV images! ")\r
-        if GenFds.OnlyGenerateThisFv != None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
-            FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(GenFds.OnlyGenerateThisFv.upper())\r
-            if FvObj != None:\r
-                Buffer = StringIO.StringIO()\r
+        if GenFds.OnlyGenerateThisFv is not None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
+            FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[GenFds.OnlyGenerateThisFv.upper()]\r
+            if FvObj is not None:\r
+                Buffer = BytesIO()\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
                 return\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
                 return\r
-        elif GenFds.OnlyGenerateThisFv == None:\r
-            for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
-                Buffer = StringIO.StringIO('')\r
-                FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName]\r
+        elif GenFds.OnlyGenerateThisFv is None:\r
+            for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():\r
+                Buffer = BytesIO('')\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
-        \r
-        if GenFds.OnlyGenerateThisFv == None and GenFds.OnlyGenerateThisFd == None and GenFds.OnlyGenerateThisCap == None:\r
+\r
+        if GenFds.OnlyGenerateThisFv is None and GenFds.OnlyGenerateThisFd is None and GenFds.OnlyGenerateThisCap is None:\r
             if GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict != {}:\r
                 GenFdsGlobalVariable.VerboseLogger("\n Generate other Capsule images!")\r
             if GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict != {}:\r
                 GenFdsGlobalVariable.VerboseLogger("\n Generate other Capsule images!")\r
-                for CapsuleName in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys():\r
-                    CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[CapsuleName]\r
+                for CapsuleObj in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.values():\r
                     CapsuleObj.GenCapsule()\r
 \r
             if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}:\r
                 GenFdsGlobalVariable.VerboseLogger("\n Generate all Option ROM!")\r
                     CapsuleObj.GenCapsule()\r
 \r
             if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}:\r
                 GenFdsGlobalVariable.VerboseLogger("\n Generate all Option ROM!")\r
-                for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys():\r
-                    OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName]\r
+                for OptRomObj in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.values():\r
                     OptRomObj.AddToBuffer(None)\r
     @staticmethod\r
     def GenFfsMakefile(OutputDir, FdfParser, WorkSpace, ArchList, GlobalData):\r
         GenFdsGlobalVariable.SetEnv(FdfParser, WorkSpace, ArchList, GlobalData)\r
                     OptRomObj.AddToBuffer(None)\r
     @staticmethod\r
     def GenFfsMakefile(OutputDir, FdfParser, WorkSpace, ArchList, GlobalData):\r
         GenFdsGlobalVariable.SetEnv(FdfParser, WorkSpace, ArchList, GlobalData)\r
-        for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
-            FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]\r
+        for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r
             FdObj.GenFd(Flag=True)\r
 \r
             FdObj.GenFd(Flag=True)\r
 \r
-        for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
-            FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName]\r
+        for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():\r
             FvObj.AddToBuffer(Buffer=None, Flag=True)\r
 \r
         if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}:\r
             FvObj.AddToBuffer(Buffer=None, Flag=True)\r
 \r
         if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}:\r
-            for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys():\r
-                OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName]\r
+            for OptRomObj in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.values():\r
                 OptRomObj.AddToBuffer(Buffer=None, Flag=True)\r
 \r
         return GenFdsGlobalVariable.FfsCmdDict\r
                 OptRomObj.AddToBuffer(Buffer=None, Flag=True)\r
 \r
         return GenFdsGlobalVariable.FfsCmdDict\r
@@ -640,14 +586,14 @@ class GenFds :
     def GetFvBlockSize(FvObj):\r
         DefaultBlockSize = 0x1\r
         FdObj = None\r
     def GetFvBlockSize(FvObj):\r
         DefaultBlockSize = 0x1\r
         FdObj = None\r
-        if GenFds.OnlyGenerateThisFd != None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
+        if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict:\r
             FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()]\r
             FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()]\r
-        if FdObj == None:\r
+        if FdObj is None:\r
             for ElementFd in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r
                 for ElementRegion in ElementFd.RegionList:\r
             for ElementFd in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r
                 for ElementRegion in ElementFd.RegionList:\r
-                    if ElementRegion.RegionType == 'FV':\r
+                    if ElementRegion.RegionType == BINARY_FILE_TYPE_FV:\r
                         for ElementRegionData in ElementRegion.RegionDataList:\r
                         for ElementRegionData in ElementRegion.RegionDataList:\r
-                            if ElementRegionData != None and ElementRegionData.upper() == FvObj.UiFvName:\r
+                            if ElementRegionData is not None and ElementRegionData.upper() == FvObj.UiFvName:\r
                                 if FvObj.BlockSizeList != []:\r
                                     return FvObj.BlockSizeList[0][0]\r
                                 else:\r
                                 if FvObj.BlockSizeList != []:\r
                                     return FvObj.BlockSizeList[0][0]\r
                                 else:\r
@@ -657,9 +603,9 @@ class GenFds :
             return DefaultBlockSize\r
         else:\r
             for ElementRegion in FdObj.RegionList:\r
             return DefaultBlockSize\r
         else:\r
             for ElementRegion in FdObj.RegionList:\r
-                    if ElementRegion.RegionType == 'FV':\r
+                    if ElementRegion.RegionType == BINARY_FILE_TYPE_FV:\r
                         for ElementRegionData in ElementRegion.RegionDataList:\r
                         for ElementRegionData in ElementRegion.RegionDataList:\r
-                            if ElementRegionData != None and ElementRegionData.upper() == FvObj.UiFvName:\r
+                            if ElementRegionData is not None and ElementRegionData.upper() == FvObj.UiFvName:\r
                                 if FvObj.BlockSizeList != []:\r
                                     return FvObj.BlockSizeList[0][0]\r
                                 else:\r
                                 if FvObj.BlockSizeList != []:\r
                                     return FvObj.BlockSizeList[0][0]\r
                                 else:\r
@@ -672,7 +618,7 @@ class GenFds :
     #   @retval None\r
     #\r
     def DisplayFvSpaceInfo(FdfParser):\r
     #   @retval None\r
     #\r
     def DisplayFvSpaceInfo(FdfParser):\r
-        \r
+\r
         FvSpaceInfoList = []\r
         MaxFvNameLength = 0\r
         for FvName in FdfParser.Profile.FvDict:\r
         FvSpaceInfoList = []\r
         MaxFvNameLength = 0\r
         for FvName in FdfParser.Profile.FvDict:\r
@@ -699,10 +645,10 @@ class GenFds :
                         if NameValue[0].strip() == 'EFI_FV_SPACE_SIZE':\r
                             FreeFound = True\r
                             Free = NameValue[1].strip()\r
                         if NameValue[0].strip() == 'EFI_FV_SPACE_SIZE':\r
                             FreeFound = True\r
                             Free = NameValue[1].strip()\r
-                \r
+\r
                 if TotalFound and UsedFound and FreeFound:\r
                     FvSpaceInfoList.append((FvName, Total, Used, Free))\r
                 if TotalFound and UsedFound and FreeFound:\r
                     FvSpaceInfoList.append((FvName, Total, Used, Free))\r
-                \r
+\r
         GenFdsGlobalVariable.InfLogger('\nFV Space Information')\r
         for FvSpaceInfo in FvSpaceInfoList:\r
             Name = FvSpaceInfo[0]\r
         GenFdsGlobalVariable.InfLogger('\nFV Space Information')\r
         for FvSpaceInfo in FvSpaceInfoList:\r
             Name = FvSpaceInfo[0]\r
@@ -723,33 +669,33 @@ class GenFds :
     #   @retval None\r
     #\r
     def PreprocessImage(BuildDb, DscFile):\r
     #   @retval None\r
     #\r
     def PreprocessImage(BuildDb, DscFile):\r
-        PcdDict = BuildDb.BuildObject[DscFile, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].Pcds\r
+        PcdDict = BuildDb.BuildObject[DscFile, TAB_COMMON, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].Pcds\r
         PcdValue = ''\r
         for Key in PcdDict:\r
             PcdObj = PcdDict[Key]\r
             if PcdObj.TokenCName == 'PcdBsBaseAddress':\r
                 PcdValue = PcdObj.DefaultValue\r
                 break\r
         PcdValue = ''\r
         for Key in PcdDict:\r
             PcdObj = PcdDict[Key]\r
             if PcdObj.TokenCName == 'PcdBsBaseAddress':\r
                 PcdValue = PcdObj.DefaultValue\r
                 break\r
-        \r
+\r
         if PcdValue == '':\r
             return\r
         if PcdValue == '':\r
             return\r
-        \r
+\r
         Int64PcdValue = long(PcdValue, 0)\r
         Int64PcdValue = long(PcdValue, 0)\r
-        if Int64PcdValue == 0 or Int64PcdValue < -1:    \r
+        if Int64PcdValue == 0 or Int64PcdValue < -1:\r
             return\r
             return\r
-                \r
+\r
         TopAddress = 0\r
         if Int64PcdValue > 0:\r
             TopAddress = Int64PcdValue\r
         TopAddress = 0\r
         if Int64PcdValue > 0:\r
             TopAddress = Int64PcdValue\r
-            \r
-        ModuleDict = BuildDb.BuildObject[DscFile, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].Modules\r
+\r
+        ModuleDict = BuildDb.BuildObject[DscFile, TAB_COMMON, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].Modules\r
         for Key in ModuleDict:\r
         for Key in ModuleDict:\r
-            ModuleObj = BuildDb.BuildObject[Key, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
-            print ModuleObj.BaseName + ' ' + ModuleObj.ModuleType\r
+            ModuleObj = BuildDb.BuildObject[Key, TAB_COMMON, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+            print(ModuleObj.BaseName + ' ' + ModuleObj.ModuleType)\r
 \r
     def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):\r
         GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")\r
 \r
     def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):\r
         GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")\r
-        GuidXRefFile = StringIO.StringIO('')\r
+        GuidXRefFile = BytesIO('')\r
         GuidDict = {}\r
         ModuleList = []\r
         FileGuidList = []\r
         GuidDict = {}\r
         ModuleList = []\r
         FileGuidList = []\r
@@ -817,7 +763,7 @@ class GenFds :
                                     length = F.tell()\r
                                     F.seek(4)\r
                                     TmpStr = unpack('%dh' % ((length - 4) / 2), F.read())\r
                                     length = F.tell()\r
                                     F.seek(4)\r
                                     TmpStr = unpack('%dh' % ((length - 4) / 2), F.read())\r
-                                    Name = ''.join([chr(c) for c in TmpStr[:-1]])\r
+                                    Name = ''.join(chr(c) for c in TmpStr[:-1])\r
                         else:\r
                             FileList = []\r
                             if 'fv.sec.txt' in MatchDict:\r
                         else:\r
                             FileList = []\r
                             if 'fv.sec.txt' in MatchDict:\r
@@ -840,7 +786,7 @@ class GenFds :
                         if not Name:\r
                             continue\r
 \r
                         if not Name:\r
                             continue\r
 \r
-                        Name = ' '.join(Name) if type(Name) == type([]) else Name\r
+                        Name = ' '.join(Name) if isinstance(Name, type([])) else Name\r
                         GuidXRefFile.write("%s %s\n" %(FileStatementGuid, Name))\r
 \r
        # Append GUIDs, Protocols, and PPIs to the Xref file\r
                         GuidXRefFile.write("%s %s\n" %(FileStatementGuid, Name))\r
 \r
        # Append GUIDs, Protocols, and PPIs to the Xref file\r