BaseTools: StructurePcd array Value support flexible format
[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) 2008 - 2018, 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 from Common.TargetTxtClassObject import *
27 from Common.ToolDefClassObject import *
28 from MetaDataTable import *
29 from MetaFileTable import *
30 from MetaFileParser import *
31
32 from WorkspaceCommon import GetDeclaredPcd
33 from Common.Misc import AnalyzeDscPcd
34 from Common.Misc import ProcessDuplicatedInf
35 import re
36 from Common.Parsing import IsValidWord
37 from Common.VariableAttributes import VariableAttributes
38 import Common.GlobalData as GlobalData
39 import subprocess
40 from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject
41
42 #
43 # Treat CHAR16 as a synonym for UINT16. CHAR16 support is required for VFR C structs
44 #
45 PcdValueInitName = 'PcdValueInit'
46 PcdSupportedBaseTypes = ['BOOLEAN', 'UINT8', 'UINT16', 'UINT32', 'UINT64', 'CHAR16']
47 PcdSupportedBaseTypeWidth = {'BOOLEAN':8, 'UINT8':8, 'UINT16':16, 'UINT32':32, 'UINT64':64}
48 PcdUnsupportedBaseTypes = ['INT8', 'INT16', 'INT32', 'INT64', 'CHAR8', 'UINTN', 'INTN', 'VOID']
49
50 PcdMainCHeader = '''
51 /**
52 DO NOT EDIT
53 FILE auto-generated
54 **/
55
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <PcdValueCommon.h>
60 '''
61
62 PcdMainCEntry = '''
63 int
64 main (
65 int argc,
66 char *argv[]
67 )
68 {
69 return PcdValueMain (argc, argv);
70 }
71 '''
72
73 PcdMakefileHeader = '''
74 #
75 # DO NOT EDIT
76 # This file is auto-generated by build utility
77 #
78
79 '''
80
81 WindowsCFLAGS = 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
82 LinuxCFLAGS = 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
83 PcdMakefileEnd = '''
84 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
85
86 LIBS = $(LIB_PATH)\Common.lib
87
88 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
89 '''
90
91 PcdGccMakefile = '''
92 ARCH ?= IA32
93 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
94 LIBS = -lCommon
95 '''
96
97 class DscBuildData(PlatformBuildClassObject):
98 # dict used to convert PCD type in database to string used by build tool
99 _PCD_TYPE_STRING_ = {
100 MODEL_PCD_FIXED_AT_BUILD : "FixedAtBuild",
101 MODEL_PCD_PATCHABLE_IN_MODULE : "PatchableInModule",
102 MODEL_PCD_FEATURE_FLAG : "FeatureFlag",
103 MODEL_PCD_DYNAMIC : "Dynamic",
104 MODEL_PCD_DYNAMIC_DEFAULT : "Dynamic",
105 MODEL_PCD_DYNAMIC_HII : "DynamicHii",
106 MODEL_PCD_DYNAMIC_VPD : "DynamicVpd",
107 MODEL_PCD_DYNAMIC_EX : "DynamicEx",
108 MODEL_PCD_DYNAMIC_EX_DEFAULT : "DynamicEx",
109 MODEL_PCD_DYNAMIC_EX_HII : "DynamicExHii",
110 MODEL_PCD_DYNAMIC_EX_VPD : "DynamicExVpd",
111 }
112
113 # dict used to convert part of [Defines] to members of DscBuildData directly
114 _PROPERTY_ = {
115 #
116 # Required Fields
117 #
118 TAB_DSC_DEFINES_PLATFORM_NAME : "_PlatformName",
119 TAB_DSC_DEFINES_PLATFORM_GUID : "_Guid",
120 TAB_DSC_DEFINES_PLATFORM_VERSION : "_Version",
121 TAB_DSC_DEFINES_DSC_SPECIFICATION : "_DscSpecification",
122 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
123 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
124 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
125 TAB_DSC_DEFINES_SKUID_IDENTIFIER : "_SkuName",
126 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
127 TAB_DSC_DEFINES_BUILD_NUMBER : "_BuildNumber",
128 TAB_DSC_DEFINES_MAKEFILE_NAME : "_MakefileName",
129 TAB_DSC_DEFINES_BS_BASE_ADDRESS : "_BsBaseAddress",
130 TAB_DSC_DEFINES_RT_BASE_ADDRESS : "_RtBaseAddress",
131 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
132 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
133 }
134
135 # used to compose dummy library class name for those forced library instances
136 _NullLibraryNumber = 0
137
138 ## Constructor of DscBuildData
139 #
140 # Initialize object of DscBuildData
141 #
142 # @param FilePath The path of platform description file
143 # @param RawData The raw data of DSC file
144 # @param BuildDataBase Database used to retrieve module/package information
145 # @param Arch The target architecture
146 # @param Platform (not used for DscBuildData)
147 # @param Macros Macros used for replacement in DSC file
148 #
149 def __init__(self, FilePath, RawData, BuildDataBase, Arch='COMMON', Target=None, Toolchain=None):
150 self.MetaFile = FilePath
151 self._RawData = RawData
152 self._Bdb = BuildDataBase
153 self._Arch = Arch
154 self._Target = Target
155 self._Toolchain = Toolchain
156 self._ToolChainFamily = None
157 self._Clear()
158 self._HandleOverridePath()
159 if os.getenv("WORKSPACE"):
160 self.OutputPath = os.path.join(os.getenv("WORKSPACE"), 'Build', PcdValueInitName)
161 else:
162 self.OutputPath = os.path.dirname(self.DscFile)
163 self.DefaultStores = None
164 self.SkuIdMgr = SkuClass(self.SkuName, self.SkuIds)
165
166 ## XXX[key] = value
167 def __setitem__(self, key, value):
168 self.__dict__[self._PROPERTY_[key]] = value
169
170 ## value = XXX[key]
171 def __getitem__(self, key):
172 return self.__dict__[self._PROPERTY_[key]]
173
174 ## "in" test support
175 def __contains__(self, key):
176 return key in self._PROPERTY_
177
178 ## Set all internal used members of DscBuildData to None
179 def _Clear(self):
180 self._Header = None
181 self._PlatformName = None
182 self._Guid = None
183 self._Version = None
184 self._DscSpecification = None
185 self._OutputDirectory = None
186 self._SupArchList = None
187 self._BuildTargets = None
188 self._SkuName = None
189 self._PcdInfoFlag = None
190 self._VarCheckFlag = None
191 self._FlashDefinition = None
192 self._Prebuild = None
193 self._Postbuild = None
194 self._BuildNumber = None
195 self._MakefileName = None
196 self._BsBaseAddress = None
197 self._RtBaseAddress = None
198 self._SkuIds = None
199 self._Modules = None
200 self._LibraryInstances = None
201 self._LibraryClasses = None
202 self._Pcds = None
203 self._DecPcds = None
204 self._BuildOptions = None
205 self._ModuleTypeOptions = None
206 self._LoadFixAddress = None
207 self._RFCLanguages = None
208 self._ISOLanguages = None
209 self._VpdToolGuid = None
210 self.__Macros = None
211 self.DefaultStores = None
212
213
214 ## handle Override Path of Module
215 def _HandleOverridePath(self):
216 RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]
217 Macros = self._Macros
218 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
219 for Record in RecordList:
220 ModuleId = Record[6]
221 LineNo = Record[7]
222 ModuleFile = PathClass(NormPath(Record[0]), GlobalData.gWorkspace, Arch=self._Arch)
223 RecordList = self._RawData[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH, self._Arch, None, ModuleId]
224 if RecordList != []:
225 SourceOverridePath = mws.join(GlobalData.gWorkspace, NormPath(RecordList[0][0]))
226
227 # Check if the source override path exists
228 if not os.path.isdir(SourceOverridePath):
229 EdkLogger.error('build', FILE_NOT_FOUND, Message='Source override path does not exist:', File=self.MetaFile, ExtraData=SourceOverridePath, Line=LineNo)
230
231 # Add to GlobalData Variables
232 GlobalData.gOverrideDir[ModuleFile.Key] = SourceOverridePath
233
234 ## Get current effective macros
235 def _GetMacros(self):
236 if self.__Macros == None:
237 self.__Macros = {}
238 self.__Macros.update(GlobalData.gPlatformDefines)
239 self.__Macros.update(GlobalData.gGlobalDefines)
240 self.__Macros.update(GlobalData.gCommandLineDefines)
241 return self.__Macros
242
243 ## Get architecture
244 def _GetArch(self):
245 return self._Arch
246
247 ## Set architecture
248 #
249 # Changing the default ARCH to another may affect all other information
250 # because all information in a platform may be ARCH-related. That's
251 # why we need to clear all internal used members, in order to cause all
252 # information to be re-retrieved.
253 #
254 # @param Value The value of ARCH
255 #
256 def _SetArch(self, Value):
257 if self._Arch == Value:
258 return
259 self._Arch = Value
260 self._Clear()
261
262 ## Retrieve all information in [Defines] section
263 #
264 # (Retriving all [Defines] information in one-shot is just to save time.)
265 #
266 def _GetHeaderInfo(self):
267 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]
268 for Record in RecordList:
269 Name = Record[1]
270 # items defined _PROPERTY_ don't need additional processing
271
272 # some special items in [Defines] section need special treatment
273 if Name == TAB_DSC_DEFINES_OUTPUT_DIRECTORY:
274 self._OutputDirectory = NormPath(Record[2], self._Macros)
275 if ' ' in self._OutputDirectory:
276 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in OUTPUT_DIRECTORY",
277 File=self.MetaFile, Line=Record[-1],
278 ExtraData=self._OutputDirectory)
279 elif Name == TAB_DSC_DEFINES_FLASH_DEFINITION:
280 self._FlashDefinition = PathClass(NormPath(Record[2], self._Macros), GlobalData.gWorkspace)
281 ErrorCode, ErrorInfo = self._FlashDefinition.Validate('.fdf')
282 if ErrorCode != 0:
283 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=Record[-1],
284 ExtraData=ErrorInfo)
285 elif Name == TAB_DSC_PREBUILD:
286 PrebuildValue = Record[2]
287 if Record[2][0] == '"':
288 if Record[2][-1] != '"':
289 EdkLogger.error('build', FORMAT_INVALID, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD,
290 File=self.MetaFile, Line=Record[-1])
291 PrebuildValue = Record[2][1:-1]
292 self._Prebuild = PrebuildValue
293 elif Name == TAB_DSC_POSTBUILD:
294 PostbuildValue = Record[2]
295 if Record[2][0] == '"':
296 if Record[2][-1] != '"':
297 EdkLogger.error('build', FORMAT_INVALID, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD,
298 File=self.MetaFile, Line=Record[-1])
299 PostbuildValue = Record[2][1:-1]
300 self._Postbuild = PostbuildValue
301 elif Name == TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES:
302 self._SupArchList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)
303 elif Name == TAB_DSC_DEFINES_BUILD_TARGETS:
304 self._BuildTargets = GetSplitValueList(Record[2])
305 elif Name == TAB_DSC_DEFINES_SKUID_IDENTIFIER:
306 if self._SkuName == None:
307 self._SkuName = Record[2]
308 if GlobalData.gSKUID_CMD:
309 self._SkuName = GlobalData.gSKUID_CMD
310 elif Name == TAB_DSC_DEFINES_PCD_INFO_GENERATION:
311 self._PcdInfoFlag = Record[2]
312 elif Name == TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION:
313 self._VarCheckFlag = Record[2]
314 elif Name == TAB_FIX_LOAD_TOP_MEMORY_ADDRESS:
315 try:
316 self._LoadFixAddress = int (Record[2], 0)
317 except:
318 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record[2]))
319 elif Name == TAB_DSC_DEFINES_RFC_LANGUAGES:
320 if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:
321 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"',
322 File=self.MetaFile, Line=Record[-1])
323 LanguageCodes = Record[2][1:-1]
324 if not LanguageCodes:
325 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
326 File=self.MetaFile, Line=Record[-1])
327 LanguageList = GetSplitValueList(LanguageCodes, TAB_SEMI_COLON_SPLIT)
328 # check whether there is empty entries in the list
329 if None in LanguageList:
330 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more empty language code is in RFC_LANGUAGES statement',
331 File=self.MetaFile, Line=Record[-1])
332 self._RFCLanguages = LanguageList
333 elif Name == TAB_DSC_DEFINES_ISO_LANGUAGES:
334 if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:
335 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
336 File=self.MetaFile, Line=Record[-1])
337 LanguageCodes = Record[2][1:-1]
338 if not LanguageCodes:
339 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
340 File=self.MetaFile, Line=Record[-1])
341 if len(LanguageCodes) % 3:
342 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'bad ISO639-2 format for ISO_LANGUAGES',
343 File=self.MetaFile, Line=Record[-1])
344 LanguageList = []
345 for i in range(0, len(LanguageCodes), 3):
346 LanguageList.append(LanguageCodes[i:i + 3])
347 self._ISOLanguages = LanguageList
348 elif Name == TAB_DSC_DEFINES_VPD_TOOL_GUID:
349 #
350 # try to convert GUID to a real UUID value to see whether the GUID is format
351 # for VPD_TOOL_GUID is correct.
352 #
353 try:
354 uuid.UUID(Record[2])
355 except:
356 EdkLogger.error("build", FORMAT_INVALID, "Invalid GUID format for VPD_TOOL_GUID", File=self.MetaFile)
357 self._VpdToolGuid = Record[2]
358 elif Name in self:
359 self[Name] = Record[2]
360 # set _Header to non-None in order to avoid database re-querying
361 self._Header = 'DUMMY'
362
363 ## Retrieve platform name
364 def _GetPlatformName(self):
365 if self._PlatformName == None:
366 if self._Header == None:
367 self._GetHeaderInfo()
368 if self._PlatformName == None:
369 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_NAME", File=self.MetaFile)
370 return self._PlatformName
371
372 ## Retrieve file guid
373 def _GetFileGuid(self):
374 if self._Guid == None:
375 if self._Header == None:
376 self._GetHeaderInfo()
377 if self._Guid == None:
378 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_GUID", File=self.MetaFile)
379 return self._Guid
380
381 ## Retrieve platform version
382 def _GetVersion(self):
383 if self._Version == None:
384 if self._Header == None:
385 self._GetHeaderInfo()
386 if self._Version == None:
387 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_VERSION", File=self.MetaFile)
388 return self._Version
389
390 ## Retrieve platform description file version
391 def _GetDscSpec(self):
392 if self._DscSpecification == None:
393 if self._Header == None:
394 self._GetHeaderInfo()
395 if self._DscSpecification == None:
396 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No DSC_SPECIFICATION", File=self.MetaFile)
397 return self._DscSpecification
398
399 ## Retrieve OUTPUT_DIRECTORY
400 def _GetOutpuDir(self):
401 if self._OutputDirectory == None:
402 if self._Header == None:
403 self._GetHeaderInfo()
404 if self._OutputDirectory == None:
405 self._OutputDirectory = os.path.join("Build", self._PlatformName)
406 return self._OutputDirectory
407
408 ## Retrieve SUPPORTED_ARCHITECTURES
409 def _GetSupArch(self):
410 if self._SupArchList == None:
411 if self._Header == None:
412 self._GetHeaderInfo()
413 if self._SupArchList == None:
414 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No SUPPORTED_ARCHITECTURES", File=self.MetaFile)
415 return self._SupArchList
416
417 ## Retrieve BUILD_TARGETS
418 def _GetBuildTarget(self):
419 if self._BuildTargets == None:
420 if self._Header == None:
421 self._GetHeaderInfo()
422 if self._BuildTargets == None:
423 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BUILD_TARGETS", File=self.MetaFile)
424 return self._BuildTargets
425
426 def _GetPcdInfoFlag(self):
427 if self._PcdInfoFlag == None or self._PcdInfoFlag.upper() == 'FALSE':
428 return False
429 elif self._PcdInfoFlag.upper() == 'TRUE':
430 return True
431 else:
432 return False
433 def _GetVarCheckFlag(self):
434 if self._VarCheckFlag == None or self._VarCheckFlag.upper() == 'FALSE':
435 return False
436 elif self._VarCheckFlag.upper() == 'TRUE':
437 return True
438 else:
439 return False
440
441 # # Retrieve SKUID_IDENTIFIER
442 def _GetSkuName(self):
443 if self._SkuName == None:
444 if self._Header == None:
445 self._GetHeaderInfo()
446 if self._SkuName == None:
447 self._SkuName = 'DEFAULT'
448 return self._SkuName
449
450 ## Override SKUID_IDENTIFIER
451 def _SetSkuName(self, Value):
452 self._SkuName = Value
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 HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
584 if Pattern.match(Record[0]) == None and HexPattern.match(Record[0]) == None:
585 EdkLogger.error('build', FORMAT_INVALID, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
586 File=self.MetaFile, Line=Record[-1])
587 if not IsValidWord(Record[1]):
588 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_-.)*'",
589 File=self.MetaFile, Line=Record[-1])
590 self._SkuIds[Record[1].upper()] = (str(self.ToInt(Record[0])), Record[1].upper(), Record[2].upper())
591 if 'DEFAULT' not in self._SkuIds:
592 self._SkuIds['DEFAULT'] = ("0","DEFAULT","DEFAULT")
593 if 'COMMON' not in self._SkuIds:
594 self._SkuIds['COMMON'] = ("0","DEFAULT","DEFAULT")
595 return self._SkuIds
596 def ToInt(self,intstr):
597 return int(intstr,16) if intstr.upper().startswith("0X") else int(intstr)
598 def _GetDefaultStores(self):
599 if self.DefaultStores == None:
600 self.DefaultStores = sdict()
601 RecordList = self._RawData[MODEL_EFI_DEFAULT_STORES, self._Arch]
602 for Record in RecordList:
603 if Record[0] in [None, '']:
604 EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID number',
605 File=self.MetaFile, Line=Record[-1])
606 if Record[1] in [None, '']:
607 EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID name',
608 File=self.MetaFile, Line=Record[-1])
609 Pattern = re.compile('^[1-9]\d*|0$')
610 HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
611 if Pattern.match(Record[0]) == None and HexPattern.match(Record[0]) == None:
612 EdkLogger.error('build', FORMAT_INVALID, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
613 File=self.MetaFile, Line=Record[-1])
614 if not IsValidWord(Record[1]):
615 EdkLogger.error('build', FORMAT_INVALID, "The format of the DefaultStores ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",
616 File=self.MetaFile, Line=Record[-1])
617 self.DefaultStores[Record[1].upper()] = (self.ToInt(Record[0]),Record[1].upper())
618 if TAB_DEFAULT_STORES_DEFAULT not in self.DefaultStores:
619 self.DefaultStores[TAB_DEFAULT_STORES_DEFAULT] = (0,TAB_DEFAULT_STORES_DEFAULT)
620 GlobalData.gDefaultStores = self.DefaultStores.keys()
621 if GlobalData.gDefaultStores:
622 GlobalData.gDefaultStores.sort()
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, self._GuidDict = 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:
819 if PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
820 EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,
821 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
822 else:
823 if ValueList[2] == '-1':
824 EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,
825 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
826 if ValueList[Index]:
827 DatumType = self._DecPcds[PcdCName, TokenSpaceGuid].DatumType
828 try:
829 ValueList[Index] = ValueExpressionEx(ValueList[Index], DatumType, self._GuidDict)(True)
830 except BadExpression, Value:
831 EdkLogger.error('Parser', FORMAT_INVALID, Value, File=self.MetaFile, Line=LineNo,
832 ExtraData="PCD [%s.%s] Value \"%s\" " % (
833 TokenSpaceGuid, PcdCName, ValueList[Index]))
834 except EvaluationException, Excpt:
835 if hasattr(Excpt, 'Pcd'):
836 if Excpt.Pcd in GlobalData.gPlatformOtherPcds:
837 EdkLogger.error('Parser', FORMAT_INVALID, "Cannot use this PCD (%s) in an expression as"
838 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
839 " of the DSC file" % Excpt.Pcd,
840 File=self.MetaFile, Line=LineNo)
841 else:
842 EdkLogger.error('Parser', FORMAT_INVALID, "PCD (%s) is not defined in DSC file" % Excpt.Pcd,
843 File=self.MetaFile, Line=LineNo)
844 else:
845 EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),
846 File=self.MetaFile, Line=LineNo)
847
848 if ValueList[Index]:
849 Valid, ErrStr = CheckPcdDatum(self._DecPcds[PcdCName, TokenSpaceGuid].DatumType, ValueList[Index])
850 if not Valid:
851 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,
852 ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
853 if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT):
854 if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() != ValueList[1].strip():
855 EdkLogger.error('build', FORMAT_INVALID, "Pcd datumtype used in DSC file is not the same as its declaration in DEC file." , File=self.MetaFile, Line=LineNo,
856 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
857 if (TokenSpaceGuid + '.' + PcdCName) in GlobalData.gPlatformPcds:
858 if GlobalData.gPlatformPcds[TokenSpaceGuid + '.' + PcdCName] != ValueList[Index]:
859 GlobalData.gPlatformPcds[TokenSpaceGuid + '.' + PcdCName] = ValueList[Index]
860 return ValueList
861
862 def _FilterPcdBySkuUsage(self,Pcds):
863 available_sku = self.SkuIdMgr.AvailableSkuIdSet
864 sku_usage = self.SkuIdMgr.SkuUsageType
865 if sku_usage == SkuClass.SINGLE:
866 for pcdname in Pcds:
867 pcd = Pcds[pcdname]
868 Pcds[pcdname].SkuInfoList = {"DEFAULT":pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku}
869 if type(pcd) is StructurePcd and pcd.SkuOverrideValues:
870 Pcds[pcdname].SkuOverrideValues = {"DEFAULT":pcd.SkuOverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_sku}
871 else:
872 for pcdname in Pcds:
873 pcd = Pcds[pcdname]
874 Pcds[pcdname].SkuInfoList = {skuid:pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku}
875 if type(pcd) is StructurePcd and pcd.SkuOverrideValues:
876 Pcds[pcdname].SkuOverrideValues = {skuid:pcd.SkuOverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_sku}
877 return Pcds
878 def CompleteHiiPcdsDefaultStores(self,Pcds):
879 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]]]
880 DefaultStoreMgr = DefaultStore(self.DefaultStores)
881 for pcd in HiiPcd:
882 for skuid in pcd.SkuInfoList:
883 skuobj = pcd.SkuInfoList.get(skuid)
884 if "STANDARD" not in skuobj.DefaultStoreDict:
885 PcdDefaultStoreSet = set([defaultstorename for defaultstorename in skuobj.DefaultStoreDict])
886 mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)
887 skuobj.DefaultStoreDict['STANDARD'] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])
888 return Pcds
889
890 def RecoverCommandLinePcd(self):
891 pcdset = []
892 if GlobalData.BuildOptionPcd:
893 for pcd in GlobalData.BuildOptionPcd:
894 if pcd[2] == "":
895 pcdset.append((pcd[0],pcd[1],pcd[3]))
896 else:
897 pcdobj = self._Pcds.get((pcd[1],pcd[0]))
898 if pcdobj:
899 pcdset.append((pcd[0],pcd[1], pcdobj.DefaultValue))
900 else:
901 pcdset.append((pcd[0],pcd[1],pcd[3]))
902 GlobalData.BuildOptionPcd = pcdset
903 def GetFieldValueFromComm(self,ValueStr,TokenSpaceGuidCName, TokenCName, FieldName):
904 PredictedFieldType = "VOID*"
905 if ValueStr.startswith('L'):
906 if not ValueStr[1]:
907 EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')
908 ValueStr = ValueStr[0] + '"' + ValueStr[1:] + '"'
909 PredictedFieldType = "VOID*"
910 elif ValueStr.startswith('H') or ValueStr.startswith('{'):
911 EdkLogger.error("build", FORMAT_INVALID, 'Currently we do not support assign H"{...}" format for Pcd field.', ExtraData="%s.%s.%s from command line" % (TokenSpaceGuidCName, TokenCName, FieldName))
912 ValueStr = ValueStr[1:]
913 PredictedFieldType = "VOID*"
914 elif ValueStr.upper() in ['TRUE', '0X1', '0X01', '1', 'FALSE', '0X0', '0X00', '0']:
915 PredictedFieldType = "BOOLEAN"
916 elif ValueStr.isdigit() or ValueStr.upper().startswith('0X'):
917 PredictedFieldType = TAB_UINT16
918 else:
919 if not ValueStr[0]:
920 EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')
921 ValueStr = '"' + ValueStr + '"'
922 PredictedFieldType = "VOID*"
923 IsValid, Cause = CheckPcdDatum(PredictedFieldType, ValueStr)
924 if not IsValid:
925 EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s.%s from command line" % (TokenSpaceGuidCName, TokenCName, FieldName))
926 if PredictedFieldType == 'BOOLEAN':
927 ValueStr = ValueStr.upper()
928 if ValueStr == 'TRUE' or ValueStr == '1':
929 ValueStr = '1'
930 elif ValueStr == 'FALSE' or ValueStr == '0':
931 ValueStr = '0'
932 return ValueStr
933 def __ParsePcdFromCommandLine(self):
934 if GlobalData.BuildOptionPcd:
935 for i, pcd in enumerate(GlobalData.BuildOptionPcd):
936 if type(pcd) is tuple:
937 continue
938 (pcdname, pcdvalue) = pcd.split('=')
939 if not pcdvalue:
940 EdkLogger.error('build', AUTOGEN_ERROR, "No Value specified for the PCD %s." % (pcdname))
941 if '.' in pcdname:
942 (Name1, Name2) = pcdname.split('.',1)
943 if "." in Name2:
944 (Name3, FieldName) = Name2.split(".",1)
945 if ((Name3,Name1)) in self.DecPcds:
946 HasTokenSpace = True
947 TokenCName = Name3
948 TokenSpaceGuidCName = Name1
949 else:
950 FieldName = Name2
951 TokenCName = Name1
952 TokenSpaceGuidCName = ''
953 HasTokenSpace = False
954 else:
955 if ((Name2,Name1)) in self.DecPcds:
956 HasTokenSpace = True
957 TokenCName = Name2
958 TokenSpaceGuidCName = Name1
959 FieldName =""
960 else:
961 FieldName = Name2
962 TokenCName = Name1
963 TokenSpaceGuidCName = ''
964 HasTokenSpace = False
965 else:
966 FieldName = ""
967 TokenCName = pcdname
968 TokenSpaceGuidCName = ''
969 HasTokenSpace = False
970 TokenSpaceGuidCNameList = []
971 FoundFlag = False
972 PcdDatumType = ''
973 NewValue = ''
974 if not HasTokenSpace:
975 for key in self.DecPcds:
976 if TokenCName == key[0]:
977 if TokenSpaceGuidCName:
978 EdkLogger.error(
979 'build',
980 AUTOGEN_ERROR,
981 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, TokenSpaceGuidCName, key[1])
982 )
983 else:
984 TokenSpaceGuidCName = key[1]
985 FoundFlag = True
986 else:
987 if (TokenCName, TokenSpaceGuidCName) in self.DecPcds:
988 FoundFlag = True
989 if FieldName:
990 NewValue = self.GetFieldValueFromComm(pcdvalue, TokenSpaceGuidCName, TokenCName, FieldName)
991 GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName,NewValue,("build command options",1))
992 else:
993 for key in self.DecPcds:
994 PcdItem = self.DecPcds[key]
995 if HasTokenSpace:
996 if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):
997 PcdDatumType = PcdItem.DatumType
998 if pcdvalue.startswith('H'):
999 try:
1000 pcdvalue = ValueExpressionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True)
1001 except BadExpression, Value:
1002 if Value.result > 1:
1003 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %
1004 (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
1005 pcdvalue = 'H' + pcdvalue
1006 NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
1007 FoundFlag = True
1008 else:
1009 if PcdItem.TokenCName == TokenCName:
1010 if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:
1011 if len (TokenSpaceGuidCNameList) < 1:
1012 TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)
1013 PcdDatumType = PcdItem.DatumType
1014 TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName
1015 if pcdvalue.startswith('H'):
1016 try:
1017 pcdvalue = ValueExpressionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True)
1018 except BadExpression, Value:
1019 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %
1020 (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
1021 pcdvalue = 'H' + pcdvalue
1022 NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
1023 FoundFlag = True
1024 else:
1025 EdkLogger.error(
1026 'build',
1027 AUTOGEN_ERROR,
1028 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])
1029 )
1030 GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName,NewValue,("build command options",1))
1031 if not FoundFlag:
1032 if HasTokenSpace:
1033 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, TokenCName))
1034 else:
1035 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (TokenCName))
1036 for BuildData in self._Bdb._CACHE_.values():
1037 if BuildData.MetaFile.Ext == '.dec' or BuildData.MetaFile.Ext == '.dsc':
1038 continue
1039 for key in BuildData.Pcds:
1040 PcdItem = BuildData.Pcds[key]
1041 if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName) and FieldName =="":
1042 PcdItem.DefaultValue = NewValue
1043 ## Retrieve all PCD settings in platform
1044 def _GetPcds(self):
1045 if self._Pcds == None:
1046 self._Pcds = sdict()
1047 self.__ParsePcdFromCommandLine()
1048 self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
1049 self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
1050 self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
1051 self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_DEFAULT))
1052 self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_HII))
1053 self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_VPD))
1054 self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_EX_DEFAULT))
1055 self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_EX_HII))
1056 self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD))
1057
1058 self._Pcds = self.CompletePcdValues(self._Pcds)
1059 self._Pcds = self.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST, self._Pcds)
1060 self._Pcds = self.CompleteHiiPcdsDefaultStores(self._Pcds)
1061 self._Pcds = self._FilterPcdBySkuUsage(self._Pcds)
1062 self._Pcds = self.OverrideByFdfCommOverAll(self._Pcds)
1063 self.RecoverCommandLinePcd()
1064 return self._Pcds
1065
1066 def _dumpPcdInfo(self,Pcds):
1067 for pcd in Pcds:
1068 pcdobj = Pcds[pcd]
1069 if not pcdobj.TokenCName.startswith("Test"):
1070 continue
1071 for skuid in pcdobj.SkuInfoList:
1072 if pcdobj.Type in (self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]):
1073 for storename in pcdobj.SkuInfoList[skuid].DefaultStoreDict:
1074 print "PcdCName: %s, SkuName: %s, StoreName: %s, Value: %s" % (".".join((pcdobj.TokenSpaceGuidCName, pcdobj.TokenCName)), skuid,storename,str(pcdobj.SkuInfoList[skuid].DefaultStoreDict[storename]))
1075 else:
1076 print "PcdCName: %s, SkuName: %s, Value: %s" % (".".join((pcdobj.TokenSpaceGuidCName, pcdobj.TokenCName)), skuid,str(pcdobj.SkuInfoList[skuid].DefaultValue))
1077 ## Retrieve [BuildOptions]
1078 def _GetBuildOptions(self):
1079 if self._BuildOptions == None:
1080 self._BuildOptions = sdict()
1081 #
1082 # Retrieve build option for EDKII and EDK style module
1083 #
1084 for CodeBase in (EDKII_NAME, EDK_NAME):
1085 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, CodeBase]
1086 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4,Dummy5 in RecordList:
1087 if Dummy3.upper() != 'COMMON':
1088 continue
1089 CurKey = (ToolChainFamily, ToolChain, CodeBase)
1090 #
1091 # Only flags can be appended
1092 #
1093 if CurKey not in self._BuildOptions or not ToolChain.endswith('_FLAGS') or Option.startswith('='):
1094 self._BuildOptions[CurKey] = Option
1095 else:
1096 if ' ' + Option not in self._BuildOptions[CurKey]:
1097 self._BuildOptions[CurKey] += ' ' + Option
1098 return self._BuildOptions
1099
1100 def GetBuildOptionsByModuleType(self, Edk, ModuleType):
1101 if self._ModuleTypeOptions == None:
1102 self._ModuleTypeOptions = sdict()
1103 if (Edk, ModuleType) not in self._ModuleTypeOptions:
1104 options = sdict()
1105 self._ModuleTypeOptions[Edk, ModuleType] = options
1106 DriverType = '%s.%s' % (Edk, ModuleType)
1107 CommonDriverType = '%s.%s' % ('COMMON', ModuleType)
1108 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch]
1109 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4,Dummy5 in RecordList:
1110 Type = Dummy2 + '.' + Dummy3
1111 if Type.upper() == DriverType.upper() or Type.upper() == CommonDriverType.upper():
1112 Key = (ToolChainFamily, ToolChain, Edk)
1113 if Key not in options or not ToolChain.endswith('_FLAGS') or Option.startswith('='):
1114 options[Key] = Option
1115 else:
1116 if ' ' + Option not in options[Key]:
1117 options[Key] += ' ' + Option
1118 return self._ModuleTypeOptions[Edk, ModuleType]
1119
1120 def GetStructurePcdInfo(self, PcdSet):
1121 structure_pcd_data = {}
1122 for item in PcdSet:
1123 if (item[0],item[1]) not in structure_pcd_data:
1124 structure_pcd_data[(item[0],item[1])] = []
1125 structure_pcd_data[(item[0],item[1])].append(item)
1126
1127 return structure_pcd_data
1128 def OverrideByFdfComm(self,StruPcds):
1129 StructurePcdInCom = {(item[0],item[1],item[2] ):(item[3],item[4]) for item in GlobalData.BuildOptionPcd if len(item) == 5 and (item[1],item[0]) in StruPcds } if GlobalData.BuildOptionPcd else {}
1130 GlobalPcds = set([(item[0],item[1]) for item in StructurePcdInCom.keys()])
1131 for Pcd in StruPcds.values():
1132 if (Pcd.TokenSpaceGuidCName,Pcd.TokenCName) not in GlobalPcds:
1133 continue
1134 FieldValues = {item[2]:StructurePcdInCom[item] for item in StructurePcdInCom if (Pcd.TokenSpaceGuidCName,Pcd.TokenCName) == (item[0],item[1]) and item[2]}
1135 for sku in Pcd.SkuOverrideValues:
1136 for defaultstore in Pcd.SkuOverrideValues[sku]:
1137 for field in FieldValues:
1138 if field not in Pcd.SkuOverrideValues[sku][defaultstore]:
1139 Pcd.SkuOverrideValues[sku][defaultstore][field] = ["","",""]
1140 Pcd.SkuOverrideValues[sku][defaultstore][field][0] = FieldValues[field][0]
1141 Pcd.SkuOverrideValues[sku][defaultstore][field][1] = FieldValues[field][1][0]
1142 Pcd.SkuOverrideValues[sku][defaultstore][field][2] = FieldValues[field][1][1]
1143 return StruPcds
1144 def OverrideByFdfCommOverAll(self,AllPcds):
1145 def CheckStructureInComm(commpcds):
1146 if not commpcds:
1147 return False
1148 if len(commpcds[0]) == 5:
1149 return True
1150 return False
1151
1152 if CheckStructureInComm(GlobalData.BuildOptionPcd):
1153 StructurePcdInCom = {(item[0],item[1],item[2] ):(item[3],item[4]) for item in GlobalData.BuildOptionPcd } if GlobalData.BuildOptionPcd else {}
1154 NoFiledValues = {(item[0],item[1]):StructurePcdInCom[item] for item in StructurePcdInCom if not item[2]}
1155 else:
1156 NoFiledValues = {(item[0],item[1]):[item[2]] for item in GlobalData.BuildOptionPcd}
1157 for Guid,Name in NoFiledValues:
1158 if (Name,Guid) in AllPcds:
1159 Pcd = AllPcds.get((Name,Guid))
1160 Pcd.DefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0]
1161 for sku in Pcd.SkuInfoList:
1162 SkuInfo = Pcd.SkuInfoList[sku]
1163 if SkuInfo.DefaultValue:
1164 SkuInfo.DefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0]
1165 else:
1166 SkuInfo.HiiDefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0]
1167 for defaultstore in SkuInfo.DefaultStoreDict:
1168 SkuInfo.DefaultStoreDict[defaultstore] = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0]
1169 else:
1170 PcdInDec = self.DecPcds.get((Name,Guid))
1171 if PcdInDec:
1172 if PcdInDec.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
1173 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
1174 self.Pcds[Name, Guid] = copy.deepcopy(PcdInDec)
1175 self.Pcds[Name, Guid].DefaultValue = NoFiledValues[( Guid,Name)][0]
1176 return AllPcds
1177 def UpdateStructuredPcds(self, TypeList, AllPcds):
1178
1179 DynamicPcdType = [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],
1180 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],
1181 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_VPD],
1182 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],
1183 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],
1184 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]
1185
1186 Pcds = AllPcds
1187 DefaultStoreMgr = DefaultStore(self.DefaultStores)
1188 SkuIds = self.SkuIdMgr.AvailableSkuIdSet
1189 SkuIds.update({'DEFAULT':0})
1190 DefaultStores = set([storename for pcdobj in AllPcds.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict.keys()])
1191
1192 S_PcdSet = []
1193 # Find out all possible PCD candidates for self._Arch
1194 RecordList = []
1195
1196 for Type in TypeList:
1197 RecordList.extend(self._RawData[Type, self._Arch])
1198
1199 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, default_store, Dummy4,Dummy5 in RecordList:
1200 SkuName = SkuName.upper()
1201 default_store = default_store.upper()
1202 SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
1203 if SkuName not in SkuIds:
1204 continue
1205
1206 if SkuName in SkuIds and "." in TokenSpaceGuid:
1207 S_PcdSet.append([ TokenSpaceGuid.split(".")[0],TokenSpaceGuid.split(".")[1], PcdCName,SkuName, default_store,Dummy5, AnalyzePcdExpression(Setting)[0]])
1208
1209 # handle pcd value override
1210 StrPcdSet = self.GetStructurePcdInfo(S_PcdSet)
1211 S_pcd_set = {}
1212 for str_pcd in StrPcdSet:
1213 str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)
1214 str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)
1215 if not isinstance (str_pcd_dec, StructurePcd):
1216 EdkLogger.error('build', PARSER_ERROR,
1217 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),
1218 File=self.MetaFile,Line = StrPcdSet[str_pcd][0][5])
1219 if str_pcd_dec:
1220 str_pcd_obj_str = StructurePcd()
1221 str_pcd_obj_str.copy(str_pcd_dec)
1222 if str_pcd_obj:
1223 str_pcd_obj_str.copy(str_pcd_obj)
1224 str_pcd_obj_str.DefaultFromDSC = str_pcd_obj_str.DefaultValue
1225 for str_pcd_data in StrPcdSet[str_pcd]:
1226 if str_pcd_data[3] in SkuIds:
1227 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])
1228 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
1229 else:
1230 EdkLogger.error('build', PARSER_ERROR,
1231 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),
1232 File=self.MetaFile,Line = StrPcdSet[str_pcd][0][5])
1233 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1234 for Pcd in self.DecPcds:
1235 if type (self._DecPcds[Pcd]) is StructurePcd:
1236 if Pcd not in S_pcd_set:
1237 str_pcd_obj_str = StructurePcd()
1238 str_pcd_obj_str.copy(self._DecPcds[Pcd])
1239 str_pcd_obj = Pcds.get(Pcd, None)
1240 if str_pcd_obj:
1241 str_pcd_obj_str.copy(str_pcd_obj)
1242 if str_pcd_obj.DefaultValue:
1243 str_pcd_obj_str.DefaultFromDSC = str_pcd_obj.DefaultValue
1244 S_pcd_set[Pcd] = str_pcd_obj_str
1245 if S_pcd_set:
1246 GlobalData.gStructurePcd[self.Arch] = S_pcd_set
1247 for stru_pcd in S_pcd_set.values():
1248 for skuid in SkuIds:
1249 if skuid in stru_pcd.SkuOverrideValues:
1250 continue
1251 nextskuid = self.SkuIdMgr.GetNextSkuId(skuid)
1252 NoDefault = False
1253 while nextskuid not in stru_pcd.SkuOverrideValues:
1254 if nextskuid == "DEFAULT":
1255 NoDefault = True
1256 break
1257 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)
1258 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})
1259 if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
1260 for skuid in SkuIds:
1261 nextskuid = skuid
1262 NoDefault = False
1263 if skuid not in stru_pcd.SkuOverrideValues:
1264 while nextskuid not in stru_pcd.SkuOverrideValues:
1265 if nextskuid == "DEFAULT":
1266 NoDefault = True
1267 break
1268 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)
1269 if NoDefault:
1270 continue
1271 PcdDefaultStoreSet = set([defaultstorename for defaultstorename in stru_pcd.SkuOverrideValues[nextskuid]])
1272 mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)
1273
1274 for defaultstoreid in DefaultStores:
1275 if defaultstoreid not in stru_pcd.SkuOverrideValues[skuid]:
1276 stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename])
1277 S_pcd_set = self.OverrideByFdfComm(S_pcd_set)
1278 Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set)
1279 if Str_Pcd_Values:
1280 for (skuname,StoreName,PcdGuid,PcdName,PcdValue) in Str_Pcd_Values:
1281 str_pcd_obj = S_pcd_set.get((PcdName, PcdGuid))
1282 if str_pcd_obj is None:
1283 print PcdName, PcdGuid
1284 raise
1285 if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],
1286 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
1287 if skuname not in str_pcd_obj.SkuInfoList:
1288 str_pcd_obj.SkuInfoList[skuname] = SkuInfoClass(SkuIdName=skuname, SkuId=self.SkuIds[skuname][0], HiiDefaultValue=PcdValue, DefaultStore = {StoreName:PcdValue})
1289 else:
1290 str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue = PcdValue
1291 str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.update({StoreName:PcdValue})
1292 elif str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
1293 self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
1294 if skuname in (self.SkuIdMgr.SystemSkuId, 'DEFAULT', 'COMMON'):
1295 str_pcd_obj.DefaultValue = PcdValue
1296 else:
1297 if skuname not in str_pcd_obj.SkuInfoList:
1298 nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)
1299 NoDefault = False
1300 while nextskuid not in str_pcd_obj.SkuInfoList:
1301 if nextskuid == "DEFAULT":
1302 NoDefault = True
1303 break
1304 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)
1305 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)
1306 str_pcd_obj.SkuInfoList[skuname].SkuId = self.SkuIds[skuname][0]
1307 str_pcd_obj.SkuInfoList[skuname].SkuIdName = skuname
1308 else:
1309 str_pcd_obj.SkuInfoList[skuname].DefaultValue = PcdValue
1310 for str_pcd_obj in S_pcd_set.values():
1311 if str_pcd_obj.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],
1312 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
1313 continue
1314 PcdDefaultStoreSet = set([defaultstorename for skuobj in str_pcd_obj.SkuInfoList.values() for defaultstorename in skuobj.DefaultStoreDict])
1315 DefaultStoreObj = DefaultStore(self._GetDefaultStores())
1316 mindefaultstorename = DefaultStoreObj.GetMin(PcdDefaultStoreSet)
1317 str_pcd_obj.SkuInfoList[self.SkuIdMgr.SystemSkuId].HiiDefaultValue = str_pcd_obj.SkuInfoList[self.SkuIdMgr.SystemSkuId].DefaultStoreDict[mindefaultstorename]
1318
1319 for str_pcd_obj in S_pcd_set.values():
1320
1321 str_pcd_obj.MaxDatumSize = self.GetStructurePcdMaxSize(str_pcd_obj)
1322 Pcds[str_pcd_obj.TokenCName, str_pcd_obj.TokenSpaceGuidCName] = str_pcd_obj
1323
1324 for pcdkey in Pcds:
1325 pcd = Pcds[pcdkey]
1326 if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
1327 pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
1328 del(pcd.SkuInfoList['COMMON'])
1329 elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
1330 del(pcd.SkuInfoList['COMMON'])
1331
1332 map(self.FilterSkuSettings,[Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])
1333 return Pcds
1334
1335 ## Retrieve non-dynamic PCD settings
1336 #
1337 # @param Type PCD type
1338 #
1339 # @retval a dict object contains settings of given PCD type
1340 #
1341 def _GetPcd(self, Type):
1342 Pcds = sdict()
1343 #
1344 # tdict is a special dict kind of type, used for selecting correct
1345 # PCD settings for certain ARCH
1346 #
1347 AvailableSkuIdSet = copy.copy(self.SkuIds)
1348
1349 PcdDict = tdict(True, 3)
1350 PcdSet = set()
1351 # Find out all possible PCD candidates for self._Arch
1352 RecordList = self._RawData[Type, self._Arch]
1353 PcdValueDict = sdict()
1354 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4,Dummy5 in RecordList:
1355 SkuName = SkuName.upper()
1356 SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
1357 if SkuName not in AvailableSkuIdSet:
1358 EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
1359 File=self.MetaFile, Line=Dummy5)
1360 if SkuName in (self.SkuIdMgr.SystemSkuId, 'DEFAULT', 'COMMON'):
1361 if "." not in TokenSpaceGuid:
1362 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
1363 PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting
1364
1365 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet:
1366 Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName]
1367 if Setting == None:
1368 continue
1369 PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
1370 if (PcdCName, TokenSpaceGuid) in PcdValueDict:
1371 PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue, DatumType, MaxDatumSize)
1372 else:
1373 PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, DatumType, MaxDatumSize)}
1374
1375 PcdsKeys = PcdValueDict.keys()
1376 for PcdCName, TokenSpaceGuid in PcdsKeys:
1377
1378 PcdSetting = PcdValueDict[PcdCName, TokenSpaceGuid]
1379 PcdValue = None
1380 DatumType = None
1381 MaxDatumSize = None
1382 if 'COMMON' in PcdSetting:
1383 PcdValue, DatumType, MaxDatumSize = PcdSetting['COMMON']
1384 if 'DEFAULT' in PcdSetting:
1385 PcdValue, DatumType, MaxDatumSize = PcdSetting['DEFAULT']
1386 if self.SkuIdMgr.SystemSkuId in PcdSetting:
1387 PcdValue, DatumType, MaxDatumSize = PcdSetting[self.SkuIdMgr.SystemSkuId]
1388
1389 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
1390 PcdCName,
1391 TokenSpaceGuid,
1392 self._PCD_TYPE_STRING_[Type],
1393 DatumType,
1394 PcdValue,
1395 '',
1396 MaxDatumSize,
1397 {},
1398 False,
1399 None,
1400 IsDsc=True)
1401
1402
1403 return Pcds
1404
1405 def __UNICODE2OCTList(self,Value):
1406 Value = Value.strip()
1407 Value = Value[2:-1]
1408 List = []
1409 for Item in Value:
1410 Temp = '%04X' % ord(Item)
1411 List.append('0x' + Temp[2:4])
1412 List.append('0x' + Temp[0:2])
1413 List.append('0x00')
1414 List.append('0x00')
1415 return List
1416 def __STRING2OCTList(self,Value):
1417 OCTList = []
1418 Value = Value.strip('"')
1419 for char in Value:
1420 Temp = '%02X' % ord(char)
1421 OCTList.append('0x' + Temp)
1422 OCTList.append('0x00')
1423 return OCTList
1424
1425 def GetStructurePcdMaxSize(self, str_pcd):
1426 pcd_default_value = str_pcd.DefaultValue
1427 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()]
1428 sku_values.append(pcd_default_value)
1429
1430 def get_length(value):
1431 Value = value.strip()
1432 if len(value) > 1:
1433 if Value.startswith('GUID') and Value.endswith(')'):
1434 return 16
1435 if Value.startswith('L"') and Value.endswith('"'):
1436 return len(Value[2:-1])
1437 if Value[0] == '"' and Value[-1] == '"':
1438 return len(Value) - 2
1439 if Value[0] == '{' and Value[-1] == '}':
1440 return len(Value.split(","))
1441 if Value.startswith("L'") and Value.endswith("'") and len(list(Value[2:-1])) > 1:
1442 return len(list(Value[2:-1]))
1443 if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1:
1444 return len(Value) - 2
1445 return len(Value)
1446
1447 return str(max([pcd_size for pcd_size in [get_length(item) for item in sku_values]]))
1448
1449 def IsFieldValueAnArray (self, Value):
1450 Value = Value.strip()
1451 if Value.startswith('GUID') and Value.endswith(')'):
1452 return True
1453 if Value.startswith('L"') and Value.endswith('"') and len(list(Value[2:-1])) > 1:
1454 return True
1455 if Value[0] == '"' and Value[-1] == '"' and len(list(Value[1:-1])) > 1:
1456 return True
1457 if Value[0] == '{' and Value[-1] == '}':
1458 return True
1459 if Value.startswith("L'") and Value.endswith("'") and len(list(Value[2:-1])) > 1:
1460 print 'foo = ', list(Value[2:-1])
1461 return True
1462 if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1:
1463 print 'bar = ', list(Value[1:-1])
1464 return True
1465 return False
1466
1467 def ExecuteCommand (self, Command):
1468 try:
1469 Process = subprocess.Popen(Command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
1470 except:
1471 EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % Command)
1472 Result = Process.communicate()
1473 return Process.returncode, Result[0], Result[1]
1474
1475 def IntToCString(self, Value, ValueSize):
1476 Result = '"'
1477 if not isinstance (Value, str):
1478 for Index in range(0, ValueSize):
1479 Result = Result + '\\x%02x' % (Value & 0xff)
1480 Value = Value >> 8
1481 Result = Result + '"'
1482 return Result
1483
1484 def GenerateInitializeFunc(self, SkuName, DefaultStoreName, Pcd, InitByteValue, CApp):
1485 OverrideValues = {DefaultStoreName:""}
1486 if Pcd.SkuOverrideValues:
1487 OverrideValues = Pcd.SkuOverrideValues[SkuName]
1488 for DefaultStoreName in OverrideValues.keys():
1489 CApp = CApp + 'void\n'
1490 CApp = CApp + 'Initialize_%s_%s_%s_%s(\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
1491 CApp = CApp + ' void\n'
1492 CApp = CApp + ' )\n'
1493 CApp = CApp + '{\n'
1494 CApp = CApp + ' UINT32 Size;\n'
1495 CApp = CApp + ' UINT32 FieldSize;\n'
1496 CApp = CApp + ' CHAR8 *Value;\n'
1497 CApp = CApp + ' UINT32 OriginalSize;\n'
1498 CApp = CApp + ' VOID *OriginalPcd;\n'
1499 CApp = CApp + ' %s *Pcd; // From %s Line %d \n' % (Pcd.DatumType, Pcd.PkgPath, Pcd.PcdDefineLineNo)
1500 CApp = CApp + '\n'
1501
1502 if SkuName in Pcd.SkuInfoList:
1503 DefaultValue = Pcd.SkuInfoList[SkuName].DefaultStoreDict.get(DefaultStoreName,Pcd.SkuInfoList[SkuName].HiiDefaultValue) if Pcd.SkuInfoList[SkuName].HiiDefaultValue else Pcd.SkuInfoList[SkuName].DefaultValue
1504 else:
1505 DefaultValue = Pcd.DefaultValue
1506 PcdDefaultValue = StringToArray(DefaultValue.strip())
1507
1508 InitByteValue += '%s.%s.%s.%s|%s|%s\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumType, PcdDefaultValue)
1509
1510 #
1511 # Get current PCD value and size
1512 #
1513 CApp = CApp + ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
1514
1515 #
1516 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
1517 # the correct value. For structures with a flexible array member, the flexible
1518 # array member is detected, and the size is based on the highest index used with
1519 # the flexible array member. The flexible array member must be the last field
1520 # in a structure. The size formula for this case is:
1521 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
1522 #
1523 CApp = CApp + ' Size = sizeof(%s);\n' % (Pcd.DatumType)
1524 for FieldList in [Pcd.DefaultValues]:
1525 if not FieldList:
1526 continue
1527 for FieldName in FieldList:
1528 FieldName = "." + FieldName
1529 IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])
1530 if IsArray:
1531 try:
1532 Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)
1533 except BadExpression:
1534 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
1535 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))
1536 Value, ValueSize = ParseFieldValue(Value)
1537 CApp = CApp + ' __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
1538 else:
1539 NewFieldName = ''
1540 FieldName_ori = FieldName.strip('.')
1541 while '[' in FieldName:
1542 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
1543 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])
1544 FieldName = FieldName.split(']', 1)[1]
1545 FieldName = NewFieldName + FieldName
1546 while '[' in FieldName:
1547 FieldName = FieldName.rsplit('[', 1)[0]
1548 CApp = CApp + ' __FLEXIBLE_SIZE(Size, %s, %s, %d); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
1549 for skuname in self.SkuIdMgr.GetSkuChain(SkuName):
1550 inherit_OverrideValues = Pcd.SkuOverrideValues[skuname]
1551 for FieldList in [inherit_OverrideValues.get(DefaultStoreName)]:
1552 if not FieldList:
1553 continue
1554 for FieldName in FieldList:
1555 FieldName = "." + FieldName
1556 IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])
1557 if IsArray:
1558 try:
1559 Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)
1560 except BadExpression:
1561 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
1562 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))
1563 Value, ValueSize = ParseFieldValue(Value)
1564 CApp = CApp + ' __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
1565 else:
1566 NewFieldName = ''
1567 FieldName_ori = FieldName.strip('.')
1568 while '[' in FieldName:
1569 NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
1570 ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])
1571 FieldName = FieldName.split(']', 1)[1]
1572 FieldName = NewFieldName + FieldName
1573 while '[' in FieldName:
1574 FieldName = FieldName.rsplit('[', 1)[0]
1575 CApp = CApp + ' __FLEXIBLE_SIZE(Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
1576 if skuname == SkuName:
1577 break
1578
1579 #
1580 # Allocate and zero buffer for the PCD
1581 # Must handle cases where current value is smaller, larger, or same size
1582 # Always keep that larger one as the current size
1583 #
1584 CApp = CApp + ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
1585 CApp = CApp + ' Pcd = (%s *)malloc (Size);\n' % (Pcd.DatumType)
1586 CApp = CApp + ' memset (Pcd, 0, Size);\n'
1587
1588 #
1589 # Copy current PCD value into allocated buffer.
1590 #
1591 CApp = CApp + ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
1592
1593 #
1594 # Assign field values in PCD
1595 #
1596 for FieldList in [Pcd.DefaultValues]:
1597 if not FieldList:
1598 continue
1599 for FieldName in FieldList:
1600 IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
1601 if IsArray:
1602 try:
1603 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)
1604 except BadExpression:
1605 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
1606 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1],FieldList[FieldName][2]))
1607
1608 try:
1609 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
1610 except Exception:
1611 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
1612 if isinstance(Value, str):
1613 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
1614 elif IsArray:
1615 #
1616 # Use memcpy() to copy value into field
1617 #
1618 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
1619 CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
1620 CApp = CApp + ' memcpy (&Pcd->%s[0], Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
1621 else:
1622 if ValueSize > 4:
1623 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
1624 else:
1625 CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
1626 for skuname in self.SkuIdMgr.GetSkuChain(SkuName):
1627 inherit_OverrideValues = Pcd.SkuOverrideValues[skuname]
1628 for FieldList in [Pcd.DefaultFromDSC,inherit_OverrideValues.get(DefaultStoreName)]:
1629 if not FieldList:
1630 continue
1631 if Pcd.DefaultFromDSC and FieldList == Pcd.DefaultFromDSC:
1632 IsArray = self.IsFieldValueAnArray(FieldList)
1633 if IsArray:
1634 try:
1635 FieldList = ValueExpressionEx(FieldList, "VOID*")(True)
1636 except BadExpression:
1637 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" %
1638 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))
1639
1640 Value, ValueSize = ParseFieldValue (FieldList)
1641 if isinstance(Value, str):
1642 CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC)
1643 elif IsArray:
1644 #
1645 # Use memcpy() to copy value into field
1646 #
1647 CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC)
1648 CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)
1649 continue
1650
1651 for FieldName in FieldList:
1652 IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
1653 if IsArray:
1654 try:
1655 FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)
1656 except BadExpression:
1657 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
1658 (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))
1659
1660 try:
1661 Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
1662 except Exception:
1663 EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
1664 if isinstance(Value, str):
1665 CApp = CApp + ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
1666 elif IsArray:
1667 #
1668 # Use memcpy() to copy value into field
1669 #
1670 CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
1671 CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
1672 CApp = CApp + ' memcpy (&Pcd->%s[0], Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
1673 else:
1674 if ValueSize > 4:
1675 CApp = CApp + ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
1676 else:
1677 CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
1678 if skuname == SkuName:
1679 break
1680 #
1681 # Set new PCD value and size
1682 #
1683 CApp = CApp + ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
1684
1685 #
1686 # Free PCD
1687 #
1688 CApp = CApp + ' free (Pcd);\n'
1689 CApp = CApp + '}\n'
1690 CApp = CApp + '\n'
1691 return InitByteValue, CApp
1692
1693 def GenerateByteArrayValue (self, StructuredPcds):
1694 #
1695 # Generate/Compile/Run C application to determine if there are any flexible array members
1696 #
1697 if not StructuredPcds:
1698 return
1699
1700 InitByteValue = ""
1701 CApp = PcdMainCHeader
1702
1703 Includes = {}
1704 for PcdName in StructuredPcds:
1705 Pcd = StructuredPcds[PcdName]
1706 for IncludeFile in Pcd.StructuredPcdIncludeFile:
1707 if IncludeFile not in Includes:
1708 Includes[IncludeFile] = True
1709 CApp = CApp + '#include <%s>\n' % (IncludeFile)
1710 CApp = CApp + '\n'
1711
1712 for PcdName in StructuredPcds:
1713 Pcd = StructuredPcds[PcdName]
1714 if not Pcd.SkuOverrideValues:
1715 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd, InitByteValue, CApp)
1716 else:
1717 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
1718 if SkuName not in Pcd.SkuOverrideValues:
1719 continue
1720 for DefaultStoreName in Pcd.DefaultStoreName:
1721 Pcd = StructuredPcds[PcdName]
1722 InitByteValue, CApp = self.GenerateInitializeFunc(SkuName, DefaultStoreName, Pcd, InitByteValue, CApp)
1723
1724 CApp = CApp + 'VOID\n'
1725 CApp = CApp + 'PcdEntryPoint(\n'
1726 CApp = CApp + ' VOID\n'
1727 CApp = CApp + ' )\n'
1728 CApp = CApp + '{\n'
1729 for Pcd in StructuredPcds.values():
1730 if not Pcd.SkuOverrideValues:
1731 CApp = CApp + ' Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
1732 else:
1733 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
1734 if SkuName not in Pcd.SkuOverrideValues:
1735 continue
1736 for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:
1737 CApp = CApp + ' Initialize_%s_%s_%s_%s();\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
1738 CApp = CApp + '}\n'
1739
1740 CApp = CApp + PcdMainCEntry + '\n'
1741
1742 if not os.path.exists(self.OutputPath):
1743 os.makedirs(self.OutputPath)
1744 CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
1745 File = open (CAppBaseFileName + '.c', 'w')
1746 File.write(CApp)
1747 File.close()
1748
1749 MakeApp = PcdMakefileHeader
1750 if sys.platform == "win32":
1751 MakeApp = MakeApp + 'ARCH = IA32\nAPPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\%s.obj\n' % (self.OutputPath, PcdValueInitName) + 'INC = '
1752 else:
1753 MakeApp = MakeApp + PcdGccMakefile
1754 MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o\n' % (self.OutputPath, PcdValueInitName) + \
1755 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
1756
1757 PlatformInc = {}
1758 for Cache in self._Bdb._CACHE_.values():
1759 if Cache.MetaFile.Ext.lower() != '.dec':
1760 continue
1761 if Cache.Includes:
1762 if str(Cache.MetaFile.Path) not in PlatformInc:
1763 PlatformInc[str(Cache.MetaFile.Path)] = Cache.Includes
1764
1765 PcdDependDEC = []
1766 for Pcd in StructuredPcds.values():
1767 for PackageDec in Pcd.PackageDecs:
1768 Package = os.path.normpath(mws.join(GlobalData.gWorkspace, PackageDec))
1769 if not os.path.exists(Package):
1770 EdkLogger.error('Build', RESOURCE_NOT_AVAILABLE, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
1771 if Package not in PcdDependDEC:
1772 PcdDependDEC.append(Package)
1773
1774 if PlatformInc and PcdDependDEC:
1775 for pkg in PcdDependDEC:
1776 if pkg in PlatformInc:
1777 for inc in PlatformInc[pkg]:
1778 MakeApp += '-I' + str(inc) + ' '
1779 MakeApp = MakeApp + '\n'
1780
1781 CC_FLAGS = LinuxCFLAGS
1782 if sys.platform == "win32":
1783 CC_FLAGS = WindowsCFLAGS
1784 BuildOptions = {}
1785 for Options in self.BuildOptions:
1786 if Options[2] != EDKII_NAME:
1787 continue
1788 Family = Options[0]
1789 if Family and Family != self.ToolChainFamily:
1790 continue
1791 Target, Tag, Arch, Tool, Attr = Options[1].split("_")
1792 if Tool != 'CC':
1793 continue
1794
1795 if Target == "*" or Target == self._Target:
1796 if Tag == "*" or Tag == self._Toolchain:
1797 if Arch == "*" or Arch == self.Arch:
1798 if Tool not in BuildOptions:
1799 BuildOptions[Tool] = {}
1800 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or self.BuildOptions[Options].startswith('='):
1801 BuildOptions[Tool][Attr] = self.BuildOptions[Options]
1802 else:
1803 # append options for the same tool except PATH
1804 if Attr != 'PATH':
1805 BuildOptions[Tool][Attr] += " " + self.BuildOptions[Options]
1806 else:
1807 BuildOptions[Tool][Attr] = self.BuildOptions[Options]
1808 if BuildOptions:
1809 for Tool in BuildOptions:
1810 for Attr in BuildOptions[Tool]:
1811 if Attr == "FLAGS":
1812 Value = BuildOptions[Tool][Attr]
1813 ValueList = Value.split()
1814 if ValueList:
1815 for Id, Item in enumerate(ValueList):
1816 if Item == '-D' or Item == '/D':
1817 CC_FLAGS += ' ' + Item
1818 if Id + 1 < len(ValueList):
1819 CC_FLAGS += ' ' + ValueList[Id + 1]
1820 elif Item.startswith('/D') or Item.startswith('-D'):
1821 CC_FLAGS += ' ' + Item
1822 MakeApp += CC_FLAGS
1823
1824 if sys.platform == "win32":
1825 MakeApp = MakeApp + PcdMakefileEnd
1826 MakeFileName = os.path.join(self.OutputPath, 'Makefile')
1827 File = open (MakeFileName, 'w')
1828 File.write(MakeApp)
1829 File.close()
1830
1831 InputValueFile = os.path.join(self.OutputPath, 'Input.txt')
1832 OutputValueFile = os.path.join(self.OutputPath, 'Output.txt')
1833 File = open (InputValueFile, 'w')
1834 File.write(InitByteValue)
1835 File.close()
1836
1837 Messages = ''
1838 if sys.platform == "win32":
1839 MakeCommand = 'nmake clean & nmake -f %s' % (MakeFileName)
1840 returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
1841 Messages = StdOut
1842 else:
1843 MakeCommand = 'make clean & make -f %s' % (MakeFileName)
1844 returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
1845 Messages = StdErr
1846 Messages = Messages.split('\n')
1847 MessageGroup = []
1848 if returncode <>0:
1849 CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
1850 File = open (CAppBaseFileName + '.c', 'r')
1851 FileData = File.readlines()
1852 File.close()
1853 for Message in Messages:
1854 if " error" in Message or "warning" in Message:
1855 FileInfo = Message.strip().split('(')
1856 if len (FileInfo) > 1:
1857 FileName = FileInfo [0]
1858 FileLine = FileInfo [1].split (')')[0]
1859 else:
1860 FileInfo = Message.strip().split(':')
1861 FileName = FileInfo [0]
1862 FileLine = FileInfo [1]
1863 if FileLine.isdigit():
1864 error_line = FileData[int (FileLine) - 1]
1865 if r"//" in error_line:
1866 c_line,dsc_line = error_line.split(r"//")
1867 else:
1868 dsc_line = error_line
1869 message_itmes = Message.split(":")
1870 Index = 0
1871 if "PcdValueInit.c" not in Message:
1872 break
1873 else:
1874 for item in message_itmes:
1875 if "PcdValueInit.c" in item:
1876 Index = message_itmes.index(item)
1877 message_itmes[Index] = dsc_line.strip()
1878 break
1879 MessageGroup.append(":".join(message_itmes[Index:]).strip())
1880 continue
1881 else:
1882 MessageGroup.append(Message)
1883 if MessageGroup:
1884 EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) )
1885 else:
1886 EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand)
1887
1888 PcdValueInitExe = PcdValueInitName
1889 if not sys.platform == "win32":
1890 PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName)
1891
1892 Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile)
1893 returncode, StdOut, StdErr = self.ExecuteCommand (Command)
1894 if returncode <> 0:
1895 EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command)
1896 FileBuffer = []
1897 else:
1898 File = open (OutputValueFile, 'r')
1899 FileBuffer = File.readlines()
1900 File.close()
1901
1902 StructurePcdSet = []
1903 for Pcd in FileBuffer:
1904 PcdValue = Pcd.split ('|')
1905 PcdInfo = PcdValue[0].split ('.')
1906 StructurePcdSet.append((PcdInfo[0],PcdInfo[1], PcdInfo[2], PcdInfo[3], PcdValue[2].strip()))
1907 return StructurePcdSet
1908
1909 ## Retrieve dynamic PCD settings
1910 #
1911 # @param Type PCD type
1912 #
1913 # @retval a dict object contains settings of given PCD type
1914 #
1915 def _GetDynamicPcd(self, Type):
1916
1917
1918 Pcds = sdict()
1919 #
1920 # tdict is a special dict kind of type, used for selecting correct
1921 # PCD settings for certain ARCH and SKU
1922 #
1923 PcdDict = tdict(True, 4)
1924 PcdList = []
1925 # Find out all possible PCD candidates for self._Arch
1926 RecordList = self._RawData[Type, self._Arch]
1927 AvailableSkuIdSet = copy.copy(self.SkuIds)
1928
1929
1930 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4,Dummy5 in RecordList:
1931 SkuName = SkuName.upper()
1932 SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
1933 if SkuName not in AvailableSkuIdSet:
1934 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
1935 File=self.MetaFile, Line=Dummy5)
1936 if "." not in TokenSpaceGuid:
1937 PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
1938 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
1939
1940 # Remove redundant PCD candidates, per the ARCH and SKU
1941 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
1942
1943 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
1944 if Setting == None:
1945 continue
1946
1947 PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
1948 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '', '', '', '', '', PcdValue)
1949 if (PcdCName, TokenSpaceGuid) in Pcds.keys():
1950 pcdObject = Pcds[PcdCName, TokenSpaceGuid]
1951 pcdObject.SkuInfoList[SkuName] = SkuInfo
1952 if MaxDatumSize.strip():
1953 CurrentMaxSize = int(MaxDatumSize.strip(), 0)
1954 else:
1955 CurrentMaxSize = 0
1956 if pcdObject.MaxDatumSize:
1957 PcdMaxSize = int(pcdObject.MaxDatumSize, 0)
1958 else:
1959 PcdMaxSize = 0
1960 if CurrentMaxSize > PcdMaxSize:
1961 pcdObject.MaxDatumSize = str(CurrentMaxSize)
1962 else:
1963 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
1964 PcdCName,
1965 TokenSpaceGuid,
1966 self._PCD_TYPE_STRING_[Type],
1967 DatumType,
1968 PcdValue,
1969 '',
1970 MaxDatumSize,
1971 {SkuName : SkuInfo},
1972 False,
1973 None,
1974 IsDsc=True)
1975
1976 for pcd in Pcds.values():
1977 pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]
1978 # Only fix the value while no value provided in DSC file.
1979 for sku in pcd.SkuInfoList.values():
1980 if (sku.DefaultValue == "" or sku.DefaultValue==None):
1981 sku.DefaultValue = pcdDecObject.DefaultValue
1982 if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
1983 valuefromDec = pcdDecObject.DefaultValue
1984 SkuInfo = SkuInfoClass('DEFAULT', '0', '', '', '', '', '', valuefromDec)
1985 pcd.SkuInfoList['DEFAULT'] = SkuInfo
1986 elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
1987 pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
1988 del(pcd.SkuInfoList['COMMON'])
1989 elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
1990 del(pcd.SkuInfoList['COMMON'])
1991
1992 map(self.FilterSkuSettings,Pcds.values())
1993
1994 return Pcds
1995
1996 def FilterSkuSettings(self, PcdObj):
1997
1998 if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE:
1999 if 'DEFAULT' in PcdObj.SkuInfoList.keys() and self.SkuIdMgr.SystemSkuId not in PcdObj.SkuInfoList.keys():
2000 PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId] = PcdObj.SkuInfoList['DEFAULT']
2001 PcdObj.SkuInfoList = {'DEFAULT':PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId]}
2002 PcdObj.SkuInfoList['DEFAULT'].SkuIdName = 'DEFAULT'
2003 PcdObj.SkuInfoList['DEFAULT'].SkuId = '0'
2004
2005 elif self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.DEFAULT:
2006 PcdObj.SkuInfoList = {'DEFAULT':PcdObj.SkuInfoList['DEFAULT']}
2007
2008 return PcdObj
2009
2010
2011 def CompareVarAttr(self, Attr1, Attr2):
2012 if not Attr1 or not Attr2: # for empty string
2013 return True
2014 Attr1s = [attr.strip() for attr in Attr1.split(",")]
2015 Attr1Set = set(Attr1s)
2016 Attr2s = [attr.strip() for attr in Attr2.split(",")]
2017 Attr2Set = set(Attr2s)
2018 if Attr2Set == Attr1Set:
2019 return True
2020 else:
2021 return False
2022 def CompletePcdValues(self,PcdSet):
2023 Pcds = {}
2024 DefaultStoreObj = DefaultStore(self._GetDefaultStores())
2025 SkuIds = {skuname:skuid for skuname,skuid in self.SkuIdMgr.AvailableSkuIdSet.items() if skuname !='COMMON'}
2026 DefaultStores = set([storename for pcdobj in PcdSet.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict.keys()])
2027 for PcdCName, TokenSpaceGuid in PcdSet:
2028 PcdObj = PcdSet[(PcdCName, TokenSpaceGuid)]
2029 if PcdObj.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],
2030 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],
2031 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_VPD],
2032 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],
2033 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],
2034 self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]:
2035 Pcds[PcdCName, TokenSpaceGuid]= PcdObj
2036 continue
2037 PcdType = PcdObj.Type
2038 if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
2039 for skuid in PcdObj.SkuInfoList:
2040 skuobj = PcdObj.SkuInfoList[skuid]
2041 mindefaultstorename = DefaultStoreObj.GetMin(set([defaultstorename for defaultstorename in skuobj.DefaultStoreDict]))
2042 for defaultstorename in DefaultStores:
2043 if defaultstorename not in skuobj.DefaultStoreDict:
2044 skuobj.DefaultStoreDict[defaultstorename] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])
2045 skuobj.HiiDefaultValue = skuobj.DefaultStoreDict[mindefaultstorename]
2046 for skuname,skuid in SkuIds.items():
2047 if skuname not in PcdObj.SkuInfoList:
2048 nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)
2049 while nextskuid not in PcdObj.SkuInfoList:
2050 nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)
2051 PcdObj.SkuInfoList[skuname] = copy.deepcopy(PcdObj.SkuInfoList[nextskuid])
2052 PcdObj.SkuInfoList[skuname].SkuId = skuid
2053 PcdObj.SkuInfoList[skuname].SkuIdName = skuname
2054 if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
2055 PcdObj.DefaultValue = PcdObj.SkuInfoList.values()[0].HiiDefaultValue if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE else PcdObj.SkuInfoList["DEFAULT"].HiiDefaultValue
2056 Pcds[PcdCName, TokenSpaceGuid]= PcdObj
2057 return Pcds
2058 ## Retrieve dynamic HII PCD settings
2059 #
2060 # @param Type PCD type
2061 #
2062 # @retval a dict object contains settings of given PCD type
2063 #
2064 def _GetDynamicHiiPcd(self, Type):
2065
2066 VariableAttrs = {}
2067
2068 Pcds = sdict()
2069 #
2070 # tdict is a special dict kind of type, used for selecting correct
2071 # PCD settings for certain ARCH and SKU
2072 #
2073 PcdDict = tdict(True, 5)
2074 PcdSet = set()
2075 RecordList = self._RawData[Type, self._Arch]
2076 # Find out all possible PCD candidates for self._Arch
2077 AvailableSkuIdSet = copy.copy(self.SkuIds)
2078 DefaultStoresDefine = self._GetDefaultStores()
2079
2080 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, DefaultStore, Dummy4,Dummy5 in RecordList:
2081 SkuName = SkuName.upper()
2082 SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
2083 DefaultStore = DefaultStore.upper()
2084 if DefaultStore == "COMMON":
2085 DefaultStore = "STANDARD"
2086 if SkuName not in AvailableSkuIdSet:
2087 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
2088 File=self.MetaFile, Line=Dummy5)
2089 if DefaultStore not in DefaultStoresDefine:
2090 EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore,
2091 File=self.MetaFile, Line=Dummy5)
2092 if "." not in TokenSpaceGuid:
2093 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy5))
2094 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore] = Setting
2095
2096
2097 # Remove redundant PCD candidates, per the ARCH and SKU
2098 for PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4 in PcdSet:
2099
2100 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore]
2101 if Setting == None:
2102 continue
2103 VariableName, VariableGuid, VariableOffset, DefaultValue, VarAttribute = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
2104
2105 rt, Msg = VariableAttributes.ValidateVarAttributes(VarAttribute)
2106 if not rt:
2107 EdkLogger.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid, PcdCName)), Msg),
2108 ExtraData="[%s]" % VarAttribute)
2109 ExceedMax = False
2110 FormatCorrect = True
2111 if VariableOffset.isdigit():
2112 if int(VariableOffset, 10) > 0xFFFF:
2113 ExceedMax = True
2114 elif re.match(r'[\t\s]*0[xX][a-fA-F0-9]+$', VariableOffset):
2115 if int(VariableOffset, 16) > 0xFFFF:
2116 ExceedMax = True
2117 # For Offset written in "A.B"
2118 elif VariableOffset.find('.') > -1:
2119 VariableOffsetList = VariableOffset.split(".")
2120 if not (len(VariableOffsetList) == 2
2121 and IsValidWord(VariableOffsetList[0])
2122 and IsValidWord(VariableOffsetList[1])):
2123 FormatCorrect = False
2124 else:
2125 FormatCorrect = False
2126 if not FormatCorrect:
2127 EdkLogger.error('Build', FORMAT_INVALID, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid, PcdCName)))
2128
2129 if ExceedMax:
2130 EdkLogger.error('Build', OPTION_VALUE_INVALID, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid, PcdCName)))
2131 if (VariableName, VariableGuid) not in VariableAttrs:
2132 VariableAttrs[(VariableName, VariableGuid)] = VarAttribute
2133 else:
2134 if not self.CompareVarAttr(VariableAttrs[(VariableName, VariableGuid)], VarAttribute):
2135 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)]))
2136
2137 pcdDecObject = self._DecPcds[PcdCName, TokenSpaceGuid]
2138 if (PcdCName, TokenSpaceGuid) in Pcds.keys():
2139 pcdObject = Pcds[PcdCName, TokenSpaceGuid]
2140 if SkuName in pcdObject.SkuInfoList:
2141 Skuitem = pcdObject.SkuInfoList[SkuName]
2142 Skuitem.DefaultStoreDict.update({DefaultStore:DefaultValue})
2143 else:
2144 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], VariableName, VariableGuid, VariableOffset, DefaultValue, VariableAttribute=VarAttribute,DefaultStore={DefaultStore:DefaultValue})
2145 pcdObject.SkuInfoList[SkuName] = SkuInfo
2146 else:
2147 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], VariableName, VariableGuid, VariableOffset, DefaultValue, VariableAttribute=VarAttribute,DefaultStore={DefaultStore:DefaultValue})
2148 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
2149 PcdCName,
2150 TokenSpaceGuid,
2151 self._PCD_TYPE_STRING_[Type],
2152 '',
2153 DefaultValue,
2154 '',
2155 '',
2156 {SkuName : SkuInfo},
2157 False,
2158 None,
2159 pcdDecObject.validateranges,
2160 pcdDecObject.validlists,
2161 pcdDecObject.expressions,
2162 IsDsc=True)
2163
2164
2165 for pcd in Pcds.values():
2166 SkuInfoObj = pcd.SkuInfoList.values()[0]
2167 pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]
2168 # Only fix the value while no value provided in DSC file.
2169 for sku in pcd.SkuInfoList.values():
2170 if (sku.HiiDefaultValue == "" or sku.HiiDefaultValue == None):
2171 sku.HiiDefaultValue = pcdDecObject.DefaultValue
2172 if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
2173 valuefromDec = pcdDecObject.DefaultValue
2174 SkuInfo = SkuInfoClass('DEFAULT', '0', SkuInfoObj.VariableName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec,VariableAttribute=SkuInfoObj.VariableAttribute,DefaultStore={DefaultStore:valuefromDec})
2175 pcd.SkuInfoList['DEFAULT'] = SkuInfo
2176 elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
2177 pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
2178 del(pcd.SkuInfoList['COMMON'])
2179 elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
2180 del(pcd.SkuInfoList['COMMON'])
2181
2182 if pcd.MaxDatumSize.strip():
2183 MaxSize = int(pcd.MaxDatumSize, 0)
2184 else:
2185 MaxSize = 0
2186 if pcdDecObject.DatumType == 'VOID*':
2187 for (_, skuobj) in pcd.SkuInfoList.items():
2188 datalen = 0
2189 skuobj.HiiDefaultValue = StringToArray(skuobj.HiiDefaultValue)
2190 datalen = len(skuobj.HiiDefaultValue.split(","))
2191 if datalen > MaxSize:
2192 MaxSize = datalen
2193 for defaultst in skuobj.DefaultStoreDict:
2194 skuobj.DefaultStoreDict[defaultst] = StringToArray(skuobj.DefaultStoreDict[defaultst])
2195 pcd.DefaultValue = StringToArray(pcd.DefaultValue)
2196 pcd.MaxDatumSize = str(MaxSize)
2197 rt, invalidhii = self.CheckVariableNameAssignment(Pcds)
2198 if not rt:
2199 invalidpcd = ",".join(invalidhii)
2200 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)
2201
2202 map(self.FilterSkuSettings,Pcds.values())
2203
2204 return Pcds
2205
2206 def CheckVariableNameAssignment(self,Pcds):
2207 invalidhii = []
2208 for pcdname in Pcds:
2209 pcd = Pcds[pcdname]
2210 varnameset = set([sku.VariableName for (skuid,sku) in pcd.SkuInfoList.items()])
2211 if len(varnameset) > 1:
2212 invalidhii.append(".".join((pcdname[1],pcdname[0])))
2213 if len(invalidhii):
2214 return False,invalidhii
2215 else:
2216 return True, []
2217 ## Retrieve dynamic VPD PCD settings
2218 #
2219 # @param Type PCD type
2220 #
2221 # @retval a dict object contains settings of given PCD type
2222 #
2223 def _GetDynamicVpdPcd(self, Type):
2224
2225
2226 Pcds = sdict()
2227 #
2228 # tdict is a special dict kind of type, used for selecting correct
2229 # PCD settings for certain ARCH and SKU
2230 #
2231 PcdDict = tdict(True, 4)
2232 PcdList = []
2233
2234 # Find out all possible PCD candidates for self._Arch
2235 RecordList = self._RawData[Type, self._Arch]
2236 AvailableSkuIdSet = copy.copy(self.SkuIds)
2237
2238 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4,Dummy5 in RecordList:
2239 SkuName = SkuName.upper()
2240 SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
2241 if SkuName not in AvailableSkuIdSet:
2242 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
2243 File=self.MetaFile, Line=Dummy5)
2244 if "." not in TokenSpaceGuid:
2245 PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
2246 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
2247
2248 # Remove redundant PCD candidates, per the ARCH and SKU
2249 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
2250 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
2251 if Setting == None:
2252 continue
2253 #
2254 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
2255 # For the Integer & Boolean type, the optional data can only be InitialValue.
2256 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
2257 # until the DEC parser has been called.
2258 #
2259 VpdOffset, MaxDatumSize, InitialValue = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
2260 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '', '', '', '', VpdOffset, InitialValue)
2261 if (PcdCName, TokenSpaceGuid) in Pcds.keys():
2262 pcdObject = Pcds[PcdCName, TokenSpaceGuid]
2263 pcdObject.SkuInfoList[SkuName] = SkuInfo
2264 if MaxDatumSize.strip():
2265 CurrentMaxSize = int(MaxDatumSize.strip(), 0)
2266 else:
2267 CurrentMaxSize = 0
2268 if pcdObject.MaxDatumSize:
2269 PcdMaxSize = int(pcdObject.MaxDatumSize, 0)
2270 else:
2271 PcdMaxSize = 0
2272 if CurrentMaxSize > PcdMaxSize:
2273 pcdObject.MaxDatumSize = str(CurrentMaxSize)
2274 else:
2275 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
2276 PcdCName,
2277 TokenSpaceGuid,
2278 self._PCD_TYPE_STRING_[Type],
2279 '',
2280 InitialValue,
2281 '',
2282 MaxDatumSize,
2283 {SkuName : SkuInfo},
2284 False,
2285 None,
2286 IsDsc=True)
2287 for pcd in Pcds.values():
2288 SkuInfoObj = pcd.SkuInfoList.values()[0]
2289 pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]
2290 # Only fix the value while no value provided in DSC file.
2291 for sku in pcd.SkuInfoList.values():
2292 if (sku.DefaultValue == "" or sku.DefaultValue==None):
2293 sku.DefaultValue = pcdDecObject.DefaultValue
2294 if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
2295 valuefromDec = pcdDecObject.DefaultValue
2296 SkuInfo = SkuInfoClass('DEFAULT', '0', '', '', '', '', SkuInfoObj.VpdOffset, valuefromDec)
2297 pcd.SkuInfoList['DEFAULT'] = SkuInfo
2298 elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
2299 pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
2300 del(pcd.SkuInfoList['COMMON'])
2301 elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
2302 del(pcd.SkuInfoList['COMMON'])
2303
2304
2305 map(self.FilterSkuSettings,Pcds.values())
2306 return Pcds
2307
2308 ## Add external modules
2309 #
2310 # The external modules are mostly those listed in FDF file, which don't
2311 # need "build".
2312 #
2313 # @param FilePath The path of module description file
2314 #
2315 def AddModule(self, FilePath):
2316 FilePath = NormPath(FilePath)
2317 if FilePath not in self.Modules:
2318 Module = ModuleBuildClassObject()
2319 Module.MetaFile = FilePath
2320 self.Modules.append(Module)
2321
2322 def _GetToolChainFamily(self):
2323 self._ToolChainFamily = "MSFT"
2324 BuildConfigurationFile = os.path.normpath(os.path.join(GlobalData.gConfDirectory, "target.txt"))
2325 if os.path.isfile(BuildConfigurationFile) == True:
2326 TargetTxt = TargetTxtClassObject()
2327 TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
2328 ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
2329 if ToolDefinitionFile == '':
2330 ToolDefinitionFile = "tools_def.txt"
2331 ToolDefinitionFile = os.path.normpath(mws.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile))
2332 if os.path.isfile(ToolDefinitionFile) == True:
2333 ToolDef = ToolDefClassObject()
2334 ToolDef.LoadToolDefFile(ToolDefinitionFile)
2335 ToolDefinition = ToolDef.ToolsDefTxtDatabase
2336 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \
2337 or self._Toolchain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \
2338 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]:
2339 self._ToolChainFamily = "MSFT"
2340 else:
2341 self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]
2342 return self._ToolChainFamily
2343
2344 ## Add external PCDs
2345 #
2346 # The external PCDs are mostly those listed in FDF file to specify address
2347 # or offset information.
2348 #
2349 # @param Name Name of the PCD
2350 # @param Guid Token space guid of the PCD
2351 # @param Value Value of the PCD
2352 #
2353 def AddPcd(self, Name, Guid, Value):
2354 if (Name, Guid) not in self.Pcds:
2355 self.Pcds[Name, Guid] = PcdClassObject(Name, Guid, '', '', '', '', '', {}, False, None)
2356 self.Pcds[Name, Guid].DefaultValue = Value
2357 @property
2358 def DecPcds(self):
2359 if self._DecPcds == None:
2360 FdfInfList = []
2361 if GlobalData.gFdfParser:
2362 FdfInfList = GlobalData.gFdfParser.Profile.InfList
2363 PkgSet = set()
2364 for Inf in FdfInfList:
2365 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch=self._Arch)
2366 if ModuleFile in self._Modules:
2367 continue
2368 ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]
2369 PkgSet.update(ModuleData.Packages)
2370 self._DecPcds, self._GuidDict = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain,PkgSet)
2371 return self._DecPcds
2372 _Macros = property(_GetMacros)
2373 Arch = property(_GetArch, _SetArch)
2374 Platform = property(_GetPlatformName)
2375 PlatformName = property(_GetPlatformName)
2376 Guid = property(_GetFileGuid)
2377 Version = property(_GetVersion)
2378 DscSpecification = property(_GetDscSpec)
2379 OutputDirectory = property(_GetOutpuDir)
2380 SupArchList = property(_GetSupArch)
2381 BuildTargets = property(_GetBuildTarget)
2382 SkuName = property(_GetSkuName, _SetSkuName)
2383 PcdInfoFlag = property(_GetPcdInfoFlag)
2384 VarCheckFlag = property(_GetVarCheckFlag)
2385 FlashDefinition = property(_GetFdfFile)
2386 Prebuild = property(_GetPrebuild)
2387 Postbuild = property(_GetPostbuild)
2388 BuildNumber = property(_GetBuildNumber)
2389 MakefileName = property(_GetMakefileName)
2390 BsBaseAddress = property(_GetBsBaseAddress)
2391 RtBaseAddress = property(_GetRtBaseAddress)
2392 LoadFixAddress = property(_GetLoadFixAddress)
2393 RFCLanguages = property(_GetRFCLanguages)
2394 ISOLanguages = property(_GetISOLanguages)
2395 VpdToolGuid = property(_GetVpdToolGuid)
2396 SkuIds = property(_GetSkuIds)
2397 Modules = property(_GetModules)
2398 LibraryInstances = property(_GetLibraryInstances)
2399 LibraryClasses = property(_GetLibraryClasses)
2400 Pcds = property(_GetPcds)
2401 BuildOptions = property(_GetBuildOptions)
2402 ToolChainFamily = property(_GetToolChainFamily)