MdeModulePkg/PerformanceMeasurement.h: Correct the license
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / DscBuildData.py
CommitLineData
ae7b6df8
LG
1## @file\r
2# This file is used to create a database used by build tool\r
3#\r
e6b10112 4# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
ae7b6df8
LG
5# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
6# This program and the accompanying materials\r
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15## Platform build information from DSC file\r
16#\r
17# This class is used to retrieve information stored in database and convert them\r
18# into PlatformBuildClassObject form for easier use for AutoGen.\r
19#\r
72443dd2 20from __future__ import print_function\r
5a57246e 21from Common.StringUtils import *\r
ae7b6df8
LG
22from Common.DataType import *\r
23from Common.Misc import *\r
24from types import *\r
8565b582 25from Common.Expression import *\r
ae7b6df8 26from CommonDataClass.CommonClass import SkuInfoClass\r
68ba919f
YZ
27from Common.TargetTxtClassObject import *\r
28from Common.ToolDefClassObject import *\r
ae7b6df8
LG
29from MetaDataTable import *\r
30from MetaFileTable import *\r
31from MetaFileParser import *\r
32\r
33from WorkspaceCommon import GetDeclaredPcd\r
34from Common.Misc import AnalyzeDscPcd\r
35from Common.Misc import ProcessDuplicatedInf\r
36import re\r
37from Common.Parsing import IsValidWord\r
38from Common.VariableAttributes import VariableAttributes\r
39import Common.GlobalData as GlobalData\r
40import subprocess\r
0a57a978 41from Common.Misc import SaveFileOnChange\r
ae7b6df8 42from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject\r
ccaa7754 43from collections import OrderedDict, defaultdict\r
ae7b6df8 44\r
ae7b6df8 45PcdValueInitName = 'PcdValueInit'\r
ae7b6df8
LG
46\r
47PcdMainCHeader = '''\r
48/**\r
49 DO NOT EDIT\r
50 FILE auto-generated\r
51**/\r
52\r
53#include <stdio.h>\r
54#include <stdlib.h>\r
55#include <string.h>\r
56#include <PcdValueCommon.h>\r
57'''\r
58\r
59PcdMainCEntry = '''\r
60int\r
61main (\r
62 int argc,\r
63 char *argv[]\r
64 )\r
65{\r
66 return PcdValueMain (argc, argv);\r
67}\r
68'''\r
69\r
70PcdMakefileHeader = '''\r
71#\r
72# DO NOT EDIT\r
73# This file is auto-generated by build utility\r
74#\r
75\r
76'''\r
77\r
68ba919f
YZ
78WindowsCFLAGS = 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '\r
79LinuxCFLAGS = 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '\r
ae7b6df8
LG
80PcdMakefileEnd = '''\r
81!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common\r
82\r
ae7b6df8
LG
83LIBS = $(LIB_PATH)\Common.lib\r
84\r
85!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app\r
86'''\r
87\r
88PcdGccMakefile = '''\r
ae7b6df8
LG
89MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C\r
90LIBS = -lCommon\r
91'''\r
92\r
3e4faa26
CJ
93variablePattern = re.compile(r'[\t\s]*0[xX][a-fA-F0-9]+$')\r
94\r
fe1abb4b
CJ
95## regular expressions for finding decimal and hex numbers\r
96Pattern = re.compile('^[1-9]\d*|0$')\r
97HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')\r
34d808ad
B
98## Regular expression for finding header file inclusions\r
99from AutoGen.GenMake import gIncludePattern\r
100\r
101## Find dependencies for one source file\r
102#\r
103# By searching recursively "#include" directive in file, find out all the\r
104# files needed by given source file. The dependecies will be only searched\r
105# in given search path list.\r
106#\r
107# @param SearchPathList The list of search path\r
108#\r
109# @retval list The list of files the given source file depends on\r
110#\r
ccaa7754 111def GetDependencyList(FileStack, SearchPathList):\r
34d808ad
B
112 DepDb = dict()\r
113 DependencySet = set(FileStack)\r
114 while len(FileStack) > 0:\r
115 F = FileStack.pop()\r
116 FullPathDependList = []\r
117 CurrentFileDependencyList = []\r
118 if F in DepDb:\r
119 CurrentFileDependencyList = DepDb[F]\r
120 else:\r
121 try:\r
122 Fd = open(F, 'r')\r
123 FileContent = Fd.read()\r
5b0671c1 124 except BaseException as X:\r
34d808ad
B
125 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F + "\n\t" + str(X))\r
126 finally:\r
127 if "Fd" in dir(locals()):\r
128 Fd.close()\r
129\r
130 if len(FileContent) == 0:\r
131 continue\r
132\r
133 if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
134 FileContent = unicode(FileContent, "utf-16")\r
135 IncludedFileList = gIncludePattern.findall(FileContent)\r
136\r
137 for Inc in IncludedFileList:\r
138 Inc = Inc.strip()\r
139 Inc = os.path.normpath(Inc)\r
140 CurrentFileDependencyList.append(Inc)\r
141 DepDb[F] = CurrentFileDependencyList\r
142\r
143 CurrentFilePath = os.path.dirname(F)\r
144 PathList = [CurrentFilePath] + SearchPathList\r
145 for Inc in CurrentFileDependencyList:\r
146 for SearchPath in PathList:\r
147 FilePath = os.path.join(SearchPath, Inc)\r
148 if not os.path.exists(FilePath):\r
149 continue\r
150 if FilePath not in DependencySet:\r
151 FileStack.append(FilePath)\r
152 FullPathDependList.append(FilePath)\r
153 break\r
154 DependencySet.update(FullPathDependList)\r
155 DependencyList = list(DependencySet) # remove duplicate ones\r
156\r
157 return DependencyList\r
158\r
ae7b6df8
LG
159class DscBuildData(PlatformBuildClassObject):\r
160 # dict used to convert PCD type in database to string used by build tool\r
161 _PCD_TYPE_STRING_ = {\r
be409b67
CJ
162 MODEL_PCD_FIXED_AT_BUILD : TAB_PCDS_FIXED_AT_BUILD,\r
163 MODEL_PCD_PATCHABLE_IN_MODULE : TAB_PCDS_PATCHABLE_IN_MODULE,\r
164 MODEL_PCD_FEATURE_FLAG : TAB_PCDS_FEATURE_FLAG,\r
165 MODEL_PCD_DYNAMIC : TAB_PCDS_DYNAMIC,\r
166 MODEL_PCD_DYNAMIC_DEFAULT : TAB_PCDS_DYNAMIC,\r
167 MODEL_PCD_DYNAMIC_HII : TAB_PCDS_DYNAMIC_HII,\r
168 MODEL_PCD_DYNAMIC_VPD : TAB_PCDS_DYNAMIC_VPD,\r
169 MODEL_PCD_DYNAMIC_EX : TAB_PCDS_DYNAMIC_EX,\r
170 MODEL_PCD_DYNAMIC_EX_DEFAULT : TAB_PCDS_DYNAMIC_EX,\r
171 MODEL_PCD_DYNAMIC_EX_HII : TAB_PCDS_DYNAMIC_EX_HII,\r
172 MODEL_PCD_DYNAMIC_EX_VPD : TAB_PCDS_DYNAMIC_EX_VPD,\r
ae7b6df8
LG
173 }\r
174\r
175 # dict used to convert part of [Defines] to members of DscBuildData directly\r
176 _PROPERTY_ = {\r
177 #\r
178 # Required Fields\r
179 #\r
180 TAB_DSC_DEFINES_PLATFORM_NAME : "_PlatformName",\r
181 TAB_DSC_DEFINES_PLATFORM_GUID : "_Guid",\r
182 TAB_DSC_DEFINES_PLATFORM_VERSION : "_Version",\r
183 TAB_DSC_DEFINES_DSC_SPECIFICATION : "_DscSpecification",\r
184 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",\r
185 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",\r
186 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",\r
187 TAB_DSC_DEFINES_SKUID_IDENTIFIER : "_SkuName",\r
188 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",\r
189 TAB_DSC_DEFINES_BUILD_NUMBER : "_BuildNumber",\r
190 TAB_DSC_DEFINES_MAKEFILE_NAME : "_MakefileName",\r
191 TAB_DSC_DEFINES_BS_BASE_ADDRESS : "_BsBaseAddress",\r
192 TAB_DSC_DEFINES_RT_BASE_ADDRESS : "_RtBaseAddress",\r
193 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",\r
194 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",\r
195 }\r
196\r
197 # used to compose dummy library class name for those forced library instances\r
198 _NullLibraryNumber = 0\r
199\r
200 ## Constructor of DscBuildData\r
201 #\r
202 # Initialize object of DscBuildData\r
203 #\r
204 # @param FilePath The path of platform description file\r
205 # @param RawData The raw data of DSC file\r
206 # @param BuildDataBase Database used to retrieve module/package information\r
207 # @param Arch The target architecture\r
208 # @param Platform (not used for DscBuildData)\r
209 # @param Macros Macros used for replacement in DSC file\r
210 #\r
55c84777 211 def __init__(self, FilePath, RawData, BuildDataBase, Arch=TAB_ARCH_COMMON, Target=None, Toolchain=None):\r
ae7b6df8
LG
212 self.MetaFile = FilePath\r
213 self._RawData = RawData\r
214 self._Bdb = BuildDataBase\r
215 self._Arch = Arch\r
216 self._Target = Target\r
217 self._Toolchain = Toolchain\r
68ba919f 218 self._ToolChainFamily = None\r
ae7b6df8
LG
219 self._Clear()\r
220 self._HandleOverridePath()\r
0a57a978 221 self.WorkspaceDir = os.getenv("WORKSPACE") if os.getenv("WORKSPACE") else ""\r
8518bf0b 222 self.DefaultStores = None\r
e651d06c 223 self.SkuIdMgr = SkuClass(self.SkuName, self.SkuIds)\r
0a57a978
FB
224 @property\r
225 def OutputPath(self):\r
226 if os.getenv("WORKSPACE"):\r
ccaa7754 227 return os.path.join(os.getenv("WORKSPACE"), self.OutputDirectory, self._Target + "_" + self._Toolchain, PcdValueInitName)\r
0a57a978
FB
228 else:\r
229 return os.path.dirname(self.DscFile)\r
ae7b6df8
LG
230\r
231 ## XXX[key] = value\r
232 def __setitem__(self, key, value):\r
233 self.__dict__[self._PROPERTY_[key]] = value\r
234\r
235 ## value = XXX[key]\r
236 def __getitem__(self, key):\r
237 return self.__dict__[self._PROPERTY_[key]]\r
238\r
239 ## "in" test support\r
240 def __contains__(self, key):\r
241 return key in self._PROPERTY_\r
242\r
243 ## Set all internal used members of DscBuildData to None\r
244 def _Clear(self):\r
245 self._Header = None\r
246 self._PlatformName = None\r
247 self._Guid = None\r
248 self._Version = None\r
249 self._DscSpecification = None\r
250 self._OutputDirectory = None\r
251 self._SupArchList = None\r
252 self._BuildTargets = None\r
253 self._SkuName = None\r
ae7b6df8
LG
254 self._PcdInfoFlag = None\r
255 self._VarCheckFlag = None\r
256 self._FlashDefinition = None\r
257 self._Prebuild = None\r
258 self._Postbuild = None\r
259 self._BuildNumber = None\r
260 self._MakefileName = None\r
261 self._BsBaseAddress = None\r
262 self._RtBaseAddress = None\r
263 self._SkuIds = None\r
264 self._Modules = None\r
265 self._LibraryInstances = None\r
266 self._LibraryClasses = None\r
267 self._Pcds = None\r
268 self._DecPcds = None\r
269 self._BuildOptions = None\r
270 self._ModuleTypeOptions = None\r
271 self._LoadFixAddress = None\r
272 self._RFCLanguages = None\r
273 self._ISOLanguages = None\r
274 self._VpdToolGuid = None\r
275 self.__Macros = None\r
8518bf0b 276 self.DefaultStores = None\r
ae7b6df8
LG
277\r
278\r
279 ## handle Override Path of Module\r
280 def _HandleOverridePath(self):\r
281 RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]\r
ae7b6df8 282 for Record in RecordList:\r
8518bf0b
LG
283 ModuleId = Record[6]\r
284 LineNo = Record[7]\r
ae7b6df8
LG
285 ModuleFile = PathClass(NormPath(Record[0]), GlobalData.gWorkspace, Arch=self._Arch)\r
286 RecordList = self._RawData[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH, self._Arch, None, ModuleId]\r
287 if RecordList != []:\r
288 SourceOverridePath = mws.join(GlobalData.gWorkspace, NormPath(RecordList[0][0]))\r
289\r
290 # Check if the source override path exists\r
291 if not os.path.isdir(SourceOverridePath):\r
292 EdkLogger.error('build', FILE_NOT_FOUND, Message='Source override path does not exist:', File=self.MetaFile, ExtraData=SourceOverridePath, Line=LineNo)\r
293\r
294 # Add to GlobalData Variables\r
295 GlobalData.gOverrideDir[ModuleFile.Key] = SourceOverridePath\r
296\r
297 ## Get current effective macros\r
298 def _GetMacros(self):\r
4231a819 299 if self.__Macros is None:\r
ae7b6df8
LG
300 self.__Macros = {}\r
301 self.__Macros.update(GlobalData.gPlatformDefines)\r
302 self.__Macros.update(GlobalData.gGlobalDefines)\r
303 self.__Macros.update(GlobalData.gCommandLineDefines)\r
304 return self.__Macros\r
305\r
306 ## Get architecture\r
307 def _GetArch(self):\r
308 return self._Arch\r
309\r
310 ## Set architecture\r
311 #\r
312 # Changing the default ARCH to another may affect all other information\r
313 # because all information in a platform may be ARCH-related. That's\r
314 # why we need to clear all internal used members, in order to cause all\r
315 # information to be re-retrieved.\r
316 #\r
317 # @param Value The value of ARCH\r
318 #\r
319 def _SetArch(self, Value):\r
320 if self._Arch == Value:\r
321 return\r
322 self._Arch = Value\r
323 self._Clear()\r
324\r
325 ## Retrieve all information in [Defines] section\r
326 #\r
327 # (Retriving all [Defines] information in one-shot is just to save time.)\r
328 #\r
329 def _GetHeaderInfo(self):\r
330 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]\r
331 for Record in RecordList:\r
332 Name = Record[1]\r
333 # items defined _PROPERTY_ don't need additional processing\r
334\r
335 # some special items in [Defines] section need special treatment\r
336 if Name == TAB_DSC_DEFINES_OUTPUT_DIRECTORY:\r
337 self._OutputDirectory = NormPath(Record[2], self._Macros)\r
338 if ' ' in self._OutputDirectory:\r
339 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in OUTPUT_DIRECTORY",\r
340 File=self.MetaFile, Line=Record[-1],\r
341 ExtraData=self._OutputDirectory)\r
342 elif Name == TAB_DSC_DEFINES_FLASH_DEFINITION:\r
343 self._FlashDefinition = PathClass(NormPath(Record[2], self._Macros), GlobalData.gWorkspace)\r
344 ErrorCode, ErrorInfo = self._FlashDefinition.Validate('.fdf')\r
345 if ErrorCode != 0:\r
346 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=Record[-1],\r
347 ExtraData=ErrorInfo)\r
348 elif Name == TAB_DSC_PREBUILD:\r
349 PrebuildValue = Record[2]\r
350 if Record[2][0] == '"':\r
351 if Record[2][-1] != '"':\r
352 EdkLogger.error('build', FORMAT_INVALID, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD,\r
353 File=self.MetaFile, Line=Record[-1])\r
354 PrebuildValue = Record[2][1:-1]\r
355 self._Prebuild = PrebuildValue\r
356 elif Name == TAB_DSC_POSTBUILD:\r
357 PostbuildValue = Record[2]\r
358 if Record[2][0] == '"':\r
359 if Record[2][-1] != '"':\r
360 EdkLogger.error('build', FORMAT_INVALID, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD,\r
361 File=self.MetaFile, Line=Record[-1])\r
362 PostbuildValue = Record[2][1:-1]\r
363 self._Postbuild = PostbuildValue\r
364 elif Name == TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES:\r
365 self._SupArchList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)\r
366 elif Name == TAB_DSC_DEFINES_BUILD_TARGETS:\r
367 self._BuildTargets = GetSplitValueList(Record[2])\r
368 elif Name == TAB_DSC_DEFINES_SKUID_IDENTIFIER:\r
4231a819 369 if self._SkuName is None:\r
ae7b6df8 370 self._SkuName = Record[2]\r
e651d06c
LG
371 if GlobalData.gSKUID_CMD:\r
372 self._SkuName = GlobalData.gSKUID_CMD\r
ae7b6df8
LG
373 elif Name == TAB_DSC_DEFINES_PCD_INFO_GENERATION:\r
374 self._PcdInfoFlag = Record[2]\r
375 elif Name == TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION:\r
376 self._VarCheckFlag = Record[2]\r
377 elif Name == TAB_FIX_LOAD_TOP_MEMORY_ADDRESS:\r
378 try:\r
379 self._LoadFixAddress = int (Record[2], 0)\r
380 except:\r
381 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record[2]))\r
382 elif Name == TAB_DSC_DEFINES_RFC_LANGUAGES:\r
383 if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:\r
384 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for RFC_LANGUAGES must have double quotes around it, for example: RFC_LANGUAGES = "en-us;zh-hans"',\r
385 File=self.MetaFile, Line=Record[-1])\r
386 LanguageCodes = Record[2][1:-1]\r
387 if not LanguageCodes:\r
388 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',\r
389 File=self.MetaFile, Line=Record[-1])\r
390 LanguageList = GetSplitValueList(LanguageCodes, TAB_SEMI_COLON_SPLIT)\r
391 # check whether there is empty entries in the list\r
392 if None in LanguageList:\r
393 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more empty language code is in RFC_LANGUAGES statement',\r
394 File=self.MetaFile, Line=Record[-1])\r
395 self._RFCLanguages = LanguageList\r
396 elif Name == TAB_DSC_DEFINES_ISO_LANGUAGES:\r
397 if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:\r
398 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',\r
399 File=self.MetaFile, Line=Record[-1])\r
400 LanguageCodes = Record[2][1:-1]\r
401 if not LanguageCodes:\r
402 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',\r
403 File=self.MetaFile, Line=Record[-1])\r
404 if len(LanguageCodes) % 3:\r
405 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'bad ISO639-2 format for ISO_LANGUAGES',\r
406 File=self.MetaFile, Line=Record[-1])\r
407 LanguageList = []\r
408 for i in range(0, len(LanguageCodes), 3):\r
409 LanguageList.append(LanguageCodes[i:i + 3])\r
410 self._ISOLanguages = LanguageList\r
411 elif Name == TAB_DSC_DEFINES_VPD_TOOL_GUID:\r
412 #\r
413 # try to convert GUID to a real UUID value to see whether the GUID is format\r
414 # for VPD_TOOL_GUID is correct.\r
415 #\r
416 try:\r
417 uuid.UUID(Record[2])\r
418 except:\r
419 EdkLogger.error("build", FORMAT_INVALID, "Invalid GUID format for VPD_TOOL_GUID", File=self.MetaFile)\r
420 self._VpdToolGuid = Record[2]\r
421 elif Name in self:\r
422 self[Name] = Record[2]\r
423 # set _Header to non-None in order to avoid database re-querying\r
424 self._Header = 'DUMMY'\r
425\r
426 ## Retrieve platform name\r
427 def _GetPlatformName(self):\r
4231a819
CJ
428 if self._PlatformName is None:\r
429 if self._Header is None:\r
ae7b6df8 430 self._GetHeaderInfo()\r
4231a819 431 if self._PlatformName is None:\r
ae7b6df8
LG
432 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_NAME", File=self.MetaFile)\r
433 return self._PlatformName\r
434\r
435 ## Retrieve file guid\r
436 def _GetFileGuid(self):\r
4231a819
CJ
437 if self._Guid is None:\r
438 if self._Header is None:\r
ae7b6df8 439 self._GetHeaderInfo()\r
4231a819 440 if self._Guid is None:\r
ae7b6df8
LG
441 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_GUID", File=self.MetaFile)\r
442 return self._Guid\r
443\r
444 ## Retrieve platform version\r
445 def _GetVersion(self):\r
4231a819
CJ
446 if self._Version is None:\r
447 if self._Header is None:\r
ae7b6df8 448 self._GetHeaderInfo()\r
4231a819 449 if self._Version is None:\r
ae7b6df8
LG
450 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_VERSION", File=self.MetaFile)\r
451 return self._Version\r
452\r
453 ## Retrieve platform description file version\r
454 def _GetDscSpec(self):\r
4231a819
CJ
455 if self._DscSpecification is None:\r
456 if self._Header is None:\r
ae7b6df8 457 self._GetHeaderInfo()\r
4231a819 458 if self._DscSpecification is None:\r
ae7b6df8
LG
459 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No DSC_SPECIFICATION", File=self.MetaFile)\r
460 return self._DscSpecification\r
461\r
462 ## Retrieve OUTPUT_DIRECTORY\r
463 def _GetOutpuDir(self):\r
4231a819
CJ
464 if self._OutputDirectory is None:\r
465 if self._Header is None:\r
ae7b6df8 466 self._GetHeaderInfo()\r
4231a819 467 if self._OutputDirectory is None:\r
ae7b6df8
LG
468 self._OutputDirectory = os.path.join("Build", self._PlatformName)\r
469 return self._OutputDirectory\r
470\r
471 ## Retrieve SUPPORTED_ARCHITECTURES\r
472 def _GetSupArch(self):\r
4231a819
CJ
473 if self._SupArchList is None:\r
474 if self._Header is None:\r
ae7b6df8 475 self._GetHeaderInfo()\r
4231a819 476 if self._SupArchList is None:\r
ae7b6df8
LG
477 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No SUPPORTED_ARCHITECTURES", File=self.MetaFile)\r
478 return self._SupArchList\r
479\r
480 ## Retrieve BUILD_TARGETS\r
481 def _GetBuildTarget(self):\r
4231a819
CJ
482 if self._BuildTargets is None:\r
483 if self._Header is None:\r
ae7b6df8 484 self._GetHeaderInfo()\r
4231a819 485 if self._BuildTargets is None:\r
ae7b6df8
LG
486 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BUILD_TARGETS", File=self.MetaFile)\r
487 return self._BuildTargets\r
488\r
489 def _GetPcdInfoFlag(self):\r
4231a819 490 if self._PcdInfoFlag is None or self._PcdInfoFlag.upper() == 'FALSE':\r
ae7b6df8
LG
491 return False\r
492 elif self._PcdInfoFlag.upper() == 'TRUE':\r
493 return True\r
494 else:\r
495 return False\r
496 def _GetVarCheckFlag(self):\r
4231a819 497 if self._VarCheckFlag is None or self._VarCheckFlag.upper() == 'FALSE':\r
ae7b6df8
LG
498 return False\r
499 elif self._VarCheckFlag.upper() == 'TRUE':\r
500 return True\r
501 else:\r
502 return False\r
e651d06c
LG
503\r
504 # # Retrieve SKUID_IDENTIFIER\r
ae7b6df8 505 def _GetSkuName(self):\r
4231a819
CJ
506 if self._SkuName is None:\r
507 if self._Header is None:\r
ae7b6df8 508 self._GetHeaderInfo()\r
4231a819 509 if self._SkuName is None:\r
55c84777 510 self._SkuName = TAB_DEFAULT\r
ae7b6df8
LG
511 return self._SkuName\r
512\r
513 ## Override SKUID_IDENTIFIER\r
514 def _SetSkuName(self, Value):\r
515 self._SkuName = Value\r
ae7b6df8
LG
516\r
517 def _GetFdfFile(self):\r
4231a819
CJ
518 if self._FlashDefinition is None:\r
519 if self._Header is None:\r
ae7b6df8 520 self._GetHeaderInfo()\r
4231a819 521 if self._FlashDefinition is None:\r
ae7b6df8
LG
522 self._FlashDefinition = ''\r
523 return self._FlashDefinition\r
524\r
525 def _GetPrebuild(self):\r
4231a819
CJ
526 if self._Prebuild is None:\r
527 if self._Header is None:\r
ae7b6df8 528 self._GetHeaderInfo()\r
4231a819 529 if self._Prebuild is None:\r
ae7b6df8
LG
530 self._Prebuild = ''\r
531 return self._Prebuild\r
532\r
533 def _GetPostbuild(self):\r
4231a819
CJ
534 if self._Postbuild is None:\r
535 if self._Header is None:\r
ae7b6df8 536 self._GetHeaderInfo()\r
4231a819 537 if self._Postbuild is None:\r
ae7b6df8
LG
538 self._Postbuild = ''\r
539 return self._Postbuild\r
540\r
541 ## Retrieve FLASH_DEFINITION\r
542 def _GetBuildNumber(self):\r
4231a819
CJ
543 if self._BuildNumber is None:\r
544 if self._Header is None:\r
ae7b6df8 545 self._GetHeaderInfo()\r
4231a819 546 if self._BuildNumber is None:\r
ae7b6df8
LG
547 self._BuildNumber = ''\r
548 return self._BuildNumber\r
549\r
550 ## Retrieve MAKEFILE_NAME\r
551 def _GetMakefileName(self):\r
4231a819
CJ
552 if self._MakefileName is None:\r
553 if self._Header is None:\r
ae7b6df8 554 self._GetHeaderInfo()\r
4231a819 555 if self._MakefileName is None:\r
ae7b6df8
LG
556 self._MakefileName = ''\r
557 return self._MakefileName\r
558\r
559 ## Retrieve BsBaseAddress\r
560 def _GetBsBaseAddress(self):\r
4231a819
CJ
561 if self._BsBaseAddress is None:\r
562 if self._Header is None:\r
ae7b6df8 563 self._GetHeaderInfo()\r
4231a819 564 if self._BsBaseAddress is None:\r
ae7b6df8
LG
565 self._BsBaseAddress = ''\r
566 return self._BsBaseAddress\r
567\r
568 ## Retrieve RtBaseAddress\r
569 def _GetRtBaseAddress(self):\r
4231a819
CJ
570 if self._RtBaseAddress is None:\r
571 if self._Header is None:\r
ae7b6df8 572 self._GetHeaderInfo()\r
4231a819 573 if self._RtBaseAddress is None:\r
ae7b6df8
LG
574 self._RtBaseAddress = ''\r
575 return self._RtBaseAddress\r
576\r
577 ## Retrieve the top address for the load fix address\r
578 def _GetLoadFixAddress(self):\r
4231a819
CJ
579 if self._LoadFixAddress is None:\r
580 if self._Header is None:\r
ae7b6df8
LG
581 self._GetHeaderInfo()\r
582\r
4231a819 583 if self._LoadFixAddress is None:\r
ae7b6df8
LG
584 self._LoadFixAddress = self._Macros.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS, '0')\r
585\r
586 try:\r
587 self._LoadFixAddress = int (self._LoadFixAddress, 0)\r
588 except:\r
589 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self._LoadFixAddress))\r
590\r
591 #\r
592 # If command line defined, should override the value in DSC file.\r
593 #\r
5a693b89 594 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines:\r
ae7b6df8
LG
595 try:\r
596 self._LoadFixAddress = int(GlobalData.gCommandLineDefines['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)\r
597 except:\r
598 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (GlobalData.gCommandLineDefines['FIX_LOAD_TOP_MEMORY_ADDRESS']))\r
599\r
600 if self._LoadFixAddress < 0:\r
601 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self._LoadFixAddress))\r
602 if self._LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self._LoadFixAddress % 0x1000 != 0:\r
603 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self._LoadFixAddress))\r
604\r
605 return self._LoadFixAddress\r
606\r
607 ## Retrieve RFCLanguage filter\r
608 def _GetRFCLanguages(self):\r
4231a819
CJ
609 if self._RFCLanguages is None:\r
610 if self._Header is None:\r
ae7b6df8 611 self._GetHeaderInfo()\r
4231a819 612 if self._RFCLanguages is None:\r
ae7b6df8
LG
613 self._RFCLanguages = []\r
614 return self._RFCLanguages\r
615\r
616 ## Retrieve ISOLanguage filter\r
617 def _GetISOLanguages(self):\r
4231a819
CJ
618 if self._ISOLanguages is None:\r
619 if self._Header is None:\r
ae7b6df8 620 self._GetHeaderInfo()\r
4231a819 621 if self._ISOLanguages is None:\r
ae7b6df8
LG
622 self._ISOLanguages = []\r
623 return self._ISOLanguages\r
624 ## Retrieve the GUID string for VPD tool\r
625 def _GetVpdToolGuid(self):\r
4231a819
CJ
626 if self._VpdToolGuid is None:\r
627 if self._Header is None:\r
ae7b6df8 628 self._GetHeaderInfo()\r
4231a819 629 if self._VpdToolGuid is None:\r
ae7b6df8
LG
630 self._VpdToolGuid = ''\r
631 return self._VpdToolGuid\r
632\r
633 ## Retrieve [SkuIds] section information\r
634 def _GetSkuIds(self):\r
4231a819 635 if self._SkuIds is None:\r
a0767bae 636 self._SkuIds = OrderedDict()\r
ae7b6df8
LG
637 RecordList = self._RawData[MODEL_EFI_SKU_ID, self._Arch]\r
638 for Record in RecordList:\r
c93356ad 639 if not Record[0]:\r
ae7b6df8
LG
640 EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number',\r
641 File=self.MetaFile, Line=Record[-1])\r
c93356ad 642 if not Record[1]:\r
ae7b6df8
LG
643 EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name',\r
644 File=self.MetaFile, Line=Record[-1])\r
fe1abb4b 645 if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]):\r
e6b10112 646 EdkLogger.error('build', FORMAT_INVALID, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",\r
8518bf0b
LG
647 File=self.MetaFile, Line=Record[-1])\r
648 if not IsValidWord(Record[1]):\r
649 EdkLogger.error('build', FORMAT_INVALID, "The format of the Sku ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",\r
650 File=self.MetaFile, Line=Record[-1])\r
9e508f3a 651 self._SkuIds[Record[1].upper()] = (str(DscBuildData.ToInt(Record[0])), Record[1].upper(), Record[2].upper())\r
55c84777
CJ
652 if TAB_DEFAULT not in self._SkuIds:\r
653 self._SkuIds[TAB_DEFAULT] = ("0", TAB_DEFAULT, TAB_DEFAULT)\r
654 if TAB_COMMON not in self._SkuIds:\r
655 self._SkuIds[TAB_COMMON] = ("0", TAB_DEFAULT, TAB_DEFAULT)\r
ae7b6df8 656 return self._SkuIds\r
9e508f3a
CJ
657\r
658 @staticmethod\r
659 def ToInt(intstr):\r
ccaa7754 660 return int(intstr, 16) if intstr.upper().startswith("0X") else int(intstr)\r
9e508f3a 661\r
8518bf0b 662 def _GetDefaultStores(self):\r
4231a819 663 if self.DefaultStores is None:\r
a0767bae 664 self.DefaultStores = OrderedDict()\r
8518bf0b
LG
665 RecordList = self._RawData[MODEL_EFI_DEFAULT_STORES, self._Arch]\r
666 for Record in RecordList:\r
c93356ad 667 if not Record[0]:\r
8518bf0b
LG
668 EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID number',\r
669 File=self.MetaFile, Line=Record[-1])\r
c93356ad 670 if not Record[1]:\r
8518bf0b
LG
671 EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID name',\r
672 File=self.MetaFile, Line=Record[-1])\r
fe1abb4b 673 if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]):\r
767ddbe8
YZ
674 EdkLogger.error('build', FORMAT_INVALID, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",\r
675 File=self.MetaFile, Line=Record[-1])\r
676 if not IsValidWord(Record[1]):\r
677 EdkLogger.error('build', FORMAT_INVALID, "The format of the DefaultStores ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",\r
678 File=self.MetaFile, Line=Record[-1])\r
ccaa7754 679 self.DefaultStores[Record[1].upper()] = (DscBuildData.ToInt(Record[0]), Record[1].upper())\r
8518bf0b 680 if TAB_DEFAULT_STORES_DEFAULT not in self.DefaultStores:\r
ccaa7754 681 self.DefaultStores[TAB_DEFAULT_STORES_DEFAULT] = (0, TAB_DEFAULT_STORES_DEFAULT)\r
5a693b89 682 GlobalData.gDefaultStores = sorted(self.DefaultStores.keys())\r
8518bf0b 683 return self.DefaultStores\r
ae7b6df8
LG
684\r
685 ## Retrieve [Components] section information\r
686 def _GetModules(self):\r
4231a819 687 if self._Modules is not None:\r
ae7b6df8
LG
688 return self._Modules\r
689\r
a0767bae 690 self._Modules = OrderedDict()\r
ae7b6df8
LG
691 RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]\r
692 Macros = self._Macros\r
693 Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
694 for Record in RecordList:\r
695 DuplicatedFile = False\r
696\r
697 ModuleFile = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
8518bf0b
LG
698 ModuleId = Record[6]\r
699 LineNo = Record[7]\r
ae7b6df8
LG
700\r
701 # check the file validation\r
702 ErrorCode, ErrorInfo = ModuleFile.Validate('.inf')\r
703 if ErrorCode != 0:\r
704 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,\r
705 ExtraData=ErrorInfo)\r
706 # Check duplication\r
707 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected\r
55c84777 708 if self._Arch != TAB_ARCH_COMMON and ModuleFile in self._Modules:\r
ae7b6df8
LG
709 DuplicatedFile = True\r
710\r
711 Module = ModuleBuildClassObject()\r
712 Module.MetaFile = ModuleFile\r
713\r
714 # get module private library instance\r
715 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, ModuleId]\r
716 for Record in RecordList:\r
717 LibraryClass = Record[0]\r
718 LibraryPath = PathClass(NormPath(Record[1], Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
719 LineNo = Record[-1]\r
720\r
721 # check the file validation\r
722 ErrorCode, ErrorInfo = LibraryPath.Validate('.inf')\r
723 if ErrorCode != 0:\r
724 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,\r
725 ExtraData=ErrorInfo)\r
726\r
727 if LibraryClass == '' or LibraryClass == 'NULL':\r
728 self._NullLibraryNumber += 1\r
729 LibraryClass = 'NULL%d' % self._NullLibraryNumber\r
730 EdkLogger.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile, LibraryPath, LibraryClass))\r
731 Module.LibraryClasses[LibraryClass] = LibraryPath\r
732 if LibraryPath not in self.LibraryInstances:\r
733 self.LibraryInstances.append(LibraryPath)\r
734\r
735 # get module private PCD setting\r
736 for Type in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, \\r
737 MODEL_PCD_FEATURE_FLAG, MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]:\r
738 RecordList = self._RawData[Type, self._Arch, None, ModuleId]\r
ccaa7754 739 for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4, Dummy5 in RecordList:\r
ae7b6df8
LG
740 TokenList = GetSplitValueList(Setting)\r
741 DefaultValue = TokenList[0]\r
cdbf45ad
YZ
742 # the format is PcdName| Value | VOID* | MaxDatumSize\r
743 if len(TokenList) > 2:\r
744 MaxDatumSize = TokenList[2]\r
ae7b6df8
LG
745 else:\r
746 MaxDatumSize = ''\r
747 TypeString = self._PCD_TYPE_STRING_[Type]\r
748 Pcd = PcdClassObject(\r
749 PcdCName,\r
750 TokenSpaceGuid,\r
751 TypeString,\r
752 '',\r
753 DefaultValue,\r
754 '',\r
755 MaxDatumSize,\r
756 {},\r
757 False,\r
758 None\r
759 )\r
760 Module.Pcds[PcdCName, TokenSpaceGuid] = Pcd\r
761\r
762 # get module private build options\r
763 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, None, ModuleId]\r
ccaa7754 764 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4, Dummy5 in RecordList:\r
ae7b6df8
LG
765 if (ToolChainFamily, ToolChain) not in Module.BuildOptions:\r
766 Module.BuildOptions[ToolChainFamily, ToolChain] = Option\r
767 else:\r
768 OptionString = Module.BuildOptions[ToolChainFamily, ToolChain]\r
769 Module.BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option\r
770\r
771 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, None, ModuleId]\r
772 if DuplicatedFile and not RecordList:\r
773 EdkLogger.error('build', FILE_DUPLICATED, File=self.MetaFile, ExtraData=str(ModuleFile), Line=LineNo)\r
774 if RecordList:\r
775 if len(RecordList) != 1:\r
776 EdkLogger.error('build', OPTION_UNKNOWN, 'Only FILE_GUID can be listed in <Defines> section.',\r
777 File=self.MetaFile, ExtraData=str(ModuleFile), Line=LineNo)\r
778 ModuleFile = ProcessDuplicatedInf(ModuleFile, RecordList[0][2], GlobalData.gWorkspace)\r
779 ModuleFile.Arch = self._Arch\r
780\r
781 self._Modules[ModuleFile] = Module\r
782 return self._Modules\r
783\r
784 ## Retrieve all possible library instances used in this platform\r
785 def _GetLibraryInstances(self):\r
4231a819 786 if self._LibraryInstances is None:\r
ae7b6df8
LG
787 self._GetLibraryClasses()\r
788 return self._LibraryInstances\r
789\r
790 ## Retrieve [LibraryClasses] information\r
791 def _GetLibraryClasses(self):\r
4231a819 792 if self._LibraryClasses is None:\r
ae7b6df8
LG
793 self._LibraryInstances = []\r
794 #\r
795 # tdict is a special dict kind of type, used for selecting correct\r
796 # library instance for given library class and module type\r
797 #\r
798 LibraryClassDict = tdict(True, 3)\r
799 # track all library class names\r
800 LibraryClassSet = set()\r
801 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, -1]\r
802 Macros = self._Macros\r
803 for Record in RecordList:\r
ccaa7754 804 LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, Dummy, LineNo = Record\r
ae7b6df8
LG
805 if LibraryClass == '' or LibraryClass == 'NULL':\r
806 self._NullLibraryNumber += 1\r
807 LibraryClass = 'NULL%d' % self._NullLibraryNumber\r
808 EdkLogger.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch, LibraryInstance, LibraryClass))\r
809 LibraryClassSet.add(LibraryClass)\r
810 LibraryInstance = PathClass(NormPath(LibraryInstance, Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
811 # check the file validation\r
812 ErrorCode, ErrorInfo = LibraryInstance.Validate('.inf')\r
813 if ErrorCode != 0:\r
814 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,\r
815 ExtraData=ErrorInfo)\r
816\r
55c84777 817 if ModuleType != TAB_COMMON and ModuleType not in SUP_MODULE_LIST:\r
ae7b6df8
LG
818 EdkLogger.error('build', OPTION_UNKNOWN, "Unknown module type [%s]" % ModuleType,\r
819 File=self.MetaFile, ExtraData=LibraryInstance, Line=LineNo)\r
820 LibraryClassDict[Arch, ModuleType, LibraryClass] = LibraryInstance\r
821 if LibraryInstance not in self._LibraryInstances:\r
822 self._LibraryInstances.append(LibraryInstance)\r
823\r
824 # resolve the specific library instance for each class and each module type\r
825 self._LibraryClasses = tdict(True)\r
826 for LibraryClass in LibraryClassSet:\r
827 # try all possible module types\r
828 for ModuleType in SUP_MODULE_LIST:\r
829 LibraryInstance = LibraryClassDict[self._Arch, ModuleType, LibraryClass]\r
4231a819 830 if LibraryInstance is None:\r
ae7b6df8
LG
831 continue\r
832 self._LibraryClasses[LibraryClass, ModuleType] = LibraryInstance\r
833\r
834 # for Edk style library instances, which are listed in different section\r
835 Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
836 RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch]\r
837 for Record in RecordList:\r
838 File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
839 LineNo = Record[-1]\r
840 # check the file validation\r
841 ErrorCode, ErrorInfo = File.Validate('.inf')\r
842 if ErrorCode != 0:\r
843 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,\r
844 ExtraData=ErrorInfo)\r
845 if File not in self._LibraryInstances:\r
846 self._LibraryInstances.append(File)\r
847 #\r
848 # we need the module name as the library class name, so we have\r
849 # to parse it here. (self._Bdb[] will trigger a file parse if it\r
850 # hasn't been parsed)\r
851 #\r
852 Library = self._Bdb[File, self._Arch, self._Target, self._Toolchain]\r
853 self._LibraryClasses[Library.BaseName, ':dummy:'] = Library\r
854 return self._LibraryClasses\r
855\r
856 def _ValidatePcd(self, PcdCName, TokenSpaceGuid, Setting, PcdType, LineNo):\r
4231a819 857 if self._DecPcds is None:\r
2b8a6c44 858\r
ae7b6df8
LG
859 FdfInfList = []\r
860 if GlobalData.gFdfParser:\r
861 FdfInfList = GlobalData.gFdfParser.Profile.InfList\r
862\r
863 PkgSet = set()\r
864 for Inf in FdfInfList:\r
865 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch=self._Arch)\r
866 if ModuleFile in self._Modules:\r
867 continue\r
868 ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]\r
869 PkgSet.update(ModuleData.Packages)\r
ae7b6df8 870\r
ccaa7754 871 self._DecPcds, self._GuidDict = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain, PkgSet)\r
9efe8d60 872 self._GuidDict.update(GlobalData.gPlatformPcds)\r
2b8a6c44
LG
873\r
874 if (PcdCName, TokenSpaceGuid) not in self._DecPcds:\r
ae7b6df8
LG
875 EdkLogger.error('build', PARSER_ERROR,\r
876 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid, PcdCName, self._Arch),\r
877 File=self.MetaFile, Line=LineNo)\r
878 ValueList, IsValid, Index = AnalyzeDscPcd(Setting, PcdType, self._DecPcds[PcdCName, TokenSpaceGuid].DatumType)\r
520365de
B
879 if not IsValid:\r
880 if PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:\r
881 EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,\r
882 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))\r
883 else:\r
884 if ValueList[2] == '-1':\r
885 EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,\r
886 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))\r
35f613d9
YF
887 if ValueList[Index]:\r
888 DatumType = self._DecPcds[PcdCName, TokenSpaceGuid].DatumType\r
ae7b6df8 889 try:\r
35f613d9 890 ValueList[Index] = ValueExpressionEx(ValueList[Index], DatumType, self._GuidDict)(True)\r
5b0671c1 891 except BadExpression as Value:\r
35f613d9
YF
892 EdkLogger.error('Parser', FORMAT_INVALID, Value, File=self.MetaFile, Line=LineNo,\r
893 ExtraData="PCD [%s.%s] Value \"%s\" " % (\r
894 TokenSpaceGuid, PcdCName, ValueList[Index]))\r
5b0671c1 895 except EvaluationException as Excpt:\r
ae7b6df8
LG
896 if hasattr(Excpt, 'Pcd'):\r
897 if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r
898 EdkLogger.error('Parser', FORMAT_INVALID, "Cannot use this PCD (%s) in an expression as"\r
899 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"\r
900 " of the DSC file" % Excpt.Pcd,\r
901 File=self.MetaFile, Line=LineNo)\r
902 else:\r
903 EdkLogger.error('Parser', FORMAT_INVALID, "PCD (%s) is not defined in DSC file" % Excpt.Pcd,\r
904 File=self.MetaFile, Line=LineNo)\r
905 else:\r
906 EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),\r
907 File=self.MetaFile, Line=LineNo)\r
35f613d9 908\r
ae7b6df8
LG
909 if ValueList[Index]:\r
910 Valid, ErrStr = CheckPcdDatum(self._DecPcds[PcdCName, TokenSpaceGuid].DatumType, ValueList[Index])\r
911 if not Valid:\r
912 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,\r
913 ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))\r
520365de
B
914 if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT):\r
915 if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() != ValueList[1].strip():\r
ccaa7754 916 EdkLogger.error('build', FORMAT_INVALID, "Pcd datumtype used in DSC file is not the same as its declaration in DEC file.", File=self.MetaFile, Line=LineNo,\r
520365de 917 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))\r
35f613d9
YF
918 if (TokenSpaceGuid + '.' + PcdCName) in GlobalData.gPlatformPcds:\r
919 if GlobalData.gPlatformPcds[TokenSpaceGuid + '.' + PcdCName] != ValueList[Index]:\r
920 GlobalData.gPlatformPcds[TokenSpaceGuid + '.' + PcdCName] = ValueList[Index]\r
ae7b6df8
LG
921 return ValueList\r
922\r
ccaa7754 923 def _FilterPcdBySkuUsage(self, Pcds):\r
8518bf0b
LG
924 available_sku = self.SkuIdMgr.AvailableSkuIdSet\r
925 sku_usage = self.SkuIdMgr.SkuUsageType\r
926 if sku_usage == SkuClass.SINGLE:\r
927 for pcdname in Pcds:\r
928 pcd = Pcds[pcdname]\r
55c84777 929 Pcds[pcdname].SkuInfoList = {TAB_DEFAULT:pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku}\r
0d1f5b2b 930 if isinstance(pcd, StructurePcd) and pcd.SkuOverrideValues:\r
55c84777 931 Pcds[pcdname].SkuOverrideValues = {TAB_DEFAULT:pcd.SkuOverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_sku}\r
8518bf0b
LG
932 else:\r
933 for pcdname in Pcds:\r
934 pcd = Pcds[pcdname]\r
935 Pcds[pcdname].SkuInfoList = {skuid:pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku}\r
0d1f5b2b 936 if isinstance(pcd, StructurePcd) and pcd.SkuOverrideValues:\r
65eff519 937 Pcds[pcdname].SkuOverrideValues = {skuid:pcd.SkuOverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_sku}\r
8518bf0b 938 return Pcds\r
ccaa7754 939 def CompleteHiiPcdsDefaultStores(self, Pcds):\r
2b8a6c44
LG
940 HiiPcd = [Pcds[pcd] for pcd in Pcds if Pcds[pcd].Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]]\r
941 DefaultStoreMgr = DefaultStore(self.DefaultStores)\r
942 for pcd in HiiPcd:\r
943 for skuid in pcd.SkuInfoList:\r
944 skuobj = pcd.SkuInfoList.get(skuid)\r
4d3b9389 945 if TAB_DEFAULT_STORES_DEFAULT not in skuobj.DefaultStoreDict:\r
c5c7e68a 946 PcdDefaultStoreSet = set(defaultstorename for defaultstorename in skuobj.DefaultStoreDict)\r
2b8a6c44 947 mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)\r
4d3b9389 948 skuobj.DefaultStoreDict[TAB_DEFAULT_STORES_DEFAULT] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])\r
2b8a6c44
LG
949 return Pcds\r
950\r
6f49996c 951 def RecoverCommandLinePcd(self):\r
0f228f19
B
952 def UpdateCommandLineValue(pcd):\r
953 if pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
954 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
955 pcd.PcdValueFromComm = pcd.DefaultValue\r
956 elif pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
55c84777 957 pcd.PcdValueFromComm = pcd.SkuInfoList.get(TAB_DEFAULT).HiiDefaultValue\r
0f228f19 958 else:\r
55c84777 959 pcd.PcdValueFromComm = pcd.SkuInfoList.get(TAB_DEFAULT).DefaultValue\r
0f228f19 960 for pcd in self._Pcds:\r
ccaa7754 961 if isinstance(self._Pcds[pcd], StructurePcd) and (self._Pcds[pcd].PcdValueFromComm or self._Pcds[pcd].PcdFieldValueFromComm):\r
0f228f19
B
962 UpdateCommandLineValue(self._Pcds[pcd])\r
963\r
6f49996c
FB
964 def __ParsePcdFromCommandLine(self):\r
965 if GlobalData.BuildOptionPcd:\r
966 for i, pcd in enumerate(GlobalData.BuildOptionPcd):\r
0d1f5b2b 967 if isinstance(pcd, tuple):\r
6f49996c
FB
968 continue\r
969 (pcdname, pcdvalue) = pcd.split('=')\r
970 if not pcdvalue:\r
971 EdkLogger.error('build', AUTOGEN_ERROR, "No Value specified for the PCD %s." % (pcdname))\r
972 if '.' in pcdname:\r
ccaa7754 973 (Name1, Name2) = pcdname.split('.', 1)\r
6f49996c 974 if "." in Name2:\r
ccaa7754
GL
975 (Name3, FieldName) = Name2.split(".", 1)\r
976 if ((Name3, Name1)) in self.DecPcds:\r
6f49996c
FB
977 HasTokenSpace = True\r
978 TokenCName = Name3\r
979 TokenSpaceGuidCName = Name1\r
980 else:\r
981 FieldName = Name2\r
982 TokenCName = Name1\r
983 TokenSpaceGuidCName = ''\r
984 HasTokenSpace = False\r
985 else:\r
ccaa7754 986 if ((Name2, Name1)) in self.DecPcds:\r
6f49996c
FB
987 HasTokenSpace = True\r
988 TokenCName = Name2\r
989 TokenSpaceGuidCName = Name1\r
990 FieldName =""\r
991 else:\r
992 FieldName = Name2\r
993 TokenCName = Name1\r
994 TokenSpaceGuidCName = ''\r
995 HasTokenSpace = False\r
996 else:\r
997 FieldName = ""\r
998 TokenCName = pcdname\r
999 TokenSpaceGuidCName = ''\r
1000 HasTokenSpace = False\r
1001 TokenSpaceGuidCNameList = []\r
1002 FoundFlag = False\r
1003 PcdDatumType = ''\r
8565b582
YZ
1004 DisplayName = TokenCName\r
1005 if FieldName:\r
1006 DisplayName = TokenCName + '.' + FieldName\r
6f49996c
FB
1007 if not HasTokenSpace:\r
1008 for key in self.DecPcds:\r
8565b582
YZ
1009 PcdItem = self.DecPcds[key]\r
1010 if TokenCName == PcdItem.TokenCName:\r
1011 if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:\r
1012 if len (TokenSpaceGuidCNameList) < 1:\r
1013 TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)\r
1014 TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName\r
1015 PcdDatumType = PcdItem.DatumType\r
1016 FoundFlag = True\r
1017 else:\r
1018 EdkLogger.error(\r
1019 'build',\r
1020 AUTOGEN_ERROR,\r
1021 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])\r
1022 )\r
6f49996c
FB
1023 else:\r
1024 if (TokenCName, TokenSpaceGuidCName) in self.DecPcds:\r
87a1f65e 1025 PcdDatumType = self.DecPcds[(TokenCName, TokenSpaceGuidCName)].DatumType\r
6f49996c 1026 FoundFlag = True\r
6f49996c
FB
1027 if not FoundFlag:\r
1028 if HasTokenSpace:\r
8565b582 1029 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, DisplayName))\r
6f49996c 1030 else:\r
8565b582
YZ
1031 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (DisplayName))\r
1032 pcdvalue = pcdvalue.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")\r
1033 if FieldName:\r
9e508f3a 1034 pcdvalue = DscBuildData.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict, FieldName)\r
8565b582 1035 else:\r
9e508f3a 1036 pcdvalue = DscBuildData.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict)\r
8565b582
YZ
1037 IsValid, Cause = CheckPcdDatum(PcdDatumType, pcdvalue)\r
1038 if not IsValid:\r
1039 EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))\r
ccaa7754 1040 GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName, pcdvalue, ("build command options", 1))\r
8565b582 1041\r
6f49996c
FB
1042 for BuildData in self._Bdb._CACHE_.values():\r
1043 if BuildData.MetaFile.Ext == '.dec' or BuildData.MetaFile.Ext == '.dsc':\r
1044 continue\r
1045 for key in BuildData.Pcds:\r
1046 PcdItem = BuildData.Pcds[key]\r
1047 if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName) and FieldName =="":\r
8565b582
YZ
1048 PcdItem.DefaultValue = pcdvalue\r
1049\r
9e508f3a
CJ
1050 @staticmethod\r
1051 def HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, PcdValue, PcdDatumType, GuidDict, FieldName=''):\r
8565b582
YZ
1052 if FieldName:\r
1053 IsArray = False\r
1054 TokenCName += '.' + FieldName\r
1055 if PcdValue.startswith('H'):\r
1056 if FieldName and IsFieldValueAnArray(PcdValue[1:]):\r
656d2539 1057 PcdDatumType = TAB_VOID\r
8565b582
YZ
1058 IsArray = True\r
1059 if FieldName and not IsArray:\r
1060 return PcdValue\r
1061 try:\r
1062 PcdValue = ValueExpressionEx(PcdValue[1:], PcdDatumType, GuidDict)(True)\r
5b0671c1 1063 except BadExpression as Value:\r
8565b582
YZ
1064 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %\r
1065 (TokenSpaceGuidCName, TokenCName, PcdValue, Value))\r
1066 elif PcdValue.startswith("L'") or PcdValue.startswith("'"):\r
1067 if FieldName and IsFieldValueAnArray(PcdValue):\r
656d2539 1068 PcdDatumType = TAB_VOID\r
8565b582
YZ
1069 IsArray = True\r
1070 if FieldName and not IsArray:\r
1071 return PcdValue\r
1072 try:\r
1073 PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True)\r
5b0671c1 1074 except BadExpression as Value:\r
8565b582
YZ
1075 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %\r
1076 (TokenSpaceGuidCName, TokenCName, PcdValue, Value))\r
1077 elif PcdValue.startswith('L'):\r
1078 PcdValue = 'L"' + PcdValue[1:] + '"'\r
1079 if FieldName and IsFieldValueAnArray(PcdValue):\r
656d2539 1080 PcdDatumType = TAB_VOID\r
8565b582
YZ
1081 IsArray = True\r
1082 if FieldName and not IsArray:\r
1083 return PcdValue\r
1084 try:\r
1085 PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True)\r
5b0671c1 1086 except BadExpression as Value:\r
8565b582
YZ
1087 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %\r
1088 (TokenSpaceGuidCName, TokenCName, PcdValue, Value))\r
1089 else:\r
1090 if PcdValue.upper() == 'FALSE':\r
1091 PcdValue = str(0)\r
1092 if PcdValue.upper() == 'TRUE':\r
1093 PcdValue = str(1)\r
1094 if not FieldName:\r
656d2539 1095 if PcdDatumType not in TAB_PCD_NUMERIC_TYPES:\r
8565b582
YZ
1096 PcdValue = '"' + PcdValue + '"'\r
1097 else:\r
1098 IsArray = False\r
1099 Base = 10\r
1100 if PcdValue.upper().startswith('0X'):\r
1101 Base = 16\r
1102 try:\r
1103 Num = int(PcdValue, Base)\r
1104 except:\r
1105 PcdValue = '"' + PcdValue + '"'\r
1106 if IsFieldValueAnArray(PcdValue):\r
656d2539 1107 PcdDatumType = TAB_VOID\r
8565b582
YZ
1108 IsArray = True\r
1109 if not IsArray:\r
1110 return PcdValue\r
1111 try:\r
1112 PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True)\r
5b0671c1 1113 except BadExpression as Value:\r
8565b582
YZ
1114 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %\r
1115 (TokenSpaceGuidCName, TokenCName, PcdValue, Value))\r
1116 return PcdValue\r
1117\r
ae7b6df8
LG
1118 ## Retrieve all PCD settings in platform\r
1119 def _GetPcds(self):\r
4231a819 1120 if self._Pcds is None:\r
a0767bae 1121 self._Pcds = OrderedDict()\r
6f49996c 1122 self.__ParsePcdFromCommandLine()\r
ae7b6df8
LG
1123 self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
1124 self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))\r
1125 self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))\r
1126 self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_DEFAULT))\r
1127 self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_HII))\r
1128 self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_VPD))\r
1129 self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_EX_DEFAULT))\r
1130 self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_EX_HII))\r
1131 self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD))\r
1132\r
8518bf0b 1133 self._Pcds = self.CompletePcdValues(self._Pcds)\r
b854e2bf 1134 self._Pcds = self.OverrideByFdfCommOverAll(self._Pcds)\r
ae7b6df8 1135 self._Pcds = self.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST, self._Pcds)\r
2b8a6c44 1136 self._Pcds = self.CompleteHiiPcdsDefaultStores(self._Pcds)\r
8518bf0b 1137 self._Pcds = self._FilterPcdBySkuUsage(self._Pcds)\r
b854e2bf 1138\r
6f49996c 1139 self.RecoverCommandLinePcd()\r
ae7b6df8
LG
1140 return self._Pcds\r
1141\r
1142 ## Retrieve [BuildOptions]\r
1143 def _GetBuildOptions(self):\r
4231a819 1144 if self._BuildOptions is None:\r
a0767bae 1145 self._BuildOptions = OrderedDict()\r
ae7b6df8
LG
1146 #\r
1147 # Retrieve build option for EDKII and EDK style module\r
1148 #\r
1149 for CodeBase in (EDKII_NAME, EDK_NAME):\r
1150 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, CodeBase]\r
ccaa7754 1151 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4, Dummy5 in RecordList:\r
55c84777 1152 if Dummy3.upper() != TAB_COMMON:\r
c05c2c05 1153 continue\r
ae7b6df8
LG
1154 CurKey = (ToolChainFamily, ToolChain, CodeBase)\r
1155 #\r
1156 # Only flags can be appended\r
1157 #\r
1158 if CurKey not in self._BuildOptions or not ToolChain.endswith('_FLAGS') or Option.startswith('='):\r
1159 self._BuildOptions[CurKey] = Option\r
1160 else:\r
c05c2c05
LG
1161 if ' ' + Option not in self._BuildOptions[CurKey]:\r
1162 self._BuildOptions[CurKey] += ' ' + Option\r
ae7b6df8
LG
1163 return self._BuildOptions\r
1164\r
1165 def GetBuildOptionsByModuleType(self, Edk, ModuleType):\r
4231a819 1166 if self._ModuleTypeOptions is None:\r
a0767bae 1167 self._ModuleTypeOptions = OrderedDict()\r
ae7b6df8 1168 if (Edk, ModuleType) not in self._ModuleTypeOptions:\r
a0767bae 1169 options = OrderedDict()\r
ae7b6df8
LG
1170 self._ModuleTypeOptions[Edk, ModuleType] = options\r
1171 DriverType = '%s.%s' % (Edk, ModuleType)\r
55c84777 1172 CommonDriverType = '%s.%s' % (TAB_COMMON, ModuleType)\r
c05c2c05 1173 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch]\r
ccaa7754 1174 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4, Dummy5 in RecordList:\r
c05c2c05
LG
1175 Type = Dummy2 + '.' + Dummy3\r
1176 if Type.upper() == DriverType.upper() or Type.upper() == CommonDriverType.upper():\r
ae7b6df8
LG
1177 Key = (ToolChainFamily, ToolChain, Edk)\r
1178 if Key not in options or not ToolChain.endswith('_FLAGS') or Option.startswith('='):\r
1179 options[Key] = Option\r
1180 else:\r
c05c2c05
LG
1181 if ' ' + Option not in options[Key]:\r
1182 options[Key] += ' ' + Option\r
ae7b6df8
LG
1183 return self._ModuleTypeOptions[Edk, ModuleType]\r
1184\r
9759febd
CJ
1185 @staticmethod\r
1186 def GetStructurePcdInfo(PcdSet):\r
1187 structure_pcd_data = defaultdict(list)\r
ae7b6df8 1188 for item in PcdSet:\r
ccaa7754 1189 structure_pcd_data[(item[0], item[1])].append(item)\r
ae7b6df8
LG
1190\r
1191 return structure_pcd_data\r
9e508f3a
CJ
1192\r
1193 @staticmethod\r
1194 def OverrideByFdfComm(StruPcds):\r
b854e2bf
B
1195 StructurePcdInCom = OrderedDict()\r
1196 for item in GlobalData.BuildOptionPcd:\r
ccaa7754
GL
1197 if len(item) == 5 and (item[1], item[0]) in StruPcds:\r
1198 StructurePcdInCom[(item[0], item[1], item[2] )] = (item[3], item[4])\r
1199 GlobalPcds = {(item[0], item[1]) for item in StructurePcdInCom}\r
6f49996c 1200 for Pcd in StruPcds.values():\r
ccaa7754 1201 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) not in GlobalPcds:\r
6f49996c 1202 continue\r
b854e2bf
B
1203 FieldValues = OrderedDict()\r
1204 for item in StructurePcdInCom:\r
ccaa7754 1205 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (item[0], item[1]) and item[2]:\r
b854e2bf
B
1206 FieldValues[item[2]] = StructurePcdInCom[item]\r
1207 for field in FieldValues:\r
1208 if field not in Pcd.PcdFieldValueFromComm:\r
ccaa7754 1209 Pcd.PcdFieldValueFromComm[field] = ["", "", ""]\r
b854e2bf
B
1210 Pcd.PcdFieldValueFromComm[field][0] = FieldValues[field][0]\r
1211 Pcd.PcdFieldValueFromComm[field][1] = FieldValues[field][1][0]\r
1212 Pcd.PcdFieldValueFromComm[field][2] = FieldValues[field][1][1]\r
6f49996c 1213 return StruPcds\r
9e508f3a 1214\r
ccaa7754 1215 def OverrideByFdfCommOverAll(self, AllPcds):\r
6f49996c
FB
1216 def CheckStructureInComm(commpcds):\r
1217 if not commpcds:\r
1218 return False\r
1219 if len(commpcds[0]) == 5:\r
1220 return True\r
1221 return False\r
ae7b6df8 1222\r
6f49996c 1223 if CheckStructureInComm(GlobalData.BuildOptionPcd):\r
ccaa7754
GL
1224 StructurePcdInCom = {(item[0], item[1], item[2] ):(item[3], item[4]) for item in GlobalData.BuildOptionPcd } if GlobalData.BuildOptionPcd else {}\r
1225 NoFiledValues = {(item[0], item[1]):StructurePcdInCom[item] for item in StructurePcdInCom if not item[2]}\r
6f49996c 1226 else:\r
ccaa7754
GL
1227 NoFiledValues = {(item[0], item[1]):[item[2]] for item in GlobalData.BuildOptionPcd}\r
1228 for Guid, Name in NoFiledValues:\r
1229 if (Name, Guid) in AllPcds:\r
1230 Pcd = AllPcds.get((Name, Guid))\r
1231 if isinstance(self._DecPcds.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName), None), StructurePcd):\r
1232 self._DecPcds.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName)).PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
b854e2bf 1233 else:\r
ccaa7754
GL
1234 Pcd.PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
1235 Pcd.DefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
b854e2bf
B
1236 for sku in Pcd.SkuInfoList:\r
1237 SkuInfo = Pcd.SkuInfoList[sku]\r
1238 if SkuInfo.DefaultValue:\r
ccaa7754 1239 SkuInfo.DefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
b854e2bf 1240 else:\r
ccaa7754 1241 SkuInfo.HiiDefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
b854e2bf 1242 for defaultstore in SkuInfo.DefaultStoreDict:\r
ccaa7754 1243 SkuInfo.DefaultStoreDict[defaultstore] = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
c8ae65ac 1244 if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII]]:\r
656d2539 1245 if Pcd.DatumType == TAB_VOID:\r
c8ae65ac
YZ
1246 if not Pcd.MaxDatumSize:\r
1247 Pcd.MaxDatumSize = '0'\r
ccaa7754 1248 CurrentSize = int(Pcd.MaxDatumSize, 16) if Pcd.MaxDatumSize.upper().startswith("0X") else int(Pcd.MaxDatumSize)\r
c8ae65ac
YZ
1249 OptionSize = len((StringToArray(Pcd.PcdValueFromComm)).split(","))\r
1250 MaxSize = max(CurrentSize, OptionSize)\r
1251 Pcd.MaxDatumSize = str(MaxSize)\r
6f49996c 1252 else:\r
ccaa7754 1253 PcdInDec = self.DecPcds.get((Name, Guid))\r
6f49996c 1254 if PcdInDec:\r
ccaa7754 1255 PcdInDec.PcdValueFromComm = NoFiledValues[(Guid, Name)][0]\r
6f49996c 1256 if PcdInDec.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
b7bfcd1a
YZ
1257 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE],\r
1258 self._PCD_TYPE_STRING_[MODEL_PCD_FEATURE_FLAG]]:\r
6f49996c 1259 self.Pcds[Name, Guid] = copy.deepcopy(PcdInDec)\r
ccaa7754 1260 self.Pcds[Name, Guid].DefaultValue = NoFiledValues[( Guid, Name)][0]\r
6f49996c 1261 return AllPcds\r
ae7b6df8 1262 def UpdateStructuredPcds(self, TypeList, AllPcds):\r
65eff519
LG
1263\r
1264 DynamicPcdType = [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],\r
1265 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
1266 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_VPD],\r
1267 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],\r
1268 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],\r
1269 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]\r
1270\r
ae7b6df8 1271 Pcds = AllPcds\r
8518bf0b 1272 DefaultStoreMgr = DefaultStore(self.DefaultStores)\r
65eff519 1273 SkuIds = self.SkuIdMgr.AvailableSkuIdSet\r
55c84777 1274 SkuIds.update({TAB_DEFAULT:0})\r
b491aa95 1275 DefaultStores = {storename for pcdobj in AllPcds.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict}\r
ae7b6df8
LG
1276\r
1277 S_PcdSet = []\r
1278 # Find out all possible PCD candidates for self._Arch\r
1279 RecordList = []\r
2b8a6c44 1280\r
ae7b6df8
LG
1281 for Type in TypeList:\r
1282 RecordList.extend(self._RawData[Type, self._Arch])\r
1283\r
ccaa7754 1284 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, default_store, Dummy4, Dummy5 in RecordList:\r
2b8a6c44
LG
1285 SkuName = SkuName.upper()\r
1286 default_store = default_store.upper()\r
55c84777 1287 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
8518bf0b
LG
1288 if SkuName not in SkuIds:\r
1289 continue\r
2b8a6c44 1290\r
8518bf0b 1291 if SkuName in SkuIds and "." in TokenSpaceGuid:\r
ccaa7754 1292 S_PcdSet.append([ TokenSpaceGuid.split(".")[0], TokenSpaceGuid.split(".")[1], PcdCName, SkuName, default_store, Dummy5, AnalyzePcdExpression(Setting)[0]])\r
ae7b6df8
LG
1293\r
1294 # handle pcd value override\r
9759febd 1295 StrPcdSet = DscBuildData.GetStructurePcdInfo(S_PcdSet)\r
79820e32 1296 S_pcd_set = OrderedDict()\r
ae7b6df8 1297 for str_pcd in StrPcdSet:\r
8518bf0b
LG
1298 str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)\r
1299 str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)\r
5db9414c
B
1300 if not isinstance (str_pcd_dec, StructurePcd):\r
1301 EdkLogger.error('build', PARSER_ERROR,\r
1302 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),\r
ccaa7754 1303 File=self.MetaFile, Line = StrPcdSet[str_pcd][0][5])\r
ae7b6df8
LG
1304 if str_pcd_dec:\r
1305 str_pcd_obj_str = StructurePcd()\r
1306 str_pcd_obj_str.copy(str_pcd_dec)\r
1307 if str_pcd_obj:\r
1308 str_pcd_obj_str.copy(str_pcd_obj)\r
f832bb34
FB
1309 if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
1310 str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}\r
1311 else:\r
1312 str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}\r
ae7b6df8 1313 for str_pcd_data in StrPcdSet[str_pcd]:\r
8518bf0b 1314 if str_pcd_data[3] in SkuIds:\r
ccaa7754 1315 str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), TAB_DEFAULT if str_pcd_data[3] == TAB_COMMON else str_pcd_data[3], TAB_DEFAULT_STORES_DEFAULT if str_pcd_data[4] == TAB_COMMON else str_pcd_data[4], self.MetaFile.File if self.WorkspaceDir not in self.MetaFile.File else self.MetaFile.File[len(self.WorkspaceDir) if self.WorkspaceDir.endswith(os.path.sep) else len(self.WorkspaceDir)+1:], LineNo=str_pcd_data[5])\r
8518bf0b 1316 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str\r
2b8a6c44
LG
1317 else:\r
1318 EdkLogger.error('build', PARSER_ERROR,\r
1319 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),\r
ccaa7754 1320 File=self.MetaFile, Line = StrPcdSet[str_pcd][0][5])\r
ae7b6df8 1321 # Add the Structure PCD that only defined in DEC, don't have override in DSC file\r
5644e5ce 1322 for Pcd in self.DecPcds:\r
0d1f5b2b 1323 if isinstance(self._DecPcds[Pcd], StructurePcd):\r
ae7b6df8
LG
1324 if Pcd not in S_pcd_set:\r
1325 str_pcd_obj_str = StructurePcd()\r
1326 str_pcd_obj_str.copy(self._DecPcds[Pcd])\r
1327 str_pcd_obj = Pcds.get(Pcd, None)\r
1328 if str_pcd_obj:\r
1329 str_pcd_obj_str.copy(str_pcd_obj)\r
77204d60
FB
1330 if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
1331 str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}\r
1332 else:\r
1333 str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}\r
ae7b6df8
LG
1334 S_pcd_set[Pcd] = str_pcd_obj_str\r
1335 if S_pcd_set:\r
1336 GlobalData.gStructurePcd[self.Arch] = S_pcd_set\r
8518bf0b 1337 for stru_pcd in S_pcd_set.values():\r
67e63e9a
LG
1338 for skuid in SkuIds:\r
1339 if skuid in stru_pcd.SkuOverrideValues:\r
1340 continue\r
1341 nextskuid = self.SkuIdMgr.GetNextSkuId(skuid)\r
1342 NoDefault = False\r
f3b31433
FB
1343 if skuid not in stru_pcd.SkuOverrideValues:\r
1344 while nextskuid not in stru_pcd.SkuOverrideValues:\r
55c84777 1345 if nextskuid == TAB_DEFAULT:\r
f3b31433
FB
1346 NoDefault = True\r
1347 break\r
1348 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
4d3b9389 1349 stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores} if DefaultStores else {TAB_DEFAULT_STORES_DEFAULT:stru_pcd.DefaultValues})\r
f3b31433 1350 if not NoDefault:\r
ccaa7754 1351 stru_pcd.ValueChain.add((skuid, ''))\r
8518bf0b
LG
1352 if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
1353 for skuid in SkuIds:\r
1354 nextskuid = skuid\r
2b8a6c44 1355 NoDefault = False\r
8518bf0b
LG
1356 if skuid not in stru_pcd.SkuOverrideValues:\r
1357 while nextskuid not in stru_pcd.SkuOverrideValues:\r
55c84777 1358 if nextskuid == TAB_DEFAULT:\r
2b8a6c44
LG
1359 NoDefault = True\r
1360 break\r
8518bf0b 1361 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
2b8a6c44
LG
1362 if NoDefault:\r
1363 continue\r
c5c7e68a 1364 PcdDefaultStoreSet = set(defaultstorename for defaultstorename in stru_pcd.SkuOverrideValues[nextskuid])\r
8518bf0b 1365 mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)\r
2b8a6c44 1366\r
8518bf0b
LG
1367 for defaultstoreid in DefaultStores:\r
1368 if defaultstoreid not in stru_pcd.SkuOverrideValues[skuid]:\r
2b8a6c44 1369 stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename])\r
ccaa7754 1370 stru_pcd.ValueChain.add((skuid, defaultstoreid))\r
9e508f3a 1371 S_pcd_set = DscBuildData.OverrideByFdfComm(S_pcd_set)\r
ae7b6df8
LG
1372 Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set)\r
1373 if Str_Pcd_Values:\r
ccaa7754 1374 for (skuname, StoreName, PcdGuid, PcdName, PcdValue) in Str_Pcd_Values:\r
8518bf0b 1375 str_pcd_obj = S_pcd_set.get((PcdName, PcdGuid))\r
ae7b6df8 1376 if str_pcd_obj is None:\r
72443dd2 1377 print(PcdName, PcdGuid)\r
ae7b6df8
LG
1378 raise\r
1379 if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
1380 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
8518bf0b
LG
1381 if skuname not in str_pcd_obj.SkuInfoList:\r
1382 str_pcd_obj.SkuInfoList[skuname] = SkuInfoClass(SkuIdName=skuname, SkuId=self.SkuIds[skuname][0], HiiDefaultValue=PcdValue, DefaultStore = {StoreName:PcdValue})\r
ae7b6df8 1383 else:\r
8518bf0b
LG
1384 str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue = PcdValue\r
1385 str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.update({StoreName:PcdValue})\r
ae7b6df8
LG
1386 elif str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
1387 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
55c84777 1388 if skuname in (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT, TAB_COMMON):\r
8518bf0b 1389 str_pcd_obj.DefaultValue = PcdValue\r
ae7b6df8 1390 else:\r
8518bf0b 1391 if skuname not in str_pcd_obj.SkuInfoList:\r
65eff519
LG
1392 nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)\r
1393 NoDefault = False\r
1394 while nextskuid not in str_pcd_obj.SkuInfoList:\r
55c84777 1395 if nextskuid == TAB_DEFAULT:\r
65eff519
LG
1396 NoDefault = True\r
1397 break\r
1398 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
1399 str_pcd_obj.SkuInfoList[skuname] = copy.deepcopy(str_pcd_obj.SkuInfoList[nextskuid]) if not NoDefault else SkuInfoClass(SkuIdName=skuname, SkuId=self.SkuIds[skuname][0], DefaultValue=PcdValue)\r
1400 str_pcd_obj.SkuInfoList[skuname].SkuId = self.SkuIds[skuname][0]\r
1401 str_pcd_obj.SkuInfoList[skuname].SkuIdName = skuname\r
ae7b6df8 1402 else:\r
8518bf0b
LG
1403 str_pcd_obj.SkuInfoList[skuname].DefaultValue = PcdValue\r
1404 for str_pcd_obj in S_pcd_set.values():\r
1405 if str_pcd_obj.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
1406 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
1407 continue\r
c5c7e68a 1408 PcdDefaultStoreSet = set(defaultstorename for skuobj in str_pcd_obj.SkuInfoList.values() for defaultstorename in skuobj.DefaultStoreDict)\r
8518bf0b
LG
1409 DefaultStoreObj = DefaultStore(self._GetDefaultStores())\r
1410 mindefaultstorename = DefaultStoreObj.GetMin(PcdDefaultStoreSet)\r
1411 str_pcd_obj.SkuInfoList[self.SkuIdMgr.SystemSkuId].HiiDefaultValue = str_pcd_obj.SkuInfoList[self.SkuIdMgr.SystemSkuId].DefaultStoreDict[mindefaultstorename]\r
ae7b6df8
LG
1412\r
1413 for str_pcd_obj in S_pcd_set.values():\r
2b8a6c44 1414\r
ae7b6df8
LG
1415 str_pcd_obj.MaxDatumSize = self.GetStructurePcdMaxSize(str_pcd_obj)\r
1416 Pcds[str_pcd_obj.TokenCName, str_pcd_obj.TokenSpaceGuidCName] = str_pcd_obj\r
1417\r
65eff519
LG
1418 for pcdkey in Pcds:\r
1419 pcd = Pcds[pcdkey]\r
55c84777
CJ
1420 if TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
1421 pcd.SkuInfoList[TAB_DEFAULT] = pcd.SkuInfoList[TAB_COMMON]\r
1422 del pcd.SkuInfoList[TAB_COMMON]\r
1423 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
1424 del pcd.SkuInfoList[TAB_COMMON]\r
65eff519 1425\r
ccaa7754 1426 map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])\r
ae7b6df8
LG
1427 return Pcds\r
1428\r
1429 ## Retrieve non-dynamic PCD settings\r
1430 #\r
1431 # @param Type PCD type\r
1432 #\r
1433 # @retval a dict object contains settings of given PCD type\r
1434 #\r
1435 def _GetPcd(self, Type):\r
a0767bae 1436 Pcds = OrderedDict()\r
ae7b6df8
LG
1437 #\r
1438 # tdict is a special dict kind of type, used for selecting correct\r
1439 # PCD settings for certain ARCH\r
1440 #\r
2b8a6c44 1441 AvailableSkuIdSet = copy.copy(self.SkuIds)\r
ae7b6df8
LG
1442\r
1443 PcdDict = tdict(True, 3)\r
1444 PcdSet = set()\r
1445 # Find out all possible PCD candidates for self._Arch\r
1446 RecordList = self._RawData[Type, self._Arch]\r
a0767bae 1447 PcdValueDict = OrderedDict()\r
ccaa7754 1448 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4, Dummy5 in RecordList:\r
2b8a6c44 1449 SkuName = SkuName.upper()\r
55c84777 1450 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
2b8a6c44
LG
1451 if SkuName not in AvailableSkuIdSet:\r
1452 EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
1453 File=self.MetaFile, Line=Dummy5)\r
55c84777 1454 if SkuName in (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT, TAB_COMMON):\r
8518bf0b 1455 if "." not in TokenSpaceGuid:\r
5db9414c 1456 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5))\r
ae7b6df8 1457 PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting\r
ae7b6df8
LG
1458\r
1459 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet:\r
1460 Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName]\r
4231a819 1461 if Setting is None:\r
ae7b6df8
LG
1462 continue\r
1463 PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
1464 if (PcdCName, TokenSpaceGuid) in PcdValueDict:\r
1465 PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue, DatumType, MaxDatumSize)\r
1466 else:\r
1467 PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, DatumType, MaxDatumSize)}\r
1468\r
ccaa7754 1469 for ((PcdCName, TokenSpaceGuid), PcdSetting) in PcdValueDict.iteritems():\r
ae7b6df8
LG
1470 PcdValue = None\r
1471 DatumType = None\r
1472 MaxDatumSize = None\r
55c84777
CJ
1473 if TAB_COMMON in PcdSetting:\r
1474 PcdValue, DatumType, MaxDatumSize = PcdSetting[TAB_COMMON]\r
1475 if TAB_DEFAULT in PcdSetting:\r
1476 PcdValue, DatumType, MaxDatumSize = PcdSetting[TAB_DEFAULT]\r
8518bf0b
LG
1477 if self.SkuIdMgr.SystemSkuId in PcdSetting:\r
1478 PcdValue, DatumType, MaxDatumSize = PcdSetting[self.SkuIdMgr.SystemSkuId]\r
ae7b6df8
LG
1479\r
1480 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
1481 PcdCName,\r
1482 TokenSpaceGuid,\r
1483 self._PCD_TYPE_STRING_[Type],\r
1484 DatumType,\r
1485 PcdValue,\r
1486 '',\r
1487 MaxDatumSize,\r
1488 {},\r
1489 False,\r
1490 None,\r
1491 IsDsc=True)\r
1492\r
1493\r
1494 return Pcds\r
1495\r
1496 def GetStructurePcdMaxSize(self, str_pcd):\r
1497 pcd_default_value = str_pcd.DefaultValue\r
1498 sku_values = [skuobj.HiiDefaultValue if str_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]] else skuobj.DefaultValue for skuobj in str_pcd.SkuInfoList.values()]\r
1499 sku_values.append(pcd_default_value)\r
1500\r
1501 def get_length(value):\r
1502 Value = value.strip()\r
a0939593 1503 if len(value) > 1:\r
91fa33ee 1504 if Value.startswith(TAB_GUID) and Value.endswith(')'):\r
a0939593
LG
1505 return 16\r
1506 if Value.startswith('L"') and Value.endswith('"'):\r
1507 return len(Value[2:-1])\r
1508 if Value[0] == '"' and Value[-1] == '"':\r
1509 return len(Value) - 2\r
1510 if Value[0] == '{' and Value[-1] == '}':\r
1511 return len(Value.split(","))\r
1512 if Value.startswith("L'") and Value.endswith("'") and len(list(Value[2:-1])) > 1:\r
1513 return len(list(Value[2:-1]))\r
1514 if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1:\r
1515 return len(Value) - 2\r
ae7b6df8
LG
1516 return len(Value)\r
1517\r
8252e6bf 1518 return str(max(get_length(item) for item in sku_values))\r
ae7b6df8 1519\r
9e508f3a
CJ
1520 @staticmethod\r
1521 def ExecuteCommand (Command):\r
ae7b6df8
LG
1522 try:\r
1523 Process = subprocess.Popen(Command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\r
1524 except:\r
5db9414c 1525 EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % Command)\r
ae7b6df8 1526 Result = Process.communicate()\r
5db9414c 1527 return Process.returncode, Result[0], Result[1]\r
ae7b6df8 1528\r
9e508f3a
CJ
1529 @staticmethod\r
1530 def IntToCString(Value, ValueSize):\r
ae7b6df8
LG
1531 Result = '"'\r
1532 if not isinstance (Value, str):\r
1533 for Index in range(0, ValueSize):\r
1534 Result = Result + '\\x%02x' % (Value & 0xff)\r
1535 Value = Value >> 8\r
1536 Result = Result + '"'\r
1537 return Result\r
1538\r
ccaa7754 1539 def GenerateSizeFunction(self, Pcd):\r
79820e32
B
1540 CApp = "// Default Value in Dec \n"\r
1541 CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1542 for FieldList in [Pcd.DefaultValues]:\r
1543 if not FieldList:\r
1544 continue\r
1545 for FieldName in FieldList:\r
1546 FieldName = "." + FieldName\r
8565b582 1547 IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
79820e32
B
1548 if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):\r
1549 try:\r
656d2539 1550 Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], TAB_VOID, self._GuidDict)(True)\r
79820e32
B
1551 except BadExpression:\r
1552 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1553 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))\r
1554 Value, ValueSize = ParseFieldValue(Value)\r
1555 CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
1556 else:\r
1557 NewFieldName = ''\r
1558 FieldName_ori = FieldName.strip('.')\r
1559 while '[' in FieldName:\r
1560 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
1561 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
1562 FieldName = FieldName.split(']', 1)[1]\r
1563 FieldName = NewFieldName + FieldName\r
1564 while '[' in FieldName:\r
1565 FieldName = FieldName.rsplit('[', 1)[0]\r
1566 CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])\r
1567 for skuname in Pcd.SkuOverrideValues:\r
55c84777 1568 if skuname == TAB_COMMON:\r
79820e32
B
1569 continue\r
1570 for defaultstorenameitem in Pcd.SkuOverrideValues[skuname]:\r
1571 CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)\r
1572 for FieldList in [Pcd.SkuOverrideValues[skuname].get(defaultstorenameitem)]:\r
1573 if not FieldList:\r
1574 continue\r
1575 for FieldName in FieldList:\r
1576 FieldName = "." + FieldName\r
8565b582 1577 IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
79820e32
B
1578 if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):\r
1579 try:\r
656d2539 1580 Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], TAB_VOID, self._GuidDict)(True)\r
79820e32
B
1581 except BadExpression:\r
1582 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1583 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))\r
1584 Value, ValueSize = ParseFieldValue(Value)\r
1585 CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
1586 else:\r
1587 NewFieldName = ''\r
1588 FieldName_ori = FieldName.strip('.')\r
1589 while '[' in FieldName:\r
1590 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
1591 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
1592 FieldName = FieldName.split(']', 1)[1]\r
1593 FieldName = NewFieldName + FieldName\r
1594 while '[' in FieldName:\r
1595 FieldName = FieldName.rsplit('[', 1)[0]\r
1596 CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])\r
b854e2bf
B
1597 if Pcd.PcdFieldValueFromComm:\r
1598 CApp = CApp + "// From Command Line \n"\r
1599 for FieldName in Pcd.PcdFieldValueFromComm:\r
1600 FieldName = "." + FieldName\r
8565b582 1601 IsArray = IsFieldValueAnArray(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0])\r
1667eec6 1602 if IsArray and not (Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].startswith('{GUID') and Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].endswith('}')):\r
b854e2bf 1603 try:\r
656d2539 1604 Value = ValueExpressionEx(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0], TAB_VOID, self._GuidDict)(True)\r
b854e2bf
B
1605 except BadExpression:\r
1606 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1667eec6 1607 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2]))\r
b854e2bf 1608 Value, ValueSize = ParseFieldValue(Value)\r
1667eec6 1609 CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0]);\r
b854e2bf
B
1610 else:\r
1611 NewFieldName = ''\r
1612 FieldName_ori = FieldName.strip('.')\r
1613 while '[' in FieldName:\r
1614 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
1615 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
1616 FieldName = FieldName.split(']', 1)[1]\r
1617 FieldName = NewFieldName + FieldName\r
1618 while '[' in FieldName:\r
1619 FieldName = FieldName.rsplit('[', 1)[0]\r
1667eec6 1620 CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValueFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0])\r
ccaa7754 1621 CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize())\r
79820e32
B
1622 CApp = CApp + "}\n"\r
1623 return CApp\r
9e508f3a
CJ
1624\r
1625 @staticmethod\r
1626 def GenerateSizeStatments(Pcd):\r
79820e32
B
1627 CApp = ' Size = sizeof(%s);\n' % (Pcd.DatumType)\r
1628 CApp = CApp + ' Cal_%s_%s_Size(&Size);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1629 return CApp\r
9e508f3a 1630\r
ccaa7754 1631 def GenerateDefaultValueAssignFunction(self, Pcd):\r
79820e32 1632 CApp = "// Default value in Dec \n"\r
ccaa7754 1633 CApp = CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumType)\r
79820e32
B
1634 CApp = CApp + ' UINT32 FieldSize;\n'\r
1635 CApp = CApp + ' CHAR8 *Value;\n'\r
1636 DefaultValueFromDec = Pcd.DefaultValueFromDec\r
8565b582 1637 IsArray = IsFieldValueAnArray(Pcd.DefaultValueFromDec)\r
79820e32
B
1638 if IsArray:\r
1639 try:\r
656d2539 1640 DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, TAB_VOID)(True)\r
79820e32
B
1641 except BadExpression:\r
1642 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" %\r
1643 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))\r
0f228f19 1644 DefaultValueFromDec = StringToArray(DefaultValueFromDec)\r
79820e32
B
1645 Value, ValueSize = ParseFieldValue (DefaultValueFromDec)\r
1646 if isinstance(Value, str):\r
1647 CApp = CApp + ' Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)\r
1648 elif IsArray:\r
1649 #\r
1650 # Use memcpy() to copy value into field\r
1651 #\r
9e508f3a 1652 CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)\r
79820e32
B
1653 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
1654 for FieldList in [Pcd.DefaultValues]:\r
1655 if not FieldList:\r
1656 continue\r
1657 for FieldName in FieldList:\r
8565b582 1658 IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
79820e32
B
1659 if IsArray:\r
1660 try:\r
656d2539 1661 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
79820e32
B
1662 except BadExpression:\r
1663 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
ccaa7754 1664 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
79820e32
B
1665\r
1666 try:\r
1667 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
1668 except Exception:\r
ccaa7754 1669 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
79820e32
B
1670 if isinstance(Value, str):\r
1671 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1672 elif IsArray:\r
1673 #\r
1674 # Use memcpy() to copy value into field\r
1675 #\r
1676 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
9e508f3a 1677 CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
79820e32
B
1678 CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
1679 else:\r
1680 if ValueSize > 4:\r
1681 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1682 else:\r
1683 CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
f3b31433
FB
1684 CApp = CApp + "}\n"\r
1685 return CApp\r
9e508f3a
CJ
1686\r
1687 @staticmethod\r
1688 def GenerateDefaultValueAssignStatement(Pcd):\r
f3b31433
FB
1689 CApp = ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1690 return CApp\r
9e508f3a 1691\r
ccaa7754
GL
1692 def GenerateInitValueFunction(self, Pcd, SkuName, DefaultStoreName):\r
1693 CApp = "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName, DefaultStoreName)\r
1694 CApp = CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, SkuName, DefaultStoreName, Pcd.DatumType)\r
f3b31433
FB
1695 CApp = CApp + ' UINT32 FieldSize;\n'\r
1696 CApp = CApp + ' CHAR8 *Value;\n'\r
1697\r
55c84777 1698 CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT)\r
f3b31433 1699 inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName]\r
ccaa7754
GL
1700 if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT):\r
1701 pcddefaultvalue = Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue\r
f3b31433 1702 else:\r
f832bb34
FB
1703 if not Pcd.DscRawValue:\r
1704 # handle the case that structure pcd is not appear in DSC\r
1705 self.CopyDscRawValue(Pcd)\r
ccaa7754
GL
1706 pcddefaultvalue = Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName)\r
1707 for FieldList in [pcddefaultvalue, inherit_OverrideValues.get(DefaultStoreName)]:\r
79820e32
B
1708 if not FieldList:\r
1709 continue\r
1710 if pcddefaultvalue and FieldList == pcddefaultvalue:\r
8565b582 1711 IsArray = IsFieldValueAnArray(FieldList)\r
79820e32
B
1712 if IsArray:\r
1713 try:\r
656d2539 1714 FieldList = ValueExpressionEx(FieldList, TAB_VOID)(True)\r
79820e32
B
1715 except BadExpression:\r
1716 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" %\r
1717 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))\r
1718 Value, ValueSize = ParseFieldValue (FieldList)\r
f3b31433 1719\r
ccaa7754 1720 if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT):\r
f3b31433 1721 if isinstance(Value, str):\r
ccaa7754 1722 CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)\r
f3b31433
FB
1723 elif IsArray:\r
1724 #\r
1725 # Use memcpy() to copy value into field\r
1726 #\r
ccaa7754 1727 CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)\r
f3b31433
FB
1728 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
1729 else:\r
1730 if isinstance(Value, str):\r
ccaa7754 1731 CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName))\r
f3b31433
FB
1732 elif IsArray:\r
1733 #\r
1734 # Use memcpy() to copy value into field\r
1735 #\r
ccaa7754 1736 CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName))\r
f3b31433 1737 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
79820e32 1738 continue\r
ccaa7754 1739 if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT) or (( (SkuName, '') not in Pcd.ValueChain) and ( (SkuName, DefaultStoreName) not in Pcd.ValueChain )):\r
f3b31433 1740 for FieldName in FieldList:\r
8565b582 1741 IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
f3b31433
FB
1742 if IsArray:\r
1743 try:\r
656d2539 1744 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
f3b31433
FB
1745 except BadExpression:\r
1746 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1747 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
79820e32 1748 try:\r
f3b31433
FB
1749 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
1750 except Exception:\r
ccaa7754 1751 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
f3b31433
FB
1752 if isinstance(Value, str):\r
1753 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1754 elif IsArray:\r
1755 #\r
1756 # Use memcpy() to copy value into field\r
1757 #\r
1758 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
9e508f3a 1759 CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
f3b31433 1760 CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
79820e32 1761 else:\r
f3b31433
FB
1762 if ValueSize > 4:\r
1763 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1764 else:\r
1765 CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
79820e32
B
1766 CApp = CApp + "}\n"\r
1767 return CApp\r
9e508f3a
CJ
1768\r
1769 @staticmethod\r
ccaa7754
GL
1770 def GenerateInitValueStatement(Pcd, SkuName, DefaultStoreName):\r
1771 CApp = ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, SkuName, DefaultStoreName)\r
79820e32 1772 return CApp\r
9e508f3a 1773\r
ccaa7754 1774 def GenerateCommandLineValue(self, Pcd):\r
b854e2bf 1775 CApp = "// Value in CommandLine\n"\r
ccaa7754 1776 CApp = CApp + "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumType)\r
b854e2bf
B
1777 CApp = CApp + ' UINT32 FieldSize;\n'\r
1778 CApp = CApp + ' CHAR8 *Value;\n'\r
1779\r
1780 pcddefaultvalue = Pcd.PcdValueFromComm\r
ccaa7754 1781 for FieldList in [pcddefaultvalue, Pcd.PcdFieldValueFromComm]:\r
b854e2bf
B
1782 if not FieldList:\r
1783 continue\r
1784 if pcddefaultvalue and FieldList == pcddefaultvalue:\r
8565b582 1785 IsArray = IsFieldValueAnArray(FieldList)\r
b854e2bf
B
1786 if IsArray:\r
1787 try:\r
656d2539 1788 FieldList = ValueExpressionEx(FieldList, TAB_VOID)(True)\r
b854e2bf 1789 except BadExpression:\r
0f228f19 1790 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from Command: %s" %\r
b854e2bf
B
1791 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))\r
1792 Value, ValueSize = ParseFieldValue (FieldList)\r
1793\r
1794 if isinstance(Value, str):\r
1795 CApp = CApp + ' Pcd = %s; // From Command Line \n' % (Value)\r
1796 elif IsArray:\r
1797 #\r
1798 # Use memcpy() to copy value into field\r
1799 #\r
9e508f3a 1800 CApp = CApp + ' Value = %s; // From Command Line.\n' % (DscBuildData.IntToCString(Value, ValueSize))\r
b854e2bf
B
1801 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
1802 continue\r
1803 for FieldName in FieldList:\r
8565b582 1804 IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
b854e2bf
B
1805 if IsArray:\r
1806 try:\r
656d2539 1807 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
b854e2bf
B
1808 except BadExpression:\r
1809 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1810 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
1811 except:\r
72443dd2 1812 print("error")\r
b854e2bf
B
1813 try:\r
1814 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
1815 except Exception:\r
ccaa7754 1816 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
b854e2bf
B
1817 if isinstance(Value, str):\r
1818 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1819 elif IsArray:\r
1820 #\r
1821 # Use memcpy() to copy value into field\r
1822 #\r
1823 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
9e508f3a 1824 CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
b854e2bf
B
1825 CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
1826 else:\r
1827 if ValueSize > 4:\r
1828 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1829 else:\r
1830 CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1831 CApp = CApp + "}\n"\r
1832 return CApp\r
9e508f3a
CJ
1833\r
1834 @staticmethod\r
1835 def GenerateCommandLineValueStatement(Pcd):\r
b854e2bf
B
1836 CApp = ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1837 return CApp\r
9e508f3a 1838\r
f3b31433
FB
1839 def GenerateInitializeFunc(self, SkuName, DefaultStore, Pcd, InitByteValue, CApp):\r
1840 OverrideValues = {DefaultStore:""}\r
ae7b6df8
LG
1841 if Pcd.SkuOverrideValues:\r
1842 OverrideValues = Pcd.SkuOverrideValues[SkuName]\r
5a693b89 1843 for DefaultStoreName in OverrideValues:\r
8518bf0b
LG
1844 CApp = CApp + 'void\n'\r
1845 CApp = CApp + 'Initialize_%s_%s_%s_%s(\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1846 CApp = CApp + ' void\n'\r
1847 CApp = CApp + ' )\n'\r
1848 CApp = CApp + '{\n'\r
1849 CApp = CApp + ' UINT32 Size;\n'\r
1850 CApp = CApp + ' UINT32 FieldSize;\n'\r
b2395724 1851 CApp = CApp + ' CHAR8 *Value;\n'\r
8518bf0b
LG
1852 CApp = CApp + ' UINT32 OriginalSize;\n'\r
1853 CApp = CApp + ' VOID *OriginalPcd;\n'\r
6a103440 1854 CApp = CApp + ' %s *Pcd; // From %s Line %d \n' % (Pcd.DatumType, Pcd.PkgPath, Pcd.PcdDefineLineNo)\r
8518bf0b 1855 CApp = CApp + '\n'\r
47854fd5 1856\r
8e011d83 1857 if SkuName in Pcd.SkuInfoList:\r
ccaa7754 1858 DefaultValue = Pcd.SkuInfoList[SkuName].DefaultStoreDict.get(DefaultStoreName, Pcd.SkuInfoList[SkuName].HiiDefaultValue if Pcd.SkuInfoList[SkuName].HiiDefaultValue else Pcd.SkuInfoList[SkuName].DefaultValue)\r
8e011d83
FB
1859 else:\r
1860 DefaultValue = Pcd.DefaultValue\r
1861 PcdDefaultValue = StringToArray(DefaultValue.strip())\r
47854fd5 1862\r
8518bf0b 1863 InitByteValue += '%s.%s.%s.%s|%s|%s\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumType, PcdDefaultValue)\r
ae7b6df8 1864\r
8518bf0b
LG
1865 #\r
1866 # Get current PCD value and size\r
1867 #\r
1868 CApp = CApp + ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
ae7b6df8 1869\r
8518bf0b
LG
1870 #\r
1871 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides\r
1872 # the correct value. For structures with a flexible array member, the flexible\r
1873 # array member is detected, and the size is based on the highest index used with\r
1874 # the flexible array member. The flexible array member must be the last field\r
1875 # in a structure. The size formula for this case is:\r
1876 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)\r
1877 #\r
9e508f3a 1878 CApp = CApp + DscBuildData.GenerateSizeStatments(Pcd)\r
ae7b6df8 1879\r
8518bf0b
LG
1880 #\r
1881 # Allocate and zero buffer for the PCD\r
1882 # Must handle cases where current value is smaller, larger, or same size\r
1883 # Always keep that larger one as the current size\r
1884 #\r
1885 CApp = CApp + ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'\r
1886 CApp = CApp + ' Pcd = (%s *)malloc (Size);\n' % (Pcd.DatumType)\r
1887 CApp = CApp + ' memset (Pcd, 0, Size);\n'\r
ae7b6df8 1888\r
8518bf0b
LG
1889 #\r
1890 # Copy current PCD value into allocated buffer.\r
1891 #\r
1892 CApp = CApp + ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'\r
ae7b6df8 1893\r
8518bf0b
LG
1894 #\r
1895 # Assign field values in PCD\r
1896 #\r
9e508f3a 1897 CApp = CApp + DscBuildData.GenerateDefaultValueAssignStatement(Pcd)\r
f3b31433
FB
1898 if Pcd.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
1899 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
1900 for skuname in self.SkuIdMgr.GetSkuChain(SkuName):\r
4d3b9389 1901 storeset = [DefaultStoreName] if DefaultStoreName == TAB_DEFAULT_STORES_DEFAULT else [TAB_DEFAULT_STORES_DEFAULT, DefaultStoreName]\r
f3b31433
FB
1902 for defaultstorenameitem in storeset:\r
1903 CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)\r
ccaa7754 1904 CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd, skuname, defaultstorenameitem)\r
f3b31433
FB
1905 if skuname == SkuName:\r
1906 break\r
1907 else:\r
f832bb34 1908 CApp = CApp + "// SkuName: %s, DefaultStoreName: STANDARD \n" % self.SkuIdMgr.SystemSkuId\r
ccaa7754 1909 CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd, self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)\r
9e508f3a 1910 CApp = CApp + DscBuildData.GenerateCommandLineValueStatement(Pcd)\r
8518bf0b
LG
1911 #\r
1912 # Set new PCD value and size\r
1913 #\r
1914 CApp = CApp + ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
ae7b6df8 1915\r
8518bf0b
LG
1916 #\r
1917 # Free PCD\r
1918 #\r
1919 CApp = CApp + ' free (Pcd);\n'\r
1920 CApp = CApp + '}\n'\r
1921 CApp = CApp + '\n'\r
ae7b6df8
LG
1922 return InitByteValue, CApp\r
1923\r
1924 def GenerateByteArrayValue (self, StructuredPcds):\r
1925 #\r
1926 # Generate/Compile/Run C application to determine if there are any flexible array members\r
1927 #\r
1928 if not StructuredPcds:\r
1929 return\r
1930\r
1931 InitByteValue = ""\r
1932 CApp = PcdMainCHeader\r
1933\r
34d808ad 1934 IncludeFiles = set()\r
ae7b6df8
LG
1935 for PcdName in StructuredPcds:\r
1936 Pcd = StructuredPcds[PcdName]\r
81add864 1937 for IncludeFile in Pcd.StructuredPcdIncludeFile:\r
1d5fde83 1938 if IncludeFile not in IncludeFiles:\r
34d808ad 1939 IncludeFiles.add(IncludeFile)\r
81add864 1940 CApp = CApp + '#include <%s>\n' % (IncludeFile)\r
ae7b6df8 1941 CApp = CApp + '\n'\r
ae7b6df8
LG
1942 for PcdName in StructuredPcds:\r
1943 Pcd = StructuredPcds[PcdName]\r
79820e32
B
1944 CApp = CApp + self.GenerateSizeFunction(Pcd)\r
1945 CApp = CApp + self.GenerateDefaultValueAssignFunction(Pcd)\r
b854e2bf 1946 CApp = CApp + self.GenerateCommandLineValue(Pcd)\r
f3b31433
FB
1947 if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
1948 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
ccaa7754 1949 CApp = CApp + self.GenerateInitValueFunction(Pcd, self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)\r
f3b31433
FB
1950 else:\r
1951 for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
1952 if SkuName not in Pcd.SkuOverrideValues:\r
1953 continue\r
1954 for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:\r
ccaa7754 1955 CApp = CApp + self.GenerateInitValueFunction(Pcd, SkuName, DefaultStoreName)\r
0a57a978
FB
1956 if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
1957 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
4d3b9389 1958 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd, InitByteValue, CApp)\r
ae7b6df8 1959 else:\r
c05c2c05
LG
1960 for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
1961 if SkuName not in Pcd.SkuOverrideValues:\r
1962 continue\r
ae7b6df8
LG
1963 for DefaultStoreName in Pcd.DefaultStoreName:\r
1964 Pcd = StructuredPcds[PcdName]\r
1965 InitByteValue, CApp = self.GenerateInitializeFunc(SkuName, DefaultStoreName, Pcd, InitByteValue, CApp)\r
1966\r
1967 CApp = CApp + 'VOID\n'\r
1968 CApp = CApp + 'PcdEntryPoint(\n'\r
1969 CApp = CApp + ' VOID\n'\r
1970 CApp = CApp + ' )\n'\r
1971 CApp = CApp + '{\n'\r
1972 for Pcd in StructuredPcds.values():\r
ccaa7754 1973 if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
4d3b9389 1974 CApp = CApp + ' Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
ae7b6df8 1975 else:\r
c05c2c05
LG
1976 for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
1977 if SkuName not in Pcd.SkuOverrideValues:\r
1978 continue\r
8518bf0b 1979 for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:\r
ae7b6df8
LG
1980 CApp = CApp + ' Initialize_%s_%s_%s_%s();\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1981 CApp = CApp + '}\n'\r
1982\r
1983 CApp = CApp + PcdMainCEntry + '\n'\r
1984\r
1985 if not os.path.exists(self.OutputPath):\r
1986 os.makedirs(self.OutputPath)\r
1987 CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)\r
0a57a978 1988 SaveFileOnChange(CAppBaseFileName + '.c', CApp, False)\r
ae7b6df8
LG
1989\r
1990 MakeApp = PcdMakefileHeader\r
1991 if sys.platform == "win32":\r
0a57a978 1992 MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\%s.obj\n' % (self.OutputPath, PcdValueInitName) + 'INC = '\r
ae7b6df8
LG
1993 else:\r
1994 MakeApp = MakeApp + PcdGccMakefile\r
1995 MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o\n' % (self.OutputPath, PcdValueInitName) + \\r
68ba919f 1996 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='\r
ae7b6df8 1997\r
34d808ad 1998 IncSearchList = []\r
ae7b6df8
LG
1999 PlatformInc = {}\r
2000 for Cache in self._Bdb._CACHE_.values():\r
2001 if Cache.MetaFile.Ext.lower() != '.dec':\r
2002 continue\r
2003 if Cache.Includes:\r
2004 if str(Cache.MetaFile.Path) not in PlatformInc:\r
b005802a
LG
2005 PlatformInc[str(Cache.MetaFile.Path)] = []\r
2006 PlatformInc[str(Cache.MetaFile.Path)].append (os.path.dirname(Cache.MetaFile.Path))\r
2007 PlatformInc[str(Cache.MetaFile.Path)].extend (Cache.CommonIncludes)\r
ae7b6df8
LG
2008\r
2009 PcdDependDEC = []\r
2010 for Pcd in StructuredPcds.values():\r
2011 for PackageDec in Pcd.PackageDecs:\r
2012 Package = os.path.normpath(mws.join(GlobalData.gWorkspace, PackageDec))\r
2013 if not os.path.exists(Package):\r
2014 EdkLogger.error('Build', RESOURCE_NOT_AVAILABLE, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
2015 if Package not in PcdDependDEC:\r
2016 PcdDependDEC.append(Package)\r
2017\r
2018 if PlatformInc and PcdDependDEC:\r
2019 for pkg in PcdDependDEC:\r
2020 if pkg in PlatformInc:\r
2021 for inc in PlatformInc[pkg]:\r
2022 MakeApp += '-I' + str(inc) + ' '\r
34d808ad 2023 IncSearchList.append(inc)\r
ae7b6df8 2024 MakeApp = MakeApp + '\n'\r
68ba919f
YZ
2025\r
2026 CC_FLAGS = LinuxCFLAGS\r
2027 if sys.platform == "win32":\r
2028 CC_FLAGS = WindowsCFLAGS\r
2029 BuildOptions = {}\r
2030 for Options in self.BuildOptions:\r
2031 if Options[2] != EDKII_NAME:\r
2032 continue\r
2033 Family = Options[0]\r
2034 if Family and Family != self.ToolChainFamily:\r
2035 continue\r
2036 Target, Tag, Arch, Tool, Attr = Options[1].split("_")\r
2037 if Tool != 'CC':\r
2038 continue\r
2039\r
2040 if Target == "*" or Target == self._Target:\r
2041 if Tag == "*" or Tag == self._Toolchain:\r
2042 if Arch == "*" or Arch == self.Arch:\r
2043 if Tool not in BuildOptions:\r
2044 BuildOptions[Tool] = {}\r
2045 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or self.BuildOptions[Options].startswith('='):\r
2046 BuildOptions[Tool][Attr] = self.BuildOptions[Options]\r
2047 else:\r
2048 # append options for the same tool except PATH\r
2049 if Attr != 'PATH':\r
2050 BuildOptions[Tool][Attr] += " " + self.BuildOptions[Options]\r
2051 else:\r
2052 BuildOptions[Tool][Attr] = self.BuildOptions[Options]\r
2053 if BuildOptions:\r
2054 for Tool in BuildOptions:\r
2055 for Attr in BuildOptions[Tool]:\r
2056 if Attr == "FLAGS":\r
2057 Value = BuildOptions[Tool][Attr]\r
2058 ValueList = Value.split()\r
2059 if ValueList:\r
2060 for Id, Item in enumerate(ValueList):\r
5d9af6a5 2061 if Item in ['-D', '/D', '-U', '/U']:\r
68ba919f
YZ
2062 CC_FLAGS += ' ' + Item\r
2063 if Id + 1 < len(ValueList):\r
2064 CC_FLAGS += ' ' + ValueList[Id + 1]\r
5d9af6a5 2065 elif Item.startswith(('-D', '/D', '-U', '/U')):\r
68ba919f
YZ
2066 CC_FLAGS += ' ' + Item\r
2067 MakeApp += CC_FLAGS\r
2068\r
ae7b6df8
LG
2069 if sys.platform == "win32":\r
2070 MakeApp = MakeApp + PcdMakefileEnd\r
34d808ad
B
2071 MakeApp = MakeApp + '\n'\r
2072 IncludeFileFullPaths = []\r
2073 for includefile in IncludeFiles:\r
2074 for includepath in IncSearchList:\r
ccaa7754 2075 includefullpath = os.path.join(str(includepath), includefile)\r
34d808ad
B
2076 if os.path.exists(includefullpath):\r
2077 IncludeFileFullPaths.append(os.path.normpath(includefullpath))\r
2078 break\r
2079 SearchPathList = []\r
2080 SearchPathList.append(os.path.normpath(mws.join(GlobalData.gWorkspace, "BaseTools/Source/C/Include")))\r
2081 SearchPathList.append(os.path.normpath(mws.join(GlobalData.gWorkspace, "BaseTools/Source/C/Common")))\r
8252e6bf 2082 SearchPathList.extend(str(item) for item in IncSearchList)\r
ccaa7754 2083 IncFileList = GetDependencyList(IncludeFileFullPaths, SearchPathList)\r
34d808ad
B
2084 for include_file in IncFileList:\r
2085 MakeApp += "$(OBJECTS) : %s\n" % include_file\r
ae7b6df8 2086 MakeFileName = os.path.join(self.OutputPath, 'Makefile')\r
34d808ad 2087 MakeApp += "$(OBJECTS) : %s\n" % MakeFileName\r
0a57a978 2088 SaveFileOnChange(MakeFileName, MakeApp, False)\r
ae7b6df8
LG
2089\r
2090 InputValueFile = os.path.join(self.OutputPath, 'Input.txt')\r
2091 OutputValueFile = os.path.join(self.OutputPath, 'Output.txt')\r
0a57a978 2092 SaveFileOnChange(InputValueFile, InitByteValue, False)\r
ae7b6df8
LG
2093\r
2094 PcdValueInitExe = PcdValueInitName\r
2095 if not sys.platform == "win32":\r
2096 PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName)\r
5db9414c 2097 else:\r
0a57a978 2098 PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Bin', 'Win32', PcdValueInitName) +".exe"\r
34d808ad
B
2099\r
2100 Messages = ''\r
2101 if sys.platform == "win32":\r
2102 MakeCommand = 'nmake -f %s' % (MakeFileName)\r
9e508f3a 2103 returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)\r
34d808ad
B
2104 Messages = StdOut\r
2105 else:\r
2106 MakeCommand = 'make -f %s' % (MakeFileName)\r
9e508f3a 2107 returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)\r
34d808ad
B
2108 Messages = StdErr\r
2109 Messages = Messages.split('\n')\r
2110 MessageGroup = []\r
9fb2cbda 2111 if returncode != 0:\r
34d808ad
B
2112 CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)\r
2113 File = open (CAppBaseFileName + '.c', 'r')\r
2114 FileData = File.readlines()\r
2115 File.close()\r
2116 for Message in Messages:\r
2117 if " error" in Message or "warning" in Message:\r
2118 FileInfo = Message.strip().split('(')\r
2119 if len (FileInfo) > 1:\r
2120 FileName = FileInfo [0]\r
2121 FileLine = FileInfo [1].split (')')[0]\r
2122 else:\r
2123 FileInfo = Message.strip().split(':')\r
2124 FileName = FileInfo [0]\r
2125 FileLine = FileInfo [1]\r
2126 if FileLine.isdigit():\r
2127 error_line = FileData[int (FileLine) - 1]\r
2128 if r"//" in error_line:\r
ccaa7754 2129 c_line, dsc_line = error_line.split(r"//")\r
0a57a978 2130 else:\r
34d808ad
B
2131 dsc_line = error_line\r
2132 message_itmes = Message.split(":")\r
2133 Index = 0\r
2134 if "PcdValueInit.c" not in Message:\r
2135 if not MessageGroup:\r
2136 MessageGroup.append(Message)\r
2137 break\r
0a57a978 2138 else:\r
34d808ad
B
2139 for item in message_itmes:\r
2140 if "PcdValueInit.c" in item:\r
2141 Index = message_itmes.index(item)\r
2142 message_itmes[Index] = dsc_line.strip()\r
2143 break\r
2144 MessageGroup.append(":".join(message_itmes[Index:]).strip())\r
2145 continue\r
2146 else:\r
2147 MessageGroup.append(Message)\r
2148 if MessageGroup:\r
2149 EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) )\r
2150 else:\r
2151 EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand)\r
2152\r
ccaa7754 2153 if DscBuildData.NeedUpdateOutput(OutputValueFile, PcdValueInitExe, InputValueFile):\r
0a57a978 2154 Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile)\r
9e508f3a 2155 returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (Command)\r
87d2afd0 2156 if returncode != 0:\r
0a57a978
FB
2157 EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command)\r
2158\r
2159 File = open (OutputValueFile, 'r')\r
2160 FileBuffer = File.readlines()\r
2161 File.close()\r
ae7b6df8
LG
2162\r
2163 StructurePcdSet = []\r
2164 for Pcd in FileBuffer:\r
2165 PcdValue = Pcd.split ('|')\r
2166 PcdInfo = PcdValue[0].split ('.')\r
ccaa7754 2167 StructurePcdSet.append((PcdInfo[0], PcdInfo[1], PcdInfo[2], PcdInfo[3], PcdValue[2].strip()))\r
ae7b6df8
LG
2168 return StructurePcdSet\r
2169\r
9e508f3a
CJ
2170 @staticmethod\r
2171 def NeedUpdateOutput(OutputFile, ValueCFile, StructureInput):\r
0a57a978
FB
2172 if not os.path.exists(OutputFile):\r
2173 return True\r
2174 if os.stat(OutputFile).st_mtime <= os.stat(ValueCFile).st_mtime:\r
2175 return True\r
0a57a978
FB
2176 if os.stat(OutputFile).st_mtime <= os.stat(StructureInput).st_mtime:\r
2177 return True\r
2178 return False\r
2179\r
ae7b6df8
LG
2180 ## Retrieve dynamic PCD settings\r
2181 #\r
2182 # @param Type PCD type\r
2183 #\r
2184 # @retval a dict object contains settings of given PCD type\r
2185 #\r
2186 def _GetDynamicPcd(self, Type):\r
2187\r
ae7b6df8 2188\r
a0767bae 2189 Pcds = OrderedDict()\r
ae7b6df8
LG
2190 #\r
2191 # tdict is a special dict kind of type, used for selecting correct\r
2192 # PCD settings for certain ARCH and SKU\r
2193 #\r
2194 PcdDict = tdict(True, 4)\r
2195 PcdList = []\r
2196 # Find out all possible PCD candidates for self._Arch\r
2197 RecordList = self._RawData[Type, self._Arch]\r
8518bf0b 2198 AvailableSkuIdSet = copy.copy(self.SkuIds)\r
ae7b6df8 2199\r
ae7b6df8 2200\r
ccaa7754 2201 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4, Dummy5 in RecordList:\r
2b8a6c44 2202 SkuName = SkuName.upper()\r
55c84777 2203 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
ae7b6df8 2204 if SkuName not in AvailableSkuIdSet:\r
2b8a6c44
LG
2205 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
2206 File=self.MetaFile, Line=Dummy5)\r
ae7b6df8 2207 if "." not in TokenSpaceGuid:\r
5db9414c 2208 PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))\r
ae7b6df8
LG
2209 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
2210\r
2211 # Remove redundant PCD candidates, per the ARCH and SKU\r
2212 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:\r
2213\r
2214 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]\r
4231a819 2215 if Setting is None:\r
ae7b6df8
LG
2216 continue\r
2217\r
2218 PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
8518bf0b 2219 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '', '', '', '', '', PcdValue)\r
5a693b89 2220 if (PcdCName, TokenSpaceGuid) in Pcds:\r
ae7b6df8
LG
2221 pcdObject = Pcds[PcdCName, TokenSpaceGuid]\r
2222 pcdObject.SkuInfoList[SkuName] = SkuInfo\r
2223 if MaxDatumSize.strip():\r
2224 CurrentMaxSize = int(MaxDatumSize.strip(), 0)\r
2225 else:\r
2226 CurrentMaxSize = 0\r
2227 if pcdObject.MaxDatumSize:\r
2228 PcdMaxSize = int(pcdObject.MaxDatumSize, 0)\r
2229 else:\r
2230 PcdMaxSize = 0\r
2231 if CurrentMaxSize > PcdMaxSize:\r
2232 pcdObject.MaxDatumSize = str(CurrentMaxSize)\r
2233 else:\r
2234 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
2235 PcdCName,\r
2236 TokenSpaceGuid,\r
2237 self._PCD_TYPE_STRING_[Type],\r
2238 DatumType,\r
2239 PcdValue,\r
2240 '',\r
2241 MaxDatumSize,\r
2242 {SkuName : SkuInfo},\r
2243 False,\r
2244 None,\r
2245 IsDsc=True)\r
2246\r
2247 for pcd in Pcds.values():\r
2248 pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
e651d06c
LG
2249 # Only fix the value while no value provided in DSC file.\r
2250 for sku in pcd.SkuInfoList.values():\r
128d435f 2251 if not sku.DefaultValue:\r
e651d06c 2252 sku.DefaultValue = pcdDecObject.DefaultValue\r
55c84777 2253 if TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON not in pcd.SkuInfoList:\r
ae7b6df8 2254 valuefromDec = pcdDecObject.DefaultValue\r
55c84777
CJ
2255 SkuInfo = SkuInfoClass(TAB_DEFAULT, '0', '', '', '', '', '', valuefromDec)\r
2256 pcd.SkuInfoList[TAB_DEFAULT] = SkuInfo\r
2257 elif TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
2258 pcd.SkuInfoList[TAB_DEFAULT] = pcd.SkuInfoList[TAB_COMMON]\r
2259 del pcd.SkuInfoList[TAB_COMMON]\r
2260 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
2261 del pcd.SkuInfoList[TAB_COMMON]\r
65eff519 2262\r
ccaa7754 2263 map(self.FilterSkuSettings, Pcds.values())\r
ae7b6df8
LG
2264\r
2265 return Pcds\r
2266\r
65eff519
LG
2267 def FilterSkuSettings(self, PcdObj):\r
2268\r
2269 if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE:\r
55c84777
CJ
2270 if TAB_DEFAULT in PcdObj.SkuInfoList and self.SkuIdMgr.SystemSkuId not in PcdObj.SkuInfoList:\r
2271 PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId] = PcdObj.SkuInfoList[TAB_DEFAULT]\r
2272 PcdObj.SkuInfoList = {TAB_DEFAULT:PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId]}\r
2273 PcdObj.SkuInfoList[TAB_DEFAULT].SkuIdName = TAB_DEFAULT\r
2274 PcdObj.SkuInfoList[TAB_DEFAULT].SkuId = '0'\r
65eff519
LG
2275\r
2276 elif self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.DEFAULT:\r
55c84777 2277 PcdObj.SkuInfoList = {TAB_DEFAULT:PcdObj.SkuInfoList[TAB_DEFAULT]}\r
65eff519
LG
2278\r
2279 return PcdObj\r
2280\r
9e508f3a
CJ
2281 @staticmethod\r
2282 def CompareVarAttr(Attr1, Attr2):\r
ae7b6df8
LG
2283 if not Attr1 or not Attr2: # for empty string\r
2284 return True\r
2285 Attr1s = [attr.strip() for attr in Attr1.split(",")]\r
2286 Attr1Set = set(Attr1s)\r
2287 Attr2s = [attr.strip() for attr in Attr2.split(",")]\r
2288 Attr2Set = set(Attr2s)\r
2289 if Attr2Set == Attr1Set:\r
2290 return True\r
2291 else:\r
2292 return False\r
9e508f3a 2293\r
ccaa7754 2294 def CopyDscRawValue(self, Pcd):\r
f3b31433
FB
2295 if Pcd.DscRawValue is None:\r
2296 Pcd.DscRawValue = dict()\r
f832bb34
FB
2297 if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
2298 if self.SkuIdMgr.SystemSkuId not in Pcd.DscRawValue:\r
2299 Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId] = {}\r
4d3b9389 2300 Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId][TAB_DEFAULT_STORES_DEFAULT] = Pcd.DefaultValue\r
f3b31433
FB
2301 for skuname in Pcd.SkuInfoList:\r
2302 Pcd.DscRawValue[skuname] = {}\r
2303 if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
2304 for defaultstore in Pcd.SkuInfoList[skuname].DefaultStoreDict:\r
2305 Pcd.DscRawValue[skuname][defaultstore] = Pcd.SkuInfoList[skuname].DefaultStoreDict[defaultstore]\r
2306 else:\r
4d3b9389 2307 Pcd.DscRawValue[skuname][TAB_DEFAULT_STORES_DEFAULT] = Pcd.SkuInfoList[skuname].DefaultValue\r
ccaa7754 2308 def CompletePcdValues(self, PcdSet):\r
8518bf0b
LG
2309 Pcds = {}\r
2310 DefaultStoreObj = DefaultStore(self._GetDefaultStores())\r
ccaa7754 2311 SkuIds = {skuname:skuid for skuname, skuid in self.SkuIdMgr.AvailableSkuIdSet.items() if skuname != TAB_COMMON}\r
c5c7e68a 2312 DefaultStores = set(storename for pcdobj in PcdSet.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict)\r
8518bf0b
LG
2313 for PcdCName, TokenSpaceGuid in PcdSet:\r
2314 PcdObj = PcdSet[(PcdCName, TokenSpaceGuid)]\r
f832bb34 2315 self.CopyDscRawValue(PcdObj)\r
8518bf0b
LG
2316 if PcdObj.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],\r
2317 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
2318 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_VPD],\r
2319 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],\r
2320 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],\r
2321 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]:\r
2322 Pcds[PcdCName, TokenSpaceGuid]= PcdObj\r
2323 continue\r
2324 PcdType = PcdObj.Type\r
2325 if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
2326 for skuid in PcdObj.SkuInfoList:\r
2327 skuobj = PcdObj.SkuInfoList[skuid]\r
8252e6bf 2328 mindefaultstorename = DefaultStoreObj.GetMin(set(defaultstorename for defaultstorename in skuobj.DefaultStoreDict))\r
8518bf0b
LG
2329 for defaultstorename in DefaultStores:\r
2330 if defaultstorename not in skuobj.DefaultStoreDict:\r
2b8a6c44 2331 skuobj.DefaultStoreDict[defaultstorename] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])\r
8518bf0b 2332 skuobj.HiiDefaultValue = skuobj.DefaultStoreDict[mindefaultstorename]\r
ccaa7754 2333 for skuname, skuid in SkuIds.items():\r
2b8a6c44
LG
2334 if skuname not in PcdObj.SkuInfoList:\r
2335 nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)\r
8518bf0b
LG
2336 while nextskuid not in PcdObj.SkuInfoList:\r
2337 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
2b8a6c44
LG
2338 PcdObj.SkuInfoList[skuname] = copy.deepcopy(PcdObj.SkuInfoList[nextskuid])\r
2339 PcdObj.SkuInfoList[skuname].SkuId = skuid\r
2340 PcdObj.SkuInfoList[skuname].SkuIdName = skuname\r
8518bf0b 2341 if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
55c84777 2342 PcdObj.DefaultValue = PcdObj.SkuInfoList.values()[0].HiiDefaultValue if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE else PcdObj.SkuInfoList[TAB_DEFAULT].HiiDefaultValue\r
8518bf0b
LG
2343 Pcds[PcdCName, TokenSpaceGuid]= PcdObj\r
2344 return Pcds\r
ae7b6df8
LG
2345 ## Retrieve dynamic HII PCD settings\r
2346 #\r
2347 # @param Type PCD type\r
2348 #\r
2349 # @retval a dict object contains settings of given PCD type\r
2350 #\r
2351 def _GetDynamicHiiPcd(self, Type):\r
2352\r
ae7b6df8
LG
2353 VariableAttrs = {}\r
2354\r
a0767bae 2355 Pcds = OrderedDict()\r
ae7b6df8
LG
2356 #\r
2357 # tdict is a special dict kind of type, used for selecting correct\r
2358 # PCD settings for certain ARCH and SKU\r
2359 #\r
8518bf0b 2360 PcdDict = tdict(True, 5)\r
ae7b6df8
LG
2361 PcdSet = set()\r
2362 RecordList = self._RawData[Type, self._Arch]\r
2363 # Find out all possible PCD candidates for self._Arch\r
8518bf0b 2364 AvailableSkuIdSet = copy.copy(self.SkuIds)\r
2b8a6c44 2365 DefaultStoresDefine = self._GetDefaultStores()\r
ae7b6df8 2366\r
ccaa7754 2367 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, DefaultStore, Dummy4, Dummy5 in RecordList:\r
2b8a6c44 2368 SkuName = SkuName.upper()\r
55c84777 2369 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
2b8a6c44 2370 DefaultStore = DefaultStore.upper()\r
55c84777 2371 if DefaultStore == TAB_COMMON:\r
4d3b9389 2372 DefaultStore = TAB_DEFAULT_STORES_DEFAULT\r
ae7b6df8 2373 if SkuName not in AvailableSkuIdSet:\r
2b8a6c44
LG
2374 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
2375 File=self.MetaFile, Line=Dummy5)\r
2376 if DefaultStore not in DefaultStoresDefine:\r
2377 EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore,\r
2378 File=self.MetaFile, Line=Dummy5)\r
ae7b6df8 2379 if "." not in TokenSpaceGuid:\r
ccaa7754
GL
2380 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, DefaultStore, Dummy5))\r
2381 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid, DefaultStore] = Setting\r
ae7b6df8
LG
2382\r
2383\r
2384 # Remove redundant PCD candidates, per the ARCH and SKU\r
ccaa7754 2385 for PcdCName, TokenSpaceGuid, SkuName, DefaultStore, Dummy4 in PcdSet:\r
ae7b6df8 2386\r
ccaa7754 2387 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid, DefaultStore]\r
4231a819 2388 if Setting is None:\r
ae7b6df8
LG
2389 continue\r
2390 VariableName, VariableGuid, VariableOffset, DefaultValue, VarAttribute = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
2391\r
2392 rt, Msg = VariableAttributes.ValidateVarAttributes(VarAttribute)\r
2393 if not rt:\r
2394 EdkLogger.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid, PcdCName)), Msg),\r
2395 ExtraData="[%s]" % VarAttribute)\r
2396 ExceedMax = False\r
2397 FormatCorrect = True\r
2398 if VariableOffset.isdigit():\r
2399 if int(VariableOffset, 10) > 0xFFFF:\r
2400 ExceedMax = True\r
3e4faa26 2401 elif variablePattern.match(VariableOffset):\r
ae7b6df8
LG
2402 if int(VariableOffset, 16) > 0xFFFF:\r
2403 ExceedMax = True\r
2404 # For Offset written in "A.B"\r
2405 elif VariableOffset.find('.') > -1:\r
2406 VariableOffsetList = VariableOffset.split(".")\r
2407 if not (len(VariableOffsetList) == 2\r
2408 and IsValidWord(VariableOffsetList[0])\r
2409 and IsValidWord(VariableOffsetList[1])):\r
2410 FormatCorrect = False\r
2411 else:\r
2412 FormatCorrect = False\r
2413 if not FormatCorrect:\r
2414 EdkLogger.error('Build', FORMAT_INVALID, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid, PcdCName)))\r
2415\r
2416 if ExceedMax:\r
2417 EdkLogger.error('Build', OPTION_VALUE_INVALID, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid, PcdCName)))\r
2418 if (VariableName, VariableGuid) not in VariableAttrs:\r
2419 VariableAttrs[(VariableName, VariableGuid)] = VarAttribute\r
2420 else:\r
9e508f3a 2421 if not DscBuildData.CompareVarAttr(VariableAttrs[(VariableName, VariableGuid)], VarAttribute):\r
ae7b6df8
LG
2422 EdkLogger.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR, "The variable %s.%s for DynamicHii PCDs has conflicting attributes [%s] and [%s] " % (VariableGuid, VariableName, VarAttribute, VariableAttrs[(VariableName, VariableGuid)]))\r
2423\r
ae7b6df8 2424 pcdDecObject = self._DecPcds[PcdCName, TokenSpaceGuid]\r
5a693b89 2425 if (PcdCName, TokenSpaceGuid) in Pcds:\r
ae7b6df8 2426 pcdObject = Pcds[PcdCName, TokenSpaceGuid]\r
8518bf0b
LG
2427 if SkuName in pcdObject.SkuInfoList:\r
2428 Skuitem = pcdObject.SkuInfoList[SkuName]\r
2429 Skuitem.DefaultStoreDict.update({DefaultStore:DefaultValue})\r
2430 else:\r
ccaa7754 2431 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], VariableName, VariableGuid, VariableOffset, DefaultValue, VariableAttribute=VarAttribute, DefaultStore={DefaultStore:DefaultValue})\r
8518bf0b 2432 pcdObject.SkuInfoList[SkuName] = SkuInfo\r
ae7b6df8 2433 else:\r
ccaa7754 2434 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], VariableName, VariableGuid, VariableOffset, DefaultValue, VariableAttribute=VarAttribute, DefaultStore={DefaultStore:DefaultValue})\r
ae7b6df8
LG
2435 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
2436 PcdCName,\r
2437 TokenSpaceGuid,\r
2438 self._PCD_TYPE_STRING_[Type],\r
2439 '',\r
2440 DefaultValue,\r
2441 '',\r
2442 '',\r
2443 {SkuName : SkuInfo},\r
2444 False,\r
2445 None,\r
2446 pcdDecObject.validateranges,\r
2447 pcdDecObject.validlists,\r
2448 pcdDecObject.expressions,\r
2449 IsDsc=True)\r
2450\r
2451\r
2452 for pcd in Pcds.values():\r
2453 SkuInfoObj = pcd.SkuInfoList.values()[0]\r
2454 pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
e1511113 2455 pcd.DatumType = pcdDecObject.DatumType\r
ae7b6df8
LG
2456 # Only fix the value while no value provided in DSC file.\r
2457 for sku in pcd.SkuInfoList.values():\r
4231a819 2458 if (sku.HiiDefaultValue == "" or sku.HiiDefaultValue is None):\r
ae7b6df8 2459 sku.HiiDefaultValue = pcdDecObject.DefaultValue\r
e1511113
B
2460 for default_store in sku.DefaultStoreDict:\r
2461 sku.DefaultStoreDict[default_store]=pcdDecObject.DefaultValue\r
2462 pcd.DefaultValue = pcdDecObject.DefaultValue\r
55c84777 2463 if TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON not in pcd.SkuInfoList:\r
ae7b6df8 2464 valuefromDec = pcdDecObject.DefaultValue\r
ccaa7754 2465 SkuInfo = SkuInfoClass(TAB_DEFAULT, '0', SkuInfoObj.VariableName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec, VariableAttribute=SkuInfoObj.VariableAttribute, DefaultStore={DefaultStore:valuefromDec})\r
55c84777
CJ
2466 pcd.SkuInfoList[TAB_DEFAULT] = SkuInfo\r
2467 elif TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
2468 pcd.SkuInfoList[TAB_DEFAULT] = pcd.SkuInfoList[TAB_COMMON]\r
2469 del pcd.SkuInfoList[TAB_COMMON]\r
2470 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
2471 del pcd.SkuInfoList[TAB_COMMON]\r
ae7b6df8 2472\r
ae7b6df8
LG
2473 if pcd.MaxDatumSize.strip():\r
2474 MaxSize = int(pcd.MaxDatumSize, 0)\r
2475 else:\r
2476 MaxSize = 0\r
656d2539 2477 if pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
2b8a6c44 2478 for (_, skuobj) in pcd.SkuInfoList.items():\r
ae7b6df8 2479 datalen = 0\r
47854fd5
LG
2480 skuobj.HiiDefaultValue = StringToArray(skuobj.HiiDefaultValue)\r
2481 datalen = len(skuobj.HiiDefaultValue.split(","))\r
ae7b6df8
LG
2482 if datalen > MaxSize:\r
2483 MaxSize = datalen\r
47854fd5
LG
2484 for defaultst in skuobj.DefaultStoreDict:\r
2485 skuobj.DefaultStoreDict[defaultst] = StringToArray(skuobj.DefaultStoreDict[defaultst])\r
2486 pcd.DefaultValue = StringToArray(pcd.DefaultValue)\r
ae7b6df8 2487 pcd.MaxDatumSize = str(MaxSize)\r
9e508f3a 2488 rt, invalidhii = DscBuildData.CheckVariableNameAssignment(Pcds)\r
2b8a6c44
LG
2489 if not rt:\r
2490 invalidpcd = ",".join(invalidhii)\r
2491 EdkLogger.error('build', PCD_VARIABLE_INFO_ERROR, Message='The same HII PCD must map to the same EFI variable for all SKUs', File=self.MetaFile, ExtraData=invalidpcd)\r
65eff519 2492\r
ccaa7754 2493 map(self.FilterSkuSettings, Pcds.values())\r
65eff519 2494\r
ae7b6df8
LG
2495 return Pcds\r
2496\r
9e508f3a
CJ
2497 @staticmethod\r
2498 def CheckVariableNameAssignment(Pcds):\r
2b8a6c44
LG
2499 invalidhii = []\r
2500 for pcdname in Pcds:\r
2501 pcd = Pcds[pcdname]\r
ccaa7754 2502 varnameset = set(sku.VariableName for (skuid, sku) in pcd.SkuInfoList.items())\r
2b8a6c44 2503 if len(varnameset) > 1:\r
ccaa7754 2504 invalidhii.append(".".join((pcdname[1], pcdname[0])))\r
2b8a6c44 2505 if len(invalidhii):\r
ccaa7754 2506 return False, invalidhii\r
2b8a6c44
LG
2507 else:\r
2508 return True, []\r
ae7b6df8
LG
2509 ## Retrieve dynamic VPD PCD settings\r
2510 #\r
2511 # @param Type PCD type\r
2512 #\r
2513 # @retval a dict object contains settings of given PCD type\r
2514 #\r
2515 def _GetDynamicVpdPcd(self, Type):\r
2516\r
ae7b6df8 2517\r
a0767bae 2518 Pcds = OrderedDict()\r
ae7b6df8
LG
2519 #\r
2520 # tdict is a special dict kind of type, used for selecting correct\r
2521 # PCD settings for certain ARCH and SKU\r
2522 #\r
2523 PcdDict = tdict(True, 4)\r
2524 PcdList = []\r
2525\r
2526 # Find out all possible PCD candidates for self._Arch\r
2527 RecordList = self._RawData[Type, self._Arch]\r
8518bf0b 2528 AvailableSkuIdSet = copy.copy(self.SkuIds)\r
ae7b6df8 2529\r
ccaa7754 2530 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4, Dummy5 in RecordList:\r
2b8a6c44 2531 SkuName = SkuName.upper()\r
55c84777 2532 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
ae7b6df8 2533 if SkuName not in AvailableSkuIdSet:\r
2b8a6c44
LG
2534 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
2535 File=self.MetaFile, Line=Dummy5)\r
ae7b6df8 2536 if "." not in TokenSpaceGuid:\r
5db9414c 2537 PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))\r
ae7b6df8
LG
2538 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
2539\r
2540 # Remove redundant PCD candidates, per the ARCH and SKU\r