]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/EfiSection.py
2 # process rule section generation
4 # Copyright (c) 2007, Intel Corporation
6 # All rights reserved. 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.
19 from GenFdsGlobalVariable
import GenFdsGlobalVariable
23 from CommonDataClass
.FdfClass
import EfiSectionClassObject
25 from Common
import EdkLogger
26 from Common
.BuildToolError
import *
28 ## generate rule section
31 class EfiSection (EfiSectionClassObject
):
35 # @param self The object pointer
38 EfiSectionClassObject
.__init
__(self
)
40 ## GenSection() method
42 # Generate rule section
44 # @param self The object pointer
45 # @param OutputPath Where to place output file
46 # @param ModuleName Which module this section belongs to
47 # @param SecNum Index of section
48 # @param KeyStringList Filter for inputs of section generation
49 # @param FfsInf FfsInfStatement object that contains this section data
50 # @param Dict dictionary contains macro and its value
51 # @retval tuple (Generated file name list, section alignment)
53 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}) :
55 if self
.FileName
!= None and self
.FileName
.startswith('PCD('):
56 self
.FileName
= GenFdsGlobalVariable
.GetPcdValue(self
.FileName
)
57 """Prepare the parameter of GenSection"""
59 InfFileName
= FfsInf
.InfFileName
60 SectionType
= FfsInf
.__ExtendMacro
__(self
.SectionType
)
61 Filename
= FfsInf
.__ExtendMacro
__(self
.FileName
)
62 BuildNum
= FfsInf
.__ExtendMacro
__(self
.BuildNum
)
63 StringData
= FfsInf
.__ExtendMacro
__(self
.StringData
)
65 if FfsInf
.ModuleType
in ('SEC', 'PEI_CORE', 'PEIM') and SectionType
in ('TE', 'PE32'):
66 if FfsInf
.KeepReloc
!= None:
67 NoStrip
= FfsInf
.KeepReloc
68 elif FfsInf
.KeepRelocFromRule
!= None:
69 NoStrip
= FfsInf
.KeepRelocFromRule
70 elif self
.KeepReloc
!= None:
71 NoStrip
= self
.KeepReloc
72 elif FfsInf
.ShadowFromInfFile
!= 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"""
80 Filename
= GenFdsGlobalVariable
.MacroExtend(Filename
, Dict
)
82 FileList
.append(Filename
)
83 elif os
.path
.exists(Filename
):
84 FileList
.append(Filename
)
86 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FileType
, self
.FileExtension
, Dict
)
88 return FileList
, self
.Alignment
92 """ If Section type is 'VERSION'"""
94 if SectionType
== 'VERSION':
96 InfOverrideVerString
= False
97 if FfsInf
.Version
!= None:
98 #StringData = FfsInf.Version
99 BuildNum
= FfsInf
.Version
100 InfOverrideVerString
= True
102 if InfOverrideVerString
:
103 #VerTuple = ('-n', '"' + StringData + '"')
104 if BuildNum
!= None and BuildNum
!= '':
105 BuildNumTuple
= ('-j', BuildNum
)
107 BuildNumTuple
= tuple()
110 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
111 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
114 OutputFileList
.append(OutputFile
)
117 for File
in FileList
:
119 Num
= '%s.%d' %(SecNum
, Index
)
120 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
124 # VerTuple = ('-n', '"' + VerString + '"')
126 if BuildNum
!= None and BuildNum
!= '':
127 BuildNumTuple
= ('-j', BuildNum
)
128 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
131 OutputFileList
.append(OutputFile
)
134 # if StringData != None and len(StringData) > 0:
135 # VerTuple = ('-n', '"' + StringData + '"')
138 # VerString = ' ' + ' '.join(VerTuple)
139 BuildNum
= StringData
140 if BuildNum
!= None and BuildNum
!= '':
141 BuildNumTuple
= ('-j', BuildNum
)
143 BuildNumTuple
= tuple()
144 BuildNumString
= ' ' + ' '.join(BuildNumTuple
)
146 #if VerString == '' and
147 if BuildNumString
== '':
148 if self
.Optional
== True :
149 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
152 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss Version Section value" %InfFileName
)
154 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
155 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_VERSION',
158 OutputFileList
.append(OutputFile
)
161 # If Section Type is 'UI'
163 elif SectionType
== 'UI':
165 InfOverrideUiString
= False
166 if FfsInf
.Ui
!= None:
167 StringData
= FfsInf
.Ui
168 InfOverrideUiString
= True
170 if InfOverrideUiString
:
172 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
173 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
175 OutputFileList
.append(OutputFile
)
178 for File
in FileList
:
180 Num
= '%s.%d' %(SecNum
, Index
)
181 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
185 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
187 OutputFileList
.append(OutputFile
)
189 if StringData
!= None and len(StringData
) > 0:
190 UiTuple
= ('-n', '"' + StringData
+ '"')
194 if self
.Optional
== True :
195 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
198 EdkLogger
.error("GenFds", GENFDS_ERROR
, "File: %s miss UI Section value" %InfFileName
)
201 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + str(Num
) + Ffs
.SectionSuffix
.get(SectionType
))
202 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [], 'EFI_SECTION_USER_INTERFACE',
204 OutputFileList
.append(OutputFile
)
208 """If File List is empty"""
210 if self
.Optional
== True:
211 GenFdsGlobalVariable
.VerboseLogger( "Optional Section don't exist!")
214 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Output file for %s section could not be found for %s" % (SectionType
, InfFileName
))
217 """Convert the File to Section file one by one """
218 for File
in FileList
:
219 """ Copy Map file to FFS output path """
221 Num
= '%s.%d' %(SecNum
, Index
)
222 OutputFile
= os
.path
.join( OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get(SectionType
))
223 File
= GenFdsGlobalVariable
.MacroExtend(File
, Dict
)
224 if File
[(len(File
)-4):] == '.efi':
225 MapFile
= File
.replace('.efi', '.map')
226 if os
.path
.exists(MapFile
):
227 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
228 if not os
.path
.exists(CopyMapFile
) or \
229 (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
230 shutil
.copyfile(MapFile
, CopyMapFile
)
233 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
234 if not os
.path
.exists(FileBeforeStrip
) or \
235 (os
.path
.getmtime(File
) > os
.path
.getmtime(FileBeforeStrip
)):
236 shutil
.copyfile(File
, FileBeforeStrip
)
237 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
238 GenFdsGlobalVariable
.GenerateFirmwareImage(
240 [GenFdsGlobalVariable
.MacroExtend(File
, Dict
)],
244 """For TE Section call GenFw to generate TE image"""
246 if SectionType
== 'TE':
247 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
248 GenFdsGlobalVariable
.GenerateFirmwareImage(
250 [GenFdsGlobalVariable
.MacroExtend(File
, Dict
)],
255 """Call GenSection"""
256 GenFdsGlobalVariable
.GenerateSection(OutputFile
,
257 [GenFdsGlobalVariable
.MacroExtend(File
)],
258 Section
.Section
.SectionType
.get (SectionType
)
260 OutputFileList
.append(OutputFile
)
262 return OutputFileList
, self
.Alignment