2 # process rule section generation
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
12 from __future__
import absolute_import
15 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
17 from .Ffs
import SectionSuffix
18 import Common
.LongFilePathOs
as os
19 from CommonDataClass
.FdfClass
import EfiSectionClassObject
20 from Common
import EdkLogger
21 from Common
.BuildToolError
import *
22 from Common
.Misc
import PeImageClass
23 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
24 from Common
.LongFilePathSupport
import CopyLongFilePath
25 from Common
.DataType
import *
27 ## generate rule section
30 class EfiSection (EfiSectionClassObject
):
34 # @param self The object pointer
37 EfiSectionClassObject
.__init
__(self
)
39 ## GenSection() method
41 # Generate rule section
43 # @param self The object pointer
44 # @param OutputPath Where to place output file
45 # @param ModuleName Which module this section belongs to
46 # @param SecNum Index of section
47 # @param KeyStringList Filter for inputs of section generation
48 # @param FfsInf FfsInfStatement object that contains this section data
49 # @param Dict dictionary contains macro and its value
50 # @retval tuple (Generated file name list, section alignment)
52 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}, IsMakefile
= False) :
54 if self
.FileName
is not None and self
.FileName
.startswith('PCD('):
55 self
.FileName
= GenFdsGlobalVariable
.GetPcdValue(self
.FileName
)
56 """Prepare the parameter of GenSection"""
57 if FfsInf
is not None :
58 InfFileName
= FfsInf
.InfFileName
59 SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
60 Filename
= FfsInf
.__ExtendMacro
__(self
.FileName
)
61 BuildNum
= FfsInf
.__ExtendMacro
__(self
.BuildNum
)
62 StringData
= FfsInf
.__ExtendMacro
__(self
.StringData
)
63 ModuleNameStr
= FfsInf
.__ExtendMacro
__('$(MODULE_NAME)')
65 if FfsInf
.ModuleType
in (SUP_MODULE_SEC
, SUP_MODULE_PEI_CORE
, SUP_MODULE_PEIM
, SUP_MODULE_MM_CORE_STANDALONE
) and SectionType
in (BINARY_FILE_TYPE_TE
, BINARY_FILE_TYPE_PE32
):
66 if FfsInf
.KeepReloc
is not None:
67 NoStrip
= FfsInf
.KeepReloc
68 elif FfsInf
.KeepRelocFromRule
is not None:
69 NoStrip
= FfsInf
.KeepRelocFromRule
70 elif self
.KeepReloc
is not None:
71 NoStrip
= self
.KeepReloc
72 elif FfsInf
.ShadowFromInfFile
is not None:
73 NoStrip
= FfsInf
.ShadowFromInfFile
75 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Module %s apply rule for None!" %ModuleName
)
77 """If the file name was pointed out, add it in FileList"""
79 if Filename
is not None:
80 Filename
= GenFdsGlobalVariable
.MacroExtend(Filename
, Dict
)
81 # check if the path is absolute or relative
82 if os
.path
.isabs(Filename
):
83 Filename
= os
.path
.normpath(Filename
)
85 Filename
= os
.path
.normpath(os
.path
.join(FfsInf
.EfiOutputPath
, Filename
))
88 FileList
.append(Filename
)
89 elif os
.path
.exists(Filename
):
90 FileList
.append(Filename
)
92 SuffixMap
= FfsInf
.GetFinalTargetSuffixMap()
93 if '.depex' in SuffixMap
:
94 FileList
.append(Filename
)
96 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FileType
, self
.FileExtension
, Dict
, IsMakefile
=IsMakefile
)
98 return FileList
, self
.Alignment
101 Align
= self
.Alignment
103 """ If Section type is 'VERSION'"""
105 if SectionType
== 'VERSION':
107 InfOverrideVerString
= False
108 if FfsInf
.Version
is not None:
109 #StringData = FfsInf.Version
110 BuildNum
= FfsInf
.Version
111 InfOverrideVerString
= True
113 if InfOverrideVerString
:
114 #VerTuple = ('-n', '"' + StringData + '"')
115 if BuildNum
is not None and BuildNum
!= '':
116 BuildNumTuple
= ('-j', BuildNum
)
118 BuildNumTuple
= tuple()
121 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
122 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
125 IsMakefile
=IsMakefile
)
126 OutputFileList
.append(OutputFile
)
129 for File
in FileList
:
131 Num
= '%s.%d' %(SecNum
, Index
)
132 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
137 if BuildNum
is not None and BuildNum
!= '':
138 BuildNumTuple
= ('-j', BuildNum
)
139 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
142 IsMakefile
=IsMakefile
)
143 OutputFileList
.append(OutputFile
)
146 BuildNum
= StringData
147 if BuildNum
is not None and BuildNum
!= '':
148 BuildNumTuple
= ('-j', BuildNum
)
150 BuildNumTuple
= tuple()
151 BuildNumString
= ' ' + ' '.join(BuildNumTuple
)
153 #if VerString == '' and
154 if BuildNumString
== '':
155 if self
.Optional
== True :
156 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
159 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss Version Section value" %InfFileName
)
161 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
162 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
165 IsMakefile
=IsMakefile
)
166 OutputFileList
.append(OutputFile
)
169 # If Section Type is BINARY_FILE_TYPE_UI
171 elif SectionType
== BINARY_FILE_TYPE_UI
:
173 InfOverrideUiString
= False
174 if FfsInf
.Ui
is not None:
175 StringData
= FfsInf
.Ui
176 InfOverrideUiString
= True
178 if InfOverrideUiString
:
180 if IsMakefile
and StringData
== ModuleNameStr
:
181 StringData
= "$(MODULE_NAME)"
182 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
183 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
184 Ui
=StringData
, IsMakefile
=IsMakefile
)
185 OutputFileList
.append(OutputFile
)
188 for File
in FileList
:
190 Num
= '%s.%d' %(SecNum
, Index
)
191 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
195 if IsMakefile
and UiString
== ModuleNameStr
:
196 UiString
= "$(MODULE_NAME)"
197 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
198 Ui
=UiString
, IsMakefile
=IsMakefile
)
199 OutputFileList
.append(OutputFile
)
201 if StringData
is not None and len(StringData
) > 0:
202 UiTuple
= ('-n', '"' + StringData
+ '"')
206 if self
.Optional
== True :
207 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
210 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss UI Section value" %InfFileName
)
213 if IsMakefile
and StringData
== ModuleNameStr
:
214 StringData
= "$(MODULE_NAME)"
215 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
216 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
217 Ui
=StringData
, IsMakefile
=IsMakefile
)
218 OutputFileList
.append(OutputFile
)
222 """If File List is empty"""
224 if self
.Optional
== True:
225 GenFdsGlobalVariable
.VerboseLogger("Optional Section don't exist!")
228 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Output file for %s section could not be found for %s" % (SectionType
, InfFileName
))
231 """Convert the File to Section file one by one """
232 for File
in FileList
:
233 """ Copy Map file to FFS output path """
235 Num
= '%s.%d' %(SecNum
, Index
)
236 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
237 File
= GenFdsGlobalVariable
.MacroExtend(File
, Dict
)
239 #Get PE Section alignment when align is set to AUTO
240 if self
.Alignment
== 'Auto' and (SectionType
== BINARY_FILE_TYPE_PE32
or SectionType
== BINARY_FILE_TYPE_TE
):
241 ImageObj
= PeImageClass (File
)
242 if ImageObj
.SectionAlignment
< 0x400:
243 Align
= str (ImageObj
.SectionAlignment
)
244 elif ImageObj
.SectionAlignment
< 0x100000:
245 Align
= str (ImageObj
.SectionAlignment
// 0x400) + 'K'
247 Align
= str (ImageObj
.SectionAlignment
// 0x100000) + 'M'
249 if File
[(len(File
)-4):] == '.efi':
250 MapFile
= File
.replace('.efi', '.map')
251 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
253 if GenFdsGlobalVariable
.CopyList
== []:
254 GenFdsGlobalVariable
.CopyList
= [(MapFile
, CopyMapFile
)]
256 GenFdsGlobalVariable
.CopyList
.append((MapFile
, CopyMapFile
))
258 if os
.path
.exists(MapFile
):
259 if not os
.path
.exists(CopyMapFile
) or \
260 (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
261 CopyLongFilePath(MapFile
, CopyMapFile
)
264 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
266 if GenFdsGlobalVariable
.CopyList
== []:
267 GenFdsGlobalVariable
.CopyList
= [(File
, FileBeforeStrip
)]
269 GenFdsGlobalVariable
.CopyList
.append((File
, FileBeforeStrip
))
271 if not os
.path
.exists(FileBeforeStrip
) or \
272 (os
.path
.getmtime(File
) > os
.path
.getmtime(FileBeforeStrip
)):
273 CopyLongFilePath(File
, FileBeforeStrip
)
274 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
275 GenFdsGlobalVariable
.GenerateFirmwareImage(
279 IsMakefile
= IsMakefile
283 """For TE Section call GenFw to generate TE image"""
285 if SectionType
== BINARY_FILE_TYPE_TE
:
286 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
287 GenFdsGlobalVariable
.GenerateFirmwareImage(
291 IsMakefile
= IsMakefile
295 """Call GenSection"""
296 GenFdsGlobalVariable
.GenerateSection(OutputFile
,
298 Section
.Section
.SectionType
.get (SectionType
),
299 IsMakefile
=IsMakefile
301 OutputFileList
.append(OutputFile
)
303 return OutputFileList
, Align