]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GuidSection.py
25609e6f2ae1a296b35c15c2a024487a2cf47af3
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 # This program and the accompanying materials
8 # are licensed and made available under the terms and conditions of the BSD License
9 # which accompanies this distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 from __future__
import absolute_import
22 from .Ffs
import SectionSuffix
23 import Common
.LongFilePathOs
as os
24 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
25 from .GenFdsGlobalVariable
import FindExtendTool
26 from CommonDataClass
.FdfClass
import GuidSectionClassObject
27 from Common
import ToolDefClassObject
29 from Common
import EdkLogger
30 from Common
.BuildToolError
import *
31 from .FvImageSection
import FvImageSection
32 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
33 from Common
.DataType
import *
35 ## generate GUIDed section
38 class GuidSection(GuidSectionClassObject
) :
42 # @param self The object pointer
45 GuidSectionClassObject
.__init
__(self
)
47 ## GenSection() method
49 # Generate GUIDed section
51 # @param self The object pointer
52 # @param OutputPath Where to place output file
53 # @param ModuleName Which module this section belongs to
54 # @param SecNum Index of section
55 # @param KeyStringList Filter for inputs of section generation
56 # @param FfsInf FfsInfStatement object that contains this section data
57 # @param Dict dictionary contains macro and its value
58 # @retval tuple (Generated file name, section alignment)
60 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
=None, Dict
={}, IsMakefile
=False):
62 # Generate all section
64 self
.KeyStringList
= KeyStringList
65 self
.CurrentArchList
= GenFdsGlobalVariable
.ArchList
66 if FfsInf
is not None:
67 self
.Alignment
= FfsInf
.__ExtendMacro
__(self
.Alignment
)
68 self
.NameGuid
= FfsInf
.__ExtendMacro
__(self
.NameGuid
)
69 self
.SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
70 self
.CurrentArchList
= [FfsInf
.CurrentArch
]
81 if self
.ProcessRequired
in ("TRUE", "1"):
83 #no use FvAddr when the image is processed.
85 if self
.FvParentAddr
is not None:
86 #no use Parent Addr when the image is processed.
87 self
.FvParentAddr
= None
89 for Sect
in self
.SectionList
:
91 SecIndex
= '%s.%d' % (SecNum
, Index
)
92 # set base address for inside FvImage
93 if isinstance(Sect
, FvImageSection
):
95 Sect
.FvAddr
= self
.FvAddr
.pop(0)
96 self
.IncludeFvSection
= True
97 elif isinstance(Sect
, GuidSection
):
98 Sect
.FvAddr
= self
.FvAddr
99 Sect
.FvParentAddr
= self
.FvParentAddr
100 ReturnSectList
, align
= Sect
.GenSection(OutputPath
, ModuleName
, SecIndex
, KeyStringList
, FfsInf
, Dict
, IsMakefile
=IsMakefile
)
101 if isinstance(Sect
, GuidSection
):
102 if Sect
.IncludeFvSection
:
103 self
.IncludeFvSection
= Sect
.IncludeFvSection
105 if align
is not None:
108 if GenFdsGlobalVariable
.GetAlignment (align
) > GenFdsGlobalVariable
.GetAlignment (MaxAlign
):
110 if ReturnSectList
!= []:
113 for file in ReturnSectList
:
115 SectAlign
.append(align
)
117 if MaxAlign
is not None:
118 if self
.Alignment
is None:
119 self
.Alignment
= MaxAlign
121 if GenFdsGlobalVariable
.GetAlignment (MaxAlign
) > GenFdsGlobalVariable
.GetAlignment (self
.Alignment
):
122 self
.Alignment
= MaxAlign
124 OutputFile
= OutputPath
+ \
129 SectionSuffix
['GUIDED']
130 OutputFile
= os
.path
.normpath(OutputFile
)
133 ExternalOption
= None
134 if self
.NameGuid
is not None:
135 ExternalTool
, ExternalOption
= FindExtendTool(self
.KeyStringList
, self
.CurrentArchList
, self
.NameGuid
)
138 # If not have GUID , call default
141 if self
.NameGuid
is None :
142 GenFdsGlobalVariable
.VerboseLogger("Use GenSection function Generate CRC32 Section")
143 GenFdsGlobalVariable
.GenerateSection(OutputFile
, SectFile
, Section
.Section
.SectionType
[self
.SectionType
], InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
145 OutputFileList
.append(OutputFile
)
146 return OutputFileList
, self
.Alignment
147 #or GUID not in External Tool List
148 elif ExternalTool
is None:
149 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No tool found with GUID %s" % self
.NameGuid
)
151 DummyFile
= OutputFile
+ ".dummy"
153 # Call GenSection with DUMMY section type.
155 GenFdsGlobalVariable
.GenerateSection(DummyFile
, SectFile
, InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
157 # Use external tool process the Output
159 TempFile
= OutputPath
+ \
165 TempFile
= os
.path
.normpath(TempFile
)
167 # Remove temp file if its time stamp is older than dummy file
168 # Just in case the external tool fails at this time but succeeded before
169 # Error should be reported if the external tool does not generate a new output based on new input
171 if os
.path
.exists(TempFile
) and os
.path
.exists(DummyFile
) and os
.path
.getmtime(TempFile
) < os
.path
.getmtime(DummyFile
):
176 if ExternalOption
is not None:
177 CmdOption
= CmdOption
+ ' ' + ExternalOption
178 if not GenFdsGlobalVariable
.EnableGenfdsMultiThread
:
179 if self
.ProcessRequired
not in ("TRUE", "1") and self
.IncludeFvSection
and not FvAddrIsSet
and self
.FvParentAddr
is not None:
180 #FirstCall is only set for the encapsulated flash FV image without process required attribute.
187 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.
188 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, '-z' + ' ' + CmdOption
, ReturnValue
)
191 # when no call or first call failed, ReturnValue are not 1.
192 # Call the guided tool with CmdOption
194 if ReturnValue
[0] != 0:
197 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
199 # There is external tool which does not follow standard rule which return nonzero if tool fails
200 # The output file has to be checked
203 if not os
.path
.exists(TempFile
) :
204 EdkLogger
.error("GenFds", COMMAND_FAILURE
, 'Fail to call %s, no output file was generated' % ExternalTool
)
206 FileHandleIn
= open(DummyFile
, 'rb')
207 FileHandleIn
.seek(0, 2)
208 InputFileSize
= FileHandleIn
.tell()
210 FileHandleOut
= open(TempFile
, 'rb')
211 FileHandleOut
.seek(0, 2)
212 TempFileSize
= FileHandleOut
.tell()
216 if self
.ExtraHeaderSize
!= -1:
217 HeaderLength
= str(self
.ExtraHeaderSize
)
219 if self
.ProcessRequired
== "NONE" and HeaderLength
is None:
220 if TempFileSize
> InputFileSize
:
222 BufferIn
= FileHandleIn
.read()
223 FileHandleOut
.seek(0)
224 BufferOut
= FileHandleOut
.read()
225 if BufferIn
== BufferOut
[TempFileSize
- InputFileSize
:]:
226 HeaderLength
= str(TempFileSize
- InputFileSize
)
227 #auto sec guided attribute with process required
228 if HeaderLength
is None:
229 Attribute
.append('PROCESSING_REQUIRED')
232 FileHandleOut
.close()
234 if FirstCall
and 'PROCESSING_REQUIRED' in Attribute
:
235 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.
236 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
239 # Call Gensection Add Section Header
241 if self
.ProcessRequired
in ("TRUE", "1"):
242 if 'PROCESSING_REQUIRED' not in Attribute
:
243 Attribute
.append('PROCESSING_REQUIRED')
245 if self
.AuthStatusValid
in ("TRUE", "1"):
246 Attribute
.append('AUTH_STATUS_VALID')
247 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
248 Guid
=self
.NameGuid
, GuidAttr
=Attribute
, GuidHdrLen
=HeaderLength
)
251 #add input file for GenSec get PROCESSING_REQUIRED
252 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
, IsMakefile
=IsMakefile
)
255 if self
.ExtraHeaderSize
!= -1:
256 HeaderLength
= str(self
.ExtraHeaderSize
)
257 if self
.AuthStatusValid
in ("TRUE", "1"):
258 Attribute
.append('AUTH_STATUS_VALID')
259 if self
.ProcessRequired
== "NONE" and HeaderLength
is None:
260 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
261 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
262 GuidHdrLen
=HeaderLength
, DummyFile
=DummyFile
, IsMakefile
=IsMakefile
)
264 if self
.ProcessRequired
in ("TRUE", "1"):
265 if 'PROCESSING_REQUIRED' not in Attribute
:
266 Attribute
.append('PROCESSING_REQUIRED')
267 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
268 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
269 GuidHdrLen
=HeaderLength
, IsMakefile
=IsMakefile
)
272 OutputFileList
.append(OutputFile
)
273 if 'PROCESSING_REQUIRED' in Attribute
:
274 # reset guided section alignment to none for the processed required guided data
275 self
.Alignment
= None
276 self
.IncludeFvSection
= False
277 self
.ProcessRequired
= "TRUE"
278 if IsMakefile
and self
.Alignment
is not None and self
.Alignment
.strip() == '0':
280 return OutputFileList
, self
.Alignment