]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/EfiSection.py
3eb4e23842f45d518c485374932f21eab3fa2f0e
2 # process rule section generation
4 # Copyright (c) 2007, 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
24 from CommonDataClass
.FdfClass
import EfiSectionClassObject
26 from Common
import EdkLogger
27 from Common
.BuildToolError
import *
28 from Common
.Misc
import PeImageClass
30 ## generate rule section
33 class EfiSection (EfiSectionClassObject
):
37 # @param self The object pointer
40 EfiSectionClassObject
.__init
__(self
)
42 ## GenSection() method
44 # Generate rule section
46 # @param self The object pointer
47 # @param OutputPath Where to place output file
48 # @param ModuleName Which module this section belongs to
49 # @param SecNum Index of section
50 # @param KeyStringList Filter for inputs of section generation
51 # @param FfsInf FfsInfStatement object that contains this section data
52 # @param Dict dictionary contains macro and its value
53 # @retval tuple (Generated file name list, section alignment)
55 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}) :
57 if self
.FileName
!= None and self
.FileName
.startswith('PCD('):
58 self
.FileName
= GenFdsGlobalVariable
.GetPcdValue(self
.FileName
)
59 """Prepare the parameter of GenSection"""
61 InfFileName
= FfsInf
.InfFileName
62 SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
63 Filename
= FfsInf
.__ExtendMacro
__(self
.FileName
)
64 BuildNum
= FfsInf
.__ExtendMacro
__(self
.BuildNum
)
65 StringData
= FfsInf
.__ExtendMacro
__(self
.StringData
)
67 if FfsInf
.ModuleType
in ('SEC', 'PEI_CORE', 'PEIM') and SectionType
in ('TE', 'PE32'):
68 if FfsInf
.KeepReloc
!= None:
69 NoStrip
= FfsInf
.KeepReloc
70 elif FfsInf
.KeepRelocFromRule
!= None:
71 NoStrip
= FfsInf
.KeepRelocFromRule
72 elif self
.KeepReloc
!= None:
73 NoStrip
= self
.KeepReloc
74 elif FfsInf
.ShadowFromInfFile
!= None:
75 NoStrip
= FfsInf
.ShadowFromInfFile
77 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Module %s apply rule for None!" %ModuleName
)
79 """If the file name was pointed out, add it in FileList"""
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 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FileType
, self
.FileExtension
, Dict
)
96 return FileList
, self
.Alignment
100 """ If Section type is 'VERSION'"""
102 if SectionType
== 'VERSION':
104 InfOverrideVerString
= False
105 if FfsInf
.Version
!= None:
106 #StringData = FfsInf.Version
107 BuildNum
= FfsInf
.Version
108 InfOverrideVerString
= True
110 if InfOverrideVerString
:
111 #VerTuple = ('-n', '"' + StringData + '"')
112 if BuildNum
!= None and BuildNum
!= '':
113 BuildNumTuple
= ('-j', BuildNum
)
115 BuildNumTuple
= tuple()
118 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
119 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
122 OutputFileList
.append(OutputFile
)
125 for File
in FileList
:
127 Num
= '%s.%d' %(SecNum
, Index
)
128 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
133 if BuildNum
!= None and BuildNum
!= '':
134 BuildNumTuple
= ('-j', BuildNum
)
135 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
138 OutputFileList
.append(OutputFile
)
141 BuildNum
= StringData
142 if BuildNum
!= None and BuildNum
!= '':
143 BuildNumTuple
= ('-j', BuildNum
)
145 BuildNumTuple
= tuple()
146 BuildNumString
= ' ' + ' '.join(BuildNumTuple
)
148 #if VerString == '' and
149 if BuildNumString
== '':
150 if self
.Optional
== True :
151 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
154 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss Version Section value" %InfFileName
)
156 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
157 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
160 OutputFileList
.append(OutputFile
)
163 # If Section Type is 'UI'
165 elif SectionType
== 'UI':
167 InfOverrideUiString
= False
168 if FfsInf
.Ui
!= None:
169 StringData
= FfsInf
.Ui
170 InfOverrideUiString
= True
172 if InfOverrideUiString
:
174 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
175 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
177 OutputFileList
.append(OutputFile
)
180 for File
in FileList
:
182 Num
= '%s.%d' %(SecNum
, Index
)
183 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
187 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
189 OutputFileList
.append(OutputFile
)
191 if StringData
!= None and len(StringData
) > 0:
192 UiTuple
= ('-n', '"' + StringData
+ '"')
196 if self
.Optional
== True :
197 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
200 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss UI Section value" %InfFileName
)
203 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
204 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
206 OutputFileList
.append(OutputFile
)
210 """If File List is empty"""
212 if self
.Optional
== True:
213 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
216 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Output file for %s section could not be found for %s" % (SectionType
, InfFileName
))
219 """Convert the File to Section file one by one """
220 for File
in FileList
:
221 """ Copy Map file to FFS output path """
223 Num
= '%s.%d' %(SecNum
, Index
)
224 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
225 File
= GenFdsGlobalVariable
.MacroExtend(File
, Dict
)
227 #Get PE Section alignment when align is set to AUTO
228 if self
.Alignment
== 'Auto' and (SectionType
== 'PE32' or SectionType
== 'TE'):
229 ImageObj
= PeImageClass (File
)
230 if ImageObj
.SectionAlignment
< 0x400:
231 self
.Alignment
= str (ImageObj
.SectionAlignment
)
233 self
.Alignment
= str (ImageObj
.SectionAlignment
/ 0x400) + 'K'
235 if File
[(len(File
)-4):] == '.efi':
236 MapFile
= File
.replace('.efi', '.map')
237 if os
.path
.exists(MapFile
):
238 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
239 if not os
.path
.exists(CopyMapFile
) or \
240 (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
241 shutil
.copyfile(MapFile
, CopyMapFile
)
244 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
245 if not os
.path
.exists(FileBeforeStrip
) or \
246 (os
.path
.getmtime(File
) > os
.path
.getmtime(FileBeforeStrip
)):
247 shutil
.copyfile(File
, FileBeforeStrip
)
248 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
249 GenFdsGlobalVariable
.GenerateFirmwareImage(
256 """For TE Section call GenFw to generate TE image"""
258 if SectionType
== 'TE':
259 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
260 GenFdsGlobalVariable
.GenerateFirmwareImage(
267 """Call GenSection"""
268 GenFdsGlobalVariable
.GenerateSection(OutputFile
,
270 Section
.Section
.SectionType
.get (SectionType
)
272 OutputFileList
.append(OutputFile
)
274 return OutputFileList
, self
.Alignment