]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GuidSection.py
BaseTools: Update the FV region name as upper letter
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GuidSection.py
index 36ad4f58ef8189f2cb13b2308179baea08b18138..ac5ae585f90f437f9b929f795c2cae3c3d75a46e 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process GUIDed section generation\r
 #\r
-#  Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -18,7 +18,7 @@
 import Section\r
 import subprocess\r
 from Ffs import Ffs\r
-import os\r
+import Common.LongFilePathOs as os\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 from CommonDataClass.FdfClass import GuidSectionClassObject\r
 from Common import ToolDefClassObject\r
@@ -26,6 +26,7 @@ import sys
 from Common import EdkLogger\r
 from Common.BuildToolError import *\r
 from FvImageSection import FvImageSection\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
 ## generate GUIDed section\r
 #\r
@@ -52,7 +53,7 @@ class GuidSection(GuidSectionClassObject) :
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}):\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}):\r
         #\r
         # Generate all section\r
         #\r
@@ -64,7 +65,7 @@ class GuidSection(GuidSectionClassObject) :
             self.SectionType = FfsInf.__ExtendMacro__(self.SectionType)\r
             self.CurrentArchList = [FfsInf.CurrentArch]\r
 \r
-        SectFile  = tuple()\r
+        SectFile = tuple()\r
         SectAlign = []\r
         Index = 0\r
         MaxAlign = None\r
@@ -83,7 +84,7 @@ class GuidSection(GuidSectionClassObject) :
 \r
         for Sect in self.SectionList:\r
             Index = Index + 1\r
-            SecIndex = '%s.%d' %(SecNum,Index)\r
+            SecIndex = '%s.%d' % (SecNum, Index)\r
             # set base address for inside FvImage\r
             if isinstance(Sect, FvImageSection):\r
                 if self.FvAddr != []:\r
@@ -92,7 +93,7 @@ class GuidSection(GuidSectionClassObject) :
             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
+            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
@@ -117,10 +118,10 @@ class GuidSection(GuidSectionClassObject) :
                     self.Alignment = MaxAlign\r
 \r
         OutputFile = OutputPath + \\r
-                     os.sep     + \\r
+                     os.sep + \\r
                      ModuleName + \\r
-                     'SEC'      + \\r
-                     SecNum     + \\r
+                     'SEC' + \\r
+                     SecNum + \\r
                      Ffs.SectionSuffix['GUIDED']\r
         OutputFile = os.path.normpath(OutputFile)\r
 \r
@@ -134,7 +135,7 @@ class GuidSection(GuidSectionClassObject) :
         # GENCRC32 section\r
         #\r
         if self.NameGuid == None :\r
-            GenFdsGlobalVariable.VerboseLogger( "Use GenSection function Generate CRC32 Section")\r
+            GenFdsGlobalVariable.VerboseLogger("Use GenSection function Generate CRC32 Section")\r
             GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType], InputAlign=SectAlign)\r
             OutputFileList = []\r
             OutputFileList.append(OutputFile)\r
@@ -143,7 +144,7 @@ class GuidSection(GuidSectionClassObject) :
         elif ExternalTool == None:\r
             EdkLogger.error("GenFds", GENFDS_ERROR, "No tool found with GUID %s" % self.NameGuid)\r
         else:\r
-            DummyFile = OutputFile+".dummy"\r
+            DummyFile = OutputFile + ".dummy"\r
             #\r
             # Call GenSection with DUMMY section type.\r
             #\r
@@ -152,12 +153,19 @@ class GuidSection(GuidSectionClassObject) :
             # Use external tool process the Output\r
             #\r
             TempFile = OutputPath + \\r
-                       os.sep     + \\r
+                       os.sep + \\r
                        ModuleName + \\r
-                       'SEC'      + \\r
-                       SecNum     + \\r
+                       'SEC' + \\r
+                       SecNum + \\r
                        '.tmp'\r
             TempFile = os.path.normpath(TempFile)\r
+            #\r
+            # Remove temp file if its time stamp is older than dummy file\r
+            # Just in case the external tool fails at this time but succeeded before\r
+            # Error should be reported if the external tool does not generate a new output based on new input\r
+            #\r
+            if os.path.exists(TempFile) and os.path.exists(DummyFile) and os.path.getmtime(TempFile) < os.path.getmtime(DummyFile):\r
+                os.remove(TempFile)\r
 \r
             FirstCall = False\r
             CmdOption = '-e'\r
@@ -182,13 +190,19 @@ class GuidSection(GuidSectionClassObject) :
                 FirstCall = False\r
                 ReturnValue[0] = 0\r
                 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)\r
+            #\r
+            # There is external tool which does not follow standard rule which return nonzero if tool fails\r
+            # The output file has to be checked\r
+            #\r
+            if not os.path.exists(TempFile):\r
+                EdkLogger.error("GenFds", COMMAND_FAILURE, 'Fail to call %s, no output file was generated' % ExternalTool)\r
 \r
-            FileHandleIn = open(DummyFile,'rb')\r
-            FileHandleIn.seek(0,2)\r
+            FileHandleIn = open(DummyFile, 'rb')\r
+            FileHandleIn.seek(0, 2)\r
             InputFileSize = FileHandleIn.tell()\r
-            \r
-            FileHandleOut = open(TempFile,'rb')\r
-            FileHandleOut.seek(0,2)\r
+\r
+            FileHandleOut = open(TempFile, 'rb')\r
+            FileHandleOut.seek(0, 2)\r
             TempFileSize = FileHandleOut.tell()\r
 \r
             Attribute = []\r
@@ -197,9 +211,9 @@ class GuidSection(GuidSectionClassObject) :
                 HeaderLength = str(self.ExtraHeaderSize)\r
 \r
             if self.ProcessRequired == "NONE" and HeaderLength == None:\r
-                if TempFileSize > InputFileSize and TempFileSize % 4 == 0:\r
+                if TempFileSize > InputFileSize:\r
                     FileHandleIn.seek(0)\r
-                    BufferIn  = FileHandleIn.read()\r
+                    BufferIn = FileHandleIn.read()\r
                     FileHandleOut.seek(0)\r
                     BufferOut = FileHandleOut.read()\r
                     if BufferIn == BufferOut[TempFileSize - InputFileSize:]:\r
@@ -210,18 +224,18 @@ class GuidSection(GuidSectionClassObject) :
 \r
             FileHandleIn.close()\r
             FileHandleOut.close()\r
-            \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
             #\r
             # Call Gensection Add Section Header\r
             #\r
             if self.ProcessRequired in ("TRUE", "1"):\r
                 if 'PROCESSING_REQUIRED' not in Attribute:\r
                     Attribute.append('PROCESSING_REQUIRED')\r
-  \r
+\r
             if self.AuthStatusValid in ("TRUE", "1"):\r
                 Attribute.append('AUTH_STATUS_VALID')\r
             GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
@@ -246,44 +260,49 @@ class GuidSection(GuidSectionClassObject) :
         if self.KeyStringList == None or self.KeyStringList == []:\r
             Target = GenFdsGlobalVariable.TargetName\r
             ToolChain = GenFdsGlobalVariable.ToolChainTag\r
-            ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.WorkSpaceDir).ToolsDefTxtDatabase\r
+            ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
             if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:\r
                 EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)\r
-            self.KeyStringList = [Target+'_'+ToolChain+'_'+self.CurrentArchList[0]]\r
+            self.KeyStringList = [Target + '_' + ToolChain + '_' + self.CurrentArchList[0]]\r
             for Arch in self.CurrentArchList:\r
-                if Target+'_'+ToolChain+'_'+Arch not in self.KeyStringList:\r
-                    self.KeyStringList.append(Target+'_'+ToolChain+'_'+Arch)\r
-                    \r
-        ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.WorkSpaceDir).ToolsDefTxtDictionary\r
+                if Target + '_' + ToolChain + '_' + Arch not in self.KeyStringList:\r
+                    self.KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)\r
+\r
+        if GenFdsGlobalVariable.GuidToolDefinition:\r
+            if self.NameGuid in GenFdsGlobalVariable.GuidToolDefinition.keys():\r
+                return GenFdsGlobalVariable.GuidToolDefinition[self.NameGuid]\r
+\r
+        ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
         ToolPathTmp = None\r
+        ToolOption = None\r
         for ToolDef in ToolDefinition.items():\r
             if self.NameGuid == ToolDef[1]:\r
                 KeyList = ToolDef[0].split('_')\r
                 Key = KeyList[0] + \\r
-                      '_'        + \\r
+                      '_' + \\r
                       KeyList[1] + \\r
-                      '_'        + \\r
+                      '_' + \\r
                       KeyList[2]\r
                 if Key in self.KeyStringList and KeyList[4] == 'GUID':\r
 \r
-                    ToolPath = ToolDefinition.get( Key        + \\r
-                                                   '_'        + \\r
+                    ToolPath = ToolDefinition.get(Key + \\r
+                                                   '_' + \\r
                                                    KeyList[3] + \\r
-                                                   '_'        + \\r
+                                                   '_' + \\r
                                                    'PATH')\r
 \r
-                    ToolOption = ToolDefinition.get( Key        + \\r
-                                                    '_'        + \\r
+                    ToolOption = ToolDefinition.get(Key + \\r
+                                                    '_' + \\r
                                                     KeyList[3] + \\r
-                                                    '_'        + \\r
+                                                    '_' + \\r
                                                     'FLAGS')\r
                     if ToolPathTmp == None:\r
                         ToolPathTmp = ToolPath\r
                     else:\r
                         if ToolPathTmp != ToolPath:\r
                             EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
-                            \r
-                    \r
+\r
+        GenFdsGlobalVariable.GuidToolDefinition[self.NameGuid] = (ToolPathTmp, ToolOption)\r
         return ToolPathTmp, ToolOption\r
 \r
 \r