]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFds.py
Sync BaseTools Branch (version r2271) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFds.py
index 1df19100d3fc99127e1c7d480615052c88eba6a2..9088a876e4c9d889753622e1b6224a7b94732cb1 100644 (file)
@@ -1,9 +1,9 @@
 ## @file
 # generate flash image
 #
-#  Copyright (c) 2007, Intel Corporation
+#  Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
 #
-#  All rights reserved. This program and the accompanying materials
+#  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
 #  which accompanies this distribution.  The full text of the license may be found at
 #  http://opensource.org/licenses/bsd-license.php
@@ -35,11 +35,12 @@ import Common.GlobalData as GlobalData
 from Common import EdkLogger
 from Common.String import *
 from Common.Misc import DirCache,PathClass
+from Common.Misc import SaveFileOnChange
 
 ## Version and Copyright
 versionNumber = "1.0"
 __version__ = "%prog Version " + versionNumber
-__copyright__ = "Copyright (c) 2007, Intel Corporation  All rights reserved."
+__copyright__ = "Copyright (c) 2007 - 2010, Intel Corporation  All rights reserved."
 
 ## Tool entrance method
 #
@@ -94,6 +95,18 @@ def main():
         if (Options.filename):
             FdfFilename = Options.filename
             FdfFilename = GenFdsGlobalVariable.ReplaceWorkspaceMacro(FdfFilename)
+
+            if FdfFilename[0:2] == '..':
+                FdfFilename = os.path.realpath(FdfFilename)
+            if not os.path.isabs (FdfFilename):
+                FdfFilename = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, FdfFilename)
+            if not os.path.exists(FdfFilename):
+                EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=FdfFilename)
+            if os.path.normcase (FdfFilename).find(Workspace) != 0:
+                EdkLogger.error("GenFds", FILE_NOT_FOUND, "FdfFile doesn't exist in Workspace!")
+
+            GenFdsGlobalVariable.FdfFile = FdfFilename
+            GenFdsGlobalVariable.FdfFileTimeStamp = os.path.getmtime(FdfFilename)
         else:
             EdkLogger.error("GenFds", OPTION_MISSING, "Missing FDF filename")
 
@@ -107,16 +120,6 @@ def main():
         else:
             EdkLogger.error("GenFds", OPTION_MISSING, "Missing tool chain tag")
 
-        if FdfFilename[0:2] == '..':
-            FdfFilename = os.path.realpath(FdfFilename)
-        if FdfFilename[1] != ':':
-            FdfFilename = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, FdfFilename)
-
-        if not os.path.exists(FdfFilename):
-            EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=FdfFilename)
-        GenFdsGlobalVariable.FdfFile = FdfFilename
-        GenFdsGlobalVariable.FdfFileTimeStamp = os.path.getmtime(FdfFilename)
-
         if (Options.activePlatform):
             ActivePlatform = Options.activePlatform
             ActivePlatform = GenFdsGlobalVariable.ReplaceWorkspaceMacro(ActivePlatform)
@@ -124,22 +127,22 @@ def main():
             if ActivePlatform[0:2] == '..':
                 ActivePlatform = os.path.realpath(ActivePlatform)
 
-            if ActivePlatform[1] != ':':
+            if not os.path.isabs (ActivePlatform):
                 ActivePlatform = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, ActivePlatform)
 
             if not os.path.exists(ActivePlatform)  :
                 EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!")
 
-            if ActivePlatform.find(Workspace) == -1:
+            if os.path.normcase (ActivePlatform).find(Workspace) != 0:
                 EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist in Workspace!")
 
-            ActivePlatform = ActivePlatform.replace(Workspace, '')
+            ActivePlatform = ActivePlatform[len(Workspace):]
             if len(ActivePlatform) > 0 :
                 if ActivePlatform[0] == '\\' or ActivePlatform[0] == '/':
                     ActivePlatform = ActivePlatform[1:]
             else:
                 EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!")
-        else :
+        else:
             EdkLogger.error("GenFds", OPTION_MISSING, "Missing active platform")
 
         GenFdsGlobalVariable.ActivePlatform = PathClass(NormPath(ActivePlatform), Workspace)
@@ -169,6 +172,7 @@ def main():
 
         """call Workspace build create database"""
         os.environ["WORKSPACE"] = Workspace
+        FdfParser.InputMacroDict["WORKSPACE"] = Workspace
         BuildWorkSpace = WorkspaceDatabase(':memory:', FdfParser.InputMacroDict)
         BuildWorkSpace.InitDatabase()
         
@@ -190,9 +194,12 @@ def main():
         
         for Arch in ArchList:
             GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].OutputDirectory)
+            GenFdsGlobalVariable.PlatformName = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].PlatformName
 
         if (Options.outputDir):
             OutputDirFromCommandLine = GenFdsGlobalVariable.ReplaceWorkspaceMacro(Options.outputDir)
+            if not os.path.isabs (OutputDirFromCommandLine):
+                OutputDirFromCommandLine = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, OutputDirFromCommandLine)
             for Arch in ArchList:
                 GenFdsGlobalVariable.OutputDirDict[Arch] = OutputDirFromCommandLine
         else:
@@ -232,15 +239,25 @@ def main():
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,
                                 "No such an FV in FDF file: %s" % Options.uiFvName)
 
+        if (Options.uiCapName) :
+            if Options.uiCapName.upper() in FdfParserObj.Profile.CapsuleDict.keys():
+                GenFds.OnlyGenerateThisCap = Options.uiCapName
+            else:
+                EdkLogger.error("GenFds", OPTION_VALUE_INVALID,
+                                "No such a Capsule in FDF file: %s" % Options.uiCapName)
+
         """Modify images from build output if the feature of loading driver at fixed address is on."""
         if GenFdsGlobalVariable.FixedLoadAddress:
             GenFds.PreprocessImage(BuildWorkSpace, GenFdsGlobalVariable.ActivePlatform)
         """Call GenFds"""
         GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList)
-        
+
+        """Generate GUID cross reference file"""
+        GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList)
+
         """Display FV space info."""
         GenFds.DisplayFvSpaceInfo(FdfParserObj)
-        
+
     except FdfParser.Warning, X:
         EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError = False)
         ReturnCode = FORMAT_INVALID
@@ -255,7 +272,7 @@ def main():
                     "\nPython",
                     CODE_ERROR,
                     "Tools code failure",
-                    ExtraData="Please submit bug report in www.TianoCore.org, attaching following call stack trace!\n",
+                    ExtraData="Please send email to edk2-buildtools-devel@lists.sourceforge.net for help, attaching following call stack trace!\n",
                     RaiseError=False
                     )
         EdkLogger.quiet(traceback.format_exc())
@@ -292,7 +309,8 @@ def myOptionParser():
     Parser.add_option("-o", "--outputDir", type="string", dest="outputDir", help="Name of Build Output directory",
                       action="callback", callback=SingleCheckCallback)
     Parser.add_option("-r", "--rom_image", dest="uiFdName", help="Build the image using the [FD] section named by FdUiName.")
-    Parser.add_option("-i", "--FvImage", dest="uiFvName", help="Buld the FV image using the [FV] section named by UiFvName")
+    Parser.add_option("-i", "--FvImage", dest="uiFvName", help="Build the FV image using the [FV] section named by UiFvName")
+    Parser.add_option("-C", "--CapsuleImage", dest="uiCapName", help="Build the Capsule image using the [Capsule] section named by UiCapName")
     Parser.add_option("-b", "--buildtarget", type="choice", choices=['DEBUG','RELEASE'], dest="BuildTarget", help="Build TARGET is one of list: DEBUG, RELEASE.",
                       action="callback", callback=SingleCheckCallback)
     Parser.add_option("-t", "--tagname", type="string", dest="ToolChain", help="Using the tools: TOOL_CHAIN_TAG name to build the platform.",
@@ -315,6 +333,7 @@ class GenFds :
     ImageBinDict = {}
     OnlyGenerateThisFd = None
     OnlyGenerateThisFv = None
+    OnlyGenerateThisCap = None
 
     ## GenFd()
     #
@@ -327,11 +346,18 @@ class GenFds :
         GenFdsGlobalVariable.SetDir ('', FdfParser, WorkSpace, ArchList)
 
         GenFdsGlobalVariable.VerboseLogger(" Generate all Fd images and their required FV and Capsule images!")
+        if GenFds.OnlyGenerateThisCap != None and GenFds.OnlyGenerateThisCap.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys():
+            CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.get(GenFds.OnlyGenerateThisCap.upper())
+            if CapsuleObj != None:
+                CapsuleObj.GenCapsule()
+                return
+
         if GenFds.OnlyGenerateThisFd != None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():
             FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(GenFds.OnlyGenerateThisFd.upper())
             if FdObj != None:
                 FdObj.GenFd()
-        elif GenFds.OnlyGenerateThisFd == None:
+                return
+        elif GenFds.OnlyGenerateThisFd == None and GenFds.OnlyGenerateThisFv == None:
             for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():
                 FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]
                 FdObj.GenFd()
@@ -341,19 +367,17 @@ class GenFds :
             FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(GenFds.OnlyGenerateThisFv.upper())
             if FvObj != None:
                 Buffer = StringIO.StringIO()
-                # Get FV base Address
-                FvObj.AddToBuffer(Buffer, None, GenFds.GetFvBlockSize(FvObj))
+                FvObj.AddToBuffer(Buffer)
                 Buffer.close()
                 return
         elif GenFds.OnlyGenerateThisFv == None:
             for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():
                 Buffer = StringIO.StringIO('')
                 FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName]
-                # Get FV base Address
-                FvObj.AddToBuffer(Buffer, None, GenFds.GetFvBlockSize(FvObj))
+                FvObj.AddToBuffer(Buffer)
                 Buffer.close()
-
-        if GenFds.OnlyGenerateThisFv == None and GenFds.OnlyGenerateThisFd == None:
+        
+        if GenFds.OnlyGenerateThisFv == None and GenFds.OnlyGenerateThisFd == None and GenFds.OnlyGenerateThisCap == None:
             if GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict != {}:
                 GenFdsGlobalVariable.VerboseLogger("\n Generate other Capsule images!")
                 for CapsuleName in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys():
@@ -372,7 +396,7 @@ class GenFds :
     #   @retval int             Block size value
     #
     def GetFvBlockSize(FvObj):
-        DefaultBlockSize = 0x10000
+        DefaultBlockSize = 0x1
         FdObj = None
         if GenFds.OnlyGenerateThisFd != None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():
             FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()]
@@ -443,7 +467,12 @@ class GenFds :
             TotalSizeValue = long(FvSpaceInfo[1], 0)
             UsedSizeValue = long(FvSpaceInfo[2], 0)
             FreeSizeValue = long(FvSpaceInfo[3], 0)
-            GenFdsGlobalVariable.InfLogger(Name + ' ' + '[' + str((UsedSizeValue+0.0)/TotalSizeValue)[0:4].lstrip('0.') + '%Full] ' + str(TotalSizeValue) + ' total, ' + str(UsedSizeValue) + ' used, ' + str(FreeSizeValue) + ' free')
+            if UsedSizeValue == TotalSizeValue:
+                Percentage = '100'
+            else:
+                Percentage = str((UsedSizeValue+0.0)/TotalSizeValue)[0:4].lstrip('0.') 
+            
+            GenFdsGlobalVariable.InfLogger(Name + ' ' + '[' + Percentage + '%Full] ' + str(TotalSizeValue) + ' total, ' + str(UsedSizeValue) + ' used, ' + str(FreeSizeValue) + ' free')
 
     ## PreprocessImage()
     #
@@ -476,11 +505,24 @@ class GenFds :
             ModuleObj = BuildDb.BuildObject[Key, 'COMMON']
             print ModuleObj.BaseName + ' ' + ModuleObj.ModuleType
 
+    def GenerateGuidXRefFile(BuildDb, ArchList):
+        GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")
+        GuidXRefFile = StringIO.StringIO('')
+        for Arch in ArchList:
+            PlatformDataBase = BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch]
+            for ModuleFile in PlatformDataBase.Modules:
+                Module = BuildDb.BuildObject[ModuleFile, Arch]
+                GuidXRefFile.write("%s %s\n" % (Module.Guid, Module.BaseName))
+        SaveFileOnChange(GuidXRefFileName, GuidXRefFile.getvalue(), False)\r
+        GuidXRefFile.close()
+        GenFdsGlobalVariable.InfLogger("\nGUID cross reference file can be found at %s" % GuidXRefFileName)
+        
     ##Define GenFd as static function
     GenFd = staticmethod(GenFd)
     GetFvBlockSize = staticmethod(GetFvBlockSize)
     DisplayFvSpaceInfo = staticmethod(DisplayFvSpaceInfo)
     PreprocessImage = staticmethod(PreprocessImage)
+    GenerateGuidXRefFile = staticmethod(GenerateGuidXRefFile)
 
 if __name__ == '__main__':
     r = main()