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 # SPDX-License-Identifier: BSD-2-Clause-Patent
9 ## Platform build information from DSC file
11 # This class is used to retrieve information stored in database and convert them
12 # into PlatformBuildClassObject form for easier use for AutoGen.
14 from __future__
import print_function
15 from __future__
import absolute_import
16 from Common
.StringUtils
import *
17 from Common
.DataType
import *
18 from Common
.Misc
import *
20 from Common
.Expression
import *
21 from CommonDataClass
.CommonClass
import SkuInfoClass
22 from Common
.TargetTxtClassObject
import TargetTxt
23 from Common
.ToolDefClassObject
import ToolDef
24 from .MetaDataTable
import *
25 from .MetaFileTable
import *
26 from .MetaFileParser
import *
28 from .WorkspaceCommon
import GetDeclaredPcd
29 from Common
.Misc
import AnalyzeDscPcd
30 from Common
.Misc
import ProcessDuplicatedInf
,RemoveCComments
,ArrayIndex
32 from Common
.Parsing
import IsValidWord
33 from Common
.VariableAttributes
import VariableAttributes
34 import Common
.GlobalData
as GlobalData
36 from functools
import reduce
37 from Common
.Misc
import SaveFileOnChange
38 from Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
39 from collections
import OrderedDict
, defaultdict
41 def _IsFieldValueAnArray (Value
):
43 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
45 if Value
.startswith('L"') and Value
.endswith('"') and len(list(Value
[2:-1])) > 1:
47 if Value
[0] == '"' and Value
[-1] == '"' and len(list(Value
[1:-1])) > 1:
49 if Value
[0] == '{' and Value
[-1] == '}':
51 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
53 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
57 PcdValueInitName
= 'PcdValueInit'
68 #include <PcdValueCommon.h>
78 return PcdValueMain (argc, argv);
82 PcdMakefileHeader
= '''
85 # This file is auto-generated by build utility
90 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
91 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
93 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
95 LIBS = $(LIB_PATH)\Common.lib
97 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
102 $(APPFILE): $(OBJECTS)
107 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
111 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
112 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
113 ## regular expressions for finding decimal and hex numbers
114 Pattern
= re
.compile('^[1-9]\d*|0$')
115 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
116 ## Regular expression for finding header file inclusions
117 from AutoGen
.GenMake
import gIncludePattern
119 ## Find dependencies for one source file
121 # By searching recursively "#include" directive in file, find out all the
122 # files needed by given source file. The dependecies will be only searched
123 # in given search path list.
125 # @param SearchPathList The list of search path
127 # @retval list The list of files the given source file depends on
129 def GetDependencyList(FileStack
, SearchPathList
):
131 DependencySet
= set(FileStack
)
132 while len(FileStack
) > 0:
134 FullPathDependList
= []
135 CurrentFileDependencyList
= []
137 CurrentFileDependencyList
= DepDb
[F
]
141 FileContent
= Fd
.read()
142 except BaseException
as X
:
143 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
145 if "Fd" in dir(locals()):
148 if len(FileContent
) == 0:
152 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
153 FileContent
= FileContent
.decode('utf-16')
155 FileContent
= FileContent
.decode()
157 # The file is not txt file. for example .mcb file
159 IncludedFileList
= gIncludePattern
.findall(FileContent
)
161 for Inc
in IncludedFileList
:
163 Inc
= os
.path
.normpath(Inc
)
164 CurrentFileDependencyList
.append(Inc
)
165 DepDb
[F
] = CurrentFileDependencyList
167 CurrentFilePath
= os
.path
.dirname(F
)
168 PathList
= [CurrentFilePath
] + SearchPathList
169 for Inc
in CurrentFileDependencyList
:
170 for SearchPath
in PathList
:
171 FilePath
= os
.path
.join(SearchPath
, Inc
)
172 if not os
.path
.exists(FilePath
):
174 if FilePath
not in DependencySet
:
175 FileStack
.append(FilePath
)
176 FullPathDependList
.append(FilePath
)
178 DependencySet
.update(FullPathDependList
)
179 DependencyList
= list(DependencySet
) # remove duplicate ones
181 return DependencyList
183 class DscBuildData(PlatformBuildClassObject
):
184 # dict used to convert PCD type in database to string used by build tool
185 _PCD_TYPE_STRING_
= {
186 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
187 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
188 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
189 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
190 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
191 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
192 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
193 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
194 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
195 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
196 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
199 # dict used to convert part of [Defines] to members of DscBuildData directly
204 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
205 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
206 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
207 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
208 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
209 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
210 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
211 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
212 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
213 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
214 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
215 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
216 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
217 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
218 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
221 # used to compose dummy library class name for those forced library instances
222 _NullLibraryNumber
= 0
224 ## Constructor of DscBuildData
226 # Initialize object of DscBuildData
228 # @param FilePath The path of platform description file
229 # @param RawData The raw data of DSC file
230 # @param BuildDataBase Database used to retrieve module/package information
231 # @param Arch The target architecture
232 # @param Platform (not used for DscBuildData)
233 # @param Macros Macros used for replacement in DSC file
235 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
236 self
.MetaFile
= FilePath
237 self
._RawData
= RawData
238 self
._Bdb
= BuildDataBase
240 self
._Target
= Target
241 self
._Toolchain
= Toolchain
242 self
._ToolChainFamily
= None
244 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
245 self
.DefaultStores
= None
246 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
249 def OutputPath(self
):
250 if os
.getenv("WORKSPACE"):
251 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
253 return os
.path
.dirname(self
.DscFile
)
256 def __setitem__(self
, key
, value
):
257 self
.__dict
__[self
._PROPERTY
_[key
]] = value
260 def __getitem__(self
, key
):
261 return self
.__dict
__[self
._PROPERTY
_[key
]]
264 def __contains__(self
, key
):
265 return key
in self
._PROPERTY
_
267 ## Set all internal used members of DscBuildData to None
270 self
._PlatformName
= None
273 self
._DscSpecification
= None
274 self
._OutputDirectory
= None
275 self
._SupArchList
= None
276 self
._BuildTargets
= None
278 self
._PcdInfoFlag
= None
279 self
._VarCheckFlag
= None
280 self
._FlashDefinition
= None
281 self
._Prebuild
= None
282 self
._Postbuild
= None
283 self
._BuildNumber
= None
284 self
._MakefileName
= None
285 self
._BsBaseAddress
= None
286 self
._RtBaseAddress
= None
289 self
._LibraryInstances
= None
290 self
._LibraryClasses
= None
293 self
._BuildOptions
= None
294 self
._ModuleTypeOptions
= None
295 self
._LoadFixAddress
= None
296 self
._RFCLanguages
= None
297 self
._ISOLanguages
= None
298 self
._VpdToolGuid
= None
299 self
._MacroDict
= None
300 self
.DefaultStores
= None
302 ## Get current effective macros
305 if self
._MacroDict
is None:
307 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
308 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
309 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
310 return self
._MacroDict
318 return self
.MetaFile
.Dir
320 ## Retrieve all information in [Defines] section
322 # (Retrieving all [Defines] information in one-shot is just to save time.)
324 def _GetHeaderInfo(self
):
325 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
326 for Record
in RecordList
:
328 # items defined _PROPERTY_ don't need additional processing
330 # some special items in [Defines] section need special treatment
331 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
332 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
333 if ' ' in self
._OutputDirectory
:
334 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
335 File
=self
.MetaFile
, Line
=Record
[-1],
336 ExtraData
=self
._OutputDirectory
)
337 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
338 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
339 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
341 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
343 elif Name
== TAB_DSC_PREBUILD
:
344 PrebuildValue
= Record
[2]
345 if Record
[2][0] == '"':
346 if Record
[2][-1] != '"':
347 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
348 File
=self
.MetaFile
, Line
=Record
[-1])
349 PrebuildValue
= Record
[2][1:-1]
350 self
._Prebuild
= PrebuildValue
351 elif Name
== TAB_DSC_POSTBUILD
:
352 PostbuildValue
= Record
[2]
353 if Record
[2][0] == '"':
354 if Record
[2][-1] != '"':
355 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
356 File
=self
.MetaFile
, Line
=Record
[-1])
357 PostbuildValue
= Record
[2][1:-1]
358 self
._Postbuild
= PostbuildValue
359 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
360 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
361 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
362 self
._BuildTargets
= GetSplitValueList(Record
[2])
363 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
364 if self
._SkuName
is None:
365 self
._SkuName
= Record
[2]
366 if GlobalData
.gSKUID_CMD
:
367 self
._SkuName
= GlobalData
.gSKUID_CMD
368 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
369 self
._PcdInfoFlag
= Record
[2]
370 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
371 self
._VarCheckFlag
= Record
[2]
372 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
374 self
._LoadFixAddress
= int (Record
[2], 0)
376 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
377 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
378 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
379 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for RFC_LANGUAGES must have double quotes around it, for example: RFC_LANGUAGES = "en-us;zh-hans"',
380 File
=self
.MetaFile
, Line
=Record
[-1])
381 LanguageCodes
= Record
[2][1:-1]
382 if not LanguageCodes
:
383 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
384 File
=self
.MetaFile
, Line
=Record
[-1])
385 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
386 # check whether there is empty entries in the list
387 if None in LanguageList
:
388 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
389 File
=self
.MetaFile
, Line
=Record
[-1])
390 self
._RFCLanguages
= LanguageList
391 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
392 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
393 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
394 File
=self
.MetaFile
, Line
=Record
[-1])
395 LanguageCodes
= Record
[2][1:-1]
396 if not LanguageCodes
:
397 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
398 File
=self
.MetaFile
, Line
=Record
[-1])
399 if len(LanguageCodes
) % 3:
400 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
401 File
=self
.MetaFile
, Line
=Record
[-1])
403 for i
in range(0, len(LanguageCodes
), 3):
404 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
405 self
._ISOLanguages
= LanguageList
406 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
408 # try to convert GUID to a real UUID value to see whether the GUID is format
409 # for VPD_TOOL_GUID is correct.
414 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
415 self
._VpdToolGuid
= Record
[2]
417 self
[Name
] = Record
[2]
418 # set _Header to non-None in order to avoid database re-querying
419 self
._Header
= 'DUMMY'
421 ## Retrieve platform name
423 def PlatformName(self
):
424 if self
._PlatformName
is None:
425 if self
._Header
is None:
426 self
._GetHeaderInfo
()
427 if self
._PlatformName
is None:
428 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
429 return self
._PlatformName
433 return self
.PlatformName
435 ## Retrieve file guid
438 if self
._Guid
is None:
439 if self
._Header
is None:
440 self
._GetHeaderInfo
()
441 if self
._Guid
is None:
442 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
445 ## Retrieve platform version
448 if self
._Version
is None:
449 if self
._Header
is None:
450 self
._GetHeaderInfo
()
451 if self
._Version
is None:
452 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
455 ## Retrieve platform description file version
457 def DscSpecification(self
):
458 if self
._DscSpecification
is None:
459 if self
._Header
is None:
460 self
._GetHeaderInfo
()
461 if self
._DscSpecification
is None:
462 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
463 return self
._DscSpecification
465 ## Retrieve OUTPUT_DIRECTORY
467 def OutputDirectory(self
):
468 if self
._OutputDirectory
is None:
469 if self
._Header
is None:
470 self
._GetHeaderInfo
()
471 if self
._OutputDirectory
is None:
472 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
473 return self
._OutputDirectory
475 ## Retrieve SUPPORTED_ARCHITECTURES
477 def SupArchList(self
):
478 if self
._SupArchList
is None:
479 if self
._Header
is None:
480 self
._GetHeaderInfo
()
481 if self
._SupArchList
is None:
482 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
483 return self
._SupArchList
485 ## Retrieve BUILD_TARGETS
487 def BuildTargets(self
):
488 if self
._BuildTargets
is None:
489 if self
._Header
is None:
490 self
._GetHeaderInfo
()
491 if self
._BuildTargets
is None:
492 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
493 return self
._BuildTargets
496 def PcdInfoFlag(self
):
497 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
499 elif self
._PcdInfoFlag
.upper() == 'TRUE':
505 def VarCheckFlag(self
):
506 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
508 elif self
._VarCheckFlag
.upper() == 'TRUE':
513 # # Retrieve SKUID_IDENTIFIER
516 if self
._SkuName
is None:
517 if self
._Header
is None:
518 self
._GetHeaderInfo
()
519 if self
._SkuName
is None:
520 self
._SkuName
= TAB_DEFAULT
523 ## Override SKUID_IDENTIFIER
525 def SkuName(self
, Value
):
526 self
._SkuName
= Value
529 def FlashDefinition(self
):
530 if self
._FlashDefinition
is None:
531 if self
._Header
is None:
532 self
._GetHeaderInfo
()
533 if self
._FlashDefinition
is None:
534 self
._FlashDefinition
= ''
535 return self
._FlashDefinition
539 if self
._Prebuild
is None:
540 if self
._Header
is None:
541 self
._GetHeaderInfo
()
542 if self
._Prebuild
is None:
544 return self
._Prebuild
548 if self
._Postbuild
is None:
549 if self
._Header
is None:
550 self
._GetHeaderInfo
()
551 if self
._Postbuild
is None:
553 return self
._Postbuild
555 ## Retrieve FLASH_DEFINITION
557 def BuildNumber(self
):
558 if self
._BuildNumber
is None:
559 if self
._Header
is None:
560 self
._GetHeaderInfo
()
561 if self
._BuildNumber
is None:
562 self
._BuildNumber
= ''
563 return self
._BuildNumber
565 ## Retrieve MAKEFILE_NAME
567 def MakefileName(self
):
568 if self
._MakefileName
is None:
569 if self
._Header
is None:
570 self
._GetHeaderInfo
()
571 if self
._MakefileName
is None:
572 self
._MakefileName
= ''
573 return self
._MakefileName
575 ## Retrieve BsBaseAddress
577 def BsBaseAddress(self
):
578 if self
._BsBaseAddress
is None:
579 if self
._Header
is None:
580 self
._GetHeaderInfo
()
581 if self
._BsBaseAddress
is None:
582 self
._BsBaseAddress
= ''
583 return self
._BsBaseAddress
585 ## Retrieve RtBaseAddress
587 def RtBaseAddress(self
):
588 if self
._RtBaseAddress
is None:
589 if self
._Header
is None:
590 self
._GetHeaderInfo
()
591 if self
._RtBaseAddress
is None:
592 self
._RtBaseAddress
= ''
593 return self
._RtBaseAddress
595 ## Retrieve the top address for the load fix address
597 def LoadFixAddress(self
):
598 if self
._LoadFixAddress
is None:
599 if self
._Header
is None:
600 self
._GetHeaderInfo
()
602 if self
._LoadFixAddress
is None:
603 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
606 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
608 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
611 # If command line defined, should override the value in DSC file.
613 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
615 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
617 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS']))
619 if self
._LoadFixAddress
< 0:
620 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
621 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
622 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
624 return self
._LoadFixAddress
626 ## Retrieve RFCLanguage filter
628 def RFCLanguages(self
):
629 if self
._RFCLanguages
is None:
630 if self
._Header
is None:
631 self
._GetHeaderInfo
()
632 if self
._RFCLanguages
is None:
633 self
._RFCLanguages
= []
634 return self
._RFCLanguages
636 ## Retrieve ISOLanguage filter
638 def ISOLanguages(self
):
639 if self
._ISOLanguages
is None:
640 if self
._Header
is None:
641 self
._GetHeaderInfo
()
642 if self
._ISOLanguages
is None:
643 self
._ISOLanguages
= []
644 return self
._ISOLanguages
646 ## Retrieve the GUID string for VPD tool
648 def VpdToolGuid(self
):
649 if self
._VpdToolGuid
is None:
650 if self
._Header
is None:
651 self
._GetHeaderInfo
()
652 if self
._VpdToolGuid
is None:
653 self
._VpdToolGuid
= ''
654 return self
._VpdToolGuid
656 ## Retrieve [SkuIds] section information
659 if self
._SkuIds
is None:
660 self
._SkuIds
= OrderedDict()
661 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
662 for Record
in RecordList
:
664 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
665 File
=self
.MetaFile
, Line
=Record
[-1])
667 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
668 File
=self
.MetaFile
, Line
=Record
[-1])
669 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
670 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
671 File
=self
.MetaFile
, Line
=Record
[-1])
672 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
673 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID name is invalid. The correct format is '(a-zA-Z_)(a-zA-Z0-9_)*'",
674 File
=self
.MetaFile
, Line
=Record
[-1])
675 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
676 if TAB_DEFAULT
not in self
._SkuIds
:
677 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
678 if TAB_COMMON
not in self
._SkuIds
:
679 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
684 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
686 def _GetDefaultStores(self
):
687 if self
.DefaultStores
is None:
688 self
.DefaultStores
= OrderedDict()
689 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
690 for Record
in RecordList
:
692 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
693 File
=self
.MetaFile
, Line
=Record
[-1])
695 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
696 File
=self
.MetaFile
, Line
=Record
[-1])
697 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
698 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
699 File
=self
.MetaFile
, Line
=Record
[-1])
700 if not IsValidWord(Record
[1]):
701 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",
702 File
=self
.MetaFile
, Line
=Record
[-1])
703 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
704 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
705 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
706 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
707 return self
.DefaultStores
709 def OverrideDuplicateModule(self
):
710 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
711 Macros
= self
._Macros
713 for Record
in RecordList
:
715 file_guid
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
716 file_guid_str
= file_guid
[0][2] if file_guid
else "NULL"
717 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
718 if self
._Arch
!= TAB_ARCH_COMMON
and (file_guid_str
,str(ModuleFile
)) in Components
:
719 self
._RawData
.DisableOverrideComponent(Components
[(file_guid_str
,str(ModuleFile
))])
720 Components
[(file_guid_str
,str(ModuleFile
))] = ModuleId
721 self
._RawData
._PostProcessed
= False
722 ## Retrieve [Components] section information
725 if self
._Modules
is not None:
727 self
.OverrideDuplicateModule()
728 self
._Modules
= OrderedDict()
729 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
730 Macros
= self
._Macros
731 for Record
in RecordList
:
732 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
736 # check the file validation
737 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
739 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
742 Module
= ModuleBuildClassObject()
743 Module
.MetaFile
= ModuleFile
745 # get module private library instance
746 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
747 for Record
in RecordList
:
748 LibraryClass
= Record
[0]
749 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
752 # check the file validation
753 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
755 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
758 if LibraryClass
== '' or LibraryClass
== 'NULL':
759 self
._NullLibraryNumber
+= 1
760 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
761 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
762 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
763 if LibraryPath
not in self
.LibraryInstances
:
764 self
.LibraryInstances
.append(LibraryPath
)
766 # get module private PCD setting
767 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
768 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
769 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
770 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
771 TokenList
= GetSplitValueList(Setting
)
772 DefaultValue
= TokenList
[0]
773 # the format is PcdName| Value | VOID* | MaxDatumSize
774 if len(TokenList
) > 2:
775 MaxDatumSize
= TokenList
[2]
778 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
779 Pcd
= PcdClassObject(
791 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
793 # get module private build options
794 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
795 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
796 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
797 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
799 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
800 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
802 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
804 if len(RecordList
) != 1:
805 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
806 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
807 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
808 ModuleFile
.Arch
= self
._Arch
810 self
._Modules
[ModuleFile
] = Module
813 ## Retrieve all possible library instances used in this platform
815 def LibraryInstances(self
):
816 if self
._LibraryInstances
is None:
818 return self
._LibraryInstances
820 ## Retrieve [LibraryClasses] information
822 def LibraryClasses(self
):
823 if self
._LibraryClasses
is None:
824 self
._LibraryInstances
= []
826 # tdict is a special dict kind of type, used for selecting correct
827 # library instance for given library class and module type
829 LibraryClassDict
= tdict(True, 3)
830 # track all library class names
831 LibraryClassSet
= set()
832 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
833 Macros
= self
._Macros
834 for Record
in RecordList
:
835 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
836 if LibraryClass
== '' or LibraryClass
== 'NULL':
837 self
._NullLibraryNumber
+= 1
838 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
839 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
840 LibraryClassSet
.add(LibraryClass
)
841 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
842 # check the file validation
843 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
845 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
848 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
849 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
850 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
851 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
852 if LibraryInstance
not in self
._LibraryInstances
:
853 self
._LibraryInstances
.append(LibraryInstance
)
855 # resolve the specific library instance for each class and each module type
856 self
._LibraryClasses
= tdict(True)
857 for LibraryClass
in LibraryClassSet
:
858 # try all possible module types
859 for ModuleType
in SUP_MODULE_LIST
:
860 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
861 if LibraryInstance
is None:
863 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
865 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
866 for Record
in RecordList
:
867 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
869 # check the file validation
870 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
872 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
874 if File
not in self
._LibraryInstances
:
875 self
._LibraryInstances
.append(File
)
877 # we need the module name as the library class name, so we have
878 # to parse it here. (self._Bdb[] will trigger a file parse if it
879 # hasn't been parsed)
881 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
882 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
883 return self
._LibraryClasses
885 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
886 if not self
._DecPcds
:
889 if GlobalData
.gFdfParser
:
890 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
893 for Inf
in FdfInfList
:
894 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
895 if ModuleFile
in self
._Modules
:
897 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
898 PkgSet
.update(ModuleData
.Packages
)
900 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
901 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
903 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
904 EdkLogger
.error('build', PARSER_ERROR
,
905 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
906 File
=self
.MetaFile
, Line
=LineNo
)
907 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
909 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
910 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
911 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
913 if ValueList
[2] == '-1':
914 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
915 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
917 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
918 if "{CODE(" not in ValueList
[Index
]:
920 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
921 except BadExpression
as Value
:
922 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
923 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
924 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
925 except EvaluationException
as Excpt
:
926 if hasattr(Excpt
, 'Pcd'):
927 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
928 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
929 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
930 " of the DSC file" % Excpt
.Pcd
,
931 File
=self
.MetaFile
, Line
=LineNo
)
933 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
934 File
=self
.MetaFile
, Line
=LineNo
)
936 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
937 File
=self
.MetaFile
, Line
=LineNo
)
940 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
942 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
943 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
944 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
945 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
946 DecPcd
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
947 EdkLogger
.error('build', FORMAT_INVALID
,
948 "Pcd datumtype used in DSC file is not the same as its declaration. DatumType:%s"%DecPcd
.DatumType
,
949 File
=self
.MetaFile
, Line
=LineNo
,
950 ExtraData
="Dsc:%s.%s|%s\n Dec:%s.%s|%s|%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
, TokenSpaceGuid
, \
951 PcdCName
, DecPcd
.DefaultValue
, DecPcd
.DatumType
, DecPcd
.TokenValue
))
952 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
953 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
954 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
957 def _FilterPcdBySkuUsage(self
, Pcds
):
958 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
959 sku_usage
= self
.SkuIdMgr
.SkuUsageType
960 if sku_usage
== SkuClass
.SINGLE
:
963 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
964 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
965 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
969 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
970 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
971 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
974 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
975 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
]]]
976 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
978 for skuid
in pcd
.SkuInfoList
:
979 skuobj
= pcd
.SkuInfoList
.get(skuid
)
980 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
981 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
982 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
983 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
986 def RecoverCommandLinePcd(self
):
987 def UpdateCommandLineValue(pcd
):
988 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
989 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
990 pcd
.PcdValueFromComm
= pcd
.DefaultValue
991 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
992 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
994 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
995 for pcd
in self
._Pcds
:
996 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
997 UpdateCommandLineValue(self
._Pcds
[pcd
])
999 def __ParsePcdFromCommandLine(self
):
1000 if GlobalData
.BuildOptionPcd
:
1001 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
1002 if isinstance(pcd
, tuple):
1004 (pcdname
, pcdvalue
) = pcd
.split('=')
1006 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1008 (Name1
, Name2
) = pcdname
.split('.', 1)
1010 (Name3
, FieldName
) = Name2
.split(".", 1)
1011 if ((Name3
, Name1
)) in self
.DecPcds
:
1012 HasTokenSpace
= True
1014 TokenSpaceGuidCName
= Name1
1018 TokenSpaceGuidCName
= ''
1019 HasTokenSpace
= False
1021 if ((Name2
, Name1
)) in self
.DecPcds
:
1022 HasTokenSpace
= True
1024 TokenSpaceGuidCName
= Name1
1029 TokenSpaceGuidCName
= ''
1030 HasTokenSpace
= False
1033 TokenCName
= pcdname
1034 TokenSpaceGuidCName
= ''
1035 HasTokenSpace
= False
1036 TokenSpaceGuidCNameList
= []
1039 DisplayName
= TokenCName
1041 DisplayName
= TokenCName
+ '.' + FieldName
1042 if not HasTokenSpace
:
1043 for key
in self
.DecPcds
:
1044 PcdItem
= self
.DecPcds
[key
]
1045 if TokenCName
== PcdItem
.TokenCName
:
1046 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1047 if len (TokenSpaceGuidCNameList
) < 1:
1048 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1049 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1050 PcdDatumType
= PcdItem
.DatumType
1056 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1059 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1060 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1064 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1066 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1067 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1069 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1071 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1072 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1074 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1075 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1077 if GlobalData
.BuildOptionPcd
:
1078 for pcd
in GlobalData
.BuildOptionPcd
:
1079 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1080 for BuildData
in self
._Bdb
._CACHE
_.values():
1081 if BuildData
.Arch
!= self
.Arch
:
1083 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1085 for key
in BuildData
.Pcds
:
1086 PcdItem
= BuildData
.Pcds
[key
]
1087 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1088 PcdItem
.DefaultValue
= pcdvalue
1089 PcdItem
.PcdValueFromComm
= pcdvalue
1090 #In command line, the latter full assign value in commandLine should override the former field assign value.
1091 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1094 if GlobalData
.BuildOptionPcd
:
1095 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1096 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1098 if (TokenSpaceGuid
, Token
) not in field_assign
:
1099 field_assign
[TokenSpaceGuid
, Token
] = []
1100 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1102 if (TokenSpaceGuid
, Token
) in field_assign
:
1103 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1104 field_assign
[TokenSpaceGuid
, Token
] = []
1105 for item
in delete_assign
:
1106 GlobalData
.BuildOptionPcd
.remove(item
)
1109 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1112 TokenCName
+= '.' + FieldName
1113 if PcdValue
.startswith('H'):
1114 if FieldName
and _IsFieldValueAnArray(PcdValue
[1:]):
1115 PcdDatumType
= TAB_VOID
1117 if FieldName
and not IsArray
:
1120 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1121 except BadExpression
as Value
:
1122 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1123 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1124 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1125 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1126 PcdDatumType
= TAB_VOID
1128 if FieldName
and not IsArray
:
1131 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1132 except BadExpression
as Value
:
1133 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1134 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1135 elif PcdValue
.startswith('L'):
1136 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1137 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1138 PcdDatumType
= TAB_VOID
1140 if FieldName
and not IsArray
:
1143 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1144 except BadExpression
as Value
:
1145 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1146 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1148 if PcdValue
.upper() == 'FALSE':
1150 if PcdValue
.upper() == 'TRUE':
1153 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1154 PcdValue
= '"' + PcdValue
+ '"'
1155 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1156 PcdValue
= '"' + PcdValue
+ '"'
1160 if PcdValue
.upper().startswith('0X'):
1163 Num
= int(PcdValue
, Base
)
1165 PcdValue
= '"' + PcdValue
+ '"'
1166 if _IsFieldValueAnArray(PcdValue
):
1167 PcdDatumType
= TAB_VOID
1172 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1173 except BadExpression
as Value
:
1174 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1175 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1178 ## Retrieve all PCD settings in platform
1181 if self
._Pcds
is None:
1182 self
._Pcds
= OrderedDict()
1183 self
.__ParsePcdFromCommandLine
()
1184 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1185 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1186 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1187 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1188 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1189 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1190 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1191 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1192 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1194 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1195 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1196 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1197 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1198 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1199 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1201 self
.RecoverCommandLinePcd()
1204 ## Retrieve [BuildOptions]
1206 def BuildOptions(self
):
1207 if self
._BuildOptions
is None:
1208 self
._BuildOptions
= OrderedDict()
1210 # Retrieve build option for EDKII and EDK style module
1212 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1213 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1214 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1215 if Dummy3
.upper() != TAB_COMMON
:
1217 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1219 # Only flags can be appended
1221 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1222 self
._BuildOptions
[CurKey
] = Option
1224 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1225 self
._BuildOptions
[CurKey
] += ' ' + Option
1226 return self
._BuildOptions
1227 def GetBuildOptionsByPkg(self
, Module
, ModuleType
):
1229 local_pkg
= os
.path
.split(Module
.LocalPkg())[0]
1230 if self
._ModuleTypeOptions
is None:
1231 self
._ModuleTypeOptions
= OrderedDict()
1232 if ModuleType
not in self
._ModuleTypeOptions
:
1233 options
= OrderedDict()
1234 self
._ModuleTypeOptions
[ ModuleType
] = options
1235 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1236 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1237 if Dummy2
not in (TAB_COMMON
,local_pkg
.upper(),"EDKII"):
1240 if Type
.upper() == ModuleType
.upper():
1241 Key
= (ToolChainFamily
, ToolChain
)
1242 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1243 options
[Key
] = Option
1245 if ' ' + Option
not in options
[Key
]:
1246 options
[Key
] += ' ' + Option
1247 return self
._ModuleTypeOptions
[ModuleType
]
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 'DEFAULT' in stru_pcd
.SkuOverrideValues
and not GlobalData
.gPcdSkuOverrides
.get((stru_pcd
.TokenCName
, stru_pcd
.TokenSpaceGuidCName
)):
1541 GlobalData
.gPcdSkuOverrides
.update(
1542 {(stru_pcd
.TokenCName
, stru_pcd
.TokenSpaceGuidCName
): {'DEFAULT':stru_pcd
.SkuOverrideValues
['DEFAULT']}})
1543 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1544 for skuid
in SkuIds
:
1547 if skuid
not in stru_pcd
.SkuOverrideValues
:
1548 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1549 if nextskuid
== TAB_DEFAULT
:
1552 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1555 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1556 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1558 for defaultstoreid
in DefaultStores
:
1559 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1560 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = CopyDict(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1561 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1562 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1563 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1564 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1566 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1567 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1568 if str_pcd_obj
is None:
1569 print(PcdName
, PcdGuid
)
1571 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1572 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1573 if skuname
not in str_pcd_obj
.SkuInfoList
:
1574 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1576 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1577 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1578 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1579 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1580 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1581 str_pcd_obj
.DefaultValue
= PcdValue
1583 if skuname
not in str_pcd_obj
.SkuInfoList
:
1584 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1586 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1587 if nextskuid
== TAB_DEFAULT
:
1590 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1591 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
)
1592 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1593 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1595 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1596 for str_pcd_obj
in S_pcd_set
.values():
1597 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1598 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1600 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1601 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1602 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1603 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1605 for str_pcd_obj
in S_pcd_set
.values():
1607 str_pcd_obj
.MaxDatumSize
= DscBuildData
.GetStructurePcdMaxSize(str_pcd_obj
)
1608 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1609 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1613 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1614 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1615 del pcd
.SkuInfoList
[TAB_COMMON
]
1616 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1617 del pcd
.SkuInfoList
[TAB_COMMON
]
1619 list(map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
]))
1622 def PlatformUsedPcds(self
):
1624 if GlobalData
.gFdfParser
:
1625 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1626 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1627 AllModulePcds
= set()
1628 ModuleSet
= set(list(self
._Modules
.keys()) + FdfModuleList
)
1629 for ModuleFile
in ModuleSet
:
1630 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1631 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1632 for ModuleFile
in self
.LibraryInstances
:
1633 ModuleData
= self
._Bdb
.CreateBuildObject(ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
)
1634 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1635 return AllModulePcds
1637 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1638 def FilterStrcturePcd(self
, S_pcd_set
):
1639 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.PlatformUsedPcds
1640 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1641 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1643 ## Retrieve non-dynamic PCD settings
1645 # @param Type PCD type
1647 # @retval a dict object contains settings of given PCD type
1649 def _GetPcd(self
, Type
):
1650 Pcds
= OrderedDict()
1652 # tdict is a special dict kind of type, used for selecting correct
1653 # PCD settings for certain ARCH
1655 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1657 PcdDict
= tdict(True, 4)
1659 # Find out all possible PCD candidates for self._Arch
1660 RecordList
= self
._RawData
[Type
, self
._Arch
]
1661 PcdValueDict
= OrderedDict()
1662 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1663 SkuName
= SkuName
.upper()
1664 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1665 if SkuName
not in AvailableSkuIdSet
:
1666 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1667 File
=self
.MetaFile
, Line
=Dummy5
)
1668 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1669 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
1670 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1671 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1673 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
1674 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1677 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1679 if int(MaxDatumSize
, 0) > 0xFFFF:
1680 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1681 File
=self
.MetaFile
, Line
=Dummy4
)
1682 if int(MaxDatumSize
, 0) < 0:
1683 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1684 File
=self
.MetaFile
, Line
=Dummy4
)
1685 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1686 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
,Dummy4
)
1688 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
,Dummy4
)}
1690 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.items():
1691 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1692 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1693 elif TAB_DEFAULT
in PcdSetting
:
1694 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[TAB_DEFAULT
]
1695 elif TAB_COMMON
in PcdSetting
:
1696 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[TAB_COMMON
]
1702 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1705 self
._PCD
_TYPE
_STRING
_[Type
],
1714 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1715 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1716 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1717 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1718 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
1719 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1720 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Settings
[3])
1724 def GetStructurePcdMaxSize(str_pcd
):
1725 pcd_default_value
= str_pcd
.DefaultValue
1726 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()]
1727 sku_values
.append(pcd_default_value
)
1729 def get_length(value
):
1730 Value
= value
.strip()
1732 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1734 if Value
.startswith('L"') and Value
.endswith('"'):
1735 return len(Value
[2:-1])
1736 if Value
[0] == '"' and Value
[-1] == '"':
1737 return len(Value
) - 2
1738 if Value
.strip().startswith("{CODE("):
1739 tmpValue
= RemoveCComments(Value
)
1740 return len(tmpValue
.split(","))
1741 if (Value
[0] == '{' and Value
[-1] == '}'):
1742 return len(Value
.split(","))
1743 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1744 return len(list(Value
[2:-1]))
1745 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1746 return len(Value
) - 2
1749 return str(max(get_length(item
) for item
in sku_values
))
1752 def ExecuteCommand (Command
):
1754 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1756 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1757 Result
= Process
.communicate()
1758 return Process
.returncode
, Result
[0].decode(), Result
[1].decode()
1761 def IntToCString(Value
, ValueSize
):
1763 if not isinstance (Value
, str):
1764 for Index
in range(0, ValueSize
):
1765 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1767 Result
= Result
+ '"'
1770 def GenerateSizeFunction(self
, Pcd
):
1771 CApp
= "// Default Value in Dec \n"
1772 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1774 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
1775 CApp
+= " *Size = (sizeof (%s) > *Size ? sizeof (%s) : *Size);\n" % (Pcd
.DatumType
,Pcd
.DatumType
)
1777 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1778 CApp
+= " *Size = (sizeof (%s_%s_INIT_Value) > *Size ? sizeof (%s_%s_INIT_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)
1779 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
1780 for skuname
in Pcd
.SkuInfoList
:
1781 skuobj
= Pcd
.SkuInfoList
[skuname
]
1782 if skuobj
.VariableName
:
1783 for defaultstore
in skuobj
.DefaultStoreDict
:
1784 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,defaultstore
)
1786 if "{CODE(" in pcddef
:
1787 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
)
1789 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1791 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1793 if "{CODE(" in pcddef
:
1794 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
)
1796 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1798 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1800 if "{CODE(" in pcddef
:
1801 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
)
1803 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1805 for index
in Pcd
.DefaultValues
:
1807 ActualCap
.append(index
)
1808 FieldList
= Pcd
.DefaultValues
[index
]
1811 for FieldName
in FieldList
:
1812 FieldName
= "." + FieldName
1813 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1814 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1816 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1817 except BadExpression
:
1818 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1819 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1820 Value
, ValueSize
= ParseFieldValue(Value
)
1821 if not Pcd
.IsArray():
1822 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]);
1825 FieldName_ori
= FieldName
.strip('.')
1826 while '[' in FieldName
:
1827 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1828 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1829 FieldName
= FieldName
.split(']', 1)[1]
1830 FieldName
= NewFieldName
+ FieldName
1831 while '[' in FieldName
and not Pcd
.IsArray():
1832 FieldName
= FieldName
.rsplit('[', 1)[0]
1833 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s\n' % (Pcd
.DatumType
, FieldName
.strip("."), Array_Index
+ 1, FieldList
[FieldName_ori
][1], FieldList
[FieldName_ori
][2], FieldList
[FieldName_ori
][0])
1834 for skuname
in Pcd
.SkuOverrideValues
:
1835 if skuname
== TAB_COMMON
:
1837 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1838 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1839 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1841 ActualCap
.append(index
)
1842 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1845 for FieldName
in FieldList
:
1846 FieldName
= "." + FieldName
1847 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1848 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1850 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1851 except BadExpression
:
1852 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1853 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1854 Value
, ValueSize
= ParseFieldValue(Value
)
1855 if not Pcd
.IsArray():
1856 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]);
1859 FieldName_ori
= FieldName
.strip('.')
1860 while '[' in FieldName
:
1861 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1862 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1863 FieldName
= FieldName
.split(']', 1)[1]
1864 FieldName
= NewFieldName
+ FieldName
1865 while '[' in FieldName
and not Pcd
.IsArray():
1866 FieldName
= FieldName
.rsplit('[', 1)[0]
1867 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), Array_Index
+ 1, FieldList
[FieldName_ori
][1], FieldList
[FieldName_ori
][2], FieldList
[FieldName_ori
][0])
1868 if Pcd
.PcdFieldValueFromFdf
:
1869 CApp
= CApp
+ "// From fdf \n"
1870 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1871 FieldName
= "." + FieldName
1872 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1873 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1875 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1876 except BadExpression
:
1877 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1878 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1879 Value
, ValueSize
= ParseFieldValue(Value
)
1880 if not Pcd
.IsArray():
1881 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]);
1884 FieldName_ori
= FieldName
.strip('.')
1885 while '[' in FieldName
:
1886 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1887 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1888 FieldName
= FieldName
.split(']', 1)[1]
1889 FieldName
= NewFieldName
+ FieldName
1890 while '[' in FieldName
:
1891 FieldName
= FieldName
.rsplit('[', 1)[0]
1892 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %s Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), Array_Index
+ 1, Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][1], Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][2], Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][0])
1893 if Pcd
.PcdFieldValueFromComm
:
1894 CApp
= CApp
+ "// From Command Line \n"
1895 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1896 FieldName
= "." + FieldName
1897 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1898 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1900 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1901 except BadExpression
:
1902 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1903 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1904 Value
, ValueSize
= ParseFieldValue(Value
)
1905 if not Pcd
.IsArray():
1906 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]);
1909 FieldName_ori
= FieldName
.strip('.')
1910 while '[' in FieldName
:
1911 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1912 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1913 FieldName
= FieldName
.split(']', 1)[1]
1914 FieldName
= NewFieldName
+ FieldName
1915 while '[' in FieldName
and not Pcd
.IsArray():
1916 FieldName
= FieldName
.rsplit('[', 1)[0]
1917 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), Array_Index
+ 1, Pcd
.PcdFieldValueFromComm
[FieldName_ori
][1], Pcd
.PcdFieldValueFromComm
[FieldName_ori
][2], Pcd
.PcdFieldValueFromComm
[FieldName_ori
][0])
1918 if Pcd
.GetPcdMaxSize():
1919 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1920 ArraySizeByAssign
= self
.CalculateActualCap(ActualCap
)
1921 if ArraySizeByAssign
> 1:
1922 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); \n" % (ArraySizeByAssign
, ArraySizeByAssign
)
1925 def CalculateActualCap(self
,ActualCap
):
1929 for item
in ActualCap
:
1930 index_elements
= ArrayIndex
.findall(item
)
1932 for index_e
in index_elements
:
1933 index_num
= index_e
.lstrip("[").rstrip("]").strip()
1935 # Not support flexiable pcd array assignment
1937 index_num
= int(index_num
,16) if index_num
.startswith(("0x","0X")) else int(index_num
)
1938 rt
= rt
* (index_num
+1)
1945 def GenerateSizeStatments(Pcd
,skuname
,defaultstorename
):
1947 r_datatype
= [Pcd
.BaseDatumType
]
1948 lastoneisEmpty
= False
1949 for dem
in Pcd
.Capacity
:
1951 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. " %
1952 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))))
1953 if dem
== '0' or dem
== "-1":
1954 r_datatype
.append("[1]")
1955 lastoneisEmpty
= True
1957 r_datatype
.append("[" + dem
+ "]")
1959 if Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_HII
, MODEL_PCD_DYNAMIC_HII
]:
1960 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultStoreDict
.get(defaultstorename
)
1961 elif Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_DEFAULT
,MODEL_PCD_DYNAMIC_VPD
,MODEL_PCD_DYNAMIC_DEFAULT
,MODEL_PCD_DYNAMIC_EX_VPD
]:
1962 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultValue
1964 PcdDefValue
= Pcd
.DefaultValue
1966 if "{CODE(" not in PcdDefValue
:
1967 sizebasevalue_plus
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
1968 sizebasevalue
= "(%s / sizeof(%s))" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
1969 sizeof
= "sizeof(%s)" % Pcd
.BaseDatumType
1970 CApp
= ' int ArraySize = %s %% %s ? %s : %s ;\n' % ( (DscBuildData
.GetStructurePcdMaxSize(Pcd
), sizeof
, sizebasevalue_plus
, sizebasevalue
))
1971 CApp
+= ' Size = ArraySize * sizeof(%s); \n' % Pcd
.BaseDatumType
1973 CApp
= " Size = 0;\n"
1975 CApp
= ' Size = sizeof(%s);\n' % ("".join(r_datatype
) )
1977 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1978 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1981 def GetIndicator(self
,index
,FieldName
,Pcd
):
1982 def cleanupindex(indexstr
):
1983 return indexstr
.strip("[").strip("]").strip()
1984 index_elements
= ArrayIndex
.findall(index
)
1985 pcd_capacity
= Pcd
.Capacity
1988 if len(pcd_capacity
)>2:
1989 for i
in range(0,len(index_elements
)):
1990 index_ele
= index_elements
[i
]
1991 index_num
= index_ele
.strip("[").strip("]").strip()
1992 if i
== len(index_elements
) -2:
1993 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
]))
1996 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]))
1997 elif len(pcd_capacity
) == 2:
1998 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
1999 elif len(pcd_capacity
) == 1:
2000 index_ele
= index_elements
[0]
2001 index_num
= index_ele
.strip("[").strip("]").strip()
2002 indicator
+= " + %s)" % (index_num
)
2006 indicator
+= "->" + FieldName
2009 def GetStarNum(self
,Pcd
):
2010 if not Pcd
.IsArray():
2012 elif Pcd
.IsSimpleTypeArray():
2013 return len(Pcd
.Capacity
)
2015 return len(Pcd
.Capacity
) + 1
2016 def GenerateDefaultValueAssignFunction(self
, Pcd
):
2017 CApp
= "// Default value in Dec \n"
2018 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2019 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2020 CApp
= CApp
+ ' CHAR8 *Value;\n'
2021 CApp
= CApp
+ ' UINT32 PcdArraySize;\n'
2022 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
2023 IsArray
= _IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
2026 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
2027 except BadExpression
:
2028 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
2029 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
2030 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
2031 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
2034 # Use memcpy() to copy value into field
2037 pcdarraysize
= Pcd
.PcdArraySize()
2038 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2039 if Pcd
.Capacity
[-1] != "-1":
2040 CApp
= CApp
+ '__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From %s Line %s \n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,pcdarraysize
,Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
,Pcd
.DefaultValueFromDecInfo
[0],Pcd
.DefaultValueFromDecInfo
[1])
2041 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2042 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2044 if Pcd
.Capacity
[-1] != "-1":
2045 CApp
= CApp
+ '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From %s Line %s \n' % (ValueSize
,pcdarraysize
,Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
,Pcd
.DefaultValueFromDecInfo
[0],Pcd
.DefaultValueFromDecInfo
[1])
2046 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2047 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
2048 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2050 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2051 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2052 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2054 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
2055 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2056 elif isinstance(Value
, str):
2057 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
2058 for index
in Pcd
.DefaultValues
:
2059 FieldList
= Pcd
.DefaultValues
[index
]
2062 for FieldName
in FieldList
:
2063 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2066 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2067 except BadExpression
:
2068 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2069 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2072 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2074 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2076 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2079 # Use memcpy() to copy value into field
2081 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2082 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2083 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])
2084 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2085 elif isinstance(Value
, str):
2086 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2088 if '[' in FieldName
and ']' in FieldName
:
2089 Index
= int(FieldName
.split('[')[1].split(']')[0])
2090 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
)
2092 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2094 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2099 def GenerateDefaultValueAssignStatement(Pcd
):
2100 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2103 def GetPcdDscRawDefaultValue(self
,Pcd
, SkuName
,DefaultStoreName
):
2104 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2105 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2106 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2108 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2110 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2112 return pcddefaultvalue
2113 def GetPcdDscRawValueInfo(self
,Pcd
, SkuName
,DefaultStoreName
):
2114 DscValueInfo
= Pcd
.DscRawValueInfo
.get(SkuName
, {}).get(DefaultStoreName
)
2116 dscfilepath
,lineno
= DscValueInfo
2118 dscfilepath
= self
.MetaFile
.File
2120 return dscfilepath
,lineno
2122 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
2123 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
2124 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
2125 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2126 CApp
= CApp
+ ' CHAR8 *Value;\n'
2127 CApp
= CApp
+ ' UINT32 PcdArraySize;\n'
2129 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2130 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2131 dscfilepath
,lineno
= self
.GetPcdDscRawValueInfo(Pcd
, SkuName
, DefaultStoreName
)
2133 valuefrom
= "%s Line %s" % (dscfilepath
,str(lineno
))
2135 valuefrom
= dscfilepath
2137 pcddefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, SkuName
, DefaultStoreName
)
2139 FieldList
= pcddefaultvalue
2140 IsArray
= _IsFieldValueAnArray(FieldList
)
2142 if "{CODE(" not in FieldList
:
2144 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2145 except BadExpression
:
2146 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2147 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2148 Value
, ValueSize
= ParseFieldValue (FieldList
)
2150 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2151 if isinstance(Value
, str):
2152 if "{CODE(" in Value
:
2153 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2154 pcdarraysize
= Pcd
.PcdArraySize()
2155 CApp
= CApp
+ '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,pcdarraysize
,Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
, valuefrom
)
2156 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2157 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2159 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
)
2162 # Use memcpy() to copy value into field
2165 pcdarraysize
= Pcd
.PcdArraySize()
2166 if "{CODE(" in pcddefaultvalue
:
2167 if Pcd
.Capacity
[-1] != "-1":
2168 CApp
= CApp
+ '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,pcdarraysize
,Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
,valuefrom
)
2169 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2170 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2172 if Pcd
.Capacity
[-1] != "-1":
2173 CApp
= CApp
+ '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (ValueSize
,pcdarraysize
,Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
,valuefrom
)
2174 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2175 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
)
2176 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2178 if "{CODE(" in pcddefaultvalue
:
2179 CApp
= CApp
+ ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
,ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
)
2180 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2182 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
)
2183 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2185 if isinstance(Value
, str):
2186 if "{CODE(" in Value
:
2187 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2188 pcdarraysize
= Pcd
.PcdArraySize()
2189 CApp
= CApp
+ '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,pcdarraysize
,Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
,valuefrom
)
2190 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n '% (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2191 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2193 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2196 # Use memcpy() to copy value into field
2199 pcdarraysize
= Pcd
.PcdArraySize()
2200 if "{CODE(" in pcddefaultvalue
:
2201 if Pcd
.Capacity
[-1] != "-1":
2202 CApp
= CApp
+ '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,pcdarraysize
,Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
,valuefrom
)
2203 CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2204 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2206 if Pcd
.Capacity
[-1] != "-1":
2207 CApp
= CApp
+ '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (ValueSize
,pcdarraysize
,Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
,valuefrom
)
2208 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2209 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
, Pcd
.DefaultValue
) if Pcd
.DefaultFromDSC
else Pcd
.DefaultValue
)
2210 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2212 if "{CODE(" in pcddefaultvalue
:
2213 CApp
= CApp
+ ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
,ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
)
2214 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2216 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2217 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2219 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2220 if not inheritvalue
:
2222 for index
in inheritvalue
:
2223 FieldList
= inheritvalue
[index
]
2226 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2227 for FieldName
in FieldList
:
2228 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2229 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2232 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2233 except BadExpression
:
2234 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2235 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2237 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2239 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]))
2240 if isinstance(Value
, str):
2241 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2244 # Use memcpy() to copy value into field
2246 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2247 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2248 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])
2249 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2251 if '[' in FieldName
and ']' in FieldName
:
2252 Index
= int(FieldName
.split('[')[1].split(']')[0])
2253 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
)
2255 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2257 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2262 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2263 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2266 def GenerateCommandLineValue(self
, Pcd
):
2267 CApp
= "// Value in CommandLine\n"
2268 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2269 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2270 CApp
= CApp
+ ' CHAR8 *Value;\n'
2272 pcddefaultvalue
= Pcd
.PcdValueFromComm
2273 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2276 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2277 IsArray
= _IsFieldValueAnArray(FieldList
)
2280 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2281 except BadExpression
:
2282 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2283 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2284 Value
, ValueSize
= ParseFieldValue (FieldList
)
2286 if isinstance(Value
, str):
2287 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2290 # Use memcpy() to copy value into field
2292 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2293 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2295 for FieldName
in FieldList
:
2296 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2299 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2300 except BadExpression
:
2301 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2302 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2306 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2308 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]))
2309 if isinstance(Value
, str):
2310 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2313 # Use memcpy() to copy value into field
2315 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2316 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2317 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])
2318 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2320 if '[' in FieldName
and ']' in FieldName
:
2321 Index
= int(FieldName
.split('[')[1].split(']')[0])
2322 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
)
2324 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2326 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2331 def GenerateCommandLineValueStatement(Pcd
):
2332 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2334 def GenerateFdfValue(self
,Pcd
):
2335 CApp
= "// Value in Fdf\n"
2336 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2337 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2338 CApp
= CApp
+ ' CHAR8 *Value;\n'
2340 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2341 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2344 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2345 IsArray
= _IsFieldValueAnArray(FieldList
)
2348 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2349 except BadExpression
:
2350 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2351 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2352 Value
, ValueSize
= ParseFieldValue (FieldList
)
2354 if isinstance(Value
, str):
2355 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2358 # Use memcpy() to copy value into field
2360 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2361 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2363 for FieldName
in FieldList
:
2364 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2367 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2368 except BadExpression
:
2369 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2370 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2374 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2376 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]))
2377 if isinstance(Value
, str):
2378 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2381 # Use memcpy() to copy value into field
2383 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2384 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2385 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])
2386 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2388 if '[' in FieldName
and ']' in FieldName
:
2389 Index
= int(FieldName
.split('[')[1].split(']')[0])
2390 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
)
2392 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2394 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2399 def GenerateFdfValueStatement(Pcd
):
2400 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2403 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2404 OverrideValues
= {DefaultStore
:{}}
2405 if Pcd
.SkuOverrideValues
:
2406 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2407 if not OverrideValues
:
2408 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2409 for DefaultStoreName
in OverrideValues
:
2410 CApp
= CApp
+ 'void\n'
2411 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2412 CApp
= CApp
+ ' void\n'
2413 CApp
= CApp
+ ' )\n'
2415 CApp
= CApp
+ ' UINT32 Size;\n'
2416 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2417 CApp
= CApp
+ ' CHAR8 *Value;\n'
2418 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2419 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2421 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2425 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2427 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2430 # Get current PCD value and size
2432 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2435 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2436 # the correct value. For structures with a flexible array member, the flexible
2437 # array member is detected, and the size is based on the highest index used with
2438 # the flexible array member. The flexible array member must be the last field
2439 # in a structure. The size formula for this case is:
2440 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2442 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,DefaultStoreName
)
2443 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2444 CApp
= CApp
+ ' OriginalSize = OriginalSize < sizeof(%s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize(),Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2445 CApp
= CApp
+ ' Size = sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2448 # Allocate and zero buffer for the PCD
2449 # Must handle cases where current value is smaller, larger, or same size
2450 # Always keep that larger one as the current size
2452 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2453 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2454 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2457 # Copy current PCD value into allocated buffer.
2459 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2462 # Assign field values in PCD
2464 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2465 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2466 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2467 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2468 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2469 for defaultstorenameitem
in storeset
:
2470 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2471 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2472 if skuname
== SkuName
:
2475 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2476 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2477 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2478 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2480 # Set new PCD value and size
2482 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2487 CApp
= CApp
+ ' free (Pcd);\n'
2490 return InitByteValue
, CApp
2492 def GenerateArrayAssignment(self
, Pcd
):
2497 for d
in Pcd
.Capacity
:
2500 Value
= Pcd
.DefaultValueFromDec
2501 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2502 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2503 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2505 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2506 for skuname
in Pcd
.SkuInfoList
:
2507 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2508 if skuinfo
.VariableName
:
2509 for defaultstore
in skuinfo
.DefaultStoreDict
:
2510 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, defaultstore
)
2511 if pcddscrawdefaultvalue
:
2512 Value
= skuinfo
.DefaultStoreDict
[defaultstore
]
2513 if "{CODE(" in Value
:
2514 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2515 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2517 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, TAB_DEFAULT_STORES_DEFAULT
)
2518 if pcddscrawdefaultvalue
:
2519 Value
= skuinfo
.DefaultValue
2520 if "{CODE(" in Value
:
2521 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2522 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2524 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2525 if pcddscrawdefaultvalue
:
2526 if "{CODE(" in Pcd
.DefaultValue
:
2527 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2528 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2532 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2533 if not OverrideValues
:
2535 for key
in OverrideValues
:
2536 if OverrideValues
[key
]:
2540 def ParseCCFlags(self
, ccflag
):
2542 ccflaglist
= ccflag
.split(" ")
2544 while i
< len(ccflaglist
):
2545 item
= ccflaglist
[i
].strip()
2546 if item
in (r
"/D", r
"/U","-D","-U"):
2547 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2549 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2553 def GenerateByteArrayValue (self
, StructuredPcds
):
2555 # Generate/Compile/Run C application to determine if there are any flexible array members
2557 if not StructuredPcds
:
2561 CApp
= PcdMainCHeader
2563 IncludeFiles
= set()
2564 for PcdName
in StructuredPcds
:
2565 Pcd
= StructuredPcds
[PcdName
]
2566 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2567 if IncludeFile
not in IncludeFiles
:
2568 IncludeFiles
.add(IncludeFile
)
2569 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2571 for Pcd
in StructuredPcds
.values():
2572 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2573 for PcdName
in StructuredPcds
:
2574 Pcd
= StructuredPcds
[PcdName
]
2575 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2576 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2577 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2578 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2579 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2580 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2581 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2583 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2584 if SkuName
not in Pcd
.SkuOverrideValues
:
2586 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2587 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2588 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2589 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2590 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2592 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2593 if SkuName
not in Pcd
.SkuOverrideValues
:
2595 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2596 Pcd
= StructuredPcds
[PcdName
]
2597 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2599 CApp
= CApp
+ 'VOID\n'
2600 CApp
= CApp
+ 'PcdEntryPoint(\n'
2601 CApp
= CApp
+ ' VOID\n'
2602 CApp
= CApp
+ ' )\n'
2604 for Pcd
in StructuredPcds
.values():
2605 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
]]:
2606 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2608 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2609 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2611 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2612 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2615 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2617 if not os
.path
.exists(self
.OutputPath
):
2618 os
.makedirs(self
.OutputPath
)
2619 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2620 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2622 MakeApp
= PcdMakefileHeader
2623 if sys
.platform
== "win32":
2624 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2626 MakeApp
= MakeApp
+ PcdGccMakefile
2627 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2628 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2631 PlatformInc
= OrderedDict()
2632 for Cache
in self
._Bdb
._CACHE
_.values():
2633 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2636 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2637 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2638 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2639 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2642 for Pcd
in StructuredPcds
.values():
2643 for PackageDec
in Pcd
.PackageDecs
:
2644 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2645 if not os
.path
.exists(Package
):
2646 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2647 if Package
not in PcdDependDEC
:
2648 PcdDependDEC
.append(Package
)
2650 if PlatformInc
and PcdDependDEC
:
2651 for pkg
in PcdDependDEC
:
2652 if pkg
in PlatformInc
:
2653 for inc
in PlatformInc
[pkg
]:
2654 MakeApp
+= '-I' + str(inc
) + ' '
2655 IncSearchList
.append(inc
)
2656 MakeApp
= MakeApp
+ '\n'
2658 CC_FLAGS
= LinuxCFLAGS
2659 if sys
.platform
== "win32":
2660 CC_FLAGS
= WindowsCFLAGS
2661 BuildOptions
= OrderedDict()
2662 for Options
in self
.BuildOptions
:
2663 if Options
[2] != EDKII_NAME
:
2666 if Family
and Family
!= self
.ToolChainFamily
:
2668 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2673 if Target
== TAB_STAR
or Target
== self
._Target
:
2674 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2675 if 'COMMON' not in BuildOptions
:
2676 BuildOptions
['COMMON'] = set()
2677 if Arch
== TAB_STAR
:
2678 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2679 if Arch
in self
.SupArchList
:
2680 if Arch
not in BuildOptions
:
2681 BuildOptions
[Arch
] = set()
2682 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2685 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2686 if len(ArchBuildOptions
.keys()) == 1:
2687 BuildOptions
['COMMON'] |
= (list(ArchBuildOptions
.values())[0])
2688 elif len(ArchBuildOptions
.keys()) > 1:
2689 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2690 BuildOptions
['COMMON'] |
= CommonBuildOptions
2691 ValueList
= [item
for item
in BuildOptions
['COMMON'] if item
.startswith((r
"/U","-U"))]
2692 ValueList
.extend([item
for item
in BuildOptions
['COMMON'] if item
.startswith((r
"/D", "-D"))])
2693 CC_FLAGS
+= " ".join(ValueList
)
2696 if sys
.platform
== "win32":
2697 MakeApp
= MakeApp
+ PcdMakefileEnd
2698 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2700 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2701 MakeApp
= MakeApp
+ '\n'
2702 IncludeFileFullPaths
= []
2703 for includefile
in IncludeFiles
:
2704 for includepath
in IncSearchList
:
2705 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2706 if os
.path
.exists(includefullpath
):
2707 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2710 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2711 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2712 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2713 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2714 for include_file
in IncFileList
:
2715 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2716 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2717 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2718 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2720 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2721 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2722 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2724 Dest_PcdValueInitExe
= PcdValueInitName
2725 if not sys
.platform
== "win32":
2726 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2728 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2730 if sys
.platform
== "win32":
2731 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2732 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2735 MakeCommand
= 'make -f %s' % (MakeFileName
)
2736 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2739 Messages
= Messages
.split('\n')
2742 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2743 File
= open (CAppBaseFileName
+ '.c', 'r')
2744 FileData
= File
.readlines()
2746 for Message
in Messages
:
2747 if " error" in Message
or "warning" in Message
:
2748 FileInfo
= Message
.strip().split('(')
2749 if len (FileInfo
) > 1:
2750 FileName
= FileInfo
[0]
2751 FileLine
= FileInfo
[1].split (')')[0]
2753 FileInfo
= Message
.strip().split(':')
2754 if len(FileInfo
) < 2:
2756 FileName
= FileInfo
[0]
2757 FileLine
= FileInfo
[1]
2758 if FileLine
.isdigit():
2759 error_line
= FileData
[int (FileLine
) - 1]
2760 if r
"//" in error_line
:
2761 c_line
, dsc_line
= error_line
.split(r
"//")
2763 dsc_line
= error_line
2764 message_itmes
= Message
.split(":")
2766 if "PcdValueInit.c" not in Message
:
2767 if not MessageGroup
:
2768 MessageGroup
.append(Message
)
2771 for item
in message_itmes
:
2772 if "PcdValueInit.c" in item
:
2773 Index
= message_itmes
.index(item
)
2774 message_itmes
[Index
] = dsc_line
.strip()
2776 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2779 MessageGroup
.append(Message
)
2781 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2783 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2785 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
2786 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2787 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2789 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2791 File
= open (OutputValueFile
, 'r')
2792 FileBuffer
= File
.readlines()
2795 StructurePcdSet
= []
2796 for Pcd
in FileBuffer
:
2797 PcdValue
= Pcd
.split ('|')
2798 PcdInfo
= PcdValue
[0].split ('.')
2799 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2800 return StructurePcdSet
2803 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2804 if not os
.path
.exists(OutputFile
):
2806 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2808 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2812 ## Retrieve dynamic PCD settings
2814 # @param Type PCD type
2816 # @retval a dict object contains settings of given PCD type
2818 def _GetDynamicPcd(self
, Type
):
2821 Pcds
= OrderedDict()
2823 # tdict is a special dict kind of type, used for selecting correct
2824 # PCD settings for certain ARCH and SKU
2826 PcdDict
= tdict(True, 4)
2828 # Find out all possible PCD candidates for self._Arch
2829 RecordList
= self
._RawData
[Type
, self
._Arch
]
2830 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2833 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2834 SkuName
= SkuName
.upper()
2835 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2836 if SkuName
not in AvailableSkuIdSet
:
2837 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2838 File
=self
.MetaFile
, Line
=Dummy5
)
2839 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
2840 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2841 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2843 # Remove redundant PCD candidates, per the ARCH and SKU
2844 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2846 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2850 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2852 if int(MaxDatumSize
, 0) > 0xFFFF:
2853 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2854 File
=self
.MetaFile
, Line
=Dummy4
)
2855 if int(MaxDatumSize
, 0) < 0:
2856 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2857 File
=self
.MetaFile
, Line
=Dummy4
)
2858 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2859 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2860 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2861 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2862 if MaxDatumSize
.strip():
2863 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2866 if pcdObject
.MaxDatumSize
:
2867 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2870 if CurrentMaxSize
> PcdMaxSize
:
2871 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2873 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2876 self
._PCD
_TYPE
_STRING
_[Type
],
2881 OrderedDict({SkuName
: SkuInfo
}),
2886 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2887 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2888 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
2889 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2890 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Dummy4
)
2892 for pcd
in Pcds
.values():
2893 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2894 # Only fix the value while no value provided in DSC file.
2895 for sku
in pcd
.SkuInfoList
.values():
2896 if not sku
.DefaultValue
:
2897 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2898 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2899 valuefromDec
= pcdDecObject
.DefaultValue
2900 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2901 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2902 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2903 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2904 del pcd
.SkuInfoList
[TAB_COMMON
]
2905 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2906 del pcd
.SkuInfoList
[TAB_COMMON
]
2908 list(map(self
.FilterSkuSettings
, Pcds
.values()))
2912 def FilterSkuSettings(self
, PcdObj
):
2914 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2915 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2916 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2917 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2918 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2919 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2921 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2922 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2927 def CompareVarAttr(Attr1
, Attr2
):
2928 if not Attr1
or not Attr2
: # for empty string
2930 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2931 Attr1Set
= set(Attr1s
)
2932 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2933 Attr2Set
= set(Attr2s
)
2934 if Attr2Set
== Attr1Set
:
2939 def CompletePcdValues(self
, PcdSet
):
2940 Pcds
= OrderedDict()
2941 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2942 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2943 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2944 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2945 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2947 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2948 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2949 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2950 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2951 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2952 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2953 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2955 PcdType
= PcdObj
.Type
2956 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2957 for skuid
in PcdObj
.SkuInfoList
:
2958 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2959 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2960 for defaultstorename
in DefaultStores
:
2961 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2962 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
2963 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2964 for skuname
, skuid
in SkuIds
.items():
2965 if skuname
not in PcdObj
.SkuInfoList
:
2966 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2967 while nextskuid
not in PcdObj
.SkuInfoList
:
2968 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2969 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2970 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2971 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2972 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2973 PcdObj
.DefaultValue
= list(PcdObj
.SkuInfoList
.values())[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2974 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2976 ## Retrieve dynamic HII PCD settings
2978 # @param Type PCD type
2980 # @retval a dict object contains settings of given PCD type
2982 def _GetDynamicHiiPcd(self
, Type
):
2986 Pcds
= OrderedDict()
2987 UserDefinedDefaultStores
= []
2989 # tdict is a special dict kind of type, used for selecting correct
2990 # PCD settings for certain ARCH and SKU
2992 PcdDict
= tdict(True, 5)
2994 RecordList
= self
._RawData
[Type
, self
._Arch
]
2995 # Find out all possible PCD candidates for self._Arch
2996 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2997 DefaultStoresDefine
= self
._GetDefaultStores
()
2999 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
3000 SkuName
= SkuName
.upper()
3001 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3002 DefaultStore
= DefaultStore
.upper()
3003 if DefaultStore
== TAB_COMMON
:
3004 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
3006 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
3007 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
3008 if SkuName
not in AvailableSkuIdSet
:
3009 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3010 File
=self
.MetaFile
, Line
=Dummy5
)
3011 if DefaultStore
not in DefaultStoresDefine
:
3012 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
3013 File
=self
.MetaFile
, Line
=Dummy5
)
3014 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
) not in PcdList
:
3015 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
3016 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
3019 # Remove redundant PCD candidates, per the ARCH and SKU
3020 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdList
:
3022 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
3025 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3027 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
3029 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
3030 ExtraData
="[%s]" % VarAttribute
)
3032 FormatCorrect
= True
3033 if VariableOffset
.isdigit():
3034 if int(VariableOffset
, 10) > 0xFFFF:
3036 elif variablePattern
.match(VariableOffset
):
3037 if int(VariableOffset
, 16) > 0xFFFF:
3039 # For Offset written in "A.B"
3040 elif VariableOffset
.find('.') > -1:
3041 VariableOffsetList
= VariableOffset
.split(".")
3042 if not (len(VariableOffsetList
) == 2
3043 and IsValidWord(VariableOffsetList
[0])
3044 and IsValidWord(VariableOffsetList
[1])):
3045 FormatCorrect
= False
3047 FormatCorrect
= False
3048 if not FormatCorrect
:
3049 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
3052 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
3053 if (VariableName
, VariableGuid
) not in VariableAttrs
:
3054 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
3056 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
3057 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
)]))
3059 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
3060 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3061 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3062 if SkuName
in pcdObject
.SkuInfoList
:
3063 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
3064 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
3066 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
3067 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3069 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
3070 PcdClassObj
= PcdClassObject(
3073 self
._PCD
_TYPE
_STRING
_[Type
],
3078 OrderedDict({SkuName
: SkuInfo
}),
3081 pcdDecObject
.validateranges
,
3082 pcdDecObject
.validlists
,
3083 pcdDecObject
.expressions
,
3085 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
3086 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
3087 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
3089 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
3090 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3091 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3092 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3093 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
3094 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][DefaultStore
] = (self
.MetaFile
.File
,Dummy4
)
3095 for pcd
in Pcds
.values():
3096 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3097 pcd
.DatumType
= pcdDecObject
.DatumType
3098 # Only fix the value while no value provided in DSC file.
3099 for sku
in pcd
.SkuInfoList
.values():
3100 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
3101 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
3102 for default_store
in sku
.DefaultStoreDict
:
3103 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
3104 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
3105 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3106 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3107 valuefromDec
= pcdDecObject
.DefaultValue
3108 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
3109 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3110 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3111 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3112 del pcd
.SkuInfoList
[TAB_COMMON
]
3113 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3114 del pcd
.SkuInfoList
[TAB_COMMON
]
3116 if pcd
.MaxDatumSize
.strip():
3117 MaxSize
= int(pcd
.MaxDatumSize
, 0)
3120 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
3121 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
3123 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
3124 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
3125 if datalen
> MaxSize
:
3127 for defaultst
in skuobj
.DefaultStoreDict
:
3128 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
3129 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
3130 pcd
.MaxDatumSize
= str(MaxSize
)
3131 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
3133 invalidpcd
= ",".join(invalidhii
)
3134 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
)
3136 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3141 def CheckVariableNameAssignment(Pcds
):
3143 for pcdname
in Pcds
:
3145 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
3146 if len(varnameset
) > 1:
3147 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
3149 return False, invalidhii
3152 ## Retrieve dynamic VPD PCD settings
3154 # @param Type PCD type
3156 # @retval a dict object contains settings of given PCD type
3158 def _GetDynamicVpdPcd(self
, Type
):
3161 Pcds
= OrderedDict()
3163 # tdict is a special dict kind of type, used for selecting correct
3164 # PCD settings for certain ARCH and SKU
3166 PcdDict
= tdict(True, 4)
3169 # Find out all possible PCD candidates for self._Arch
3170 RecordList
= self
._RawData
[Type
, self
._Arch
]
3171 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3173 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3174 SkuName
= SkuName
.upper()
3175 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3176 if SkuName
not in AvailableSkuIdSet
:
3177 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3178 File
=self
.MetaFile
, Line
=Dummy5
)
3179 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
3180 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3181 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3183 # Remove redundant PCD candidates, per the ARCH and SKU
3184 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3185 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3189 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3190 # For the Integer & Boolean type, the optional data can only be InitialValue.
3191 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3192 # until the DEC parser has been called.
3194 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3196 if int(MaxDatumSize
, 0) > 0xFFFF:
3197 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3198 File
=self
.MetaFile
, Line
=Dummy4
)
3199 if int(MaxDatumSize
, 0) < 0:
3200 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3201 File
=self
.MetaFile
, Line
=Dummy4
)
3202 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3203 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3204 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3205 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3206 if MaxDatumSize
.strip():
3207 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3210 if pcdObject
.MaxDatumSize
:
3211 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3214 if CurrentMaxSize
> PcdMaxSize
:
3215 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3217 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3220 self
._PCD
_TYPE
_STRING
_[Type
],
3225 OrderedDict({SkuName
: SkuInfo
}),
3230 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3231 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3232 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3233 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3234 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Dummy4
)
3235 for pcd
in Pcds
.values():
3236 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3237 pcd
.DatumType
= pcdDecObject
.DatumType
3238 # Only fix the value while no value provided in DSC file.
3239 for sku
in pcd
.SkuInfoList
.values():
3240 if not sku
.DefaultValue
:
3241 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3242 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3243 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3244 valuefromDec
= pcdDecObject
.DefaultValue
3245 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3246 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3247 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3248 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3249 del pcd
.SkuInfoList
[TAB_COMMON
]
3250 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3251 del pcd
.SkuInfoList
[TAB_COMMON
]
3253 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3254 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3255 for pcd
in Pcds
.values():
3256 PcdValueTypeSet
= set()
3257 for sku
in pcd
.SkuInfoList
.values():
3258 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3259 if len(PcdValueTypeSet
) > 1:
3260 for sku
in pcd
.SkuInfoList
.values():
3261 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3263 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3266 ## Add external modules
3268 # The external modules are mostly those listed in FDF file, which don't
3271 # @param FilePath The path of module description file
3273 def AddModule(self
, FilePath
):
3274 FilePath
= NormPath(FilePath
)
3275 if FilePath
not in self
.Modules
:
3276 Module
= ModuleBuildClassObject()
3277 Module
.MetaFile
= FilePath
3278 self
.Modules
.append(Module
)
3281 def ToolChainFamily(self
):
3282 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3283 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
3284 if os
.path
.isfile(BuildConfigurationFile
) == True:
3285 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3286 if ToolDefinitionFile
== '':
3287 ToolDefinitionFile
= "tools_def.txt"
3288 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
3289 if os
.path
.isfile(ToolDefinitionFile
) == True:
3290 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
3291 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3292 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3293 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3294 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3296 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3297 return self
._ToolChainFamily
3299 ## Add external PCDs
3301 # The external PCDs are mostly those listed in FDF file to specify address
3302 # or offset information.
3304 # @param Name Name of the PCD
3305 # @param Guid Token space guid of the PCD
3306 # @param Value Value of the PCD
3308 def AddPcd(self
, Name
, Guid
, Value
):
3309 if (Name
, Guid
) not in self
.Pcds
:
3310 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3311 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3315 if self
._DecPcds
is None:
3317 if GlobalData
.gFdfParser
:
3318 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3320 for Inf
in FdfInfList
:
3321 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3322 if ModuleFile
in self
._Modules
:
3324 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3325 PkgSet
.update(ModuleData
.Packages
)
3326 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3327 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3328 return self
._DecPcds