Modify GenFds related files.
authorqouyang <qouyang@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 25 Jul 2007 05:46:24 +0000 (05:46 +0000)
committerqouyang <qouyang@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 25 Jul 2007 05:46:24 +0000 (05:46 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@389 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/Common/EdkIIWorkspaceBuild.py
Source/Python/GenFds/DataSection.py
Source/Python/GenFds/EfiSection.py
Source/Python/GenFds/FfsInfStatement.py
Source/Python/GenFds/Fv.py
Source/Python/GenFds/FvImageSection.py
Source/Python/GenFds/GenFds.py
Source/Python/GenFds/GenFdsGlobalVariable.py
Source/Python/GenFds/Region.py

index 7a32a90..6c7032b 100644 (file)
@@ -336,12 +336,12 @@ class WorkspaceBuild(object):
                     pcd.append(None)\r
                     SkuName = dscObj.Contents[key].PcdsDynamicDefault[index][1]\r
                     SkuInfoList = []\r
-                    if SkuName == None or SkuName == []:\r
+                    if SkuName == None or SkuName == [] or SkuName == ['']:\r
                         SkuName = ['DEFAULT']\r
                     SkuNameList = map(lambda l: l.strip(), SkuName[0].split(DataType.TAB_VALUE_SPLIT))\r
                     for Item in SkuNameList:\r
                         SkuInfo = SkuInfoClass()\r
-                        SkuInfo.SkuId = pb.SkuIds[Item]\r
+                        SkuInfo.SkuId = Item[1]\r
                         SkuInfo.DefaultValue = pcd[2]\r
                         SkuInfoList.append(SkuInfo)\r
                     pb.Pcds[(pcd[0], pcd[1])] = PcdClassObject(pcd[0], pcd[1], DataType.TAB_PCDS_DYNAMIC_DEFAULT, None, None, None, pcd[3], SkuInfoList)\r
index 8551016..35e0b8a 100644 (file)
@@ -26,14 +26,19 @@ class DataSection (Section.Section):
         if not os.path.exists(self.SectFileName):\r
             self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,\r
                                               self.SectFileName)\r
-\r
-        OutputFile = OutputPath + \\r
-                     os.sep     + \\r
-                     ModuleName + \\r
-                     Ffs.SectionSuffix.get(self.SecType)\r
+        if self.SecType == 'TE':\r
+            TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
+            GenTeCmd = 'GenFW -t '    + \\r
+                       ' -o '         + \\r
+                        TeFile        + \\r
+                        ' '           + \\r
+                       GenFdsGlobalVariable.ExtendMarco(self.SectFileName)\r
+            print GenTeCmd\r
+            GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
+            self.SectFileName = TeFile\r
+                 \r
+        OutputFile = os.path.join (OutputPath, ModuleName + Ffs.SectionSuffix.get(self.SecType))\r
         OutputFile = os.path.normpath(OutputFile)\r
-        print "DataSection SectionType: %s" %self.SecType\r
-        print "DataSection SectFileName: %s" %self.SectFileName\r
         \r
         GenSectionCmd = 'GenSec -o '                                     + \\r
                          OutputFile                                      + \\r
index bf713f3..5c723db 100644 (file)
@@ -111,6 +111,20 @@ class EfiSection (Section.Section):
                      return '', None\r
                  else:\r
                      raise Exception(" %s does't exist" %Filename)\r
+             #\r
+             # For TE Section call GenFw to generate TE image\r
+             #\r
+             if SectionType == 'TE':\r
+                 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
+                 GenTeCmd = 'GenFW -t '    + \\r
+                            ' -o '         + \\r
+                             TeFile        + \\r
+                             ' '           + \\r
+                             GenFdsGlobalVariable.ExtendMarco(Filename)\r
+                 print GenTeCmd\r
+                 GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
+                 Filename = TeFile\r
+\r
                  \r
              GenSectionCmd = 'GenSec -o '                                     + \\r
                               OutputFile                                      + \\r
index 3b91098..d25b705 100644 (file)
@@ -7,6 +7,8 @@ import sys
 import Section\r
 import RuleSimpleFile\r
 import RuleComplexFile\r
+import Common.TargetTxtClassObject\r
+\r
 #from String import *\r
 \r
 class FfsInfStatement(Ffs.Ffs):\r
@@ -18,7 +20,6 @@ class FfsInfStatement(Ffs.Ffs):
         self.InfFileName = None\r
         self.BuildNum = ''\r
         self.KeyStringList = []\r
-        self.RuleOverride = None\r
 \r
     def __infParse__(self):\r
         #\r
@@ -69,7 +70,7 @@ class FfsInfStatement(Ffs.Ffs):
         # Get the rule of how to generate Ffs file\r
         #\r
         Rule = self.__GetRule__()\r
-                                                       \r
+\r
         FileType = Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]\r
         #\r
         # For the rule only has simpleFile\r
@@ -105,57 +106,90 @@ class FfsInfStatement(Ffs.Ffs):
         return String\r
 \r
     def __GetRule__ (self) :\r
-        currentArch = 'IA32'\r
+        currentArchList = self.__GetCurrentArch__()\r
+        \r
         #for item in GenFdsGlobalVariable.FdfParser.profile.RuleDict :\r
         #    print item\r
+        for currentArch in currentArchList:\r
+            RuleName = 'RULE'              + \\r
+                       '.'                 + \\r
+                       currentArch.upper() + \\r
+                       '.'                 + \\r
+                       self.ModuleType.upper()\r
+            if self.Rule != None:\r
+                RuleName = RuleName + \\r
+                           '.'      + \\r
+                           self.Rule.upper()\r
+                           \r
+            Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)\r
+            if Rule != None:\r
+                print "Want To Find Rule Name is : " + RuleName\r
+                return Rule\r
+            \r
         RuleName = 'RULE'      + \\r
                    '.'         + \\r
-                   currentArch + \\r
+                   'COMMON'    + \\r
                    '.'         + \\r
                    self.ModuleType.upper()\r
-        \r
+        if self.Rule != None:\r
+            RuleName = RuleName + \\r
+                       '.'      + \\r
+                       self.Rule.upper()\r
+                       \r
         Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)\r
-        if Rule == None :\r
-            RuleName = 'RULE'      + \\r
-                       '.'         + \\r
-                       'COMMON'    + \\r
-                       '.'         + \\r
-                       self.ModuleType.upper()\r
+        if Rule != None:\r
             print "Want To Find Rule Name is : " + RuleName\r
-            Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)\r
-            if Rule == None :\r
-                print 'Dont Find Related Rule, Using Default Rule !!!'\r
-                if GenFdsGlobalVariable.DefaultRule == None:\r
-                    raise Exception ("Default Rule doesn't exist!!")\r
+            return Rule\r
+\r
+        if Rule == None :\r
+            print 'Dont Find Related Rule, Using Default Rule !!!'\r
+            if GenFdsGlobalVariable.DefaultRule == None:\r
+                raise Exception ("Default Rule doesn't exist!!")\r
+            else:\r
                 return GenFdsGlobalVariable.DefaultRule\r
-        print "Want To Find Rule Name is : " + RuleName\r
-        return Rule\r
+\r
+    def __GetCurrentArch__(self):\r
+        Target = Common.TargetTxtClassObject.TargetTxtDict(GenFdsGlobalVariable.WorkSpaceDir)\r
+        targetArchList = Target.TargetTxtDictionary['TARGET_ARCH']\r
+        #targetArchList = GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary["TARGET_ARCH"]\r
+        if len(targetArchList) == 0:\r
+            targetArchList = GenFdsGlobalVariable.WorkSpace.SupArchList\r
+        else:\r
+            targetArchList = set(GenFdsGlobalVariable.WorkSpace.SupArchList) & set(targetArchList)\r
+            \r
+        #activePlatform = GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary.get('ACTIVE_PLATFORM')[0]\r
+        dscArchList = []\r
+        if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('IA32').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):\r
+            dscArchList.append ('IA32')\r
+        if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('X64').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):\r
+            dscArchList.append ('X64')\r
+        if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('IPF').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):\r
+            dscArchList.append ('IPF')\r
+\r
+        curArchList = set (targetArchList) & set (dscArchList)\r
+        print "Valid target architecture(s) is", " ".join(curArchList)\r
+        return curArchList\r
     \r
     def __GetEFIOutPutPath__(self):\r
-        Flag = False\r
         Arch = ''\r
         OutputPath = ''\r
         (ModulePath, fileName) = os.path.split(self.InfFileName)\r
         index = fileName.find('.')\r
         fileName = fileName[0:index]\r
-        Platform = os.path.normpath(GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary["ACTIVE_PLATFORM"][0])\r
-        targetArchList = GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary["TARGET_ARCH"]\r
-        if len(targetArchList) == 0:\r
-            myArchList = GenFdsGlobalVariable.WorkSpace.SupArchList\r
-        else:\r
-            myArchList = set(GenFdsGlobalVariable.WorkSpace.SupArchList) & set(targetArchList)\r
-            print "Valid target architecture(s) is", " ".join(myArchList)\r
 \r
-        if len(myArchList) > 1 :\r
+        curArchList = self.__GetCurrentArch__()\r
+        if len(curArchList) > 1 :\r
             for Key in self.KeyStringList:\r
                 Target, Tag, Arch = Key.split('_')\r
                 ArchList = set (ArchList) & Arch\r
-                if ArchList == 1:\r
-                    Arch = ArchList[0]\r
-                else:\r
-                    raise Exception("Module %s has too many bulid Arch !" %self.InfFileNames)\r
-        elif len(myArchList) == 1 :\r
-            Arch = myArchList.pop()\r
+            if len(ArchList) == 1:\r
+                Arch = ArchList[0]\r
+            elif len(ArchList) > 1:\r
+                raise Exception("Module %s has too many bulid Arch !" %self.InfFileNames)\r
+            else:\r
+                raise Exception("Don't find legal Arch in Module %s !" %self.InfFileNames)\r
+        elif len(curArchList) == 1 :\r
+            Arch = curArchList.pop()\r
             \r
         OutputPath = os.path.join(GenFdsGlobalVariable.OuputDir,\r
                                   Arch ,\r
@@ -163,7 +197,8 @@ class FfsInfStatement(Ffs.Ffs):
                                   fileName,\r
                                   'OUTPUT'\r
                                   )\r
-        OutputPath = os.path.normcase(OutputPath)\r
+                                  \r
+        OutputPath = os.path.realpath(OutputPath)\r
         return OutputPath\r
         \r
     def __GenSimpleFileSection__(self, Rule):\r
@@ -230,7 +265,10 @@ class FfsInfStatement(Ffs.Ffs):
         for Sect in Rule.SectionList:\r
            #print 'GenSection: %s %s :' %(self.OutputPath ,self.ModuleGuid)\r
            secName = ''\r
-           secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, self.KeyStringList, self)\r
+           if Rule.KeyStringList != []:\r
+               secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, Rule.KeyStringList, self)\r
+           else :\r
+               secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, self.KeyStringList, self)\r
            if secName != '':\r
                SectFiles = SectFiles    + \\r
                            ' -i '       + \\r
index 096ca38..5ca4579 100644 (file)
@@ -74,7 +74,7 @@ class FV:
         #\r
         fv = open ( FvOutputFile,'r+b')\r
                    \r
-        print "Write the Fv contents to buffer"\r
+        print "Generate %s Fv Successful" %self.UiFvName\r
               \r
         Buffer.write(fv.read())\r
         fv.close\r
index 9ee4e5a..0465565 100644 (file)
@@ -3,6 +3,7 @@ import StringIO
 from Ffs import Ffs\r
 import subprocess\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
+import os\r
 \r
 class FvImageSection(Section.Section):\r
     def __init__(self):\r
@@ -23,22 +24,13 @@ class FvImageSection(Section.Section):
                                  FvImageSection both in FvUiName and \\r
                                  FvImageArg!")\r
                                  \r
-        self.Fv.AddToBuffer(Buffer)\r
-        \r
-        FvFileName = OutputPath + \\r
-                     ModuleName + \\r
-                     '.fv'\r
-        FvFile = open ( FvFileName, 'w+')\r
-        FvFile.write(Buffer.getvalue())\r
-        FvFile.close()\r
+        FvFileName = self.Fv.AddToBuffer(Buffer)\r
         #\r
         # Prepare the parameter of GenSection\r
         #\r
-        OutputFile = OutputPath + \\r
-                     ModuleName + \\r
-                     Ffs.SectionSuffix.get("FV_IMAGE")\r
+        OutputFile = os.path.join(OutputPath, ModuleName + Ffs.SectionSuffix.get("FV_IMAGE"))\r
                      \r
-        GenSectionCmd = 'GenSec -o '                      + \\r
+        GenSectionCmd = 'GenSec -o '                          + \\r
                          OutputFile                           + \\r
                          ' -s '                               + \\r
                          'EFI_SECTION_FIRMWARE_VOLUME_IMAGE ' + \\r
index f2b4b80..56bc568 100644 (file)
@@ -7,6 +7,7 @@ import Common.EdkIIWorkspaceBuild
 import RuleComplexFile\r
 from EfiSection import EfiSection\r
 import StringIO\r
+import Common.TargetTxtClassObject\r
 \r
 versionNumber = "1.0"\r
 __version__ = "%prog Version " + versionNumber\r
@@ -25,6 +26,7 @@ def main():
         sys.exit(1)\r
     else:\r
         workspace = options.workspace\r
+        GenFdsGlobalVariable.WorkSpaceDir = workspace\r
         if (options.debug):\r
             print "Using Workspace:", workspace\r
 \r
@@ -41,7 +43,11 @@ def main():
     if (options.activePlatform):\r
         activePlatform = options.activePlatform\r
     else :\r
-        activePlatform = None\r
+        Target = Common.TargetTxtClassObject.TargetTxtDict(GenFdsGlobalVariable.WorkSpaceDir)\r
+        activePlatform = Target.TargetTxtDictionary['ACTIVE_PLATFORM']\r
+        \r
+    GenFdsGlobalVariable.ActivePlatform = activePlatform\r
+\r
         \r
     if (options.outputDir):\r
         outputDir = options.outputDir\r
@@ -60,7 +66,8 @@ def main():
     \r
     """call workspace build create database"""\r
     os.environ["WORKSPACE"] = workspace\r
-    buildWorkSpace = Common.EdkIIWorkspaceBuild.WorkspaceBuild(activePlatform)\r
+    buildWorkSpace = Common.EdkIIWorkspaceBuild.WorkspaceBuild(activePlatform, workspace)\r
+    buildWorkSpace.GenBuildDatabase()\r
     \r
     """Call GenFds"""\r
     GenFds.GenFd(outputDir, fdfParser, buildWorkSpace, archList)\r
index aa64e0e..732953a 100644 (file)
@@ -13,7 +13,7 @@ class GenFdsGlobalVariable:
     DefaultRule = None\r
     ArchList = None\r
     VtfDict = {}\r
-    \r
+    ActivePlatform = None\r
     def ExtendMarco (String):\r
         return String\r
     \r
@@ -24,19 +24,21 @@ class GenFdsGlobalVariable:
         GenFdsGlobalVariable.WorkSpace = WorkSpace\r
         GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OuputDir, 'Fv')\r
         GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
-        GenFdsGlobalVariable.WorkSpaceDir = GenFdsGlobalVariable.WorkSpace.Workspace.WorkspaceDir\r
         if ArchList != None:\r
             GenFdsGlobalVariable.ArchList = ArchList\r
             \r
         if not os.path.exists(GenFdsGlobalVariable.FvDir) :\r
             os.makedirs(GenFdsGlobalVariable.FvDir)\r
-            \r
+        \r
     def SetDefaultRule (Rule) :\r
         GenFdsGlobalVariable.DefaultRule = Rule\r
 \r
     def ReplaceWorkspaceMarco(String):\r
         Str = String.replace('$(WORKSPACE)', GenFdsGlobalVariable.WorkSpaceDir)\r
-        Str = os.path.realpath(Str)\r
+        if os.path.exists(Str):\r
+            Str = os.path.realpath(Str)\r
+        else:\r
+            Str = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, String)\r
         return Str\r
     \r
     def CallExternalTool (cmd, errorMess):\r
index 6e21c9d..249addf 100644 (file)
@@ -36,11 +36,20 @@ class region:
                 #\r
                 # Call GenFv tool\r
                 #\r
+                \r
                 self.FvAddress = int(BaseAddress, 16) + self.Offset\r
                 BlockSize = self.__BlockSizeOfRegion__(BlockSizeList)\r
                 BlockNum = self.__BlockNumOfRegion__(BlockSize)\r
                 FvBaseAddress = '0x%x' %self.FvAddress\r
                 FileName = fv.AddToBuffer(Buffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict)\r
+                BinFile = open (FileName, 'r+b')\r
+                FvBuffer = StringIO.StringIO('')\r
+                FvBuffer.write(BinFile.read())\r
+                if FvBuffer.len > Size:\r
+                    raise Exception ("Size of Fv (%s) is large than Region Size ", self.RegionData)\r
+                elif FvBuffer.len < Size :\r
+                    raise Exception ("Size of Fv (%s) is less than Region Size ", self.RegionData)\r
+                FvBuffer.close()\r
                 FvBinDict[self.RegionData.upper()] = FileName\r
 \r
         if self.RegionType == 'FILE':\r