]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/EfiSection.py
2 # process rule 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.
20 from GenFdsGlobalVariable
import GenFdsGlobalVariable
23 import Common
.LongFilePathOs
as os
24 from CommonDataClass
.FdfClass
import EfiSectionClassObject
25 from Common
import EdkLogger
26 from Common
.BuildToolError
import *
27 from Common
.Misc
import PeImageClass
28 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
29 from Common
.LongFilePathSupport
import CopyLongFilePath
31 ## generate rule section
34 class EfiSection (EfiSectionClassObject
):
38 # @param self The object pointer
41 EfiSectionClassObject
.__init
__(self
)
43 ## GenSection() method
45 # Generate rule section
47 # @param self The object pointer
48 # @param OutputPath Where to place output file
49 # @param ModuleName Which module this section belongs to
50 # @param SecNum Index of section
51 # @param KeyStringList Filter for inputs of section generation
52 # @param FfsInf FfsInfStatement object that contains this section data
53 # @param Dict dictionary contains macro and its value
54 # @retval tuple (Generated file name list, section alignment)
56 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}, IsMakefile
= False) :
58 if self
.FileName
is not None and self
.FileName
.startswith('PCD('):
59 self
.FileName
= GenFdsGlobalVariable
.GetPcdValue(self
.FileName
)
60 """Prepare the parameter of GenSection"""
61 if FfsInf
is not None :
62 InfFileName
= FfsInf
.InfFileName
63 SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
64 Filename
= FfsInf
.__ExtendMacro
__(self
.FileName
)
65 BuildNum
= FfsInf
.__ExtendMacro
__(self
.BuildNum
)
66 StringData
= FfsInf
.__ExtendMacro
__(self
.StringData
)
67 ModuleNameStr
= FfsInf
.__ExtendMacro
__('$(MODULE_NAME)')
69 if FfsInf
.ModuleType
in ('SEC', 'PEI_CORE', 'PEIM') and SectionType
in ('TE', 'PE32'):
70 if FfsInf
.KeepReloc
is not None:
71 NoStrip
= FfsInf
.KeepReloc
72 elif FfsInf
.KeepRelocFromRule
is not None:
73 NoStrip
= FfsInf
.KeepRelocFromRule
74 elif self
.KeepReloc
is not None:
75 NoStrip
= self
.KeepReloc
76 elif FfsInf
.ShadowFromInfFile
is not None:
77 NoStrip
= FfsInf
.ShadowFromInfFile
79 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Module %s apply rule for None!" %ModuleName
)
81 """If the file name was pointed out, add it in FileList"""
83 if Filename
is not None:
84 Filename
= GenFdsGlobalVariable
.MacroExtend(Filename
, Dict
)
85 # check if the path is absolute or relative
86 if os
.path
.isabs(Filename
):
87 Filename
= os
.path
.normpath(Filename
)
89 Filename
= os
.path
.normpath(os
.path
.join(FfsInf
.EfiOutputPath
, Filename
))
92 FileList
.append(Filename
)
93 elif os
.path
.exists(Filename
):
94 FileList
.append(Filename
)
96 SuffixMap
= FfsInf
.GetFinalTargetSuffixMap()
97 if '.depex' in SuffixMap
:
98 FileList
.append(Filename
)
100 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FileType
, self
.FileExtension
, Dict
, IsMakefile
=IsMakefile
)
102 return FileList
, self
.Alignment
105 Align
= self
.Alignment
107 """ If Section type is 'VERSION'"""
109 if SectionType
== 'VERSION':
111 InfOverrideVerString
= False
112 if FfsInf
.Version
is not None:
113 #StringData = FfsInf.Version
114 BuildNum
= FfsInf
.Version
115 InfOverrideVerString
= True
117 if InfOverrideVerString
:
118 #VerTuple = ('-n', '"' + StringData + '"')
119 if BuildNum
is not None and BuildNum
!= '':
120 BuildNumTuple
= ('-j', BuildNum
)
122 BuildNumTuple
= tuple()
125 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
126 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
129 IsMakefile
=IsMakefile
)
130 OutputFileList
.append(OutputFile
)
133 for File
in FileList
:
135 Num
= '%s.%d' %(SecNum
, Index
)
136 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
141 if BuildNum
is not None and BuildNum
!= '':
142 BuildNumTuple
= ('-j', BuildNum
)
143 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
146 IsMakefile
=IsMakefile
)
147 OutputFileList
.append(OutputFile
)
150 BuildNum
= StringData
151 if BuildNum
is not None and BuildNum
!= '':
152 BuildNumTuple
= ('-j', BuildNum
)
154 BuildNumTuple
= tuple()
155 BuildNumString
= ' ' + ' '.join(BuildNumTuple
)
157 #if VerString == '' and
158 if BuildNumString
== '':
159 if self
.Optional
== True :
160 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
163 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss Version Section value" %InfFileName
)
165 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
166 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
169 IsMakefile
=IsMakefile
)
170 OutputFileList
.append(OutputFile
)
173 # If Section Type is 'UI'
175 elif SectionType
== 'UI':
177 InfOverrideUiString
= False
178 if FfsInf
.Ui
is not None:
179 StringData
= FfsInf
.Ui
180 InfOverrideUiString
= True
182 if InfOverrideUiString
:
184 if IsMakefile
and StringData
== ModuleNameStr
:
185 StringData
= "$(MODULE_NAME)"
186 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
187 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
188 Ui
=StringData
, IsMakefile
=IsMakefile
)
189 OutputFileList
.append(OutputFile
)
192 for File
in FileList
:
194 Num
= '%s.%d' %(SecNum
, Index
)
195 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
199 if IsMakefile
and UiString
== ModuleNameStr
:
200 UiString
= "$(MODULE_NAME)"
201 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
202 Ui
=UiString
, IsMakefile
=IsMakefile
)
203 OutputFileList
.append(OutputFile
)
205 if StringData
is not None and len(StringData
) > 0:
206 UiTuple
= ('-n', '"' + StringData
+ '"')
210 if self
.Optional
== True :
211 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
214 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss UI Section value" %InfFileName
)
217 if IsMakefile
and StringData
== ModuleNameStr
:
218 StringData
= "$(MODULE_NAME)"
219 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
220 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
221 Ui
=StringData
, IsMakefile
=IsMakefile
)
222 OutputFileList
.append(OutputFile
)
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
))
235 """Convert the File to Section file one by one """
236 for File
in FileList
:
237 """ Copy Map file to FFS output path """
239 Num
= '%s.%d' %(SecNum
, Index
)
240 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
241 File
= GenFdsGlobalVariable
.MacroExtend(File
, Dict
)
243 #Get PE Section alignment when align is set to AUTO
244 if self
.Alignment
== 'Auto' and (SectionType
== 'PE32' or SectionType
== 'TE'):
245 ImageObj
= PeImageClass (File
)
246 if ImageObj
.SectionAlignment
< 0x400:
247 Align
= str (ImageObj
.SectionAlignment
)
248 elif ImageObj
.SectionAlignment
< 0x100000:
249 Align
= str (ImageObj
.SectionAlignment
/ 0x400) + 'K'
251 Align
= str (ImageObj
.SectionAlignment
/ 0x100000) + 'M'
253 if File
[(len(File
)-4):] == '.efi':
254 MapFile
= File
.replace('.efi', '.map')
255 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
257 if GenFdsGlobalVariable
.CopyList
== []:
258 GenFdsGlobalVariable
.CopyList
= [(MapFile
, CopyMapFile
)]
260 GenFdsGlobalVariable
.CopyList
.append((MapFile
, CopyMapFile
))
262 if os
.path
.exists(MapFile
):
263 if not os
.path
.exists(CopyMapFile
) or \
264 (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
265 CopyLongFilePath(MapFile
, CopyMapFile
)
268 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
270 if GenFdsGlobalVariable
.CopyList
== []:
271 GenFdsGlobalVariable
.CopyList
= [(File
, FileBeforeStrip
)]
273 GenFdsGlobalVariable
.CopyList
.append((File
, FileBeforeStrip
))
275 if not os
.path
.exists(FileBeforeStrip
) or \
276 (os
.path
.getmtime(File
) > os
.path
.getmtime(FileBeforeStrip
)):
277 CopyLongFilePath(File
, FileBeforeStrip
)
278 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
279 GenFdsGlobalVariable
.GenerateFirmwareImage(
283 IsMakefile
= IsMakefile
287 """For TE Section call GenFw to generate TE image"""
289 if SectionType
== 'TE':
290 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
291 GenFdsGlobalVariable
.GenerateFirmwareImage(
295 IsMakefile
= IsMakefile
299 """Call GenSection"""
300 GenFdsGlobalVariable
.GenerateSection(OutputFile
,
302 Section
.Section
.SectionType
.get (SectionType
),
303 IsMakefile
=IsMakefile
305 OutputFileList
.append(OutputFile
)
307 return OutputFileList
, Align