]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/GenFds/EfiSection.py
BaseTools: Enhance BaseTools supports FixedAtBuild usage in VFR file
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / EfiSection.py
... / ...
CommitLineData
1## @file\r
2# process rule section generation\r
3#\r
4# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# This program and the accompanying materials\r
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
18from struct import *\r
19import Section\r
20from GenFdsGlobalVariable import GenFdsGlobalVariable\r
21import subprocess\r
22from Ffs import Ffs\r
23import Common.LongFilePathOs as os\r
24from CommonDataClass.FdfClass import EfiSectionClassObject\r
25from Common import EdkLogger\r
26from Common.BuildToolError import *\r
27from Common.Misc import PeImageClass\r
28from Common.LongFilePathSupport import OpenLongFilePath as open\r
29from Common.LongFilePathSupport import CopyLongFilePath\r
30\r
31## generate rule section\r
32#\r
33#\r
34class EfiSection (EfiSectionClassObject):\r
35\r
36 ## The constructor\r
37 #\r
38 # @param self The object pointer\r
39 #\r
40 def __init__(self):\r
41 EfiSectionClassObject.__init__(self)\r
42\r
43 ## GenSection() method\r
44 #\r
45 # Generate rule section\r
46 #\r
47 # @param self The object pointer\r
48 # @param OutputPath Where to place output file\r
49 # @param ModuleName Which module this section belongs to\r
50 # @param SecNum Index of section\r
51 # @param KeyStringList Filter for inputs of section generation\r
52 # @param FfsInf FfsInfStatement object that contains this section data\r
53 # @param Dict dictionary contains macro and its value\r
54 # @retval tuple (Generated file name list, section alignment)\r
55 #\r
56 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}) :\r
57 \r
58 if self.FileName != None and self.FileName.startswith('PCD('):\r
59 self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)\r
60 """Prepare the parameter of GenSection"""\r
61 if FfsInf != None :\r
62 InfFileName = FfsInf.InfFileName\r
63 SectionType = FfsInf.__ExtendMacro__(self.SectionType)\r
64 Filename = FfsInf.__ExtendMacro__(self.FileName)\r
65 BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)\r
66 StringData = FfsInf.__ExtendMacro__(self.StringData)\r
67 NoStrip = True\r
68 if FfsInf.ModuleType in ('SEC', 'PEI_CORE', 'PEIM') and SectionType in ('TE', 'PE32'):\r
69 if FfsInf.KeepReloc != None:\r
70 NoStrip = FfsInf.KeepReloc\r
71 elif FfsInf.KeepRelocFromRule != None:\r
72 NoStrip = FfsInf.KeepRelocFromRule\r
73 elif self.KeepReloc != None:\r
74 NoStrip = self.KeepReloc\r
75 elif FfsInf.ShadowFromInfFile != None:\r
76 NoStrip = FfsInf.ShadowFromInfFile\r
77 else:\r
78 EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule for None!" %ModuleName)\r
79\r
80 """If the file name was pointed out, add it in FileList"""\r
81 FileList = []\r
82 if Filename != None:\r
83 Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)\r
84 # check if the path is absolute or relative\r
85 if os.path.isabs(Filename):\r
86 Filename = os.path.normpath(Filename)\r
87 else:\r
88 Filename = os.path.normpath(os.path.join(FfsInf.EfiOutputPath, Filename))\r
89\r
90 if not self.Optional:\r
91 FileList.append(Filename)\r
92 elif os.path.exists(Filename):\r
93 FileList.append(Filename)\r
94 else:\r
95 FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict)\r
96 if IsSect :\r
97 return FileList, self.Alignment\r
98\r
99 Index = 0\r
100 Align = self.Alignment\r
101\r
102 """ If Section type is 'VERSION'"""\r
103 OutputFileList = []\r
104 if SectionType == 'VERSION':\r
105\r
106 InfOverrideVerString = False\r
107 if FfsInf.Version != None:\r
108 #StringData = FfsInf.Version\r
109 BuildNum = FfsInf.Version\r
110 InfOverrideVerString = True\r
111\r
112 if InfOverrideVerString:\r
113 #VerTuple = ('-n', '"' + StringData + '"')\r
114 if BuildNum != None and BuildNum != '':\r
115 BuildNumTuple = ('-j', BuildNum)\r
116 else:\r
117 BuildNumTuple = tuple()\r
118\r
119 Num = SecNum\r
120 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
121 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
122 #Ui=StringData, \r
123 Ver=BuildNum)\r
124 OutputFileList.append(OutputFile)\r
125\r
126 elif FileList != []:\r
127 for File in FileList:\r
128 Index = Index + 1\r
129 Num = '%s.%d' %(SecNum , Index)\r
130 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
131 f = open(File, 'r')\r
132 VerString = f.read()\r
133 f.close()\r
134 BuildNum = VerString\r
135 if BuildNum != None and BuildNum != '':\r
136 BuildNumTuple = ('-j', BuildNum)\r
137 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
138 #Ui=VerString, \r
139 Ver=BuildNum)\r
140 OutputFileList.append(OutputFile)\r
141\r
142 else:\r
143 BuildNum = StringData\r
144 if BuildNum != None and BuildNum != '':\r
145 BuildNumTuple = ('-j', BuildNum)\r
146 else:\r
147 BuildNumTuple = tuple()\r
148 BuildNumString = ' ' + ' '.join(BuildNumTuple)\r
149\r
150 #if VerString == '' and \r
151 if BuildNumString == '':\r
152 if self.Optional == True :\r
153 GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r
154 return [], None\r
155 else:\r
156 EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName)\r
157 Num = SecNum\r
158 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
159 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
160 #Ui=VerString, \r
161 Ver=BuildNum)\r
162 OutputFileList.append(OutputFile)\r
163\r
164 #\r
165 # If Section Type is 'UI'\r
166 #\r
167 elif SectionType == 'UI':\r
168\r
169 InfOverrideUiString = False\r
170 if FfsInf.Ui != None:\r
171 StringData = FfsInf.Ui\r
172 InfOverrideUiString = True\r
173\r
174 if InfOverrideUiString:\r
175 Num = SecNum\r
176 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
177 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
178 Ui=StringData)\r
179 OutputFileList.append(OutputFile)\r
180\r
181 elif FileList != []:\r
182 for File in FileList:\r
183 Index = Index + 1\r
184 Num = '%s.%d' %(SecNum , Index)\r
185 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
186 f = open(File, 'r')\r
187 UiString = f.read()\r
188 f.close()\r
189 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
190 Ui=UiString)\r
191 OutputFileList.append(OutputFile)\r
192 else:\r
193 if StringData != None and len(StringData) > 0:\r
194 UiTuple = ('-n', '"' + StringData + '"')\r
195 else:\r
196 UiTuple = tuple()\r
197\r
198 if self.Optional == True :\r
199 GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r
200 return '', None\r
201 else:\r
202 EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss UI Section value" %InfFileName)\r
203\r
204 Num = SecNum\r
205 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
206 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
207 Ui=StringData)\r
208 OutputFileList.append(OutputFile)\r
209\r
210\r
211 else:\r
212 """If File List is empty"""\r
213 if FileList == [] :\r
214 if self.Optional == True:\r
215 GenFdsGlobalVariable.VerboseLogger("Optional Section don't exist!")\r
216 return [], None\r
217 else:\r
218 EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName))\r
219\r
220 else:\r
221 """Convert the File to Section file one by one """\r
222 for File in FileList:\r
223 """ Copy Map file to FFS output path """\r
224 Index = Index + 1\r
225 Num = '%s.%d' %(SecNum , Index)\r
226 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
227 File = GenFdsGlobalVariable.MacroExtend(File, Dict)\r
228 \r
229 #Get PE Section alignment when align is set to AUTO\r
230 if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r
231 ImageObj = PeImageClass (File)\r
232 if ImageObj.SectionAlignment < 0x400:\r
233 Align = str (ImageObj.SectionAlignment)\r
234 else:\r
235 Align = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
236\r
237 if File[(len(File)-4):] == '.efi':\r
238 MapFile = File.replace('.efi', '.map')\r
239 if os.path.exists(MapFile):\r
240 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
241 if not os.path.exists(CopyMapFile) or \\r
242 (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
243 CopyLongFilePath(MapFile, CopyMapFile)\r
244\r
245 if not NoStrip:\r
246 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
247 if not os.path.exists(FileBeforeStrip) or \\r
248 (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
249 CopyLongFilePath(File, FileBeforeStrip)\r
250 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
251 GenFdsGlobalVariable.GenerateFirmwareImage(\r
252 StrippedFile,\r
253 [File],\r
254 Strip=True\r
255 )\r
256 File = StrippedFile\r
257 \r
258 """For TE Section call GenFw to generate TE image"""\r
259\r
260 if SectionType == 'TE':\r
261 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
262 GenFdsGlobalVariable.GenerateFirmwareImage(\r
263 TeFile,\r
264 [File],\r
265 Type='te'\r
266 )\r
267 File = TeFile\r
268\r
269 """Call GenSection"""\r
270 GenFdsGlobalVariable.GenerateSection(OutputFile,\r
271 [File],\r
272 Section.Section.SectionType.get (SectionType)\r
273 )\r
274 OutputFileList.append(OutputFile)\r
275\r
276 return OutputFileList, Align\r