]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Enhance BaseTools supports FixedAtBuild usage in VFR file
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
... / ...
CommitLineData
1## @file\r
2# Generate AutoGen.h, AutoGen.c and *.depex files\r
3#\r
4# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14## Import Modules\r
15#\r
16import Common.LongFilePathOs as os\r
17import re\r
18import os.path as path\r
19import copy\r
20import uuid\r
21\r
22import GenC\r
23import GenMake\r
24import GenDepex\r
25from StringIO import StringIO\r
26\r
27from StrGather import *\r
28from BuildEngine import BuildRule\r
29\r
30from Common.LongFilePathSupport import CopyLongFilePath\r
31from Common.BuildToolError import *\r
32from Common.DataType import *\r
33from Common.Misc import *\r
34from Common.String import *\r
35import Common.GlobalData as GlobalData\r
36from GenFds.FdfParser import *\r
37from CommonDataClass.CommonClass import SkuInfoClass\r
38from Workspace.BuildClassObject import *\r
39from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r
40import Common.VpdInfoFile as VpdInfoFile\r
41from GenPcdDb import CreatePcdDatabaseCode\r
42from Workspace.MetaFileCommentParser import UsageList\r
43from Common.MultipleWorkspace import MultipleWorkspace as mws\r
44import InfSectionParser\r
45\r
46## Regular expression for splitting Dependency Expression string into tokens\r
47gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
48\r
49#\r
50# Match name = variable\r
51#\r
52gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")\r
53#\r
54# The format of guid in efivarstore statement likes following and must be correct:\r
55# guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}\r
56#\r
57gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")\r
58\r
59## Mapping Makefile type\r
60gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}\r
61\r
62\r
63## Build rule configuration file\r
64gDefaultBuildRuleFile = 'Conf/build_rule.txt'\r
65\r
66## Build rule default version\r
67AutoGenReqBuildRuleVerNum = "0.1"\r
68\r
69## default file name for AutoGen\r
70gAutoGenCodeFileName = "AutoGen.c"\r
71gAutoGenHeaderFileName = "AutoGen.h"\r
72gAutoGenStringFileName = "%(module_name)sStrDefs.h"\r
73gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r
74gAutoGenDepexFileName = "%(module_name)s.depex"\r
75gAutoGenImageDefFileName = "%(module_name)sImgDefs.h"\r
76gAutoGenIdfFileName = "%(module_name)sIdf.hpk"\r
77gInfSpecVersion = "0x00010017"\r
78\r
79#\r
80# Template string to generic AsBuilt INF\r
81#\r
82gAsBuiltInfHeaderString = TemplateString("""${header_comments}\r
83\r
84# DO NOT EDIT\r
85# FILE auto-generated\r
86\r
87[Defines]\r
88 INF_VERSION = ${module_inf_version}\r
89 BASE_NAME = ${module_name}\r
90 FILE_GUID = ${module_guid}\r
91 MODULE_TYPE = ${module_module_type}${BEGIN}\r
92 VERSION_STRING = ${module_version_string}${END}${BEGIN}\r
93 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}\r
94 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}\r
95 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}\r
96 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}\r
97 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}\r
98 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}\r
99 DESTRUCTOR = ${module_destructor}${END}${BEGIN}\r
100 SHADOW = ${module_shadow}${END}${BEGIN}\r
101 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}\r
102 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}\r
103 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}\r
104 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}\r
105 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}\r
106 SPEC = ${module_spec}${END}${BEGIN}\r
107 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}\r
108 MODULE_UNI_FILE = ${module_uni_file}${END}\r
109\r
110[Packages.${module_arch}]${BEGIN}\r
111 ${package_item}${END}\r
112\r
113[Binaries.${module_arch}]${BEGIN}\r
114 ${binary_item}${END}\r
115\r
116[PatchPcd.${module_arch}]${BEGIN}\r
117 ${patchablepcd_item}\r
118${END}\r
119\r
120[Protocols.${module_arch}]${BEGIN}\r
121 ${protocol_item}\r
122${END}\r
123\r
124[Ppis.${module_arch}]${BEGIN}\r
125 ${ppi_item}\r
126${END}\r
127\r
128[Guids.${module_arch}]${BEGIN}\r
129 ${guid_item}\r
130${END}\r
131\r
132[PcdEx.${module_arch}]${BEGIN}\r
133 ${pcd_item}\r
134${END}\r
135\r
136[LibraryClasses.${module_arch}]\r
137## @LIB_INSTANCES${BEGIN}\r
138# ${libraryclasses_item}${END}\r
139\r
140${depexsection_item}\r
141\r
142${tail_comments}\r
143\r
144[BuildOptions.${module_arch}]\r
145## @AsBuilt${BEGIN}\r
146## ${flags_item}${END}\r
147""")\r
148\r
149## Base class for AutoGen\r
150#\r
151# This class just implements the cache mechanism of AutoGen objects.\r
152#\r
153class AutoGen(object):\r
154 # database to maintain the objects of xxxAutoGen\r
155 _CACHE_ = {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}\r
156\r
157 ## Factory method\r
158 #\r
159 # @param Class class object of real AutoGen class\r
160 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)\r
161 # @param Workspace Workspace directory or WorkspaceAutoGen object\r
162 # @param MetaFile The path of meta file\r
163 # @param Target Build target\r
164 # @param Toolchain Tool chain name\r
165 # @param Arch Target arch\r
166 # @param *args The specific class related parameters\r
167 # @param **kwargs The specific class related dict parameters\r
168 #\r
169 def __new__(Class, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
170 # check if the object has been created\r
171 Key = (Target, Toolchain)\r
172 if Key not in Class._CACHE_ or Arch not in Class._CACHE_[Key] \\r
173 or MetaFile not in Class._CACHE_[Key][Arch]:\r
174 AutoGenObject = super(AutoGen, Class).__new__(Class)\r
175 # call real constructor\r
176 if not AutoGenObject._Init(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
177 return None\r
178 if Key not in Class._CACHE_:\r
179 Class._CACHE_[Key] = {}\r
180 if Arch not in Class._CACHE_[Key]:\r
181 Class._CACHE_[Key][Arch] = {}\r
182 Class._CACHE_[Key][Arch][MetaFile] = AutoGenObject\r
183 else:\r
184 AutoGenObject = Class._CACHE_[Key][Arch][MetaFile]\r
185\r
186 return AutoGenObject\r
187\r
188 ## hash() operator\r
189 #\r
190 # The file path of platform file will be used to represent hash value of this object\r
191 #\r
192 # @retval int Hash value of the file path of platform file\r
193 #\r
194 def __hash__(self):\r
195 return hash(self.MetaFile)\r
196\r
197 ## str() operator\r
198 #\r
199 # The file path of platform file will be used to represent this object\r
200 #\r
201 # @retval string String of platform file path\r
202 #\r
203 def __str__(self):\r
204 return str(self.MetaFile)\r
205\r
206 ## "==" operator\r
207 def __eq__(self, Other):\r
208 return Other and self.MetaFile == Other\r
209\r
210## Workspace AutoGen class\r
211#\r
212# This class is used mainly to control the whole platform build for different\r
213# architecture. This class will generate top level makefile.\r
214#\r
215class WorkspaceAutoGen(AutoGen):\r
216 ## Real constructor of WorkspaceAutoGen\r
217 #\r
218 # This method behaves the same as __init__ except that it needs explicit invoke\r
219 # (in super class's __new__ method)\r
220 #\r
221 # @param WorkspaceDir Root directory of workspace\r
222 # @param ActivePlatform Meta-file of active platform\r
223 # @param Target Build target\r
224 # @param Toolchain Tool chain name\r
225 # @param ArchList List of architecture of current build\r
226 # @param MetaFileDb Database containing meta-files\r
227 # @param BuildConfig Configuration of build\r
228 # @param ToolDefinition Tool chain definitions\r
229 # @param FlashDefinitionFile File of flash definition\r
230 # @param Fds FD list to be generated\r
231 # @param Fvs FV list to be generated\r
232 # @param Caps Capsule list to be generated\r
233 # @param SkuId SKU id from command line\r
234 #\r
235 def _Init(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
236 BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,\r
237 Progress=None, BuildModule=None):\r
238 if Fds is None:\r
239 Fds = []\r
240 if Fvs is None:\r
241 Fvs = []\r
242 if Caps is None:\r
243 Caps = []\r
244 self.BuildDatabase = MetaFileDb\r
245 self.MetaFile = ActivePlatform\r
246 self.WorkspaceDir = WorkspaceDir\r
247 self.Platform = self.BuildDatabase[self.MetaFile, 'COMMON', Target, Toolchain]\r
248 GlobalData.gActivePlatform = self.Platform\r
249 self.BuildTarget = Target\r
250 self.ToolChain = Toolchain\r
251 self.ArchList = ArchList\r
252 self.SkuId = SkuId\r
253 self.UniFlag = UniFlag\r
254\r
255 self.TargetTxt = BuildConfig\r
256 self.ToolDef = ToolDefinition\r
257 self.FdfFile = FlashDefinitionFile\r
258 self.FdTargetList = Fds\r
259 self.FvTargetList = Fvs\r
260 self.CapTargetList = Caps\r
261 self.AutoGenObjectList = []\r
262\r
263 # there's many relative directory operations, so ...\r
264 os.chdir(self.WorkspaceDir)\r
265\r
266 #\r
267 # Merge Arch\r
268 #\r
269 if not self.ArchList:\r
270 ArchList = set(self.Platform.SupArchList)\r
271 else:\r
272 ArchList = set(self.ArchList) & set(self.Platform.SupArchList)\r
273 if not ArchList:\r
274 EdkLogger.error("build", PARAMETER_INVALID,\r
275 ExtraData = "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self.Platform.SupArchList)))\r
276 elif self.ArchList and len(ArchList) != len(self.ArchList):\r
277 SkippedArchList = set(self.ArchList).symmetric_difference(set(self.Platform.SupArchList))\r
278 EdkLogger.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"\r
279 % (" ".join(SkippedArchList), " ".join(self.Platform.SupArchList)))\r
280 self.ArchList = tuple(ArchList)\r
281\r
282 # Validate build target\r
283 if self.BuildTarget not in self.Platform.BuildTargets:\r
284 EdkLogger.error("build", PARAMETER_INVALID,\r
285 ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"\r
286 % (self.BuildTarget, " ".join(self.Platform.BuildTargets)))\r
287\r
288 \r
289 # parse FDF file to get PCDs in it, if any\r
290 if not self.FdfFile:\r
291 self.FdfFile = self.Platform.FlashDefinition\r
292\r
293 EdkLogger.info("")\r
294 if self.ArchList:\r
295 EdkLogger.info('%-16s = %s' % ("Architecture(s)", ' '.join(self.ArchList)))\r
296 EdkLogger.info('%-16s = %s' % ("Build target", self.BuildTarget))\r
297 EdkLogger.info('%-16s = %s' % ("Toolchain", self.ToolChain))\r
298\r
299 EdkLogger.info('\n%-24s = %s' % ("Active Platform", self.Platform))\r
300 if BuildModule:\r
301 EdkLogger.info('%-24s = %s' % ("Active Module", BuildModule))\r
302\r
303 if self.FdfFile:\r
304 EdkLogger.info('%-24s = %s' % ("Flash Image Definition", self.FdfFile))\r
305\r
306 EdkLogger.verbose("\nFLASH_DEFINITION = %s" % self.FdfFile)\r
307\r
308 if Progress:\r
309 Progress.Start("\nProcessing meta-data")\r
310\r
311 if self.FdfFile:\r
312 #\r
313 # Mark now build in AutoGen Phase\r
314 #\r
315 GlobalData.gAutoGenPhase = True\r
316 Fdf = FdfParser(self.FdfFile.Path)\r
317 Fdf.ParseFile()\r
318 GlobalData.gFdfParser = Fdf\r
319 GlobalData.gAutoGenPhase = False\r
320 PcdSet = Fdf.Profile.PcdDict\r
321 if Fdf.CurrentFdName and Fdf.CurrentFdName in Fdf.Profile.FdDict:\r
322 FdDict = Fdf.Profile.FdDict[Fdf.CurrentFdName]\r
323 for FdRegion in FdDict.RegionList:\r
324 if str(FdRegion.RegionType) is 'FILE' and self.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
325 if int(FdRegion.Offset) % 8 != 0:\r
326 EdkLogger.error("build", FORMAT_INVALID, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion.Offset))\r
327 ModuleList = Fdf.Profile.InfList\r
328 self.FdfProfile = Fdf.Profile\r
329 for fvname in self.FvTargetList:\r
330 if fvname.upper() not in self.FdfProfile.FvDict:\r
331 EdkLogger.error("build", OPTION_VALUE_INVALID,\r
332 "No such an FV in FDF file: %s" % fvname)\r
333\r
334 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,\r
335 # but the path (self.MetaFile.Path) is the real path\r
336 for key in self.FdfProfile.InfDict:\r
337 if key == 'ArchTBD':\r
338 Platform_cache = {}\r
339 MetaFile_cache = {}\r
340 for Arch in self.ArchList:\r
341 Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
342 MetaFile_cache[Arch] = []\r
343 for Pkey in Platform_cache[Arch].Modules.keys():\r
344 MetaFile_cache[Arch].append(Platform_cache[Arch].Modules[Pkey].MetaFile)\r
345 for Inf in self.FdfProfile.InfDict[key]:\r
346 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
347 for Arch in self.ArchList:\r
348 if ModuleFile in MetaFile_cache[Arch]:\r
349 break\r
350 else:\r
351 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
352 if not ModuleData.IsBinaryModule:\r
353 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
354\r
355 else:\r
356 for Arch in self.ArchList:\r
357 if Arch == key:\r
358 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
359 MetaFileList = []\r
360 for Pkey in Platform.Modules.keys():\r
361 MetaFileList.append(Platform.Modules[Pkey].MetaFile)\r
362 for Inf in self.FdfProfile.InfDict[key]:\r
363 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
364 if ModuleFile in MetaFileList:\r
365 continue\r
366 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
367 if not ModuleData.IsBinaryModule:\r
368 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
369\r
370 else:\r
371 PcdSet = {}\r
372 ModuleList = []\r
373 self.FdfProfile = None\r
374 if self.FdTargetList:\r
375 EdkLogger.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self.FdTargetList))\r
376 self.FdTargetList = []\r
377 if self.FvTargetList:\r
378 EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvTargetList))\r
379 self.FvTargetList = []\r
380 if self.CapTargetList:\r
381 EdkLogger.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self.CapTargetList))\r
382 self.CapTargetList = []\r
383\r
384 # apply SKU and inject PCDs from Flash Definition file\r
385 for Arch in self.ArchList:\r
386 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
387\r
388 DecPcds = {}\r
389 DecPcdsKey = set()\r
390 PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
391 if GlobalData.BuildOptionPcd:\r
392 for i, pcd in enumerate(GlobalData.BuildOptionPcd):\r
393 if type(pcd) is tuple:\r
394 continue\r
395 (pcdname, pcdvalue) = pcd.split('=')\r
396 if not pcdvalue:\r
397 EdkLogger.error('build', AUTOGEN_ERROR, "No Value specified for the PCD %s." % (pcdname))\r
398 if '.' in pcdname:\r
399 (TokenSpaceGuidCName, TokenCName) = pcdname.split('.')\r
400 HasTokenSpace = True\r
401 else:\r
402 TokenCName = pcdname\r
403 TokenSpaceGuidCName = ''\r
404 HasTokenSpace = False\r
405 TokenSpaceGuidCNameList = []\r
406 FoundFlag = False\r
407 PcdDatumType = ''\r
408 NewValue = ''\r
409 for package in PGen.PackageList:\r
410 for key in package.Pcds:\r
411 PcdItem = package.Pcds[key]\r
412 if HasTokenSpace:\r
413 if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):\r
414 PcdDatumType = PcdItem.DatumType\r
415 NewValue = self._BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
416 FoundFlag = True\r
417 else:\r
418 if PcdItem.TokenCName == TokenCName:\r
419 if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:\r
420 if len (TokenSpaceGuidCNameList) < 1:\r
421 TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)\r
422 PcdDatumType = PcdItem.DatumType\r
423 TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName\r
424 NewValue = self._BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
425 FoundFlag = True\r
426 else:\r
427 EdkLogger.error(\r
428 'build',\r
429 AUTOGEN_ERROR,\r
430 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])\r
431 )\r
432\r
433 GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)\r
434\r
435 if not FoundFlag:\r
436 if HasTokenSpace:\r
437 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, TokenCName))\r
438 else:\r
439 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (TokenCName))\r
440\r
441 for BuildData in PGen.BuildDatabase._CACHE_.values():\r
442 if BuildData.Arch != Arch:\r
443 continue\r
444 if BuildData.MetaFile.Ext == '.dec':\r
445 continue\r
446 for key in BuildData.Pcds:\r
447 PcdItem = BuildData.Pcds[key]\r
448 if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName):\r
449 PcdItem.DefaultValue = NewValue\r
450\r
451 if (TokenCName, TokenSpaceGuidCName) in PcdSet:\r
452 PcdSet[(TokenCName, TokenSpaceGuidCName)] = NewValue\r
453\r
454 SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}\r
455 BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]}\r
456 SourcePcdDict_Keys = SourcePcdDict.keys()\r
457 BinaryPcdDict_Keys = BinaryPcdDict.keys()\r
458\r
459 # generate the SourcePcdDict and BinaryPcdDict\r
460 for BuildData in PGen.BuildDatabase._CACHE_.values():\r
461 if BuildData.Arch != Arch:\r
462 continue\r
463 if BuildData.MetaFile.Ext == '.inf':\r
464 for key in BuildData.Pcds:\r
465 if BuildData.Pcds[key].Pending:\r
466 if key in Platform.Pcds:\r
467 PcdInPlatform = Platform.Pcds[key]\r
468 if PcdInPlatform.Type not in [None, '']:\r
469 BuildData.Pcds[key].Type = PcdInPlatform.Type\r
470\r
471 if BuildData.MetaFile in Platform.Modules:\r
472 PlatformModule = Platform.Modules[str(BuildData.MetaFile)]\r
473 if key in PlatformModule.Pcds:\r
474 PcdInPlatform = PlatformModule.Pcds[key]\r
475 if PcdInPlatform.Type not in [None, '']:\r
476 BuildData.Pcds[key].Type = PcdInPlatform.Type\r
477\r
478 if 'DynamicEx' in BuildData.Pcds[key].Type:\r
479 if BuildData.IsBinaryModule:\r
480 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['DynamicEx']:\r
481 BinaryPcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
482 else:\r
483 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['DynamicEx']:\r
484 SourcePcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
485\r
486 elif 'PatchableInModule' in BuildData.Pcds[key].Type:\r
487 if BuildData.MetaFile.Ext == '.inf':\r
488 if BuildData.IsBinaryModule:\r
489 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['PatchableInModule']:\r
490 BinaryPcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
491 else:\r
492 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['PatchableInModule']:\r
493 SourcePcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
494\r
495 elif 'Dynamic' in BuildData.Pcds[key].Type:\r
496 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['Dynamic']:\r
497 SourcePcdDict['Dynamic'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
498 elif 'FixedAtBuild' in BuildData.Pcds[key].Type:\r
499 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['FixedAtBuild']:\r
500 SourcePcdDict['FixedAtBuild'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
501 else:\r
502 pass\r
503\r
504 #\r
505 # intersection the BinaryPCD for Mixed PCD\r
506 #\r
507 for i in BinaryPcdDict_Keys:\r
508 for j in BinaryPcdDict_Keys:\r
509 if i != j:\r
510 IntersectionList = list(set(BinaryPcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
511 for item in IntersectionList:\r
512 NewPcd1 = (item[0] + '_' + i, item[1])\r
513 NewPcd2 = (item[0] + '_' + j, item[1])\r
514 if item not in GlobalData.MixedPcd:\r
515 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
516 else:\r
517 if NewPcd1 not in GlobalData.MixedPcd[item]:\r
518 GlobalData.MixedPcd[item].append(NewPcd1)\r
519 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
520 GlobalData.MixedPcd[item].append(NewPcd2)\r
521 else:\r
522 pass\r
523\r
524 #\r
525 # intersection the SourcePCD and BinaryPCD for Mixed PCD\r
526 #\r
527 for i in SourcePcdDict_Keys:\r
528 for j in BinaryPcdDict_Keys:\r
529 if i != j:\r
530 IntersectionList = list(set(SourcePcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
531 for item in IntersectionList:\r
532 NewPcd1 = (item[0] + '_' + i, item[1])\r
533 NewPcd2 = (item[0] + '_' + j, item[1])\r
534 if item not in GlobalData.MixedPcd:\r
535 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
536 else:\r
537 if NewPcd1 not in GlobalData.MixedPcd[item]:\r
538 GlobalData.MixedPcd[item].append(NewPcd1)\r
539 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
540 GlobalData.MixedPcd[item].append(NewPcd2)\r
541 else:\r
542 pass\r
543\r
544 for BuildData in PGen.BuildDatabase._CACHE_.values():\r
545 if BuildData.Arch != Arch:\r
546 continue\r
547 for key in BuildData.Pcds:\r
548 for SinglePcd in GlobalData.MixedPcd:\r
549 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
550 for item in GlobalData.MixedPcd[SinglePcd]:\r
551 Pcd_Type = item[0].split('_')[-1]\r
552 if (Pcd_Type == BuildData.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and BuildData.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
553 (Pcd_Type == TAB_PCDS_DYNAMIC and BuildData.Pcds[key].Type in GenC.gDynamicPcd):\r
554 Value = BuildData.Pcds[key]\r
555 Value.TokenCName = BuildData.Pcds[key].TokenCName + '_' + Pcd_Type\r
556 if len(key) == 2:\r
557 newkey = (Value.TokenCName, key[1])\r
558 elif len(key) == 3:\r
559 newkey = (Value.TokenCName, key[1], key[2])\r
560 del BuildData.Pcds[key]\r
561 BuildData.Pcds[newkey] = Value\r
562 break\r
563 else:\r
564 pass\r
565 break\r
566 else:\r
567 pass\r
568\r
569 # handle the mixed pcd in FDF file\r
570 for key in PcdSet:\r
571 if key in GlobalData.MixedPcd:\r
572 Value = PcdSet[key]\r
573 del PcdSet[key]\r
574 for item in GlobalData.MixedPcd[key]:\r
575 PcdSet[item] = Value\r
576\r
577 #Collect package set information from INF of FDF\r
578 PkgSet = set()\r
579 for Inf in ModuleList:\r
580 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
581 if ModuleFile in Platform.Modules:\r
582 continue\r
583 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
584 PkgSet.update(ModuleData.Packages)\r
585 Pkgs = list(PkgSet) + list(PGen.PackageList)\r
586 for Pkg in Pkgs:\r
587 for Pcd in Pkg.Pcds:\r
588 DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
589 DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
590\r
591 Platform.SkuName = self.SkuId\r
592 for Name, Guid in PcdSet:\r
593 if (Name, Guid) not in DecPcds:\r
594 EdkLogger.error(\r
595 'build',\r
596 PARSER_ERROR,\r
597 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid, Name),\r
598 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
599 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
600 )\r
601 else:\r
602 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.\r
603 if (Name, Guid, TAB_PCDS_FIXED_AT_BUILD) in DecPcdsKey \\r
604 or (Name, Guid, TAB_PCDS_PATCHABLE_IN_MODULE) in DecPcdsKey \\r
605 or (Name, Guid, TAB_PCDS_FEATURE_FLAG) in DecPcdsKey:\r
606 Platform.AddPcd(Name, Guid, PcdSet[Name, Guid])\r
607 continue\r
608 elif (Name, Guid, TAB_PCDS_DYNAMIC) in DecPcdsKey or (Name, Guid, TAB_PCDS_DYNAMIC_EX) in DecPcdsKey:\r
609 EdkLogger.error(\r
610 'build',\r
611 PARSER_ERROR,\r
612 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid, Name),\r
613 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
614 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
615 )\r
616\r
617 Pa = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
618 #\r
619 # Explicitly collect platform's dynamic PCDs\r
620 #\r
621 Pa.CollectPlatformDynamicPcds()\r
622 Pa.CollectFixedAtBuildPcds()\r
623 self.AutoGenObjectList.append(Pa)\r
624\r
625 #\r
626 # Check PCDs token value conflict in each DEC file.\r
627 #\r
628 self._CheckAllPcdsTokenValueConflict()\r
629\r
630 #\r
631 # Check PCD type and definition between DSC and DEC\r
632 #\r
633 self._CheckPcdDefineAndType()\r
634\r
635# if self.FdfFile:\r
636# self._CheckDuplicateInFV(Fdf)\r
637\r
638 self._BuildDir = None\r
639 self._FvDir = None\r
640 self._MakeFileDir = None\r
641 self._BuildCommand = None\r
642\r
643 return True\r
644\r
645 def _BuildOptionPcdValueFormat(self, TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):\r
646 if PcdDatumType == 'VOID*':\r
647 if Value.startswith('L'):\r
648 if not Value[1]:\r
649 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
650 Value = Value[0] + '"' + Value[1:] + '"'\r
651 elif Value.startswith('B'):\r
652 if not Value[1]:\r
653 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
654 Value = Value[1:]\r
655 else:\r
656 if not Value[0]:\r
657 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
658 Value = '"' + Value + '"'\r
659\r
660 IsValid, Cause = CheckPcdDatum(PcdDatumType, Value)\r
661 if not IsValid:\r
662 EdkLogger.error('build', FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))\r
663 if PcdDatumType == 'BOOLEAN':\r
664 Value = Value.upper()\r
665 if Value == 'TRUE' or Value == '1':\r
666 Value = '1'\r
667 elif Value == 'FALSE' or Value == '0':\r
668 Value = '0'\r
669 return Value\r
670\r
671 ## _CheckDuplicateInFV() method\r
672 #\r
673 # Check whether there is duplicate modules/files exist in FV section. \r
674 # The check base on the file GUID;\r
675 #\r
676 def _CheckDuplicateInFV(self, Fdf):\r
677 for Fv in Fdf.Profile.FvDict:\r
678 _GuidDict = {}\r
679 for FfsFile in Fdf.Profile.FvDict[Fv].FfsList:\r
680 if FfsFile.InfFileName and FfsFile.NameGuid == None:\r
681 #\r
682 # Get INF file GUID\r
683 #\r
684 InfFoundFlag = False\r
685 for Pa in self.AutoGenObjectList:\r
686 if InfFoundFlag:\r
687 break\r
688 for Module in Pa.ModuleAutoGenList:\r
689 if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName):\r
690 InfFoundFlag = True\r
691 if not Module.Guid.upper() in _GuidDict.keys():\r
692 _GuidDict[Module.Guid.upper()] = FfsFile\r
693 break\r
694 else:\r
695 EdkLogger.error("build",\r
696 FORMAT_INVALID,\r
697 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
698 FfsFile.CurrentLineContent,\r
699 _GuidDict[Module.Guid.upper()].CurrentLineNum,\r
700 _GuidDict[Module.Guid.upper()].CurrentLineContent,\r
701 Module.Guid.upper()),\r
702 ExtraData=self.FdfFile)\r
703 #\r
704 # Some INF files not have entity in DSC file. \r
705 #\r
706 if not InfFoundFlag:\r
707 if FfsFile.InfFileName.find('$') == -1:\r
708 InfPath = NormPath(FfsFile.InfFileName)\r
709 if not os.path.exists(InfPath):\r
710 EdkLogger.error('build', GENFDS_ERROR, "Non-existant Module %s !" % (FfsFile.InfFileName))\r
711\r
712 PathClassObj = PathClass(FfsFile.InfFileName, self.WorkspaceDir)\r
713 #\r
714 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use \r
715 # BuildObject from one of AutoGenObjectList is enough.\r
716 #\r
717 InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain]\r
718 if not InfObj.Guid.upper() in _GuidDict.keys():\r
719 _GuidDict[InfObj.Guid.upper()] = FfsFile\r
720 else:\r
721 EdkLogger.error("build",\r
722 FORMAT_INVALID,\r
723 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
724 FfsFile.CurrentLineContent,\r
725 _GuidDict[InfObj.Guid.upper()].CurrentLineNum,\r
726 _GuidDict[InfObj.Guid.upper()].CurrentLineContent,\r
727 InfObj.Guid.upper()),\r
728 ExtraData=self.FdfFile)\r
729 InfFoundFlag = False\r
730\r
731 if FfsFile.NameGuid != None:\r
732 _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$")\r
733\r
734 #\r
735 # If the NameGuid reference a PCD name. \r
736 # The style must match: PCD(xxxx.yyy)\r
737 #\r
738 if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid):\r
739 #\r
740 # Replace the PCD value.\r
741 #\r
742 _PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")")\r
743 PcdFoundFlag = False\r
744 for Pa in self.AutoGenObjectList:\r
745 if not PcdFoundFlag:\r
746 for PcdItem in Pa.AllPcdList:\r
747 if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName:\r
748 #\r
749 # First convert from CFormatGuid to GUID string\r
750 #\r
751 _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)\r
752\r
753 if not _PcdGuidString:\r
754 #\r
755 # Then try Byte array.\r
756 #\r
757 _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)\r
758\r
759 if not _PcdGuidString:\r
760 #\r
761 # Not Byte array or CFormat GUID, raise error.\r
762 #\r
763 EdkLogger.error("build",\r
764 FORMAT_INVALID,\r
765 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue),\r
766 ExtraData=self.FdfFile)\r
767\r
768 if not _PcdGuidString.upper() in _GuidDict.keys():\r
769 _GuidDict[_PcdGuidString.upper()] = FfsFile\r
770 PcdFoundFlag = True\r
771 break\r
772 else:\r
773 EdkLogger.error("build",\r
774 FORMAT_INVALID,\r
775 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
776 FfsFile.CurrentLineContent,\r
777 _GuidDict[_PcdGuidString.upper()].CurrentLineNum,\r
778 _GuidDict[_PcdGuidString.upper()].CurrentLineContent,\r
779 FfsFile.NameGuid.upper()),\r
780 ExtraData=self.FdfFile)\r
781\r
782 if not FfsFile.NameGuid.upper() in _GuidDict.keys():\r
783 _GuidDict[FfsFile.NameGuid.upper()] = FfsFile\r
784 else:\r
785 #\r
786 # Two raw file GUID conflict.\r
787 #\r
788 EdkLogger.error("build",\r
789 FORMAT_INVALID,\r
790 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
791 FfsFile.CurrentLineContent,\r
792 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineNum,\r
793 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineContent,\r
794 FfsFile.NameGuid.upper()),\r
795 ExtraData=self.FdfFile)\r
796\r
797\r
798 def _CheckPcdDefineAndType(self):\r
799 PcdTypeList = [\r
800 "FixedAtBuild", "PatchableInModule", "FeatureFlag",\r
801 "Dynamic", #"DynamicHii", "DynamicVpd",\r
802 "DynamicEx", # "DynamicExHii", "DynamicExVpd"\r
803 ]\r
804\r
805 # This dict store PCDs which are not used by any modules with specified arches\r
806 UnusedPcd = sdict()\r
807 for Pa in self.AutoGenObjectList:\r
808 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
809 for Pcd in Pa.Platform.Pcds:\r
810 PcdType = Pa.Platform.Pcds[Pcd].Type\r
811\r
812 # If no PCD type, this PCD comes from FDF \r
813 if not PcdType:\r
814 continue\r
815\r
816 # Try to remove Hii and Vpd suffix\r
817 if PcdType.startswith("DynamicEx"):\r
818 PcdType = "DynamicEx"\r
819 elif PcdType.startswith("Dynamic"):\r
820 PcdType = "Dynamic"\r
821\r
822 for Package in Pa.PackageList:\r
823 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType\r
824 if (Pcd[0], Pcd[1], PcdType) in Package.Pcds:\r
825 break\r
826 for Type in PcdTypeList:\r
827 if (Pcd[0], Pcd[1], Type) in Package.Pcds:\r
828 EdkLogger.error(\r
829 'build',\r
830 FORMAT_INVALID,\r
831 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \\r
832 % (Pa.Platform.Pcds[Pcd].Type, Pcd[1], Pcd[0], Type),\r
833 ExtraData=None\r
834 )\r
835 return\r
836 else:\r
837 UnusedPcd.setdefault(Pcd, []).append(Pa.Arch)\r
838\r
839 for Pcd in UnusedPcd:\r
840 EdkLogger.warn(\r
841 'build',\r
842 "The PCD was not specified by any INF module in the platform for the given architecture.\n"\r
843 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"\r
844 % (Pcd[1], Pcd[0], os.path.basename(str(self.MetaFile)), str(UnusedPcd[Pcd])),\r
845 ExtraData=None\r
846 )\r
847\r
848 def __repr__(self):\r
849 return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))\r
850\r
851 ## Return the directory to store FV files\r
852 def _GetFvDir(self):\r
853 if self._FvDir == None:\r
854 self._FvDir = path.join(self.BuildDir, 'FV')\r
855 return self._FvDir\r
856\r
857 ## Return the directory to store all intermediate and final files built\r
858 def _GetBuildDir(self):\r
859 return self.AutoGenObjectList[0].BuildDir\r
860\r
861 ## Return the build output directory platform specifies\r
862 def _GetOutputDir(self):\r
863 return self.Platform.OutputDirectory\r
864\r
865 ## Return platform name\r
866 def _GetName(self):\r
867 return self.Platform.PlatformName\r
868\r
869 ## Return meta-file GUID\r
870 def _GetGuid(self):\r
871 return self.Platform.Guid\r
872\r
873 ## Return platform version\r
874 def _GetVersion(self):\r
875 return self.Platform.Version\r
876\r
877 ## Return paths of tools\r
878 def _GetToolDefinition(self):\r
879 return self.AutoGenObjectList[0].ToolDefinition\r
880\r
881 ## Return directory of platform makefile\r
882 #\r
883 # @retval string Makefile directory\r
884 #\r
885 def _GetMakeFileDir(self):\r
886 if self._MakeFileDir == None:\r
887 self._MakeFileDir = self.BuildDir\r
888 return self._MakeFileDir\r
889\r
890 ## Return build command string\r
891 #\r
892 # @retval string Build command string\r
893 #\r
894 def _GetBuildCommand(self):\r
895 if self._BuildCommand == None:\r
896 # BuildCommand should be all the same. So just get one from platform AutoGen\r
897 self._BuildCommand = self.AutoGenObjectList[0].BuildCommand\r
898 return self._BuildCommand\r
899\r
900 ## Check the PCDs token value conflict in each DEC file.\r
901 #\r
902 # Will cause build break and raise error message while two PCDs conflict.\r
903 # \r
904 # @return None\r
905 #\r
906 def _CheckAllPcdsTokenValueConflict(self):\r
907 for Pa in self.AutoGenObjectList:\r
908 for Package in Pa.PackageList:\r
909 PcdList = Package.Pcds.values()\r
910 PcdList.sort(lambda x, y: cmp(int(x.TokenValue, 0), int(y.TokenValue, 0))) \r
911 Count = 0\r
912 while (Count < len(PcdList) - 1) :\r
913 Item = PcdList[Count]\r
914 ItemNext = PcdList[Count + 1]\r
915 #\r
916 # Make sure in the same token space the TokenValue should be unique\r
917 #\r
918 if (int(Item.TokenValue, 0) == int(ItemNext.TokenValue, 0)):\r
919 SameTokenValuePcdList = []\r
920 SameTokenValuePcdList.append(Item)\r
921 SameTokenValuePcdList.append(ItemNext)\r
922 RemainPcdListLength = len(PcdList) - Count - 2\r
923 for ValueSameCount in range(RemainPcdListLength):\r
924 if int(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount].TokenValue, 0) == int(Item.TokenValue, 0):\r
925 SameTokenValuePcdList.append(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount])\r
926 else:\r
927 break;\r
928 #\r
929 # Sort same token value PCD list with TokenGuid and TokenCName\r
930 #\r
931 SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
932 SameTokenValuePcdListCount = 0\r
933 while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):\r
934 Flag = False\r
935 TemListItem = SameTokenValuePcdList[SameTokenValuePcdListCount]\r
936 TemListItemNext = SameTokenValuePcdList[SameTokenValuePcdListCount + 1]\r
937\r
938 if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):\r
939 for PcdItem in GlobalData.MixedPcd:\r
940 if (TemListItem.TokenCName, TemListItem.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem] or \\r
941 (TemListItemNext.TokenCName, TemListItemNext.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
942 Flag = True\r
943 if not Flag:\r
944 EdkLogger.error(\r
945 'build',\r
946 FORMAT_INVALID,\r
947 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\\r
948 % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),\r
949 ExtraData=None\r
950 )\r
951 SameTokenValuePcdListCount += 1\r
952 Count += SameTokenValuePcdListCount\r
953 Count += 1\r
954\r
955 PcdList = Package.Pcds.values()\r
956 PcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
957 Count = 0\r
958 while (Count < len(PcdList) - 1) :\r
959 Item = PcdList[Count]\r
960 ItemNext = PcdList[Count + 1]\r
961 #\r
962 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.\r
963 #\r
964 if (Item.TokenSpaceGuidCName == ItemNext.TokenSpaceGuidCName) and (Item.TokenCName == ItemNext.TokenCName) and (int(Item.TokenValue, 0) != int(ItemNext.TokenValue, 0)):\r
965 EdkLogger.error(\r
966 'build',\r
967 FORMAT_INVALID,\r
968 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\\r
969 % (Item.TokenValue, Item.TokenSpaceGuidCName, Item.TokenCName, Package),\r
970 ExtraData=None\r
971 )\r
972 Count += 1\r
973 ## Generate fds command\r
974 def _GenFdsCommand(self):\r
975 return (GenMake.TopLevelMakefile(self)._TEMPLATE_.Replace(GenMake.TopLevelMakefile(self)._TemplateDict)).strip()\r
976\r
977 ## Create makefile for the platform and modules in it\r
978 #\r
979 # @param CreateDepsMakeFile Flag indicating if the makefile for\r
980 # modules will be created as well\r
981 #\r
982 def CreateMakeFile(self, CreateDepsMakeFile=False):\r
983 if CreateDepsMakeFile:\r
984 for Pa in self.AutoGenObjectList:\r
985 Pa.CreateMakeFile(CreateDepsMakeFile)\r
986\r
987 ## Create autogen code for platform and modules\r
988 #\r
989 # Since there's no autogen code for platform, this method will do nothing\r
990 # if CreateModuleCodeFile is set to False.\r
991 #\r
992 # @param CreateDepsCodeFile Flag indicating if creating module's\r
993 # autogen code file or not\r
994 #\r
995 def CreateCodeFile(self, CreateDepsCodeFile=False):\r
996 if not CreateDepsCodeFile:\r
997 return\r
998 for Pa in self.AutoGenObjectList:\r
999 Pa.CreateCodeFile(CreateDepsCodeFile)\r
1000\r
1001 ## Create AsBuilt INF file the platform\r
1002 #\r
1003 def CreateAsBuiltInf(self):\r
1004 return\r
1005\r
1006 Name = property(_GetName)\r
1007 Guid = property(_GetGuid)\r
1008 Version = property(_GetVersion)\r
1009 OutputDir = property(_GetOutputDir)\r
1010\r
1011 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
1012\r
1013 BuildDir = property(_GetBuildDir)\r
1014 FvDir = property(_GetFvDir)\r
1015 MakeFileDir = property(_GetMakeFileDir)\r
1016 BuildCommand = property(_GetBuildCommand)\r
1017 GenFdsCommand = property(_GenFdsCommand)\r
1018\r
1019## AutoGen class for platform\r
1020#\r
1021# PlatformAutoGen class will process the original information in platform\r
1022# file in order to generate makefile for platform.\r
1023#\r
1024class PlatformAutoGen(AutoGen):\r
1025 #\r
1026 # Used to store all PCDs for both PEI and DXE phase, in order to generate \r
1027 # correct PCD database\r
1028 # \r
1029 _DynaPcdList_ = []\r
1030 _NonDynaPcdList_ = []\r
1031 _PlatformPcds = {}\r
1032 \r
1033 #\r
1034 # The priority list while override build option \r
1035 #\r
1036 PrioList = {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)\r
1037 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
1038 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
1039 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE \r
1040 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
1041 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
1042 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
1043 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE\r
1044 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
1045 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
1046 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE\r
1047 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE\r
1048 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE\r
1049 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE\r
1050 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE\r
1051 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)\r
1052\r
1053 ## The real constructor of PlatformAutoGen\r
1054 #\r
1055 # This method is not supposed to be called by users of PlatformAutoGen. It's\r
1056 # only used by factory method __new__() to do real initialization work for an\r
1057 # object of PlatformAutoGen\r
1058 #\r
1059 # @param Workspace WorkspaceAutoGen object\r
1060 # @param PlatformFile Platform file (DSC file)\r
1061 # @param Target Build target (DEBUG, RELEASE)\r
1062 # @param Toolchain Name of tool chain\r
1063 # @param Arch arch of the platform supports\r
1064 #\r
1065 def _Init(self, Workspace, PlatformFile, Target, Toolchain, Arch):\r
1066 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))\r
1067 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)\r
1068\r
1069 self.MetaFile = PlatformFile\r
1070 self.Workspace = Workspace\r
1071 self.WorkspaceDir = Workspace.WorkspaceDir\r
1072 self.ToolChain = Toolchain\r
1073 self.BuildTarget = Target\r
1074 self.Arch = Arch\r
1075 self.SourceDir = PlatformFile.SubDir\r
1076 self.SourceOverrideDir = None\r
1077 self.FdTargetList = self.Workspace.FdTargetList\r
1078 self.FvTargetList = self.Workspace.FvTargetList\r
1079 self.AllPcdList = []\r
1080 # get the original module/package/platform objects\r
1081 self.BuildDatabase = Workspace.BuildDatabase\r
1082\r
1083 # flag indicating if the makefile/C-code file has been created or not\r
1084 self.IsMakeFileCreated = False\r
1085 self.IsCodeFileCreated = False\r
1086\r
1087 self._Platform = None\r
1088 self._Name = None\r
1089 self._Guid = None\r
1090 self._Version = None\r
1091\r
1092 self._BuildRule = None\r
1093 self._SourceDir = None\r
1094 self._BuildDir = None\r
1095 self._OutputDir = None\r
1096 self._FvDir = None\r
1097 self._MakeFileDir = None\r
1098 self._FdfFile = None\r
1099\r
1100 self._PcdTokenNumber = None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
1101 self._DynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
1102 self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
1103 self._NonDynamicPcdDict = {}\r
1104\r
1105 self._ToolDefinitions = None\r
1106 self._ToolDefFile = None # toolcode : tool path\r
1107 self._ToolChainFamily = None\r
1108 self._BuildRuleFamily = None\r
1109 self._BuildOption = None # toolcode : option\r
1110 self._EdkBuildOption = None # edktoolcode : option\r
1111 self._EdkIIBuildOption = None # edkiitoolcode : option\r
1112 self._PackageList = None\r
1113 self._ModuleAutoGenList = None\r
1114 self._LibraryAutoGenList = None\r
1115 self._BuildCommand = None\r
1116 self._AsBuildInfList = []\r
1117 self._AsBuildModuleList = []\r
1118 if GlobalData.gFdfParser != None:\r
1119 self._AsBuildInfList = GlobalData.gFdfParser.Profile.InfList\r
1120 for Inf in self._AsBuildInfList:\r
1121 InfClass = PathClass(NormPath(Inf), GlobalData.gWorkspace, self.Arch)\r
1122 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
1123 if not M.IsSupportedArch:\r
1124 continue\r
1125 self._AsBuildModuleList.append(InfClass)\r
1126 # get library/modules for build\r
1127 self.LibraryBuildDirectoryList = []\r
1128 self.ModuleBuildDirectoryList = []\r
1129 return True\r
1130\r
1131 def __repr__(self):\r
1132 return "%s [%s]" % (self.MetaFile, self.Arch)\r
1133\r
1134 ## Create autogen code for platform and modules\r
1135 #\r
1136 # Since there's no autogen code for platform, this method will do nothing\r
1137 # if CreateModuleCodeFile is set to False.\r
1138 #\r
1139 # @param CreateModuleCodeFile Flag indicating if creating module's\r
1140 # autogen code file or not\r
1141 #\r
1142 def CreateCodeFile(self, CreateModuleCodeFile=False):\r
1143 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False\r
1144 if self.IsCodeFileCreated or not CreateModuleCodeFile:\r
1145 return\r
1146\r
1147 for Ma in self.ModuleAutoGenList:\r
1148 Ma.CreateCodeFile(True)\r
1149\r
1150 # don't do this twice\r
1151 self.IsCodeFileCreated = True\r
1152\r
1153 ## Generate Fds Command\r
1154 def _GenFdsCommand(self):\r
1155 return self.Workspace.GenFdsCommand\r
1156\r
1157 ## Create makefile for the platform and mdoules in it\r
1158 #\r
1159 # @param CreateModuleMakeFile Flag indicating if the makefile for\r
1160 # modules will be created as well\r
1161 #\r
1162 def CreateMakeFile(self, CreateModuleMakeFile=False):\r
1163 if CreateModuleMakeFile:\r
1164 for ModuleFile in self.Platform.Modules:\r
1165 Ma = ModuleAutoGen(self.Workspace, ModuleFile, self.BuildTarget,\r
1166 self.ToolChain, self.Arch, self.MetaFile)\r
1167 Ma.CreateMakeFile(True)\r
1168 #Ma.CreateAsBuiltInf()\r
1169\r
1170 # no need to create makefile for the platform more than once\r
1171 if self.IsMakeFileCreated:\r
1172 return\r
1173\r
1174 # create library/module build dirs for platform\r
1175 Makefile = GenMake.PlatformMakefile(self)\r
1176 self.LibraryBuildDirectoryList = Makefile.GetLibraryBuildDirectoryList()\r
1177 self.ModuleBuildDirectoryList = Makefile.GetModuleBuildDirectoryList()\r
1178\r
1179 self.IsMakeFileCreated = True\r
1180\r
1181 ## Deal with Shared FixedAtBuild Pcds\r
1182 #\r
1183 def CollectFixedAtBuildPcds(self):\r
1184 for LibAuto in self.LibraryAutoGenList:\r
1185 FixedAtBuildPcds = {} \r
1186 ShareFixedAtBuildPcdsSameValue = {} \r
1187 for Module in LibAuto._ReferenceModules: \r
1188 for Pcd in Module.FixedAtBuildPcds + LibAuto.FixedAtBuildPcds:\r
1189 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName)) \r
1190 if key not in FixedAtBuildPcds:\r
1191 ShareFixedAtBuildPcdsSameValue[key] = True\r
1192 FixedAtBuildPcds[key] = Pcd.DefaultValue\r
1193 else:\r
1194 if FixedAtBuildPcds[key] != Pcd.DefaultValue:\r
1195 ShareFixedAtBuildPcdsSameValue[key] = False \r
1196 for Pcd in LibAuto.FixedAtBuildPcds:\r
1197 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
1198 if (Pcd.TokenCName,Pcd.TokenSpaceGuidCName) not in self.NonDynamicPcdDict:\r
1199 continue\r
1200 else:\r
1201 DscPcd = self.NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)]\r
1202 if DscPcd.Type != "FixedAtBuild":\r
1203 continue\r
1204 if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]: \r
1205 LibAuto.ConstPcd[key] = Pcd.DefaultValue\r
1206\r
1207 ## Collect dynamic PCDs\r
1208 #\r
1209 # Gather dynamic PCDs list from each module and their settings from platform\r
1210 # This interface should be invoked explicitly when platform action is created.\r
1211 #\r
1212 def CollectPlatformDynamicPcds(self):\r
1213 # Override the platform Pcd's value by build option\r
1214 if GlobalData.BuildOptionPcd:\r
1215 for key in self.Platform.Pcds:\r
1216 PlatformPcd = self.Platform.Pcds[key]\r
1217 for PcdItem in GlobalData.BuildOptionPcd:\r
1218 if (PlatformPcd.TokenSpaceGuidCName, PlatformPcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
1219 PlatformPcd.DefaultValue = PcdItem[2]\r
1220 if PlatformPcd.SkuInfoList:\r
1221 Sku = PlatformPcd.SkuInfoList[PlatformPcd.SkuInfoList.keys()[0]]\r
1222 Sku.DefaultValue = PcdItem[2]\r
1223 break\r
1224\r
1225 for key in self.Platform.Pcds:\r
1226 for SinglePcd in GlobalData.MixedPcd:\r
1227 if (self.Platform.Pcds[key].TokenCName, self.Platform.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
1228 for item in GlobalData.MixedPcd[SinglePcd]:\r
1229 Pcd_Type = item[0].split('_')[-1]\r
1230 if (Pcd_Type == self.Platform.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and self.Platform.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
1231 (Pcd_Type == TAB_PCDS_DYNAMIC and self.Platform.Pcds[key].Type in GenC.gDynamicPcd):\r
1232 Value = self.Platform.Pcds[key]\r
1233 Value.TokenCName = self.Platform.Pcds[key].TokenCName + '_' + Pcd_Type\r
1234 if len(key) == 2:\r
1235 newkey = (Value.TokenCName, key[1])\r
1236 elif len(key) == 3:\r
1237 newkey = (Value.TokenCName, key[1], key[2])\r
1238 del self.Platform.Pcds[key]\r
1239 self.Platform.Pcds[newkey] = Value\r
1240 break\r
1241 else:\r
1242 pass\r
1243 break\r
1244 else:\r
1245 pass\r
1246\r
1247 # for gathering error information\r
1248 NoDatumTypePcdList = set()\r
1249 PcdNotInDb = []\r
1250 self._GuidValue = {}\r
1251 FdfModuleList = []\r
1252 for InfName in self._AsBuildInfList:\r
1253 InfName = mws.join(self.WorkspaceDir, InfName)\r
1254 FdfModuleList.append(os.path.normpath(InfName))\r
1255 for F in self.Platform.Modules.keys():\r
1256 M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)\r
1257 #GuidValue.update(M.Guids)\r
1258 \r
1259 self.Platform.Modules[F].M = M\r
1260\r
1261 for PcdFromModule in M.ModulePcdList + M.LibraryPcdList:\r
1262 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
1263 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
1264 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))\r
1265\r
1266 # Check the PCD from Binary INF or Source INF\r
1267 if M.IsBinaryModule == True:\r
1268 PcdFromModule.IsFromBinaryInf = True\r
1269\r
1270 # Check the PCD from DSC or not \r
1271 if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys():\r
1272 PcdFromModule.IsFromDsc = True\r
1273 else:\r
1274 PcdFromModule.IsFromDsc = False\r
1275 if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:\r
1276 if F.Path not in FdfModuleList:\r
1277 # If one of the Source built modules listed in the DSC is not listed \r
1278 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic \r
1279 # access method (it is only listed in the DEC file that declares the \r
1280 # PCD as PcdsDynamic), then build tool will report warning message\r
1281 # notify the PI that they are attempting to build a module that must \r
1282 # be included in a flash image in order to be functional. These Dynamic \r
1283 # PCD will not be added into the Database unless it is used by other \r
1284 # modules that are included in the FDF file.\r
1285 if PcdFromModule.Type in GenC.gDynamicPcd and \\r
1286 PcdFromModule.IsFromBinaryInf == False:\r
1287 # Print warning message to let the developer make a determine.\r
1288 if PcdFromModule not in PcdNotInDb:\r
1289 PcdNotInDb.append(PcdFromModule)\r
1290 continue\r
1291 # If one of the Source built modules listed in the DSC is not listed in \r
1292 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx \r
1293 # access method (it is only listed in the DEC file that declares the \r
1294 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the \r
1295 # PCD to the Platform's PCD Database.\r
1296 if PcdFromModule.Type in GenC.gDynamicExPcd:\r
1297 if PcdFromModule not in PcdNotInDb:\r
1298 PcdNotInDb.append(PcdFromModule)\r
1299 continue\r
1300 #\r
1301 # If a dynamic PCD used by a PEM module/PEI module & DXE module,\r
1302 # it should be stored in Pcd PEI database, If a dynamic only\r
1303 # used by DXE module, it should be stored in DXE PCD database.\r
1304 # The default Phase is DXE\r
1305 #\r
1306 if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
1307 PcdFromModule.Phase = "PEI"\r
1308 if PcdFromModule not in self._DynaPcdList_:\r
1309 self._DynaPcdList_.append(PcdFromModule)\r
1310 elif PcdFromModule.Phase == 'PEI':\r
1311 # overwrite any the same PCD existing, if Phase is PEI\r
1312 Index = self._DynaPcdList_.index(PcdFromModule)\r
1313 self._DynaPcdList_[Index] = PcdFromModule\r
1314 elif PcdFromModule not in self._NonDynaPcdList_:\r
1315 self._NonDynaPcdList_.append(PcdFromModule)\r
1316 elif PcdFromModule in self._NonDynaPcdList_ and PcdFromModule.IsFromBinaryInf == True:\r
1317 Index = self._NonDynaPcdList_.index(PcdFromModule)\r
1318 if self._NonDynaPcdList_[Index].IsFromBinaryInf == False:\r
1319 #The PCD from Binary INF will override the same one from source INF\r
1320 self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])\r
1321 PcdFromModule.Pending = False\r
1322 self._NonDynaPcdList_.append (PcdFromModule)\r
1323 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.\r
1324 DscModuleList = []\r
1325 for ModuleInf in self.Platform.Modules.keys():\r
1326 DscModuleList.append (os.path.normpath(ModuleInf.Path))\r
1327 # add the PCD from modules that listed in FDF but not in DSC to Database \r
1328 for InfName in FdfModuleList:\r
1329 if InfName not in DscModuleList:\r
1330 InfClass = PathClass(InfName)\r
1331 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
1332 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source) \r
1333 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here. \r
1334 # For binary module, if in current arch, we need to list the PCDs into database. \r
1335 if not M.IsSupportedArch:\r
1336 continue\r
1337 # Override the module PCD setting by platform setting\r
1338 ModulePcdList = self.ApplyPcdSetting(M, M.Pcds)\r
1339 for PcdFromModule in ModulePcdList:\r
1340 PcdFromModule.IsFromBinaryInf = True\r
1341 PcdFromModule.IsFromDsc = False\r
1342 # Only allow the DynamicEx and Patchable PCD in AsBuild INF\r
1343 if PcdFromModule.Type not in GenC.gDynamicExPcd and PcdFromModule.Type not in TAB_PCDS_PATCHABLE_IN_MODULE:\r
1344 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
1345 File=self.MetaFile,\r
1346 ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n"\r
1347 % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName))\r
1348 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
1349 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
1350 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))\r
1351 if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
1352 PcdFromModule.Phase = "PEI"\r
1353 if PcdFromModule not in self._DynaPcdList_ and PcdFromModule.Type in GenC.gDynamicExPcd:\r
1354 self._DynaPcdList_.append(PcdFromModule)\r
1355 elif PcdFromModule not in self._NonDynaPcdList_ and PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE:\r
1356 self._NonDynaPcdList_.append(PcdFromModule)\r
1357 if PcdFromModule in self._DynaPcdList_ and PcdFromModule.Phase == 'PEI' and PcdFromModule.Type in GenC.gDynamicExPcd:\r
1358 # Overwrite the phase of any the same PCD existing, if Phase is PEI.\r
1359 # It is to solve the case that a dynamic PCD used by a PEM module/PEI \r
1360 # module & DXE module at a same time.\r
1361 # Overwrite the type of the PCDs in source INF by the type of AsBuild\r
1362 # INF file as DynamicEx. \r
1363 Index = self._DynaPcdList_.index(PcdFromModule)\r
1364 self._DynaPcdList_[Index].Phase = PcdFromModule.Phase\r
1365 self._DynaPcdList_[Index].Type = PcdFromModule.Type\r
1366 for PcdFromModule in self._NonDynaPcdList_:\r
1367 # If a PCD is not listed in the DSC file, but binary INF files used by \r
1368 # this platform all (that use this PCD) list the PCD in a [PatchPcds] \r
1369 # section, AND all source INF files used by this platform the build \r
1370 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds] \r
1371 # section, then the tools must NOT add the PCD to the Platform's PCD\r
1372 # Database; the build must assign the access method for this PCD as \r
1373 # PcdsPatchableInModule.\r
1374 if PcdFromModule not in self._DynaPcdList_:\r
1375 continue\r
1376 Index = self._DynaPcdList_.index(PcdFromModule)\r
1377 if PcdFromModule.IsFromDsc == False and \\r
1378 PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE and \\r
1379 PcdFromModule.IsFromBinaryInf == True and \\r
1380 self._DynaPcdList_[Index].IsFromBinaryInf == False:\r
1381 Index = self._DynaPcdList_.index(PcdFromModule)\r
1382 self._DynaPcdList_.remove (self._DynaPcdList_[Index])\r
1383\r
1384 # print out error information and break the build, if error found\r
1385 if len(NoDatumTypePcdList) > 0:\r
1386 NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)\r
1387 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
1388 File=self.MetaFile,\r
1389 ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"\r
1390 % NoDatumTypePcdListString)\r
1391 self._NonDynamicPcdList = self._NonDynaPcdList_\r
1392 self._DynamicPcdList = self._DynaPcdList_\r
1393 #\r
1394 # Sort dynamic PCD list to:\r
1395 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should \r
1396 # try to be put header of dynamicd List\r
1397 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD\r
1398 #\r
1399 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.\r
1400 #\r
1401 UnicodePcdArray = []\r
1402 HiiPcdArray = []\r
1403 OtherPcdArray = []\r
1404 VpdPcdDict = {}\r
1405 VpdFile = VpdInfoFile.VpdInfoFile()\r
1406 NeedProcessVpdMapFile = False\r
1407\r
1408 for pcd in self.Platform.Pcds.keys():\r
1409 if pcd not in self._PlatformPcds.keys():\r
1410 self._PlatformPcds[pcd] = self.Platform.Pcds[pcd]\r
1411\r
1412 if (self.Workspace.ArchList[-1] == self.Arch): \r
1413 for Pcd in self._DynamicPcdList:\r
1414 # just pick the a value to determine whether is unicode string type\r
1415 Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]\r
1416 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1417\r
1418 PcdValue = Sku.DefaultValue\r
1419 if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
1420 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
1421 UnicodePcdArray.append(Pcd)\r
1422 elif len(Sku.VariableName) > 0:\r
1423 # if found HII type PCD then insert to right of UnicodeIndex\r
1424 HiiPcdArray.append(Pcd)\r
1425 else:\r
1426 OtherPcdArray.append(Pcd)\r
1427 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
1428 VpdPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)] = Pcd\r
1429\r
1430 PlatformPcds = self._PlatformPcds.keys()\r
1431 PlatformPcds.sort()\r
1432 #\r
1433 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.\r
1434 #\r
1435 for PcdKey in PlatformPcds:\r
1436 Pcd = self._PlatformPcds[PcdKey]\r
1437 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD] and \\r
1438 PcdKey in VpdPcdDict:\r
1439 Pcd = VpdPcdDict[PcdKey]\r
1440 for (SkuName,Sku) in Pcd.SkuInfoList.items():\r
1441 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1442 PcdValue = Sku.DefaultValue\r
1443 if PcdValue == "":\r
1444 PcdValue = Pcd.DefaultValue\r
1445 if Sku.VpdOffset != '*':\r
1446 if PcdValue.startswith("{"):\r
1447 Alignment = 8\r
1448 elif PcdValue.startswith("L"):\r
1449 Alignment = 2\r
1450 else:\r
1451 Alignment = 1\r
1452 try:\r
1453 VpdOffset = int(Sku.VpdOffset)\r
1454 except:\r
1455 try:\r
1456 VpdOffset = int(Sku.VpdOffset, 16)\r
1457 except:\r
1458 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
1459 if VpdOffset % Alignment != 0:\r
1460 if PcdValue.startswith("{"):\r
1461 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName), File=self.MetaFile)\r
1462 else:\r
1463 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Alignment))\r
1464 VpdFile.Add(Pcd, Sku.VpdOffset)\r
1465 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
1466 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
1467 NeedProcessVpdMapFile = True\r
1468 if self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == '':\r
1469 EdkLogger.error("Build", FILE_NOT_FOUND, \\r
1470 "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")\r
1471\r
1472\r
1473 #\r
1474 # Fix the PCDs define in VPD PCD section that never referenced by module.\r
1475 # An example is PCD for signature usage.\r
1476 # \r
1477 for DscPcd in PlatformPcds:\r
1478 DscPcdEntry = self._PlatformPcds[DscPcd]\r
1479 if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
1480 if not (self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == ''):\r
1481 FoundFlag = False\r
1482 for VpdPcd in VpdFile._VpdArray.keys():\r
1483 # This PCD has been referenced by module\r
1484 if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
1485 (VpdPcd.TokenCName == DscPcdEntry.TokenCName):\r
1486 FoundFlag = True\r
1487\r
1488 # Not found, it should be signature\r
1489 if not FoundFlag :\r
1490 # just pick the a value to determine whether is unicode string type\r
1491 for (SkuName,Sku) in DscPcdEntry.SkuInfoList.items():\r
1492 Sku.VpdOffset = Sku.VpdOffset.strip() \r
1493 \r
1494 # Need to iterate DEC pcd information to get the value & datumtype\r
1495 for eachDec in self.PackageList:\r
1496 for DecPcd in eachDec.Pcds:\r
1497 DecPcdEntry = eachDec.Pcds[DecPcd]\r
1498 if (DecPcdEntry.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
1499 (DecPcdEntry.TokenCName == DscPcdEntry.TokenCName):\r
1500 # Print warning message to let the developer make a determine.\r
1501 EdkLogger.warn("build", "Unreferenced vpd pcd used!",\r
1502 File=self.MetaFile, \\r
1503 ExtraData = "PCD: %s.%s used in the DSC file %s is unreferenced." \\r
1504 %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, self.Platform.MetaFile.Path)) \r
1505 \r
1506 DscPcdEntry.DatumType = DecPcdEntry.DatumType\r
1507 DscPcdEntry.DefaultValue = DecPcdEntry.DefaultValue\r
1508 DscPcdEntry.TokenValue = DecPcdEntry.TokenValue\r
1509 DscPcdEntry.TokenSpaceGuidValue = eachDec.Guids[DecPcdEntry.TokenSpaceGuidCName]\r
1510 # Only fix the value while no value provided in DSC file.\r
1511 if (Sku.DefaultValue == "" or Sku.DefaultValue==None):\r
1512 DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue\r
1513 \r
1514 if DscPcdEntry not in self._DynamicPcdList:\r
1515 self._DynamicPcdList.append(DscPcdEntry)\r
1516# Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]\r
1517 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1518 PcdValue = Sku.DefaultValue\r
1519 if PcdValue == "":\r
1520 PcdValue = DscPcdEntry.DefaultValue\r
1521 if Sku.VpdOffset != '*':\r
1522 if PcdValue.startswith("{"):\r
1523 Alignment = 8\r
1524 elif PcdValue.startswith("L"):\r
1525 Alignment = 2\r
1526 else:\r
1527 Alignment = 1\r
1528 try:\r
1529 VpdOffset = int(Sku.VpdOffset)\r
1530 except:\r
1531 try:\r
1532 VpdOffset = int(Sku.VpdOffset, 16)\r
1533 except:\r
1534 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName))\r
1535 if VpdOffset % Alignment != 0:\r
1536 if PcdValue.startswith("{"):\r
1537 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName), File=self.MetaFile)\r
1538 else:\r
1539 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, Alignment))\r
1540 VpdFile.Add(DscPcdEntry, Sku.VpdOffset)\r
1541 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
1542 NeedProcessVpdMapFile = True \r
1543 if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
1544 UnicodePcdArray.append(DscPcdEntry)\r
1545 elif len(Sku.VariableName) > 0:\r
1546 HiiPcdArray.append(DscPcdEntry)\r
1547 else:\r
1548 OtherPcdArray.append(DscPcdEntry)\r
1549 \r
1550 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
1551 \r
1552 \r
1553 \r
1554 if (self.Platform.FlashDefinition == None or self.Platform.FlashDefinition == '') and \\r
1555 VpdFile.GetCount() != 0:\r
1556 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, \r
1557 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self.Platform.MetaFile))\r
1558\r
1559 if VpdFile.GetCount() != 0:\r
1560 FvPath = os.path.join(self.BuildDir, "FV")\r
1561 if not os.path.exists(FvPath):\r
1562 try:\r
1563 os.makedirs(FvPath)\r
1564 except:\r
1565 EdkLogger.error("build", FILE_WRITE_FAILURE, "Fail to create FV folder under %s" % self.BuildDir)\r
1566\r
1567 VpdFilePath = os.path.join(FvPath, "%s.txt" % self.Platform.VpdToolGuid)\r
1568\r
1569 if VpdFile.Write(VpdFilePath):\r
1570 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.\r
1571 BPDGToolName = None\r
1572 for ToolDef in self.ToolDefinition.values():\r
1573 if ToolDef.has_key("GUID") and ToolDef["GUID"] == self.Platform.VpdToolGuid:\r
1574 if not ToolDef.has_key("PATH"):\r
1575 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)\r
1576 BPDGToolName = ToolDef["PATH"]\r
1577 break\r
1578 # Call third party GUID BPDG tool.\r
1579 if BPDGToolName != None:\r
1580 VpdInfoFile.CallExtenalBPDGTool(BPDGToolName, VpdFilePath)\r
1581 else:\r
1582 EdkLogger.error("Build", FILE_NOT_FOUND, "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")\r
1583\r
1584 # Process VPD map file generated by third party BPDG tool\r
1585 if NeedProcessVpdMapFile:\r
1586 VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
1587 if os.path.exists(VpdMapFilePath):\r
1588 VpdFile.Read(VpdMapFilePath)\r
1589\r
1590 # Fixup "*" offset\r
1591 for Pcd in self._DynamicPcdList:\r
1592 # just pick the a value to determine whether is unicode string type\r
1593 i = 0\r
1594 for (SkuName,Sku) in Pcd.SkuInfoList.items(): \r
1595 if Sku.VpdOffset == "*":\r
1596 Sku.VpdOffset = VpdFile.GetOffset(Pcd)[i].strip()\r
1597 i += 1\r
1598 else:\r
1599 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
1600\r
1601 # Delete the DynamicPcdList At the last time enter into this function \r
1602 del self._DynamicPcdList[:]\r
1603 self._DynamicPcdList.extend(UnicodePcdArray)\r
1604 self._DynamicPcdList.extend(HiiPcdArray)\r
1605 self._DynamicPcdList.extend(OtherPcdArray)\r
1606 self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
1607 \r
1608 ## Return the platform build data object\r
1609 def _GetPlatform(self):\r
1610 if self._Platform == None:\r
1611 self._Platform = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
1612 return self._Platform\r
1613\r
1614 ## Return platform name\r
1615 def _GetName(self):\r
1616 return self.Platform.PlatformName\r
1617\r
1618 ## Return the meta file GUID\r
1619 def _GetGuid(self):\r
1620 return self.Platform.Guid\r
1621\r
1622 ## Return the platform version\r
1623 def _GetVersion(self):\r
1624 return self.Platform.Version\r
1625\r
1626 ## Return the FDF file name\r
1627 def _GetFdfFile(self):\r
1628 if self._FdfFile == None:\r
1629 if self.Workspace.FdfFile != "":\r
1630 self._FdfFile= mws.join(self.WorkspaceDir, self.Workspace.FdfFile)\r
1631 else:\r
1632 self._FdfFile = ''\r
1633 return self._FdfFile\r
1634\r
1635 ## Return the build output directory platform specifies\r
1636 def _GetOutputDir(self):\r
1637 return self.Platform.OutputDirectory\r
1638\r
1639 ## Return the directory to store all intermediate and final files built\r
1640 def _GetBuildDir(self):\r
1641 if self._BuildDir == None:\r
1642 if os.path.isabs(self.OutputDir):\r
1643 self._BuildDir = path.join(\r
1644 path.abspath(self.OutputDir),\r
1645 self.BuildTarget + "_" + self.ToolChain,\r
1646 )\r
1647 else:\r
1648 self._BuildDir = path.join(\r
1649 self.WorkspaceDir,\r
1650 self.OutputDir,\r
1651 self.BuildTarget + "_" + self.ToolChain,\r
1652 )\r
1653 return self._BuildDir\r
1654\r
1655 ## Return directory of platform makefile\r
1656 #\r
1657 # @retval string Makefile directory\r
1658 #\r
1659 def _GetMakeFileDir(self):\r
1660 if self._MakeFileDir == None:\r
1661 self._MakeFileDir = path.join(self.BuildDir, self.Arch)\r
1662 return self._MakeFileDir\r
1663\r
1664 ## Return build command string\r
1665 #\r
1666 # @retval string Build command string\r
1667 #\r
1668 def _GetBuildCommand(self):\r
1669 if self._BuildCommand == None:\r
1670 self._BuildCommand = []\r
1671 if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:\r
1672 self._BuildCommand += SplitOption(self.ToolDefinition["MAKE"]["PATH"])\r
1673 if "FLAGS" in self.ToolDefinition["MAKE"]:\r
1674 NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()\r
1675 if NewOption != '':\r
1676 self._BuildCommand += SplitOption(NewOption)\r
1677 return self._BuildCommand\r
1678\r
1679 ## Get tool chain definition\r
1680 #\r
1681 # Get each tool defition for given tool chain from tools_def.txt and platform\r
1682 #\r
1683 def _GetToolDefinition(self):\r
1684 if self._ToolDefinitions == None:\r
1685 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary\r
1686 if TAB_TOD_DEFINES_COMMAND_TYPE not in self.Workspace.ToolDef.ToolsDefTxtDatabase:\r
1687 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No tools found in configuration",\r
1688 ExtraData="[%s]" % self.MetaFile)\r
1689 self._ToolDefinitions = {}\r
1690 DllPathList = set()\r
1691 for Def in ToolDefinition:\r
1692 Target, Tag, Arch, Tool, Attr = Def.split("_")\r
1693 if Target != self.BuildTarget or Tag != self.ToolChain or Arch != self.Arch:\r
1694 continue\r
1695\r
1696 Value = ToolDefinition[Def]\r
1697 # don't record the DLL\r
1698 if Attr == "DLL":\r
1699 DllPathList.add(Value)\r
1700 continue\r
1701\r
1702 if Tool not in self._ToolDefinitions:\r
1703 self._ToolDefinitions[Tool] = {}\r
1704 self._ToolDefinitions[Tool][Attr] = Value\r
1705\r
1706 ToolsDef = ''\r
1707 MakePath = ''\r
1708 if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:\r
1709 if "FLAGS" not in self._ToolDefinitions["MAKE"]:\r
1710 self._ToolDefinitions["MAKE"]["FLAGS"] = ""\r
1711 self._ToolDefinitions["MAKE"]["FLAGS"] += " -s"\r
1712 MakeFlags = ''\r
1713 for Tool in self._ToolDefinitions:\r
1714 for Attr in self._ToolDefinitions[Tool]:\r
1715 Value = self._ToolDefinitions[Tool][Attr]\r
1716 if Tool in self.BuildOption and Attr in self.BuildOption[Tool]:\r
1717 # check if override is indicated\r
1718 if self.BuildOption[Tool][Attr].startswith('='):\r
1719 Value = self.BuildOption[Tool][Attr][1:]\r
1720 else:\r
1721 Value += " " + self.BuildOption[Tool][Attr]\r
1722\r
1723 if Attr == "PATH":\r
1724 # Don't put MAKE definition in the file\r
1725 if Tool == "MAKE":\r
1726 MakePath = Value\r
1727 else:\r
1728 ToolsDef += "%s = %s\n" % (Tool, Value)\r
1729 elif Attr != "DLL":\r
1730 # Don't put MAKE definition in the file\r
1731 if Tool == "MAKE":\r
1732 if Attr == "FLAGS":\r
1733 MakeFlags = Value\r
1734 else:\r
1735 ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)\r
1736 ToolsDef += "\n"\r
1737\r
1738 SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)\r
1739 for DllPath in DllPathList:\r
1740 os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]\r
1741 os.environ["MAKE_FLAGS"] = MakeFlags\r
1742\r
1743 return self._ToolDefinitions\r
1744\r
1745 ## Return the paths of tools\r
1746 def _GetToolDefFile(self):\r
1747 if self._ToolDefFile == None:\r
1748 self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)\r
1749 return self._ToolDefFile\r
1750\r
1751 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.\r
1752 def _GetToolChainFamily(self):\r
1753 if self._ToolChainFamily == None:\r
1754 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1755 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \\r
1756 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
1757 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:\r
1758 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1759 % self.ToolChain)\r
1760 self._ToolChainFamily = "MSFT"\r
1761 else:\r
1762 self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]\r
1763 return self._ToolChainFamily\r
1764\r
1765 def _GetBuildRuleFamily(self):\r
1766 if self._BuildRuleFamily == None:\r
1767 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1768 if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \\r
1769 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
1770 or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:\r
1771 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1772 % self.ToolChain)\r
1773 self._BuildRuleFamily = "MSFT"\r
1774 else:\r
1775 self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]\r
1776 return self._BuildRuleFamily\r
1777\r
1778 ## Return the build options specific for all modules in this platform\r
1779 def _GetBuildOptions(self):\r
1780 if self._BuildOption == None:\r
1781 self._BuildOption = self._ExpandBuildOption(self.Platform.BuildOptions)\r
1782 return self._BuildOption\r
1783\r
1784 ## Return the build options specific for EDK modules in this platform\r
1785 def _GetEdkBuildOptions(self):\r
1786 if self._EdkBuildOption == None:\r
1787 self._EdkBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDK_NAME)\r
1788 return self._EdkBuildOption\r
1789\r
1790 ## Return the build options specific for EDKII modules in this platform\r
1791 def _GetEdkIIBuildOptions(self):\r
1792 if self._EdkIIBuildOption == None:\r
1793 self._EdkIIBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)\r
1794 return self._EdkIIBuildOption\r
1795\r
1796 ## Parse build_rule.txt in Conf Directory.\r
1797 #\r
1798 # @retval BuildRule object\r
1799 #\r
1800 def _GetBuildRule(self):\r
1801 if self._BuildRule == None:\r
1802 BuildRuleFile = None\r
1803 if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:\r
1804 BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
1805 if BuildRuleFile in [None, '']:\r
1806 BuildRuleFile = gDefaultBuildRuleFile\r
1807 self._BuildRule = BuildRule(BuildRuleFile)\r
1808 if self._BuildRule._FileVersion == "":\r
1809 self._BuildRule._FileVersion = AutoGenReqBuildRuleVerNum\r
1810 else:\r
1811 if self._BuildRule._FileVersion < AutoGenReqBuildRuleVerNum :\r
1812 # If Build Rule's version is less than the version number required by the tools, halting the build.\r
1813 EdkLogger.error("build", AUTOGEN_ERROR,\r
1814 ExtraData="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\\r
1815 % (self._BuildRule._FileVersion, AutoGenReqBuildRuleVerNum))\r
1816\r
1817 return self._BuildRule\r
1818\r
1819 ## Summarize the packages used by modules in this platform\r
1820 def _GetPackageList(self):\r
1821 if self._PackageList == None:\r
1822 self._PackageList = set()\r
1823 for La in self.LibraryAutoGenList:\r
1824 self._PackageList.update(La.DependentPackageList)\r
1825 for Ma in self.ModuleAutoGenList:\r
1826 self._PackageList.update(Ma.DependentPackageList)\r
1827 #Collect package set information from INF of FDF\r
1828 PkgSet = set()\r
1829 for ModuleFile in self._AsBuildModuleList:\r
1830 if ModuleFile in self.Platform.Modules:\r
1831 continue\r
1832 ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]\r
1833 PkgSet.update(ModuleData.Packages)\r
1834 self._PackageList = list(self._PackageList) + list (PkgSet)\r
1835 return self._PackageList\r
1836\r
1837 def _GetNonDynamicPcdDict(self):\r
1838 if self._NonDynamicPcdDict:\r
1839 return self._NonDynamicPcdDict\r
1840 for Pcd in self.NonDynamicPcdList:\r
1841 self._NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)] = Pcd\r
1842 return self._NonDynamicPcdDict\r
1843\r
1844 ## Get list of non-dynamic PCDs\r
1845 def _GetNonDynamicPcdList(self):\r
1846 if self._NonDynamicPcdList == None:\r
1847 self.CollectPlatformDynamicPcds()\r
1848 return self._NonDynamicPcdList\r
1849\r
1850 ## Get list of dynamic PCDs\r
1851 def _GetDynamicPcdList(self):\r
1852 if self._DynamicPcdList == None:\r
1853 self.CollectPlatformDynamicPcds()\r
1854 return self._DynamicPcdList\r
1855\r
1856 ## Generate Token Number for all PCD\r
1857 def _GetPcdTokenNumbers(self):\r
1858 if self._PcdTokenNumber == None:\r
1859 self._PcdTokenNumber = sdict()\r
1860 TokenNumber = 1\r
1861 #\r
1862 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
1863 # Such as:\r
1864 # \r
1865 # Dynamic PCD:\r
1866 # TokenNumber 0 ~ 10\r
1867 # DynamicEx PCD:\r
1868 # TokeNumber 11 ~ 20\r
1869 #\r
1870 for Pcd in self.DynamicPcdList:\r
1871 if Pcd.Phase == "PEI":\r
1872 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
1873 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1874 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1875 TokenNumber += 1\r
1876\r
1877 for Pcd in self.DynamicPcdList:\r
1878 if Pcd.Phase == "PEI":\r
1879 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
1880 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1881 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1882 TokenNumber += 1\r
1883\r
1884 for Pcd in self.DynamicPcdList:\r
1885 if Pcd.Phase == "DXE":\r
1886 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
1887 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1888 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1889 TokenNumber += 1\r
1890\r
1891 for Pcd in self.DynamicPcdList:\r
1892 if Pcd.Phase == "DXE":\r
1893 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
1894 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1895 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1896 TokenNumber += 1\r
1897\r
1898 for Pcd in self.NonDynamicPcdList:\r
1899 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1900 TokenNumber += 1\r
1901 return self._PcdTokenNumber\r
1902\r
1903 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform\r
1904 def _GetAutoGenObjectList(self):\r
1905 self._ModuleAutoGenList = []\r
1906 self._LibraryAutoGenList = []\r
1907 for ModuleFile in self.Platform.Modules:\r
1908 Ma = ModuleAutoGen(\r
1909 self.Workspace,\r
1910 ModuleFile,\r
1911 self.BuildTarget,\r
1912 self.ToolChain,\r
1913 self.Arch,\r
1914 self.MetaFile\r
1915 )\r
1916 if Ma not in self._ModuleAutoGenList:\r
1917 self._ModuleAutoGenList.append(Ma)\r
1918 for La in Ma.LibraryAutoGenList:\r
1919 if La not in self._LibraryAutoGenList:\r
1920 self._LibraryAutoGenList.append(La)\r
1921 if Ma not in La._ReferenceModules:\r
1922 La._ReferenceModules.append(Ma)\r
1923\r
1924 ## Summarize ModuleAutoGen objects of all modules to be built for this platform\r
1925 def _GetModuleAutoGenList(self):\r
1926 if self._ModuleAutoGenList == None:\r
1927 self._GetAutoGenObjectList()\r
1928 return self._ModuleAutoGenList\r
1929\r
1930 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform\r
1931 def _GetLibraryAutoGenList(self):\r
1932 if self._LibraryAutoGenList == None:\r
1933 self._GetAutoGenObjectList()\r
1934 return self._LibraryAutoGenList\r
1935\r
1936 ## Test if a module is supported by the platform\r
1937 #\r
1938 # An error will be raised directly if the module or its arch is not supported\r
1939 # by the platform or current configuration\r
1940 #\r
1941 def ValidModule(self, Module):\r
1942 return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \\r
1943 or Module in self._AsBuildModuleList\r
1944\r
1945 ## Resolve the library classes in a module to library instances\r
1946 #\r
1947 # This method will not only resolve library classes but also sort the library\r
1948 # instances according to the dependency-ship.\r
1949 #\r
1950 # @param Module The module from which the library classes will be resolved\r
1951 #\r
1952 # @retval library_list List of library instances sorted\r
1953 #\r
1954 def ApplyLibraryInstance(self, Module):\r
1955 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly\r
1956 if str(Module) not in self.Platform.Modules:\r
1957 return []\r
1958\r
1959 ModuleType = Module.ModuleType\r
1960\r
1961 # for overridding library instances with module specific setting\r
1962 PlatformModule = self.Platform.Modules[str(Module)]\r
1963\r
1964 # add forced library instances (specified under LibraryClasses sections)\r
1965 #\r
1966 # If a module has a MODULE_TYPE of USER_DEFINED,\r
1967 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
1968 #\r
1969 if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
1970 for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
1971 if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
1972 Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
1973\r
1974 # add forced library instances (specified in module overrides)\r
1975 for LibraryClass in PlatformModule.LibraryClasses:\r
1976 if LibraryClass.startswith("NULL"):\r
1977 Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
1978\r
1979 # EdkII module\r
1980 LibraryConsumerList = [Module]\r
1981 Constructor = []\r
1982 ConsumedByList = sdict()\r
1983 LibraryInstance = sdict()\r
1984\r
1985 EdkLogger.verbose("")\r
1986 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
1987 while len(LibraryConsumerList) > 0:\r
1988 M = LibraryConsumerList.pop()\r
1989 for LibraryClassName in M.LibraryClasses:\r
1990 if LibraryClassName not in LibraryInstance:\r
1991 # override library instance for this module\r
1992 if LibraryClassName in PlatformModule.LibraryClasses:\r
1993 LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
1994 else:\r
1995 LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]\r
1996 if LibraryPath == None or LibraryPath == "":\r
1997 LibraryPath = M.LibraryClasses[LibraryClassName]\r
1998 if LibraryPath == None or LibraryPath == "":\r
1999 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
2000 "Instance of library class [%s] is not found" % LibraryClassName,\r
2001 File=self.MetaFile,\r
2002 ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))\r
2003\r
2004 LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]\r
2005 # for those forced library instance (NULL library), add a fake library class\r
2006 if LibraryClassName.startswith("NULL"):\r
2007 LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
2008 elif LibraryModule.LibraryClass == None \\r
2009 or len(LibraryModule.LibraryClass) == 0 \\r
2010 or (ModuleType != 'USER_DEFINED'\r
2011 and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
2012 # only USER_DEFINED can link against any library instance despite of its SupModList\r
2013 EdkLogger.error("build", OPTION_MISSING,\r
2014 "Module type [%s] is not supported by library instance [%s]" \\r
2015 % (ModuleType, LibraryPath), File=self.MetaFile,\r
2016 ExtraData="consumed by [%s]" % str(Module))\r
2017\r
2018 LibraryInstance[LibraryClassName] = LibraryModule\r
2019 LibraryConsumerList.append(LibraryModule)\r
2020 EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
2021 else:\r
2022 LibraryModule = LibraryInstance[LibraryClassName]\r
2023\r
2024 if LibraryModule == None:\r
2025 continue\r
2026\r
2027 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
2028 Constructor.append(LibraryModule)\r
2029\r
2030 if LibraryModule not in ConsumedByList:\r
2031 ConsumedByList[LibraryModule] = []\r
2032 # don't add current module itself to consumer list\r
2033 if M != Module:\r
2034 if M in ConsumedByList[LibraryModule]:\r
2035 continue\r
2036 ConsumedByList[LibraryModule].append(M)\r
2037 #\r
2038 # Initialize the sorted output list to the empty set\r
2039 #\r
2040 SortedLibraryList = []\r
2041 #\r
2042 # Q <- Set of all nodes with no incoming edges\r
2043 #\r
2044 LibraryList = [] #LibraryInstance.values()\r
2045 Q = []\r
2046 for LibraryClassName in LibraryInstance:\r
2047 M = LibraryInstance[LibraryClassName]\r
2048 LibraryList.append(M)\r
2049 if ConsumedByList[M] == []:\r
2050 Q.append(M)\r
2051\r
2052 #\r
2053 # start the DAG algorithm\r
2054 #\r
2055 while True:\r
2056 EdgeRemoved = True\r
2057 while Q == [] and EdgeRemoved:\r
2058 EdgeRemoved = False\r
2059 # for each node Item with a Constructor\r
2060 for Item in LibraryList:\r
2061 if Item not in Constructor:\r
2062 continue\r
2063 # for each Node without a constructor with an edge e from Item to Node\r
2064 for Node in ConsumedByList[Item]:\r
2065 if Node in Constructor:\r
2066 continue\r
2067 # remove edge e from the graph if Node has no constructor\r
2068 ConsumedByList[Item].remove(Node)\r
2069 EdgeRemoved = True\r
2070 if ConsumedByList[Item] == []:\r
2071 # insert Item into Q\r
2072 Q.insert(0, Item)\r
2073 break\r
2074 if Q != []:\r
2075 break\r
2076 # DAG is done if there's no more incoming edge for all nodes\r
2077 if Q == []:\r
2078 break\r
2079\r
2080 # remove node from Q\r
2081 Node = Q.pop()\r
2082 # output Node\r
2083 SortedLibraryList.append(Node)\r
2084\r
2085 # for each node Item with an edge e from Node to Item do\r
2086 for Item in LibraryList:\r
2087 if Node not in ConsumedByList[Item]:\r
2088 continue\r
2089 # remove edge e from the graph\r
2090 ConsumedByList[Item].remove(Node)\r
2091\r
2092 if ConsumedByList[Item] != []:\r
2093 continue\r
2094 # insert Item into Q, if Item has no other incoming edges\r
2095 Q.insert(0, Item)\r
2096\r
2097 #\r
2098 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
2099 #\r
2100 for Item in LibraryList:\r
2101 if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
2102 ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])\r
2103 EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
2104 ExtraData=ErrorMessage, File=self.MetaFile)\r
2105 if Item not in SortedLibraryList:\r
2106 SortedLibraryList.append(Item)\r
2107\r
2108 #\r
2109 # Build the list of constructor and destructir names\r
2110 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
2111 #\r
2112 SortedLibraryList.reverse()\r
2113 return SortedLibraryList\r
2114\r
2115\r
2116 ## Override PCD setting (type, value, ...)\r
2117 #\r
2118 # @param ToPcd The PCD to be overrided\r
2119 # @param FromPcd The PCD overrideing from\r
2120 #\r
2121 def _OverridePcd(self, ToPcd, FromPcd, Module=""):\r
2122 #\r
2123 # in case there's PCDs coming from FDF file, which have no type given.\r
2124 # at this point, ToPcd.Type has the type found from dependent\r
2125 # package\r
2126 #\r
2127 TokenCName = ToPcd.TokenCName\r
2128 for PcdItem in GlobalData.MixedPcd:\r
2129 if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
2130 TokenCName = PcdItem[0]\r
2131 break\r
2132 if FromPcd != None:\r
2133 if GlobalData.BuildOptionPcd:\r
2134 for pcd in GlobalData.BuildOptionPcd:\r
2135 if (FromPcd.TokenSpaceGuidCName, FromPcd.TokenCName) == (pcd[0], pcd[1]):\r
2136 FromPcd.DefaultValue = pcd[2]\r
2137 break\r
2138 if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
2139 ToPcd.Type = FromPcd.Type\r
2140 elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
2141 and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):\r
2142 if ToPcd.Type.strip() == "DynamicEx":\r
2143 ToPcd.Type = FromPcd.Type\r
2144 elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \\r
2145 and ToPcd.Type != FromPcd.Type:\r
2146 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
2147 ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
2148 % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
2149 ToPcd.Type, Module, FromPcd.Type),\r
2150 File=self.MetaFile)\r
2151\r
2152 if FromPcd.MaxDatumSize not in [None, '']:\r
2153 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2154 if FromPcd.DefaultValue not in [None, '']:\r
2155 ToPcd.DefaultValue = FromPcd.DefaultValue\r
2156 if FromPcd.TokenValue not in [None, '']:\r
2157 ToPcd.TokenValue = FromPcd.TokenValue\r
2158 if FromPcd.MaxDatumSize not in [None, '']:\r
2159 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2160 if FromPcd.DatumType not in [None, '']:\r
2161 ToPcd.DatumType = FromPcd.DatumType\r
2162 if FromPcd.SkuInfoList not in [None, '', []]:\r
2163 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
2164\r
2165 # check the validation of datum\r
2166 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
2167 if not IsValid:\r
2168 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
2169 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
2170 ToPcd.validateranges = FromPcd.validateranges\r
2171 ToPcd.validlists = FromPcd.validlists\r
2172 ToPcd.expressions = FromPcd.expressions\r
2173\r
2174 if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
2175 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
2176 % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
2177 Value = ToPcd.DefaultValue\r
2178 if Value in [None, '']:\r
2179 ToPcd.MaxDatumSize = '1'\r
2180 elif Value[0] == 'L':\r
2181 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
2182 elif Value[0] == '{':\r
2183 ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
2184 else:\r
2185 ToPcd.MaxDatumSize = str(len(Value) - 1)\r
2186\r
2187 # apply default SKU for dynamic PCDS if specified one is not available\r
2188 if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \\r
2189 and ToPcd.SkuInfoList in [None, {}, '']:\r
2190 if self.Platform.SkuName in self.Platform.SkuIds:\r
2191 SkuName = self.Platform.SkuName\r
2192 else:\r
2193 SkuName = 'DEFAULT'\r
2194 ToPcd.SkuInfoList = {\r
2195 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)\r
2196 }\r
2197\r
2198 ## Apply PCD setting defined platform to a module\r
2199 #\r
2200 # @param Module The module from which the PCD setting will be overrided\r
2201 #\r
2202 # @retval PCD_list The list PCDs with settings from platform\r
2203 #\r
2204 def ApplyPcdSetting(self, Module, Pcds):\r
2205 # for each PCD in module\r
2206 for Name, Guid in Pcds:\r
2207 PcdInModule = Pcds[Name, Guid]\r
2208 # find out the PCD setting in platform\r
2209 if (Name, Guid) in self.Platform.Pcds:\r
2210 PcdInPlatform = self.Platform.Pcds[Name, Guid]\r
2211 else:\r
2212 PcdInPlatform = None\r
2213 # then override the settings if any\r
2214 self._OverridePcd(PcdInModule, PcdInPlatform, Module)\r
2215 # resolve the VariableGuid value\r
2216 for SkuId in PcdInModule.SkuInfoList:\r
2217 Sku = PcdInModule.SkuInfoList[SkuId]\r
2218 if Sku.VariableGuid == '': continue\r
2219 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
2220 if Sku.VariableGuidValue == None:\r
2221 PackageList = "\n\t".join([str(P) for P in self.PackageList])\r
2222 EdkLogger.error(\r
2223 'build',\r
2224 RESOURCE_NOT_AVAILABLE,\r
2225 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
2226 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
2227 % (Guid, Name, str(Module)),\r
2228 File=self.MetaFile\r
2229 )\r
2230\r
2231 # override PCD settings with module specific setting\r
2232 if Module in self.Platform.Modules:\r
2233 PlatformModule = self.Platform.Modules[str(Module)]\r
2234 for Key in PlatformModule.Pcds:\r
2235 if Key in Pcds:\r
2236 self._OverridePcd(Pcds[Key], PlatformModule.Pcds[Key], Module)\r
2237 return Pcds.values()\r
2238\r
2239 ## Resolve library names to library modules\r
2240 #\r
2241 # (for Edk.x modules)\r
2242 #\r
2243 # @param Module The module from which the library names will be resolved\r
2244 #\r
2245 # @retval library_list The list of library modules\r
2246 #\r
2247 def ResolveLibraryReference(self, Module):\r
2248 EdkLogger.verbose("")\r
2249 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
2250 LibraryConsumerList = [Module]\r
2251\r
2252 # "CompilerStub" is a must for Edk modules\r
2253 if Module.Libraries:\r
2254 Module.Libraries.append("CompilerStub")\r
2255 LibraryList = []\r
2256 while len(LibraryConsumerList) > 0:\r
2257 M = LibraryConsumerList.pop()\r
2258 for LibraryName in M.Libraries:\r
2259 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']\r
2260 if Library == None:\r
2261 for Key in self.Platform.LibraryClasses.data.keys():\r
2262 if LibraryName.upper() == Key.upper():\r
2263 Library = self.Platform.LibraryClasses[Key, ':dummy:']\r
2264 break\r
2265 if Library == None:\r
2266 EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),\r
2267 ExtraData="\t%s [%s]" % (str(Module), self.Arch))\r
2268 continue\r
2269\r
2270 if Library not in LibraryList:\r
2271 LibraryList.append(Library)\r
2272 LibraryConsumerList.append(Library)\r
2273 EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))\r
2274 return LibraryList\r
2275\r
2276 ## Calculate the priority value of the build option\r
2277 #\r
2278 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2279 #\r
2280 # @retval Value Priority value based on the priority list.\r
2281 #\r
2282 def CalculatePriorityValue(self, Key):\r
2283 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')\r
2284 PriorityValue = 0x11111\r
2285 if Target == "*":\r
2286 PriorityValue &= 0x01111\r
2287 if ToolChain == "*":\r
2288 PriorityValue &= 0x10111\r
2289 if Arch == "*":\r
2290 PriorityValue &= 0x11011\r
2291 if CommandType == "*":\r
2292 PriorityValue &= 0x11101\r
2293 if Attr == "*":\r
2294 PriorityValue &= 0x11110\r
2295\r
2296 return self.PrioList["0x%0.5x" % PriorityValue]\r
2297\r
2298\r
2299 ## Expand * in build option key\r
2300 #\r
2301 # @param Options Options to be expanded\r
2302 #\r
2303 # @retval options Options expanded\r
2304 # \r
2305 def _ExpandBuildOption(self, Options, ModuleStyle=None):\r
2306 BuildOptions = {}\r
2307 FamilyMatch = False\r
2308 FamilyIsNull = True\r
2309\r
2310 OverrideList = {}\r
2311 #\r
2312 # Construct a list contain the build options which need override.\r
2313 #\r
2314 for Key in Options:\r
2315 #\r
2316 # Key[0] -- tool family\r
2317 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2318 #\r
2319 if (Key[0] == self.BuildRuleFamily and\r
2320 (ModuleStyle == None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):\r
2321 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
2322 if Target == self.BuildTarget or Target == "*":\r
2323 if ToolChain == self.ToolChain or ToolChain == "*":\r
2324 if Arch == self.Arch or Arch == "*":\r
2325 if Options[Key].startswith("="):\r
2326 if OverrideList.get(Key[1]) != None:\r
2327 OverrideList.pop(Key[1])\r
2328 OverrideList[Key[1]] = Options[Key]\r
2329 \r
2330 #\r
2331 # Use the highest priority value. \r
2332 #\r
2333 if (len(OverrideList) >= 2):\r
2334 KeyList = OverrideList.keys()\r
2335 for Index in range(len(KeyList)):\r
2336 NowKey = KeyList[Index]\r
2337 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
2338 for Index1 in range(len(KeyList) - Index - 1):\r
2339 NextKey = KeyList[Index1 + Index + 1]\r
2340 #\r
2341 # Compare two Key, if one is included by another, choose the higher priority one\r
2342 # \r
2343 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
2344 if Target1 == Target2 or Target1 == "*" or Target2 == "*":\r
2345 if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":\r
2346 if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":\r
2347 if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":\r
2348 if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":\r
2349 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):\r
2350 if Options.get((self.BuildRuleFamily, NextKey)) != None:\r
2351 Options.pop((self.BuildRuleFamily, NextKey))\r
2352 else:\r
2353 if Options.get((self.BuildRuleFamily, NowKey)) != None:\r
2354 Options.pop((self.BuildRuleFamily, NowKey))\r
2355 \r
2356 for Key in Options:\r
2357 if ModuleStyle != None and len (Key) > 2:\r
2358 # Check Module style is EDK or EDKII.\r
2359 # Only append build option for the matched style module.\r
2360 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2361 continue\r
2362 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2363 continue\r
2364 Family = Key[0]\r
2365 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2366 # if tool chain family doesn't match, skip it\r
2367 if Tool in self.ToolDefinition and Family != "":\r
2368 FamilyIsNull = False\r
2369 if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
2370 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
2371 continue\r
2372 elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2373 continue\r
2374 FamilyMatch = True\r
2375 # expand any wildcard\r
2376 if Target == "*" or Target == self.BuildTarget:\r
2377 if Tag == "*" or Tag == self.ToolChain:\r
2378 if Arch == "*" or Arch == self.Arch:\r
2379 if Tool not in BuildOptions:\r
2380 BuildOptions[Tool] = {}\r
2381 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
2382 BuildOptions[Tool][Attr] = Options[Key]\r
2383 else:\r
2384 # append options for the same tool\r
2385 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2386 # Build Option Family has been checked, which need't to be checked again for family.\r
2387 if FamilyMatch or FamilyIsNull:\r
2388 return BuildOptions\r
2389\r
2390 for Key in Options:\r
2391 if ModuleStyle != None and len (Key) > 2:\r
2392 # Check Module style is EDK or EDKII.\r
2393 # Only append build option for the matched style module.\r
2394 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2395 continue\r
2396 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2397 continue\r
2398 Family = Key[0]\r
2399 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2400 # if tool chain family doesn't match, skip it\r
2401 if Tool not in self.ToolDefinition or Family == "":\r
2402 continue\r
2403 # option has been added before\r
2404 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2405 continue\r
2406\r
2407 # expand any wildcard\r
2408 if Target == "*" or Target == self.BuildTarget:\r
2409 if Tag == "*" or Tag == self.ToolChain:\r
2410 if Arch == "*" or Arch == self.Arch:\r
2411 if Tool not in BuildOptions:\r
2412 BuildOptions[Tool] = {}\r
2413 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
2414 BuildOptions[Tool][Attr] = Options[Key]\r
2415 else:\r
2416 # append options for the same tool\r
2417 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2418 return BuildOptions\r
2419\r
2420 ## Append build options in platform to a module\r
2421 #\r
2422 # @param Module The module to which the build options will be appened\r
2423 #\r
2424 # @retval options The options appended with build options in platform\r
2425 #\r
2426 def ApplyBuildOption(self, Module):\r
2427 # Get the different options for the different style module\r
2428 if Module.AutoGenVersion < 0x00010005:\r
2429 PlatformOptions = self.EdkBuildOption\r
2430 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDK_NAME, Module.ModuleType)\r
2431 else:\r
2432 PlatformOptions = self.EdkIIBuildOption\r
2433 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDKII_NAME, Module.ModuleType)\r
2434 ModuleTypeOptions = self._ExpandBuildOption(ModuleTypeOptions)\r
2435 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)\r
2436 if Module in self.Platform.Modules:\r
2437 PlatformModule = self.Platform.Modules[str(Module)]\r
2438 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)\r
2439 else:\r
2440 PlatformModuleOptions = {}\r
2441\r
2442 BuildRuleOrder = None\r
2443 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
2444 for Tool in Options:\r
2445 for Attr in Options[Tool]:\r
2446 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2447 BuildRuleOrder = Options[Tool][Attr]\r
2448\r
2449 AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +\r
2450 PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +\r
2451 self.ToolDefinition.keys())\r
2452 BuildOptions = {}\r
2453 for Tool in AllTools:\r
2454 if Tool not in BuildOptions:\r
2455 BuildOptions[Tool] = {}\r
2456\r
2457 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
2458 if Tool not in Options:\r
2459 continue\r
2460 for Attr in Options[Tool]:\r
2461 Value = Options[Tool][Attr]\r
2462 #\r
2463 # Do not generate it in Makefile\r
2464 #\r
2465 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2466 continue\r
2467 if Attr not in BuildOptions[Tool]:\r
2468 BuildOptions[Tool][Attr] = ""\r
2469 # check if override is indicated\r
2470 if Value.startswith('='):\r
2471 ToolPath = Value[1:]\r
2472 ToolPath = mws.handleWsMacro(ToolPath)\r
2473 BuildOptions[Tool][Attr] = ToolPath\r
2474 else:\r
2475 Value = mws.handleWsMacro(Value)\r
2476 BuildOptions[Tool][Attr] += " " + Value\r
2477 if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:\r
2478 #\r
2479 # Override UNI flag only for EDK module.\r
2480 #\r
2481 if 'BUILD' not in BuildOptions:\r
2482 BuildOptions['BUILD'] = {}\r
2483 BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
2484 return BuildOptions, BuildRuleOrder\r
2485\r
2486 Platform = property(_GetPlatform)\r
2487 Name = property(_GetName)\r
2488 Guid = property(_GetGuid)\r
2489 Version = property(_GetVersion)\r
2490\r
2491 OutputDir = property(_GetOutputDir)\r
2492 BuildDir = property(_GetBuildDir)\r
2493 MakeFileDir = property(_GetMakeFileDir)\r
2494 FdfFile = property(_GetFdfFile)\r
2495\r
2496 PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
2497 DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2498 NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2499 NonDynamicPcdDict = property(_GetNonDynamicPcdDict)\r
2500 PackageList = property(_GetPackageList)\r
2501\r
2502 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
2503 ToolDefinitionFile = property(_GetToolDefFile) # toolcode : lib path\r
2504 ToolChainFamily = property(_GetToolChainFamily)\r
2505 BuildRuleFamily = property(_GetBuildRuleFamily)\r
2506 BuildOption = property(_GetBuildOptions) # toolcode : option\r
2507 EdkBuildOption = property(_GetEdkBuildOptions) # edktoolcode : option\r
2508 EdkIIBuildOption = property(_GetEdkIIBuildOptions) # edkiitoolcode : option\r
2509\r
2510 BuildCommand = property(_GetBuildCommand)\r
2511 BuildRule = property(_GetBuildRule)\r
2512 ModuleAutoGenList = property(_GetModuleAutoGenList)\r
2513 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
2514 GenFdsCommand = property(_GenFdsCommand)\r
2515\r
2516## ModuleAutoGen class\r
2517#\r
2518# This class encapsules the AutoGen behaviors for the build tools. In addition to\r
2519# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r
2520# to the [depex] section in module's inf file.\r
2521#\r
2522class ModuleAutoGen(AutoGen):\r
2523 ## The real constructor of ModuleAutoGen\r
2524 #\r
2525 # This method is not supposed to be called by users of ModuleAutoGen. It's\r
2526 # only used by factory method __new__() to do real initialization work for an\r
2527 # object of ModuleAutoGen\r
2528 #\r
2529 # @param Workspace EdkIIWorkspaceBuild object\r
2530 # @param ModuleFile The path of module file\r
2531 # @param Target Build target (DEBUG, RELEASE)\r
2532 # @param Toolchain Name of tool chain\r
2533 # @param Arch The arch the module supports\r
2534 # @param PlatformFile Platform meta-file\r
2535 #\r
2536 def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
2537 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
2538 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
2539\r
2540 self.Workspace = Workspace\r
2541 self.WorkspaceDir = Workspace.WorkspaceDir\r
2542\r
2543 self.MetaFile = ModuleFile\r
2544 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
2545 # check if this module is employed by active platform\r
2546 if not self.PlatformInfo.ValidModule(self.MetaFile):\r
2547 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
2548 % (self.MetaFile, Arch))\r
2549 return False\r
2550\r
2551 self.SourceDir = self.MetaFile.SubDir\r
2552 self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r
2553\r
2554 self.SourceOverrideDir = None\r
2555 # use overrided path defined in DSC file\r
2556 if self.MetaFile.Key in GlobalData.gOverrideDir:\r
2557 self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]\r
2558\r
2559 self.ToolChain = Toolchain\r
2560 self.BuildTarget = Target\r
2561 self.Arch = Arch\r
2562 self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r
2563 self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r
2564\r
2565 self.IsMakeFileCreated = False\r
2566 self.IsCodeFileCreated = False\r
2567 self.IsAsBuiltInfCreated = False\r
2568 self.DepexGenerated = False\r
2569\r
2570 self.BuildDatabase = self.Workspace.BuildDatabase\r
2571 self.BuildRuleOrder = None\r
2572\r
2573 self._Module = None\r
2574 self._Name = None\r
2575 self._Guid = None\r
2576 self._Version = None\r
2577 self._ModuleType = None\r
2578 self._ComponentType = None\r
2579 self._PcdIsDriver = None\r
2580 self._AutoGenVersion = None\r
2581 self._LibraryFlag = None\r
2582 self._CustomMakefile = None\r
2583 self._Macro = None\r
2584\r
2585 self._BuildDir = None\r
2586 self._OutputDir = None\r
2587 self._DebugDir = None\r
2588 self._MakeFileDir = None\r
2589\r
2590 self._IncludePathList = None\r
2591 self._IncludePathLength = 0\r
2592 self._AutoGenFileList = None\r
2593 self._UnicodeFileList = None\r
2594 self._VfrFileList = None\r
2595 self._IdfFileList = None\r
2596 self._SourceFileList = None\r
2597 self._ObjectFileList = None\r
2598 self._BinaryFileList = None\r
2599\r
2600 self._DependentPackageList = None\r
2601 self._DependentLibraryList = None\r
2602 self._LibraryAutoGenList = None\r
2603 self._DerivedPackageList = None\r
2604 self._ModulePcdList = None\r
2605 self._LibraryPcdList = None\r
2606 self._PcdComments = sdict()\r
2607 self._GuidList = None\r
2608 self._GuidsUsedByPcd = None\r
2609 self._GuidComments = sdict()\r
2610 self._ProtocolList = None\r
2611 self._ProtocolComments = sdict()\r
2612 self._PpiList = None\r
2613 self._PpiComments = sdict()\r
2614 self._DepexList = None\r
2615 self._DepexExpressionList = None\r
2616 self._BuildOption = None\r
2617 self._BuildOptionIncPathList = None\r
2618 self._BuildTargets = None\r
2619 self._IntroBuildTargetList = None\r
2620 self._FinalBuildTargetList = None\r
2621 self._FileTypes = None\r
2622 self._BuildRules = None\r
2623 \r
2624 ## The Modules referenced to this Library\r
2625 # Only Library has this attribute\r
2626 self._ReferenceModules = [] \r
2627 \r
2628 ## Store the FixedAtBuild Pcds\r
2629 # \r
2630 self._FixedAtBuildPcds = []\r
2631 self.ConstPcd = {}\r
2632 return True\r
2633\r
2634 def __repr__(self):\r
2635 return "%s [%s]" % (self.MetaFile, self.Arch)\r
2636\r
2637 # Get FixedAtBuild Pcds of this Module\r
2638 def _GetFixedAtBuildPcds(self):\r
2639 if self._FixedAtBuildPcds:\r
2640 return self._FixedAtBuildPcds\r
2641 for Pcd in self.ModulePcdList:\r
2642 if self.IsLibrary:\r
2643 if not (Pcd.Pending == False and Pcd.Type == "FixedAtBuild"):\r
2644 continue\r
2645 elif Pcd.Type != "FixedAtBuild":\r
2646 continue\r
2647 if Pcd not in self._FixedAtBuildPcds:\r
2648 self._FixedAtBuildPcds.append(Pcd)\r
2649 \r
2650 return self._FixedAtBuildPcds \r
2651\r
2652 def _GetUniqueBaseName(self):\r
2653 BaseName = self.Name\r
2654 for Module in self.PlatformInfo.ModuleAutoGenList:\r
2655 if Module.MetaFile == self.MetaFile:\r
2656 continue\r
2657 if Module.Name == self.Name:\r
2658 if uuid.UUID(Module.Guid) == uuid.UUID(self.Guid):\r
2659 EdkLogger.error("build", FILE_DUPLICATED, 'Modules have same BaseName and FILE_GUID:\n'\r
2660 ' %s\n %s' % (Module.MetaFile, self.MetaFile))\r
2661 BaseName = '%s_%s' % (self.Name, self.Guid)\r
2662 return BaseName\r
2663\r
2664 # Macros could be used in build_rule.txt (also Makefile)\r
2665 def _GetMacros(self):\r
2666 if self._Macro == None:\r
2667 self._Macro = sdict()\r
2668 self._Macro["WORKSPACE" ] = self.WorkspaceDir\r
2669 self._Macro["MODULE_NAME" ] = self.Name\r
2670 self._Macro["MODULE_NAME_GUID" ] = self._GetUniqueBaseName()\r
2671 self._Macro["MODULE_GUID" ] = self.Guid\r
2672 self._Macro["MODULE_VERSION" ] = self.Version\r
2673 self._Macro["MODULE_TYPE" ] = self.ModuleType\r
2674 self._Macro["MODULE_FILE" ] = str(self.MetaFile)\r
2675 self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName\r
2676 self._Macro["MODULE_RELATIVE_DIR" ] = self.SourceDir\r
2677 self._Macro["MODULE_DIR" ] = self.SourceDir\r
2678\r
2679 self._Macro["BASE_NAME" ] = self.Name\r
2680\r
2681 self._Macro["ARCH" ] = self.Arch\r
2682 self._Macro["TOOLCHAIN" ] = self.ToolChain\r
2683 self._Macro["TOOLCHAIN_TAG" ] = self.ToolChain\r
2684 self._Macro["TOOL_CHAIN_TAG" ] = self.ToolChain\r
2685 self._Macro["TARGET" ] = self.BuildTarget\r
2686\r
2687 self._Macro["BUILD_DIR" ] = self.PlatformInfo.BuildDir\r
2688 self._Macro["BIN_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2689 self._Macro["LIB_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2690 self._Macro["MODULE_BUILD_DIR" ] = self.BuildDir\r
2691 self._Macro["OUTPUT_DIR" ] = self.OutputDir\r
2692 self._Macro["DEBUG_DIR" ] = self.DebugDir\r
2693 self._Macro["DEST_DIR_OUTPUT" ] = self.OutputDir\r
2694 self._Macro["DEST_DIR_DEBUG" ] = self.DebugDir\r
2695 self._Macro["PLATFORM_NAME" ] = self.PlatformInfo.Name\r
2696 self._Macro["PLATFORM_GUID" ] = self.PlatformInfo.Guid\r
2697 self._Macro["PLATFORM_VERSION" ] = self.PlatformInfo.Version\r
2698 self._Macro["PLATFORM_RELATIVE_DIR" ] = self.PlatformInfo.SourceDir\r
2699 self._Macro["PLATFORM_DIR" ] = mws.join(self.WorkspaceDir, self.PlatformInfo.SourceDir)\r
2700 self._Macro["PLATFORM_OUTPUT_DIR" ] = self.PlatformInfo.OutputDir\r
2701 return self._Macro\r
2702\r
2703 ## Return the module build data object\r
2704 def _GetModule(self):\r
2705 if self._Module == None:\r
2706 self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
2707 return self._Module\r
2708\r
2709 ## Return the module name\r
2710 def _GetBaseName(self):\r
2711 return self.Module.BaseName\r
2712\r
2713 ## Return the module DxsFile if exist\r
2714 def _GetDxsFile(self):\r
2715 return self.Module.DxsFile\r
2716\r
2717 ## Return the module SourceOverridePath\r
2718 def _GetSourceOverridePath(self):\r
2719 return self.Module.SourceOverridePath\r
2720\r
2721 ## Return the module meta-file GUID\r
2722 def _GetGuid(self):\r
2723 #\r
2724 # To build same module more than once, the module path with FILE_GUID overridden has\r
2725 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path\r
2726 # in DSC. The overridden GUID can be retrieved from file name\r
2727 #\r
2728 if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):\r
2729 #\r
2730 # Length of GUID is 36\r
2731 #\r
2732 return os.path.basename(self.MetaFile.Path)[:36]\r
2733 return self.Module.Guid\r
2734\r
2735 ## Return the module version\r
2736 def _GetVersion(self):\r
2737 return self.Module.Version\r
2738\r
2739 ## Return the module type\r
2740 def _GetModuleType(self):\r
2741 return self.Module.ModuleType\r
2742\r
2743 ## Return the component type (for Edk.x style of module)\r
2744 def _GetComponentType(self):\r
2745 return self.Module.ComponentType\r
2746\r
2747 ## Return the build type\r
2748 def _GetBuildType(self):\r
2749 return self.Module.BuildType\r
2750\r
2751 ## Return the PCD_IS_DRIVER setting\r
2752 def _GetPcdIsDriver(self):\r
2753 return self.Module.PcdIsDriver\r
2754\r
2755 ## Return the autogen version, i.e. module meta-file version\r
2756 def _GetAutoGenVersion(self):\r
2757 return self.Module.AutoGenVersion\r
2758\r
2759 ## Check if the module is library or not\r
2760 def _IsLibrary(self):\r
2761 if self._LibraryFlag == None:\r
2762 if self.Module.LibraryClass != None and self.Module.LibraryClass != []:\r
2763 self._LibraryFlag = True\r
2764 else:\r
2765 self._LibraryFlag = False\r
2766 return self._LibraryFlag\r
2767\r
2768 ## Check if the module is binary module or not\r
2769 def _IsBinaryModule(self):\r
2770 return self.Module.IsBinaryModule\r
2771\r
2772 ## Return the directory to store intermediate files of the module\r
2773 def _GetBuildDir(self):\r
2774 if self._BuildDir == None:\r
2775 self._BuildDir = path.join(\r
2776 self.PlatformInfo.BuildDir,\r
2777 self.Arch,\r
2778 self.SourceDir,\r
2779 self.MetaFile.BaseName\r
2780 )\r
2781 CreateDirectory(self._BuildDir)\r
2782 return self._BuildDir\r
2783\r
2784 ## Return the directory to store the intermediate object files of the mdoule\r
2785 def _GetOutputDir(self):\r
2786 if self._OutputDir == None:\r
2787 self._OutputDir = path.join(self.BuildDir, "OUTPUT")\r
2788 CreateDirectory(self._OutputDir)\r
2789 return self._OutputDir\r
2790\r
2791 ## Return the directory to store auto-gened source files of the mdoule\r
2792 def _GetDebugDir(self):\r
2793 if self._DebugDir == None:\r
2794 self._DebugDir = path.join(self.BuildDir, "DEBUG")\r
2795 CreateDirectory(self._DebugDir)\r
2796 return self._DebugDir\r
2797\r
2798 ## Return the path of custom file\r
2799 def _GetCustomMakefile(self):\r
2800 if self._CustomMakefile == None:\r
2801 self._CustomMakefile = {}\r
2802 for Type in self.Module.CustomMakefile:\r
2803 if Type in gMakeTypeMap:\r
2804 MakeType = gMakeTypeMap[Type]\r
2805 else:\r
2806 MakeType = 'nmake'\r
2807 if self.SourceOverrideDir != None:\r
2808 File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])\r
2809 if not os.path.exists(File):\r
2810 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2811 else:\r
2812 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2813 self._CustomMakefile[MakeType] = File\r
2814 return self._CustomMakefile\r
2815\r
2816 ## Return the directory of the makefile\r
2817 #\r
2818 # @retval string The directory string of module's makefile\r
2819 #\r
2820 def _GetMakeFileDir(self):\r
2821 return self.BuildDir\r
2822\r
2823 ## Return build command string\r
2824 #\r
2825 # @retval string Build command string\r
2826 #\r
2827 def _GetBuildCommand(self):\r
2828 return self.PlatformInfo.BuildCommand\r
2829\r
2830 ## Get object list of all packages the module and its dependent libraries belong to\r
2831 #\r
2832 # @retval list The list of package object\r
2833 #\r
2834 def _GetDerivedPackageList(self):\r
2835 PackageList = []\r
2836 for M in [self.Module] + self.DependentLibraryList:\r
2837 for Package in M.Packages:\r
2838 if Package in PackageList:\r
2839 continue\r
2840 PackageList.append(Package)\r
2841 return PackageList\r
2842 \r
2843 ## Get the depex string\r
2844 #\r
2845 # @return : a string contain all depex expresion.\r
2846 def _GetDepexExpresionString(self):\r
2847 DepexStr = ''\r
2848 DepexList = []\r
2849 ## DPX_SOURCE IN Define section.\r
2850 if self.Module.DxsFile:\r
2851 return DepexStr\r
2852 for M in [self.Module] + self.DependentLibraryList:\r
2853 Filename = M.MetaFile.Path\r
2854 InfObj = InfSectionParser.InfSectionParser(Filename)\r
2855 DepexExpresionList = InfObj.GetDepexExpresionList()\r
2856 for DepexExpresion in DepexExpresionList:\r
2857 for key in DepexExpresion.keys():\r
2858 Arch, ModuleType = key\r
2859 DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')]\r
2860 # the type of build module is USER_DEFINED.\r
2861 # All different DEPEX section tags would be copied into the As Built INF file\r
2862 # and there would be separate DEPEX section tags\r
2863 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2864 if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):\r
2865 DepexList.append({(Arch, ModuleType): DepexExpr})\r
2866 else:\r
2867 if Arch.upper() == TAB_ARCH_COMMON or \\r
2868 (Arch.upper() == self.Arch.upper() and \\r
2869 ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):\r
2870 DepexList.append({(Arch, ModuleType): DepexExpr})\r
2871 \r
2872 #the type of build module is USER_DEFINED.\r
2873 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2874 for Depex in DepexList:\r
2875 for key in Depex.keys():\r
2876 DepexStr += '[Depex.%s.%s]\n' % key\r
2877 DepexStr += '\n'.join(['# '+ val for val in Depex[key]])\r
2878 DepexStr += '\n\n'\r
2879 if not DepexStr:\r
2880 return '[Depex.%s]\n' % self.Arch\r
2881 return DepexStr\r
2882 \r
2883 #the type of build module not is USER_DEFINED.\r
2884 Count = 0\r
2885 for Depex in DepexList:\r
2886 Count += 1\r
2887 if DepexStr != '':\r
2888 DepexStr += ' AND '\r
2889 DepexStr += '('\r
2890 for D in Depex.values():\r
2891 DepexStr += ' '.join([val for val in D])\r
2892 Index = DepexStr.find('END')\r
2893 if Index > -1 and Index == len(DepexStr) - 3:\r
2894 DepexStr = DepexStr[:-3]\r
2895 DepexStr = DepexStr.strip()\r
2896 DepexStr += ')'\r
2897 if Count == 1:\r
2898 DepexStr = DepexStr.lstrip('(').rstrip(')').strip()\r
2899 if not DepexStr:\r
2900 return '[Depex.%s]\n' % self.Arch\r
2901 return '[Depex.%s]\n# ' % self.Arch + DepexStr\r
2902 \r
2903 ## Merge dependency expression\r
2904 #\r
2905 # @retval list The token list of the dependency expression after parsed\r
2906 #\r
2907 def _GetDepexTokenList(self):\r
2908 if self._DepexList == None:\r
2909 self._DepexList = {}\r
2910 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
2911 return self._DepexList\r
2912\r
2913 self._DepexList[self.ModuleType] = []\r
2914\r
2915 for ModuleType in self._DepexList:\r
2916 DepexList = self._DepexList[ModuleType]\r
2917 #\r
2918 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2919 #\r
2920 for M in [self.Module] + self.DependentLibraryList:\r
2921 Inherited = False\r
2922 for D in M.Depex[self.Arch, ModuleType]:\r
2923 if DepexList != []:\r
2924 DepexList.append('AND')\r
2925 DepexList.append('(')\r
2926 DepexList.extend(D)\r
2927 if DepexList[-1] == 'END': # no need of a END at this time\r
2928 DepexList.pop()\r
2929 DepexList.append(')')\r
2930 Inherited = True\r
2931 if Inherited:\r
2932 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))\r
2933 if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
2934 break\r
2935 if len(DepexList) > 0:\r
2936 EdkLogger.verbose('')\r
2937 return self._DepexList\r
2938\r
2939 ## Merge dependency expression\r
2940 #\r
2941 # @retval list The token list of the dependency expression after parsed\r
2942 #\r
2943 def _GetDepexExpressionTokenList(self):\r
2944 if self._DepexExpressionList == None:\r
2945 self._DepexExpressionList = {}\r
2946 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
2947 return self._DepexExpressionList\r
2948\r
2949 self._DepexExpressionList[self.ModuleType] = ''\r
2950\r
2951 for ModuleType in self._DepexExpressionList:\r
2952 DepexExpressionList = self._DepexExpressionList[ModuleType]\r
2953 #\r
2954 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2955 #\r
2956 for M in [self.Module] + self.DependentLibraryList:\r
2957 Inherited = False\r
2958 for D in M.DepexExpression[self.Arch, ModuleType]:\r
2959 if DepexExpressionList != '':\r
2960 DepexExpressionList += ' AND '\r
2961 DepexExpressionList += '('\r
2962 DepexExpressionList += D\r
2963 DepexExpressionList = DepexExpressionList.rstrip('END').strip()\r
2964 DepexExpressionList += ')'\r
2965 Inherited = True\r
2966 if Inherited:\r
2967 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionList))\r
2968 if 'BEFORE' in DepexExpressionList or 'AFTER' in DepexExpressionList:\r
2969 break\r
2970 if len(DepexExpressionList) > 0:\r
2971 EdkLogger.verbose('')\r
2972 self._DepexExpressionList[ModuleType] = DepexExpressionList\r
2973 return self._DepexExpressionList\r
2974\r
2975 ## Return the list of specification version required for the module\r
2976 #\r
2977 # @retval list The list of specification defined in module file\r
2978 #\r
2979 def _GetSpecification(self):\r
2980 return self.Module.Specification\r
2981\r
2982 ## Tool option for the module build\r
2983 #\r
2984 # @param PlatformInfo The object of PlatformBuildInfo\r
2985 # @retval dict The dict containing valid options\r
2986 #\r
2987 def _GetModuleBuildOption(self):\r
2988 if self._BuildOption == None:\r
2989 self._BuildOption, self.BuildRuleOrder = self.PlatformInfo.ApplyBuildOption(self.Module)\r
2990 if self.BuildRuleOrder:\r
2991 self.BuildRuleOrder = ['.%s' % Ext for Ext in self.BuildRuleOrder.split()]\r
2992 return self._BuildOption\r
2993\r
2994 ## Get include path list from tool option for the module build\r
2995 #\r
2996 # @retval list The include path list\r
2997 #\r
2998 def _GetBuildOptionIncPathList(self):\r
2999 if self._BuildOptionIncPathList == None:\r
3000 #\r
3001 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
3002 # is the former use /I , the Latter used -I to specify include directories\r
3003 #\r
3004 if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
3005 gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
3006 elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
3007 gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
3008 else:\r
3009 #\r
3010 # New ToolChainFamily, don't known whether there is option to specify include directories\r
3011 #\r
3012 self._BuildOptionIncPathList = []\r
3013 return self._BuildOptionIncPathList\r
3014 \r
3015 BuildOptionIncPathList = []\r
3016 for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):\r
3017 Attr = 'FLAGS'\r
3018 try:\r
3019 FlagOption = self.BuildOption[Tool][Attr]\r
3020 except KeyError:\r
3021 FlagOption = ''\r
3022 \r
3023 if self.PlatformInfo.ToolChainFamily != 'RVCT':\r
3024 IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]\r
3025 else:\r
3026 #\r
3027 # RVCT may specify a list of directory seperated by commas\r
3028 #\r
3029 IncPathList = []\r
3030 for Path in gBuildOptIncludePattern.findall(FlagOption):\r
3031 PathList = GetSplitList(Path, TAB_COMMA_SPLIT)\r
3032 IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList]\r
3033\r
3034 #\r
3035 # EDK II modules must not reference header files outside of the packages they depend on or \r
3036 # within the module's directory tree. Report error if violation.\r
3037 #\r
3038 if self.AutoGenVersion >= 0x00010005 and len(IncPathList) > 0:\r
3039 for Path in IncPathList:\r
3040 if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r
3041 ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)\r
3042 EdkLogger.error("build",\r
3043 PARAMETER_INVALID,\r
3044 ExtraData=ErrMsg,\r
3045 File=str(self.MetaFile))\r
3046\r
3047 \r
3048 BuildOptionIncPathList += IncPathList\r
3049 \r
3050 self._BuildOptionIncPathList = BuildOptionIncPathList\r
3051 \r
3052 return self._BuildOptionIncPathList\r
3053 \r
3054 ## Return a list of files which can be built from source\r
3055 #\r
3056 # What kind of files can be built is determined by build rules in\r
3057 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.\r
3058 #\r
3059 def _GetSourceFileList(self):\r
3060 if self._SourceFileList == None:\r
3061 self._SourceFileList = []\r
3062 for F in self.Module.Sources:\r
3063 # match tool chain\r
3064 if F.TagName not in ("", "*", self.ToolChain):\r
3065 EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "\r
3066 "but [%s] is needed" % (F.TagName, str(F), self.ToolChain))\r
3067 continue\r
3068 # match tool chain family\r
3069 if F.ToolChainFamily not in ("", "*", self.ToolChainFamily):\r
3070 EdkLogger.debug(\r
3071 EdkLogger.DEBUG_0,\r
3072 "The file [%s] must be built by tools of [%s], " \\r
3073 "but current toolchain family is [%s]" \\r
3074 % (str(F), F.ToolChainFamily, self.ToolChainFamily))\r
3075 continue\r
3076\r
3077 # add the file path into search path list for file including\r
3078 if F.Dir not in self.IncludePathList and self.AutoGenVersion >= 0x00010005:\r
3079 self.IncludePathList.insert(0, F.Dir)\r
3080 self._SourceFileList.append(F)\r
3081\r
3082 self._MatchBuildRuleOrder(self._SourceFileList)\r
3083\r
3084 for F in self._SourceFileList:\r
3085 self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)\r
3086 return self._SourceFileList\r
3087\r
3088 def _MatchBuildRuleOrder(self, FileList):\r
3089 Order_Dict = {}\r
3090 self._GetModuleBuildOption()\r
3091 for SingleFile in FileList:\r
3092 if self.BuildRuleOrder and SingleFile.Ext in self.BuildRuleOrder and SingleFile.Ext in self.BuildRules:\r
3093 key = SingleFile.Path.split(SingleFile.Ext)[0]\r
3094 if key in Order_Dict:\r
3095 Order_Dict[key].append(SingleFile.Ext)\r
3096 else:\r
3097 Order_Dict[key] = [SingleFile.Ext]\r
3098\r
3099 RemoveList = []\r
3100 for F in Order_Dict:\r
3101 if len(Order_Dict[F]) > 1:\r
3102 Order_Dict[F].sort(key=lambda i: self.BuildRuleOrder.index(i))\r
3103 for Ext in Order_Dict[F][1:]:\r
3104 RemoveList.append(F + Ext)\r
3105 \r
3106 for item in RemoveList:\r
3107 FileList.remove(item)\r
3108\r
3109 return FileList\r
3110\r
3111 ## Return the list of unicode files\r
3112 def _GetUnicodeFileList(self):\r
3113 if self._UnicodeFileList == None:\r
3114 if TAB_UNICODE_FILE in self.FileTypes:\r
3115 self._UnicodeFileList = self.FileTypes[TAB_UNICODE_FILE]\r
3116 else:\r
3117 self._UnicodeFileList = []\r
3118 return self._UnicodeFileList\r
3119\r
3120 ## Return the list of vfr files\r
3121 def _GetVfrFileList(self):\r
3122 if self._VfrFileList == None:\r
3123 if TAB_VFR_FILE in self.FileTypes:\r
3124 self._VfrFileList = self.FileTypes[TAB_VFR_FILE]\r
3125 else:\r
3126 self._VfrFileList = []\r
3127 return self._VfrFileList\r
3128\r
3129 ## Return the list of Image Definition files\r
3130 def _GetIdfFileList(self):\r
3131 if self._IdfFileList == None:\r
3132 if TAB_IMAGE_FILE in self.FileTypes:\r
3133 self._IdfFileList = self.FileTypes[TAB_IMAGE_FILE]\r
3134 else:\r
3135 self._IdfFileList = []\r
3136 return self._IdfFileList\r
3137\r
3138 ## Return a list of files which can be built from binary\r
3139 #\r
3140 # "Build" binary files are just to copy them to build directory.\r
3141 #\r
3142 # @retval list The list of files which can be built later\r
3143 #\r
3144 def _GetBinaryFiles(self):\r
3145 if self._BinaryFileList == None:\r
3146 self._BinaryFileList = []\r
3147 for F in self.Module.Binaries:\r
3148 if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget:\r
3149 continue\r
3150 self._BinaryFileList.append(F)\r
3151 self._ApplyBuildRule(F, F.Type)\r
3152 return self._BinaryFileList\r
3153\r
3154 def _GetBuildRules(self):\r
3155 if self._BuildRules == None:\r
3156 BuildRules = {}\r
3157 BuildRuleDatabase = self.PlatformInfo.BuildRule\r
3158 for Type in BuildRuleDatabase.FileTypeList:\r
3159 #first try getting build rule by BuildRuleFamily\r
3160 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]\r
3161 if not RuleObject:\r
3162 # build type is always module type, but ...\r
3163 if self.ModuleType != self.BuildType:\r
3164 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]\r
3165 #second try getting build rule by ToolChainFamily\r
3166 if not RuleObject:\r
3167 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]\r
3168 if not RuleObject:\r
3169 # build type is always module type, but ...\r
3170 if self.ModuleType != self.BuildType:\r
3171 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]\r
3172 if not RuleObject:\r
3173 continue\r
3174 RuleObject = RuleObject.Instantiate(self.Macros)\r
3175 BuildRules[Type] = RuleObject\r
3176 for Ext in RuleObject.SourceFileExtList:\r
3177 BuildRules[Ext] = RuleObject\r
3178 self._BuildRules = BuildRules\r
3179 return self._BuildRules\r
3180\r
3181 def _ApplyBuildRule(self, File, FileType):\r
3182 if self._BuildTargets == None:\r
3183 self._IntroBuildTargetList = set()\r
3184 self._FinalBuildTargetList = set()\r
3185 self._BuildTargets = {}\r
3186 self._FileTypes = {}\r
3187\r
3188 SubDirectory = os.path.join(self.OutputDir, File.SubDir)\r
3189 if not os.path.exists(SubDirectory):\r
3190 CreateDirectory(SubDirectory)\r
3191 LastTarget = None\r
3192 RuleChain = []\r
3193 SourceList = [File]\r
3194 Index = 0\r
3195 #\r
3196 # Make sure to get build rule order value\r
3197 #\r
3198 self._GetModuleBuildOption()\r
3199\r
3200 while Index < len(SourceList):\r
3201 Source = SourceList[Index]\r
3202 Index = Index + 1\r
3203\r
3204 if Source != File:\r
3205 CreateDirectory(Source.Dir)\r
3206\r
3207 if File.IsBinary and File == Source and self._BinaryFileList != None and File in self._BinaryFileList:\r
3208 # Skip all files that are not binary libraries\r
3209 if not self.IsLibrary:\r
3210 continue\r
3211 RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]\r
3212 elif FileType in self.BuildRules:\r
3213 RuleObject = self.BuildRules[FileType]\r
3214 elif Source.Ext in self.BuildRules:\r
3215 RuleObject = self.BuildRules[Source.Ext]\r
3216 else:\r
3217 # stop at no more rules\r
3218 if LastTarget:\r
3219 self._FinalBuildTargetList.add(LastTarget)\r
3220 break\r
3221\r
3222 FileType = RuleObject.SourceFileType\r
3223 if FileType not in self._FileTypes:\r
3224 self._FileTypes[FileType] = set()\r
3225 self._FileTypes[FileType].add(Source)\r
3226\r
3227 # stop at STATIC_LIBRARY for library\r
3228 if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:\r
3229 if LastTarget:\r
3230 self._FinalBuildTargetList.add(LastTarget)\r
3231 break\r
3232\r
3233 Target = RuleObject.Apply(Source, self.BuildRuleOrder)\r
3234 if not Target:\r
3235 if LastTarget:\r
3236 self._FinalBuildTargetList.add(LastTarget)\r
3237 break\r
3238 elif not Target.Outputs:\r
3239 # Only do build for target with outputs\r
3240 self._FinalBuildTargetList.add(Target)\r
3241\r
3242 if FileType not in self._BuildTargets:\r
3243 self._BuildTargets[FileType] = set()\r
3244 self._BuildTargets[FileType].add(Target)\r
3245\r
3246 if not Source.IsBinary and Source == File:\r
3247 self._IntroBuildTargetList.add(Target)\r
3248\r
3249 # to avoid cyclic rule\r
3250 if FileType in RuleChain:\r
3251 break\r
3252\r
3253 RuleChain.append(FileType)\r
3254 SourceList.extend(Target.Outputs)\r
3255 LastTarget = Target\r
3256 FileType = TAB_UNKNOWN_FILE\r
3257\r
3258 def _GetTargets(self):\r
3259 if self._BuildTargets == None:\r
3260 self._IntroBuildTargetList = set()\r
3261 self._FinalBuildTargetList = set()\r
3262 self._BuildTargets = {}\r
3263 self._FileTypes = {}\r
3264\r
3265 #TRICK: call _GetSourceFileList to apply build rule for source files\r
3266 if self.SourceFileList:\r
3267 pass\r
3268\r
3269 #TRICK: call _GetBinaryFileList to apply build rule for binary files\r
3270 if self.BinaryFileList:\r
3271 pass\r
3272\r
3273 return self._BuildTargets\r
3274\r
3275 def _GetIntroTargetList(self):\r
3276 self._GetTargets()\r
3277 return self._IntroBuildTargetList\r
3278\r
3279 def _GetFinalTargetList(self):\r
3280 self._GetTargets()\r
3281 return self._FinalBuildTargetList\r
3282\r
3283 def _GetFileTypes(self):\r
3284 self._GetTargets()\r
3285 return self._FileTypes\r
3286\r
3287 ## Get the list of package object the module depends on\r
3288 #\r
3289 # @retval list The package object list\r
3290 #\r
3291 def _GetDependentPackageList(self):\r
3292 return self.Module.Packages\r
3293\r
3294 ## Return the list of auto-generated code file\r
3295 #\r
3296 # @retval list The list of auto-generated file\r
3297 #\r
3298 def _GetAutoGenFileList(self):\r
3299 UniStringAutoGenC = True\r
3300 IdfStringAutoGenC = True\r
3301 UniStringBinBuffer = StringIO()\r
3302 IdfGenBinBuffer = StringIO()\r
3303 if self.BuildType == 'UEFI_HII':\r
3304 UniStringAutoGenC = False\r
3305 IdfStringAutoGenC = False\r
3306 if self._AutoGenFileList == None:\r
3307 self._AutoGenFileList = {}\r
3308 AutoGenC = TemplateString()\r
3309 AutoGenH = TemplateString()\r
3310 StringH = TemplateString()\r
3311 StringIdf = TemplateString()\r
3312 GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer, StringIdf, IdfStringAutoGenC, IdfGenBinBuffer)\r
3313 #\r
3314 # AutoGen.c is generated if there are library classes in inf, or there are object files\r
3315 #\r
3316 if str(AutoGenC) != "" and (len(self.Module.LibraryClasses) > 0\r
3317 or TAB_OBJECT_FILE in self.FileTypes):\r
3318 AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)\r
3319 self._AutoGenFileList[AutoFile] = str(AutoGenC)\r
3320 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3321 if str(AutoGenH) != "":\r
3322 AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)\r
3323 self._AutoGenFileList[AutoFile] = str(AutoGenH)\r
3324 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3325 if str(StringH) != "":\r
3326 AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)\r
3327 self._AutoGenFileList[AutoFile] = str(StringH)\r
3328 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3329 if UniStringBinBuffer != None and UniStringBinBuffer.getvalue() != "":\r
3330 AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)\r
3331 self._AutoGenFileList[AutoFile] = UniStringBinBuffer.getvalue()\r
3332 AutoFile.IsBinary = True\r
3333 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3334 if UniStringBinBuffer != None:\r
3335 UniStringBinBuffer.close()\r
3336 if str(StringIdf) != "":\r
3337 AutoFile = PathClass(gAutoGenImageDefFileName % {"module_name":self.Name}, self.DebugDir)\r
3338 self._AutoGenFileList[AutoFile] = str(StringIdf)\r
3339 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3340 if IdfGenBinBuffer != None and IdfGenBinBuffer.getvalue() != "":\r
3341 AutoFile = PathClass(gAutoGenIdfFileName % {"module_name":self.Name}, self.OutputDir)\r
3342 self._AutoGenFileList[AutoFile] = IdfGenBinBuffer.getvalue()\r
3343 AutoFile.IsBinary = True\r
3344 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3345 if IdfGenBinBuffer != None:\r
3346 IdfGenBinBuffer.close()\r
3347 return self._AutoGenFileList\r
3348\r
3349 ## Return the list of library modules explicitly or implicityly used by this module\r
3350 def _GetLibraryList(self):\r
3351 if self._DependentLibraryList == None:\r
3352 # only merge library classes and PCD for non-library module\r
3353 if self.IsLibrary:\r
3354 self._DependentLibraryList = []\r
3355 else:\r
3356 if self.AutoGenVersion < 0x00010005:\r
3357 self._DependentLibraryList = self.PlatformInfo.ResolveLibraryReference(self.Module)\r
3358 else:\r
3359 self._DependentLibraryList = self.PlatformInfo.ApplyLibraryInstance(self.Module)\r
3360 return self._DependentLibraryList\r
3361\r
3362 @staticmethod\r
3363 def UpdateComments(Recver, Src):\r
3364 for Key in Src:\r
3365 if Key not in Recver:\r
3366 Recver[Key] = []\r
3367 Recver[Key].extend(Src[Key])\r
3368 ## Get the list of PCDs from current module\r
3369 #\r
3370 # @retval list The list of PCD\r
3371 #\r
3372 def _GetModulePcdList(self):\r
3373 if self._ModulePcdList == None:\r
3374 # apply PCD settings from platform\r
3375 self._ModulePcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, self.Module.Pcds)\r
3376 self.UpdateComments(self._PcdComments, self.Module.PcdComments)\r
3377 return self._ModulePcdList\r
3378\r
3379 ## Get the list of PCDs from dependent libraries\r
3380 #\r
3381 # @retval list The list of PCD\r
3382 #\r
3383 def _GetLibraryPcdList(self):\r
3384 if self._LibraryPcdList == None:\r
3385 Pcds = sdict()\r
3386 if not self.IsLibrary:\r
3387 # get PCDs from dependent libraries\r
3388 for Library in self.DependentLibraryList:\r
3389 self.UpdateComments(self._PcdComments, Library.PcdComments)\r
3390 for Key in Library.Pcds:\r
3391 # skip duplicated PCDs\r
3392 if Key in self.Module.Pcds or Key in Pcds:\r
3393 continue\r
3394 Pcds[Key] = copy.copy(Library.Pcds[Key])\r
3395 # apply PCD settings from platform\r
3396 self._LibraryPcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, Pcds)\r
3397 else:\r
3398 self._LibraryPcdList = []\r
3399 return self._LibraryPcdList\r
3400\r
3401 ## Get the GUID value mapping\r
3402 #\r
3403 # @retval dict The mapping between GUID cname and its value\r
3404 #\r
3405 def _GetGuidList(self):\r
3406 if self._GuidList == None:\r
3407 self._GuidList = sdict()\r
3408 self._GuidList.update(self.Module.Guids)\r
3409 for Library in self.DependentLibraryList:\r
3410 self._GuidList.update(Library.Guids)\r
3411 self.UpdateComments(self._GuidComments, Library.GuidComments)\r
3412 self.UpdateComments(self._GuidComments, self.Module.GuidComments)\r
3413 return self._GuidList\r
3414\r
3415 def GetGuidsUsedByPcd(self):\r
3416 if self._GuidsUsedByPcd == None:\r
3417 self._GuidsUsedByPcd = sdict()\r
3418 self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd())\r
3419 for Library in self.DependentLibraryList:\r
3420 self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd())\r
3421 return self._GuidsUsedByPcd\r
3422 ## Get the protocol value mapping\r
3423 #\r
3424 # @retval dict The mapping between protocol cname and its value\r
3425 #\r
3426 def _GetProtocolList(self):\r
3427 if self._ProtocolList == None:\r
3428 self._ProtocolList = sdict()\r
3429 self._ProtocolList.update(self.Module.Protocols)\r
3430 for Library in self.DependentLibraryList:\r
3431 self._ProtocolList.update(Library.Protocols)\r
3432 self.UpdateComments(self._ProtocolComments, Library.ProtocolComments)\r
3433 self.UpdateComments(self._ProtocolComments, self.Module.ProtocolComments)\r
3434 return self._ProtocolList\r
3435\r
3436 ## Get the PPI value mapping\r
3437 #\r
3438 # @retval dict The mapping between PPI cname and its value\r
3439 #\r
3440 def _GetPpiList(self):\r
3441 if self._PpiList == None:\r
3442 self._PpiList = sdict()\r
3443 self._PpiList.update(self.Module.Ppis)\r
3444 for Library in self.DependentLibraryList:\r
3445 self._PpiList.update(Library.Ppis)\r
3446 self.UpdateComments(self._PpiComments, Library.PpiComments)\r
3447 self.UpdateComments(self._PpiComments, self.Module.PpiComments)\r
3448 return self._PpiList\r
3449\r
3450 ## Get the list of include search path\r
3451 #\r
3452 # @retval list The list path\r
3453 #\r
3454 def _GetIncludePathList(self):\r
3455 if self._IncludePathList == None:\r
3456 self._IncludePathList = []\r
3457 if self.AutoGenVersion < 0x00010005:\r
3458 for Inc in self.Module.Includes:\r
3459 if Inc not in self._IncludePathList:\r
3460 self._IncludePathList.append(Inc)\r
3461 # for Edk modules\r
3462 Inc = path.join(Inc, self.Arch.capitalize())\r
3463 if os.path.exists(Inc) and Inc not in self._IncludePathList:\r
3464 self._IncludePathList.append(Inc)\r
3465 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time\r
3466 self._IncludePathList.append(self.DebugDir)\r
3467 else:\r
3468 self._IncludePathList.append(self.MetaFile.Dir)\r
3469 self._IncludePathList.append(self.DebugDir)\r
3470\r
3471 for Package in self.Module.Packages:\r
3472 PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)\r
3473 if PackageDir not in self._IncludePathList:\r
3474 self._IncludePathList.append(PackageDir)\r
3475 IncludesList = Package.Includes\r
3476 if Package._PrivateIncludes:\r
3477 if not self.MetaFile.Path.startswith(PackageDir):\r
3478 IncludesList = list(set(Package.Includes).difference(set(Package._PrivateIncludes)))\r
3479 for Inc in IncludesList:\r
3480 if Inc not in self._IncludePathList:\r
3481 self._IncludePathList.append(str(Inc))\r
3482 return self._IncludePathList\r
3483\r
3484 def _GetIncludePathLength(self):\r
3485 self._IncludePathLength = 0\r
3486 if self._IncludePathList:\r
3487 for inc in self._IncludePathList:\r
3488 self._IncludePathLength += len(' ' + inc)\r
3489 return self._IncludePathLength\r
3490\r
3491 ## Get HII EX PCDs which maybe used by VFR\r
3492 #\r
3493 # efivarstore used by VFR may relate with HII EX PCDs\r
3494 # Get the variable name and GUID from efivarstore and HII EX PCD\r
3495 # List the HII EX PCDs in As Built INF if both name and GUID match.\r
3496 #\r
3497 # @retval list HII EX PCDs\r
3498 #\r
3499 def _GetPcdsMaybeUsedByVfr(self):\r
3500 if not self.SourceFileList:\r
3501 return []\r
3502\r
3503 NameGuids = []\r
3504 for SrcFile in self.SourceFileList:\r
3505 if SrcFile.Ext.lower() != '.vfr':\r
3506 continue\r
3507 Vfri = os.path.join(self.OutputDir, SrcFile.BaseName + '.i')\r
3508 if not os.path.exists(Vfri):\r
3509 continue\r
3510 VfriFile = open(Vfri, 'r')\r
3511 Content = VfriFile.read()\r
3512 VfriFile.close()\r
3513 Pos = Content.find('efivarstore')\r
3514 while Pos != -1:\r
3515 #\r
3516 # Make sure 'efivarstore' is the start of efivarstore statement\r
3517 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'\r
3518 #\r
3519 Index = Pos - 1\r
3520 while Index >= 0 and Content[Index] in ' \t\r\n':\r
3521 Index -= 1\r
3522 if Index >= 0 and Content[Index] != ';':\r
3523 Pos = Content.find('efivarstore', Pos + len('efivarstore'))\r
3524 continue\r
3525 #\r
3526 # 'efivarstore' must be followed by name and guid\r
3527 #\r
3528 Name = gEfiVarStoreNamePattern.search(Content, Pos)\r
3529 if not Name:\r
3530 break\r
3531 Guid = gEfiVarStoreGuidPattern.search(Content, Pos)\r
3532 if not Guid:\r
3533 break\r
3534 NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')\r
3535 NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
3536 Pos = Content.find('efivarstore', Name.end())\r
3537 if not NameGuids:\r
3538 return []\r
3539 HiiExPcds = []\r
3540 for Pcd in self.PlatformInfo.Platform.Pcds.values():\r
3541 if Pcd.Type != TAB_PCDS_DYNAMIC_EX_HII:\r
3542 continue\r
3543 for SkuName in Pcd.SkuInfoList:\r
3544 SkuInfo = Pcd.SkuInfoList[SkuName]\r
3545 Name = ConvertStringToByteArray(SkuInfo.VariableName)\r
3546 Value = GuidValue(SkuInfo.VariableGuid, self.PlatformInfo.PackageList, self.MetaFile.Path)\r
3547 if not Value:\r
3548 continue\r
3549 Guid = GuidStructureStringToGuidString(Value)\r
3550 if (Name, Guid) in NameGuids and Pcd not in HiiExPcds:\r
3551 HiiExPcds.append(Pcd)\r
3552 break\r
3553\r
3554 return HiiExPcds\r
3555\r
3556 def _GenOffsetBin(self):\r
3557 VfrUniBaseName = {}\r
3558 for SourceFile in self.Module.Sources:\r
3559 if SourceFile.Type.upper() == ".VFR" :\r
3560 #\r
3561 # search the .map file to find the offset of vfr binary in the PE32+/TE file. \r
3562 #\r
3563 VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")\r
3564 if SourceFile.Type.upper() == ".UNI" :\r
3565 #\r
3566 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file. \r
3567 #\r
3568 VfrUniBaseName["UniOffsetName"] = (self.Name + "Strings")\r
3569\r
3570 if len(VfrUniBaseName) == 0:\r
3571 return None\r
3572 MapFileName = os.path.join(self.OutputDir, self.Name + ".map")\r
3573 EfiFileName = os.path.join(self.OutputDir, self.Name + ".efi")\r
3574 VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, VfrUniBaseName.values())\r
3575 if not VfrUniOffsetList:\r
3576 return None\r
3577\r
3578 OutputName = '%sOffset.bin' % self.Name\r
3579 UniVfrOffsetFileName = os.path.join( self.OutputDir, OutputName)\r
3580\r
3581 try:\r
3582 fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r
3583 except:\r
3584 EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName,None)\r
3585\r
3586 # Use a instance of StringIO to cache data\r
3587 fStringIO = StringIO('') \r
3588\r
3589 for Item in VfrUniOffsetList:\r
3590 if (Item[0].find("Strings") != -1):\r
3591 #\r
3592 # UNI offset in image.\r
3593 # GUID + Offset\r
3594 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r
3595 #\r
3596 UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]\r
3597 UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]\r
3598 fStringIO.write(''.join(UniGuid)) \r
3599 UniValue = pack ('Q', int (Item[1], 16))\r
3600 fStringIO.write (UniValue)\r
3601 else:\r
3602 #\r
3603 # VFR binary offset in image.\r
3604 # GUID + Offset\r
3605 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r
3606 #\r
3607 VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]\r
3608 VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]\r
3609 fStringIO.write(''.join(VfrGuid)) \r
3610 type (Item[1]) \r
3611 VfrValue = pack ('Q', int (Item[1], 16))\r
3612 fStringIO.write (VfrValue)\r
3613 #\r
3614 # write data into file.\r
3615 #\r
3616 try : \r
3617 fInputfile.write (fStringIO.getvalue())\r
3618 except:\r
3619 EdkLogger.error("build", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the "\r
3620 "file been locked or using by other applications." %UniVfrOffsetFileName,None)\r
3621\r
3622 fStringIO.close ()\r
3623 fInputfile.close ()\r
3624 return OutputName\r
3625\r
3626 ## Create AsBuilt INF file the module\r
3627 #\r
3628 def CreateAsBuiltInf(self):\r
3629 if self.IsAsBuiltInfCreated:\r
3630 return\r
3631 \r
3632 # Skip the following code for EDK I inf\r
3633 if self.AutoGenVersion < 0x00010005:\r
3634 return\r
3635 \r
3636 # Skip the following code for libraries\r
3637 if self.IsLibrary:\r
3638 return\r
3639 \r
3640 # Skip the following code for modules with no source files\r
3641 if self.SourceFileList == None or self.SourceFileList == []:\r
3642 return\r
3643\r
3644 # Skip the following code for modules without any binary files\r
3645 if self.BinaryFileList <> None and self.BinaryFileList <> []:\r
3646 return\r
3647 \r
3648 ### TODO: How to handles mixed source and binary modules\r
3649\r
3650 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries\r
3651 # Also find all packages that the DynamicEx PCDs depend on\r
3652 Pcds = []\r
3653 PatchablePcds = []\r
3654 Packages = []\r
3655 PcdCheckList = []\r
3656 PcdTokenSpaceList = []\r
3657 for Pcd in self.ModulePcdList + self.LibraryPcdList:\r
3658 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
3659 PatchablePcds += [Pcd]\r
3660 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'PatchableInModule'))\r
3661 elif Pcd.Type in GenC.gDynamicExPcd:\r
3662 if Pcd not in Pcds:\r
3663 Pcds += [Pcd]\r
3664 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx'))\r
3665 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic'))\r
3666 PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r
3667 GuidList = sdict()\r
3668 GuidList.update(self.GuidList)\r
3669 for TokenSpace in self.GetGuidsUsedByPcd():\r
3670 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list\r
3671 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs\r
3672 if TokenSpace not in PcdTokenSpaceList and TokenSpace in GuidList:\r
3673 GuidList.pop(TokenSpace)\r
3674 CheckList = (GuidList, self.PpiList, self.ProtocolList, PcdCheckList)\r
3675 for Package in self.DerivedPackageList:\r
3676 if Package in Packages:\r
3677 continue\r
3678 BeChecked = (Package.Guids, Package.Ppis, Package.Protocols, Package.Pcds)\r
3679 Found = False\r
3680 for Index in range(len(BeChecked)):\r
3681 for Item in CheckList[Index]:\r
3682 if Item in BeChecked[Index]:\r
3683 Packages += [Package]\r
3684 Found = True\r
3685 break\r
3686 if Found: break\r
3687\r
3688 VfrPcds = self._GetPcdsMaybeUsedByVfr()\r
3689 for Pkg in self.PlatformInfo.PackageList:\r
3690 if Pkg in Packages:\r
3691 continue\r
3692 for VfrPcd in VfrPcds:\r
3693 if ((VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'DynamicEx') in Pkg.Pcds or\r
3694 (VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'Dynamic') in Pkg.Pcds):\r
3695 Packages += [Pkg]\r
3696 break\r
3697\r
3698 ModuleType = self.ModuleType\r
3699 if ModuleType == 'UEFI_DRIVER' and self.DepexGenerated:\r
3700 ModuleType = 'DXE_DRIVER'\r
3701\r
3702 DriverType = ''\r
3703 if self.PcdIsDriver != '':\r
3704 DriverType = self.PcdIsDriver\r
3705\r
3706 Guid = self.Guid\r
3707 MDefs = self.Module.Defines\r
3708\r
3709 AsBuiltInfDict = {\r
3710 'module_name' : self.Name,\r
3711 'module_guid' : Guid,\r
3712 'module_module_type' : ModuleType,\r
3713 'module_version_string' : [MDefs['VERSION_STRING']] if 'VERSION_STRING' in MDefs else [],\r
3714 'pcd_is_driver_string' : [],\r
3715 'module_uefi_specification_version' : [],\r
3716 'module_pi_specification_version' : [],\r
3717 'module_entry_point' : self.Module.ModuleEntryPointList,\r
3718 'module_unload_image' : self.Module.ModuleUnloadImageList,\r
3719 'module_constructor' : self.Module.ConstructorList,\r
3720 'module_destructor' : self.Module.DestructorList,\r
3721 'module_shadow' : [MDefs['SHADOW']] if 'SHADOW' in MDefs else [],\r
3722 'module_pci_vendor_id' : [MDefs['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs else [],\r
3723 'module_pci_device_id' : [MDefs['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs else [],\r
3724 'module_pci_class_code' : [MDefs['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs else [],\r
3725 'module_pci_revision' : [MDefs['PCI_REVISION']] if 'PCI_REVISION' in MDefs else [],\r
3726 'module_build_number' : [MDefs['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs else [],\r
3727 'module_spec' : [MDefs['SPEC']] if 'SPEC' in MDefs else [],\r
3728 'module_uefi_hii_resource_section' : [MDefs['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs else [],\r
3729 'module_uni_file' : [MDefs['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs else [],\r
3730 'module_arch' : self.Arch,\r
3731 'package_item' : ['%s' % (Package.MetaFile.File.replace('\\', '/')) for Package in Packages],\r
3732 'binary_item' : [],\r
3733 'patchablepcd_item' : [],\r
3734 'pcd_item' : [],\r
3735 'protocol_item' : [],\r
3736 'ppi_item' : [],\r
3737 'guid_item' : [],\r
3738 'flags_item' : [],\r
3739 'libraryclasses_item' : []\r
3740 }\r
3741\r
3742 if self.AutoGenVersion > int(gInfSpecVersion, 0):\r
3743 AsBuiltInfDict['module_inf_version'] = '0x%08x' % self.AutoGenVersion\r
3744 else:\r
3745 AsBuiltInfDict['module_inf_version'] = gInfSpecVersion\r
3746\r
3747 if DriverType:\r
3748 AsBuiltInfDict['pcd_is_driver_string'] += [DriverType]\r
3749\r
3750 if 'UEFI_SPECIFICATION_VERSION' in self.Specification:\r
3751 AsBuiltInfDict['module_uefi_specification_version'] += [self.Specification['UEFI_SPECIFICATION_VERSION']]\r
3752 if 'PI_SPECIFICATION_VERSION' in self.Specification:\r
3753 AsBuiltInfDict['module_pi_specification_version'] += [self.Specification['PI_SPECIFICATION_VERSION']]\r
3754\r
3755 OutputDir = self.OutputDir.replace('\\', '/').strip('/')\r
3756\r
3757 for Item in self.CodaTargetList:\r
3758 File = Item.Target.Path.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')\r
3759 if Item.Target.Ext.lower() == '.aml':\r
3760 AsBuiltInfDict['binary_item'] += ['ASL|' + File]\r
3761 elif Item.Target.Ext.lower() == '.acpi':\r
3762 AsBuiltInfDict['binary_item'] += ['ACPI|' + File]\r
3763 elif Item.Target.Ext.lower() == '.efi':\r
3764 AsBuiltInfDict['binary_item'] += ['PE32|' + self.Name + '.efi']\r
3765 else:\r
3766 AsBuiltInfDict['binary_item'] += ['BIN|' + File]\r
3767 if self.DepexGenerated:\r
3768 if self.ModuleType in ['PEIM']:\r
3769 AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']\r
3770 if self.ModuleType in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:\r
3771 AsBuiltInfDict['binary_item'] += ['DXE_DEPEX|' + self.Name + '.depex']\r
3772 if self.ModuleType in ['DXE_SMM_DRIVER']:\r
3773 AsBuiltInfDict['binary_item'] += ['SMM_DEPEX|' + self.Name + '.depex']\r
3774\r
3775 Bin = self._GenOffsetBin()\r
3776 if Bin:\r
3777 AsBuiltInfDict['binary_item'] += ['BIN|%s' % Bin]\r
3778\r
3779 for Root, Dirs, Files in os.walk(OutputDir):\r
3780 for File in Files:\r
3781 if File.lower().endswith('.pdb'):\r
3782 AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File]\r
3783 HeaderComments = self.Module.HeaderComments\r
3784 StartPos = 0\r
3785 for Index in range(len(HeaderComments)):\r
3786 if HeaderComments[Index].find('@BinaryHeader') != -1:\r
3787 HeaderComments[Index] = HeaderComments[Index].replace('@BinaryHeader', '@file')\r
3788 StartPos = Index\r
3789 break\r
3790 AsBuiltInfDict['header_comments'] = '\n'.join(HeaderComments[StartPos:]).replace(':#', '://')\r
3791 AsBuiltInfDict['tail_comments'] = '\n'.join(self.Module.TailComments)\r
3792\r
3793 GenList = [\r
3794 (self.ProtocolList, self._ProtocolComments, 'protocol_item'),\r
3795 (self.PpiList, self._PpiComments, 'ppi_item'),\r
3796 (GuidList, self._GuidComments, 'guid_item')\r
3797 ]\r
3798 for Item in GenList:\r
3799 for CName in Item[0]:\r
3800 Comments = ''\r
3801 if CName in Item[1]:\r
3802 Comments = '\n '.join(Item[1][CName])\r
3803 Entry = CName\r
3804 if Comments:\r
3805 Entry = Comments + '\n ' + CName\r
3806 AsBuiltInfDict[Item[2]].append(Entry)\r
3807 PatchList = parsePcdInfoFromMapFile(\r
3808 os.path.join(self.OutputDir, self.Name + '.map'),\r
3809 os.path.join(self.OutputDir, self.Name + '.efi')\r
3810 )\r
3811 if PatchList:\r
3812 for Pcd in PatchablePcds:\r
3813 TokenCName = Pcd.TokenCName\r
3814 for PcdItem in GlobalData.MixedPcd:\r
3815 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
3816 TokenCName = PcdItem[0]\r
3817 break\r
3818 for PatchPcd in PatchList:\r
3819 if TokenCName == PatchPcd[0]:\r
3820 break\r
3821 else:\r
3822 continue\r
3823 PcdValue = ''\r
3824 if Pcd.DatumType != 'VOID*':\r
3825 HexFormat = '0x%02x'\r
3826 if Pcd.DatumType == 'UINT16':\r
3827 HexFormat = '0x%04x'\r
3828 elif Pcd.DatumType == 'UINT32':\r
3829 HexFormat = '0x%08x'\r
3830 elif Pcd.DatumType == 'UINT64':\r
3831 HexFormat = '0x%016x'\r
3832 PcdValue = HexFormat % int(Pcd.DefaultValue, 0)\r
3833 else:\r
3834 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
3835 EdkLogger.error("build", AUTOGEN_ERROR,\r
3836 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName)\r
3837 )\r
3838 ArraySize = int(Pcd.MaxDatumSize, 0)\r
3839 PcdValue = Pcd.DefaultValue\r
3840 if PcdValue[0] != '{':\r
3841 Unicode = False\r
3842 if PcdValue[0] == 'L':\r
3843 Unicode = True\r
3844 PcdValue = PcdValue.lstrip('L')\r
3845 PcdValue = eval(PcdValue)\r
3846 NewValue = '{'\r
3847 for Index in range(0, len(PcdValue)):\r
3848 if Unicode:\r
3849 CharVal = ord(PcdValue[Index])\r
3850 NewValue = NewValue + '0x%02x' % (CharVal & 0x00FF) + ', ' \\r
3851 + '0x%02x' % (CharVal >> 8) + ', '\r
3852 else:\r
3853 NewValue = NewValue + '0x%02x' % (ord(PcdValue[Index]) % 0x100) + ', '\r
3854 Padding = '0x00, '\r
3855 if Unicode:\r
3856 Padding = Padding * 2\r
3857 ArraySize = ArraySize / 2\r
3858 if ArraySize < (len(PcdValue) + 1):\r
3859 EdkLogger.error("build", AUTOGEN_ERROR,\r
3860 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
3861 )\r
3862 if ArraySize > len(PcdValue) + 1:\r
3863 NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r
3864 PcdValue = NewValue + Padding.strip().rstrip(',') + '}'\r
3865 elif len(PcdValue.split(',')) <= ArraySize:\r
3866 PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))\r
3867 PcdValue += '}'\r
3868 else:\r
3869 EdkLogger.error("build", AUTOGEN_ERROR,\r
3870 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
3871 )\r
3872 PcdItem = '%s.%s|%s|0x%X' % \\r
3873 (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])\r
3874 PcdComments = ''\r
3875 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
3876 PcdComments = '\n '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])\r
3877 if PcdComments:\r
3878 PcdItem = PcdComments + '\n ' + PcdItem\r
3879 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r
3880\r
3881 HiiPcds = []\r
3882 for Pcd in Pcds + VfrPcds:\r
3883 PcdComments = ''\r
3884 PcdCommentList = []\r
3885 HiiInfo = ''\r
3886 SkuId = ''\r
3887 TokenCName = Pcd.TokenCName\r
3888 for PcdItem in GlobalData.MixedPcd:\r
3889 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
3890 TokenCName = PcdItem[0]\r
3891 break\r
3892 if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:\r
3893 for SkuName in Pcd.SkuInfoList:\r
3894 SkuInfo = Pcd.SkuInfoList[SkuName]\r
3895 SkuId = SkuInfo.SkuId\r
3896 HiiInfo = '## %s|%s|%s' % (SkuInfo.VariableName, SkuInfo.VariableGuid, SkuInfo.VariableOffset)\r
3897 break\r
3898 if SkuId:\r
3899 #\r
3900 # Don't generate duplicated HII PCD\r
3901 #\r
3902 if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds:\r
3903 continue\r
3904 else:\r
3905 HiiPcds.append((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
3906 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
3907 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]\r
3908 if HiiInfo:\r
3909 UsageIndex = -1\r
3910 UsageStr = ''\r
3911 for Index, Comment in enumerate(PcdCommentList):\r
3912 for Usage in UsageList:\r
3913 if Comment.find(Usage) != -1:\r
3914 UsageStr = Usage\r
3915 UsageIndex = Index\r
3916 break\r
3917 if UsageIndex != -1:\r
3918 PcdCommentList[UsageIndex] = '## %s %s %s' % (UsageStr, HiiInfo, PcdCommentList[UsageIndex].replace(UsageStr, '')) \r
3919 else:\r
3920 PcdCommentList.append('## UNDEFINED ' + HiiInfo)\r
3921 PcdComments = '\n '.join(PcdCommentList)\r
3922 PcdEntry = Pcd.TokenSpaceGuidCName + '.' + TokenCName\r
3923 if PcdComments:\r
3924 PcdEntry = PcdComments + '\n ' + PcdEntry\r
3925 AsBuiltInfDict['pcd_item'] += [PcdEntry]\r
3926 for Item in self.BuildOption:\r
3927 if 'FLAGS' in self.BuildOption[Item]:\r
3928 AsBuiltInfDict['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self.ToolChainFamily, self.BuildTarget, self.ToolChain, self.Arch, Item, self.BuildOption[Item]['FLAGS'].strip())]\r
3929\r
3930 # Generated LibraryClasses section in comments.\r
3931 for Library in self.LibraryAutoGenList:\r
3932 AsBuiltInfDict['libraryclasses_item'] += [Library.MetaFile.File.replace('\\', '/')]\r
3933 \r
3934 # Generated depex expression section in comments.\r
3935 AsBuiltInfDict['depexsection_item'] = ''\r
3936 DepexExpresion = self._GetDepexExpresionString()\r
3937 if DepexExpresion:\r
3938 AsBuiltInfDict['depexsection_item'] = DepexExpresion\r
3939 \r
3940 AsBuiltInf = TemplateString()\r
3941 AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))\r
3942 \r
3943 SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r
3944 \r
3945 self.IsAsBuiltInfCreated = True\r
3946 \r
3947 ## Create makefile for the module and its dependent libraries\r
3948 #\r
3949 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of\r
3950 # dependent libraries will be created\r
3951 #\r
3952 def CreateMakeFile(self, CreateLibraryMakeFile=True):\r
3953 # Ignore generating makefile when it is a binary module\r
3954 if self.IsBinaryModule:\r
3955 return\r
3956\r
3957 if self.IsMakeFileCreated:\r
3958 return\r
3959\r
3960 if not self.IsLibrary and CreateLibraryMakeFile:\r
3961 for LibraryAutoGen in self.LibraryAutoGenList:\r
3962 LibraryAutoGen.CreateMakeFile()\r
3963\r
3964 if len(self.CustomMakefile) == 0:\r
3965 Makefile = GenMake.ModuleMakefile(self)\r
3966 else:\r
3967 Makefile = GenMake.CustomMakefile(self)\r
3968 if Makefile.Generate():\r
3969 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %\r
3970 (self.Name, self.Arch))\r
3971 else:\r
3972 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %\r
3973 (self.Name, self.Arch))\r
3974\r
3975 self.IsMakeFileCreated = True\r
3976\r
3977 def CopyBinaryFiles(self):\r
3978 for File in self.Module.Binaries:\r
3979 SrcPath = File.Path\r
3980 DstPath = os.path.join(self.OutputDir , os.path.basename(SrcPath))\r
3981 CopyLongFilePath(SrcPath, DstPath)\r
3982 ## Create autogen code for the module and its dependent libraries\r
3983 #\r
3984 # @param CreateLibraryCodeFile Flag indicating if or not the code of\r
3985 # dependent libraries will be created\r
3986 #\r
3987 def CreateCodeFile(self, CreateLibraryCodeFile=True):\r
3988 if self.IsCodeFileCreated:\r
3989 return\r
3990\r
3991 # Need to generate PcdDatabase even PcdDriver is binarymodule\r
3992 if self.IsBinaryModule and self.PcdIsDriver != '':\r
3993 CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
3994 return\r
3995 if self.IsBinaryModule:\r
3996 if self.IsLibrary:\r
3997 self.CopyBinaryFiles()\r
3998 return\r
3999\r
4000 if not self.IsLibrary and CreateLibraryCodeFile:\r
4001 for LibraryAutoGen in self.LibraryAutoGenList:\r
4002 LibraryAutoGen.CreateCodeFile()\r
4003\r
4004 AutoGenList = []\r
4005 IgoredAutoGenList = []\r
4006\r
4007 for File in self.AutoGenFileList:\r
4008 if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):\r
4009 #Ignore Edk AutoGen.c\r
4010 if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':\r
4011 continue\r
4012\r
4013 AutoGenList.append(str(File))\r
4014 else:\r
4015 IgoredAutoGenList.append(str(File))\r
4016\r
4017 # Skip the following code for EDK I inf\r
4018 if self.AutoGenVersion < 0x00010005:\r
4019 return\r
4020\r
4021 for ModuleType in self.DepexList:\r
4022 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module\r
4023 if len(self.DepexList[ModuleType]) == 0 or ModuleType == "USER_DEFINED":\r
4024 continue\r
4025\r
4026 Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)\r
4027 DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}\r
4028\r
4029 if len(Dpx.PostfixNotation) <> 0:\r
4030 self.DepexGenerated = True\r
4031\r
4032 if Dpx.Generate(path.join(self.OutputDir, DpxFile)):\r
4033 AutoGenList.append(str(DpxFile))\r
4034 else:\r
4035 IgoredAutoGenList.append(str(DpxFile))\r
4036\r
4037 if IgoredAutoGenList == []:\r
4038 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %\r
4039 (" ".join(AutoGenList), self.Name, self.Arch))\r
4040 elif AutoGenList == []:\r
4041 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %\r
4042 (" ".join(IgoredAutoGenList), self.Name, self.Arch))\r
4043 else:\r
4044 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %\r
4045 (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))\r
4046\r
4047 self.IsCodeFileCreated = True\r
4048 return AutoGenList\r
4049\r
4050 ## Summarize the ModuleAutoGen objects of all libraries used by this module\r
4051 def _GetLibraryAutoGenList(self):\r
4052 if self._LibraryAutoGenList == None:\r
4053 self._LibraryAutoGenList = []\r
4054 for Library in self.DependentLibraryList:\r
4055 La = ModuleAutoGen(\r
4056 self.Workspace,\r
4057 Library.MetaFile,\r
4058 self.BuildTarget,\r
4059 self.ToolChain,\r
4060 self.Arch,\r
4061 self.PlatformInfo.MetaFile\r
4062 )\r
4063 if La not in self._LibraryAutoGenList:\r
4064 self._LibraryAutoGenList.append(La)\r
4065 for Lib in La.CodaTargetList:\r
4066 self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)\r
4067 return self._LibraryAutoGenList\r
4068\r
4069 Module = property(_GetModule)\r
4070 Name = property(_GetBaseName)\r
4071 Guid = property(_GetGuid)\r
4072 Version = property(_GetVersion)\r
4073 ModuleType = property(_GetModuleType)\r
4074 ComponentType = property(_GetComponentType)\r
4075 BuildType = property(_GetBuildType)\r
4076 PcdIsDriver = property(_GetPcdIsDriver)\r
4077 AutoGenVersion = property(_GetAutoGenVersion)\r
4078 Macros = property(_GetMacros)\r
4079 Specification = property(_GetSpecification)\r
4080\r
4081 IsLibrary = property(_IsLibrary)\r
4082 IsBinaryModule = property(_IsBinaryModule)\r
4083 BuildDir = property(_GetBuildDir)\r
4084 OutputDir = property(_GetOutputDir)\r
4085 DebugDir = property(_GetDebugDir)\r
4086 MakeFileDir = property(_GetMakeFileDir)\r
4087 CustomMakefile = property(_GetCustomMakefile)\r
4088\r
4089 IncludePathList = property(_GetIncludePathList)\r
4090 IncludePathLength = property(_GetIncludePathLength)\r
4091 AutoGenFileList = property(_GetAutoGenFileList)\r
4092 UnicodeFileList = property(_GetUnicodeFileList)\r
4093 VfrFileList = property(_GetVfrFileList)\r
4094 SourceFileList = property(_GetSourceFileList)\r
4095 BinaryFileList = property(_GetBinaryFiles) # FileType : [File List]\r
4096 Targets = property(_GetTargets)\r
4097 IntroTargetList = property(_GetIntroTargetList)\r
4098 CodaTargetList = property(_GetFinalTargetList)\r
4099 FileTypes = property(_GetFileTypes)\r
4100 BuildRules = property(_GetBuildRules)\r
4101 IdfFileList = property(_GetIdfFileList)\r
4102\r
4103 DependentPackageList = property(_GetDependentPackageList)\r
4104 DependentLibraryList = property(_GetLibraryList)\r
4105 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
4106 DerivedPackageList = property(_GetDerivedPackageList)\r
4107\r
4108 ModulePcdList = property(_GetModulePcdList)\r
4109 LibraryPcdList = property(_GetLibraryPcdList)\r
4110 GuidList = property(_GetGuidList)\r
4111 ProtocolList = property(_GetProtocolList)\r
4112 PpiList = property(_GetPpiList)\r
4113 DepexList = property(_GetDepexTokenList)\r
4114 DxsFile = property(_GetDxsFile)\r
4115 DepexExpressionList = property(_GetDepexExpressionTokenList)\r
4116 BuildOption = property(_GetModuleBuildOption)\r
4117 BuildOptionIncPathList = property(_GetBuildOptionIncPathList)\r
4118 BuildCommand = property(_GetBuildCommand)\r
4119 \r
4120 FixedAtBuildPcds = property(_GetFixedAtBuildPcds)\r
4121\r
4122# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
4123if __name__ == '__main__':\r
4124 pass\r
4125\r