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