2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
5 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 ## Platform build information from DSC file
17 # This class is used to retrieve information stored in database and convert them
18 # into PlatformBuildClassObject form for easier use for AutoGen.
20 from __future__
import print_function
21 from __future__
import absolute_import
22 from Common
.StringUtils
import *
23 from Common
.DataType
import *
24 from Common
.Misc
import *
26 from Common
.Expression
import *
27 from CommonDataClass
.CommonClass
import SkuInfoClass
28 from Common
.TargetTxtClassObject
import TargetTxtClassObject
29 from Common
.ToolDefClassObject
import ToolDefClassObject
30 from .MetaDataTable
import *
31 from .MetaFileTable
import *
32 from .MetaFileParser
import *
34 from .WorkspaceCommon
import GetDeclaredPcd
35 from Common
.Misc
import AnalyzeDscPcd
36 from Common
.Misc
import ProcessDuplicatedInf
,RemoveCComments
38 from Common
.Parsing
import IsValidWord
39 from Common
.VariableAttributes
import VariableAttributes
40 import Common
.GlobalData
as GlobalData
42 from functools
import reduce
43 from Common
.Misc
import SaveFileOnChange
44 from Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
45 from collections
import OrderedDict
, defaultdict
46 from .BuildClassObject
import ArrayIndex
48 def _IsFieldValueAnArray (Value
):
50 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
52 if Value
.startswith('L"') and Value
.endswith('"') and len(list(Value
[2:-1])) > 1:
54 if Value
[0] == '"' and Value
[-1] == '"' and len(list(Value
[1:-1])) > 1:
56 if Value
[0] == '{' and Value
[-1] == '}':
58 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
60 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
64 PcdValueInitName
= 'PcdValueInit'
75 #include <PcdValueCommon.h>
85 return PcdValueMain (argc, argv);
89 PcdMakefileHeader
= '''
92 # This file is auto-generated by build utility
97 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
98 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
100 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
102 LIBS = $(LIB_PATH)\Common.lib
104 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
109 $(APPFILE): $(OBJECTS)
114 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
118 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
119 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
120 ## regular expressions for finding decimal and hex numbers
121 Pattern
= re
.compile('^[1-9]\d*|0$')
122 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
123 ## Regular expression for finding header file inclusions
124 from AutoGen
.GenMake
import gIncludePattern
126 ## Find dependencies for one source file
128 # By searching recursively "#include" directive in file, find out all the
129 # files needed by given source file. The dependecies will be only searched
130 # in given search path list.
132 # @param SearchPathList The list of search path
134 # @retval list The list of files the given source file depends on
136 def GetDependencyList(FileStack
, SearchPathList
):
138 DependencySet
= set(FileStack
)
139 while len(FileStack
) > 0:
141 FullPathDependList
= []
142 CurrentFileDependencyList
= []
144 CurrentFileDependencyList
= DepDb
[F
]
148 FileContent
= Fd
.read()
149 except BaseException
as X
:
150 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
152 if "Fd" in dir(locals()):
155 if len(FileContent
) == 0:
158 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
159 FileContent
= FileContent
.decode('utf-16')
160 IncludedFileList
= gIncludePattern
.findall(FileContent
)
163 FileContent
= str(FileContent
)
164 IncludedFileList
= gIncludePattern
.findall(FileContent
)
167 IncludedFileList
= gIncludePattern
.findall(FileContent
)
169 for Inc
in IncludedFileList
:
171 Inc
= os
.path
.normpath(Inc
)
172 CurrentFileDependencyList
.append(Inc
)
173 DepDb
[F
] = CurrentFileDependencyList
175 CurrentFilePath
= os
.path
.dirname(F
)
176 PathList
= [CurrentFilePath
] + SearchPathList
177 for Inc
in CurrentFileDependencyList
:
178 for SearchPath
in PathList
:
179 FilePath
= os
.path
.join(SearchPath
, Inc
)
180 if not os
.path
.exists(FilePath
):
182 if FilePath
not in DependencySet
:
183 FileStack
.append(FilePath
)
184 FullPathDependList
.append(FilePath
)
186 DependencySet
.update(FullPathDependList
)
187 DependencyList
= list(DependencySet
) # remove duplicate ones
189 return DependencyList
191 class DscBuildData(PlatformBuildClassObject
):
192 # dict used to convert PCD type in database to string used by build tool
193 _PCD_TYPE_STRING_
= {
194 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
195 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
196 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
197 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
198 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
199 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
200 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
201 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
202 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
203 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
204 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
207 # dict used to convert part of [Defines] to members of DscBuildData directly
212 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
213 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
214 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
215 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
216 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
217 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
218 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
219 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
220 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
221 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
222 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
223 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
224 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
225 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
226 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
229 # used to compose dummy library class name for those forced library instances
230 _NullLibraryNumber
= 0
232 ## Constructor of DscBuildData
234 # Initialize object of DscBuildData
236 # @param FilePath The path of platform description file
237 # @param RawData The raw data of DSC file
238 # @param BuildDataBase Database used to retrieve module/package information
239 # @param Arch The target architecture
240 # @param Platform (not used for DscBuildData)
241 # @param Macros Macros used for replacement in DSC file
243 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
244 self
.MetaFile
= FilePath
245 self
._RawData
= RawData
246 self
._Bdb
= BuildDataBase
248 self
._Target
= Target
249 self
._Toolchain
= Toolchain
250 self
._ToolChainFamily
= None
252 self
._HandleOverridePath
()
253 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
254 self
.DefaultStores
= None
255 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
258 def OutputPath(self
):
259 if os
.getenv("WORKSPACE"):
260 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
262 return os
.path
.dirname(self
.DscFile
)
265 def __setitem__(self
, key
, value
):
266 self
.__dict
__[self
._PROPERTY
_[key
]] = value
269 def __getitem__(self
, key
):
270 return self
.__dict
__[self
._PROPERTY
_[key
]]
273 def __contains__(self
, key
):
274 return key
in self
._PROPERTY
_
276 ## Set all internal used members of DscBuildData to None
279 self
._PlatformName
= None
282 self
._DscSpecification
= None
283 self
._OutputDirectory
= None
284 self
._SupArchList
= None
285 self
._BuildTargets
= None
287 self
._PcdInfoFlag
= None
288 self
._VarCheckFlag
= None
289 self
._FlashDefinition
= None
290 self
._Prebuild
= None
291 self
._Postbuild
= None
292 self
._BuildNumber
= None
293 self
._MakefileName
= None
294 self
._BsBaseAddress
= None
295 self
._RtBaseAddress
= None
298 self
._LibraryInstances
= None
299 self
._LibraryClasses
= None
302 self
._BuildOptions
= None
303 self
._ModuleTypeOptions
= None
304 self
._LoadFixAddress
= None
305 self
._RFCLanguages
= None
306 self
._ISOLanguages
= None
307 self
._VpdToolGuid
= None
308 self
._MacroDict
= None
309 self
.DefaultStores
= None
311 ## handle Override Path of Module
312 def _HandleOverridePath(self
):
313 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
314 for Record
in RecordList
:
317 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
318 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
320 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
322 # Check if the source override path exists
323 if not os
.path
.isdir(SourceOverridePath
):
324 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
326 # Add to GlobalData Variables
327 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
329 ## Get current effective macros
332 if self
._MacroDict
is None:
334 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
335 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
336 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
337 return self
._MacroDict
344 ## Retrieve all information in [Defines] section
346 # (Retriving all [Defines] information in one-shot is just to save time.)
348 def _GetHeaderInfo(self
):
349 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
350 for Record
in RecordList
:
352 # items defined _PROPERTY_ don't need additional processing
354 # some special items in [Defines] section need special treatment
355 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
356 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
357 if ' ' in self
._OutputDirectory
:
358 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
359 File
=self
.MetaFile
, Line
=Record
[-1],
360 ExtraData
=self
._OutputDirectory
)
361 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
362 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
363 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
365 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
367 elif Name
== TAB_DSC_PREBUILD
:
368 PrebuildValue
= Record
[2]
369 if Record
[2][0] == '"':
370 if Record
[2][-1] != '"':
371 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
372 File
=self
.MetaFile
, Line
=Record
[-1])
373 PrebuildValue
= Record
[2][1:-1]
374 self
._Prebuild
= PrebuildValue
375 elif Name
== TAB_DSC_POSTBUILD
:
376 PostbuildValue
= Record
[2]
377 if Record
[2][0] == '"':
378 if Record
[2][-1] != '"':
379 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
380 File
=self
.MetaFile
, Line
=Record
[-1])
381 PostbuildValue
= Record
[2][1:-1]
382 self
._Postbuild
= PostbuildValue
383 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
384 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
385 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
386 self
._BuildTargets
= GetSplitValueList(Record
[2])
387 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
388 if self
._SkuName
is None:
389 self
._SkuName
= Record
[2]
390 if GlobalData
.gSKUID_CMD
:
391 self
._SkuName
= GlobalData
.gSKUID_CMD
392 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
393 self
._PcdInfoFlag
= Record
[2]
394 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
395 self
._VarCheckFlag
= Record
[2]
396 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
398 self
._LoadFixAddress
= int (Record
[2], 0)
400 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
401 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
402 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
403 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"',
404 File
=self
.MetaFile
, Line
=Record
[-1])
405 LanguageCodes
= Record
[2][1:-1]
406 if not LanguageCodes
:
407 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
408 File
=self
.MetaFile
, Line
=Record
[-1])
409 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
410 # check whether there is empty entries in the list
411 if None in LanguageList
:
412 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
413 File
=self
.MetaFile
, Line
=Record
[-1])
414 self
._RFCLanguages
= LanguageList
415 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
416 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
417 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
418 File
=self
.MetaFile
, Line
=Record
[-1])
419 LanguageCodes
= Record
[2][1:-1]
420 if not LanguageCodes
:
421 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
422 File
=self
.MetaFile
, Line
=Record
[-1])
423 if len(LanguageCodes
) % 3:
424 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
425 File
=self
.MetaFile
, Line
=Record
[-1])
427 for i
in range(0, len(LanguageCodes
), 3):
428 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
429 self
._ISOLanguages
= LanguageList
430 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
432 # try to convert GUID to a real UUID value to see whether the GUID is format
433 # for VPD_TOOL_GUID is correct.
438 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
439 self
._VpdToolGuid
= Record
[2]
441 self
[Name
] = Record
[2]
442 # set _Header to non-None in order to avoid database re-querying
443 self
._Header
= 'DUMMY'
445 ## Retrieve platform name
447 def PlatformName(self
):
448 if self
._PlatformName
is None:
449 if self
._Header
is None:
450 self
._GetHeaderInfo
()
451 if self
._PlatformName
is None:
452 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
453 return self
._PlatformName
457 return self
.PlatformName
459 ## Retrieve file guid
462 if self
._Guid
is None:
463 if self
._Header
is None:
464 self
._GetHeaderInfo
()
465 if self
._Guid
is None:
466 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
469 ## Retrieve platform version
472 if self
._Version
is None:
473 if self
._Header
is None:
474 self
._GetHeaderInfo
()
475 if self
._Version
is None:
476 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
479 ## Retrieve platform description file version
481 def DscSpecification(self
):
482 if self
._DscSpecification
is None:
483 if self
._Header
is None:
484 self
._GetHeaderInfo
()
485 if self
._DscSpecification
is None:
486 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
487 return self
._DscSpecification
489 ## Retrieve OUTPUT_DIRECTORY
491 def OutputDirectory(self
):
492 if self
._OutputDirectory
is None:
493 if self
._Header
is None:
494 self
._GetHeaderInfo
()
495 if self
._OutputDirectory
is None:
496 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
497 return self
._OutputDirectory
499 ## Retrieve SUPPORTED_ARCHITECTURES
501 def SupArchList(self
):
502 if self
._SupArchList
is None:
503 if self
._Header
is None:
504 self
._GetHeaderInfo
()
505 if self
._SupArchList
is None:
506 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
507 return self
._SupArchList
509 ## Retrieve BUILD_TARGETS
511 def BuildTargets(self
):
512 if self
._BuildTargets
is None:
513 if self
._Header
is None:
514 self
._GetHeaderInfo
()
515 if self
._BuildTargets
is None:
516 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
517 return self
._BuildTargets
520 def PcdInfoFlag(self
):
521 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
523 elif self
._PcdInfoFlag
.upper() == 'TRUE':
529 def VarCheckFlag(self
):
530 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
532 elif self
._VarCheckFlag
.upper() == 'TRUE':
537 # # Retrieve SKUID_IDENTIFIER
540 if self
._SkuName
is None:
541 if self
._Header
is None:
542 self
._GetHeaderInfo
()
543 if self
._SkuName
is None:
544 self
._SkuName
= TAB_DEFAULT
547 ## Override SKUID_IDENTIFIER
549 def SkuName(self
, Value
):
550 self
._SkuName
= Value
553 def FlashDefinition(self
):
554 if self
._FlashDefinition
is None:
555 if self
._Header
is None:
556 self
._GetHeaderInfo
()
557 if self
._FlashDefinition
is None:
558 self
._FlashDefinition
= ''
559 return self
._FlashDefinition
563 if self
._Prebuild
is None:
564 if self
._Header
is None:
565 self
._GetHeaderInfo
()
566 if self
._Prebuild
is None:
568 return self
._Prebuild
572 if self
._Postbuild
is None:
573 if self
._Header
is None:
574 self
._GetHeaderInfo
()
575 if self
._Postbuild
is None:
577 return self
._Postbuild
579 ## Retrieve FLASH_DEFINITION
581 def BuildNumber(self
):
582 if self
._BuildNumber
is None:
583 if self
._Header
is None:
584 self
._GetHeaderInfo
()
585 if self
._BuildNumber
is None:
586 self
._BuildNumber
= ''
587 return self
._BuildNumber
589 ## Retrieve MAKEFILE_NAME
591 def MakefileName(self
):
592 if self
._MakefileName
is None:
593 if self
._Header
is None:
594 self
._GetHeaderInfo
()
595 if self
._MakefileName
is None:
596 self
._MakefileName
= ''
597 return self
._MakefileName
599 ## Retrieve BsBaseAddress
601 def BsBaseAddress(self
):
602 if self
._BsBaseAddress
is None:
603 if self
._Header
is None:
604 self
._GetHeaderInfo
()
605 if self
._BsBaseAddress
is None:
606 self
._BsBaseAddress
= ''
607 return self
._BsBaseAddress
609 ## Retrieve RtBaseAddress
611 def RtBaseAddress(self
):
612 if self
._RtBaseAddress
is None:
613 if self
._Header
is None:
614 self
._GetHeaderInfo
()
615 if self
._RtBaseAddress
is None:
616 self
._RtBaseAddress
= ''
617 return self
._RtBaseAddress
619 ## Retrieve the top address for the load fix address
621 def LoadFixAddress(self
):
622 if self
._LoadFixAddress
is None:
623 if self
._Header
is None:
624 self
._GetHeaderInfo
()
626 if self
._LoadFixAddress
is None:
627 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
630 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
632 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
635 # If command line defined, should override the value in DSC file.
637 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
639 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
641 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']))
643 if self
._LoadFixAddress
< 0:
644 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
645 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
646 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
648 return self
._LoadFixAddress
650 ## Retrieve RFCLanguage filter
652 def RFCLanguages(self
):
653 if self
._RFCLanguages
is None:
654 if self
._Header
is None:
655 self
._GetHeaderInfo
()
656 if self
._RFCLanguages
is None:
657 self
._RFCLanguages
= []
658 return self
._RFCLanguages
660 ## Retrieve ISOLanguage filter
662 def ISOLanguages(self
):
663 if self
._ISOLanguages
is None:
664 if self
._Header
is None:
665 self
._GetHeaderInfo
()
666 if self
._ISOLanguages
is None:
667 self
._ISOLanguages
= []
668 return self
._ISOLanguages
670 ## Retrieve the GUID string for VPD tool
672 def VpdToolGuid(self
):
673 if self
._VpdToolGuid
is None:
674 if self
._Header
is None:
675 self
._GetHeaderInfo
()
676 if self
._VpdToolGuid
is None:
677 self
._VpdToolGuid
= ''
678 return self
._VpdToolGuid
680 ## Retrieve [SkuIds] section information
683 if self
._SkuIds
is None:
684 self
._SkuIds
= OrderedDict()
685 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
686 for Record
in RecordList
:
688 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
689 File
=self
.MetaFile
, Line
=Record
[-1])
691 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
692 File
=self
.MetaFile
, Line
=Record
[-1])
693 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
694 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
695 File
=self
.MetaFile
, Line
=Record
[-1])
696 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
697 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_)*'",
698 File
=self
.MetaFile
, Line
=Record
[-1])
699 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
700 if TAB_DEFAULT
not in self
._SkuIds
:
701 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
702 if TAB_COMMON
not in self
._SkuIds
:
703 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
708 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
710 def _GetDefaultStores(self
):
711 if self
.DefaultStores
is None:
712 self
.DefaultStores
= OrderedDict()
713 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
714 for Record
in RecordList
:
716 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
717 File
=self
.MetaFile
, Line
=Record
[-1])
719 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
720 File
=self
.MetaFile
, Line
=Record
[-1])
721 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
722 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
723 File
=self
.MetaFile
, Line
=Record
[-1])
724 if not IsValidWord(Record
[1]):
725 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_-.)*'",
726 File
=self
.MetaFile
, Line
=Record
[-1])
727 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
728 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
729 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
730 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
731 return self
.DefaultStores
733 def OverrideDuplicateModule(self
):
734 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
735 Macros
= self
._Macros
737 for Record
in RecordList
:
739 file_guid
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
740 file_guid_str
= file_guid
[0][2] if file_guid
else "NULL"
741 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
742 if self
._Arch
!= TAB_ARCH_COMMON
and (file_guid_str
,str(ModuleFile
)) in Components
:
743 self
._RawData
.DisableOverrideComponent(Components
[(file_guid_str
,str(ModuleFile
))])
744 Components
[(file_guid_str
,str(ModuleFile
))] = ModuleId
745 self
._RawData
._PostProcessed
= False
746 ## Retrieve [Components] section information
749 if self
._Modules
is not None:
751 self
.OverrideDuplicateModule()
752 self
._Modules
= OrderedDict()
753 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
754 Macros
= self
._Macros
755 for Record
in RecordList
:
756 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
760 # check the file validation
761 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
763 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
766 Module
= ModuleBuildClassObject()
767 Module
.MetaFile
= ModuleFile
769 # get module private library instance
770 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
771 for Record
in RecordList
:
772 LibraryClass
= Record
[0]
773 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
776 # check the file validation
777 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
779 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
782 if LibraryClass
== '' or LibraryClass
== 'NULL':
783 self
._NullLibraryNumber
+= 1
784 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
785 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
786 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
787 if LibraryPath
not in self
.LibraryInstances
:
788 self
.LibraryInstances
.append(LibraryPath
)
790 # get module private PCD setting
791 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
792 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
793 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
794 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
795 TokenList
= GetSplitValueList(Setting
)
796 DefaultValue
= TokenList
[0]
797 # the format is PcdName| Value | VOID* | MaxDatumSize
798 if len(TokenList
) > 2:
799 MaxDatumSize
= TokenList
[2]
802 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
803 Pcd
= PcdClassObject(
815 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
817 # get module private build options
818 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
819 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
820 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
821 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
823 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
824 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
826 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
828 if len(RecordList
) != 1:
829 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
830 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
831 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
832 ModuleFile
.Arch
= self
._Arch
834 self
._Modules
[ModuleFile
] = Module
837 ## Retrieve all possible library instances used in this platform
839 def LibraryInstances(self
):
840 if self
._LibraryInstances
is None:
842 return self
._LibraryInstances
844 ## Retrieve [LibraryClasses] information
846 def LibraryClasses(self
):
847 if self
._LibraryClasses
is None:
848 self
._LibraryInstances
= []
850 # tdict is a special dict kind of type, used for selecting correct
851 # library instance for given library class and module type
853 LibraryClassDict
= tdict(True, 3)
854 # track all library class names
855 LibraryClassSet
= set()
856 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
857 Macros
= self
._Macros
858 for Record
in RecordList
:
859 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
860 if LibraryClass
== '' or LibraryClass
== 'NULL':
861 self
._NullLibraryNumber
+= 1
862 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
863 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
864 LibraryClassSet
.add(LibraryClass
)
865 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
866 # check the file validation
867 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
869 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
872 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
873 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
874 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
875 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
876 if LibraryInstance
not in self
._LibraryInstances
:
877 self
._LibraryInstances
.append(LibraryInstance
)
879 # resolve the specific library instance for each class and each module type
880 self
._LibraryClasses
= tdict(True)
881 for LibraryClass
in LibraryClassSet
:
882 # try all possible module types
883 for ModuleType
in SUP_MODULE_LIST
:
884 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
885 if LibraryInstance
is None:
887 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
889 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
890 for Record
in RecordList
:
891 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
893 # check the file validation
894 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
896 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
898 if File
not in self
._LibraryInstances
:
899 self
._LibraryInstances
.append(File
)
901 # we need the module name as the library class name, so we have
902 # to parse it here. (self._Bdb[] will trigger a file parse if it
903 # hasn't been parsed)
905 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
906 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
907 return self
._LibraryClasses
909 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
910 if not self
._DecPcds
:
913 if GlobalData
.gFdfParser
:
914 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
917 for Inf
in FdfInfList
:
918 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
919 if ModuleFile
in self
._Modules
:
921 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
922 PkgSet
.update(ModuleData
.Packages
)
924 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
925 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
927 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
928 EdkLogger
.error('build', PARSER_ERROR
,
929 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
930 File
=self
.MetaFile
, Line
=LineNo
)
931 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
933 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
934 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
935 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
937 if ValueList
[2] == '-1':
938 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
939 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
941 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
942 if "{CODE(" not in ValueList
[Index
]:
944 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
945 except BadExpression
as Value
:
946 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
947 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
948 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
949 except EvaluationException
as Excpt
:
950 if hasattr(Excpt
, 'Pcd'):
951 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
952 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
953 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
954 " of the DSC file" % Excpt
.Pcd
,
955 File
=self
.MetaFile
, Line
=LineNo
)
957 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
958 File
=self
.MetaFile
, Line
=LineNo
)
960 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
961 File
=self
.MetaFile
, Line
=LineNo
)
964 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
966 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
967 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
968 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
969 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
970 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
,
971 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
972 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
973 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
974 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
977 def _FilterPcdBySkuUsage(self
, Pcds
):
978 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
979 sku_usage
= self
.SkuIdMgr
.SkuUsageType
980 if sku_usage
== SkuClass
.SINGLE
:
983 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
984 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
985 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
989 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
990 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
991 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
994 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
995 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
]]]
996 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
998 for skuid
in pcd
.SkuInfoList
:
999 skuobj
= pcd
.SkuInfoList
.get(skuid
)
1000 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
1001 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
1002 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1003 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
1006 def RecoverCommandLinePcd(self
):
1007 def UpdateCommandLineValue(pcd
):
1008 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1009 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1010 pcd
.PcdValueFromComm
= pcd
.DefaultValue
1011 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1012 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
1014 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
1015 for pcd
in self
._Pcds
:
1016 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
1017 UpdateCommandLineValue(self
._Pcds
[pcd
])
1019 def __ParsePcdFromCommandLine(self
):
1020 if GlobalData
.BuildOptionPcd
:
1021 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
1022 if isinstance(pcd
, tuple):
1024 (pcdname
, pcdvalue
) = pcd
.split('=')
1026 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1028 (Name1
, Name2
) = pcdname
.split('.', 1)
1030 (Name3
, FieldName
) = Name2
.split(".", 1)
1031 if ((Name3
, Name1
)) in self
.DecPcds
:
1032 HasTokenSpace
= True
1034 TokenSpaceGuidCName
= Name1
1038 TokenSpaceGuidCName
= ''
1039 HasTokenSpace
= False
1041 if ((Name2
, Name1
)) in self
.DecPcds
:
1042 HasTokenSpace
= True
1044 TokenSpaceGuidCName
= Name1
1049 TokenSpaceGuidCName
= ''
1050 HasTokenSpace
= False
1053 TokenCName
= pcdname
1054 TokenSpaceGuidCName
= ''
1055 HasTokenSpace
= False
1056 TokenSpaceGuidCNameList
= []
1059 DisplayName
= TokenCName
1061 DisplayName
= TokenCName
+ '.' + FieldName
1062 if not HasTokenSpace
:
1063 for key
in self
.DecPcds
:
1064 PcdItem
= self
.DecPcds
[key
]
1065 if TokenCName
== PcdItem
.TokenCName
:
1066 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1067 if len (TokenSpaceGuidCNameList
) < 1:
1068 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1069 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1070 PcdDatumType
= PcdItem
.DatumType
1076 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1079 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1080 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1084 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1086 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1087 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1089 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1091 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1092 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1094 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1095 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1097 if GlobalData
.BuildOptionPcd
:
1098 for pcd
in GlobalData
.BuildOptionPcd
:
1099 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1100 for BuildData
in self
._Bdb
._CACHE
_.values():
1101 if BuildData
.Arch
!= self
.Arch
:
1103 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1105 for key
in BuildData
.Pcds
:
1106 PcdItem
= BuildData
.Pcds
[key
]
1107 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1108 PcdItem
.DefaultValue
= pcdvalue
1109 PcdItem
.PcdValueFromComm
= pcdvalue
1110 #In command line, the latter full assign value in commandLine should override the former field assign value.
1111 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1114 if GlobalData
.BuildOptionPcd
:
1115 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1116 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1118 if (TokenSpaceGuid
, Token
) not in field_assign
:
1119 field_assign
[TokenSpaceGuid
, Token
] = []
1120 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1122 if (TokenSpaceGuid
, Token
) in field_assign
:
1123 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1124 field_assign
[TokenSpaceGuid
, Token
] = []
1125 for item
in delete_assign
:
1126 GlobalData
.BuildOptionPcd
.remove(item
)
1129 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1132 TokenCName
+= '.' + FieldName
1133 if PcdValue
.startswith('H'):
1134 if FieldName
and _IsFieldValueAnArray(PcdValue
[1:]):
1135 PcdDatumType
= TAB_VOID
1137 if FieldName
and not IsArray
:
1140 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1141 except BadExpression
as Value
:
1142 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1143 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1144 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1145 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1146 PcdDatumType
= TAB_VOID
1148 if FieldName
and not IsArray
:
1151 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1152 except BadExpression
as Value
:
1153 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1154 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1155 elif PcdValue
.startswith('L'):
1156 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1157 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1158 PcdDatumType
= TAB_VOID
1160 if FieldName
and not IsArray
:
1163 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1164 except BadExpression
as Value
:
1165 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1166 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1168 if PcdValue
.upper() == 'FALSE':
1170 if PcdValue
.upper() == 'TRUE':
1173 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1174 PcdValue
= '"' + PcdValue
+ '"'
1175 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1176 PcdValue
= '"' + PcdValue
+ '"'
1180 if PcdValue
.upper().startswith('0X'):
1183 Num
= int(PcdValue
, Base
)
1185 PcdValue
= '"' + PcdValue
+ '"'
1186 if _IsFieldValueAnArray(PcdValue
):
1187 PcdDatumType
= TAB_VOID
1192 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1193 except BadExpression
as Value
:
1194 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1195 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1198 ## Retrieve all PCD settings in platform
1201 if self
._Pcds
is None:
1202 self
._Pcds
= OrderedDict()
1203 self
.__ParsePcdFromCommandLine
()
1204 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1205 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1206 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1207 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1208 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1209 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1210 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1211 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1212 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1214 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1215 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1216 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1217 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1218 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1219 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1221 self
.RecoverCommandLinePcd()
1224 ## Retrieve [BuildOptions]
1226 def BuildOptions(self
):
1227 if self
._BuildOptions
is None:
1228 self
._BuildOptions
= OrderedDict()
1230 # Retrieve build option for EDKII and EDK style module
1232 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1233 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1234 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1235 if Dummy3
.upper() != TAB_COMMON
:
1237 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1239 # Only flags can be appended
1241 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1242 self
._BuildOptions
[CurKey
] = Option
1244 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1245 self
._BuildOptions
[CurKey
] += ' ' + Option
1246 return self
._BuildOptions
1248 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1249 if self
._ModuleTypeOptions
is None:
1250 self
._ModuleTypeOptions
= OrderedDict()
1251 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1252 options
= OrderedDict()
1253 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1254 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1255 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1256 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1257 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1258 Type
= Dummy2
+ '.' + Dummy3
1259 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1260 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1261 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1262 options
[Key
] = Option
1264 if ' ' + Option
not in options
[Key
]:
1265 options
[Key
] += ' ' + Option
1266 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1269 def GetStructurePcdInfo(PcdSet
):
1270 structure_pcd_data
= defaultdict(list)
1272 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1274 return structure_pcd_data
1277 def OverrideByFdf(StruPcds
,workspace
):
1278 if GlobalData
.gFdfParser
is None:
1280 StructurePcdInFdf
= OrderedDict()
1281 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1282 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1283 for item
in fdfpcd
:
1284 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1285 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1286 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1287 for Pcd
in StruPcds
.values():
1288 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1290 FieldValues
= OrderedDict()
1291 for item
in StructurePcdInFdf
:
1292 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1293 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1294 for field
in FieldValues
:
1295 if field
not in Pcd
.PcdFieldValueFromFdf
:
1296 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1297 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1298 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1299 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1304 def OverrideByComm(StruPcds
):
1305 StructurePcdInCom
= OrderedDict()
1306 for item
in GlobalData
.BuildOptionPcd
:
1307 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1308 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1309 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1310 for Pcd
in StruPcds
.values():
1311 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1313 FieldValues
= OrderedDict()
1314 for item
in StructurePcdInCom
:
1315 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1316 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1317 for field
in FieldValues
:
1318 if field
not in Pcd
.PcdFieldValueFromComm
:
1319 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1320 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1321 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1322 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1325 def OverrideByCommOverAll(self
,AllPcds
):
1326 def CheckStructureInComm(commpcds
):
1329 if len(commpcds
[0]) == 5:
1332 NoFiledValues
= OrderedDict()
1333 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1334 StructurePcdInCom
= OrderedDict()
1335 for item
in GlobalData
.BuildOptionPcd
:
1336 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1337 for item
in StructurePcdInCom
:
1339 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1341 for item
in GlobalData
.BuildOptionPcd
:
1342 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1343 for Guid
, Name
in NoFiledValues
:
1344 if (Name
, Guid
) in AllPcds
:
1345 Pcd
= AllPcds
.get((Name
, Guid
))
1346 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1347 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1349 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1350 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1351 for sku
in Pcd
.SkuInfoList
:
1352 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1353 if SkuInfo
.DefaultValue
:
1354 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1356 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1357 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1358 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1359 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1360 if Pcd
.DatumType
== TAB_VOID
:
1361 if not Pcd
.MaxDatumSize
:
1362 Pcd
.MaxDatumSize
= '0'
1363 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1364 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1365 MaxSize
= max(CurrentSize
, OptionSize
)
1366 Pcd
.MaxDatumSize
= str(MaxSize
)
1368 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1370 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1371 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1372 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1373 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1374 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1375 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1376 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1377 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1378 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1379 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1380 self
.Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1383 def OverrideByFdfOverAll(self
,AllPcds
):
1385 if GlobalData
.gFdfParser
is None:
1387 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1388 for Name
,Guid
,Field
in NoFiledValues
:
1391 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1392 if (Name
,Guid
) in AllPcds
:
1393 Pcd
= AllPcds
.get((Name
,Guid
))
1394 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1395 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1397 Pcd
.PcdValueFromComm
= Value
1398 Pcd
.DefaultValue
= Value
1399 for sku
in Pcd
.SkuInfoList
:
1400 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1401 if SkuInfo
.DefaultValue
:
1402 SkuInfo
.DefaultValue
= Value
1404 SkuInfo
.HiiDefaultValue
= Value
1405 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1406 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1407 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1408 if Pcd
.DatumType
== TAB_VOID
:
1409 if not Pcd
.MaxDatumSize
:
1410 Pcd
.MaxDatumSize
= '0'
1411 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1412 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1413 MaxSize
= max(CurrentSize
, OptionSize
)
1414 Pcd
.MaxDatumSize
= str(MaxSize
)
1416 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1418 PcdInDec
.PcdValueFromFdf
= Value
1419 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1420 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1421 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1422 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1423 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
1426 def ParsePcdNameStruct(self
,NamePart1
,NamePart2
):
1427 TokenSpaceCName
= PcdCName
= DimensionAttr
= Field
= ""
1428 if "." in NamePart1
:
1429 TokenSpaceCName
, TempPcdCName
= NamePart1
.split(".")
1430 if "[" in TempPcdCName
:
1431 PcdCName
= TempPcdCName
[:TempPcdCName
.index("[")]
1432 DimensionAttr
= TempPcdCName
[TempPcdCName
.index("["):]
1434 PcdCName
= TempPcdCName
1437 TokenSpaceCName
= NamePart1
1438 if "[" in NamePart2
:
1439 PcdCName
= NamePart2
[:NamePart2
.index("[")]
1440 DimensionAttr
= NamePart2
[NamePart2
.index("["):]
1442 PcdCName
= NamePart2
1444 return TokenSpaceCName
,PcdCName
,DimensionAttr
,Field
1446 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1448 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1449 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1450 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1451 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1452 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1453 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1456 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1457 SkuIds
= self
.SkuIds
1458 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1459 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1460 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1463 # Find out all possible PCD candidates for self._Arch
1466 for Type
in TypeList
:
1467 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1469 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1470 SkuName
= SkuName
.upper()
1471 default_store
= default_store
.upper()
1472 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1473 if SkuName
not in SkuIds
:
1475 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
1476 pcd_in_dec
= self
._DecPcds
.get((PCName
,TCName
), None)
1477 if pcd_in_dec
is None:
1478 EdkLogger
.error('build', PARSER_ERROR
,
1479 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1480 File
=self
.MetaFile
, Line
= Dummy5
)
1481 if SkuName
in SkuIds
and ("." in TokenSpaceGuid
or "[" in PcdCName
):
1482 if not isinstance (pcd_in_dec
, StructurePcd
):
1483 EdkLogger
.error('build', PARSER_ERROR
,
1484 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1485 File
=self
.MetaFile
, Line
= Dummy5
)
1487 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1489 # handle pcd value override
1490 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1491 S_pcd_set
= OrderedDict()
1492 for str_pcd
in StrPcdSet
:
1493 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1494 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1495 str_pcd_obj_str
= StructurePcd()
1496 str_pcd_obj_str
.copy(str_pcd_dec
)
1498 str_pcd_obj_str
.copy(str_pcd_obj
)
1499 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1500 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
}
1502 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
}
1503 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1504 if str_pcd_data
[4] in SkuIds
:
1505 str_pcd_obj_str
.AddOverrideValue(str_pcd_data
[3], str(str_pcd_data
[7]), TAB_DEFAULT
if str_pcd_data
[4] == TAB_COMMON
else str_pcd_data
[4], TAB_DEFAULT_STORES_DEFAULT
if str_pcd_data
[5] == TAB_COMMON
else str_pcd_data
[5], self
.MetaFile
.File
if self
.WorkspaceDir
not in self
.MetaFile
.File
else self
.MetaFile
.File
[len(self
.WorkspaceDir
) if self
.WorkspaceDir
.endswith(os
.path
.sep
) else len(self
.WorkspaceDir
)+1:], LineNo
=str_pcd_data
[6],DimensionAttr
= str_pcd_data
[2])
1506 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1508 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1509 for Pcd
in self
.DecPcds
:
1510 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1511 if Pcd
not in S_pcd_set
:
1512 str_pcd_obj_str
= StructurePcd()
1513 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1514 str_pcd_obj
= Pcds
.get(Pcd
, None)
1516 str_pcd_obj_str
.copy(str_pcd_obj
)
1517 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1518 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
}
1520 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
}
1521 S_pcd_set
[Pcd
] = str_pcd_obj_str
1522 self
.FilterStrcturePcd(S_pcd_set
)
1524 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1525 for stru_pcd
in S_pcd_set
.values():
1526 for skuid
in SkuIds
:
1527 if skuid
in stru_pcd
.SkuOverrideValues
:
1529 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1531 if skuid
not in stru_pcd
.SkuOverrideValues
:
1532 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1533 if nextskuid
== TAB_DEFAULT
:
1536 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1537 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})
1539 stru_pcd
.ValueChain
.add((skuid
, ''))
1540 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1541 for skuid
in SkuIds
:
1544 if skuid
not in stru_pcd
.SkuOverrideValues
:
1545 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1546 if nextskuid
== TAB_DEFAULT
:
1549 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1552 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1553 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1555 for defaultstoreid
in DefaultStores
:
1556 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1557 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = CopyDict(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1558 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1559 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1560 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1561 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1563 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1564 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1565 if str_pcd_obj
is None:
1566 print(PcdName
, PcdGuid
)
1568 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1569 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1570 if skuname
not in str_pcd_obj
.SkuInfoList
:
1571 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1573 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1574 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1575 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1576 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1577 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1578 str_pcd_obj
.DefaultValue
= PcdValue
1580 if skuname
not in str_pcd_obj
.SkuInfoList
:
1581 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1583 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1584 if nextskuid
== TAB_DEFAULT
:
1587 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1588 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
)
1589 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1590 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1592 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1593 for str_pcd_obj
in S_pcd_set
.values():
1594 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1595 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1597 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1598 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1599 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1600 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1602 for str_pcd_obj
in S_pcd_set
.values():
1604 str_pcd_obj
.MaxDatumSize
= DscBuildData
.GetStructurePcdMaxSize(str_pcd_obj
)
1605 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1606 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1610 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1611 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1612 del pcd
.SkuInfoList
[TAB_COMMON
]
1613 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1614 del pcd
.SkuInfoList
[TAB_COMMON
]
1616 list((self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
]))
1619 def PlatformUsedPcds(self
):
1621 if GlobalData
.gFdfParser
:
1622 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1623 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1624 AllModulePcds
= set()
1625 ModuleSet
= set(list(self
._Modules
.keys()) + FdfModuleList
)
1626 for ModuleFile
in ModuleSet
:
1627 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1628 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1629 for ModuleFile
in self
.LibraryInstances
:
1630 ModuleData
= self
._Bdb
.CreateBuildObject(ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
)
1631 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1632 return AllModulePcds
1634 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1635 def FilterStrcturePcd(self
, S_pcd_set
):
1636 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.PlatformUsedPcds
1637 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1638 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1640 ## Retrieve non-dynamic PCD settings
1642 # @param Type PCD type
1644 # @retval a dict object contains settings of given PCD type
1646 def _GetPcd(self
, Type
):
1647 Pcds
= OrderedDict()
1649 # tdict is a special dict kind of type, used for selecting correct
1650 # PCD settings for certain ARCH
1652 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1654 PcdDict
= tdict(True, 4)
1656 # Find out all possible PCD candidates for self._Arch
1657 RecordList
= self
._RawData
[Type
, self
._Arch
]
1658 PcdValueDict
= OrderedDict()
1659 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1660 SkuName
= SkuName
.upper()
1661 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1662 if SkuName
not in AvailableSkuIdSet
:
1663 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1664 File
=self
.MetaFile
, Line
=Dummy5
)
1665 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1666 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
1667 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1668 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1670 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1671 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1674 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1676 if int(MaxDatumSize
, 0) > 0xFFFF:
1677 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1678 File
=self
.MetaFile
, Line
=Dummy4
)
1679 if int(MaxDatumSize
, 0) < 0:
1680 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1681 File
=self
.MetaFile
, Line
=Dummy4
)
1682 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1683 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1685 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1687 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.items():
1688 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1689 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1690 elif TAB_DEFAULT
in PcdSetting
:
1691 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_DEFAULT
]
1692 elif TAB_COMMON
in PcdSetting
:
1693 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_COMMON
]
1699 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1702 self
._PCD
_TYPE
_STRING
_[Type
],
1711 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1712 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1713 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1714 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1715 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1719 def GetStructurePcdMaxSize(str_pcd
):
1720 pcd_default_value
= str_pcd
.DefaultValue
1721 sku_values
= [skuobj
.HiiDefaultValue
if str_pcd
.Type
in [DscBuildData
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], DscBuildData
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]] else skuobj
.DefaultValue
for skuobj
in str_pcd
.SkuInfoList
.values()]
1722 sku_values
.append(pcd_default_value
)
1724 def get_length(value
):
1725 Value
= value
.strip()
1727 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1729 if Value
.startswith('L"') and Value
.endswith('"'):
1730 return len(Value
[2:-1])
1731 if Value
[0] == '"' and Value
[-1] == '"':
1732 return len(Value
) - 2
1733 if Value
.strip().startswith("{CODE("):
1734 tmpValue
= RemoveCComments(Value
)
1735 return len(tmpValue
.split(","))
1736 if (Value
[0] == '{' and Value
[-1] == '}'):
1737 return len(Value
.split(","))
1738 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1739 return len(list(Value
[2:-1]))
1740 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1741 return len(Value
) - 2
1744 return str(max(get_length(item
) for item
in sku_values
))
1747 def ExecuteCommand (Command
):
1749 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1751 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1752 Result
= Process
.communicate()
1753 return Process
.returncode
, Result
[0].decode(encoding
='utf-8', errors
='ignore'), Result
[1].decode(encoding
='utf-8', errors
='ignore')
1756 def IntToCString(Value
, ValueSize
):
1758 if not isinstance (Value
, str):
1759 for Index
in range(0, ValueSize
):
1760 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1762 Result
= Result
+ '"'
1765 def GenerateSizeFunction(self
, Pcd
):
1766 CApp
= "// Default Value in Dec \n"
1767 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1769 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
1770 for skuname
in Pcd
.SkuInfoList
:
1771 skuobj
= Pcd
.SkuInfoList
[skuname
]
1772 if skuobj
.VariableName
:
1773 for defaultstore
in skuobj
.DefaultStoreDict
:
1774 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,defaultstore
)
1775 if pcddef
and "{CODE(" in pcddef
:
1776 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
)
1778 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1779 if pcddef
and "{CODE(" in pcddef
:
1780 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1782 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1783 if pcddef
and "{CODE(" in pcddef
:
1784 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1785 for index
in Pcd
.DefaultValues
:
1786 FieldList
= Pcd
.DefaultValues
[index
]
1789 for FieldName
in FieldList
:
1790 FieldName
= "." + FieldName
1791 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1792 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1794 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1795 except BadExpression
:
1796 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1797 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1798 Value
, ValueSize
= ParseFieldValue(Value
)
1799 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]);
1802 FieldName_ori
= FieldName
.strip('.')
1803 while '[' in FieldName
:
1804 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1805 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1806 FieldName
= FieldName
.split(']', 1)[1]
1807 FieldName
= NewFieldName
+ FieldName
1808 while '[' in FieldName
:
1809 FieldName
= FieldName
.rsplit('[', 1)[0]
1810 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])
1811 for skuname
in Pcd
.SkuOverrideValues
:
1812 if skuname
== TAB_COMMON
:
1814 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1815 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1816 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1817 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1820 for FieldName
in FieldList
:
1821 FieldName
= "." + FieldName
1822 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1823 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1825 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1826 except BadExpression
:
1827 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1828 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1829 Value
, ValueSize
= ParseFieldValue(Value
)
1830 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]);
1833 FieldName_ori
= FieldName
.strip('.')
1834 while '[' in FieldName
:
1835 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1836 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1837 FieldName
= FieldName
.split(']', 1)[1]
1838 FieldName
= NewFieldName
+ FieldName
1839 while '[' in FieldName
:
1840 FieldName
= FieldName
.rsplit('[', 1)[0]
1841 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])
1842 if Pcd
.PcdFieldValueFromFdf
:
1843 CApp
= CApp
+ "// From fdf \n"
1844 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1845 FieldName
= "." + FieldName
1846 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1847 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1849 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1850 except BadExpression
:
1851 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1852 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1853 Value
, ValueSize
= ParseFieldValue(Value
)
1854 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]);
1857 FieldName_ori
= FieldName
.strip('.')
1858 while '[' in FieldName
:
1859 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1860 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1861 FieldName
= FieldName
.split(']', 1)[1]
1862 FieldName
= NewFieldName
+ FieldName
1863 while '[' in FieldName
:
1864 FieldName
= FieldName
.rsplit('[', 1)[0]
1865 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])
1866 if Pcd
.PcdFieldValueFromComm
:
1867 CApp
= CApp
+ "// From Command Line \n"
1868 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1869 FieldName
= "." + FieldName
1870 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1871 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1873 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1874 except BadExpression
:
1875 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1876 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1877 Value
, ValueSize
= ParseFieldValue(Value
)
1878 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]);
1881 FieldName_ori
= FieldName
.strip('.')
1882 while '[' in FieldName
:
1883 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1884 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1885 FieldName
= FieldName
.split(']', 1)[1]
1886 FieldName
= NewFieldName
+ FieldName
1887 while '[' in FieldName
:
1888 FieldName
= FieldName
.rsplit('[', 1)[0]
1889 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])
1890 if Pcd
.GetPcdMaxSize():
1891 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1896 def GenerateSizeStatments(Pcd
,skuname
,defaultstorename
):
1898 r_datatype
= [Pcd
.BaseDatumType
]
1899 lastoneisEmpty
= False
1900 for dem
in Pcd
.Capacity
:
1902 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. " %
1903 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))))
1904 if dem
== '0' or dem
== "-1":
1905 r_datatype
.append("[1]")
1906 lastoneisEmpty
= True
1908 r_datatype
.append("[" + dem
+ "]")
1910 if Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_HII
, MODEL_PCD_DYNAMIC_HII
]:
1911 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultStoreDict
.get(defaultstorename
)
1912 elif Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_DEFAULT
,MODEL_PCD_DYNAMIC_VPD
,MODEL_PCD_DYNAMIC_DEFAULT
,MODEL_PCD_DYNAMIC_EX_VPD
]:
1913 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultValue
1915 PcdDefValue
= Pcd
.DefaultValue
1917 if "{CODE(" not in PcdDefValue
:
1918 sizebasevalue_plus
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), "".join(r_datatype
)))
1919 sizebasevalue
= "(%s / sizeof(%s))" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), "".join(r_datatype
)))
1920 sizeof
= "sizeof(%s)" % Pcd
.BaseDatumType
1921 CApp
= ' Size = %s %% %s ? %s : %s ;\n' % ( (DscBuildData
.GetStructurePcdMaxSize(Pcd
), sizeof
, sizebasevalue_plus
, sizebasevalue
))
1923 CApp
= " Size = 0;\n"
1925 CApp
= ' Size = sizeof(%s);\n' % ("".join(r_datatype
) )
1927 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1928 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1931 def GetIndicator(self
,index
,FieldName
,Pcd
):
1932 def cleanupindex(indexstr
):
1933 return indexstr
.strip("[").strip("]").strip()
1934 index_elements
= ArrayIndex
.findall(index
)
1935 pcd_capacity
= Pcd
.Capacity
1938 if len(pcd_capacity
)>2:
1939 for i
in range(0,len(index_elements
)):
1940 index_ele
= index_elements
[i
]
1941 index_num
= index_ele
.strip("[").strip("]").strip()
1942 if i
== len(index_elements
) -2:
1943 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[i
+1])),Pcd
.BaseDatumType
,reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[:-1]), cleanupindex(index_elements
[i
]))
1946 indicator
+= " + %d*%s*Size/sizeof(%s)/%d" %(int(cleanupindex(index_elements
[i
])),reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[i
+1:-1]),Pcd
.BaseDatumType
,reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[:-1]))
1947 elif len(pcd_capacity
) == 2:
1948 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
1949 elif len(pcd_capacity
) == 1:
1950 index_ele
= index_elements
[0]
1951 index_num
= index_ele
.strip("[").strip("]").strip()
1952 indicator
+= " + %s)" % (index_num
)
1956 indicator
+= "->" + FieldName
1959 def GetStarNum(self
,Pcd
):
1960 if not Pcd
.IsArray():
1962 elif Pcd
.IsSimpleTypeArray():
1963 return len(Pcd
.Capacity
)
1965 return len(Pcd
.Capacity
) + 1
1966 def GenerateDefaultValueAssignFunction(self
, Pcd
):
1967 CApp
= "// Default value in Dec \n"
1968 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
1969 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1970 CApp
= CApp
+ ' CHAR8 *Value;\n'
1971 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1972 IsArray
= _IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1975 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1976 except BadExpression
:
1977 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1978 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1979 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1980 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1981 if isinstance(Value
, str):
1982 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1985 # Use memcpy() to copy value into field
1987 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1988 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value, sizeof(%s_%s_INIT_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1990 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1991 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1992 for index
in Pcd
.DefaultValues
:
1993 FieldList
= Pcd
.DefaultValues
[index
]
1996 for FieldName
in FieldList
:
1997 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2000 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2001 except BadExpression
:
2002 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2003 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2006 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2008 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]))
2010 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2011 if isinstance(Value
, str):
2012 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2015 # Use memcpy() to copy value into field
2017 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
2018 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2019 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])
2020 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2021 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2024 if '[' in FieldName
and ']' in FieldName
:
2025 Index
= int(FieldName
.split('[')[1].split(']')[0])
2026 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
)
2028 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2030 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2035 def GenerateDefaultValueAssignStatement(Pcd
):
2036 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2039 def GetPcdDscRawDefaultValue(self
,Pcd
, SkuName
,DefaultStoreName
):
2040 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2041 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2042 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2044 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2046 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2048 return pcddefaultvalue
2049 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
2050 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
2051 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
2052 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2053 CApp
= CApp
+ ' CHAR8 *Value;\n'
2055 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2056 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2058 pcddefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, SkuName
, DefaultStoreName
)
2060 FieldList
= pcddefaultvalue
2061 IsArray
= _IsFieldValueAnArray(FieldList
)
2063 if "{CODE(" not in FieldList
:
2065 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2066 except BadExpression
:
2067 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2068 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2069 Value
, ValueSize
= ParseFieldValue (FieldList
)
2071 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2072 if isinstance(Value
, str):
2073 if "{CODE(" in Value
:
2074 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2076 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
)
2079 # Use memcpy() to copy value into field
2081 if Pcd
.IsArray() and "{CODE(" in pcddefaultvalue
:
2082 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2084 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
)
2085 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2087 if isinstance(Value
, str):
2088 if "{CODE(" in Value
:
2089 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2091 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2094 # Use memcpy() to copy value into field
2096 if Pcd
.IsArray() and "{CODE(" in pcddefaultvalue
:
2097 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2099 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2100 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2102 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2103 if not inheritvalue
:
2105 for index
in inheritvalue
:
2106 FieldList
= inheritvalue
[index
]
2109 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2110 for FieldName
in FieldList
:
2111 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2112 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2115 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2116 except BadExpression
:
2117 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2118 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2120 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2122 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]))
2123 if isinstance(Value
, str):
2124 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2127 # Use memcpy() to copy value into field
2129 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2130 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2131 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])
2132 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2133 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2135 if '[' in FieldName
and ']' in FieldName
:
2136 Index
= int(FieldName
.split('[')[1].split(']')[0])
2137 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
)
2139 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2141 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2146 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2147 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2150 def GenerateCommandLineValue(self
, Pcd
):
2151 CApp
= "// Value in CommandLine\n"
2152 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2153 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2154 CApp
= CApp
+ ' CHAR8 *Value;\n'
2156 pcddefaultvalue
= Pcd
.PcdValueFromComm
2157 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2160 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2161 IsArray
= _IsFieldValueAnArray(FieldList
)
2164 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2165 except BadExpression
:
2166 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2167 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2168 Value
, ValueSize
= ParseFieldValue (FieldList
)
2170 if isinstance(Value
, str):
2171 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2174 # Use memcpy() to copy value into field
2176 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2177 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2179 for FieldName
in FieldList
:
2180 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2183 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2184 except BadExpression
:
2185 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2186 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2190 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2192 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]))
2193 if isinstance(Value
, str):
2194 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2197 # Use memcpy() to copy value into field
2199 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2200 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2201 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])
2202 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2204 if '[' in FieldName
and ']' in FieldName
:
2205 Index
= int(FieldName
.split('[')[1].split(']')[0])
2206 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
)
2208 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2210 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2215 def GenerateCommandLineValueStatement(Pcd
):
2216 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2218 def GenerateFdfValue(self
,Pcd
):
2219 CApp
= "// Value in Fdf\n"
2220 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2221 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2222 CApp
= CApp
+ ' CHAR8 *Value;\n'
2224 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2225 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2228 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2229 IsArray
= _IsFieldValueAnArray(FieldList
)
2232 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2233 except BadExpression
:
2234 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2235 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2236 Value
, ValueSize
= ParseFieldValue (FieldList
)
2238 if isinstance(Value
, str):
2239 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2242 # Use memcpy() to copy value into field
2244 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2245 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2247 for FieldName
in FieldList
:
2248 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2251 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2252 except BadExpression
:
2253 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2254 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2258 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2260 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]))
2261 if isinstance(Value
, str):
2262 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2265 # Use memcpy() to copy value into field
2267 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2268 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2269 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])
2270 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2272 if '[' in FieldName
and ']' in FieldName
:
2273 Index
= int(FieldName
.split('[')[1].split(']')[0])
2274 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
)
2276 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2278 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2283 def GenerateFdfValueStatement(Pcd
):
2284 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2287 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2288 OverrideValues
= {DefaultStore
:{}}
2289 if Pcd
.SkuOverrideValues
:
2290 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2291 if not OverrideValues
:
2292 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2293 for DefaultStoreName
in OverrideValues
:
2294 CApp
= CApp
+ 'void\n'
2295 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2296 CApp
= CApp
+ ' void\n'
2297 CApp
= CApp
+ ' )\n'
2299 CApp
= CApp
+ ' UINT32 Size;\n'
2300 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2301 CApp
= CApp
+ ' CHAR8 *Value;\n'
2302 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2303 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2305 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2309 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2311 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2314 # Get current PCD value and size
2316 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2319 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2320 # the correct value. For structures with a flexible array member, the flexible
2321 # array member is detected, and the size is based on the highest index used with
2322 # the flexible array member. The flexible array member must be the last field
2323 # in a structure. The size formula for this case is:
2324 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2326 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,DefaultStoreName
)
2329 # Allocate and zero buffer for the PCD
2330 # Must handle cases where current value is smaller, larger, or same size
2331 # Always keep that larger one as the current size
2333 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2334 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2335 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2338 # Copy current PCD value into allocated buffer.
2340 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2343 # Assign field values in PCD
2345 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2346 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2347 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2348 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2349 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2350 for defaultstorenameitem
in storeset
:
2351 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2352 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2353 if skuname
== SkuName
:
2356 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2357 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2358 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2359 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2361 # Set new PCD value and size
2363 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2368 CApp
= CApp
+ ' free (Pcd);\n'
2371 return InitByteValue
, CApp
2373 def GenerateArrayAssignment(self
, Pcd
):
2377 if not Pcd
.IsArray():
2380 for d
in Pcd
.Capacity
:
2383 Value
= Pcd
.DefaultValueFromDec
2384 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2385 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2386 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2388 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2389 for skuname
in Pcd
.SkuInfoList
:
2390 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2391 if skuinfo
.VariableName
:
2392 for defaultstore
in skuinfo
.DefaultStoreDict
:
2393 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, defaultstore
)
2394 if pcddscrawdefaultvalue
:
2395 Value
= skuinfo
[defaultstore
]
2396 if "{CODE(" in Value
:
2397 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2398 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2400 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, TAB_DEFAULT_STORES_DEFAULT
)
2401 if pcddscrawdefaultvalue
:
2402 Value
= skuinfo
.DefaultValue
2403 if "{CODE(" in Value
:
2404 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2405 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2407 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2408 if pcddscrawdefaultvalue
:
2409 if "{CODE(" in Pcd
.DefaultValue
:
2410 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2411 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2415 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2416 if not OverrideValues
:
2418 for key
in OverrideValues
:
2419 if OverrideValues
[key
]:
2423 def ParseCCFlags(self
, ccflag
):
2425 ccflaglist
= ccflag
.split(" ")
2427 while i
< len(ccflaglist
):
2428 item
= ccflaglist
[i
].strip()
2429 if item
in (r
"/D", r
"/U","-D","-U"):
2430 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2432 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2436 def GenerateByteArrayValue (self
, StructuredPcds
):
2438 # Generate/Compile/Run C application to determine if there are any flexible array members
2440 if not StructuredPcds
:
2444 CApp
= PcdMainCHeader
2446 IncludeFiles
= set()
2447 for PcdName
in StructuredPcds
:
2448 Pcd
= StructuredPcds
[PcdName
]
2449 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2450 if IncludeFile
not in IncludeFiles
:
2451 IncludeFiles
.add(IncludeFile
)
2452 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2454 for Pcd
in StructuredPcds
.values():
2455 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2456 for PcdName
in StructuredPcds
:
2457 Pcd
= StructuredPcds
[PcdName
]
2458 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2459 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2460 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2461 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2462 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2463 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2464 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2466 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2467 if SkuName
not in Pcd
.SkuOverrideValues
:
2469 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2470 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2471 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2472 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2473 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2475 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2476 if SkuName
not in Pcd
.SkuOverrideValues
:
2478 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2479 Pcd
= StructuredPcds
[PcdName
]
2480 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2482 CApp
= CApp
+ 'VOID\n'
2483 CApp
= CApp
+ 'PcdEntryPoint(\n'
2484 CApp
= CApp
+ ' VOID\n'
2485 CApp
= CApp
+ ' )\n'
2487 for Pcd
in StructuredPcds
.values():
2488 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
]]:
2489 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2491 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2492 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2494 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2495 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2498 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2500 if not os
.path
.exists(self
.OutputPath
):
2501 os
.makedirs(self
.OutputPath
)
2502 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2503 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2505 MakeApp
= PcdMakefileHeader
2506 if sys
.platform
== "win32":
2507 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2509 MakeApp
= MakeApp
+ PcdGccMakefile
2510 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2511 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2514 PlatformInc
= OrderedDict()
2515 for Cache
in self
._Bdb
._CACHE
_.values():
2516 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2519 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2520 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2521 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2522 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2525 for Pcd
in StructuredPcds
.values():
2526 for PackageDec
in Pcd
.PackageDecs
:
2527 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2528 if not os
.path
.exists(Package
):
2529 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2530 if Package
not in PcdDependDEC
:
2531 PcdDependDEC
.append(Package
)
2533 if PlatformInc
and PcdDependDEC
:
2534 for pkg
in PcdDependDEC
:
2535 if pkg
in PlatformInc
:
2536 for inc
in PlatformInc
[pkg
]:
2537 MakeApp
+= '-I' + str(inc
) + ' '
2538 IncSearchList
.append(inc
)
2539 MakeApp
= MakeApp
+ '\n'
2541 CC_FLAGS
= LinuxCFLAGS
2542 if sys
.platform
== "win32":
2543 CC_FLAGS
= WindowsCFLAGS
2544 BuildOptions
= OrderedDict()
2545 for Options
in self
.BuildOptions
:
2546 if Options
[2] != EDKII_NAME
:
2549 if Family
and Family
!= self
.ToolChainFamily
:
2551 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2556 if Target
== TAB_STAR
or Target
== self
._Target
:
2557 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2558 if 'COMMON' not in BuildOptions
:
2559 BuildOptions
['COMMON'] = set()
2560 if Arch
== TAB_STAR
:
2561 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2562 if Arch
in self
.SupArchList
:
2563 if Arch
not in BuildOptions
:
2564 BuildOptions
[Arch
] = set()
2565 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2568 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2569 if len(ArchBuildOptions
.keys()) == 1:
2570 BuildOptions
['COMMON'] |
= (list(ArchBuildOptions
.values())[0])
2571 elif len(ArchBuildOptions
.keys()) > 1:
2572 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2573 BuildOptions
['COMMON'] |
= CommonBuildOptions
2574 ValueList
= list(BuildOptions
['COMMON'])
2575 CC_FLAGS
+= " ".join(ValueList
)
2578 if sys
.platform
== "win32":
2579 MakeApp
= MakeApp
+ PcdMakefileEnd
2580 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2582 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2583 MakeApp
= MakeApp
+ '\n'
2584 IncludeFileFullPaths
= []
2585 for includefile
in IncludeFiles
:
2586 for includepath
in IncSearchList
:
2587 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2588 if os
.path
.exists(includefullpath
):
2589 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2592 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2593 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2594 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2595 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2596 for include_file
in IncFileList
:
2597 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2598 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2599 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2600 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2602 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2603 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2604 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2606 Dest_PcdValueInitExe
= PcdValueInitName
2607 if not sys
.platform
== "win32":
2608 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2610 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2612 if sys
.platform
== "win32":
2613 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2614 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2617 MakeCommand
= 'make -f %s' % (MakeFileName
)
2618 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2621 Messages
= Messages
.split('\n')
2624 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2625 File
= open (CAppBaseFileName
+ '.c', 'r')
2626 FileData
= File
.readlines()
2628 for Message
in Messages
:
2629 if " error" in Message
or "warning" in Message
:
2630 FileInfo
= Message
.strip().split('(')
2631 if len (FileInfo
) > 1:
2632 FileName
= FileInfo
[0]
2633 FileLine
= FileInfo
[1].split (')')[0]
2635 FileInfo
= Message
.strip().split(':')
2636 if len(FileInfo
) < 2:
2638 FileName
= FileInfo
[0]
2639 FileLine
= FileInfo
[1]
2640 if FileLine
.isdigit():
2641 error_line
= FileData
[int (FileLine
) - 1]
2642 if r
"//" in error_line
:
2643 c_line
, dsc_line
= error_line
.split(r
"//")
2645 dsc_line
= error_line
2646 message_itmes
= Message
.split(":")
2648 if "PcdValueInit.c" not in Message
:
2649 if not MessageGroup
:
2650 MessageGroup
.append(Message
)
2653 for item
in message_itmes
:
2654 if "PcdValueInit.c" in item
:
2655 Index
= message_itmes
.index(item
)
2656 message_itmes
[Index
] = dsc_line
.strip()
2658 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2661 MessageGroup
.append(Message
)
2663 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2665 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2667 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
2668 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2669 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2671 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2673 File
= open (OutputValueFile
, 'r')
2674 FileBuffer
= File
.readlines()
2677 StructurePcdSet
= []
2678 for Pcd
in FileBuffer
:
2679 PcdValue
= Pcd
.split ('|')
2680 PcdInfo
= PcdValue
[0].split ('.')
2681 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2682 return StructurePcdSet
2685 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2686 if not os
.path
.exists(OutputFile
):
2688 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2690 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2694 ## Retrieve dynamic PCD settings
2696 # @param Type PCD type
2698 # @retval a dict object contains settings of given PCD type
2700 def _GetDynamicPcd(self
, Type
):
2703 Pcds
= OrderedDict()
2705 # tdict is a special dict kind of type, used for selecting correct
2706 # PCD settings for certain ARCH and SKU
2708 PcdDict
= tdict(True, 4)
2710 # Find out all possible PCD candidates for self._Arch
2711 RecordList
= self
._RawData
[Type
, self
._Arch
]
2712 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2715 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2716 SkuName
= SkuName
.upper()
2717 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2718 if SkuName
not in AvailableSkuIdSet
:
2719 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2720 File
=self
.MetaFile
, Line
=Dummy5
)
2721 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2722 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2723 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2725 # Remove redundant PCD candidates, per the ARCH and SKU
2726 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2728 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2732 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2734 if int(MaxDatumSize
, 0) > 0xFFFF:
2735 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2736 File
=self
.MetaFile
, Line
=Dummy4
)
2737 if int(MaxDatumSize
, 0) < 0:
2738 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2739 File
=self
.MetaFile
, Line
=Dummy4
)
2740 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2741 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2742 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2743 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2744 if MaxDatumSize
.strip():
2745 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2748 if pcdObject
.MaxDatumSize
:
2749 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2752 if CurrentMaxSize
> PcdMaxSize
:
2753 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2755 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2758 self
._PCD
_TYPE
_STRING
_[Type
],
2763 OrderedDict({SkuName
: SkuInfo
}),
2768 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2769 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2770 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2772 for pcd
in Pcds
.values():
2773 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2774 # Only fix the value while no value provided in DSC file.
2775 for sku
in pcd
.SkuInfoList
.values():
2776 if not sku
.DefaultValue
:
2777 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2778 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2779 valuefromDec
= pcdDecObject
.DefaultValue
2780 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2781 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2782 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2783 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2784 del pcd
.SkuInfoList
[TAB_COMMON
]
2785 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2786 del pcd
.SkuInfoList
[TAB_COMMON
]
2788 list(map(self
.FilterSkuSettings
, Pcds
.values()))
2792 def FilterSkuSettings(self
, PcdObj
):
2794 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2795 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2796 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2797 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2798 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2799 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2801 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2802 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2807 def CompareVarAttr(Attr1
, Attr2
):
2808 if not Attr1
or not Attr2
: # for empty string
2810 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2811 Attr1Set
= set(Attr1s
)
2812 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2813 Attr2Set
= set(Attr2s
)
2814 if Attr2Set
== Attr1Set
:
2819 def CompletePcdValues(self
, PcdSet
):
2820 Pcds
= OrderedDict()
2821 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2822 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2823 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2824 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2825 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2827 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2828 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2829 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2830 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2831 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2832 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2833 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2835 PcdType
= PcdObj
.Type
2836 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2837 for skuid
in PcdObj
.SkuInfoList
:
2838 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2839 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2840 for defaultstorename
in DefaultStores
:
2841 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2842 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
2843 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2844 for skuname
, skuid
in SkuIds
.items():
2845 if skuname
not in PcdObj
.SkuInfoList
:
2846 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2847 while nextskuid
not in PcdObj
.SkuInfoList
:
2848 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2849 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2850 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2851 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2852 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2853 PcdObj
.DefaultValue
= list(PcdObj
.SkuInfoList
.values())[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2854 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2856 ## Retrieve dynamic HII PCD settings
2858 # @param Type PCD type
2860 # @retval a dict object contains settings of given PCD type
2862 def _GetDynamicHiiPcd(self
, Type
):
2866 Pcds
= OrderedDict()
2867 UserDefinedDefaultStores
= []
2869 # tdict is a special dict kind of type, used for selecting correct
2870 # PCD settings for certain ARCH and SKU
2872 PcdDict
= tdict(True, 5)
2874 RecordList
= self
._RawData
[Type
, self
._Arch
]
2875 # Find out all possible PCD candidates for self._Arch
2876 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2877 DefaultStoresDefine
= self
._GetDefaultStores
()
2879 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
2880 SkuName
= SkuName
.upper()
2881 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2882 DefaultStore
= DefaultStore
.upper()
2883 if DefaultStore
== TAB_COMMON
:
2884 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2886 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
2887 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
2888 if SkuName
not in AvailableSkuIdSet
:
2889 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2890 File
=self
.MetaFile
, Line
=Dummy5
)
2891 if DefaultStore
not in DefaultStoresDefine
:
2892 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2893 File
=self
.MetaFile
, Line
=Dummy5
)
2894 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2895 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
2896 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
2899 # Remove redundant PCD candidates, per the ARCH and SKU
2900 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdSet
:
2902 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
2905 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2907 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2909 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2910 ExtraData
="[%s]" % VarAttribute
)
2912 FormatCorrect
= True
2913 if VariableOffset
.isdigit():
2914 if int(VariableOffset
, 10) > 0xFFFF:
2916 elif variablePattern
.match(VariableOffset
):
2917 if int(VariableOffset
, 16) > 0xFFFF:
2919 # For Offset written in "A.B"
2920 elif VariableOffset
.find('.') > -1:
2921 VariableOffsetList
= VariableOffset
.split(".")
2922 if not (len(VariableOffsetList
) == 2
2923 and IsValidWord(VariableOffsetList
[0])
2924 and IsValidWord(VariableOffsetList
[1])):
2925 FormatCorrect
= False
2927 FormatCorrect
= False
2928 if not FormatCorrect
:
2929 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2932 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2933 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2934 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2936 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2937 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
)]))
2939 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2940 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2941 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2942 if SkuName
in pcdObject
.SkuInfoList
:
2943 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2944 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2946 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2947 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2949 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2950 PcdClassObj
= PcdClassObject(
2953 self
._PCD
_TYPE
_STRING
_[Type
],
2958 OrderedDict({SkuName
: SkuInfo
}),
2961 pcdDecObject
.validateranges
,
2962 pcdDecObject
.validlists
,
2963 pcdDecObject
.expressions
,
2965 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
2966 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
2967 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
2969 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
2970 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2971 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2972 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
2973 for pcd
in Pcds
.values():
2974 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2975 pcd
.DatumType
= pcdDecObject
.DatumType
2976 # Only fix the value while no value provided in DSC file.
2977 for sku
in pcd
.SkuInfoList
.values():
2978 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2979 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2980 for default_store
in sku
.DefaultStoreDict
:
2981 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2982 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2983 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2984 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
2985 valuefromDec
= pcdDecObject
.DefaultValue
2986 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
2987 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2988 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2989 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2990 del pcd
.SkuInfoList
[TAB_COMMON
]
2991 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2992 del pcd
.SkuInfoList
[TAB_COMMON
]
2994 if pcd
.MaxDatumSize
.strip():
2995 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2998 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
2999 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
3001 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
3002 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
3003 if datalen
> MaxSize
:
3005 for defaultst
in skuobj
.DefaultStoreDict
:
3006 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
3007 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
3008 pcd
.MaxDatumSize
= str(MaxSize
)
3009 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
3011 invalidpcd
= ",".join(invalidhii
)
3012 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
)
3014 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3019 def CheckVariableNameAssignment(Pcds
):
3021 for pcdname
in Pcds
:
3023 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
3024 if len(varnameset
) > 1:
3025 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
3027 return False, invalidhii
3030 ## Retrieve dynamic VPD PCD settings
3032 # @param Type PCD type
3034 # @retval a dict object contains settings of given PCD type
3036 def _GetDynamicVpdPcd(self
, Type
):
3039 Pcds
= OrderedDict()
3041 # tdict is a special dict kind of type, used for selecting correct
3042 # PCD settings for certain ARCH and SKU
3044 PcdDict
= tdict(True, 4)
3047 # Find out all possible PCD candidates for self._Arch
3048 RecordList
= self
._RawData
[Type
, self
._Arch
]
3049 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3051 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3052 SkuName
= SkuName
.upper()
3053 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3054 if SkuName
not in AvailableSkuIdSet
:
3055 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3056 File
=self
.MetaFile
, Line
=Dummy5
)
3057 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
3058 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3059 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3061 # Remove redundant PCD candidates, per the ARCH and SKU
3062 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3063 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3067 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3068 # For the Integer & Boolean type, the optional data can only be InitialValue.
3069 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3070 # until the DEC parser has been called.
3072 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3074 if int(MaxDatumSize
, 0) > 0xFFFF:
3075 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3076 File
=self
.MetaFile
, Line
=Dummy4
)
3077 if int(MaxDatumSize
, 0) < 0:
3078 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3079 File
=self
.MetaFile
, Line
=Dummy4
)
3080 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3081 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3082 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3083 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3084 if MaxDatumSize
.strip():
3085 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3088 if pcdObject
.MaxDatumSize
:
3089 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3092 if CurrentMaxSize
> PcdMaxSize
:
3093 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3095 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3098 self
._PCD
_TYPE
_STRING
_[Type
],
3103 OrderedDict({SkuName
: SkuInfo
}),
3108 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3109 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3110 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3111 for pcd
in Pcds
.values():
3112 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3113 pcd
.DatumType
= pcdDecObject
.DatumType
3114 # Only fix the value while no value provided in DSC file.
3115 for sku
in pcd
.SkuInfoList
.values():
3116 if not sku
.DefaultValue
:
3117 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3118 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3119 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3120 valuefromDec
= pcdDecObject
.DefaultValue
3121 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3122 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3123 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3124 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3125 del pcd
.SkuInfoList
[TAB_COMMON
]
3126 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3127 del pcd
.SkuInfoList
[TAB_COMMON
]
3129 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3130 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3131 for pcd
in Pcds
.values():
3132 PcdValueTypeSet
= set()
3133 for sku
in pcd
.SkuInfoList
.values():
3134 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3135 if len(PcdValueTypeSet
) > 1:
3136 for sku
in pcd
.SkuInfoList
.values():
3137 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3139 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3142 ## Add external modules
3144 # The external modules are mostly those listed in FDF file, which don't
3147 # @param FilePath The path of module description file
3149 def AddModule(self
, FilePath
):
3150 FilePath
= NormPath(FilePath
)
3151 if FilePath
not in self
.Modules
:
3152 Module
= ModuleBuildClassObject()
3153 Module
.MetaFile
= FilePath
3154 self
.Modules
.append(Module
)
3157 def ToolChainFamily(self
):
3158 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3159 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
3160 if os
.path
.isfile(BuildConfigurationFile
) == True:
3161 TargetTxt
= TargetTxtClassObject()
3162 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
3163 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3164 if ToolDefinitionFile
== '':
3165 ToolDefinitionFile
= "tools_def.txt"
3166 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
3167 if os
.path
.isfile(ToolDefinitionFile
) == True:
3168 ToolDef
= ToolDefClassObject()
3169 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
3170 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
3171 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3172 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3173 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3174 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3176 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3177 return self
._ToolChainFamily
3179 ## Add external PCDs
3181 # The external PCDs are mostly those listed in FDF file to specify address
3182 # or offset information.
3184 # @param Name Name of the PCD
3185 # @param Guid Token space guid of the PCD
3186 # @param Value Value of the PCD
3188 def AddPcd(self
, Name
, Guid
, Value
):
3189 if (Name
, Guid
) not in self
.Pcds
:
3190 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3191 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3195 if self
._DecPcds
is None:
3197 if GlobalData
.gFdfParser
:
3198 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3200 for Inf
in FdfInfList
:
3201 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3202 if ModuleFile
in self
._Modules
:
3204 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3205 PkgSet
.update(ModuleData
.Packages
)
3206 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3207 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3208 return self
._DecPcds