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