]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GuidSection.py
530e2b3957c0b5477f714e56fd3788d7bfe969a5
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
={}, 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
]
74 if self
.ProcessRequired
in ("TRUE", "1"):
76 #no use FvAddr when the image is processed.
78 if self
.FvParentAddr
is not None:
79 #no use Parent Addr when the image is processed.
80 self
.FvParentAddr
= None
82 for Sect
in self
.SectionList
:
84 SecIndex
= '%s.%d' % (SecNum
, Index
)
85 # set base address for inside FvImage
86 if isinstance(Sect
, FvImageSection
):
88 Sect
.FvAddr
= self
.FvAddr
.pop(0)
89 self
.IncludeFvSection
= True
90 elif isinstance(Sect
, GuidSection
):
91 Sect
.FvAddr
= self
.FvAddr
92 Sect
.FvParentAddr
= self
.FvParentAddr
93 ReturnSectList
, align
= Sect
.GenSection(OutputPath
, ModuleName
, SecIndex
, KeyStringList
, FfsInf
, Dict
, IsMakefile
=IsMakefile
)
94 if isinstance(Sect
, GuidSection
):
95 if Sect
.IncludeFvSection
:
96 self
.IncludeFvSection
= Sect
.IncludeFvSection
101 if GenFdsGlobalVariable
.GetAlignment (align
) > GenFdsGlobalVariable
.GetAlignment (MaxAlign
):
103 if ReturnSectList
!= []:
106 for file in ReturnSectList
:
108 SectAlign
.append(align
)
110 if MaxAlign
is not None:
111 if self
.Alignment
is None:
112 self
.Alignment
= MaxAlign
114 if GenFdsGlobalVariable
.GetAlignment (MaxAlign
) > GenFdsGlobalVariable
.GetAlignment (self
.Alignment
):
115 self
.Alignment
= MaxAlign
117 OutputFile
= OutputPath
+ \
122 SectionSuffix
['GUIDED']
123 OutputFile
= os
.path
.normpath(OutputFile
)
126 ExternalOption
= None
127 if self
.NameGuid
is not None:
128 ExternalTool
, ExternalOption
= FindExtendTool(self
.KeyStringList
, self
.CurrentArchList
, self
.NameGuid
)
131 # If not have GUID , call default
134 if self
.NameGuid
is None :
135 GenFdsGlobalVariable
.VerboseLogger("Use GenSection function Generate CRC32 Section")
136 GenFdsGlobalVariable
.GenerateSection(OutputFile
, SectFile
, Section
.Section
.SectionType
[self
.SectionType
], InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
138 OutputFileList
.append(OutputFile
)
139 return OutputFileList
, self
.Alignment
140 #or GUID not in External Tool List
141 elif ExternalTool
is None:
142 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No tool found with GUID %s" % self
.NameGuid
)
144 DummyFile
= OutputFile
+ ".dummy"
146 # Call GenSection with DUMMY section type.
148 GenFdsGlobalVariable
.GenerateSection(DummyFile
, SectFile
, InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
150 # Use external tool process the Output
152 TempFile
= OutputPath
+ \
158 TempFile
= os
.path
.normpath(TempFile
)
160 # Remove temp file if its time stamp is older than dummy file
161 # Just in case the external tool fails at this time but succeeded before
162 # Error should be reported if the external tool does not generate a new output based on new input
164 if os
.path
.exists(TempFile
) and os
.path
.exists(DummyFile
) and os
.path
.getmtime(TempFile
) < os
.path
.getmtime(DummyFile
):
169 if ExternalOption
is not None:
170 CmdOption
= CmdOption
+ ' ' + ExternalOption
171 if not GenFdsGlobalVariable
.EnableGenfdsMultiThread
:
172 if self
.ProcessRequired
not in ("TRUE", "1") and self
.IncludeFvSection
and not FvAddrIsSet
and self
.FvParentAddr
is not None:
173 #FirstCall is only set for the encapsulated flash FV image without process required attribute.
180 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.
181 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, '-z' + ' ' + CmdOption
, ReturnValue
)
184 # when no call or first call failed, ReturnValue are not 1.
185 # Call the guided tool with CmdOption
187 if ReturnValue
[0] != 0:
190 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
192 # There is external tool which does not follow standard rule which return nonzero if tool fails
193 # The output file has to be checked
196 if not os
.path
.exists(TempFile
) :
197 EdkLogger
.error("GenFds", COMMAND_FAILURE
, 'Fail to call %s, no output file was generated' % ExternalTool
)
199 FileHandleIn
= open(DummyFile
, 'rb')
200 FileHandleIn
.seek(0, 2)
201 InputFileSize
= FileHandleIn
.tell()
203 FileHandleOut
= open(TempFile
, 'rb')
204 FileHandleOut
.seek(0, 2)
205 TempFileSize
= FileHandleOut
.tell()
209 if self
.ExtraHeaderSize
!= -1:
210 HeaderLength
= str(self
.ExtraHeaderSize
)
212 if self
.ProcessRequired
== "NONE" and HeaderLength
is None:
213 if TempFileSize
> InputFileSize
:
215 BufferIn
= FileHandleIn
.read()
216 FileHandleOut
.seek(0)
217 BufferOut
= FileHandleOut
.read()
218 if BufferIn
== BufferOut
[TempFileSize
- InputFileSize
:]:
219 HeaderLength
= str(TempFileSize
- InputFileSize
)
220 #auto sec guided attribute with process required
221 if HeaderLength
is None:
222 Attribute
.append('PROCESSING_REQUIRED')
225 FileHandleOut
.close()
227 if FirstCall
and 'PROCESSING_REQUIRED' in Attribute
:
228 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.
229 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
232 # Call Gensection Add Section Header
234 if self
.ProcessRequired
in ("TRUE", "1"):
235 if 'PROCESSING_REQUIRED' not in Attribute
:
236 Attribute
.append('PROCESSING_REQUIRED')
238 if self
.AuthStatusValid
in ("TRUE", "1"):
239 Attribute
.append('AUTH_STATUS_VALID')
240 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
241 Guid
=self
.NameGuid
, GuidAttr
=Attribute
, GuidHdrLen
=HeaderLength
)
244 #add input file for GenSec get PROCESSING_REQUIRED
245 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
, IsMakefile
=IsMakefile
)
248 if self
.ExtraHeaderSize
!= -1:
249 HeaderLength
= str(self
.ExtraHeaderSize
)
250 if self
.AuthStatusValid
in ("TRUE", "1"):
251 Attribute
.append('AUTH_STATUS_VALID')
252 if self
.ProcessRequired
== "NONE" and HeaderLength
is None:
253 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
254 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
255 GuidHdrLen
=HeaderLength
, DummyFile
=DummyFile
, IsMakefile
=IsMakefile
)
257 if self
.ProcessRequired
in ("TRUE", "1"):
258 if 'PROCESSING_REQUIRED' not in Attribute
:
259 Attribute
.append('PROCESSING_REQUIRED')
260 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
261 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
262 GuidHdrLen
=HeaderLength
, IsMakefile
=IsMakefile
)
265 OutputFileList
.append(OutputFile
)
266 if 'PROCESSING_REQUIRED' in Attribute
:
267 # reset guided section alignment to none for the processed required guided data
268 self
.Alignment
= None
269 self
.IncludeFvSection
= False
270 self
.ProcessRequired
= "TRUE"
271 if IsMakefile
and self
.Alignment
is not None and self
.Alignment
.strip() == '0':
273 return OutputFileList
, self
.Alignment