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