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
,gDefaultTargetTxtFile
23 from Common
.ToolDefClassObject
import ToolDefDict
,gDefaultToolsDefFile
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
):
183 # dict used to convert part of [Defines] to members of DscBuildData directly
188 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
189 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
190 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
191 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
192 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
193 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
194 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
195 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
196 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
197 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
198 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
199 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
200 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
201 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
202 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
205 # used to compose dummy library class name for those forced library instances
206 _NullLibraryNumber
= 0
208 ## Constructor of DscBuildData
210 # Initialize object of DscBuildData
212 # @param FilePath The path of platform description file
213 # @param RawData The raw data of DSC file
214 # @param BuildDataBase Database used to retrieve module/package information
215 # @param Arch The target architecture
216 # @param Platform (not used for DscBuildData)
217 # @param Macros Macros used for replacement in DSC file
219 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
220 self
.MetaFile
= FilePath
221 self
._RawData
= RawData
222 self
._Bdb
= BuildDataBase
224 self
._Target
= Target
225 self
._Toolchain
= Toolchain
226 self
._ToolChainFamily
= None
228 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
229 self
.DefaultStores
= None
230 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
231 self
.UpdatePcdTypeDict()
233 def OutputPath(self
):
234 if os
.getenv("WORKSPACE"):
235 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
237 return os
.path
.dirname(self
.DscFile
)
240 def __setitem__(self
, key
, value
):
241 self
.__dict
__[self
._PROPERTY
_[key
]] = value
244 def __getitem__(self
, key
):
245 return self
.__dict
__[self
._PROPERTY
_[key
]]
248 def __contains__(self
, key
):
249 return key
in self
._PROPERTY
_
251 ## Set all internal used members of DscBuildData to None
254 self
._PlatformName
= None
257 self
._DscSpecification
= None
258 self
._OutputDirectory
= None
259 self
._SupArchList
= None
260 self
._BuildTargets
= None
262 self
._PcdInfoFlag
= None
263 self
._VarCheckFlag
= None
264 self
._FlashDefinition
= None
265 self
._Prebuild
= None
266 self
._Postbuild
= None
267 self
._BuildNumber
= None
268 self
._MakefileName
= None
269 self
._BsBaseAddress
= None
270 self
._RtBaseAddress
= None
273 self
._LibraryInstances
= None
274 self
._LibraryClasses
= None
277 self
._BuildOptions
= None
278 self
._ModuleTypeOptions
= None
279 self
._LoadFixAddress
= None
280 self
._RFCLanguages
= None
281 self
._ISOLanguages
= None
282 self
._VpdToolGuid
= None
283 self
._MacroDict
= None
284 self
.DefaultStores
= None
286 ## Get current effective macros
289 if self
._MacroDict
is None:
291 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
292 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
293 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
294 return self
._MacroDict
302 return self
.MetaFile
.Dir
304 ## Retrieve all information in [Defines] section
306 # (Retrieving all [Defines] information in one-shot is just to save time.)
308 def _GetHeaderInfo(self
):
309 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
310 for Record
in RecordList
:
312 # items defined _PROPERTY_ don't need additional processing
314 # some special items in [Defines] section need special treatment
315 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
316 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
317 if ' ' in self
._OutputDirectory
:
318 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
319 File
=self
.MetaFile
, Line
=Record
[-1],
320 ExtraData
=self
._OutputDirectory
)
321 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
322 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
323 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
325 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
327 elif Name
== TAB_DSC_PREBUILD
:
328 PrebuildValue
= Record
[2]
329 if Record
[2][0] == '"':
330 if Record
[2][-1] != '"':
331 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
332 File
=self
.MetaFile
, Line
=Record
[-1])
333 PrebuildValue
= Record
[2][1:-1]
334 self
._Prebuild
= PrebuildValue
335 elif Name
== TAB_DSC_POSTBUILD
:
336 PostbuildValue
= Record
[2]
337 if Record
[2][0] == '"':
338 if Record
[2][-1] != '"':
339 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
340 File
=self
.MetaFile
, Line
=Record
[-1])
341 PostbuildValue
= Record
[2][1:-1]
342 self
._Postbuild
= PostbuildValue
343 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
344 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
345 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
346 self
._BuildTargets
= GetSplitValueList(Record
[2])
347 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
348 if self
._SkuName
is None:
349 self
._SkuName
= Record
[2]
350 if GlobalData
.gSKUID_CMD
:
351 self
._SkuName
= GlobalData
.gSKUID_CMD
352 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
353 self
._PcdInfoFlag
= Record
[2]
354 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
355 self
._VarCheckFlag
= Record
[2]
356 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
358 self
._LoadFixAddress
= int (Record
[2], 0)
360 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
361 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
362 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
363 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"',
364 File
=self
.MetaFile
, Line
=Record
[-1])
365 LanguageCodes
= Record
[2][1:-1]
366 if not LanguageCodes
:
367 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
368 File
=self
.MetaFile
, Line
=Record
[-1])
369 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
370 # check whether there is empty entries in the list
371 if None in LanguageList
:
372 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
373 File
=self
.MetaFile
, Line
=Record
[-1])
374 self
._RFCLanguages
= LanguageList
375 elif Name
== TAB_DSC_DEFINES_ISO_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 ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
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 ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
382 File
=self
.MetaFile
, Line
=Record
[-1])
383 if len(LanguageCodes
) % 3:
384 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
385 File
=self
.MetaFile
, Line
=Record
[-1])
387 for i
in range(0, len(LanguageCodes
), 3):
388 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
389 self
._ISOLanguages
= LanguageList
390 elif Name
== TAB_DSC_DEFINES_VPD_AUTHENTICATED_VARIABLE_STORE
:
391 if TAB_DSC_DEFINES_VPD_AUTHENTICATED_VARIABLE_STORE
not in gCommandLineDefines
:
392 gCommandLineDefines
[TAB_DSC_DEFINES_VPD_AUTHENTICATED_VARIABLE_STORE
] = Record
[2].strip()
394 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
396 # try to convert GUID to a real UUID value to see whether the GUID is format
397 # for VPD_TOOL_GUID is correct.
402 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
403 self
._VpdToolGuid
= Record
[2]
404 elif Name
== TAB_DSC_DEFINES_PCD_DYNAMIC_AS_DYNAMICEX
:
405 if TAB_DSC_DEFINES_PCD_DYNAMIC_AS_DYNAMICEX
not in gCommandLineDefines
:
406 gCommandLineDefines
[TAB_DSC_DEFINES_PCD_DYNAMIC_AS_DYNAMICEX
] = Record
[2].strip()
408 self
[Name
] = Record
[2]
409 # set _Header to non-None in order to avoid database re-querying
410 self
._Header
= 'DUMMY'
412 ## Retrieve platform name
414 def PlatformName(self
):
415 if self
._PlatformName
is None:
416 if self
._Header
is None:
417 self
._GetHeaderInfo
()
418 if self
._PlatformName
is None:
419 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
420 return self
._PlatformName
424 return self
.PlatformName
426 ## Retrieve file guid
429 if self
._Guid
is None:
430 if self
._Header
is None:
431 self
._GetHeaderInfo
()
432 if self
._Guid
is None:
433 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
436 ## Retrieve platform version
439 if self
._Version
is None:
440 if self
._Header
is None:
441 self
._GetHeaderInfo
()
442 if self
._Version
is None:
443 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
446 ## Retrieve platform description file version
448 def DscSpecification(self
):
449 if self
._DscSpecification
is None:
450 if self
._Header
is None:
451 self
._GetHeaderInfo
()
452 if self
._DscSpecification
is None:
453 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
454 return self
._DscSpecification
456 ## Retrieve OUTPUT_DIRECTORY
458 def OutputDirectory(self
):
459 if self
._OutputDirectory
is None:
460 if self
._Header
is None:
461 self
._GetHeaderInfo
()
462 if self
._OutputDirectory
is None:
463 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
464 return self
._OutputDirectory
466 ## Retrieve SUPPORTED_ARCHITECTURES
468 def SupArchList(self
):
469 if self
._SupArchList
is None:
470 if self
._Header
is None:
471 self
._GetHeaderInfo
()
472 if self
._SupArchList
is None:
473 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
474 return self
._SupArchList
476 ## Retrieve BUILD_TARGETS
478 def BuildTargets(self
):
479 if self
._BuildTargets
is None:
480 if self
._Header
is None:
481 self
._GetHeaderInfo
()
482 if self
._BuildTargets
is None:
483 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
484 return self
._BuildTargets
487 def PcdInfoFlag(self
):
488 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
490 elif self
._PcdInfoFlag
.upper() == 'TRUE':
496 def VarCheckFlag(self
):
497 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
499 elif self
._VarCheckFlag
.upper() == 'TRUE':
504 # # Retrieve SKUID_IDENTIFIER
507 if self
._SkuName
is None:
508 if self
._Header
is None:
509 self
._GetHeaderInfo
()
510 if self
._SkuName
is None:
511 self
._SkuName
= TAB_DEFAULT
514 ## Override SKUID_IDENTIFIER
516 def SkuName(self
, Value
):
517 self
._SkuName
= Value
520 def FlashDefinition(self
):
521 if self
._FlashDefinition
is None:
522 if self
._Header
is None:
523 self
._GetHeaderInfo
()
524 if self
._FlashDefinition
is None:
525 self
._FlashDefinition
= ''
526 return self
._FlashDefinition
530 if self
._Prebuild
is None:
531 if self
._Header
is None:
532 self
._GetHeaderInfo
()
533 if self
._Prebuild
is None:
535 return self
._Prebuild
539 if self
._Postbuild
is None:
540 if self
._Header
is None:
541 self
._GetHeaderInfo
()
542 if self
._Postbuild
is None:
544 return self
._Postbuild
546 ## Retrieve FLASH_DEFINITION
548 def BuildNumber(self
):
549 if self
._BuildNumber
is None:
550 if self
._Header
is None:
551 self
._GetHeaderInfo
()
552 if self
._BuildNumber
is None:
553 self
._BuildNumber
= ''
554 return self
._BuildNumber
556 ## Retrieve MAKEFILE_NAME
558 def MakefileName(self
):
559 if self
._MakefileName
is None:
560 if self
._Header
is None:
561 self
._GetHeaderInfo
()
562 if self
._MakefileName
is None:
563 self
._MakefileName
= ''
564 return self
._MakefileName
566 ## Retrieve BsBaseAddress
568 def BsBaseAddress(self
):
569 if self
._BsBaseAddress
is None:
570 if self
._Header
is None:
571 self
._GetHeaderInfo
()
572 if self
._BsBaseAddress
is None:
573 self
._BsBaseAddress
= ''
574 return self
._BsBaseAddress
576 ## Retrieve RtBaseAddress
578 def RtBaseAddress(self
):
579 if self
._RtBaseAddress
is None:
580 if self
._Header
is None:
581 self
._GetHeaderInfo
()
582 if self
._RtBaseAddress
is None:
583 self
._RtBaseAddress
= ''
584 return self
._RtBaseAddress
586 ## Retrieve the top address for the load fix address
588 def LoadFixAddress(self
):
589 if self
._LoadFixAddress
is None:
590 if self
._Header
is None:
591 self
._GetHeaderInfo
()
593 if self
._LoadFixAddress
is None:
594 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
597 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
599 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
602 # If command line defined, should override the value in DSC file.
604 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
606 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
608 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']))
610 if self
._LoadFixAddress
< 0:
611 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
612 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
613 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
615 return self
._LoadFixAddress
617 ## Retrieve RFCLanguage filter
619 def RFCLanguages(self
):
620 if self
._RFCLanguages
is None:
621 if self
._Header
is None:
622 self
._GetHeaderInfo
()
623 if self
._RFCLanguages
is None:
624 self
._RFCLanguages
= []
625 return self
._RFCLanguages
627 ## Retrieve ISOLanguage filter
629 def ISOLanguages(self
):
630 if self
._ISOLanguages
is None:
631 if self
._Header
is None:
632 self
._GetHeaderInfo
()
633 if self
._ISOLanguages
is None:
634 self
._ISOLanguages
= []
635 return self
._ISOLanguages
637 ## Retrieve the GUID string for VPD tool
639 def VpdToolGuid(self
):
640 if self
._VpdToolGuid
is None:
641 if self
._Header
is None:
642 self
._GetHeaderInfo
()
643 if self
._VpdToolGuid
is None:
644 self
._VpdToolGuid
= ''
645 return self
._VpdToolGuid
647 ## Retrieve [SkuIds] section information
650 if self
._SkuIds
is None:
651 self
._SkuIds
= OrderedDict()
652 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
653 for Record
in RecordList
:
655 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
656 File
=self
.MetaFile
, Line
=Record
[-1])
658 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
659 File
=self
.MetaFile
, Line
=Record
[-1])
660 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
661 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
662 File
=self
.MetaFile
, Line
=Record
[-1])
663 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
664 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_)*'",
665 File
=self
.MetaFile
, Line
=Record
[-1])
666 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
667 if TAB_DEFAULT
not in self
._SkuIds
:
668 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
669 if TAB_COMMON
not in self
._SkuIds
:
670 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
675 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
677 def _GetDefaultStores(self
):
678 if self
.DefaultStores
is None:
679 self
.DefaultStores
= OrderedDict()
680 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
681 for Record
in RecordList
:
683 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
684 File
=self
.MetaFile
, Line
=Record
[-1])
686 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
687 File
=self
.MetaFile
, Line
=Record
[-1])
688 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
689 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
690 File
=self
.MetaFile
, Line
=Record
[-1])
691 if not IsValidWord(Record
[1]):
692 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_-.)*'",
693 File
=self
.MetaFile
, Line
=Record
[-1])
694 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
695 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
696 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
697 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
698 return self
.DefaultStores
700 def OverrideDuplicateModule(self
):
701 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
702 Macros
= self
._Macros
704 for Record
in RecordList
:
706 file_guid
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
707 file_guid_str
= file_guid
[0][2] if file_guid
else "NULL"
708 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
709 if self
._Arch
!= TAB_ARCH_COMMON
and (file_guid_str
,str(ModuleFile
)) in Components
:
710 self
._RawData
.DisableOverrideComponent(Components
[(file_guid_str
,str(ModuleFile
))])
711 Components
[(file_guid_str
,str(ModuleFile
))] = ModuleId
712 self
._RawData
._PostProcessed
= False
714 ## Retrieve packages this Platform depends on
718 RecordList
= self
._RawData
[MODEL_META_DATA_PACKAGE
, self
._Arch
]
719 Macros
= self
._Macros
720 for Record
in RecordList
:
721 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
722 # check the file validation
723 ErrorCode
, ErrorInfo
= File
.Validate('.dec')
726 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
727 # parse this package now. we need it to get protocol/ppi/guid value
728 RetVal
.add(self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
])
731 ## Retrieve [Components] section information
734 if self
._Modules
is not None:
736 self
.OverrideDuplicateModule()
737 self
._Modules
= OrderedDict()
738 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
739 Macros
= self
._Macros
740 for Record
in RecordList
:
741 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
745 # check the file validation
746 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
748 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
751 ModuleBuildData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
752 Module
= ModuleBuildClassObject()
753 Module
.MetaFile
= ModuleFile
754 Module
.Guid
= ModuleBuildData
.Guid
755 # get module private library instance
756 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
757 for Record
in RecordList
:
758 LibraryClass
= Record
[0]
759 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
762 # check the file validation
763 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
765 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
768 if LibraryClass
== '' or LibraryClass
== 'NULL':
769 self
._NullLibraryNumber
+= 1
770 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
771 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
772 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
773 if LibraryPath
not in self
.LibraryInstances
:
774 self
.LibraryInstances
.append(LibraryPath
)
776 # get module private PCD setting
777 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
778 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
779 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
780 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
781 TokenList
= GetSplitValueList(Setting
)
782 DefaultValue
= TokenList
[0]
783 # the format is PcdName| Value | VOID* | MaxDatumSize
784 if len(TokenList
) > 2:
785 MaxDatumSize
= TokenList
[2]
788 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
790 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
792 if ("." in TokenSpaceGuid
or "[" in PcdCName
):
793 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, ModuleBuildData
.Guid
, "", Dummy5
, AnalyzePcdExpression(Setting
)[0]])
795 if ( PCName
,TCName
) not in Module
.Pcds
:
796 Pcd
= PcdClassObject(
808 Module
.Pcds
[PCName
, TCName
] = Pcd
810 Module
.StrPcdSet
= S_PcdSet
811 for TCName
,PCName
, _
,_
,_
,_
,_
,_
in S_PcdSet
:
812 if (PCName
,TCName
) in Module
.Pcds
:
813 Module
.StrPcdOverallValue
[(PCName
,TCName
)] = Module
.Pcds
[(PCName
,TCName
)].DefaultValue
, self
.MetaFile
,Dummy5
814 # get module private build options
815 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
816 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
817 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
818 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
820 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
821 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
823 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
825 if len(RecordList
) != 1:
826 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
827 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
828 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
829 ModuleFile
.Arch
= self
._Arch
830 Module
.Guid
= RecordList
[0][2]
831 for item
in Module
.StrPcdSet
:
832 item
[4] = RecordList
[0][2]
833 self
._Modules
[ModuleFile
] = Module
836 ## Retrieve all possible library instances used in this platform
838 def LibraryInstances(self
):
839 if self
._LibraryInstances
is None:
841 return self
._LibraryInstances
843 ## Retrieve [LibraryClasses] information
845 def LibraryClasses(self
):
846 if self
._LibraryClasses
is None:
847 self
._LibraryInstances
= []
849 # tdict is a special dict kind of type, used for selecting correct
850 # library instance for given library class and module type
852 LibraryClassDict
= tdict(True, 3)
853 # track all library class names
854 LibraryClassSet
= set()
855 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
856 Macros
= self
._Macros
857 for Record
in RecordList
:
858 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
859 if LibraryClass
== '' or LibraryClass
== 'NULL':
860 self
._NullLibraryNumber
+= 1
861 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
862 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
863 LibraryClassSet
.add(LibraryClass
)
864 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
865 # check the file validation
866 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
868 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
871 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
872 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
873 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
874 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
875 if LibraryInstance
not in self
._LibraryInstances
:
876 self
._LibraryInstances
.append(LibraryInstance
)
878 # resolve the specific library instance for each class and each module type
879 self
._LibraryClasses
= tdict(True)
880 for LibraryClass
in LibraryClassSet
:
881 # try all possible module types
882 for ModuleType
in SUP_MODULE_LIST
:
883 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
884 if LibraryInstance
is None:
886 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
888 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
889 for Record
in RecordList
:
890 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
892 # check the file validation
893 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
895 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
897 if File
not in self
._LibraryInstances
:
898 self
._LibraryInstances
.append(File
)
900 # we need the module name as the library class name, so we have
901 # to parse it here. (self._Bdb[] will trigger a file parse if it
902 # hasn't been parsed)
904 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
905 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
906 return self
._LibraryClasses
908 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
909 if not self
._DecPcds
:
912 if GlobalData
.gFdfParser
:
913 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
916 for Inf
in FdfInfList
:
917 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
918 if ModuleFile
in self
._Modules
:
920 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
921 PkgSet
.update(ModuleData
.Packages
)
923 PkgSet
.update(self
.Packages
)
924 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
925 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
927 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
928 EdkLogger
.error('build', PARSER_ERROR
,
929 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
930 File
=self
.MetaFile
, Line
=LineNo
)
931 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
933 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
934 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
935 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
937 if ValueList
[2] == '-1':
938 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
939 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
941 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
942 if "{CODE(" not in ValueList
[Index
]:
944 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
945 except BadExpression
as Value
:
946 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
947 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
948 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
949 except EvaluationException
as Excpt
:
950 if hasattr(Excpt
, 'Pcd'):
951 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
952 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
953 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
954 " of the DSC file" % Excpt
.Pcd
,
955 File
=self
.MetaFile
, Line
=LineNo
)
957 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
958 File
=self
.MetaFile
, Line
=LineNo
)
960 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
961 File
=self
.MetaFile
, Line
=LineNo
)
964 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
966 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
967 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
968 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
969 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
970 DecPcd
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
971 EdkLogger
.error('build', FORMAT_INVALID
,
972 "Pcd datumtype used in DSC file is not the same as its declaration. DatumType:%s"%DecPcd
.DatumType
,
973 File
=self
.MetaFile
, Line
=LineNo
,
974 ExtraData
="Dsc:%s.%s|%s\n Dec:%s.%s|%s|%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
, TokenSpaceGuid
, \
975 PcdCName
, DecPcd
.DefaultValue
, DecPcd
.DatumType
, DecPcd
.TokenValue
))
976 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
977 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
978 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
981 def _FilterPcdBySkuUsage(self
, Pcds
):
982 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
983 sku_usage
= self
.SkuIdMgr
.SkuUsageType
984 if sku_usage
== SkuClass
.SINGLE
:
987 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
988 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
989 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
993 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
994 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
995 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
998 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
999 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
]]]
1000 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1002 for skuid
in pcd
.SkuInfoList
:
1003 skuobj
= pcd
.SkuInfoList
.get(skuid
)
1004 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
1005 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
1006 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1007 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
1010 def RecoverCommandLinePcd(self
):
1011 def UpdateCommandLineValue(pcd
):
1012 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1013 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1014 pcd
.PcdValueFromComm
= pcd
.DefaultValue
1015 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1016 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
1018 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
1019 for pcd
in self
._Pcds
:
1020 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
1021 UpdateCommandLineValue(self
._Pcds
[pcd
])
1023 def __ParsePcdFromCommandLine(self
):
1024 if GlobalData
.BuildOptionPcd
:
1025 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
1026 if isinstance(pcd
, tuple):
1028 (pcdname
, pcdvalue
) = pcd
.split('=')
1030 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1032 (Name1
, Name2
) = pcdname
.split('.', 1)
1034 (Name3
, FieldName
) = Name2
.split(".", 1)
1035 if ((Name3
, Name1
)) in self
.DecPcds
:
1036 HasTokenSpace
= True
1038 TokenSpaceGuidCName
= Name1
1042 TokenSpaceGuidCName
= ''
1043 HasTokenSpace
= False
1045 if ((Name2
, Name1
)) in self
.DecPcds
:
1046 HasTokenSpace
= True
1048 TokenSpaceGuidCName
= Name1
1053 TokenSpaceGuidCName
= ''
1054 HasTokenSpace
= False
1057 TokenCName
= pcdname
1058 TokenSpaceGuidCName
= ''
1059 HasTokenSpace
= False
1060 TokenSpaceGuidCNameList
= []
1063 DisplayName
= TokenCName
1065 DisplayName
= TokenCName
+ '.' + FieldName
1066 if not HasTokenSpace
:
1067 for key
in self
.DecPcds
:
1068 PcdItem
= self
.DecPcds
[key
]
1069 if TokenCName
== PcdItem
.TokenCName
:
1070 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1071 if len (TokenSpaceGuidCNameList
) < 1:
1072 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1073 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1074 PcdDatumType
= PcdItem
.DatumType
1080 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1083 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1084 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1088 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1090 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1091 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1093 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1095 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1096 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1098 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1099 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1101 if GlobalData
.BuildOptionPcd
:
1102 inf_objs
= [item
for item
in self
._Bdb
._CACHE
_.values() if item
.Arch
== self
.Arch
and item
.MetaFile
.Ext
.lower() == '.inf']
1103 for pcd
in GlobalData
.BuildOptionPcd
:
1104 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1105 for BuildData
in inf_objs
:
1106 for key
in BuildData
.Pcds
:
1107 PcdItem
= BuildData
.Pcds
[key
]
1108 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1109 PcdItem
.DefaultValue
= pcdvalue
1110 PcdItem
.PcdValueFromComm
= pcdvalue
1111 #In command line, the latter full assign value in commandLine should override the former field assign value.
1112 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1115 if GlobalData
.BuildOptionPcd
:
1116 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1117 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1119 if (TokenSpaceGuid
, Token
) not in field_assign
:
1120 field_assign
[TokenSpaceGuid
, Token
] = []
1121 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1123 if (TokenSpaceGuid
, Token
) in field_assign
:
1124 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1125 field_assign
[TokenSpaceGuid
, Token
] = []
1126 for item
in delete_assign
:
1127 GlobalData
.BuildOptionPcd
.remove(item
)
1130 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1133 TokenCName
+= '.' + FieldName
1134 if PcdValue
.startswith('H'):
1135 if FieldName
and _IsFieldValueAnArray(PcdValue
[1:]):
1136 PcdDatumType
= TAB_VOID
1138 if FieldName
and not IsArray
:
1141 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1142 except BadExpression
as Value
:
1143 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1144 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1145 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1146 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1147 PcdDatumType
= TAB_VOID
1149 if FieldName
and not IsArray
:
1152 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1153 except BadExpression
as Value
:
1154 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1155 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1156 elif PcdValue
.startswith('L'):
1157 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1158 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1159 PcdDatumType
= TAB_VOID
1161 if FieldName
and not IsArray
:
1164 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1165 except BadExpression
as Value
:
1166 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1167 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1169 if PcdValue
.upper() == 'FALSE':
1171 if PcdValue
.upper() == 'TRUE':
1174 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1175 PcdValue
= '"' + PcdValue
+ '"'
1176 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1177 PcdValue
= '"' + PcdValue
+ '"'
1181 if PcdValue
.upper().startswith('0X'):
1184 Num
= int(PcdValue
, Base
)
1186 PcdValue
= '"' + PcdValue
+ '"'
1187 if _IsFieldValueAnArray(PcdValue
):
1188 PcdDatumType
= TAB_VOID
1193 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1194 except BadExpression
as Value
:
1195 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1196 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1199 ## Retrieve all PCD settings in platform
1202 if self
._Pcds
is None:
1203 self
._Pcds
= OrderedDict()
1204 self
.__ParsePcdFromCommandLine
()
1205 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1206 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1207 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1208 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1209 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1210 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1211 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1212 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1213 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1215 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1216 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1217 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1218 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1219 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1220 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1222 self
.RecoverCommandLinePcd()
1225 ## Retrieve [BuildOptions]
1227 def BuildOptions(self
):
1228 if self
._BuildOptions
is None:
1229 self
._BuildOptions
= OrderedDict()
1231 # Retrieve build option for EDKII and EDK style module
1233 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1234 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1235 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1236 if Dummy3
.upper() != TAB_COMMON
:
1238 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1240 # Only flags can be appended
1242 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1243 self
._BuildOptions
[CurKey
] = Option
1245 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1246 self
._BuildOptions
[CurKey
] += ' ' + Option
1247 return self
._BuildOptions
1248 def GetBuildOptionsByPkg(self
, Module
, ModuleType
):
1250 local_pkg
= os
.path
.split(Module
.LocalPkg())[0]
1251 if self
._ModuleTypeOptions
is None:
1252 self
._ModuleTypeOptions
= OrderedDict()
1253 if ModuleType
not in self
._ModuleTypeOptions
:
1254 options
= OrderedDict()
1255 self
._ModuleTypeOptions
[ ModuleType
] = options
1256 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1257 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1258 if Dummy2
not in (TAB_COMMON
,local_pkg
.upper(),"EDKII"):
1261 if Type
.upper() == ModuleType
.upper():
1262 Key
= (ToolChainFamily
, ToolChain
)
1263 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1264 options
[Key
] = Option
1266 if ' ' + Option
not in options
[Key
]:
1267 options
[Key
] += ' ' + Option
1268 return self
._ModuleTypeOptions
[ModuleType
]
1269 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1270 if self
._ModuleTypeOptions
is None:
1271 self
._ModuleTypeOptions
= OrderedDict()
1272 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1273 options
= OrderedDict()
1274 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1275 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1276 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1277 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1278 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1279 Type
= Dummy2
+ '.' + Dummy3
1280 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1281 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1282 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1283 options
[Key
] = Option
1285 if ' ' + Option
not in options
[Key
]:
1286 options
[Key
] += ' ' + Option
1287 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1290 def GetStructurePcdInfo(PcdSet
):
1291 structure_pcd_data
= defaultdict(list)
1293 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1295 return structure_pcd_data
1298 def OverrideByFdf(StruPcds
,workspace
):
1299 if GlobalData
.gFdfParser
is None:
1301 StructurePcdInFdf
= OrderedDict()
1302 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1303 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1304 for item
in fdfpcd
:
1305 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1306 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1307 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1308 for Pcd
in StruPcds
.values():
1309 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1311 FieldValues
= OrderedDict()
1312 for item
in StructurePcdInFdf
:
1313 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1314 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1315 for field
in FieldValues
:
1316 if field
not in Pcd
.PcdFieldValueFromFdf
:
1317 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1318 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1319 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1320 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1325 def OverrideByComm(StruPcds
):
1326 StructurePcdInCom
= OrderedDict()
1327 for item
in GlobalData
.BuildOptionPcd
:
1328 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1329 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1330 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1331 for Pcd
in StruPcds
.values():
1332 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1334 FieldValues
= OrderedDict()
1335 for item
in StructurePcdInCom
:
1336 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1337 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1338 for field
in FieldValues
:
1339 if field
not in Pcd
.PcdFieldValueFromComm
:
1340 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1341 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1342 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1343 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1346 def OverrideByCommOverAll(self
,AllPcds
):
1347 def CheckStructureInComm(commpcds
):
1350 if len(commpcds
[0]) == 5:
1353 NoFiledValues
= OrderedDict()
1354 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1355 StructurePcdInCom
= OrderedDict()
1356 for item
in GlobalData
.BuildOptionPcd
:
1357 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1358 for item
in StructurePcdInCom
:
1360 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1362 for item
in GlobalData
.BuildOptionPcd
:
1363 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1364 for Guid
, Name
in NoFiledValues
:
1365 if (Name
, Guid
) in AllPcds
:
1366 Pcd
= AllPcds
.get((Name
, Guid
))
1367 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1368 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1370 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1371 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1372 for sku
in Pcd
.SkuInfoList
:
1373 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1374 if SkuInfo
.DefaultValue
:
1375 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1377 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1378 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1379 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1380 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1381 if Pcd
.DatumType
== TAB_VOID
:
1382 if not Pcd
.MaxDatumSize
:
1383 Pcd
.MaxDatumSize
= '0'
1384 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1385 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1386 MaxSize
= max(CurrentSize
, OptionSize
)
1387 Pcd
.MaxDatumSize
= str(MaxSize
)
1389 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1391 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1392 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1393 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1394 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1395 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1396 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1397 self
._Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1398 self
._Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1399 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1400 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1401 self
._Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1404 def OverrideByFdfOverAll(self
,AllPcds
):
1406 if GlobalData
.gFdfParser
is None:
1408 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1409 for Name
,Guid
,Field
in NoFiledValues
:
1412 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1413 if (Name
,Guid
) in AllPcds
:
1414 Pcd
= AllPcds
.get((Name
,Guid
))
1415 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1416 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1418 Pcd
.PcdValueFromComm
= Value
1419 Pcd
.DefaultValue
= Value
1420 for sku
in Pcd
.SkuInfoList
:
1421 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1422 if SkuInfo
.DefaultValue
:
1423 SkuInfo
.DefaultValue
= Value
1425 SkuInfo
.HiiDefaultValue
= Value
1426 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1427 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1428 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1429 if Pcd
.DatumType
== TAB_VOID
:
1430 if not Pcd
.MaxDatumSize
:
1431 Pcd
.MaxDatumSize
= '0'
1432 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1433 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1434 MaxSize
= max(CurrentSize
, OptionSize
)
1435 Pcd
.MaxDatumSize
= str(MaxSize
)
1437 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1439 PcdInDec
.PcdValueFromFdf
= Value
1440 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1441 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1442 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1443 self
._Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1444 self
._Pcds
[Name
, Guid
].DefaultValue
= Value
1447 def ParsePcdNameStruct(self
,NamePart1
,NamePart2
):
1448 TokenSpaceCName
= PcdCName
= DimensionAttr
= Field
= ""
1449 if "." in NamePart1
:
1450 TokenSpaceCName
, TempPcdCName
= NamePart1
.split(".")
1451 if "[" in TempPcdCName
:
1452 PcdCName
= TempPcdCName
[:TempPcdCName
.index("[")]
1453 DimensionAttr
= TempPcdCName
[TempPcdCName
.index("["):]
1455 PcdCName
= TempPcdCName
1458 TokenSpaceCName
= NamePart1
1459 if "[" in NamePart2
:
1460 PcdCName
= NamePart2
[:NamePart2
.index("[")]
1461 DimensionAttr
= NamePart2
[NamePart2
.index("["):]
1463 PcdCName
= NamePart2
1465 return TokenSpaceCName
,PcdCName
,DimensionAttr
,Field
1467 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1469 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1470 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1471 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1472 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1473 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1474 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1477 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1478 SkuIds
= self
.SkuIds
1479 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1480 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1481 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1484 # Find out all possible PCD candidates for self._Arch
1487 for Type
in TypeList
:
1488 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1490 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1491 SkuName
= SkuName
.upper()
1492 default_store
= default_store
.upper()
1493 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1494 if SkuName
not in SkuIds
:
1496 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
1497 pcd_in_dec
= self
._DecPcds
.get((PCName
,TCName
), None)
1498 if pcd_in_dec
is None:
1499 EdkLogger
.error('build', PARSER_ERROR
,
1500 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1501 File
=self
.MetaFile
, Line
= Dummy5
)
1502 if SkuName
in SkuIds
and ("." in TokenSpaceGuid
or "[" in PcdCName
):
1503 if not isinstance (pcd_in_dec
, StructurePcd
):
1504 EdkLogger
.error('build', PARSER_ERROR
,
1505 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1506 File
=self
.MetaFile
, Line
= Dummy5
)
1508 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1509 ModuleScopeOverallValue
= {}
1510 for m
in self
.Modules
.values():
1513 S_PcdSet
.extend(m
.StrPcdSet
)
1514 mguid
= m
.StrPcdSet
[0][4]
1515 for (PCName
,TCName
) in m
.StrPcdOverallValue
:
1516 Value
, dsc_file
, lineNo
= m
.StrPcdOverallValue
[(PCName
,TCName
)]
1517 ModuleScopeOverallValue
.setdefault((PCName
,TCName
),{})[mguid
] = Value
, dsc_file
, lineNo
1518 # handle pcd value override
1519 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1520 S_pcd_set
= OrderedDict()
1521 for str_pcd
in StrPcdSet
:
1522 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1523 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1524 str_pcd_obj_str
= StructurePcd()
1525 str_pcd_obj_str
.copy(str_pcd_dec
)
1527 str_pcd_obj_str
.copy(str_pcd_obj
)
1528 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1529 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
}
1531 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
}
1532 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1533 if str_pcd_data
[4] in SkuIds
:
1534 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])
1535 elif GlobalData
.gGuidPattern
.match(str_pcd_data
[4]):
1536 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])
1537 PcdComponentValue
= ModuleScopeOverallValue
.get((str_pcd_obj_str
.TokenCName
,str_pcd_obj_str
.TokenSpaceGuidCName
))
1538 for module_guid
in PcdComponentValue
:
1539 str_pcd_obj_str
.PcdValueFromComponents
[module_guid
.replace("-","S")] = PcdComponentValue
[module_guid
]
1540 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1542 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1543 for Pcd
in self
.DecPcds
:
1544 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1545 if Pcd
not in S_pcd_set
:
1546 str_pcd_obj_str
= StructurePcd()
1547 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1548 str_pcd_obj
= Pcds
.get(Pcd
, None)
1550 str_pcd_obj_str
.copy(str_pcd_obj
)
1551 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1552 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
}
1554 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
}
1555 S_pcd_set
[Pcd
] = str_pcd_obj_str
1557 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
.copy()
1558 self
.FilterStrcturePcd(S_pcd_set
)
1559 for stru_pcd
in S_pcd_set
.values():
1560 for skuid
in SkuIds
:
1561 if skuid
in stru_pcd
.SkuOverrideValues
:
1563 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1565 if skuid
not in stru_pcd
.SkuOverrideValues
:
1566 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1567 if nextskuid
== TAB_DEFAULT
:
1570 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1571 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})
1573 stru_pcd
.ValueChain
.add((skuid
, ''))
1574 if 'DEFAULT' in stru_pcd
.SkuOverrideValues
and not GlobalData
.gPcdSkuOverrides
.get((stru_pcd
.TokenCName
, stru_pcd
.TokenSpaceGuidCName
)):
1575 GlobalData
.gPcdSkuOverrides
.update(
1576 {(stru_pcd
.TokenCName
, stru_pcd
.TokenSpaceGuidCName
): {'DEFAULT':stru_pcd
.SkuOverrideValues
['DEFAULT']}})
1577 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1578 for skuid
in SkuIds
:
1581 if skuid
not in stru_pcd
.SkuOverrideValues
:
1582 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1583 if nextskuid
== TAB_DEFAULT
:
1586 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1589 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1590 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1592 for defaultstoreid
in DefaultStores
:
1593 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1594 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = CopyDict(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1595 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1596 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1597 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1599 # Create a tool to caculate structure pcd value
1600 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1603 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1604 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1605 if str_pcd_obj
is None:
1606 print(PcdName
, PcdGuid
)
1608 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1609 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1610 if skuname
not in str_pcd_obj
.SkuInfoList
:
1611 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1613 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1614 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1615 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1616 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1617 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1618 str_pcd_obj
.DefaultValue
= PcdValue
1620 #Module Scope Structure Pcd
1621 moduleguid
= skuname
.replace("S","-")
1622 if GlobalData
.gGuidPattern
.match(moduleguid
):
1623 for component
in self
.Modules
.values():
1624 if component
.Guid
== moduleguid
:
1625 component
.Pcds
[(PcdName
, PcdGuid
)].DefaultValue
= PcdValue
1628 if skuname
not in str_pcd_obj
.SkuInfoList
:
1629 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1631 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1632 if nextskuid
== TAB_DEFAULT
:
1635 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1636 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
)
1637 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1638 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1640 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1641 for str_pcd_obj
in S_pcd_set
.values():
1642 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1643 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1645 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1646 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1647 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1648 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1650 for str_pcd_obj
in S_pcd_set
.values():
1652 str_pcd_obj
.MaxDatumSize
= DscBuildData
.GetStructurePcdMaxSize(str_pcd_obj
)
1653 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1654 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1658 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1659 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1660 del pcd
.SkuInfoList
[TAB_COMMON
]
1661 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1662 del pcd
.SkuInfoList
[TAB_COMMON
]
1664 list(map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
]))
1667 def PlatformUsedPcds(self
):
1669 if GlobalData
.gFdfParser
:
1670 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1671 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1672 AllModulePcds
= set()
1673 ModuleSet
= set(list(self
._Modules
.keys()) + FdfModuleList
)
1674 for ModuleFile
in ModuleSet
:
1675 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1676 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1677 for ModuleFile
in self
.LibraryInstances
:
1678 ModuleData
= self
._Bdb
.CreateBuildObject(ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
)
1679 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1680 return AllModulePcds
1682 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1683 def FilterStrcturePcd(self
, S_pcd_set
):
1684 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.PlatformUsedPcds
1685 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1686 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1688 ## Retrieve non-dynamic PCD settings
1690 # @param Type PCD type
1692 # @retval a dict object contains settings of given PCD type
1694 def _GetPcd(self
, Type
):
1695 Pcds
= OrderedDict()
1697 # tdict is a special dict kind of type, used for selecting correct
1698 # PCD settings for certain ARCH
1700 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1702 PcdDict
= tdict(True, 4)
1704 # Find out all possible PCD candidates for self._Arch
1705 RecordList
= self
._RawData
[Type
, self
._Arch
]
1706 PcdValueDict
= OrderedDict()
1707 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1708 SkuName
= SkuName
.upper()
1709 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1710 if SkuName
not in AvailableSkuIdSet
:
1711 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1712 File
=self
.MetaFile
, Line
=Dummy5
)
1713 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1714 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
1715 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1716 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1718 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
1719 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1722 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1724 if int(MaxDatumSize
, 0) > 0xFFFF:
1725 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1726 File
=self
.MetaFile
, Line
=Dummy4
)
1727 if int(MaxDatumSize
, 0) < 0:
1728 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1729 File
=self
.MetaFile
, Line
=Dummy4
)
1730 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1731 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
,Dummy4
)
1733 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
,Dummy4
)}
1735 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.items():
1736 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1737 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1738 elif TAB_DEFAULT
in PcdSetting
:
1739 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[TAB_DEFAULT
]
1740 elif TAB_COMMON
in PcdSetting
:
1741 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[TAB_COMMON
]
1747 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1750 self
._PCD
_TYPE
_STRING
_[Type
],
1759 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1760 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1761 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1762 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1763 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
1764 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1765 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Settings
[3])
1769 def GetStructurePcdMaxSize(str_pcd
):
1770 pcd_default_value
= str_pcd
.DefaultValue
1771 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()]
1772 sku_values
.append(pcd_default_value
)
1774 def get_length(value
):
1775 Value
= value
.strip()
1777 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1779 if Value
.startswith('L"') and Value
.endswith('"'):
1780 return len(Value
[2:-1])
1781 if Value
[0] == '"' and Value
[-1] == '"':
1782 return len(Value
) - 2
1783 if Value
.strip().startswith("{CODE("):
1784 tmpValue
= RemoveCComments(Value
)
1785 return len(tmpValue
.split(","))
1786 if (Value
[0] == '{' and Value
[-1] == '}'):
1787 return len(Value
.split(","))
1788 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1789 return len(list(Value
[2:-1]))
1790 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1791 return len(Value
) - 2
1794 return str(max(get_length(item
) for item
in sku_values
))
1797 def ExecuteCommand (Command
):
1799 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1801 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1802 Result
= Process
.communicate()
1803 return Process
.returncode
, Result
[0].decode(errors
='ignore'), Result
[1].decode(errors
='ignore')
1806 def IntToCString(Value
, ValueSize
):
1808 if not isinstance (Value
, str):
1809 for Index
in range(0, ValueSize
):
1810 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1812 Result
= Result
+ '"'
1815 def GenerateSizeFunction(self
, Pcd
):
1816 CApp
= "// Default Value in Dec \n"
1817 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1819 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
1820 CApp
+= " *Size = (sizeof (%s) > *Size ? sizeof (%s) : *Size);\n" % (Pcd
.DatumType
,Pcd
.DatumType
)
1822 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1823 CApp
+= " *Size = (sizeof (%s_%s_INIT_Value) > *Size ? sizeof (%s_%s_INIT_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)
1824 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
1825 for skuname
in Pcd
.SkuInfoList
:
1826 skuobj
= Pcd
.SkuInfoList
[skuname
]
1827 if skuobj
.VariableName
:
1828 for defaultstore
in skuobj
.DefaultStoreDict
:
1829 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,defaultstore
)
1831 if "{CODE(" in pcddef
:
1832 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
)
1834 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1836 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
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
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1841 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1843 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,TAB_DEFAULT
,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
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1848 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1850 for index
in Pcd
.DefaultValues
:
1852 ActualCap
.append(index
)
1853 FieldList
= Pcd
.DefaultValues
[index
]
1856 for FieldName
in FieldList
:
1857 FieldName
= "." + FieldName
1858 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1859 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1861 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1862 except BadExpression
:
1863 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1864 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1865 Value
, ValueSize
= ParseFieldValue(Value
)
1866 if not Pcd
.IsArray():
1867 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]);
1870 FieldName_ori
= FieldName
.strip('.')
1871 while '[' in FieldName
:
1872 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1873 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1874 FieldName
= FieldName
.split(']', 1)[1]
1875 FieldName
= NewFieldName
+ FieldName
1876 while '[' in FieldName
and not Pcd
.IsArray():
1877 FieldName
= FieldName
.rsplit('[', 1)[0]
1878 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])
1879 flexisbale_size_statement_cache
= set()
1880 for skuname
in Pcd
.SkuOverrideValues
:
1881 if skuname
== TAB_COMMON
:
1883 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1884 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1885 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1887 ActualCap
.append(index
)
1888 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1891 for FieldName
in FieldList
:
1892 fieldinfo
= tuple(FieldList
[FieldName
])
1893 if fieldinfo
in flexisbale_size_statement_cache
:
1895 flexisbale_size_statement_cache
.add(fieldinfo
)
1896 FieldName
= "." + FieldName
1897 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1898 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1900 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1901 except BadExpression
:
1902 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1903 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1904 Value
, ValueSize
= ParseFieldValue(Value
)
1905 if not Pcd
.IsArray():
1906 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd
.DatumType
, FieldName
.strip("."), ValueSize
, Pcd
.DatumType
, FieldName
.strip("."), ValueSize
, Pcd
.DatumType
, FieldName
.strip("."), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2], FieldList
[FieldName
.strip(".")][0]);
1909 FieldName_ori
= FieldName
.strip('.')
1910 while '[' in FieldName
:
1911 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1912 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1913 FieldName
= FieldName
.split(']', 1)[1]
1914 FieldName
= NewFieldName
+ FieldName
1915 while '[' in FieldName
and not Pcd
.IsArray():
1916 FieldName
= FieldName
.rsplit('[', 1)[0]
1917 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), Array_Index
+ 1, FieldList
[FieldName_ori
][1], FieldList
[FieldName_ori
][2], FieldList
[FieldName_ori
][0])
1918 if Pcd
.PcdFieldValueFromFdf
:
1919 CApp
= CApp
+ "// From fdf \n"
1920 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1921 FieldName
= "." + FieldName
1922 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1923 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1925 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1926 except BadExpression
:
1927 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1928 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1929 Value
, ValueSize
= ParseFieldValue(Value
)
1930 if not Pcd
.IsArray():
1931 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]);
1934 FieldName_ori
= FieldName
.strip('.')
1935 while '[' in FieldName
:
1936 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1937 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1938 FieldName
= FieldName
.split(']', 1)[1]
1939 FieldName
= NewFieldName
+ FieldName
1940 while '[' in FieldName
:
1941 FieldName
= FieldName
.rsplit('[', 1)[0]
1942 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])
1943 if Pcd
.PcdFieldValueFromComm
:
1944 CApp
= CApp
+ "// From Command Line \n"
1945 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1946 FieldName
= "." + FieldName
1947 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1948 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1950 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1951 except BadExpression
:
1952 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1953 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1954 Value
, ValueSize
= ParseFieldValue(Value
)
1955 if not Pcd
.IsArray():
1956 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]);
1959 FieldName_ori
= FieldName
.strip('.')
1960 while '[' in FieldName
:
1961 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1962 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1963 FieldName
= FieldName
.split(']', 1)[1]
1964 FieldName
= NewFieldName
+ FieldName
1965 while '[' in FieldName
and not Pcd
.IsArray():
1966 FieldName
= FieldName
.rsplit('[', 1)[0]
1967 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])
1968 if Pcd
.GetPcdMaxSize():
1969 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1970 ArraySizeByAssign
= self
.CalculateActualCap(ActualCap
)
1971 if ArraySizeByAssign
> 1:
1972 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); \n" % (ArraySizeByAssign
, ArraySizeByAssign
)
1975 def CalculateActualCap(self
,ActualCap
):
1979 for item
in ActualCap
:
1980 index_elements
= ArrayIndex
.findall(item
)
1982 for index_e
in index_elements
:
1983 index_num
= index_e
.lstrip("[").rstrip("]").strip()
1985 # Not support flexiable pcd array assignment
1987 index_num
= int(index_num
,16) if index_num
.startswith(("0x","0X")) else int(index_num
)
1988 rt
= rt
* (index_num
+1)
1995 def GenerateSizeStatments(Pcd
,skuname
,defaultstorename
):
1997 r_datatype
= [Pcd
.BaseDatumType
]
1998 lastoneisEmpty
= False
1999 for dem
in Pcd
.Capacity
:
2001 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. " %
2002 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))))
2003 if dem
== '0' or dem
== "-1":
2004 r_datatype
.append("[1]")
2005 lastoneisEmpty
= True
2007 r_datatype
.append("[" + dem
+ "]")
2009 if Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_HII
, MODEL_PCD_DYNAMIC_HII
]:
2010 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultStoreDict
.get(defaultstorename
)
2011 elif Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_DEFAULT
,MODEL_PCD_DYNAMIC_VPD
,MODEL_PCD_DYNAMIC_DEFAULT
,MODEL_PCD_DYNAMIC_EX_VPD
]:
2012 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultValue
2014 PcdDefValue
= Pcd
.DefaultValue
2016 if "{CODE(" not in PcdDefValue
:
2017 sizebasevalue_plus
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
2018 sizebasevalue
= "(%s / sizeof(%s))" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
2019 sizeof
= "sizeof(%s)" % Pcd
.BaseDatumType
2020 CApp
= ' int ArraySize = %s %% %s ? %s : %s ;\n' % ( (DscBuildData
.GetStructurePcdMaxSize(Pcd
), sizeof
, sizebasevalue_plus
, sizebasevalue
))
2021 CApp
+= ' Size = ArraySize * sizeof(%s); \n' % Pcd
.BaseDatumType
2023 CApp
= " Size = 0;\n"
2025 CApp
= ' Size = sizeof(%s);\n' % ("".join(r_datatype
) )
2027 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
2028 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2031 def GetIndicator(self
,index
,FieldName
,Pcd
):
2032 def cleanupindex(indexstr
):
2033 return indexstr
.strip("[").strip("]").strip()
2034 index_elements
= ArrayIndex
.findall(index
)
2035 pcd_capacity
= Pcd
.Capacity
2038 if len(pcd_capacity
)>2:
2039 for i
in range(0,len(index_elements
)):
2040 index_ele
= index_elements
[i
]
2041 index_num
= index_ele
.strip("[").strip("]").strip()
2042 if i
== len(index_elements
) -2:
2043 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
]))
2046 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]))
2047 elif len(pcd_capacity
) == 2:
2048 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
2049 elif len(pcd_capacity
) == 1:
2050 index_ele
= index_elements
[0]
2051 index_num
= index_ele
.strip("[").strip("]").strip()
2052 indicator
+= " + %s)" % (index_num
)
2056 indicator
+= "->" + FieldName
2059 def GetStarNum(self
,Pcd
):
2060 if not Pcd
.IsArray():
2062 elif Pcd
.IsSimpleTypeArray():
2063 return len(Pcd
.Capacity
)
2065 return len(Pcd
.Capacity
) + 1
2066 def GenerateDefaultValueAssignFunction(self
, Pcd
):
2067 CApp
= "// Default value in Dec \n"
2068 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2069 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2070 CApp
= CApp
+ ' CHAR8 *Value;\n'
2071 CApp
= CApp
+ ' UINT32 PcdArraySize;\n'
2072 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
2073 IsArray
= _IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
2076 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
2077 except BadExpression
:
2078 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
2079 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
2080 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
2081 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
2084 # Use memcpy() to copy value into field
2087 pcdarraysize
= Pcd
.PcdArraySize()
2088 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2089 if Pcd
.Capacity
[-1] != "-1":
2090 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])
2091 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2092 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2094 if Pcd
.Capacity
[-1] != "-1":
2095 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])
2096 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2097 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
2098 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2100 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2101 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2102 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2104 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
2105 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2106 elif isinstance(Value
, str):
2107 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
2108 for index
in Pcd
.DefaultValues
:
2109 FieldList
= Pcd
.DefaultValues
[index
]
2112 for FieldName
in FieldList
:
2113 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2116 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2117 except BadExpression
:
2118 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2119 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2122 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2124 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2126 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2129 # Use memcpy() to copy value into field
2131 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2132 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2133 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])
2134 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2135 elif isinstance(Value
, str):
2136 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2138 if '[' in FieldName
and ']' in FieldName
:
2139 Index
= int(FieldName
.split('[')[1].split(']')[0])
2140 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
)
2142 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2144 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2149 def GenerateDefaultValueAssignStatement(Pcd
):
2150 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2153 def GetPcdDscRawDefaultValue(self
,Pcd
, SkuName
,DefaultStoreName
):
2154 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2155 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2156 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2158 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2160 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2162 return pcddefaultvalue
2163 def GetPcdDscRawValueInfo(self
,Pcd
, SkuName
,DefaultStoreName
):
2164 DscValueInfo
= Pcd
.DscRawValueInfo
.get(SkuName
, {}).get(DefaultStoreName
)
2166 dscfilepath
,lineno
= DscValueInfo
2168 dscfilepath
= self
.MetaFile
.File
2170 return dscfilepath
,lineno
2172 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
2173 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
2174 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
2175 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2176 CApp
= CApp
+ ' CHAR8 *Value;\n'
2177 CApp
= CApp
+ ' UINT32 PcdArraySize;\n'
2179 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2180 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2181 dscfilepath
,lineno
= self
.GetPcdDscRawValueInfo(Pcd
, SkuName
, DefaultStoreName
)
2183 valuefrom
= "%s Line %s" % (dscfilepath
,str(lineno
))
2185 valuefrom
= dscfilepath
2187 pcddefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, SkuName
, DefaultStoreName
)
2189 FieldList
= pcddefaultvalue
2190 IsArray
= _IsFieldValueAnArray(FieldList
)
2192 if "{CODE(" not in FieldList
:
2194 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2195 except BadExpression
:
2196 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2197 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2198 Value
, ValueSize
= ParseFieldValue (FieldList
)
2200 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2201 if isinstance(Value
, str):
2202 if "{CODE(" in Value
:
2203 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2204 pcdarraysize
= Pcd
.PcdArraySize()
2205 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
)
2206 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2207 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2209 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
)
2212 # Use memcpy() to copy value into field
2215 pcdarraysize
= Pcd
.PcdArraySize()
2216 if "{CODE(" in pcddefaultvalue
:
2217 if Pcd
.Capacity
[-1] != "-1":
2218 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
)
2219 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2220 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2222 if Pcd
.Capacity
[-1] != "-1":
2223 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
)
2224 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2225 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
)
2226 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2228 if "{CODE(" in pcddefaultvalue
:
2229 CApp
= CApp
+ ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
,ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
)
2230 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2232 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
)
2233 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2235 if isinstance(Value
, str):
2236 if "{CODE(" in Value
:
2237 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2238 pcdarraysize
= Pcd
.PcdArraySize()
2239 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
)
2240 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n '% (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2241 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2243 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2246 # Use memcpy() to copy value into field
2249 pcdarraysize
= Pcd
.PcdArraySize()
2250 if "{CODE(" in pcddefaultvalue
:
2251 if Pcd
.Capacity
[-1] != "-1":
2252 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
)
2253 CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2254 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2256 if Pcd
.Capacity
[-1] != "-1":
2257 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
)
2258 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2259 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
)
2260 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2262 if "{CODE(" in pcddefaultvalue
:
2263 CApp
= CApp
+ ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
,ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
)
2264 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2266 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2267 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2269 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2270 if not inheritvalue
:
2272 for index
in inheritvalue
:
2273 FieldList
= inheritvalue
[index
]
2276 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2277 for FieldName
in FieldList
:
2278 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2279 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2282 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2283 except BadExpression
:
2284 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2285 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2287 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2289 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]))
2290 if isinstance(Value
, str):
2291 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2294 # Use memcpy() to copy value into field
2296 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2297 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2298 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])
2299 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2301 if '[' in FieldName
and ']' in FieldName
:
2302 Index
= int(FieldName
.split('[')[1].split(']')[0])
2303 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
)
2305 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2307 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2312 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2313 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2316 def GenerateCommandLineValue(self
, Pcd
):
2317 CApp
= "// Value in CommandLine\n"
2318 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2319 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2320 CApp
= CApp
+ ' CHAR8 *Value;\n'
2322 pcddefaultvalue
= Pcd
.PcdValueFromComm
2323 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2326 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2327 IsArray
= _IsFieldValueAnArray(FieldList
)
2330 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2331 except BadExpression
:
2332 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2333 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2334 Value
, ValueSize
= ParseFieldValue (FieldList
)
2336 if isinstance(Value
, str):
2337 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2340 # Use memcpy() to copy value into field
2342 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2343 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2345 for FieldName
in FieldList
:
2346 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2349 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2350 except BadExpression
:
2351 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2352 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2356 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2358 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]))
2359 if isinstance(Value
, str):
2360 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2363 # Use memcpy() to copy value into field
2365 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2366 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2367 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])
2368 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2370 if '[' in FieldName
and ']' in FieldName
:
2371 Index
= int(FieldName
.split('[')[1].split(']')[0])
2372 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
)
2374 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2376 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2380 def GenerateModuleScopeValue(self
, Pcd
):
2381 CApp
= "// Value in Dsc Module scope \n"
2382 for ModuleGuid
in Pcd
.PcdFiledValueFromDscComponent
:
2384 CApp
= CApp
+ "void Assign_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, ModuleGuid
,Pcd
.BaseDatumType
)
2385 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2386 CApp
= CApp
+ ' CHAR8 *Value;\n'
2387 pcddefaultvalue
, file_path
,lineNo
= Pcd
.PcdValueFromComponents
.get(ModuleGuid
,(None,None,None))
2390 IsArray
= _IsFieldValueAnArray(pcddefaultvalue
)
2393 FieldList
= ValueExpressionEx(pcddefaultvalue
, TAB_VOID
)(True)
2394 except BadExpression
:
2395 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from %s Line %s: %s" %
2396 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, file_path
, lineNo
, FieldList
))
2397 Value
, ValueSize
= ParseFieldValue (FieldList
)
2399 if isinstance(Value
, str):
2400 CApp
= CApp
+ ' Pcd = %s; // From %s Line %s \n' % (Value
, file_path
, lineNo
)
2403 # Use memcpy() to copy value into field
2405 CApp
= CApp
+ ' Value = %s; // From %s Line %s.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), file_path
, lineNo
)
2406 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2409 PcdFiledValue
= Pcd
.PcdFiledValueFromDscComponent
.get(ModuleGuid
)
2410 for index
in PcdFiledValue
:
2411 FieldList
= PcdFiledValue
[index
]
2414 for FieldName
in FieldList
:
2415 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2418 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2419 except BadExpression
:
2420 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2421 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2425 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2427 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]))
2428 if isinstance(Value
, str):
2429 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2432 # Use memcpy() to copy value into field
2434 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2435 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2436 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])
2437 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2439 if '[' in FieldName
and ']' in FieldName
:
2440 Index
= int(FieldName
.split('[')[1].split(']')[0])
2441 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
)
2443 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2445 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2450 def GenerateCommandLineValueStatement(Pcd
):
2451 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2453 def GenerateFdfValue(self
,Pcd
):
2454 CApp
= "// Value in Fdf\n"
2455 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2456 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2457 CApp
= CApp
+ ' CHAR8 *Value;\n'
2459 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2460 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2463 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2464 IsArray
= _IsFieldValueAnArray(FieldList
)
2467 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2468 except BadExpression
:
2469 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2470 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2471 Value
, ValueSize
= ParseFieldValue (FieldList
)
2473 if isinstance(Value
, str):
2474 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2477 # Use memcpy() to copy value into field
2479 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2480 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2482 for FieldName
in FieldList
:
2483 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2486 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2487 except BadExpression
:
2488 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2489 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2493 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2495 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]))
2496 if isinstance(Value
, str):
2497 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2500 # Use memcpy() to copy value into field
2502 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2503 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2504 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])
2505 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2507 if '[' in FieldName
and ']' in FieldName
:
2508 Index
= int(FieldName
.split('[')[1].split(']')[0])
2509 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
)
2511 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2513 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2518 def GenerateFdfValueStatement(Pcd
):
2519 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2523 def GenerateModuleValueStatement(module_guid
, Pcd
):
2524 CApp
= " Assign_%s_%s_%s_Value(Pcd);\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, module_guid
)
2526 def GenerateModuleScopeInitializeFunc(self
,SkuName
, Pcd
, InitByteValue
, CApp
):
2527 for module_guid
in Pcd
.PcdFiledValueFromDscComponent
:
2528 CApp
= CApp
+ 'void\n'
2529 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2530 CApp
= CApp
+ ' void\n'
2531 CApp
= CApp
+ ' )\n'
2533 CApp
= CApp
+ ' UINT32 Size;\n'
2534 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2535 CApp
= CApp
+ ' CHAR8 *Value;\n'
2536 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2537 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2539 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2543 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2544 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2546 # Get current PCD value and size
2548 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2551 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2552 # the correct value. For structures with a flexible array member, the flexible
2553 # array member is detected, and the size is based on the highest index used with
2554 # the flexible array member. The flexible array member must be the last field
2555 # in a structure. The size formula for this case is:
2556 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2558 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,TAB_DEFAULT_STORES_DEFAULT
)
2559 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2560 CApp
= CApp
+ ' OriginalSize = OriginalSize < sizeof(%s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize(),Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2561 CApp
= CApp
+ ' Size = sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2564 # Allocate and zero buffer for the PCD
2565 # Must handle cases where current value is smaller, larger, or same size
2566 # Always keep that larger one as the current size
2568 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2569 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2570 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2573 # Copy current PCD value into allocated buffer.
2575 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2578 # Assign field values in PCD
2580 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2582 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2583 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2584 CApp
= CApp
+ DscBuildData
.GenerateModuleValueStatement(module_guid
,Pcd
)
2585 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2586 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2589 # Set new PCD value and size
2591 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2596 CApp
= CApp
+ ' free (Pcd);\n'
2599 return InitByteValue
,CApp
2601 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2602 OverrideValues
= {DefaultStore
:{}}
2603 if Pcd
.SkuOverrideValues
:
2604 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2605 if not OverrideValues
:
2606 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2607 for DefaultStoreName
in OverrideValues
:
2608 CApp
= CApp
+ 'void\n'
2609 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2610 CApp
= CApp
+ ' void\n'
2611 CApp
= CApp
+ ' )\n'
2613 CApp
= CApp
+ ' UINT32 Size;\n'
2614 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2615 CApp
= CApp
+ ' CHAR8 *Value;\n'
2616 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2617 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2619 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2623 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2625 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2628 # Get current PCD value and size
2630 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2633 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2634 # the correct value. For structures with a flexible array member, the flexible
2635 # array member is detected, and the size is based on the highest index used with
2636 # the flexible array member. The flexible array member must be the last field
2637 # in a structure. The size formula for this case is:
2638 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2640 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,DefaultStoreName
)
2641 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2642 CApp
= CApp
+ ' OriginalSize = OriginalSize < sizeof(%s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize(),Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2643 CApp
= CApp
+ ' Size = sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2646 # Allocate and zero buffer for the PCD
2647 # Must handle cases where current value is smaller, larger, or same size
2648 # Always keep that larger one as the current size
2650 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2651 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2652 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2655 # Copy current PCD value into allocated buffer.
2657 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2660 # Assign field values in PCD
2662 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2663 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2664 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2665 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2666 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2667 for defaultstorenameitem
in storeset
:
2668 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2669 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2670 if skuname
== SkuName
:
2673 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2674 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2675 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2676 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2678 # Set new PCD value and size
2680 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2685 CApp
= CApp
+ ' free (Pcd);\n'
2688 return InitByteValue
, CApp
2690 def GenerateArrayAssignment(self
, Pcd
):
2695 for d
in Pcd
.Capacity
:
2698 Value
= Pcd
.DefaultValueFromDec
2699 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2700 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2701 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2703 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2704 for skuname
in Pcd
.SkuInfoList
:
2705 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2706 if skuinfo
.VariableName
:
2707 for defaultstore
in skuinfo
.DefaultStoreDict
:
2708 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, defaultstore
)
2709 if pcddscrawdefaultvalue
:
2710 Value
= skuinfo
.DefaultStoreDict
[defaultstore
]
2711 if "{CODE(" in Value
:
2712 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2713 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2715 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, TAB_DEFAULT_STORES_DEFAULT
)
2716 if pcddscrawdefaultvalue
:
2717 Value
= skuinfo
.DefaultValue
2718 if "{CODE(" in Value
:
2719 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2720 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2722 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2723 if pcddscrawdefaultvalue
:
2724 if "{CODE(" in Pcd
.DefaultValue
:
2725 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2726 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2730 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2731 if not OverrideValues
:
2733 for key
in OverrideValues
:
2734 if OverrideValues
[key
]:
2738 def ParseCCFlags(self
, ccflag
):
2740 ccflaglist
= ccflag
.split(" ")
2742 while i
< len(ccflaglist
):
2743 item
= ccflaglist
[i
].strip()
2744 if item
in (r
"/D", r
"/U","-D","-U"):
2745 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2747 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2751 def GenerateByteArrayValue (self
, StructuredPcds
):
2753 # Generate/Compile/Run C application to determine if there are any flexible array members
2755 if not StructuredPcds
:
2759 CApp
= PcdMainCHeader
2761 IncludeFiles
= set()
2762 for PcdName
in StructuredPcds
:
2763 Pcd
= StructuredPcds
[PcdName
]
2764 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2765 if IncludeFile
not in IncludeFiles
:
2766 IncludeFiles
.add(IncludeFile
)
2767 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2769 for Pcd
in StructuredPcds
.values():
2770 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2771 for PcdName
in sorted(StructuredPcds
.keys()):
2772 Pcd
= StructuredPcds
[PcdName
]
2774 #create void void Cal_tocken_cname_Size functions
2775 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2777 #create void Assign_ functions
2780 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2782 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2784 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2786 # From Dsc Global setting
2787 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2788 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2789 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2791 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2792 if SkuName
not in Pcd
.SkuOverrideValues
:
2794 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2795 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2797 # From Dsc module scope setting
2798 CApp
= CApp
+ self
.GenerateModuleScopeValue(Pcd
)
2800 #create Initialize_ functions
2801 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2802 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2803 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2804 InitByteValue
, CApp
= self
.GenerateModuleScopeInitializeFunc(self
.SkuIdMgr
.SystemSkuId
,Pcd
,InitByteValue
,CApp
)
2806 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2807 if SkuName
not in Pcd
.SkuOverrideValues
:
2809 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2810 Pcd
= StructuredPcds
[PcdName
]
2811 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2813 CApp
= CApp
+ 'VOID\n'
2814 CApp
= CApp
+ 'PcdEntryPoint(\n'
2815 CApp
= CApp
+ ' VOID\n'
2816 CApp
= CApp
+ ' )\n'
2818 for Pcd
in StructuredPcds
.values():
2819 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
]]:
2820 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2821 for ModuleGuid
in Pcd
.PcdFiledValueFromDscComponent
:
2822 CApp
+= " Initialize_%s_%s_%s_%s();\n" % (ModuleGuid
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2824 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2825 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2827 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2828 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2831 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2833 if not os
.path
.exists(self
.OutputPath
):
2834 os
.makedirs(self
.OutputPath
)
2835 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2836 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2838 # start generating makefile
2839 MakeApp
= PcdMakefileHeader
2840 if sys
.platform
== "win32":
2841 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 = '
2843 MakeApp
= MakeApp
+ PcdGccMakefile
2844 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
)) + \
2845 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
2848 PlatformInc
= OrderedDict()
2849 for Cache
in self
._Bdb
._CACHE
_.values():
2850 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2853 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2854 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2855 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2856 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2859 for Pcd
in StructuredPcds
.values():
2860 for PackageDec
in Pcd
.PackageDecs
:
2861 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2862 if not os
.path
.exists(Package
):
2863 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2864 if Package
not in PcdDependDEC
:
2865 PcdDependDEC
.append(Package
)
2867 if PlatformInc
and PcdDependDEC
:
2868 for pkg
in PcdDependDEC
:
2869 if pkg
in PlatformInc
:
2870 for inc
in PlatformInc
[pkg
]:
2872 # Get list of files in potential -I include path
2874 FileList
= os
.listdir (str(inc
))
2876 # Skip -I include path if one of the include files required
2877 # by PcdValueInit.c are present in the include paths from
2878 # the DEC file. PcdValueInit.c must use the standard include
2879 # files from the host compiler.
2881 if 'stdio.h' in FileList
:
2883 if 'stdlib.h' in FileList
:
2885 if 'string.h' in FileList
:
2887 MakeApp
+= '-I' + str(inc
) + ' '
2888 IncSearchList
.append(inc
)
2889 MakeApp
= MakeApp
+ '\n'
2891 CC_FLAGS
= LinuxCFLAGS
2892 if sys
.platform
== "win32":
2893 CC_FLAGS
= WindowsCFLAGS
2894 BuildOptions
= OrderedDict()
2895 for Options
in self
.BuildOptions
:
2896 if Options
[2] != EDKII_NAME
:
2899 if Family
and Family
!= self
.ToolChainFamily
:
2901 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2906 if Target
== TAB_STAR
or Target
== self
._Target
:
2907 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2908 if 'COMMON' not in BuildOptions
:
2909 BuildOptions
['COMMON'] = set()
2910 if Arch
== TAB_STAR
:
2911 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2912 if Arch
in self
.SupArchList
:
2913 if Arch
not in BuildOptions
:
2914 BuildOptions
[Arch
] = set()
2915 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2918 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2919 if len(ArchBuildOptions
.keys()) == 1:
2920 BuildOptions
['COMMON'] |
= (list(ArchBuildOptions
.values())[0])
2921 elif len(ArchBuildOptions
.keys()) > 1:
2922 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2923 BuildOptions
['COMMON'] |
= CommonBuildOptions
2924 ValueList
= [item
for item
in BuildOptions
['COMMON'] if item
.startswith((r
"/U","-U"))]
2925 ValueList
.extend([item
for item
in BuildOptions
['COMMON'] if item
.startswith((r
"/D", "-D"))])
2926 CC_FLAGS
+= " ".join(ValueList
)
2929 if sys
.platform
== "win32":
2930 MakeApp
= MakeApp
+ PcdMakefileEnd
2931 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2933 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2934 MakeApp
= MakeApp
+ '\n'
2935 IncludeFileFullPaths
= []
2936 for includefile
in IncludeFiles
:
2937 for includepath
in IncSearchList
:
2938 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2939 if os
.path
.exists(includefullpath
):
2940 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2943 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "BaseTools/Source/C/Include")))
2944 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "BaseTools/Source/C/Common")))
2945 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2946 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2947 for include_file
in IncFileList
:
2948 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2949 if sys
.platform
== "win32":
2950 PcdValueCommonPath
= os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "Source\C\Common\PcdValueCommon.c"))
2951 MakeApp
= MakeApp
+ '%s\PcdValueCommon.c : %s\n' % (self
.OutputPath
, PcdValueCommonPath
)
2952 MakeApp
= MakeApp
+ '\tcopy /y %s $@\n' % (PcdValueCommonPath
)
2954 PcdValueCommonPath
= os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "Source/C/Common/PcdValueCommon.c"))
2955 MakeApp
= MakeApp
+ '%s/PcdValueCommon.c : %s\n' % (self
.OutputPath
, PcdValueCommonPath
)
2956 MakeApp
= MakeApp
+ '\tcp -f %s %s/PcdValueCommon.c\n' % (PcdValueCommonPath
, self
.OutputPath
)
2957 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2958 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2959 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2961 # start generating input file
2962 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2963 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2964 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2966 Dest_PcdValueInitExe
= PcdValueInitName
2967 if not sys
.platform
== "win32":
2968 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2970 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2972 #start building the structure pcd value tool
2974 if sys
.platform
== "win32":
2975 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2976 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2979 MakeCommand
= 'make -f %s' % (MakeFileName
)
2980 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2983 EdkLogger
.verbose ('%s\n%s\n%s' % (MakeCommand
, StdOut
, StdErr
))
2984 Messages
= Messages
.split('\n')
2987 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2988 File
= open (CAppBaseFileName
+ '.c', 'r')
2989 FileData
= File
.readlines()
2991 for Message
in Messages
:
2992 if " error" in Message
or "warning" in Message
:
2994 FileInfo
= Message
.strip().split('(')
2995 if len (FileInfo
) > 1:
2996 FileName
= FileInfo
[0]
2997 FileLine
= FileInfo
[1].split (')')[0]
2999 FileInfo
= Message
.strip().split(':')
3000 if len(FileInfo
) < 2:
3002 FileName
= FileInfo
[0]
3003 FileLine
= FileInfo
[1]
3006 if "PcdValueInit.c" not in FileName
:
3008 if FileLine
.isdigit():
3009 error_line
= FileData
[int (FileLine
) - 1]
3010 if r
"//" in error_line
:
3011 c_line
, dsc_line
= error_line
.split(r
"//")
3013 dsc_line
= error_line
3014 message_itmes
= Message
.split(":")
3016 if "PcdValueInit.c" not in Message
:
3017 if not MessageGroup
:
3018 MessageGroup
.append(Message
)
3021 for item
in message_itmes
:
3022 if "PcdValueInit.c" in item
:
3023 Index
= message_itmes
.index(item
)
3024 message_itmes
[Index
] = dsc_line
.strip()
3026 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
3029 MessageGroup
.append(Message
)
3031 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
3033 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s\n%s\n%s' % (MakeCommand
, StdOut
, StdErr
))
3035 #start executing the structure pcd value tool
3036 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
3037 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
3038 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
3039 EdkLogger
.verbose ('%s\n%s\n%s' % (Command
, StdOut
, StdErr
))
3041 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s\n%s\n%s\n' % (Command
, StdOut
, StdErr
))
3043 #start update structure pcd final value
3044 File
= open (OutputValueFile
, 'r')
3045 FileBuffer
= File
.readlines()
3048 StructurePcdSet
= []
3049 for Pcd
in FileBuffer
:
3050 PcdValue
= Pcd
.split ('|')
3051 PcdInfo
= PcdValue
[0].split ('.')
3052 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
3053 return StructurePcdSet
3056 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
3057 if not os
.path
.exists(OutputFile
):
3059 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
3061 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
3065 ## Retrieve dynamic PCD settings
3067 # @param Type PCD type
3069 # @retval a dict object contains settings of given PCD type
3071 def _GetDynamicPcd(self
, Type
):
3074 Pcds
= OrderedDict()
3076 # tdict is a special dict kind of type, used for selecting correct
3077 # PCD settings for certain ARCH and SKU
3079 PcdDict
= tdict(True, 4)
3081 # Find out all possible PCD candidates for self._Arch
3082 RecordList
= self
._RawData
[Type
, self
._Arch
]
3083 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3086 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3087 SkuName
= SkuName
.upper()
3088 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3089 if SkuName
not in AvailableSkuIdSet
:
3090 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3091 File
=self
.MetaFile
, Line
=Dummy5
)
3092 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
3093 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3094 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3096 # Remove redundant PCD candidates, per the ARCH and SKU
3097 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3099 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3103 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3105 if int(MaxDatumSize
, 0) > 0xFFFF:
3106 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3107 File
=self
.MetaFile
, Line
=Dummy4
)
3108 if int(MaxDatumSize
, 0) < 0:
3109 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3110 File
=self
.MetaFile
, Line
=Dummy4
)
3111 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
3112 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3113 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3114 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3115 if MaxDatumSize
.strip():
3116 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3119 if pcdObject
.MaxDatumSize
:
3120 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3123 if CurrentMaxSize
> PcdMaxSize
:
3124 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3126 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3129 self
._PCD
_TYPE
_STRING
_[Type
],
3134 OrderedDict({SkuName
: SkuInfo
}),
3139 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3140 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3141 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3142 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
3143 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Dummy4
)
3145 for pcd
in Pcds
.values():
3146 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3147 # Only fix the value while no value provided in DSC file.
3148 for sku
in pcd
.SkuInfoList
.values():
3149 if not sku
.DefaultValue
:
3150 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3151 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3152 valuefromDec
= pcdDecObject
.DefaultValue
3153 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
3154 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3155 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3156 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3157 del pcd
.SkuInfoList
[TAB_COMMON
]
3158 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3159 del pcd
.SkuInfoList
[TAB_COMMON
]
3161 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3165 def FilterSkuSettings(self
, PcdObj
):
3167 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
3168 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
3169 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
3170 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
3171 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
3172 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
3174 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
3175 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
3180 def CompareVarAttr(Attr1
, Attr2
):
3181 if not Attr1
or not Attr2
: # for empty string
3183 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
3184 Attr1Set
= set(Attr1s
)
3185 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
3186 Attr2Set
= set(Attr2s
)
3187 if Attr2Set
== Attr1Set
:
3192 def CompletePcdValues(self
, PcdSet
):
3193 Pcds
= OrderedDict()
3194 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
3195 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
3196 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
3197 for PcdCName
, TokenSpaceGuid
in PcdSet
:
3198 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
3200 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
3201 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
3202 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
3203 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
3204 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
3205 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
3206 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
3208 PcdType
= PcdObj
.Type
3209 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
3210 for skuid
in PcdObj
.SkuInfoList
:
3211 skuobj
= PcdObj
.SkuInfoList
[skuid
]
3212 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
3213 for defaultstorename
in DefaultStores
:
3214 if defaultstorename
not in skuobj
.DefaultStoreDict
:
3215 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
3216 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
3217 for skuname
, skuid
in SkuIds
.items():
3218 if skuname
not in PcdObj
.SkuInfoList
:
3219 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
3220 while nextskuid
not in PcdObj
.SkuInfoList
:
3221 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
3222 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
3223 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
3224 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
3225 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
3226 PcdObj
.DefaultValue
= list(PcdObj
.SkuInfoList
.values())[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
3227 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
3229 ## Retrieve dynamic HII PCD settings
3231 # @param Type PCD type
3233 # @retval a dict object contains settings of given PCD type
3235 def _GetDynamicHiiPcd(self
, Type
):
3239 Pcds
= OrderedDict()
3240 UserDefinedDefaultStores
= []
3242 # tdict is a special dict kind of type, used for selecting correct
3243 # PCD settings for certain ARCH and SKU
3245 PcdDict
= tdict(True, 5)
3247 RecordList
= self
._RawData
[Type
, self
._Arch
]
3248 # Find out all possible PCD candidates for self._Arch
3249 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3250 DefaultStoresDefine
= self
._GetDefaultStores
()
3252 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
3253 SkuName
= SkuName
.upper()
3254 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3255 DefaultStore
= DefaultStore
.upper()
3256 if DefaultStore
== TAB_COMMON
:
3257 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
3259 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
3260 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
3261 if SkuName
not in AvailableSkuIdSet
:
3262 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3263 File
=self
.MetaFile
, Line
=Dummy5
)
3264 if DefaultStore
not in DefaultStoresDefine
:
3265 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
3266 File
=self
.MetaFile
, Line
=Dummy5
)
3267 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
) not in PcdList
:
3268 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
3269 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
3272 # Remove redundant PCD candidates, per the ARCH and SKU
3273 for index
,(PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
) in enumerate(PcdList
):
3275 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
3278 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3280 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
3282 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
3283 ExtraData
="[%s]" % VarAttribute
)
3285 FormatCorrect
= True
3286 if VariableOffset
.isdigit():
3287 if int(VariableOffset
, 10) > 0xFFFF:
3289 elif variablePattern
.match(VariableOffset
):
3290 if int(VariableOffset
, 16) > 0xFFFF:
3292 # For Offset written in "A.B"
3293 elif VariableOffset
.find('.') > -1:
3294 VariableOffsetList
= VariableOffset
.split(".")
3295 if not (len(VariableOffsetList
) == 2
3296 and IsValidWord(VariableOffsetList
[0])
3297 and IsValidWord(VariableOffsetList
[1])):
3298 FormatCorrect
= False
3300 FormatCorrect
= False
3301 if not FormatCorrect
:
3302 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
3305 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
3306 if (VariableName
, VariableGuid
) not in VariableAttrs
:
3307 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
3309 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
3310 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
)]))
3312 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
3313 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3314 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3315 if SkuName
in pcdObject
.SkuInfoList
:
3316 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
3317 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
3319 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
3320 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3322 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
3323 PcdClassObj
= PcdClassObject(
3326 self
._PCD
_TYPE
_STRING
_[Type
],
3331 OrderedDict({SkuName
: SkuInfo
}),
3334 pcdDecObject
.validateranges
,
3335 pcdDecObject
.validlists
,
3336 pcdDecObject
.expressions
,
3338 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
3339 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
3340 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
3342 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = index
3343 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3344 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3345 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3346 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
3347 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][DefaultStore
] = (self
.MetaFile
.File
,Dummy4
)
3348 for pcd
in Pcds
.values():
3349 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3350 pcd
.DatumType
= pcdDecObject
.DatumType
3351 # Only fix the value while no value provided in DSC file.
3352 for sku
in pcd
.SkuInfoList
.values():
3353 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
3354 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
3355 for default_store
in sku
.DefaultStoreDict
:
3356 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
3357 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
3358 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3359 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3360 valuefromDec
= pcdDecObject
.DefaultValue
3361 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
3362 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3363 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3364 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3365 del pcd
.SkuInfoList
[TAB_COMMON
]
3366 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3367 del pcd
.SkuInfoList
[TAB_COMMON
]
3369 if pcd
.MaxDatumSize
.strip():
3370 MaxSize
= int(pcd
.MaxDatumSize
, 0)
3373 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
3374 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
3376 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
3377 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
3378 if datalen
> MaxSize
:
3380 for defaultst
in skuobj
.DefaultStoreDict
:
3381 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
3382 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
3383 pcd
.MaxDatumSize
= str(MaxSize
)
3384 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
3386 invalidpcd
= ",".join(invalidhii
)
3387 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
)
3389 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3394 def CheckVariableNameAssignment(Pcds
):
3396 for pcdname
in Pcds
:
3398 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
3399 if len(varnameset
) > 1:
3400 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
3402 return False, invalidhii
3405 ## Retrieve dynamic VPD PCD settings
3407 # @param Type PCD type
3409 # @retval a dict object contains settings of given PCD type
3411 def _GetDynamicVpdPcd(self
, Type
):
3414 Pcds
= OrderedDict()
3416 # tdict is a special dict kind of type, used for selecting correct
3417 # PCD settings for certain ARCH and SKU
3419 PcdDict
= tdict(True, 4)
3422 # Find out all possible PCD candidates for self._Arch
3423 RecordList
= self
._RawData
[Type
, self
._Arch
]
3424 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3426 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3427 SkuName
= SkuName
.upper()
3428 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3429 if SkuName
not in AvailableSkuIdSet
:
3430 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3431 File
=self
.MetaFile
, Line
=Dummy5
)
3432 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
3433 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3434 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3436 # Remove redundant PCD candidates, per the ARCH and SKU
3437 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3438 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3442 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3443 # For the Integer & Boolean type, the optional data can only be InitialValue.
3444 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3445 # until the DEC parser has been called.
3447 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3449 if int(MaxDatumSize
, 0) > 0xFFFF:
3450 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3451 File
=self
.MetaFile
, Line
=Dummy4
)
3452 if int(MaxDatumSize
, 0) < 0:
3453 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3454 File
=self
.MetaFile
, Line
=Dummy4
)
3455 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3456 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3457 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3458 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3459 if MaxDatumSize
.strip():
3460 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3463 if pcdObject
.MaxDatumSize
:
3464 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3467 if CurrentMaxSize
> PcdMaxSize
:
3468 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3470 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3473 self
._PCD
_TYPE
_STRING
_[Type
],
3478 OrderedDict({SkuName
: SkuInfo
}),
3483 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3484 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3485 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3486 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3487 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Dummy4
)
3488 for pcd
in Pcds
.values():
3489 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3490 pcd
.DatumType
= pcdDecObject
.DatumType
3491 # Only fix the value while no value provided in DSC file.
3492 for sku
in pcd
.SkuInfoList
.values():
3493 if not sku
.DefaultValue
:
3494 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3495 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3496 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3497 valuefromDec
= pcdDecObject
.DefaultValue
3498 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3499 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3500 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3501 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3502 del pcd
.SkuInfoList
[TAB_COMMON
]
3503 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3504 del pcd
.SkuInfoList
[TAB_COMMON
]
3506 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3507 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3508 for pcd
in Pcds
.values():
3509 PcdValueTypeSet
= set()
3510 for sku
in pcd
.SkuInfoList
.values():
3511 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3512 if len(PcdValueTypeSet
) > 1:
3513 for sku
in pcd
.SkuInfoList
.values():
3514 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3516 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3519 ## Add external modules
3521 # The external modules are mostly those listed in FDF file, which don't
3524 # @param FilePath The path of module description file
3526 def AddModule(self
, FilePath
):
3527 FilePath
= NormPath(FilePath
)
3528 if FilePath
not in self
.Modules
:
3529 Module
= ModuleBuildClassObject()
3530 Module
.MetaFile
= FilePath
3531 self
.Modules
.append(Module
)
3534 def ToolChainFamily(self
):
3535 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3536 TargetObj
= TargetTxtDict()
3537 TargetTxt
= TargetObj
.Target
3538 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultTargetTxtFile
))
3539 if os
.path
.isfile(BuildConfigurationFile
) == True:
3540 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3541 if ToolDefinitionFile
== '':
3542 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', gDefaultToolsDefFile
))
3543 if os
.path
.isfile(ToolDefinitionFile
) == True:
3544 ToolDefObj
= ToolDefDict((os
.path
.join(os
.getenv("WORKSPACE"), "Conf")))
3545 ToolDefinition
= ToolDefObj
.ToolDef
.ToolsDefTxtDatabase
3546 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3547 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3548 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3549 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3551 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3552 return self
._ToolChainFamily
3554 ## Add external PCDs
3556 # The external PCDs are mostly those listed in FDF file to specify address
3557 # or offset information.
3559 # @param Name Name of the PCD
3560 # @param Guid Token space guid of the PCD
3561 # @param Value Value of the PCD
3563 def AddPcd(self
, Name
, Guid
, Value
):
3564 if (Name
, Guid
) not in self
.Pcds
:
3565 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3566 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3570 if self
._DecPcds
is None:
3572 if GlobalData
.gFdfParser
:
3573 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3575 for Inf
in FdfInfList
:
3576 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3577 if ModuleFile
in self
._Modules
:
3579 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3580 PkgSet
.update(ModuleData
.Packages
)
3582 PkgSet
.update(self
.Packages
)
3583 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3584 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3585 return self
._DecPcds