]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GuidSection.py
006cf0f2169bb7ce2ea754fcc0a769d081c8bb2d
2 # process GUIDed section generation
4 # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 import Common
.LongFilePathOs
as os
22 from GenFdsGlobalVariable
import GenFdsGlobalVariable
23 from CommonDataClass
.FdfClass
import GuidSectionClassObject
24 from Common
import ToolDefClassObject
26 from Common
import EdkLogger
27 from Common
.BuildToolError
import *
28 from FvImageSection
import FvImageSection
29 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
31 ## generate GUIDed section
34 class GuidSection(GuidSectionClassObject
) :
38 # @param self The object pointer
41 GuidSectionClassObject
.__init
__(self
)
43 ## GenSection() method
45 # Generate GUIDed section
47 # @param self The object pointer
48 # @param OutputPath Where to place output file
49 # @param ModuleName Which module this section belongs to
50 # @param SecNum Index of section
51 # @param KeyStringList Filter for inputs of section generation
52 # @param FfsInf FfsInfStatement object that contains this section data
53 # @param Dict dictionary contains macro and its value
54 # @retval tuple (Generated file name, section alignment)
56 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}):
58 # Generate all section
60 self
.KeyStringList
= KeyStringList
61 self
.CurrentArchList
= GenFdsGlobalVariable
.ArchList
63 self
.Alignment
= FfsInf
.__ExtendMacro
__(self
.Alignment
)
64 self
.NameGuid
= FfsInf
.__ExtendMacro
__(self
.NameGuid
)
65 self
.SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
66 self
.CurrentArchList
= [FfsInf
.CurrentArch
]
77 if self
.ProcessRequired
in ("TRUE", "1"):
79 #no use FvAddr when the image is processed.
81 if self
.FvParentAddr
!= None:
82 #no use Parent Addr when the image is processed.
83 self
.FvParentAddr
= None
85 for Sect
in self
.SectionList
:
87 SecIndex
= '%s.%d' %(SecNum
,Index
)
88 # set base address for inside FvImage
89 if isinstance(Sect
, FvImageSection
):
91 Sect
.FvAddr
= self
.FvAddr
.pop(0)
92 self
.IncludeFvSection
= True
93 elif isinstance(Sect
, GuidSection
):
94 Sect
.FvAddr
= self
.FvAddr
95 Sect
.FvParentAddr
= self
.FvParentAddr
96 ReturnSectList
, align
= Sect
.GenSection(OutputPath
, ModuleName
, SecIndex
, KeyStringList
,FfsInf
, Dict
)
97 if isinstance(Sect
, GuidSection
):
98 if Sect
.IncludeFvSection
:
99 self
.IncludeFvSection
= Sect
.IncludeFvSection
104 if GenFdsGlobalVariable
.GetAlignment (align
) > GenFdsGlobalVariable
.GetAlignment (MaxAlign
):
106 if ReturnSectList
!= []:
109 for file in ReturnSectList
:
111 SectAlign
.append(align
)
114 if self
.Alignment
== None:
115 self
.Alignment
= MaxAlign
117 if GenFdsGlobalVariable
.GetAlignment (MaxAlign
) > GenFdsGlobalVariable
.GetAlignment (self
.Alignment
):
118 self
.Alignment
= MaxAlign
120 OutputFile
= OutputPath
+ \
125 Ffs
.SectionSuffix
['GUIDED']
126 OutputFile
= os
.path
.normpath(OutputFile
)
129 ExternalOption
= None
130 if self
.NameGuid
!= None:
131 ExternalTool
, ExternalOption
= self
.__FindExtendTool
__()
134 # If not have GUID , call default
137 if self
.NameGuid
== None :
138 GenFdsGlobalVariable
.VerboseLogger( "Use GenSection function Generate CRC32 Section")
139 GenFdsGlobalVariable
.GenerateSection(OutputFile
, SectFile
, Section
.Section
.SectionType
[self
.SectionType
], InputAlign
=SectAlign
)
141 OutputFileList
.append(OutputFile
)
142 return OutputFileList
, self
.Alignment
143 #or GUID not in External Tool List
144 elif ExternalTool
== None:
145 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No tool found with GUID %s" % self
.NameGuid
)
147 DummyFile
= OutputFile
+".dummy"
149 # Call GenSection with DUMMY section type.
151 GenFdsGlobalVariable
.GenerateSection(DummyFile
, SectFile
, InputAlign
=SectAlign
)
153 # Use external tool process the Output
155 TempFile
= OutputPath
+ \
161 TempFile
= os
.path
.normpath(TempFile
)
163 # Remove temp file if its time stamp is older than dummy file
164 # Just in case the external tool fails at this time but succeeded before
165 # Error should be reported if the external tool does not generate a new output based on new input
167 if os
.path
.exists(TempFile
) and os
.path
.exists(DummyFile
) and os
.path
.getmtime(TempFile
) < os
.path
.getmtime(DummyFile
):
172 if ExternalOption
!= None:
173 CmdOption
= CmdOption
+ ' ' + ExternalOption
174 if self
.ProcessRequired
not in ("TRUE", "1") and self
.IncludeFvSection
and not FvAddrIsSet
and self
.FvParentAddr
!= None:
175 #FirstCall is only set for the encapsulated flash FV image without process required attribute.
182 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.
183 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, '-z' + ' ' + CmdOption
, ReturnValue
)
186 # when no call or first call failed, ReturnValue are not 1.
187 # Call the guided tool with CmdOption
189 if ReturnValue
[0] != 0:
192 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
194 # There is external tool which does not follow standard rule which return nonzero if tool fails
195 # The output file has to be checked
197 if not os
.path
.exists(TempFile
):
198 EdkLogger
.error("GenFds", COMMAND_FAILURE
, 'Fail to call %s, no output file was generated' % ExternalTool
)
200 FileHandleIn
= open(DummyFile
,'rb')
201 FileHandleIn
.seek(0,2)
202 InputFileSize
= FileHandleIn
.tell()
204 FileHandleOut
= open(TempFile
,'rb')
205 FileHandleOut
.seek(0,2)
206 TempFileSize
= FileHandleOut
.tell()
210 if self
.ExtraHeaderSize
!= -1:
211 HeaderLength
= str(self
.ExtraHeaderSize
)
213 if self
.ProcessRequired
== "NONE" and HeaderLength
== None:
214 if TempFileSize
> InputFileSize
:
216 BufferIn
= FileHandleIn
.read()
217 FileHandleOut
.seek(0)
218 BufferOut
= FileHandleOut
.read()
219 if BufferIn
== BufferOut
[TempFileSize
- InputFileSize
:]:
220 HeaderLength
= str(TempFileSize
- InputFileSize
)
221 #auto sec guided attribute with process required
222 if HeaderLength
== None:
223 Attribute
.append('PROCESSING_REQUIRED')
226 FileHandleOut
.close()
228 if FirstCall
and 'PROCESSING_REQUIRED' in Attribute
:
229 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.
230 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
233 # Call Gensection Add Section Header
235 if self
.ProcessRequired
in ("TRUE", "1"):
236 if 'PROCESSING_REQUIRED' not in Attribute
:
237 Attribute
.append('PROCESSING_REQUIRED')
239 if self
.AuthStatusValid
in ("TRUE", "1"):
240 Attribute
.append('AUTH_STATUS_VALID')
241 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
242 Guid
=self
.NameGuid
, GuidAttr
=Attribute
, GuidHdrLen
=HeaderLength
)
244 OutputFileList
.append(OutputFile
)
245 if 'PROCESSING_REQUIRED' in Attribute
:
246 # reset guided section alignment to none for the processed required guided data
247 self
.Alignment
= None
248 self
.IncludeFvSection
= False
249 self
.ProcessRequired
= "TRUE"
250 return OutputFileList
, self
.Alignment
252 ## __FindExtendTool()
254 # Find location of tools to process section data
256 # @param self The object pointer
258 def __FindExtendTool__(self
):
259 # if user not specify filter, try to deduce it from global data.
260 if self
.KeyStringList
== None or self
.KeyStringList
== []:
261 Target
= GenFdsGlobalVariable
.TargetName
262 ToolChain
= GenFdsGlobalVariable
.ToolChainTag
263 ToolDb
= ToolDefClassObject
.ToolDefDict(GenFdsGlobalVariable
.ConfDir
).ToolsDefTxtDatabase
264 if ToolChain
not in ToolDb
['TOOL_CHAIN_TAG']:
265 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain
)
266 self
.KeyStringList
= [Target
+'_'+ToolChain
+'_'+self
.CurrentArchList
[0]]
267 for Arch
in self
.CurrentArchList
:
268 if Target
+ '_' + ToolChain
+ '_' + Arch
not in self
.KeyStringList
:
269 self
.KeyStringList
.append(Target
+ '_' + ToolChain
+ '_' + Arch
)
271 ToolDefinition
= ToolDefClassObject
.ToolDefDict(GenFdsGlobalVariable
.ConfDir
).ToolsDefTxtDictionary
274 for ToolDef
in ToolDefinition
.items():
275 if self
.NameGuid
== ToolDef
[1]:
276 KeyList
= ToolDef
[0].split('_')
282 if Key
in self
.KeyStringList
and KeyList
[4] == 'GUID':
284 ToolPath
= ToolDefinition
.get( Key
+ \
290 ToolOption
= ToolDefinition
.get( Key
+ \
295 if ToolPathTmp
== None:
296 ToolPathTmp
= ToolPath
298 if ToolPathTmp
!= ToolPath
:
299 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp
, ToolPath
))
302 return ToolPathTmp
, ToolOption