]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
Sync EDKII BaseTools to BaseTools project r1937.
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index 61293080117cae0862a581ea67c43f7ec9aa438e..f608dee9b8c703094bd01274f61d272369ab9be2 100644 (file)
@@ -656,14 +656,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 +706,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,6 +733,7 @@ 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
         self.Progress = Utils.Progressor()\r
@@ -1007,22 +1010,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
@@ -1069,9 +1076,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
@@ -1094,6 +1105,7 @@ class Build():
         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
@@ -1114,6 +1126,15 @@ class Build():
                         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
@@ -1148,7 +1169,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
@@ -1268,7 +1289,9 @@ class Build():
         #\r
         # Save address map into MAP file.\r
         #\r
-        SaveFileOnChange(MapFilePath, MapBuffer.getvalue(), False)\r
+        MapFile = open(MapFilePath, "wb")
+        MapFile.write(MapBuffer.getvalue())
+        MapFile.close()
         MapBuffer.close()\r
         if self.LoadFixAddress != 0:
             sys.stdout.write ("\nLoad Module At Fix Address Map file saved to %s\n" %(MapFilePath))
@@ -1291,7 +1314,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
                 self.Progress.Stop("done!")\r
@@ -1322,11 +1346,12 @@ class Build():
                         # Rebase module to the preferred memory address before GenFds\r
                         #\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 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
@@ -1357,7 +1382,8 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
-                        self.SkuId\r
+                        self.SkuId,\r
+                        self.UniFlag\r
                         )\r
                 Wa.CreateMakeFile(False)\r
                 self.Progress.Stop("done!")\r
@@ -1434,7 +1460,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
@@ -1521,13 +1548,11 @@ class Build():
                     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"]:\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
@@ -1711,6 +1736,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
@@ -1822,12 +1851,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