]>
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
30 from Common
.DataType
import *
32 ## generate rule section
35 class EfiSection (EfiSectionClassObject
):
39 # @param self The object pointer
42 EfiSectionClassObject
.__init
__(self
)
44 ## GenSection() method
46 # Generate rule 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 list, section alignment)
57 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}, IsMakefile
= False) :
59 if self
.FileName
is not None and self
.FileName
.startswith('PCD('):
60 self
.FileName
= GenFdsGlobalVariable
.GetPcdValue(self
.FileName
)
61 """Prepare the parameter of GenSection"""
62 if FfsInf
is not None :
63 InfFileName
= FfsInf
.InfFileName
64 SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
65 Filename
= FfsInf
.__ExtendMacro
__(self
.FileName
)
66 BuildNum
= FfsInf
.__ExtendMacro
__(self
.BuildNum
)
67 StringData
= FfsInf
.__ExtendMacro
__(self
.StringData
)
68 ModuleNameStr
= FfsInf
.__ExtendMacro
__('$(MODULE_NAME)')
70 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
):
71 if FfsInf
.KeepReloc
is not None:
72 NoStrip
= FfsInf
.KeepReloc
73 elif FfsInf
.KeepRelocFromRule
is not None:
74 NoStrip
= FfsInf
.KeepRelocFromRule
75 elif self
.KeepReloc
is not None:
76 NoStrip
= self
.KeepReloc
77 elif FfsInf
.ShadowFromInfFile
is not None:
78 NoStrip
= FfsInf
.ShadowFromInfFile
80 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Module %s apply rule for None!" %ModuleName
)
82 """If the file name was pointed out, add it in FileList"""
84 if Filename
is not None:
85 Filename
= GenFdsGlobalVariable
.MacroExtend(Filename
, Dict
)
86 # check if the path is absolute or relative
87 if os
.path
.isabs(Filename
):
88 Filename
= os
.path
.normpath(Filename
)
90 Filename
= os
.path
.normpath(os
.path
.join(FfsInf
.EfiOutputPath
, Filename
))
93 FileList
.append(Filename
)
94 elif os
.path
.exists(Filename
):
95 FileList
.append(Filename
)
97 SuffixMap
= FfsInf
.GetFinalTargetSuffixMap()
98 if '.depex' in SuffixMap
:
99 FileList
.append(Filename
)
101 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FileType
, self
.FileExtension
, Dict
, IsMakefile
=IsMakefile
)
103 return FileList
, self
.Alignment
106 Align
= self
.Alignment
108 """ If Section type is 'VERSION'"""
110 if SectionType
== 'VERSION':
112 InfOverrideVerString
= False
113 if FfsInf
.Version
is not None:
114 #StringData = FfsInf.Version
115 BuildNum
= FfsInf
.Version
116 InfOverrideVerString
= True
118 if InfOverrideVerString
:
119 #VerTuple = ('-n', '"' + StringData + '"')
120 if BuildNum
is not None and BuildNum
!= '':
121 BuildNumTuple
= ('-j', BuildNum
)
123 BuildNumTuple
= tuple()
126 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
127 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
130 IsMakefile
=IsMakefile
)
131 OutputFileList
.append(OutputFile
)
134 for File
in FileList
:
136 Num
= '%s.%d' %(SecNum
, Index
)
137 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ Ffs
.SectionSuffix
.get(SectionType
))
142 if BuildNum
is not None and BuildNum
!= '':
143 BuildNumTuple
= ('-j', BuildNum
)
144 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
147 IsMakefile
=IsMakefile
)
148 OutputFileList
.append(OutputFile
)
151 BuildNum
= StringData
152 if BuildNum
is not None and BuildNum
!= '':
153 BuildNumTuple
= ('-j', BuildNum
)
155 BuildNumTuple
= tuple()
156 BuildNumString
= ' ' + ' '.join(BuildNumTuple
)
158 #if VerString == '' and
159 if BuildNumString
== '':
160 if self
.Optional
== True :
161 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
164 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss Version Section value" %InfFileName
)
166 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
167 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
170 IsMakefile
=IsMakefile
)
171 OutputFileList
.append(OutputFile
)
174 # If Section Type is BINARY_FILE_TYPE_UI
176 elif SectionType
== BINARY_FILE_TYPE_UI
:
178 InfOverrideUiString
= False
179 if FfsInf
.Ui
is not None:
180 StringData
= FfsInf
.Ui
181 InfOverrideUiString
= True
183 if InfOverrideUiString
:
185 if IsMakefile
and StringData
== ModuleNameStr
:
186 StringData
= "$(MODULE_NAME)"
187 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
188 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
189 Ui
=StringData
, IsMakefile
=IsMakefile
)
190 OutputFileList
.append(OutputFile
)
193 for File
in FileList
:
195 Num
= '%s.%d' %(SecNum
, Index
)
196 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ Ffs
.SectionSuffix
.get(SectionType
))
200 if IsMakefile
and UiString
== ModuleNameStr
:
201 UiString
= "$(MODULE_NAME)"
202 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
203 Ui
=UiString
, IsMakefile
=IsMakefile
)
204 OutputFileList
.append(OutputFile
)
206 if StringData
is not None and len(StringData
) > 0:
207 UiTuple
= ('-n', '"' + StringData
+ '"')
211 if self
.Optional
== True :
212 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
215 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss UI Section value" %InfFileName
)
218 if IsMakefile
and StringData
== ModuleNameStr
:
219 StringData
= "$(MODULE_NAME)"
220 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
221 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
222 Ui
=StringData
, IsMakefile
=IsMakefile
)
223 OutputFileList
.append(OutputFile
)
227 """If File List is empty"""
229 if self
.Optional
== True:
230 GenFdsGlobalVariable
.VerboseLogger("Optional Section don't exist!")
233 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Output file for %s section could not be found for %s" % (SectionType
, InfFileName
))
236 """Convert the File to Section file one by one """
237 for File
in FileList
:
238 """ Copy Map file to FFS output path """
240 Num
= '%s.%d' %(SecNum
, Index
)
241 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ Ffs
.SectionSuffix
.get(SectionType
))
242 File
= GenFdsGlobalVariable
.MacroExtend(File
, Dict
)
244 #Get PE Section alignment when align is set to AUTO
245 if self
.Alignment
== 'Auto' and (SectionType
== BINARY_FILE_TYPE_PE32
or SectionType
== BINARY_FILE_TYPE_TE
):
246 ImageObj
= PeImageClass (File
)
247 if ImageObj
.SectionAlignment
< 0x400:
248 Align
= str (ImageObj
.SectionAlignment
)
249 elif ImageObj
.SectionAlignment
< 0x100000:
250 Align
= str (ImageObj
.SectionAlignment
/ 0x400) + 'K'
252 Align
= str (ImageObj
.SectionAlignment
/ 0x100000) + 'M'
254 if File
[(len(File
)-4):] == '.efi':
255 MapFile
= File
.replace('.efi', '.map')
256 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
258 if GenFdsGlobalVariable
.CopyList
== []:
259 GenFdsGlobalVariable
.CopyList
= [(MapFile
, CopyMapFile
)]
261 GenFdsGlobalVariable
.CopyList
.append((MapFile
, CopyMapFile
))
263 if os
.path
.exists(MapFile
):
264 if not os
.path
.exists(CopyMapFile
) or \
265 (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
266 CopyLongFilePath(MapFile
, CopyMapFile
)
269 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
271 if GenFdsGlobalVariable
.CopyList
== []:
272 GenFdsGlobalVariable
.CopyList
= [(File
, FileBeforeStrip
)]
274 GenFdsGlobalVariable
.CopyList
.append((File
, FileBeforeStrip
))
276 if not os
.path
.exists(FileBeforeStrip
) or \
277 (os
.path
.getmtime(File
) > os
.path
.getmtime(FileBeforeStrip
)):
278 CopyLongFilePath(File
, FileBeforeStrip
)
279 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
280 GenFdsGlobalVariable
.GenerateFirmwareImage(
284 IsMakefile
= IsMakefile
288 """For TE Section call GenFw to generate TE image"""
290 if SectionType
== BINARY_FILE_TYPE_TE
:
291 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
292 GenFdsGlobalVariable
.GenerateFirmwareImage(
296 IsMakefile
= IsMakefile
300 """Call GenSection"""
301 GenFdsGlobalVariable
.GenerateSection(OutputFile
,
303 Section
.Section
.SectionType
.get (SectionType
),
304 IsMakefile
=IsMakefile
306 OutputFileList
.append(OutputFile
)
308 return OutputFileList
, Align