]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
BaseTools: Create ".cache" folder when initialize Build object
[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 5#\r
2e351cbe 6# SPDX-License-Identifier: BSD-2-Clause-Patent\r
f51461c8
LG
7#\r
8\r
9##\r
10# Import Modules\r
11#\r
1ccc4d89 12from __future__ import print_function\r
9e47e6f9
CJ
13from __future__ import absolute_import\r
14\r
1be2ed90 15import Common.LongFilePathOs as os\r
9e47e6f9
CJ
16from sys import stdout\r
17from subprocess import PIPE,Popen\r
18from struct import Struct\r
19from array import array\r
f51461c8 20\r
9e47e6f9 21from Common.BuildToolError import COMMAND_FAILURE,GENFDS_ERROR\r
f51461c8
LG
22from Common import EdkLogger\r
23from Common.Misc import SaveFileOnChange\r
24\r
25from Common.TargetTxtClassObject import TargetTxtClassObject\r
89a69d4b 26from Common.ToolDefClassObject import ToolDefClassObject, ToolDefDict\r
f51461c8
LG
27from AutoGen.BuildEngine import BuildRule\r
28import Common.DataType as DataType\r
29from Common.Misc import PathClass\r
1be2ed90 30from Common.LongFilePathSupport import OpenLongFilePath as open\r
05cc51ad 31from Common.MultipleWorkspace import MultipleWorkspace as mws\r
b1e27d17 32import Common.GlobalData as GlobalData\r
f51461c8
LG
33\r
34## Global variables\r
35#\r
36#\r
37class GenFdsGlobalVariable:\r
38 FvDir = ''\r
39 OutputDirDict = {}\r
40 BinDir = ''\r
41 # will be FvDir + os.sep + 'Ffs'\r
42 FfsDir = ''\r
43 FdfParser = None\r
44 LibDir = ''\r
45 WorkSpace = None\r
46 WorkSpaceDir = ''\r
97fa0ee9 47 ConfDir = ''\r
f51461c8
LG
48 OutputDirFromDscDict = {}\r
49 TargetName = ''\r
50 ToolChainTag = ''\r
51 RuleDict = {}\r
52 ArchList = None\r
f51461c8
LG
53 ActivePlatform = None\r
54 FvAddressFileName = ''\r
55 VerboseMode = False\r
56 DebugLevel = -1\r
57 SharpCounter = 0\r
58 SharpNumberPerLine = 40\r
59 FdfFile = ''\r
60 FdfFileTimeStamp = 0\r
61 FixedLoadAddress = False\r
62 PlatformName = ''\r
f7496d71 63\r
94c04559
CJ
64 BuildRuleFamily = DataType.TAB_COMPILER_MSFT\r
65 ToolChainFamily = DataType.TAB_COMPILER_MSFT\r
f51461c8 66 __BuildRuleDatabase = None\r
213ae077 67 GuidToolDefinition = {}\r
37de70b7
YZ
68 FfsCmdDict = {}\r
69 SecCmdList = []\r
70 CopyList = []\r
71 ModuleFile = ''\r
72 EnableGenfdsMultiThread = False\r
f7496d71 73\r
f51461c8
LG
74 #\r
75 # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.\r
76 # At the beginning of each generation of FV, false flag is appended to the list,\r
77 # after the call to GenerateSection returns, check the size of the output file,\r
78 # if it is greater than 0xFFFFFF, the tail flag in list is set to true,\r
79 # and EFI_FIRMWARE_FILE_SYSTEM3_GUID is passed to C GenFv.\r
80 # At the end of generation of FV, pop the flag.\r
81 # List is used as a stack to handle nested FV generation.\r
82 #\r
83 LargeFileInFvFlags = []\r
84 EFI_FIRMWARE_FILE_SYSTEM3_GUID = '5473C07A-3DCB-4dca-BD6F-1E9689E7349A'\r
85 LARGE_FILE_SIZE = 0x1000000\r
86\r
9e47e6f9 87 SectionHeader = Struct("3B 1B")\r
f7496d71 88\r
7de00838
GL
89 # FvName, FdName, CapName in FDF, Image file name\r
90 ImageBinDict = {}\r
91\r
f51461c8
LG
92 ## LoadBuildRule\r
93 #\r
94 @staticmethod\r
9e47e6f9 95 def _LoadBuildRule():\r
f51461c8
LG
96 if GenFdsGlobalVariable.__BuildRuleDatabase:\r
97 return GenFdsGlobalVariable.__BuildRuleDatabase\r
97fa0ee9 98 BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.ConfDir, "target.txt"))\r
f51461c8
LG
99 TargetTxt = TargetTxtClassObject()\r
100 if os.path.isfile(BuildConfigurationFile) == True:\r
101 TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)\r
102 if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:\r
103 BuildRuleFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
c93356ad 104 if not BuildRuleFile:\r
f51461c8
LG
105 BuildRuleFile = 'Conf/build_rule.txt'\r
106 GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)\r
107 ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
108 if ToolDefinitionFile == '':\r
109 ToolDefinitionFile = "Conf/tools_def.txt"\r
110 if os.path.isfile(ToolDefinitionFile):\r
111 ToolDef = ToolDefClassObject()\r
112 ToolDef.LoadToolDefFile(ToolDefinitionFile)\r
113 ToolDefinition = ToolDef.ToolsDefTxtDatabase\r
114 if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \\r
115 and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
116 and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
117 GenFdsGlobalVariable.BuildRuleFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]\r
f7496d71 118\r
f51461c8
LG
119 if DataType.TAB_TOD_DEFINES_FAMILY in ToolDefinition \\r
120 and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY] \\r
121 and ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
122 GenFdsGlobalVariable.ToolChainFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]\r
123 return GenFdsGlobalVariable.__BuildRuleDatabase\r
124\r
125 ## GetBuildRules\r
126 # @param Inf: object of InfBuildData\r
127 # @param Arch: current arch\r
128 #\r
129 @staticmethod\r
130 def GetBuildRules(Inf, Arch):\r
131 if not Arch:\r
55c84777 132 Arch = DataType.TAB_COMMON\r
f51461c8
LG
133\r
134 if not Arch in GenFdsGlobalVariable.OutputDirDict:\r
135 return {}\r
136\r
9e47e6f9 137 BuildRuleDatabase = GenFdsGlobalVariable._LoadBuildRule()\r
f51461c8
LG
138 if not BuildRuleDatabase:\r
139 return {}\r
140\r
141 PathClassObj = PathClass(Inf.MetaFile.File,\r
142 GenFdsGlobalVariable.WorkSpaceDir)\r
f51461c8
LG
143 BuildDir = os.path.join(\r
144 GenFdsGlobalVariable.OutputDirDict[Arch],\r
145 Arch,\r
146 PathClassObj.SubDir,\r
147 PathClassObj.BaseName\r
148 )\r
9e47e6f9
CJ
149 BinDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)\r
150 Macro = {\r
151 "WORKSPACE":GenFdsGlobalVariable.WorkSpaceDir,\r
152 "MODULE_NAME":Inf.BaseName,\r
153 "MODULE_GUID":Inf.Guid,\r
154 "MODULE_VERSION":Inf.Version,\r
155 "MODULE_TYPE":Inf.ModuleType,\r
156 "MODULE_FILE":str(PathClassObj),\r
157 "MODULE_FILE_BASE_NAME":PathClassObj.BaseName,\r
158 "MODULE_RELATIVE_DIR":PathClassObj.SubDir,\r
159 "MODULE_DIR":PathClassObj.SubDir,\r
160 "BASE_NAME":Inf.BaseName,\r
161 "ARCH":Arch,\r
162 "TOOLCHAIN":GenFdsGlobalVariable.ToolChainTag,\r
163 "TOOLCHAIN_TAG":GenFdsGlobalVariable.ToolChainTag,\r
164 "TOOL_CHAIN_TAG":GenFdsGlobalVariable.ToolChainTag,\r
165 "TARGET":GenFdsGlobalVariable.TargetName,\r
166 "BUILD_DIR":GenFdsGlobalVariable.OutputDirDict[Arch],\r
167 "BIN_DIR":BinDir,\r
168 "LIB_DIR":BinDir,\r
169 "MODULE_BUILD_DIR":BuildDir,\r
170 "OUTPUT_DIR":os.path.join(BuildDir, "OUTPUT"),\r
171 "DEBUG_DIR":os.path.join(BuildDir, "DEBUG")\r
172 }\r
173 \r
f51461c8
LG
174 BuildRules = {}\r
175 for Type in BuildRuleDatabase.FileTypeList:\r
176 #first try getting build rule by BuildRuleFamily\r
177 RuleObject = BuildRuleDatabase[Type, Inf.BuildType, Arch, GenFdsGlobalVariable.BuildRuleFamily]\r
178 if not RuleObject:\r
179 # build type is always module type, but ...\r
180 if Inf.ModuleType != Inf.BuildType:\r
181 RuleObject = BuildRuleDatabase[Type, Inf.ModuleType, Arch, GenFdsGlobalVariable.BuildRuleFamily]\r
182 #second try getting build rule by ToolChainFamily\r
183 if not RuleObject:\r
184 RuleObject = BuildRuleDatabase[Type, Inf.BuildType, Arch, GenFdsGlobalVariable.ToolChainFamily]\r
185 if not RuleObject:\r
186 # build type is always module type, but ...\r
187 if Inf.ModuleType != Inf.BuildType:\r
188 RuleObject = BuildRuleDatabase[Type, Inf.ModuleType, Arch, GenFdsGlobalVariable.ToolChainFamily]\r
189 if not RuleObject:\r
190 continue\r
191 RuleObject = RuleObject.Instantiate(Macro)\r
192 BuildRules[Type] = RuleObject\r
193 for Ext in RuleObject.SourceFileExtList:\r
194 BuildRules[Ext] = RuleObject\r
195 return BuildRules\r
196\r
197 ## GetModuleCodaTargetList\r
198 #\r
199 # @param Inf: object of InfBuildData\r
200 # @param Arch: current arch\r
201 #\r
202 @staticmethod\r
203 def GetModuleCodaTargetList(Inf, Arch):\r
204 BuildRules = GenFdsGlobalVariable.GetBuildRules(Inf, Arch)\r
205 if not BuildRules:\r
206 return []\r
207\r
208 TargetList = set()\r
209 FileList = []\r
97fa0ee9
YL
210\r
211 if not Inf.IsBinaryModule:\r
212 for File in Inf.Sources:\r
bc39c5cb
JC
213 if File.TagName in {"", DataType.TAB_STAR, GenFdsGlobalVariable.ToolChainTag} and \\r
214 File.ToolChainFamily in {"", DataType.TAB_STAR, GenFdsGlobalVariable.ToolChainFamily}:\r
97fa0ee9
YL
215 FileList.append((File, DataType.TAB_UNKNOWN_FILE))\r
216\r
f51461c8 217 for File in Inf.Binaries:\r
bc39c5cb 218 if File.Target in {DataType.TAB_COMMON, DataType.TAB_STAR, GenFdsGlobalVariable.TargetName}:\r
f51461c8
LG
219 FileList.append((File, File.Type))\r
220\r
221 for File, FileType in FileList:\r
222 LastTarget = None\r
223 RuleChain = []\r
224 SourceList = [File]\r
225 Index = 0\r
226 while Index < len(SourceList):\r
227 Source = SourceList[Index]\r
228 Index = Index + 1\r
f7496d71 229\r
9e47e6f9 230 if File.IsBinary and File == Source and Inf.Binaries and File in Inf.Binaries:\r
f51461c8
LG
231 # Skip all files that are not binary libraries\r
232 if not Inf.LibraryClass:\r
f7496d71 233 continue\r
f51461c8
LG
234 RuleObject = BuildRules[DataType.TAB_DEFAULT_BINARY_FILE]\r
235 elif FileType in BuildRules:\r
236 RuleObject = BuildRules[FileType]\r
237 elif Source.Ext in BuildRules:\r
238 RuleObject = BuildRules[Source.Ext]\r
239 else:\r
240 # stop at no more rules\r
241 if LastTarget:\r
242 TargetList.add(str(LastTarget))\r
243 break\r
f7496d71 244\r
f51461c8 245 FileType = RuleObject.SourceFileType\r
f7496d71 246\r
f51461c8
LG
247 # stop at STATIC_LIBRARY for library\r
248 if Inf.LibraryClass and FileType == DataType.TAB_STATIC_LIBRARY:\r
249 if LastTarget:\r
250 TargetList.add(str(LastTarget))\r
251 break\r
f7496d71 252\r
f51461c8
LG
253 Target = RuleObject.Apply(Source)\r
254 if not Target:\r
255 if LastTarget:\r
256 TargetList.add(str(LastTarget))\r
257 break\r
258 elif not Target.Outputs:\r
259 # Only do build for target with outputs\r
260 TargetList.add(str(Target))\r
f7496d71 261\r
f51461c8
LG
262 # to avoid cyclic rule\r
263 if FileType in RuleChain:\r
264 break\r
f7496d71 265\r
f51461c8
LG
266 RuleChain.append(FileType)\r
267 SourceList.extend(Target.Outputs)\r
268 LastTarget = Target\r
269 FileType = DataType.TAB_UNKNOWN_FILE\r
37de70b7
YZ
270 for Cmd in Target.Commands:\r
271 if "$(CP)" == Cmd.split()[0]:\r
272 CpTarget = Cmd.split()[2]\r
273 TargetList.add(CpTarget)\r
f51461c8
LG
274\r
275 return list(TargetList)\r
276\r
277 ## SetDir()\r
278 #\r
279 # @param OutputDir Output directory\r
280 # @param FdfParser FDF contents parser\r
281 # @param Workspace The directory of workspace\r
282 # @param ArchList The Arch list of platform\r
283 #\r
9e47e6f9 284 @staticmethod\r
f51461c8 285 def SetDir (OutputDir, FdfParser, WorkSpace, ArchList):\r
9e47e6f9 286 GenFdsGlobalVariable.VerboseLogger("GenFdsGlobalVariable.OutputDir:%s" % OutputDir)\r
f51461c8
LG
287 GenFdsGlobalVariable.FdfParser = FdfParser\r
288 GenFdsGlobalVariable.WorkSpace = WorkSpace\r
91fa33ee 289 GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], DataType.TAB_FV_DIRECTORY)\r
9e47e6f9 290 if not os.path.exists(GenFdsGlobalVariable.FvDir):\r
f51461c8
LG
291 os.makedirs(GenFdsGlobalVariable.FvDir)\r
292 GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
9e47e6f9 293 if not os.path.exists(GenFdsGlobalVariable.FfsDir):\r
f51461c8 294 os.makedirs(GenFdsGlobalVariable.FfsDir)\r
f51461c8 295\r
f51461c8
LG
296 #\r
297 # Create FV Address inf file\r
298 #\r
299 GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')\r
47fea6af 300 FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')\r
f51461c8
LG
301 #\r
302 # Add [Options]\r
303 #\r
9e47e6f9 304 FvAddressFile.writelines("[options]" + DataType.TAB_LINE_BREAK)\r
f51461c8
LG
305 BsAddress = '0'\r
306 for Arch in ArchList:\r
307 if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress:\r
308 BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress\r
309 break\r
310\r
311 FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
47fea6af 312 BsAddress + \\r
9e47e6f9 313 DataType.TAB_LINE_BREAK)\r
f51461c8
LG
314\r
315 RtAddress = '0'\r
9e47e6f9
CJ
316 for Arch in reversed(ArchList):\r
317 temp = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress\r
318 if temp:\r
319 RtAddress = temp\r
320 break\r
f51461c8
LG
321\r
322 FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
47fea6af 323 RtAddress + \\r
9e47e6f9 324 DataType.TAB_LINE_BREAK)\r
f51461c8
LG
325\r
326 FvAddressFile.close()\r
327\r
9e47e6f9 328 @staticmethod\r
37de70b7
YZ
329 def SetEnv(FdfParser, WorkSpace, ArchList, GlobalData):\r
330 GenFdsGlobalVariable.ModuleFile = WorkSpace.ModuleFile\r
331 GenFdsGlobalVariable.FdfParser = FdfParser\r
332 GenFdsGlobalVariable.WorkSpace = WorkSpace.Db\r
333 GenFdsGlobalVariable.ArchList = ArchList\r
334 GenFdsGlobalVariable.ToolChainTag = GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]\r
335 GenFdsGlobalVariable.TargetName = GlobalData.gGlobalDefines["TARGET"]\r
336 GenFdsGlobalVariable.ActivePlatform = GlobalData.gActivePlatform\r
37de70b7
YZ
337 GenFdsGlobalVariable.ConfDir = GlobalData.gConfDirectory\r
338 GenFdsGlobalVariable.EnableGenfdsMultiThread = GlobalData.gEnableGenfdsMultiThread\r
339 for Arch in ArchList:\r
340 GenFdsGlobalVariable.OutputDirDict[Arch] = os.path.normpath(\r
341 os.path.join(GlobalData.gWorkspace,\r
ccaa7754 342 WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
37de70b7
YZ
343 GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory,\r
344 GlobalData.gGlobalDefines['TARGET'] +'_' + GlobalData.gGlobalDefines['TOOLCHAIN']))\r
345 GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = os.path.normpath(\r
346 WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
347 GlobalData.gGlobalDefines['TARGET'], GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory)\r
348 GenFdsGlobalVariable.PlatformName = WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
349 GlobalData.gGlobalDefines['TARGET'],\r
350 GlobalData.gGlobalDefines['TOOLCHAIN']].PlatformName\r
91fa33ee 351 GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], DataType.TAB_FV_DIRECTORY)\r
37de70b7
YZ
352 if not os.path.exists(GenFdsGlobalVariable.FvDir):\r
353 os.makedirs(GenFdsGlobalVariable.FvDir)\r
354 GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
355 if not os.path.exists(GenFdsGlobalVariable.FfsDir):\r
356 os.makedirs(GenFdsGlobalVariable.FfsDir)\r
357\r
37de70b7
YZ
358 #\r
359 # Create FV Address inf file\r
360 #\r
361 GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')\r
362 FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')\r
363 #\r
364 # Add [Options]\r
365 #\r
9e47e6f9 366 FvAddressFile.writelines("[options]" + DataType.TAB_LINE_BREAK)\r
37de70b7
YZ
367 BsAddress = '0'\r
368 for Arch in ArchList:\r
369 BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
370 GlobalData.gGlobalDefines['TARGET'],\r
371 GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].BsBaseAddress\r
372 if BsAddress:\r
373 break\r
374\r
375 FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
376 BsAddress + \\r
9e47e6f9 377 DataType.TAB_LINE_BREAK)\r
37de70b7
YZ
378\r
379 RtAddress = '0'\r
9e47e6f9
CJ
380 for Arch in reversed(ArchList):\r
381 temp = GenFdsGlobalVariable.WorkSpace.BuildObject[\r
37de70b7 382 GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
9e47e6f9
CJ
383 GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress\r
384 if temp:\r
385 RtAddress = temp\r
386 break\r
37de70b7
YZ
387\r
388 FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
389 RtAddress + \\r
9e47e6f9 390 DataType.TAB_LINE_BREAK)\r
37de70b7
YZ
391\r
392 FvAddressFile.close()\r
393\r
f51461c8
LG
394 ## ReplaceWorkspaceMacro()\r
395 #\r
396 # @param String String that may contain macro\r
397 #\r
9e47e6f9 398 @staticmethod\r
f51461c8 399 def ReplaceWorkspaceMacro(String):\r
05cc51ad 400 String = mws.handleWsMacro(String)\r
f51461c8
LG
401 Str = String.replace('$(WORKSPACE)', GenFdsGlobalVariable.WorkSpaceDir)\r
402 if os.path.exists(Str):\r
403 if not os.path.isabs(Str):\r
404 Str = os.path.abspath(Str)\r
405 else:\r
05cc51ad 406 Str = mws.join(GenFdsGlobalVariable.WorkSpaceDir, String)\r
f51461c8
LG
407 return os.path.normpath(Str)\r
408\r
409 ## Check if the input files are newer than output files\r
410 #\r
411 # @param Output Path of output file\r
412 # @param Input Path list of input files\r
413 #\r
414 # @retval True if Output doesn't exist, or any Input is newer\r
415 # @retval False if all Input is older than Output\r
416 #\r
417 @staticmethod\r
418 def NeedsUpdate(Output, Input):\r
419 if not os.path.exists(Output):\r
420 return True\r
421 # always update "Output" if no "Input" given\r
9e47e6f9 422 if not Input:\r
f51461c8
LG
423 return True\r
424\r
425 # if fdf file is changed after the 'Output" is generated, update the 'Output'\r
426 OutputTime = os.path.getmtime(Output)\r
427 if GenFdsGlobalVariable.FdfFileTimeStamp > OutputTime:\r
428 return True\r
429\r
430 for F in Input:\r
431 # always update "Output" if any "Input" doesn't exist\r
432 if not os.path.exists(F):\r
433 return True\r
434 # always update "Output" if any "Input" is newer than "Output"\r
435 if os.path.getmtime(F) > OutputTime:\r
436 return True\r
437 return False\r
438\r
439 @staticmethod\r
440 def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,\r
caf74495 441 GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=[], BuildNumber=None, DummyFile=None, IsMakefile=False):\r
f51461c8 442 Cmd = ["GenSec"]\r
c93356ad 443 if Type:\r
caf74495 444 Cmd += ("-s", Type)\r
c93356ad 445 if CompressionType:\r
caf74495 446 Cmd += ("-c", CompressionType)\r
9e47e6f9 447 if Guid:\r
caf74495 448 Cmd += ("-g", Guid)\r
9e47e6f9 449 if DummyFile:\r
caf74495 450 Cmd += ("--dummy", DummyFile)\r
c93356ad 451 if GuidHdrLen:\r
caf74495
JC
452 Cmd += ("-l", GuidHdrLen)\r
453 #Add each guided attribute\r
454 for Attr in GuidAttr:\r
455 Cmd += ("-r", Attr)\r
456 #Section Align is only for dummy section without section type\r
457 for SecAlign in InputAlign:\r
458 Cmd += ("--sectionalign", SecAlign)\r
f51461c8
LG
459\r
460 CommandFile = Output + '.txt'\r
c93356ad 461 if Ui:\r
37de70b7 462 if IsMakefile:\r
a146c532 463 if Ui == "$(MODULE_NAME)":\r
caf74495 464 Cmd += ('-n', Ui)\r
a146c532 465 else:\r
caf74495
JC
466 Cmd += ("-n", '"' + Ui + '"')\r
467 Cmd += ("-o", Output)\r
37de70b7
YZ
468 if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
469 GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
470 else:\r
9e47e6f9 471 SectionData = array('B', [0, 0, 0, 0])\r
37de70b7
YZ
472 SectionData.fromstring(Ui.encode("utf_16_le"))\r
473 SectionData.append(0)\r
474 SectionData.append(0)\r
475 Len = len(SectionData)\r
476 GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
477 SaveFileOnChange(Output, SectionData.tostring())\r
478\r
c93356ad 479 elif Ver:\r
caf74495 480 Cmd += ("-n", Ver)\r
f51461c8 481 if BuildNumber:\r
caf74495
JC
482 Cmd += ("-j", BuildNumber)\r
483 Cmd += ("-o", Output)\r
f51461c8
LG
484\r
485 SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
37de70b7
YZ
486 if IsMakefile:\r
487 if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
488 GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
489 else:\r
490 if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
491 return\r
492 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
f51461c8 493 else:\r
caf74495 494 Cmd += ("-o", Output)\r
f51461c8
LG
495 Cmd += Input\r
496\r
497 SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
37de70b7 498 if IsMakefile:\r
b1e27d17
FB
499 if GlobalData.gGlobalDefines.get("FAMILY") == "MSFT":\r
500 Cmd = ['if', 'exist', Input[0]] + Cmd\r
501 else:\r
502 Cmd = ['test', '-e', Input[0], "&&"] + Cmd\r
37de70b7
YZ
503 if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
504 GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
6735645d 505 elif GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
f51461c8
LG
506 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
507 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
37de70b7
YZ
508 if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and\r
509 GenFdsGlobalVariable.LargeFileInFvFlags):\r
510 GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True\r
f51461c8
LG
511\r
512 @staticmethod\r
513 def GetAlignment (AlignString):\r
7bf1eb6e 514 if not AlignString:\r
f51461c8 515 return 0\r
7bf1eb6e 516 if AlignString.endswith('K'):\r
52302d4d 517 return int (AlignString.rstrip('K')) * 1024\r
7bf1eb6e 518 if AlignString.endswith('M'):\r
e921f58d 519 return int (AlignString.rstrip('M')) * 1024 * 1024\r
7bf1eb6e
CJ
520 if AlignString.endswith('G'):\r
521 return int (AlignString.rstrip('G')) * 1024 * 1024 * 1024\r
522 return int (AlignString)\r
f51461c8
LG
523\r
524 @staticmethod\r
525 def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
37de70b7 526 SectionAlign=None, MakefilePath=None):\r
f51461c8 527 Cmd = ["GenFfs", "-t", Type, "-g", Guid]\r
e921f58d 528 mFfsValidAlign = ["0", "8", "16", "128", "512", "1K", "4K", "32K", "64K", "128K", "256K", "512K", "1M", "2M", "4M", "8M", "16M"]\r
f51461c8 529 if Fixed == True:\r
caf74495 530 Cmd.append("-x")\r
f51461c8 531 if CheckSum:\r
caf74495 532 Cmd.append("-s")\r
c93356ad 533 if Align:\r
d2192f12
YZ
534 if Align not in mFfsValidAlign:\r
535 Align = GenFdsGlobalVariable.GetAlignment (Align)\r
536 for index in range(0, len(mFfsValidAlign) - 1):\r
537 if ((Align > GenFdsGlobalVariable.GetAlignment(mFfsValidAlign[index])) and (Align <= GenFdsGlobalVariable.GetAlignment(mFfsValidAlign[index + 1]))):\r
538 break\r
539 Align = mFfsValidAlign[index + 1]\r
caf74495 540 Cmd += ("-a", Align)\r
f51461c8 541\r
caf74495 542 Cmd += ("-o", Output)\r
f51461c8 543 for I in range(0, len(Input)):\r
b1e27d17
FB
544 if MakefilePath:\r
545 Cmd += ("-oi", Input[I])\r
546 else:\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
d943b0c3
FB
727 GenFdsGlobalVariable.InfLogger(out.decode(encoding='utf-8', errors='ignore'))\r
728 GenFdsGlobalVariable.InfLogger(error.decode(encoding='utf-8', errors='ignore'))\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 759 Dict = {'$(WORKSPACE)': GenFdsGlobalVariable.WorkSpaceDir,\r
f51461c8 760# '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,\r
9e47e6f9
CJ
761 '$(TARGET)': GenFdsGlobalVariable.TargetName,\r
762 '$(TOOL_CHAIN_TAG)': GenFdsGlobalVariable.ToolChainTag,\r
763 '$(SPACE)': ' '\r
f51461c8 764 }\r
9e47e6f9 765\r
55c84777 766 if Arch != DataType.TAB_COMMON and Arch in GenFdsGlobalVariable.ArchList:\r
f51461c8 767 OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[Arch]\r
9e47e6f9
CJ
768 else:\r
769 OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
f51461c8
LG
770\r
771 Dict['$(OUTPUT_DIRECTORY)'] = OutputDir\r
772\r
9e47e6f9 773 if MacroDict:\r
f51461c8
LG
774 Dict.update(MacroDict)\r
775\r
9eb87141 776 for key in Dict:\r
9e47e6f9 777 if Str.find(key) >= 0:\r
f51461c8
LG
778 Str = Str.replace (key, Dict[key])\r
779\r
780 if Str.find('$(ARCH)') >= 0:\r
781 if len(GenFdsGlobalVariable.ArchList) == 1:\r
782 Str = Str.replace('$(ARCH)', GenFdsGlobalVariable.ArchList[0])\r
783 else:\r
784 EdkLogger.error("GenFds", GENFDS_ERROR, "No way to determine $(ARCH) for %s" % Str)\r
785\r
786 return Str\r
787\r
788 ## GetPcdValue()\r
789 #\r
790 # @param PcdPattern pattern that labels a PCD.\r
791 #\r
9e47e6f9 792 @staticmethod\r
f51461c8 793 def GetPcdValue (PcdPattern):\r
9e47e6f9 794 if PcdPattern is None:\r
f51461c8
LG
795 return None\r
796 PcdPair = PcdPattern.lstrip('PCD(').rstrip(')').strip().split('.')\r
797 TokenSpace = PcdPair[0]\r
798 TokenCName = PcdPair[1]\r
799\r
f51461c8
LG
800 for Arch in GenFdsGlobalVariable.ArchList:\r
801 Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
802 PcdDict = Platform.Pcds\r
803 for Key in PcdDict:\r
804 PcdObj = PcdDict[Key]\r
805 if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):\r
be409b67 806 if PcdObj.Type != DataType.TAB_PCDS_FIXED_AT_BUILD:\r
f51461c8 807 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)\r
656d2539 808 if PcdObj.DatumType != DataType.TAB_VOID:\r
f51461c8 809 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)\r
f7496d71 810\r
9e47e6f9 811 return PcdObj.DefaultValue\r
47fea6af
YZ
812\r
813 for Package in GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,\r
814 Arch,\r
815 GenFdsGlobalVariable.TargetName,\r
f51461c8
LG
816 GenFdsGlobalVariable.ToolChainTag):\r
817 PcdDict = Package.Pcds\r
818 for Key in PcdDict:\r
819 PcdObj = PcdDict[Key]\r
820 if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):\r
be409b67 821 if PcdObj.Type != DataType.TAB_PCDS_FIXED_AT_BUILD:\r
f51461c8 822 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)\r
656d2539 823 if PcdObj.DatumType != DataType.TAB_VOID:\r
f51461c8 824 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)\r
f7496d71 825\r
9e47e6f9 826 return PcdObj.DefaultValue\r
f51461c8 827\r
9e47e6f9 828 return ''\r
89a69d4b
GL
829\r
830## FindExtendTool()\r
831#\r
832# Find location of tools to process data\r
833#\r
834# @param KeyStringList Filter for inputs of section generation\r
835# @param CurrentArchList Arch list\r
836# @param NameGuid The Guid name\r
837#\r
838def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
839 ToolDb = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
840 # if user not specify filter, try to deduce it from global data.\r
841 if KeyStringList is None or KeyStringList == []:\r
842 Target = GenFdsGlobalVariable.TargetName\r
843 ToolChain = GenFdsGlobalVariable.ToolChainTag\r
844 if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:\r
845 EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)\r
846 KeyStringList = [Target + '_' + ToolChain + '_' + CurrentArchList[0]]\r
847 for Arch in CurrentArchList:\r
848 if Target + '_' + ToolChain + '_' + Arch not in KeyStringList:\r
849 KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)\r
850\r
851 if GenFdsGlobalVariable.GuidToolDefinition:\r
852 if NameGuid in GenFdsGlobalVariable.GuidToolDefinition:\r
853 return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]\r
854\r
855 ToolDefinition = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
856 ToolPathTmp = None\r
857 ToolOption = None\r
858 ToolPathKey = None\r
859 ToolOptionKey = None\r
860 KeyList = None\r
861 for ToolDef in ToolDefinition.items():\r
9e47e6f9 862 if NameGuid.lower() == ToolDef[1].lower():\r
89a69d4b
GL
863 KeyList = ToolDef[0].split('_')\r
864 Key = KeyList[0] + \\r
865 '_' + \\r
866 KeyList[1] + \\r
867 '_' + \\r
868 KeyList[2]\r
869 if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID:\r
870 ToolPathKey = Key + '_' + KeyList[3] + '_PATH'\r
871 ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
872 ToolPath = ToolDefinition.get(ToolPathKey)\r
873 ToolOption = ToolDefinition.get(ToolOptionKey)\r
874 if ToolPathTmp is None:\r
875 ToolPathTmp = ToolPath\r
876 else:\r
877 if ToolPathTmp != ToolPath:\r
878 EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
879\r
880 BuildOption = {}\r
881 for Arch in CurrentArchList:\r
882 Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
883 # key is (ToolChainFamily, ToolChain, CodeBase)\r
884 for item in Platform.BuildOptions:\r
885 if '_PATH' in item[1] or '_FLAGS' in item[1] or '_GUID' in item[1]:\r
886 if not item[0] or (item[0] and GenFdsGlobalVariable.ToolChainFamily== item[0]):\r
887 if item[1] not in BuildOption:\r
888 BuildOption[item[1]] = Platform.BuildOptions[item]\r
889 if BuildOption:\r
890 ToolList = [DataType.TAB_TOD_DEFINES_TARGET, DataType.TAB_TOD_DEFINES_TOOL_CHAIN_TAG, DataType.TAB_TOD_DEFINES_TARGET_ARCH]\r
891 for Index in range(2, -1, -1):\r
892 for Key in list(BuildOption.keys()):\r
893 List = Key.split('_')\r
bc39c5cb 894 if List[Index] == DataType.TAB_STAR:\r
89a69d4b
GL
895 for String in ToolDb[ToolList[Index]]:\r
896 if String in [Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]:\r
897 List[Index] = String\r
898 NewKey = '%s_%s_%s_%s_%s' % tuple(List)\r
899 if NewKey not in BuildOption:\r
900 BuildOption[NewKey] = BuildOption[Key]\r
901 continue\r
902 del BuildOption[Key]\r
903 elif List[Index] not in ToolDb[ToolList[Index]]:\r
904 del BuildOption[Key]\r
905 if BuildOption:\r
906 if not KeyList:\r
907 for Op in BuildOption:\r
908 if NameGuid == BuildOption[Op]:\r
909 KeyList = Op.split('_')\r
910 Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]\r
911 if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID:\r
912 ToolPathKey = Key + '_' + KeyList[3] + '_PATH'\r
913 ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
914 if ToolPathKey in BuildOption:\r
915 ToolPathTmp = BuildOption[ToolPathKey]\r
916 if ToolOptionKey in BuildOption:\r
917 ToolOption = BuildOption[ToolOptionKey]\r
918\r
919 GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
920 return ToolPathTmp, ToolOption\r