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