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
= None, 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"""
81 if Filename
is not None:
82 Filename
= GenFdsGlobalVariable
.MacroExtend(Filename
, Dict
)
83 # check if the path is absolute or relative
84 if os
.path
.isabs(Filename
):
85 Filename
= os
.path
.normpath(Filename
)
87 Filename
= os
.path
.normpath(os
.path
.join(FfsInf
.EfiOutputPath
, Filename
))
90 FileList
.append(Filename
)
91 elif os
.path
.exists(Filename
):
92 FileList
.append(Filename
)
94 SuffixMap
= FfsInf
.GetFinalTargetSuffixMap()
95 if '.depex' in SuffixMap
:
96 FileList
.append(Filename
)
98 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FileType
, self
.FileExtension
, Dict
, IsMakefile
=IsMakefile
, SectionType
=SectionType
)
100 return FileList
, self
.Alignment
103 Align
= self
.Alignment
105 """ If Section type is 'VERSION'"""
107 if SectionType
== 'VERSION':
109 InfOverrideVerString
= False
110 if FfsInf
.Version
is not None:
111 #StringData = FfsInf.Version
112 BuildNum
= FfsInf
.Version
113 InfOverrideVerString
= True
115 if InfOverrideVerString
:
116 #VerTuple = ('-n', '"' + StringData + '"')
117 if BuildNum
is not None and BuildNum
!= '':
118 BuildNumTuple
= ('-j', BuildNum
)
120 BuildNumTuple
= tuple()
123 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
124 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
127 IsMakefile
=IsMakefile
)
128 OutputFileList
.append(OutputFile
)
131 for File
in FileList
:
133 Num
= '%s.%d' %(SecNum
, Index
)
134 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
139 if BuildNum
is not None and BuildNum
!= '':
140 BuildNumTuple
= ('-j', BuildNum
)
141 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
144 IsMakefile
=IsMakefile
)
145 OutputFileList
.append(OutputFile
)
148 BuildNum
= StringData
149 if BuildNum
is not None and BuildNum
!= '':
150 BuildNumTuple
= ('-j', BuildNum
)
152 BuildNumTuple
= tuple()
153 BuildNumString
= ' ' + ' '.join(BuildNumTuple
)
155 #if VerString == '' and
156 if BuildNumString
== '':
157 if self
.Optional
== True :
158 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
161 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss Version Section value" %InfFileName
)
163 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
164 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
167 IsMakefile
=IsMakefile
)
168 OutputFileList
.append(OutputFile
)
171 # If Section Type is BINARY_FILE_TYPE_UI
173 elif SectionType
== BINARY_FILE_TYPE_UI
:
175 InfOverrideUiString
= False
176 if FfsInf
.Ui
is not None:
177 StringData
= FfsInf
.Ui
178 InfOverrideUiString
= True
180 if InfOverrideUiString
:
182 if IsMakefile
and StringData
== ModuleNameStr
:
183 StringData
= "$(MODULE_NAME)"
184 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
185 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
186 Ui
=StringData
, IsMakefile
=IsMakefile
)
187 OutputFileList
.append(OutputFile
)
190 for File
in FileList
:
192 Num
= '%s.%d' %(SecNum
, Index
)
193 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
197 if IsMakefile
and UiString
== ModuleNameStr
:
198 UiString
= "$(MODULE_NAME)"
199 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
200 Ui
=UiString
, IsMakefile
=IsMakefile
)
201 OutputFileList
.append(OutputFile
)
203 if StringData
is not None and len(StringData
) > 0:
204 UiTuple
= ('-n', '"' + StringData
+ '"')
208 if self
.Optional
== True :
209 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
212 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss UI Section value" %InfFileName
)
215 if IsMakefile
and StringData
== ModuleNameStr
:
216 StringData
= "$(MODULE_NAME)"
217 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
218 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
219 Ui
=StringData
, IsMakefile
=IsMakefile
)
220 OutputFileList
.append(OutputFile
)
223 # If Section Type is BINARY_FILE_TYPE_RAW
225 elif SectionType
== BINARY_FILE_TYPE_RAW
:
226 """If File List is empty"""
228 if self
.Optional
== True:
229 GenFdsGlobalVariable
.VerboseLogger("Optional Section don't exist!")
232 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Output file for %s section could not be found for %s" % (SectionType
, InfFileName
))
234 elif len(FileList
) > 1:
235 EdkLogger
.error("GenFds", GENFDS_ERROR
,
236 "Files suffixed with %s are not allowed to have more than one file in %s[Binaries] section" % (
237 self
.FileExtension
, InfFileName
))
239 for File
in FileList
:
240 File
= GenFdsGlobalVariable
.MacroExtend(File
, Dict
)
241 OutputFileList
.append(File
)
244 """If File List is empty"""
246 if self
.Optional
== True:
247 GenFdsGlobalVariable
.VerboseLogger("Optional Section don't exist!")
250 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Output file for %s section could not be found for %s" % (SectionType
, InfFileName
))
253 """Convert the File to Section file one by one """
254 for File
in FileList
:
255 """ Copy Map file to FFS output path """
257 Num
= '%s.%d' %(SecNum
, Index
)
258 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
259 File
= GenFdsGlobalVariable
.MacroExtend(File
, Dict
)
261 #Get PE Section alignment when align is set to AUTO
262 if self
.Alignment
== 'Auto' and (SectionType
== BINARY_FILE_TYPE_PE32
or SectionType
== BINARY_FILE_TYPE_TE
):
264 if File
[(len(File
)-4):] == '.efi' and FfsInf
.InfModule
.BaseName
== os
.path
.basename(File
)[:-4]:
265 MapFile
= File
.replace('.efi', '.map')
266 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
268 if GenFdsGlobalVariable
.CopyList
== []:
269 GenFdsGlobalVariable
.CopyList
= [(MapFile
, CopyMapFile
)]
271 GenFdsGlobalVariable
.CopyList
.append((MapFile
, CopyMapFile
))
273 if os
.path
.exists(MapFile
):
274 if not os
.path
.exists(CopyMapFile
) or \
275 (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
276 CopyLongFilePath(MapFile
, CopyMapFile
)
279 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
281 if GenFdsGlobalVariable
.CopyList
== []:
282 GenFdsGlobalVariable
.CopyList
= [(File
, FileBeforeStrip
)]
284 GenFdsGlobalVariable
.CopyList
.append((File
, FileBeforeStrip
))
286 if not os
.path
.exists(FileBeforeStrip
) or \
287 (os
.path
.getmtime(File
) > os
.path
.getmtime(FileBeforeStrip
)):
288 CopyLongFilePath(File
, FileBeforeStrip
)
289 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
290 GenFdsGlobalVariable
.GenerateFirmwareImage(
294 IsMakefile
= IsMakefile
298 """For TE Section call GenFw to generate TE image"""
300 if SectionType
== BINARY_FILE_TYPE_TE
:
301 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
302 GenFdsGlobalVariable
.GenerateFirmwareImage(
306 IsMakefile
= IsMakefile
310 """Call GenSection"""
311 GenFdsGlobalVariable
.GenerateSection(OutputFile
,
313 Section
.Section
.SectionType
.get (SectionType
),
314 IsMakefile
=IsMakefile
316 OutputFileList
.append(OutputFile
)
318 return OutputFileList
, Align