2 # This file is used to create a database used by build tool
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
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.
15 ## Platform build information from DSC file
17 # This class is used to retrieve information stored in database and convert them
18 # into PlatformBuildClassObject form for easier use for AutoGen.
20 from __future__
import print_function
21 from __future__
import absolute_import
22 from Common
.StringUtils
import *
23 from Common
.DataType
import *
24 from Common
.Misc
import *
26 from Common
.Expression
import *
27 from CommonDataClass
.CommonClass
import SkuInfoClass
28 from Common
.TargetTxtClassObject
import TargetTxtClassObject
29 from Common
.ToolDefClassObject
import ToolDefClassObject
30 from .MetaDataTable
import *
31 from .MetaFileTable
import *
32 from .MetaFileParser
import *
34 from .WorkspaceCommon
import GetDeclaredPcd
35 from Common
.Misc
import AnalyzeDscPcd
36 from Common
.Misc
import ProcessDuplicatedInf
,RemoveCComments
38 from Common
.Parsing
import IsValidWord
39 from Common
.VariableAttributes
import VariableAttributes
40 import Common
.GlobalData
as GlobalData
42 from Common
.Misc
import SaveFileOnChange
43 from Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
44 from collections
import OrderedDict
, defaultdict
45 from .BuildClassObject
import ArrayIndex
47 PcdValueInitName
= 'PcdValueInit'
58 #include <PcdValueCommon.h>
68 return PcdValueMain (argc, argv);
72 PcdMakefileHeader
= '''
75 # This file is auto-generated by build utility
80 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
81 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
83 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
85 LIBS = $(LIB_PATH)\Common.lib
87 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
92 $(APPFILE): $(OBJECTS)
97 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
101 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
102 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
103 ## regular expressions for finding decimal and hex numbers
104 Pattern
= re
.compile('^[1-9]\d*|0$')
105 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
106 ## Regular expression for finding header file inclusions
107 from AutoGen
.GenMake
import gIncludePattern
109 ## Find dependencies for one source file
111 # By searching recursively "#include" directive in file, find out all the
112 # files needed by given source file. The dependecies will be only searched
113 # in given search path list.
115 # @param SearchPathList The list of search path
117 # @retval list The list of files the given source file depends on
119 def GetDependencyList(FileStack
, SearchPathList
):
121 DependencySet
= set(FileStack
)
122 while len(FileStack
) > 0:
124 FullPathDependList
= []
125 CurrentFileDependencyList
= []
127 CurrentFileDependencyList
= DepDb
[F
]
131 FileContent
= Fd
.read()
132 except BaseException
as X
:
133 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
135 if "Fd" in dir(locals()):
138 if len(FileContent
) == 0:
141 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
142 FileContent
= unicode(FileContent
, "utf-16")
143 IncludedFileList
= gIncludePattern
.findall(FileContent
)
145 for Inc
in IncludedFileList
:
147 Inc
= os
.path
.normpath(Inc
)
148 CurrentFileDependencyList
.append(Inc
)
149 DepDb
[F
] = CurrentFileDependencyList
151 CurrentFilePath
= os
.path
.dirname(F
)
152 PathList
= [CurrentFilePath
] + SearchPathList
153 for Inc
in CurrentFileDependencyList
:
154 for SearchPath
in PathList
:
155 FilePath
= os
.path
.join(SearchPath
, Inc
)
156 if not os
.path
.exists(FilePath
):
158 if FilePath
not in DependencySet
:
159 FileStack
.append(FilePath
)
160 FullPathDependList
.append(FilePath
)
162 DependencySet
.update(FullPathDependList
)
163 DependencyList
= list(DependencySet
) # remove duplicate ones
165 return DependencyList
167 class DscBuildData(PlatformBuildClassObject
):
168 # dict used to convert PCD type in database to string used by build tool
169 _PCD_TYPE_STRING_
= {
170 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
171 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
172 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
173 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
174 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
175 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
176 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
177 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
178 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
179 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
180 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
183 # dict used to convert part of [Defines] to members of DscBuildData directly
188 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
189 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
190 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
191 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
192 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
193 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
194 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
195 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
196 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
197 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
198 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
199 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
200 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
201 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
202 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
205 # used to compose dummy library class name for those forced library instances
206 _NullLibraryNumber
= 0
208 ## Constructor of DscBuildData
210 # Initialize object of DscBuildData
212 # @param FilePath The path of platform description file
213 # @param RawData The raw data of DSC file
214 # @param BuildDataBase Database used to retrieve module/package information
215 # @param Arch The target architecture
216 # @param Platform (not used for DscBuildData)
217 # @param Macros Macros used for replacement in DSC file
219 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
220 self
.MetaFile
= FilePath
221 self
._RawData
= RawData
222 self
._Bdb
= BuildDataBase
224 self
._Target
= Target
225 self
._Toolchain
= Toolchain
226 self
._ToolChainFamily
= None
228 self
._HandleOverridePath
()
229 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
230 self
.DefaultStores
= None
231 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
234 def OutputPath(self
):
235 if os
.getenv("WORKSPACE"):
236 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
238 return os
.path
.dirname(self
.DscFile
)
241 def __setitem__(self
, key
, value
):
242 self
.__dict
__[self
._PROPERTY
_[key
]] = value
245 def __getitem__(self
, key
):
246 return self
.__dict
__[self
._PROPERTY
_[key
]]
249 def __contains__(self
, key
):
250 return key
in self
._PROPERTY
_
252 ## Set all internal used members of DscBuildData to None
255 self
._PlatformName
= None
258 self
._DscSpecification
= None
259 self
._OutputDirectory
= None
260 self
._SupArchList
= None
261 self
._BuildTargets
= None
263 self
._PcdInfoFlag
= None
264 self
._VarCheckFlag
= None
265 self
._FlashDefinition
= None
266 self
._Prebuild
= None
267 self
._Postbuild
= None
268 self
._BuildNumber
= None
269 self
._MakefileName
= None
270 self
._BsBaseAddress
= None
271 self
._RtBaseAddress
= None
274 self
._LibraryInstances
= None
275 self
._LibraryClasses
= None
278 self
._BuildOptions
= None
279 self
._ModuleTypeOptions
= None
280 self
._LoadFixAddress
= None
281 self
._RFCLanguages
= None
282 self
._ISOLanguages
= None
283 self
._VpdToolGuid
= None
284 self
._MacroDict
= None
285 self
.DefaultStores
= None
287 ## handle Override Path of Module
288 def _HandleOverridePath(self
):
289 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
290 for Record
in RecordList
:
293 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
294 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
296 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
298 # Check if the source override path exists
299 if not os
.path
.isdir(SourceOverridePath
):
300 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
302 # Add to GlobalData Variables
303 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
305 ## Get current effective macros
308 if self
._MacroDict
is None:
310 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
311 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
312 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
313 return self
._MacroDict
320 ## Retrieve all information in [Defines] section
322 # (Retriving all [Defines] information in one-shot is just to save time.)
324 def _GetHeaderInfo(self
):
325 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
326 for Record
in RecordList
:
328 # items defined _PROPERTY_ don't need additional processing
330 # some special items in [Defines] section need special treatment
331 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
332 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
333 if ' ' in self
._OutputDirectory
:
334 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
335 File
=self
.MetaFile
, Line
=Record
[-1],
336 ExtraData
=self
._OutputDirectory
)
337 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
338 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
339 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
341 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
343 elif Name
== TAB_DSC_PREBUILD
:
344 PrebuildValue
= Record
[2]
345 if Record
[2][0] == '"':
346 if Record
[2][-1] != '"':
347 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
348 File
=self
.MetaFile
, Line
=Record
[-1])
349 PrebuildValue
= Record
[2][1:-1]
350 self
._Prebuild
= PrebuildValue
351 elif Name
== TAB_DSC_POSTBUILD
:
352 PostbuildValue
= 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_POSTBUILD
,
356 File
=self
.MetaFile
, Line
=Record
[-1])
357 PostbuildValue
= Record
[2][1:-1]
358 self
._Postbuild
= PostbuildValue
359 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
360 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
361 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
362 self
._BuildTargets
= GetSplitValueList(Record
[2])
363 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
364 if self
._SkuName
is None:
365 self
._SkuName
= Record
[2]
366 if GlobalData
.gSKUID_CMD
:
367 self
._SkuName
= GlobalData
.gSKUID_CMD
368 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
369 self
._PcdInfoFlag
= Record
[2]
370 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
371 self
._VarCheckFlag
= Record
[2]
372 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
374 self
._LoadFixAddress
= int (Record
[2], 0)
376 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
377 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
378 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
379 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"',
380 File
=self
.MetaFile
, Line
=Record
[-1])
381 LanguageCodes
= Record
[2][1:-1]
382 if not LanguageCodes
:
383 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
384 File
=self
.MetaFile
, Line
=Record
[-1])
385 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
386 # check whether there is empty entries in the list
387 if None in LanguageList
:
388 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
389 File
=self
.MetaFile
, Line
=Record
[-1])
390 self
._RFCLanguages
= LanguageList
391 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
392 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
393 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
394 File
=self
.MetaFile
, Line
=Record
[-1])
395 LanguageCodes
= Record
[2][1:-1]
396 if not LanguageCodes
:
397 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
398 File
=self
.MetaFile
, Line
=Record
[-1])
399 if len(LanguageCodes
) % 3:
400 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
401 File
=self
.MetaFile
, Line
=Record
[-1])
403 for i
in range(0, len(LanguageCodes
), 3):
404 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
405 self
._ISOLanguages
= LanguageList
406 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
408 # try to convert GUID to a real UUID value to see whether the GUID is format
409 # for VPD_TOOL_GUID is correct.
414 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
415 self
._VpdToolGuid
= Record
[2]
417 self
[Name
] = Record
[2]
418 # set _Header to non-None in order to avoid database re-querying
419 self
._Header
= 'DUMMY'
421 ## Retrieve platform name
423 def PlatformName(self
):
424 if self
._PlatformName
is None:
425 if self
._Header
is None:
426 self
._GetHeaderInfo
()
427 if self
._PlatformName
is None:
428 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
429 return self
._PlatformName
433 return self
.PlatformName
435 ## Retrieve file guid
438 if self
._Guid
is None:
439 if self
._Header
is None:
440 self
._GetHeaderInfo
()
441 if self
._Guid
is None:
442 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
445 ## Retrieve platform version
448 if self
._Version
is None:
449 if self
._Header
is None:
450 self
._GetHeaderInfo
()
451 if self
._Version
is None:
452 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
455 ## Retrieve platform description file version
457 def DscSpecification(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
465 ## Retrieve OUTPUT_DIRECTORY
467 def OutputDirectory(self
):
468 if self
._OutputDirectory
is None:
469 if self
._Header
is None:
470 self
._GetHeaderInfo
()
471 if self
._OutputDirectory
is None:
472 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
473 return self
._OutputDirectory
475 ## Retrieve SUPPORTED_ARCHITECTURES
477 def SupArchList(self
):
478 if self
._SupArchList
is None:
479 if self
._Header
is None:
480 self
._GetHeaderInfo
()
481 if self
._SupArchList
is None:
482 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
483 return self
._SupArchList
485 ## Retrieve BUILD_TARGETS
487 def BuildTargets(self
):
488 if self
._BuildTargets
is None:
489 if self
._Header
is None:
490 self
._GetHeaderInfo
()
491 if self
._BuildTargets
is None:
492 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
493 return self
._BuildTargets
496 def PcdInfoFlag(self
):
497 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
499 elif self
._PcdInfoFlag
.upper() == 'TRUE':
505 def VarCheckFlag(self
):
506 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
508 elif self
._VarCheckFlag
.upper() == 'TRUE':
513 # # Retrieve SKUID_IDENTIFIER
516 if self
._SkuName
is None:
517 if self
._Header
is None:
518 self
._GetHeaderInfo
()
519 if self
._SkuName
is None:
520 self
._SkuName
= TAB_DEFAULT
523 ## Override SKUID_IDENTIFIER
525 def SkuName(self
, Value
):
526 self
._SkuName
= Value
529 def FlashDefinition(self
):
530 if self
._FlashDefinition
is None:
531 if self
._Header
is None:
532 self
._GetHeaderInfo
()
533 if self
._FlashDefinition
is None:
534 self
._FlashDefinition
= ''
535 return self
._FlashDefinition
539 if self
._Prebuild
is None:
540 if self
._Header
is None:
541 self
._GetHeaderInfo
()
542 if self
._Prebuild
is None:
544 return self
._Prebuild
548 if self
._Postbuild
is None:
549 if self
._Header
is None:
550 self
._GetHeaderInfo
()
551 if self
._Postbuild
is None:
553 return self
._Postbuild
555 ## Retrieve FLASH_DEFINITION
557 def BuildNumber(self
):
558 if self
._BuildNumber
is None:
559 if self
._Header
is None:
560 self
._GetHeaderInfo
()
561 if self
._BuildNumber
is None:
562 self
._BuildNumber
= ''
563 return self
._BuildNumber
565 ## Retrieve MAKEFILE_NAME
567 def MakefileName(self
):
568 if self
._MakefileName
is None:
569 if self
._Header
is None:
570 self
._GetHeaderInfo
()
571 if self
._MakefileName
is None:
572 self
._MakefileName
= ''
573 return self
._MakefileName
575 ## Retrieve BsBaseAddress
577 def BsBaseAddress(self
):
578 if self
._BsBaseAddress
is None:
579 if self
._Header
is None:
580 self
._GetHeaderInfo
()
581 if self
._BsBaseAddress
is None:
582 self
._BsBaseAddress
= ''
583 return self
._BsBaseAddress
585 ## Retrieve RtBaseAddress
587 def RtBaseAddress(self
):
588 if self
._RtBaseAddress
is None:
589 if self
._Header
is None:
590 self
._GetHeaderInfo
()
591 if self
._RtBaseAddress
is None:
592 self
._RtBaseAddress
= ''
593 return self
._RtBaseAddress
595 ## Retrieve the top address for the load fix address
597 def LoadFixAddress(self
):
598 if self
._LoadFixAddress
is None:
599 if self
._Header
is None:
600 self
._GetHeaderInfo
()
602 if self
._LoadFixAddress
is None:
603 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
606 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
608 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
611 # If command line defined, should override the value in DSC file.
613 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
615 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
617 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']))
619 if self
._LoadFixAddress
< 0:
620 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
621 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
622 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
624 return self
._LoadFixAddress
626 ## Retrieve RFCLanguage filter
628 def RFCLanguages(self
):
629 if self
._RFCLanguages
is None:
630 if self
._Header
is None:
631 self
._GetHeaderInfo
()
632 if self
._RFCLanguages
is None:
633 self
._RFCLanguages
= []
634 return self
._RFCLanguages
636 ## Retrieve ISOLanguage filter
638 def ISOLanguages(self
):
639 if self
._ISOLanguages
is None:
640 if self
._Header
is None:
641 self
._GetHeaderInfo
()
642 if self
._ISOLanguages
is None:
643 self
._ISOLanguages
= []
644 return self
._ISOLanguages
646 ## Retrieve the GUID string for VPD tool
648 def VpdToolGuid(self
):
649 if self
._VpdToolGuid
is None:
650 if self
._Header
is None:
651 self
._GetHeaderInfo
()
652 if self
._VpdToolGuid
is None:
653 self
._VpdToolGuid
= ''
654 return self
._VpdToolGuid
656 ## Retrieve [SkuIds] section information
659 if self
._SkuIds
is None:
660 self
._SkuIds
= OrderedDict()
661 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
662 for Record
in RecordList
:
664 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
665 File
=self
.MetaFile
, Line
=Record
[-1])
667 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
668 File
=self
.MetaFile
, Line
=Record
[-1])
669 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
670 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
671 File
=self
.MetaFile
, Line
=Record
[-1])
672 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
673 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID name is invalid. The correct format is '(a-zA-Z_)(a-zA-Z0-9_)*'",
674 File
=self
.MetaFile
, Line
=Record
[-1])
675 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
676 if TAB_DEFAULT
not in self
._SkuIds
:
677 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
678 if TAB_COMMON
not in self
._SkuIds
:
679 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
684 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
686 def _GetDefaultStores(self
):
687 if self
.DefaultStores
is None:
688 self
.DefaultStores
= OrderedDict()
689 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
690 for Record
in RecordList
:
692 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
693 File
=self
.MetaFile
, Line
=Record
[-1])
695 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
696 File
=self
.MetaFile
, Line
=Record
[-1])
697 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
698 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
699 File
=self
.MetaFile
, Line
=Record
[-1])
700 if not IsValidWord(Record
[1]):
701 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_-.)*'",
702 File
=self
.MetaFile
, Line
=Record
[-1])
703 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
704 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
705 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
706 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
707 return self
.DefaultStores
709 ## Retrieve [Components] section information
712 if self
._Modules
is not None:
715 self
._Modules
= OrderedDict()
716 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
717 Macros
= self
._Macros
718 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
719 for Record
in RecordList
:
720 DuplicatedFile
= False
722 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
726 # check the file validation
727 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
729 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
732 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
733 if self
._Arch
!= TAB_ARCH_COMMON
and ModuleFile
in self
._Modules
:
734 DuplicatedFile
= True
736 Module
= ModuleBuildClassObject()
737 Module
.MetaFile
= ModuleFile
739 # get module private library instance
740 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
741 for Record
in RecordList
:
742 LibraryClass
= Record
[0]
743 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
746 # check the file validation
747 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
749 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
752 if LibraryClass
== '' or LibraryClass
== 'NULL':
753 self
._NullLibraryNumber
+= 1
754 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
755 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
756 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
757 if LibraryPath
not in self
.LibraryInstances
:
758 self
.LibraryInstances
.append(LibraryPath
)
760 # get module private PCD setting
761 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
762 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
763 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
764 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
765 TokenList
= GetSplitValueList(Setting
)
766 DefaultValue
= TokenList
[0]
767 # the format is PcdName| Value | VOID* | MaxDatumSize
768 if len(TokenList
) > 2:
769 MaxDatumSize
= TokenList
[2]
772 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
773 Pcd
= PcdClassObject(
785 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
787 # get module private build options
788 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
789 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
790 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
791 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
793 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
794 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
796 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
797 if DuplicatedFile
and not RecordList
:
798 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
800 if len(RecordList
) != 1:
801 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
802 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
803 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
804 ModuleFile
.Arch
= self
._Arch
806 self
._Modules
[ModuleFile
] = Module
809 ## Retrieve all possible library instances used in this platform
811 def LibraryInstances(self
):
812 if self
._LibraryInstances
is None:
814 return self
._LibraryInstances
816 ## Retrieve [LibraryClasses] information
818 def LibraryClasses(self
):
819 if self
._LibraryClasses
is None:
820 self
._LibraryInstances
= []
822 # tdict is a special dict kind of type, used for selecting correct
823 # library instance for given library class and module type
825 LibraryClassDict
= tdict(True, 3)
826 # track all library class names
827 LibraryClassSet
= set()
828 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
829 Macros
= self
._Macros
830 for Record
in RecordList
:
831 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
832 if LibraryClass
== '' or LibraryClass
== 'NULL':
833 self
._NullLibraryNumber
+= 1
834 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
835 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
836 LibraryClassSet
.add(LibraryClass
)
837 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
838 # check the file validation
839 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
841 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
844 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
845 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
846 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
847 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
848 if LibraryInstance
not in self
._LibraryInstances
:
849 self
._LibraryInstances
.append(LibraryInstance
)
851 # resolve the specific library instance for each class and each module type
852 self
._LibraryClasses
= tdict(True)
853 for LibraryClass
in LibraryClassSet
:
854 # try all possible module types
855 for ModuleType
in SUP_MODULE_LIST
:
856 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
857 if LibraryInstance
is None:
859 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
861 # for Edk style library instances, which are listed in different section
862 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
863 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
864 for Record
in RecordList
:
865 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
867 # check the file validation
868 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
870 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
872 if File
not in self
._LibraryInstances
:
873 self
._LibraryInstances
.append(File
)
875 # we need the module name as the library class name, so we have
876 # to parse it here. (self._Bdb[] will trigger a file parse if it
877 # hasn't been parsed)
879 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
880 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
881 return self
._LibraryClasses
883 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
884 if not self
._DecPcds
:
887 if GlobalData
.gFdfParser
:
888 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
891 for Inf
in FdfInfList
:
892 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
893 if ModuleFile
in self
._Modules
:
895 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
896 PkgSet
.update(ModuleData
.Packages
)
898 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
899 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
901 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
902 EdkLogger
.error('build', PARSER_ERROR
,
903 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
904 File
=self
.MetaFile
, Line
=LineNo
)
905 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
907 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
908 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
909 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
911 if ValueList
[2] == '-1':
912 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
913 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
915 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
916 if "{CODE(" not in ValueList
[Index
]:
918 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
919 except BadExpression
as Value
:
920 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
921 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
922 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
923 except EvaluationException
as Excpt
:
924 if hasattr(Excpt
, 'Pcd'):
925 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
926 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
927 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
928 " of the DSC file" % Excpt
.Pcd
,
929 File
=self
.MetaFile
, Line
=LineNo
)
931 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
932 File
=self
.MetaFile
, Line
=LineNo
)
934 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
935 File
=self
.MetaFile
, Line
=LineNo
)
938 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
940 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
941 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
942 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
943 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
944 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
,
945 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
946 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
947 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
948 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
951 def _FilterPcdBySkuUsage(self
, Pcds
):
952 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
953 sku_usage
= self
.SkuIdMgr
.SkuUsageType
954 if sku_usage
== SkuClass
.SINGLE
:
957 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
958 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
959 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
963 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
964 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
965 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
968 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
969 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
]]]
970 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
972 for skuid
in pcd
.SkuInfoList
:
973 skuobj
= pcd
.SkuInfoList
.get(skuid
)
974 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
975 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
976 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
977 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
980 def RecoverCommandLinePcd(self
):
981 def UpdateCommandLineValue(pcd
):
982 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
983 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
984 pcd
.PcdValueFromComm
= pcd
.DefaultValue
985 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
986 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
988 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
989 for pcd
in self
._Pcds
:
990 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
991 UpdateCommandLineValue(self
._Pcds
[pcd
])
993 def __ParsePcdFromCommandLine(self
):
994 if GlobalData
.BuildOptionPcd
:
995 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
996 if isinstance(pcd
, tuple):
998 (pcdname
, pcdvalue
) = pcd
.split('=')
1000 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1002 (Name1
, Name2
) = pcdname
.split('.', 1)
1004 (Name3
, FieldName
) = Name2
.split(".", 1)
1005 if ((Name3
, Name1
)) in self
.DecPcds
:
1006 HasTokenSpace
= True
1008 TokenSpaceGuidCName
= Name1
1012 TokenSpaceGuidCName
= ''
1013 HasTokenSpace
= False
1015 if ((Name2
, Name1
)) in self
.DecPcds
:
1016 HasTokenSpace
= True
1018 TokenSpaceGuidCName
= Name1
1023 TokenSpaceGuidCName
= ''
1024 HasTokenSpace
= False
1027 TokenCName
= pcdname
1028 TokenSpaceGuidCName
= ''
1029 HasTokenSpace
= False
1030 TokenSpaceGuidCNameList
= []
1033 DisplayName
= TokenCName
1035 DisplayName
= TokenCName
+ '.' + FieldName
1036 if not HasTokenSpace
:
1037 for key
in self
.DecPcds
:
1038 PcdItem
= self
.DecPcds
[key
]
1039 if TokenCName
== PcdItem
.TokenCName
:
1040 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1041 if len (TokenSpaceGuidCNameList
) < 1:
1042 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1043 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1044 PcdDatumType
= PcdItem
.DatumType
1050 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1053 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1054 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1058 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1060 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1061 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1063 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1065 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1066 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1068 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1069 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1071 if GlobalData
.BuildOptionPcd
:
1072 for pcd
in GlobalData
.BuildOptionPcd
:
1073 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1074 for BuildData
in self
._Bdb
._CACHE
_.values():
1075 if BuildData
.Arch
!= self
.Arch
:
1077 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1079 for key
in BuildData
.Pcds
:
1080 PcdItem
= BuildData
.Pcds
[key
]
1081 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1082 PcdItem
.DefaultValue
= pcdvalue
1083 PcdItem
.PcdValueFromComm
= pcdvalue
1084 #In command line, the latter full assign value in commandLine should override the former field assign value.
1085 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1088 if GlobalData
.BuildOptionPcd
:
1089 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1090 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1092 if (TokenSpaceGuid
, Token
) not in field_assign
:
1093 field_assign
[TokenSpaceGuid
, Token
] = []
1094 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1096 if (TokenSpaceGuid
, Token
) in field_assign
:
1097 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1098 field_assign
[TokenSpaceGuid
, Token
] = []
1099 for item
in delete_assign
:
1100 GlobalData
.BuildOptionPcd
.remove(item
)
1103 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1106 TokenCName
+= '.' + FieldName
1107 if PcdValue
.startswith('H'):
1108 if FieldName
and IsFieldValueAnArray(PcdValue
[1:]):
1109 PcdDatumType
= TAB_VOID
1111 if FieldName
and not IsArray
:
1114 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1115 except BadExpression
as Value
:
1116 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1117 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1118 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1119 if FieldName
and IsFieldValueAnArray(PcdValue
):
1120 PcdDatumType
= TAB_VOID
1122 if FieldName
and not IsArray
:
1125 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1126 except BadExpression
as Value
:
1127 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1128 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1129 elif PcdValue
.startswith('L'):
1130 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1131 if FieldName
and IsFieldValueAnArray(PcdValue
):
1132 PcdDatumType
= TAB_VOID
1134 if FieldName
and not IsArray
:
1137 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1138 except BadExpression
as Value
:
1139 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1140 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1142 if PcdValue
.upper() == 'FALSE':
1144 if PcdValue
.upper() == 'TRUE':
1147 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1148 PcdValue
= '"' + PcdValue
+ '"'
1149 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1150 PcdValue
= '"' + PcdValue
+ '"'
1154 if PcdValue
.upper().startswith('0X'):
1157 Num
= int(PcdValue
, Base
)
1159 PcdValue
= '"' + PcdValue
+ '"'
1160 if IsFieldValueAnArray(PcdValue
):
1161 PcdDatumType
= TAB_VOID
1166 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1167 except BadExpression
as Value
:
1168 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1169 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1172 ## Retrieve all PCD settings in platform
1175 if self
._Pcds
is None:
1176 self
._Pcds
= OrderedDict()
1177 self
.__ParsePcdFromCommandLine
()
1178 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1179 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1180 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1181 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1182 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1183 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1184 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1185 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1186 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1188 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1189 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1190 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1191 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1192 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1193 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1195 self
.RecoverCommandLinePcd()
1198 ## Retrieve [BuildOptions]
1200 def BuildOptions(self
):
1201 if self
._BuildOptions
is None:
1202 self
._BuildOptions
= OrderedDict()
1204 # Retrieve build option for EDKII and EDK style module
1206 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1207 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1208 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1209 if Dummy3
.upper() != TAB_COMMON
:
1211 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1213 # Only flags can be appended
1215 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1216 self
._BuildOptions
[CurKey
] = Option
1218 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1219 self
._BuildOptions
[CurKey
] += ' ' + Option
1220 return self
._BuildOptions
1222 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1223 if self
._ModuleTypeOptions
is None:
1224 self
._ModuleTypeOptions
= OrderedDict()
1225 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1226 options
= OrderedDict()
1227 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1228 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1229 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1230 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1231 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1232 Type
= Dummy2
+ '.' + Dummy3
1233 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1234 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1235 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1236 options
[Key
] = Option
1238 if ' ' + Option
not in options
[Key
]:
1239 options
[Key
] += ' ' + Option
1240 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1243 def GetStructurePcdInfo(PcdSet
):
1244 structure_pcd_data
= defaultdict(list)
1246 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1248 return structure_pcd_data
1251 def OverrideByFdf(StruPcds
,workspace
):
1252 if GlobalData
.gFdfParser
is None:
1254 StructurePcdInFdf
= OrderedDict()
1255 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1256 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1257 for item
in fdfpcd
:
1258 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1259 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1260 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1261 for Pcd
in StruPcds
.values():
1262 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1264 FieldValues
= OrderedDict()
1265 for item
in StructurePcdInFdf
:
1266 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1267 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1268 for field
in FieldValues
:
1269 if field
not in Pcd
.PcdFieldValueFromFdf
:
1270 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1271 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1272 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1273 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1278 def OverrideByComm(StruPcds
):
1279 StructurePcdInCom
= OrderedDict()
1280 for item
in GlobalData
.BuildOptionPcd
:
1281 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1282 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1283 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1284 for Pcd
in StruPcds
.values():
1285 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1287 FieldValues
= OrderedDict()
1288 for item
in StructurePcdInCom
:
1289 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1290 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1291 for field
in FieldValues
:
1292 if field
not in Pcd
.PcdFieldValueFromComm
:
1293 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1294 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1295 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1296 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1299 def OverrideByCommOverAll(self
,AllPcds
):
1300 def CheckStructureInComm(commpcds
):
1303 if len(commpcds
[0]) == 5:
1306 NoFiledValues
= OrderedDict()
1307 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1308 StructurePcdInCom
= OrderedDict()
1309 for item
in GlobalData
.BuildOptionPcd
:
1310 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1311 for item
in StructurePcdInCom
:
1313 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1315 for item
in GlobalData
.BuildOptionPcd
:
1316 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1317 for Guid
, Name
in NoFiledValues
:
1318 if (Name
, Guid
) in AllPcds
:
1319 Pcd
= AllPcds
.get((Name
, Guid
))
1320 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1321 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1323 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1324 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1325 for sku
in Pcd
.SkuInfoList
:
1326 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1327 if SkuInfo
.DefaultValue
:
1328 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1330 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1331 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1332 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1333 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1334 if Pcd
.DatumType
== TAB_VOID
:
1335 if not Pcd
.MaxDatumSize
:
1336 Pcd
.MaxDatumSize
= '0'
1337 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1338 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1339 MaxSize
= max(CurrentSize
, OptionSize
)
1340 Pcd
.MaxDatumSize
= str(MaxSize
)
1342 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1344 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1345 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1346 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1347 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1348 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1349 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1350 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1351 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1352 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1353 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1354 self
.Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1357 def OverrideByFdfOverAll(self
,AllPcds
):
1359 if GlobalData
.gFdfParser
is None:
1361 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1362 for Name
,Guid
,Field
in NoFiledValues
:
1365 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1366 if (Name
,Guid
) in AllPcds
:
1367 Pcd
= AllPcds
.get((Name
,Guid
))
1368 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1369 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1371 Pcd
.PcdValueFromComm
= Value
1372 Pcd
.DefaultValue
= Value
1373 for sku
in Pcd
.SkuInfoList
:
1374 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1375 if SkuInfo
.DefaultValue
:
1376 SkuInfo
.DefaultValue
= Value
1378 SkuInfo
.HiiDefaultValue
= Value
1379 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1380 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1381 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1382 if Pcd
.DatumType
== TAB_VOID
:
1383 if not Pcd
.MaxDatumSize
:
1384 Pcd
.MaxDatumSize
= '0'
1385 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1386 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1387 MaxSize
= max(CurrentSize
, OptionSize
)
1388 Pcd
.MaxDatumSize
= str(MaxSize
)
1390 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1392 PcdInDec
.PcdValueFromFdf
= Value
1393 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1394 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1395 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1396 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1397 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
1400 def ParsePcdNameStruct(self
,NamePart1
,NamePart2
):
1401 TokenSpaceCName
= PcdCName
= DimensionAttr
= Field
= ""
1402 if "." in NamePart1
:
1403 TokenSpaceCName
, TempPcdCName
= NamePart1
.split(".")
1404 if "[" in TempPcdCName
:
1405 PcdCName
= TempPcdCName
[:TempPcdCName
.index("[")]
1406 DimensionAttr
= TempPcdCName
[TempPcdCName
.index("["):]
1408 PcdCName
= TempPcdCName
1411 TokenSpaceCName
= NamePart1
1412 if "[" in NamePart2
:
1413 PcdCName
= NamePart2
[:NamePart2
.index("[")]
1414 DimensionAttr
= NamePart2
[NamePart2
.index("["):]
1416 PcdCName
= NamePart2
1418 return TokenSpaceCName
,PcdCName
,DimensionAttr
,Field
1420 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1422 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1423 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1424 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1425 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1426 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1427 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1430 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1431 SkuIds
= self
.SkuIds
1432 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1433 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1434 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1437 # Find out all possible PCD candidates for self._Arch
1440 for Type
in TypeList
:
1441 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1443 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1444 SkuName
= SkuName
.upper()
1445 default_store
= default_store
.upper()
1446 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1447 if SkuName
not in SkuIds
:
1449 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
1450 pcd_in_dec
= self
._DecPcds
.get((PCName
,TCName
), None)
1451 if pcd_in_dec
is None:
1452 EdkLogger
.error('build', PARSER_ERROR
,
1453 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1454 File
=self
.MetaFile
, Line
= Dummy5
)
1455 if SkuName
in SkuIds
and ("." in TokenSpaceGuid
or "[" in PcdCName
):
1456 if not isinstance (pcd_in_dec
, StructurePcd
):
1457 EdkLogger
.error('build', PARSER_ERROR
,
1458 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1459 File
=self
.MetaFile
, Line
= Dummy5
)
1461 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1463 # handle pcd value override
1464 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1465 S_pcd_set
= OrderedDict()
1466 for str_pcd
in StrPcdSet
:
1467 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1468 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1469 str_pcd_obj_str
= StructurePcd()
1470 str_pcd_obj_str
.copy(str_pcd_dec
)
1472 str_pcd_obj_str
.copy(str_pcd_obj
)
1473 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1474 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
}
1476 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
}
1477 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1478 if str_pcd_data
[4] in SkuIds
:
1479 str_pcd_obj_str
.AddOverrideValue(str_pcd_data
[3], str(str_pcd_data
[7]), TAB_DEFAULT
if str_pcd_data
[4] == TAB_COMMON
else str_pcd_data
[4], TAB_DEFAULT_STORES_DEFAULT
if str_pcd_data
[5] == TAB_COMMON
else str_pcd_data
[5], 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
[6],DimensionAttr
= str_pcd_data
[2])
1480 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1482 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1483 for Pcd
in self
.DecPcds
:
1484 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1485 if Pcd
not in S_pcd_set
:
1486 str_pcd_obj_str
= StructurePcd()
1487 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1488 str_pcd_obj
= Pcds
.get(Pcd
, None)
1490 str_pcd_obj_str
.copy(str_pcd_obj
)
1491 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1492 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
}
1494 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
}
1495 S_pcd_set
[Pcd
] = str_pcd_obj_str
1496 self
.FilterStrcturePcd(S_pcd_set
)
1498 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1499 for stru_pcd
in S_pcd_set
.values():
1500 for skuid
in SkuIds
:
1501 if skuid
in stru_pcd
.SkuOverrideValues
:
1503 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1505 if skuid
not in stru_pcd
.SkuOverrideValues
:
1506 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1507 if nextskuid
== TAB_DEFAULT
:
1510 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1511 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})
1513 stru_pcd
.ValueChain
.add((skuid
, ''))
1514 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1515 for skuid
in SkuIds
:
1518 if skuid
not in stru_pcd
.SkuOverrideValues
:
1519 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1520 if nextskuid
== TAB_DEFAULT
:
1523 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1526 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1527 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1529 for defaultstoreid
in DefaultStores
:
1530 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1531 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = CopyDict(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1532 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1533 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1534 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1535 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1537 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1538 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1539 if str_pcd_obj
is None:
1540 print(PcdName
, PcdGuid
)
1542 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1543 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1544 if skuname
not in str_pcd_obj
.SkuInfoList
:
1545 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1547 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1548 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1549 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1550 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1551 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1552 str_pcd_obj
.DefaultValue
= PcdValue
1554 if skuname
not in str_pcd_obj
.SkuInfoList
:
1555 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1557 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1558 if nextskuid
== TAB_DEFAULT
:
1561 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1562 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
)
1563 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1564 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1566 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1567 for str_pcd_obj
in S_pcd_set
.values():
1568 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1569 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1571 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1572 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1573 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1574 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1576 for str_pcd_obj
in S_pcd_set
.values():
1578 str_pcd_obj
.MaxDatumSize
= DscBuildData
.GetStructurePcdMaxSize(str_pcd_obj
)
1579 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1580 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1584 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1585 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1586 del pcd
.SkuInfoList
[TAB_COMMON
]
1587 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1588 del pcd
.SkuInfoList
[TAB_COMMON
]
1590 map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1593 def PlatformUsedPcds(self
):
1595 if GlobalData
.gFdfParser
:
1596 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1597 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1598 AllModulePcds
= set()
1599 ModuleSet
= set(self
._Modules
.keys() + FdfModuleList
)
1600 for ModuleFile
in ModuleSet
:
1601 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1602 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1603 for ModuleFile
in self
.LibraryInstances
:
1604 ModuleData
= self
._Bdb
.CreateBuildObject(ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
)
1605 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1606 return AllModulePcds
1608 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1609 def FilterStrcturePcd(self
, S_pcd_set
):
1610 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.PlatformUsedPcds
1611 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1612 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1614 ## Retrieve non-dynamic PCD settings
1616 # @param Type PCD type
1618 # @retval a dict object contains settings of given PCD type
1620 def _GetPcd(self
, Type
):
1621 Pcds
= OrderedDict()
1623 # tdict is a special dict kind of type, used for selecting correct
1624 # PCD settings for certain ARCH
1626 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1628 PcdDict
= tdict(True, 4)
1630 # Find out all possible PCD candidates for self._Arch
1631 RecordList
= self
._RawData
[Type
, self
._Arch
]
1632 PcdValueDict
= OrderedDict()
1633 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1634 SkuName
= SkuName
.upper()
1635 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1636 if SkuName
not in AvailableSkuIdSet
:
1637 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1638 File
=self
.MetaFile
, Line
=Dummy5
)
1639 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1640 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
1641 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1642 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1644 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1645 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1648 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1650 if int(MaxDatumSize
, 0) > 0xFFFF:
1651 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1652 File
=self
.MetaFile
, Line
=Dummy4
)
1653 if int(MaxDatumSize
, 0) < 0:
1654 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1655 File
=self
.MetaFile
, Line
=Dummy4
)
1656 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1657 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1659 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1661 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.iteritems():
1662 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1663 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1664 elif TAB_DEFAULT
in PcdSetting
:
1665 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_DEFAULT
]
1666 elif TAB_COMMON
in PcdSetting
:
1667 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_COMMON
]
1673 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1676 self
._PCD
_TYPE
_STRING
_[Type
],
1685 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1686 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1687 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1688 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1689 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1693 def GetStructurePcdMaxSize(str_pcd
):
1694 pcd_default_value
= str_pcd
.DefaultValue
1695 sku_values
= [skuobj
.HiiDefaultValue
if str_pcd
.Type
in [DscBuildData
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], DscBuildData
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]] else skuobj
.DefaultValue
for skuobj
in str_pcd
.SkuInfoList
.values()]
1696 sku_values
.append(pcd_default_value
)
1698 def get_length(value
):
1699 Value
= value
.strip()
1701 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1703 if Value
.startswith('L"') and Value
.endswith('"'):
1704 return len(Value
[2:-1])
1705 if Value
[0] == '"' and Value
[-1] == '"':
1706 return len(Value
) - 2
1707 if Value
.strip().startswith("{CODE("):
1708 tmpValue
= RemoveCComments(Value
)
1709 return len(tmpValue
.split(","))
1710 if (Value
[0] == '{' and Value
[-1] == '}'):
1711 return len(Value
.split(","))
1712 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1713 return len(list(Value
[2:-1]))
1714 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1715 return len(Value
) - 2
1718 return str(max(get_length(item
) for item
in sku_values
))
1721 def ExecuteCommand (Command
):
1723 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1725 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1726 Result
= Process
.communicate()
1727 return Process
.returncode
, Result
[0], Result
[1]
1730 def IntToCString(Value
, ValueSize
):
1732 if not isinstance (Value
, str):
1733 for Index
in range(0, ValueSize
):
1734 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1736 Result
= Result
+ '"'
1739 def GenerateSizeFunction(self
, Pcd
):
1740 CApp
= "// Default Value in Dec \n"
1741 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1743 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
1744 for skuname
in Pcd
.SkuInfoList
:
1745 skuobj
= Pcd
.SkuInfoList
[skuname
]
1746 if skuobj
.VariableName
:
1747 for defaultstore
in skuobj
.DefaultStoreDict
:
1748 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,defaultstore
)
1749 if pcddef
and "{CODE(" in pcddef
:
1750 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
)
1752 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1753 if pcddef
and "{CODE(" in pcddef
:
1754 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1756 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1757 if pcddef
and "{CODE(" in pcddef
:
1758 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1759 for index
in Pcd
.DefaultValues
:
1760 FieldList
= Pcd
.DefaultValues
[index
]
1763 for FieldName
in FieldList
:
1764 FieldName
= "." + FieldName
1765 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1766 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1768 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1769 except BadExpression
:
1770 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1771 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1772 Value
, ValueSize
= ParseFieldValue(Value
)
1773 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]);
1776 FieldName_ori
= FieldName
.strip('.')
1777 while '[' in FieldName
:
1778 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1779 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1780 FieldName
= FieldName
.split(']', 1)[1]
1781 FieldName
= NewFieldName
+ FieldName
1782 while '[' in FieldName
:
1783 FieldName
= FieldName
.rsplit('[', 1)[0]
1784 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])
1785 for skuname
in Pcd
.SkuOverrideValues
:
1786 if skuname
== TAB_COMMON
:
1788 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1789 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1790 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1791 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1794 for FieldName
in FieldList
:
1795 FieldName
= "." + FieldName
1796 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1797 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1799 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1800 except BadExpression
:
1801 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1802 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1803 Value
, ValueSize
= ParseFieldValue(Value
)
1804 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]);
1807 FieldName_ori
= FieldName
.strip('.')
1808 while '[' in FieldName
:
1809 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1810 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1811 FieldName
= FieldName
.split(']', 1)[1]
1812 FieldName
= NewFieldName
+ FieldName
1813 while '[' in FieldName
:
1814 FieldName
= FieldName
.rsplit('[', 1)[0]
1815 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])
1816 if Pcd
.PcdFieldValueFromFdf
:
1817 CApp
= CApp
+ "// From fdf \n"
1818 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1819 FieldName
= "." + FieldName
1820 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1821 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1823 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1824 except BadExpression
:
1825 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1826 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1827 Value
, ValueSize
= ParseFieldValue(Value
)
1828 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
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0]);
1831 FieldName_ori
= FieldName
.strip('.')
1832 while '[' in FieldName
:
1833 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1834 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1835 FieldName
= FieldName
.split(']', 1)[1]
1836 FieldName
= NewFieldName
+ FieldName
1837 while '[' in FieldName
:
1838 FieldName
= FieldName
.rsplit('[', 1)[0]
1839 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %s Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), ArrayIndex
+ 1, Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][1], Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][2], Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][0])
1840 if Pcd
.PcdFieldValueFromComm
:
1841 CApp
= CApp
+ "// From Command Line \n"
1842 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1843 FieldName
= "." + FieldName
1844 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1845 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1847 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1848 except BadExpression
:
1849 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1850 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1851 Value
, ValueSize
= ParseFieldValue(Value
)
1852 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]);
1855 FieldName_ori
= FieldName
.strip('.')
1856 while '[' in FieldName
:
1857 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1858 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1859 FieldName
= FieldName
.split(']', 1)[1]
1860 FieldName
= NewFieldName
+ FieldName
1861 while '[' in FieldName
:
1862 FieldName
= FieldName
.rsplit('[', 1)[0]
1863 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])
1864 if Pcd
.GetPcdMaxSize():
1865 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1870 def GenerateSizeStatments(Pcd
,skuname
,defaultstorename
):
1872 r_datatype
= [Pcd
.BaseDatumType
]
1873 lastoneisEmpty
= False
1874 for dem
in Pcd
.Capacity
:
1876 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. " %
1877 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))))
1878 if dem
== '0' or dem
== "-1":
1879 r_datatype
.append("[1]")
1880 lastoneisEmpty
= True
1882 r_datatype
.append("[" + dem
+ "]")
1884 if Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_HII
, MODEL_PCD_DYNAMIC_HII
]:
1885 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultStoreDict
.get(defaultstorename
)
1886 elif Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_DEFAULT
,MODEL_PCD_DYNAMIC_VPD
,MODEL_PCD_DYNAMIC_DEFAULT
,MODEL_PCD_DYNAMIC_EX_VPD
]:
1887 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultValue
1889 PcdDefValue
= Pcd
.DefaultValue
1891 if "{CODE(" not in PcdDefValue
:
1892 sizebasevalue_plus
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), "".join(r_datatype
)))
1893 sizebasevalue
= "(%s / sizeof(%s))" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), "".join(r_datatype
)))
1894 sizeof
= "sizeof(%s)" % Pcd
.BaseDatumType
1895 CApp
= ' Size = %s %% %s ? %s : %s ;\n' % ( (DscBuildData
.GetStructurePcdMaxSize(Pcd
), sizeof
, sizebasevalue_plus
, sizebasevalue
))
1897 CApp
= " Size = 0;\n"
1899 CApp
= ' Size = sizeof(%s);\n' % ("".join(r_datatype
) )
1901 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1902 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1905 def GetIndicator(self
,index
,FieldName
,Pcd
):
1906 def cleanupindex(indexstr
):
1907 return indexstr
.strip("[").strip("]").strip()
1908 index_elements
= ArrayIndex
.findall(index
)
1909 pcd_capacity
= Pcd
.Capacity
1912 if len(pcd_capacity
)>2:
1913 for i
in xrange(0,len(index_elements
)):
1914 index_ele
= index_elements
[i
]
1915 index_num
= index_ele
.strip("[").strip("]").strip()
1916 if i
== len(index_elements
) -2:
1917 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[i
+1])),Pcd
.BaseDatumType
,reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[:-1]), cleanupindex(index_elements
[i
]))
1920 indicator
+= " + %d*%s*Size/sizeof(%s)/%d" %(int(cleanupindex(index_elements
[i
])),reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[i
+1:-1]),Pcd
.BaseDatumType
,reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[:-1]))
1921 elif len(pcd_capacity
) == 2:
1922 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
1923 elif len(pcd_capacity
) == 1:
1924 index_ele
= index_elements
[0]
1925 index_num
= index_ele
.strip("[").strip("]").strip()
1926 indicator
+= " + %s)" % (index_num
)
1930 indicator
+= "->" + FieldName
1933 def GetStarNum(self
,Pcd
):
1934 if not Pcd
.IsArray():
1936 elif Pcd
.IsSimpleTypeArray():
1937 return len(Pcd
.Capacity
)
1939 return len(Pcd
.Capacity
) + 1
1940 def GenerateDefaultValueAssignFunction(self
, Pcd
):
1941 CApp
= "// Default value in Dec \n"
1942 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
1943 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1944 CApp
= CApp
+ ' CHAR8 *Value;\n'
1945 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1946 IsArray
= IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1949 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1950 except BadExpression
:
1951 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1952 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1953 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1954 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1955 if isinstance(Value
, str):
1956 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1959 # Use memcpy() to copy value into field
1961 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1962 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value, sizeof(%s_%s_INIT_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1964 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1965 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1966 for index
in Pcd
.DefaultValues
:
1967 FieldList
= Pcd
.DefaultValues
[index
]
1970 for FieldName
in FieldList
:
1971 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1974 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1975 except BadExpression
:
1976 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1977 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1980 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1982 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]))
1984 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
1985 if isinstance(Value
, str):
1986 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1989 # Use memcpy() to copy value into field
1991 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1992 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1993 CApp
= CApp
+ ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd
.DatumType
, FieldName
, ValueSize
, Pcd
.DatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1994 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1995 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
1998 if '[' in FieldName
and ']' in FieldName
:
1999 Index
= int(FieldName
.split('[')[1].split(']')[0])
2000 CApp
= CApp
+ ' __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index
, FieldName
.split('[')[0], FieldName
.split('[')[0], FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldName
)
2002 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2004 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2009 def GenerateDefaultValueAssignStatement(Pcd
):
2010 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2013 def GetPcdDscRawDefaultValue(self
,Pcd
, SkuName
,DefaultStoreName
):
2014 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2015 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2016 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2018 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2020 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2022 return pcddefaultvalue
2023 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
2024 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
2025 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
2026 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2027 CApp
= CApp
+ ' CHAR8 *Value;\n'
2029 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2030 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2032 pcddefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, SkuName
, DefaultStoreName
)
2034 FieldList
= pcddefaultvalue
2035 IsArray
= IsFieldValueAnArray(FieldList
)
2037 if "{CODE(" not in FieldList
:
2039 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2040 except BadExpression
:
2041 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2042 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2043 Value
, ValueSize
= ParseFieldValue (FieldList
)
2045 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2046 if isinstance(Value
, str):
2047 if "{CODE(" in Value
:
2048 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2050 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
)
2053 # Use memcpy() to copy value into field
2055 if Pcd
.IsArray() and "{CODE(" in pcddefaultvalue
:
2056 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2058 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
)
2059 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2061 if isinstance(Value
, str):
2062 if "{CODE(" in Value
:
2063 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2065 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2068 # Use memcpy() to copy value into field
2070 if Pcd
.IsArray() and "{CODE(" in pcddefaultvalue
:
2071 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2073 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2074 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2076 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2077 if not inheritvalue
:
2079 for index
in inheritvalue
:
2080 FieldList
= inheritvalue
[index
]
2083 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2084 for FieldName
in FieldList
:
2085 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2086 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2089 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2090 except BadExpression
:
2091 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2092 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2094 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2096 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]))
2097 if isinstance(Value
, str):
2098 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2101 # Use memcpy() to copy value into field
2103 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2104 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2105 CApp
= CApp
+ ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd
.DatumType
, FieldName
, ValueSize
, Pcd
.DatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2106 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2107 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2109 if '[' in FieldName
and ']' in FieldName
:
2110 Index
= int(FieldName
.split('[')[1].split(']')[0])
2111 CApp
= CApp
+ ' __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index
, FieldName
.split('[')[0], FieldName
.split('[')[0], FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldName
)
2113 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2115 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2120 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2121 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2124 def GenerateCommandLineValue(self
, Pcd
):
2125 CApp
= "// Value in CommandLine\n"
2126 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2127 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2128 CApp
= CApp
+ ' CHAR8 *Value;\n'
2130 pcddefaultvalue
= Pcd
.PcdValueFromComm
2131 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2134 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2135 IsArray
= IsFieldValueAnArray(FieldList
)
2138 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2139 except BadExpression
:
2140 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2141 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2142 Value
, ValueSize
= ParseFieldValue (FieldList
)
2144 if isinstance(Value
, str):
2145 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2148 # Use memcpy() to copy value into field
2150 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2151 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2153 for FieldName
in FieldList
:
2154 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2157 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2158 except BadExpression
:
2159 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2160 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2164 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2166 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]))
2167 if isinstance(Value
, str):
2168 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2171 # Use memcpy() to copy value into field
2173 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2174 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2175 CApp
= CApp
+ ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd
.DatumType
, FieldName
, ValueSize
, Pcd
.DatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2176 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2178 if '[' in FieldName
and ']' in FieldName
:
2179 Index
= int(FieldName
.split('[')[1].split(']')[0])
2180 CApp
= CApp
+ ' __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index
, FieldName
.split('[')[0], FieldName
.split('[')[0], FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldName
)
2182 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2184 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2189 def GenerateCommandLineValueStatement(Pcd
):
2190 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2192 def GenerateFdfValue(self
,Pcd
):
2193 CApp
= "// Value in Fdf\n"
2194 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2195 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2196 CApp
= CApp
+ ' CHAR8 *Value;\n'
2198 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2199 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2202 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2203 IsArray
= IsFieldValueAnArray(FieldList
)
2206 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2207 except BadExpression
:
2208 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2209 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2210 Value
, ValueSize
= ParseFieldValue (FieldList
)
2212 if isinstance(Value
, str):
2213 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2216 # Use memcpy() to copy value into field
2218 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2219 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2221 for FieldName
in FieldList
:
2222 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2225 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2226 except BadExpression
:
2227 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2228 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2232 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2234 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]))
2235 if isinstance(Value
, str):
2236 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2239 # Use memcpy() to copy value into field
2241 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2242 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2243 CApp
= CApp
+ ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd
.DatumType
, FieldName
, ValueSize
, Pcd
.DatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2244 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2246 if '[' in FieldName
and ']' in FieldName
:
2247 Index
= int(FieldName
.split('[')[1].split(']')[0])
2248 CApp
= CApp
+ ' __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index
, FieldName
.split('[')[0], FieldName
.split('[')[0], FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldName
)
2250 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2252 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2257 def GenerateFdfValueStatement(Pcd
):
2258 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2261 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2262 OverrideValues
= {DefaultStore
:{}}
2263 if Pcd
.SkuOverrideValues
:
2264 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2265 if not OverrideValues
:
2266 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2267 for DefaultStoreName
in OverrideValues
:
2268 CApp
= CApp
+ 'void\n'
2269 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2270 CApp
= CApp
+ ' void\n'
2271 CApp
= CApp
+ ' )\n'
2273 CApp
= CApp
+ ' UINT32 Size;\n'
2274 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2275 CApp
= CApp
+ ' CHAR8 *Value;\n'
2276 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2277 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2279 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2283 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2285 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2288 # Get current PCD value and size
2290 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2293 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2294 # the correct value. For structures with a flexible array member, the flexible
2295 # array member is detected, and the size is based on the highest index used with
2296 # the flexible array member. The flexible array member must be the last field
2297 # in a structure. The size formula for this case is:
2298 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2300 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,DefaultStoreName
)
2303 # Allocate and zero buffer for the PCD
2304 # Must handle cases where current value is smaller, larger, or same size
2305 # Always keep that larger one as the current size
2307 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2308 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2309 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2312 # Copy current PCD value into allocated buffer.
2314 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2317 # Assign field values in PCD
2319 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2320 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2321 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2322 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2323 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2324 for defaultstorenameitem
in storeset
:
2325 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2326 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2327 if skuname
== SkuName
:
2330 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2331 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2332 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2333 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2335 # Set new PCD value and size
2337 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2342 CApp
= CApp
+ ' free (Pcd);\n'
2345 return InitByteValue
, CApp
2347 def GenerateArrayAssignment(self
, Pcd
):
2351 if not Pcd
.IsArray():
2354 for d
in Pcd
.Capacity
:
2357 Value
= Pcd
.DefaultValueFromDec
2358 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2359 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2360 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2362 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2363 for skuname
in Pcd
.SkuInfoList
:
2364 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2365 if skuinfo
.VariableName
:
2366 for defaultstore
in skuinfo
.DefaultStoreDict
:
2367 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, defaultstore
)
2368 if pcddscrawdefaultvalue
:
2369 Value
= skuinfo
[defaultstore
]
2370 if "{CODE(" in Value
:
2371 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2372 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2374 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, TAB_DEFAULT_STORES_DEFAULT
)
2375 if pcddscrawdefaultvalue
:
2376 Value
= skuinfo
.DefaultValue
2377 if "{CODE(" in Value
:
2378 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2379 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2381 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2382 if pcddscrawdefaultvalue
:
2383 if "{CODE(" in Pcd
.DefaultValue
:
2384 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2385 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2389 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2390 if not OverrideValues
:
2392 for key
in OverrideValues
:
2393 if OverrideValues
[key
]:
2397 def ParseCCFlags(self
, ccflag
):
2399 ccflaglist
= ccflag
.split(" ")
2401 while i
< len(ccflaglist
):
2402 item
= ccflaglist
[i
].strip()
2403 if item
in (r
"/D", r
"/U","-D","-U"):
2404 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2406 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2410 def GenerateByteArrayValue (self
, StructuredPcds
):
2412 # Generate/Compile/Run C application to determine if there are any flexible array members
2414 if not StructuredPcds
:
2418 CApp
= PcdMainCHeader
2420 IncludeFiles
= set()
2421 for PcdName
in StructuredPcds
:
2422 Pcd
= StructuredPcds
[PcdName
]
2423 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2424 if IncludeFile
not in IncludeFiles
:
2425 IncludeFiles
.add(IncludeFile
)
2426 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2428 for Pcd
in StructuredPcds
.values():
2429 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2430 for PcdName
in StructuredPcds
:
2431 Pcd
= StructuredPcds
[PcdName
]
2432 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2433 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2434 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2435 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2436 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2437 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2438 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2440 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2441 if SkuName
not in Pcd
.SkuOverrideValues
:
2443 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2444 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2445 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2446 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2447 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2449 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2450 if SkuName
not in Pcd
.SkuOverrideValues
:
2452 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2453 Pcd
= StructuredPcds
[PcdName
]
2454 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2456 CApp
= CApp
+ 'VOID\n'
2457 CApp
= CApp
+ 'PcdEntryPoint(\n'
2458 CApp
= CApp
+ ' VOID\n'
2459 CApp
= CApp
+ ' )\n'
2461 for Pcd
in StructuredPcds
.values():
2462 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2463 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2465 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2466 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2468 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2469 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2472 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2474 if not os
.path
.exists(self
.OutputPath
):
2475 os
.makedirs(self
.OutputPath
)
2476 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2477 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2479 MakeApp
= PcdMakefileHeader
2480 if sys
.platform
== "win32":
2481 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2483 MakeApp
= MakeApp
+ PcdGccMakefile
2484 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2485 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2488 PlatformInc
= OrderedDict()
2489 for Cache
in self
._Bdb
._CACHE
_.values():
2490 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2493 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2494 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2495 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2496 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2499 for Pcd
in StructuredPcds
.values():
2500 for PackageDec
in Pcd
.PackageDecs
:
2501 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2502 if not os
.path
.exists(Package
):
2503 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2504 if Package
not in PcdDependDEC
:
2505 PcdDependDEC
.append(Package
)
2507 if PlatformInc
and PcdDependDEC
:
2508 for pkg
in PcdDependDEC
:
2509 if pkg
in PlatformInc
:
2510 for inc
in PlatformInc
[pkg
]:
2511 MakeApp
+= '-I' + str(inc
) + ' '
2512 IncSearchList
.append(inc
)
2513 MakeApp
= MakeApp
+ '\n'
2515 CC_FLAGS
= LinuxCFLAGS
2516 if sys
.platform
== "win32":
2517 CC_FLAGS
= WindowsCFLAGS
2518 BuildOptions
= OrderedDict()
2519 for Options
in self
.BuildOptions
:
2520 if Options
[2] != EDKII_NAME
:
2523 if Family
and Family
!= self
.ToolChainFamily
:
2525 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2530 if Target
== TAB_STAR
or Target
== self
._Target
:
2531 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2532 if 'COMMON' not in BuildOptions
:
2533 BuildOptions
['COMMON'] = set()
2534 if Arch
== TAB_STAR
:
2535 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2536 if Arch
in self
.SupArchList
:
2537 if Arch
not in BuildOptions
:
2538 BuildOptions
[Arch
] = set()
2539 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2542 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2543 if len(ArchBuildOptions
.keys()) == 1:
2544 BuildOptions
['COMMON'] |
= (ArchBuildOptions
.values()[0])
2545 elif len(ArchBuildOptions
.keys()) > 1:
2546 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2547 BuildOptions
['COMMON'] |
= CommonBuildOptions
2548 ValueList
= list(BuildOptions
['COMMON'])
2549 CC_FLAGS
+= " ".join(ValueList
)
2552 if sys
.platform
== "win32":
2553 MakeApp
= MakeApp
+ PcdMakefileEnd
2554 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2556 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2557 MakeApp
= MakeApp
+ '\n'
2558 IncludeFileFullPaths
= []
2559 for includefile
in IncludeFiles
:
2560 for includepath
in IncSearchList
:
2561 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2562 if os
.path
.exists(includefullpath
):
2563 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2566 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2567 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2568 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2569 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2570 for include_file
in IncFileList
:
2571 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2572 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2573 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2574 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2576 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2577 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2578 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2580 Dest_PcdValueInitExe
= PcdValueInitName
2581 if not sys
.platform
== "win32":
2582 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2584 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2586 if sys
.platform
== "win32":
2587 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2588 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2591 MakeCommand
= 'make -f %s' % (MakeFileName
)
2592 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2595 Messages
= Messages
.split('\n')
2598 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2599 File
= open (CAppBaseFileName
+ '.c', 'r')
2600 FileData
= File
.readlines()
2602 for Message
in Messages
:
2603 if " error" in Message
or "warning" in Message
:
2604 FileInfo
= Message
.strip().split('(')
2605 if len (FileInfo
) > 1:
2606 FileName
= FileInfo
[0]
2607 FileLine
= FileInfo
[1].split (')')[0]
2609 FileInfo
= Message
.strip().split(':')
2610 if len(FileInfo
) < 2:
2612 FileName
= FileInfo
[0]
2613 FileLine
= FileInfo
[1]
2614 if FileLine
.isdigit():
2615 error_line
= FileData
[int (FileLine
) - 1]
2616 if r
"//" in error_line
:
2617 c_line
, dsc_line
= error_line
.split(r
"//")
2619 dsc_line
= error_line
2620 message_itmes
= Message
.split(":")
2622 if "PcdValueInit.c" not in Message
:
2623 if not MessageGroup
:
2624 MessageGroup
.append(Message
)
2627 for item
in message_itmes
:
2628 if "PcdValueInit.c" in item
:
2629 Index
= message_itmes
.index(item
)
2630 message_itmes
[Index
] = dsc_line
.strip()
2632 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2635 MessageGroup
.append(Message
)
2637 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2639 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2641 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
2642 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2643 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2645 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2647 File
= open (OutputValueFile
, 'r')
2648 FileBuffer
= File
.readlines()
2651 StructurePcdSet
= []
2652 for Pcd
in FileBuffer
:
2653 PcdValue
= Pcd
.split ('|')
2654 PcdInfo
= PcdValue
[0].split ('.')
2655 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2656 return StructurePcdSet
2659 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2660 if not os
.path
.exists(OutputFile
):
2662 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2664 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2668 ## Retrieve dynamic PCD settings
2670 # @param Type PCD type
2672 # @retval a dict object contains settings of given PCD type
2674 def _GetDynamicPcd(self
, Type
):
2677 Pcds
= OrderedDict()
2679 # tdict is a special dict kind of type, used for selecting correct
2680 # PCD settings for certain ARCH and SKU
2682 PcdDict
= tdict(True, 4)
2684 # Find out all possible PCD candidates for self._Arch
2685 RecordList
= self
._RawData
[Type
, self
._Arch
]
2686 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2689 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2690 SkuName
= SkuName
.upper()
2691 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2692 if SkuName
not in AvailableSkuIdSet
:
2693 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2694 File
=self
.MetaFile
, Line
=Dummy5
)
2695 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2696 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2697 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2699 # Remove redundant PCD candidates, per the ARCH and SKU
2700 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2702 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2706 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2708 if int(MaxDatumSize
, 0) > 0xFFFF:
2709 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2710 File
=self
.MetaFile
, Line
=Dummy4
)
2711 if int(MaxDatumSize
, 0) < 0:
2712 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2713 File
=self
.MetaFile
, Line
=Dummy4
)
2714 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2715 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2716 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2717 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2718 if MaxDatumSize
.strip():
2719 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2722 if pcdObject
.MaxDatumSize
:
2723 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2726 if CurrentMaxSize
> PcdMaxSize
:
2727 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2729 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2732 self
._PCD
_TYPE
_STRING
_[Type
],
2737 OrderedDict({SkuName
: SkuInfo
}),
2742 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2743 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2744 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2746 for pcd
in Pcds
.values():
2747 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2748 # Only fix the value while no value provided in DSC file.
2749 for sku
in pcd
.SkuInfoList
.values():
2750 if not sku
.DefaultValue
:
2751 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2752 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2753 valuefromDec
= pcdDecObject
.DefaultValue
2754 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2755 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2756 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2757 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2758 del pcd
.SkuInfoList
[TAB_COMMON
]
2759 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2760 del pcd
.SkuInfoList
[TAB_COMMON
]
2762 map(self
.FilterSkuSettings
, Pcds
.values())
2766 def FilterSkuSettings(self
, PcdObj
):
2768 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2769 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2770 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2771 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2772 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2773 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2775 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2776 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2781 def CompareVarAttr(Attr1
, Attr2
):
2782 if not Attr1
or not Attr2
: # for empty string
2784 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2785 Attr1Set
= set(Attr1s
)
2786 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2787 Attr2Set
= set(Attr2s
)
2788 if Attr2Set
== Attr1Set
:
2793 def CompletePcdValues(self
, PcdSet
):
2794 Pcds
= OrderedDict()
2795 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2796 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2797 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2798 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2799 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2801 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2802 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2803 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2804 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2805 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2806 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2807 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2809 PcdType
= PcdObj
.Type
2810 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2811 for skuid
in PcdObj
.SkuInfoList
:
2812 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2813 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2814 for defaultstorename
in DefaultStores
:
2815 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2816 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
2817 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2818 for skuname
, skuid
in SkuIds
.items():
2819 if skuname
not in PcdObj
.SkuInfoList
:
2820 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2821 while nextskuid
not in PcdObj
.SkuInfoList
:
2822 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2823 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2824 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2825 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2826 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2827 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2828 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2830 ## Retrieve dynamic HII PCD settings
2832 # @param Type PCD type
2834 # @retval a dict object contains settings of given PCD type
2836 def _GetDynamicHiiPcd(self
, Type
):
2840 Pcds
= OrderedDict()
2841 UserDefinedDefaultStores
= []
2843 # tdict is a special dict kind of type, used for selecting correct
2844 # PCD settings for certain ARCH and SKU
2846 PcdDict
= tdict(True, 5)
2848 RecordList
= self
._RawData
[Type
, self
._Arch
]
2849 # Find out all possible PCD candidates for self._Arch
2850 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2851 DefaultStoresDefine
= self
._GetDefaultStores
()
2853 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
2854 SkuName
= SkuName
.upper()
2855 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2856 DefaultStore
= DefaultStore
.upper()
2857 if DefaultStore
== TAB_COMMON
:
2858 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2860 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
2861 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
2862 if SkuName
not in AvailableSkuIdSet
:
2863 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2864 File
=self
.MetaFile
, Line
=Dummy5
)
2865 if DefaultStore
not in DefaultStoresDefine
:
2866 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2867 File
=self
.MetaFile
, Line
=Dummy5
)
2868 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2869 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
2870 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
2873 # Remove redundant PCD candidates, per the ARCH and SKU
2874 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdSet
:
2876 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
2879 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2881 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2883 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2884 ExtraData
="[%s]" % VarAttribute
)
2886 FormatCorrect
= True
2887 if VariableOffset
.isdigit():
2888 if int(VariableOffset
, 10) > 0xFFFF:
2890 elif variablePattern
.match(VariableOffset
):
2891 if int(VariableOffset
, 16) > 0xFFFF:
2893 # For Offset written in "A.B"
2894 elif VariableOffset
.find('.') > -1:
2895 VariableOffsetList
= VariableOffset
.split(".")
2896 if not (len(VariableOffsetList
) == 2
2897 and IsValidWord(VariableOffsetList
[0])
2898 and IsValidWord(VariableOffsetList
[1])):
2899 FormatCorrect
= False
2901 FormatCorrect
= False
2902 if not FormatCorrect
:
2903 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2906 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2907 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2908 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2910 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2911 EdkLogger
.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR
, "The variable %s.%s for DynamicHii PCDs has conflicting attributes [%s] and [%s] " % (VariableGuid
, VariableName
, VarAttribute
, VariableAttrs
[(VariableName
, VariableGuid
)]))
2913 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2914 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2915 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2916 if SkuName
in pcdObject
.SkuInfoList
:
2917 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2918 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2920 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2921 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2923 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2924 PcdClassObj
= PcdClassObject(
2927 self
._PCD
_TYPE
_STRING
_[Type
],
2932 OrderedDict({SkuName
: SkuInfo
}),
2935 pcdDecObject
.validateranges
,
2936 pcdDecObject
.validlists
,
2937 pcdDecObject
.expressions
,
2939 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
2940 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
2941 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
2943 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
2944 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2945 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2946 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
2947 for pcd
in Pcds
.values():
2948 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2949 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2950 pcd
.DatumType
= pcdDecObject
.DatumType
2951 # Only fix the value while no value provided in DSC file.
2952 for sku
in pcd
.SkuInfoList
.values():
2953 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2954 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2955 for default_store
in sku
.DefaultStoreDict
:
2956 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2957 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2958 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2959 valuefromDec
= pcdDecObject
.DefaultValue
2960 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
2961 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2962 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2963 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2964 del pcd
.SkuInfoList
[TAB_COMMON
]
2965 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2966 del pcd
.SkuInfoList
[TAB_COMMON
]
2968 if pcd
.MaxDatumSize
.strip():
2969 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2972 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
2973 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2975 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2976 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2977 if datalen
> MaxSize
:
2979 for defaultst
in skuobj
.DefaultStoreDict
:
2980 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2981 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
2982 pcd
.MaxDatumSize
= str(MaxSize
)
2983 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
2985 invalidpcd
= ",".join(invalidhii
)
2986 EdkLogger
.error('build', PCD_VARIABLE_INFO_ERROR
, Message
='The same HII PCD must map to the same EFI variable for all SKUs', File
=self
.MetaFile
, ExtraData
=invalidpcd
)
2988 map(self
.FilterSkuSettings
, Pcds
.values())
2993 def CheckVariableNameAssignment(Pcds
):
2995 for pcdname
in Pcds
:
2997 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
2998 if len(varnameset
) > 1:
2999 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
3001 return False, invalidhii
3004 ## Retrieve dynamic VPD PCD settings
3006 # @param Type PCD type
3008 # @retval a dict object contains settings of given PCD type
3010 def _GetDynamicVpdPcd(self
, Type
):
3013 Pcds
= OrderedDict()
3015 # tdict is a special dict kind of type, used for selecting correct
3016 # PCD settings for certain ARCH and SKU
3018 PcdDict
= tdict(True, 4)
3021 # Find out all possible PCD candidates for self._Arch
3022 RecordList
= self
._RawData
[Type
, self
._Arch
]
3023 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3025 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3026 SkuName
= SkuName
.upper()
3027 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3028 if SkuName
not in AvailableSkuIdSet
:
3029 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3030 File
=self
.MetaFile
, Line
=Dummy5
)
3031 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
3032 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3033 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3035 # Remove redundant PCD candidates, per the ARCH and SKU
3036 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3037 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3041 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3042 # For the Integer & Boolean type, the optional data can only be InitialValue.
3043 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3044 # until the DEC parser has been called.
3046 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3048 if int(MaxDatumSize
, 0) > 0xFFFF:
3049 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3050 File
=self
.MetaFile
, Line
=Dummy4
)
3051 if int(MaxDatumSize
, 0) < 0:
3052 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3053 File
=self
.MetaFile
, Line
=Dummy4
)
3054 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3055 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3056 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3057 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3058 if MaxDatumSize
.strip():
3059 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3062 if pcdObject
.MaxDatumSize
:
3063 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3066 if CurrentMaxSize
> PcdMaxSize
:
3067 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3069 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3072 self
._PCD
_TYPE
_STRING
_[Type
],
3077 OrderedDict({SkuName
: SkuInfo
}),
3082 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3083 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3084 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3085 for pcd
in Pcds
.values():
3086 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
3087 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3088 pcd
.DatumType
= pcdDecObject
.DatumType
3089 # Only fix the value while no value provided in DSC file.
3090 for sku
in pcd
.SkuInfoList
.values():
3091 if not sku
.DefaultValue
:
3092 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3093 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3094 valuefromDec
= pcdDecObject
.DefaultValue
3095 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3096 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3097 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3098 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3099 del pcd
.SkuInfoList
[TAB_COMMON
]
3100 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3101 del pcd
.SkuInfoList
[TAB_COMMON
]
3103 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3104 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3105 for pcd
in Pcds
.values():
3106 PcdValueTypeSet
= set()
3107 for sku
in pcd
.SkuInfoList
.values():
3108 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3109 if len(PcdValueTypeSet
) > 1:
3110 for sku
in pcd
.SkuInfoList
.values():
3111 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3113 map(self
.FilterSkuSettings
, Pcds
.values())
3116 ## Add external modules
3118 # The external modules are mostly those listed in FDF file, which don't
3121 # @param FilePath The path of module description file
3123 def AddModule(self
, FilePath
):
3124 FilePath
= NormPath(FilePath
)
3125 if FilePath
not in self
.Modules
:
3126 Module
= ModuleBuildClassObject()
3127 Module
.MetaFile
= FilePath
3128 self
.Modules
.append(Module
)
3131 def ToolChainFamily(self
):
3132 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3133 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
3134 if os
.path
.isfile(BuildConfigurationFile
) == True:
3135 TargetTxt
= TargetTxtClassObject()
3136 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
3137 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3138 if ToolDefinitionFile
== '':
3139 ToolDefinitionFile
= "tools_def.txt"
3140 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
3141 if os
.path
.isfile(ToolDefinitionFile
) == True:
3142 ToolDef
= ToolDefClassObject()
3143 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
3144 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
3145 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3146 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3147 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3148 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3150 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3151 return self
._ToolChainFamily
3153 ## Add external PCDs
3155 # The external PCDs are mostly those listed in FDF file to specify address
3156 # or offset information.
3158 # @param Name Name of the PCD
3159 # @param Guid Token space guid of the PCD
3160 # @param Value Value of the PCD
3162 def AddPcd(self
, Name
, Guid
, Value
):
3163 if (Name
, Guid
) not in self
.Pcds
:
3164 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3165 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3169 if self
._DecPcds
is None:
3171 if GlobalData
.gFdfParser
:
3172 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3174 for Inf
in FdfInfList
:
3175 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3176 if ModuleFile
in self
._Modules
:
3178 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3179 PkgSet
.update(ModuleData
.Packages
)
3180 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3181 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3182 return self
._DecPcds