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