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 *
29 from Common
.ToolDefClassObject
import *
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
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
46 PcdValueInitName
= 'PcdValueInit'
57 #include <PcdValueCommon.h>
67 return PcdValueMain (argc, argv);
71 PcdMakefileHeader
= '''
74 # This file is auto-generated by build utility
79 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
80 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
82 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
84 LIBS = $(LIB_PATH)\Common.lib
86 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
90 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
94 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
95 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
96 ## regular expressions for finding decimal and hex numbers
97 Pattern
= re
.compile('^[1-9]\d*|0$')
98 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
99 ## Regular expression for finding header file inclusions
100 from AutoGen
.GenMake
import gIncludePattern
102 ## Find dependencies for one source file
104 # By searching recursively "#include" directive in file, find out all the
105 # files needed by given source file. The dependecies will be only searched
106 # in given search path list.
108 # @param SearchPathList The list of search path
110 # @retval list The list of files the given source file depends on
112 def GetDependencyList(FileStack
, SearchPathList
):
114 DependencySet
= set(FileStack
)
115 while len(FileStack
) > 0:
117 FullPathDependList
= []
118 CurrentFileDependencyList
= []
120 CurrentFileDependencyList
= DepDb
[F
]
124 FileContent
= Fd
.read()
125 except BaseException
as X
:
126 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
128 if "Fd" in dir(locals()):
131 if len(FileContent
) == 0:
134 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
135 FileContent
= unicode(FileContent
, "utf-16")
136 IncludedFileList
= gIncludePattern
.findall(FileContent
)
138 for Inc
in IncludedFileList
:
140 Inc
= os
.path
.normpath(Inc
)
141 CurrentFileDependencyList
.append(Inc
)
142 DepDb
[F
] = CurrentFileDependencyList
144 CurrentFilePath
= os
.path
.dirname(F
)
145 PathList
= [CurrentFilePath
] + SearchPathList
146 for Inc
in CurrentFileDependencyList
:
147 for SearchPath
in PathList
:
148 FilePath
= os
.path
.join(SearchPath
, Inc
)
149 if not os
.path
.exists(FilePath
):
151 if FilePath
not in DependencySet
:
152 FileStack
.append(FilePath
)
153 FullPathDependList
.append(FilePath
)
155 DependencySet
.update(FullPathDependList
)
156 DependencyList
= list(DependencySet
) # remove duplicate ones
158 return DependencyList
160 class DscBuildData(PlatformBuildClassObject
):
161 # dict used to convert PCD type in database to string used by build tool
162 _PCD_TYPE_STRING_
= {
163 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
164 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
165 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
166 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
167 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
168 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
169 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
170 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
171 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
172 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
173 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
176 # dict used to convert part of [Defines] to members of DscBuildData directly
181 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
182 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
183 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
184 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
185 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
186 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
187 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
188 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
189 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
190 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
191 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
192 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
193 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
194 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
195 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
198 # used to compose dummy library class name for those forced library instances
199 _NullLibraryNumber
= 0
201 ## Constructor of DscBuildData
203 # Initialize object of DscBuildData
205 # @param FilePath The path of platform description file
206 # @param RawData The raw data of DSC file
207 # @param BuildDataBase Database used to retrieve module/package information
208 # @param Arch The target architecture
209 # @param Platform (not used for DscBuildData)
210 # @param Macros Macros used for replacement in DSC file
212 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
213 self
.MetaFile
= FilePath
214 self
._RawData
= RawData
215 self
._Bdb
= BuildDataBase
217 self
._Target
= Target
218 self
._Toolchain
= Toolchain
219 self
._ToolChainFamily
= None
221 self
._HandleOverridePath
()
222 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
223 self
.DefaultStores
= None
224 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
227 def OutputPath(self
):
228 if os
.getenv("WORKSPACE"):
229 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
231 return os
.path
.dirname(self
.DscFile
)
234 def __setitem__(self
, key
, value
):
235 self
.__dict
__[self
._PROPERTY
_[key
]] = value
238 def __getitem__(self
, key
):
239 return self
.__dict
__[self
._PROPERTY
_[key
]]
242 def __contains__(self
, key
):
243 return key
in self
._PROPERTY
_
245 ## Set all internal used members of DscBuildData to None
248 self
._PlatformName
= None
251 self
._DscSpecification
= None
252 self
._OutputDirectory
= None
253 self
._SupArchList
= None
254 self
._BuildTargets
= None
256 self
._PcdInfoFlag
= None
257 self
._VarCheckFlag
= None
258 self
._FlashDefinition
= None
259 self
._Prebuild
= None
260 self
._Postbuild
= None
261 self
._BuildNumber
= None
262 self
._MakefileName
= None
263 self
._BsBaseAddress
= None
264 self
._RtBaseAddress
= None
267 self
._LibraryInstances
= None
268 self
._LibraryClasses
= None
271 self
._BuildOptions
= None
272 self
._ModuleTypeOptions
= None
273 self
._LoadFixAddress
= None
274 self
._RFCLanguages
= None
275 self
._ISOLanguages
= None
276 self
._VpdToolGuid
= None
277 self
._MacroDict
= None
278 self
.DefaultStores
= None
280 ## handle Override Path of Module
281 def _HandleOverridePath(self
):
282 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
283 for Record
in RecordList
:
286 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
287 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
289 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
291 # Check if the source override path exists
292 if not os
.path
.isdir(SourceOverridePath
):
293 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
295 # Add to GlobalData Variables
296 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
298 ## Get current effective macros
301 if self
._MacroDict
is None:
303 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
304 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
305 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
306 return self
._MacroDict
313 ## Retrieve all information in [Defines] section
315 # (Retriving all [Defines] information in one-shot is just to save time.)
317 def _GetHeaderInfo(self
):
318 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
319 for Record
in RecordList
:
321 # items defined _PROPERTY_ don't need additional processing
323 # some special items in [Defines] section need special treatment
324 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
325 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
326 if ' ' in self
._OutputDirectory
:
327 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
328 File
=self
.MetaFile
, Line
=Record
[-1],
329 ExtraData
=self
._OutputDirectory
)
330 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
331 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
332 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
334 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
336 elif Name
== TAB_DSC_PREBUILD
:
337 PrebuildValue
= Record
[2]
338 if Record
[2][0] == '"':
339 if Record
[2][-1] != '"':
340 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
341 File
=self
.MetaFile
, Line
=Record
[-1])
342 PrebuildValue
= Record
[2][1:-1]
343 self
._Prebuild
= PrebuildValue
344 elif Name
== TAB_DSC_POSTBUILD
:
345 PostbuildValue
= Record
[2]
346 if Record
[2][0] == '"':
347 if Record
[2][-1] != '"':
348 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
349 File
=self
.MetaFile
, Line
=Record
[-1])
350 PostbuildValue
= Record
[2][1:-1]
351 self
._Postbuild
= PostbuildValue
352 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
353 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
354 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
355 self
._BuildTargets
= GetSplitValueList(Record
[2])
356 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
357 if self
._SkuName
is None:
358 self
._SkuName
= Record
[2]
359 if GlobalData
.gSKUID_CMD
:
360 self
._SkuName
= GlobalData
.gSKUID_CMD
361 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
362 self
._PcdInfoFlag
= Record
[2]
363 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
364 self
._VarCheckFlag
= Record
[2]
365 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
367 self
._LoadFixAddress
= int (Record
[2], 0)
369 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
370 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
371 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
372 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"',
373 File
=self
.MetaFile
, Line
=Record
[-1])
374 LanguageCodes
= Record
[2][1:-1]
375 if not LanguageCodes
:
376 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
377 File
=self
.MetaFile
, Line
=Record
[-1])
378 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
379 # check whether there is empty entries in the list
380 if None in LanguageList
:
381 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
382 File
=self
.MetaFile
, Line
=Record
[-1])
383 self
._RFCLanguages
= LanguageList
384 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
385 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
386 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
387 File
=self
.MetaFile
, Line
=Record
[-1])
388 LanguageCodes
= Record
[2][1:-1]
389 if not LanguageCodes
:
390 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
391 File
=self
.MetaFile
, Line
=Record
[-1])
392 if len(LanguageCodes
) % 3:
393 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
394 File
=self
.MetaFile
, Line
=Record
[-1])
396 for i
in range(0, len(LanguageCodes
), 3):
397 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
398 self
._ISOLanguages
= LanguageList
399 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
401 # try to convert GUID to a real UUID value to see whether the GUID is format
402 # for VPD_TOOL_GUID is correct.
407 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
408 self
._VpdToolGuid
= Record
[2]
410 self
[Name
] = Record
[2]
411 # set _Header to non-None in order to avoid database re-querying
412 self
._Header
= 'DUMMY'
414 ## Retrieve platform name
416 def PlatformName(self
):
417 if self
._PlatformName
is None:
418 if self
._Header
is None:
419 self
._GetHeaderInfo
()
420 if self
._PlatformName
is None:
421 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
422 return self
._PlatformName
426 return self
.PlatformName
428 ## Retrieve file guid
431 if self
._Guid
is None:
432 if self
._Header
is None:
433 self
._GetHeaderInfo
()
434 if self
._Guid
is None:
435 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
438 ## Retrieve platform version
441 if self
._Version
is None:
442 if self
._Header
is None:
443 self
._GetHeaderInfo
()
444 if self
._Version
is None:
445 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
448 ## Retrieve platform description file version
450 def DscSpecification(self
):
451 if self
._DscSpecification
is None:
452 if self
._Header
is None:
453 self
._GetHeaderInfo
()
454 if self
._DscSpecification
is None:
455 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
456 return self
._DscSpecification
458 ## Retrieve OUTPUT_DIRECTORY
460 def OutputDirectory(self
):
461 if self
._OutputDirectory
is None:
462 if self
._Header
is None:
463 self
._GetHeaderInfo
()
464 if self
._OutputDirectory
is None:
465 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
466 return self
._OutputDirectory
468 ## Retrieve SUPPORTED_ARCHITECTURES
470 def SupArchList(self
):
471 if self
._SupArchList
is None:
472 if self
._Header
is None:
473 self
._GetHeaderInfo
()
474 if self
._SupArchList
is None:
475 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
476 return self
._SupArchList
478 ## Retrieve BUILD_TARGETS
480 def BuildTargets(self
):
481 if self
._BuildTargets
is None:
482 if self
._Header
is None:
483 self
._GetHeaderInfo
()
484 if self
._BuildTargets
is None:
485 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
486 return self
._BuildTargets
489 def PcdInfoFlag(self
):
490 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
492 elif self
._PcdInfoFlag
.upper() == 'TRUE':
498 def VarCheckFlag(self
):
499 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
501 elif self
._VarCheckFlag
.upper() == 'TRUE':
506 # # Retrieve SKUID_IDENTIFIER
509 if self
._SkuName
is None:
510 if self
._Header
is None:
511 self
._GetHeaderInfo
()
512 if self
._SkuName
is None:
513 self
._SkuName
= TAB_DEFAULT
516 ## Override SKUID_IDENTIFIER
518 def SkuName(self
, Value
):
519 self
._SkuName
= Value
522 def FlashDefinition(self
):
523 if self
._FlashDefinition
is None:
524 if self
._Header
is None:
525 self
._GetHeaderInfo
()
526 if self
._FlashDefinition
is None:
527 self
._FlashDefinition
= ''
528 return self
._FlashDefinition
532 if self
._Prebuild
is None:
533 if self
._Header
is None:
534 self
._GetHeaderInfo
()
535 if self
._Prebuild
is None:
537 return self
._Prebuild
541 if self
._Postbuild
is None:
542 if self
._Header
is None:
543 self
._GetHeaderInfo
()
544 if self
._Postbuild
is None:
546 return self
._Postbuild
548 ## Retrieve FLASH_DEFINITION
550 def BuildNumber(self
):
551 if self
._BuildNumber
is None:
552 if self
._Header
is None:
553 self
._GetHeaderInfo
()
554 if self
._BuildNumber
is None:
555 self
._BuildNumber
= ''
556 return self
._BuildNumber
558 ## Retrieve MAKEFILE_NAME
560 def MakefileName(self
):
561 if self
._MakefileName
is None:
562 if self
._Header
is None:
563 self
._GetHeaderInfo
()
564 if self
._MakefileName
is None:
565 self
._MakefileName
= ''
566 return self
._MakefileName
568 ## Retrieve BsBaseAddress
570 def BsBaseAddress(self
):
571 if self
._BsBaseAddress
is None:
572 if self
._Header
is None:
573 self
._GetHeaderInfo
()
574 if self
._BsBaseAddress
is None:
575 self
._BsBaseAddress
= ''
576 return self
._BsBaseAddress
578 ## Retrieve RtBaseAddress
580 def RtBaseAddress(self
):
581 if self
._RtBaseAddress
is None:
582 if self
._Header
is None:
583 self
._GetHeaderInfo
()
584 if self
._RtBaseAddress
is None:
585 self
._RtBaseAddress
= ''
586 return self
._RtBaseAddress
588 ## Retrieve the top address for the load fix address
590 def LoadFixAddress(self
):
591 if self
._LoadFixAddress
is None:
592 if self
._Header
is None:
593 self
._GetHeaderInfo
()
595 if self
._LoadFixAddress
is None:
596 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
599 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
601 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
604 # If command line defined, should override the value in DSC file.
606 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
608 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
610 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']))
612 if self
._LoadFixAddress
< 0:
613 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
614 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
615 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
617 return self
._LoadFixAddress
619 ## Retrieve RFCLanguage filter
621 def RFCLanguages(self
):
622 if self
._RFCLanguages
is None:
623 if self
._Header
is None:
624 self
._GetHeaderInfo
()
625 if self
._RFCLanguages
is None:
626 self
._RFCLanguages
= []
627 return self
._RFCLanguages
629 ## Retrieve ISOLanguage filter
631 def ISOLanguages(self
):
632 if self
._ISOLanguages
is None:
633 if self
._Header
is None:
634 self
._GetHeaderInfo
()
635 if self
._ISOLanguages
is None:
636 self
._ISOLanguages
= []
637 return self
._ISOLanguages
639 ## Retrieve the GUID string for VPD tool
641 def VpdToolGuid(self
):
642 if self
._VpdToolGuid
is None:
643 if self
._Header
is None:
644 self
._GetHeaderInfo
()
645 if self
._VpdToolGuid
is None:
646 self
._VpdToolGuid
= ''
647 return self
._VpdToolGuid
649 ## Retrieve [SkuIds] section information
652 if self
._SkuIds
is None:
653 self
._SkuIds
= OrderedDict()
654 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
655 for Record
in RecordList
:
657 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
658 File
=self
.MetaFile
, Line
=Record
[-1])
660 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
661 File
=self
.MetaFile
, Line
=Record
[-1])
662 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
663 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
664 File
=self
.MetaFile
, Line
=Record
[-1])
665 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
666 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_)*'",
667 File
=self
.MetaFile
, Line
=Record
[-1])
668 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
669 if TAB_DEFAULT
not in self
._SkuIds
:
670 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
671 if TAB_COMMON
not in self
._SkuIds
:
672 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
677 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
679 def _GetDefaultStores(self
):
680 if self
.DefaultStores
is None:
681 self
.DefaultStores
= OrderedDict()
682 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
683 for Record
in RecordList
:
685 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
686 File
=self
.MetaFile
, Line
=Record
[-1])
688 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
689 File
=self
.MetaFile
, Line
=Record
[-1])
690 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
691 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
692 File
=self
.MetaFile
, Line
=Record
[-1])
693 if not IsValidWord(Record
[1]):
694 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_-.)*'",
695 File
=self
.MetaFile
, Line
=Record
[-1])
696 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
697 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
698 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
699 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
700 return self
.DefaultStores
702 ## Retrieve [Components] section information
705 if self
._Modules
is not None:
708 self
._Modules
= OrderedDict()
709 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
710 Macros
= self
._Macros
711 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
712 for Record
in RecordList
:
713 DuplicatedFile
= False
715 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
719 # check the file validation
720 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
722 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
725 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
726 if self
._Arch
!= TAB_ARCH_COMMON
and ModuleFile
in self
._Modules
:
727 DuplicatedFile
= True
729 Module
= ModuleBuildClassObject()
730 Module
.MetaFile
= ModuleFile
732 # get module private library instance
733 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
734 for Record
in RecordList
:
735 LibraryClass
= Record
[0]
736 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
739 # check the file validation
740 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
742 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
745 if LibraryClass
== '' or LibraryClass
== 'NULL':
746 self
._NullLibraryNumber
+= 1
747 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
748 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
749 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
750 if LibraryPath
not in self
.LibraryInstances
:
751 self
.LibraryInstances
.append(LibraryPath
)
753 # get module private PCD setting
754 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
755 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
756 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
757 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
758 TokenList
= GetSplitValueList(Setting
)
759 DefaultValue
= TokenList
[0]
760 # the format is PcdName| Value | VOID* | MaxDatumSize
761 if len(TokenList
) > 2:
762 MaxDatumSize
= TokenList
[2]
765 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
766 Pcd
= PcdClassObject(
778 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
780 # get module private build options
781 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
782 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
783 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
784 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
786 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
787 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
789 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
790 if DuplicatedFile
and not RecordList
:
791 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
793 if len(RecordList
) != 1:
794 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
795 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
796 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
797 ModuleFile
.Arch
= self
._Arch
799 self
._Modules
[ModuleFile
] = Module
802 ## Retrieve all possible library instances used in this platform
804 def LibraryInstances(self
):
805 if self
._LibraryInstances
is None:
807 return self
._LibraryInstances
809 ## Retrieve [LibraryClasses] information
811 def LibraryClasses(self
):
812 if self
._LibraryClasses
is None:
813 self
._LibraryInstances
= []
815 # tdict is a special dict kind of type, used for selecting correct
816 # library instance for given library class and module type
818 LibraryClassDict
= tdict(True, 3)
819 # track all library class names
820 LibraryClassSet
= set()
821 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
822 Macros
= self
._Macros
823 for Record
in RecordList
:
824 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
825 if LibraryClass
== '' or LibraryClass
== 'NULL':
826 self
._NullLibraryNumber
+= 1
827 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
828 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
829 LibraryClassSet
.add(LibraryClass
)
830 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
831 # check the file validation
832 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
834 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
837 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
838 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
839 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
840 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
841 if LibraryInstance
not in self
._LibraryInstances
:
842 self
._LibraryInstances
.append(LibraryInstance
)
844 # resolve the specific library instance for each class and each module type
845 self
._LibraryClasses
= tdict(True)
846 for LibraryClass
in LibraryClassSet
:
847 # try all possible module types
848 for ModuleType
in SUP_MODULE_LIST
:
849 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
850 if LibraryInstance
is None:
852 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
854 # for Edk style library instances, which are listed in different section
855 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
856 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
857 for Record
in RecordList
:
858 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
860 # check the file validation
861 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
863 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
865 if File
not in self
._LibraryInstances
:
866 self
._LibraryInstances
.append(File
)
868 # we need the module name as the library class name, so we have
869 # to parse it here. (self._Bdb[] will trigger a file parse if it
870 # hasn't been parsed)
872 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
873 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
874 return self
._LibraryClasses
876 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
877 if self
._DecPcds
is None:
880 if GlobalData
.gFdfParser
:
881 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
884 for Inf
in FdfInfList
:
885 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
886 if ModuleFile
in self
._Modules
:
888 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
889 PkgSet
.update(ModuleData
.Packages
)
891 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
892 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
894 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
895 EdkLogger
.error('build', PARSER_ERROR
,
896 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
897 File
=self
.MetaFile
, Line
=LineNo
)
898 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
900 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
901 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
902 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
904 if ValueList
[2] == '-1':
905 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
906 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
908 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
910 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
911 except BadExpression
as Value
:
912 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
913 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
914 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
915 except EvaluationException
as Excpt
:
916 if hasattr(Excpt
, 'Pcd'):
917 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
918 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
919 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
920 " of the DSC file" % Excpt
.Pcd
,
921 File
=self
.MetaFile
, Line
=LineNo
)
923 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
924 File
=self
.MetaFile
, Line
=LineNo
)
926 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
927 File
=self
.MetaFile
, Line
=LineNo
)
930 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
932 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
933 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
934 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
935 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
936 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
,
937 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
938 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
939 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
940 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
943 def _FilterPcdBySkuUsage(self
, Pcds
):
944 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
945 sku_usage
= self
.SkuIdMgr
.SkuUsageType
946 if sku_usage
== SkuClass
.SINGLE
:
949 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
950 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
951 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
955 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
956 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
957 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
960 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
961 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
]]]
962 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
964 for skuid
in pcd
.SkuInfoList
:
965 skuobj
= pcd
.SkuInfoList
.get(skuid
)
966 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
967 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
968 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
969 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
972 def RecoverCommandLinePcd(self
):
973 def UpdateCommandLineValue(pcd
):
974 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
975 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
976 pcd
.PcdValueFromComm
= pcd
.DefaultValue
977 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
978 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
980 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
981 for pcd
in self
._Pcds
:
982 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
983 UpdateCommandLineValue(self
._Pcds
[pcd
])
985 def __ParsePcdFromCommandLine(self
):
986 if GlobalData
.BuildOptionPcd
:
987 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
988 if isinstance(pcd
, tuple):
990 (pcdname
, pcdvalue
) = pcd
.split('=')
992 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
994 (Name1
, Name2
) = pcdname
.split('.', 1)
996 (Name3
, FieldName
) = Name2
.split(".", 1)
997 if ((Name3
, Name1
)) in self
.DecPcds
:
1000 TokenSpaceGuidCName
= Name1
1004 TokenSpaceGuidCName
= ''
1005 HasTokenSpace
= False
1007 if ((Name2
, Name1
)) in self
.DecPcds
:
1008 HasTokenSpace
= True
1010 TokenSpaceGuidCName
= Name1
1015 TokenSpaceGuidCName
= ''
1016 HasTokenSpace
= False
1019 TokenCName
= pcdname
1020 TokenSpaceGuidCName
= ''
1021 HasTokenSpace
= False
1022 TokenSpaceGuidCNameList
= []
1025 DisplayName
= TokenCName
1027 DisplayName
= TokenCName
+ '.' + FieldName
1028 if not HasTokenSpace
:
1029 for key
in self
.DecPcds
:
1030 PcdItem
= self
.DecPcds
[key
]
1031 if TokenCName
== PcdItem
.TokenCName
:
1032 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1033 if len (TokenSpaceGuidCNameList
) < 1:
1034 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1035 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1036 PcdDatumType
= PcdItem
.DatumType
1042 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1045 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1046 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1050 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1052 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1053 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1055 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1057 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1058 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1060 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1061 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1063 for BuildData
in self
._Bdb
._CACHE
_.values():
1064 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1066 for key
in BuildData
.Pcds
:
1067 PcdItem
= BuildData
.Pcds
[key
]
1068 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1069 PcdItem
.DefaultValue
= pcdvalue
1070 PcdItem
.PcdValueFromComm
= pcdvalue
1071 #In command line, the latter full assign value in commandLine should override the former field assign value.
1072 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1075 if GlobalData
.BuildOptionPcd
:
1076 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1077 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1079 if (TokenSpaceGuid
, Token
) not in field_assign
:
1080 field_assign
[TokenSpaceGuid
, Token
] = []
1081 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1083 if (TokenSpaceGuid
, Token
) in field_assign
:
1084 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1085 field_assign
[TokenSpaceGuid
, Token
] = []
1086 for item
in delete_assign
:
1087 GlobalData
.BuildOptionPcd
.remove(item
)
1090 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1093 TokenCName
+= '.' + FieldName
1094 if PcdValue
.startswith('H'):
1095 if FieldName
and IsFieldValueAnArray(PcdValue
[1:]):
1096 PcdDatumType
= TAB_VOID
1098 if FieldName
and not IsArray
:
1101 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1102 except BadExpression
as Value
:
1103 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1104 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1105 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1106 if FieldName
and IsFieldValueAnArray(PcdValue
):
1107 PcdDatumType
= TAB_VOID
1109 if FieldName
and not IsArray
:
1112 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1113 except BadExpression
as Value
:
1114 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1115 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1116 elif PcdValue
.startswith('L'):
1117 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1118 if FieldName
and IsFieldValueAnArray(PcdValue
):
1119 PcdDatumType
= TAB_VOID
1121 if FieldName
and not IsArray
:
1124 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1125 except BadExpression
as Value
:
1126 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1127 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1129 if PcdValue
.upper() == 'FALSE':
1131 if PcdValue
.upper() == 'TRUE':
1134 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1135 PcdValue
= '"' + PcdValue
+ '"'
1136 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1137 PcdValue
= '"' + PcdValue
+ '"'
1141 if PcdValue
.upper().startswith('0X'):
1144 Num
= int(PcdValue
, Base
)
1146 PcdValue
= '"' + PcdValue
+ '"'
1147 if IsFieldValueAnArray(PcdValue
):
1148 PcdDatumType
= TAB_VOID
1153 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1154 except BadExpression
as Value
:
1155 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1156 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1159 ## Retrieve all PCD settings in platform
1162 if self
._Pcds
is None:
1163 self
._Pcds
= OrderedDict()
1164 self
.__ParsePcdFromCommandLine
()
1165 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1166 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1167 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1168 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1169 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1170 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1171 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1172 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1173 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1175 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1176 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1177 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1178 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1179 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1180 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1182 self
.RecoverCommandLinePcd()
1185 ## Retrieve [BuildOptions]
1187 def BuildOptions(self
):
1188 if self
._BuildOptions
is None:
1189 self
._BuildOptions
= OrderedDict()
1191 # Retrieve build option for EDKII and EDK style module
1193 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1194 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1195 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1196 if Dummy3
.upper() != TAB_COMMON
:
1198 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1200 # Only flags can be appended
1202 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1203 self
._BuildOptions
[CurKey
] = Option
1205 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1206 self
._BuildOptions
[CurKey
] += ' ' + Option
1207 return self
._BuildOptions
1209 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1210 if self
._ModuleTypeOptions
is None:
1211 self
._ModuleTypeOptions
= OrderedDict()
1212 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1213 options
= OrderedDict()
1214 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1215 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1216 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1217 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1218 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1219 Type
= Dummy2
+ '.' + Dummy3
1220 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1221 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1222 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1223 options
[Key
] = Option
1225 if ' ' + Option
not in options
[Key
]:
1226 options
[Key
] += ' ' + Option
1227 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1230 def GetStructurePcdInfo(PcdSet
):
1231 structure_pcd_data
= defaultdict(list)
1233 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1235 return structure_pcd_data
1238 def OverrideByFdf(StruPcds
,workspace
):
1239 if GlobalData
.gFdfParser
is None:
1241 StructurePcdInFdf
= OrderedDict()
1242 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1243 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1244 for item
in fdfpcd
:
1245 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1246 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1247 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1248 for Pcd
in StruPcds
.values():
1249 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1251 FieldValues
= OrderedDict()
1252 for item
in StructurePcdInFdf
:
1253 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1254 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1255 for field
in FieldValues
:
1256 if field
not in Pcd
.PcdFieldValueFromFdf
:
1257 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1258 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1259 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1260 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1265 def OverrideByComm(StruPcds
):
1266 StructurePcdInCom
= OrderedDict()
1267 for item
in GlobalData
.BuildOptionPcd
:
1268 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1269 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1270 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1271 for Pcd
in StruPcds
.values():
1272 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1274 FieldValues
= OrderedDict()
1275 for item
in StructurePcdInCom
:
1276 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1277 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1278 for field
in FieldValues
:
1279 if field
not in Pcd
.PcdFieldValueFromComm
:
1280 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1281 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1282 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1283 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1286 def OverrideByCommOverAll(self
,AllPcds
):
1287 def CheckStructureInComm(commpcds
):
1290 if len(commpcds
[0]) == 5:
1293 NoFiledValues
= OrderedDict()
1294 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1295 StructurePcdInCom
= OrderedDict()
1296 for item
in GlobalData
.BuildOptionPcd
:
1297 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1298 for item
in StructurePcdInCom
:
1300 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1302 for item
in GlobalData
.BuildOptionPcd
:
1303 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1304 for Guid
, Name
in NoFiledValues
:
1305 if (Name
, Guid
) in AllPcds
:
1306 Pcd
= AllPcds
.get((Name
, Guid
))
1307 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1308 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1310 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
1311 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1312 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1314 Pcd
.PcdValueFromComm
= StringToArray(NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0])
1315 Pcd
.DefaultValue
= StringToArray(NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0])
1316 for sku
in Pcd
.SkuInfoList
:
1317 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1318 if SkuInfo
.DefaultValue
:
1319 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
1320 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1322 SkuInfo
.DefaultValue
= StringToArray(NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0])
1324 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
1325 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1327 SkuInfo
.HiiDefaultValue
= StringToArray(NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0])
1328 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1329 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
1330 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1332 SkuInfo
.DefaultStoreDict
[defaultstore
] = StringToArray(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 if PcdInDec
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
1345 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1347 PcdInDec
.PcdValueFromComm
= StringToArray(NoFiledValues
[(Guid
, Name
)][0])
1348 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1349 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1350 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1351 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1352 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1353 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1354 if PcdInDec
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
1355 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1357 self
.Pcds
[Name
, Guid
].DefaultValue
= StringToArray(NoFiledValues
[( Guid
, Name
)][0])
1358 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1359 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1360 if PcdInDec
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
1361 self
.Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1363 self
.Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', StringToArray(NoFiledValues
[( Guid
, Name
)][0]))}
1366 def OverrideByFdfOverAll(self
,AllPcds
):
1368 if GlobalData
.gFdfParser
is None:
1370 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1371 for Name
,Guid
,Field
in NoFiledValues
:
1374 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1375 if (Name
,Guid
) in AllPcds
:
1376 Pcd
= AllPcds
.get((Name
,Guid
))
1377 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1378 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1380 Pcd
.PcdValueFromComm
= Value
1381 Pcd
.DefaultValue
= Value
1382 for sku
in Pcd
.SkuInfoList
:
1383 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1384 if SkuInfo
.DefaultValue
:
1385 SkuInfo
.DefaultValue
= Value
1387 SkuInfo
.HiiDefaultValue
= Value
1388 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1389 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1390 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1391 if Pcd
.DatumType
== TAB_VOID
:
1392 if not Pcd
.MaxDatumSize
:
1393 Pcd
.MaxDatumSize
= '0'
1394 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1395 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1396 MaxSize
= max(CurrentSize
, OptionSize
)
1397 Pcd
.MaxDatumSize
= str(MaxSize
)
1399 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1401 PcdInDec
.PcdValueFromFdf
= Value
1402 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1403 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1404 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1405 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1406 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
1409 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1411 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1412 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1413 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1414 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1415 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1416 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1419 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1420 SkuIds
= self
.SkuIds
1421 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1422 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1425 # Find out all possible PCD candidates for self._Arch
1428 for Type
in TypeList
:
1429 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1431 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1432 SkuName
= SkuName
.upper()
1433 default_store
= default_store
.upper()
1434 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1435 if SkuName
not in SkuIds
:
1438 if SkuName
in SkuIds
and "." in TokenSpaceGuid
:
1439 S_PcdSet
.append([ TokenSpaceGuid
.split(".")[0], TokenSpaceGuid
.split(".")[1], PcdCName
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1441 # handle pcd value override
1442 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1443 S_pcd_set
= OrderedDict()
1444 for str_pcd
in StrPcdSet
:
1445 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1446 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1447 if not isinstance (str_pcd_dec
, StructurePcd
):
1448 EdkLogger
.error('build', PARSER_ERROR
,
1449 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1450 File
=self
.MetaFile
, Line
= StrPcdSet
[str_pcd
][0][5])
1452 str_pcd_obj_str
= StructurePcd()
1453 str_pcd_obj_str
.copy(str_pcd_dec
)
1455 str_pcd_obj_str
.copy(str_pcd_obj
)
1456 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1457 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
}
1459 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
}
1460 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1461 if str_pcd_data
[3] in SkuIds
:
1462 str_pcd_obj_str
.AddOverrideValue(str_pcd_data
[2], str(str_pcd_data
[6]), TAB_DEFAULT
if str_pcd_data
[3] == TAB_COMMON
else str_pcd_data
[3], TAB_DEFAULT_STORES_DEFAULT
if str_pcd_data
[4] == TAB_COMMON
else str_pcd_data
[4], self
.MetaFile
.File
if self
.WorkspaceDir
not in self
.MetaFile
.File
else self
.MetaFile
.File
[len(self
.WorkspaceDir
) if self
.WorkspaceDir
.endswith(os
.path
.sep
) else len(self
.WorkspaceDir
)+1:], LineNo
=str_pcd_data
[5])
1463 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1465 EdkLogger
.error('build', PARSER_ERROR
,
1466 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1467 File
=self
.MetaFile
, Line
= StrPcdSet
[str_pcd
][0][5])
1468 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1469 for Pcd
in self
.DecPcds
:
1470 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1471 if Pcd
not in S_pcd_set
:
1472 str_pcd_obj_str
= StructurePcd()
1473 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1474 str_pcd_obj
= Pcds
.get(Pcd
, None)
1476 str_pcd_obj_str
.copy(str_pcd_obj
)
1477 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1478 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
}
1480 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
}
1481 S_pcd_set
[Pcd
] = str_pcd_obj_str
1483 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1484 for stru_pcd
in S_pcd_set
.values():
1485 for skuid
in SkuIds
:
1486 if skuid
in stru_pcd
.SkuOverrideValues
:
1488 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1490 if skuid
not in stru_pcd
.SkuOverrideValues
:
1491 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1492 if nextskuid
== TAB_DEFAULT
:
1495 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1496 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})
1498 stru_pcd
.ValueChain
.add((skuid
, ''))
1499 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1500 for skuid
in SkuIds
:
1503 if skuid
not in stru_pcd
.SkuOverrideValues
:
1504 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1505 if nextskuid
== TAB_DEFAULT
:
1508 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1511 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1512 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1514 for defaultstoreid
in DefaultStores
:
1515 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1516 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = copy
.deepcopy(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1517 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1518 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1519 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1520 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1522 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1523 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1524 if str_pcd_obj
is None:
1525 print(PcdName
, PcdGuid
)
1527 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1528 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1529 if skuname
not in str_pcd_obj
.SkuInfoList
:
1530 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1532 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1533 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1534 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1535 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1536 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1537 str_pcd_obj
.DefaultValue
= PcdValue
1539 if skuname
not in str_pcd_obj
.SkuInfoList
:
1540 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1542 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1543 if nextskuid
== TAB_DEFAULT
:
1546 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1547 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
)
1548 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1549 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1551 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1552 for str_pcd_obj
in S_pcd_set
.values():
1553 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1554 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1556 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1557 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1558 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1559 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1561 for str_pcd_obj
in S_pcd_set
.values():
1563 str_pcd_obj
.MaxDatumSize
= self
.GetStructurePcdMaxSize(str_pcd_obj
)
1564 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1565 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1569 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1570 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1571 del pcd
.SkuInfoList
[TAB_COMMON
]
1572 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1573 del pcd
.SkuInfoList
[TAB_COMMON
]
1575 map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1578 ## Retrieve non-dynamic PCD settings
1580 # @param Type PCD type
1582 # @retval a dict object contains settings of given PCD type
1584 def _GetPcd(self
, Type
):
1585 Pcds
= OrderedDict()
1587 # tdict is a special dict kind of type, used for selecting correct
1588 # PCD settings for certain ARCH
1590 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1592 PcdDict
= tdict(True, 3)
1594 # Find out all possible PCD candidates for self._Arch
1595 RecordList
= self
._RawData
[Type
, self
._Arch
]
1596 PcdValueDict
= OrderedDict()
1597 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1598 SkuName
= SkuName
.upper()
1599 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1600 if SkuName
not in AvailableSkuIdSet
:
1601 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1602 File
=self
.MetaFile
, Line
=Dummy5
)
1603 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1604 if "." not in TokenSpaceGuid
:
1605 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1606 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1608 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1609 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1612 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1614 if int(MaxDatumSize
, 0) > 0xFFFF:
1615 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1616 File
=self
.MetaFile
, Line
=Dummy4
)
1617 if int(MaxDatumSize
, 0) < 0:
1618 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1619 File
=self
.MetaFile
, Line
=Dummy4
)
1620 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1621 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1623 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1625 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.iteritems():
1626 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1627 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1628 elif TAB_DEFAULT
in PcdSetting
:
1629 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_DEFAULT
]
1630 elif TAB_COMMON
in PcdSetting
:
1631 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_COMMON
]
1637 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1640 self
._PCD
_TYPE
_STRING
_[Type
],
1650 if self
.SkuIdMgr
.SystemSkuId
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1651 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[self
.SkuIdMgr
.SystemSkuId
] = {}
1652 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[self
.SkuIdMgr
.SystemSkuId
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
1655 def GetStructurePcdMaxSize(self
, str_pcd
):
1656 pcd_default_value
= str_pcd
.DefaultValue
1657 sku_values
= [skuobj
.HiiDefaultValue
if str_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]] else skuobj
.DefaultValue
for skuobj
in str_pcd
.SkuInfoList
.values()]
1658 sku_values
.append(pcd_default_value
)
1660 def get_length(value
):
1661 Value
= value
.strip()
1663 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1665 if Value
.startswith('L"') and Value
.endswith('"'):
1666 return len(Value
[2:-1])
1667 if Value
[0] == '"' and Value
[-1] == '"':
1668 return len(Value
) - 2
1669 if Value
[0] == '{' and Value
[-1] == '}':
1670 return len(Value
.split(","))
1671 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1672 return len(list(Value
[2:-1]))
1673 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1674 return len(Value
) - 2
1677 return str(max(get_length(item
) for item
in sku_values
))
1680 def ExecuteCommand (Command
):
1682 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1684 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1685 Result
= Process
.communicate()
1686 return Process
.returncode
, Result
[0], Result
[1]
1689 def IntToCString(Value
, ValueSize
):
1691 if not isinstance (Value
, str):
1692 for Index
in range(0, ValueSize
):
1693 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1695 Result
= Result
+ '"'
1698 def GenerateSizeFunction(self
, Pcd
):
1699 CApp
= "// Default Value in Dec \n"
1700 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1701 for FieldList
in [Pcd
.DefaultValues
]:
1704 for FieldName
in FieldList
:
1705 FieldName
= "." + FieldName
1706 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1707 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1709 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1710 except BadExpression
:
1711 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1712 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1713 Value
, ValueSize
= ParseFieldValue(Value
)
1714 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]);
1717 FieldName_ori
= FieldName
.strip('.')
1718 while '[' in FieldName
:
1719 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1720 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1721 FieldName
= FieldName
.split(']', 1)[1]
1722 FieldName
= NewFieldName
+ FieldName
1723 while '[' in FieldName
:
1724 FieldName
= FieldName
.rsplit('[', 1)[0]
1725 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])
1726 for skuname
in Pcd
.SkuOverrideValues
:
1727 if skuname
== TAB_COMMON
:
1729 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1730 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1731 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
].get(defaultstorenameitem
)]:
1734 for FieldName
in FieldList
:
1735 FieldName
= "." + FieldName
1736 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1737 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1739 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1740 except BadExpression
:
1741 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1742 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1743 Value
, ValueSize
= ParseFieldValue(Value
)
1744 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]);
1747 FieldName_ori
= FieldName
.strip('.')
1748 while '[' in FieldName
:
1749 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1750 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1751 FieldName
= FieldName
.split(']', 1)[1]
1752 FieldName
= NewFieldName
+ FieldName
1753 while '[' in FieldName
:
1754 FieldName
= FieldName
.rsplit('[', 1)[0]
1755 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])
1756 if Pcd
.PcdFieldValueFromFdf
:
1757 CApp
= CApp
+ "// From fdf \n"
1758 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1759 FieldName
= "." + FieldName
1760 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1761 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1763 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1764 except BadExpression
:
1765 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1766 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1767 Value
, ValueSize
= ParseFieldValue(Value
)
1768 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]);
1771 FieldName_ori
= FieldName
.strip('.')
1772 while '[' in FieldName
:
1773 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1774 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1775 FieldName
= FieldName
.split(']', 1)[1]
1776 FieldName
= NewFieldName
+ FieldName
1777 while '[' in FieldName
:
1778 FieldName
= FieldName
.rsplit('[', 1)[0]
1779 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])
1780 if Pcd
.PcdFieldValueFromComm
:
1781 CApp
= CApp
+ "// From Command Line \n"
1782 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1783 FieldName
= "." + FieldName
1784 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1785 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1787 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1788 except BadExpression
:
1789 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1790 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1791 Value
, ValueSize
= ParseFieldValue(Value
)
1792 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]);
1795 FieldName_ori
= FieldName
.strip('.')
1796 while '[' in FieldName
:
1797 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1798 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1799 FieldName
= FieldName
.split(']', 1)[1]
1800 FieldName
= NewFieldName
+ FieldName
1801 while '[' in FieldName
:
1802 FieldName
= FieldName
.rsplit('[', 1)[0]
1803 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])
1804 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1809 def GenerateSizeStatments(Pcd
):
1810 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1811 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1814 def GenerateDefaultValueAssignFunction(self
, Pcd
):
1815 CApp
= "// Default value in Dec \n"
1816 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
)
1817 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1818 CApp
= CApp
+ ' CHAR8 *Value;\n'
1819 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1820 IsArray
= IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1823 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1824 except BadExpression
:
1825 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1826 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1827 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1828 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1829 if isinstance(Value
, str):
1830 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1833 # Use memcpy() to copy value into field
1835 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1836 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1837 for FieldList
in [Pcd
.DefaultValues
]:
1840 for FieldName
in FieldList
:
1841 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1844 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1845 except BadExpression
:
1846 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1847 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1850 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1852 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]))
1853 if isinstance(Value
, str):
1854 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1857 # Use memcpy() to copy value into field
1859 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1860 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1861 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])
1862 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1864 if '[' in FieldName
and ']' in FieldName
:
1865 Index
= int(FieldName
.split('[')[1].split(']')[0])
1866 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
)
1868 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1870 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1875 def GenerateDefaultValueAssignStatement(Pcd
):
1876 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1879 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
1880 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
1881 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.DatumType
)
1882 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1883 CApp
= CApp
+ ' CHAR8 *Value;\n'
1885 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
1886 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1887 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
1888 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
1890 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
1891 for FieldList
in [pcddefaultvalue
, inherit_OverrideValues
.get(DefaultStoreName
)]:
1894 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1895 IsArray
= IsFieldValueAnArray(FieldList
)
1898 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
1899 except BadExpression
:
1900 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
1901 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1902 Value
, ValueSize
= ParseFieldValue (FieldList
)
1904 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
1905 if isinstance(Value
, str):
1906 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
)
1909 # Use memcpy() to copy value into field
1911 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
)
1912 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1914 if isinstance(Value
, str):
1915 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
1918 # Use memcpy() to copy value into field
1920 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
1921 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1923 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
1924 for FieldName
in FieldList
:
1925 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1928 FieldValue
= ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1929 except BadExpression
:
1930 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1931 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1934 Value
, ValueSize
= ParseFieldValue (FieldValue
)
1936 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1938 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]))
1939 if isinstance(Value
, str):
1940 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1943 # Use memcpy() to copy value into field
1945 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1946 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1947 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])
1948 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1950 if '[' in FieldName
and ']' in FieldName
:
1951 Index
= int(FieldName
.split('[')[1].split(']')[0])
1952 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
)
1954 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1956 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1961 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
1962 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
1965 def GenerateCommandLineValue(self
, Pcd
):
1966 CApp
= "// Value in CommandLine\n"
1967 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
)
1968 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1969 CApp
= CApp
+ ' CHAR8 *Value;\n'
1971 pcddefaultvalue
= Pcd
.PcdValueFromComm
1972 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
1975 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1976 IsArray
= IsFieldValueAnArray(FieldList
)
1979 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
1980 except BadExpression
:
1981 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
1982 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1983 Value
, ValueSize
= ParseFieldValue (FieldList
)
1985 if isinstance(Value
, str):
1986 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
1989 # Use memcpy() to copy value into field
1991 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
1992 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1994 for FieldName
in FieldList
:
1995 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1998 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1999 except BadExpression
:
2000 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2001 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2005 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2007 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]))
2008 if isinstance(Value
, str):
2009 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2012 # Use memcpy() to copy value into field
2014 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
2015 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2016 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])
2017 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2019 if '[' in FieldName
and ']' in FieldName
:
2020 Index
= int(FieldName
.split('[')[1].split(']')[0])
2021 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
)
2023 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2025 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2030 def GenerateCommandLineValueStatement(Pcd
):
2031 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2033 def GenerateFdfValue(self
,Pcd
):
2034 CApp
= "// Value in Fdf\n"
2035 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
)
2036 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2037 CApp
= CApp
+ ' CHAR8 *Value;\n'
2039 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2040 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2043 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2044 IsArray
= IsFieldValueAnArray(FieldList
)
2047 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2048 except BadExpression
:
2049 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2050 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2051 Value
, ValueSize
= ParseFieldValue (FieldList
)
2053 if isinstance(Value
, str):
2054 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2057 # Use memcpy() to copy value into field
2059 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2060 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2062 for FieldName
in FieldList
:
2063 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2066 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2067 except BadExpression
:
2068 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2069 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2073 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2075 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]))
2076 if isinstance(Value
, str):
2077 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2080 # Use memcpy() to copy value into field
2082 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
2083 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2084 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])
2085 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2087 if '[' in FieldName
and ']' in FieldName
:
2088 Index
= int(FieldName
.split('[')[1].split(']')[0])
2089 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
)
2091 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2093 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2098 def GenerateFdfValueStatement(Pcd
):
2099 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2102 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2103 OverrideValues
= {DefaultStore
:""}
2104 if Pcd
.SkuOverrideValues
:
2105 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2106 if not OverrideValues
:
2107 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2108 for DefaultStoreName
in OverrideValues
:
2109 CApp
= CApp
+ 'void\n'
2110 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2111 CApp
= CApp
+ ' void\n'
2112 CApp
= CApp
+ ' )\n'
2114 CApp
= CApp
+ ' UINT32 Size;\n'
2115 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2116 CApp
= CApp
+ ' CHAR8 *Value;\n'
2117 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2118 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2119 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.DatumType
, Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2122 if SkuName
in Pcd
.SkuInfoList
:
2123 DefaultValue
= Pcd
.SkuInfoList
[SkuName
].DefaultStoreDict
.get(DefaultStoreName
, Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
if Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
else Pcd
.SkuInfoList
[SkuName
].DefaultValue
)
2125 DefaultValue
= Pcd
.DefaultValue
2126 PcdDefaultValue
= StringToArray(DefaultValue
.strip())
2128 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2131 # Get current PCD value and size
2133 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2136 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2137 # the correct value. For structures with a flexible array member, the flexible
2138 # array member is detected, and the size is based on the highest index used with
2139 # the flexible array member. The flexible array member must be the last field
2140 # in a structure. The size formula for this case is:
2141 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2143 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
)
2146 # Allocate and zero buffer for the PCD
2147 # Must handle cases where current value is smaller, larger, or same size
2148 # Always keep that larger one as the current size
2150 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2151 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.DatumType
)
2152 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2155 # Copy current PCD value into allocated buffer.
2157 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2160 # Assign field values in PCD
2162 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2163 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2164 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2165 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2166 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2167 for defaultstorenameitem
in storeset
:
2168 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2169 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2170 if skuname
== SkuName
:
2173 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2174 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2175 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2176 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2178 # Set new PCD value and size
2180 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2185 CApp
= CApp
+ ' free (Pcd);\n'
2188 return InitByteValue
, CApp
2189 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2190 if not OverrideValues
:
2192 for key
in OverrideValues
:
2193 if OverrideValues
[key
]:
2197 def GenerateByteArrayValue (self
, StructuredPcds
):
2199 # Generate/Compile/Run C application to determine if there are any flexible array members
2201 if not StructuredPcds
:
2205 CApp
= PcdMainCHeader
2207 IncludeFiles
= set()
2208 for PcdName
in StructuredPcds
:
2209 Pcd
= StructuredPcds
[PcdName
]
2210 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2211 if IncludeFile
not in IncludeFiles
:
2212 IncludeFiles
.add(IncludeFile
)
2213 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2215 for PcdName
in StructuredPcds
:
2216 Pcd
= StructuredPcds
[PcdName
]
2217 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2218 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2219 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2220 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2221 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2222 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2223 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2225 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2226 if SkuName
not in Pcd
.SkuOverrideValues
:
2228 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2229 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2230 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2231 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2232 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2234 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2235 if SkuName
not in Pcd
.SkuOverrideValues
:
2237 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2238 Pcd
= StructuredPcds
[PcdName
]
2239 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2241 CApp
= CApp
+ 'VOID\n'
2242 CApp
= CApp
+ 'PcdEntryPoint(\n'
2243 CApp
= CApp
+ ' VOID\n'
2244 CApp
= CApp
+ ' )\n'
2246 for Pcd
in StructuredPcds
.values():
2247 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
]]:
2248 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2250 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2251 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2253 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2254 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2257 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2259 if not os
.path
.exists(self
.OutputPath
):
2260 os
.makedirs(self
.OutputPath
)
2261 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2262 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2264 MakeApp
= PcdMakefileHeader
2265 if sys
.platform
== "win32":
2266 MakeApp
= MakeApp
+ 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2268 MakeApp
= MakeApp
+ PcdGccMakefile
2269 MakeApp
= MakeApp
+ 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2270 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2273 PlatformInc
= OrderedDict()
2274 for Cache
in self
._Bdb
._CACHE
_.values():
2275 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2278 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2279 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2280 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2281 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2284 for Pcd
in StructuredPcds
.values():
2285 for PackageDec
in Pcd
.PackageDecs
:
2286 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2287 if not os
.path
.exists(Package
):
2288 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2289 if Package
not in PcdDependDEC
:
2290 PcdDependDEC
.append(Package
)
2292 if PlatformInc
and PcdDependDEC
:
2293 for pkg
in PcdDependDEC
:
2294 if pkg
in PlatformInc
:
2295 for inc
in PlatformInc
[pkg
]:
2296 MakeApp
+= '-I' + str(inc
) + ' '
2297 IncSearchList
.append(inc
)
2298 MakeApp
= MakeApp
+ '\n'
2300 CC_FLAGS
= LinuxCFLAGS
2301 if sys
.platform
== "win32":
2302 CC_FLAGS
= WindowsCFLAGS
2303 BuildOptions
= OrderedDict()
2304 for Options
in self
.BuildOptions
:
2305 if Options
[2] != EDKII_NAME
:
2308 if Family
and Family
!= self
.ToolChainFamily
:
2310 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2314 if Target
== "*" or Target
== self
._Target
:
2315 if Tag
== "*" or Tag
== self
._Toolchain
:
2316 if Arch
== "*" or Arch
== self
.Arch
:
2317 if Tool
not in BuildOptions
:
2318 BuildOptions
[Tool
] = OrderedDict()
2319 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or self
.BuildOptions
[Options
].startswith('='):
2320 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
2322 # append options for the same tool except PATH
2324 BuildOptions
[Tool
][Attr
] += " " + self
.BuildOptions
[Options
]
2326 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
2328 for Tool
in BuildOptions
:
2329 for Attr
in BuildOptions
[Tool
]:
2331 Value
= BuildOptions
[Tool
][Attr
]
2332 ValueList
= Value
.split()
2334 for Id
, Item
in enumerate(ValueList
):
2335 if Item
in ['-D', '/D', '-U', '/U']:
2336 CC_FLAGS
+= ' ' + Item
2337 if Id
+ 1 < len(ValueList
):
2338 CC_FLAGS
+= ' ' + ValueList
[Id
+ 1]
2339 elif Item
.startswith(('-D', '/D', '-U', '/U')):
2340 CC_FLAGS
+= ' ' + Item
2343 if sys
.platform
== "win32":
2344 MakeApp
= MakeApp
+ PcdMakefileEnd
2345 MakeApp
= MakeApp
+ '\n'
2346 IncludeFileFullPaths
= []
2347 for includefile
in IncludeFiles
:
2348 for includepath
in IncSearchList
:
2349 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2350 if os
.path
.exists(includefullpath
):
2351 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2354 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2355 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2356 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2357 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2358 for include_file
in IncFileList
:
2359 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2360 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2361 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2362 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2364 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2365 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2366 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2368 PcdValueInitExe
= PcdValueInitName
2369 if not sys
.platform
== "win32":
2370 PcdValueInitExe
= os
.path
.join(os
.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName
)
2372 PcdValueInitExe
= os
.path
.join(os
.getenv("EDK_TOOLS_PATH"), 'Bin', 'Win32', PcdValueInitName
) +".exe"
2375 if sys
.platform
== "win32":
2376 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2377 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2380 MakeCommand
= 'make -f %s' % (MakeFileName
)
2381 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2383 Messages
= Messages
.split('\n')
2386 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2387 File
= open (CAppBaseFileName
+ '.c', 'r')
2388 FileData
= File
.readlines()
2390 for Message
in Messages
:
2391 if " error" in Message
or "warning" in Message
:
2392 FileInfo
= Message
.strip().split('(')
2393 if len (FileInfo
) > 1:
2394 FileName
= FileInfo
[0]
2395 FileLine
= FileInfo
[1].split (')')[0]
2397 FileInfo
= Message
.strip().split(':')
2398 FileName
= FileInfo
[0]
2399 FileLine
= FileInfo
[1]
2400 if FileLine
.isdigit():
2401 error_line
= FileData
[int (FileLine
) - 1]
2402 if r
"//" in error_line
:
2403 c_line
, dsc_line
= error_line
.split(r
"//")
2405 dsc_line
= error_line
2406 message_itmes
= Message
.split(":")
2408 if "PcdValueInit.c" not in Message
:
2409 if not MessageGroup
:
2410 MessageGroup
.append(Message
)
2413 for item
in message_itmes
:
2414 if "PcdValueInit.c" in item
:
2415 Index
= message_itmes
.index(item
)
2416 message_itmes
[Index
] = dsc_line
.strip()
2418 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2421 MessageGroup
.append(Message
)
2423 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2425 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2427 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, PcdValueInitExe
, InputValueFile
):
2428 Command
= PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2429 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2431 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2433 File
= open (OutputValueFile
, 'r')
2434 FileBuffer
= File
.readlines()
2437 StructurePcdSet
= []
2438 for Pcd
in FileBuffer
:
2439 PcdValue
= Pcd
.split ('|')
2440 PcdInfo
= PcdValue
[0].split ('.')
2441 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2442 return StructurePcdSet
2445 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2446 if not os
.path
.exists(OutputFile
):
2448 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2450 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2454 ## Retrieve dynamic PCD settings
2456 # @param Type PCD type
2458 # @retval a dict object contains settings of given PCD type
2460 def _GetDynamicPcd(self
, Type
):
2463 Pcds
= OrderedDict()
2465 # tdict is a special dict kind of type, used for selecting correct
2466 # PCD settings for certain ARCH and SKU
2468 PcdDict
= tdict(True, 4)
2470 # Find out all possible PCD candidates for self._Arch
2471 RecordList
= self
._RawData
[Type
, self
._Arch
]
2472 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2475 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2476 SkuName
= SkuName
.upper()
2477 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2478 if SkuName
not in AvailableSkuIdSet
:
2479 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2480 File
=self
.MetaFile
, Line
=Dummy5
)
2481 if "." not in TokenSpaceGuid
:
2482 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2483 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2485 # Remove redundant PCD candidates, per the ARCH and SKU
2486 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2488 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2492 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2494 if int(MaxDatumSize
, 0) > 0xFFFF:
2495 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2496 File
=self
.MetaFile
, Line
=Dummy4
)
2497 if int(MaxDatumSize
, 0) < 0:
2498 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2499 File
=self
.MetaFile
, Line
=Dummy4
)
2500 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2501 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2502 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2503 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2504 if MaxDatumSize
.strip():
2505 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2508 if pcdObject
.MaxDatumSize
:
2509 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2512 if CurrentMaxSize
> PcdMaxSize
:
2513 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2515 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2518 self
._PCD
_TYPE
_STRING
_[Type
],
2523 OrderedDict({SkuName
: SkuInfo
}),
2528 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2529 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2530 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2532 for pcd
in Pcds
.values():
2533 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2534 # Only fix the value while no value provided in DSC file.
2535 for sku
in pcd
.SkuInfoList
.values():
2536 if not sku
.DefaultValue
:
2537 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2538 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2539 valuefromDec
= pcdDecObject
.DefaultValue
2540 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2541 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2542 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2543 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2544 del pcd
.SkuInfoList
[TAB_COMMON
]
2545 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2546 del pcd
.SkuInfoList
[TAB_COMMON
]
2548 map(self
.FilterSkuSettings
, Pcds
.values())
2552 def FilterSkuSettings(self
, PcdObj
):
2554 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2555 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2556 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2557 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2558 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2559 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2561 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2562 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2567 def CompareVarAttr(Attr1
, Attr2
):
2568 if not Attr1
or not Attr2
: # for empty string
2570 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2571 Attr1Set
= set(Attr1s
)
2572 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2573 Attr2Set
= set(Attr2s
)
2574 if Attr2Set
== Attr1Set
:
2579 def CompletePcdValues(self
, PcdSet
):
2580 Pcds
= OrderedDict()
2581 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2582 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2583 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2584 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2585 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2587 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2588 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2589 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2590 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2591 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2592 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2593 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2595 PcdType
= PcdObj
.Type
2596 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2597 for skuid
in PcdObj
.SkuInfoList
:
2598 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2599 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2600 for defaultstorename
in DefaultStores
:
2601 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2602 skuobj
.DefaultStoreDict
[defaultstorename
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
2603 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2604 for skuname
, skuid
in SkuIds
.items():
2605 if skuname
not in PcdObj
.SkuInfoList
:
2606 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2607 while nextskuid
not in PcdObj
.SkuInfoList
:
2608 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2609 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2610 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2611 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2612 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2613 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2614 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2616 ## Retrieve dynamic HII PCD settings
2618 # @param Type PCD type
2620 # @retval a dict object contains settings of given PCD type
2622 def _GetDynamicHiiPcd(self
, Type
):
2626 Pcds
= OrderedDict()
2627 UserDefinedDefaultStores
= []
2629 # tdict is a special dict kind of type, used for selecting correct
2630 # PCD settings for certain ARCH and SKU
2632 PcdDict
= tdict(True, 5)
2634 RecordList
= self
._RawData
[Type
, self
._Arch
]
2635 # Find out all possible PCD candidates for self._Arch
2636 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2637 DefaultStoresDefine
= self
._GetDefaultStores
()
2639 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
2640 SkuName
= SkuName
.upper()
2641 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2642 DefaultStore
= DefaultStore
.upper()
2643 if DefaultStore
== TAB_COMMON
:
2644 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2646 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
2647 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
2648 if SkuName
not in AvailableSkuIdSet
:
2649 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2650 File
=self
.MetaFile
, Line
=Dummy5
)
2651 if DefaultStore
not in DefaultStoresDefine
:
2652 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2653 File
=self
.MetaFile
, Line
=Dummy5
)
2654 if "." not in TokenSpaceGuid
:
2655 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
2656 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
2659 # Remove redundant PCD candidates, per the ARCH and SKU
2660 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdSet
:
2662 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
2665 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2667 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2669 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2670 ExtraData
="[%s]" % VarAttribute
)
2672 FormatCorrect
= True
2673 if VariableOffset
.isdigit():
2674 if int(VariableOffset
, 10) > 0xFFFF:
2676 elif variablePattern
.match(VariableOffset
):
2677 if int(VariableOffset
, 16) > 0xFFFF:
2679 # For Offset written in "A.B"
2680 elif VariableOffset
.find('.') > -1:
2681 VariableOffsetList
= VariableOffset
.split(".")
2682 if not (len(VariableOffsetList
) == 2
2683 and IsValidWord(VariableOffsetList
[0])
2684 and IsValidWord(VariableOffsetList
[1])):
2685 FormatCorrect
= False
2687 FormatCorrect
= False
2688 if not FormatCorrect
:
2689 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2692 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2693 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2694 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2696 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2697 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
)]))
2699 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2700 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2701 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2702 if SkuName
in pcdObject
.SkuInfoList
:
2703 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2704 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2706 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2707 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2709 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2710 PcdClassObj
= PcdClassObject(
2713 self
._PCD
_TYPE
_STRING
_[Type
],
2718 OrderedDict({SkuName
: SkuInfo
}),
2721 pcdDecObject
.validateranges
,
2722 pcdDecObject
.validlists
,
2723 pcdDecObject
.expressions
,
2725 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
2726 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
2727 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
2729 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
2730 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2731 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2732 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
2733 for pcd
in Pcds
.values():
2734 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2735 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2736 pcd
.DatumType
= pcdDecObject
.DatumType
2737 # Only fix the value while no value provided in DSC file.
2738 for sku
in pcd
.SkuInfoList
.values():
2739 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2740 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2741 for default_store
in sku
.DefaultStoreDict
:
2742 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2743 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2744 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2745 valuefromDec
= pcdDecObject
.DefaultValue
2746 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
2747 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2748 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2749 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2750 del pcd
.SkuInfoList
[TAB_COMMON
]
2751 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2752 del pcd
.SkuInfoList
[TAB_COMMON
]
2754 if pcd
.MaxDatumSize
.strip():
2755 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2758 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
2759 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2761 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2762 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2763 if datalen
> MaxSize
:
2765 for defaultst
in skuobj
.DefaultStoreDict
:
2766 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2767 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
2768 pcd
.MaxDatumSize
= str(MaxSize
)
2769 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
2771 invalidpcd
= ",".join(invalidhii
)
2772 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
)
2774 map(self
.FilterSkuSettings
, Pcds
.values())
2779 def CheckVariableNameAssignment(Pcds
):
2781 for pcdname
in Pcds
:
2783 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
2784 if len(varnameset
) > 1:
2785 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
2787 return False, invalidhii
2790 ## Retrieve dynamic VPD PCD settings
2792 # @param Type PCD type
2794 # @retval a dict object contains settings of given PCD type
2796 def _GetDynamicVpdPcd(self
, Type
):
2799 Pcds
= OrderedDict()
2801 # tdict is a special dict kind of type, used for selecting correct
2802 # PCD settings for certain ARCH and SKU
2804 PcdDict
= tdict(True, 4)
2807 # Find out all possible PCD candidates for self._Arch
2808 RecordList
= self
._RawData
[Type
, self
._Arch
]
2809 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2811 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2812 SkuName
= SkuName
.upper()
2813 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2814 if SkuName
not in AvailableSkuIdSet
:
2815 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2816 File
=self
.MetaFile
, Line
=Dummy5
)
2817 if "." not in TokenSpaceGuid
:
2818 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2819 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2821 # Remove redundant PCD candidates, per the ARCH and SKU
2822 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2823 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2827 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
2828 # For the Integer & Boolean type, the optional data can only be InitialValue.
2829 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
2830 # until the DEC parser has been called.
2832 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2834 if int(MaxDatumSize
, 0) > 0xFFFF:
2835 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2836 File
=self
.MetaFile
, Line
=Dummy4
)
2837 if int(MaxDatumSize
, 0) < 0:
2838 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2839 File
=self
.MetaFile
, Line
=Dummy4
)
2840 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
2841 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2842 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2843 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2844 if MaxDatumSize
.strip():
2845 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2848 if pcdObject
.MaxDatumSize
:
2849 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2852 if CurrentMaxSize
> PcdMaxSize
:
2853 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2855 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2858 self
._PCD
_TYPE
_STRING
_[Type
],
2863 OrderedDict({SkuName
: SkuInfo
}),
2868 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2869 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2870 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
2871 for pcd
in Pcds
.values():
2872 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2873 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2874 pcd
.DatumType
= pcdDecObject
.DatumType
2875 # Only fix the value while no value provided in DSC file.
2876 for sku
in pcd
.SkuInfoList
.values():
2877 if not sku
.DefaultValue
:
2878 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2879 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2880 valuefromDec
= pcdDecObject
.DefaultValue
2881 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
2882 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2883 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2884 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2885 del pcd
.SkuInfoList
[TAB_COMMON
]
2886 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2887 del pcd
.SkuInfoList
[TAB_COMMON
]
2889 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
2890 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
2891 for pcd
in Pcds
.values():
2892 PcdValueTypeSet
= set()
2893 for sku
in pcd
.SkuInfoList
.values():
2894 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
2895 if len(PcdValueTypeSet
) > 1:
2896 for sku
in pcd
.SkuInfoList
.values():
2897 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
2899 map(self
.FilterSkuSettings
, Pcds
.values())
2902 ## Add external modules
2904 # The external modules are mostly those listed in FDF file, which don't
2907 # @param FilePath The path of module description file
2909 def AddModule(self
, FilePath
):
2910 FilePath
= NormPath(FilePath
)
2911 if FilePath
not in self
.Modules
:
2912 Module
= ModuleBuildClassObject()
2913 Module
.MetaFile
= FilePath
2914 self
.Modules
.append(Module
)
2917 def ToolChainFamily(self
):
2918 self
._ToolChainFamily
= TAB_COMPILER_MSFT
2919 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
2920 if os
.path
.isfile(BuildConfigurationFile
) == True:
2921 TargetTxt
= TargetTxtClassObject()
2922 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
2923 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
2924 if ToolDefinitionFile
== '':
2925 ToolDefinitionFile
= "tools_def.txt"
2926 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
2927 if os
.path
.isfile(ToolDefinitionFile
) == True:
2928 ToolDef
= ToolDefClassObject()
2929 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
2930 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
2931 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
2932 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
2933 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
2934 self
._ToolChainFamily
= TAB_COMPILER_MSFT
2936 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
2937 return self
._ToolChainFamily
2939 ## Add external PCDs
2941 # The external PCDs are mostly those listed in FDF file to specify address
2942 # or offset information.
2944 # @param Name Name of the PCD
2945 # @param Guid Token space guid of the PCD
2946 # @param Value Value of the PCD
2948 def AddPcd(self
, Name
, Guid
, Value
):
2949 if (Name
, Guid
) not in self
.Pcds
:
2950 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
2951 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
2955 if self
._DecPcds
is None:
2957 if GlobalData
.gFdfParser
:
2958 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
2960 for Inf
in FdfInfList
:
2961 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
2962 if ModuleFile
in self
._Modules
:
2964 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
2965 PkgSet
.update(ModuleData
.Packages
)
2966 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
2967 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
2968 return self
._DecPcds