]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
Sync EDKII BaseTools to BaseTools project r2065.
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index 9705097606b8ae4836ce255d9e85735335d433a2..54265952d03ba034d540168a6429e66603005161 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 - 2010, 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
@@ -304,7 +305,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 +657,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
@@ -704,7 +707,7 @@ class Build():
                  BuildTarget, FlashDefinition, FdList=[], FvList=[],\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
@@ -731,13 +734,24 @@ 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) in meta data files as special macro when it has only one build target.\r
+        # This is not a complete support for $(TARGET) macro as it can only support one build target in ONE\r
+        # invocation of build command. However, it should cover the frequent usage model that $(TARGET) macro\r
+        # is used in DSC 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
+        \r
         self.InitBuild()\r
 \r
         # print current build environment and configuration\r
@@ -929,7 +943,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
@@ -997,22 +1011,26 @@ class Build():
             sys.stdout.flush()
             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 +1077,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 +1102,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,7 +1117,25 @@ 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
@@ -1114,7 +1156,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 +1170,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
@@ -1225,9 +1268,9 @@ 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
@@ -1248,8 +1291,9 @@ class Build():
         # Save address map into MAP file.\r
         #\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))
+        MapBuffer.close()
+        if self.LoadFixAddress != 0:
+            sys.stdout.write ("\nLoad Module At Fix Address Map file can be found at %s\n" %(MapFilePath))
         sys.stdout.flush()
 \r
     ## Build active platform for different build targets and different tool chains\r
@@ -1269,14 +1313,15 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
-                        self.SkuId\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 +1331,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 +1381,9 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
-                        self.SkuId\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 +1392,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 +1405,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 +1415,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 +1459,8 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
-                        self.SkuId\r
+                        self.SkuId,\r
+                        self.UniFlag\r
                         )\r
                 self.BuildReport.AddPlatformReport(Wa)\r
                 Wa.CreateMakeFile(False)\r
@@ -1472,7 +1523,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 +1533,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
@@ -1685,6 +1735,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
@@ -1796,12 +1850,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
                         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