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