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