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_TOOL_GUID
:
392 # try to convert GUID to a real UUID value to see whether the GUID is format
393 # for VPD_TOOL_GUID is correct.
398 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
399 self
._VpdToolGuid
= Record
[2]
400 elif Name
== TAB_DSC_DEFINES_PCD_DYNAMIC_AS_DYNAMICEX
:
401 if TAB_DSC_DEFINES_PCD_DYNAMIC_AS_DYNAMICEX
not in gCommandLineDefines
:
402 gCommandLineDefines
[TAB_DSC_DEFINES_PCD_DYNAMIC_AS_DYNAMICEX
] = Record
[2].strip()
404 self
[Name
] = Record
[2]
405 # set _Header to non-None in order to avoid database re-querying
406 self
._Header
= 'DUMMY'
408 ## Retrieve platform name
410 def PlatformName(self
):
411 if self
._PlatformName
is None:
412 if self
._Header
is None:
413 self
._GetHeaderInfo
()
414 if self
._PlatformName
is None:
415 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
416 return self
._PlatformName
420 return self
.PlatformName
422 ## Retrieve file guid
425 if self
._Guid
is None:
426 if self
._Header
is None:
427 self
._GetHeaderInfo
()
428 if self
._Guid
is None:
429 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
432 ## Retrieve platform version
435 if self
._Version
is None:
436 if self
._Header
is None:
437 self
._GetHeaderInfo
()
438 if self
._Version
is None:
439 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
442 ## Retrieve platform description file version
444 def DscSpecification(self
):
445 if self
._DscSpecification
is None:
446 if self
._Header
is None:
447 self
._GetHeaderInfo
()
448 if self
._DscSpecification
is None:
449 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
450 return self
._DscSpecification
452 ## Retrieve OUTPUT_DIRECTORY
454 def OutputDirectory(self
):
455 if self
._OutputDirectory
is None:
456 if self
._Header
is None:
457 self
._GetHeaderInfo
()
458 if self
._OutputDirectory
is None:
459 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
460 return self
._OutputDirectory
462 ## Retrieve SUPPORTED_ARCHITECTURES
464 def SupArchList(self
):
465 if self
._SupArchList
is None:
466 if self
._Header
is None:
467 self
._GetHeaderInfo
()
468 if self
._SupArchList
is None:
469 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
470 return self
._SupArchList
472 ## Retrieve BUILD_TARGETS
474 def BuildTargets(self
):
475 if self
._BuildTargets
is None:
476 if self
._Header
is None:
477 self
._GetHeaderInfo
()
478 if self
._BuildTargets
is None:
479 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
480 return self
._BuildTargets
483 def PcdInfoFlag(self
):
484 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
486 elif self
._PcdInfoFlag
.upper() == 'TRUE':
492 def VarCheckFlag(self
):
493 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
495 elif self
._VarCheckFlag
.upper() == 'TRUE':
500 # # Retrieve SKUID_IDENTIFIER
503 if self
._SkuName
is None:
504 if self
._Header
is None:
505 self
._GetHeaderInfo
()
506 if self
._SkuName
is None:
507 self
._SkuName
= TAB_DEFAULT
510 ## Override SKUID_IDENTIFIER
512 def SkuName(self
, Value
):
513 self
._SkuName
= Value
516 def FlashDefinition(self
):
517 if self
._FlashDefinition
is None:
518 if self
._Header
is None:
519 self
._GetHeaderInfo
()
520 if self
._FlashDefinition
is None:
521 self
._FlashDefinition
= ''
522 return self
._FlashDefinition
526 if self
._Prebuild
is None:
527 if self
._Header
is None:
528 self
._GetHeaderInfo
()
529 if self
._Prebuild
is None:
531 return self
._Prebuild
535 if self
._Postbuild
is None:
536 if self
._Header
is None:
537 self
._GetHeaderInfo
()
538 if self
._Postbuild
is None:
540 return self
._Postbuild
542 ## Retrieve FLASH_DEFINITION
544 def BuildNumber(self
):
545 if self
._BuildNumber
is None:
546 if self
._Header
is None:
547 self
._GetHeaderInfo
()
548 if self
._BuildNumber
is None:
549 self
._BuildNumber
= ''
550 return self
._BuildNumber
552 ## Retrieve MAKEFILE_NAME
554 def MakefileName(self
):
555 if self
._MakefileName
is None:
556 if self
._Header
is None:
557 self
._GetHeaderInfo
()
558 if self
._MakefileName
is None:
559 self
._MakefileName
= ''
560 return self
._MakefileName
562 ## Retrieve BsBaseAddress
564 def BsBaseAddress(self
):
565 if self
._BsBaseAddress
is None:
566 if self
._Header
is None:
567 self
._GetHeaderInfo
()
568 if self
._BsBaseAddress
is None:
569 self
._BsBaseAddress
= ''
570 return self
._BsBaseAddress
572 ## Retrieve RtBaseAddress
574 def RtBaseAddress(self
):
575 if self
._RtBaseAddress
is None:
576 if self
._Header
is None:
577 self
._GetHeaderInfo
()
578 if self
._RtBaseAddress
is None:
579 self
._RtBaseAddress
= ''
580 return self
._RtBaseAddress
582 ## Retrieve the top address for the load fix address
584 def LoadFixAddress(self
):
585 if self
._LoadFixAddress
is None:
586 if self
._Header
is None:
587 self
._GetHeaderInfo
()
589 if self
._LoadFixAddress
is None:
590 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
593 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
595 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
598 # If command line defined, should override the value in DSC file.
600 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
602 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
604 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']))
606 if self
._LoadFixAddress
< 0:
607 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
608 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
609 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
611 return self
._LoadFixAddress
613 ## Retrieve RFCLanguage filter
615 def RFCLanguages(self
):
616 if self
._RFCLanguages
is None:
617 if self
._Header
is None:
618 self
._GetHeaderInfo
()
619 if self
._RFCLanguages
is None:
620 self
._RFCLanguages
= []
621 return self
._RFCLanguages
623 ## Retrieve ISOLanguage filter
625 def ISOLanguages(self
):
626 if self
._ISOLanguages
is None:
627 if self
._Header
is None:
628 self
._GetHeaderInfo
()
629 if self
._ISOLanguages
is None:
630 self
._ISOLanguages
= []
631 return self
._ISOLanguages
633 ## Retrieve the GUID string for VPD tool
635 def VpdToolGuid(self
):
636 if self
._VpdToolGuid
is None:
637 if self
._Header
is None:
638 self
._GetHeaderInfo
()
639 if self
._VpdToolGuid
is None:
640 self
._VpdToolGuid
= ''
641 return self
._VpdToolGuid
643 ## Retrieve [SkuIds] section information
646 if self
._SkuIds
is None:
647 self
._SkuIds
= OrderedDict()
648 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
649 for Record
in RecordList
:
651 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
652 File
=self
.MetaFile
, Line
=Record
[-1])
654 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
655 File
=self
.MetaFile
, Line
=Record
[-1])
656 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
657 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
658 File
=self
.MetaFile
, Line
=Record
[-1])
659 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
660 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_)*'",
661 File
=self
.MetaFile
, Line
=Record
[-1])
662 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
663 if TAB_DEFAULT
not in self
._SkuIds
:
664 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
665 if TAB_COMMON
not in self
._SkuIds
:
666 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
671 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
673 def _GetDefaultStores(self
):
674 if self
.DefaultStores
is None:
675 self
.DefaultStores
= OrderedDict()
676 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
677 for Record
in RecordList
:
679 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
680 File
=self
.MetaFile
, Line
=Record
[-1])
682 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
683 File
=self
.MetaFile
, Line
=Record
[-1])
684 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
685 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
686 File
=self
.MetaFile
, Line
=Record
[-1])
687 if not IsValidWord(Record
[1]):
688 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_-.)*'",
689 File
=self
.MetaFile
, Line
=Record
[-1])
690 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
691 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
692 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
693 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
694 return self
.DefaultStores
696 def OverrideDuplicateModule(self
):
697 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
698 Macros
= self
._Macros
700 for Record
in RecordList
:
702 file_guid
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
703 file_guid_str
= file_guid
[0][2] if file_guid
else "NULL"
704 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
705 if self
._Arch
!= TAB_ARCH_COMMON
and (file_guid_str
,str(ModuleFile
)) in Components
:
706 self
._RawData
.DisableOverrideComponent(Components
[(file_guid_str
,str(ModuleFile
))])
707 Components
[(file_guid_str
,str(ModuleFile
))] = ModuleId
708 self
._RawData
._PostProcessed
= False
710 ## Retrieve packages this Platform depends on
714 RecordList
= self
._RawData
[MODEL_META_DATA_PACKAGE
, self
._Arch
]
715 Macros
= self
._Macros
716 for Record
in RecordList
:
717 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
718 # check the file validation
719 ErrorCode
, ErrorInfo
= File
.Validate('.dec')
722 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
723 # parse this package now. we need it to get protocol/ppi/guid value
724 RetVal
.add(self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
])
727 ## Retrieve [Components] section information
730 if self
._Modules
is not None:
732 self
.OverrideDuplicateModule()
733 self
._Modules
= OrderedDict()
734 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
735 Macros
= self
._Macros
736 for Record
in RecordList
:
737 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
741 # check the file validation
742 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
744 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
747 ModuleBuildData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
748 Module
= ModuleBuildClassObject()
749 Module
.MetaFile
= ModuleFile
750 Module
.Guid
= ModuleBuildData
.Guid
751 # get module private library instance
752 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
753 for Record
in RecordList
:
754 LibraryClass
= Record
[0]
755 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
758 # check the file validation
759 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
761 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
764 if LibraryClass
== '' or LibraryClass
== 'NULL':
765 self
._NullLibraryNumber
+= 1
766 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
767 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
768 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
769 if LibraryPath
not in self
.LibraryInstances
:
770 self
.LibraryInstances
.append(LibraryPath
)
772 # get module private PCD setting
773 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
774 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
775 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
776 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
777 TokenList
= GetSplitValueList(Setting
)
778 DefaultValue
= TokenList
[0]
779 # the format is PcdName| Value | VOID* | MaxDatumSize
780 if len(TokenList
) > 2:
781 MaxDatumSize
= TokenList
[2]
784 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
786 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
788 if ("." in TokenSpaceGuid
or "[" in PcdCName
):
789 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, ModuleBuildData
.Guid
, "", Dummy5
, AnalyzePcdExpression(Setting
)[0]])
791 if ( PCName
,TCName
) not in Module
.Pcds
:
792 Pcd
= PcdClassObject(
804 Module
.Pcds
[PCName
, TCName
] = Pcd
806 Module
.StrPcdSet
= S_PcdSet
807 for TCName
,PCName
, _
,_
,_
,_
,_
,_
in S_PcdSet
:
808 if (PCName
,TCName
) in Module
.Pcds
:
809 Module
.StrPcdOverallValue
[(PCName
,TCName
)] = Module
.Pcds
[(PCName
,TCName
)].DefaultValue
, self
.MetaFile
,Dummy5
810 # get module private build options
811 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
812 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
813 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
814 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
816 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
817 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
819 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
821 if len(RecordList
) != 1:
822 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
823 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
824 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
825 ModuleFile
.Arch
= self
._Arch
826 Module
.Guid
= RecordList
[0][2]
827 for item
in Module
.StrPcdSet
:
828 item
[4] = RecordList
[0][2]
829 self
._Modules
[ModuleFile
] = Module
832 ## Retrieve all possible library instances used in this platform
834 def LibraryInstances(self
):
835 if self
._LibraryInstances
is None:
837 return self
._LibraryInstances
839 ## Retrieve [LibraryClasses] information
841 def LibraryClasses(self
):
842 if self
._LibraryClasses
is None:
843 self
._LibraryInstances
= []
845 # tdict is a special dict kind of type, used for selecting correct
846 # library instance for given library class and module type
848 LibraryClassDict
= tdict(True, 3)
849 # track all library class names
850 LibraryClassSet
= set()
851 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
852 Macros
= self
._Macros
853 for Record
in RecordList
:
854 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
855 if LibraryClass
== '' or LibraryClass
== 'NULL':
856 self
._NullLibraryNumber
+= 1
857 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
858 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
859 LibraryClassSet
.add(LibraryClass
)
860 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
861 # check the file validation
862 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
864 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
867 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
868 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
869 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
870 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
871 if LibraryInstance
not in self
._LibraryInstances
:
872 self
._LibraryInstances
.append(LibraryInstance
)
874 # resolve the specific library instance for each class and each module type
875 self
._LibraryClasses
= tdict(True)
876 for LibraryClass
in LibraryClassSet
:
877 # try all possible module types
878 for ModuleType
in SUP_MODULE_LIST
:
879 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
880 if LibraryInstance
is None:
882 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
884 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
885 for Record
in RecordList
:
886 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
888 # check the file validation
889 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
891 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
893 if File
not in self
._LibraryInstances
:
894 self
._LibraryInstances
.append(File
)
896 # we need the module name as the library class name, so we have
897 # to parse it here. (self._Bdb[] will trigger a file parse if it
898 # hasn't been parsed)
900 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
901 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
902 return self
._LibraryClasses
904 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
905 if not self
._DecPcds
:
908 if GlobalData
.gFdfParser
:
909 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
912 for Inf
in FdfInfList
:
913 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
914 if ModuleFile
in self
._Modules
:
916 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
917 PkgSet
.update(ModuleData
.Packages
)
919 PkgSet
.update(self
.Packages
)
920 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
921 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
923 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
924 EdkLogger
.error('build', PARSER_ERROR
,
925 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
926 File
=self
.MetaFile
, Line
=LineNo
)
927 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
929 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
930 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
931 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
933 if ValueList
[2] == '-1':
934 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
935 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
937 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
938 if "{CODE(" not in ValueList
[Index
]:
940 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
941 except BadExpression
as Value
:
942 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
943 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
944 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
945 except EvaluationException
as Excpt
:
946 if hasattr(Excpt
, 'Pcd'):
947 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
948 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
949 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
950 " of the DSC file" % Excpt
.Pcd
,
951 File
=self
.MetaFile
, Line
=LineNo
)
953 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
954 File
=self
.MetaFile
, Line
=LineNo
)
956 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
957 File
=self
.MetaFile
, Line
=LineNo
)
960 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
962 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
963 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
964 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
965 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
966 DecPcd
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
967 EdkLogger
.error('build', FORMAT_INVALID
,
968 "Pcd datumtype used in DSC file is not the same as its declaration. DatumType:%s"%DecPcd
.DatumType
,
969 File
=self
.MetaFile
, Line
=LineNo
,
970 ExtraData
="Dsc:%s.%s|%s\n Dec:%s.%s|%s|%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
, TokenSpaceGuid
, \
971 PcdCName
, DecPcd
.DefaultValue
, DecPcd
.DatumType
, DecPcd
.TokenValue
))
972 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
973 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
974 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
977 def _FilterPcdBySkuUsage(self
, Pcds
):
978 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
979 sku_usage
= self
.SkuIdMgr
.SkuUsageType
980 if sku_usage
== SkuClass
.SINGLE
:
983 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
984 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
985 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
989 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
990 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
991 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
994 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
995 HiiPcd
= [Pcds
[pcd
] for pcd
in Pcds
if Pcds
[pcd
].Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]]
996 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
998 for skuid
in pcd
.SkuInfoList
:
999 skuobj
= pcd
.SkuInfoList
.get(skuid
)
1000 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
1001 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
1002 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1003 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
1006 def RecoverCommandLinePcd(self
):
1007 def UpdateCommandLineValue(pcd
):
1008 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1009 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1010 pcd
.PcdValueFromComm
= pcd
.DefaultValue
1011 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1012 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
1014 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
1015 for pcd
in self
._Pcds
:
1016 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
1017 UpdateCommandLineValue(self
._Pcds
[pcd
])
1019 def __ParsePcdFromCommandLine(self
):
1020 if GlobalData
.BuildOptionPcd
:
1021 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
1022 if isinstance(pcd
, tuple):
1024 (pcdname
, pcdvalue
) = pcd
.split('=')
1026 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1028 (Name1
, Name2
) = pcdname
.split('.', 1)
1030 (Name3
, FieldName
) = Name2
.split(".", 1)
1031 if ((Name3
, Name1
)) in self
.DecPcds
:
1032 HasTokenSpace
= True
1034 TokenSpaceGuidCName
= Name1
1038 TokenSpaceGuidCName
= ''
1039 HasTokenSpace
= False
1041 if ((Name2
, Name1
)) in self
.DecPcds
:
1042 HasTokenSpace
= True
1044 TokenSpaceGuidCName
= Name1
1049 TokenSpaceGuidCName
= ''
1050 HasTokenSpace
= False
1053 TokenCName
= pcdname
1054 TokenSpaceGuidCName
= ''
1055 HasTokenSpace
= False
1056 TokenSpaceGuidCNameList
= []
1059 DisplayName
= TokenCName
1061 DisplayName
= TokenCName
+ '.' + FieldName
1062 if not HasTokenSpace
:
1063 for key
in self
.DecPcds
:
1064 PcdItem
= self
.DecPcds
[key
]
1065 if TokenCName
== PcdItem
.TokenCName
:
1066 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1067 if len (TokenSpaceGuidCNameList
) < 1:
1068 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1069 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1070 PcdDatumType
= PcdItem
.DatumType
1076 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1079 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1080 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1084 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1086 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1087 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1089 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1091 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1092 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1094 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1095 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1097 if GlobalData
.BuildOptionPcd
:
1098 inf_objs
= [item
for item
in self
._Bdb
._CACHE
_.values() if item
.Arch
== self
.Arch
and item
.MetaFile
.Ext
.lower() == '.inf']
1099 for pcd
in GlobalData
.BuildOptionPcd
:
1100 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1101 for BuildData
in inf_objs
:
1102 for key
in BuildData
.Pcds
:
1103 PcdItem
= BuildData
.Pcds
[key
]
1104 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1105 PcdItem
.DefaultValue
= pcdvalue
1106 PcdItem
.PcdValueFromComm
= pcdvalue
1107 #In command line, the latter full assign value in commandLine should override the former field assign value.
1108 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1111 if GlobalData
.BuildOptionPcd
:
1112 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1113 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1115 if (TokenSpaceGuid
, Token
) not in field_assign
:
1116 field_assign
[TokenSpaceGuid
, Token
] = []
1117 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1119 if (TokenSpaceGuid
, Token
) in field_assign
:
1120 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1121 field_assign
[TokenSpaceGuid
, Token
] = []
1122 for item
in delete_assign
:
1123 GlobalData
.BuildOptionPcd
.remove(item
)
1126 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1129 TokenCName
+= '.' + FieldName
1130 if PcdValue
.startswith('H'):
1131 if FieldName
and _IsFieldValueAnArray(PcdValue
[1:]):
1132 PcdDatumType
= TAB_VOID
1134 if FieldName
and not IsArray
:
1137 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1138 except BadExpression
as Value
:
1139 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1140 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1141 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1142 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1143 PcdDatumType
= TAB_VOID
1145 if FieldName
and not IsArray
:
1148 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1149 except BadExpression
as Value
:
1150 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1151 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1152 elif PcdValue
.startswith('L'):
1153 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1154 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1155 PcdDatumType
= TAB_VOID
1157 if FieldName
and not IsArray
:
1160 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1161 except BadExpression
as Value
:
1162 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1163 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1165 if PcdValue
.upper() == 'FALSE':
1167 if PcdValue
.upper() == 'TRUE':
1170 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1171 PcdValue
= '"' + PcdValue
+ '"'
1172 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1173 PcdValue
= '"' + PcdValue
+ '"'
1177 if PcdValue
.upper().startswith('0X'):
1180 Num
= int(PcdValue
, Base
)
1182 PcdValue
= '"' + PcdValue
+ '"'
1183 if _IsFieldValueAnArray(PcdValue
):
1184 PcdDatumType
= TAB_VOID
1189 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1190 except BadExpression
as Value
:
1191 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1192 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1195 ## Retrieve all PCD settings in platform
1198 if self
._Pcds
is None:
1199 self
._Pcds
= OrderedDict()
1200 self
.__ParsePcdFromCommandLine
()
1201 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1202 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1203 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1204 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1205 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1206 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1207 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1208 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1209 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1211 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1212 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1213 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1214 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1215 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1216 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1218 self
.RecoverCommandLinePcd()
1221 ## Retrieve [BuildOptions]
1223 def BuildOptions(self
):
1224 if self
._BuildOptions
is None:
1225 self
._BuildOptions
= OrderedDict()
1227 # Retrieve build option for EDKII and EDK style module
1229 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1230 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1231 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1232 if Dummy3
.upper() != TAB_COMMON
:
1234 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1236 # Only flags can be appended
1238 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1239 self
._BuildOptions
[CurKey
] = Option
1241 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1242 self
._BuildOptions
[CurKey
] += ' ' + Option
1243 return self
._BuildOptions
1244 def GetBuildOptionsByPkg(self
, Module
, ModuleType
):
1246 local_pkg
= os
.path
.split(Module
.LocalPkg())[0]
1247 if self
._ModuleTypeOptions
is None:
1248 self
._ModuleTypeOptions
= OrderedDict()
1249 if ModuleType
not in self
._ModuleTypeOptions
:
1250 options
= OrderedDict()
1251 self
._ModuleTypeOptions
[ ModuleType
] = options
1252 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1253 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1254 if Dummy2
not in (TAB_COMMON
,local_pkg
.upper(),"EDKII"):
1257 if Type
.upper() == ModuleType
.upper():
1258 Key
= (ToolChainFamily
, ToolChain
)
1259 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1260 options
[Key
] = Option
1262 if ' ' + Option
not in options
[Key
]:
1263 options
[Key
] += ' ' + Option
1264 return self
._ModuleTypeOptions
[ModuleType
]
1265 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1266 if self
._ModuleTypeOptions
is None:
1267 self
._ModuleTypeOptions
= OrderedDict()
1268 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1269 options
= OrderedDict()
1270 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1271 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1272 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1273 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1274 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1275 Type
= Dummy2
+ '.' + Dummy3
1276 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1277 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1278 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1279 options
[Key
] = Option
1281 if ' ' + Option
not in options
[Key
]:
1282 options
[Key
] += ' ' + Option
1283 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1286 def GetStructurePcdInfo(PcdSet
):
1287 structure_pcd_data
= defaultdict(list)
1289 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1291 return structure_pcd_data
1294 def OverrideByFdf(StruPcds
,workspace
):
1295 if GlobalData
.gFdfParser
is None:
1297 StructurePcdInFdf
= OrderedDict()
1298 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1299 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1300 for item
in fdfpcd
:
1301 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1302 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1303 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1304 for Pcd
in StruPcds
.values():
1305 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1307 FieldValues
= OrderedDict()
1308 for item
in StructurePcdInFdf
:
1309 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1310 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1311 for field
in FieldValues
:
1312 if field
not in Pcd
.PcdFieldValueFromFdf
:
1313 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1314 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1315 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1316 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1321 def OverrideByComm(StruPcds
):
1322 StructurePcdInCom
= OrderedDict()
1323 for item
in GlobalData
.BuildOptionPcd
:
1324 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1325 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1326 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1327 for Pcd
in StruPcds
.values():
1328 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1330 FieldValues
= OrderedDict()
1331 for item
in StructurePcdInCom
:
1332 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1333 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1334 for field
in FieldValues
:
1335 if field
not in Pcd
.PcdFieldValueFromComm
:
1336 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1337 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1338 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1339 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1342 def OverrideByCommOverAll(self
,AllPcds
):
1343 def CheckStructureInComm(commpcds
):
1346 if len(commpcds
[0]) == 5:
1349 NoFiledValues
= OrderedDict()
1350 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1351 StructurePcdInCom
= OrderedDict()
1352 for item
in GlobalData
.BuildOptionPcd
:
1353 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1354 for item
in StructurePcdInCom
:
1356 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1358 for item
in GlobalData
.BuildOptionPcd
:
1359 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1360 for Guid
, Name
in NoFiledValues
:
1361 if (Name
, Guid
) in AllPcds
:
1362 Pcd
= AllPcds
.get((Name
, Guid
))
1363 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1364 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1366 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1367 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1368 for sku
in Pcd
.SkuInfoList
:
1369 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1370 if SkuInfo
.DefaultValue
:
1371 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1373 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1374 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1375 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1376 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1377 if Pcd
.DatumType
== TAB_VOID
:
1378 if not Pcd
.MaxDatumSize
:
1379 Pcd
.MaxDatumSize
= '0'
1380 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1381 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1382 MaxSize
= max(CurrentSize
, OptionSize
)
1383 Pcd
.MaxDatumSize
= str(MaxSize
)
1385 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1387 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1388 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1389 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1390 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1391 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1392 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1393 self
._Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1394 self
._Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1395 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1396 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1397 self
._Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1400 def OverrideByFdfOverAll(self
,AllPcds
):
1402 if GlobalData
.gFdfParser
is None:
1404 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1405 for Name
,Guid
,Field
in NoFiledValues
:
1408 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1409 if (Name
,Guid
) in AllPcds
:
1410 Pcd
= AllPcds
.get((Name
,Guid
))
1411 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1412 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1414 Pcd
.PcdValueFromComm
= Value
1415 Pcd
.DefaultValue
= Value
1416 for sku
in Pcd
.SkuInfoList
:
1417 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1418 if SkuInfo
.DefaultValue
:
1419 SkuInfo
.DefaultValue
= Value
1421 SkuInfo
.HiiDefaultValue
= Value
1422 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1423 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1424 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1425 if Pcd
.DatumType
== TAB_VOID
:
1426 if not Pcd
.MaxDatumSize
:
1427 Pcd
.MaxDatumSize
= '0'
1428 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1429 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1430 MaxSize
= max(CurrentSize
, OptionSize
)
1431 Pcd
.MaxDatumSize
= str(MaxSize
)
1433 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1435 PcdInDec
.PcdValueFromFdf
= Value
1436 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1437 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1438 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1439 self
._Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1440 self
._Pcds
[Name
, Guid
].DefaultValue
= Value
1443 def ParsePcdNameStruct(self
,NamePart1
,NamePart2
):
1444 TokenSpaceCName
= PcdCName
= DimensionAttr
= Field
= ""
1445 if "." in NamePart1
:
1446 TokenSpaceCName
, TempPcdCName
= NamePart1
.split(".")
1447 if "[" in TempPcdCName
:
1448 PcdCName
= TempPcdCName
[:TempPcdCName
.index("[")]
1449 DimensionAttr
= TempPcdCName
[TempPcdCName
.index("["):]
1451 PcdCName
= TempPcdCName
1454 TokenSpaceCName
= NamePart1
1455 if "[" in NamePart2
:
1456 PcdCName
= NamePart2
[:NamePart2
.index("[")]
1457 DimensionAttr
= NamePart2
[NamePart2
.index("["):]
1459 PcdCName
= NamePart2
1461 return TokenSpaceCName
,PcdCName
,DimensionAttr
,Field
1463 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1465 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1466 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1467 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1468 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1469 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1470 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1473 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1474 SkuIds
= self
.SkuIds
1475 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1476 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1477 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1480 # Find out all possible PCD candidates for self._Arch
1483 for Type
in TypeList
:
1484 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1486 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1487 SkuName
= SkuName
.upper()
1488 default_store
= default_store
.upper()
1489 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1490 if SkuName
not in SkuIds
:
1492 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
1493 pcd_in_dec
= self
._DecPcds
.get((PCName
,TCName
), None)
1494 if pcd_in_dec
is None:
1495 EdkLogger
.error('build', PARSER_ERROR
,
1496 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1497 File
=self
.MetaFile
, Line
= Dummy5
)
1498 if SkuName
in SkuIds
and ("." in TokenSpaceGuid
or "[" in PcdCName
):
1499 if not isinstance (pcd_in_dec
, StructurePcd
):
1500 EdkLogger
.error('build', PARSER_ERROR
,
1501 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1502 File
=self
.MetaFile
, Line
= Dummy5
)
1504 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1505 ModuleScopeOverallValue
= {}
1506 for m
in self
.Modules
.values():
1509 S_PcdSet
.extend(m
.StrPcdSet
)
1510 mguid
= m
.StrPcdSet
[0][4]
1511 for (PCName
,TCName
) in m
.StrPcdOverallValue
:
1512 Value
, dsc_file
, lineNo
= m
.StrPcdOverallValue
[(PCName
,TCName
)]
1513 ModuleScopeOverallValue
.setdefault((PCName
,TCName
),{})[mguid
] = Value
, dsc_file
, lineNo
1514 # handle pcd value override
1515 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1516 S_pcd_set
= OrderedDict()
1517 for str_pcd
in StrPcdSet
:
1518 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1519 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1520 str_pcd_obj_str
= StructurePcd()
1521 str_pcd_obj_str
.copy(str_pcd_dec
)
1523 str_pcd_obj_str
.copy(str_pcd_obj
)
1524 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1525 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
}
1527 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
}
1528 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1529 if str_pcd_data
[4] in SkuIds
:
1530 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])
1531 elif GlobalData
.gGuidPattern
.match(str_pcd_data
[4]):
1532 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])
1533 PcdComponentValue
= ModuleScopeOverallValue
.get((str_pcd_obj_str
.TokenCName
,str_pcd_obj_str
.TokenSpaceGuidCName
))
1534 for module_guid
in PcdComponentValue
:
1535 str_pcd_obj_str
.PcdValueFromComponents
[module_guid
.replace("-","S")] = PcdComponentValue
[module_guid
]
1536 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1538 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1539 for Pcd
in self
.DecPcds
:
1540 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1541 if Pcd
not in S_pcd_set
:
1542 str_pcd_obj_str
= StructurePcd()
1543 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1544 str_pcd_obj
= Pcds
.get(Pcd
, None)
1546 str_pcd_obj_str
.copy(str_pcd_obj
)
1547 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1548 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
}
1550 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
}
1551 S_pcd_set
[Pcd
] = str_pcd_obj_str
1553 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
.copy()
1554 self
.FilterStrcturePcd(S_pcd_set
)
1555 for stru_pcd
in S_pcd_set
.values():
1556 for skuid
in SkuIds
:
1557 if skuid
in stru_pcd
.SkuOverrideValues
:
1559 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1561 if skuid
not in stru_pcd
.SkuOverrideValues
:
1562 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1563 if nextskuid
== TAB_DEFAULT
:
1566 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1567 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})
1569 stru_pcd
.ValueChain
.add((skuid
, ''))
1570 if 'DEFAULT' in stru_pcd
.SkuOverrideValues
and not GlobalData
.gPcdSkuOverrides
.get((stru_pcd
.TokenCName
, stru_pcd
.TokenSpaceGuidCName
)):
1571 GlobalData
.gPcdSkuOverrides
.update(
1572 {(stru_pcd
.TokenCName
, stru_pcd
.TokenSpaceGuidCName
): {'DEFAULT':stru_pcd
.SkuOverrideValues
['DEFAULT']}})
1573 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1574 for skuid
in SkuIds
:
1577 if skuid
not in stru_pcd
.SkuOverrideValues
:
1578 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1579 if nextskuid
== TAB_DEFAULT
:
1582 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1585 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1586 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1588 for defaultstoreid
in DefaultStores
:
1589 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1590 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = CopyDict(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1591 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1592 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1593 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1595 # Create a tool to caculate structure pcd value
1596 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1599 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1600 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1601 if str_pcd_obj
is None:
1602 print(PcdName
, PcdGuid
)
1604 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1605 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1606 if skuname
not in str_pcd_obj
.SkuInfoList
:
1607 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1609 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1610 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1611 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1612 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1613 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1614 str_pcd_obj
.DefaultValue
= PcdValue
1616 #Module Scope Structure Pcd
1617 moduleguid
= skuname
.replace("S","-")
1618 if GlobalData
.gGuidPattern
.match(moduleguid
):
1619 for component
in self
.Modules
.values():
1620 if component
.Guid
== moduleguid
:
1621 component
.Pcds
[(PcdName
, PcdGuid
)].DefaultValue
= PcdValue
1624 if skuname
not in str_pcd_obj
.SkuInfoList
:
1625 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1627 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1628 if nextskuid
== TAB_DEFAULT
:
1631 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1632 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
)
1633 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1634 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1636 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1637 for str_pcd_obj
in S_pcd_set
.values():
1638 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1639 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1641 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1642 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1643 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1644 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1646 for str_pcd_obj
in S_pcd_set
.values():
1648 str_pcd_obj
.MaxDatumSize
= DscBuildData
.GetStructurePcdMaxSize(str_pcd_obj
)
1649 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1650 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1654 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1655 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1656 del pcd
.SkuInfoList
[TAB_COMMON
]
1657 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1658 del pcd
.SkuInfoList
[TAB_COMMON
]
1660 list(map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
]))
1663 def PlatformUsedPcds(self
):
1665 if GlobalData
.gFdfParser
:
1666 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1667 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1668 AllModulePcds
= set()
1669 ModuleSet
= set(list(self
._Modules
.keys()) + FdfModuleList
)
1670 for ModuleFile
in ModuleSet
:
1671 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1672 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1673 for ModuleFile
in self
.LibraryInstances
:
1674 ModuleData
= self
._Bdb
.CreateBuildObject(ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
)
1675 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1676 return AllModulePcds
1678 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1679 def FilterStrcturePcd(self
, S_pcd_set
):
1680 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.PlatformUsedPcds
1681 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1682 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1684 ## Retrieve non-dynamic PCD settings
1686 # @param Type PCD type
1688 # @retval a dict object contains settings of given PCD type
1690 def _GetPcd(self
, Type
):
1691 Pcds
= OrderedDict()
1693 # tdict is a special dict kind of type, used for selecting correct
1694 # PCD settings for certain ARCH
1696 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1698 PcdDict
= tdict(True, 4)
1700 # Find out all possible PCD candidates for self._Arch
1701 RecordList
= self
._RawData
[Type
, self
._Arch
]
1702 PcdValueDict
= OrderedDict()
1703 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1704 SkuName
= SkuName
.upper()
1705 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1706 if SkuName
not in AvailableSkuIdSet
:
1707 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1708 File
=self
.MetaFile
, Line
=Dummy5
)
1709 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1710 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
1711 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1712 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1714 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
1715 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1718 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1720 if int(MaxDatumSize
, 0) > 0xFFFF:
1721 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1722 File
=self
.MetaFile
, Line
=Dummy4
)
1723 if int(MaxDatumSize
, 0) < 0:
1724 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1725 File
=self
.MetaFile
, Line
=Dummy4
)
1726 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1727 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
,Dummy4
)
1729 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
,Dummy4
)}
1731 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.items():
1732 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1733 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1734 elif TAB_DEFAULT
in PcdSetting
:
1735 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[TAB_DEFAULT
]
1736 elif TAB_COMMON
in PcdSetting
:
1737 PcdValue
, DatumType
, MaxDatumSize
,_
= PcdSetting
[TAB_COMMON
]
1743 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1746 self
._PCD
_TYPE
_STRING
_[Type
],
1755 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1756 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1757 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1758 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1759 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
1760 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1761 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Settings
[3])
1765 def GetStructurePcdMaxSize(str_pcd
):
1766 pcd_default_value
= str_pcd
.DefaultValue
1767 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()]
1768 sku_values
.append(pcd_default_value
)
1770 def get_length(value
):
1771 Value
= value
.strip()
1773 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1775 if Value
.startswith('L"') and Value
.endswith('"'):
1776 return len(Value
[2:-1])
1777 if Value
[0] == '"' and Value
[-1] == '"':
1778 return len(Value
) - 2
1779 if Value
.strip().startswith("{CODE("):
1780 tmpValue
= RemoveCComments(Value
)
1781 return len(tmpValue
.split(","))
1782 if (Value
[0] == '{' and Value
[-1] == '}'):
1783 return len(Value
.split(","))
1784 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1785 return len(list(Value
[2:-1]))
1786 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1787 return len(Value
) - 2
1790 return str(max(get_length(item
) for item
in sku_values
))
1793 def ExecuteCommand (Command
):
1795 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1797 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1798 Result
= Process
.communicate()
1799 return Process
.returncode
, Result
[0].decode(errors
='ignore'), Result
[1].decode(errors
='ignore')
1802 def IntToCString(Value
, ValueSize
):
1804 if not isinstance (Value
, str):
1805 for Index
in range(0, ValueSize
):
1806 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1808 Result
= Result
+ '"'
1811 def GenerateSizeFunction(self
, Pcd
):
1812 CApp
= "// Default Value in Dec \n"
1813 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1815 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
1816 CApp
+= " *Size = (sizeof (%s) > *Size ? sizeof (%s) : *Size);\n" % (Pcd
.DatumType
,Pcd
.DatumType
)
1818 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1819 CApp
+= " *Size = (sizeof (%s_%s_INIT_Value) > *Size ? sizeof (%s_%s_INIT_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)
1820 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
1821 for skuname
in Pcd
.SkuInfoList
:
1822 skuobj
= Pcd
.SkuInfoList
[skuname
]
1823 if skuobj
.VariableName
:
1824 for defaultstore
in skuobj
.DefaultStoreDict
:
1825 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,defaultstore
)
1827 if "{CODE(" in pcddef
:
1828 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
)
1830 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1832 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1834 if "{CODE(" in pcddef
:
1835 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
)
1837 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1839 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1841 if "{CODE(" in pcddef
:
1842 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
)
1844 CApp
+= " *Size = %s > *Size ? %s : *Size;\n" % (self
.GetStructurePcdMaxSize(Pcd
),self
.GetStructurePcdMaxSize(Pcd
))
1846 for index
in Pcd
.DefaultValues
:
1848 ActualCap
.append(index
)
1849 FieldList
= Pcd
.DefaultValues
[index
]
1852 for FieldName
in FieldList
:
1853 FieldName
= "." + FieldName
1854 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1855 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1857 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1858 except BadExpression
:
1859 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1860 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1861 Value
, ValueSize
= ParseFieldValue(Value
)
1862 if not Pcd
.IsArray():
1863 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]);
1866 FieldName_ori
= FieldName
.strip('.')
1867 while '[' in FieldName
:
1868 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1869 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1870 FieldName
= FieldName
.split(']', 1)[1]
1871 FieldName
= NewFieldName
+ FieldName
1872 while '[' in FieldName
and not Pcd
.IsArray():
1873 FieldName
= FieldName
.rsplit('[', 1)[0]
1874 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])
1875 for skuname
in Pcd
.SkuOverrideValues
:
1876 if skuname
== TAB_COMMON
:
1878 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1879 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1880 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1882 ActualCap
.append(index
)
1883 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1886 for FieldName
in FieldList
:
1887 FieldName
= "." + FieldName
1888 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1889 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1891 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1892 except BadExpression
:
1893 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1894 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1895 Value
, ValueSize
= ParseFieldValue(Value
)
1896 if not Pcd
.IsArray():
1897 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]);
1900 FieldName_ori
= FieldName
.strip('.')
1901 while '[' in FieldName
:
1902 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1903 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1904 FieldName
= FieldName
.split(']', 1)[1]
1905 FieldName
= NewFieldName
+ FieldName
1906 while '[' in FieldName
and not Pcd
.IsArray():
1907 FieldName
= FieldName
.rsplit('[', 1)[0]
1908 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])
1909 if Pcd
.PcdFieldValueFromFdf
:
1910 CApp
= CApp
+ "// From fdf \n"
1911 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1912 FieldName
= "." + FieldName
1913 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1914 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1916 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1917 except BadExpression
:
1918 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1919 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1920 Value
, ValueSize
= ParseFieldValue(Value
)
1921 if not Pcd
.IsArray():
1922 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]);
1925 FieldName_ori
= FieldName
.strip('.')
1926 while '[' in FieldName
:
1927 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1928 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1929 FieldName
= FieldName
.split(']', 1)[1]
1930 FieldName
= NewFieldName
+ FieldName
1931 while '[' in FieldName
:
1932 FieldName
= FieldName
.rsplit('[', 1)[0]
1933 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])
1934 if Pcd
.PcdFieldValueFromComm
:
1935 CApp
= CApp
+ "// From Command Line \n"
1936 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1937 FieldName
= "." + FieldName
1938 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1939 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1941 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1942 except BadExpression
:
1943 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1944 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1945 Value
, ValueSize
= ParseFieldValue(Value
)
1946 if not Pcd
.IsArray():
1947 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]);
1950 FieldName_ori
= FieldName
.strip('.')
1951 while '[' in FieldName
:
1952 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1953 Array_Index
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1954 FieldName
= FieldName
.split(']', 1)[1]
1955 FieldName
= NewFieldName
+ FieldName
1956 while '[' in FieldName
and not Pcd
.IsArray():
1957 FieldName
= FieldName
.rsplit('[', 1)[0]
1958 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])
1959 if Pcd
.GetPcdMaxSize():
1960 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1961 ArraySizeByAssign
= self
.CalculateActualCap(ActualCap
)
1962 if ArraySizeByAssign
> 1:
1963 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); \n" % (ArraySizeByAssign
, ArraySizeByAssign
)
1966 def CalculateActualCap(self
,ActualCap
):
1970 for item
in ActualCap
:
1971 index_elements
= ArrayIndex
.findall(item
)
1973 for index_e
in index_elements
:
1974 index_num
= index_e
.lstrip("[").rstrip("]").strip()
1976 # Not support flexiable pcd array assignment
1978 index_num
= int(index_num
,16) if index_num
.startswith(("0x","0X")) else int(index_num
)
1979 rt
= rt
* (index_num
+1)
1986 def GenerateSizeStatments(Pcd
,skuname
,defaultstorename
):
1988 r_datatype
= [Pcd
.BaseDatumType
]
1989 lastoneisEmpty
= False
1990 for dem
in Pcd
.Capacity
:
1992 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. " %
1993 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))))
1994 if dem
== '0' or dem
== "-1":
1995 r_datatype
.append("[1]")
1996 lastoneisEmpty
= True
1998 r_datatype
.append("[" + dem
+ "]")
2000 if Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_HII
, MODEL_PCD_DYNAMIC_HII
]:
2001 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultStoreDict
.get(defaultstorename
)
2002 elif Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_DEFAULT
,MODEL_PCD_DYNAMIC_VPD
,MODEL_PCD_DYNAMIC_DEFAULT
,MODEL_PCD_DYNAMIC_EX_VPD
]:
2003 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultValue
2005 PcdDefValue
= Pcd
.DefaultValue
2007 if "{CODE(" not in PcdDefValue
:
2008 sizebasevalue_plus
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
2009 sizebasevalue
= "(%s / sizeof(%s))" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
2010 sizeof
= "sizeof(%s)" % Pcd
.BaseDatumType
2011 CApp
= ' int ArraySize = %s %% %s ? %s : %s ;\n' % ( (DscBuildData
.GetStructurePcdMaxSize(Pcd
), sizeof
, sizebasevalue_plus
, sizebasevalue
))
2012 CApp
+= ' Size = ArraySize * sizeof(%s); \n' % Pcd
.BaseDatumType
2014 CApp
= " Size = 0;\n"
2016 CApp
= ' Size = sizeof(%s);\n' % ("".join(r_datatype
) )
2018 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
2019 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2022 def GetIndicator(self
,index
,FieldName
,Pcd
):
2023 def cleanupindex(indexstr
):
2024 return indexstr
.strip("[").strip("]").strip()
2025 index_elements
= ArrayIndex
.findall(index
)
2026 pcd_capacity
= Pcd
.Capacity
2029 if len(pcd_capacity
)>2:
2030 for i
in range(0,len(index_elements
)):
2031 index_ele
= index_elements
[i
]
2032 index_num
= index_ele
.strip("[").strip("]").strip()
2033 if i
== len(index_elements
) -2:
2034 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
]))
2037 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]))
2038 elif len(pcd_capacity
) == 2:
2039 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
2040 elif len(pcd_capacity
) == 1:
2041 index_ele
= index_elements
[0]
2042 index_num
= index_ele
.strip("[").strip("]").strip()
2043 indicator
+= " + %s)" % (index_num
)
2047 indicator
+= "->" + FieldName
2050 def GetStarNum(self
,Pcd
):
2051 if not Pcd
.IsArray():
2053 elif Pcd
.IsSimpleTypeArray():
2054 return len(Pcd
.Capacity
)
2056 return len(Pcd
.Capacity
) + 1
2057 def GenerateDefaultValueAssignFunction(self
, Pcd
):
2058 CApp
= "// Default value in Dec \n"
2059 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2060 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2061 CApp
= CApp
+ ' CHAR8 *Value;\n'
2062 CApp
= CApp
+ ' UINT32 PcdArraySize;\n'
2063 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
2064 IsArray
= _IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
2067 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
2068 except BadExpression
:
2069 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
2070 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
2071 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
2072 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
2075 # Use memcpy() to copy value into field
2078 pcdarraysize
= Pcd
.PcdArraySize()
2079 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2080 if Pcd
.Capacity
[-1] != "-1":
2081 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])
2082 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2083 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2085 if Pcd
.Capacity
[-1] != "-1":
2086 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])
2087 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2088 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
2089 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2091 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2092 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2093 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2095 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
2096 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2097 elif isinstance(Value
, str):
2098 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
2099 for index
in Pcd
.DefaultValues
:
2100 FieldList
= Pcd
.DefaultValues
[index
]
2103 for FieldName
in FieldList
:
2104 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2107 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2108 except BadExpression
:
2109 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2110 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2113 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2115 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]))
2117 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2120 # Use memcpy() to copy value into field
2122 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2123 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2124 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])
2125 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2126 elif isinstance(Value
, str):
2127 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2129 if '[' in FieldName
and ']' in FieldName
:
2130 Index
= int(FieldName
.split('[')[1].split(']')[0])
2131 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
)
2133 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2135 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2140 def GenerateDefaultValueAssignStatement(Pcd
):
2141 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2144 def GetPcdDscRawDefaultValue(self
,Pcd
, SkuName
,DefaultStoreName
):
2145 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2146 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2147 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2149 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2151 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2153 return pcddefaultvalue
2154 def GetPcdDscRawValueInfo(self
,Pcd
, SkuName
,DefaultStoreName
):
2155 DscValueInfo
= Pcd
.DscRawValueInfo
.get(SkuName
, {}).get(DefaultStoreName
)
2157 dscfilepath
,lineno
= DscValueInfo
2159 dscfilepath
= self
.MetaFile
.File
2161 return dscfilepath
,lineno
2163 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
2164 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
2165 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
2166 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2167 CApp
= CApp
+ ' CHAR8 *Value;\n'
2168 CApp
= CApp
+ ' UINT32 PcdArraySize;\n'
2170 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2171 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2172 dscfilepath
,lineno
= self
.GetPcdDscRawValueInfo(Pcd
, SkuName
, DefaultStoreName
)
2174 valuefrom
= "%s Line %s" % (dscfilepath
,str(lineno
))
2176 valuefrom
= dscfilepath
2178 pcddefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, SkuName
, DefaultStoreName
)
2180 FieldList
= pcddefaultvalue
2181 IsArray
= _IsFieldValueAnArray(FieldList
)
2183 if "{CODE(" not in FieldList
:
2185 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2186 except BadExpression
:
2187 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2188 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2189 Value
, ValueSize
= ParseFieldValue (FieldList
)
2191 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2192 if isinstance(Value
, str):
2193 if "{CODE(" in Value
:
2194 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2195 pcdarraysize
= Pcd
.PcdArraySize()
2196 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
)
2197 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2198 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2200 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
)
2203 # Use memcpy() to copy value into field
2206 pcdarraysize
= Pcd
.PcdArraySize()
2207 if "{CODE(" in pcddefaultvalue
:
2208 if Pcd
.Capacity
[-1] != "-1":
2209 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
)
2210 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2211 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2213 if Pcd
.Capacity
[-1] != "-1":
2214 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
)
2215 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2216 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
)
2217 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2219 if "{CODE(" in pcddefaultvalue
:
2220 CApp
= CApp
+ ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
,ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
)
2221 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2223 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
)
2224 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2226 if isinstance(Value
, str):
2227 if "{CODE(" in Value
:
2228 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2229 pcdarraysize
= Pcd
.PcdArraySize()
2230 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
)
2231 CApp
= CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n '% (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2232 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2234 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2237 # Use memcpy() to copy value into field
2240 pcdarraysize
= Pcd
.PcdArraySize()
2241 if "{CODE(" in pcddefaultvalue
:
2242 if Pcd
.Capacity
[-1] != "-1":
2243 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
)
2244 CApp
+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2245 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2247 if Pcd
.Capacity
[-1] != "-1":
2248 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
)
2249 CApp
= CApp
+ ' PcdArraySize = %d;\n' % ValueSize
2250 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
)
2251 CApp
= CApp
+ ' memcpy (Pcd, Value, PcdArraySize);\n'
2253 if "{CODE(" in pcddefaultvalue
:
2254 CApp
= CApp
+ ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
,ValueSize
,Pcd
.BaseDatumType
,pcdarraysize
)
2255 CApp
= CApp
+ ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2257 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2258 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2260 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2261 if not inheritvalue
:
2263 for index
in inheritvalue
:
2264 FieldList
= inheritvalue
[index
]
2267 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2268 for FieldName
in FieldList
:
2269 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2270 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2273 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2274 except BadExpression
:
2275 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2276 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2278 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2280 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]))
2281 if isinstance(Value
, str):
2282 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2285 # Use memcpy() to copy value into field
2287 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2288 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2289 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])
2290 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2292 if '[' in FieldName
and ']' in FieldName
:
2293 Index
= int(FieldName
.split('[')[1].split(']')[0])
2294 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
)
2296 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2298 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2303 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2304 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2307 def GenerateCommandLineValue(self
, Pcd
):
2308 CApp
= "// Value in CommandLine\n"
2309 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2310 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2311 CApp
= CApp
+ ' CHAR8 *Value;\n'
2313 pcddefaultvalue
= Pcd
.PcdValueFromComm
2314 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2317 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2318 IsArray
= _IsFieldValueAnArray(FieldList
)
2321 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2322 except BadExpression
:
2323 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2324 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2325 Value
, ValueSize
= ParseFieldValue (FieldList
)
2327 if isinstance(Value
, str):
2328 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2331 # Use memcpy() to copy value into field
2333 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2334 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2336 for FieldName
in FieldList
:
2337 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2340 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2341 except BadExpression
:
2342 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2343 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2347 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2349 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]))
2350 if isinstance(Value
, str):
2351 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2354 # Use memcpy() to copy value into field
2356 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2357 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2358 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])
2359 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2361 if '[' in FieldName
and ']' in FieldName
:
2362 Index
= int(FieldName
.split('[')[1].split(']')[0])
2363 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
)
2365 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2367 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2371 def GenerateModuleScopeValue(self
, Pcd
):
2372 CApp
= "// Value in Dsc Module scope \n"
2373 for ModuleGuid
in Pcd
.PcdFiledValueFromDscComponent
:
2375 CApp
= CApp
+ "void Assign_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, ModuleGuid
,Pcd
.BaseDatumType
)
2376 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2377 CApp
= CApp
+ ' CHAR8 *Value;\n'
2378 pcddefaultvalue
, file_path
,lineNo
= Pcd
.PcdValueFromComponents
.get(ModuleGuid
,(None,None,None))
2381 IsArray
= _IsFieldValueAnArray(pcddefaultvalue
)
2384 FieldList
= ValueExpressionEx(pcddefaultvalue
, TAB_VOID
)(True)
2385 except BadExpression
:
2386 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from %s Line %s: %s" %
2387 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, file_path
, lineNo
, FieldList
))
2388 Value
, ValueSize
= ParseFieldValue (FieldList
)
2390 if isinstance(Value
, str):
2391 CApp
= CApp
+ ' Pcd = %s; // From %s Line %s \n' % (Value
, file_path
, lineNo
)
2394 # Use memcpy() to copy value into field
2396 CApp
= CApp
+ ' Value = %s; // From %s Line %s.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), file_path
, lineNo
)
2397 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2400 PcdFiledValue
= Pcd
.PcdFiledValueFromDscComponent
.get(ModuleGuid
)
2401 for index
in PcdFiledValue
:
2402 FieldList
= PcdFiledValue
[index
]
2405 for FieldName
in FieldList
:
2406 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2409 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2410 except BadExpression
:
2411 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2412 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2416 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2418 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]))
2419 if isinstance(Value
, str):
2420 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2423 # Use memcpy() to copy value into field
2425 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2426 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2427 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])
2428 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2430 if '[' in FieldName
and ']' in FieldName
:
2431 Index
= int(FieldName
.split('[')[1].split(']')[0])
2432 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
)
2434 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2436 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2441 def GenerateCommandLineValueStatement(Pcd
):
2442 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2444 def GenerateFdfValue(self
,Pcd
):
2445 CApp
= "// Value in Fdf\n"
2446 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2447 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2448 CApp
= CApp
+ ' CHAR8 *Value;\n'
2450 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2451 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2454 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2455 IsArray
= _IsFieldValueAnArray(FieldList
)
2458 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2459 except BadExpression
:
2460 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2461 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2462 Value
, ValueSize
= ParseFieldValue (FieldList
)
2464 if isinstance(Value
, str):
2465 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2468 # Use memcpy() to copy value into field
2470 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2471 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2473 for FieldName
in FieldList
:
2474 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2477 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2478 except BadExpression
:
2479 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2480 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2484 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2486 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]))
2487 if isinstance(Value
, str):
2488 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2491 # Use memcpy() to copy value into field
2493 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2494 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2495 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])
2496 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2498 if '[' in FieldName
and ']' in FieldName
:
2499 Index
= int(FieldName
.split('[')[1].split(']')[0])
2500 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
)
2502 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2504 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2509 def GenerateFdfValueStatement(Pcd
):
2510 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2514 def GenerateModuleValueStatement(module_guid
, Pcd
):
2515 CApp
= " Assign_%s_%s_%s_Value(Pcd);\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, module_guid
)
2517 def GenerateModuleScopeInitializeFunc(self
,SkuName
, Pcd
, InitByteValue
, CApp
):
2518 for module_guid
in Pcd
.PcdFiledValueFromDscComponent
:
2519 CApp
= CApp
+ 'void\n'
2520 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2521 CApp
= CApp
+ ' void\n'
2522 CApp
= CApp
+ ' )\n'
2524 CApp
= CApp
+ ' UINT32 Size;\n'
2525 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2526 CApp
= CApp
+ ' CHAR8 *Value;\n'
2527 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2528 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2530 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2534 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2535 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2537 # Get current PCD value and size
2539 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2542 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2543 # the correct value. For structures with a flexible array member, the flexible
2544 # array member is detected, and the size is based on the highest index used with
2545 # the flexible array member. The flexible array member must be the last field
2546 # in a structure. The size formula for this case is:
2547 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2549 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,TAB_DEFAULT_STORES_DEFAULT
)
2550 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2551 CApp
= CApp
+ ' OriginalSize = OriginalSize < sizeof(%s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize(),Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2552 CApp
= CApp
+ ' Size = sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2555 # Allocate and zero buffer for the PCD
2556 # Must handle cases where current value is smaller, larger, or same size
2557 # Always keep that larger one as the current size
2559 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2560 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2561 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2564 # Copy current PCD value into allocated buffer.
2566 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2569 # Assign field values in PCD
2571 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2573 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2574 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2575 CApp
= CApp
+ DscBuildData
.GenerateModuleValueStatement(module_guid
,Pcd
)
2576 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2577 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2580 # Set new PCD value and size
2582 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (module_guid
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2587 CApp
= CApp
+ ' free (Pcd);\n'
2590 return InitByteValue
,CApp
2592 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2593 OverrideValues
= {DefaultStore
:{}}
2594 if Pcd
.SkuOverrideValues
:
2595 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2596 if not OverrideValues
:
2597 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2598 for DefaultStoreName
in OverrideValues
:
2599 CApp
= CApp
+ 'void\n'
2600 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2601 CApp
= CApp
+ ' void\n'
2602 CApp
= CApp
+ ' )\n'
2604 CApp
= CApp
+ ' UINT32 Size;\n'
2605 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2606 CApp
= CApp
+ ' CHAR8 *Value;\n'
2607 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2608 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2610 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2614 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2616 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2619 # Get current PCD value and size
2621 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2624 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2625 # the correct value. For structures with a flexible array member, the flexible
2626 # array member is detected, and the size is based on the highest index used with
2627 # the flexible array member. The flexible array member must be the last field
2628 # in a structure. The size formula for this case is:
2629 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2631 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,DefaultStoreName
)
2632 if Pcd
.IsArray() and Pcd
.Capacity
[-1] != "-1":
2633 CApp
= CApp
+ ' OriginalSize = OriginalSize < sizeof(%s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize(),Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2634 CApp
= CApp
+ ' Size = sizeof(%s) * %d; \n' % (Pcd
.BaseDatumType
,Pcd
.PcdArraySize())
2637 # Allocate and zero buffer for the PCD
2638 # Must handle cases where current value is smaller, larger, or same size
2639 # Always keep that larger one as the current size
2641 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2642 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2643 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2646 # Copy current PCD value into allocated buffer.
2648 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2651 # Assign field values in PCD
2653 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2654 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2655 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2656 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2657 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2658 for defaultstorenameitem
in storeset
:
2659 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2660 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2661 if skuname
== SkuName
:
2664 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2665 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2666 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2667 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2669 # Set new PCD value and size
2671 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2676 CApp
= CApp
+ ' free (Pcd);\n'
2679 return InitByteValue
, CApp
2681 def GenerateArrayAssignment(self
, Pcd
):
2686 for d
in Pcd
.Capacity
:
2689 Value
= Pcd
.DefaultValueFromDec
2690 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2691 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2692 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2694 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2695 for skuname
in Pcd
.SkuInfoList
:
2696 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2697 if skuinfo
.VariableName
:
2698 for defaultstore
in skuinfo
.DefaultStoreDict
:
2699 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, defaultstore
)
2700 if pcddscrawdefaultvalue
:
2701 Value
= skuinfo
.DefaultStoreDict
[defaultstore
]
2702 if "{CODE(" in Value
:
2703 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2704 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2706 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, TAB_DEFAULT_STORES_DEFAULT
)
2707 if pcddscrawdefaultvalue
:
2708 Value
= skuinfo
.DefaultValue
2709 if "{CODE(" in Value
:
2710 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2711 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2713 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2714 if pcddscrawdefaultvalue
:
2715 if "{CODE(" in Pcd
.DefaultValue
:
2716 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2717 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2721 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2722 if not OverrideValues
:
2724 for key
in OverrideValues
:
2725 if OverrideValues
[key
]:
2729 def ParseCCFlags(self
, ccflag
):
2731 ccflaglist
= ccflag
.split(" ")
2733 while i
< len(ccflaglist
):
2734 item
= ccflaglist
[i
].strip()
2735 if item
in (r
"/D", r
"/U","-D","-U"):
2736 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2738 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2742 def GenerateByteArrayValue (self
, StructuredPcds
):
2744 # Generate/Compile/Run C application to determine if there are any flexible array members
2746 if not StructuredPcds
:
2750 CApp
= PcdMainCHeader
2752 IncludeFiles
= set()
2753 for PcdName
in StructuredPcds
:
2754 Pcd
= StructuredPcds
[PcdName
]
2755 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2756 if IncludeFile
not in IncludeFiles
:
2757 IncludeFiles
.add(IncludeFile
)
2758 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2760 for Pcd
in StructuredPcds
.values():
2761 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2762 for PcdName
in sorted(StructuredPcds
.keys()):
2763 Pcd
= StructuredPcds
[PcdName
]
2765 #create void void Cal_tocken_cname_Size functions
2766 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2768 #create void Assign_ functions
2771 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2773 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2775 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2777 # From Dsc Global setting
2778 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2779 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2780 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2782 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2783 if SkuName
not in Pcd
.SkuOverrideValues
:
2785 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2786 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2788 # From Dsc module scope setting
2789 CApp
= CApp
+ self
.GenerateModuleScopeValue(Pcd
)
2791 #create Initialize_ functions
2792 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2793 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2794 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2795 InitByteValue
, CApp
= self
.GenerateModuleScopeInitializeFunc(self
.SkuIdMgr
.SystemSkuId
,Pcd
,InitByteValue
,CApp
)
2797 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2798 if SkuName
not in Pcd
.SkuOverrideValues
:
2800 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2801 Pcd
= StructuredPcds
[PcdName
]
2802 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2804 CApp
= CApp
+ 'VOID\n'
2805 CApp
= CApp
+ 'PcdEntryPoint(\n'
2806 CApp
= CApp
+ ' VOID\n'
2807 CApp
= CApp
+ ' )\n'
2809 for Pcd
in StructuredPcds
.values():
2810 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
]]:
2811 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2812 for ModuleGuid
in Pcd
.PcdFiledValueFromDscComponent
:
2813 CApp
+= " Initialize_%s_%s_%s_%s();\n" % (ModuleGuid
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2815 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2816 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2818 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2819 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2822 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2824 if not os
.path
.exists(self
.OutputPath
):
2825 os
.makedirs(self
.OutputPath
)
2826 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2827 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2829 # start generating makefile
2830 MakeApp
= PcdMakefileHeader
2831 if sys
.platform
== "win32":
2832 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 = '
2834 MakeApp
= MakeApp
+ PcdGccMakefile
2835 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
)) + \
2836 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
2839 PlatformInc
= OrderedDict()
2840 for Cache
in self
._Bdb
._CACHE
_.values():
2841 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2844 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2845 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2846 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2847 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2850 for Pcd
in StructuredPcds
.values():
2851 for PackageDec
in Pcd
.PackageDecs
:
2852 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2853 if not os
.path
.exists(Package
):
2854 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2855 if Package
not in PcdDependDEC
:
2856 PcdDependDEC
.append(Package
)
2858 if PlatformInc
and PcdDependDEC
:
2859 for pkg
in PcdDependDEC
:
2860 if pkg
in PlatformInc
:
2861 for inc
in PlatformInc
[pkg
]:
2863 # Get list of files in potential -I include path
2865 FileList
= os
.listdir (str(inc
))
2867 # Skip -I include path if one of the include files required
2868 # by PcdValueInit.c are present in the include paths from
2869 # the DEC file. PcdValueInit.c must use the standard include
2870 # files from the host compiler.
2872 if 'stdio.h' in FileList
:
2874 if 'stdlib.h' in FileList
:
2876 if 'string.h' in FileList
:
2878 MakeApp
+= '-I' + str(inc
) + ' '
2879 IncSearchList
.append(inc
)
2880 MakeApp
= MakeApp
+ '\n'
2882 CC_FLAGS
= LinuxCFLAGS
2883 if sys
.platform
== "win32":
2884 CC_FLAGS
= WindowsCFLAGS
2885 BuildOptions
= OrderedDict()
2886 for Options
in self
.BuildOptions
:
2887 if Options
[2] != EDKII_NAME
:
2890 if Family
and Family
!= self
.ToolChainFamily
:
2892 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2897 if Target
== TAB_STAR
or Target
== self
._Target
:
2898 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2899 if 'COMMON' not in BuildOptions
:
2900 BuildOptions
['COMMON'] = set()
2901 if Arch
== TAB_STAR
:
2902 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2903 if Arch
in self
.SupArchList
:
2904 if Arch
not in BuildOptions
:
2905 BuildOptions
[Arch
] = set()
2906 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2909 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2910 if len(ArchBuildOptions
.keys()) == 1:
2911 BuildOptions
['COMMON'] |
= (list(ArchBuildOptions
.values())[0])
2912 elif len(ArchBuildOptions
.keys()) > 1:
2913 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2914 BuildOptions
['COMMON'] |
= CommonBuildOptions
2915 ValueList
= [item
for item
in BuildOptions
['COMMON'] if item
.startswith((r
"/U","-U"))]
2916 ValueList
.extend([item
for item
in BuildOptions
['COMMON'] if item
.startswith((r
"/D", "-D"))])
2917 CC_FLAGS
+= " ".join(ValueList
)
2920 if sys
.platform
== "win32":
2921 MakeApp
= MakeApp
+ PcdMakefileEnd
2922 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2924 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2925 MakeApp
= MakeApp
+ '\n'
2926 IncludeFileFullPaths
= []
2927 for includefile
in IncludeFiles
:
2928 for includepath
in IncSearchList
:
2929 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2930 if os
.path
.exists(includefullpath
):
2931 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2934 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "BaseTools/Source/C/Include")))
2935 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "BaseTools/Source/C/Common")))
2936 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2937 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2938 for include_file
in IncFileList
:
2939 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2940 if sys
.platform
== "win32":
2941 PcdValueCommonPath
= os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "Source\C\Common\PcdValueCommon.c"))
2942 MakeApp
= MakeApp
+ '%s\PcdValueCommon.c : %s\n' % (self
.OutputPath
, PcdValueCommonPath
)
2943 MakeApp
= MakeApp
+ '\tcopy /y %s $@\n' % (PcdValueCommonPath
)
2945 PcdValueCommonPath
= os
.path
.normpath(mws
.join(GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"], "Source/C/Common/PcdValueCommon.c"))
2946 MakeApp
= MakeApp
+ '%s/PcdValueCommon.c : %s\n' % (self
.OutputPath
, PcdValueCommonPath
)
2947 MakeApp
= MakeApp
+ '\tcp -f %s %s/PcdValueCommon.c\n' % (PcdValueCommonPath
, self
.OutputPath
)
2948 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2949 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2950 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2952 # start generating input file
2953 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2954 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2955 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2957 Dest_PcdValueInitExe
= PcdValueInitName
2958 if not sys
.platform
== "win32":
2959 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2961 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2963 #start building the structure pcd value tool
2965 if sys
.platform
== "win32":
2966 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2967 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2970 MakeCommand
= 'make -f %s' % (MakeFileName
)
2971 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2974 EdkLogger
.verbose ('%s\n%s\n%s' % (MakeCommand
, StdOut
, StdErr
))
2975 Messages
= Messages
.split('\n')
2978 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2979 File
= open (CAppBaseFileName
+ '.c', 'r')
2980 FileData
= File
.readlines()
2982 for Message
in Messages
:
2983 if " error" in Message
or "warning" in Message
:
2985 FileInfo
= Message
.strip().split('(')
2986 if len (FileInfo
) > 1:
2987 FileName
= FileInfo
[0]
2988 FileLine
= FileInfo
[1].split (')')[0]
2990 FileInfo
= Message
.strip().split(':')
2991 if len(FileInfo
) < 2:
2993 FileName
= FileInfo
[0]
2994 FileLine
= FileInfo
[1]
2997 if "PcdValueInit.c" not in FileName
:
2999 if FileLine
.isdigit():
3000 error_line
= FileData
[int (FileLine
) - 1]
3001 if r
"//" in error_line
:
3002 c_line
, dsc_line
= error_line
.split(r
"//")
3004 dsc_line
= error_line
3005 message_itmes
= Message
.split(":")
3007 if "PcdValueInit.c" not in Message
:
3008 if not MessageGroup
:
3009 MessageGroup
.append(Message
)
3012 for item
in message_itmes
:
3013 if "PcdValueInit.c" in item
:
3014 Index
= message_itmes
.index(item
)
3015 message_itmes
[Index
] = dsc_line
.strip()
3017 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
3020 MessageGroup
.append(Message
)
3022 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
3024 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s\n%s\n%s' % (MakeCommand
, StdOut
, StdErr
))
3026 #start executing the structure pcd value tool
3027 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
3028 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
3029 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
3030 EdkLogger
.verbose ('%s\n%s\n%s' % (Command
, StdOut
, StdErr
))
3032 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s\n%s\n' % (Command
, StdOut
, StdErr
))
3034 #start update structure pcd final value
3035 File
= open (OutputValueFile
, 'r')
3036 FileBuffer
= File
.readlines()
3039 StructurePcdSet
= []
3040 for Pcd
in FileBuffer
:
3041 PcdValue
= Pcd
.split ('|')
3042 PcdInfo
= PcdValue
[0].split ('.')
3043 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
3044 return StructurePcdSet
3047 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
3048 if not os
.path
.exists(OutputFile
):
3050 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
3052 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
3056 ## Retrieve dynamic PCD settings
3058 # @param Type PCD type
3060 # @retval a dict object contains settings of given PCD type
3062 def _GetDynamicPcd(self
, Type
):
3065 Pcds
= OrderedDict()
3067 # tdict is a special dict kind of type, used for selecting correct
3068 # PCD settings for certain ARCH and SKU
3070 PcdDict
= tdict(True, 4)
3072 # Find out all possible PCD candidates for self._Arch
3073 RecordList
= self
._RawData
[Type
, self
._Arch
]
3074 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3077 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3078 SkuName
= SkuName
.upper()
3079 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3080 if SkuName
not in AvailableSkuIdSet
:
3081 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3082 File
=self
.MetaFile
, Line
=Dummy5
)
3083 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
3084 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3085 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3087 # Remove redundant PCD candidates, per the ARCH and SKU
3088 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3090 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3094 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3096 if int(MaxDatumSize
, 0) > 0xFFFF:
3097 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3098 File
=self
.MetaFile
, Line
=Dummy4
)
3099 if int(MaxDatumSize
, 0) < 0:
3100 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3101 File
=self
.MetaFile
, Line
=Dummy4
)
3102 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
3103 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3104 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3105 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3106 if MaxDatumSize
.strip():
3107 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3110 if pcdObject
.MaxDatumSize
:
3111 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3114 if CurrentMaxSize
> PcdMaxSize
:
3115 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3117 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3120 self
._PCD
_TYPE
_STRING
_[Type
],
3125 OrderedDict({SkuName
: SkuInfo
}),
3130 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3131 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3132 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3133 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
3134 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Dummy4
)
3136 for pcd
in Pcds
.values():
3137 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3138 # Only fix the value while no value provided in DSC file.
3139 for sku
in pcd
.SkuInfoList
.values():
3140 if not sku
.DefaultValue
:
3141 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3142 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3143 valuefromDec
= pcdDecObject
.DefaultValue
3144 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
3145 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3146 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3147 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3148 del pcd
.SkuInfoList
[TAB_COMMON
]
3149 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3150 del pcd
.SkuInfoList
[TAB_COMMON
]
3152 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3156 def FilterSkuSettings(self
, PcdObj
):
3158 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
3159 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
3160 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
3161 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
3162 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
3163 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
3165 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
3166 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
3171 def CompareVarAttr(Attr1
, Attr2
):
3172 if not Attr1
or not Attr2
: # for empty string
3174 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
3175 Attr1Set
= set(Attr1s
)
3176 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
3177 Attr2Set
= set(Attr2s
)
3178 if Attr2Set
== Attr1Set
:
3183 def CompletePcdValues(self
, PcdSet
):
3184 Pcds
= OrderedDict()
3185 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
3186 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
3187 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
3188 for PcdCName
, TokenSpaceGuid
in PcdSet
:
3189 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
3191 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
3192 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
3193 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
3194 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
3195 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
3196 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
3197 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
3199 PcdType
= PcdObj
.Type
3200 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
3201 for skuid
in PcdObj
.SkuInfoList
:
3202 skuobj
= PcdObj
.SkuInfoList
[skuid
]
3203 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
3204 for defaultstorename
in DefaultStores
:
3205 if defaultstorename
not in skuobj
.DefaultStoreDict
:
3206 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
3207 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
3208 for skuname
, skuid
in SkuIds
.items():
3209 if skuname
not in PcdObj
.SkuInfoList
:
3210 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
3211 while nextskuid
not in PcdObj
.SkuInfoList
:
3212 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
3213 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
3214 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
3215 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
3216 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
3217 PcdObj
.DefaultValue
= list(PcdObj
.SkuInfoList
.values())[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
3218 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
3220 ## Retrieve dynamic HII PCD settings
3222 # @param Type PCD type
3224 # @retval a dict object contains settings of given PCD type
3226 def _GetDynamicHiiPcd(self
, Type
):
3230 Pcds
= OrderedDict()
3231 UserDefinedDefaultStores
= []
3233 # tdict is a special dict kind of type, used for selecting correct
3234 # PCD settings for certain ARCH and SKU
3236 PcdDict
= tdict(True, 5)
3238 RecordList
= self
._RawData
[Type
, self
._Arch
]
3239 # Find out all possible PCD candidates for self._Arch
3240 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3241 DefaultStoresDefine
= self
._GetDefaultStores
()
3243 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
3244 SkuName
= SkuName
.upper()
3245 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3246 DefaultStore
= DefaultStore
.upper()
3247 if DefaultStore
== TAB_COMMON
:
3248 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
3250 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
3251 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
3252 if SkuName
not in AvailableSkuIdSet
:
3253 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3254 File
=self
.MetaFile
, Line
=Dummy5
)
3255 if DefaultStore
not in DefaultStoresDefine
:
3256 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
3257 File
=self
.MetaFile
, Line
=Dummy5
)
3258 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
) not in PcdList
:
3259 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
3260 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
3263 # Remove redundant PCD candidates, per the ARCH and SKU
3264 for index
,(PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
) in enumerate(PcdList
):
3266 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
3269 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3271 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
3273 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
3274 ExtraData
="[%s]" % VarAttribute
)
3276 FormatCorrect
= True
3277 if VariableOffset
.isdigit():
3278 if int(VariableOffset
, 10) > 0xFFFF:
3280 elif variablePattern
.match(VariableOffset
):
3281 if int(VariableOffset
, 16) > 0xFFFF:
3283 # For Offset written in "A.B"
3284 elif VariableOffset
.find('.') > -1:
3285 VariableOffsetList
= VariableOffset
.split(".")
3286 if not (len(VariableOffsetList
) == 2
3287 and IsValidWord(VariableOffsetList
[0])
3288 and IsValidWord(VariableOffsetList
[1])):
3289 FormatCorrect
= False
3291 FormatCorrect
= False
3292 if not FormatCorrect
:
3293 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
3296 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
3297 if (VariableName
, VariableGuid
) not in VariableAttrs
:
3298 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
3300 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
3301 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
)]))
3303 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
3304 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3305 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3306 if SkuName
in pcdObject
.SkuInfoList
:
3307 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
3308 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
3310 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
3311 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3313 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
3314 PcdClassObj
= PcdClassObject(
3317 self
._PCD
_TYPE
_STRING
_[Type
],
3322 OrderedDict({SkuName
: SkuInfo
}),
3325 pcdDecObject
.validateranges
,
3326 pcdDecObject
.validlists
,
3327 pcdDecObject
.expressions
,
3329 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
3330 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
3331 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
3333 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = index
3334 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3335 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3336 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3337 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
3338 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][DefaultStore
] = (self
.MetaFile
.File
,Dummy4
)
3339 for pcd
in Pcds
.values():
3340 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3341 pcd
.DatumType
= pcdDecObject
.DatumType
3342 # Only fix the value while no value provided in DSC file.
3343 for sku
in pcd
.SkuInfoList
.values():
3344 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
3345 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
3346 for default_store
in sku
.DefaultStoreDict
:
3347 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
3348 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
3349 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3350 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3351 valuefromDec
= pcdDecObject
.DefaultValue
3352 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
3353 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3354 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3355 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3356 del pcd
.SkuInfoList
[TAB_COMMON
]
3357 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3358 del pcd
.SkuInfoList
[TAB_COMMON
]
3360 if pcd
.MaxDatumSize
.strip():
3361 MaxSize
= int(pcd
.MaxDatumSize
, 0)
3364 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
3365 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
3367 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
3368 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
3369 if datalen
> MaxSize
:
3371 for defaultst
in skuobj
.DefaultStoreDict
:
3372 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
3373 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
3374 pcd
.MaxDatumSize
= str(MaxSize
)
3375 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
3377 invalidpcd
= ",".join(invalidhii
)
3378 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
)
3380 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3385 def CheckVariableNameAssignment(Pcds
):
3387 for pcdname
in Pcds
:
3389 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
3390 if len(varnameset
) > 1:
3391 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
3393 return False, invalidhii
3396 ## Retrieve dynamic VPD PCD settings
3398 # @param Type PCD type
3400 # @retval a dict object contains settings of given PCD type
3402 def _GetDynamicVpdPcd(self
, Type
):
3405 Pcds
= OrderedDict()
3407 # tdict is a special dict kind of type, used for selecting correct
3408 # PCD settings for certain ARCH and SKU
3410 PcdDict
= tdict(True, 4)
3413 # Find out all possible PCD candidates for self._Arch
3414 RecordList
= self
._RawData
[Type
, self
._Arch
]
3415 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3417 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3418 SkuName
= SkuName
.upper()
3419 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3420 if SkuName
not in AvailableSkuIdSet
:
3421 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3422 File
=self
.MetaFile
, Line
=Dummy5
)
3423 if "." not in TokenSpaceGuid
and "[" not in PcdCName
and (PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
) not in PcdList
:
3424 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3425 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3427 # Remove redundant PCD candidates, per the ARCH and SKU
3428 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3429 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3433 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3434 # For the Integer & Boolean type, the optional data can only be InitialValue.
3435 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3436 # until the DEC parser has been called.
3438 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3440 if int(MaxDatumSize
, 0) > 0xFFFF:
3441 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3442 File
=self
.MetaFile
, Line
=Dummy4
)
3443 if int(MaxDatumSize
, 0) < 0:
3444 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3445 File
=self
.MetaFile
, Line
=Dummy4
)
3446 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3447 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3448 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3449 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3450 if MaxDatumSize
.strip():
3451 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3454 if pcdObject
.MaxDatumSize
:
3455 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3458 if CurrentMaxSize
> PcdMaxSize
:
3459 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3461 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3464 self
._PCD
_TYPE
_STRING
_[Type
],
3469 OrderedDict({SkuName
: SkuInfo
}),
3474 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3475 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3476 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
] = {}
3477 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3478 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValueInfo
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = (self
.MetaFile
.File
,Dummy4
)
3479 for pcd
in Pcds
.values():
3480 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3481 pcd
.DatumType
= pcdDecObject
.DatumType
3482 # Only fix the value while no value provided in DSC file.
3483 for sku
in pcd
.SkuInfoList
.values():
3484 if not sku
.DefaultValue
:
3485 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3486 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3487 SkuInfoObj
= list(pcd
.SkuInfoList
.values())[0]
3488 valuefromDec
= pcdDecObject
.DefaultValue
3489 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3490 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3491 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3492 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3493 del pcd
.SkuInfoList
[TAB_COMMON
]
3494 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3495 del pcd
.SkuInfoList
[TAB_COMMON
]
3497 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3498 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3499 for pcd
in Pcds
.values():
3500 PcdValueTypeSet
= set()
3501 for sku
in pcd
.SkuInfoList
.values():
3502 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3503 if len(PcdValueTypeSet
) > 1:
3504 for sku
in pcd
.SkuInfoList
.values():
3505 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3507 list(map(self
.FilterSkuSettings
, Pcds
.values()))
3510 ## Add external modules
3512 # The external modules are mostly those listed in FDF file, which don't
3515 # @param FilePath The path of module description file
3517 def AddModule(self
, FilePath
):
3518 FilePath
= NormPath(FilePath
)
3519 if FilePath
not in self
.Modules
:
3520 Module
= ModuleBuildClassObject()
3521 Module
.MetaFile
= FilePath
3522 self
.Modules
.append(Module
)
3525 def ToolChainFamily(self
):
3526 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3527 TargetObj
= TargetTxtDict()
3528 TargetTxt
= TargetObj
.Target
3529 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultTargetTxtFile
))
3530 if os
.path
.isfile(BuildConfigurationFile
) == True:
3531 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3532 if ToolDefinitionFile
== '':
3533 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', gDefaultToolsDefFile
))
3534 if os
.path
.isfile(ToolDefinitionFile
) == True:
3535 ToolDefObj
= ToolDefDict((os
.path
.join(os
.getenv("WORKSPACE"), "Conf")))
3536 ToolDefinition
= ToolDefObj
.ToolDef
.ToolsDefTxtDatabase
3537 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3538 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3539 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3540 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3542 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3543 return self
._ToolChainFamily
3545 ## Add external PCDs
3547 # The external PCDs are mostly those listed in FDF file to specify address
3548 # or offset information.
3550 # @param Name Name of the PCD
3551 # @param Guid Token space guid of the PCD
3552 # @param Value Value of the PCD
3554 def AddPcd(self
, Name
, Guid
, Value
):
3555 if (Name
, Guid
) not in self
.Pcds
:
3556 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3557 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3561 if self
._DecPcds
is None:
3563 if GlobalData
.gFdfParser
:
3564 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3566 for Inf
in FdfInfList
:
3567 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3568 if ModuleFile
in self
._Modules
:
3570 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3571 PkgSet
.update(ModuleData
.Packages
)
3573 PkgSet
.update(self
.Packages
)
3574 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3575 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3576 return self
._DecPcds