]>
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>
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
31 from Common
.DataType
import *
33 ## generate GUIDed section
36 class GuidSection(GuidSectionClassObject
) :
40 # @param self The object pointer
43 GuidSectionClassObject
.__init
__(self
)
45 ## GenSection() method
47 # Generate GUIDed section
49 # @param self The object pointer
50 # @param OutputPath Where to place output file
51 # @param ModuleName Which module this section belongs to
52 # @param SecNum Index of section
53 # @param KeyStringList Filter for inputs of section generation
54 # @param FfsInf FfsInfStatement object that contains this section data
55 # @param Dict dictionary contains macro and its value
56 # @retval tuple (Generated file name, section alignment)
58 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
=None, Dict
={}, IsMakefile
=False):
60 # Generate all section
62 self
.KeyStringList
= KeyStringList
63 self
.CurrentArchList
= GenFdsGlobalVariable
.ArchList
64 if FfsInf
is not None:
65 self
.Alignment
= FfsInf
.__ExtendMacro
__(self
.Alignment
)
66 self
.NameGuid
= FfsInf
.__ExtendMacro
__(self
.NameGuid
)
67 self
.SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
68 self
.CurrentArchList
= [FfsInf
.CurrentArch
]
79 if self
.ProcessRequired
in ("TRUE", "1"):
81 #no use FvAddr when the image is processed.
83 if self
.FvParentAddr
is not None:
84 #no use Parent Addr when the image is processed.
85 self
.FvParentAddr
= None
87 for Sect
in self
.SectionList
:
89 SecIndex
= '%s.%d' % (SecNum
, Index
)
90 # set base address for inside FvImage
91 if isinstance(Sect
, FvImageSection
):
93 Sect
.FvAddr
= self
.FvAddr
.pop(0)
94 self
.IncludeFvSection
= True
95 elif isinstance(Sect
, GuidSection
):
96 Sect
.FvAddr
= self
.FvAddr
97 Sect
.FvParentAddr
= self
.FvParentAddr
98 ReturnSectList
, align
= Sect
.GenSection(OutputPath
, ModuleName
, SecIndex
, KeyStringList
, FfsInf
, Dict
, IsMakefile
=IsMakefile
)
99 if isinstance(Sect
, GuidSection
):
100 if Sect
.IncludeFvSection
:
101 self
.IncludeFvSection
= Sect
.IncludeFvSection
103 if align
is not None:
106 if GenFdsGlobalVariable
.GetAlignment (align
) > GenFdsGlobalVariable
.GetAlignment (MaxAlign
):
108 if ReturnSectList
!= []:
111 for file in ReturnSectList
:
113 SectAlign
.append(align
)
115 if MaxAlign
is not None:
116 if self
.Alignment
is None:
117 self
.Alignment
= MaxAlign
119 if GenFdsGlobalVariable
.GetAlignment (MaxAlign
) > GenFdsGlobalVariable
.GetAlignment (self
.Alignment
):
120 self
.Alignment
= MaxAlign
122 OutputFile
= OutputPath
+ \
127 Ffs
.SectionSuffix
['GUIDED']
128 OutputFile
= os
.path
.normpath(OutputFile
)
131 ExternalOption
= None
132 if self
.NameGuid
is not None:
133 ExternalTool
, ExternalOption
= FindExtendTool(self
.KeyStringList
, self
.CurrentArchList
, self
.NameGuid
)
136 # If not have GUID , call default
139 if self
.NameGuid
is None :
140 GenFdsGlobalVariable
.VerboseLogger("Use GenSection function Generate CRC32 Section")
141 GenFdsGlobalVariable
.GenerateSection(OutputFile
, SectFile
, Section
.Section
.SectionType
[self
.SectionType
], InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
143 OutputFileList
.append(OutputFile
)
144 return OutputFileList
, self
.Alignment
145 #or GUID not in External Tool List
146 elif ExternalTool
is None:
147 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No tool found with GUID %s" % self
.NameGuid
)
149 DummyFile
= OutputFile
+ ".dummy"
151 # Call GenSection with DUMMY section type.
153 GenFdsGlobalVariable
.GenerateSection(DummyFile
, SectFile
, InputAlign
=SectAlign
, IsMakefile
=IsMakefile
)
155 # Use external tool process the Output
157 TempFile
= OutputPath
+ \
163 TempFile
= os
.path
.normpath(TempFile
)
165 # Remove temp file if its time stamp is older than dummy file
166 # Just in case the external tool fails at this time but succeeded before
167 # Error should be reported if the external tool does not generate a new output based on new input
169 if os
.path
.exists(TempFile
) and os
.path
.exists(DummyFile
) and os
.path
.getmtime(TempFile
) < os
.path
.getmtime(DummyFile
):
174 if ExternalOption
is not None:
175 CmdOption
= CmdOption
+ ' ' + ExternalOption
176 if not GenFdsGlobalVariable
.EnableGenfdsMultiThread
:
177 if self
.ProcessRequired
not in ("TRUE", "1") and self
.IncludeFvSection
and not FvAddrIsSet
and self
.FvParentAddr
is not None:
178 #FirstCall is only set for the encapsulated flash FV image without process required attribute.
185 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.
186 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, '-z' + ' ' + CmdOption
, ReturnValue
)
189 # when no call or first call failed, ReturnValue are not 1.
190 # Call the guided tool with CmdOption
192 if ReturnValue
[0] != 0:
195 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
197 # There is external tool which does not follow standard rule which return nonzero if tool fails
198 # The output file has to be checked
201 if not os
.path
.exists(TempFile
) :
202 EdkLogger
.error("GenFds", COMMAND_FAILURE
, 'Fail to call %s, no output file was generated' % ExternalTool
)
204 FileHandleIn
= open(DummyFile
, 'rb')
205 FileHandleIn
.seek(0, 2)
206 InputFileSize
= FileHandleIn
.tell()
208 FileHandleOut
= open(TempFile
, 'rb')
209 FileHandleOut
.seek(0, 2)
210 TempFileSize
= FileHandleOut
.tell()
214 if self
.ExtraHeaderSize
!= -1:
215 HeaderLength
= str(self
.ExtraHeaderSize
)
217 if self
.ProcessRequired
== "NONE" and HeaderLength
is None:
218 if TempFileSize
> InputFileSize
:
220 BufferIn
= FileHandleIn
.read()
221 FileHandleOut
.seek(0)
222 BufferOut
= FileHandleOut
.read()
223 if BufferIn
== BufferOut
[TempFileSize
- InputFileSize
:]:
224 HeaderLength
= str(TempFileSize
- InputFileSize
)
225 #auto sec guided attribute with process required
226 if HeaderLength
is None:
227 Attribute
.append('PROCESSING_REQUIRED')
230 FileHandleOut
.close()
232 if FirstCall
and 'PROCESSING_REQUIRED' in Attribute
:
233 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.
234 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
237 # Call Gensection Add Section Header
239 if self
.ProcessRequired
in ("TRUE", "1"):
240 if 'PROCESSING_REQUIRED' not in Attribute
:
241 Attribute
.append('PROCESSING_REQUIRED')
243 if self
.AuthStatusValid
in ("TRUE", "1"):
244 Attribute
.append('AUTH_STATUS_VALID')
245 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
246 Guid
=self
.NameGuid
, GuidAttr
=Attribute
, GuidHdrLen
=HeaderLength
)
249 #add input file for GenSec get PROCESSING_REQUIRED
250 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
, IsMakefile
=IsMakefile
)
253 if self
.ExtraHeaderSize
!= -1:
254 HeaderLength
= str(self
.ExtraHeaderSize
)
255 if self
.AuthStatusValid
in ("TRUE", "1"):
256 Attribute
.append('AUTH_STATUS_VALID')
257 if self
.ProcessRequired
== "NONE" and HeaderLength
is None:
258 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
259 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
260 GuidHdrLen
=HeaderLength
, DummyFile
=DummyFile
, IsMakefile
=IsMakefile
)
262 if self
.ProcessRequired
in ("TRUE", "1"):
263 if 'PROCESSING_REQUIRED' not in Attribute
:
264 Attribute
.append('PROCESSING_REQUIRED')
265 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [TempFile
], Section
.Section
.SectionType
['GUIDED'],
266 Guid
=self
.NameGuid
, GuidAttr
=Attribute
,
267 GuidHdrLen
=HeaderLength
, IsMakefile
=IsMakefile
)
270 OutputFileList
.append(OutputFile
)
271 if 'PROCESSING_REQUIRED' in Attribute
:
272 # reset guided section alignment to none for the processed required guided data
273 self
.Alignment
= None
274 self
.IncludeFvSection
= False
275 self
.ProcessRequired
= "TRUE"
276 if IsMakefile
and self
.Alignment
.strip() == '0':
278 return OutputFileList
, self
.Alignment