]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GuidSection.py
2 # process GUIDed section generation
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
13 from __future__
import absolute_import
16 from .Ffs
import SectionSuffix
17 import Common
.LongFilePathOs
as os
18 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
19 from .GenFdsGlobalVariable
import FindExtendTool
20 from CommonDataClass
.FdfClass
import GuidSectionClassObject
22 from Common
import EdkLogger
23 from Common
.BuildToolError
import *
24 from .FvImageSection
import FvImageSection
25 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
26 from Common
.DataType
import *
28 ## generate GUIDed section
31 class GuidSection(GuidSectionClassObject
) :
35 # @param self The object pointer
38 GuidSectionClassObject
.__init
__(self
)
40 ## GenSection() method
42 # Generate GUIDed section
44 # @param self The object pointer
45 # @param OutputPath Where to place output file
46 # @param ModuleName Which module this section belongs to
47 # @param SecNum Index of section
48 # @param KeyStringList Filter for inputs of section generation
49 # @param FfsInf FfsInfStatement object that contains this section data
50 # @param Dict dictionary contains macro and its value
51 # @retval tuple (Generated file name, section alignment)
53 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
=None, Dict
=None, IsMakefile
=False):
55 # Generate all section
57 self
.KeyStringList
= KeyStringList
58 self
.CurrentArchList
= GenFdsGlobalVariable
.ArchList
59 if FfsInf
is not None:
60 self
.Alignment
= FfsInf
.__ExtendMacro
__(self
.Alignment
)
61 self
.NameGuid
= FfsInf
.__ExtendMacro
__(self
.NameGuid
)
62 self
.SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
63 self
.CurrentArchList
= [FfsInf
.CurrentArch
]
76 if self
.ProcessRequired
in ("TRUE", "1"):
78 #no use FvAddr when the image is processed.
80 if self
.FvParentAddr
is not None:
81 #no use Parent Addr when the image is processed.
82 self
.FvParentAddr
= None
84 for Sect
in self
.SectionList
:
86 SecIndex
= '%s.%d' % (SecNum
, Index
)
87 # set base address for inside FvImage
88 if isinstance(Sect
, FvImageSection
):
90 Sect
.FvAddr
= self
.FvAddr
.pop(0)
91 self
.IncludeFvSection
= True
92 elif isinstance(Sect
, GuidSection
):
93 Sect
.FvAddr
= self
.FvAddr
94 Sect
.FvParentAddr
= self
.FvParentAddr
95 ReturnSectList
, align
= Sect
.GenSection(OutputPath
, ModuleName
, SecIndex
, KeyStringList
, FfsInf
, Dict
, IsMakefile
=IsMakefile
)
96 if isinstance(Sect
, GuidSection
):
97 if Sect
.IncludeFvSection
:
98 self
.IncludeFvSection
= Sect
.IncludeFvSection
100 if align
is not None:
103 if GenFdsGlobalVariable
.GetAlignment (align
) > GenFdsGlobalVariable
.GetAlignment (MaxAlign
):
105 if ReturnSectList
!= []:
108 for file in ReturnSectList
:
110 SectAlign
.append(align
)
112 if MaxAlign
is not None:
113 if self
.Alignment
is None:
114 self
.Alignment
= MaxAlign
116 if GenFdsGlobalVariable
.GetAlignment (MaxAlign
) > GenFdsGlobalVariable
.GetAlignment (self
.Alignment
):
117 self
.Alignment
= MaxAlign
119 OutputFile
= OutputPath
+ \
124 SectionSuffix
['GUIDED']
125 OutputFile
= os
.path
.normpath(OutputFile
)
128 ExternalOption
= None
129 if self
.NameGuid
is not None:
130 ExternalTool
, ExternalOption
= FindExtendTool(self
.KeyStringList
, self
.CurrentArchList
, self
.NameGuid
)
133 # If not have GUID , call default
136 if self
.NameGuid
is None :
137 GenFdsGlobalVariable
.VerboseLogger("Use GenSection function Generate CRC32 Section")
138 GenFdsGlobalVariable
.GenerateSection(OutputFile
, SectFile
, Section
.Section
.SectionType
[self
.SectionType
], InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
140 OutputFileList
.append(OutputFile
)
141 return OutputFileList
, self
.Alignment
142 #or GUID not in External Tool List
143 elif ExternalTool
is None:
144 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No tool found with GUID %s" % self
.NameGuid
)
146 DummyFile
= OutputFile
+ ".dummy"
148 # Call GenSection with DUMMY section type.
150 GenFdsGlobalVariable
.GenerateSection(DummyFile
, SectFile
, InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
152 # Use external tool process the Output
154 TempFile
= OutputPath
+ \
160 TempFile
= os
.path
.normpath(TempFile
)
162 # Remove temp file if its time stamp is older than dummy file
163 # Just in case the external tool fails at this time but succeeded before
164 # Error should be reported if the external tool does not generate a new output based on new input
166 if os
.path
.exists(TempFile
) and os
.path
.exists(DummyFile
) and os
.path
.getmtime(TempFile
) < os
.path
.getmtime(DummyFile
):
171 if ExternalOption
is not None:
172 CmdOption
= CmdOption
+ ' ' + ExternalOption
173 if not GenFdsGlobalVariable
.EnableGenfdsMultiThread
:
174 if self
.ProcessRequired
not in ("TRUE", "1") and self
.IncludeFvSection
and not FvAddrIsSet
and self
.FvParentAddr
is not 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
198 if not os
.path
.exists(TempFile
) :
199 EdkLogger
.error("GenFds", COMMAND_FAILURE
, 'Fail to call %s, no output file was generated' % ExternalTool
)
201 FileHandleIn
= open(DummyFile
, 'rb')
202 FileHandleIn
.seek(0, 2)
203 InputFileSize
= FileHandleIn
.tell()
205 FileHandleOut
= open(TempFile
, 'rb')
206 FileHandleOut
.seek(0, 2)
207 TempFileSize
= FileHandleOut
.tell()
211 if self
.ExtraHeaderSize
!= -1:
212 HeaderLength
= str(self
.ExtraHeaderSize
)
214 if self
.ProcessRequired
== "NONE" and HeaderLength
is None:
215 if TempFileSize
> InputFileSize
:
217 BufferIn
= FileHandleIn
.read()
218 FileHandleOut
.seek(0)
219 BufferOut
= FileHandleOut
.read()
220 if BufferIn
== BufferOut
[TempFileSize
- InputFileSize
:]:
221 HeaderLength
= str(TempFileSize
- InputFileSize
)
222 #auto sec guided attribute with process required
223 if HeaderLength
is None:
224 Attribute
.append('PROCESSING_REQUIRED')
227 FileHandleOut
.close()
229 if FirstCall
and 'PROCESSING_REQUIRED' in Attribute
:
230 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.
231 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
234 # Call Gensection Add Section Header
236 if self
.ProcessRequired
in ("TRUE", "1"):
237 if 'PROCESSING_REQUIRED' not in Attribute
:
238 Attribute
.append('PROCESSING_REQUIRED')
240 if self
.AuthStatusValid
in ("TRUE", "1"):
241 Attribute
.append('AUTH_STATUS_VALID')
242 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
243 Guid
=self
.NameGuid
, GuidAttr
=Attribute
, GuidHdrLen
=HeaderLength
)
246 #add input file for GenSec get PROCESSING_REQUIRED
247 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
, IsMakefile
=IsMakefile
)
250 if self
.ExtraHeaderSize
!= -1:
251 HeaderLength
= str(self
.ExtraHeaderSize
)
252 if self
.AuthStatusValid
in ("TRUE", "1"):
253 Attribute
.append('AUTH_STATUS_VALID')
254 if self
.ProcessRequired
== "NONE" and HeaderLength
is None:
255 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
256 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
257 GuidHdrLen
=HeaderLength
, DummyFile
=DummyFile
, IsMakefile
=IsMakefile
)
259 if self
.ProcessRequired
in ("TRUE", "1"):
260 if 'PROCESSING_REQUIRED' not in Attribute
:
261 Attribute
.append('PROCESSING_REQUIRED')
262 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
263 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
264 GuidHdrLen
=HeaderLength
, IsMakefile
=IsMakefile
)
267 OutputFileList
.append(OutputFile
)
268 if 'PROCESSING_REQUIRED' in Attribute
:
269 # reset guided section alignment to none for the processed required guided data
270 self
.Alignment
= None
271 self
.IncludeFvSection
= False
272 self
.ProcessRequired
= "TRUE"
273 if IsMakefile
and self
.Alignment
is not None and self
.Alignment
.strip() == '0':
275 return OutputFileList
, self
.Alignment