BaseTools: Enable structure pcd in FDF file
[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
543f5ac3
B
1134 self._Pcds = self.OverrideByFdfOverAll(self._Pcds)\r
1135 self._Pcds = self.OverrideByCommOverAll(self._Pcds)\r
ae7b6df8 1136 self._Pcds = self.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST, self._Pcds)\r
2b8a6c44 1137 self._Pcds = self.CompleteHiiPcdsDefaultStores(self._Pcds)\r
8518bf0b 1138 self._Pcds = self._FilterPcdBySkuUsage(self._Pcds)\r
b854e2bf 1139\r
6f49996c 1140 self.RecoverCommandLinePcd()\r
ae7b6df8
LG
1141 return self._Pcds\r
1142\r
1143 ## Retrieve [BuildOptions]\r
1144 def _GetBuildOptions(self):\r
4231a819 1145 if self._BuildOptions is None:\r
a0767bae 1146 self._BuildOptions = OrderedDict()\r
ae7b6df8
LG
1147 #\r
1148 # Retrieve build option for EDKII and EDK style module\r
1149 #\r
1150 for CodeBase in (EDKII_NAME, EDK_NAME):\r
1151 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, CodeBase]\r
ccaa7754 1152 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4, Dummy5 in RecordList:\r
55c84777 1153 if Dummy3.upper() != TAB_COMMON:\r
c05c2c05 1154 continue\r
ae7b6df8
LG
1155 CurKey = (ToolChainFamily, ToolChain, CodeBase)\r
1156 #\r
1157 # Only flags can be appended\r
1158 #\r
1159 if CurKey not in self._BuildOptions or not ToolChain.endswith('_FLAGS') or Option.startswith('='):\r
1160 self._BuildOptions[CurKey] = Option\r
1161 else:\r
c05c2c05
LG
1162 if ' ' + Option not in self._BuildOptions[CurKey]:\r
1163 self._BuildOptions[CurKey] += ' ' + Option\r
ae7b6df8
LG
1164 return self._BuildOptions\r
1165\r
1166 def GetBuildOptionsByModuleType(self, Edk, ModuleType):\r
4231a819 1167 if self._ModuleTypeOptions is None:\r
a0767bae 1168 self._ModuleTypeOptions = OrderedDict()\r
ae7b6df8 1169 if (Edk, ModuleType) not in self._ModuleTypeOptions:\r
a0767bae 1170 options = OrderedDict()\r
ae7b6df8
LG
1171 self._ModuleTypeOptions[Edk, ModuleType] = options\r
1172 DriverType = '%s.%s' % (Edk, ModuleType)\r
55c84777 1173 CommonDriverType = '%s.%s' % (TAB_COMMON, ModuleType)\r
c05c2c05 1174 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch]\r
ccaa7754 1175 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4, Dummy5 in RecordList:\r
c05c2c05
LG
1176 Type = Dummy2 + '.' + Dummy3\r
1177 if Type.upper() == DriverType.upper() or Type.upper() == CommonDriverType.upper():\r
ae7b6df8
LG
1178 Key = (ToolChainFamily, ToolChain, Edk)\r
1179 if Key not in options or not ToolChain.endswith('_FLAGS') or Option.startswith('='):\r
1180 options[Key] = Option\r
1181 else:\r
c05c2c05
LG
1182 if ' ' + Option not in options[Key]:\r
1183 options[Key] += ' ' + Option\r
ae7b6df8
LG
1184 return self._ModuleTypeOptions[Edk, ModuleType]\r
1185\r
9759febd
CJ
1186 @staticmethod\r
1187 def GetStructurePcdInfo(PcdSet):\r
1188 structure_pcd_data = defaultdict(list)\r
ae7b6df8 1189 for item in PcdSet:\r
ccaa7754 1190 structure_pcd_data[(item[0], item[1])].append(item)\r
ae7b6df8
LG
1191\r
1192 return structure_pcd_data\r
9e508f3a
CJ
1193\r
1194 @staticmethod\r
543f5ac3
B
1195 def OverrideByFdf(StruPcds,workspace):\r
1196 if GlobalData.gFdfParser is None:\r
1197 return StruPcds\r
1198 StructurePcdInFdf = OrderedDict()\r
1199 fdfpcd = GlobalData.gFdfParser.Profile.PcdDict\r
1200 fdfpcdlocation = GlobalData.gFdfParser.Profile.PcdLocalDict\r
1201 for item in fdfpcd :\r
1202 if len(item[2]) and (item[0],item[1]) in StruPcds:\r
1203 StructurePcdInFdf[(item[1],item[0],item[2] )] = fdfpcd[item]\r
1204 GlobalPcds = {(item[0],item[1]) for item in StructurePcdInFdf}\r
1205 for Pcd in StruPcds.values():\r
1206 if (Pcd.TokenSpaceGuidCName,Pcd.TokenCName) not in GlobalPcds:\r
1207 continue\r
1208 FieldValues = OrderedDict()\r
1209 for item in StructurePcdInFdf:\r
1210 if (Pcd.TokenSpaceGuidCName,Pcd.TokenCName) == (item[0],item[1]) and item[2]:\r
1211 FieldValues[item[2]] = StructurePcdInFdf[item]\r
1212 for field in FieldValues:\r
1213 if field not in Pcd.PcdFieldValueFromFdf:\r
1214 Pcd.PcdFieldValueFromFdf[field] = ["","",""]\r
1215 Pcd.PcdFieldValueFromFdf[field][0] = FieldValues[field]\r
1216 Pcd.PcdFieldValueFromFdf[field][1] = os.path.relpath(fdfpcdlocation[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName,field)][0],workspace)\r
1217 Pcd.PcdFieldValueFromFdf[field][2] = fdfpcdlocation[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName,field)][1]\r
1218\r
1219 return StruPcds\r
1220\r
1221 @staticmethod\r
1222 def OverrideByComm(StruPcds):\r
b854e2bf
B
1223 StructurePcdInCom = OrderedDict()\r
1224 for item in GlobalData.BuildOptionPcd:\r
ccaa7754
GL
1225 if len(item) == 5 and (item[1], item[0]) in StruPcds:\r
1226 StructurePcdInCom[(item[0], item[1], item[2] )] = (item[3], item[4])\r
1227 GlobalPcds = {(item[0], item[1]) for item in StructurePcdInCom}\r
6f49996c 1228 for Pcd in StruPcds.values():\r
ccaa7754 1229 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) not in GlobalPcds:\r
6f49996c 1230 continue\r
b854e2bf
B
1231 FieldValues = OrderedDict()\r
1232 for item in StructurePcdInCom:\r
ccaa7754 1233 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (item[0], item[1]) and item[2]:\r
b854e2bf
B
1234 FieldValues[item[2]] = StructurePcdInCom[item]\r
1235 for field in FieldValues:\r
1236 if field not in Pcd.PcdFieldValueFromComm:\r
ccaa7754 1237 Pcd.PcdFieldValueFromComm[field] = ["", "", ""]\r
b854e2bf
B
1238 Pcd.PcdFieldValueFromComm[field][0] = FieldValues[field][0]\r
1239 Pcd.PcdFieldValueFromComm[field][1] = FieldValues[field][1][0]\r
1240 Pcd.PcdFieldValueFromComm[field][2] = FieldValues[field][1][1]\r
6f49996c 1241 return StruPcds\r
9e508f3a 1242\r
543f5ac3
B
1243\r
1244 def OverrideByCommOverAll(self,AllPcds):\r
6f49996c
FB
1245 def CheckStructureInComm(commpcds):\r
1246 if not commpcds:\r
1247 return False\r
1248 if len(commpcds[0]) == 5:\r
1249 return True\r
1250 return False\r
ae7b6df8 1251\r
6f49996c 1252 if CheckStructureInComm(GlobalData.BuildOptionPcd):\r
ccaa7754
GL
1253 StructurePcdInCom = {(item[0], item[1], item[2] ):(item[3], item[4]) for item in GlobalData.BuildOptionPcd } if GlobalData.BuildOptionPcd else {}\r
1254 NoFiledValues = {(item[0], item[1]):StructurePcdInCom[item] for item in StructurePcdInCom if not item[2]}\r
6f49996c 1255 else:\r
ccaa7754
GL
1256 NoFiledValues = {(item[0], item[1]):[item[2]] for item in GlobalData.BuildOptionPcd}\r
1257 for Guid, Name in NoFiledValues:\r
1258 if (Name, Guid) in AllPcds:\r
1259 Pcd = AllPcds.get((Name, Guid))\r
1260 if isinstance(self._DecPcds.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName), None), StructurePcd):\r
1261 self._DecPcds.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName)).PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
b854e2bf 1262 else:\r
ccaa7754
GL
1263 Pcd.PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
1264 Pcd.DefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
b854e2bf
B
1265 for sku in Pcd.SkuInfoList:\r
1266 SkuInfo = Pcd.SkuInfoList[sku]\r
1267 if SkuInfo.DefaultValue:\r
ccaa7754 1268 SkuInfo.DefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
b854e2bf 1269 else:\r
ccaa7754 1270 SkuInfo.HiiDefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
b854e2bf 1271 for defaultstore in SkuInfo.DefaultStoreDict:\r
ccaa7754 1272 SkuInfo.DefaultStoreDict[defaultstore] = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]\r
c8ae65ac 1273 if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII]]:\r
656d2539 1274 if Pcd.DatumType == TAB_VOID:\r
c8ae65ac
YZ
1275 if not Pcd.MaxDatumSize:\r
1276 Pcd.MaxDatumSize = '0'\r
ccaa7754 1277 CurrentSize = int(Pcd.MaxDatumSize, 16) if Pcd.MaxDatumSize.upper().startswith("0X") else int(Pcd.MaxDatumSize)\r
c8ae65ac
YZ
1278 OptionSize = len((StringToArray(Pcd.PcdValueFromComm)).split(","))\r
1279 MaxSize = max(CurrentSize, OptionSize)\r
1280 Pcd.MaxDatumSize = str(MaxSize)\r
6f49996c 1281 else:\r
ccaa7754 1282 PcdInDec = self.DecPcds.get((Name, Guid))\r
6f49996c 1283 if PcdInDec:\r
ccaa7754 1284 PcdInDec.PcdValueFromComm = NoFiledValues[(Guid, Name)][0]\r
6f49996c 1285 if PcdInDec.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
b7bfcd1a
YZ
1286 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE],\r
1287 self._PCD_TYPE_STRING_[MODEL_PCD_FEATURE_FLAG]]:\r
6f49996c 1288 self.Pcds[Name, Guid] = copy.deepcopy(PcdInDec)\r
ccaa7754 1289 self.Pcds[Name, Guid].DefaultValue = NoFiledValues[( Guid, Name)][0]\r
6f49996c 1290 return AllPcds\r
543f5ac3
B
1291\r
1292 def OverrideByFdfOverAll(self,AllPcds):\r
1293\r
1294 if GlobalData.gFdfParser is None:\r
1295 return AllPcds\r
1296 NoFiledValues = GlobalData.gFdfParser.Profile.PcdDict\r
1297 for Guid,Name,Field in NoFiledValues:\r
1298 if len(Field):\r
1299 continue\r
1300 Value = NoFiledValues[(Guid,Name,Field)]\r
1301 if (Name,Guid) in AllPcds:\r
1302 Pcd = AllPcds.get((Name,Guid))\r
1303 if isinstance(self._DecPcds.get((Pcd.TokenCName,Pcd.TokenSpaceGuidCName), None),StructurePcd):\r
1304 self._DecPcds.get((Pcd.TokenCName,Pcd.TokenSpaceGuidCName)).PcdValueFromComm = Value\r
1305 else:\r
1306 Pcd.PcdValueFromComm = Value\r
1307 Pcd.DefaultValue = Value\r
1308 for sku in Pcd.SkuInfoList:\r
1309 SkuInfo = Pcd.SkuInfoList[sku]\r
1310 if SkuInfo.DefaultValue:\r
1311 SkuInfo.DefaultValue = Value\r
1312 else:\r
1313 SkuInfo.HiiDefaultValue = Value\r
1314 for defaultstore in SkuInfo.DefaultStoreDict:\r
1315 SkuInfo.DefaultStoreDict[defaultstore] = Value\r
1316 if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII]]:\r
1317 if Pcd.DatumType == TAB_VOID:\r
1318 if not Pcd.MaxDatumSize:\r
1319 Pcd.MaxDatumSize = '0'\r
1320 CurrentSize = int(Pcd.MaxDatumSize,16) if Pcd.MaxDatumSize.upper().startswith("0X") else int(Pcd.MaxDatumSize)\r
1321 OptionSize = len((StringToArray(Pcd.PcdValueFromComm)).split(","))\r
1322 MaxSize = max(CurrentSize, OptionSize)\r
1323 Pcd.MaxDatumSize = str(MaxSize)\r
1324 else:\r
1325 PcdInDec = self.DecPcds.get((Name,Guid))\r
1326 if PcdInDec:\r
1327 PcdInDec.PcdValueFromComm = Value\r
1328 if PcdInDec.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
1329 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE],\r
1330 self._PCD_TYPE_STRING_[MODEL_PCD_FEATURE_FLAG]]:\r
1331 self.Pcds[Name, Guid] = copy.deepcopy(PcdInDec)\r
1332 self.Pcds[Name, Guid].DefaultValue = Value\r
1333 return AllPcds\r
1334\r
ae7b6df8 1335 def UpdateStructuredPcds(self, TypeList, AllPcds):\r
65eff519
LG
1336\r
1337 DynamicPcdType = [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],\r
1338 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
1339 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_VPD],\r
1340 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],\r
1341 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],\r
1342 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]\r
1343\r
ae7b6df8 1344 Pcds = AllPcds\r
8518bf0b 1345 DefaultStoreMgr = DefaultStore(self.DefaultStores)\r
65eff519 1346 SkuIds = self.SkuIdMgr.AvailableSkuIdSet\r
55c84777 1347 SkuIds.update({TAB_DEFAULT:0})\r
b491aa95 1348 DefaultStores = {storename for pcdobj in AllPcds.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict}\r
ae7b6df8
LG
1349\r
1350 S_PcdSet = []\r
1351 # Find out all possible PCD candidates for self._Arch\r
1352 RecordList = []\r
2b8a6c44 1353\r
ae7b6df8
LG
1354 for Type in TypeList:\r
1355 RecordList.extend(self._RawData[Type, self._Arch])\r
1356\r
ccaa7754 1357 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, default_store, Dummy4, Dummy5 in RecordList:\r
2b8a6c44
LG
1358 SkuName = SkuName.upper()\r
1359 default_store = default_store.upper()\r
55c84777 1360 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
8518bf0b
LG
1361 if SkuName not in SkuIds:\r
1362 continue\r
2b8a6c44 1363\r
8518bf0b 1364 if SkuName in SkuIds and "." in TokenSpaceGuid:\r
ccaa7754 1365 S_PcdSet.append([ TokenSpaceGuid.split(".")[0], TokenSpaceGuid.split(".")[1], PcdCName, SkuName, default_store, Dummy5, AnalyzePcdExpression(Setting)[0]])\r
ae7b6df8
LG
1366\r
1367 # handle pcd value override\r
9759febd 1368 StrPcdSet = DscBuildData.GetStructurePcdInfo(S_PcdSet)\r
79820e32 1369 S_pcd_set = OrderedDict()\r
ae7b6df8 1370 for str_pcd in StrPcdSet:\r
8518bf0b
LG
1371 str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)\r
1372 str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)\r
5db9414c
B
1373 if not isinstance (str_pcd_dec, StructurePcd):\r
1374 EdkLogger.error('build', PARSER_ERROR,\r
1375 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),\r
ccaa7754 1376 File=self.MetaFile, Line = StrPcdSet[str_pcd][0][5])\r
ae7b6df8
LG
1377 if str_pcd_dec:\r
1378 str_pcd_obj_str = StructurePcd()\r
1379 str_pcd_obj_str.copy(str_pcd_dec)\r
1380 if str_pcd_obj:\r
1381 str_pcd_obj_str.copy(str_pcd_obj)\r
f832bb34
FB
1382 if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
1383 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
1384 else:\r
1385 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 1386 for str_pcd_data in StrPcdSet[str_pcd]:\r
8518bf0b 1387 if str_pcd_data[3] in SkuIds:\r
ccaa7754 1388 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 1389 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str\r
2b8a6c44
LG
1390 else:\r
1391 EdkLogger.error('build', PARSER_ERROR,\r
1392 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),\r
ccaa7754 1393 File=self.MetaFile, Line = StrPcdSet[str_pcd][0][5])\r
ae7b6df8 1394 # Add the Structure PCD that only defined in DEC, don't have override in DSC file\r
5644e5ce 1395 for Pcd in self.DecPcds:\r
0d1f5b2b 1396 if isinstance(self._DecPcds[Pcd], StructurePcd):\r
ae7b6df8
LG
1397 if Pcd not in S_pcd_set:\r
1398 str_pcd_obj_str = StructurePcd()\r
1399 str_pcd_obj_str.copy(self._DecPcds[Pcd])\r
1400 str_pcd_obj = Pcds.get(Pcd, None)\r
1401 if str_pcd_obj:\r
1402 str_pcd_obj_str.copy(str_pcd_obj)\r
77204d60
FB
1403 if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
1404 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
1405 else:\r
1406 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
1407 S_pcd_set[Pcd] = str_pcd_obj_str\r
1408 if S_pcd_set:\r
1409 GlobalData.gStructurePcd[self.Arch] = S_pcd_set\r
8518bf0b 1410 for stru_pcd in S_pcd_set.values():\r
67e63e9a
LG
1411 for skuid in SkuIds:\r
1412 if skuid in stru_pcd.SkuOverrideValues:\r
1413 continue\r
1414 nextskuid = self.SkuIdMgr.GetNextSkuId(skuid)\r
1415 NoDefault = False\r
f3b31433
FB
1416 if skuid not in stru_pcd.SkuOverrideValues:\r
1417 while nextskuid not in stru_pcd.SkuOverrideValues:\r
55c84777 1418 if nextskuid == TAB_DEFAULT:\r
f3b31433
FB
1419 NoDefault = True\r
1420 break\r
1421 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
4d3b9389 1422 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 1423 if not NoDefault:\r
ccaa7754 1424 stru_pcd.ValueChain.add((skuid, ''))\r
8518bf0b
LG
1425 if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
1426 for skuid in SkuIds:\r
1427 nextskuid = skuid\r
2b8a6c44 1428 NoDefault = False\r
8518bf0b
LG
1429 if skuid not in stru_pcd.SkuOverrideValues:\r
1430 while nextskuid not in stru_pcd.SkuOverrideValues:\r
55c84777 1431 if nextskuid == TAB_DEFAULT:\r
2b8a6c44
LG
1432 NoDefault = True\r
1433 break\r
8518bf0b 1434 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
2b8a6c44
LG
1435 if NoDefault:\r
1436 continue\r
c5c7e68a 1437 PcdDefaultStoreSet = set(defaultstorename for defaultstorename in stru_pcd.SkuOverrideValues[nextskuid])\r
8518bf0b 1438 mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)\r
2b8a6c44 1439\r
8518bf0b
LG
1440 for defaultstoreid in DefaultStores:\r
1441 if defaultstoreid not in stru_pcd.SkuOverrideValues[skuid]:\r
2b8a6c44 1442 stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename])\r
ccaa7754 1443 stru_pcd.ValueChain.add((skuid, defaultstoreid))\r
543f5ac3
B
1444 S_pcd_set = DscBuildData.OverrideByFdf(S_pcd_set,self.WorkspaceDir)\r
1445 S_pcd_set = DscBuildData.OverrideByComm(S_pcd_set)\r
ae7b6df8
LG
1446 Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set)\r
1447 if Str_Pcd_Values:\r
ccaa7754 1448 for (skuname, StoreName, PcdGuid, PcdName, PcdValue) in Str_Pcd_Values:\r
8518bf0b 1449 str_pcd_obj = S_pcd_set.get((PcdName, PcdGuid))\r
ae7b6df8 1450 if str_pcd_obj is None:\r
72443dd2 1451 print(PcdName, PcdGuid)\r
ae7b6df8
LG
1452 raise\r
1453 if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
1454 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
8518bf0b
LG
1455 if skuname not in str_pcd_obj.SkuInfoList:\r
1456 str_pcd_obj.SkuInfoList[skuname] = SkuInfoClass(SkuIdName=skuname, SkuId=self.SkuIds[skuname][0], HiiDefaultValue=PcdValue, DefaultStore = {StoreName:PcdValue})\r
ae7b6df8 1457 else:\r
8518bf0b
LG
1458 str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue = PcdValue\r
1459 str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.update({StoreName:PcdValue})\r
ae7b6df8
LG
1460 elif str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
1461 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
55c84777 1462 if skuname in (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT, TAB_COMMON):\r
8518bf0b 1463 str_pcd_obj.DefaultValue = PcdValue\r
ae7b6df8 1464 else:\r
8518bf0b 1465 if skuname not in str_pcd_obj.SkuInfoList:\r
65eff519
LG
1466 nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)\r
1467 NoDefault = False\r
1468 while nextskuid not in str_pcd_obj.SkuInfoList:\r
55c84777 1469 if nextskuid == TAB_DEFAULT:\r
65eff519
LG
1470 NoDefault = True\r
1471 break\r
1472 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
1473 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
1474 str_pcd_obj.SkuInfoList[skuname].SkuId = self.SkuIds[skuname][0]\r
1475 str_pcd_obj.SkuInfoList[skuname].SkuIdName = skuname\r
ae7b6df8 1476 else:\r
8518bf0b
LG
1477 str_pcd_obj.SkuInfoList[skuname].DefaultValue = PcdValue\r
1478 for str_pcd_obj in S_pcd_set.values():\r
1479 if str_pcd_obj.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
1480 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
1481 continue\r
c5c7e68a 1482 PcdDefaultStoreSet = set(defaultstorename for skuobj in str_pcd_obj.SkuInfoList.values() for defaultstorename in skuobj.DefaultStoreDict)\r
8518bf0b
LG
1483 DefaultStoreObj = DefaultStore(self._GetDefaultStores())\r
1484 mindefaultstorename = DefaultStoreObj.GetMin(PcdDefaultStoreSet)\r
1485 str_pcd_obj.SkuInfoList[self.SkuIdMgr.SystemSkuId].HiiDefaultValue = str_pcd_obj.SkuInfoList[self.SkuIdMgr.SystemSkuId].DefaultStoreDict[mindefaultstorename]\r
ae7b6df8
LG
1486\r
1487 for str_pcd_obj in S_pcd_set.values():\r
2b8a6c44 1488\r
ae7b6df8
LG
1489 str_pcd_obj.MaxDatumSize = self.GetStructurePcdMaxSize(str_pcd_obj)\r
1490 Pcds[str_pcd_obj.TokenCName, str_pcd_obj.TokenSpaceGuidCName] = str_pcd_obj\r
1491\r
65eff519
LG
1492 for pcdkey in Pcds:\r
1493 pcd = Pcds[pcdkey]\r
55c84777
CJ
1494 if TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
1495 pcd.SkuInfoList[TAB_DEFAULT] = pcd.SkuInfoList[TAB_COMMON]\r
1496 del pcd.SkuInfoList[TAB_COMMON]\r
1497 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
1498 del pcd.SkuInfoList[TAB_COMMON]\r
65eff519 1499\r
ccaa7754 1500 map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])\r
ae7b6df8
LG
1501 return Pcds\r
1502\r
1503 ## Retrieve non-dynamic PCD settings\r
1504 #\r
1505 # @param Type PCD type\r
1506 #\r
1507 # @retval a dict object contains settings of given PCD type\r
1508 #\r
1509 def _GetPcd(self, Type):\r
a0767bae 1510 Pcds = OrderedDict()\r
ae7b6df8
LG
1511 #\r
1512 # tdict is a special dict kind of type, used for selecting correct\r
1513 # PCD settings for certain ARCH\r
1514 #\r
2b8a6c44 1515 AvailableSkuIdSet = copy.copy(self.SkuIds)\r
ae7b6df8
LG
1516\r
1517 PcdDict = tdict(True, 3)\r
1518 PcdSet = set()\r
1519 # Find out all possible PCD candidates for self._Arch\r
1520 RecordList = self._RawData[Type, self._Arch]\r
a0767bae 1521 PcdValueDict = OrderedDict()\r
ccaa7754 1522 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4, Dummy5 in RecordList:\r
2b8a6c44 1523 SkuName = SkuName.upper()\r
55c84777 1524 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
2b8a6c44
LG
1525 if SkuName not in AvailableSkuIdSet:\r
1526 EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
1527 File=self.MetaFile, Line=Dummy5)\r
55c84777 1528 if SkuName in (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT, TAB_COMMON):\r
8518bf0b 1529 if "." not in TokenSpaceGuid:\r
5db9414c 1530 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5))\r
ae7b6df8 1531 PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting\r
ae7b6df8
LG
1532\r
1533 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet:\r
1534 Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName]\r
4231a819 1535 if Setting is None:\r
ae7b6df8
LG
1536 continue\r
1537 PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
1538 if (PcdCName, TokenSpaceGuid) in PcdValueDict:\r
1539 PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue, DatumType, MaxDatumSize)\r
1540 else:\r
1541 PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, DatumType, MaxDatumSize)}\r
1542\r
ccaa7754 1543 for ((PcdCName, TokenSpaceGuid), PcdSetting) in PcdValueDict.iteritems():\r
ae7b6df8
LG
1544 PcdValue = None\r
1545 DatumType = None\r
1546 MaxDatumSize = None\r
55c84777
CJ
1547 if TAB_COMMON in PcdSetting:\r
1548 PcdValue, DatumType, MaxDatumSize = PcdSetting[TAB_COMMON]\r
1549 if TAB_DEFAULT in PcdSetting:\r
1550 PcdValue, DatumType, MaxDatumSize = PcdSetting[TAB_DEFAULT]\r
8518bf0b
LG
1551 if self.SkuIdMgr.SystemSkuId in PcdSetting:\r
1552 PcdValue, DatumType, MaxDatumSize = PcdSetting[self.SkuIdMgr.SystemSkuId]\r
ae7b6df8
LG
1553\r
1554 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
1555 PcdCName,\r
1556 TokenSpaceGuid,\r
1557 self._PCD_TYPE_STRING_[Type],\r
1558 DatumType,\r
1559 PcdValue,\r
1560 '',\r
1561 MaxDatumSize,\r
1562 {},\r
1563 False,\r
1564 None,\r
1565 IsDsc=True)\r
1566\r
1567\r
1568 return Pcds\r
1569\r
1570 def GetStructurePcdMaxSize(self, str_pcd):\r
1571 pcd_default_value = str_pcd.DefaultValue\r
1572 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
1573 sku_values.append(pcd_default_value)\r
1574\r
1575 def get_length(value):\r
1576 Value = value.strip()\r
a0939593 1577 if len(value) > 1:\r
91fa33ee 1578 if Value.startswith(TAB_GUID) and Value.endswith(')'):\r
a0939593
LG
1579 return 16\r
1580 if Value.startswith('L"') and Value.endswith('"'):\r
1581 return len(Value[2:-1])\r
1582 if Value[0] == '"' and Value[-1] == '"':\r
1583 return len(Value) - 2\r
1584 if Value[0] == '{' and Value[-1] == '}':\r
1585 return len(Value.split(","))\r
1586 if Value.startswith("L'") and Value.endswith("'") and len(list(Value[2:-1])) > 1:\r
1587 return len(list(Value[2:-1]))\r
1588 if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1:\r
1589 return len(Value) - 2\r
ae7b6df8
LG
1590 return len(Value)\r
1591\r
8252e6bf 1592 return str(max(get_length(item) for item in sku_values))\r
ae7b6df8 1593\r
9e508f3a
CJ
1594 @staticmethod\r
1595 def ExecuteCommand (Command):\r
ae7b6df8
LG
1596 try:\r
1597 Process = subprocess.Popen(Command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\r
1598 except:\r
5db9414c 1599 EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % Command)\r
ae7b6df8 1600 Result = Process.communicate()\r
5db9414c 1601 return Process.returncode, Result[0], Result[1]\r
ae7b6df8 1602\r
9e508f3a
CJ
1603 @staticmethod\r
1604 def IntToCString(Value, ValueSize):\r
ae7b6df8
LG
1605 Result = '"'\r
1606 if not isinstance (Value, str):\r
1607 for Index in range(0, ValueSize):\r
1608 Result = Result + '\\x%02x' % (Value & 0xff)\r
1609 Value = Value >> 8\r
1610 Result = Result + '"'\r
1611 return Result\r
1612\r
ccaa7754 1613 def GenerateSizeFunction(self, Pcd):\r
79820e32
B
1614 CApp = "// Default Value in Dec \n"\r
1615 CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1616 for FieldList in [Pcd.DefaultValues]:\r
1617 if not FieldList:\r
1618 continue\r
1619 for FieldName in FieldList:\r
1620 FieldName = "." + FieldName\r
8565b582 1621 IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
79820e32
B
1622 if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):\r
1623 try:\r
656d2539 1624 Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], TAB_VOID, self._GuidDict)(True)\r
79820e32
B
1625 except BadExpression:\r
1626 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1627 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))\r
1628 Value, ValueSize = ParseFieldValue(Value)\r
1629 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
1630 else:\r
1631 NewFieldName = ''\r
1632 FieldName_ori = FieldName.strip('.')\r
1633 while '[' in FieldName:\r
1634 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
1635 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
1636 FieldName = FieldName.split(']', 1)[1]\r
1637 FieldName = NewFieldName + FieldName\r
1638 while '[' in FieldName:\r
1639 FieldName = FieldName.rsplit('[', 1)[0]\r
1640 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
1641 for skuname in Pcd.SkuOverrideValues:\r
55c84777 1642 if skuname == TAB_COMMON:\r
79820e32
B
1643 continue\r
1644 for defaultstorenameitem in Pcd.SkuOverrideValues[skuname]:\r
1645 CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)\r
1646 for FieldList in [Pcd.SkuOverrideValues[skuname].get(defaultstorenameitem)]:\r
1647 if not FieldList:\r
1648 continue\r
1649 for FieldName in FieldList:\r
1650 FieldName = "." + FieldName\r
8565b582 1651 IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
79820e32
B
1652 if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):\r
1653 try:\r
656d2539 1654 Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], TAB_VOID, self._GuidDict)(True)\r
79820e32
B
1655 except BadExpression:\r
1656 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1657 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))\r
1658 Value, ValueSize = ParseFieldValue(Value)\r
1659 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
1660 else:\r
1661 NewFieldName = ''\r
1662 FieldName_ori = FieldName.strip('.')\r
1663 while '[' in FieldName:\r
1664 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
1665 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
1666 FieldName = FieldName.split(']', 1)[1]\r
1667 FieldName = NewFieldName + FieldName\r
1668 while '[' in FieldName:\r
1669 FieldName = FieldName.rsplit('[', 1)[0]\r
1670 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
543f5ac3
B
1671 if Pcd.PcdFieldValueFromFdf:\r
1672 CApp = CApp + "// From fdf \n"\r
1673 for FieldName in Pcd.PcdFieldValueFromFdf:\r
1674 FieldName = "." + FieldName\r
1675 IsArray = IsFieldValueAnArray(Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0])\r
1676 if IsArray and not (Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0].startswith('{GUID') and Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0].endswith('}')):\r
1677 try:\r
1678 Value = ValueExpressionEx(Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0], TAB_VOID, self._GuidDict)(True)\r
1679 except BadExpression:\r
1680 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1681 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2]))\r
1682 Value, ValueSize = ParseFieldValue(Value)\r
1683 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.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0]);\r
1684 else:\r
1685 NewFieldName = ''\r
1686 FieldName_ori = FieldName.strip('.')\r
1687 while '[' in FieldName:\r
1688 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
1689 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
1690 FieldName = FieldName.split(']', 1)[1]\r
1691 FieldName = NewFieldName + FieldName\r
1692 while '[' in FieldName:\r
1693 FieldName = FieldName.rsplit('[', 1)[0]\r
1694 CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %s Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromFdf[FieldName_ori][1], Pcd.PcdFieldValueFromFdf[FieldName_ori][2], Pcd.PcdFieldValueFromFdf[FieldName_ori][0])\r
b854e2bf
B
1695 if Pcd.PcdFieldValueFromComm:\r
1696 CApp = CApp + "// From Command Line \n"\r
1697 for FieldName in Pcd.PcdFieldValueFromComm:\r
1698 FieldName = "." + FieldName\r
8565b582 1699 IsArray = IsFieldValueAnArray(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0])\r
1667eec6 1700 if IsArray and not (Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].startswith('{GUID') and Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].endswith('}')):\r
b854e2bf 1701 try:\r
656d2539 1702 Value = ValueExpressionEx(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0], TAB_VOID, self._GuidDict)(True)\r
b854e2bf
B
1703 except BadExpression:\r
1704 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1667eec6 1705 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2]))\r
b854e2bf 1706 Value, ValueSize = ParseFieldValue(Value)\r
1667eec6 1707 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
1708 else:\r
1709 NewFieldName = ''\r
1710 FieldName_ori = FieldName.strip('.')\r
1711 while '[' in FieldName:\r
1712 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
1713 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
1714 FieldName = FieldName.split(']', 1)[1]\r
1715 FieldName = NewFieldName + FieldName\r
1716 while '[' in FieldName:\r
1717 FieldName = FieldName.rsplit('[', 1)[0]\r
1667eec6 1718 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 1719 CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize())\r
79820e32
B
1720 CApp = CApp + "}\n"\r
1721 return CApp\r
9e508f3a
CJ
1722\r
1723 @staticmethod\r
1724 def GenerateSizeStatments(Pcd):\r
79820e32
B
1725 CApp = ' Size = sizeof(%s);\n' % (Pcd.DatumType)\r
1726 CApp = CApp + ' Cal_%s_%s_Size(&Size);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1727 return CApp\r
9e508f3a 1728\r
ccaa7754 1729 def GenerateDefaultValueAssignFunction(self, Pcd):\r
79820e32 1730 CApp = "// Default value in Dec \n"\r
ccaa7754 1731 CApp = CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumType)\r
79820e32
B
1732 CApp = CApp + ' UINT32 FieldSize;\n'\r
1733 CApp = CApp + ' CHAR8 *Value;\n'\r
1734 DefaultValueFromDec = Pcd.DefaultValueFromDec\r
8565b582 1735 IsArray = IsFieldValueAnArray(Pcd.DefaultValueFromDec)\r
79820e32
B
1736 if IsArray:\r
1737 try:\r
656d2539 1738 DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, TAB_VOID)(True)\r
79820e32
B
1739 except BadExpression:\r
1740 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" %\r
1741 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))\r
0f228f19 1742 DefaultValueFromDec = StringToArray(DefaultValueFromDec)\r
79820e32
B
1743 Value, ValueSize = ParseFieldValue (DefaultValueFromDec)\r
1744 if isinstance(Value, str):\r
1745 CApp = CApp + ' Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)\r
1746 elif IsArray:\r
1747 #\r
1748 # Use memcpy() to copy value into field\r
1749 #\r
9e508f3a 1750 CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)\r
79820e32
B
1751 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
1752 for FieldList in [Pcd.DefaultValues]:\r
1753 if not FieldList:\r
1754 continue\r
1755 for FieldName in FieldList:\r
8565b582 1756 IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
79820e32
B
1757 if IsArray:\r
1758 try:\r
656d2539 1759 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
79820e32
B
1760 except BadExpression:\r
1761 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
ccaa7754 1762 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
79820e32
B
1763\r
1764 try:\r
1765 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
1766 except Exception:\r
ccaa7754 1767 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
1768 if isinstance(Value, str):\r
1769 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1770 elif IsArray:\r
1771 #\r
1772 # Use memcpy() to copy value into field\r
1773 #\r
1774 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
9e508f3a 1775 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
1776 CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
1777 else:\r
1778 if ValueSize > 4:\r
1779 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1780 else:\r
1781 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
1782 CApp = CApp + "}\n"\r
1783 return CApp\r
9e508f3a
CJ
1784\r
1785 @staticmethod\r
1786 def GenerateDefaultValueAssignStatement(Pcd):\r
f3b31433
FB
1787 CApp = ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1788 return CApp\r
9e508f3a 1789\r
ccaa7754
GL
1790 def GenerateInitValueFunction(self, Pcd, SkuName, DefaultStoreName):\r
1791 CApp = "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName, DefaultStoreName)\r
1792 CApp = CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, SkuName, DefaultStoreName, Pcd.DatumType)\r
f3b31433
FB
1793 CApp = CApp + ' UINT32 FieldSize;\n'\r
1794 CApp = CApp + ' CHAR8 *Value;\n'\r
1795\r
55c84777 1796 CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT)\r
f3b31433 1797 inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName]\r
ccaa7754
GL
1798 if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT):\r
1799 pcddefaultvalue = Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue\r
f3b31433 1800 else:\r
f832bb34
FB
1801 if not Pcd.DscRawValue:\r
1802 # handle the case that structure pcd is not appear in DSC\r
1803 self.CopyDscRawValue(Pcd)\r
ccaa7754
GL
1804 pcddefaultvalue = Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName)\r
1805 for FieldList in [pcddefaultvalue, inherit_OverrideValues.get(DefaultStoreName)]:\r
79820e32
B
1806 if not FieldList:\r
1807 continue\r
1808 if pcddefaultvalue and FieldList == pcddefaultvalue:\r
8565b582 1809 IsArray = IsFieldValueAnArray(FieldList)\r
79820e32
B
1810 if IsArray:\r
1811 try:\r
656d2539 1812 FieldList = ValueExpressionEx(FieldList, TAB_VOID)(True)\r
79820e32
B
1813 except BadExpression:\r
1814 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" %\r
1815 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))\r
1816 Value, ValueSize = ParseFieldValue (FieldList)\r
f3b31433 1817\r
ccaa7754 1818 if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT):\r
f3b31433 1819 if isinstance(Value, str):\r
ccaa7754 1820 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
1821 elif IsArray:\r
1822 #\r
1823 # Use memcpy() to copy value into field\r
1824 #\r
ccaa7754 1825 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
1826 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
1827 else:\r
1828 if isinstance(Value, str):\r
ccaa7754 1829 CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName))\r
f3b31433
FB
1830 elif IsArray:\r
1831 #\r
1832 # Use memcpy() to copy value into field\r
1833 #\r
ccaa7754 1834 CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName))\r
f3b31433 1835 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
79820e32 1836 continue\r
ccaa7754 1837 if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT) or (( (SkuName, '') not in Pcd.ValueChain) and ( (SkuName, DefaultStoreName) not in Pcd.ValueChain )):\r
f3b31433 1838 for FieldName in FieldList:\r
8565b582 1839 IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
f3b31433
FB
1840 if IsArray:\r
1841 try:\r
656d2539 1842 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
f3b31433
FB
1843 except BadExpression:\r
1844 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1845 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
79820e32 1846 try:\r
f3b31433
FB
1847 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
1848 except Exception:\r
ccaa7754 1849 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
1850 if isinstance(Value, str):\r
1851 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1852 elif IsArray:\r
1853 #\r
1854 # Use memcpy() to copy value into field\r
1855 #\r
1856 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
9e508f3a 1857 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 1858 CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
79820e32 1859 else:\r
f3b31433
FB
1860 if ValueSize > 4:\r
1861 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1862 else:\r
1863 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
1864 CApp = CApp + "}\n"\r
1865 return CApp\r
9e508f3a
CJ
1866\r
1867 @staticmethod\r
ccaa7754
GL
1868 def GenerateInitValueStatement(Pcd, SkuName, DefaultStoreName):\r
1869 CApp = ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, SkuName, DefaultStoreName)\r
79820e32 1870 return CApp\r
9e508f3a 1871\r
ccaa7754 1872 def GenerateCommandLineValue(self, Pcd):\r
b854e2bf 1873 CApp = "// Value in CommandLine\n"\r
ccaa7754 1874 CApp = CApp + "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumType)\r
b854e2bf
B
1875 CApp = CApp + ' UINT32 FieldSize;\n'\r
1876 CApp = CApp + ' CHAR8 *Value;\n'\r
1877\r
1878 pcddefaultvalue = Pcd.PcdValueFromComm\r
ccaa7754 1879 for FieldList in [pcddefaultvalue, Pcd.PcdFieldValueFromComm]:\r
b854e2bf
B
1880 if not FieldList:\r
1881 continue\r
1882 if pcddefaultvalue and FieldList == pcddefaultvalue:\r
8565b582 1883 IsArray = IsFieldValueAnArray(FieldList)\r
b854e2bf
B
1884 if IsArray:\r
1885 try:\r
656d2539 1886 FieldList = ValueExpressionEx(FieldList, TAB_VOID)(True)\r
b854e2bf 1887 except BadExpression:\r
0f228f19 1888 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from Command: %s" %\r
b854e2bf
B
1889 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))\r
1890 Value, ValueSize = ParseFieldValue (FieldList)\r
1891\r
1892 if isinstance(Value, str):\r
1893 CApp = CApp + ' Pcd = %s; // From Command Line \n' % (Value)\r
1894 elif IsArray:\r
1895 #\r
1896 # Use memcpy() to copy value into field\r
1897 #\r
9e508f3a 1898 CApp = CApp + ' Value = %s; // From Command Line.\n' % (DscBuildData.IntToCString(Value, ValueSize))\r
b854e2bf
B
1899 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
1900 continue\r
1901 for FieldName in FieldList:\r
8565b582 1902 IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
b854e2bf
B
1903 if IsArray:\r
1904 try:\r
656d2539 1905 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
b854e2bf
B
1906 except BadExpression:\r
1907 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1908 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
1909 except:\r
72443dd2 1910 print("error")\r
b854e2bf
B
1911 try:\r
1912 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
1913 except Exception:\r
ccaa7754 1914 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
1915 if isinstance(Value, str):\r
1916 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1917 elif IsArray:\r
1918 #\r
1919 # Use memcpy() to copy value into field\r
1920 #\r
1921 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
9e508f3a 1922 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
1923 CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
1924 else:\r
1925 if ValueSize > 4:\r
1926 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1927 else:\r
1928 CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1929 CApp = CApp + "}\n"\r
1930 return CApp\r
9e508f3a
CJ
1931\r
1932 @staticmethod\r
1933 def GenerateCommandLineValueStatement(Pcd):\r
b854e2bf
B
1934 CApp = ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1935 return CApp\r
543f5ac3
B
1936 def GenerateFdfValue(self,Pcd):\r
1937 CApp = "// Value in Fdf\n"\r
1938 CApp = CApp + "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType)\r
1939 CApp = CApp + ' UINT32 FieldSize;\n'\r
1940 CApp = CApp + ' CHAR8 *Value;\n'\r
1941\r
1942 pcddefaultvalue = Pcd.PcdValueFromFdf\r
1943 for FieldList in [pcddefaultvalue,Pcd.PcdFieldValueFromFdf]:\r
1944 if not FieldList:\r
1945 continue\r
1946 if pcddefaultvalue and FieldList == pcddefaultvalue:\r
1947 IsArray = IsFieldValueAnArray(FieldList)\r
1948 if IsArray:\r
1949 try:\r
1950 FieldList = ValueExpressionEx(FieldList, TAB_VOID)(True)\r
1951 except BadExpression:\r
1952 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from Fdf: %s" %\r
1953 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))\r
1954 Value, ValueSize = ParseFieldValue (FieldList)\r
1955\r
1956 if isinstance(Value, str):\r
1957 CApp = CApp + ' Pcd = %s; // From Fdf \n' % (Value)\r
1958 elif IsArray:\r
1959 #\r
1960 # Use memcpy() to copy value into field\r
1961 #\r
1962 CApp = CApp + ' Value = %s; // From Fdf .\n' % (DscBuildData.IntToCString(Value, ValueSize))\r
1963 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
1964 continue\r
1965 for FieldName in FieldList:\r
1966 IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
1967 if IsArray:\r
1968 try:\r
1969 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
1970 except BadExpression:\r
1971 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
1972 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
1973 except:\r
1974 print("error")\r
1975 try:\r
1976 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
1977 except Exception:\r
1978 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
1979 if isinstance(Value, str):\r
1980 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1981 elif IsArray:\r
1982 #\r
1983 # Use memcpy() to copy value into field\r
1984 #\r
1985 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
1986 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
1987 CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
1988 else:\r
1989 if ValueSize > 4:\r
1990 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1991 else:\r
1992 CApp = CApp + ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
1993 CApp = CApp + "}\n"\r
1994 return CApp\r
1995\r
1996 @staticmethod\r
1997 def GenerateFdfValueStatement(Pcd):\r
1998 CApp = ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
1999 return CApp\r
9e508f3a 2000\r
f3b31433
FB
2001 def GenerateInitializeFunc(self, SkuName, DefaultStore, Pcd, InitByteValue, CApp):\r
2002 OverrideValues = {DefaultStore:""}\r
ae7b6df8
LG
2003 if Pcd.SkuOverrideValues:\r
2004 OverrideValues = Pcd.SkuOverrideValues[SkuName]\r
5a693b89 2005 for DefaultStoreName in OverrideValues:\r
8518bf0b
LG
2006 CApp = CApp + 'void\n'\r
2007 CApp = CApp + 'Initialize_%s_%s_%s_%s(\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
2008 CApp = CApp + ' void\n'\r
2009 CApp = CApp + ' )\n'\r
2010 CApp = CApp + '{\n'\r
2011 CApp = CApp + ' UINT32 Size;\n'\r
2012 CApp = CApp + ' UINT32 FieldSize;\n'\r
b2395724 2013 CApp = CApp + ' CHAR8 *Value;\n'\r
8518bf0b
LG
2014 CApp = CApp + ' UINT32 OriginalSize;\n'\r
2015 CApp = CApp + ' VOID *OriginalPcd;\n'\r
6a103440 2016 CApp = CApp + ' %s *Pcd; // From %s Line %d \n' % (Pcd.DatumType, Pcd.PkgPath, Pcd.PcdDefineLineNo)\r
8518bf0b 2017 CApp = CApp + '\n'\r
47854fd5 2018\r
8e011d83 2019 if SkuName in Pcd.SkuInfoList:\r
ccaa7754 2020 DefaultValue = Pcd.SkuInfoList[SkuName].DefaultStoreDict.get(DefaultStoreName, Pcd.SkuInfoList[SkuName].HiiDefaultValue if Pcd.SkuInfoList[SkuName].HiiDefaultValue else Pcd.SkuInfoList[SkuName].DefaultValue)\r
8e011d83
FB
2021 else:\r
2022 DefaultValue = Pcd.DefaultValue\r
2023 PcdDefaultValue = StringToArray(DefaultValue.strip())\r
47854fd5 2024\r
8518bf0b 2025 InitByteValue += '%s.%s.%s.%s|%s|%s\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumType, PcdDefaultValue)\r
ae7b6df8 2026\r
8518bf0b
LG
2027 #\r
2028 # Get current PCD value and size\r
2029 #\r
2030 CApp = CApp + ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
ae7b6df8 2031\r
8518bf0b
LG
2032 #\r
2033 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides\r
2034 # the correct value. For structures with a flexible array member, the flexible\r
2035 # array member is detected, and the size is based on the highest index used with\r
2036 # the flexible array member. The flexible array member must be the last field\r
2037 # in a structure. The size formula for this case is:\r
2038 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)\r
2039 #\r
9e508f3a 2040 CApp = CApp + DscBuildData.GenerateSizeStatments(Pcd)\r
ae7b6df8 2041\r
8518bf0b
LG
2042 #\r
2043 # Allocate and zero buffer for the PCD\r
2044 # Must handle cases where current value is smaller, larger, or same size\r
2045 # Always keep that larger one as the current size\r
2046 #\r
2047 CApp = CApp + ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'\r
2048 CApp = CApp + ' Pcd = (%s *)malloc (Size);\n' % (Pcd.DatumType)\r
2049 CApp = CApp + ' memset (Pcd, 0, Size);\n'\r
ae7b6df8 2050\r
8518bf0b
LG
2051 #\r
2052 # Copy current PCD value into allocated buffer.\r
2053 #\r
2054 CApp = CApp + ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'\r
ae7b6df8 2055\r
8518bf0b
LG
2056 #\r
2057 # Assign field values in PCD\r
2058 #\r
9e508f3a 2059 CApp = CApp + DscBuildData.GenerateDefaultValueAssignStatement(Pcd)\r
f3b31433
FB
2060 if Pcd.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
2061 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
2062 for skuname in self.SkuIdMgr.GetSkuChain(SkuName):\r
4d3b9389 2063 storeset = [DefaultStoreName] if DefaultStoreName == TAB_DEFAULT_STORES_DEFAULT else [TAB_DEFAULT_STORES_DEFAULT, DefaultStoreName]\r
f3b31433
FB
2064 for defaultstorenameitem in storeset:\r
2065 CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)\r
ccaa7754 2066 CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd, skuname, defaultstorenameitem)\r
f3b31433
FB
2067 if skuname == SkuName:\r
2068 break\r
2069 else:\r
f832bb34 2070 CApp = CApp + "// SkuName: %s, DefaultStoreName: STANDARD \n" % self.SkuIdMgr.SystemSkuId\r
ccaa7754 2071 CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd, self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)\r
543f5ac3 2072 CApp = CApp + DscBuildData.GenerateFdfValueStatement(Pcd)\r
9e508f3a 2073 CApp = CApp + DscBuildData.GenerateCommandLineValueStatement(Pcd)\r
8518bf0b
LG
2074 #\r
2075 # Set new PCD value and size\r
2076 #\r
2077 CApp = CApp + ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
ae7b6df8 2078\r
8518bf0b
LG
2079 #\r
2080 # Free PCD\r
2081 #\r
2082 CApp = CApp + ' free (Pcd);\n'\r
2083 CApp = CApp + '}\n'\r
2084 CApp = CApp + '\n'\r
ae7b6df8
LG
2085 return InitByteValue, CApp\r
2086\r
2087 def GenerateByteArrayValue (self, StructuredPcds):\r
2088 #\r
2089 # Generate/Compile/Run C application to determine if there are any flexible array members\r
2090 #\r
2091 if not StructuredPcds:\r
2092 return\r
2093\r
2094 InitByteValue = ""\r
2095 CApp = PcdMainCHeader\r
2096\r
34d808ad 2097 IncludeFiles = set()\r
ae7b6df8
LG
2098 for PcdName in StructuredPcds:\r
2099 Pcd = StructuredPcds[PcdName]\r
81add864 2100 for IncludeFile in Pcd.StructuredPcdIncludeFile:\r
1d5fde83 2101 if IncludeFile not in IncludeFiles:\r
34d808ad 2102 IncludeFiles.add(IncludeFile)\r
81add864 2103 CApp = CApp + '#include <%s>\n' % (IncludeFile)\r
ae7b6df8 2104 CApp = CApp + '\n'\r
ae7b6df8
LG
2105 for PcdName in StructuredPcds:\r
2106 Pcd = StructuredPcds[PcdName]\r
79820e32
B
2107 CApp = CApp + self.GenerateSizeFunction(Pcd)\r
2108 CApp = CApp + self.GenerateDefaultValueAssignFunction(Pcd)\r
543f5ac3 2109 CApp = CApp + self.GenerateFdfValue(Pcd)\r
b854e2bf 2110 CApp = CApp + self.GenerateCommandLineValue(Pcd)\r
f3b31433
FB
2111 if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
2112 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
ccaa7754 2113 CApp = CApp + self.GenerateInitValueFunction(Pcd, self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)\r
f3b31433
FB
2114 else:\r
2115 for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
2116 if SkuName not in Pcd.SkuOverrideValues:\r
2117 continue\r
2118 for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:\r
ccaa7754 2119 CApp = CApp + self.GenerateInitValueFunction(Pcd, SkuName, DefaultStoreName)\r
0a57a978
FB
2120 if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
2121 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
4d3b9389 2122 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd, InitByteValue, CApp)\r
ae7b6df8 2123 else:\r
c05c2c05
LG
2124 for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
2125 if SkuName not in Pcd.SkuOverrideValues:\r
2126 continue\r
ae7b6df8
LG
2127 for DefaultStoreName in Pcd.DefaultStoreName:\r
2128 Pcd = StructuredPcds[PcdName]\r
2129 InitByteValue, CApp = self.GenerateInitializeFunc(SkuName, DefaultStoreName, Pcd, InitByteValue, CApp)\r
2130\r
2131 CApp = CApp + 'VOID\n'\r
2132 CApp = CApp + 'PcdEntryPoint(\n'\r
2133 CApp = CApp + ' VOID\n'\r
2134 CApp = CApp + ' )\n'\r
2135 CApp = CApp + '{\n'\r
2136 for Pcd in StructuredPcds.values():\r
ccaa7754 2137 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 2138 CApp = CApp + ' Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
ae7b6df8 2139 else:\r
c05c2c05
LG
2140 for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
2141 if SkuName not in Pcd.SkuOverrideValues:\r
2142 continue\r
8518bf0b 2143 for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:\r
ae7b6df8
LG
2144 CApp = CApp + ' Initialize_%s_%s_%s_%s();\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
2145 CApp = CApp + '}\n'\r
2146\r
2147 CApp = CApp + PcdMainCEntry + '\n'\r
2148\r
2149 if not os.path.exists(self.OutputPath):\r
2150 os.makedirs(self.OutputPath)\r
2151 CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)\r
0a57a978 2152 SaveFileOnChange(CAppBaseFileName + '.c', CApp, False)\r
ae7b6df8
LG
2153\r
2154 MakeApp = PcdMakefileHeader\r
2155 if sys.platform == "win32":\r
0a57a978 2156 MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\%s.obj\n' % (self.OutputPath, PcdValueInitName) + 'INC = '\r
ae7b6df8
LG
2157 else:\r
2158 MakeApp = MakeApp + PcdGccMakefile\r
2159 MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o\n' % (self.OutputPath, PcdValueInitName) + \\r
68ba919f 2160 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='\r
ae7b6df8 2161\r
34d808ad 2162 IncSearchList = []\r
ae7b6df8
LG
2163 PlatformInc = {}\r
2164 for Cache in self._Bdb._CACHE_.values():\r
2165 if Cache.MetaFile.Ext.lower() != '.dec':\r
2166 continue\r
2167 if Cache.Includes:\r
2168 if str(Cache.MetaFile.Path) not in PlatformInc:\r
b005802a
LG
2169 PlatformInc[str(Cache.MetaFile.Path)] = []\r
2170 PlatformInc[str(Cache.MetaFile.Path)].append (os.path.dirname(Cache.MetaFile.Path))\r
2171 PlatformInc[str(Cache.MetaFile.Path)].extend (Cache.CommonIncludes)\r
ae7b6df8
LG
2172\r
2173 PcdDependDEC = []\r
2174 for Pcd in StructuredPcds.values():\r
2175 for PackageDec in Pcd.PackageDecs:\r
2176 Package = os.path.normpath(mws.join(GlobalData.gWorkspace, PackageDec))\r
2177 if not os.path.exists(Package):\r
2178 EdkLogger.error('Build', RESOURCE_NOT_AVAILABLE, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
2179 if Package not in PcdDependDEC:\r
2180 PcdDependDEC.append(Package)\r
2181\r
2182 if PlatformInc and PcdDependDEC:\r
2183 for pkg in PcdDependDEC:\r
2184 if pkg in PlatformInc:\r
2185 for inc in PlatformInc[pkg]:\r
2186 MakeApp += '-I' + str(inc) + ' '\r
34d808ad 2187 IncSearchList.append(inc)\r
ae7b6df8 2188 MakeApp = MakeApp + '\n'\r
68ba919f
YZ
2189\r
2190 CC_FLAGS = LinuxCFLAGS\r
2191 if sys.platform == "win32":\r
2192 CC_FLAGS = WindowsCFLAGS\r
2193 BuildOptions = {}\r
2194 for Options in self.BuildOptions:\r
2195 if Options[2] != EDKII_NAME:\r
2196 continue\r
2197 Family = Options[0]\r
2198 if Family and Family != self.ToolChainFamily:\r
2199 continue\r
2200 Target, Tag, Arch, Tool, Attr = Options[1].split("_")\r
2201 if Tool != 'CC':\r
2202 continue\r
2203\r
2204 if Target == "*" or Target == self._Target:\r
2205 if Tag == "*" or Tag == self._Toolchain:\r
2206 if Arch == "*" or Arch == self.Arch:\r
2207 if Tool not in BuildOptions:\r
2208 BuildOptions[Tool] = {}\r
2209 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or self.BuildOptions[Options].startswith('='):\r
2210 BuildOptions[Tool][Attr] = self.BuildOptions[Options]\r
2211 else:\r
2212 # append options for the same tool except PATH\r
2213 if Attr != 'PATH':\r
2214 BuildOptions[Tool][Attr] += " " + self.BuildOptions[Options]\r
2215 else:\r
2216 BuildOptions[Tool][Attr] = self.BuildOptions[Options]\r
2217 if BuildOptions:\r
2218 for Tool in BuildOptions:\r
2219 for Attr in BuildOptions[Tool]:\r
2220 if Attr == "FLAGS":\r
2221 Value = BuildOptions[Tool][Attr]\r
2222 ValueList = Value.split()\r
2223 if ValueList:\r
2224 for Id, Item in enumerate(ValueList):\r
5d9af6a5 2225 if Item in ['-D', '/D', '-U', '/U']:\r
68ba919f
YZ
2226 CC_FLAGS += ' ' + Item\r
2227 if Id + 1 < len(ValueList):\r
2228 CC_FLAGS += ' ' + ValueList[Id + 1]\r
5d9af6a5 2229 elif Item.startswith(('-D', '/D', '-U', '/U')):\r
68ba919f
YZ
2230 CC_FLAGS += ' ' + Item\r
2231 MakeApp += CC_FLAGS\r
2232\r
ae7b6df8
LG
2233 if sys.platform == "win32":\r
2234 MakeApp = MakeApp + PcdMakefileEnd\r
34d808ad
B
2235 MakeApp = MakeApp + '\n'\r
2236 IncludeFileFullPaths = []\r
2237 for includefile in IncludeFiles:\r
2238 for includepath in IncSearchList:\r
ccaa7754 2239 includefullpath = os.path.join(str(includepath), includefile)\r
34d808ad
B
2240 if os.path.exists(includefullpath):\r
2241 IncludeFileFullPaths.append(os.path.normpath(includefullpath))\r
2242 break\r
2243 SearchPathList = []\r
2244 SearchPathList.append(os.path.normpath(mws.join(GlobalData.gWorkspace, "BaseTools/Source/C/Include")))\r
2245 SearchPathList.append(os.path.normpath(mws.join(GlobalData.gWorkspace, "BaseTools/Source/C/Common")))\r
8252e6bf 2246 SearchPathList.extend(str(item) for item in IncSearchList)\r
ccaa7754 2247 IncFileList = GetDependencyList(IncludeFileFullPaths, SearchPathList)\r
34d808ad
B
2248 for include_file in IncFileList:\r
2249 MakeApp += "$(OBJECTS) : %s\n" % include_file\r
ae7b6df8 2250 MakeFileName = os.path.join(self.OutputPath, 'Makefile')\r
34d808ad 2251 MakeApp += "$(OBJECTS) : %s\n" % MakeFileName\r
0a57a978 2252 SaveFileOnChange(MakeFileName, MakeApp, False)\r
ae7b6df8
LG
2253\r
2254 InputValueFile = os.path.join(self.OutputPath, 'Input.txt')\r
2255 OutputValueFile = os.path.join(self.OutputPath, 'Output.txt')\r
0a57a978 2256 SaveFileOnChange(InputValueFile, InitByteValue, False)\r
ae7b6df8
LG
2257\r
2258 PcdValueInitExe = PcdValueInitName\r
2259 if not sys.platform == "win32":\r
2260 PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName)\r
5db9414c 2261 else:\r
0a57a978 2262 PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Bin', 'Win32', PcdValueInitName) +".exe"\r
34d808ad
B
2263\r
2264 Messages = ''\r
2265 if sys.platform == "win32":\r
2266 MakeCommand = 'nmake -f %s' % (MakeFileName)\r
9e508f3a 2267 returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)\r
34d808ad
B
2268 Messages = StdOut\r
2269 else:\r
2270 MakeCommand = 'make -f %s' % (MakeFileName)\r
9e508f3a 2271 returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)\r
34d808ad
B
2272 Messages = StdErr\r
2273 Messages = Messages.split('\n')\r
2274 MessageGroup = []\r
9fb2cbda 2275 if returncode != 0:\r
34d808ad
B
2276 CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)\r
2277 File = open (CAppBaseFileName + '.c', 'r')\r
2278 FileData = File.readlines()\r
2279 File.close()\r
2280 for Message in Messages:\r
2281 if " error" in Message or "warning" in Message:\r
2282 FileInfo = Message.strip().split('(')\r
2283 if len (FileInfo) > 1:\r
2284 FileName = FileInfo [0]\r
2285 FileLine = FileInfo [1].split (')')[0]\r
2286 else:\r
2287 FileInfo = Message.strip().split(':')\r
2288 FileName = FileInfo [0]\r
2289 FileLine = FileInfo [1]\r
2290 if FileLine.isdigit():\r
2291 error_line = FileData[int (FileLine) - 1]\r
2292 if r"//" in error_line:\r
ccaa7754 2293 c_line, dsc_line = error_line.split(r"//")\r
0a57a978 2294 else:\r
34d808ad
B
2295 dsc_line = error_line\r
2296 message_itmes = Message.split(":")\r
2297 Index = 0\r
2298 if "PcdValueInit.c" not in Message:\r
2299 if not MessageGroup:\r
2300 MessageGroup.append(Message)\r
2301 break\r
0a57a978 2302 else:\r
34d808ad
B
2303 for item in message_itmes:\r
2304 if "PcdValueInit.c" in item:\r
2305 Index = message_itmes.index(item)\r
2306 message_itmes[Index] = dsc_line.strip()\r
2307 break\r
2308 MessageGroup.append(":".join(message_itmes[Index:]).strip())\r
2309 continue\r
2310 else:\r
2311 MessageGroup.append(Message)\r
2312 if MessageGroup:\r
2313 EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) )\r
2314 else:\r
2315 EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand)\r
2316\r
ccaa7754 2317 if DscBuildData.NeedUpdateOutput(OutputValueFile, PcdValueInitExe, InputValueFile):\r
0a57a978 2318 Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile)\r
9e508f3a 2319 returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (Command)\r
87d2afd0 2320 if returncode != 0:\r
0a57a978
FB
2321 EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command)\r
2322\r
2323 File = open (OutputValueFile, 'r')\r
2324 FileBuffer = File.readlines()\r
2325 File.close()\r
ae7b6df8
LG
2326\r
2327 StructurePcdSet = []\r
2328 for Pcd in FileBuffer:\r
2329 PcdValue = Pcd.split ('|')\r
2330 PcdInfo = PcdValue[0].split ('.')\r
ccaa7754 2331 StructurePcdSet.append((PcdInfo[0], PcdInfo[1], PcdInfo[2], PcdInfo[3], PcdValue[2].strip()))\r
ae7b6df8
LG
2332 return StructurePcdSet\r
2333\r
9e508f3a
CJ
2334 @staticmethod\r
2335 def NeedUpdateOutput(OutputFile, ValueCFile, StructureInput):\r
0a57a978
FB
2336 if not os.path.exists(OutputFile):\r
2337 return True\r
2338 if os.stat(OutputFile).st_mtime <= os.stat(ValueCFile).st_mtime:\r
2339 return True\r
0a57a978
FB
2340 if os.stat(OutputFile).st_mtime <= os.stat(StructureInput).st_mtime:\r
2341 return True\r
2342 return False\r
2343\r
ae7b6df8
LG
2344 ## Retrieve dynamic PCD settings\r
2345 #\r
2346 # @param Type PCD type\r
2347 #\r
2348 # @retval a dict object contains settings of given PCD type\r
2349 #\r
2350 def _GetDynamicPcd(self, Type):\r
2351\r
ae7b6df8 2352\r
a0767bae 2353 Pcds = OrderedDict()\r
ae7b6df8
LG
2354 #\r
2355 # tdict is a special dict kind of type, used for selecting correct\r
2356 # PCD settings for certain ARCH and SKU\r
2357 #\r
2358 PcdDict = tdict(True, 4)\r
2359 PcdList = []\r
2360 # Find out all possible PCD candidates for self._Arch\r
2361 RecordList = self._RawData[Type, self._Arch]\r
8518bf0b 2362 AvailableSkuIdSet = copy.copy(self.SkuIds)\r
ae7b6df8 2363\r
ae7b6df8 2364\r
ccaa7754 2365 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4, Dummy5 in RecordList:\r
2b8a6c44 2366 SkuName = SkuName.upper()\r
55c84777 2367 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
ae7b6df8 2368 if SkuName not in AvailableSkuIdSet:\r
2b8a6c44
LG
2369 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
2370 File=self.MetaFile, Line=Dummy5)\r
ae7b6df8 2371 if "." not in TokenSpaceGuid:\r
5db9414c 2372 PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))\r
ae7b6df8
LG
2373 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
2374\r
2375 # Remove redundant PCD candidates, per the ARCH and SKU\r
2376 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:\r
2377\r
2378 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]\r
4231a819 2379 if Setting is None:\r
ae7b6df8
LG
2380 continue\r
2381\r
2382 PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
8518bf0b 2383 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '', '', '', '', '', PcdValue)\r
5a693b89 2384 if (PcdCName, TokenSpaceGuid) in Pcds:\r
ae7b6df8
LG
2385 pcdObject = Pcds[PcdCName, TokenSpaceGuid]\r
2386 pcdObject.SkuInfoList[SkuName] = SkuInfo\r
2387 if MaxDatumSize.strip():\r
2388 CurrentMaxSize = int(MaxDatumSize.strip(), 0)\r
2389 else:\r
2390 CurrentMaxSize = 0\r
2391 if pcdObject.MaxDatumSize:\r
2392 PcdMaxSize = int(pcdObject.MaxDatumSize, 0)\r
2393 else:\r
2394 PcdMaxSize = 0\r
2395 if CurrentMaxSize > PcdMaxSize:\r
2396 pcdObject.MaxDatumSize = str(CurrentMaxSize)\r
2397 else:\r
2398 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
2399 PcdCName,\r
2400 TokenSpaceGuid,\r
2401 self._PCD_TYPE_STRING_[Type],\r
2402 DatumType,\r
2403 PcdValue,\r
2404 '',\r
2405 MaxDatumSize,\r
2406 {SkuName : SkuInfo},\r
2407 False,\r
2408 None,\r
2409 IsDsc=True)\r
2410\r
2411 for pcd in Pcds.values():\r
2412 pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
e651d06c
LG
2413 # Only fix the value while no value provided in DSC file.\r
2414 for sku in pcd.SkuInfoList.values():\r
128d435f 2415 if not sku.DefaultValue:\r
e651d06c 2416 sku.DefaultValue = pcdDecObject.DefaultValue\r
55c84777 2417 if TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON not in pcd.SkuInfoList:\r
ae7b6df8 2418 valuefromDec = pcdDecObject.DefaultValue\r
55c84777
CJ
2419 SkuInfo = SkuInfoClass(TAB_DEFAULT, '0', '', '', '', '', '', valuefromDec)\r
2420 pcd.SkuInfoList[TAB_DEFAULT] = SkuInfo\r
2421 elif TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
2422 pcd.SkuInfoList[TAB_DEFAULT] = pcd.SkuInfoList[TAB_COMMON]\r
2423 del pcd.SkuInfoList[TAB_COMMON]\r
2424 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
2425 del pcd.SkuInfoList[TAB_COMMON]\r
65eff519 2426\r
ccaa7754 2427 map(self.FilterSkuSettings, Pcds.values())\r
ae7b6df8
LG
2428\r
2429 return Pcds\r
2430\r
65eff519
LG
2431 def FilterSkuSettings(self, PcdObj):\r
2432\r
2433 if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE:\r
55c84777
CJ
2434 if TAB_DEFAULT in PcdObj.SkuInfoList and self.SkuIdMgr.SystemSkuId not in PcdObj.SkuInfoList:\r
2435 PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId] = PcdObj.SkuInfoList[TAB_DEFAULT]\r
2436 PcdObj.SkuInfoList = {TAB_DEFAULT:PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId]}\r
2437 PcdObj.SkuInfoList[TAB_DEFAULT].SkuIdName = TAB_DEFAULT\r
2438 PcdObj.SkuInfoList[TAB_DEFAULT].SkuId = '0'\r
65eff519
LG
2439\r
2440 elif self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.DEFAULT:\r
55c84777 2441 PcdObj.SkuInfoList = {TAB_DEFAULT:PcdObj.SkuInfoList[TAB_DEFAULT]}\r
65eff519
LG
2442\r
2443 return PcdObj\r
2444\r
9e508f3a
CJ
2445 @staticmethod\r
2446 def CompareVarAttr(Attr1, Attr2):\r
ae7b6df8
LG
2447 if not Attr1 or not Attr2: # for empty string\r
2448 return True\r
2449 Attr1s = [attr.strip() for attr in Attr1.split(",")]\r
2450 Attr1Set = set(Attr1s)\r
2451 Attr2s = [attr.strip() for attr in Attr2.split(",")]\r
2452 Attr2Set = set(Attr2s)\r
2453 if Attr2Set == Attr1Set:\r
2454 return True\r
2455 else:\r
2456 return False\r
9e508f3a 2457\r
ccaa7754 2458 def CopyDscRawValue(self, Pcd):\r
f3b31433
FB
2459 if Pcd.DscRawValue is None:\r
2460 Pcd.DscRawValue = dict()\r
f832bb34
FB
2461 if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
2462 if self.SkuIdMgr.SystemSkuId not in Pcd.DscRawValue:\r
2463 Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId] = {}\r
4d3b9389 2464 Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId][TAB_DEFAULT_STORES_DEFAULT] = Pcd.DefaultValue\r
f3b31433
FB
2465 for skuname in Pcd.SkuInfoList:\r
2466 Pcd.DscRawValue[skuname] = {}\r
2467 if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
2468 for defaultstore in Pcd.SkuInfoList[skuname].DefaultStoreDict:\r
2469 Pcd.DscRawValue[skuname][defaultstore] = Pcd.SkuInfoList[skuname].DefaultStoreDict[defaultstore]\r
2470 else:\r
4d3b9389 2471 Pcd.DscRawValue[skuname][TAB_DEFAULT_STORES_DEFAULT] = Pcd.SkuInfoList[skuname].DefaultValue\r
ccaa7754 2472 def CompletePcdValues(self, PcdSet):\r
8518bf0b
LG
2473 Pcds = {}\r
2474 DefaultStoreObj = DefaultStore(self._GetDefaultStores())\r
ccaa7754 2475 SkuIds = {skuname:skuid for skuname, skuid in self.SkuIdMgr.AvailableSkuIdSet.items() if skuname != TAB_COMMON}\r
c5c7e68a 2476 DefaultStores = set(storename for pcdobj in PcdSet.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict)\r
8518bf0b
LG
2477 for PcdCName, TokenSpaceGuid in PcdSet:\r
2478 PcdObj = PcdSet[(PcdCName, TokenSpaceGuid)]\r
f832bb34 2479 self.CopyDscRawValue(PcdObj)\r
8518bf0b
LG
2480 if PcdObj.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],\r
2481 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
2482 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_VPD],\r
2483 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],\r
2484 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],\r
2485 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]:\r
2486 Pcds[PcdCName, TokenSpaceGuid]= PcdObj\r
2487 continue\r
2488 PcdType = PcdObj.Type\r
2489 if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
2490 for skuid in PcdObj.SkuInfoList:\r
2491 skuobj = PcdObj.SkuInfoList[skuid]\r
8252e6bf 2492 mindefaultstorename = DefaultStoreObj.GetMin(set(defaultstorename for defaultstorename in skuobj.DefaultStoreDict))\r
8518bf0b
LG
2493 for defaultstorename in DefaultStores:\r
2494 if defaultstorename not in skuobj.DefaultStoreDict:\r
2b8a6c44 2495 skuobj.DefaultStoreDict[defaultstorename] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])\r
8518bf0b 2496 skuobj.HiiDefaultValue = skuobj.DefaultStoreDict[mindefaultstorename]\r
ccaa7754 2497 for skuname, skuid in SkuIds.items():\r
2b8a6c44
LG
2498 if skuname not in PcdObj.SkuInfoList:\r
2499 nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)\r
8518bf0b
LG
2500 while nextskuid not in PcdObj.SkuInfoList:\r
2501 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
2b8a6c44
LG
2502 PcdObj.SkuInfoList[skuname] = copy.deepcopy(PcdObj.SkuInfoList[nextskuid])\r
2503 PcdObj.SkuInfoList[skuname].SkuId = skuid\r
2504 PcdObj.SkuInfoList[skuname].SkuIdName = skuname\r
8518bf0b 2505 if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
55c84777 2506 PcdObj.DefaultValue = PcdObj.SkuInfoList.values()[0].HiiDefaultValue if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE else PcdObj.SkuInfoList[TAB_DEFAULT].HiiDefaultValue\r
8518bf0b
LG
2507 Pcds[PcdCName, TokenSpaceGuid]= PcdObj\r
2508 return Pcds\r
ae7b6df8
LG
2509 ## Retrieve dynamic HII 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 _GetDynamicHiiPcd(self, Type):\r
2516\r
ae7b6df8
LG
2517 VariableAttrs = {}\r
2518\r
a0767bae 2519 Pcds = OrderedDict()\r
ae7b6df8
LG
2520 #\r
2521 # tdict is a special dict kind of type, used for selecting correct\r
2522 # PCD settings for certain ARCH and SKU\r
2523 #\r
8518bf0b 2524 PcdDict = tdict(True, 5)\r
ae7b6df8
LG
2525 PcdSet = set()\r
2526 RecordList = self._RawData[Type, self._Arch]\r
2527 # Find out all possible PCD candidates for self._Arch\r
8518bf0b 2528 AvailableSkuIdSet = copy.copy(self.SkuIds)\r
2b8a6c44 2529 DefaultStoresDefine = self._GetDefaultStores()\r
ae7b6df8 2530\r
ccaa7754 2531 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, DefaultStore, Dummy4, Dummy5 in RecordList:\r
2b8a6c44 2532 SkuName = SkuName.upper()\r
55c84777 2533 SkuName = TAB_DEFAULT if SkuName == TAB_COMMON else SkuName\r
2b8a6c44 2534 DefaultStore = DefaultStore.upper()\r
55c84777 2535 if DefaultStore == TAB_COMMON:\r
4d3b9389 2536 DefaultStore = TAB_DEFAULT_STORES_DEFAULT\r
ae7b6df8 2537 if SkuName not in AvailableSkuIdSet:\r
2b8a6c44
LG
2538 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
2539 File=self.MetaFile, Line=Dummy5)\r
2540 if DefaultStore not in DefaultStoresDefine:\r
2541 EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore,\r
2542 File=self.MetaFile, Line=Dummy5)\r
ae7b6df8 2543 if "." not in TokenSpaceGuid:\r
ccaa7754
GL
2544 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, DefaultStore, Dummy5))\r
2545 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid, DefaultStore] = Setting\r
ae7b6df8
LG
2546\r
2547\r
2548 # Remove redundant PCD candidates, per the ARCH and SKU\r
ccaa7754 2549 for PcdCName, TokenSpaceGuid, SkuName, DefaultStore, Dummy4 in PcdSet:\r
ae7b6df8 2550\r
ccaa7754 2551 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid, DefaultStore]\r
4231a819 2552 if Setting is None:\r
ae7b6df8
LG
2553 continue\r
2554 VariableName, VariableGuid, VariableOffset, DefaultValue, VarAttribute = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
2555\r
2556 rt, Msg = VariableAttributes.ValidateVarAttributes(VarAttribute)\r
2557 if not rt:\r
2558 EdkLogger.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid, PcdCName)), Msg),\r
2559 ExtraData="[%s]" % VarAttribute)\r
2560 ExceedMax = False\r
2561 FormatCorrect = True\r
2562 if VariableOffset.isdigit():\r
2563 if int(VariableOffset, 10) > 0xFFFF:\r
2564 ExceedMax = True\r
3e4faa26 2565 elif variablePattern.match(VariableOffset):\r
ae7b6df8
LG
2566 if int(VariableOffset, 16) > 0xFFFF:\r
2567 ExceedMax = True\r
2568 # For Offset written in "A.B"\r
2569 elif VariableOffset.find('.') > -1:\r
2570 VariableOffsetList = VariableOffset.split(".")\r
2571 if not (len(VariableOffsetList) == 2\r
2572 and IsValidWord(VariableOffsetList[0])\r