GenFds Tool: Add a feature of "copy *.map files to FFS output directory"
authorqouyang <qouyang@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 1 Aug 2007 05:56:52 +0000 (05:56 +0000)
committerqouyang <qouyang@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 1 Aug 2007 05:56:52 +0000 (05:56 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@465 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/GenFds/DataSection.py
Source/Python/GenFds/EfiSection.py
Source/Python/GenFds/GenFds.py

index 57ed27c..2460239 100644 (file)
@@ -4,6 +4,7 @@ import subprocess
 from Ffs import Ffs\r
 import os\r
 from CommonDataClass.FdfClassObject import DataSectionClassObject\r
+import shutil\r
 \r
 class DataSection (DataSectionClassObject):\r
     def __init__(self):\r
@@ -43,7 +44,14 @@ class DataSection (DataSectionClassObject):
                          Section.Section.SectionType.get (self.SecType)  + \\r
                          ' '                                             + \\r
                          GenFdsGlobalVariable.ExtendMarco(self.SectFileName)\r
-\r
+                         \r
+        """Copy Map file to Ffs output"""\r
+        Filename = GenFdsGlobalVariable.ExtendMarco(self.SectFileName)\r
+        if Filename[(len(Filename)-4):] == '.efi':\r
+             MapFile = Filename.replace('.efi', '.map')\r
+             if os.path.exists(MapFile):\r
+                 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
+                 shutil.copyfile(MapFile, CopyMapFile)\r
         #\r
         # Call GenSection\r
         #\r
index 24778ef..129d4fe 100644 (file)
@@ -4,7 +4,7 @@ import subprocess
 from Ffs import Ffs\r
 import os\r
 from CommonDataClass.FdfClassObject import EfiSectionClassObject\r
-\r
+import shutil\r
 class EfiSection (EfiSectionClassObject):\r
     \r
     def __init__(self):\r
@@ -67,6 +67,7 @@ class EfiSection (EfiSectionClassObject):
                              ' -s EFI_SECTION_VERSION'  + \\r
                              VerString                  + \\r
                              BuildNumString\r
+            \r
         #\r
         # If Section Type is 'UI'\r
         #\r
@@ -125,6 +126,15 @@ class EfiSection (EfiSectionClassObject):
                               Section.Section.SectionType.get (SectionType)   + \\r
                               ' '                                             + \\r
                               GenFdsGlobalVariable.ExtendMarco(Filename)\r
+\r
+             """ Copy Map file to FFS output path """\r
+             Filename = GenFdsGlobalVariable.ExtendMarco(Filename)\r
+             if Filename[(len(Filename)-4):] == '.efi':\r
+                 MapFile = Filename.replace('.efi', '.map')\r
+                 if os.path.exists(MapFile):\r
+                     CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
+                     shutil.copyfile(MapFile, CopyMapFile)\r
+\r
         #\r
         # Call GenSection\r
         #\r
index e312fca..5b77f05 100644 (file)
@@ -42,18 +42,30 @@ def main():
 \r
     if (options.filename):\r
         fdfFilename = options.filename\r
+        fdfFilename = GenFdsGlobalVariable.ReplaceWorkspaceMarco(fdfFilename)\r
     else:\r
         GenFdsGlobalVariable.InfLogger("ERROR: E0001 - You must specify an input filename")\r
         sys.exit(1)\r
 \r
+    if fdfFilename[0:2] == '..':\r
+        fdfFilename = os.path.realpath(fdfFilename)\r
+    if fdfFilename[1] != ':':\r
+        fdfFilename = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, fdfFilename)\r
+            \r
     if not os.path.exists(fdfFilename):\r
-        GenFdsGlobalVariable.InfLogger ("ERROR: E1000: File %s not found" % (filename))\r
+        GenFdsGlobalVariable.InfLogger ("ERROR: E1000: File %s not found" % (fdfFilename))\r
         sys.exit(1)\r
 \r
     if (options.activePlatform):\r
         activePlatform = options.activePlatform\r
-        activePlatform = os.path.realpath(activePlatform)\r
-        \r
+        activePlatform = GenFdsGlobalVariable.ReplaceWorkspaceMarco(activePlatform)\r
+\r
+        if activePlatform[0:2] == '..':\r
+            activePlatform = os.path.realpath(activePlatform)\r
+\r
+        if activePlatform[1] != ':':\r
+            activePlatform = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, activePlatform)\r
+\r
         if not os.path.exists(activePlatform)  :\r
             raise Exception ("ActivePlatform doesn't exist!")\r
         \r
@@ -74,16 +86,33 @@ def main():
         \r
     if (options.outputDir):\r
         outputDir = options.outputDir\r
+        outputDir = GenFdsGlobalVariable.ReplaceWorkspaceMarco(outputDir)\r
     else:\r
         #print "ERROR: E0001 - You must specify an Output directory"\r
         GenFdsGlobalVariable.InfLogger("ERROR: E0001 - You must specify an Output directory")\r
         sys.exit(1)\r
+\r
+    if outputDir[0:2] == '..':\r
+        outputDir = os.path.realpath(outputDir)\r
         \r
+    if outputDir[1] != ':':\r
+        outputDir = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, outputDir)\r
+\r
+    if not os.path.exists(outputDir):\r
+        GenFdsGlobalVariable.InfLogger ("ERROR: E1000: Directory %s not found" % (outputDir))\r
+        sys.exit(1)\r
+\r
     if (options.archList) :\r
         archList = options.archList.split(',')\r
     else:\r
         Target = Common.TargetTxtClassObject.TargetTxtDict(GenFdsGlobalVariable.WorkSpaceDir)\r
         archList = Target.TargetTxtDictionary['TARGET_ARCH']\r
+\r
+    if (options.uiFdName) :\r
+        GenFds.currentFd = options.uiFdName\r
+\r
+    if (options.uiFvName) :\r
+        GenFds.currentFv = options.uiFvName\r
         \r
     """ Parse Fdf file """\r
     fdfParser = FdfParser.FdfParser(fdfFilename)\r
@@ -102,13 +131,14 @@ def myOptionParser():
     parser = OptionParser(usage=usage,description=__copyright__,version="%prog " + str(versionNumber))\r
     parser.add_option("-f", "--file", dest="filename", help="Name of FDF file to convert")\r
     parser.add_option("-a", "--arch", dest="archList", help="comma separated list containing one or more of: IA32, X64, IPF or EBC which should be built, overrides target.txt?s TARGET_ARCH")\r
-    parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False, help="Set Interactive mode, user must approve each change.")\r
     parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")\r
     parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed.")\r
     parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")\r
     parser.add_option("-p", "--platform", dest="activePlatform", help="Set the Active platform")\r
     parser.add_option("-w", "--workspace", dest="workspace", default=str(os.environ.get('WORKSPACE')), help="Enable printing of debug messages.")\r
     parser.add_option("-o", "--outputDir", dest="outputDir", help="Name of Output directory")\r
+    parser.add_option("-r", "--rom_image", dest="uiFdName", help="Build the image using the [FD] section named by FdUiName.")\r
+    parser.add_option("-i", "--FvImage", dest="uiFvName", help="Buld the FV image using the [FV] section named by UiFvName")\r
     (options, args) = parser.parse_args()\r
     return options\r
 \r
@@ -116,9 +146,12 @@ def myOptionParser():
 class GenFds :\r
     FdfParsef = None\r
     FvBinDict = {}      # FvName in Fdf, FvBinFile\r
+    currentFd = None\r
+    currentFv = None\r
     \r
     def GenFd (OutputDir, FdfParser, WorkSpace, ArchList):\r
         GenFdsGlobalVariable.SetDir (OutputDir, FdfParser, WorkSpace, ArchList)\r
+        \r
         """Set Default Rule! Hard code here will be move"""\r
         verSection1 = EfiSection()\r
         verSection1.BuildNum = "$(BUILD_NUMBER)"\r
@@ -136,7 +169,7 @@ class GenFds :
         dataSection.Filename = "$(INF_OUTPUT)/$(MODULE_NAME).efi"\r
 \r
         ruleComplexFile1 = RuleComplexFile.RuleComplexFile()\r
-        ruleComplexFile1.Alignment = 16\r
+        ruleComplexFile1.Alignment = 32\r
         ruleComplexFile1.Arch = 'COMMON'\r
         ruleComplexFile1.CheckSum = True\r
         ruleComplexFile1.Fixed = True\r
@@ -148,17 +181,30 @@ class GenFds :
         GenFdsGlobalVariable.SetDefaultRule(ruleComplexFile1)\r
 \r
         GenFdsGlobalVariable.VerboseLogger("   Gen Fd  !")\r
-        for item in GenFdsGlobalVariable.FdfParser.profile.FdDict.keys():\r
-            fd = GenFdsGlobalVariable.FdfParser.profile.FdDict[item]\r
-            fd.GenFd(GenFds.FvBinDict)\r
+        if GenFds.currentFd != None:\r
+            fd = GenFdsGlobalVariable.FdfParser.profile.FdDict.get(GenFds.currentFd.upper())\r
+            if fd != None:\r
+                fd.GenFd(GenFds.FvBinDict)\r
+        else :\r
+            for item in GenFdsGlobalVariable.FdfParser.profile.FdDict.keys():\r
+                fd = GenFdsGlobalVariable.FdfParser.profile.FdDict[item]\r
+                fd.GenFd(GenFds.FvBinDict)\r
             \r
         GenFdsGlobalVariable.VerboseLogger(" Gen FV ! ")\r
-        for FvName in GenFdsGlobalVariable.FdfParser.profile.FvDict.keys():\r
-            if not FvName in GenFds.FvBinDict.keys():\r
+        if GenFds.currentFv != None:\r
+            fv = GenFdsGlobalVariable.FdfParser.profile.FvDict.get(GenFds.currentFv.upper())\r
+            if fv != None:\r
                 Buffer = StringIO.StringIO()\r
-                fv = GenFdsGlobalVariable.FdfParser.profile.FvDict[FvName]\r
                 fv.AddToBuffer(Buffer)\r
                 Buffer.close()\r
+                \r
+        else:\r
+            for FvName in GenFdsGlobalVariable.FdfParser.profile.FvDict.keys():\r
+                if not FvName in GenFds.FvBinDict.keys():\r
+                    Buffer = StringIO.StringIO()\r
+                    fv = GenFdsGlobalVariable.FdfParser.profile.FvDict[FvName]\r
+                    fv.AddToBuffer(Buffer)\r
+                    Buffer.close()\r
         \r
         GenFdsGlobalVariable.VerboseLogger(" Gen Capsule !")\r
         for capsule in GenFdsGlobalVariable.FdfParser.profile.CapsuleList:\r