Update GenFds tool to support the guided data generation for the fixuped sub FvImage...
authorlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Sat, 9 Jan 2010 07:37:03 +0000 (07:37 +0000)
committerlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Sat, 9 Jan 2010 07:37:03 +0000 (07:37 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1796 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/CommonDataClass/FdfClass.py
Source/Python/GenFds/FfsFileStatement.py
Source/Python/GenFds/FfsInfStatement.py
Source/Python/GenFds/Fv.py
Source/Python/GenFds/GenFdsGlobalVariable.py
Source/Python/GenFds/GuidSection.py

index 140795a..a6953b8 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # classes represent data in FDF\r
 #\r
-#  Copyright (c) 2007, Intel Corporation\r
+#  Copyright (c) 2007 - 2010, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -249,7 +249,9 @@ class GuidSectionClassObject (SectionClassObject) :
         self.SectionType = None\r
         self.ProcessRequired = False\r
         self.AuthStatusValid = False\r
-        self.FvAddr = None\r
+        self.FvAddr = []\r
+        self.FvParentAddr = None\r
+        self.IncludeFvSection = False\r
 \r
 ## UI section data in FDF\r
 #\r
index 56297a8..b0b1b00 100755 (executable)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FFS generation from FILE statement\r
 #\r
-#  Copyright (c) 2007, Intel Corporation\r
+#  Copyright (c) 2007 - 2010, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -44,11 +44,13 @@ class FileStatement (FileStatementClassObject) :
     #\r
     #   Generate FFS\r
     #\r
-    #   @param  self        The object pointer\r
-    #   @param  Dict        dictionary contains macro and value pair\r
-    #   @retval string      Generated FFS file name\r
+    #   @param  self         The object pointer\r
+    #   @param  Dict         dictionary contains macro and value pair\r
+    #   @param  FvChildAddr  Array of the inside FvImage base address\r
+    #   @param  FvParentAddr Parent Fv base address\r
+    #   @retval string       Generated FFS file name\r
     #\r
-    def GenFfs(self, Dict = {}, FvAddr=[]):\r
+    def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None):\r
         \r
         if self.NameGuid != None and self.NameGuid.startswith('PCD('):\r
             PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)\r
@@ -96,12 +98,14 @@ class FileStatement (FileStatementClassObject) :
                 Index = Index + 1\r
                 SecIndex = '%d' %Index\r
                 # process the inside FvImage from FvSection or GuidSection\r
-                if FvAddr != []:\r
+                if FvChildAddr != []:\r
                     if isinstance(section, FvImageSection):\r
-                        section.FvAddr = FvAddr.pop(0)\r
+                        section.FvAddr = FvChildAddr.pop(0)\r
                     elif isinstance(section, GuidSection):\r
-                        if section.ProcessRequired == False:\r
-                            section.FvAddr = FvAddr.pop(0)\r
+                        section.FvAddr = FvChildAddr\r
+                if FvParentAddr != None and isinstance(section, GuidSection):\r
+                    section.FvParentAddr = FvParentAddr\r
+\r
                 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)\r
                 if sectList != []:\r
                     for sect in sectList:\r
index e9a90ee..b053edc 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FFS generation from INF statement\r
 #\r
-#  Copyright (c) 2007, Intel Corporation\r
+#  Copyright (c) 2007 - 2010, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -31,6 +31,8 @@ from Common.Misc import PathClass
 from Common.Misc import GuidStructureByteArrayToGuidString\r
 from Common import EdkLogger\r
 from Common.BuildToolError import *\r
+from GuidSection import GuidSection\r
+from FvImageSection import FvImageSection\r
 \r
 ## generate FFS from INF\r
 #\r
@@ -146,11 +148,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #\r
     #   Generate FFS\r
     #\r
-    #   @param  self        The object pointer\r
-    #   @param  Dict        dictionary contains macro and value pair\r
-    #   @retval string      Generated FFS file name\r
+    #   @param  self         The object pointer\r
+    #   @param  Dict         dictionary contains macro and value pair\r
+    #   @param  FvChildAddr  Array of the inside FvImage base address\r
+    #   @param  FvParentAddr Parent Fv base address\r
+    #   @retval string       Generated FFS file name\r
     #\r
-    def GenFfs(self, Dict = {}, FvAddr = []):\r
+    def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None):\r
         #\r
         # Parse Inf file get Module related information\r
         #\r
@@ -184,7 +188,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         # For Rule has ComplexFile\r
         #\r
         elif isinstance(Rule, RuleComplexFile.RuleComplexFile):\r
-            InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule)\r
+            InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule, FvChildAddr, FvParentAddr)\r
             FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList, InputSectAlignments)\r
 \r
             return FfsOutput\r
@@ -589,11 +593,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #\r
     #   Generate section by sections in Rule\r
     #\r
-    #   @param  self        The object pointer\r
-    #   @param  Rule        The rule object used to generate section\r
-    #   @retval string      File name of the generated section file\r
+    #   @param  self         The object pointer\r
+    #   @param  Rule         The rule object used to generate section\r
+    #   @param  FvChildAddr  Array of the inside FvImage base address\r
+    #   @param  FvParentAddr Parent Fv base address\r
+    #   @retval string       File name of the generated section file\r
     #\r
-    def __GenComplexFileSection__(self, Rule):\r
+    def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr):\r
         if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
             if Rule.KeepReloc != None:\r
                 self.KeepRelocFromRule = Rule.KeepReloc\r
@@ -615,6 +621,17 @@ class FfsInfStatement(FfsInfStatementClassObject):
             if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion < 0x0001000A:\r
                 if Sect.SectionType == 'SMM_DEPEX':\r
                     EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)\r
+            #\r
+            # process the inside FvImage from FvSection or GuidSection\r
+            #\r
+            if FvChildAddr != []:\r
+                if isinstance(Sect, FvImageSection):\r
+                    Sect.FvAddr = FvChildAddr.pop(0)\r
+                elif isinstance(Sect, GuidSection):\r
+                    Sect.FvAddr = FvChildAddr\r
+            if FvParentAddr != None and isinstance(Sect, GuidSection):\r
+                Sect.FvParentAddr = FvParentAddr\r
+            \r
             if Rule.KeyStringList != []:\r
                 SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)\r
             else :\r
index 976516c..d7471f7 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FV generation\r
 #\r
-#  Copyright (c) 2007, Intel Corporation\r
+#  Copyright (c) 2007 - 2010, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -103,7 +103,7 @@ class FV (FvClassObject):
 \r
         # Process Modules in FfsList\r
         for FfsFile in self.FfsList :\r
-            FileName = FfsFile.GenFfs(MacroDict)\r
+            FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress)\r
             FfsFileList.append(FileName)\r
             self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
                                        FileName          + \\r
@@ -131,22 +131,22 @@ class FV (FvClassObject):
                                 )\r
 \r
         if os.path.getmtime(FvInfoFileName) > oldtime:\r
-            FvAddrString = []\r
+            FvChildAddr = []\r
             AddFileObj = open(FvInfoFileName, 'r')\r
             AddrStrings = AddFileObj.readlines()\r
             AddrKeyFound = False\r
             for AddrString in AddrStrings:\r
                 if AddrKeyFound:\r
                     #get base address for the inside FvImage\r
-                    FvAddrString.append (AddrString)\r
+                    FvChildAddr.append (AddrString)\r
                 elif AddrString.find ("[FV_BASE_ADDRESS]") != -1:\r
                     AddrKeyFound = True\r
             AddFileObj.close()\r
 \r
-            if FvAddrString != []:\r
+            if FvChildAddr != []:\r
                 # Update Ffs again\r
                 for FfsFile in self.FfsList :\r
-                    FileName = FfsFile.GenFfs(MacroDict, FvAddr=FvAddrString)\r
+                    FileName = FfsFile.GenFfs(MacroDict, FvChildAddr, BaseAddress)\r
                 \r
                 #Update GenFv again\r
                 GenFdsGlobalVariable.GenerateFirmwareVolume(\r
index e9af852..6dfe246 100644 (file)
@@ -1,7 +1,7 @@
 ## @file
 # Global variables for GenFds
 #
-#  Copyright (c) 2007, Intel Corporation
+#  Copyright (c) 2007 - 2010, Intel Corporation
 #
 #  All rights reserved. This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -346,18 +346,19 @@ class GenFdsGlobalVariable:
         GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")
 
     @staticmethod
-    def GuidTool(Output, Input, ToolPath, Options=''):
+    def GuidTool(Output, Input, ToolPath, Options='', returnValue=[]):
         if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):
             return
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
 
-        Cmd = [ToolPath, Options]
+        Cmd = [ToolPath, ]
+        Cmd += Options.split(' ')
         Cmd += ["-o", Output]
         Cmd += Input
 
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath)
+        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)
 
-    def CallExternalTool (cmd, errorMess):
+    def CallExternalTool (cmd, errorMess, returnValue=[]):
 
         if type(cmd) not in (tuple, list):
             GenFdsGlobalVariable.ErrorLogger("ToolError!  Invalid parameter type in call to CallExternalTool")
@@ -384,6 +385,10 @@ class GenFdsGlobalVariable:
 
         while PopenObject.returncode == None :
             PopenObject.wait()
+        if returnValue != [] and returnValue[0] != 0:
+            #get command return value
+            returnValue[0] = PopenObject.returncode
+            return
         if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:
             GenFdsGlobalVariable.InfLogger ("Return Value = %d" %PopenObject.returncode)
             GenFdsGlobalVariable.InfLogger (out)
index ef0cfe8..f24724e 100755 (executable)
@@ -1,7 +1,7 @@
 ## @file\r
 # process GUIDed section generation\r
 #\r
-#  Copyright (c) 2007, Intel Corporation\r
+#  Copyright (c) 2007 - 2010, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -68,13 +68,35 @@ class GuidSection(GuidSectionClassObject) :
         SectAlign = []\r
         Index = 0\r
         MaxAlign = None\r
+        if self.FvAddr != []:\r
+            FvAddrIsSet = True\r
+        else:\r
+            FvAddrIsSet = False\r
+        \r
+        if self.ProcessRequired in ("TRUE", "1"):\r
+            if self.FvAddr != []:\r
+                #no use FvAddr when the image is processed.\r
+                self.FvAddr = []\r
+            if self.FvParentAddr != None:\r
+                #no use Parent Addr when the image is processed.\r
+                self.FvParentAddr = None\r
+\r
         for Sect in self.SectionList:\r
             Index = Index + 1\r
             SecIndex = '%s.%d' %(SecNum,Index)\r
             # set base address for inside FvImage\r
             if isinstance(Sect, FvImageSection):\r
+                if self.FvAddr != []:\r
+                    Sect.FvAddr = self.FvAddr.pop(0)\r
+                self.IncludeFvSection = True\r
+            elif isinstance(Sect, GuidSection):\r
                 Sect.FvAddr = self.FvAddr\r
+                Sect.FvParentAddr = self.FvParentAddr\r
             ReturnSectList, align = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList,FfsInf, Dict)\r
+            if isinstance(Sect, GuidSection):\r
+                if Sect.IncludeFvSection:\r
+                    self.IncludeFvSection = Sect.IncludeFvSection\r
+\r
             if align != None:\r
                 if MaxAlign == None:\r
                     MaxAlign = align\r
@@ -103,8 +125,10 @@ class GuidSection(GuidSectionClassObject) :
         OutputFile = os.path.normpath(OutputFile)\r
 \r
         ExternalTool = None\r
+        ExternalOption = None\r
         if self.NameGuid != None:\r
-            ExternalTool = self.__FindExtendTool__()\r
+            ExternalTool, ExternalOption = self.__FindExtendTool__()\r
+\r
         #\r
         # If not have GUID , call default\r
         # GENCRC32 section\r
@@ -135,10 +159,29 @@ class GuidSection(GuidSectionClassObject) :
                        '.tmp'\r
             TempFile = os.path.normpath(TempFile)\r
 \r
+            FirstCall = False\r
+            CmdOption = '-e'\r
+            if ExternalOption != None:\r
+                CmdOption = CmdOption + ' ' + ExternalOption\r
+            if self.ProcessRequired not in ("TRUE", "1") and self.IncludeFvSection and not FvAddrIsSet and self.FvParentAddr != None:\r
+                #FirstCall is only set for the encapsulated flash FV image without process required attribute.\r
+                FirstCall = True\r
             #\r
             # Call external tool\r
             #\r
-            GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, '-e')\r
+            ReturnValue = [1]\r
+            if FirstCall:\r
+                #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.\r
+                GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, '-z' + ' ' + CmdOption, ReturnValue)\r
+\r
+            #\r
+            # when no call or first call failed, ReturnValue are not 1.\r
+            # Call the guided tool with CmdOption\r
+            #\r
+            if ReturnValue[0] != 0:\r
+                FirstCall = False\r
+                ReturnValue[0] = 0\r
+                GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)\r
 \r
             FileHandleIn = open(DummyFile,'rb')\r
             FileHandleIn.seek(0,2)\r
@@ -164,6 +207,10 @@ class GuidSection(GuidSectionClassObject) :
             FileHandleIn.close()\r
             FileHandleOut.close()\r
             \r
+            if FirstCall and 'PROCESSING_REQUIRED' in Attribute:\r
+                # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.\r
+                GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)\r
+            \r
             #\r
             # Call Gensection Add Section Header\r
             #\r
@@ -180,6 +227,8 @@ class GuidSection(GuidSectionClassObject) :
             if 'PROCESSING_REQUIRED' in Attribute:\r
                 # reset guided section alignment to none for the processed required guided data\r
                 self.Alignment = None\r
+                self.IncludeFvSection = False\r
+                self.ProcessRequired = "TRUE"\r
             return OutputFileList, self.Alignment\r
 \r
     ## __FindExtendTool()\r
@@ -218,6 +267,12 @@ class GuidSection(GuidSectionClassObject) :
                                                    KeyList[3] + \\r
                                                    '_'        + \\r
                                                    'PATH')\r
+\r
+                    ToolOption = ToolDefinition.get( Key        + \\r
+                                                    '_'        + \\r
+                                                    KeyList[3] + \\r
+                                                    '_'        + \\r
+                                                    'FLAGS')\r
                     if ToolPathTmp == None:\r
                         ToolPathTmp = ToolPath\r
                     else:\r
@@ -225,7 +280,7 @@ class GuidSection(GuidSectionClassObject) :
                             EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
                             \r
                     \r
-        return ToolPathTmp\r
+        return ToolPathTmp, ToolOption\r
 \r
 \r
 \r