]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GuidSection.py
2 # process GUIDed section generation
4 # Copyright (c) 2007 - 2016, 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
={}):
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
)
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
)
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
)
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 self
.ProcessRequired
not in ("TRUE", "1") and self
.IncludeFvSection
and not FvAddrIsSet
and self
.FvParentAddr
!= None:
176 #FirstCall is only set for the encapsulated flash FV image without process required attribute.
183 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.
184 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, '-z' + ' ' + CmdOption
, ReturnValue
)
187 # when no call or first call failed, ReturnValue are not 1.
188 # Call the guided tool with CmdOption
190 if ReturnValue
[0] != 0:
193 GenFdsGlobalVariable
.GuidTool(TempFile
, [DummyFile
], ExternalTool
, CmdOption
)
195 # There is external tool which does not follow standard rule which return nonzero if tool fails
196 # 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
== 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
== 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
)
245 OutputFileList
.append(OutputFile
)
246 if 'PROCESSING_REQUIRED' in Attribute
:
247 # reset guided section alignment to none for the processed required guided data
248 self
.Alignment
= None
249 self
.IncludeFvSection
= False
250 self
.ProcessRequired
= "TRUE"
251 return OutputFileList
, self
.Alignment