]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GuidSection.py
2 # process GUIDed section generation
4 # Copyright (c) 2007 - 2017, 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
30 from GenFds
import FindExtendTool
32 ## generate GUIDed section
35 class GuidSection(GuidSectionClassObject
) :
39 # @param self The object pointer
42 GuidSectionClassObject
.__init
__(self
)
44 ## GenSection() method
46 # Generate GUIDed section
48 # @param self The object pointer
49 # @param OutputPath Where to place output file
50 # @param ModuleName Which module this section belongs to
51 # @param SecNum Index of section
52 # @param KeyStringList Filter for inputs of section generation
53 # @param FfsInf FfsInfStatement object that contains this section data
54 # @param Dict dictionary contains macro and its value
55 # @retval tuple (Generated file name, section alignment)
57 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
=None, Dict
={}, IsMakefile
=False):
59 # Generate all section
61 self
.KeyStringList
= KeyStringList
62 self
.CurrentArchList
= GenFdsGlobalVariable
.ArchList
64 self
.Alignment
= FfsInf
.__ExtendMacro
__(self
.Alignment
)
65 self
.NameGuid
= FfsInf
.__ExtendMacro
__(self
.NameGuid
)
66 self
.SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
67 self
.CurrentArchList
= [FfsInf
.CurrentArch
]
78 if self
.ProcessRequired
in ("TRUE", "1"):
80 #no use FvAddr when the image is processed.
82 if self
.FvParentAddr
!= None:
83 #no use Parent Addr when the image is processed.
84 self
.FvParentAddr
= None
86 for Sect
in self
.SectionList
:
88 SecIndex
= '%s.%d' % (SecNum
, Index
)
89 # set base address for inside FvImage
90 if isinstance(Sect
, FvImageSection
):
92 Sect
.FvAddr
= self
.FvAddr
.pop(0)
93 self
.IncludeFvSection
= True
94 elif isinstance(Sect
, GuidSection
):
95 Sect
.FvAddr
= self
.FvAddr
96 Sect
.FvParentAddr
= self
.FvParentAddr
97 ReturnSectList
, align
= Sect
.GenSection(OutputPath
, ModuleName
, SecIndex
, KeyStringList
, FfsInf
, Dict
, IsMakefile
=IsMakefile
)
98 if isinstance(Sect
, GuidSection
):
99 if Sect
.IncludeFvSection
:
100 self
.IncludeFvSection
= Sect
.IncludeFvSection
105 if GenFdsGlobalVariable
.GetAlignment (align
) > GenFdsGlobalVariable
.GetAlignment (MaxAlign
):
107 if ReturnSectList
!= []:
110 for file in ReturnSectList
:
112 SectAlign
.append(align
)
115 if self
.Alignment
== None:
116 self
.Alignment
= MaxAlign
118 if GenFdsGlobalVariable
.GetAlignment (MaxAlign
) > GenFdsGlobalVariable
.GetAlignment (self
.Alignment
):
119 self
.Alignment
= MaxAlign
121 OutputFile
= OutputPath
+ \
126 Ffs
.SectionSuffix
['GUIDED']
127 OutputFile
= os
.path
.normpath(OutputFile
)
130 ExternalOption
= None
131 if self
.NameGuid
!= None:
132 ExternalTool
, ExternalOption
= FindExtendTool(self
.KeyStringList
, self
.CurrentArchList
, self
.NameGuid
)
135 # If not have GUID , call default
138 if self
.NameGuid
== None :
139 GenFdsGlobalVariable
.VerboseLogger("Use GenSection function Generate CRC32 Section")
140 GenFdsGlobalVariable
.GenerateSection(OutputFile
, SectFile
, Section
.Section
.SectionType
[self
.SectionType
], InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
142 OutputFileList
.append(OutputFile
)
143 return OutputFileList
, self
.Alignment
144 #or GUID not in External Tool List
145 elif ExternalTool
== None:
146 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No tool found with GUID %s" % self
.NameGuid
)
148 DummyFile
= OutputFile
+ ".dummy"
150 # Call GenSection with DUMMY section type.
152 GenFdsGlobalVariable
.GenerateSection(DummyFile
, SectFile
, InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
154 # Use external tool process the Output
156 TempFile
= OutputPath
+ \
162 TempFile
= os
.path
.normpath(TempFile
)
164 # Remove temp file if its time stamp is older than dummy file
165 # Just in case the external tool fails at this time but succeeded before
166 # Error should be reported if the external tool does not generate a new output based on new input
168 if os
.path
.exists(TempFile
) and os
.path
.exists(DummyFile
) and os
.path
.getmtime(TempFile
) < os
.path
.getmtime(DummyFile
):
173 if ExternalOption
!= None:
174 CmdOption
= CmdOption
+ ' ' + ExternalOption
175 if not GenFdsGlobalVariable
.EnableGenfdsMultiThread
:
176 if self
.ProcessRequired
not in ("TRUE", "1") and self
.IncludeFvSection
and not FvAddrIsSet
and self
.FvParentAddr
!= None:
177 #FirstCall is only set for the encapsulated flash FV image without process required attribute.
184 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.
185 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, '-z' + ' ' + CmdOption
, ReturnValue
)
188 # when no call or first call failed, ReturnValue are not 1.
189 # Call the guided tool with CmdOption
191 if ReturnValue
[0] != 0:
194 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
196 # There is external tool which does not follow standard rule which return nonzero if tool fails
197 # The output file has to be checked
200 if not os
.path
.exists(TempFile
) :
201 EdkLogger
.error("GenFds", COMMAND_FAILURE
, 'Fail to call %s, no output file was generated' % ExternalTool
)
203 FileHandleIn
= open(DummyFile
, 'rb')
204 FileHandleIn
.seek(0, 2)
205 InputFileSize
= FileHandleIn
.tell()
207 FileHandleOut
= open(TempFile
, 'rb')
208 FileHandleOut
.seek(0, 2)
209 TempFileSize
= FileHandleOut
.tell()
213 if self
.ExtraHeaderSize
!= -1:
214 HeaderLength
= str(self
.ExtraHeaderSize
)
216 if self
.ProcessRequired
== "NONE" and HeaderLength
== None:
217 if TempFileSize
> InputFileSize
:
219 BufferIn
= FileHandleIn
.read()
220 FileHandleOut
.seek(0)
221 BufferOut
= FileHandleOut
.read()
222 if BufferIn
== BufferOut
[TempFileSize
- InputFileSize
:]:
223 HeaderLength
= str(TempFileSize
- InputFileSize
)
224 #auto sec guided attribute with process required
225 if HeaderLength
== None:
226 Attribute
.append('PROCESSING_REQUIRED')
229 FileHandleOut
.close()
231 if FirstCall
and 'PROCESSING_REQUIRED' in Attribute
:
232 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.
233 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
236 # Call Gensection Add Section Header
238 if self
.ProcessRequired
in ("TRUE", "1"):
239 if 'PROCESSING_REQUIRED' not in Attribute
:
240 Attribute
.append('PROCESSING_REQUIRED')
242 if self
.AuthStatusValid
in ("TRUE", "1"):
243 Attribute
.append('AUTH_STATUS_VALID')
244 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
245 Guid
=self
.NameGuid
, GuidAttr
=Attribute
, GuidHdrLen
=HeaderLength
)
248 #add input file for GenSec get PROCESSING_REQUIRED
249 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
, IsMakefile
=IsMakefile
)
252 if self
.ExtraHeaderSize
!= -1:
253 HeaderLength
= str(self
.ExtraHeaderSize
)
254 if self
.AuthStatusValid
in ("TRUE", "1"):
255 Attribute
.append('AUTH_STATUS_VALID')
256 if self
.ProcessRequired
== "NONE" and HeaderLength
== None:
257 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
258 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
259 GuidHdrLen
=HeaderLength
, DummyFile
=DummyFile
, IsMakefile
=IsMakefile
)
261 if self
.ProcessRequired
in ("TRUE", "1"):
262 if 'PROCESSING_REQUIRED' not in Attribute
:
263 Attribute
.append('PROCESSING_REQUIRED')
264 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
265 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
266 GuidHdrLen
=HeaderLength
, IsMakefile
=IsMakefile
)
269 OutputFileList
.append(OutputFile
)
270 if 'PROCESSING_REQUIRED' in Attribute
:
271 # reset guided section alignment to none for the processed required guided data
272 self
.Alignment
= None
273 self
.IncludeFvSection
= False
274 self
.ProcessRequired
= "TRUE"
275 return OutputFileList
, self
.Alignment