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