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