## @file\r
# process GUIDed section generation\r
#\r
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<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
-# which accompanies this distribution. The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
##\r
# Import Modules\r
#\r
-import Section\r
+from __future__ import absolute_import\r
+from . import Section\r
import subprocess\r
-from Ffs import Ffs\r
-import os\r
-from GenFdsGlobalVariable import GenFdsGlobalVariable\r
+from .Ffs import SectionSuffix\r
+import Common.LongFilePathOs as os\r
+from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
+from .GenFdsGlobalVariable import FindExtendTool\r
from CommonDataClass.FdfClass import GuidSectionClassObject\r
-from Common import ToolDefClassObject\r
import sys\r
from Common import EdkLogger\r
from Common.BuildToolError import *\r
-from FvImageSection import FvImageSection\r
+from .FvImageSection import FvImageSection\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.DataType import *\r
\r
## generate GUIDed section\r
#\r
# @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={}, IsMakefile=False):\r
#\r
# Generate all section\r
#\r
self.KeyStringList = KeyStringList\r
self.CurrentArchList = GenFdsGlobalVariable.ArchList\r
- if FfsInf != None:\r
+ if FfsInf is not None:\r
self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)\r
self.NameGuid = FfsInf.__ExtendMacro__(self.NameGuid)\r
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
FvAddrIsSet = True\r
else:\r
FvAddrIsSet = False\r
- \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
+ if self.FvParentAddr is not 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
+ SecIndex = '%s.%d' % (SecNum, Index)\r
# set base address for inside FvImage\r
if isinstance(Sect, FvImageSection):\r
if self.FvAddr != []:\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
+ ReturnSectList, align = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList, FfsInf, Dict, IsMakefile=IsMakefile)\r
if isinstance(Sect, GuidSection):\r
if Sect.IncludeFvSection:\r
self.IncludeFvSection = Sect.IncludeFvSection\r
\r
- if align != None:\r
- if MaxAlign == None:\r
+ if align is not None:\r
+ if MaxAlign is None:\r
MaxAlign = align\r
if GenFdsGlobalVariable.GetAlignment (align) > GenFdsGlobalVariable.GetAlignment (MaxAlign):\r
MaxAlign = align\r
if ReturnSectList != []:\r
- if align == None:\r
+ if align is None:\r
align = "1"\r
for file in ReturnSectList:\r
SectFile += (file,)\r
SectAlign.append(align)\r
\r
- if MaxAlign != None:\r
- if self.Alignment == None:\r
+ if MaxAlign is not None:\r
+ if self.Alignment is None:\r
self.Alignment = MaxAlign\r
else:\r
if GenFdsGlobalVariable.GetAlignment (MaxAlign) > GenFdsGlobalVariable.GetAlignment (self.Alignment):\r
self.Alignment = MaxAlign\r
\r
OutputFile = OutputPath + \\r
- os.sep + \\r
+ os.sep + \\r
ModuleName + \\r
- 'SEC' + \\r
- SecNum + \\r
- Ffs.SectionSuffix['GUIDED']\r
+ SUP_MODULE_SEC + \\r
+ SecNum + \\r
+ SectionSuffix['GUIDED']\r
OutputFile = os.path.normpath(OutputFile)\r
\r
ExternalTool = None\r
ExternalOption = None\r
- if self.NameGuid != None:\r
- ExternalTool, ExternalOption = self.__FindExtendTool__()\r
+ if self.NameGuid is not None:\r
+ ExternalTool, ExternalOption = FindExtendTool(self.KeyStringList, self.CurrentArchList, self.NameGuid)\r
\r
#\r
# If not have GUID , call default\r
# GENCRC32 section\r
#\r
- if self.NameGuid == None :\r
- GenFdsGlobalVariable.VerboseLogger( "Use GenSection function Generate CRC32 Section")\r
- GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType], InputAlign=SectAlign)\r
+ if self.NameGuid is None :\r
+ GenFdsGlobalVariable.VerboseLogger("Use GenSection function Generate CRC32 Section")\r
+ GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType], InputAlign=SectAlign, IsMakefile=IsMakefile)\r
OutputFileList = []\r
OutputFileList.append(OutputFile)\r
return OutputFileList, self.Alignment\r
#or GUID not in External Tool List\r
- elif ExternalTool == None:\r
+ elif ExternalTool is 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
- GenFdsGlobalVariable.GenerateSection(DummyFile, SectFile, InputAlign=SectAlign)\r
+ GenFdsGlobalVariable.GenerateSection(DummyFile, SectFile, InputAlign=SectAlign, IsMakefile=IsMakefile)\r
#\r
# Use external tool process the Output\r
#\r
TempFile = OutputPath + \\r
- os.sep + \\r
+ os.sep + \\r
ModuleName + \\r
- 'SEC' + \\r
- SecNum + \\r
+ SUP_MODULE_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
- if ExternalOption != None:\r
+ if ExternalOption is not 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
- 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
+ if not GenFdsGlobalVariable.EnableGenfdsMultiThread:\r
+ if self.ProcessRequired not in ("TRUE", "1") and self.IncludeFvSection and not FvAddrIsSet and self.FvParentAddr is not 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
+ 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
+ # 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
+ # 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
\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
- TempFileSize = FileHandleOut.tell()\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
- Attribute = []\r
- HeaderLength = None\r
- if self.ProcessRequired == "NONE":\r
- if TempFileSize > InputFileSize and TempFileSize % 4 == 0:\r
- FileHandleIn.seek(0)\r
- BufferIn = FileHandleIn.read()\r
- FileHandleOut.seek(0)\r
- BufferOut = FileHandleOut.read()\r
- if BufferIn == BufferOut[TempFileSize - InputFileSize:]:\r
- HeaderLength = str(TempFileSize - InputFileSize)\r
- #auto sec guided attribute with process required\r
- if HeaderLength == None:\r
- Attribute.append('PROCESSING_REQUIRED')\r
+ FileHandleIn = open(DummyFile, 'rb')\r
+ FileHandleIn.seek(0, 2)\r
+ InputFileSize = FileHandleIn.tell()\r
\r
- 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
- if self.ProcessRequired in ("TRUE", "1"):\r
- if 'PROCESSING_REQUIRED' not in Attribute:\r
- Attribute.append('PROCESSING_REQUIRED')\r
+ FileHandleOut = open(TempFile, 'rb')\r
+ FileHandleOut.seek(0, 2)\r
+ TempFileSize = FileHandleOut.tell()\r
+\r
+ Attribute = []\r
HeaderLength = None\r
- if self.AuthStatusValid in ("TRUE", "1"):\r
- Attribute.append('AUTH_STATUS_VALID')\r
- GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
- Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength)\r
+ if self.ExtraHeaderSize != -1:\r
+ HeaderLength = str(self.ExtraHeaderSize)\r
+\r
+ if self.ProcessRequired == "NONE" and HeaderLength is None:\r
+ if TempFileSize > InputFileSize:\r
+ FileHandleIn.seek(0)\r
+ BufferIn = FileHandleIn.read()\r
+ FileHandleOut.seek(0)\r
+ BufferOut = FileHandleOut.read()\r
+ if BufferIn == BufferOut[TempFileSize - InputFileSize:]:\r
+ HeaderLength = str(TempFileSize - InputFileSize)\r
+ #auto sec guided attribute with process required\r
+ if HeaderLength is None:\r
+ Attribute.append('PROCESSING_REQUIRED')\r
+\r
+ 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
+ if self.ProcessRequired in ("TRUE", "1"):\r
+ if 'PROCESSING_REQUIRED' not in Attribute:\r
+ Attribute.append('PROCESSING_REQUIRED')\r
+\r
+ if self.AuthStatusValid in ("TRUE", "1"):\r
+ Attribute.append('AUTH_STATUS_VALID')\r
+ GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
+ Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength)\r
+\r
+ else:\r
+ #add input file for GenSec get PROCESSING_REQUIRED\r
+ GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption, IsMakefile=IsMakefile)\r
+ Attribute = []\r
+ HeaderLength = None\r
+ if self.ExtraHeaderSize != -1:\r
+ HeaderLength = str(self.ExtraHeaderSize)\r
+ if self.AuthStatusValid in ("TRUE", "1"):\r
+ Attribute.append('AUTH_STATUS_VALID')\r
+ if self.ProcessRequired == "NONE" and HeaderLength is None:\r
+ GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
+ Guid=self.NameGuid, GuidAttr=Attribute,\r
+ GuidHdrLen=HeaderLength, DummyFile=DummyFile, IsMakefile=IsMakefile)\r
+ else:\r
+ if self.ProcessRequired in ("TRUE", "1"):\r
+ if 'PROCESSING_REQUIRED' not in Attribute:\r
+ Attribute.append('PROCESSING_REQUIRED')\r
+ GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
+ Guid=self.NameGuid, GuidAttr=Attribute,\r
+ GuidHdrLen=HeaderLength, IsMakefile=IsMakefile)\r
+\r
OutputFileList = []\r
OutputFileList.append(OutputFile)\r
if 'PROCESSING_REQUIRED' in Attribute:\r
self.Alignment = None\r
self.IncludeFvSection = False\r
self.ProcessRequired = "TRUE"\r
+ if IsMakefile and self.Alignment is not None and self.Alignment.strip() == '0':\r
+ self.Alignment = '1'\r
return OutputFileList, self.Alignment\r
\r
- ## __FindExtendTool()\r
- #\r
- # Find location of tools to process section data\r
- #\r
- # @param self The object pointer\r
- #\r
- def __FindExtendTool__(self):\r
- # if user not specify filter, try to deduce it from global data.\r
- if self.KeyStringList == None or self.KeyStringList == []:\r
- Target = GenFdsGlobalVariable.TargetName\r
- ToolChain = GenFdsGlobalVariable.ToolChainTag\r
- ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.WorkSpaceDir).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
- 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
- ToolPathTmp = None\r
- for ToolDef in ToolDefinition.items():\r
- if self.NameGuid == ToolDef[1]:\r
- KeyList = ToolDef[0].split('_')\r
- Key = KeyList[0] + \\r
- '_' + \\r
- KeyList[1] + \\r
- '_' + \\r
- KeyList[2]\r
- if Key in self.KeyStringList and KeyList[4] == 'GUID':\r
-\r
- ToolPath = ToolDefinition.get( Key + \\r
- '_' + \\r
- 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
- if ToolPathTmp != ToolPath:\r
- EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
- \r
- \r
- return ToolPathTmp, ToolOption\r
-\r
\r
\r