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