]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GuidSection.py
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
)
165 if ExternalOption
!= None:
166 CmdOption
= CmdOption
+ ' ' + ExternalOption
167 if self
.ProcessRequired
not in ("TRUE", "1") and self
.IncludeFvSection
and not FvAddrIsSet
and self
.FvParentAddr
!= None:
168 #FirstCall is only set for the encapsulated flash FV image without process required attribute.
175 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.
176 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, '-z' + ' ' + CmdOption
, ReturnValue
)
179 # when no call or first call failed, ReturnValue are not 1.
180 # Call the guided tool with CmdOption
182 if ReturnValue
[0] != 0:
185 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
187 FileHandleIn
= open(DummyFile
,'rb')
188 FileHandleIn
.seek(0,2)
189 InputFileSize
= FileHandleIn
.tell()
191 FileHandleOut
= open(TempFile
,'rb')
192 FileHandleOut
.seek(0,2)
193 TempFileSize
= FileHandleOut
.tell()
197 if self
.ExtraHeaderSize
!= -1:
198 HeaderLength
= str(self
.ExtraHeaderSize
)
200 if self
.ProcessRequired
== "NONE" and HeaderLength
== None:
201 if TempFileSize
> InputFileSize
:
203 BufferIn
= FileHandleIn
.read()
204 FileHandleOut
.seek(0)
205 BufferOut
= FileHandleOut
.read()
206 if BufferIn
== BufferOut
[TempFileSize
- InputFileSize
:]:
207 HeaderLength
= str(TempFileSize
- InputFileSize
)
208 #auto sec guided attribute with process required
209 if HeaderLength
== None:
210 Attribute
.append('PROCESSING_REQUIRED')
213 FileHandleOut
.close()
215 if FirstCall
and 'PROCESSING_REQUIRED' in Attribute
:
216 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.
217 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
220 # Call Gensection Add Section Header
222 if self
.ProcessRequired
in ("TRUE", "1"):
223 if 'PROCESSING_REQUIRED' not in Attribute
:
224 Attribute
.append('PROCESSING_REQUIRED')
226 if self
.AuthStatusValid
in ("TRUE", "1"):
227 Attribute
.append('AUTH_STATUS_VALID')
228 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
229 Guid
=self
.NameGuid
, GuidAttr
=Attribute
, GuidHdrLen
=HeaderLength
)
231 OutputFileList
.append(OutputFile
)
232 if 'PROCESSING_REQUIRED' in Attribute
:
233 # reset guided section alignment to none for the processed required guided data
234 self
.Alignment
= None
235 self
.IncludeFvSection
= False
236 self
.ProcessRequired
= "TRUE"
237 return OutputFileList
, self
.Alignment
239 ## __FindExtendTool()
241 # Find location of tools to process section data
243 # @param self The object pointer
245 def __FindExtendTool__(self
):
246 # if user not specify filter, try to deduce it from global data.
247 if self
.KeyStringList
== None or self
.KeyStringList
== []:
248 Target
= GenFdsGlobalVariable
.TargetName
249 ToolChain
= GenFdsGlobalVariable
.ToolChainTag
250 ToolDb
= ToolDefClassObject
.ToolDefDict(GenFdsGlobalVariable
.ConfDir
).ToolsDefTxtDatabase
251 if ToolChain
not in ToolDb
['TOOL_CHAIN_TAG']:
252 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain
)
253 self
.KeyStringList
= [Target
+'_'+ToolChain
+'_'+self
.CurrentArchList
[0]]
254 for Arch
in self
.CurrentArchList
:
255 if Target
+ '_' + ToolChain
+ '_' + Arch
not in self
.KeyStringList
:
256 self
.KeyStringList
.append(Target
+ '_' + ToolChain
+ '_' + Arch
)
258 ToolDefinition
= ToolDefClassObject
.ToolDefDict(GenFdsGlobalVariable
.ConfDir
).ToolsDefTxtDictionary
260 for ToolDef
in ToolDefinition
.items():
261 if self
.NameGuid
== ToolDef
[1]:
262 KeyList
= ToolDef
[0].split('_')
268 if Key
in self
.KeyStringList
and KeyList
[4] == 'GUID':
270 ToolPath
= ToolDefinition
.get( Key
+ \
276 ToolOption
= ToolDefinition
.get( Key
+ \
281 if ToolPathTmp
== None:
282 ToolPathTmp
= ToolPath
284 if ToolPathTmp
!= ToolPath
:
285 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp
, ToolPath
))
288 return ToolPathTmp
, ToolOption