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