2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2020, 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 TargetTxtDict
23 from Common
.ToolDefClassObject
import ToolDefDict
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'
58 PcdValueCommonName
= 'PcdValueCommon'
69 #include <PcdValueCommon.h>
79 return PcdValueMain (argc, argv);
83 PcdMakefileHeader
= '''
86 # This file is auto-generated by build utility
91 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
92 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
94 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
95 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
100 $(APPFILE): $(OBJECTS)
105 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
109 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
110 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
111 ## regular expressions for finding decimal and hex numbers
112 Pattern
= re
.compile('^[1-9]\d*|0$')
113 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
114 ## Regular expression for finding header file inclusions
115 from AutoGen
.GenMake
import gIncludePattern
117 ## Find dependencies for one source file
119 # By searching recursively "#include" directive in file, find out all the
120 # files needed by given source file. The dependecies will be only searched
121 # in given search path list.
123 # @param SearchPathList The list of search path
125 # @retval list The list of files the given source file depends on
127 def GetDependencyList(FileStack
, SearchPathList
):
129 DependencySet
= set(FileStack
)
130 while len(FileStack
) > 0:
132 FullPathDependList
= []
133 CurrentFileDependencyList
= []
135 CurrentFileDependencyList
= DepDb
[F
]
139 FileContent
= Fd
.read()
140 except BaseException
as X
:
141 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
143 if "Fd" in dir(locals()):
146 if len(FileContent
) == 0:
150 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
151 FileContent
= FileContent
.decode('utf-16')
153 FileContent
= FileContent
.decode()
155 # The file is not txt file. for example .mcb file
157 IncludedFileList
= gIncludePattern
.findall(FileContent
)
159 for Inc
in IncludedFileList
:
161 Inc
= os
.path
.normpath(Inc
)
162 CurrentFileDependencyList
.append(Inc
)
163 DepDb
[F
] = CurrentFileDependencyList
165 CurrentFilePath
= os
.path
.dirname(F
)
166 PathList
= [CurrentFilePath
] + SearchPathList
167 for Inc
in CurrentFileDependencyList
:
168 for SearchPath
in PathList
:
169 FilePath
= os
.path
.join(SearchPath
, Inc
)
170 if not os
.path
.exists(FilePath
):
172 if FilePath
not in DependencySet
:
173 FileStack
.append(FilePath
)
174 FullPathDependList
.append(FilePath
)
176 DependencySet
.update(FullPathDependList
)
177 DependencyList
= list(DependencySet
) # remove duplicate ones
179 return DependencyList
181 class DscBuildData(PlatformBuildClassObject
):
182 # dict used to convert PCD type in database to string used by build tool
183 _PCD_TYPE_STRING_
= {
184 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
185 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
186 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
187 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
188 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
189 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
190 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
191 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
192 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
193 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
194 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
197 # dict used to convert part of [Defines] to members of DscBuildData directly
202 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
203 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
204 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
205 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
206 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
207 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
208 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
209 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
210 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
211 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
212 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
213 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
214 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
215 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
216 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
219 # used to compose dummy library class name for those forced library instances
220 _NullLibraryNumber
= 0
222 ## Constructor of DscBuildData
224 # Initialize object of DscBuildData
226 # @param FilePath The path of platform description file
227 # @param RawData The raw data of DSC file
228 # @param BuildDataBase Database used to retrieve module/package information
229 # @param Arch The target architecture
230 # @param Platform (not used for DscBuildData)
231 # @param Macros Macros used for replacement in DSC file
233 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
234 self
.MetaFile
= FilePath
235 self
._RawData
= RawData
236 self
._Bdb
= BuildDataBase
238 self
._Target
= Target
239 self
._Toolchain
= Toolchain
240 self
._ToolChainFamily
= None
242 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
243 self
.DefaultStores
= None
244 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
247 def OutputPath(self
):
248 if os
.getenv("WORKSPACE"):
249 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
251 return os
.path
.dirname(self
.DscFile
)
254 def __setitem__(self
, key
, value
):
255 self
.__dict
__[self
._PROPERTY
_[key
]] = value
258 def __getitem__(self
, key
):
259 return self
.__dict
__[self
._PROPERTY
_[key
]]
262 def __contains__(self
, key
):
263 return key
in self
._PROPERTY
_
265 ## Set all internal used members of DscBuildData to None
268 self
._PlatformName
= None
271 self
._DscSpecification
= None
272 self
._OutputDirectory
= None
273 self
._SupArchList
= None
274 self
._BuildTargets
= None
276 self
._PcdInfoFlag
= None
277 self
._VarCheckFlag
= None
278 self
._FlashDefinition
= None
279 self
._Prebuild
= None
280 self
._Postbuild
= None
281 self
._BuildNumber
= None
282 self
._MakefileName
= None
283 self
._BsBaseAddress
= None
284 self
._RtBaseAddress
= None
287 self
._LibraryInstances
= None
288 self
._LibraryClasses
= None
291 self
._BuildOptions
= None
292 self
._ModuleTypeOptions
= None
293 self
._LoadFixAddress
= None
294 self
._RFCLanguages
= None
295 self
._ISOLanguages
= None
296 self
._VpdToolGuid
= None
297 self
._MacroDict
= None
298 self
.DefaultStores
= None
300 ## Get current effective macros
303 if self
._MacroDict
is None:
305 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
306 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
307 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
308 return self
._MacroDict
316 return self
.MetaFile
.Dir
318 ## Retrieve all information in [Defines] section
320 # (Retrieving all [Defines] information in one-shot is just to save time.)
322 def _GetHeaderInfo(self
):
323 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
324 for Record
in RecordList
:
326 # items defined _PROPERTY_ don't need additional processing
328 # some special items in [Defines] section need special treatment
329 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
330 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
331 if ' ' in self
._OutputDirectory
:
332 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
333 File
=self
.MetaFile
, Line
=Record
[-1],
334 ExtraData
=self
._OutputDirectory
)
335 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
336 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
337 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
339 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
341 elif Name
== TAB_DSC_PREBUILD
:
342 PrebuildValue
= Record
[2]
343 if Record
[2][0] == '"':
344 if Record
[2][-1] != '"':
345 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
346 File
=self
.MetaFile
, Line
=Record
[-1])
347 PrebuildValue
= Record
[2][1:-1]
348 self
._Prebuild
= PrebuildValue
349 elif Name
== TAB_DSC_POSTBUILD
:
350 PostbuildValue
= Record
[2]
351 if Record
[2][0] == '"':
352 if Record
[2][-1] != '"':
353 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
354 File
=self
.MetaFile
, Line
=Record
[-1])
355 PostbuildValue
= Record
[2][1:-1]
356 self
._Postbuild
= PostbuildValue
357 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
358 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
359 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
360 self
._BuildTargets
= GetSplitValueList(Record
[2])
361 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
362 if self
._SkuName
is None:
363 self
._SkuName
= Record
[2]
364 if GlobalData
.gSKUID_CMD
:
365 self
._SkuName
= GlobalData
.gSKUID_CMD
366 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
367 self
._PcdInfoFlag
= Record
[2]
368 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
369 self
._VarCheckFlag
= Record
[2]
370 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
372 self
._LoadFixAddress
= int (Record
[2], 0)
374 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
375 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
376 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
377 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"',
378 File
=self
.MetaFile
, Line
=Record
[-1])
379 LanguageCodes
= Record
[2][1:-1]
380 if not LanguageCodes
:
381 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
382 File
=self
.MetaFile
, Line
=Record
[-1])
383 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
384 # check whether there is empty entries in the list
385 if None in LanguageList
:
386 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
387 File
=self
.MetaFile
, Line
=Record
[-1])
388 self
._RFCLanguages
= LanguageList
389 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
390 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
391 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
392 File
=self
.MetaFile
, Line
=Record
[-1])
393 LanguageCodes
= Record
[2][1:-1]
394 if not LanguageCodes
:
395 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
396 File
=self
.MetaFile
, Line
=Record
[-1])
397 if len(LanguageCodes
) % 3:
398 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
399 File
=self
.MetaFile
, Line
=Record
[-1])
401 for i
in range(0, len(LanguageCodes
), 3):
402 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
403 self
._ISOLanguages
= LanguageList
404 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
406 # try to convert GUID to a real UUID value to see whether the GUID is format
407 # for VPD_TOOL_GUID is correct.
412 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
413 self
._VpdToolGuid
= Record
[2]
415 self
[Name
] = Record
[2]
416 # set _Header to non-None in order to avoid database re-querying
417 self
._Header
= 'DUMMY'
419 ## Retrieve platform name
421 def PlatformName(self
):
422 if self
._PlatformName
is None:
423 if self
._Header
is None:
424 self
._GetHeaderInfo
()
425 if self
._PlatformName
is None:
426 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
427 return self
._PlatformName
431 return self
.PlatformName
433 ## Retrieve file guid
436 if self
._Guid
is None:
437 if self
._Header
is None:
438 self
._GetHeaderInfo
()
439 if self
._Guid
is None:
440 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
443 ## Retrieve platform version
446 if self
._Version
is None:
447 if self
._Header
is None:
448 self
._GetHeaderInfo
()
449 if self
._Version
is None:
450 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
453 ## Retrieve platform description file version
455 def DscSpecification(self
):
456 if self
._DscSpecification
is None:
457 if self
._Header
is None:
458 self
._GetHeaderInfo
()
459 if self
._DscSpecification
is None:
460 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
461 return self
._DscSpecification
463 ## Retrieve OUTPUT_DIRECTORY
465 def OutputDirectory(self
):
466 if self
._OutputDirectory
is None:
467 if self
._Header
is None:
468 self
._GetHeaderInfo
()
469 if self
._OutputDirectory
is None:
470 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
471 return self
._OutputDirectory
473 ## Retrieve SUPPORTED_ARCHITECTURES
475 def SupArchList(self
):
476 if self
._SupArchList
is None:
477 if self
._Header
is None:
478 self
._GetHeaderInfo
()
479 if self
._SupArchList
is None:
480 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
481 return self
._SupArchList
483 ## Retrieve BUILD_TARGETS
485 def BuildTargets(self
):
486 if self
._BuildTargets
is None:
487 if self
._Header
is None:
488 self
._GetHeaderInfo
()
489 if self
._BuildTargets
is None:
490 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
491 return self
._BuildTargets
494 def PcdInfoFlag(self
):
495 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
497 elif self
._PcdInfoFlag
.upper() == 'TRUE':
503 def VarCheckFlag(self
):
504 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
506 elif self
._VarCheckFlag
.upper() == 'TRUE':
511 # # Retrieve SKUID_IDENTIFIER
514 if self
._SkuName
is None:
515 if self
._Header
is None:
516 self
._GetHeaderInfo
()
517 if self
._SkuName
is None:
518 self
._SkuName
= TAB_DEFAULT
521 ## Override SKUID_IDENTIFIER
523 def SkuName(self
, Value
):
524 self
._SkuName
= Value
527 def FlashDefinition(self
):
528 if self
._FlashDefinition
is None:
529 if self
._Header
is None:
530 self
._GetHeaderInfo
()
531 if self
._FlashDefinition
is None:
532 self
._FlashDefinition
= ''
533 return self
._FlashDefinition
537 if self
._Prebuild
is None:
538 if self
._Header
is None:
539 self
._GetHeaderInfo
()
540 if self
._Prebuild
is None:
542 return self
._Prebuild
546 if self
._Postbuild
is None:
547 if self
._Header
is None:
548 self
._GetHeaderInfo
()
549 if self
._Postbuild
is None:
551 return self
._Postbuild
553 ## Retrieve FLASH_DEFINITION
555 def BuildNumber(self
):
556 if self
._BuildNumber
is None:
557 if self
._Header
is None:
558 self
._GetHeaderInfo
()
559 if self
._BuildNumber
is None:
560 self
._BuildNumber
= ''
561 return self
._BuildNumber
563 ## Retrieve MAKEFILE_NAME
565 def MakefileName(self
):
566 if self
._MakefileName
is None:
567 if self
._Header
is None:
568 self
._GetHeaderInfo
()
569 if self
._MakefileName
is None:
570 self
._MakefileName
= ''
571 return self
._MakefileName
573 ## Retrieve BsBaseAddress
575 def BsBaseAddress(self
):
576 if self
._BsBaseAddress
is None:
577 if self
._Header
is None:
578 self
._GetHeaderInfo
()
579 if self
._BsBaseAddress
is None:
580 self
._BsBaseAddress
= ''
581 return self
._BsBaseAddress
583 ## Retrieve RtBaseAddress
585 def RtBaseAddress(self
):
586 if self
._RtBaseAddress
is None:
587 if self
._Header
is None:
588 self
._GetHeaderInfo
()
589 if self
._RtBaseAddress
is None:
590 self
._RtBaseAddress
= ''
591 return self
._RtBaseAddress
593 ## Retrieve the top address for the load fix address
595 def LoadFixAddress(self
):
596 if self
._LoadFixAddress
is None:
597 if self
._Header
is None:
598 self
._GetHeaderInfo
()
600 if self
._LoadFixAddress
is None:
601 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
604 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
606 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
609 # If command line defined, should override the value in DSC file.
611 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
613 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
615 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']))
617 if self
._LoadFixAddress
< 0:
618 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
619 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
620 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
622 return self
._LoadFixAddress
624 ## Retrieve RFCLanguage filter
626 def RFCLanguages(self
):
627 if self
._RFCLanguages
is None:
628 if self
._Header
is None:
629 self
._GetHeaderInfo
()
630 if self
._RFCLanguages
is None:
631 self
._RFCLanguages
= []
632 return self
._RFCLanguages
634 ## Retrieve ISOLanguage filter
636 def ISOLanguages(self
):
637 if self
._ISOLanguages
is None:
638 if self
._Header
is None:
639 self
._GetHeaderInfo
()
640 if self
._ISOLanguages
is None:
641 self
._ISOLanguages
= []
642 return self
._ISOLanguages
644 ## Retrieve the GUID string for VPD tool
646 def VpdToolGuid(self
):
647 if self
._VpdToolGuid
is None:
648 if self
._Header
is None:
649 self
._GetHeaderInfo
()
650 if self
._VpdToolGuid
is None:
651 self
._VpdToolGuid
= ''
652 return self
._VpdToolGuid
654 ## Retrieve [SkuIds] section information
657 if self
._SkuIds
is None:
658 self
._SkuIds
= OrderedDict()
659 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
660 for Record
in RecordList
:
662 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
663 File
=self
.MetaFile
, Line
=Record
[-1])
665 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
666 File
=self
.MetaFile
, Line
=Record
[-1])
667 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
668 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
669 File
=self
.MetaFile
, Line
=Record
[-1])
670 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
671 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_)*'",
672 File
=self
.MetaFile
, Line
=Record
[-1])
673 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
674 if TAB_DEFAULT
not in self
._SkuIds
:
675 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
676 if TAB_COMMON
not in self
._SkuIds
:
677 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
682 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
684 def _GetDefaultStores(self
):
685 if self
.DefaultStores
is None:
686 self
.DefaultStores
= OrderedDict()
687 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
688 for Record
in RecordList
:
690 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
691 File
=self
.MetaFile
, Line
=Record
[-1])
693 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
694 File
=self
.MetaFile
, Line
=Record
[-1])
695 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
696 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
697 File
=self
.MetaFile
, Line
=Record
[-1])
698 if not IsValidWord(Record
[1]):
699 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_-.)*'",
700 File
=self
.MetaFile
, Line
=Record
[-1])
701 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
702 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
703 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
704 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
705 return self
.DefaultStores
707 def OverrideDuplicateModule(self
):
708 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
709 Macros
= self
._Macros
711 for Record
in RecordList
:
713 file_guid
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
714 file_guid_str
= file_guid
[0][2] if file_guid
else "NULL"
715 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
716 if self
._Arch
!= TAB_ARCH_COMMON
and (file_guid_str
,str(ModuleFile
)) in Components
:
717 self
._RawData
.DisableOverrideComponent(Components
[(file_guid_str
,str(ModuleFile
))])
718 Components
[(file_guid_str
,str(ModuleFile
))] = ModuleId
719 self
._RawData
._PostProcessed
= False
721 ## Retrieve packages this Platform depends on
725 RecordList
= self
._RawData
[MODEL_META_DATA_PACKAGE
, self
._Arch
]
726 Macros
= self
._Macros
727 for Record
in RecordList
:
728 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
729 # check the file validation
730 ErrorCode
, ErrorInfo
= File
.Validate('.dec')
733 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
734 # parse this package now. we need it to get protocol/ppi/guid value
735 RetVal
.add(self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
])
738 ## Retrieve [Components] section information
741 if self
._Modules
is not None:
743 self
.OverrideDuplicateModule()
744 self
._Modules
= OrderedDict()
745 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
746 Macros
= self
._Macros
747 for Record
in RecordList
:
748 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
752 # check the file validation
753 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
755 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
758 ModuleBuildData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
759 Module
= ModuleBuildClassObject()
760 Module
.MetaFile
= ModuleFile
761 Module
.Guid
= ModuleBuildData
.Guid
762 # get module private library instance
763 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
764 for Record
in RecordList
:
765 LibraryClass
= Record
[0]
766 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
769 # check the file validation
770 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
772 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
775 if LibraryClass
== '' or LibraryClass
== 'NULL':
776 self
._NullLibraryNumber
+= 1
777 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
778 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
779 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
780 if LibraryPath
not in self
.LibraryInstances
:
781 self
.LibraryInstances
.append(LibraryPath
)
783 # get module private PCD setting
784 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
785 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
786 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
787 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
788 TokenList
= GetSplitValueList(Setting
)
789 DefaultValue
= TokenList
[0]
790 # the format is PcdName| Value | VOID* | MaxDatumSize
791 if len(TokenList
) > 2:
792 MaxDatumSize
= TokenList
[2]
795 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
797 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
799 if ("." in TokenSpaceGuid
or "[" in PcdCName
):
800 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, ModuleBuildData
.Guid
, "", Dummy5
, AnalyzePcdExpression(Setting
)[0]])
802 if ( PCName
,TCName
) not in Module
.Pcds
:
803 Pcd
= PcdClassObject(
815 Module
.Pcds
[PCName
, TCName
] = Pcd
817 Module
.StrPcdSet
= S_PcdSet
818 for TCName
,PCName
, _
,_
,_
,_
,_
,_
in S_PcdSet
:
819 if (PCName
,TCName
) in Module
.Pcds
:
820 Module
.StrPcdOverallValue
[(PCName
,TCName
)] = Module
.Pcds
[(PCName
,TCName
)].DefaultValue
, self
.MetaFile
,Dummy5
821 # get module private build options
822 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
823 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
824 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
825 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
827 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
828 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
830 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
832 if len(RecordList
) != 1:
833 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
834 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
835 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
836 ModuleFile
.Arch
= self
._Arch
837 Module
.Guid
= RecordList
[0][2]
838 for item
in Module
.StrPcdSet
:
839 item
[4] = RecordList
[0][2]
840 self
._Modules
[ModuleFile
] = Module
843 ## Retrieve all possible library instances used in this platform
845 def LibraryInstances(self
):
846 if self
._LibraryInstances
is None:
848 return self
._LibraryInstances
850 ## Retrieve [LibraryClasses] information
852 def LibraryClasses(self
):
853 if self
._LibraryClasses
is None:
854 self
._LibraryInstances
= []
856 # tdict is a special dict kind of type, used for selecting correct
857 # library instance for given library class and module type
859 LibraryClassDict
= tdict(True, 3)
860 # track all library class names
861 LibraryClassSet
= set()
862 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
863 Macros
= self
._Macros
864 for Record
in RecordList
:
865 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
866 if LibraryClass
== '' or LibraryClass
== 'NULL':
867 self
._NullLibraryNumber
+= 1
868 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
869 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
870 LibraryClassSet
.add(LibraryClass
)
871 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
872 # check the file validation
873 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
875 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
878 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
879 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
880 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
881 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
882 if LibraryInstance
not in self
._LibraryInstances
:
883 self
._LibraryInstances
.append(LibraryInstance
)
885 # resolve the specific library instance for each class and each module type
886 self
._LibraryClasses
= tdict(True)
887 for LibraryClass
in LibraryClassSet
:
888 # try all possible module types
889 for ModuleType
in SUP_MODULE_LIST
:
890 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
891 if LibraryInstance
is None:
893 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
895 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
896 for Record
in RecordList
:
897 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
899 # check the file validation
900 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
902 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
904 if File
not in self
._LibraryInstances
:
905 self
._LibraryInstances
.append(File
)
907 # we need the module name as the library class name, so we have
908 # to parse it here. (self._Bdb[] will trigger a file parse if it
909 # hasn't been parsed)
911 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
912 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
913 return self
._LibraryClasses
915 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
916 if not self
._DecPcds
:
919 if GlobalData
.gFdfParser
:
920 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
923 for Inf
in FdfInfList
:
924 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
925 if ModuleFile
in self
._Modules
:
927 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
928 PkgSet
.update(ModuleData
.Packages
)
930 PkgSet
.update(self
.Packages
)
931 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
932 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
934 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
935 EdkLogger
.error('build', PARSER_ERROR
,
936 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
937 File
=self
.MetaFile
, Line
=LineNo
)
938 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
940 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
941 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
942 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
944 if ValueList
[2] == '-1':
945 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
946 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
948 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
949 if "{CODE(" not in ValueList
[Index
]:
951 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
952 except BadExpression
as Value
:
953 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
954 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
955 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
956 except EvaluationException
as Excpt
:
957 if hasattr(Excpt
, 'Pcd'):
958 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
959 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
960 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
961 " of the DSC file" % Excpt
.Pcd
,
962 File
=self
.MetaFile
, Line
=LineNo
)
964 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
965 File
=self
.MetaFile
, Line
=LineNo
)
967 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
968 File
=self
.MetaFile
, Line
=LineNo
)
971 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
973 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
974 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
975 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
976 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
977 DecPcd
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
978 EdkLogger
.error('build', FORMAT_INVALID
,
979 "Pcd datumtype used in DSC file is not the same as its declaration. DatumType:%s"%DecPcd
.DatumType
,
980 File
=self
.MetaFile
, Line
=LineNo
,
981 ExtraData
="Dsc:%s.%s|%s\n Dec:%s.%s|%s|%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
, TokenSpaceGuid
, \
982 PcdCName
, DecPcd
.DefaultValue
, DecPcd
.DatumType
, DecPcd
.TokenValue
))
983 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
984 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
985 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
988 def _FilterPcdBySkuUsage(self
, Pcds
):
989 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
990 sku_usage
= self
.SkuIdMgr
.SkuUsageType
991 if sku_usage
== SkuClass
.SINGLE
:
994 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
995 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
996 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
1000 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
1001 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
1002 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
1005 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
1006 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
]]]
1007 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1009 for skuid
in pcd
.SkuInfoList
:
1010 skuobj
= pcd
.SkuInfoList
.get(skuid
)
1011 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
1012 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
1013 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1014 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
1017 def RecoverCommandLinePcd(self
):
1018 def UpdateCommandLineValue(pcd
):
1019 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1020 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1021 pcd
.PcdValueFromComm
= pcd
.DefaultValue
1022 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1023 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
1025 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
1026 for pcd
in self
._Pcds
:
1027 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
1028 UpdateCommandLineValue(self
._Pcds
[pcd
])
1030 def __ParsePcdFromCommandLine(self
):
1031 if GlobalData
.BuildOptionPcd
:
1032 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
1033 if isinstance(pcd
, tuple):
1035 (pcdname
, pcdvalue
) = pcd
.split('=')
1037 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1039 (Name1
, Name2
) = pcdname
.split('.', 1)
1041 (Name3
, FieldName
) = Name2
.split(".", 1)
1042 if ((Name3
, Name1
)) in self
.DecPcds
:
1043 HasTokenSpace
= True
1045 TokenSpaceGuidCName
= Name1
1049 TokenSpaceGuidCName
= ''
1050 HasTokenSpace
= False
1052 if ((Name2
, Name1
)) in self
.DecPcds
:
1053 HasTokenSpace
= True
1055 TokenSpaceGuidCName
= Name1
1060 TokenSpaceGuidCName
= ''
1061 HasTokenSpace
= False
1064 TokenCName
= pcdname
1065 TokenSpaceGuidCName
= ''
1066 HasTokenSpace
= False
1067 TokenSpaceGuidCNameList
= []
1070 DisplayName
= TokenCName
1072 DisplayName
= TokenCName
+ '.' + FieldName
1073 if not HasTokenSpace
:
1074 for key
in self
.DecPcds
:
1075 PcdItem
= self
.DecPcds
[key
]
1076 if TokenCName
== PcdItem
.TokenCName
:
1077 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1078 if len (TokenSpaceGuidCNameList
) < 1:
1079 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1080 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1081 PcdDatumType
= PcdItem
.DatumType
1087 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1090 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1091 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1095 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1097 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1098 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1100 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1102 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1103 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1105 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1106 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1108 if GlobalData
.BuildOptionPcd
:
1109 inf_objs
= [item
for item
in self
._Bdb
._CACHE
_.values() if item
.Arch
== self
.Arch
and item
.MetaFile
.Ext
.lower() == '.inf']
1110 for pcd
in GlobalData
.BuildOptionPcd
:
1111 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1112 for BuildData
in inf_objs
:
1113 for key
in BuildData
.Pcds
:
1114 PcdItem
= BuildData
.Pcds
[key
]
1115 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1116 PcdItem
.DefaultValue
= pcdvalue
1117 PcdItem
.PcdValueFromComm
= pcdvalue
1118 #In command line, the latter full assign value in commandLine should override the former field assign value.
1119 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1122 if GlobalData
.BuildOptionPcd
:
1123 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1124 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1126 if (TokenSpaceGuid
, Token
) not in field_assign
:
1127 field_assign
[TokenSpaceGuid
, Token
] = []
1128 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1130 if (TokenSpaceGuid
, Token
) in field_assign
:
1131 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1132 field_assign
[TokenSpaceGuid
, Token
] = []
1133 for item
in delete_assign
:
1134 GlobalData
.BuildOptionPcd
.remove(item
)
1137 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1140 TokenCName
+= '.' + FieldName
1141 if PcdValue
.startswith('H'):
1142 if FieldName
and _IsFieldValueAnArray(PcdValue
[1:]):
1143 PcdDatumType
= TAB_VOID
1145 if FieldName
and not IsArray
:
1148 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1149 except BadExpression
as Value
:
1150 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1151 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1152 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1153 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1154 PcdDatumType
= TAB_VOID
1156 if FieldName
and not IsArray
:
1159 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1160 except BadExpression
as Value
:
1161 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1162 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1163 elif PcdValue
.startswith('L'):
1164 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1165 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1166 PcdDatumType
= TAB_VOID
1168 if FieldName
and not IsArray
:
1171 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1172 except BadExpression
as Value
:
1173 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1174 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1176 if PcdValue
.upper() == 'FALSE':
1178 if PcdValue
.upper() == 'TRUE':
1181 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1182 PcdValue
= '"' + PcdValue
+ '"'
1183 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1184 PcdValue
= '"' + PcdValue
+ '"'
1188 if PcdValue
.upper().startswith('0X'):
1191 Num
= int(PcdValue
, Base
)
1193 PcdValue
= '"' + PcdValue
+ '"'
1194 if _IsFieldValueAnArray(PcdValue
):
1195 PcdDatumType
= TAB_VOID
1200 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1201 except BadExpression
as Value
:
1202 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1203 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1206 ## Retrieve all PCD settings in platform
1209 if self
._Pcds
is None:
1210 self
._Pcds
= OrderedDict()
1211 self
.__ParsePcdFromCommandLine
()
1212 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1213 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1214 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1215 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1216 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1217 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1218 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1219 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1220 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1222 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1223 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1224 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1225 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1226 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1227 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1229 self
.RecoverCommandLinePcd()
1232 ## Retrieve [BuildOptions]
1234 def BuildOptions(self
):
1235 if self
._BuildOptions
is None:
1236 self
._BuildOptions
= OrderedDict()
1238 # Retrieve build option for EDKII and EDK style module
1240 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1241 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1242 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1243 if Dummy3
.upper() != TAB_COMMON
:
1245 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1247 # Only flags can be appended
1249 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1250 self
._BuildOptions
[CurKey
] = Option
1252 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1253 self
._BuildOptions
[CurKey
] += ' ' + Option
1254 return self
._BuildOptions
1255 def GetBuildOptionsByPkg(self
, Module
, ModuleType
):
1257 local_pkg
= os
.path
.split(Module
.LocalPkg())[0]
1258 if self
._ModuleTypeOptions
is None:
1259 self
._ModuleTypeOptions
= OrderedDict()
1260 if ModuleType
not in self
._ModuleTypeOptions
:
1261 options
= OrderedDict()
1262 self
._ModuleTypeOptions
[ ModuleType
] = options
1263 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1264 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1265 if Dummy2
not in (TAB_COMMON
,local_pkg
.upper(),"EDKII"):
1268 if Type
.upper() == ModuleType
.upper():
1269 Key
= (ToolChainFamily
, ToolChain
)
1270 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1271 options
[Key
] = Option
1273 if ' ' + Option
not in options
[Key
]:
1274 options
[Key
] += ' ' + Option
1275 return self
._ModuleTypeOptions
[ModuleType
]
1276 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1277 if self
._ModuleTypeOptions
is None:
1278 self
._ModuleTypeOptions
= OrderedDict()
1279 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1280 options
= OrderedDict()
1281 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1282 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1283 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1284 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1285 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1286 Type
= Dummy2
+ '.' + Dummy3
1287 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1288 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1289 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1290 options
[Key
] = Option
1292 if ' ' + Option
not in options
[Key
]:
1293 options
[Key
] += ' ' + Option
1294 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1297 def GetStructurePcdInfo(PcdSet
):
1298 structure_pcd_data
= defaultdict(list)
1300 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1302 return structure_pcd_data
1305 def OverrideByFdf(StruPcds
,workspace
):
1306 if GlobalData
.gFdfParser
is None:
1308 StructurePcdInFdf
= OrderedDict()
1309 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1310 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1311 for item
in fdfpcd
:
1312 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1313 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1314 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1315 for Pcd
in StruPcds
.values():
1316 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1318 FieldValues
= OrderedDict()
1319 for item
in StructurePcdInFdf
:
1320 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1321 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1322 for field
in FieldValues
:
1323 if field
not in Pcd
.PcdFieldValueFromFdf
:
1324 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1325 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1326 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1327 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1332 def OverrideByComm(StruPcds
):
1333 StructurePcdInCom
= OrderedDict()
1334 for item
in GlobalData
.BuildOptionPcd
:
1335 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1336 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1337 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1338 for Pcd
in StruPcds
.values():
1339 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1341 FieldValues
= OrderedDict()
1342 for item
in StructurePcdInCom
:
1343 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1344 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1345 for field
in FieldValues
:
1346 if field
not in Pcd
.PcdFieldValueFromComm
:
1347 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1348 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1349 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1350 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1353 def OverrideByCommOverAll(self
,AllPcds
):
1354 def CheckStructureInComm(commpcds
):
1357 if len(commpcds
[0]) == 5:
1360 NoFiledValues
= OrderedDict()
1361 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1362 StructurePcdInCom
= OrderedDict()
1363 for item
in GlobalData
.BuildOptionPcd
:
1364 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1365 for item
in StructurePcdInCom
:
1367 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1369 for item
in GlobalData
.BuildOptionPcd
:
1370 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1371 for Guid
, Name
in NoFiledValues
:
1372 if (Name
, Guid
) in AllPcds
:
1373 Pcd
= AllPcds
.get((Name
, Guid
))
1374 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1375 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1377 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1378 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1379 for sku
in Pcd
.SkuInfoList
:
1380 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1381 if SkuInfo
.DefaultValue
:
1382 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1384 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1385 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1386 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1387 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1388 if Pcd
.DatumType
== TAB_VOID
:
1389 if not Pcd
.MaxDatumSize
:
1390 Pcd
.MaxDatumSize
= '0'
1391 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1392 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1393 MaxSize
= max(CurrentSize
, OptionSize
)
1394 Pcd
.MaxDatumSize
= str(MaxSize
)
1396 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1398 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1399 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1400 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1401 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1402 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1403 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1404 self
._Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1405 self
._Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1406 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1407 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1408 self
._Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1411 def OverrideByFdfOverAll(self
,AllPcds
):
1413 if GlobalData
.gFdfParser
is None:
1415 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1416 for Name
,Guid
,Field
in NoFiledValues
:
1419 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1420 if (Name
,Guid
) in AllPcds
:
1421 Pcd
= AllPcds
.get((Name
,Guid
))
1422 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1423 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1425 Pcd
.PcdValueFromComm
= Value
1426 Pcd
.DefaultValue
= Value
1427 for sku
in Pcd
.SkuInfoList
:
1428 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1429 if SkuInfo
.DefaultValue
:
1430 SkuInfo
.DefaultValue
= Value
1432 SkuInfo
.HiiDefaultValue
= Value
1433 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1434 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1435 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1436 if Pcd
.DatumType
== TAB_VOID
:
1437 if not Pcd
.MaxDatumSize
:
1438 Pcd
.MaxDatumSize
= '0'
1439 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1440 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1441 MaxSize
= max(CurrentSize
, OptionSize
)
1442 Pcd
.MaxDatumSize
= str(MaxSize
)
1444 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1446 PcdInDec
.PcdValueFromFdf
= Value
1447 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1448 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1449 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1450 self
._Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1451 self
._Pcds
[Name
, Guid
].DefaultValue
= Value
1454 def ParsePcdNameStruct(self
,NamePart1
,NamePart2
):
1455 TokenSpaceCName
= PcdCName
= DimensionAttr
= Field
= ""
1456 if "." in NamePart1
:
1457 TokenSpaceCName
, TempPcdCName
= NamePart1
.split(".")
1458 if "[" in TempPcdCName
:
1459 PcdCName
= TempPcdCName
[:TempPcdCName
.index("[")]
1460 DimensionAttr
= TempPcdCName
[TempPcdCName
.index("["):]
1462 PcdCName
= TempPcdCName
1465 TokenSpaceCName
= NamePart1
1466 if "[" in NamePart2
:
1467 PcdCName
= NamePart2
[:NamePart2
.index("[")]
1468 DimensionAttr
= NamePart2
[NamePart2
.index("["):]
1470 PcdCName
= NamePart2
1472 return TokenSpaceCName
,PcdCName
,DimensionAttr
,Field
1474 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1476 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1477 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1478 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1479 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1480 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1481 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1484 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1485 SkuIds
= self
.SkuIds
1486 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1487 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1488 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1491 # Find out all possible PCD candidates for self._Arch
1494 for Type
in TypeList
:
1495 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1497 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1498 SkuName
= SkuName
.upper()
1499 default_store
= default_store
.upper()
1500 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1501 if SkuName
not in SkuIds
:
1503 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
1504 pcd_in_dec
= self
._DecPcds
.get((PCName
,TCName
), None)
1505 if pcd_in_dec
is None:
1506 EdkLogger
.error('build', PARSER_ERROR
,
1507 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1508 File
=self
.MetaFile
, Line
= Dummy5
)
1509 if SkuName
in SkuIds
and ("." in TokenSpaceGuid
or "[" in PcdCName
):
1510 if not isinstance (pcd_in_dec
, StructurePcd
):
1511 EdkLogger
.error('build', PARSER_ERROR
,
1512 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1513 File
=self
.MetaFile
, Line
= Dummy5
)
1515 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1516 ModuleScopeOverallValue
= {}
1517 for m
in self
.Modules
.values():
1520 S_PcdSet
.extend(m
.StrPcdSet
)
1521 mguid
= m
.StrPcdSet
[0][4]
1522 for (PCName
,TCName
) in m
.StrPcdOverallValue
:
1523 Value
, dsc_file
, lineNo
= m
.StrPcdOverallValue
[(PCName
,TCName
)]
1524 ModuleScopeOverallValue
.setdefault((PCName
,TCName
),{})[mguid
] = Value
, dsc_file
, lineNo
1525 # handle pcd value override
1526 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1527 S_pcd_set
= OrderedDict()
1528 for str_pcd
in StrPcdSet
:
1529 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1530 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1531 str_pcd_obj_str
= StructurePcd()
1532 str_pcd_obj_str
.copy(str_pcd_dec
)
1534 str_pcd_obj_str
.copy(str_pcd_obj
)
1535 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1536 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
}
1538 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
}
1539 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1540 if str_pcd_data
[4] in SkuIds
:
1541 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])
1542 elif GlobalData
.gGuidPattern
.match(str_pcd_data
[4]):
1543 str_pcd_obj_str
.AddComponentOverrideValue(str_pcd_data
[3], str(str_pcd_data
[7]), str_pcd_data
[4].replace("-","S"), 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])
1544 PcdComponentValue
= ModuleScopeOverallValue
.get((str_pcd_obj_str
.TokenCName
,str_pcd_obj_str
.TokenSpaceGuidCName
))
1545 for module_guid
in PcdComponentValue
:
1546 str_pcd_obj_str
.PcdValueFromComponents
[module_guid
.replace("-","S")] = PcdComponentValue
[module_guid
]
1547 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1549 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1550 for Pcd
in self
.DecPcds
:
1551 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1552 if Pcd
not in S_pcd_set
:
1553 str_pcd_obj_str
= StructurePcd()
1554 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1555 str_pcd_obj
= Pcds
.get(Pcd
, None)
1557 str_pcd_obj_str
.copy(str_pcd_obj
)
1558 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1559 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
}
1561 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
}
1562 S_pcd_set
[Pcd
] = str_pcd_obj_str
1564 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
.copy()
1565 self
.FilterStrcturePcd(S_pcd_set
)
1566 for stru_pcd
in S_pcd_set
.values():
1567 for skuid
in SkuIds
:
1568 if skuid
in stru_pcd
.SkuOverrideValues
:
1570 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1572 if skuid
not in stru_pcd
.SkuOverrideValues
:
1573 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1574 if nextskuid
== TAB_DEFAULT
:
1577 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1578 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})
1580 stru_pcd
.ValueChain
.add((skuid
, ''))
1581 if 'DEFAULT' in stru_pcd
.SkuOverrideValues
and not GlobalData
.gPcdSkuOverrides
.get((stru_pcd
.TokenCName
, stru_pcd
.TokenSpaceGuidCName
)):
1582 GlobalData
.gPcdSkuOverrides
.update(
1583 {(stru_pcd
.TokenCName
, stru_pcd
.TokenSpaceGuidCName
): {'DEFAULT':stru_pcd
.SkuOverrideValues
['DEFAULT']}})
1584 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1585 for skuid
in SkuIds
:
1588 if skuid
not in stru_pcd
.SkuOverrideValues
:
1589 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1590 if nextskuid
== TAB_DEFAULT
:
1593 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1596 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1597 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1599 for defaultstoreid
in DefaultStores
:
1600 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1601 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = CopyDict(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1602 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1603 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1604 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1606 # Create a tool to caculate structure pcd value
1607 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1610 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1611 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1612 if str_pcd_obj
is None:
1613 print(PcdName
, PcdGuid
)
1615 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1616 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1617 if skuname
not in str_pcd_obj
.SkuInfoList
:
1618 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1620 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1621 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1622 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1623 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1624 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1625 str_pcd_obj
.DefaultValue
= PcdValue
1627 #Module Scope Structure Pcd
1628 moduleguid
= skuname
.replace("S","-")
1629 if GlobalData
.gGuidPattern
.match(moduleguid
):
1630 for component
in self
.Modules
.values():
1631 if component
.Guid
== moduleguid
:
1632 component
.Pcds
[(PcdName
, PcdGuid
)].DefaultValue
= PcdValue
1635 if skuname
not in str_pcd_obj
.SkuInfoList
:
1636 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1638 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1639 if nextskuid
== TAB_DEFAULT
:
1642 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1643 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
)
1644 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1645 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1647 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1648 for str_pcd_obj
in S_pcd_set
.values():
1649 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1650 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1652 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1653 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1654 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1655 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1657 for str_pcd_obj
in S_pcd_set
.values():
1659 str_pcd_obj
.MaxDatumSize
= DscBuildData
.GetStructurePcdMaxSize(str_pcd_obj
)
1660 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1661 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1665 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1666 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1667 del pcd
.SkuInfoList
[TAB_COMMON
]
1668 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1669 del pcd
.SkuInfoList
[TAB_COMMON
]
1671 list(map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
]))
1674 def PlatformUsedPcds(self
):
1676 if GlobalData
.gFdfParser
:
1677 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1678 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1679 AllModulePcds
= set()
1680 ModuleSet
= set(list(self
._Modules
.keys()) + FdfModuleList
)
1681 for ModuleFile
in ModuleSet
:
1682 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1683 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1684 for ModuleFile
in self
.LibraryInstances
:
1685 ModuleData
= self
._Bdb
.CreateBuildObject(ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
)
1686 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1687 return AllModulePcds
1689 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1690 def FilterStrcturePcd(self
, S_pcd_set
):
1691 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.PlatformUsedPcds
1692 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1693 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1695 ## Retrieve non-dynamic PCD settings
1697 # @param Type PCD type
1699 # @retval a dict object contains settings of given PCD type
1701 def _GetPcd(self
, Type
):
1702 Pcds
= OrderedDict()
1704 # tdict is a special dict kind of type, used for selecting correct
1705 # PCD settings for certain ARCH
1707 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1709 PcdDict
= tdict(True, 4)
1711 # Find out all possible PCD candidates for self._Arch
1712 RecordList
= self
._RawData
[Type
, self
._Arch
]
1713 PcdValueDict
= OrderedDict()
1714 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1715 SkuName
= SkuName
.upper()
1716 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1717 if SkuName
not in AvailableSkuIdSet
:
1718 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1719 File
=self
.MetaFile
, Line
=Dummy5
)
1720 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1721 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
1722 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1723 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1725 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
1726 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1729 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1731 if int(MaxDatumSize
, 0) > 0xFFFF:
1732 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1733 File
=self
.MetaFile
, Line
=Dummy4
)
1734 if int(MaxDatumSize
, 0) < 0:
1735 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1736 File
=self
.MetaFile
, Line
=Dummy4
)
1737 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1738 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
,Dummy4
)
1740 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
,Dummy4
)}
1742 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.items():
1743 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1744 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1745 elif TAB_DEFAULT
in PcdSetting
:
1746 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[TAB_DEFAULT
]
1747 elif TAB_COMMON
in PcdSetting
:
1748 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[TAB_COMMON
]
1754 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1757 self
._PCD
_TYPE
_STRING
_[Type
],
1766 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1767 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1768 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1769 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1770 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
1771 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1772 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Settings
[3])
1776 def GetStructurePcdMaxSize(str_pcd
):
1777 pcd_default_value
= str_pcd
.DefaultValue
1778 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()]
1779 sku_values
.append(pcd_default_value
)
1781 def get_length(value
):
1782 Value
= value
.strip()
1784 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1786 if Value
.startswith('L"') and Value
.endswith('"'):
1787 return len(Value
[2:-1])
1788 if Value
[0] == '"' and Value
[-1] == '"':
1789 return len(Value
) - 2
1790 if Value
.strip().startswith("{CODE("):
1791 tmpValue
= RemoveCComments(Value
)
1792 return len(tmpValue
.split(","))
1793 if (Value
[0] == '{' and Value
[-1] == '}'):
1794 return len(Value
.split(","))
1795 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1796 return len(list(Value
[2:-1]))
1797 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1798 return len(Value
) - 2
1801 return str(max(get_length(item
) for item
in sku_values
))
1804 def ExecuteCommand (Command
):
1806 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1808 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1809 Result
= Process
.communicate()
1810 return Process
.returncode
, Result
[0].decode(errors
='ignore'), Result
[1].decode(errors
='ignore')
1813 def IntToCString(Value
, ValueSize
):
1815 if not isinstance (Value
, str):
1816 for Index
in range(0, ValueSize
):
1817 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1819 Result
= Result
+ '"'
1822 def GenerateSizeFunction(self
, Pcd
):
1823 CApp
= "// Default Value in Dec \n"
1824 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1826 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
1827 CApp
+= " *Size = (sizeof (%s) > *Size ? sizeof (%s) : *Size);\n" % (Pcd
.DatumType
,Pcd
.DatumType
)
1829 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1830 CApp
+= " *Size = (sizeof (%s_%s_INIT_Value) > *Size ? sizeof (%s_%s_INIT_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)
1831 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
1832 for skuname
in Pcd
.SkuInfoList
:
1833 skuobj
= Pcd
.SkuInfoList
[skuname
]
1834 if skuobj
.VariableName
:
1835 for defaultstore
in skuobj
.DefaultStoreDict
:
1836 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,defaultstore
)
1838 if "{CODE(" in pcddef
:
1839 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
)
1841 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1843 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1845 if "{CODE(" in pcddef
:
1846 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
)
1848 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1850 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1852 if "{CODE(" in pcddef
:
1853 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
)
1855 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1857 for index
in Pcd
.DefaultValues
:
1859 ActualCap
.append(index
)
1860 FieldList
= Pcd
.DefaultValues
[index
]
1863 for FieldName
in FieldList
:
1864 FieldName
= "." + FieldName
1865 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1866 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1868 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1869 except BadExpression
:
1870 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1871 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1872 Value
, ValueSize
= ParseFieldValue(Value
)
1873 if not Pcd
.IsArray():
1874 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]);
1877 FieldName_ori
= FieldName
.strip('.')
1878 while '[' in FieldName
:
1879 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1880 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1881 FieldName
= FieldName
.split(']', 1)[1]
1882 FieldName
= NewFieldName
+ FieldName
1883 while '[' in FieldName
and not Pcd
.IsArray():
1884 FieldName
= FieldName
.rsplit('[', 1)[0]
1885 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])
1886 for skuname
in Pcd
.SkuOverrideValues
:
1887 if skuname
== TAB_COMMON
:
1889 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1890 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1891 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1893 ActualCap
.append(index
)
1894 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1897 for FieldName
in FieldList
:
1898 FieldName
= "." + FieldName
1899 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1900 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1902 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1903 except BadExpression
:
1904 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1905 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1906 Value
, ValueSize
= ParseFieldValue(Value
)
1907 if not Pcd
.IsArray():
1908 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]);
1911 FieldName_ori
= FieldName
.strip('.')
1912 while '[' in FieldName
:
1913 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1914 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1915 FieldName
= FieldName
.split(']', 1)[1]
1916 FieldName
= NewFieldName
+ FieldName
1917 while '[' in FieldName
and not Pcd
.IsArray():
1918 FieldName
= FieldName
.rsplit('[', 1)[0]
1919 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])
1920 if Pcd
.PcdFieldValueFromFdf
:
1921 CApp
= CApp
+ "// From fdf \n"
1922 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1923 FieldName
= "." + FieldName
1924 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1925 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1927 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1928 except BadExpression
:
1929 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1930 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1931 Value
, ValueSize
= ParseFieldValue(Value
)
1932 if not Pcd
.IsArray():
1933 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]);
1936 FieldName_ori
= FieldName
.strip('.')
1937 while '[' in FieldName
:
1938 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1939 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1940 FieldName
= FieldName
.split(']', 1)[1]
1941 FieldName
= NewFieldName
+ FieldName
1942 while '[' in FieldName
:
1943 FieldName
= FieldName
.rsplit('[', 1)[0]
1944 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])
1945 if Pcd
.PcdFieldValueFromComm
:
1946 CApp
= CApp
+ "// From Command Line \n"
1947 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1948 FieldName
= "." + FieldName
1949 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1950 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1952 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1953 except BadExpression
:
1954 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1955 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1956 Value
, ValueSize
= ParseFieldValue(Value
)
1957 if not Pcd
.IsArray():
1958 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]);
1961 FieldName_ori
= FieldName
.strip('.')
1962 while '[' in FieldName
:
1963 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1964 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1965 FieldName
= FieldName
.split(']', 1)[1]
1966 FieldName
= NewFieldName
+ FieldName
1967 while '[' in FieldName
and not Pcd
.IsArray():
1968 FieldName
= FieldName
.rsplit('[', 1)[0]
1969 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])
1970 if Pcd
.GetPcdMaxSize():
1971 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1972 ArraySizeByAssign
= self
.CalculateActualCap(ActualCap
)
1973 if ArraySizeByAssign
> 1:
1974 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); \n" % (ArraySizeByAssign
, ArraySizeByAssign
)
1977 def CalculateActualCap(self
,ActualCap
):
1981 for item
in ActualCap
:
1982 index_elements
= ArrayIndex
.findall(item
)
1984 for index_e
in index_elements
:
1985 index_num
= index_e
.lstrip("[").rstrip("]").strip()
1987 # Not support flexiable pcd array assignment
1989 index_num
= int(index_num
,16) if index_num
.startswith(("0x","0X")) else int(index_num
)
1990 rt
= rt
* (index_num
+1)
1997 def GenerateSizeStatments(Pcd
,skuname
,defaultstorename
):
1999 r_datatype
= [Pcd
.BaseDatumType
]
2000 lastoneisEmpty
= False
2001 for dem
in Pcd
.Capacity
:
2003 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. " %
2004 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))))
2005 if dem
== '0' or dem
== "-1":
2006 r_datatype
.append("[1]")
2007 lastoneisEmpty
= True
2009 r_datatype
.append("[" + dem
+ "]")
2011 if Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_HII
, MODEL_PCD_DYNAMIC_HII
]:
2012 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultStoreDict
.get(defaultstorename
)
2013 elif Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_DEFAULT
,MODEL_PCD_DYNAMIC_VPD
,MODEL_PCD_DYNAMIC_DEFAULT
,MODEL_PCD_DYNAMIC_EX_VPD
]:
2014 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultValue
2016 PcdDefValue
= Pcd
.DefaultValue
2018 if "{CODE(" not in PcdDefValue
:
2019 sizebasevalue_plus
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
2020 sizebasevalue
= "(%s / sizeof(%s))" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
2021 sizeof
= "sizeof(%s)" % Pcd
.BaseDatumType
2022 CApp
= ' int ArraySize = %s %% %s ? %s : %s ;\n' % ( (DscBuildData
.GetStructurePcdMaxSize(Pcd
), sizeof
, sizebasevalue_plus
, sizebasevalue
))
2023 CApp
+= ' Size = ArraySize * sizeof(%s); \n' % Pcd
.BaseDatumType
2025 CApp
= " Size = 0;\n"
2027 CApp
= ' Size = sizeof(%s);\n' % ("".join(r_datatype
) )
2029 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
2030 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2033 def GetIndicator(self
,index
,FieldName
,Pcd
):
2034 def cleanupindex(indexstr
):
2035 return indexstr
.strip("[").strip("]").strip()
2036 index_elements
= ArrayIndex
.findall(index
)
2037 pcd_capacity
= Pcd
.Capacity
2040 if len(pcd_capacity
)>2:
2041 for i
in range(0,len(index_elements
)):
2042 index_ele
= index_elements
[i
]
2043 index_num
= index_ele
.strip("[").strip("]").strip()
2044 if i
== len(index_elements
) -2:
2045 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
]))
2048 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]))
2049 elif len(pcd_capacity
) == 2:
2050 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
2051 elif len(pcd_capacity
) == 1:
2052 index_ele
= index_elements
[0]
2053 index_num
= index_ele
.strip("[").strip("]").strip()
2054 indicator
+= " + %s)" % (index_num
)
2058 indicator
+= "->" + FieldName
2061 def GetStarNum(self
,Pcd
):
2062 if not Pcd
.IsArray():
2064 elif Pcd
.IsSimpleTypeArray():
2065 return len(Pcd
.Capacity
)
2067 return len(Pcd
.Capacity
) + 1
2068 def GenerateDefaultValueAssignFunction(self
, Pcd
):
2069 CApp
= "// Default value in Dec \n"
2070 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2071 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2072 CApp
= CApp
+ ' CHAR8 *Value;\n'
2073 CApp
= CApp
+ ' UINT32 PcdArraySize;\n'
2074 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
2075 IsArray
= _IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
2078 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
2079 except BadExpression
:
2080 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
2081 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
2082 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
2083 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
2086 # Use memcpy() to copy value into field
2089 pcdarraysize
= Pcd
.PcdArraySize()
2090 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2091 if Pcd
.Capacity
[-1] != "-1":
2092 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])
2093 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2094 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2096 if Pcd
.Capacity
[-1] != "-1":
2097 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])
2098 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2099 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
2100 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2102 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2103 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2104 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2106 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
2107 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2108 elif isinstance(Value
, str):
2109 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
2110 for index
in Pcd
.DefaultValues
:
2111 FieldList
= Pcd
.DefaultValues
[index
]
2114 for FieldName
in FieldList
:
2115 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2118 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2119 except BadExpression
:
2120 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2121 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2124 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2126 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]))
2128 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2131 # Use memcpy() to copy value into field
2133 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2134 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2135 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])
2136 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2137 elif isinstance(Value
, str):
2138 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2140 if '[' in FieldName
and ']' in FieldName
:
2141 Index
= int(FieldName
.split('[')[1].split(']')[0])
2142 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
)
2144 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2146 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2151 def GenerateDefaultValueAssignStatement(Pcd
):
2152 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2155 def GetPcdDscRawDefaultValue(self
,Pcd
, SkuName
,DefaultStoreName
):
2156 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2157 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2158 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2160 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2162 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2164 return pcddefaultvalue
2165 def GetPcdDscRawValueInfo(self
,Pcd
, SkuName
,DefaultStoreName
):
2166 DscValueInfo
= Pcd
.DscRawValueInfo
.get(SkuName
, {}).get(DefaultStoreName
)
2168 dscfilepath
,lineno
= DscValueInfo
2170 dscfilepath
= self
.MetaFile
.File
2172 return dscfilepath
,lineno
2174 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
2175 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
2176 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
2177 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2178 CApp
= CApp
+ ' CHAR8 *Value;\n'
2179 CApp
= CApp
+ ' UINT32 PcdArraySize;\n'
2181 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2182 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2183 dscfilepath
,lineno
= self
.GetPcdDscRawValueInfo(Pcd
, SkuName
, DefaultStoreName
)
2185 valuefrom
= "%s Line %s" % (dscfilepath
,str(lineno
))
2187 valuefrom
= dscfilepath
2189 pcddefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, SkuName
, DefaultStoreName
)
2191 FieldList
= pcddefaultvalue
2192 IsArray
= _IsFieldValueAnArray(FieldList
)
2194 if "{CODE(" not in FieldList
:
2196 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2197 except BadExpression
:
2198 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2199 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2200 Value
, ValueSize
= ParseFieldValue (FieldList
)
2202 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2203 if isinstance(Value
, str):
2204 if "{CODE(" in Value
:
2205 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2206 pcdarraysize
= Pcd
.PcdArraySize()
2207 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
)
2208 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2209 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2211 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
)
2214 # Use memcpy() to copy value into field
2217 pcdarraysize
= Pcd
.PcdArraySize()
2218 if "{CODE(" in pcddefaultvalue
:
2219 if Pcd
.Capacity
[-1] != "-1":
2220 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
)
2221 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2222 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2224 if Pcd
.Capacity
[-1] != "-1":
2225 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
)
2226 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2227 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
)
2228 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2230 if "{CODE(" in pcddefaultvalue
:
2231 CApp
= CApp
+ ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
,ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
)
2232 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2234 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
)
2235 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2237 if isinstance(Value
, str):
2238 if "{CODE(" in Value
:
2239 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2240 pcdarraysize
= Pcd
.PcdArraySize()
2241 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
)
2242 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n '% (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2243 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2245 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2248 # Use memcpy() to copy value into field
2251 pcdarraysize
= Pcd
.PcdArraySize()
2252 if "{CODE(" in pcddefaultvalue
:
2253 if Pcd
.Capacity
[-1] != "-1":
2254 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
)
2255 CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2256 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2258 if Pcd
.Capacity
[-1] != "-1":
2259 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
)
2260 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2261 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
)
2262 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2264 if "{CODE(" in pcddefaultvalue
:
2265 CApp
= CApp
+ ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
,ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
)
2266 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2268 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2269 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2271 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2272 if not inheritvalue
:
2274 for index
in inheritvalue
:
2275 FieldList
= inheritvalue
[index
]
2278 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2279 for FieldName
in FieldList
:
2280 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2281 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2284 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2285 except BadExpression
:
2286 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2287 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2289 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2291 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]))
2292 if isinstance(Value
, str):
2293 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2296 # Use memcpy() to copy value into field
2298 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2299 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2300 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])
2301 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2303 if '[' in FieldName
and ']' in FieldName
:
2304 Index
= int(FieldName
.split('[')[1].split(']')[0])
2305 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
)
2307 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2309 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2314 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2315 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2318 def GenerateCommandLineValue(self
, Pcd
):
2319 CApp
= "// Value in CommandLine\n"
2320 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2321 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2322 CApp
= CApp
+ ' CHAR8 *Value;\n'
2324 pcddefaultvalue
= Pcd
.PcdValueFromComm
2325 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2328 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2329 IsArray
= _IsFieldValueAnArray(FieldList
)
2332 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2333 except BadExpression
:
2334 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2335 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2336 Value
, ValueSize
= ParseFieldValue (FieldList
)
2338 if isinstance(Value
, str):
2339 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2342 # Use memcpy() to copy value into field
2344 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2345 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2347 for FieldName
in FieldList
:
2348 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2351 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2352 except BadExpression
:
2353 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2354 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2358 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2360 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]))
2361 if isinstance(Value
, str):
2362 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2365 # Use memcpy() to copy value into field
2367 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2368 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2369 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])
2370 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2372 if '[' in FieldName
and ']' in FieldName
:
2373 Index
= int(FieldName
.split('[')[1].split(']')[0])
2374 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
)
2376 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2378 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2382 def GenerateModuleScopeValue(self
, Pcd
):
2383 CApp
= "// Value in Dsc Module scope \n"
2384 for ModuleGuid
in Pcd
.PcdFiledValueFromDscComponent
:
2386 CApp
= CApp
+ "void Assign_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, ModuleGuid
,Pcd
.BaseDatumType
)
2387 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2388 CApp
= CApp
+ ' CHAR8 *Value;\n'
2389 pcddefaultvalue
, file_path
,lineNo
= Pcd
.PcdValueFromComponents
.get(ModuleGuid
,(None,None,None))
2392 IsArray
= _IsFieldValueAnArray(pcddefaultvalue
)
2395 FieldList
= ValueExpressionEx(pcddefaultvalue
, TAB_VOID
)(True)
2396 except BadExpression
:
2397 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from %s Line %s: %s" %
2398 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, file_path
, lineNo
, FieldList
))
2399 Value
, ValueSize
= ParseFieldValue (FieldList
)
2401 if isinstance(Value
, str):
2402 CApp
= CApp
+ ' Pcd = %s; // From %s Line %s \n' % (Value
, file_path
, lineNo
)
2405 # Use memcpy() to copy value into field
2407 CApp
= CApp
+ ' Value = %s; // From %s Line %s.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), file_path
, lineNo
)
2408 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2411 PcdFiledValue
= Pcd
.PcdFiledValueFromDscComponent
.get(ModuleGuid
)
2412 for index
in PcdFiledValue
:
2413 FieldList
= PcdFiledValue
[index
]
2416 for FieldName
in FieldList
:
2417 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2420 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2421 except BadExpression
:
2422 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2423 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2427 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2429 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]))
2430 if isinstance(Value
, str):
2431 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2434 # Use memcpy() to copy value into field
2436 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2437 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2438 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])
2439 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2441 if '[' in FieldName
and ']' in FieldName
:
2442 Index
= int(FieldName
.split('[')[1].split(']')[0])
2443 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
)
2445 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2447 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2452 def GenerateCommandLineValueStatement(Pcd
):
2453 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2455 def GenerateFdfValue(self
,Pcd
):
2456 CApp
= "// Value in Fdf\n"
2457 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2458 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2459 CApp
= CApp
+ ' CHAR8 *Value;\n'
2461 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2462 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2465 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2466 IsArray
= _IsFieldValueAnArray(FieldList
)
2469 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2470 except BadExpression
:
2471 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2472 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2473 Value
, ValueSize
= ParseFieldValue (FieldList
)
2475 if isinstance(Value
, str):
2476 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2479 # Use memcpy() to copy value into field
2481 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2482 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2484 for FieldName
in FieldList
:
2485 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2488 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2489 except BadExpression
:
2490 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2491 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2495 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2497 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]))
2498 if isinstance(Value
, str):
2499 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2502 # Use memcpy() to copy value into field
2504 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2505 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2506 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])
2507 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2509 if '[' in FieldName
and ']' in FieldName
:
2510 Index
= int(FieldName
.split('[')[1].split(']')[0])
2511 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
)
2513 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2515 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2520 def GenerateFdfValueStatement(Pcd
):
2521 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2525 def GenerateModuleValueStatement(module_guid
, Pcd
):
2526 CApp
= " Assign_%s_%s_%s_Value(Pcd);\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, module_guid
)
2528 def GenerateModuleScopeInitializeFunc(self
,SkuName
, Pcd
, InitByteValue
, CApp
):
2529 for module_guid
in Pcd
.PcdFiledValueFromDscComponent
:
2530 CApp
= CApp
+ 'void\n'
2531 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2532 CApp
= CApp
+ ' void\n'
2533 CApp
= CApp
+ ' )\n'
2535 CApp
= CApp
+ ' UINT32 Size;\n'
2536 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2537 CApp
= CApp
+ ' CHAR8 *Value;\n'
2538 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2539 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2541 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2545 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2546 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2548 # Get current PCD value and size
2550 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2553 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2554 # the correct value. For structures with a flexible array member, the flexible
2555 # array member is detected, and the size is based on the highest index used with
2556 # the flexible array member. The flexible array member must be the last field
2557 # in a structure. The size formula for this case is:
2558 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2560 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,TAB_DEFAULT_STORES_DEFAULT
)
2561 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2562 CApp
= CApp
+ ' OriginalSize = OriginalSize < sizeof(%s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize(),Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2563 CApp
= CApp
+ ' Size = sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2566 # Allocate and zero buffer for the PCD
2567 # Must handle cases where current value is smaller, larger, or same size
2568 # Always keep that larger one as the current size
2570 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2571 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2572 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2575 # Copy current PCD value into allocated buffer.
2577 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2580 # Assign field values in PCD
2582 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2584 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2585 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2586 CApp
= CApp
+ DscBuildData
.GenerateModuleValueStatement(module_guid
,Pcd
)
2587 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2588 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2591 # Set new PCD value and size
2593 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2598 CApp
= CApp
+ ' free (Pcd);\n'
2601 return InitByteValue
,CApp
2603 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2604 OverrideValues
= {DefaultStore
:{}}
2605 if Pcd
.SkuOverrideValues
:
2606 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2607 if not OverrideValues
:
2608 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2609 for DefaultStoreName
in OverrideValues
:
2610 CApp
= CApp
+ 'void\n'
2611 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2612 CApp
= CApp
+ ' void\n'
2613 CApp
= CApp
+ ' )\n'
2615 CApp
= CApp
+ ' UINT32 Size;\n'
2616 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2617 CApp
= CApp
+ ' CHAR8 *Value;\n'
2618 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2619 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2621 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2625 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2627 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2630 # Get current PCD value and size
2632 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2635 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2636 # the correct value. For structures with a flexible array member, the flexible
2637 # array member is detected, and the size is based on the highest index used with
2638 # the flexible array member. The flexible array member must be the last field
2639 # in a structure. The size formula for this case is:
2640 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2642 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,DefaultStoreName
)
2643 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2644 CApp
= CApp
+ ' OriginalSize = OriginalSize < sizeof(%s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize(),Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2645 CApp
= CApp
+ ' Size = sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2648 # Allocate and zero buffer for the PCD
2649 # Must handle cases where current value is smaller, larger, or same size
2650 # Always keep that larger one as the current size
2652 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2653 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2654 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2657 # Copy current PCD value into allocated buffer.
2659 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2662 # Assign field values in PCD
2664 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2665 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2666 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2667 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2668 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2669 for defaultstorenameitem
in storeset
:
2670 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2671 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2672 if skuname
== SkuName
:
2675 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2676 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2677 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2678 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2680 # Set new PCD value and size
2682 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2687 CApp
= CApp
+ ' free (Pcd);\n'
2690 return InitByteValue
, CApp
2692 def GenerateArrayAssignment(self
, Pcd
):
2697 for d
in Pcd
.Capacity
:
2700 Value
= Pcd
.DefaultValueFromDec
2701 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2702 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2703 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2705 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2706 for skuname
in Pcd
.SkuInfoList
:
2707 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2708 if skuinfo
.VariableName
:
2709 for defaultstore
in skuinfo
.DefaultStoreDict
:
2710 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, defaultstore
)
2711 if pcddscrawdefaultvalue
:
2712 Value
= skuinfo
.DefaultStoreDict
[defaultstore
]
2713 if "{CODE(" in Value
:
2714 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2715 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2717 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, TAB_DEFAULT_STORES_DEFAULT
)
2718 if pcddscrawdefaultvalue
:
2719 Value
= skuinfo
.DefaultValue
2720 if "{CODE(" in Value
:
2721 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2722 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2724 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2725 if pcddscrawdefaultvalue
:
2726 if "{CODE(" in Pcd
.DefaultValue
:
2727 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2728 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2732 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2733 if not OverrideValues
:
2735 for key
in OverrideValues
:
2736 if OverrideValues
[key
]:
2740 def ParseCCFlags(self
, ccflag
):
2742 ccflaglist
= ccflag
.split(" ")
2744 while i
< len(ccflaglist
):
2745 item
= ccflaglist
[i
].strip()
2746 if item
in (r
"/D", r
"/U","-D","-U"):
2747 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2749 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2753 def GenerateByteArrayValue (self
, StructuredPcds
):
2755 # Generate/Compile/Run C application to determine if there are any flexible array members
2757 if not StructuredPcds
:
2761 CApp
= PcdMainCHeader
2763 IncludeFiles
= set()
2764 for PcdName
in StructuredPcds
:
2765 Pcd
= StructuredPcds
[PcdName
]
2766 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2767 if IncludeFile
not in IncludeFiles
:
2768 IncludeFiles
.add(IncludeFile
)
2769 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2771 for Pcd
in StructuredPcds
.values():
2772 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2773 for PcdName
in sorted(StructuredPcds
.keys()):
2774 Pcd
= StructuredPcds
[PcdName
]
2776 #create void void Cal_tocken_cname_Size functions
2777 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2779 #create void Assign_ functions
2782 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2784 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2786 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2788 # From Dsc Global setting
2789 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2790 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2791 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2793 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2794 if SkuName
not in Pcd
.SkuOverrideValues
:
2796 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2797 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2799 # From Dsc module scope setting
2800 CApp
= CApp
+ self
.GenerateModuleScopeValue(Pcd
)
2802 #create Initialize_ functions
2803 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2804 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2805 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2806 InitByteValue
, CApp
= self
.GenerateModuleScopeInitializeFunc(self
.SkuIdMgr
.SystemSkuId
,Pcd
,InitByteValue
,CApp
)
2808 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2809 if SkuName
not in Pcd
.SkuOverrideValues
:
2811 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2812 Pcd
= StructuredPcds
[PcdName
]
2813 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2815 CApp
= CApp
+ 'VOID\n'
2816 CApp
= CApp
+ 'PcdEntryPoint(\n'
2817 CApp
= CApp
+ ' VOID\n'
2818 CApp
= CApp
+ ' )\n'
2820 for Pcd
in StructuredPcds
.values():
2821 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
]]:
2822 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2823 for ModuleGuid
in Pcd
.PcdFiledValueFromDscComponent
:
2824 CApp
+= " Initialize_%s_%s_%s_%s();\n" % (ModuleGuid
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2826 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2827 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2829 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2830 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2833 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2835 if not os
.path
.exists(self
.OutputPath
):
2836 os
.makedirs(self
.OutputPath
)
2837 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2838 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2840 # start generating makefile
2841 MakeApp
= PcdMakefileHeader
2842 if sys
.platform
== "win32":
2843 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj %s.obj\n' % (self
.OutputPath
, PcdValueInitName
, os
.path
.join(self
.OutputPath
, PcdValueCommonName
)) + 'INC = '
2845 MakeApp
= MakeApp
+ PcdGccMakefile
2846 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o %s.o\n' % (self
.OutputPath
, PcdValueInitName
, os
.path
.join(self
.OutputPath
, PcdValueCommonName
)) + \
2847 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
2850 PlatformInc
= OrderedDict()
2851 for Cache
in self
._Bdb
._CACHE
_.values():
2852 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2855 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2856 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2857 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2858 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2861 for Pcd
in StructuredPcds
.values():
2862 for PackageDec
in Pcd
.PackageDecs
:
2863 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2864 if not os
.path
.exists(Package
):
2865 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2866 if Package
not in PcdDependDEC
:
2867 PcdDependDEC
.append(Package
)
2869 if PlatformInc
and PcdDependDEC
:
2870 for pkg
in PcdDependDEC
:
2871 if pkg
in PlatformInc
:
2872 for inc
in PlatformInc
[pkg
]:
2874 # Get list of files in potential -I include path
2876 FileList
= os
.listdir (str(inc
))
2878 # Skip -I include path if one of the include files required
2879 # by PcdValueInit.c are present in the include paths from
2880 # the DEC file. PcdValueInit.c must use the standard include
2881 # files from the host compiler.
2883 if 'stdio.h' in FileList
:
2885 if 'stdlib.h' in FileList
:
2887 if 'string.h' in FileList
:
2889 MakeApp
+= '-I' + str(inc
) + ' '
2890 IncSearchList
.append(inc
)
2891 MakeApp
= MakeApp
+ '\n'
2893 CC_FLAGS
= LinuxCFLAGS
2894 if sys
.platform
== "win32":
2895 CC_FLAGS
= WindowsCFLAGS
2896 BuildOptions
= OrderedDict()
2897 for Options
in self
.BuildOptions
:
2898 if Options
[2] != EDKII_NAME
:
2901 if Family
and Family
!= self
.ToolChainFamily
:
2903 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2908 if Target
== TAB_STAR
or Target
== self
._Target
:
2909 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2910 if 'COMMON' not in BuildOptions
:
2911 BuildOptions
['COMMON'] = set()
2912 if Arch
== TAB_STAR
:
2913 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2914 if Arch
in self
.SupArchList
:
2915 if Arch
not in BuildOptions
:
2916 BuildOptions
[Arch
] = set()
2917 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2920 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2921 if len(ArchBuildOptions
.keys()) == 1:
2922 BuildOptions
['COMMON'] |
= (list(ArchBuildOptions
.values())[0])
2923 elif len(ArchBuildOptions
.keys()) > 1:
2924 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2925 BuildOptions
['COMMON'] |
= CommonBuildOptions
2926 ValueList
= [item
for item
in BuildOptions
['COMMON'] if item
.startswith((r
"/U","-U"))]
2927 ValueList
.extend([item
for item
in BuildOptions
['COMMON'] if item
.startswith((r
"/D", "-D"))])
2928 CC_FLAGS
+= " ".join(ValueList
)
2931 if sys
.platform
== "win32":
2932 MakeApp
= MakeApp
+ PcdMakefileEnd
2933 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2935 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2936 MakeApp
= MakeApp
+ '\n'
2937 IncludeFileFullPaths
= []
2938 for includefile
in IncludeFiles
:
2939 for includepath
in IncSearchList
:
2940 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2941 if os
.path
.exists(includefullpath
):
2942 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2945 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "BaseTools/Source/C/Include")))
2946 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "BaseTools/Source/C/Common")))
2947 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2948 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2949 for include_file
in IncFileList
:
2950 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2951 if sys
.platform
== "win32":
2952 PcdValueCommonPath
= os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "Source\C\Common\PcdValueCommon.c"))
2953 MakeApp
= MakeApp
+ '%s\PcdValueCommon.c : %s\n' % (self
.OutputPath
, PcdValueCommonPath
)
2954 MakeApp
= MakeApp
+ '\tcopy /y %s $@\n' % (PcdValueCommonPath
)
2956 PcdValueCommonPath
= os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "Source/C/Common/PcdValueCommon.c"))
2957 MakeApp
= MakeApp
+ '%s/PcdValueCommon.c : %s\n' % (self
.OutputPath
, PcdValueCommonPath
)
2958 MakeApp
= MakeApp
+ '\tcp -f %s %s/PcdValueCommon.c\n' % (PcdValueCommonPath
, self
.OutputPath
)
2959 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2960 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2961 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2963 # start generating input file
2964 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2965 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2966 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2968 Dest_PcdValueInitExe
= PcdValueInitName
2969 if not sys
.platform
== "win32":
2970 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2972 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2974 #start building the structure pcd value tool
2976 if sys
.platform
== "win32":
2977 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2978 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2981 MakeCommand
= 'make -f %s' % (MakeFileName
)
2982 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2985 EdkLogger
.verbose ('%s\n%s\n%s' % (MakeCommand
, StdOut
, StdErr
))
2986 Messages
= Messages
.split('\n')
2989 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2990 File
= open (CAppBaseFileName
+ '.c', 'r')
2991 FileData
= File
.readlines()
2993 for Message
in Messages
:
2994 if " error" in Message
or "warning" in Message
:
2996 FileInfo
= Message
.strip().split('(')
2997 if len (FileInfo
) > 1:
2998 FileName
= FileInfo
[0]
2999 FileLine
= FileInfo
[1].split (')')[0]
3001 FileInfo
= Message
.strip().split(':')
3002 if len(FileInfo
) < 2:
3004 FileName
= FileInfo
[0]
3005 FileLine
= FileInfo
[1]
3008 if "PcdValueInit.c" not in FileName
:
3010 if FileLine
.isdigit():
3011 error_line
= FileData
[int (FileLine
) - 1]
3012 if r
"//" in error_line
:
3013 c_line
, dsc_line
= error_line
.split(r
"//")
3015 dsc_line
= error_line
3016 message_itmes
= Message
.split(":")
3018 if "PcdValueInit.c" not in Message
:
3019 if not MessageGroup
:
3020 MessageGroup
.append(Message
)
3023 for item
in message_itmes
:
3024 if "PcdValueInit.c" in item
:
3025 Index
= message_itmes
.index(item
)
3026 message_itmes
[Index
] = dsc_line
.strip()
3028 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
3031 MessageGroup
.append(Message
)
3033 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
3035 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s\n%s\n%s' % (MakeCommand
, StdOut
, StdErr
))
3037 #start executing the structure pcd value tool
3038 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
3039 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
3040 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
3041 EdkLogger
.verbose ('%s\n%s\n%s' % (Command
, StdOut
, StdErr
))
3043 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s\n%s\n' % (Command
, StdOut
, StdErr
))
3045 #start update structure pcd final value
3046 File
= open (OutputValueFile
, 'r')
3047 FileBuffer
= File
.readlines()
3050 StructurePcdSet
= []
3051 for Pcd
in FileBuffer
:
3052 PcdValue
= Pcd
.split ('|')
3053 PcdInfo
= PcdValue
[0].split ('.')
3054 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
3055 return StructurePcdSet
3058 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
3059 if not os
.path
.exists(OutputFile
):
3061 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
3063 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
3067 ## Retrieve dynamic PCD settings
3069 # @param Type PCD type
3071 # @retval a dict object contains settings of given PCD type
3073 def _GetDynamicPcd(self
, Type
):
3076 Pcds
= OrderedDict()
3078 # tdict is a special dict kind of type, used for selecting correct
3079 # PCD settings for certain ARCH and SKU
3081 PcdDict
= tdict(True, 4)
3083 # Find out all possible PCD candidates for self._Arch
3084 RecordList
= self
._RawData
[Type
, self
._Arch
]
3085 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3088 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3089 SkuName
= SkuName
.upper()
3090 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3091 if SkuName
not in AvailableSkuIdSet
:
3092 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3093 File
=self
.MetaFile
, Line
=Dummy5
)
3094 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
3095 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3096 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3098 # Remove redundant PCD candidates, per the ARCH and SKU
3099 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3101 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3105 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3107 if int(MaxDatumSize
, 0) > 0xFFFF:
3108 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3109 File
=self
.MetaFile
, Line
=Dummy4
)
3110 if int(MaxDatumSize
, 0) < 0:
3111 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3112 File
=self
.MetaFile
, Line
=Dummy4
)
3113 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
3114 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3115 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3116 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3117 if MaxDatumSize
.strip():
3118 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3121 if pcdObject
.MaxDatumSize
:
3122 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3125 if CurrentMaxSize
> PcdMaxSize
:
3126 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3128 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3131 self
._PCD
_TYPE
_STRING
_[Type
],
3136 OrderedDict({SkuName
: SkuInfo
}),
3141 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3142 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3143 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3144 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
3145 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Dummy4
)
3147 for pcd
in Pcds
.values():
3148 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3149 # Only fix the value while no value provided in DSC file.
3150 for sku
in pcd
.SkuInfoList
.values():
3151 if not sku
.DefaultValue
:
3152 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3153 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3154 valuefromDec
= pcdDecObject
.DefaultValue
3155 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
3156 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3157 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3158 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3159 del pcd
.SkuInfoList
[TAB_COMMON
]
3160 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3161 del pcd
.SkuInfoList
[TAB_COMMON
]
3163 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3167 def FilterSkuSettings(self
, PcdObj
):
3169 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
3170 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
3171 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
3172 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
3173 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
3174 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
3176 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
3177 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
3182 def CompareVarAttr(Attr1
, Attr2
):
3183 if not Attr1
or not Attr2
: # for empty string
3185 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
3186 Attr1Set
= set(Attr1s
)
3187 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
3188 Attr2Set
= set(Attr2s
)
3189 if Attr2Set
== Attr1Set
:
3194 def CompletePcdValues(self
, PcdSet
):
3195 Pcds
= OrderedDict()
3196 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
3197 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
3198 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
3199 for PcdCName
, TokenSpaceGuid
in PcdSet
:
3200 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
3202 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
3203 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
3204 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
3205 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
3206 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
3207 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
3208 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
3210 PcdType
= PcdObj
.Type
3211 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
3212 for skuid
in PcdObj
.SkuInfoList
:
3213 skuobj
= PcdObj
.SkuInfoList
[skuid
]
3214 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
3215 for defaultstorename
in DefaultStores
:
3216 if defaultstorename
not in skuobj
.DefaultStoreDict
:
3217 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
3218 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
3219 for skuname
, skuid
in SkuIds
.items():
3220 if skuname
not in PcdObj
.SkuInfoList
:
3221 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
3222 while nextskuid
not in PcdObj
.SkuInfoList
:
3223 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
3224 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
3225 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
3226 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
3227 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
3228 PcdObj
.DefaultValue
= list(PcdObj
.SkuInfoList
.values())[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
3229 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
3231 ## Retrieve dynamic HII PCD settings
3233 # @param Type PCD type
3235 # @retval a dict object contains settings of given PCD type
3237 def _GetDynamicHiiPcd(self
, Type
):
3241 Pcds
= OrderedDict()
3242 UserDefinedDefaultStores
= []
3244 # tdict is a special dict kind of type, used for selecting correct
3245 # PCD settings for certain ARCH and SKU
3247 PcdDict
= tdict(True, 5)
3249 RecordList
= self
._RawData
[Type
, self
._Arch
]
3250 # Find out all possible PCD candidates for self._Arch
3251 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3252 DefaultStoresDefine
= self
._GetDefaultStores
()
3254 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
3255 SkuName
= SkuName
.upper()
3256 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3257 DefaultStore
= DefaultStore
.upper()
3258 if DefaultStore
== TAB_COMMON
:
3259 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
3261 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
3262 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
3263 if SkuName
not in AvailableSkuIdSet
:
3264 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3265 File
=self
.MetaFile
, Line
=Dummy5
)
3266 if DefaultStore
not in DefaultStoresDefine
:
3267 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
3268 File
=self
.MetaFile
, Line
=Dummy5
)
3269 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
) not in PcdList
:
3270 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
3271 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
3274 # Remove redundant PCD candidates, per the ARCH and SKU
3275 for index
,(PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
) in enumerate(PcdList
):
3277 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
3280 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3282 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
3284 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
3285 ExtraData
="[%s]" % VarAttribute
)
3287 FormatCorrect
= True
3288 if VariableOffset
.isdigit():
3289 if int(VariableOffset
, 10) > 0xFFFF:
3291 elif variablePattern
.match(VariableOffset
):
3292 if int(VariableOffset
, 16) > 0xFFFF:
3294 # For Offset written in "A.B"
3295 elif VariableOffset
.find('.') > -1:
3296 VariableOffsetList
= VariableOffset
.split(".")
3297 if not (len(VariableOffsetList
) == 2
3298 and IsValidWord(VariableOffsetList
[0])
3299 and IsValidWord(VariableOffsetList
[1])):
3300 FormatCorrect
= False
3302 FormatCorrect
= False
3303 if not FormatCorrect
:
3304 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
3307 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
3308 if (VariableName
, VariableGuid
) not in VariableAttrs
:
3309 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
3311 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
3312 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
)]))
3314 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
3315 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3316 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3317 if SkuName
in pcdObject
.SkuInfoList
:
3318 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
3319 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
3321 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
3322 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3324 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
3325 PcdClassObj
= PcdClassObject(
3328 self
._PCD
_TYPE
_STRING
_[Type
],
3333 OrderedDict({SkuName
: SkuInfo
}),
3336 pcdDecObject
.validateranges
,
3337 pcdDecObject
.validlists
,
3338 pcdDecObject
.expressions
,
3340 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
3341 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
3342 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
3344 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = index
3345 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3346 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3347 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3348 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
3349 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][DefaultStore
] = (self
.MetaFile
.File
,Dummy4
)
3350 for pcd
in Pcds
.values():
3351 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3352 pcd
.DatumType
= pcdDecObject
.DatumType
3353 # Only fix the value while no value provided in DSC file.
3354 for sku
in pcd
.SkuInfoList
.values():
3355 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
3356 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
3357 for default_store
in sku
.DefaultStoreDict
:
3358 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
3359 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
3360 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3361 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3362 valuefromDec
= pcdDecObject
.DefaultValue
3363 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
3364 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3365 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3366 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3367 del pcd
.SkuInfoList
[TAB_COMMON
]
3368 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3369 del pcd
.SkuInfoList
[TAB_COMMON
]
3371 if pcd
.MaxDatumSize
.strip():
3372 MaxSize
= int(pcd
.MaxDatumSize
, 0)
3375 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
3376 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
3378 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
3379 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
3380 if datalen
> MaxSize
:
3382 for defaultst
in skuobj
.DefaultStoreDict
:
3383 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
3384 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
3385 pcd
.MaxDatumSize
= str(MaxSize
)
3386 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
3388 invalidpcd
= ",".join(invalidhii
)
3389 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
)
3391 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3396 def CheckVariableNameAssignment(Pcds
):
3398 for pcdname
in Pcds
:
3400 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
3401 if len(varnameset
) > 1:
3402 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
3404 return False, invalidhii
3407 ## Retrieve dynamic VPD PCD settings
3409 # @param Type PCD type
3411 # @retval a dict object contains settings of given PCD type
3413 def _GetDynamicVpdPcd(self
, Type
):
3416 Pcds
= OrderedDict()
3418 # tdict is a special dict kind of type, used for selecting correct
3419 # PCD settings for certain ARCH and SKU
3421 PcdDict
= tdict(True, 4)
3424 # Find out all possible PCD candidates for self._Arch
3425 RecordList
= self
._RawData
[Type
, self
._Arch
]
3426 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3428 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3429 SkuName
= SkuName
.upper()
3430 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3431 if SkuName
not in AvailableSkuIdSet
:
3432 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3433 File
=self
.MetaFile
, Line
=Dummy5
)
3434 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
3435 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3436 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3438 # Remove redundant PCD candidates, per the ARCH and SKU
3439 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3440 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3444 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3445 # For the Integer & Boolean type, the optional data can only be InitialValue.
3446 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3447 # until the DEC parser has been called.
3449 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3451 if int(MaxDatumSize
, 0) > 0xFFFF:
3452 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3453 File
=self
.MetaFile
, Line
=Dummy4
)
3454 if int(MaxDatumSize
, 0) < 0:
3455 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3456 File
=self
.MetaFile
, Line
=Dummy4
)
3457 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3458 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3459 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3460 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3461 if MaxDatumSize
.strip():
3462 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3465 if pcdObject
.MaxDatumSize
:
3466 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3469 if CurrentMaxSize
> PcdMaxSize
:
3470 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3472 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3475 self
._PCD
_TYPE
_STRING
_[Type
],
3480 OrderedDict({SkuName
: SkuInfo
}),
3485 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3486 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3487 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3488 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3489 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Dummy4
)
3490 for pcd
in Pcds
.values():
3491 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3492 pcd
.DatumType
= pcdDecObject
.DatumType
3493 # Only fix the value while no value provided in DSC file.
3494 for sku
in pcd
.SkuInfoList
.values():
3495 if not sku
.DefaultValue
:
3496 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3497 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3498 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3499 valuefromDec
= pcdDecObject
.DefaultValue
3500 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3501 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3502 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3503 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3504 del pcd
.SkuInfoList
[TAB_COMMON
]
3505 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3506 del pcd
.SkuInfoList
[TAB_COMMON
]
3508 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3509 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3510 for pcd
in Pcds
.values():
3511 PcdValueTypeSet
= set()
3512 for sku
in pcd
.SkuInfoList
.values():
3513 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3514 if len(PcdValueTypeSet
) > 1:
3515 for sku
in pcd
.SkuInfoList
.values():
3516 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3518 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3521 ## Add external modules
3523 # The external modules are mostly those listed in FDF file, which don't
3526 # @param FilePath The path of module description file
3528 def AddModule(self
, FilePath
):
3529 FilePath
= NormPath(FilePath
)
3530 if FilePath
not in self
.Modules
:
3531 Module
= ModuleBuildClassObject()
3532 Module
.MetaFile
= FilePath
3533 self
.Modules
.append(Module
)
3536 def ToolChainFamily(self
):
3537 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3538 TargetObj
= TargetTxtDict()
3539 TargetTxt
= TargetObj
.Target
3540 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
3541 if os
.path
.isfile(BuildConfigurationFile
) == True:
3542 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3543 if ToolDefinitionFile
== '':
3544 ToolDefinitionFile
= "tools_def.txt"
3545 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
3546 if os
.path
.isfile(ToolDefinitionFile
) == True:
3547 ToolDefObj
= ToolDefDict((os
.path
.join(os
.getenv("WORKSPACE"), "Conf")))
3548 ToolDefinition
= ToolDefObj
.ToolDef
.ToolsDefTxtDatabase
3549 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3550 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3551 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3552 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3554 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3555 return self
._ToolChainFamily
3557 ## Add external PCDs
3559 # The external PCDs are mostly those listed in FDF file to specify address
3560 # or offset information.
3562 # @param Name Name of the PCD
3563 # @param Guid Token space guid of the PCD
3564 # @param Value Value of the PCD
3566 def AddPcd(self
, Name
, Guid
, Value
):
3567 if (Name
, Guid
) not in self
.Pcds
:
3568 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3569 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3573 if self
._DecPcds
is None:
3575 if GlobalData
.gFdfParser
:
3576 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3578 for Inf
in FdfInfList
:
3579 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3580 if ModuleFile
in self
._Modules
:
3582 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3583 PkgSet
.update(ModuleData
.Packages
)
3585 PkgSet
.update(self
.Packages
)
3586 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3587 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3588 return self
._DecPcds