BaseTools: Fix a bug for Size incorrect of Void* Fixatbuild Pcd
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
CommitLineData
52302d4d
LG
1## @file\r
2# Generate AutoGen.h, AutoGen.c and *.depex files\r
3#\r
e74cea4c 4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
40d841f6 5# This program and the accompanying materials\r
52302d4d
LG
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14## Import Modules\r
15#\r
1be2ed90 16import Common.LongFilePathOs as os\r
52302d4d
LG
17import re\r
18import os.path as path\r
19import copy\r
867d1cd4 20import uuid\r
52302d4d
LG
21\r
22import GenC\r
23import GenMake\r
24import GenDepex\r
25from StringIO import StringIO\r
26\r
27from StrGather import *\r
28from BuildEngine import BuildRule\r
29\r
1be2ed90 30from Common.LongFilePathSupport import CopyLongFilePath\r
52302d4d
LG
31from Common.BuildToolError import *\r
32from Common.DataType import *\r
33from Common.Misc import *\r
34from Common.String import *\r
35import Common.GlobalData as GlobalData\r
36from GenFds.FdfParser import *\r
37from CommonDataClass.CommonClass import SkuInfoClass\r
38from Workspace.BuildClassObject import *\r
e8a47801 39from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r
e56468c0 40import Common.VpdInfoFile as VpdInfoFile\r
e8a47801
LG
41from GenPcdDb import CreatePcdDatabaseCode\r
42from Workspace.MetaFileCommentParser import UsageList\r
05cc51ad 43from Common.MultipleWorkspace import MultipleWorkspace as mws\r
97fa0ee9 44import InfSectionParser\r
c17956e0 45import datetime\r
36d083ef 46import hashlib\r
8518bf0b 47from GenVar import VariableMgr,var_info\r
9006a2c6 48from collections import OrderedDict\r
a993dc03 49from collections import defaultdict\r
97fa0ee9 50\r
e8a47801 51## Regular expression for splitting Dependency Expression string into tokens\r
52302d4d
LG
52gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
53\r
c8802c3d
CJ
54## Regular expression for match: PCD(xxxx.yyy)\r
55gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$")\r
56\r
57#\r
58# Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
59# is the former use /I , the Latter used -I to specify include directories\r
60#\r
61gBuildOptIncludePatternMsft = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
62gBuildOptIncludePatternOther = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
63\r
97fa0ee9
YL
64#\r
65# Match name = variable\r
66#\r
67gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")\r
68#\r
69# The format of guid in efivarstore statement likes following and must be correct:\r
70# guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}\r
71#\r
72gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")\r
73\r
52302d4d
LG
74## Mapping Makefile type\r
75gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}\r
76\r
77\r
78## Build rule configuration file\r
51de5c30 79gDefaultBuildRuleFile = 'build_rule.txt'\r
52302d4d 80\r
86601b78 81## Tools definition configuration file\r
51de5c30 82gDefaultToolsDefFile = 'tools_def.txt'\r
86601b78 83\r
64b2609f
LG
84## Build rule default version\r
85AutoGenReqBuildRuleVerNum = "0.1"\r
86\r
52302d4d
LG
87## default file name for AutoGen\r
88gAutoGenCodeFileName = "AutoGen.c"\r
89gAutoGenHeaderFileName = "AutoGen.h"\r
90gAutoGenStringFileName = "%(module_name)sStrDefs.h"\r
91gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r
92gAutoGenDepexFileName = "%(module_name)s.depex"\r
333ba578
YZ
93gAutoGenImageDefFileName = "%(module_name)sImgDefs.h"\r
94gAutoGenIdfFileName = "%(module_name)sIdf.hpk"\r
97fa0ee9
YL
95gInfSpecVersion = "0x00010017"\r
96\r
da92f276
LG
97#\r
98# Template string to generic AsBuilt INF\r
99#\r
e8a47801 100gAsBuiltInfHeaderString = TemplateString("""${header_comments}\r
da92f276 101\r
97fa0ee9
YL
102# DO NOT EDIT\r
103# FILE auto-generated\r
104\r
da92f276 105[Defines]\r
97fa0ee9 106 INF_VERSION = ${module_inf_version}\r
da92f276
LG
107 BASE_NAME = ${module_name}\r
108 FILE_GUID = ${module_guid}\r
97fa0ee9
YL
109 MODULE_TYPE = ${module_module_type}${BEGIN}\r
110 VERSION_STRING = ${module_version_string}${END}${BEGIN}\r
e8a47801 111 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}\r
da92f276 112 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}\r
97fa0ee9
YL
113 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}\r
114 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}\r
115 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}\r
116 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}\r
117 DESTRUCTOR = ${module_destructor}${END}${BEGIN}\r
118 SHADOW = ${module_shadow}${END}${BEGIN}\r
119 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}\r
120 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}\r
121 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}\r
122 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}\r
123 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}\r
124 SPEC = ${module_spec}${END}${BEGIN}\r
125 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}\r
126 MODULE_UNI_FILE = ${module_uni_file}${END}\r
127\r
128[Packages.${module_arch}]${BEGIN}\r
da92f276
LG
129 ${package_item}${END}\r
130\r
131[Binaries.${module_arch}]${BEGIN}\r
132 ${binary_item}${END}\r
133\r
e8a47801
LG
134[PatchPcd.${module_arch}]${BEGIN}\r
135 ${patchablepcd_item}\r
136${END}\r
97fa0ee9 137\r
e8a47801
LG
138[Protocols.${module_arch}]${BEGIN}\r
139 ${protocol_item}\r
140${END}\r
97fa0ee9 141\r
e8a47801
LG
142[Ppis.${module_arch}]${BEGIN}\r
143 ${ppi_item}\r
144${END}\r
97fa0ee9 145\r
e8a47801
LG
146[Guids.${module_arch}]${BEGIN}\r
147 ${guid_item}\r
148${END}\r
97fa0ee9 149\r
e8a47801
LG
150[PcdEx.${module_arch}]${BEGIN}\r
151 ${pcd_item}\r
152${END}\r
da92f276 153\r
97fa0ee9
YL
154[LibraryClasses.${module_arch}]\r
155## @LIB_INSTANCES${BEGIN}\r
156# ${libraryclasses_item}${END}\r
157\r
158${depexsection_item}\r
159\r
dfa41b4a
YZ
160${userextension_tianocore_item}\r
161\r
97fa0ee9
YL
162${tail_comments}\r
163\r
164[BuildOptions.${module_arch}]\r
da92f276
LG
165## @AsBuilt${BEGIN}\r
166## ${flags_item}${END}\r
167""")\r
168\r
52302d4d
LG
169## Base class for AutoGen\r
170#\r
171# This class just implements the cache mechanism of AutoGen objects.\r
172#\r
173class AutoGen(object):\r
b24e99f7
CJ
174 # database to maintain the objects in each child class\r
175 __ObjectCache = {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object\r
52302d4d
LG
176\r
177 ## Factory method\r
178 #\r
179 # @param Class class object of real AutoGen class\r
180 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)\r
181 # @param Workspace Workspace directory or WorkspaceAutoGen object\r
182 # @param MetaFile The path of meta file\r
183 # @param Target Build target\r
184 # @param Toolchain Tool chain name\r
185 # @param Arch Target arch\r
186 # @param *args The specific class related parameters\r
187 # @param **kwargs The specific class related dict parameters\r
188 #\r
b24e99f7 189 def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
52302d4d 190 # check if the object has been created\r
b24e99f7
CJ
191 Key = (Target, Toolchain, Arch, MetaFile)\r
192 try:\r
193 # if it exists, just return it directly\r
194 return cls.__ObjectCache[Key]\r
195 except:\r
196 # it didnt exist. create it, cache it, then return it\r
197 cls.__ObjectCache[Key] = super(AutoGen, cls).__new__(cls)\r
198 return cls.__ObjectCache[Key]\r
199\r
200 def __init__ (self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
201 super(AutoGen, self).__init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
52302d4d
LG
202\r
203 ## hash() operator\r
204 #\r
205 # The file path of platform file will be used to represent hash value of this object\r
206 #\r
207 # @retval int Hash value of the file path of platform file\r
208 #\r
209 def __hash__(self):\r
210 return hash(self.MetaFile)\r
211\r
212 ## str() operator\r
213 #\r
214 # The file path of platform file will be used to represent this object\r
215 #\r
216 # @retval string String of platform file path\r
217 #\r
218 def __str__(self):\r
219 return str(self.MetaFile)\r
220\r
221 ## "==" operator\r
222 def __eq__(self, Other):\r
223 return Other and self.MetaFile == Other\r
224\r
225## Workspace AutoGen class\r
226#\r
227# This class is used mainly to control the whole platform build for different\r
228# architecture. This class will generate top level makefile.\r
229#\r
230class WorkspaceAutoGen(AutoGen):\r
b24e99f7
CJ
231 # call super().__init__ then call the worker function with different parameter count\r
232 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
233 try:\r
234 self._Init\r
235 except:\r
236 super(WorkspaceAutoGen, self).__init__(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
237 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
238 self._Init = True\r
239 \r
240 ## Initialize WorkspaceAutoGen\r
52302d4d
LG
241 #\r
242 # @param WorkspaceDir Root directory of workspace\r
243 # @param ActivePlatform Meta-file of active platform\r
244 # @param Target Build target\r
245 # @param Toolchain Tool chain name\r
246 # @param ArchList List of architecture of current build\r
247 # @param MetaFileDb Database containing meta-files\r
248 # @param BuildConfig Configuration of build\r
249 # @param ToolDefinition Tool chain definitions\r
250 # @param FlashDefinitionFile File of flash definition\r
251 # @param Fds FD list to be generated\r
252 # @param Fvs FV list to be generated\r
4234283c 253 # @param Caps Capsule list to be generated\r
52302d4d
LG
254 # @param SkuId SKU id from command line\r
255 #\r
b24e99f7 256 def _InitWorker(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
47fea6af 257 BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,\r
9508d0fa 258 Progress=None, BuildModule=None):\r
4234283c
LG
259 if Fds is None:\r
260 Fds = []\r
261 if Fvs is None:\r
262 Fvs = []\r
263 if Caps is None:\r
264 Caps = []\r
0d2711a6
LG
265 self.BuildDatabase = MetaFileDb\r
266 self.MetaFile = ActivePlatform\r
52302d4d 267 self.WorkspaceDir = WorkspaceDir\r
0d2711a6 268 self.Platform = self.BuildDatabase[self.MetaFile, 'COMMON', Target, Toolchain]\r
d0acc87a 269 GlobalData.gActivePlatform = self.Platform\r
52302d4d
LG
270 self.BuildTarget = Target\r
271 self.ToolChain = Toolchain\r
272 self.ArchList = ArchList\r
273 self.SkuId = SkuId\r
f3decdc3 274 self.UniFlag = UniFlag\r
52302d4d 275\r
52302d4d
LG
276 self.TargetTxt = BuildConfig\r
277 self.ToolDef = ToolDefinition\r
278 self.FdfFile = FlashDefinitionFile\r
279 self.FdTargetList = Fds\r
280 self.FvTargetList = Fvs\r
4234283c 281 self.CapTargetList = Caps\r
52302d4d 282 self.AutoGenObjectList = []\r
36d083ef
YZ
283 self._BuildDir = None\r
284 self._FvDir = None\r
285 self._MakeFileDir = None\r
286 self._BuildCommand = None\r
726c501c 287 self._GuidDict = {}\r
52302d4d
LG
288\r
289 # there's many relative directory operations, so ...\r
290 os.chdir(self.WorkspaceDir)\r
291\r
0d2711a6
LG
292 #\r
293 # Merge Arch\r
294 #\r
295 if not self.ArchList:\r
296 ArchList = set(self.Platform.SupArchList)\r
297 else:\r
298 ArchList = set(self.ArchList) & set(self.Platform.SupArchList)\r
299 if not ArchList:\r
300 EdkLogger.error("build", PARAMETER_INVALID,\r
301 ExtraData = "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self.Platform.SupArchList)))\r
302 elif self.ArchList and len(ArchList) != len(self.ArchList):\r
303 SkippedArchList = set(self.ArchList).symmetric_difference(set(self.Platform.SupArchList))\r
304 EdkLogger.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"\r
305 % (" ".join(SkippedArchList), " ".join(self.Platform.SupArchList)))\r
306 self.ArchList = tuple(ArchList)\r
307\r
308 # Validate build target\r
309 if self.BuildTarget not in self.Platform.BuildTargets:\r
47fea6af 310 EdkLogger.error("build", PARAMETER_INVALID,\r
0d2711a6
LG
311 ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"\r
312 % (self.BuildTarget, " ".join(self.Platform.BuildTargets)))\r
313\r
12d37ace 314 \r
52302d4d 315 # parse FDF file to get PCDs in it, if any\r
0d2711a6
LG
316 if not self.FdfFile:\r
317 self.FdfFile = self.Platform.FlashDefinition\r
47fea6af 318\r
9508d0fa
LG
319 EdkLogger.info("")\r
320 if self.ArchList:\r
321 EdkLogger.info('%-16s = %s' % ("Architecture(s)", ' '.join(self.ArchList)))\r
322 EdkLogger.info('%-16s = %s' % ("Build target", self.BuildTarget))\r
47fea6af
YZ
323 EdkLogger.info('%-16s = %s' % ("Toolchain", self.ToolChain))\r
324\r
9508d0fa
LG
325 EdkLogger.info('\n%-24s = %s' % ("Active Platform", self.Platform))\r
326 if BuildModule:\r
327 EdkLogger.info('%-24s = %s' % ("Active Module", BuildModule))\r
47fea6af 328\r
9508d0fa
LG
329 if self.FdfFile:\r
330 EdkLogger.info('%-24s = %s' % ("Flash Image Definition", self.FdfFile))\r
0d2711a6 331\r
9508d0fa 332 EdkLogger.verbose("\nFLASH_DEFINITION = %s" % self.FdfFile)\r
47fea6af 333\r
e74cea4c
YZ
334 if Progress:\r
335 Progress.Start("\nProcessing meta-data")\r
47fea6af 336\r
0d2711a6 337 if self.FdfFile:\r
df692f02
LG
338 #\r
339 # Mark now build in AutoGen Phase\r
340 #\r
47fea6af 341 GlobalData.gAutoGenPhase = True\r
52302d4d
LG
342 Fdf = FdfParser(self.FdfFile.Path)\r
343 Fdf.ParseFile()\r
a0a2cd1e 344 GlobalData.gFdfParser = Fdf\r
0d2711a6 345 GlobalData.gAutoGenPhase = False\r
52302d4d 346 PcdSet = Fdf.Profile.PcdDict\r
cb04330e
YZ
347 if Fdf.CurrentFdName and Fdf.CurrentFdName in Fdf.Profile.FdDict:\r
348 FdDict = Fdf.Profile.FdDict[Fdf.CurrentFdName]\r
349 for FdRegion in FdDict.RegionList:\r
350 if str(FdRegion.RegionType) is 'FILE' and self.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
351 if int(FdRegion.Offset) % 8 != 0:\r
352 EdkLogger.error("build", FORMAT_INVALID, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion.Offset))\r
52302d4d
LG
353 ModuleList = Fdf.Profile.InfList\r
354 self.FdfProfile = Fdf.Profile\r
0d2711a6
LG
355 for fvname in self.FvTargetList:\r
356 if fvname.upper() not in self.FdfProfile.FvDict:\r
357 EdkLogger.error("build", OPTION_VALUE_INVALID,\r
358 "No such an FV in FDF file: %s" % fvname)\r
2502b735 359\r
622b1758
YZ
360 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,\r
361 # but the path (self.MetaFile.Path) is the real path\r
2502b735
YZ
362 for key in self.FdfProfile.InfDict:\r
363 if key == 'ArchTBD':\r
364 Platform_cache = {}\r
622b1758 365 MetaFile_cache = {}\r
2502b735
YZ
366 for Arch in self.ArchList:\r
367 Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
b74b419a
CJ
368 MetaFile_cache[Arch] = set()\r
369 for Pkey in Platform_cache[Arch].Modules:\r
370 MetaFile_cache[Arch].add(Platform_cache[Arch].Modules[Pkey].MetaFile)\r
2502b735
YZ
371 for Inf in self.FdfProfile.InfDict[key]:\r
372 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
373 for Arch in self.ArchList:\r
622b1758 374 if ModuleFile in MetaFile_cache[Arch]:\r
2502b735
YZ
375 break\r
376 else:\r
377 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
378 if not ModuleData.IsBinaryModule:\r
379 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
380\r
381 else:\r
382 for Arch in self.ArchList:\r
383 if Arch == key:\r
384 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
b74b419a
CJ
385 MetaFileList = set()\r
386 for Pkey in Platform.Modules:\r
387 MetaFileList.add(Platform.Modules[Pkey].MetaFile)\r
2502b735
YZ
388 for Inf in self.FdfProfile.InfDict[key]:\r
389 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
622b1758 390 if ModuleFile in MetaFileList:\r
2502b735
YZ
391 continue\r
392 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
393 if not ModuleData.IsBinaryModule:\r
394 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
395\r
52302d4d
LG
396 else:\r
397 PcdSet = {}\r
398 ModuleList = []\r
399 self.FdfProfile = None\r
0d2711a6
LG
400 if self.FdTargetList:\r
401 EdkLogger.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self.FdTargetList))\r
402 self.FdTargetList = []\r
403 if self.FvTargetList:\r
404 EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvTargetList))\r
405 self.FvTargetList = []\r
406 if self.CapTargetList:\r
407 EdkLogger.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self.CapTargetList))\r
408 self.CapTargetList = []\r
47fea6af 409\r
52302d4d
LG
410 # apply SKU and inject PCDs from Flash Definition file\r
411 for Arch in self.ArchList:\r
0d2711a6 412 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
64b2609f 413\r
ff5635e9
CJ
414 SourcePcdDict = {'DynamicEx':set(), 'PatchableInModule':set(),'Dynamic':set(),'FixedAtBuild':set()}\r
415 BinaryPcdDict = {'DynamicEx':set(), 'PatchableInModule':set()}\r
2a29017e
YZ
416 SourcePcdDict_Keys = SourcePcdDict.keys()\r
417 BinaryPcdDict_Keys = BinaryPcdDict.keys()\r
418\r
419 # generate the SourcePcdDict and BinaryPcdDict\r
6f49996c 420 PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
2a29017e
YZ
421 for BuildData in PGen.BuildDatabase._CACHE_.values():\r
422 if BuildData.Arch != Arch:\r
423 continue\r
424 if BuildData.MetaFile.Ext == '.inf':\r
425 for key in BuildData.Pcds:\r
426 if BuildData.Pcds[key].Pending:\r
427 if key in Platform.Pcds:\r
428 PcdInPlatform = Platform.Pcds[key]\r
429 if PcdInPlatform.Type not in [None, '']:\r
430 BuildData.Pcds[key].Type = PcdInPlatform.Type\r
431\r
432 if BuildData.MetaFile in Platform.Modules:\r
433 PlatformModule = Platform.Modules[str(BuildData.MetaFile)]\r
434 if key in PlatformModule.Pcds:\r
435 PcdInPlatform = PlatformModule.Pcds[key]\r
436 if PcdInPlatform.Type not in [None, '']:\r
437 BuildData.Pcds[key].Type = PcdInPlatform.Type\r
438\r
439 if 'DynamicEx' in BuildData.Pcds[key].Type:\r
440 if BuildData.IsBinaryModule:\r
ff5635e9 441 BinaryPcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
2a29017e 442 else:\r
ff5635e9 443 SourcePcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
2a29017e
YZ
444\r
445 elif 'PatchableInModule' in BuildData.Pcds[key].Type:\r
446 if BuildData.MetaFile.Ext == '.inf':\r
447 if BuildData.IsBinaryModule:\r
ff5635e9 448 BinaryPcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
2a29017e 449 else:\r
ff5635e9 450 SourcePcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
2a29017e
YZ
451\r
452 elif 'Dynamic' in BuildData.Pcds[key].Type:\r
ff5635e9 453 SourcePcdDict['Dynamic'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
2a29017e 454 elif 'FixedAtBuild' in BuildData.Pcds[key].Type:\r
ff5635e9 455 SourcePcdDict['FixedAtBuild'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
2a29017e
YZ
456 else:\r
457 pass\r
97cdb33b
YZ
458 #\r
459 # A PCD can only use one type for all source modules\r
460 #\r
461 for i in SourcePcdDict_Keys:\r
462 for j in SourcePcdDict_Keys:\r
463 if i != j:\r
ff5635e9
CJ
464 Intersections = SourcePcdDict[i].intersection(SourcePcdDict[j])\r
465 if len(Intersections) > 0:\r
97cdb33b
YZ
466 EdkLogger.error(\r
467 'build',\r
468 FORMAT_INVALID,\r
469 "Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i, j),\r
ff5635e9 470 ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in Intersections])\r
97cdb33b 471 )\r
2a29017e
YZ
472\r
473 #\r
474 # intersection the BinaryPCD for Mixed PCD\r
475 #\r
476 for i in BinaryPcdDict_Keys:\r
477 for j in BinaryPcdDict_Keys:\r
478 if i != j:\r
ff5635e9
CJ
479 Intersections = BinaryPcdDict[i].intersection(BinaryPcdDict[j])\r
480 for item in Intersections:\r
2a29017e
YZ
481 NewPcd1 = (item[0] + '_' + i, item[1])\r
482 NewPcd2 = (item[0] + '_' + j, item[1])\r
483 if item not in GlobalData.MixedPcd:\r
484 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
485 else:\r
486 if NewPcd1 not in GlobalData.MixedPcd[item]:\r
487 GlobalData.MixedPcd[item].append(NewPcd1)\r
488 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
489 GlobalData.MixedPcd[item].append(NewPcd2)\r
2a29017e
YZ
490\r
491 #\r
492 # intersection the SourcePCD and BinaryPCD for Mixed PCD\r
493 #\r
494 for i in SourcePcdDict_Keys:\r
495 for j in BinaryPcdDict_Keys:\r
496 if i != j:\r
ff5635e9
CJ
497 Intersections = SourcePcdDict[i].intersection(BinaryPcdDict[j])\r
498 for item in Intersections:\r
2a29017e
YZ
499 NewPcd1 = (item[0] + '_' + i, item[1])\r
500 NewPcd2 = (item[0] + '_' + j, item[1])\r
501 if item not in GlobalData.MixedPcd:\r
502 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
503 else:\r
504 if NewPcd1 not in GlobalData.MixedPcd[item]:\r
505 GlobalData.MixedPcd[item].append(NewPcd1)\r
506 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
507 GlobalData.MixedPcd[item].append(NewPcd2)\r
2a29017e
YZ
508\r
509 for BuildData in PGen.BuildDatabase._CACHE_.values():\r
510 if BuildData.Arch != Arch:\r
511 continue\r
512 for key in BuildData.Pcds:\r
513 for SinglePcd in GlobalData.MixedPcd:\r
514 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
515 for item in GlobalData.MixedPcd[SinglePcd]:\r
516 Pcd_Type = item[0].split('_')[-1]\r
517 if (Pcd_Type == BuildData.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and BuildData.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
518 (Pcd_Type == TAB_PCDS_DYNAMIC and BuildData.Pcds[key].Type in GenC.gDynamicPcd):\r
519 Value = BuildData.Pcds[key]\r
520 Value.TokenCName = BuildData.Pcds[key].TokenCName + '_' + Pcd_Type\r
521 if len(key) == 2:\r
522 newkey = (Value.TokenCName, key[1])\r
523 elif len(key) == 3:\r
524 newkey = (Value.TokenCName, key[1], key[2])\r
525 del BuildData.Pcds[key]\r
526 BuildData.Pcds[newkey] = Value\r
527 break\r
2a29017e 528 break\r
2a29017e
YZ
529\r
530 # handle the mixed pcd in FDF file\r
531 for key in PcdSet:\r
532 if key in GlobalData.MixedPcd:\r
533 Value = PcdSet[key]\r
534 del PcdSet[key]\r
535 for item in GlobalData.MixedPcd[key]:\r
536 PcdSet[item] = Value\r
537\r
97fa0ee9 538 #Collect package set information from INF of FDF\r
a0a2cd1e
FB
539 PkgSet = set()\r
540 for Inf in ModuleList:\r
541 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
542 if ModuleFile in Platform.Modules:\r
543 continue\r
544 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
545 PkgSet.update(ModuleData.Packages)\r
546 Pkgs = list(PkgSet) + list(PGen.PackageList)\r
6b26dd71 547 DecPcds = set()\r
6f49996c 548 DecPcdsKey = set()\r
64b2609f 549 for Pkg in Pkgs:\r
25918452 550 for Pcd in Pkg.Pcds:\r
6b26dd71 551 DecPcds.add((Pcd[0], Pcd[1]))\r
4afd3d04 552 DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
64b2609f 553\r
52302d4d
LG
554 Platform.SkuName = self.SkuId\r
555 for Name, Guid in PcdSet:\r
64b2609f
LG
556 if (Name, Guid) not in DecPcds:\r
557 EdkLogger.error(\r
558 'build',\r
559 PARSER_ERROR,\r
560 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid, Name),\r
561 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
562 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
563 )\r
4afd3d04
LG
564 else:\r
565 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.\r
566 if (Name, Guid, TAB_PCDS_FIXED_AT_BUILD) in DecPcdsKey \\r
567 or (Name, Guid, TAB_PCDS_PATCHABLE_IN_MODULE) in DecPcdsKey \\r
568 or (Name, Guid, TAB_PCDS_FEATURE_FLAG) in DecPcdsKey:\r
569 Platform.AddPcd(Name, Guid, PcdSet[Name, Guid])\r
570 continue\r
571 elif (Name, Guid, TAB_PCDS_DYNAMIC) in DecPcdsKey or (Name, Guid, TAB_PCDS_DYNAMIC_EX) in DecPcdsKey:\r
572 EdkLogger.error(\r
573 'build',\r
574 PARSER_ERROR,\r
575 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid, Name),\r
576 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
577 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
578 )\r
52302d4d
LG
579\r
580 Pa = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
581 #\r
582 # Explicitly collect platform's dynamic PCDs\r
583 #\r
584 Pa.CollectPlatformDynamicPcds()\r
2bc3256c 585 Pa.CollectFixedAtBuildPcds()\r
52302d4d 586 self.AutoGenObjectList.append(Pa)\r
47fea6af 587\r
36d083ef
YZ
588 #\r
589 # Generate Package level hash value\r
590 #\r
591 GlobalData.gPackageHash[Arch] = {}\r
592 if GlobalData.gUseHashCache:\r
593 for Pkg in Pkgs:\r
594 self._GenPkgLevelHash(Pkg)\r
595\r
6780eef1
LG
596 #\r
597 # Check PCDs token value conflict in each DEC file.\r
598 #\r
599 self._CheckAllPcdsTokenValueConflict()\r
47fea6af 600\r
4234283c
LG
601 #\r
602 # Check PCD type and definition between DSC and DEC\r
603 #\r
604 self._CheckPcdDefineAndType()\r
97fa0ee9
YL
605\r
606# if self.FdfFile:\r
607# self._CheckDuplicateInFV(Fdf)\r
608\r
c17956e0 609 #\r
2d499388 610 # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.\r
c17956e0
DL
611 #\r
612 content = 'gCommandLineDefines: '\r
613 content += str(GlobalData.gCommandLineDefines)\r
614 content += os.linesep\r
615 content += 'BuildOptionPcd: '\r
616 content += str(GlobalData.BuildOptionPcd)\r
2d499388
YZ
617 content += os.linesep\r
618 content += 'Active Platform: '\r
619 content += str(self.Platform)\r
620 content += os.linesep\r
621 if self.FdfFile:\r
622 content += 'Flash Image Definition: '\r
623 content += str(self.FdfFile)\r
36d083ef 624 content += os.linesep\r
c17956e0
DL
625 SaveFileOnChange(os.path.join(self.BuildDir, 'BuildOptions'), content, False)\r
626\r
99adfe9f
YZ
627 #\r
628 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.\r
629 #\r
630 PcdTokenNumber = 'PcdTokenNumber: '\r
631 if Pa.PcdTokenNumber:\r
632 if Pa.DynamicPcdList:\r
633 for Pcd in Pa.DynamicPcdList:\r
634 PcdTokenNumber += os.linesep\r
635 PcdTokenNumber += str((Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
636 PcdTokenNumber += ' : '\r
637 PcdTokenNumber += str(Pa.PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName])\r
638 SaveFileOnChange(os.path.join(self.BuildDir, 'PcdTokenNumber'), PcdTokenNumber, False)\r
639\r
c17956e0
DL
640 #\r
641 # Get set of workspace metafiles\r
642 #\r
643 AllWorkSpaceMetaFiles = self._GetMetaFiles(Target, Toolchain, Arch)\r
644\r
645 #\r
646 # Retrieve latest modified time of all metafiles\r
647 #\r
648 SrcTimeStamp = 0\r
649 for f in AllWorkSpaceMetaFiles:\r
650 if os.stat(f)[8] > SrcTimeStamp:\r
651 SrcTimeStamp = os.stat(f)[8]\r
652 self._SrcTimeStamp = SrcTimeStamp\r
653\r
36d083ef
YZ
654 if GlobalData.gUseHashCache:\r
655 m = hashlib.md5()\r
656 for files in AllWorkSpaceMetaFiles:\r
657 if files.endswith('.dec'):\r
658 continue\r
659 f = open(files, 'r')\r
660 Content = f.read()\r
661 f.close()\r
662 m.update(Content)\r
663 SaveFileOnChange(os.path.join(self.BuildDir, 'AutoGen.hash'), m.hexdigest(), True)\r
664 GlobalData.gPlatformHash = m.hexdigest()\r
665\r
c17956e0
DL
666 #\r
667 # Write metafile list to build directory\r
668 #\r
669 AutoGenFilePath = os.path.join(self.BuildDir, 'AutoGen')\r
670 if os.path.exists (AutoGenFilePath):\r
671 os.remove(AutoGenFilePath)\r
672 if not os.path.exists(self.BuildDir):\r
673 os.makedirs(self.BuildDir)\r
674 with open(os.path.join(self.BuildDir, 'AutoGen'), 'w+') as file:\r
675 for f in AllWorkSpaceMetaFiles:\r
676 print >> file, f\r
52302d4d
LG
677 return True\r
678\r
36d083ef
YZ
679 def _GenPkgLevelHash(self, Pkg):\r
680 PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName)\r
681 CreateDirectory(PkgDir)\r
682 HashFile = os.path.join(PkgDir, Pkg.PackageName + '.hash')\r
683 m = hashlib.md5()\r
684 # Get .dec file's hash value\r
685 f = open(Pkg.MetaFile.Path, 'r')\r
686 Content = f.read()\r
687 f.close()\r
688 m.update(Content)\r
689 # Get include files hash value\r
690 if Pkg.Includes:\r
691 for inc in Pkg.Includes:\r
692 for Root, Dirs, Files in os.walk(str(inc)):\r
693 for File in Files:\r
694 File_Path = os.path.join(Root, File)\r
695 f = open(File_Path, 'r')\r
696 Content = f.read()\r
697 f.close()\r
698 m.update(Content)\r
699 SaveFileOnChange(HashFile, m.hexdigest(), True)\r
700 if Pkg.PackageName not in GlobalData.gPackageHash[Pkg.Arch]:\r
701 GlobalData.gPackageHash[Pkg.Arch][Pkg.PackageName] = m.hexdigest()\r
763e8edf 702\r
c17956e0
DL
703 def _GetMetaFiles(self, Target, Toolchain, Arch):\r
704 AllWorkSpaceMetaFiles = set()\r
705 #\r
706 # add fdf\r
707 #\r
708 if self.FdfFile:\r
709 AllWorkSpaceMetaFiles.add (self.FdfFile.Path)\r
710 if self.FdfFile:\r
711 FdfFiles = GlobalData.gFdfParser.GetAllIncludedFile()\r
712 for f in FdfFiles:\r
713 AllWorkSpaceMetaFiles.add (f.FileName)\r
714 #\r
715 # add dsc\r
716 #\r
717 AllWorkSpaceMetaFiles.add(self.MetaFile.Path)\r
718\r
719 #\r
86601b78
DL
720 # add build_rule.txt & tools_def.txt\r
721 #\r
51de5c30
YZ
722 AllWorkSpaceMetaFiles.add(os.path.join(GlobalData.gConfDirectory, gDefaultBuildRuleFile))\r
723 AllWorkSpaceMetaFiles.add(os.path.join(GlobalData.gConfDirectory, gDefaultToolsDefFile))\r
86601b78 724\r
c17956e0
DL
725 # add BuildOption metafile\r
726 #\r
727 AllWorkSpaceMetaFiles.add(os.path.join(self.BuildDir, 'BuildOptions'))\r
728\r
99adfe9f
YZ
729 # add PcdToken Number file for Dynamic/DynamicEx Pcd\r
730 #\r
731 AllWorkSpaceMetaFiles.add(os.path.join(self.BuildDir, 'PcdTokenNumber'))\r
732\r
c17956e0
DL
733 for Arch in self.ArchList:\r
734 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
735 PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
736\r
737 #\r
738 # add dec\r
739 #\r
740 for Package in PGen.PackageList:\r
741 AllWorkSpaceMetaFiles.add(Package.MetaFile.Path)\r
742\r
743 #\r
744 # add included dsc\r
745 #\r
746 for filePath in Platform._RawData.IncludedFiles:\r
747 AllWorkSpaceMetaFiles.add(filePath.Path)\r
748\r
749 return AllWorkSpaceMetaFiles\r
750\r
79b74a03
LG
751 ## _CheckDuplicateInFV() method\r
752 #\r
753 # Check whether there is duplicate modules/files exist in FV section. \r
754 # The check base on the file GUID;\r
755 #\r
756 def _CheckDuplicateInFV(self, Fdf):\r
757 for Fv in Fdf.Profile.FvDict:\r
758 _GuidDict = {}\r
759 for FfsFile in Fdf.Profile.FvDict[Fv].FfsList:\r
4231a819 760 if FfsFile.InfFileName and FfsFile.NameGuid is None:\r
79b74a03
LG
761 #\r
762 # Get INF file GUID\r
763 #\r
47fea6af 764 InfFoundFlag = False\r
79b74a03 765 for Pa in self.AutoGenObjectList:\r
64b2609f
LG
766 if InfFoundFlag:\r
767 break\r
79b74a03
LG
768 for Module in Pa.ModuleAutoGenList:\r
769 if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName):\r
770 InfFoundFlag = True\r
771 if not Module.Guid.upper() in _GuidDict.keys():\r
772 _GuidDict[Module.Guid.upper()] = FfsFile\r
64b2609f 773 break\r
79b74a03 774 else:\r
47fea6af 775 EdkLogger.error("build",\r
79b74a03 776 FORMAT_INVALID,\r
47fea6af 777 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
79b74a03
LG
778 FfsFile.CurrentLineContent,\r
779 _GuidDict[Module.Guid.upper()].CurrentLineNum,\r
780 _GuidDict[Module.Guid.upper()].CurrentLineContent,\r
781 Module.Guid.upper()),\r
782 ExtraData=self.FdfFile)\r
783 #\r
784 # Some INF files not have entity in DSC file. \r
785 #\r
786 if not InfFoundFlag:\r
787 if FfsFile.InfFileName.find('$') == -1:\r
788 InfPath = NormPath(FfsFile.InfFileName)\r
789 if not os.path.exists(InfPath):\r
790 EdkLogger.error('build', GENFDS_ERROR, "Non-existant Module %s !" % (FfsFile.InfFileName))\r
47fea6af 791\r
79b74a03
LG
792 PathClassObj = PathClass(FfsFile.InfFileName, self.WorkspaceDir)\r
793 #\r
794 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use \r
795 # BuildObject from one of AutoGenObjectList is enough.\r
796 #\r
797 InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain]\r
798 if not InfObj.Guid.upper() in _GuidDict.keys():\r
799 _GuidDict[InfObj.Guid.upper()] = FfsFile\r
800 else:\r
47fea6af 801 EdkLogger.error("build",\r
79b74a03 802 FORMAT_INVALID,\r
47fea6af 803 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
79b74a03
LG
804 FfsFile.CurrentLineContent,\r
805 _GuidDict[InfObj.Guid.upper()].CurrentLineNum,\r
806 _GuidDict[InfObj.Guid.upper()].CurrentLineContent,\r
807 InfObj.Guid.upper()),\r
808 ExtraData=self.FdfFile)\r
809 InfFoundFlag = False\r
47fea6af 810\r
4231a819 811 if FfsFile.NameGuid is not None:\r
79b74a03
LG
812 #\r
813 # If the NameGuid reference a PCD name. \r
814 # The style must match: PCD(xxxx.yyy)\r
815 #\r
c8802c3d 816 if gPCDAsGuidPattern.match(FfsFile.NameGuid):\r
79b74a03
LG
817 #\r
818 # Replace the PCD value.\r
819 #\r
820 _PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")")\r
821 PcdFoundFlag = False\r
822 for Pa in self.AutoGenObjectList:\r
823 if not PcdFoundFlag:\r
824 for PcdItem in Pa.AllPcdList:\r
825 if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName:\r
826 #\r
827 # First convert from CFormatGuid to GUID string\r
828 #\r
829 _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)\r
47fea6af 830\r
79b74a03
LG
831 if not _PcdGuidString:\r
832 #\r
833 # Then try Byte array.\r
834 #\r
835 _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)\r
47fea6af 836\r
79b74a03
LG
837 if not _PcdGuidString:\r
838 #\r
839 # Not Byte array or CFormat GUID, raise error.\r
840 #\r
841 EdkLogger.error("build",\r
842 FORMAT_INVALID,\r
47fea6af 843 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue),\r
79b74a03 844 ExtraData=self.FdfFile)\r
47fea6af
YZ
845\r
846 if not _PcdGuidString.upper() in _GuidDict.keys():\r
79b74a03
LG
847 _GuidDict[_PcdGuidString.upper()] = FfsFile\r
848 PcdFoundFlag = True\r
849 break\r
850 else:\r
47fea6af 851 EdkLogger.error("build",\r
79b74a03 852 FORMAT_INVALID,\r
47fea6af 853 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
79b74a03
LG
854 FfsFile.CurrentLineContent,\r
855 _GuidDict[_PcdGuidString.upper()].CurrentLineNum,\r
856 _GuidDict[_PcdGuidString.upper()].CurrentLineContent,\r
857 FfsFile.NameGuid.upper()),\r
47fea6af
YZ
858 ExtraData=self.FdfFile)\r
859\r
79b74a03
LG
860 if not FfsFile.NameGuid.upper() in _GuidDict.keys():\r
861 _GuidDict[FfsFile.NameGuid.upper()] = FfsFile\r
862 else:\r
863 #\r
864 # Two raw file GUID conflict.\r
865 #\r
47fea6af 866 EdkLogger.error("build",\r
79b74a03 867 FORMAT_INVALID,\r
47fea6af 868 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
79b74a03
LG
869 FfsFile.CurrentLineContent,\r
870 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineNum,\r
871 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineContent,\r
872 FfsFile.NameGuid.upper()),\r
873 ExtraData=self.FdfFile)\r
47fea6af 874\r
79b74a03 875\r
4234283c
LG
876 def _CheckPcdDefineAndType(self):\r
877 PcdTypeList = [\r
878 "FixedAtBuild", "PatchableInModule", "FeatureFlag",\r
879 "Dynamic", #"DynamicHii", "DynamicVpd",\r
880 "DynamicEx", # "DynamicExHii", "DynamicExVpd"\r
881 ]\r
882\r
883 # This dict store PCDs which are not used by any modules with specified arches\r
9006a2c6 884 UnusedPcd = OrderedDict()\r
4234283c
LG
885 for Pa in self.AutoGenObjectList:\r
886 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
887 for Pcd in Pa.Platform.Pcds:\r
888 PcdType = Pa.Platform.Pcds[Pcd].Type\r
47fea6af 889\r
4234283c
LG
890 # If no PCD type, this PCD comes from FDF \r
891 if not PcdType:\r
892 continue\r
47fea6af 893\r
4234283c
LG
894 # Try to remove Hii and Vpd suffix\r
895 if PcdType.startswith("DynamicEx"):\r
896 PcdType = "DynamicEx"\r
897 elif PcdType.startswith("Dynamic"):\r
898 PcdType = "Dynamic"\r
47fea6af 899\r
4234283c
LG
900 for Package in Pa.PackageList:\r
901 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType\r
902 if (Pcd[0], Pcd[1], PcdType) in Package.Pcds:\r
903 break\r
904 for Type in PcdTypeList:\r
905 if (Pcd[0], Pcd[1], Type) in Package.Pcds:\r
906 EdkLogger.error(\r
907 'build',\r
908 FORMAT_INVALID,\r
909 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \\r
910 % (Pa.Platform.Pcds[Pcd].Type, Pcd[1], Pcd[0], Type),\r
911 ExtraData=None\r
912 )\r
913 return\r
914 else:\r
915 UnusedPcd.setdefault(Pcd, []).append(Pa.Arch)\r
916\r
917 for Pcd in UnusedPcd:\r
918 EdkLogger.warn(\r
919 'build',\r
920 "The PCD was not specified by any INF module in the platform for the given architecture.\n"\r
921 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"\r
922 % (Pcd[1], Pcd[0], os.path.basename(str(self.MetaFile)), str(UnusedPcd[Pcd])),\r
923 ExtraData=None\r
924 )\r
925\r
52302d4d
LG
926 def __repr__(self):\r
927 return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))\r
928\r
929 ## Return the directory to store FV files\r
930 def _GetFvDir(self):\r
4231a819 931 if self._FvDir is None:\r
52302d4d
LG
932 self._FvDir = path.join(self.BuildDir, 'FV')\r
933 return self._FvDir\r
934\r
935 ## Return the directory to store all intermediate and final files built\r
936 def _GetBuildDir(self):\r
4231a819 937 if self._BuildDir is None:\r
36d083ef 938 return self.AutoGenObjectList[0].BuildDir\r
52302d4d
LG
939\r
940 ## Return the build output directory platform specifies\r
941 def _GetOutputDir(self):\r
942 return self.Platform.OutputDirectory\r
943\r
944 ## Return platform name\r
945 def _GetName(self):\r
946 return self.Platform.PlatformName\r
947\r
948 ## Return meta-file GUID\r
949 def _GetGuid(self):\r
950 return self.Platform.Guid\r
951\r
952 ## Return platform version\r
953 def _GetVersion(self):\r
954 return self.Platform.Version\r
955\r
956 ## Return paths of tools\r
957 def _GetToolDefinition(self):\r
958 return self.AutoGenObjectList[0].ToolDefinition\r
959\r
960 ## Return directory of platform makefile\r
961 #\r
962 # @retval string Makefile directory\r
963 #\r
964 def _GetMakeFileDir(self):\r
4231a819 965 if self._MakeFileDir is None:\r
52302d4d
LG
966 self._MakeFileDir = self.BuildDir\r
967 return self._MakeFileDir\r
968\r
969 ## Return build command string\r
970 #\r
971 # @retval string Build command string\r
972 #\r
973 def _GetBuildCommand(self):\r
4231a819 974 if self._BuildCommand is None:\r
52302d4d
LG
975 # BuildCommand should be all the same. So just get one from platform AutoGen\r
976 self._BuildCommand = self.AutoGenObjectList[0].BuildCommand\r
977 return self._BuildCommand\r
47fea6af 978\r
6780eef1
LG
979 ## Check the PCDs token value conflict in each DEC file.\r
980 #\r
981 # Will cause build break and raise error message while two PCDs conflict.\r
982 # \r
983 # @return None\r
984 #\r
985 def _CheckAllPcdsTokenValueConflict(self):\r
b36d134f
LG
986 for Pa in self.AutoGenObjectList:\r
987 for Package in Pa.PackageList:\r
6780eef1 988 PcdList = Package.Pcds.values()\r
f827cd07 989 PcdList.sort(lambda x, y: cmp(int(x.TokenValue, 0), int(y.TokenValue, 0))) \r
6780eef1
LG
990 Count = 0\r
991 while (Count < len(PcdList) - 1) :\r
992 Item = PcdList[Count]\r
993 ItemNext = PcdList[Count + 1]\r
994 #\r
995 # Make sure in the same token space the TokenValue should be unique\r
996 #\r
f827cd07 997 if (int(Item.TokenValue, 0) == int(ItemNext.TokenValue, 0)):\r
6780eef1
LG
998 SameTokenValuePcdList = []\r
999 SameTokenValuePcdList.append(Item)\r
1000 SameTokenValuePcdList.append(ItemNext)\r
1001 RemainPcdListLength = len(PcdList) - Count - 2\r
1002 for ValueSameCount in range(RemainPcdListLength):\r
f827cd07 1003 if int(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount].TokenValue, 0) == int(Item.TokenValue, 0):\r
6780eef1
LG
1004 SameTokenValuePcdList.append(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount])\r
1005 else:\r
1006 break;\r
1007 #\r
1008 # Sort same token value PCD list with TokenGuid and TokenCName\r
1009 #\r
47fea6af
YZ
1010 SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
1011 SameTokenValuePcdListCount = 0\r
6780eef1 1012 while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):\r
2a29017e 1013 Flag = False\r
47fea6af
YZ
1014 TemListItem = SameTokenValuePcdList[SameTokenValuePcdListCount]\r
1015 TemListItemNext = SameTokenValuePcdList[SameTokenValuePcdListCount + 1]\r
1016\r
6780eef1 1017 if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):\r
2a29017e
YZ
1018 for PcdItem in GlobalData.MixedPcd:\r
1019 if (TemListItem.TokenCName, TemListItem.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem] or \\r
1020 (TemListItemNext.TokenCName, TemListItemNext.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1021 Flag = True\r
1022 if not Flag:\r
1023 EdkLogger.error(\r
1024 'build',\r
1025 FORMAT_INVALID,\r
1026 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\\r
1027 % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),\r
1028 ExtraData=None\r
1029 )\r
6780eef1
LG
1030 SameTokenValuePcdListCount += 1\r
1031 Count += SameTokenValuePcdListCount\r
1032 Count += 1\r
47fea6af 1033\r
6780eef1 1034 PcdList = Package.Pcds.values()\r
47fea6af 1035 PcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
6780eef1
LG
1036 Count = 0\r
1037 while (Count < len(PcdList) - 1) :\r
1038 Item = PcdList[Count]\r
47fea6af 1039 ItemNext = PcdList[Count + 1]\r
6780eef1
LG
1040 #\r
1041 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.\r
1042 #\r
f827cd07 1043 if (Item.TokenSpaceGuidCName == ItemNext.TokenSpaceGuidCName) and (Item.TokenCName == ItemNext.TokenCName) and (int(Item.TokenValue, 0) != int(ItemNext.TokenValue, 0)):\r
6780eef1
LG
1044 EdkLogger.error(\r
1045 'build',\r
1046 FORMAT_INVALID,\r
1047 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\\r
1048 % (Item.TokenValue, Item.TokenSpaceGuidCName, Item.TokenCName, Package),\r
1049 ExtraData=None\r
1050 )\r
1051 Count += 1\r
97fa0ee9 1052 ## Generate fds command\r
03af2753
HC
1053 def _GenFdsCommand(self):\r
1054 return (GenMake.TopLevelMakefile(self)._TEMPLATE_.Replace(GenMake.TopLevelMakefile(self)._TemplateDict)).strip()\r
52302d4d 1055\r
e56468c0 1056 ## Create makefile for the platform and modules in it\r
52302d4d
LG
1057 #\r
1058 # @param CreateDepsMakeFile Flag indicating if the makefile for\r
1059 # modules will be created as well\r
1060 #\r
1061 def CreateMakeFile(self, CreateDepsMakeFile=False):\r
52302d4d
LG
1062 if CreateDepsMakeFile:\r
1063 for Pa in self.AutoGenObjectList:\r
1064 Pa.CreateMakeFile(CreateDepsMakeFile)\r
1065\r
1066 ## Create autogen code for platform and modules\r
1067 #\r
1068 # Since there's no autogen code for platform, this method will do nothing\r
1069 # if CreateModuleCodeFile is set to False.\r
1070 #\r
1071 # @param CreateDepsCodeFile Flag indicating if creating module's\r
1072 # autogen code file or not\r
1073 #\r
1074 def CreateCodeFile(self, CreateDepsCodeFile=False):\r
1075 if not CreateDepsCodeFile:\r
1076 return\r
1077 for Pa in self.AutoGenObjectList:\r
1078 Pa.CreateCodeFile(CreateDepsCodeFile)\r
1079\r
7c1fd323
LG
1080 ## Create AsBuilt INF file the platform\r
1081 #\r
1082 def CreateAsBuiltInf(self):\r
1083 return\r
1084\r
52302d4d
LG
1085 Name = property(_GetName)\r
1086 Guid = property(_GetGuid)\r
1087 Version = property(_GetVersion)\r
1088 OutputDir = property(_GetOutputDir)\r
1089\r
1090 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
1091\r
1092 BuildDir = property(_GetBuildDir)\r
1093 FvDir = property(_GetFvDir)\r
1094 MakeFileDir = property(_GetMakeFileDir)\r
1095 BuildCommand = property(_GetBuildCommand)\r
03af2753 1096 GenFdsCommand = property(_GenFdsCommand)\r
52302d4d
LG
1097\r
1098## AutoGen class for platform\r
1099#\r
1100# PlatformAutoGen class will process the original information in platform\r
1101# file in order to generate makefile for platform.\r
1102#\r
1103class PlatformAutoGen(AutoGen):\r
b24e99f7
CJ
1104 # call super().__init__ then call the worker function with different parameter count\r
1105 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
1106 try:\r
1107 self._Init\r
1108 except:\r
1109 super(PlatformAutoGen, self).__init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
1110 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch)\r
1111 self._Init = True\r
52302d4d
LG
1112 #\r
1113 # Used to store all PCDs for both PEI and DXE phase, in order to generate \r
1114 # correct PCD database\r
1115 # \r
1116 _DynaPcdList_ = []\r
1117 _NonDynaPcdList_ = []\r
61ee1dff 1118 _PlatformPcds = {}\r
6780eef1
LG
1119 \r
1120 #\r
1121 # The priority list while override build option \r
1122 #\r
1123 PrioList = {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)\r
1124 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
1125 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
1126 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE \r
1127 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
1128 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
1129 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
1130 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE\r
1131 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
1132 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
1133 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE\r
1134 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE\r
1135 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE\r
1136 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE\r
1137 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE\r
1138 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)\r
47fea6af 1139\r
b24e99f7 1140 ## Initialize PlatformAutoGen\r
52302d4d 1141 #\r
52302d4d
LG
1142 #\r
1143 # @param Workspace WorkspaceAutoGen object\r
1144 # @param PlatformFile Platform file (DSC file)\r
1145 # @param Target Build target (DEBUG, RELEASE)\r
1146 # @param Toolchain Name of tool chain\r
1147 # @param Arch arch of the platform supports\r
1148 #\r
b24e99f7 1149 def _InitWorker(self, Workspace, PlatformFile, Target, Toolchain, Arch):\r
52302d4d
LG
1150 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))\r
1151 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)\r
1152\r
1153 self.MetaFile = PlatformFile\r
1154 self.Workspace = Workspace\r
1155 self.WorkspaceDir = Workspace.WorkspaceDir\r
1156 self.ToolChain = Toolchain\r
1157 self.BuildTarget = Target\r
1158 self.Arch = Arch\r
1159 self.SourceDir = PlatformFile.SubDir\r
1160 self.SourceOverrideDir = None\r
1161 self.FdTargetList = self.Workspace.FdTargetList\r
1162 self.FvTargetList = self.Workspace.FvTargetList\r
1163 self.AllPcdList = []\r
a0a2cd1e
FB
1164 # get the original module/package/platform objects\r
1165 self.BuildDatabase = Workspace.BuildDatabase\r
8518bf0b 1166 self.DscBuildDataObj = Workspace.Platform\r
35f613d9 1167 self._GuidDict = Workspace._GuidDict\r
52302d4d
LG
1168\r
1169 # flag indicating if the makefile/C-code file has been created or not\r
1170 self.IsMakeFileCreated = False\r
1171 self.IsCodeFileCreated = False\r
1172\r
1173 self._Platform = None\r
1174 self._Name = None\r
1175 self._Guid = None\r
1176 self._Version = None\r
1177\r
1178 self._BuildRule = None\r
1179 self._SourceDir = None\r
1180 self._BuildDir = None\r
1181 self._OutputDir = None\r
1182 self._FvDir = None\r
1183 self._MakeFileDir = None\r
1184 self._FdfFile = None\r
1185\r
1186 self._PcdTokenNumber = None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
1187 self._DynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
1188 self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2bc3256c 1189 self._NonDynamicPcdDict = {}\r
52302d4d
LG
1190\r
1191 self._ToolDefinitions = None\r
1192 self._ToolDefFile = None # toolcode : tool path\r
1193 self._ToolChainFamily = None\r
1194 self._BuildRuleFamily = None\r
1195 self._BuildOption = None # toolcode : option\r
1196 self._EdkBuildOption = None # edktoolcode : option\r
1197 self._EdkIIBuildOption = None # edkiitoolcode : option\r
1198 self._PackageList = None\r
1199 self._ModuleAutoGenList = None\r
1200 self._LibraryAutoGenList = None\r
1201 self._BuildCommand = None\r
a0a2cd1e
FB
1202 self._AsBuildInfList = []\r
1203 self._AsBuildModuleList = []\r
47854fd5
LG
1204\r
1205 self.VariableInfo = None\r
1206\r
4231a819 1207 if GlobalData.gFdfParser is not None:\r
a0a2cd1e
FB
1208 self._AsBuildInfList = GlobalData.gFdfParser.Profile.InfList\r
1209 for Inf in self._AsBuildInfList:\r
1210 InfClass = PathClass(NormPath(Inf), GlobalData.gWorkspace, self.Arch)\r
1211 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
1212 if not M.IsSupportedArch:\r
1213 continue\r
1214 self._AsBuildModuleList.append(InfClass)\r
03af2753
HC
1215 # get library/modules for build\r
1216 self.LibraryBuildDirectoryList = []\r
1217 self.ModuleBuildDirectoryList = []\r
47854fd5 1218\r
52302d4d
LG
1219 return True\r
1220\r
1221 def __repr__(self):\r
1222 return "%s [%s]" % (self.MetaFile, self.Arch)\r
1223\r
1224 ## Create autogen code for platform and modules\r
1225 #\r
1226 # Since there's no autogen code for platform, this method will do nothing\r
1227 # if CreateModuleCodeFile is set to False.\r
1228 #\r
1229 # @param CreateModuleCodeFile Flag indicating if creating module's\r
1230 # autogen code file or not\r
1231 #\r
1232 def CreateCodeFile(self, CreateModuleCodeFile=False):\r
1233 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False\r
1234 if self.IsCodeFileCreated or not CreateModuleCodeFile:\r
1235 return\r
1236\r
1237 for Ma in self.ModuleAutoGenList:\r
1238 Ma.CreateCodeFile(True)\r
1239\r
1240 # don't do this twice\r
1241 self.IsCodeFileCreated = True\r
1242\r
03af2753
HC
1243 ## Generate Fds Command\r
1244 def _GenFdsCommand(self):\r
1245 return self.Workspace.GenFdsCommand\r
481252bb 1246\r
52302d4d
LG
1247 ## Create makefile for the platform and mdoules in it\r
1248 #\r
1249 # @param CreateModuleMakeFile Flag indicating if the makefile for\r
1250 # modules will be created as well\r
1251 #\r
37de70b7 1252 def CreateMakeFile(self, CreateModuleMakeFile=False, FfsCommand = {}):\r
52302d4d
LG
1253 if CreateModuleMakeFile:\r
1254 for ModuleFile in self.Platform.Modules:\r
1255 Ma = ModuleAutoGen(self.Workspace, ModuleFile, self.BuildTarget,\r
1256 self.ToolChain, self.Arch, self.MetaFile)\r
37de70b7
YZ
1257 if (ModuleFile.File, self.Arch) in FfsCommand:\r
1258 Ma.CreateMakeFile(True, FfsCommand[ModuleFile.File, self.Arch])\r
1259 else:\r
1260 Ma.CreateMakeFile(True)\r
97fa0ee9 1261 #Ma.CreateAsBuiltInf()\r
52302d4d
LG
1262\r
1263 # no need to create makefile for the platform more than once\r
1264 if self.IsMakeFileCreated:\r
1265 return\r
1266\r
03af2753 1267 # create library/module build dirs for platform\r
52302d4d 1268 Makefile = GenMake.PlatformMakefile(self)\r
03af2753
HC
1269 self.LibraryBuildDirectoryList = Makefile.GetLibraryBuildDirectoryList()\r
1270 self.ModuleBuildDirectoryList = Makefile.GetModuleBuildDirectoryList()\r
1271\r
52302d4d
LG
1272 self.IsMakeFileCreated = True\r
1273\r
2bc3256c
LG
1274 ## Deal with Shared FixedAtBuild Pcds\r
1275 #\r
1276 def CollectFixedAtBuildPcds(self):\r
1277 for LibAuto in self.LibraryAutoGenList:\r
1278 FixedAtBuildPcds = {} \r
1279 ShareFixedAtBuildPcdsSameValue = {} \r
1280 for Module in LibAuto._ReferenceModules: \r
eca980c0 1281 for Pcd in Module.FixedAtBuildPcds:\r
2bc3256c
LG
1282 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName)) \r
1283 if key not in FixedAtBuildPcds:\r
1284 ShareFixedAtBuildPcdsSameValue[key] = True\r
1285 FixedAtBuildPcds[key] = Pcd.DefaultValue\r
1286 else:\r
1287 if FixedAtBuildPcds[key] != Pcd.DefaultValue:\r
1288 ShareFixedAtBuildPcdsSameValue[key] = False \r
1289 for Pcd in LibAuto.FixedAtBuildPcds:\r
1290 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
1291 if (Pcd.TokenCName,Pcd.TokenSpaceGuidCName) not in self.NonDynamicPcdDict:\r
1292 continue\r
1293 else:\r
1294 DscPcd = self.NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)]\r
1295 if DscPcd.Type != "FixedAtBuild":\r
1296 continue\r
1297 if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]: \r
eca980c0 1298 LibAuto.ConstPcd[key] = FixedAtBuildPcds[key]\r
2bc3256c 1299\r
34952f49 1300 def CollectVariables(self, DynamicPcdSet):\r
47854fd5
LG
1301\r
1302 VpdRegionSize = 0\r
1303 VpdRegionBase = 0\r
1304 if self.Workspace.FdfFile:\r
1305 FdDict = self.Workspace.FdfProfile.FdDict[GlobalData.gFdfParser.CurrentFdName]\r
1306 for FdRegion in FdDict.RegionList:\r
1307 for item in FdRegion.RegionDataList:\r
1308 if self.Platform.VpdToolGuid.strip() and self.Platform.VpdToolGuid in item:\r
1309 VpdRegionSize = FdRegion.Size\r
1310 VpdRegionBase = FdRegion.Offset\r
1311 break\r
1312\r
1313\r
8518bf0b 1314 VariableInfo = VariableMgr(self.DscBuildDataObj._GetDefaultStores(),self.DscBuildDataObj._GetSkuIds())\r
47854fd5
LG
1315 VariableInfo.SetVpdRegionMaxSize(VpdRegionSize)\r
1316 VariableInfo.SetVpdRegionOffset(VpdRegionBase)\r
34952f49
LG
1317 Index = 0\r
1318 for Pcd in DynamicPcdSet:\r
8518bf0b
LG
1319 pcdname = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
1320 for SkuName in Pcd.SkuInfoList:\r
1321 Sku = Pcd.SkuInfoList[SkuName]\r
1322 SkuId = Sku.SkuId\r
4231a819 1323 if SkuId is None or SkuId == '':\r
8518bf0b
LG
1324 continue\r
1325 if len(Sku.VariableName) > 0:\r
1326 VariableGuidStructure = Sku.VariableGuidValue\r
1327 VariableGuid = GuidStructureStringToGuidString(VariableGuidStructure)\r
a3623244 1328 for StorageName in Sku.DefaultStoreDict:\r
e6bf3cfd 1329 VariableInfo.append_variable(var_info(Index,pcdname,StorageName,SkuName, StringToArray(Sku.VariableName),VariableGuid, Sku.VariableOffset, Sku.VariableAttribute , Sku.HiiDefaultValue,Sku.DefaultStoreDict[StorageName],Pcd.DatumType))\r
34952f49
LG
1330 Index += 1\r
1331 return VariableInfo\r
47854fd5
LG
1332\r
1333 def UpdateNVStoreMaxSize(self,OrgVpdFile):\r
0b6c5954
LG
1334 if self.VariableInfo:\r
1335 VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
1336 PcdNvStoreDfBuffer = [item for item in self._DynamicPcdList if item.TokenCName == "PcdNvStoreDefaultValueBuffer" and item.TokenSpaceGuidCName == "gEfiMdeModulePkgTokenSpaceGuid"]\r
1337\r
1338 if PcdNvStoreDfBuffer:\r
1339 if os.path.exists(VpdMapFilePath):\r
1340 OrgVpdFile.Read(VpdMapFilePath)\r
1341 PcdItems = OrgVpdFile.GetOffset(PcdNvStoreDfBuffer[0])\r
8ac16789 1342 NvStoreOffset = PcdItems.values()[0].strip() if PcdItems else '0'\r
0b6c5954
LG
1343 else:\r
1344 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
1345\r
1346 NvStoreOffset = int(NvStoreOffset,16) if NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset)\r
1347 default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get("DEFAULT")\r
1348 maxsize = self.VariableInfo.VpdRegionSize - NvStoreOffset if self.VariableInfo.VpdRegionSize else len(default_skuobj.DefaultValue.split(","))\r
1349 var_data = self.VariableInfo.PatchNVStoreDefaultMaxSize(maxsize)\r
1350\r
1351 if var_data and default_skuobj:\r
1352 default_skuobj.DefaultValue = var_data\r
1353 PcdNvStoreDfBuffer[0].DefaultValue = var_data\r
1354 PcdNvStoreDfBuffer[0].SkuInfoList.clear()\r
1355 PcdNvStoreDfBuffer[0].SkuInfoList['DEFAULT'] = default_skuobj\r
1356 PcdNvStoreDfBuffer[0].MaxDatumSize = str(len(default_skuobj.DefaultValue.split(",")))\r
47854fd5
LG
1357\r
1358 return OrgVpdFile\r
1359\r
52302d4d
LG
1360 ## Collect dynamic PCDs\r
1361 #\r
1362 # Gather dynamic PCDs list from each module and their settings from platform\r
1363 # This interface should be invoked explicitly when platform action is created.\r
1364 #\r
1365 def CollectPlatformDynamicPcds(self):\r
763e8edf 1366\r
2a29017e
YZ
1367 for key in self.Platform.Pcds:\r
1368 for SinglePcd in GlobalData.MixedPcd:\r
1369 if (self.Platform.Pcds[key].TokenCName, self.Platform.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
1370 for item in GlobalData.MixedPcd[SinglePcd]:\r
1371 Pcd_Type = item[0].split('_')[-1]\r
1372 if (Pcd_Type == self.Platform.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and self.Platform.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
1373 (Pcd_Type == TAB_PCDS_DYNAMIC and self.Platform.Pcds[key].Type in GenC.gDynamicPcd):\r
1374 Value = self.Platform.Pcds[key]\r
1375 Value.TokenCName = self.Platform.Pcds[key].TokenCName + '_' + Pcd_Type\r
1376 if len(key) == 2:\r
1377 newkey = (Value.TokenCName, key[1])\r
1378 elif len(key) == 3:\r
1379 newkey = (Value.TokenCName, key[1], key[2])\r
1380 del self.Platform.Pcds[key]\r
1381 self.Platform.Pcds[newkey] = Value\r
1382 break\r
1383 else:\r
1384 pass\r
1385 break\r
1386 else:\r
1387 pass\r
1388\r
52302d4d
LG
1389 # for gathering error information\r
1390 NoDatumTypePcdList = set()\r
a0a2cd1e
FB
1391 FdfModuleList = []\r
1392 for InfName in self._AsBuildInfList:\r
05cc51ad 1393 InfName = mws.join(self.WorkspaceDir, InfName)\r
a0a2cd1e 1394 FdfModuleList.append(os.path.normpath(InfName))\r
52302d4d
LG
1395 for F in self.Platform.Modules.keys():\r
1396 M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)\r
1397 #GuidValue.update(M.Guids)\r
1398 \r
1399 self.Platform.Modules[F].M = M\r
47fea6af
YZ
1400\r
1401 for PcdFromModule in M.ModulePcdList + M.LibraryPcdList:\r
52302d4d 1402 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
e8a47801 1403 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
52302d4d
LG
1404 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))\r
1405\r
97fa0ee9 1406 # Check the PCD from Binary INF or Source INF\r
a0a2cd1e
FB
1407 if M.IsBinaryModule == True:\r
1408 PcdFromModule.IsFromBinaryInf = True\r
97fa0ee9
YL
1409\r
1410 # Check the PCD from DSC or not \r
a0a2cd1e
FB
1411 if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys():\r
1412 PcdFromModule.IsFromDsc = True\r
1413 else:\r
1414 PcdFromModule.IsFromDsc = False\r
52302d4d 1415 if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:\r
a0a2cd1e
FB
1416 if F.Path not in FdfModuleList:\r
1417 # If one of the Source built modules listed in the DSC is not listed \r
1418 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic \r
1419 # access method (it is only listed in the DEC file that declares the \r
1420 # PCD as PcdsDynamic), then build tool will report warning message\r
1421 # notify the PI that they are attempting to build a module that must \r
1422 # be included in a flash image in order to be functional. These Dynamic \r
1423 # PCD will not be added into the Database unless it is used by other \r
1424 # modules that are included in the FDF file.\r
1425 if PcdFromModule.Type in GenC.gDynamicPcd and \\r
1426 PcdFromModule.IsFromBinaryInf == False:\r
1427 # Print warning message to let the developer make a determine.\r
a0a2cd1e
FB
1428 continue\r
1429 # If one of the Source built modules listed in the DSC is not listed in \r
1430 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx \r
1431 # access method (it is only listed in the DEC file that declares the \r
1432 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the \r
1433 # PCD to the Platform's PCD Database.\r
1434 if PcdFromModule.Type in GenC.gDynamicExPcd:\r
a0a2cd1e 1435 continue\r
52302d4d
LG
1436 #\r
1437 # If a dynamic PCD used by a PEM module/PEI module & DXE module,\r
1438 # it should be stored in Pcd PEI database, If a dynamic only\r
1439 # used by DXE module, it should be stored in DXE PCD database.\r
1440 # The default Phase is DXE\r
1441 #\r
1442 if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
1443 PcdFromModule.Phase = "PEI"\r
1444 if PcdFromModule not in self._DynaPcdList_:\r
1445 self._DynaPcdList_.append(PcdFromModule)\r
1446 elif PcdFromModule.Phase == 'PEI':\r
1447 # overwrite any the same PCD existing, if Phase is PEI\r
1448 Index = self._DynaPcdList_.index(PcdFromModule)\r
1449 self._DynaPcdList_[Index] = PcdFromModule\r
1450 elif PcdFromModule not in self._NonDynaPcdList_:\r
1451 self._NonDynaPcdList_.append(PcdFromModule)\r
a0a2cd1e
FB
1452 elif PcdFromModule in self._NonDynaPcdList_ and PcdFromModule.IsFromBinaryInf == True:\r
1453 Index = self._NonDynaPcdList_.index(PcdFromModule)\r
1454 if self._NonDynaPcdList_[Index].IsFromBinaryInf == False:\r
1455 #The PCD from Binary INF will override the same one from source INF\r
1456 self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])\r
1457 PcdFromModule.Pending = False\r
1458 self._NonDynaPcdList_.append (PcdFromModule)\r
1459 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.\r
1460 DscModuleList = []\r
1461 for ModuleInf in self.Platform.Modules.keys():\r
1462 DscModuleList.append (os.path.normpath(ModuleInf.Path))\r
1463 # add the PCD from modules that listed in FDF but not in DSC to Database \r
1464 for InfName in FdfModuleList:\r
1465 if InfName not in DscModuleList:\r
1466 InfClass = PathClass(InfName)\r
1467 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
1468 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source) \r
1469 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here. \r
1470 # For binary module, if in current arch, we need to list the PCDs into database. \r
1471 if not M.IsSupportedArch:\r
1472 continue\r
1473 # Override the module PCD setting by platform setting\r
1474 ModulePcdList = self.ApplyPcdSetting(M, M.Pcds)\r
1475 for PcdFromModule in ModulePcdList:\r
1476 PcdFromModule.IsFromBinaryInf = True\r
1477 PcdFromModule.IsFromDsc = False\r
1478 # Only allow the DynamicEx and Patchable PCD in AsBuild INF\r
1479 if PcdFromModule.Type not in GenC.gDynamicExPcd and PcdFromModule.Type not in TAB_PCDS_PATCHABLE_IN_MODULE:\r
1480 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
1481 File=self.MetaFile,\r
1482 ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n"\r
1483 % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName))\r
1484 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
1485 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
1486 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))\r
1487 if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
1488 PcdFromModule.Phase = "PEI"\r
1489 if PcdFromModule not in self._DynaPcdList_ and PcdFromModule.Type in GenC.gDynamicExPcd:\r
1490 self._DynaPcdList_.append(PcdFromModule)\r
1491 elif PcdFromModule not in self._NonDynaPcdList_ and PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE:\r
1492 self._NonDynaPcdList_.append(PcdFromModule)\r
1493 if PcdFromModule in self._DynaPcdList_ and PcdFromModule.Phase == 'PEI' and PcdFromModule.Type in GenC.gDynamicExPcd:\r
97fa0ee9
YL
1494 # Overwrite the phase of any the same PCD existing, if Phase is PEI.\r
1495 # It is to solve the case that a dynamic PCD used by a PEM module/PEI \r
1496 # module & DXE module at a same time.\r
1497 # Overwrite the type of the PCDs in source INF by the type of AsBuild\r
1498 # INF file as DynamicEx. \r
a0a2cd1e
FB
1499 Index = self._DynaPcdList_.index(PcdFromModule)\r
1500 self._DynaPcdList_[Index].Phase = PcdFromModule.Phase\r
1501 self._DynaPcdList_[Index].Type = PcdFromModule.Type\r
1502 for PcdFromModule in self._NonDynaPcdList_:\r
1503 # If a PCD is not listed in the DSC file, but binary INF files used by \r
1504 # this platform all (that use this PCD) list the PCD in a [PatchPcds] \r
1505 # section, AND all source INF files used by this platform the build \r
1506 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds] \r
1507 # section, then the tools must NOT add the PCD to the Platform's PCD\r
1508 # Database; the build must assign the access method for this PCD as \r
1509 # PcdsPatchableInModule.\r
1510 if PcdFromModule not in self._DynaPcdList_:\r
1511 continue\r
1512 Index = self._DynaPcdList_.index(PcdFromModule)\r
1513 if PcdFromModule.IsFromDsc == False and \\r
1514 PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE and \\r
1515 PcdFromModule.IsFromBinaryInf == True and \\r
1516 self._DynaPcdList_[Index].IsFromBinaryInf == False:\r
1517 Index = self._DynaPcdList_.index(PcdFromModule)\r
1518 self._DynaPcdList_.remove (self._DynaPcdList_[Index])\r
52302d4d
LG
1519\r
1520 # print out error information and break the build, if error found\r
1521 if len(NoDatumTypePcdList) > 0:\r
1522 NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)\r
1523 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
1524 File=self.MetaFile,\r
1525 ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"\r
1526 % NoDatumTypePcdListString)\r
1527 self._NonDynamicPcdList = self._NonDynaPcdList_\r
1528 self._DynamicPcdList = self._DynaPcdList_\r
52302d4d
LG
1529 #\r
1530 # Sort dynamic PCD list to:\r
1531 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should \r
1532 # try to be put header of dynamicd List\r
1533 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD\r
1534 #\r
1535 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.\r
1536 #\r
0b6c5954
LG
1537 UnicodePcdArray = set()\r
1538 HiiPcdArray = set()\r
1539 OtherPcdArray = set()\r
6780eef1 1540 VpdPcdDict = {}\r
e56468c0 1541 VpdFile = VpdInfoFile.VpdInfoFile()\r
61ee1dff
YZ
1542 NeedProcessVpdMapFile = False\r
1543\r
1544 for pcd in self.Platform.Pcds.keys():\r
1545 if pcd not in self._PlatformPcds.keys():\r
1546 self._PlatformPcds[pcd] = self.Platform.Pcds[pcd]\r
1547\r
ae7b6df8
LG
1548 for item in self._PlatformPcds:\r
1549 if self._PlatformPcds[item].DatumType and self._PlatformPcds[item].DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
1550 self._PlatformPcds[item].DatumType = "VOID*"\r
1551\r
e56468c0 1552 if (self.Workspace.ArchList[-1] == self.Arch): \r
1553 for Pcd in self._DynamicPcdList:\r
e56468c0 1554 # just pick the a value to determine whether is unicode string type\r
47fea6af 1555 Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]\r
e56468c0 1556 Sku.VpdOffset = Sku.VpdOffset.strip()\r
47fea6af 1557\r
ae7b6df8
LG
1558 if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
1559 Pcd.DatumType = "VOID*"\r
1560\r
e56468c0 1561 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
e56468c0 1562 # if found HII type PCD then insert to right of UnicodeIndex\r
e56468c0 1563 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
47fea6af
YZ
1564 VpdPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)] = Pcd\r
1565\r
34952f49
LG
1566 #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer\r
1567 PcdNvStoreDfBuffer = VpdPcdDict.get(("PcdNvStoreDefaultValueBuffer","gEfiMdeModulePkgTokenSpaceGuid"))\r
1568 if PcdNvStoreDfBuffer:\r
47854fd5 1569 self.VariableInfo = self.CollectVariables(self._DynamicPcdList)\r
47854fd5 1570 vardump = self.VariableInfo.dump()\r
626bece4 1571 if vardump:\r
2b8a6c44 1572 PcdNvStoreDfBuffer.DefaultValue = vardump\r
626bece4
LG
1573 for skuname in PcdNvStoreDfBuffer.SkuInfoList:\r
1574 PcdNvStoreDfBuffer.SkuInfoList[skuname].DefaultValue = vardump\r
1575 PcdNvStoreDfBuffer.MaxDatumSize = str(len(vardump.split(",")))\r
34952f49 1576\r
61ee1dff 1577 PlatformPcds = self._PlatformPcds.keys()\r
47fea6af 1578 PlatformPcds.sort()\r
6780eef1
LG
1579 #\r
1580 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.\r
1581 #\r
626bece4 1582 VpdSkuMap = {}\r
6780eef1 1583 for PcdKey in PlatformPcds:\r
61ee1dff 1584 Pcd = self._PlatformPcds[PcdKey]\r
e8a47801
LG
1585 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD] and \\r
1586 PcdKey in VpdPcdDict:\r
1587 Pcd = VpdPcdDict[PcdKey]\r
626bece4 1588 SkuValueMap = {}\r
8ac16789
LG
1589 DefaultSku = Pcd.SkuInfoList.get('DEFAULT')\r
1590 if DefaultSku:\r
1591 PcdValue = DefaultSku.DefaultValue\r
1592 if PcdValue not in SkuValueMap:\r
1593 SkuValueMap[PcdValue] = []\r
1594 VpdFile.Add(Pcd, 'DEFAULT',DefaultSku.VpdOffset)\r
1595 SkuValueMap[PcdValue].append(DefaultSku)\r
1596\r
e8a47801
LG
1597 for (SkuName,Sku) in Pcd.SkuInfoList.items():\r
1598 Sku.VpdOffset = Sku.VpdOffset.strip()\r
5a13737a
YZ
1599 PcdValue = Sku.DefaultValue\r
1600 if PcdValue == "":\r
1601 PcdValue = Pcd.DefaultValue\r
1602 if Sku.VpdOffset != '*':\r
1603 if PcdValue.startswith("{"):\r
1604 Alignment = 8\r
1605 elif PcdValue.startswith("L"):\r
1606 Alignment = 2\r
1607 else:\r
1608 Alignment = 1\r
ca85291f
YZ
1609 try:\r
1610 VpdOffset = int(Sku.VpdOffset)\r
1611 except:\r
1612 try:\r
1613 VpdOffset = int(Sku.VpdOffset, 16)\r
1614 except:\r
1615 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
1616 if VpdOffset % Alignment != 0:\r
815ada26
YZ
1617 if PcdValue.startswith("{"):\r
1618 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName), File=self.MetaFile)\r
1619 else:\r
1620 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Alignment))\r
626bece4
LG
1621 if PcdValue not in SkuValueMap:\r
1622 SkuValueMap[PcdValue] = []\r
8ac16789 1623 VpdFile.Add(Pcd, SkuName,Sku.VpdOffset)\r
626bece4 1624 SkuValueMap[PcdValue].append(Sku)\r
e8a47801
LG
1625 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
1626 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
1627 NeedProcessVpdMapFile = True\r
4231a819 1628 if self.Platform.VpdToolGuid is None or self.Platform.VpdToolGuid == '':\r
e8a47801
LG
1629 EdkLogger.error("Build", FILE_NOT_FOUND, \\r
1630 "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.")\r
47fea6af 1631\r
626bece4 1632 VpdSkuMap[PcdKey] = SkuValueMap\r
e56468c0 1633 #\r
1634 # Fix the PCDs define in VPD PCD section that never referenced by module.\r
1635 # An example is PCD for signature usage.\r
6780eef1
LG
1636 # \r
1637 for DscPcd in PlatformPcds:\r
61ee1dff 1638 DscPcdEntry = self._PlatformPcds[DscPcd]\r
e56468c0 1639 if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
4231a819 1640 if not (self.Platform.VpdToolGuid is None or self.Platform.VpdToolGuid == ''):\r
e56468c0 1641 FoundFlag = False\r
1642 for VpdPcd in VpdFile._VpdArray.keys():\r
1643 # This PCD has been referenced by module\r
1644 if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
1645 (VpdPcd.TokenCName == DscPcdEntry.TokenCName):\r
1646 FoundFlag = True\r
47fea6af 1647\r
e56468c0 1648 # Not found, it should be signature\r
1649 if not FoundFlag :\r
1650 # just pick the a value to determine whether is unicode string type\r
626bece4 1651 SkuValueMap = {}\r
e827d21d 1652 SkuObjList = DscPcdEntry.SkuInfoList.items()\r
8ac16789
LG
1653 DefaultSku = DscPcdEntry.SkuInfoList.get('DEFAULT')\r
1654 if DefaultSku:\r
e827d21d
B
1655 defaultindex = SkuObjList.index(('DEFAULT',DefaultSku))\r
1656 SkuObjList[0],SkuObjList[defaultindex] = SkuObjList[defaultindex],SkuObjList[0]\r
1657 for (SkuName,Sku) in SkuObjList:\r
e8a47801
LG
1658 Sku.VpdOffset = Sku.VpdOffset.strip() \r
1659 \r
1660 # Need to iterate DEC pcd information to get the value & datumtype\r
1661 for eachDec in self.PackageList:\r
1662 for DecPcd in eachDec.Pcds:\r
1663 DecPcdEntry = eachDec.Pcds[DecPcd]\r
1664 if (DecPcdEntry.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
1665 (DecPcdEntry.TokenCName == DscPcdEntry.TokenCName):\r
1666 # Print warning message to let the developer make a determine.\r
1667 EdkLogger.warn("build", "Unreferenced vpd pcd used!",\r
1668 File=self.MetaFile, \\r
1669 ExtraData = "PCD: %s.%s used in the DSC file %s is unreferenced." \\r
1670 %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, self.Platform.MetaFile.Path)) \r
1671 \r
1672 DscPcdEntry.DatumType = DecPcdEntry.DatumType\r
1673 DscPcdEntry.DefaultValue = DecPcdEntry.DefaultValue\r
1674 DscPcdEntry.TokenValue = DecPcdEntry.TokenValue\r
1675 DscPcdEntry.TokenSpaceGuidValue = eachDec.Guids[DecPcdEntry.TokenSpaceGuidCName]\r
1676 # Only fix the value while no value provided in DSC file.\r
1677 if (Sku.DefaultValue == "" or Sku.DefaultValue==None):\r
1678 DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue\r
1679 \r
1680 if DscPcdEntry not in self._DynamicPcdList:\r
1681 self._DynamicPcdList.append(DscPcdEntry)\r
e8a47801
LG
1682 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1683 PcdValue = Sku.DefaultValue\r
5a13737a
YZ
1684 if PcdValue == "":\r
1685 PcdValue = DscPcdEntry.DefaultValue\r
1686 if Sku.VpdOffset != '*':\r
1687 if PcdValue.startswith("{"):\r
1688 Alignment = 8\r
1689 elif PcdValue.startswith("L"):\r
1690 Alignment = 2\r
1691 else:\r
1692 Alignment = 1\r
ca85291f
YZ
1693 try:\r
1694 VpdOffset = int(Sku.VpdOffset)\r
1695 except:\r
1696 try:\r
1697 VpdOffset = int(Sku.VpdOffset, 16)\r
1698 except:\r
1699 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName))\r
1700 if VpdOffset % Alignment != 0:\r
815ada26
YZ
1701 if PcdValue.startswith("{"):\r
1702 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName), File=self.MetaFile)\r
1703 else:\r
1704 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, Alignment))\r
626bece4
LG
1705 if PcdValue not in SkuValueMap:\r
1706 SkuValueMap[PcdValue] = []\r
8ac16789 1707 VpdFile.Add(DscPcdEntry, SkuName,Sku.VpdOffset)\r
626bece4 1708 SkuValueMap[PcdValue].append(Sku)\r
e8a47801
LG
1709 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
1710 NeedProcessVpdMapFile = True \r
1711 if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
0b6c5954 1712 UnicodePcdArray.add(DscPcdEntry)\r
e8a47801 1713 elif len(Sku.VariableName) > 0:\r
0b6c5954 1714 HiiPcdArray.add(DscPcdEntry)\r
e8a47801 1715 else:\r
0b6c5954
LG
1716 OtherPcdArray.add(DscPcdEntry)\r
1717\r
e8a47801 1718 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
626bece4 1719 VpdSkuMap[DscPcd] = SkuValueMap\r
4231a819 1720 if (self.Platform.FlashDefinition is None or self.Platform.FlashDefinition == '') and \\r
e56468c0 1721 VpdFile.GetCount() != 0:\r
1722 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, \r
1723 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self.Platform.MetaFile))\r
47fea6af 1724\r
e56468c0 1725 if VpdFile.GetCount() != 0:\r
47854fd5
LG
1726\r
1727 self.FixVpdOffset(VpdFile)\r
1728\r
1729 self.FixVpdOffset(self.UpdateNVStoreMaxSize(VpdFile))\r
47fea6af 1730\r
e56468c0 1731 # Process VPD map file generated by third party BPDG tool\r
1732 if NeedProcessVpdMapFile:\r
08dd311f 1733 VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
e56468c0 1734 if os.path.exists(VpdMapFilePath):\r
1735 VpdFile.Read(VpdMapFilePath)\r
47fea6af 1736\r
e56468c0 1737 # Fixup "*" offset\r
626bece4
LG
1738 for pcd in VpdSkuMap:\r
1739 vpdinfo = VpdFile.GetVpdInfo(pcd)\r
1740 if vpdinfo is None:\r
e56468c0 1741 # just pick the a value to determine whether is unicode string type\r
626bece4
LG
1742 continue\r
1743 for pcdvalue in VpdSkuMap[pcd]:\r
1744 for sku in VpdSkuMap[pcd][pcdvalue]:\r
1745 for item in vpdinfo:\r
1746 if item[2] == pcdvalue:\r
1747 sku.VpdOffset = item[1]\r
e56468c0 1748 else:\r
1749 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
47fea6af 1750\r
626bece4
LG
1751 # Delete the DynamicPcdList At the last time enter into this function\r
1752 for Pcd in self._DynamicPcdList:\r
1753 # just pick the a value to determine whether is unicode string type\r
1754 Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]\r
1755 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1756\r
1757 if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
1758 Pcd.DatumType = "VOID*"\r
1759\r
1760 PcdValue = Sku.DefaultValue\r
1761 if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
1762 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
0b6c5954 1763 UnicodePcdArray.add(Pcd)\r
626bece4
LG
1764 elif len(Sku.VariableName) > 0:\r
1765 # if found HII type PCD then insert to right of UnicodeIndex\r
0b6c5954 1766 HiiPcdArray.add(Pcd)\r
626bece4 1767 else:\r
0b6c5954 1768 OtherPcdArray.add(Pcd)\r
47fea6af 1769 del self._DynamicPcdList[:]\r
0b6c5954
LG
1770 self._DynamicPcdList.extend(list(UnicodePcdArray))\r
1771 self._DynamicPcdList.extend(list(HiiPcdArray))\r
1772 self._DynamicPcdList.extend(list(OtherPcdArray))\r
2b8a6c44
LG
1773 allskuset = [(SkuName,Sku.SkuId) for pcd in self._DynamicPcdList for (SkuName,Sku) in pcd.SkuInfoList.items()]\r
1774 for pcd in self._DynamicPcdList:\r
1775 if len(pcd.SkuInfoList) == 1:\r
1776 for (SkuName,SkuId) in allskuset:\r
1777 if type(SkuId) in (str,unicode) and eval(SkuId) == 0 or SkuId == 0:\r
1778 continue\r
65eff519
LG
1779 pcd.SkuInfoList[SkuName] = copy.deepcopy(pcd.SkuInfoList['DEFAULT'])\r
1780 pcd.SkuInfoList[SkuName].SkuId = SkuId\r
a0a2cd1e 1781 self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
47854fd5
LG
1782\r
1783 def FixVpdOffset(self,VpdFile ):\r
1784 FvPath = os.path.join(self.BuildDir, "FV")\r
1785 if not os.path.exists(FvPath):\r
1786 try:\r
1787 os.makedirs(FvPath)\r
1788 except:\r
1789 EdkLogger.error("build", FILE_WRITE_FAILURE, "Fail to create FV folder under %s" % self.BuildDir)\r
1790\r
1791 VpdFilePath = os.path.join(FvPath, "%s.txt" % self.Platform.VpdToolGuid)\r
1792\r
1793 if VpdFile.Write(VpdFilePath):\r
1794 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.\r
1795 BPDGToolName = None\r
1796 for ToolDef in self.ToolDefinition.values():\r
1797 if ToolDef.has_key("GUID") and ToolDef["GUID"] == self.Platform.VpdToolGuid:\r
1798 if not ToolDef.has_key("PATH"):\r
1799 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)\r
1800 BPDGToolName = ToolDef["PATH"]\r
1801 break\r
1802 # Call third party GUID BPDG tool.\r
4231a819 1803 if BPDGToolName is not None:\r
47854fd5
LG
1804 VpdInfoFile.CallExtenalBPDGTool(BPDGToolName, VpdFilePath)\r
1805 else:\r
1806 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.")\r
1807\r
52302d4d
LG
1808 ## Return the platform build data object\r
1809 def _GetPlatform(self):\r
4231a819 1810 if self._Platform is None:\r
0d2711a6 1811 self._Platform = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
1812 return self._Platform\r
1813\r
1814 ## Return platform name\r
1815 def _GetName(self):\r
1816 return self.Platform.PlatformName\r
1817\r
1818 ## Return the meta file GUID\r
1819 def _GetGuid(self):\r
1820 return self.Platform.Guid\r
1821\r
1822 ## Return the platform version\r
1823 def _GetVersion(self):\r
1824 return self.Platform.Version\r
1825\r
1826 ## Return the FDF file name\r
1827 def _GetFdfFile(self):\r
4231a819 1828 if self._FdfFile is None:\r
52302d4d 1829 if self.Workspace.FdfFile != "":\r
05cc51ad 1830 self._FdfFile= mws.join(self.WorkspaceDir, self.Workspace.FdfFile)\r
52302d4d
LG
1831 else:\r
1832 self._FdfFile = ''\r
1833 return self._FdfFile\r
1834\r
1835 ## Return the build output directory platform specifies\r
1836 def _GetOutputDir(self):\r
1837 return self.Platform.OutputDirectory\r
1838\r
1839 ## Return the directory to store all intermediate and final files built\r
1840 def _GetBuildDir(self):\r
4231a819 1841 if self._BuildDir is None:\r
52302d4d
LG
1842 if os.path.isabs(self.OutputDir):\r
1843 self._BuildDir = path.join(\r
1844 path.abspath(self.OutputDir),\r
1845 self.BuildTarget + "_" + self.ToolChain,\r
1846 )\r
1847 else:\r
1848 self._BuildDir = path.join(\r
1849 self.WorkspaceDir,\r
1850 self.OutputDir,\r
1851 self.BuildTarget + "_" + self.ToolChain,\r
1852 )\r
97058144 1853 GlobalData.gBuildDirectory = self._BuildDir\r
52302d4d
LG
1854 return self._BuildDir\r
1855\r
1856 ## Return directory of platform makefile\r
1857 #\r
1858 # @retval string Makefile directory\r
1859 #\r
1860 def _GetMakeFileDir(self):\r
4231a819 1861 if self._MakeFileDir is None:\r
52302d4d
LG
1862 self._MakeFileDir = path.join(self.BuildDir, self.Arch)\r
1863 return self._MakeFileDir\r
1864\r
1865 ## Return build command string\r
1866 #\r
1867 # @retval string Build command string\r
1868 #\r
1869 def _GetBuildCommand(self):\r
4231a819 1870 if self._BuildCommand is None:\r
52302d4d
LG
1871 self._BuildCommand = []\r
1872 if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:\r
1873 self._BuildCommand += SplitOption(self.ToolDefinition["MAKE"]["PATH"])\r
1874 if "FLAGS" in self.ToolDefinition["MAKE"]:\r
1875 NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()\r
1876 if NewOption != '':\r
6780eef1 1877 self._BuildCommand += SplitOption(NewOption)\r
02a908fc
YZ
1878 if "MAKE" in self.EdkIIBuildOption:\r
1879 if "FLAGS" in self.EdkIIBuildOption["MAKE"]:\r
1880 Flags = self.EdkIIBuildOption["MAKE"]["FLAGS"]\r
1881 if Flags.startswith('='):\r
1882 self._BuildCommand = [self._BuildCommand[0]] + [Flags[1:]]\r
1883 else:\r
1884 self._BuildCommand += [Flags]\r
52302d4d
LG
1885 return self._BuildCommand\r
1886\r
1887 ## Get tool chain definition\r
1888 #\r
1889 # Get each tool defition for given tool chain from tools_def.txt and platform\r
1890 #\r
1891 def _GetToolDefinition(self):\r
4231a819 1892 if self._ToolDefinitions is None:\r
52302d4d
LG
1893 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary\r
1894 if TAB_TOD_DEFINES_COMMAND_TYPE not in self.Workspace.ToolDef.ToolsDefTxtDatabase:\r
1895 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No tools found in configuration",\r
1896 ExtraData="[%s]" % self.MetaFile)\r
1897 self._ToolDefinitions = {}\r
1898 DllPathList = set()\r
1899 for Def in ToolDefinition:\r
1900 Target, Tag, Arch, Tool, Attr = Def.split("_")\r
1901 if Target != self.BuildTarget or Tag != self.ToolChain or Arch != self.Arch:\r
1902 continue\r
1903\r
1904 Value = ToolDefinition[Def]\r
1905 # don't record the DLL\r
1906 if Attr == "DLL":\r
1907 DllPathList.add(Value)\r
1908 continue\r
1909\r
1910 if Tool not in self._ToolDefinitions:\r
1911 self._ToolDefinitions[Tool] = {}\r
1912 self._ToolDefinitions[Tool][Attr] = Value\r
1913\r
1914 ToolsDef = ''\r
52302d4d
LG
1915 if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:\r
1916 if "FLAGS" not in self._ToolDefinitions["MAKE"]:\r
1917 self._ToolDefinitions["MAKE"]["FLAGS"] = ""\r
1918 self._ToolDefinitions["MAKE"]["FLAGS"] += " -s"\r
1919 MakeFlags = ''\r
1920 for Tool in self._ToolDefinitions:\r
1921 for Attr in self._ToolDefinitions[Tool]:\r
1922 Value = self._ToolDefinitions[Tool][Attr]\r
1923 if Tool in self.BuildOption and Attr in self.BuildOption[Tool]:\r
1924 # check if override is indicated\r
1925 if self.BuildOption[Tool][Attr].startswith('='):\r
1926 Value = self.BuildOption[Tool][Attr][1:]\r
1927 else:\r
95816356
YZ
1928 if Attr != 'PATH':\r
1929 Value += " " + self.BuildOption[Tool][Attr]\r
1930 else:\r
1931 Value = self.BuildOption[Tool][Attr]\r
52302d4d
LG
1932\r
1933 if Attr == "PATH":\r
1934 # Don't put MAKE definition in the file\r
d98cce8e 1935 if Tool != "MAKE":\r
52302d4d
LG
1936 ToolsDef += "%s = %s\n" % (Tool, Value)\r
1937 elif Attr != "DLL":\r
1938 # Don't put MAKE definition in the file\r
1939 if Tool == "MAKE":\r
1940 if Attr == "FLAGS":\r
1941 MakeFlags = Value\r
1942 else:\r
1943 ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)\r
1944 ToolsDef += "\n"\r
1945\r
1946 SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)\r
1947 for DllPath in DllPathList:\r
1948 os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]\r
1949 os.environ["MAKE_FLAGS"] = MakeFlags\r
1950\r
1951 return self._ToolDefinitions\r
1952\r
1953 ## Return the paths of tools\r
1954 def _GetToolDefFile(self):\r
4231a819 1955 if self._ToolDefFile is None:\r
52302d4d
LG
1956 self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)\r
1957 return self._ToolDefFile\r
1958\r
1959 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.\r
1960 def _GetToolChainFamily(self):\r
4231a819 1961 if self._ToolChainFamily is None:\r
52302d4d
LG
1962 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1963 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \\r
1964 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
1965 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:\r
1966 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1967 % self.ToolChain)\r
1968 self._ToolChainFamily = "MSFT"\r
1969 else:\r
1970 self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]\r
1971 return self._ToolChainFamily\r
1972\r
1973 def _GetBuildRuleFamily(self):\r
4231a819 1974 if self._BuildRuleFamily is None:\r
52302d4d
LG
1975 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1976 if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \\r
1977 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
1978 or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:\r
1979 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1980 % self.ToolChain)\r
1981 self._BuildRuleFamily = "MSFT"\r
1982 else:\r
1983 self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]\r
1984 return self._BuildRuleFamily\r
1985\r
1986 ## Return the build options specific for all modules in this platform\r
1987 def _GetBuildOptions(self):\r
4231a819 1988 if self._BuildOption is None:\r
52302d4d
LG
1989 self._BuildOption = self._ExpandBuildOption(self.Platform.BuildOptions)\r
1990 return self._BuildOption\r
1991\r
1992 ## Return the build options specific for EDK modules in this platform\r
1993 def _GetEdkBuildOptions(self):\r
4231a819 1994 if self._EdkBuildOption is None:\r
52302d4d
LG
1995 self._EdkBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDK_NAME)\r
1996 return self._EdkBuildOption\r
1997\r
1998 ## Return the build options specific for EDKII modules in this platform\r
1999 def _GetEdkIIBuildOptions(self):\r
4231a819 2000 if self._EdkIIBuildOption is None:\r
52302d4d
LG
2001 self._EdkIIBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)\r
2002 return self._EdkIIBuildOption\r
2003\r
97fa0ee9 2004 ## Parse build_rule.txt in Conf Directory.\r
52302d4d
LG
2005 #\r
2006 # @retval BuildRule object\r
2007 #\r
2008 def _GetBuildRule(self):\r
4231a819 2009 if self._BuildRule is None:\r
52302d4d
LG
2010 BuildRuleFile = None\r
2011 if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:\r
2012 BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
2013 if BuildRuleFile in [None, '']:\r
97fa0ee9 2014 BuildRuleFile = gDefaultBuildRuleFile\r
52302d4d 2015 self._BuildRule = BuildRule(BuildRuleFile)\r
64b2609f
LG
2016 if self._BuildRule._FileVersion == "":\r
2017 self._BuildRule._FileVersion = AutoGenReqBuildRuleVerNum\r
2018 else:\r
2019 if self._BuildRule._FileVersion < AutoGenReqBuildRuleVerNum :\r
2020 # If Build Rule's version is less than the version number required by the tools, halting the build.\r
47fea6af 2021 EdkLogger.error("build", AUTOGEN_ERROR,\r
64b2609f
LG
2022 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])"\\r
2023 % (self._BuildRule._FileVersion, AutoGenReqBuildRuleVerNum))\r
47fea6af 2024\r
52302d4d
LG
2025 return self._BuildRule\r
2026\r
2027 ## Summarize the packages used by modules in this platform\r
2028 def _GetPackageList(self):\r
4231a819 2029 if self._PackageList is None:\r
52302d4d
LG
2030 self._PackageList = set()\r
2031 for La in self.LibraryAutoGenList:\r
2032 self._PackageList.update(La.DependentPackageList)\r
2033 for Ma in self.ModuleAutoGenList:\r
2034 self._PackageList.update(Ma.DependentPackageList)\r
a0a2cd1e
FB
2035 #Collect package set information from INF of FDF\r
2036 PkgSet = set()\r
2037 for ModuleFile in self._AsBuildModuleList:\r
2038 if ModuleFile in self.Platform.Modules:\r
2039 continue\r
2040 ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]\r
2041 PkgSet.update(ModuleData.Packages)\r
2042 self._PackageList = list(self._PackageList) + list (PkgSet)\r
52302d4d
LG
2043 return self._PackageList\r
2044\r
2bc3256c
LG
2045 def _GetNonDynamicPcdDict(self):\r
2046 if self._NonDynamicPcdDict:\r
2047 return self._NonDynamicPcdDict\r
2048 for Pcd in self.NonDynamicPcdList:\r
2049 self._NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)] = Pcd\r
2050 return self._NonDynamicPcdDict\r
2051\r
52302d4d
LG
2052 ## Get list of non-dynamic PCDs\r
2053 def _GetNonDynamicPcdList(self):\r
4231a819 2054 if self._NonDynamicPcdList is None:\r
e56468c0 2055 self.CollectPlatformDynamicPcds()\r
52302d4d
LG
2056 return self._NonDynamicPcdList\r
2057\r
2058 ## Get list of dynamic PCDs\r
2059 def _GetDynamicPcdList(self):\r
4231a819 2060 if self._DynamicPcdList is None:\r
e56468c0 2061 self.CollectPlatformDynamicPcds()\r
52302d4d
LG
2062 return self._DynamicPcdList\r
2063\r
2064 ## Generate Token Number for all PCD\r
2065 def _GetPcdTokenNumbers(self):\r
4231a819 2066 if self._PcdTokenNumber is None:\r
9006a2c6 2067 self._PcdTokenNumber = OrderedDict()\r
52302d4d 2068 TokenNumber = 1\r
d0acc87a
LG
2069 #\r
2070 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
2071 # Such as:\r
2072 # \r
2073 # Dynamic PCD:\r
2074 # TokenNumber 0 ~ 10\r
2075 # DynamicEx PCD:\r
2076 # TokeNumber 11 ~ 20\r
2077 #\r
52302d4d
LG
2078 for Pcd in self.DynamicPcdList:\r
2079 if Pcd.Phase == "PEI":\r
d0acc87a
LG
2080 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
2081 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
2082 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2083 TokenNumber += 1\r
47fea6af 2084\r
d0acc87a
LG
2085 for Pcd in self.DynamicPcdList:\r
2086 if Pcd.Phase == "PEI":\r
2087 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
2088 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
2089 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2090 TokenNumber += 1\r
47fea6af 2091\r
52302d4d
LG
2092 for Pcd in self.DynamicPcdList:\r
2093 if Pcd.Phase == "DXE":\r
d0acc87a
LG
2094 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
2095 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
2096 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2097 TokenNumber += 1\r
47fea6af 2098\r
d0acc87a
LG
2099 for Pcd in self.DynamicPcdList:\r
2100 if Pcd.Phase == "DXE":\r
2101 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
2102 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
2103 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2104 TokenNumber += 1\r
47fea6af 2105\r
52302d4d
LG
2106 for Pcd in self.NonDynamicPcdList:\r
2107 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2108 TokenNumber += 1\r
2109 return self._PcdTokenNumber\r
2110\r
2111 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform\r
2112 def _GetAutoGenObjectList(self):\r
2113 self._ModuleAutoGenList = []\r
2114 self._LibraryAutoGenList = []\r
2115 for ModuleFile in self.Platform.Modules:\r
2116 Ma = ModuleAutoGen(\r
2117 self.Workspace,\r
2118 ModuleFile,\r
2119 self.BuildTarget,\r
2120 self.ToolChain,\r
2121 self.Arch,\r
2122 self.MetaFile\r
2123 )\r
2124 if Ma not in self._ModuleAutoGenList:\r
2125 self._ModuleAutoGenList.append(Ma)\r
2126 for La in Ma.LibraryAutoGenList:\r
2127 if La not in self._LibraryAutoGenList:\r
2128 self._LibraryAutoGenList.append(La)\r
2bc3256c
LG
2129 if Ma not in La._ReferenceModules:\r
2130 La._ReferenceModules.append(Ma)\r
52302d4d
LG
2131\r
2132 ## Summarize ModuleAutoGen objects of all modules to be built for this platform\r
2133 def _GetModuleAutoGenList(self):\r
4231a819 2134 if self._ModuleAutoGenList is None:\r
52302d4d
LG
2135 self._GetAutoGenObjectList()\r
2136 return self._ModuleAutoGenList\r
2137\r
2138 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform\r
2139 def _GetLibraryAutoGenList(self):\r
4231a819 2140 if self._LibraryAutoGenList is None:\r
52302d4d
LG
2141 self._GetAutoGenObjectList()\r
2142 return self._LibraryAutoGenList\r
2143\r
2144 ## Test if a module is supported by the platform\r
2145 #\r
2146 # An error will be raised directly if the module or its arch is not supported\r
2147 # by the platform or current configuration\r
2148 #\r
2149 def ValidModule(self, Module):\r
a0a2cd1e
FB
2150 return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \\r
2151 or Module in self._AsBuildModuleList\r
52302d4d
LG
2152\r
2153 ## Resolve the library classes in a module to library instances\r
2154 #\r
2155 # This method will not only resolve library classes but also sort the library\r
2156 # instances according to the dependency-ship.\r
2157 #\r
2158 # @param Module The module from which the library classes will be resolved\r
2159 #\r
2160 # @retval library_list List of library instances sorted\r
2161 #\r
2162 def ApplyLibraryInstance(self, Module):\r
25193a33
YZ
2163 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly\r
2164 if str(Module) not in self.Platform.Modules:\r
2165 return []\r
2166\r
52302d4d
LG
2167 ModuleType = Module.ModuleType\r
2168\r
2169 # for overridding library instances with module specific setting\r
2170 PlatformModule = self.Platform.Modules[str(Module)]\r
2171\r
2172 # add forced library instances (specified under LibraryClasses sections)\r
da92f276
LG
2173 #\r
2174 # If a module has a MODULE_TYPE of USER_DEFINED,\r
2175 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
2176 #\r
2177 if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
2178 for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
2179 if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
2180 Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
52302d4d
LG
2181\r
2182 # add forced library instances (specified in module overrides)\r
2183 for LibraryClass in PlatformModule.LibraryClasses:\r
2184 if LibraryClass.startswith("NULL"):\r
2185 Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
2186\r
b36d134f 2187 # EdkII module\r
52302d4d
LG
2188 LibraryConsumerList = [Module]\r
2189 Constructor = []\r
9006a2c6
CJ
2190 ConsumedByList = OrderedDict()\r
2191 LibraryInstance = OrderedDict()\r
52302d4d
LG
2192\r
2193 EdkLogger.verbose("")\r
2194 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
2195 while len(LibraryConsumerList) > 0:\r
2196 M = LibraryConsumerList.pop()\r
2197 for LibraryClassName in M.LibraryClasses:\r
2198 if LibraryClassName not in LibraryInstance:\r
2199 # override library instance for this module\r
2200 if LibraryClassName in PlatformModule.LibraryClasses:\r
2201 LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
2202 else:\r
2203 LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]\r
4231a819 2204 if LibraryPath is None or LibraryPath == "":\r
52302d4d 2205 LibraryPath = M.LibraryClasses[LibraryClassName]\r
4231a819 2206 if LibraryPath is None or LibraryPath == "":\r
52302d4d
LG
2207 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
2208 "Instance of library class [%s] is not found" % LibraryClassName,\r
2209 File=self.MetaFile,\r
2210 ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))\r
2211\r
0d2711a6 2212 LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
2213 # for those forced library instance (NULL library), add a fake library class\r
2214 if LibraryClassName.startswith("NULL"):\r
2215 LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
4231a819 2216 elif LibraryModule.LibraryClass is None \\r
52302d4d
LG
2217 or len(LibraryModule.LibraryClass) == 0 \\r
2218 or (ModuleType != 'USER_DEFINED'\r
2219 and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
2220 # only USER_DEFINED can link against any library instance despite of its SupModList\r
2221 EdkLogger.error("build", OPTION_MISSING,\r
2222 "Module type [%s] is not supported by library instance [%s]" \\r
2223 % (ModuleType, LibraryPath), File=self.MetaFile,\r
2224 ExtraData="consumed by [%s]" % str(Module))\r
2225\r
2226 LibraryInstance[LibraryClassName] = LibraryModule\r
2227 LibraryConsumerList.append(LibraryModule)\r
2228 EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
2229 else:\r
2230 LibraryModule = LibraryInstance[LibraryClassName]\r
2231\r
4231a819 2232 if LibraryModule is None:\r
52302d4d
LG
2233 continue\r
2234\r
2235 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
2236 Constructor.append(LibraryModule)\r
2237\r
2238 if LibraryModule not in ConsumedByList:\r
2239 ConsumedByList[LibraryModule] = []\r
2240 # don't add current module itself to consumer list\r
2241 if M != Module:\r
2242 if M in ConsumedByList[LibraryModule]:\r
2243 continue\r
2244 ConsumedByList[LibraryModule].append(M)\r
2245 #\r
2246 # Initialize the sorted output list to the empty set\r
2247 #\r
2248 SortedLibraryList = []\r
2249 #\r
2250 # Q <- Set of all nodes with no incoming edges\r
2251 #\r
2252 LibraryList = [] #LibraryInstance.values()\r
2253 Q = []\r
2254 for LibraryClassName in LibraryInstance:\r
2255 M = LibraryInstance[LibraryClassName]\r
2256 LibraryList.append(M)\r
2257 if ConsumedByList[M] == []:\r
2258 Q.append(M)\r
2259\r
2260 #\r
2261 # start the DAG algorithm\r
2262 #\r
2263 while True:\r
2264 EdgeRemoved = True\r
2265 while Q == [] and EdgeRemoved:\r
2266 EdgeRemoved = False\r
2267 # for each node Item with a Constructor\r
2268 for Item in LibraryList:\r
2269 if Item not in Constructor:\r
2270 continue\r
2271 # for each Node without a constructor with an edge e from Item to Node\r
2272 for Node in ConsumedByList[Item]:\r
2273 if Node in Constructor:\r
2274 continue\r
2275 # remove edge e from the graph if Node has no constructor\r
2276 ConsumedByList[Item].remove(Node)\r
2277 EdgeRemoved = True\r
2278 if ConsumedByList[Item] == []:\r
2279 # insert Item into Q\r
2280 Q.insert(0, Item)\r
2281 break\r
2282 if Q != []:\r
2283 break\r
2284 # DAG is done if there's no more incoming edge for all nodes\r
2285 if Q == []:\r
2286 break\r
2287\r
2288 # remove node from Q\r
2289 Node = Q.pop()\r
2290 # output Node\r
2291 SortedLibraryList.append(Node)\r
2292\r
2293 # for each node Item with an edge e from Node to Item do\r
2294 for Item in LibraryList:\r
2295 if Node not in ConsumedByList[Item]:\r
2296 continue\r
2297 # remove edge e from the graph\r
2298 ConsumedByList[Item].remove(Node)\r
2299\r
2300 if ConsumedByList[Item] != []:\r
2301 continue\r
2302 # insert Item into Q, if Item has no other incoming edges\r
2303 Q.insert(0, Item)\r
2304\r
2305 #\r
2306 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
2307 #\r
2308 for Item in LibraryList:\r
2309 if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
2310 ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])\r
2311 EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
2312 ExtraData=ErrorMessage, File=self.MetaFile)\r
2313 if Item not in SortedLibraryList:\r
2314 SortedLibraryList.append(Item)\r
2315\r
2316 #\r
2317 # Build the list of constructor and destructir names\r
2318 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
2319 #\r
2320 SortedLibraryList.reverse()\r
2321 return SortedLibraryList\r
2322\r
2323\r
2324 ## Override PCD setting (type, value, ...)\r
2325 #\r
2326 # @param ToPcd The PCD to be overrided\r
2327 # @param FromPcd The PCD overrideing from\r
2328 #\r
2329 def _OverridePcd(self, ToPcd, FromPcd, Module=""):\r
2330 #\r
2331 # in case there's PCDs coming from FDF file, which have no type given.\r
2332 # at this point, ToPcd.Type has the type found from dependent\r
2333 # package\r
2334 #\r
2a29017e
YZ
2335 TokenCName = ToPcd.TokenCName\r
2336 for PcdItem in GlobalData.MixedPcd:\r
2337 if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
2338 TokenCName = PcdItem[0]\r
2339 break\r
4231a819 2340 if FromPcd is not None:\r
52302d4d
LG
2341 if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
2342 ToPcd.Type = FromPcd.Type\r
e56468c0 2343 elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
2344 and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):\r
2345 if ToPcd.Type.strip() == "DynamicEx":\r
47fea6af 2346 ToPcd.Type = FromPcd.Type\r
52302d4d
LG
2347 elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \\r
2348 and ToPcd.Type != FromPcd.Type:\r
2349 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
2350 ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
2a29017e 2351 % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
52302d4d
LG
2352 ToPcd.Type, Module, FromPcd.Type),\r
2353 File=self.MetaFile)\r
2354\r
6be94743 2355 if FromPcd.MaxDatumSize:\r
52302d4d 2356 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
6be94743 2357 if FromPcd.DefaultValue:\r
52302d4d 2358 ToPcd.DefaultValue = FromPcd.DefaultValue\r
6be94743 2359 if FromPcd.TokenValue:\r
52302d4d 2360 ToPcd.TokenValue = FromPcd.TokenValue\r
6be94743 2361 if FromPcd.DatumType:\r
52302d4d 2362 ToPcd.DatumType = FromPcd.DatumType\r
6be94743 2363 if FromPcd.SkuInfoList:\r
52302d4d 2364 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
726c501c 2365 # Add Flexible PCD format parse\r
726c501c 2366 if ToPcd.DefaultValue:\r
726c501c 2367 try:\r
35f613d9 2368 ToPcd.DefaultValue = ValueExpressionEx(ToPcd.DefaultValue, ToPcd.DatumType, self._GuidDict)(True)\r
726c501c
YZ
2369 except BadExpression, Value:\r
2370 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.DefaultValue, Value),\r
2371 File=self.MetaFile)\r
52302d4d
LG
2372\r
2373 # check the validation of datum\r
2374 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
2375 if not IsValid:\r
2376 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
2a29017e 2377 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
82a6a960
BF
2378 ToPcd.validateranges = FromPcd.validateranges\r
2379 ToPcd.validlists = FromPcd.validlists\r
2380 ToPcd.expressions = FromPcd.expressions\r
52302d4d 2381\r
4231a819 2382 if FromPcd is not None and ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
52302d4d 2383 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
2a29017e 2384 % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
52302d4d
LG
2385 Value = ToPcd.DefaultValue\r
2386 if Value in [None, '']:\r
e8a47801 2387 ToPcd.MaxDatumSize = '1'\r
52302d4d 2388 elif Value[0] == 'L':\r
e8a47801 2389 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
52302d4d
LG
2390 elif Value[0] == '{':\r
2391 ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
2392 else:\r
e8a47801 2393 ToPcd.MaxDatumSize = str(len(Value) - 1)\r
52302d4d
LG
2394\r
2395 # apply default SKU for dynamic PCDS if specified one is not available\r
2396 if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \\r
2397 and ToPcd.SkuInfoList in [None, {}, '']:\r
2398 if self.Platform.SkuName in self.Platform.SkuIds:\r
2399 SkuName = self.Platform.SkuName\r
2400 else:\r
2401 SkuName = 'DEFAULT'\r
2402 ToPcd.SkuInfoList = {\r
8518bf0b 2403 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName][0], '', '', '', '', '', ToPcd.DefaultValue)\r
52302d4d
LG
2404 }\r
2405\r
2406 ## Apply PCD setting defined platform to a module\r
2407 #\r
2408 # @param Module The module from which the PCD setting will be overrided\r
2409 #\r
2410 # @retval PCD_list The list PCDs with settings from platform\r
2411 #\r
2412 def ApplyPcdSetting(self, Module, Pcds):\r
2413 # for each PCD in module\r
47fea6af
YZ
2414 for Name, Guid in Pcds:\r
2415 PcdInModule = Pcds[Name, Guid]\r
52302d4d 2416 # find out the PCD setting in platform\r
47fea6af
YZ
2417 if (Name, Guid) in self.Platform.Pcds:\r
2418 PcdInPlatform = self.Platform.Pcds[Name, Guid]\r
52302d4d
LG
2419 else:\r
2420 PcdInPlatform = None\r
2421 # then override the settings if any\r
2422 self._OverridePcd(PcdInModule, PcdInPlatform, Module)\r
2423 # resolve the VariableGuid value\r
2424 for SkuId in PcdInModule.SkuInfoList:\r
2425 Sku = PcdInModule.SkuInfoList[SkuId]\r
2426 if Sku.VariableGuid == '': continue\r
c28d2e10 2427 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
4231a819 2428 if Sku.VariableGuidValue is None:\r
52302d4d
LG
2429 PackageList = "\n\t".join([str(P) for P in self.PackageList])\r
2430 EdkLogger.error(\r
2431 'build',\r
2432 RESOURCE_NOT_AVAILABLE,\r
2433 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
2434 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
2435 % (Guid, Name, str(Module)),\r
2436 File=self.MetaFile\r
2437 )\r
2438\r
2439 # override PCD settings with module specific setting\r
2440 if Module in self.Platform.Modules:\r
2441 PlatformModule = self.Platform.Modules[str(Module)]\r
2442 for Key in PlatformModule.Pcds:\r
aa9aa47e 2443 Flag = False\r
52302d4d 2444 if Key in Pcds:\r
aa9aa47e
YZ
2445 ToPcd = Pcds[Key]\r
2446 Flag = True\r
2447 elif Key in GlobalData.MixedPcd:\r
2448 for PcdItem in GlobalData.MixedPcd[Key]:\r
2449 if PcdItem in Pcds:\r
2450 ToPcd = Pcds[PcdItem]\r
2451 Flag = True\r
2452 break\r
2453 if Flag:\r
2454 self._OverridePcd(ToPcd, PlatformModule.Pcds[Key], Module)\r
cdbf45ad
YZ
2455 # use PCD value to calculate the MaxDatumSize when it is not specified\r
2456 for Name, Guid in Pcds:\r
2457 Pcd = Pcds[Name, Guid]\r
2458 if Pcd.DatumType == "VOID*" and Pcd.MaxDatumSize in ['', None]:\r
2459 Value = Pcd.DefaultValue\r
2460 if Value in [None, '']:\r
2461 Pcd.MaxDatumSize = '1'\r
2462 elif Value[0] == 'L':\r
2463 Pcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
2464 elif Value[0] == '{':\r
2465 Pcd.MaxDatumSize = str(len(Value.split(',')))\r
2466 else:\r
2467 Pcd.MaxDatumSize = str(len(Value) - 1)\r
52302d4d
LG
2468 return Pcds.values()\r
2469\r
2470 ## Resolve library names to library modules\r
2471 #\r
b36d134f 2472 # (for Edk.x modules)\r
52302d4d
LG
2473 #\r
2474 # @param Module The module from which the library names will be resolved\r
2475 #\r
2476 # @retval library_list The list of library modules\r
2477 #\r
2478 def ResolveLibraryReference(self, Module):\r
2479 EdkLogger.verbose("")\r
2480 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
2481 LibraryConsumerList = [Module]\r
2482\r
b36d134f 2483 # "CompilerStub" is a must for Edk modules\r
52302d4d
LG
2484 if Module.Libraries:\r
2485 Module.Libraries.append("CompilerStub")\r
2486 LibraryList = []\r
2487 while len(LibraryConsumerList) > 0:\r
2488 M = LibraryConsumerList.pop()\r
2489 for LibraryName in M.Libraries:\r
2490 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']\r
4231a819 2491 if Library is None:\r
52302d4d
LG
2492 for Key in self.Platform.LibraryClasses.data.keys():\r
2493 if LibraryName.upper() == Key.upper():\r
2494 Library = self.Platform.LibraryClasses[Key, ':dummy:']\r
2495 break\r
4231a819 2496 if Library is None:\r
52302d4d
LG
2497 EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),\r
2498 ExtraData="\t%s [%s]" % (str(Module), self.Arch))\r
2499 continue\r
2500\r
2501 if Library not in LibraryList:\r
2502 LibraryList.append(Library)\r
2503 LibraryConsumerList.append(Library)\r
2504 EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))\r
2505 return LibraryList\r
2506\r
6780eef1
LG
2507 ## Calculate the priority value of the build option\r
2508 #\r
2509 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2510 #\r
2511 # @retval Value Priority value based on the priority list.\r
2512 #\r
2513 def CalculatePriorityValue(self, Key):\r
47fea6af
YZ
2514 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')\r
2515 PriorityValue = 0x11111\r
6780eef1
LG
2516 if Target == "*":\r
2517 PriorityValue &= 0x01111\r
2518 if ToolChain == "*":\r
2519 PriorityValue &= 0x10111\r
2520 if Arch == "*":\r
2521 PriorityValue &= 0x11011\r
2522 if CommandType == "*":\r
2523 PriorityValue &= 0x11101\r
2524 if Attr == "*":\r
2525 PriorityValue &= 0x11110\r
47fea6af
YZ
2526\r
2527 return self.PrioList["0x%0.5x" % PriorityValue]\r
2528\r
6780eef1 2529\r
52302d4d
LG
2530 ## Expand * in build option key\r
2531 #\r
2532 # @param Options Options to be expanded\r
2533 #\r
2534 # @retval options Options expanded\r
6780eef1 2535 # \r
52302d4d
LG
2536 def _ExpandBuildOption(self, Options, ModuleStyle=None):\r
2537 BuildOptions = {}\r
2538 FamilyMatch = False\r
2539 FamilyIsNull = True\r
47fea6af 2540\r
6780eef1
LG
2541 OverrideList = {}\r
2542 #\r
2543 # Construct a list contain the build options which need override.\r
2544 #\r
2545 for Key in Options:\r
2546 #\r
2547 # Key[0] -- tool family\r
2548 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2549 #\r
1ba5124e 2550 if (Key[0] == self.BuildRuleFamily and\r
4231a819 2551 (ModuleStyle is None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):\r
6780eef1
LG
2552 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
2553 if Target == self.BuildTarget or Target == "*":\r
2554 if ToolChain == self.ToolChain or ToolChain == "*":\r
2555 if Arch == self.Arch or Arch == "*":\r
2556 if Options[Key].startswith("="):\r
4231a819 2557 if OverrideList.get(Key[1]) is not None:\r
6780eef1
LG
2558 OverrideList.pop(Key[1])\r
2559 OverrideList[Key[1]] = Options[Key]\r
2560 \r
2561 #\r
2562 # Use the highest priority value. \r
2563 #\r
2564 if (len(OverrideList) >= 2):\r
47fea6af 2565 KeyList = OverrideList.keys()\r
6780eef1 2566 for Index in range(len(KeyList)):\r
47fea6af 2567 NowKey = KeyList[Index]\r
6780eef1
LG
2568 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
2569 for Index1 in range(len(KeyList) - Index - 1):\r
2570 NextKey = KeyList[Index1 + Index + 1]\r
2571 #\r
2572 # Compare two Key, if one is included by another, choose the higher priority one\r
2573 # \r
2574 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
2575 if Target1 == Target2 or Target1 == "*" or Target2 == "*":\r
2576 if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":\r
2577 if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":\r
2578 if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":\r
2579 if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":\r
2580 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):\r
4231a819 2581 if Options.get((self.BuildRuleFamily, NextKey)) is not None:\r
6780eef1
LG
2582 Options.pop((self.BuildRuleFamily, NextKey))\r
2583 else:\r
4231a819 2584 if Options.get((self.BuildRuleFamily, NowKey)) is not None:\r
6780eef1
LG
2585 Options.pop((self.BuildRuleFamily, NowKey))\r
2586 \r
52302d4d 2587 for Key in Options:\r
4231a819 2588 if ModuleStyle is not None and len (Key) > 2:\r
52302d4d
LG
2589 # Check Module style is EDK or EDKII.\r
2590 # Only append build option for the matched style module.\r
2591 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2592 continue\r
2593 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2594 continue\r
2595 Family = Key[0]\r
2596 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2597 # if tool chain family doesn't match, skip it\r
2598 if Tool in self.ToolDefinition and Family != "":\r
2599 FamilyIsNull = False\r
2600 if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
2601 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
2602 continue\r
2603 elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2604 continue\r
2605 FamilyMatch = True\r
2606 # expand any wildcard\r
2607 if Target == "*" or Target == self.BuildTarget:\r
2608 if Tag == "*" or Tag == self.ToolChain:\r
2609 if Arch == "*" or Arch == self.Arch:\r
2610 if Tool not in BuildOptions:\r
2611 BuildOptions[Tool] = {}\r
5015bee2 2612 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
52302d4d
LG
2613 BuildOptions[Tool][Attr] = Options[Key]\r
2614 else:\r
95816356
YZ
2615 # append options for the same tool except PATH\r
2616 if Attr != 'PATH':\r
2617 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2618 else:\r
2619 BuildOptions[Tool][Attr] = Options[Key]\r
52302d4d
LG
2620 # Build Option Family has been checked, which need't to be checked again for family.\r
2621 if FamilyMatch or FamilyIsNull:\r
2622 return BuildOptions\r
1ba5124e 2623\r
52302d4d 2624 for Key in Options:\r
4231a819 2625 if ModuleStyle is not None and len (Key) > 2:\r
52302d4d
LG
2626 # Check Module style is EDK or EDKII.\r
2627 # Only append build option for the matched style module.\r
2628 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2629 continue\r
2630 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2631 continue\r
2632 Family = Key[0]\r
2633 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2634 # if tool chain family doesn't match, skip it\r
47fea6af 2635 if Tool not in self.ToolDefinition or Family == "":\r
52302d4d
LG
2636 continue\r
2637 # option has been added before\r
2638 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2639 continue\r
2640\r
2641 # expand any wildcard\r
2642 if Target == "*" or Target == self.BuildTarget:\r
2643 if Tag == "*" or Tag == self.ToolChain:\r
2644 if Arch == "*" or Arch == self.Arch:\r
2645 if Tool not in BuildOptions:\r
2646 BuildOptions[Tool] = {}\r
5015bee2 2647 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
52302d4d
LG
2648 BuildOptions[Tool][Attr] = Options[Key]\r
2649 else:\r
95816356
YZ
2650 # append options for the same tool except PATH\r
2651 if Attr != 'PATH':\r
2652 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2653 else:\r
2654 BuildOptions[Tool][Attr] = Options[Key]\r
52302d4d
LG
2655 return BuildOptions\r
2656\r
2657 ## Append build options in platform to a module\r
2658 #\r
2659 # @param Module The module to which the build options will be appened\r
2660 #\r
2661 # @retval options The options appended with build options in platform\r
2662 #\r
2663 def ApplyBuildOption(self, Module):\r
2664 # Get the different options for the different style module\r
2665 if Module.AutoGenVersion < 0x00010005:\r
2666 PlatformOptions = self.EdkBuildOption\r
35f69db9 2667 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDK_NAME, Module.ModuleType)\r
52302d4d
LG
2668 else:\r
2669 PlatformOptions = self.EdkIIBuildOption\r
35f69db9
YL
2670 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDKII_NAME, Module.ModuleType)\r
2671 ModuleTypeOptions = self._ExpandBuildOption(ModuleTypeOptions)\r
52302d4d
LG
2672 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)\r
2673 if Module in self.Platform.Modules:\r
2674 PlatformModule = self.Platform.Modules[str(Module)]\r
2675 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)\r
2676 else:\r
2677 PlatformModuleOptions = {}\r
2678\r
fe4bf2f9 2679 BuildRuleOrder = None\r
35f69db9 2680 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
fe4bf2f9
YL
2681 for Tool in Options:\r
2682 for Attr in Options[Tool]:\r
2683 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2684 BuildRuleOrder = Options[Tool][Attr]\r
2685\r
35f69db9
YL
2686 AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +\r
2687 PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +\r
2688 self.ToolDefinition.keys())\r
339fe8dd 2689 BuildOptions = defaultdict(lambda: defaultdict(str))\r
52302d4d 2690 for Tool in AllTools:\r
35f69db9 2691 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
52302d4d
LG
2692 if Tool not in Options:\r
2693 continue\r
2694 for Attr in Options[Tool]:\r
fe4bf2f9
YL
2695 #\r
2696 # Do not generate it in Makefile\r
2697 #\r
2698 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2699 continue\r
339fe8dd 2700 Value = Options[Tool][Attr]\r
52302d4d
LG
2701 # check if override is indicated\r
2702 if Value.startswith('='):\r
339fe8dd 2703 BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:])\r
5015bee2 2704 else:\r
95816356 2705 if Attr != 'PATH':\r
339fe8dd 2706 BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value)\r
95816356 2707 else:\r
339fe8dd
CJ
2708 BuildOptions[Tool][Attr] = mws.handleWsMacro(Value)\r
2709\r
4231a819 2710 if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag is not None:\r
f3decdc3
LG
2711 #\r
2712 # Override UNI flag only for EDK module.\r
2713 #\r
f3decdc3 2714 BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
fe4bf2f9 2715 return BuildOptions, BuildRuleOrder\r
52302d4d
LG
2716\r
2717 Platform = property(_GetPlatform)\r
2718 Name = property(_GetName)\r
2719 Guid = property(_GetGuid)\r
2720 Version = property(_GetVersion)\r
2721\r
2722 OutputDir = property(_GetOutputDir)\r
2723 BuildDir = property(_GetBuildDir)\r
2724 MakeFileDir = property(_GetMakeFileDir)\r
2725 FdfFile = property(_GetFdfFile)\r
2726\r
2727 PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
2728 DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2729 NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2bc3256c 2730 NonDynamicPcdDict = property(_GetNonDynamicPcdDict)\r
52302d4d
LG
2731 PackageList = property(_GetPackageList)\r
2732\r
2733 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
2734 ToolDefinitionFile = property(_GetToolDefFile) # toolcode : lib path\r
2735 ToolChainFamily = property(_GetToolChainFamily)\r
2736 BuildRuleFamily = property(_GetBuildRuleFamily)\r
2737 BuildOption = property(_GetBuildOptions) # toolcode : option\r
2738 EdkBuildOption = property(_GetEdkBuildOptions) # edktoolcode : option\r
2739 EdkIIBuildOption = property(_GetEdkIIBuildOptions) # edkiitoolcode : option\r
2740\r
2741 BuildCommand = property(_GetBuildCommand)\r
2742 BuildRule = property(_GetBuildRule)\r
2743 ModuleAutoGenList = property(_GetModuleAutoGenList)\r
2744 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
0923aa1c 2745 GenFdsCommand = property(_GenFdsCommand)\r
52302d4d
LG
2746\r
2747## ModuleAutoGen class\r
2748#\r
2749# This class encapsules the AutoGen behaviors for the build tools. In addition to\r
2750# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r
2751# to the [depex] section in module's inf file.\r
2752#\r
2753class ModuleAutoGen(AutoGen):\r
b24e99f7
CJ
2754 # call super().__init__ then call the worker function with different parameter count\r
2755 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
2756 try:\r
2757 self._Init\r
2758 except:\r
2759 super(ModuleAutoGen, self).__init__(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
2760 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args)\r
2761 self._Init = True\r
2762\r
c17956e0
DL
2763 ## Cache the timestamps of metafiles of every module in a class variable\r
2764 #\r
2765 TimeDict = {}\r
2766\r
b24e99f7
CJ
2767 def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
2768 obj = super(ModuleAutoGen, cls).__new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
2769 # check if this module is employed by active platform\r
2770 if not PlatformAutoGen(Workspace, args[0], Target, Toolchain, Arch).ValidModule(MetaFile):\r
2771 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
2772 % (MetaFile, Arch))\r
2773 return None\r
2774 return obj\r
2775 \r
2776 ## Initialize ModuleAutoGen\r
52302d4d
LG
2777 #\r
2778 # @param Workspace EdkIIWorkspaceBuild object\r
2779 # @param ModuleFile The path of module file\r
2780 # @param Target Build target (DEBUG, RELEASE)\r
2781 # @param Toolchain Name of tool chain\r
2782 # @param Arch The arch the module supports\r
2783 # @param PlatformFile Platform meta-file\r
2784 #\r
b24e99f7 2785 def _InitWorker(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
52302d4d
LG
2786 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
2787 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
2788\r
2789 self.Workspace = Workspace\r
2790 self.WorkspaceDir = Workspace.WorkspaceDir\r
2791\r
2792 self.MetaFile = ModuleFile\r
2793 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
52302d4d
LG
2794\r
2795 self.SourceDir = self.MetaFile.SubDir\r
05cc51ad 2796 self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r