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 # (Retrieving 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
1523 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
.copy()
1524 self
.FilterStrcturePcd(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(map(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
)
1800 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]);
1803 FieldName_ori
= FieldName
.strip('.')
1804 while '[' in FieldName
:
1805 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1806 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1807 FieldName
= FieldName
.split(']', 1)[1]
1808 FieldName
= NewFieldName
+ FieldName
1809 while '[' in FieldName
and not Pcd
.IsArray
:
1810 FieldName
= FieldName
.rsplit('[', 1)[0]
1811 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])
1812 for skuname
in Pcd
.SkuOverrideValues
:
1813 if skuname
== TAB_COMMON
:
1815 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1816 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1817 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1818 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1821 for FieldName
in FieldList
:
1822 FieldName
= "." + FieldName
1823 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1824 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1826 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1827 except BadExpression
:
1828 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1829 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1830 Value
, ValueSize
= ParseFieldValue(Value
)
1832 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]);
1835 FieldName_ori
= FieldName
.strip('.')
1836 while '[' in FieldName
:
1837 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1838 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1839 FieldName
= FieldName
.split(']', 1)[1]
1840 FieldName
= NewFieldName
+ FieldName
1841 while '[' in FieldName
and not Pcd
.IsArray
:
1842 FieldName
= FieldName
.rsplit('[', 1)[0]
1843 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])
1844 if Pcd
.PcdFieldValueFromFdf
:
1845 CApp
= CApp
+ "// From fdf \n"
1846 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1847 FieldName
= "." + FieldName
1848 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1849 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1851 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1852 except BadExpression
:
1853 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1854 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1855 Value
, ValueSize
= ParseFieldValue(Value
)
1857 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]);
1860 FieldName_ori
= FieldName
.strip('.')
1861 while '[' in FieldName
:
1862 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1863 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1864 FieldName
= FieldName
.split(']', 1)[1]
1865 FieldName
= NewFieldName
+ FieldName
1866 while '[' in FieldName
:
1867 FieldName
= FieldName
.rsplit('[', 1)[0]
1868 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])
1869 if Pcd
.PcdFieldValueFromComm
:
1870 CApp
= CApp
+ "// From Command Line \n"
1871 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1872 FieldName
= "." + FieldName
1873 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1874 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1876 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1877 except BadExpression
:
1878 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1879 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1880 Value
, ValueSize
= ParseFieldValue(Value
)
1882 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]);
1885 FieldName_ori
= FieldName
.strip('.')
1886 while '[' in FieldName
:
1887 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1888 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1889 FieldName
= FieldName
.split(']', 1)[1]
1890 FieldName
= NewFieldName
+ FieldName
1891 while '[' in FieldName
and not Pcd
.IsArray
:
1892 FieldName
= FieldName
.rsplit('[', 1)[0]
1893 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])
1894 if Pcd
.GetPcdMaxSize():
1895 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1900 def GenerateSizeStatments(Pcd
,skuname
,defaultstorename
):
1902 r_datatype
= [Pcd
.BaseDatumType
]
1903 lastoneisEmpty
= False
1904 for dem
in Pcd
.Capacity
:
1906 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. " %
1907 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))))
1908 if dem
== '0' or dem
== "-1":
1909 r_datatype
.append("[1]")
1910 lastoneisEmpty
= True
1912 r_datatype
.append("[" + dem
+ "]")
1914 if Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_HII
, MODEL_PCD_DYNAMIC_HII
]:
1915 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultStoreDict
.get(defaultstorename
)
1916 elif Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_DEFAULT
,MODEL_PCD_DYNAMIC_VPD
,MODEL_PCD_DYNAMIC_DEFAULT
,MODEL_PCD_DYNAMIC_EX_VPD
]:
1917 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultValue
1919 PcdDefValue
= Pcd
.DefaultValue
1921 if "{CODE(" not in PcdDefValue
:
1922 sizebasevalue_plus
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
1923 sizebasevalue
= "(%s / sizeof(%s))" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
1924 sizeof
= "sizeof(%s)" % Pcd
.BaseDatumType
1925 CApp
= ' int ArraySize = %s %% %s ? %s : %s ;\n' % ( (DscBuildData
.GetStructurePcdMaxSize(Pcd
), sizeof
, sizebasevalue_plus
, sizebasevalue
))
1926 CApp
+= ' Size = ArraySize * sizeof(%s); \n' % Pcd
.BaseDatumType
1928 CApp
= " Size = 0;\n"
1930 CApp
= ' Size = sizeof(%s);\n' % ("".join(r_datatype
) )
1932 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1933 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1936 def GetIndicator(self
,index
,FieldName
,Pcd
):
1937 def cleanupindex(indexstr
):
1938 return indexstr
.strip("[").strip("]").strip()
1939 index_elements
= ArrayIndex
.findall(index
)
1940 pcd_capacity
= Pcd
.Capacity
1943 if len(pcd_capacity
)>2:
1944 for i
in range(0,len(index_elements
)):
1945 index_ele
= index_elements
[i
]
1946 index_num
= index_ele
.strip("[").strip("]").strip()
1947 if i
== len(index_elements
) -2:
1948 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
]))
1951 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]))
1952 elif len(pcd_capacity
) == 2:
1953 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
1954 elif len(pcd_capacity
) == 1:
1955 index_ele
= index_elements
[0]
1956 index_num
= index_ele
.strip("[").strip("]").strip()
1957 indicator
+= " + %s)" % (index_num
)
1961 indicator
+= "->" + FieldName
1964 def GetStarNum(self
,Pcd
):
1965 if not Pcd
.IsArray():
1967 elif Pcd
.IsSimpleTypeArray():
1968 return len(Pcd
.Capacity
)
1970 return len(Pcd
.Capacity
) + 1
1971 def GenerateDefaultValueAssignFunction(self
, Pcd
):
1972 CApp
= "// Default value in Dec \n"
1973 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
1974 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1975 CApp
= CApp
+ ' CHAR8 *Value;\n'
1976 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1977 IsArray
= _IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1980 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1981 except BadExpression
:
1982 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1983 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1984 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1985 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1988 # Use memcpy() to copy value into field
1990 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1991 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value, sizeof(%s_%s_INIT_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1993 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1994 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1995 elif isinstance(Value
, str):
1996 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1997 for index
in Pcd
.DefaultValues
:
1998 FieldList
= Pcd
.DefaultValues
[index
]
2001 for FieldName
in FieldList
:
2002 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2005 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2006 except BadExpression
:
2007 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2008 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2011 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2013 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]))
2015 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2018 # Use memcpy() to copy value into field
2020 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2021 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2022 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
.BaseDatumType
, FieldName
, ValueSize
, Pcd
.BaseDatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2023 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2024 elif isinstance(Value
, str):
2025 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2027 if '[' in FieldName
and ']' in FieldName
:
2028 Index
= int(FieldName
.split('[')[1].split(']')[0])
2029 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
)
2031 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2033 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2038 def GenerateDefaultValueAssignStatement(Pcd
):
2039 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2042 def GetPcdDscRawDefaultValue(self
,Pcd
, SkuName
,DefaultStoreName
):
2043 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2044 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2045 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2047 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2049 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2051 return pcddefaultvalue
2052 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
2053 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
2054 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
2055 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2056 CApp
= CApp
+ ' CHAR8 *Value;\n'
2058 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2059 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2061 pcddefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, SkuName
, DefaultStoreName
)
2063 FieldList
= pcddefaultvalue
2064 IsArray
= _IsFieldValueAnArray(FieldList
)
2066 if "{CODE(" not in FieldList
:
2068 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2069 except BadExpression
:
2070 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2071 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2072 Value
, ValueSize
= ParseFieldValue (FieldList
)
2074 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2075 if isinstance(Value
, str):
2076 if "{CODE(" in Value
:
2077 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
)
2079 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
)
2082 # Use memcpy() to copy value into field
2084 if Pcd
.IsArray() and "{CODE(" in pcddefaultvalue
:
2085 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
)
2087 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
)
2088 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2090 if isinstance(Value
, str):
2091 if "{CODE(" in Value
:
2092 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
)
2094 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2097 # Use memcpy() to copy value into field
2099 if Pcd
.IsArray() and "{CODE(" in pcddefaultvalue
:
2100 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
)
2102 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2103 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2105 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2106 if not inheritvalue
:
2108 for index
in inheritvalue
:
2109 FieldList
= inheritvalue
[index
]
2112 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2113 for FieldName
in FieldList
:
2114 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2115 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2118 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2119 except BadExpression
:
2120 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2121 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2123 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2125 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]))
2126 if isinstance(Value
, str):
2127 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2130 # Use memcpy() to copy value into field
2132 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2133 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2134 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
.BaseDatumType
, FieldName
, ValueSize
, Pcd
.BaseDatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2135 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2137 if '[' in FieldName
and ']' in FieldName
:
2138 Index
= int(FieldName
.split('[')[1].split(']')[0])
2139 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
)
2141 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2143 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2148 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2149 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2152 def GenerateCommandLineValue(self
, Pcd
):
2153 CApp
= "// Value in CommandLine\n"
2154 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2155 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2156 CApp
= CApp
+ ' CHAR8 *Value;\n'
2158 pcddefaultvalue
= Pcd
.PcdValueFromComm
2159 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2162 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2163 IsArray
= _IsFieldValueAnArray(FieldList
)
2166 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2167 except BadExpression
:
2168 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2169 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2170 Value
, ValueSize
= ParseFieldValue (FieldList
)
2172 if isinstance(Value
, str):
2173 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2176 # Use memcpy() to copy value into field
2178 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2179 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2181 for FieldName
in FieldList
:
2182 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2185 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2186 except BadExpression
:
2187 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2188 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2192 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2194 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]))
2195 if isinstance(Value
, str):
2196 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2199 # Use memcpy() to copy value into field
2201 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2202 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2203 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
.BaseDatumType
, FieldName
, ValueSize
, Pcd
.BaseDatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2204 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2206 if '[' in FieldName
and ']' in FieldName
:
2207 Index
= int(FieldName
.split('[')[1].split(']')[0])
2208 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
)
2210 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2212 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2217 def GenerateCommandLineValueStatement(Pcd
):
2218 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2220 def GenerateFdfValue(self
,Pcd
):
2221 CApp
= "// Value in Fdf\n"
2222 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2223 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2224 CApp
= CApp
+ ' CHAR8 *Value;\n'
2226 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2227 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2230 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2231 IsArray
= _IsFieldValueAnArray(FieldList
)
2234 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2235 except BadExpression
:
2236 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2237 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2238 Value
, ValueSize
= ParseFieldValue (FieldList
)
2240 if isinstance(Value
, str):
2241 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2244 # Use memcpy() to copy value into field
2246 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2247 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2249 for FieldName
in FieldList
:
2250 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2253 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2254 except BadExpression
:
2255 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2256 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2260 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2262 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]))
2263 if isinstance(Value
, str):
2264 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2267 # Use memcpy() to copy value into field
2269 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2270 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2271 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
.BaseDatumType
, FieldName
, ValueSize
, Pcd
.BaseDatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2272 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2274 if '[' in FieldName
and ']' in FieldName
:
2275 Index
= int(FieldName
.split('[')[1].split(']')[0])
2276 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
)
2278 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2280 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2285 def GenerateFdfValueStatement(Pcd
):
2286 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2289 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2290 OverrideValues
= {DefaultStore
:{}}
2291 if Pcd
.SkuOverrideValues
:
2292 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2293 if not OverrideValues
:
2294 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2295 for DefaultStoreName
in OverrideValues
:
2296 CApp
= CApp
+ 'void\n'
2297 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2298 CApp
= CApp
+ ' void\n'
2299 CApp
= CApp
+ ' )\n'
2301 CApp
= CApp
+ ' UINT32 Size;\n'
2302 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2303 CApp
= CApp
+ ' CHAR8 *Value;\n'
2304 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2305 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2307 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2311 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2313 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2316 # Get current PCD value and size
2318 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2321 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2322 # the correct value. For structures with a flexible array member, the flexible
2323 # array member is detected, and the size is based on the highest index used with
2324 # the flexible array member. The flexible array member must be the last field
2325 # in a structure. The size formula for this case is:
2326 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2328 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,DefaultStoreName
)
2331 # Allocate and zero buffer for the PCD
2332 # Must handle cases where current value is smaller, larger, or same size
2333 # Always keep that larger one as the current size
2335 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2336 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2337 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2340 # Copy current PCD value into allocated buffer.
2342 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2345 # Assign field values in PCD
2347 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2348 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2349 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2350 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2351 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2352 for defaultstorenameitem
in storeset
:
2353 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2354 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2355 if skuname
== SkuName
:
2358 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2359 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2360 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2361 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2363 # Set new PCD value and size
2365 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2370 CApp
= CApp
+ ' free (Pcd);\n'
2373 return InitByteValue
, CApp
2375 def GenerateArrayAssignment(self
, Pcd
):
2379 if not Pcd
.IsArray():
2382 for d
in Pcd
.Capacity
:
2385 Value
= Pcd
.DefaultValueFromDec
2386 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2387 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2388 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2390 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2391 for skuname
in Pcd
.SkuInfoList
:
2392 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2393 if skuinfo
.VariableName
:
2394 for defaultstore
in skuinfo
.DefaultStoreDict
:
2395 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, defaultstore
)
2396 if pcddscrawdefaultvalue
:
2397 Value
= skuinfo
[defaultstore
]
2398 if "{CODE(" in Value
:
2399 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2400 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2402 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, TAB_DEFAULT_STORES_DEFAULT
)
2403 if pcddscrawdefaultvalue
:
2404 Value
= skuinfo
.DefaultValue
2405 if "{CODE(" in Value
:
2406 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2407 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2409 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2410 if pcddscrawdefaultvalue
:
2411 if "{CODE(" in Pcd
.DefaultValue
:
2412 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2413 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2417 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2418 if not OverrideValues
:
2420 for key
in OverrideValues
:
2421 if OverrideValues
[key
]:
2425 def ParseCCFlags(self
, ccflag
):
2427 ccflaglist
= ccflag
.split(" ")
2429 while i
< len(ccflaglist
):
2430 item
= ccflaglist
[i
].strip()
2431 if item
in (r
"/D", r
"/U","-D","-U"):
2432 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2434 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2438 def GenerateByteArrayValue (self
, StructuredPcds
):
2440 # Generate/Compile/Run C application to determine if there are any flexible array members
2442 if not StructuredPcds
:
2446 CApp
= PcdMainCHeader
2448 IncludeFiles
= set()
2449 for PcdName
in StructuredPcds
:
2450 Pcd
= StructuredPcds
[PcdName
]
2451 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2452 if IncludeFile
not in IncludeFiles
:
2453 IncludeFiles
.add(IncludeFile
)
2454 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2456 for Pcd
in StructuredPcds
.values():
2457 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2458 for PcdName
in StructuredPcds
:
2459 Pcd
= StructuredPcds
[PcdName
]
2460 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2461 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2462 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2463 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2464 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2465 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2466 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2468 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2469 if SkuName
not in Pcd
.SkuOverrideValues
:
2471 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2472 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2473 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2474 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2475 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2477 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2478 if SkuName
not in Pcd
.SkuOverrideValues
:
2480 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2481 Pcd
= StructuredPcds
[PcdName
]
2482 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2484 CApp
= CApp
+ 'VOID\n'
2485 CApp
= CApp
+ 'PcdEntryPoint(\n'
2486 CApp
= CApp
+ ' VOID\n'
2487 CApp
= CApp
+ ' )\n'
2489 for Pcd
in StructuredPcds
.values():
2490 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
]]:
2491 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2493 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2494 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2496 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2497 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2500 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2502 if not os
.path
.exists(self
.OutputPath
):
2503 os
.makedirs(self
.OutputPath
)
2504 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2505 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2507 MakeApp
= PcdMakefileHeader
2508 if sys
.platform
== "win32":
2509 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2511 MakeApp
= MakeApp
+ PcdGccMakefile
2512 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2513 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2516 PlatformInc
= OrderedDict()
2517 for Cache
in self
._Bdb
._CACHE
_.values():
2518 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2521 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2522 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2523 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2524 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2527 for Pcd
in StructuredPcds
.values():
2528 for PackageDec
in Pcd
.PackageDecs
:
2529 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2530 if not os
.path
.exists(Package
):
2531 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2532 if Package
not in PcdDependDEC
:
2533 PcdDependDEC
.append(Package
)
2535 if PlatformInc
and PcdDependDEC
:
2536 for pkg
in PcdDependDEC
:
2537 if pkg
in PlatformInc
:
2538 for inc
in PlatformInc
[pkg
]:
2539 MakeApp
+= '-I' + str(inc
) + ' '
2540 IncSearchList
.append(inc
)
2541 MakeApp
= MakeApp
+ '\n'
2543 CC_FLAGS
= LinuxCFLAGS
2544 if sys
.platform
== "win32":
2545 CC_FLAGS
= WindowsCFLAGS
2546 BuildOptions
= OrderedDict()
2547 for Options
in self
.BuildOptions
:
2548 if Options
[2] != EDKII_NAME
:
2551 if Family
and Family
!= self
.ToolChainFamily
:
2553 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2558 if Target
== TAB_STAR
or Target
== self
._Target
:
2559 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2560 if 'COMMON' not in BuildOptions
:
2561 BuildOptions
['COMMON'] = set()
2562 if Arch
== TAB_STAR
:
2563 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2564 if Arch
in self
.SupArchList
:
2565 if Arch
not in BuildOptions
:
2566 BuildOptions
[Arch
] = set()
2567 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2570 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2571 if len(ArchBuildOptions
.keys()) == 1:
2572 BuildOptions
['COMMON'] |
= (list(ArchBuildOptions
.values())[0])
2573 elif len(ArchBuildOptions
.keys()) > 1:
2574 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2575 BuildOptions
['COMMON'] |
= CommonBuildOptions
2576 ValueList
= list(BuildOptions
['COMMON'])
2577 CC_FLAGS
+= " ".join(ValueList
)
2580 if sys
.platform
== "win32":
2581 MakeApp
= MakeApp
+ PcdMakefileEnd
2582 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2584 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2585 MakeApp
= MakeApp
+ '\n'
2586 IncludeFileFullPaths
= []
2587 for includefile
in IncludeFiles
:
2588 for includepath
in IncSearchList
:
2589 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2590 if os
.path
.exists(includefullpath
):
2591 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2594 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2595 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2596 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2597 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2598 for include_file
in IncFileList
:
2599 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2600 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2601 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2602 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2604 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2605 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2606 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2608 Dest_PcdValueInitExe
= PcdValueInitName
2609 if not sys
.platform
== "win32":
2610 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2612 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2614 if sys
.platform
== "win32":
2615 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2616 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2619 MakeCommand
= 'make -f %s' % (MakeFileName
)
2620 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2623 Messages
= Messages
.split('\n')
2626 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2627 File
= open (CAppBaseFileName
+ '.c', 'r')
2628 FileData
= File
.readlines()
2630 for Message
in Messages
:
2631 if " error" in Message
or "warning" in Message
:
2632 FileInfo
= Message
.strip().split('(')
2633 if len (FileInfo
) > 1:
2634 FileName
= FileInfo
[0]
2635 FileLine
= FileInfo
[1].split (')')[0]
2637 FileInfo
= Message
.strip().split(':')
2638 if len(FileInfo
) < 2:
2640 FileName
= FileInfo
[0]
2641 FileLine
= FileInfo
[1]
2642 if FileLine
.isdigit():
2643 error_line
= FileData
[int (FileLine
) - 1]
2644 if r
"//" in error_line
:
2645 c_line
, dsc_line
= error_line
.split(r
"//")
2647 dsc_line
= error_line
2648 message_itmes
= Message
.split(":")
2650 if "PcdValueInit.c" not in Message
:
2651 if not MessageGroup
:
2652 MessageGroup
.append(Message
)
2655 for item
in message_itmes
:
2656 if "PcdValueInit.c" in item
:
2657 Index
= message_itmes
.index(item
)
2658 message_itmes
[Index
] = dsc_line
.strip()
2660 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2663 MessageGroup
.append(Message
)
2665 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2667 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2669 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
2670 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2671 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2673 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2675 File
= open (OutputValueFile
, 'r')
2676 FileBuffer
= File
.readlines()
2679 StructurePcdSet
= []
2680 for Pcd
in FileBuffer
:
2681 PcdValue
= Pcd
.split ('|')
2682 PcdInfo
= PcdValue
[0].split ('.')
2683 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2684 return StructurePcdSet
2687 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2688 if not os
.path
.exists(OutputFile
):
2690 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2692 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2696 ## Retrieve dynamic PCD settings
2698 # @param Type PCD type
2700 # @retval a dict object contains settings of given PCD type
2702 def _GetDynamicPcd(self
, Type
):
2705 Pcds
= OrderedDict()
2707 # tdict is a special dict kind of type, used for selecting correct
2708 # PCD settings for certain ARCH and SKU
2710 PcdDict
= tdict(True, 4)
2712 # Find out all possible PCD candidates for self._Arch
2713 RecordList
= self
._RawData
[Type
, self
._Arch
]
2714 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2717 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2718 SkuName
= SkuName
.upper()
2719 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2720 if SkuName
not in AvailableSkuIdSet
:
2721 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2722 File
=self
.MetaFile
, Line
=Dummy5
)
2723 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2724 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2725 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2727 # Remove redundant PCD candidates, per the ARCH and SKU
2728 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2730 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2734 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2736 if int(MaxDatumSize
, 0) > 0xFFFF:
2737 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2738 File
=self
.MetaFile
, Line
=Dummy4
)
2739 if int(MaxDatumSize
, 0) < 0:
2740 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2741 File
=self
.MetaFile
, Line
=Dummy4
)
2742 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2743 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2744 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2745 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2746 if MaxDatumSize
.strip():
2747 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2750 if pcdObject
.MaxDatumSize
:
2751 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2754 if CurrentMaxSize
> PcdMaxSize
:
2755 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2757 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2760 self
._PCD
_TYPE
_STRING
_[Type
],
2765 OrderedDict({SkuName
: SkuInfo
}),
2770 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2771 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2772 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2774 for pcd
in Pcds
.values():
2775 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2776 # Only fix the value while no value provided in DSC file.
2777 for sku
in pcd
.SkuInfoList
.values():
2778 if not sku
.DefaultValue
:
2779 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2780 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2781 valuefromDec
= pcdDecObject
.DefaultValue
2782 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2783 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2784 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2785 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2786 del pcd
.SkuInfoList
[TAB_COMMON
]
2787 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2788 del pcd
.SkuInfoList
[TAB_COMMON
]
2790 list(map(self
.FilterSkuSettings
, Pcds
.values()))
2794 def FilterSkuSettings(self
, PcdObj
):
2796 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2797 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2798 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2799 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2800 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2801 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2803 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2804 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2809 def CompareVarAttr(Attr1
, Attr2
):
2810 if not Attr1
or not Attr2
: # for empty string
2812 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2813 Attr1Set
= set(Attr1s
)
2814 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2815 Attr2Set
= set(Attr2s
)
2816 if Attr2Set
== Attr1Set
:
2821 def CompletePcdValues(self
, PcdSet
):
2822 Pcds
= OrderedDict()
2823 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2824 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2825 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2826 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2827 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2829 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2830 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2831 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2832 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2833 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2834 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2835 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2837 PcdType
= PcdObj
.Type
2838 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2839 for skuid
in PcdObj
.SkuInfoList
:
2840 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2841 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2842 for defaultstorename
in DefaultStores
:
2843 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2844 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
2845 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2846 for skuname
, skuid
in SkuIds
.items():
2847 if skuname
not in PcdObj
.SkuInfoList
:
2848 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2849 while nextskuid
not in PcdObj
.SkuInfoList
:
2850 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2851 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2852 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2853 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2854 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2855 PcdObj
.DefaultValue
= list(PcdObj
.SkuInfoList
.values())[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2856 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2858 ## Retrieve dynamic HII PCD settings
2860 # @param Type PCD type
2862 # @retval a dict object contains settings of given PCD type
2864 def _GetDynamicHiiPcd(self
, Type
):
2868 Pcds
= OrderedDict()
2869 UserDefinedDefaultStores
= []
2871 # tdict is a special dict kind of type, used for selecting correct
2872 # PCD settings for certain ARCH and SKU
2874 PcdDict
= tdict(True, 5)
2876 RecordList
= self
._RawData
[Type
, self
._Arch
]
2877 # Find out all possible PCD candidates for self._Arch
2878 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2879 DefaultStoresDefine
= self
._GetDefaultStores
()
2881 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
2882 SkuName
= SkuName
.upper()
2883 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2884 DefaultStore
= DefaultStore
.upper()
2885 if DefaultStore
== TAB_COMMON
:
2886 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2888 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
2889 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
2890 if SkuName
not in AvailableSkuIdSet
:
2891 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2892 File
=self
.MetaFile
, Line
=Dummy5
)
2893 if DefaultStore
not in DefaultStoresDefine
:
2894 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2895 File
=self
.MetaFile
, Line
=Dummy5
)
2896 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2897 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
2898 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
2901 # Remove redundant PCD candidates, per the ARCH and SKU
2902 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdSet
:
2904 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
2907 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2909 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2911 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2912 ExtraData
="[%s]" % VarAttribute
)
2914 FormatCorrect
= True
2915 if VariableOffset
.isdigit():
2916 if int(VariableOffset
, 10) > 0xFFFF:
2918 elif variablePattern
.match(VariableOffset
):
2919 if int(VariableOffset
, 16) > 0xFFFF:
2921 # For Offset written in "A.B"
2922 elif VariableOffset
.find('.') > -1:
2923 VariableOffsetList
= VariableOffset
.split(".")
2924 if not (len(VariableOffsetList
) == 2
2925 and IsValidWord(VariableOffsetList
[0])
2926 and IsValidWord(VariableOffsetList
[1])):
2927 FormatCorrect
= False
2929 FormatCorrect
= False
2930 if not FormatCorrect
:
2931 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2934 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2935 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2936 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2938 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2939 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
)]))
2941 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2942 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2943 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2944 if SkuName
in pcdObject
.SkuInfoList
:
2945 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2946 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2948 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2949 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2951 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2952 PcdClassObj
= PcdClassObject(
2955 self
._PCD
_TYPE
_STRING
_[Type
],
2960 OrderedDict({SkuName
: SkuInfo
}),
2963 pcdDecObject
.validateranges
,
2964 pcdDecObject
.validlists
,
2965 pcdDecObject
.expressions
,
2967 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
2968 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
2969 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
2971 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
2972 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2973 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2974 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
2975 for pcd
in Pcds
.values():
2976 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2977 pcd
.DatumType
= pcdDecObject
.DatumType
2978 # Only fix the value while no value provided in DSC file.
2979 for sku
in pcd
.SkuInfoList
.values():
2980 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2981 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2982 for default_store
in sku
.DefaultStoreDict
:
2983 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2984 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2985 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2986 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
2987 valuefromDec
= pcdDecObject
.DefaultValue
2988 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
2989 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2990 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2991 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2992 del pcd
.SkuInfoList
[TAB_COMMON
]
2993 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2994 del pcd
.SkuInfoList
[TAB_COMMON
]
2996 if pcd
.MaxDatumSize
.strip():
2997 MaxSize
= int(pcd
.MaxDatumSize
, 0)
3000 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
3001 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
3003 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
3004 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
3005 if datalen
> MaxSize
:
3007 for defaultst
in skuobj
.DefaultStoreDict
:
3008 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
3009 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
3010 pcd
.MaxDatumSize
= str(MaxSize
)
3011 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
3013 invalidpcd
= ",".join(invalidhii
)
3014 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
)
3016 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3021 def CheckVariableNameAssignment(Pcds
):
3023 for pcdname
in Pcds
:
3025 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
3026 if len(varnameset
) > 1:
3027 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
3029 return False, invalidhii
3032 ## Retrieve dynamic VPD PCD settings
3034 # @param Type PCD type
3036 # @retval a dict object contains settings of given PCD type
3038 def _GetDynamicVpdPcd(self
, Type
):
3041 Pcds
= OrderedDict()
3043 # tdict is a special dict kind of type, used for selecting correct
3044 # PCD settings for certain ARCH and SKU
3046 PcdDict
= tdict(True, 4)
3049 # Find out all possible PCD candidates for self._Arch
3050 RecordList
= self
._RawData
[Type
, self
._Arch
]
3051 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3053 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3054 SkuName
= SkuName
.upper()
3055 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3056 if SkuName
not in AvailableSkuIdSet
:
3057 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3058 File
=self
.MetaFile
, Line
=Dummy5
)
3059 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
3060 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3061 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3063 # Remove redundant PCD candidates, per the ARCH and SKU
3064 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3065 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3069 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3070 # For the Integer & Boolean type, the optional data can only be InitialValue.
3071 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3072 # until the DEC parser has been called.
3074 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3076 if int(MaxDatumSize
, 0) > 0xFFFF:
3077 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3078 File
=self
.MetaFile
, Line
=Dummy4
)
3079 if int(MaxDatumSize
, 0) < 0:
3080 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3081 File
=self
.MetaFile
, Line
=Dummy4
)
3082 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3083 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3084 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3085 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3086 if MaxDatumSize
.strip():
3087 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3090 if pcdObject
.MaxDatumSize
:
3091 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3094 if CurrentMaxSize
> PcdMaxSize
:
3095 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3097 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3100 self
._PCD
_TYPE
_STRING
_[Type
],
3105 OrderedDict({SkuName
: SkuInfo
}),
3110 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3111 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3112 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3113 for pcd
in Pcds
.values():
3114 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3115 pcd
.DatumType
= pcdDecObject
.DatumType
3116 # Only fix the value while no value provided in DSC file.
3117 for sku
in pcd
.SkuInfoList
.values():
3118 if not sku
.DefaultValue
:
3119 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3120 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3121 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3122 valuefromDec
= pcdDecObject
.DefaultValue
3123 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3124 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3125 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3126 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3127 del pcd
.SkuInfoList
[TAB_COMMON
]
3128 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3129 del pcd
.SkuInfoList
[TAB_COMMON
]
3131 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3132 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3133 for pcd
in Pcds
.values():
3134 PcdValueTypeSet
= set()
3135 for sku
in pcd
.SkuInfoList
.values():
3136 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3137 if len(PcdValueTypeSet
) > 1:
3138 for sku
in pcd
.SkuInfoList
.values():
3139 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3141 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3144 ## Add external modules
3146 # The external modules are mostly those listed in FDF file, which don't
3149 # @param FilePath The path of module description file
3151 def AddModule(self
, FilePath
):
3152 FilePath
= NormPath(FilePath
)
3153 if FilePath
not in self
.Modules
:
3154 Module
= ModuleBuildClassObject()
3155 Module
.MetaFile
= FilePath
3156 self
.Modules
.append(Module
)
3159 def ToolChainFamily(self
):
3160 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3161 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
3162 if os
.path
.isfile(BuildConfigurationFile
) == True:
3163 TargetTxt
= TargetTxtClassObject()
3164 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
3165 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3166 if ToolDefinitionFile
== '':
3167 ToolDefinitionFile
= "tools_def.txt"
3168 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
3169 if os
.path
.isfile(ToolDefinitionFile
) == True:
3170 ToolDef
= ToolDefClassObject()
3171 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
3172 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
3173 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3174 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3175 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3176 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3178 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3179 return self
._ToolChainFamily
3181 ## Add external PCDs
3183 # The external PCDs are mostly those listed in FDF file to specify address
3184 # or offset information.
3186 # @param Name Name of the PCD
3187 # @param Guid Token space guid of the PCD
3188 # @param Value Value of the PCD
3190 def AddPcd(self
, Name
, Guid
, Value
):
3191 if (Name
, Guid
) not in self
.Pcds
:
3192 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3193 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3197 if self
._DecPcds
is None:
3199 if GlobalData
.gFdfParser
:
3200 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3202 for Inf
in FdfInfList
:
3203 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3204 if ModuleFile
in self
._Modules
:
3206 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3207 PkgSet
.update(ModuleData
.Packages
)
3208 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3209 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3210 return self
._DecPcds