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