]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
EmulatorPkg/build.sh: Use GCC49 toolchain with GCC 5.*
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFdsGlobalVariable.py
CommitLineData
f51461c8
LG
1## @file\r
2# Global variables for GenFds\r
3#\r
1be2ed90 4# Copyright (c) 2007 - 2014, 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
29from Common.ToolDefClassObject import ToolDefClassObject\r
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
f51461c8
LG
34\r
35## Global variables\r
36#\r
37#\r
38class GenFdsGlobalVariable:\r
39 FvDir = ''\r
40 OutputDirDict = {}\r
41 BinDir = ''\r
42 # will be FvDir + os.sep + 'Ffs'\r
43 FfsDir = ''\r
44 FdfParser = None\r
45 LibDir = ''\r
46 WorkSpace = None\r
47 WorkSpaceDir = ''\r
97fa0ee9 48 ConfDir = ''\r
f51461c8
LG
49 EdkSourceDir = ''\r
50 OutputDirFromDscDict = {}\r
51 TargetName = ''\r
52 ToolChainTag = ''\r
53 RuleDict = {}\r
54 ArchList = None\r
55 VtfDict = {}\r
56 ActivePlatform = None\r
57 FvAddressFileName = ''\r
58 VerboseMode = False\r
59 DebugLevel = -1\r
60 SharpCounter = 0\r
61 SharpNumberPerLine = 40\r
62 FdfFile = ''\r
63 FdfFileTimeStamp = 0\r
64 FixedLoadAddress = False\r
65 PlatformName = ''\r
66 \r
67 BuildRuleFamily = "MSFT"\r
68 ToolChainFamily = "MSFT"\r
69 __BuildRuleDatabase = None\r
70 \r
71 #\r
72 # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.\r
73 # At the beginning of each generation of FV, false flag is appended to the list,\r
74 # after the call to GenerateSection returns, check the size of the output file,\r
75 # if it is greater than 0xFFFFFF, the tail flag in list is set to true,\r
76 # and EFI_FIRMWARE_FILE_SYSTEM3_GUID is passed to C GenFv.\r
77 # At the end of generation of FV, pop the flag.\r
78 # List is used as a stack to handle nested FV generation.\r
79 #\r
80 LargeFileInFvFlags = []\r
81 EFI_FIRMWARE_FILE_SYSTEM3_GUID = '5473C07A-3DCB-4dca-BD6F-1E9689E7349A'\r
82 LARGE_FILE_SIZE = 0x1000000\r
83\r
84 SectionHeader = struct.Struct("3B 1B")\r
85 \r
86 ## LoadBuildRule\r
87 #\r
88 @staticmethod\r
89 def __LoadBuildRule():\r
90 if GenFdsGlobalVariable.__BuildRuleDatabase:\r
91 return GenFdsGlobalVariable.__BuildRuleDatabase\r
97fa0ee9 92 BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.ConfDir, "target.txt"))\r
f51461c8
LG
93 TargetTxt = TargetTxtClassObject()\r
94 if os.path.isfile(BuildConfigurationFile) == True:\r
95 TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)\r
96 if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:\r
97 BuildRuleFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
98 if BuildRuleFile in [None, '']:\r
99 BuildRuleFile = 'Conf/build_rule.txt'\r
100 GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)\r
101 ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
102 if ToolDefinitionFile == '':\r
103 ToolDefinitionFile = "Conf/tools_def.txt"\r
104 if os.path.isfile(ToolDefinitionFile):\r
105 ToolDef = ToolDefClassObject()\r
106 ToolDef.LoadToolDefFile(ToolDefinitionFile)\r
107 ToolDefinition = ToolDef.ToolsDefTxtDatabase\r
108 if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \\r
109 and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
110 and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
111 GenFdsGlobalVariable.BuildRuleFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]\r
112 \r
113 if DataType.TAB_TOD_DEFINES_FAMILY in ToolDefinition \\r
114 and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY] \\r
115 and ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
116 GenFdsGlobalVariable.ToolChainFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]\r
117 return GenFdsGlobalVariable.__BuildRuleDatabase\r
118\r
119 ## GetBuildRules\r
120 # @param Inf: object of InfBuildData\r
121 # @param Arch: current arch\r
122 #\r
123 @staticmethod\r
124 def GetBuildRules(Inf, Arch):\r
125 if not Arch:\r
126 Arch = 'COMMON'\r
127\r
128 if not Arch in GenFdsGlobalVariable.OutputDirDict:\r
129 return {}\r
130\r
131 BuildRuleDatabase = GenFdsGlobalVariable.__LoadBuildRule()\r
132 if not BuildRuleDatabase:\r
133 return {}\r
134\r
135 PathClassObj = PathClass(Inf.MetaFile.File,\r
136 GenFdsGlobalVariable.WorkSpaceDir)\r
137 Macro = {}\r
138 Macro["WORKSPACE" ] = GenFdsGlobalVariable.WorkSpaceDir\r
139 Macro["MODULE_NAME" ] = Inf.BaseName\r
140 Macro["MODULE_GUID" ] = Inf.Guid\r
141 Macro["MODULE_VERSION" ] = Inf.Version\r
142 Macro["MODULE_TYPE" ] = Inf.ModuleType\r
143 Macro["MODULE_FILE" ] = str(PathClassObj)\r
144 Macro["MODULE_FILE_BASE_NAME" ] = PathClassObj.BaseName\r
145 Macro["MODULE_RELATIVE_DIR" ] = PathClassObj.SubDir\r
146 Macro["MODULE_DIR" ] = PathClassObj.SubDir\r
147\r
148 Macro["BASE_NAME" ] = Inf.BaseName\r
149\r
150 Macro["ARCH" ] = Arch\r
151 Macro["TOOLCHAIN" ] = GenFdsGlobalVariable.ToolChainTag\r
152 Macro["TOOLCHAIN_TAG" ] = GenFdsGlobalVariable.ToolChainTag\r
153 Macro["TOOL_CHAIN_TAG" ] = GenFdsGlobalVariable.ToolChainTag\r
154 Macro["TARGET" ] = GenFdsGlobalVariable.TargetName\r
155\r
156 Macro["BUILD_DIR" ] = GenFdsGlobalVariable.OutputDirDict[Arch]\r
157 Macro["BIN_DIR" ] = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)\r
158 Macro["LIB_DIR" ] = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)\r
159 BuildDir = os.path.join(\r
160 GenFdsGlobalVariable.OutputDirDict[Arch],\r
161 Arch,\r
162 PathClassObj.SubDir,\r
163 PathClassObj.BaseName\r
164 )\r
165 Macro["MODULE_BUILD_DIR" ] = BuildDir\r
166 Macro["OUTPUT_DIR" ] = os.path.join(BuildDir, "OUTPUT")\r
167 Macro["DEBUG_DIR" ] = os.path.join(BuildDir, "DEBUG")\r
168\r
169 BuildRules = {}\r
170 for Type in BuildRuleDatabase.FileTypeList:\r
171 #first try getting build rule by BuildRuleFamily\r
172 RuleObject = BuildRuleDatabase[Type, Inf.BuildType, Arch, GenFdsGlobalVariable.BuildRuleFamily]\r
173 if not RuleObject:\r
174 # build type is always module type, but ...\r
175 if Inf.ModuleType != Inf.BuildType:\r
176 RuleObject = BuildRuleDatabase[Type, Inf.ModuleType, Arch, GenFdsGlobalVariable.BuildRuleFamily]\r
177 #second try getting build rule by ToolChainFamily\r
178 if not RuleObject:\r
179 RuleObject = BuildRuleDatabase[Type, Inf.BuildType, Arch, GenFdsGlobalVariable.ToolChainFamily]\r
180 if not RuleObject:\r
181 # build type is always module type, but ...\r
182 if Inf.ModuleType != Inf.BuildType:\r
183 RuleObject = BuildRuleDatabase[Type, Inf.ModuleType, Arch, GenFdsGlobalVariable.ToolChainFamily]\r
184 if not RuleObject:\r
185 continue\r
186 RuleObject = RuleObject.Instantiate(Macro)\r
187 BuildRules[Type] = RuleObject\r
188 for Ext in RuleObject.SourceFileExtList:\r
189 BuildRules[Ext] = RuleObject\r
190 return BuildRules\r
191\r
192 ## GetModuleCodaTargetList\r
193 #\r
194 # @param Inf: object of InfBuildData\r
195 # @param Arch: current arch\r
196 #\r
197 @staticmethod\r
198 def GetModuleCodaTargetList(Inf, Arch):\r
199 BuildRules = GenFdsGlobalVariable.GetBuildRules(Inf, Arch)\r
200 if not BuildRules:\r
201 return []\r
202\r
203 TargetList = set()\r
204 FileList = []\r
97fa0ee9
YL
205\r
206 if not Inf.IsBinaryModule:\r
207 for File in Inf.Sources:\r
208 if File.TagName in ("", "*", GenFdsGlobalVariable.ToolChainTag) and \\r
209 File.ToolChainFamily in ("", "*", GenFdsGlobalVariable.ToolChainFamily):\r
210 FileList.append((File, DataType.TAB_UNKNOWN_FILE))\r
211\r
f51461c8
LG
212 for File in Inf.Binaries:\r
213 if File.Target in ['COMMON', '*', GenFdsGlobalVariable.TargetName]:\r
214 FileList.append((File, File.Type))\r
215\r
216 for File, FileType in FileList:\r
217 LastTarget = None\r
218 RuleChain = []\r
219 SourceList = [File]\r
220 Index = 0\r
221 while Index < len(SourceList):\r
222 Source = SourceList[Index]\r
223 Index = Index + 1\r
224 \r
225 if File.IsBinary and File == Source and Inf.Binaries != None and File in Inf.Binaries:\r
226 # Skip all files that are not binary libraries\r
227 if not Inf.LibraryClass:\r
228 continue \r
229 RuleObject = BuildRules[DataType.TAB_DEFAULT_BINARY_FILE]\r
230 elif FileType in BuildRules:\r
231 RuleObject = BuildRules[FileType]\r
232 elif Source.Ext in BuildRules:\r
233 RuleObject = BuildRules[Source.Ext]\r
234 else:\r
235 # stop at no more rules\r
236 if LastTarget:\r
237 TargetList.add(str(LastTarget))\r
238 break\r
239 \r
240 FileType = RuleObject.SourceFileType\r
241 \r
242 # stop at STATIC_LIBRARY for library\r
243 if Inf.LibraryClass and FileType == DataType.TAB_STATIC_LIBRARY:\r
244 if LastTarget:\r
245 TargetList.add(str(LastTarget))\r
246 break\r
247 \r
248 Target = RuleObject.Apply(Source)\r
249 if not Target:\r
250 if LastTarget:\r
251 TargetList.add(str(LastTarget))\r
252 break\r
253 elif not Target.Outputs:\r
254 # Only do build for target with outputs\r
255 TargetList.add(str(Target))\r
256 \r
257 # to avoid cyclic rule\r
258 if FileType in RuleChain:\r
259 break\r
260 \r
261 RuleChain.append(FileType)\r
262 SourceList.extend(Target.Outputs)\r
263 LastTarget = Target\r
264 FileType = DataType.TAB_UNKNOWN_FILE\r
265\r
266 return list(TargetList)\r
267\r
268 ## SetDir()\r
269 #\r
270 # @param OutputDir Output directory\r
271 # @param FdfParser FDF contents parser\r
272 # @param Workspace The directory of workspace\r
273 # @param ArchList The Arch list of platform\r
274 #\r
275 def SetDir (OutputDir, FdfParser, WorkSpace, ArchList):\r
276 GenFdsGlobalVariable.VerboseLogger( "GenFdsGlobalVariable.OutputDir :%s" %OutputDir)\r
277# GenFdsGlobalVariable.OutputDirDict = OutputDir\r
278 GenFdsGlobalVariable.FdfParser = FdfParser\r
279 GenFdsGlobalVariable.WorkSpace = WorkSpace\r
280 GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], 'FV')\r
281 if not os.path.exists(GenFdsGlobalVariable.FvDir) :\r
282 os.makedirs(GenFdsGlobalVariable.FvDir)\r
283 GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
284 if not os.path.exists(GenFdsGlobalVariable.FfsDir) :\r
285 os.makedirs(GenFdsGlobalVariable.FfsDir)\r
286 if ArchList != None:\r
287 GenFdsGlobalVariable.ArchList = ArchList\r
288\r
289 T_CHAR_LF = '\n'\r
290 #\r
291 # Create FV Address inf file\r
292 #\r
293 GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')\r
294 FvAddressFile = open (GenFdsGlobalVariable.FvAddressFileName, 'w')\r
295 #\r
296 # Add [Options]\r
297 #\r
298 FvAddressFile.writelines("[options]" + T_CHAR_LF)\r
299 BsAddress = '0'\r
300 for Arch in ArchList:\r
301 if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress:\r
302 BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress\r
303 break\r
304\r
305 FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
306 BsAddress + \\r
307 T_CHAR_LF)\r
308\r
309 RtAddress = '0'\r
310 for Arch in ArchList:\r
311 if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress:\r
312 RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress\r
313\r
314 FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
315 RtAddress + \\r
316 T_CHAR_LF)\r
317\r
318 FvAddressFile.close()\r
319\r
320 ## ReplaceWorkspaceMacro()\r
321 #\r
322 # @param String String that may contain macro\r
323 #\r
324 def ReplaceWorkspaceMacro(String):\r
325 Str = String.replace('$(WORKSPACE)', GenFdsGlobalVariable.WorkSpaceDir)\r
326 if os.path.exists(Str):\r
327 if not os.path.isabs(Str):\r
328 Str = os.path.abspath(Str)\r
329 else:\r
330 Str = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, String)\r
331 return os.path.normpath(Str)\r
332\r
333 ## Check if the input files are newer than output files\r
334 #\r
335 # @param Output Path of output file\r
336 # @param Input Path list of input files\r
337 #\r
338 # @retval True if Output doesn't exist, or any Input is newer\r
339 # @retval False if all Input is older than Output\r
340 #\r
341 @staticmethod\r
342 def NeedsUpdate(Output, Input):\r
343 if not os.path.exists(Output):\r
344 return True\r
345 # always update "Output" if no "Input" given\r
346 if Input == None or len(Input) == 0:\r
347 return True\r
348\r
349 # if fdf file is changed after the 'Output" is generated, update the 'Output'\r
350 OutputTime = os.path.getmtime(Output)\r
351 if GenFdsGlobalVariable.FdfFileTimeStamp > OutputTime:\r
352 return True\r
353\r
354 for F in Input:\r
355 # always update "Output" if any "Input" doesn't exist\r
356 if not os.path.exists(F):\r
357 return True\r
358 # always update "Output" if any "Input" is newer than "Output"\r
359 if os.path.getmtime(F) > OutputTime:\r
360 return True\r
361 return False\r
362\r
363 @staticmethod\r
364 def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,\r
365 GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None):\r
366 Cmd = ["GenSec"]\r
367 if Type not in [None, '']:\r
368 Cmd += ["-s", Type]\r
369 if CompressionType not in [None, '']:\r
370 Cmd += ["-c", CompressionType]\r
371 if Guid != None:\r
372 Cmd += ["-g", Guid]\r
373 if GuidHdrLen not in [None, '']:\r
374 Cmd += ["-l", GuidHdrLen]\r
375 if len(GuidAttr) != 0:\r
376 #Add each guided attribute\r
377 for Attr in GuidAttr:\r
378 Cmd += ["-r", Attr]\r
379 if InputAlign != None:\r
380 #Section Align is only for dummy section without section type\r
381 for SecAlign in InputAlign:\r
382 Cmd += ["--sectionalign", SecAlign]\r
383\r
384 CommandFile = Output + '.txt'\r
385 if Ui not in [None, '']:\r
386 #Cmd += ["-n", '"' + Ui + '"']\r
387 SectionData = array.array('B', [0,0,0,0])\r
388 SectionData.fromstring(Ui.encode("utf_16_le"))\r
389 SectionData.append(0)\r
390 SectionData.append(0)\r
391 Len = len(SectionData)\r
392 GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
393 SaveFileOnChange(Output, SectionData.tostring())\r
394 elif Ver not in [None, '']:\r
395 Cmd += ["-n", Ver]\r
396 if BuildNumber:\r
397 Cmd += ["-j", BuildNumber]\r
398 Cmd += ["-o", Output]\r
399\r
400 SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
401 if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
402 return\r
403\r
404 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
405 else:\r
406 Cmd += ["-o", Output]\r
407 Cmd += Input\r
408\r
409 SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
410 if GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
411 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
412 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
413\r
414 if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and\r
415 GenFdsGlobalVariable.LargeFileInFvFlags):\r
416 GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True \r
417\r
418 @staticmethod\r
419 def GetAlignment (AlignString):\r
420 if AlignString == None:\r
421 return 0\r
52302d4d
LG
422 if AlignString in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):\r
423 return int (AlignString.rstrip('K')) * 1024\r
424 else:\r
425 return int (AlignString)\r
f51461c8
LG
426\r
427 @staticmethod\r
428 def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
429 SectionAlign=None):\r
430 Cmd = ["GenFfs", "-t", Type, "-g", Guid]\r
431 if Fixed == True:\r
432 Cmd += ["-x"]\r
433 if CheckSum:\r
434 Cmd += ["-s"]\r
435 if Align not in [None, '']:\r
436 Cmd += ["-a", Align]\r
437\r
438 Cmd += ["-o", Output]\r
439 for I in range(0, len(Input)):\r
440 Cmd += ("-i", Input[I])\r
441 if SectionAlign not in [None, '', []] and SectionAlign[I] not in [None, '']:\r
442 Cmd += ("-n", SectionAlign[I])\r
443\r
444 CommandFile = Output + '.txt'\r
445 SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
446 if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
447 return\r
448 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
449\r
450 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")\r
451\r
452 @staticmethod\r
453 def GenerateFirmwareVolume(Output, Input, BaseAddress=None, ForceRebase=None, Capsule=False, Dump=False,\r
454 AddressFile=None, MapFile=None, FfsList=[], FileSystemGuid=None):\r
455 if not GenFdsGlobalVariable.NeedsUpdate(Output, Input+FfsList):\r
456 return\r
457 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
458\r
459 Cmd = ["GenFv"]\r
460 if BaseAddress not in [None, '']:\r
461 Cmd += ["-r", BaseAddress]\r
462 \r
463 if ForceRebase == False:\r
464 Cmd +=["-F", "FALSE"]\r
465 elif ForceRebase == True:\r
466 Cmd +=["-F", "TRUE"]\r
467 \r
468 if Capsule:\r
469 Cmd += ["-c"]\r
470 if Dump:\r
471 Cmd += ["-p"]\r
472 if AddressFile not in [None, '']:\r
473 Cmd += ["-a", AddressFile]\r
474 if MapFile not in [None, '']:\r
475 Cmd += ["-m", MapFile]\r
476 if FileSystemGuid:\r
477 Cmd += ["-g", FileSystemGuid]\r
478 Cmd += ["-o", Output]\r
479 for I in Input:\r
480 Cmd += ["-i", I]\r
481\r
482 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FV")\r
483\r
484 @staticmethod\r
485 def GenerateVtf(Output, Input, BaseAddress=None, FvSize=None):\r
486 if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
487 return\r
488 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
489\r
490 Cmd = ["GenVtf"]\r
491 if BaseAddress not in [None, ''] and FvSize not in [None, ''] \\r
492 and len(BaseAddress) == len(FvSize):\r
493 for I in range(0, len(BaseAddress)):\r
494 Cmd += ["-r", BaseAddress[I], "-s", FvSize[I]]\r
495 Cmd += ["-o", Output]\r
496 for F in Input:\r
497 Cmd += ["-f", F]\r
498\r
499 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate VTF")\r
500\r
501 @staticmethod\r
502 def GenerateFirmwareImage(Output, Input, Type="efi", SubType=None, Zero=False,\r
503 Strip=False, Replace=False, TimeStamp=None, Join=False,\r
504 Align=None, Padding=None, Convert=False):\r
505 if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
506 return\r
507 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
508\r
509 Cmd = ["GenFw"]\r
510 if Type.lower() == "te":\r
511 Cmd += ["-t"]\r
512 if SubType not in [None, '']:\r
513 Cmd += ["-e", SubType]\r
514 if TimeStamp not in [None, '']:\r
515 Cmd += ["-s", TimeStamp]\r
516 if Align not in [None, '']:\r
517 Cmd += ["-a", Align]\r
518 if Padding not in [None, '']:\r
519 Cmd += ["-p", Padding]\r
520 if Zero:\r
521 Cmd += ["-z"]\r
522 if Strip:\r
523 Cmd += ["-l"]\r
524 if Replace:\r
525 Cmd += ["-r"]\r
526 if Join:\r
527 Cmd += ["-j"]\r
528 if Convert:\r
529 Cmd += ["-m"]\r
530 Cmd += ["-o", Output]\r
531 Cmd += Input\r
532\r
533 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")\r
534\r
535 @staticmethod\r
536 def GenerateOptionRom(Output, EfiInput, BinaryInput, Compress=False, ClassCode=None,\r
537 Revision=None, DeviceId=None, VendorId=None):\r
538 InputList = [] \r
539 Cmd = ["EfiRom"]\r
540 if len(EfiInput) > 0:\r
541 \r
542 if Compress:\r
543 Cmd += ["-ec"]\r
544 else:\r
545 Cmd += ["-e"]\r
546 \r
547 for EfiFile in EfiInput:\r
548 Cmd += [EfiFile]\r
549 InputList.append (EfiFile)\r
550 \r
551 if len(BinaryInput) > 0:\r
552 Cmd += ["-b"]\r
553 for BinFile in BinaryInput:\r
554 Cmd += [BinFile]\r
555 InputList.append (BinFile)\r
556\r
557 # Check List\r
558 if not GenFdsGlobalVariable.NeedsUpdate(Output, InputList):\r
559 return\r
560 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, InputList))\r
561 \r
562 if ClassCode != None:\r
563 Cmd += ["-l", ClassCode]\r
564 if Revision != None:\r
565 Cmd += ["-r", Revision]\r
566 if DeviceId != None:\r
567 Cmd += ["-i", DeviceId]\r
568 if VendorId != None:\r
569 Cmd += ["-f", VendorId]\r
570\r
571 Cmd += ["-o", Output] \r
572 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
573\r
574 @staticmethod\r
575 def GuidTool(Output, Input, ToolPath, Options='', returnValue=[]):\r
576 if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
577 return\r
578 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
579\r
580 Cmd = [ToolPath, ]\r
581 Cmd += Options.split(' ')\r
582 Cmd += ["-o", Output]\r
583 Cmd += Input\r
584\r
585 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)\r
586\r
587 def CallExternalTool (cmd, errorMess, returnValue=[]):\r
588\r
589 if type(cmd) not in (tuple, list):\r
590 GenFdsGlobalVariable.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool")\r
591\r
592 if GenFdsGlobalVariable.DebugLevel != -1:\r
593 cmd += ('--debug', str(GenFdsGlobalVariable.DebugLevel))\r
594 GenFdsGlobalVariable.InfLogger (cmd)\r
595\r
596 if GenFdsGlobalVariable.VerboseMode:\r
597 cmd += ('-v',)\r
598 GenFdsGlobalVariable.InfLogger (cmd)\r
599 else:\r
600 sys.stdout.write ('#')\r
601 sys.stdout.flush()\r
602 GenFdsGlobalVariable.SharpCounter = GenFdsGlobalVariable.SharpCounter + 1\r
603 if GenFdsGlobalVariable.SharpCounter % GenFdsGlobalVariable.SharpNumberPerLine == 0:\r
604 sys.stdout.write('\n')\r
605\r
606 try:\r
607 PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr= subprocess.PIPE, shell=True)\r
608 except Exception, X:\r
609 EdkLogger.error("GenFds", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0]))\r
610 (out, error) = PopenObject.communicate()\r
611\r
612 while PopenObject.returncode == None :\r
613 PopenObject.wait()\r
614 if returnValue != [] and returnValue[0] != 0:\r
615 #get command return value\r
616 returnValue[0] = PopenObject.returncode\r
617 return\r
618 if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:\r
619 GenFdsGlobalVariable.InfLogger ("Return Value = %d" %PopenObject.returncode)\r
620 GenFdsGlobalVariable.InfLogger (out)\r
621 GenFdsGlobalVariable.InfLogger (error)\r
622 if PopenObject.returncode != 0:\r
623 print "###", cmd\r
624 EdkLogger.error("GenFds", COMMAND_FAILURE, errorMess)\r
625\r
626 def VerboseLogger (msg):\r
627 EdkLogger.verbose(msg)\r
628\r
629 def InfLogger (msg):\r
630 EdkLogger.info(msg)\r
631\r
632 def ErrorLogger (msg, File = None, Line = None, ExtraData = None):\r
633 EdkLogger.error('GenFds', GENFDS_ERROR, msg, File, Line, ExtraData)\r
634\r
635 def DebugLogger (Level, msg):\r
636 EdkLogger.debug(Level, msg)\r
637\r
638 ## ReplaceWorkspaceMacro()\r
639 #\r
640 # @param Str String that may contain macro\r
641 # @param MacroDict Dictionary that contains macro value pair\r
642 #\r
643 def MacroExtend (Str, MacroDict = {}, Arch = 'COMMON'):\r
644 if Str == None :\r
645 return None\r
646\r
647 Dict = {'$(WORKSPACE)' : GenFdsGlobalVariable.WorkSpaceDir,\r
648 '$(EDK_SOURCE)' : GenFdsGlobalVariable.EdkSourceDir,\r
649# '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,\r
650 '$(TARGET)' : GenFdsGlobalVariable.TargetName,\r
97fa0ee9
YL
651 '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable.ToolChainTag,\r
652 '$(SPACE)' : ' '\r
f51461c8
LG
653 }\r
654 OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
655 if Arch != 'COMMON' and Arch in GenFdsGlobalVariable.ArchList:\r
656 OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[Arch]\r
657\r
658 Dict['$(OUTPUT_DIRECTORY)'] = OutputDir\r
659\r
660 if MacroDict != None and len (MacroDict) != 0:\r
661 Dict.update(MacroDict)\r
662\r
663 for key in Dict.keys():\r
664 if Str.find(key) >= 0 :\r
665 Str = Str.replace (key, Dict[key])\r
666\r
667 if Str.find('$(ARCH)') >= 0:\r
668 if len(GenFdsGlobalVariable.ArchList) == 1:\r
669 Str = Str.replace('$(ARCH)', GenFdsGlobalVariable.ArchList[0])\r
670 else:\r
671 EdkLogger.error("GenFds", GENFDS_ERROR, "No way to determine $(ARCH) for %s" % Str)\r
672\r
673 return Str\r
674\r
675 ## GetPcdValue()\r
676 #\r
677 # @param PcdPattern pattern that labels a PCD.\r
678 #\r
679 def GetPcdValue (PcdPattern):\r
680 if PcdPattern == None :\r
681 return None\r
682 PcdPair = PcdPattern.lstrip('PCD(').rstrip(')').strip().split('.')\r
683 TokenSpace = PcdPair[0]\r
684 TokenCName = PcdPair[1]\r
685\r
686 PcdValue = ''\r
687 for Arch in GenFdsGlobalVariable.ArchList:\r
688 Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
689 PcdDict = Platform.Pcds\r
690 for Key in PcdDict:\r
691 PcdObj = PcdDict[Key]\r
692 if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):\r
693 if PcdObj.Type != 'FixedAtBuild':\r
694 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)\r
695 if PcdObj.DatumType != 'VOID*':\r
696 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)\r
697 \r
698 PcdValue = PcdObj.DefaultValue\r
699 return PcdValue\r
700 \r
701 for Package in GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform, \r
702 Arch, \r
703 GenFdsGlobalVariable.TargetName, \r
704 GenFdsGlobalVariable.ToolChainTag):\r
705 PcdDict = Package.Pcds\r
706 for Key in PcdDict:\r
707 PcdObj = PcdDict[Key]\r
708 if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):\r
709 if PcdObj.Type != 'FixedAtBuild':\r
710 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)\r
711 if PcdObj.DatumType != 'VOID*':\r
712 EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)\r
713 \r
714 PcdValue = PcdObj.DefaultValue\r
715 return PcdValue\r
716\r
717 return PcdValue\r
718\r
719 SetDir = staticmethod(SetDir)\r
720 ReplaceWorkspaceMacro = staticmethod(ReplaceWorkspaceMacro)\r
721 CallExternalTool = staticmethod(CallExternalTool)\r
722 VerboseLogger = staticmethod(VerboseLogger)\r
723 InfLogger = staticmethod(InfLogger)\r
724 ErrorLogger = staticmethod(ErrorLogger)\r
725 DebugLogger = staticmethod(DebugLogger)\r
726 MacroExtend = staticmethod (MacroExtend)\r
727 GetPcdValue = staticmethod(GetPcdValue)\r