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