]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/EfiSection.py
f8573b5c7d1b03bfcef1e0843744967055358a69
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.
18 from __future__
import absolute_import
21 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
23 from .Ffs
import SectionSuffix
24 import Common
.LongFilePathOs
as os
25 from CommonDataClass
.FdfClass
import EfiSectionClassObject
26 from Common
import EdkLogger
27 from Common
.BuildToolError
import *
28 from Common
.Misc
import PeImageClass
29 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
30 from Common
.LongFilePathSupport
import CopyLongFilePath
31 from Common
.DataType
import *
33 ## generate rule section
36 class EfiSection (EfiSectionClassObject
):
40 # @param self The object pointer
43 EfiSectionClassObject
.__init
__(self
)
45 ## GenSection() method
47 # Generate rule 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 list, section alignment)
58 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}, IsMakefile
= False) :
60 if self
.FileName
is not None and self
.FileName
.startswith('PCD('):
61 self
.FileName
= GenFdsGlobalVariable
.GetPcdValue(self
.FileName
)
62 """Prepare the parameter of GenSection"""
63 if FfsInf
is not None :
64 InfFileName
= FfsInf
.InfFileName
65 SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
66 Filename
= FfsInf
.__ExtendMacro
__(self
.FileName
)
67 BuildNum
= FfsInf
.__ExtendMacro
__(self
.BuildNum
)
68 StringData
= FfsInf
.__ExtendMacro
__(self
.StringData
)
69 ModuleNameStr
= FfsInf
.__ExtendMacro
__('$(MODULE_NAME)')
71 if FfsInf
.ModuleType
in (SUP_MODULE_SEC
, SUP_MODULE_PEI_CORE
, SUP_MODULE_PEIM
) and SectionType
in (BINARY_FILE_TYPE_TE
, BINARY_FILE_TYPE_PE32
):
72 if FfsInf
.KeepReloc
is not None:
73 NoStrip
= FfsInf
.KeepReloc
74 elif FfsInf
.KeepRelocFromRule
is not None:
75 NoStrip
= FfsInf
.KeepRelocFromRule
76 elif self
.KeepReloc
is not None:
77 NoStrip
= self
.KeepReloc
78 elif FfsInf
.ShadowFromInfFile
is not None:
79 NoStrip
= FfsInf
.ShadowFromInfFile
81 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Module %s apply rule for None!" %ModuleName
)
83 """If the file name was pointed out, add it in FileList"""
85 if Filename
is not None:
86 Filename
= GenFdsGlobalVariable
.MacroExtend(Filename
, Dict
)
87 # check if the path is absolute or relative
88 if os
.path
.isabs(Filename
):
89 Filename
= os
.path
.normpath(Filename
)
91 Filename
= os
.path
.normpath(os
.path
.join(FfsInf
.EfiOutputPath
, Filename
))
94 FileList
.append(Filename
)
95 elif os
.path
.exists(Filename
):
96 FileList
.append(Filename
)
98 SuffixMap
= FfsInf
.GetFinalTargetSuffixMap()
99 if '.depex' in SuffixMap
:
100 FileList
.append(Filename
)
102 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FileType
, self
.FileExtension
, Dict
, IsMakefile
=IsMakefile
)
104 return FileList
, self
.Alignment
107 Align
= self
.Alignment
109 """ If Section type is 'VERSION'"""
111 if SectionType
== 'VERSION':
113 InfOverrideVerString
= False
114 if FfsInf
.Version
is not None:
115 #StringData = FfsInf.Version
116 BuildNum
= FfsInf
.Version
117 InfOverrideVerString
= True
119 if InfOverrideVerString
:
120 #VerTuple = ('-n', '"' + StringData + '"')
121 if BuildNum
is not None and BuildNum
!= '':
122 BuildNumTuple
= ('-j', BuildNum
)
124 BuildNumTuple
= tuple()
127 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
128 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
131 IsMakefile
=IsMakefile
)
132 OutputFileList
.append(OutputFile
)
135 for File
in FileList
:
137 Num
= '%s.%d' %(SecNum
, Index
)
138 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
143 if BuildNum
is not None and BuildNum
!= '':
144 BuildNumTuple
= ('-j', BuildNum
)
145 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
148 IsMakefile
=IsMakefile
)
149 OutputFileList
.append(OutputFile
)
152 BuildNum
= StringData
153 if BuildNum
is not None and BuildNum
!= '':
154 BuildNumTuple
= ('-j', BuildNum
)
156 BuildNumTuple
= tuple()
157 BuildNumString
= ' ' + ' '.join(BuildNumTuple
)
159 #if VerString == '' and
160 if BuildNumString
== '':
161 if self
.Optional
== True :
162 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
165 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss Version Section value" %InfFileName
)
167 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
168 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
171 IsMakefile
=IsMakefile
)
172 OutputFileList
.append(OutputFile
)
175 # If Section Type is BINARY_FILE_TYPE_UI
177 elif SectionType
== BINARY_FILE_TYPE_UI
:
179 InfOverrideUiString
= False
180 if FfsInf
.Ui
is not None:
181 StringData
= FfsInf
.Ui
182 InfOverrideUiString
= True
184 if InfOverrideUiString
:
186 if IsMakefile
and StringData
== ModuleNameStr
:
187 StringData
= "$(MODULE_NAME)"
188 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
189 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
190 Ui
=StringData
, IsMakefile
=IsMakefile
)
191 OutputFileList
.append(OutputFile
)
194 for File
in FileList
:
196 Num
= '%s.%d' %(SecNum
, Index
)
197 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
201 if IsMakefile
and UiString
== ModuleNameStr
:
202 UiString
= "$(MODULE_NAME)"
203 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
204 Ui
=UiString
, IsMakefile
=IsMakefile
)
205 OutputFileList
.append(OutputFile
)
207 if StringData
is not None and len(StringData
) > 0:
208 UiTuple
= ('-n', '"' + StringData
+ '"')
212 if self
.Optional
== True :
213 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
216 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss UI Section value" %InfFileName
)
219 if IsMakefile
and StringData
== ModuleNameStr
:
220 StringData
= "$(MODULE_NAME)"
221 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + SectionSuffix
.get(SectionType
))
222 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
223 Ui
=StringData
, IsMakefile
=IsMakefile
)
224 OutputFileList
.append(OutputFile
)
228 """If File List is empty"""
230 if self
.Optional
== True:
231 GenFdsGlobalVariable
.VerboseLogger("Optional Section don't exist!")
234 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Output file for %s section could not be found for %s" % (SectionType
, InfFileName
))
237 """Convert the File to Section file one by one """
238 for File
in FileList
:
239 """ Copy Map file to FFS output path """
241 Num
= '%s.%d' %(SecNum
, Index
)
242 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ SectionSuffix
.get(SectionType
))
243 File
= GenFdsGlobalVariable
.MacroExtend(File
, Dict
)
245 #Get PE Section alignment when align is set to AUTO
246 if self
.Alignment
== 'Auto' and (SectionType
== BINARY_FILE_TYPE_PE32
or SectionType
== BINARY_FILE_TYPE_TE
):
247 ImageObj
= PeImageClass (File
)
248 if ImageObj
.SectionAlignment
< 0x400:
249 Align
= str (ImageObj
.SectionAlignment
)
250 elif ImageObj
.SectionAlignment
< 0x100000:
251 Align
= str (ImageObj
.SectionAlignment
/ 0x400) + 'K'
253 Align
= str (ImageObj
.SectionAlignment
/ 0x100000) + 'M'
255 if File
[(len(File
)-4):] == '.efi':
256 MapFile
= File
.replace('.efi', '.map')
257 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
259 if GenFdsGlobalVariable
.CopyList
== []:
260 GenFdsGlobalVariable
.CopyList
= [(MapFile
, CopyMapFile
)]
262 GenFdsGlobalVariable
.CopyList
.append((MapFile
, CopyMapFile
))
264 if os
.path
.exists(MapFile
):
265 if not os
.path
.exists(CopyMapFile
) or \
266 (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
267 CopyLongFilePath(MapFile
, CopyMapFile
)
270 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
272 if GenFdsGlobalVariable
.CopyList
== []:
273 GenFdsGlobalVariable
.CopyList
= [(File
, FileBeforeStrip
)]
275 GenFdsGlobalVariable
.CopyList
.append((File
, FileBeforeStrip
))
277 if not os
.path
.exists(FileBeforeStrip
) or \
278 (os
.path
.getmtime(File
) > os
.path
.getmtime(FileBeforeStrip
)):
279 CopyLongFilePath(File
, FileBeforeStrip
)
280 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
281 GenFdsGlobalVariable
.GenerateFirmwareImage(
285 IsMakefile
= IsMakefile
289 """For TE Section call GenFw to generate TE image"""
291 if SectionType
== BINARY_FILE_TYPE_TE
:
292 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
293 GenFdsGlobalVariable
.GenerateFirmwareImage(
297 IsMakefile
= IsMakefile
301 """Call GenSection"""
302 GenFdsGlobalVariable
.GenerateSection(OutputFile
,
304 Section
.Section
.SectionType
.get (SectionType
),
305 IsMakefile
=IsMakefile
307 OutputFileList
.append(OutputFile
)
309 return OutputFileList
, Align