]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
Sync BaseTools Branch (version r2323) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index 9705097606b8ae4836ce255d9e85735335d433a2..9502bf3364442a5e3454d964013b95fd1367afe6 100644 (file)
@@ -1,9 +1,9 @@
 ## @file\r
 # build a platform or a module\r
 #\r
-#  Copyright (c) 2007 - 2010, Intel Corporation\r
+#  Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
 #\r
-#  All rights reserved. This program and the accompanying materials\r
+#  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
 #  http://opensource.org/licenses/bsd-license.php\r
@@ -23,6 +23,7 @@ import glob
 import time\r
 import platform\r
 import traceback\r
+import encodings.ascii \r
 \r
 from struct import *\r
 from threading import *\r
@@ -33,6 +34,7 @@ from Common import Misc as Utils
 from Common.TargetTxtClassObject import *\r
 from Common.ToolDefClassObject import *\r
 from Common.DataType import *\r
+from Common.BuildVersion import gBUILD_VERSION\r
 from AutoGen.AutoGen import *\r
 from Common.BuildToolError import *\r
 from Workspace.WorkspaceDatabase import *\r
@@ -45,7 +47,7 @@ import Common.EdkLogger
 import Common.GlobalData as GlobalData\r
 \r
 # Version and Copyright\r
-VersionNumber = "0.5"\r
+VersionNumber = "0.5" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + VersionNumber\r
 __copyright__ = "Copyright (c) 2007 - 2010, Intel Corporation  All rights reserved."\r
 \r
@@ -99,9 +101,10 @@ def CheckEnvVariable():
     os.environ["WORKSPACE"] = WorkspaceDir\r
 \r
     #\r
-    # Check EFI_SOURCE (R8 build convention). EDK_SOURCE will always point to ECP\r
+    # Check EFI_SOURCE (Edk build convention). EDK_SOURCE will always point to ECP\r
     #\r
-    os.environ["ECP_SOURCE"] = os.path.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg)\r
+    if "ECP_SOURCE" not in os.environ:\r
+        os.environ["ECP_SOURCE"] = os.path.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg)\r
     if "EFI_SOURCE" not in os.environ:\r
         os.environ["EFI_SOURCE"] = os.environ["ECP_SOURCE"]\r
     if "EDK_SOURCE" not in os.environ:\r
@@ -120,13 +123,13 @@ def CheckEnvVariable():
     os.environ["EDK_TOOLS_PATH"] = os.path.normcase(os.environ["EDK_TOOLS_PATH"])\r
     \r
     if not os.path.exists(EcpSourceDir):\r
-        EdkLogger.verbose("ECP_SOURCE = %s doesn't exist. R8 modules could not be built." % EcpSourceDir)\r
+        EdkLogger.verbose("ECP_SOURCE = %s doesn't exist. Edk modules could not be built." % EcpSourceDir)\r
     elif ' ' in EcpSourceDir:\r
         EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in ECP_SOURCE path",\r
                         ExtraData=EcpSourceDir)\r
     if not os.path.exists(EdkSourceDir):\r
         if EdkSourceDir == EcpSourceDir:\r
-            EdkLogger.verbose("EDK_SOURCE = %s doesn't exist. R8 modules could not be built." % EdkSourceDir)\r
+            EdkLogger.verbose("EDK_SOURCE = %s doesn't exist. Edk modules could not be built." % EdkSourceDir)\r
         else:\r
             EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE does not exist",\r
                             ExtraData=EdkSourceDir)\r
@@ -135,7 +138,7 @@ def CheckEnvVariable():
                         ExtraData=EdkSourceDir)\r
     if not os.path.exists(EfiSourceDir):\r
         if EfiSourceDir == EcpSourceDir:\r
-            EdkLogger.verbose("EFI_SOURCE = %s doesn't exist. R8 modules could not be built." % EfiSourceDir)\r
+            EdkLogger.verbose("EFI_SOURCE = %s doesn't exist. Edk modules could not be built." % EfiSourceDir)\r
         else:\r
             EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE does not exist",\r
                             ExtraData=EfiSourceDir)\r
@@ -304,7 +307,7 @@ class BuildUnit:
 \r
     ## str() method\r
     #\r
-    #   It just returns the string representaion of self.BuildObject\r
+    #   It just returns the string representation of self.BuildObject\r
     #\r
     #   @param  self        The object pointer\r
     #\r
@@ -656,14 +659,16 @@ class PeImageInfo():
     #   @param  BaseName          The full file path of image. \r
     #   @param  Guid              The GUID for image.\r
     #   @param  Arch              Arch of this image.\r
-    #   @param  OutpuDir          The output directory for image.\r
+    #   @param  OutputDir         The output directory for image.\r
+    #   @param  DebugDir          The debug directory for image.\r
     #   @param  ImageClass        PeImage Information\r
     #\r
-    def __init__(self, BaseName, Guid, Arch, OutpuDir, ImageClass):\r
+    def __init__(self, BaseName, Guid, Arch, OutputDir, DebugDir, ImageClass):\r
         self.BaseName         = BaseName\r
         self.Guid             = Guid\r
         self.Arch             = Arch\r
-        self.OutpuDir         = OutpuDir\r
+        self.OutputDir        = OutputDir\r
+        self.DebugDir         = DebugDir\r
         self.Image            = ImageClass\r
         self.Image.Size       = (self.Image.Size / 0x1000 + 1) * 0x1000\r
 \r
@@ -701,10 +706,10 @@ class Build():
     #   @param  SkuId               SKU id from command line\r
     #\r
     def __init__(self, Target, WorkspaceDir, Platform, Module, Arch, ToolChain,\r
-                 BuildTarget, FlashDefinition, FdList=[], FvList=[],\r
+                 BuildTarget, FlashDefinition, FdList=[], FvList=[], CapList=[],\r
                  MakefileType="nmake", SilentMode=False, ThreadNumber=2,\r
                  SkipAutoGen=False, Reparse=False, SkuId=None, \r
-                 ReportFile=None, ReportType=None):\r
+                 ReportFile=None, ReportType=None, UniFlag=None):\r
 \r
         self.WorkspaceDir = WorkspaceDir\r
         self.Target         = Target\r
@@ -716,6 +721,7 @@ class Build():
         self.Fdf            = FlashDefinition\r
         self.FdList         = FdList\r
         self.FvList         = FvList\r
+        self.CapList        = CapList\r
         self.MakefileType   = MakefileType\r
         self.SilentMode     = SilentMode\r
         self.ThreadNumber   = ThreadNumber\r
@@ -731,13 +737,26 @@ class Build():
         self.BuildDatabase  = self.Db.BuildObject\r
         self.Platform       = None\r
         self.LoadFixAddress = 0\r
+        self.UniFlag        = UniFlag\r
 \r
-        # print dot charater during doing some time-consuming work\r
+        # print dot character during doing some time-consuming work\r
         self.Progress = Utils.Progressor()\r
 \r
         # parse target.txt, tools_def.txt, and platform file\r
         #self.RestoreBuildData()\r
         self.LoadConfiguration()\r
+        \r
+        #\r
+        # @attention Treat $(TARGET)/$(TOOL_CHAIN_TAG) in meta data files as special macro when it has only one build target/toolchain.\r
+        # This is not a complete support for $(TARGET)/$(TOOL_CHAIN_TAG) macro as it can only support one build target/toolchain in ONE\r
+        # invocation of build command. However, it should cover the frequent usage model that $(TARGET)/$(TOOL_CHAIN_TAG) macro\r
+        # is used in DSC/FDF files to specify different libraries & PCD setting for debug/release build.\r
+        #\r
+        if len(self.BuildTargetList) == 1:\r
+            self.Db._GlobalMacros.setdefault("TARGET", self.BuildTargetList[0])\r
+        if len(self.ToolChainList) == 1:   \r
+            self.Db._GlobalMacros.setdefault("TOOL_CHAIN_TAG", self.ToolChainList[0])\r
+        \r
         self.InitBuild()\r
 \r
         # print current build environment and configuration\r
@@ -874,7 +893,7 @@ class Build():
                     self.LoadFixAddress = int (LoadFixAddressString, 16)\r
                 else:\r
                     self.LoadFixAddress = int (LoadFixAddressString)\r
-            except:
+            except:\r
                 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (LoadFixAddressString))\r
             if self.LoadFixAddress < 0:\r
                 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value %s" % (LoadFixAddressString))\r
@@ -893,12 +912,19 @@ class Build():
                 EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvList))\r
                 self.FvList = []\r
         else:\r
+            #\r
+            # Mark now build in AutoGen Phase\r
+            #\r
+            GlobalData.gAutoGenPhase = True\r
             FdfParserObj = FdfParser(str(self.Fdf))\r
+            for key in self.Db._GlobalMacros:\r
+                InputMacroDict[key] = self.Db._GlobalMacros[key]\r
             FdfParserObj.ParseFile()\r
             for fvname in self.FvList:\r
                 if fvname.upper() not in FdfParserObj.Profile.FvDict.keys():\r
                     EdkLogger.error("build", OPTION_VALUE_INVALID,\r
                                     "No such an FV in FDF file: %s" % fvname)\r
+            GlobalData.gAutoGenPhase = False\r
 \r
         #\r
         # Merge Arch\r
@@ -929,7 +955,7 @@ class Build():
 \r
     ## Build a module or platform\r
     #\r
-    # Create autogen code and makfile for a module or platform, and the launch\r
+    # Create autogen code and makefile for a module or platform, and the launch\r
     # "make" command to build it\r
     #\r
     #   @param  Target                      The target of build command\r
@@ -960,6 +986,7 @@ class Build():
             if not self.SkipAutoGen or Target == 'genmake':\r
                 self.Progress.Start("Generating makefile")\r
                 AutoGenObject.CreateMakeFile(CreateDepsMakeFile)\r
+                AutoGenObject.CreateAsBuiltInf()\r
                 self.Progress.Stop("done!")\r
             if Target == "genmake":\r
                 return True\r
@@ -981,11 +1008,16 @@ class Build():
             try:\r
                 #os.rmdir(AutoGenObject.BuildDir)\r
                 RemoveDirectory(AutoGenObject.BuildDir, True)\r
+                #\r
+                # First should close DB.\r
+                #\r
+                self.Db.Close()     \r
+                RemoveDirectory(gBuildCacheDir, True)\r
             except WindowsError, X:\r
                 EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X))\r
         return True\r
 \r
-    ## Rebase module image and Get function address for the inpug module list.\r
+    ## Rebase module image and Get function address for the input module list.\r
     #\r
     def _RebaseModule (self, MapBuffer, BaseAddress, ModuleList, AddrIsOffset = True, ModeIsSmm = False):\r
         if ModeIsSmm:\r
@@ -993,26 +1025,30 @@ class Build():
         InfFileNameList = ModuleList.keys()\r
         #InfFileNameList.sort()\r
         for InfFile in InfFileNameList:\r
-            sys.stdout.write (".")
-            sys.stdout.flush()
+            sys.stdout.write (".")\r
+            sys.stdout.flush()\r
             ModuleInfo = ModuleList[InfFile]\r
             ModuleName = ModuleInfo.BaseName\r
+            ModuleOutputImage = ModuleInfo.Image.FileName\r
+            ModuleDebugImage  = os.path.join(ModuleInfo.DebugDir, ModuleInfo.BaseName + '.efi')\r
             ## for SMM module in SMRAM, the SMRAM will be allocated from base to top.\r
             if not ModeIsSmm:\r
                 BaseAddress = BaseAddress - ModuleInfo.Image.Size\r
                 #\r
                 # Update Image to new BaseAddress by GenFw tool\r
                 #\r
-                LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleInfo.Image.FileName], ModuleInfo.OutpuDir)\r
+                LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)\r
+                LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleDebugImage],  ModuleInfo.DebugDir)\r
             else:\r
                 #\r
                 # Set new address to the section header only for SMM driver.\r
                 #\r
-                LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleInfo.Image.FileName], ModuleInfo.OutpuDir)\r
+                LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)\r
+                LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleDebugImage],  ModuleInfo.DebugDir)\r
             #\r
             # Collect funtion address from Map file\r
             #\r
-            ImageMapTable = ModuleInfo.Image.FileName.replace('.efi', '.map')\r
+            ImageMapTable = ModuleOutputImage.replace('.efi', '.map')\r
             FunctionList = []\r
             if os.path.exists(ImageMapTable):\r
                 OrigImageBaseAddress = 0\r
@@ -1059,9 +1095,13 @@ class Build():
                 elif SectionHeader[0] in ['.data', '.sdata']:\r
                     DataSectionAddress = SectionHeader[1]\r
             if AddrIsOffset:\r
-                MapBuffer.write('(GUID=%s, .textbaseaddress=-0x%010X, .databaseaddress=-0x%010X)\n\n' % (ModuleInfo.Guid, 0 - (BaseAddress + TextSectionAddress), 0 - (BaseAddress + DataSectionAddress))) \r
+                MapBuffer.write('(GUID=%s, .textbaseaddress=-0x%010X, .databaseaddress=-0x%010X)\n' % (ModuleInfo.Guid, 0 - (BaseAddress + TextSectionAddress), 0 - (BaseAddress + DataSectionAddress))) \r
             else:\r
-                MapBuffer.write('(GUID=%s, .textbaseaddress=0x%010X, .databaseaddress=0x%010X)\n\n' % (ModuleInfo.Guid, BaseAddress + TextSectionAddress, BaseAddress + DataSectionAddress)) \r
+                MapBuffer.write('(GUID=%s, .textbaseaddress=0x%010X, .databaseaddress=0x%010X)\n' % (ModuleInfo.Guid, BaseAddress + TextSectionAddress, BaseAddress + DataSectionAddress)) \r
+            #\r
+            # Add debug image full path.\r
+            #\r
+            MapBuffer.write('(IMAGE=%s)\n\n' % (ModuleDebugImage))\r
             #\r
             # Add funtion address\r
             #\r
@@ -1080,9 +1120,11 @@ class Build():
 \r
     ## Collect MAP information of all FVs\r
     #\r
-    def _CollectFvMapBuffer (self, MapBuffer, Wa):\r
+    def _CollectFvMapBuffer (self, MapBuffer, Wa, ModuleList):\r
         if self.Fdf != '':\r
             # First get the XIP base address for FV map file.\r
+            GuidPattern = re.compile("[-a-fA-F0-9]+")\r
+            GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")\r
             for FvName in Wa.FdfProfile.FvDict.keys():\r
                 FvMapBuffer = os.path.join(Wa.FvDir, FvName + '.Fv.map')\r
                 if not os.path.exists(FvMapBuffer):\r
@@ -1093,14 +1135,32 @@ class Build():
                 FvMap.readline()\r
                 FvMap.readline()\r
                 FvMap.readline()\r
-                MapBuffer.write(FvMap.read())\r
+                for Line in FvMap:\r
+                    MatchGuid = GuidPattern.match(Line)\r
+                    if MatchGuid != None:\r
+                        #\r
+                        # Replace GUID with module name\r
+                        #\r
+                        GuidString = MatchGuid.group()\r
+                        if GuidString.upper() in ModuleList:\r
+                            Line = Line.replace(GuidString, ModuleList[GuidString.upper()].Name)\r
+                    MapBuffer.write('%s' % (Line))\r
+                    #\r
+                    # Add the debug image full path.\r
+                    #\r
+                    MatchGuid = GuidName.match(Line)\r
+                    if MatchGuid != None:\r
+                        GuidString = MatchGuid.group().split("=")[1]\r
+                        if GuidString.upper() in ModuleList:\r
+                            MapBuffer.write('(IMAGE=%s)\n' % (os.path.join(ModuleList[GuidString.upper()].DebugDir, ModuleList[GuidString.upper()].Name + '.efi')))\r
+\r
                 FvMap.close()\r
 \r
     ## Collect MAP information of all modules\r
     #\r
     def _CollectModuleMapBuffer (self, MapBuffer, ModuleList):\r
-        sys.stdout.write ("Generate Load Module At Fix Address Map")
-        sys.stdout.flush()
+        sys.stdout.write ("Generate Load Module At Fix Address Map")\r
+        sys.stdout.flush()\r
         PatchEfiImageList = []\r
         PeiModuleList  = {}\r
         BtModuleList   = {}\r
@@ -1114,7 +1174,8 @@ class Build():
         IsIpfPlatform = False\r
         if 'IPF' in self.ArchList:\r
             IsIpfPlatform = True\r
-        for Module in ModuleList:\r
+        for ModuleGuid in ModuleList:\r
+            Module = ModuleList[ModuleGuid]\r
             GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (Module.MetaFile, Module.Arch, Module.ToolChain, Module.BuildTarget)\r
             \r
             OutputImageFile = ''\r
@@ -1127,7 +1188,7 @@ class Build():
                     ImageClass = PeImageClass (OutputImageFile)\r
                     if not ImageClass.IsValid:\r
                         EdkLogger.error("build", FILE_PARSE_FAILURE, ExtraData=ImageClass.ErrorInfo)\r
-                    ImageInfo = PeImageInfo(Module.Name, Module.Guid, Module.Arch, Module.OutputDir, ImageClass)\r
+                    ImageInfo = PeImageInfo(Module.Name, Module.Guid, Module.Arch, Module.OutputDir, Module.DebugDir, ImageClass)\r
                     if Module.ModuleType in ['PEI_CORE', 'PEIM', 'COMBINED_PEIM_DRIVER','PIC_PEIM', 'RELOCATABLE_PEIM', 'DXE_CORE']:\r
                         PeiModuleList[Module.MetaFile] = ImageInfo\r
                         PeiSize += ImageInfo.Image.Size\r
@@ -1144,11 +1205,11 @@ class Build():
                         SmmModuleList[Module.MetaFile] = ImageInfo\r
                         SmmSize += ImageInfo.Image.Size\r
                         if Module.ModuleType == 'DXE_SMM_DRIVER':\r
-                            PiSpecVersion = 0
-                            if 'PI_SPECIFICATION_VERSION' in Module.Module.Specification:
-                                PiSpecVersion = Module.Module.Specification['PI_SPECIFICATION_VERSION']
+                            PiSpecVersion = '0x00000000'\r
+                            if 'PI_SPECIFICATION_VERSION' in Module.Module.Specification:\r
+                                PiSpecVersion = Module.Module.Specification['PI_SPECIFICATION_VERSION']\r
                             # for PI specification < PI1.1, DXE_SMM_DRIVER also runs as BOOT time driver.\r
-                            if PiSpecVersion < 0x0001000A:\r
+                            if int(PiSpecVersion, 16) < 0x0001000A:\r
                                 BtModuleList[Module.MetaFile] = ImageInfo\r
                                 BtSize += ImageInfo.Image.Size\r
                     break\r
@@ -1202,7 +1263,7 @@ class Build():
             #\r
             # Get PCD offset in EFI image by GenPatchPcdTable function\r
             #\r
-            PcdTable = parsePcdInfoFromMapFile(EfiImageMap, EfiImage) 
+            PcdTable = parsePcdInfoFromMapFile(EfiImageMap, EfiImage) \r
             #\r
             # Patch real PCD value by PatchPcdValue tool\r
             #\r
@@ -1225,17 +1286,17 @@ class Build():
         if len (SmmModuleList) > 0:\r
             MapBuffer.write('SMM_CODE_PAGE_NUMBER      = 0x%x\n' % (SmmSize/0x1000))\r
         \r
-        PeiBaseAddr = TopMemoryAddress - RtSize - BtSize\r
+        PeiBaseAddr = TopMemoryAddress - RtSize - BtSize \r
         BtBaseAddr  = TopMemoryAddress - RtSize\r
-        RtBaseAddr  = TopMemoryAddress - ReservedRuntimeMemorySize\r
+        RtBaseAddr  = TopMemoryAddress - ReservedRuntimeMemorySize \r
 \r
         self._RebaseModule (MapBuffer, PeiBaseAddr, PeiModuleList, TopMemoryAddress == 0)\r
         self._RebaseModule (MapBuffer, BtBaseAddr, BtModuleList, TopMemoryAddress == 0)\r
         self._RebaseModule (MapBuffer, RtBaseAddr, RtModuleList, TopMemoryAddress == 0)\r
         self._RebaseModule (MapBuffer, 0x1000, SmmModuleList, AddrIsOffset = False, ModeIsSmm = True)\r
         MapBuffer.write('\n\n')\r
-        sys.stdout.write ("\n")
-        sys.stdout.flush()
+        sys.stdout.write ("\n")\r
+        sys.stdout.flush()\r
     \r
     ## Save platform Map file\r
     #\r
@@ -1249,8 +1310,9 @@ class Build():
         #\r
         SaveFileOnChange(MapFilePath, MapBuffer.getvalue(), False)\r
         MapBuffer.close()\r
-        sys.stdout.write ("\nLoad Module At Fix Address Map file saved to %s\n" %(MapFilePath))
-        sys.stdout.flush()
+        if self.LoadFixAddress != 0:\r
+            sys.stdout.write ("\nLoad Module At Fix Address Map file can be found at %s\n" %(MapFilePath))\r
+        sys.stdout.flush()\r
 \r
     ## Build active platform for different build targets and different tool chains\r
     #\r
@@ -1269,14 +1331,16 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
-                        self.SkuId\r
+                        self.CapList,\r
+                        self.SkuId,\r
+                        self.UniFlag\r
                         )\r
                 self.BuildReport.AddPlatformReport(Wa)\r
                 self.Progress.Stop("done!")\r
                 self._Build(self.Target, Wa)\r
                 \r
                 # Create MAP file when Load Fix Address is enabled.\r
-                if self.Target in ["", "all", "fds"] and self.LoadFixAddress != 0:\r
+                if self.Target in ["", "all", "fds"]:\r
                     for Arch in self.ArchList:\r
                         #\r
                         # Check whether the set fix address is above 4G for 32bit image.\r
@@ -1286,28 +1350,30 @@ class Build():
                     #\r
                     # Get Module List\r
                     #\r
-                    ModuleList = []\r
+                    ModuleList = {}\r
                     for Pa in Wa.AutoGenObjectList:\r
                         for Ma in Pa.ModuleAutoGenList:\r
                             if Ma == None:\r
                                 continue\r
                             if not Ma.IsLibrary:\r
-                                ModuleList.append (Ma)\r
+                                ModuleList[Ma.Guid.upper()] = Ma\r
 \r
                     MapBuffer = StringIO('')\r
-                    #\r
-                    # Rebase module to the preferred memory address before GenFds\r
-                    #\r
-                    self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
-                    if self.Fdf != '':\r
+                    if self.LoadFixAddress != 0:\r
                         #\r
-                        # create FDS again for the updated EFI image\r
+                        # Rebase module to the preferred memory address before GenFds\r
                         #\r
-                        self._Build("fds", Wa)\r
+                        self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
+                        if self.Fdf != '':\r
+                            #\r
+                            # create FDS again for the updated EFI image\r
+                            #\r
+                            self._Build("fds", Wa)\r
+                    if self.Fdf != '':\r
                         #\r
                         # Create MAP file for all platform FVs after GenFds.\r
                         #\r
-                        self._CollectFvMapBuffer(MapBuffer, Wa)\r
+                        self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)\r
                     #\r
                     # Save MAP buffer into MAP file.\r
                     #\r
@@ -1334,9 +1400,10 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
-                        self.SkuId\r
+                        self.CapList,\r
+                        self.SkuId,\r
+                        self.UniFlag\r
                         )\r
-                self.BuildReport.AddPlatformReport(Wa)\r
                 Wa.CreateMakeFile(False)\r
                 self.Progress.Stop("done!")\r
                 MaList = []\r
@@ -1345,6 +1412,8 @@ class Build():
                     if Ma == None: continue\r
                     MaList.append(Ma)\r
                     self._Build(self.Target, Ma)\r
+\r
+                self.BuildReport.AddPlatformReport(Wa, MaList)\r
                 if MaList == []:\r
                     EdkLogger.error(\r
                                 'build',\r
@@ -1356,7 +1425,7 @@ class Build():
                                 ExtraData=self.ModuleFile\r
                                 )\r
                 # Create MAP file when Load Fix Address is enabled.\r
-                if self.LoadFixAddress != 0 and self.Target == "fds" and self.Fdf != '':\r
+                if self.Target == "fds" and self.Fdf != '':\r
                     for Arch in self.ArchList:\r
                         #\r
                         # Check whether the set fix address is above 4G for 32bit image.\r
@@ -1366,27 +1435,28 @@ class Build():
                     #\r
                     # Get Module List\r
                     #\r
-                    ModuleList = []\r
+                    ModuleList = {}\r
                     for Pa in Wa.AutoGenObjectList:\r
                         for Ma in Pa.ModuleAutoGenList:\r
                             if Ma == None:\r
                                 continue\r
                             if not Ma.IsLibrary:\r
-                                ModuleList.append (Ma)\r
+                                ModuleList[Ma.Guid.upper()] = Ma\r
 \r
                     MapBuffer = StringIO('')\r
-                    #\r
-                    # Rebase module to the preferred memory address before GenFds\r
-                    #\r
-                    self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
-                    #\r
-                    # create FDS again for the updated EFI image\r
-                    #\r
-                    self._Build("fds", Wa)\r
+                    if self.LoadFixAddress != 0:\r
+                        #\r
+                        # Rebase module to the preferred memory address before GenFds\r
+                        #\r
+                        self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
+                        #\r
+                        # create FDS again for the updated EFI image\r
+                        #\r
+                        self._Build("fds", Wa)\r
                     #\r
                     # Create MAP file for all platform FVs after GenFds.\r
                     #\r
-                    self._CollectFvMapBuffer(MapBuffer, Wa)\r
+                    self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)\r
                     #\r
                     # Save MAP buffer into MAP file.\r
                     #\r
@@ -1409,7 +1479,9 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
-                        self.SkuId\r
+                        self.CapList,\r
+                        self.SkuId,\r
+                        self.UniFlag\r
                         )\r
                 self.BuildReport.AddPlatformReport(Wa)\r
                 Wa.CreateMakeFile(False)\r
@@ -1436,6 +1508,7 @@ class Build():
 \r
                             if not self.SkipAutoGen or self.Target == 'genmake':\r
                                 Ma.CreateMakeFile(True)\r
+                                Ma.CreateAsBuiltInf()\r
                             if self.Target == "genmake":\r
                                 continue\r
                         self.Progress.Stop("done!")\r
@@ -1472,7 +1545,7 @@ class Build():
                     EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
 \r
                 # Create MAP file when Load Fix Address is enabled.\r
-                if self.Target in ["", "all", "fds"] and self.LoadFixAddress != 0:\r
+                if self.Target in ["", "all", "fds"]:\r
                     for Arch in self.ArchList:\r
                         #\r
                         # Check whether the set fix address is above 4G for 32bit image.\r
@@ -1482,30 +1555,29 @@ class Build():
                     #\r
                     # Get Module List\r
                     #\r
-                    ModuleList = []\r
+                    ModuleList = {}\r
                     for Pa in Wa.AutoGenObjectList:\r
                         for Ma in Pa.ModuleAutoGenList:\r
                             if Ma == None:\r
                                 continue\r
                             if not Ma.IsLibrary:\r
-                                ModuleList.append (Ma)\r
+                                ModuleList[Ma.Guid.upper()] = Ma\r
                     #\r
                     # Rebase module to the preferred memory address before GenFds\r
                     #\r
                     MapBuffer = StringIO('')\r
-                    self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
+                    if self.LoadFixAddress != 0:\r
+                        self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
 \r
-                # Generate FD image if there's a FDF file found\r
-                if self.Fdf != '' and self.Target in ["", "all", "fds"]:\r
-                    LaunchCommand(Wa.BuildCommand + ["fds"], Wa.MakeFileDir)\r
-\r
-                # Create MAP file for all platform FV after GenFds\r
-                if self.Target in ["", "all", "fds"] and self.LoadFixAddress != 0:\r
                     if self.Fdf != '':\r
+                        #\r
+                        # Generate FD image if there's a FDF file found\r
+                        #\r
+                        LaunchCommand(Wa.BuildCommand + ["fds"], Wa.MakeFileDir)\r
                         #\r
                         # Create MAP file for all platform FVs after GenFds.\r
                         #\r
-                        self._CollectFvMapBuffer(MapBuffer, Wa)\r
+                        self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)\r
                     #\r
                     # Save MAP buffer into MAP file.\r
                     #\r
@@ -1644,8 +1716,8 @@ def MyOptionParser():
         help="Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition.")\r
     Parser.add_option("-m", "--module", action="callback", type="string", dest="ModuleFile", callback=SingleCheckCallback,\r
         help="Build the module specified by the INF file name argument.")\r
-    Parser.add_option("-b", "--buildtarget", action="append", type="choice", choices=['DEBUG','RELEASE'], dest="BuildTarget",\r
-        help="BuildTarget is one of list: DEBUG, RELEASE, which overrides target.txt's TARGET definition. To specify more TARGET, please repeat this option.")\r
+    Parser.add_option("-b", "--buildtarget", action="append", type="choice", choices=['DEBUG','RELEASE','NOOPT'], dest="BuildTarget",\r
+        help="BuildTarget is one of list: DEBUG, RELEASE, NOOPT, which overrides target.txt's TARGET definition. To specify more TARGET, please repeat this option.")\r
     Parser.add_option("-t", "--tagname", action="append", type="string", dest="ToolChain",\r
         help="Using the Tool Chain Tagname to build the platform, overriding target.txt's TOOL_CHAIN_TAG definition.")\r
     Parser.add_option("-x", "--sku-id", action="callback", type="string", dest="SkuId", callback=SingleCheckCallback,\r
@@ -1660,7 +1732,8 @@ def MyOptionParser():
         help="The name of FD to be generated. The name must be from [FD] section in FDF file.")\r
     Parser.add_option("-i", "--fv-image", action="append", type="string", dest="FvImage", default=[],\r
         help="The name of FV to be generated. The name must be from [FV] section in FDF file.")\r
-\r
+    Parser.add_option("-C", "--capsule-image", action="append", type="string", dest="CapName", default=[],\r
+        help="The name of Capsule to be generated. The name must be from [Capsule] section in FDF file.")\r
     Parser.add_option("-u", "--skip-autogen", action="store_true", dest="SkipAutoGen", help="Skip AutoGen step.")\r
     Parser.add_option("-e", "--re-parse", action="store_true", dest="Reparse", help="Re-parse all meta-data files.")\r
 \r
@@ -1685,6 +1758,10 @@ def MyOptionParser():
     Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD','LIBRARY','FLASH','DEPEX','BUILD_FLAGS','FIXED_ADDRESS', 'EXECUTION_ORDER'], dest="ReportType", default=[],\r
         help="Flags that control the type of build report to generate.  Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS, EXECUTION_ORDER].  "\\r
              "To specify more than one flag, repeat this option on the command line and the default flag set is [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS]")\r
+    Parser.add_option("-F", "--flag", action="store", type="string", dest="Flag",\r
+        help="Specify the specific option to parse EDK UNI file. Must be one of: [-c, -s]. -c is for EDK framework UNI file, and -s is for EDK UEFI UNI file. "\\r
+             "This option can also be specified by setting *_*_*_BUILD_FLAGS in [BuildOptions] section of platform DSC. If they are both specified, this value "\\r
+             "will override the setting in [BuildOptions] section of platform DSC.")\r
 \r
     (Opt, Args)=Parser.parse_args()\r
     return (Opt, Args)\r
@@ -1732,7 +1809,8 @@ def Main():
     else:\r
         GlobalData.gIsWindows = False\r
 \r
-    EdkLogger.quiet(time.strftime("%H:%M:%S, %b.%d %Y ", time.localtime()) + "[%s]\n" % platform.platform())\r
+    EdkLogger.quiet("Build environment: %s" % platform.platform())\r
+    EdkLogger.quiet(time.strftime("Build start time: %H:%M:%S, %b.%d %Y\n", time.localtime()));\r
     ReturnCode = 0\r
     MyBuild = None\r
     try:\r
@@ -1796,12 +1874,15 @@ def Main():
             if ErrorCode != 0:\r
                 EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo)\r
 \r
+        if Option.Flag != None and Option.Flag not in ['-c', '-s']:\r
+            EdkLogger.error("build", OPTION_VALUE_INVALID, "UNI flag must be one of -c or -s")\r
+\r
         MyBuild = Build(Target, Workspace, Option.PlatformFile, Option.ModuleFile,\r
                         Option.TargetArch, Option.ToolChain, Option.BuildTarget,\r
-                        Option.FdfFile, Option.RomImage, Option.FvImage,\r
+                        Option.FdfFile, Option.RomImage, Option.FvImage, Option.CapName,\r
                         None, Option.SilentMode, Option.ThreadNumber,\r
                         Option.SkipAutoGen, Option.Reparse, Option.SkuId, \r
-                        Option.ReportFile, Option.ReportType)\r
+                        Option.ReportFile, Option.ReportType, Option.Flag)\r
         MyBuild.Launch()\r
         #MyBuild.DumpBuildData()\r
     except FatalError, X:\r
@@ -1856,13 +1937,19 @@ def Main():
     else:\r
         Conclusion = "Failed"\r
     FinishTime = time.time()\r
-    BuildDuration = time.strftime("%M:%S", time.gmtime(int(round(FinishTime - StartTime))))\r
+    BuildDuration = time.gmtime(int(round(FinishTime - StartTime)))\r
+    BuildDurationStr = ""\r
+    if BuildDuration.tm_yday > 1:\r
+        BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration) + ", %d day(s)"%(BuildDuration.tm_yday - 1)\r
+    else:\r
+        BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration)\r
     if MyBuild != None:\r
-        MyBuild.BuildReport.GenerateReport(BuildDuration)\r
+        MyBuild.BuildReport.GenerateReport(BuildDurationStr)\r
         MyBuild.Db.Close()\r
     EdkLogger.SetLevel(EdkLogger.QUIET)\r
-    EdkLogger.quiet("\n- %s -\n%s [%s]" % (Conclusion, time.strftime("%H:%M:%S, %b.%d %Y", time.localtime()), BuildDuration))\r
-\r
+    EdkLogger.quiet("\n- %s -" % Conclusion)\r
+    EdkLogger.quiet(time.strftime("Build end time: %H:%M:%S, %b.%d %Y", time.localtime()))\r
+    EdkLogger.quiet("Build total time: %s\n" % BuildDurationStr)\r
     return ReturnCode\r
 \r
 if __name__ == '__main__':\r