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