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