]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
BaseTools: Remove unused logic for IPF
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFdsGlobalVariable.py
CommitLineData
f51461c8
LG
1## @file\r
2# Global variables for GenFds\r
3#\r
6735645d 4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
f51461c8
LG
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
1ccc4d89 18from __future__ import print_function\r
9e47e6f9
CJ
19from __future__ import absolute_import\r
20\r
1be2ed90 21import Common.LongFilePathOs as os\r
9e47e6f9
CJ
22from sys import stdout\r
23from subprocess import PIPE,Popen\r
24from struct import Struct\r
25from array import array\r
f51461c8 26\r
9e47e6f9 27from Common.BuildToolError import COMMAND_FAILURE,GENFDS_ERROR\r
f51461c8
LG
28from Common import EdkLogger\r
29from Common.Misc import SaveFileOnChange\r
30\r
31from Common.TargetTxtClassObject import TargetTxtClassObject\r
89a69d4b 32from Common.ToolDefClassObject import ToolDefClassObject, ToolDefDict\r
f51461c8
LG
33from AutoGen.BuildEngine import BuildRule\r
34import Common.DataType as DataType\r
35from Common.Misc import PathClass\r
1be2ed90 36from Common.LongFilePathSupport import OpenLongFilePath as open\r
05cc51ad 37from Common.MultipleWorkspace import MultipleWorkspace as mws\r
f51461c8
LG
38\r
39## Global variables\r
40#\r
41#\r
42class GenFdsGlobalVariable:\r
43 FvDir = ''\r
44 OutputDirDict = {}\r
45 BinDir = ''\r
46 # will be FvDir + os.sep + 'Ffs'\r
47 FfsDir = ''\r
48 FdfParser = None\r
49 LibDir = ''\r
50 WorkSpace = None\r
51 WorkSpaceDir = ''\r
97fa0ee9 52 ConfDir = ''\r
f51461c8
LG
53 EdkSourceDir = ''\r
54 OutputDirFromDscDict = {}\r
55 TargetName = ''\r
56 ToolChainTag = ''\r
57 RuleDict = {}\r
58 ArchList = None\r
f51461c8
LG
59 ActivePlatform = None\r
60 FvAddressFileName = ''\r
61 VerboseMode = False\r
62 DebugLevel = -1\r
63 SharpCounter = 0\r
64 SharpNumberPerLine = 40\r
65 FdfFile = ''\r
66 FdfFileTimeStamp = 0\r
67 FixedLoadAddress = False\r
68 PlatformName = ''\r
f7496d71 69\r
94c04559
CJ
70 BuildRuleFamily = DataType.TAB_COMPILER_MSFT\r
71 ToolChainFamily = DataType.TAB_COMPILER_MSFT\r
f51461c8 72 __BuildRuleDatabase = None\r
213ae077 73 GuidToolDefinition = {}\r
37de70b7
YZ
74 FfsCmdDict = {}\r
75 SecCmdList = []\r
76 CopyList = []\r
77 ModuleFile = ''\r
78 EnableGenfdsMultiThread = False\r
f7496d71 79\r
f51461c8
LG
80 #\r
81 # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.\r
82 # At the beginning of each generation of FV, false flag is appended to the list,\r
83 # after the call to GenerateSection returns, check the size of the output file,\r
84 # if it is greater than 0xFFFFFF, the tail flag in list is set to true,\r
85 # and EFI_FIRMWARE_FILE_SYSTEM3_GUID is passed to C GenFv.\r
86 # At the end of generation of FV, pop the flag.\r
87 # List is used as a stack to handle nested FV generation.\r
88 #\r
89 LargeFileInFvFlags = []\r
90 EFI_FIRMWARE_FILE_SYSTEM3_GUID = '5473C07A-3DCB-4dca-BD6F-1E9689E7349A'\r
91 LARGE_FILE_SIZE = 0x1000000\r
92\r
9e47e6f9 93 SectionHeader = Struct("3B 1B")\r
f7496d71 94\r
7de00838
GL
95 # FvName, FdName, CapName in FDF, Image file name\r
96 ImageBinDict = {}\r
97\r
f51461c8
LG
98 ## LoadBuildRule\r
99 #\r
100 @staticmethod\r
9e47e6f9 101 def _LoadBuildRule():\r
f51461c8
LG
102 if GenFdsGlobalVariable.__BuildRuleDatabase:\r
103 return GenFdsGlobalVariable.__BuildRuleDatabase\r
97fa0ee9 104 BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.ConfDir, "target.txt"))\r
f51461c8
LG
105 TargetTxt = TargetTxtClassObject()\r
106 if os.path.isfile(BuildConfigurationFile) == True:\r
107 TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)\r
108 if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:\r
109 BuildRuleFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
c93356ad 110 if not BuildRuleFile:\r
f51461c8
LG
111 BuildRuleFile = 'Conf/build_rule.txt'\r
112 GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)\r
113 ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
114 if ToolDefinitionFile == '':\r
115 ToolDefinitionFile = "Conf/tools_def.txt"\r
116 if os.path.isfile(ToolDefinitionFile):\r
117 ToolDef = ToolDefClassObject()\r
118 ToolDef.LoadToolDefFile(ToolDefinitionFile)\r
119 ToolDefinition = ToolDef.ToolsDefTxtDatabase\r
120 if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \\r
121 and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
122 and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
123 GenFdsGlobalVariable.BuildRuleFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]\r
f7496d71 124\r
f51461c8
LG
125 if DataType.TAB_TOD_DEFINES_FAMILY in ToolDefinition \\r
126 and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY] \\r
127 and ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
128 GenFdsGlobalVariable.ToolChainFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]\r
129 return GenFdsGlobalVariable.__BuildRuleDatabase\r
130\r
131 ## GetBuildRules\r
132 # @param Inf: object of InfBuildData\r
133 # @param Arch: current arch\r
134 #\r
135 @staticmethod\r
136 def GetBuildRules(Inf, Arch):\r
137 if not Arch:\r
55c84777 138 Arch = DataType.TAB_COMMON\r
f51461c8
LG
139\r
140 if not Arch in GenFdsGlobalVariable.OutputDirDict:\r
141 return {}\r
142\r
9e47e6f9 143 BuildRuleDatabase = GenFdsGlobalVariable._LoadBuildRule()\r
f51461c8
LG
144 if not BuildRuleDatabase:\r
145 return {}\r
146\r
147 PathClassObj = PathClass(Inf.MetaFile.File,\r
148 GenFdsGlobalVariable.WorkSpaceDir)\r
f51461c8
LG
149 BuildDir = os.path.join(\r
150 GenFdsGlobalVariable.OutputDirDict[Arch],\r
151 Arch,\r
152 PathClassObj.SubDir,\r
153 PathClassObj.BaseName\r
154 )\r
9e47e6f9
CJ
155 BinDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)\r
156 Macro = {\r
157 "WORKSPACE":GenFdsGlobalVariable.WorkSpaceDir,\r
158 "MODULE_NAME":Inf.BaseName,\r
159 "MODULE_GUID":Inf.Guid,\r
160 "MODULE_VERSION":Inf.Version,\r
161 "MODULE_TYPE":Inf.ModuleType,\r
162 "MODULE_FILE":str(PathClassObj),\r
163 "MODULE_FILE_BASE_NAME":PathClassObj.BaseName,\r
164 "MODULE_RELATIVE_DIR":PathClassObj.SubDir,\r
165 "MODULE_DIR":PathClassObj.SubDir,\r
166 "BASE_NAME":Inf.BaseName,\r
167 "ARCH":Arch,\r
168 "TOOLCHAIN":GenFdsGlobalVariable.ToolChainTag,\r
169 "TOOLCHAIN_TAG":GenFdsGlobalVariable.ToolChainTag,\r
170 "TOOL_CHAIN_TAG":GenFdsGlobalVariable.ToolChainTag,\r
171 "TARGET":GenFdsGlobalVariable.TargetName,\r
172 "BUILD_DIR":GenFdsGlobalVariable.OutputDirDict[Arch],\r
173 "BIN_DIR":BinDir,\r
174 "LIB_DIR":BinDir,\r
175 "MODULE_BUILD_DIR":BuildDir,\r
176 "OUTPUT_DIR":os.path.join(BuildDir, "OUTPUT"),\r
177 "DEBUG_DIR":os.path.join(BuildDir, "DEBUG")\r
178 }\r
179 \r
f51461c8
LG
180 BuildRules = {}\r
181 for Type in BuildRuleDatabase.FileTypeList:\r
182 #first try getting build rule by BuildRuleFamily\r
183 RuleObject = BuildRuleDatabase[Type, Inf.BuildType, Arch, GenFdsGlobalVariable.BuildRuleFamily]\r
184 if not RuleObject:\r
185 # build type is always module type, but ...\r
186 if Inf.ModuleType != Inf.BuildType:\r
187 RuleObject = BuildRuleDatabase[Type, Inf.ModuleType, Arch, GenFdsGlobalVariable.BuildRuleFamily]\r
188 #second try getting build rule by ToolChainFamily\r
189 if not RuleObject:\r
190 RuleObject = BuildRuleDatabase[Type, Inf.BuildType, Arch, GenFdsGlobalVariable.ToolChainFamily]\r
191 if not RuleObject:\r
192 # build type is always module type, but ...\r
193 if Inf.ModuleType != Inf.BuildType:\r
194 RuleObject = BuildRuleDatabase[Type, Inf.ModuleType, Arch, GenFdsGlobalVariable.ToolChainFamily]\r
195 if not RuleObject:\r
196 continue\r
197 RuleObject = RuleObject.Instantiate(Macro)\r
198 BuildRules[Type] = RuleObject\r
199 for Ext in RuleObject.SourceFileExtList:\r
200 BuildRules[Ext] = RuleObject\r
201 return BuildRules\r
202\r
203 ## GetModuleCodaTargetList\r
204 #\r
205 # @param Inf: object of InfBuildData\r
206 # @param Arch: current arch\r
207 #\r
208 @staticmethod\r
209 def GetModuleCodaTargetList(Inf, Arch):\r
210 BuildRules = GenFdsGlobalVariable.GetBuildRules(Inf, Arch)\r
211 if not BuildRules:\r
212 return []\r
213\r
214 TargetList = set()\r
215 FileList = []\r
97fa0ee9
YL
216\r
217 if not Inf.IsBinaryModule:\r
218 for File in Inf.Sources:\r
bc39c5cb
JC
219 if File.TagName in {"", DataType.TAB_STAR, GenFdsGlobalVariable.ToolChainTag} and \\r
220 File.ToolChainFamily in {"", DataType.TAB_STAR, GenFdsGlobalVariable.ToolChainFamily}:\r
97fa0ee9
YL
221 FileList.append((File, DataType.TAB_UNKNOWN_FILE))\r
222\r
f51461c8 223 for File in Inf.Binaries:\r
bc39c5cb 224 if File.Target in {DataType.TAB_COMMON, DataType.TAB_STAR, GenFdsGlobalVariable.TargetName}:\r
f51461c8
LG
225 FileList.append((File, File.Type))\r
226\r
227 for File, FileType in FileList:\r
228 LastTarget = None\r
229 RuleChain = []\r
230 SourceList = [File]\r
231 Index = 0\r
232 while Index < len(SourceList):\r
233 Source = SourceList[Index]\r
234 Index = Index + 1\r
f7496d71 235\r
9e47e6f9 236 if File.IsBinary and File == Source and Inf.Binaries and File in Inf.Binaries:\r
f51461c8
LG
237 # Skip all files that are not binary libraries\r
238 if not Inf.LibraryClass:\r
f7496d71 239 continue\r
f51461c8
LG
240 RuleObject = BuildRules[DataType.TAB_DEFAULT_BINARY_FILE]\r
241 elif FileType in BuildRules:\r
242 RuleObject = BuildRules[FileType]\r
243 elif Source.Ext in BuildRules:\r
244 RuleObject = BuildRules[Source.Ext]\r
245 else:\r
246 # stop at no more rules\r
247 if LastTarget:\r
248 TargetList.add(str(LastTarget))\r
249 break\r
f7496d71 250\r
f51461c8 251 FileType = RuleObject.SourceFileType\r
f7496d71 252\r
f51461c8
LG
253 # stop at STATIC_LIBRARY for library\r
254 if Inf.LibraryClass and FileType == DataType.TAB_STATIC_LIBRARY:\r
255 if LastTarget:\r
256 TargetList.add(str(LastTarget))\r
257 break\r
f7496d71 258\r
f51461c8
LG
259 Target = RuleObject.Apply(Source)\r
260 if not Target:\r
261 if LastTarget:\r
262 TargetList.add(str(LastTarget))\r
263 break\r
264 elif not Target.Outputs:\r
265 # Only do build for target with outputs\r
266 TargetList.add(str(Target))\r
f7496d71 267\r
f51461c8
LG
268 # to avoid cyclic rule\r
269 if FileType in RuleChain:\r
270 break\r
f7496d71 271\r
f51461c8
LG
272 RuleChain.append(FileType)\r
273 SourceList.extend(Target.Outputs)\r
274 LastTarget = Target\r
275 FileType = DataType.TAB_UNKNOWN_FILE\r
37de70b7
YZ
276 for Cmd in Target.Commands:\r
277 if "$(CP)" == Cmd.split()[0]:\r
278 CpTarget = Cmd.split()[2]\r
279 TargetList.add(CpTarget)\r
f51461c8
LG
280\r
281 return list(TargetList)\r
282\r
283 ## SetDir()\r
284 #\r
285 # @param OutputDir Output directory\r
286 # @param FdfParser FDF contents parser\r
287 # @param Workspace The directory of workspace\r
288 # @param ArchList The Arch list of platform\r
289 #\r
9e47e6f9 290 @staticmethod\r
f51461c8 291 def SetDir (OutputDir, FdfParser, WorkSpace, ArchList):\r
9e47e6f9 292 GenFdsGlobalVariable.VerboseLogger("GenFdsGlobalVariable.OutputDir:%s" % OutputDir)\r
f51461c8
LG
293 GenFdsGlobalVariable.FdfParser = FdfParser\r
294 GenFdsGlobalVariable.WorkSpace = WorkSpace\r
91fa33ee 295 GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], DataType.TAB_FV_DIRECTORY)\r
9e47e6f9 296 if not os.path.exists(GenFdsGlobalVariable.FvDir):\r
f51461c8
LG
297 os.makedirs(GenFdsGlobalVariable.FvDir)\r
298 GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
9e47e6f9 299 if not os.path.exists(GenFdsGlobalVariable.FfsDir):\r
f51461c8 300 os.makedirs(GenFdsGlobalVariable.FfsDir)\r
f51461c8 301\r
f51461c8
LG
302 #\r
303 # Create FV Address inf file\r
304 #\r
305 GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')\r
47fea6af 306 FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')\r
f51461c8
LG
307 #\r
308 # Add [Options]\r
309 #\r
9e47e6f9 310 FvAddressFile.writelines("[options]" + DataType.TAB_LINE_BREAK)\r
f51461c8
LG
311 BsAddress = '0'\r
312 for Arch in ArchList:\r
313 if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress:\r
314 BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress\r
315 break\r
316\r
317 FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
47fea6af 318 BsAddress + \\r
9e47e6f9 319 DataType.TAB_LINE_BREAK)\r
f51461c8
LG
320\r
321 RtAddress = '0'\r
9e47e6f9
CJ
322 for Arch in reversed(ArchList):\r
323 temp = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress\r
324 if temp:\r
325 RtAddress = temp\r
326 break\r
f51461c8
LG
327\r
328 FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
47fea6af 329 RtAddress + \\r
9e47e6f9 330 DataType.TAB_LINE_BREAK)\r
f51461c8
LG
331\r
332 FvAddressFile.close()\r
333\r
9e47e6f9 334 @staticmethod\r
37de70b7
YZ
335 def SetEnv(FdfParser, WorkSpace, ArchList, GlobalData):\r
336 GenFdsGlobalVariable.ModuleFile = WorkSpace.ModuleFile\r
337 GenFdsGlobalVariable.FdfParser = FdfParser\r
338 GenFdsGlobalVariable.WorkSpace = WorkSpace.Db\r
339 GenFdsGlobalVariable.ArchList = ArchList\r
340 GenFdsGlobalVariable.ToolChainTag = GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]\r
341 GenFdsGlobalVariable.TargetName = GlobalData.gGlobalDefines["TARGET"]\r
342 GenFdsGlobalVariable.ActivePlatform = GlobalData.gActivePlatform\r
343 GenFdsGlobalVariable.EdkSourceDir = GlobalData.gGlobalDefines["EDK_SOURCE"]\r
344 GenFdsGlobalVariable.ConfDir = GlobalData.gConfDirectory\r
345 GenFdsGlobalVariable.EnableGenfdsMultiThread = GlobalData.gEnableGenfdsMultiThread\r
346 for Arch in ArchList:\r
347 GenFdsGlobalVariable.OutputDirDict[Arch] = os.path.normpath(\r
348 os.path.join(GlobalData.gWorkspace,\r
ccaa7754 349 WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
37de70b7
YZ
350 GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory,\r
351 GlobalData.gGlobalDefines['TARGET'] +'_' + GlobalData.gGlobalDefines['TOOLCHAIN']))\r
352 GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = os.path.normpath(\r
353 WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
354 GlobalData.gGlobalDefines['TARGET'], GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory)\r
355 GenFdsGlobalVariable.PlatformName = WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
356 GlobalData.gGlobalDefines['TARGET'],\r
357 GlobalData.gGlobalDefines['TOOLCHAIN']].PlatformName\r
91fa33ee 358 GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], DataType.TAB_FV_DIRECTORY)\r
37de70b7
YZ
359 if not os.path.exists(GenFdsGlobalVariable.FvDir):\r
360 os.makedirs(GenFdsGlobalVariable.FvDir)\r
361 GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
362 if not os.path.exists(GenFdsGlobalVariable.FfsDir):\r
363 os.makedirs(GenFdsGlobalVariable.FfsDir)\r
364\r
37de70b7
YZ
365 #\r
366 # Create FV Address inf file\r
367 #\r
368 GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')\r
369 FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')\r
370 #\r
371 # Add [Options]\r
372 #\r
9e47e6f9 373 FvAddressFile.writelines("[options]" + DataType.TAB_LINE_BREAK)\r
37de70b7
YZ
374 BsAddress = '0'\r
375 for Arch in ArchList:\r
376 BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
377 GlobalData.gGlobalDefines['TARGET'],\r
378 GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].BsBaseAddress\r
379 if BsAddress:\r
380 break\r
381\r
382 FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
383 BsAddress + \\r
9e47e6f9 384 DataType.TAB_LINE_BREAK)\r
37de70b7
YZ
385\r
386 RtAddress = '0'\r
9e47e6f9
CJ
387 for Arch in reversed(ArchList):\r
388 temp = GenFdsGlobalVariable.WorkSpace.BuildObject[\r
37de70b7 389 GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
9e47e6f9
CJ
390 GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress\r
391 if temp:\r
392 RtAddress = temp\r
393 break\r
37de70b7
YZ
394\r
395 FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
396 RtAddress + \\r
9e47e6f9 397 DataType.TAB_LINE_BREAK)\r
37de70b7
YZ
398\r
399 FvAddressFile.close()\r
400\r
f51461c8
LG
401 ## ReplaceWorkspaceMacro()\r
402 #\r
403 # @param String String that may contain macro\r
404 #\r
9e47e6f9 405 @staticmethod\r
f51461c8 406 def ReplaceWorkspaceMacro(String):\r
05cc51ad 407 String = mws.handleWsMacro(String)\r
f51461c8
LG
408 Str = String.replace('$(WORKSPACE)', GenFdsGlobalVariable.WorkSpaceDir)\r
409 if os.path.exists(Str):\r
410 if not os.path.isabs(Str):\r
411 Str = os.path.abspath(Str)\r
412 else:\r
05cc51ad 413 Str = mws.join(GenFdsGlobalVariable.WorkSpaceDir, String)\r
f51461c8
LG
414 return os.path.normpath(Str)\r
415\r
416 ## Check if the input files are newer than output files\r
417 #\r
418 # @param Output Path of output file\r
419 # @param Input Path list of input files\r
420 #\r
421 # @retval True if Output doesn't exist, or any Input is newer\r
422 # @retval False if all Input is older than Output\r
423 #\r
424 @staticmethod\r
425 def NeedsUpdate(Output, Input):\r
426 if not os.path.exists(Output):\r
427 return True\r
428 # always update "Output" if no "Input" given\r
9e47e6f9 429 if not Input:\r
f51461c8
LG
430 return True\r
431\r
432 # if fdf file is changed after the 'Output" is generated, update the 'Output'\r
433 OutputTime = os.path.getmtime(Output)\r
434 if GenFdsGlobalVariable.FdfFileTimeStamp > OutputTime:\r
435 return True\r
436\r
437 for F in Input:\r
438 # always update "Output" if any "Input" doesn't exist\r
439 if not os.path.exists(F):\r
440 return True\r
441 # always update "Output" if any "Input" is newer than "Output"\r
442 if os.path.getmtime(F) > OutputTime:\r
443 return True\r
444 return False\r
445\r
446 @staticmethod\r
447 def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,\r
caf74495 448 GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=[], BuildNumber=None, DummyFile=None, IsMakefile=False):\r
f51461c8 449 Cmd = ["GenSec"]\r
c93356ad 450 if Type:\r
caf74495 451 Cmd += ("-s", Type)\r
c93356ad 452 if CompressionType:\r
caf74495 453 Cmd += ("-c", CompressionType)\r
9e47e6f9 454 if Guid:\r
caf74495 455 Cmd += ("-g", Guid)\r
9e47e6f9 456 if DummyFile:\r
caf74495 457 Cmd += ("--dummy", DummyFile)\r
c93356ad 458 if GuidHdrLen:\r
caf74495
JC
459 Cmd += ("-l", GuidHdrLen)\r
460 #Add each guided attribute\r
461 for Attr in GuidAttr:\r
462 Cmd += ("-r", Attr)\r
463 #Section Align is only for dummy section without section type\r
464 for SecAlign in InputAlign:\r
465 Cmd += ("--sectionalign", SecAlign)\r
f51461c8
LG
466\r
467 CommandFile = Output + '.txt'\r
c93356ad 468 if Ui:\r
37de70b7 469 if IsMakefile:\r
a146c532 470 if Ui == "$(MODULE_NAME)":\r
caf74495 471 Cmd += ('-n', Ui)\r
a146c532 472 else:\r
caf74495
JC
473 Cmd += ("-n", '"' + Ui + '"')\r
474 Cmd += ("-o", Output)\r
37de70b7
YZ
475 if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
476 GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
477 else:\r
9e47e6f9 478 SectionData = array('B', [0, 0, 0, 0])\r
37de70b7
YZ
479 SectionData.fromstring(Ui.encode("utf_16_le"))\r
480 SectionData.append(0)\r
481 SectionData.append(0)\r
482 Len = len(SectionData)\r
483 GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
484 SaveFileOnChange(Output, SectionData.tostring())\r
485\r
c93356ad 486 elif Ver:\r
caf74495 487 Cmd += ("-n", Ver)\r
f51461c8 488 if BuildNumber:\r
caf74495
JC
489 Cmd += ("-j", BuildNumber)\r
490 Cmd += ("-o", Output)\r
f51461c8
LG
491\r
492 SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
37de70b7
YZ
493 if IsMakefile:\r
494 if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
495 GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
496 else:\r
497 if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
498 return\r
499 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
f51461c8 500 else:\r
caf74495 501 Cmd += ("-o", Output)\r
f51461c8
LG
502 Cmd += Input\r
503\r
504 SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
37de70b7
YZ
505 if IsMakefile:\r
506 if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
507 GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
6735645d 508 elif GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
f51461c8
LG
509 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
510 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
37de70b7
YZ
511 if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and\r
512 GenFdsGlobalVariable.LargeFileInFvFlags):\r
513 GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True\r
f51461c8
LG
514\r
515 @staticmethod\r
516 def GetAlignment (AlignString):\r
7bf1eb6e 517 if not AlignString:\r
f51461c8 518 return 0\r
7bf1eb6e 519 if AlignString.endswith('K'):\r
52302d4d 520 return int (AlignString.rstrip('K')) * 1024\r
7bf1eb6e 521 if AlignString.endswith('M'):\r
e921f58d 522 return int (AlignString.rstrip('M')) * 1024 * 1024\r
7bf1eb6e
CJ
523 if AlignString.endswith('G'):\r
524 return int (AlignString.rstrip('G')) * 1024 * 1024 * 1024\r
525 return int (AlignString)\r
f51461c8
LG
526\r
527 @staticmethod\r
528 def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
37de70b7 529 SectionAlign=None, MakefilePath=None):\r
f51461c8 530 Cmd = ["GenFfs", "-t", Type, "-g", Guid]\r
e921f58d 531 mFfsValidAlign = ["0", "8", "16", "128", "512", "1K", "4K", "32K", "64K", "128K", "256K", "512K", "1M", "2M", "4M", "8M", "16M"]\r
f51461c8 532 if Fixed == True:\r
caf74495 533 Cmd.append("-x")\r
f51461c8 534 if CheckSum:\r
caf74495 535 Cmd.append("-s")\r
c93356ad 536 if Align:\r
d2192f12
YZ
537 if Align not in mFfsValidAlign:\r
538 Align = GenFdsGlobalVariable.GetAlignment (Align)\r
539 for index in range(0, len(mFfsValidAlign) - 1):\r
540 if ((Align > GenFdsGlobalVariable.GetAlignment(mFfsValidAlign[index])) and (Align <= GenFdsGlobalVariable.GetAlignment(mFfsValidAlign[index + 1]))):\r
541 break\r
542 Align = mFfsValidAlign[index + 1]\r
caf74495 543 Cmd += ("-a", Align)\r
f51461c8 544\r
caf74495 545 Cmd += ("-o", Output)\r
f51461c8
LG
546 for I in range(0, len(Input)):\r
547 Cmd += ("-i", Input[I])\r
c93356ad 548 if SectionAlign and SectionAlign[I]:\r
f51461c8
LG
549 Cmd += ("-n", SectionAlign[I])\r
550\r
551 CommandFile = Output + '.txt'\r
552 SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
f51461c8 553\r
37de70b7
YZ
554 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
555 if MakefilePath:\r
ccaa7754 556 if (tuple(Cmd), tuple(GenFdsGlobalVariable.SecCmdList), tuple(GenFdsGlobalVariable.CopyList)) not in GenFdsGlobalVariable.FfsCmdDict:\r
37de70b7
YZ
557 GenFdsGlobalVariable.FfsCmdDict[tuple(Cmd), tuple(GenFdsGlobalVariable.SecCmdList), tuple(GenFdsGlobalVariable.CopyList)] = MakefilePath\r
558 GenFdsGlobalVariable.SecCmdList = []\r
559 GenFdsGlobalVariable.CopyList = []\r
560 else:\r
6735645d 561 if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
37de70b7
YZ
562 return\r
563 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")\r
f51461c8
LG
564\r
565 @staticmethod\r
566 def GenerateFirmwareVolume(Output, Input, BaseAddress=None, ForceRebase=None, Capsule=False, Dump=False,\r
567 AddressFile=None, MapFile=None, FfsList=[], FileSystemGuid=None):\r
568 if not GenFdsGlobalVariable.NeedsUpdate(Output, Input+FfsList):\r
569 return\r
570 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
571\r
572 Cmd = ["GenFv"]\r
c93356ad 573 if BaseAddress:\r
caf74495 574 Cmd += ("-r", BaseAddress)\r
47fea6af 575\r
599bb2be 576 if ForceRebase == False:\r
caf74495 577 Cmd += ("-F", "FALSE")\r
599bb2be 578 elif ForceRebase == True:\r
caf74495 579 Cmd += ("-F", "TRUE")\r
47fea6af 580\r
f51461c8 581 if Capsule:\r
caf74495 582 Cmd.append("-c")\r
f51461c8 583 if Dump:\r
caf74495 584 Cmd.append("-p")\r
c93356ad 585 if AddressFile:\r
caf74495 586 Cmd += ("-a", AddressFile)\r
c93356ad 587 if MapFile:\r
caf74495 588 Cmd += ("-m", MapFile)\r
f51461c8 589 if FileSystemGuid:\r
caf74495
JC
590 Cmd += ("-g", FileSystemGuid)\r
591 Cmd += ("-o", Output)\r
f51461c8 592 for I in Input:\r
caf74495 593 Cmd += ("-i", I)\r
f51461c8
LG
594\r
595 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FV")\r
596\r
f51461c8
LG
597 @staticmethod\r
598 def GenerateFirmwareImage(Output, Input, Type="efi", SubType=None, Zero=False,\r
599 Strip=False, Replace=False, TimeStamp=None, Join=False,\r
37de70b7
YZ
600 Align=None, Padding=None, Convert=False, IsMakefile=False):\r
601 if not GenFdsGlobalVariable.NeedsUpdate(Output, Input) and not IsMakefile:\r
f51461c8
LG
602 return\r
603 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
604\r
605 Cmd = ["GenFw"]\r
606 if Type.lower() == "te":\r
caf74495 607 Cmd.append("-t")\r
c93356ad 608 if SubType:\r
caf74495 609 Cmd += ("-e", SubType)\r
c93356ad 610 if TimeStamp:\r
caf74495 611 Cmd += ("-s", TimeStamp)\r
c93356ad 612 if Align:\r
caf74495 613 Cmd += ("-a", Align)\r
c93356ad 614 if Padding:\r
caf74495 615 Cmd += ("-p", Padding)\r
f51461c8 616 if Zero:\r
caf74495 617 Cmd.append("-z")\r
f51461c8 618 if Strip:\r
caf74495 619 Cmd.append("-l")\r
f51461c8 620 if Replace:\r
caf74495 621 Cmd.append("-r")\r
f51461c8 622 if Join:\r
caf74495 623 Cmd.append("-j")\r
f51461c8 624 if Convert:\r
caf74495
JC
625 Cmd.append("-m")\r
626 Cmd += ("-o", Output)\r
f51461c8 627 Cmd += Input\r
37de70b7
YZ
628 if IsMakefile:\r
629 if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
630 GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
631 else:\r
632 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")\r
f51461c8
LG
633\r
634 @staticmethod\r
635 def GenerateOptionRom(Output, EfiInput, BinaryInput, Compress=False, ClassCode=None,\r
37de70b7 636 Revision=None, DeviceId=None, VendorId=None, IsMakefile=False):\r
f7496d71 637 InputList = []\r
f51461c8 638 Cmd = ["EfiRom"]\r
9e47e6f9 639 if EfiInput:\r
f7496d71 640\r
f51461c8 641 if Compress:\r
caf74495 642 Cmd.append("-ec")\r
f51461c8 643 else:\r
caf74495 644 Cmd.append("-e")\r
f7496d71 645\r
f51461c8 646 for EfiFile in EfiInput:\r
caf74495 647 Cmd.append(EfiFile)\r
f51461c8 648 InputList.append (EfiFile)\r
f7496d71 649\r
9e47e6f9 650 if BinaryInput:\r
caf74495 651 Cmd.append("-b")\r
f51461c8 652 for BinFile in BinaryInput:\r
caf74495 653 Cmd.append(BinFile)\r
f51461c8
LG
654 InputList.append (BinFile)\r
655\r
656 # Check List\r
37de70b7 657 if not GenFdsGlobalVariable.NeedsUpdate(Output, InputList) and not IsMakefile:\r
f51461c8
LG
658 return\r
659 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, InputList))\r
f7496d71 660\r
9e47e6f9 661 if ClassCode:\r
caf74495 662 Cmd += ("-l", ClassCode)\r
9e47e6f9 663 if Revision:\r
caf74495 664 Cmd += ("-r", Revision)\r
9e47e6f9 665 if DeviceId:\r
caf74495 666 Cmd += ("-i", DeviceId)\r
9e47e6f9 667 if VendorId:\r
caf74495 668 Cmd += ("-f", VendorId)\r
f51461c8 669\r
caf74495 670 Cmd += ("-o", Output)\r
37de70b7
YZ
671 if IsMakefile:\r
672 if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
673 GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
674 else:\r
675 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
f51461c8
LG
676\r
677 @staticmethod\r
37de70b7
YZ
678 def GuidTool(Output, Input, ToolPath, Options='', returnValue=[], IsMakefile=False):\r
679 if not GenFdsGlobalVariable.NeedsUpdate(Output, Input) and not IsMakefile:\r
f51461c8
LG
680 return\r
681 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
682\r
683 Cmd = [ToolPath, ]\r
684 Cmd += Options.split(' ')\r
caf74495 685 Cmd += ("-o", Output)\r
f51461c8 686 Cmd += Input\r
37de70b7
YZ
687 if IsMakefile:\r
688 if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
689 GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
690 else:\r
691 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)\r
f51461c8 692\r
9e47e6f9 693 @staticmethod\r
f51461c8
LG
694 def CallExternalTool (cmd, errorMess, returnValue=[]):\r
695\r
696 if type(cmd) not in (tuple, list):\r
697 GenFdsGlobalVariable.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool")\r
698\r
699 if GenFdsGlobalVariable.DebugLevel != -1:\r
700 cmd += ('--debug', str(GenFdsGlobalVariable.DebugLevel))\r
701 GenFdsGlobalVariable.InfLogger (cmd)\r
702\r
703 if GenFdsGlobalVariable.VerboseMode:\r
704 cmd += ('-v',)\r
705 GenFdsGlobalVariable.InfLogger (cmd)\r
706 else:\r
9e47e6f9
CJ
707 stdout.write ('#')\r
708 stdout.flush()\r
f51461c8
LG
709 GenFdsGlobalVariable.SharpCounter = GenFdsGlobalVariable.SharpCounter + 1\r
710 if GenFdsGlobalVariable.SharpCounter % GenFdsGlobalVariable.SharpNumberPerLine == 0:\r
9e47e6f9 711 stdout.write('\n')\r
f51461c8
LG
712\r
713 try:\r
9e47e6f9 714 PopenObject = Popen(' '.join(cmd), stdout=PIPE, stderr=PIPE, shell=True)\r
5b0671c1 715 except Exception as X:\r
f51461c8
LG
716 EdkLogger.error("GenFds", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0]))\r
717 (out, error) = PopenObject.communicate()\r
718\r
9e47e6f9 719 while PopenObject.returncode is None:\r
f51461c8
LG
720 PopenObject.wait()\r
721 if returnValue != [] and returnValue[0] != 0:\r
722 #get command return value\r
723 returnValue[0] = PopenObject.returncode\r
724 return\r
725 if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:\r
47fea6af 726 GenFdsGlobalVariable.InfLogger ("Return Value = %d" % PopenObject.returncode)\r
1ccc4d89
LG
727 GenFdsGlobalVariable.InfLogger (out)\r
728 GenFdsGlobalVariable.InfLogger (error)\r
f51461c8 729 if PopenObject.returncode != 0:\r
72443dd2 730 print("###", cmd)\r
f51461c8
LG
731 EdkLogger.error("GenFds", COMMAND_FAILURE, errorMess)\r
732\r
9e47e6f9 733 @staticmethod\r
f51461c8
LG
734 def VerboseLogger (msg):\r
735 EdkLogger.verbose(msg)\r
736\r
9e47e6f9 737 @staticmethod\r
f51461c8
LG
738 def InfLogger (msg):\r
739 EdkLogger.info(msg)\r
740\r
9e47e6f9 741 @staticmethod\r
47fea6af 742 def ErrorLogger (msg, File=None, Line=None, ExtraData=None):\r
f51461c8
LG
743 EdkLogger.error('GenFds', GENFDS_ERROR, msg, File, Line, ExtraData)\r
744\r
9e47e6f9 745 @staticmethod\r
f51461c8
LG
746 def DebugLogger (Level, msg):\r
747 EdkLogger.debug(Level, msg)\r
748\r
9e47e6f9 749 ## MacroExtend()\r
f51461c8
LG
750 #\r
751 # @param Str String that may contain macro\r
752 # @param MacroDict Dictionary that contains macro value pair\r
753 #\r
9e47e6f9 754 @staticmethod\r
55c84777 755 def MacroExtend (Str, MacroDict={}, Arch=DataType.TAB_COMMON):\r
9e47e6f9 756 if Str is None:\r
f51461c8
LG
757 return None\r
758\r
9e47e6f9
CJ
759 Dict = {'$(WORKSPACE)': GenFdsGlobalVariable.WorkSpaceDir,\r
760 '$(EDK_SOURCE)': GenFdsGlobalVariable.EdkSourceDir,\r
f51461c8 761# '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,\r
9e47e6f9
CJ
762 '$(TARGET)': GenFdsGlobalVariable.TargetName,\r
763 '$(TOOL_CHAIN_TAG)': GenFdsGlobalVariable.ToolChainTag,\r
764 '$(SPACE)': ' '\r
f51461c8 765 }\r
9e47e6f9 766\r
55c84777 767 if Arch != DataType.TAB_COMMON and Arch in GenFdsGlobalVariable.ArchList:\r
f51461c8 768 OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[Arch]\r
9e47e6f9
CJ
769 else:\r
770 OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
f51461c8
LG
771\r
772 Dict['$(OUTPUT_DIRECTORY)'] = OutputDir\r
773\r
9e47e6f9 774 if MacroDict:\r
f51461c8
LG
775 Dict.update(MacroDict)\r
776\r
9eb87141 777 for key in Dict:\r
9e47e6f9 778 if Str.find(key) >= 0:\r
f51461c8
LG
779 Str = Str.replace (key, Dict[key])\r
780\r
781 if Str.find('$(ARCH)') >= 0:\r
782 if len(GenFdsGlobalVariable.ArchList) == 1:\r
783 Str = Str.replace('$(ARCH)', GenFdsGlobalVariable.ArchList[0])\r
784 else:\r
785 EdkLogger.error("GenFds", GENFDS_ERROR, "No way to determine $(ARCH) for %s" % Str)\r
786\r
787 return Str\r
788\r
789 ## GetPcdValue()\r
790 #\r
791 # @param PcdPattern pattern that labels a PCD.\r
792 #\r
9e47e6f9 793 @staticmethod\r
f51461c8 794 def GetPcdValue (PcdPattern):\r
9e47e6f9 795 if PcdPattern is None:\r
f51461c8
LG
796 return None\r
797 PcdPair = PcdPattern.lstrip('PCD(').rstrip(')').strip().split('.')\r
798 TokenSpace = PcdPair[0]\r
799 TokenCName = PcdPair[1]\r
800\r
f51461c8
LG
801 for Arch in GenFdsGlobalVariable.ArchList:\r
802 Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
803 PcdDict = Platform.Pcds\r
804 for Key in PcdDict:\r
805 PcdObj = PcdDict[Key]\r
806 if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):\r
be409b67 807 if PcdObj.Type != DataType.TAB_PCDS_FIXED_AT_BUILD:\r
f51461c8 808 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)\r
656d2539 809 if PcdObj.DatumType != DataType.TAB_VOID:\r
f51461c8 810 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)\r
f7496d71 811\r
9e47e6f9 812 return PcdObj.DefaultValue\r
47fea6af
YZ
813\r
814 for Package in GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,\r
815 Arch,\r
816 GenFdsGlobalVariable.TargetName,\r
f51461c8
LG
817 GenFdsGlobalVariable.ToolChainTag):\r
818 PcdDict = Package.Pcds\r
819 for Key in PcdDict:\r
820 PcdObj = PcdDict[Key]\r
821 if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):\r
be409b67 822 if PcdObj.Type != DataType.TAB_PCDS_FIXED_AT_BUILD:\r
f51461c8 823 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)\r
656d2539 824 if PcdObj.DatumType != DataType.TAB_VOID:\r
f51461c8 825 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)\r
f7496d71 826\r
9e47e6f9 827 return PcdObj.DefaultValue\r
f51461c8 828\r
9e47e6f9 829 return ''\r
89a69d4b
GL
830\r
831## FindExtendTool()\r
832#\r
833# Find location of tools to process data\r
834#\r
835# @param KeyStringList Filter for inputs of section generation\r
836# @param CurrentArchList Arch list\r
837# @param NameGuid The Guid name\r
838#\r
839def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
840 ToolDb = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
841 # if user not specify filter, try to deduce it from global data.\r
842 if KeyStringList is None or KeyStringList == []:\r
843 Target = GenFdsGlobalVariable.TargetName\r
844 ToolChain = GenFdsGlobalVariable.ToolChainTag\r
845 if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:\r
846 EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)\r
847 KeyStringList = [Target + '_' + ToolChain + '_' + CurrentArchList[0]]\r
848 for Arch in CurrentArchList:\r
849 if Target + '_' + ToolChain + '_' + Arch not in KeyStringList:\r
850 KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)\r
851\r
852 if GenFdsGlobalVariable.GuidToolDefinition:\r
853 if NameGuid in GenFdsGlobalVariable.GuidToolDefinition:\r
854 return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]\r
855\r
856 ToolDefinition = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
857 ToolPathTmp = None\r
858 ToolOption = None\r
859 ToolPathKey = None\r
860 ToolOptionKey = None\r
861 KeyList = None\r
862 for ToolDef in ToolDefinition.items():\r
9e47e6f9 863 if NameGuid.lower() == ToolDef[1].lower():\r
89a69d4b
GL
864 KeyList = ToolDef[0].split('_')\r
865 Key = KeyList[0] + \\r
866 '_' + \\r
867 KeyList[1] + \\r
868 '_' + \\r
869 KeyList[2]\r
870 if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID:\r
871 ToolPathKey = Key + '_' + KeyList[3] + '_PATH'\r
872 ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
873 ToolPath = ToolDefinition.get(ToolPathKey)\r
874 ToolOption = ToolDefinition.get(ToolOptionKey)\r
875 if ToolPathTmp is None:\r
876 ToolPathTmp = ToolPath\r
877 else:\r
878 if ToolPathTmp != ToolPath:\r
879 EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
880\r
881 BuildOption = {}\r
882 for Arch in CurrentArchList:\r
883 Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
884 # key is (ToolChainFamily, ToolChain, CodeBase)\r
885 for item in Platform.BuildOptions:\r
886 if '_PATH' in item[1] or '_FLAGS' in item[1] or '_GUID' in item[1]:\r
887 if not item[0] or (item[0] and GenFdsGlobalVariable.ToolChainFamily== item[0]):\r
888 if item[1] not in BuildOption:\r
889 BuildOption[item[1]] = Platform.BuildOptions[item]\r
890 if BuildOption:\r
891 ToolList = [DataType.TAB_TOD_DEFINES_TARGET, DataType.TAB_TOD_DEFINES_TOOL_CHAIN_TAG, DataType.TAB_TOD_DEFINES_TARGET_ARCH]\r
892 for Index in range(2, -1, -1):\r
893 for Key in list(BuildOption.keys()):\r
894 List = Key.split('_')\r
bc39c5cb 895 if List[Index] == DataType.TAB_STAR:\r
89a69d4b
GL
896 for String in ToolDb[ToolList[Index]]:\r
897 if String in [Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]:\r
898 List[Index] = String\r
899 NewKey = '%s_%s_%s_%s_%s' % tuple(List)\r
900 if NewKey not in BuildOption:\r
901 BuildOption[NewKey] = BuildOption[Key]\r
902 continue\r
903 del BuildOption[Key]\r
904 elif List[Index] not in ToolDb[ToolList[Index]]:\r
905 del BuildOption[Key]\r
906 if BuildOption:\r
907 if not KeyList:\r
908 for Op in BuildOption:\r
909 if NameGuid == BuildOption[Op]:\r
910 KeyList = Op.split('_')\r
911 Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]\r
912 if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID:\r
913 ToolPathKey = Key + '_' + KeyList[3] + '_PATH'\r
914 ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
915 if ToolPathKey in BuildOption:\r
916 ToolPathTmp = BuildOption[ToolPathKey]\r
917 if ToolOptionKey in BuildOption:\r
918 ToolOption = BuildOption[ToolOptionKey]\r
919\r
920 GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
921 return ToolPathTmp, ToolOption\r