2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 ## Platform build information from DSC file
17 # This class is used to retrieve information stored in database and convert them
18 # into PlatformBuildClassObject form for easier use for AutoGen.
20 from __future__
import print_function
21 from __future__
import absolute_import
22 from Common
.StringUtils
import *
23 from Common
.DataType
import *
24 from Common
.Misc
import *
26 from Common
.Expression
import *
27 from CommonDataClass
.CommonClass
import SkuInfoClass
28 from Common
.TargetTxtClassObject
import *
29 from Common
.ToolDefClassObject
import *
30 from .MetaDataTable
import *
31 from .MetaFileTable
import *
32 from .MetaFileParser
import *
34 from .WorkspaceCommon
import GetDeclaredPcd
35 from Common
.Misc
import AnalyzeDscPcd
36 from Common
.Misc
import ProcessDuplicatedInf
,RemoveCComments
38 from Common
.Parsing
import IsValidWord
39 from Common
.VariableAttributes
import VariableAttributes
40 import Common
.GlobalData
as GlobalData
42 from Common
.Misc
import SaveFileOnChange
43 from Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
44 from collections
import OrderedDict
, defaultdict
45 from .BuildClassObject
import ArrayIndex
47 PcdValueInitName
= 'PcdValueInit'
58 #include <PcdValueCommon.h>
68 return PcdValueMain (argc, argv);
72 PcdMakefileHeader
= '''
75 # This file is auto-generated by build utility
80 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
81 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
83 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
85 LIBS = $(LIB_PATH)\Common.lib
87 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
92 $(APPFILE): $(OBJECTS)
97 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
101 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
102 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
103 ## regular expressions for finding decimal and hex numbers
104 Pattern
= re
.compile('^[1-9]\d*|0$')
105 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
106 ## Regular expression for finding header file inclusions
107 from AutoGen
.GenMake
import gIncludePattern
109 ## Find dependencies for one source file
111 # By searching recursively "#include" directive in file, find out all the
112 # files needed by given source file. The dependecies will be only searched
113 # in given search path list.
115 # @param SearchPathList The list of search path
117 # @retval list The list of files the given source file depends on
119 def GetDependencyList(FileStack
, SearchPathList
):
121 DependencySet
= set(FileStack
)
122 while len(FileStack
) > 0:
124 FullPathDependList
= []
125 CurrentFileDependencyList
= []
127 CurrentFileDependencyList
= DepDb
[F
]
131 FileContent
= Fd
.read()
132 except BaseException
as X
:
133 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
135 if "Fd" in dir(locals()):
138 if len(FileContent
) == 0:
141 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
142 FileContent
= unicode(FileContent
, "utf-16")
143 IncludedFileList
= gIncludePattern
.findall(FileContent
)
145 for Inc
in IncludedFileList
:
147 Inc
= os
.path
.normpath(Inc
)
148 CurrentFileDependencyList
.append(Inc
)
149 DepDb
[F
] = CurrentFileDependencyList
151 CurrentFilePath
= os
.path
.dirname(F
)
152 PathList
= [CurrentFilePath
] + SearchPathList
153 for Inc
in CurrentFileDependencyList
:
154 for SearchPath
in PathList
:
155 FilePath
= os
.path
.join(SearchPath
, Inc
)
156 if not os
.path
.exists(FilePath
):
158 if FilePath
not in DependencySet
:
159 FileStack
.append(FilePath
)
160 FullPathDependList
.append(FilePath
)
162 DependencySet
.update(FullPathDependList
)
163 DependencyList
= list(DependencySet
) # remove duplicate ones
165 return DependencyList
167 class DscBuildData(PlatformBuildClassObject
):
168 # dict used to convert PCD type in database to string used by build tool
169 _PCD_TYPE_STRING_
= {
170 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
171 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
172 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
173 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
174 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
175 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
176 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
177 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
178 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
179 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
180 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
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
._HandleOverridePath
()
229 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
230 self
.DefaultStores
= None
231 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
234 def OutputPath(self
):
235 if os
.getenv("WORKSPACE"):
236 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
238 return os
.path
.dirname(self
.DscFile
)
241 def __setitem__(self
, key
, value
):
242 self
.__dict
__[self
._PROPERTY
_[key
]] = value
245 def __getitem__(self
, key
):
246 return self
.__dict
__[self
._PROPERTY
_[key
]]
249 def __contains__(self
, key
):
250 return key
in self
._PROPERTY
_
252 ## Set all internal used members of DscBuildData to None
255 self
._PlatformName
= None
258 self
._DscSpecification
= None
259 self
._OutputDirectory
= None
260 self
._SupArchList
= None
261 self
._BuildTargets
= None
263 self
._PcdInfoFlag
= None
264 self
._VarCheckFlag
= None
265 self
._FlashDefinition
= None
266 self
._Prebuild
= None
267 self
._Postbuild
= None
268 self
._BuildNumber
= None
269 self
._MakefileName
= None
270 self
._BsBaseAddress
= None
271 self
._RtBaseAddress
= None
274 self
._LibraryInstances
= None
275 self
._LibraryClasses
= None
278 self
._BuildOptions
= None
279 self
._ModuleTypeOptions
= None
280 self
._LoadFixAddress
= None
281 self
._RFCLanguages
= None
282 self
._ISOLanguages
= None
283 self
._VpdToolGuid
= None
284 self
._MacroDict
= None
285 self
.DefaultStores
= None
287 ## handle Override Path of Module
288 def _HandleOverridePath(self
):
289 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
290 for Record
in RecordList
:
293 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
294 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
296 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
298 # Check if the source override path exists
299 if not os
.path
.isdir(SourceOverridePath
):
300 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
302 # Add to GlobalData Variables
303 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
305 ## Get current effective macros
308 if self
._MacroDict
is None:
310 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
311 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
312 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
313 return self
._MacroDict
320 ## Retrieve all information in [Defines] section
322 # (Retriving all [Defines] information in one-shot is just to save time.)
324 def _GetHeaderInfo(self
):
325 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
326 for Record
in RecordList
:
328 # items defined _PROPERTY_ don't need additional processing
330 # some special items in [Defines] section need special treatment
331 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
332 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
333 if ' ' in self
._OutputDirectory
:
334 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
335 File
=self
.MetaFile
, Line
=Record
[-1],
336 ExtraData
=self
._OutputDirectory
)
337 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
338 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
339 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
341 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
343 elif Name
== TAB_DSC_PREBUILD
:
344 PrebuildValue
= Record
[2]
345 if Record
[2][0] == '"':
346 if Record
[2][-1] != '"':
347 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
348 File
=self
.MetaFile
, Line
=Record
[-1])
349 PrebuildValue
= Record
[2][1:-1]
350 self
._Prebuild
= PrebuildValue
351 elif Name
== TAB_DSC_POSTBUILD
:
352 PostbuildValue
= Record
[2]
353 if Record
[2][0] == '"':
354 if Record
[2][-1] != '"':
355 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
356 File
=self
.MetaFile
, Line
=Record
[-1])
357 PostbuildValue
= Record
[2][1:-1]
358 self
._Postbuild
= PostbuildValue
359 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
360 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
361 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
362 self
._BuildTargets
= GetSplitValueList(Record
[2])
363 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
364 if self
._SkuName
is None:
365 self
._SkuName
= Record
[2]
366 if GlobalData
.gSKUID_CMD
:
367 self
._SkuName
= GlobalData
.gSKUID_CMD
368 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
369 self
._PcdInfoFlag
= Record
[2]
370 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
371 self
._VarCheckFlag
= Record
[2]
372 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
374 self
._LoadFixAddress
= int (Record
[2], 0)
376 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
377 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
378 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
379 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for RFC_LANGUAGES must have double quotes around it, for example: RFC_LANGUAGES = "en-us;zh-hans"',
380 File
=self
.MetaFile
, Line
=Record
[-1])
381 LanguageCodes
= Record
[2][1:-1]
382 if not LanguageCodes
:
383 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
384 File
=self
.MetaFile
, Line
=Record
[-1])
385 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
386 # check whether there is empty entries in the list
387 if None in LanguageList
:
388 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
389 File
=self
.MetaFile
, Line
=Record
[-1])
390 self
._RFCLanguages
= LanguageList
391 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
392 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
393 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
394 File
=self
.MetaFile
, Line
=Record
[-1])
395 LanguageCodes
= Record
[2][1:-1]
396 if not LanguageCodes
:
397 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
398 File
=self
.MetaFile
, Line
=Record
[-1])
399 if len(LanguageCodes
) % 3:
400 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
401 File
=self
.MetaFile
, Line
=Record
[-1])
403 for i
in range(0, len(LanguageCodes
), 3):
404 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
405 self
._ISOLanguages
= LanguageList
406 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
408 # try to convert GUID to a real UUID value to see whether the GUID is format
409 # for VPD_TOOL_GUID is correct.
414 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
415 self
._VpdToolGuid
= Record
[2]
417 self
[Name
] = Record
[2]
418 # set _Header to non-None in order to avoid database re-querying
419 self
._Header
= 'DUMMY'
421 ## Retrieve platform name
423 def PlatformName(self
):
424 if self
._PlatformName
is None:
425 if self
._Header
is None:
426 self
._GetHeaderInfo
()
427 if self
._PlatformName
is None:
428 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
429 return self
._PlatformName
433 return self
.PlatformName
435 ## Retrieve file guid
438 if self
._Guid
is None:
439 if self
._Header
is None:
440 self
._GetHeaderInfo
()
441 if self
._Guid
is None:
442 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
445 ## Retrieve platform version
448 if self
._Version
is None:
449 if self
._Header
is None:
450 self
._GetHeaderInfo
()
451 if self
._Version
is None:
452 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
455 ## Retrieve platform description file version
457 def DscSpecification(self
):
458 if self
._DscSpecification
is None:
459 if self
._Header
is None:
460 self
._GetHeaderInfo
()
461 if self
._DscSpecification
is None:
462 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
463 return self
._DscSpecification
465 ## Retrieve OUTPUT_DIRECTORY
467 def OutputDirectory(self
):
468 if self
._OutputDirectory
is None:
469 if self
._Header
is None:
470 self
._GetHeaderInfo
()
471 if self
._OutputDirectory
is None:
472 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
473 return self
._OutputDirectory
475 ## Retrieve SUPPORTED_ARCHITECTURES
477 def SupArchList(self
):
478 if self
._SupArchList
is None:
479 if self
._Header
is None:
480 self
._GetHeaderInfo
()
481 if self
._SupArchList
is None:
482 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
483 return self
._SupArchList
485 ## Retrieve BUILD_TARGETS
487 def BuildTargets(self
):
488 if self
._BuildTargets
is None:
489 if self
._Header
is None:
490 self
._GetHeaderInfo
()
491 if self
._BuildTargets
is None:
492 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
493 return self
._BuildTargets
496 def PcdInfoFlag(self
):
497 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
499 elif self
._PcdInfoFlag
.upper() == 'TRUE':
505 def VarCheckFlag(self
):
506 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
508 elif self
._VarCheckFlag
.upper() == 'TRUE':
513 # # Retrieve SKUID_IDENTIFIER
516 if self
._SkuName
is None:
517 if self
._Header
is None:
518 self
._GetHeaderInfo
()
519 if self
._SkuName
is None:
520 self
._SkuName
= TAB_DEFAULT
523 ## Override SKUID_IDENTIFIER
525 def SkuName(self
, Value
):
526 self
._SkuName
= Value
529 def FlashDefinition(self
):
530 if self
._FlashDefinition
is None:
531 if self
._Header
is None:
532 self
._GetHeaderInfo
()
533 if self
._FlashDefinition
is None:
534 self
._FlashDefinition
= ''
535 return self
._FlashDefinition
539 if self
._Prebuild
is None:
540 if self
._Header
is None:
541 self
._GetHeaderInfo
()
542 if self
._Prebuild
is None:
544 return self
._Prebuild
548 if self
._Postbuild
is None:
549 if self
._Header
is None:
550 self
._GetHeaderInfo
()
551 if self
._Postbuild
is None:
553 return self
._Postbuild
555 ## Retrieve FLASH_DEFINITION
557 def BuildNumber(self
):
558 if self
._BuildNumber
is None:
559 if self
._Header
is None:
560 self
._GetHeaderInfo
()
561 if self
._BuildNumber
is None:
562 self
._BuildNumber
= ''
563 return self
._BuildNumber
565 ## Retrieve MAKEFILE_NAME
567 def MakefileName(self
):
568 if self
._MakefileName
is None:
569 if self
._Header
is None:
570 self
._GetHeaderInfo
()
571 if self
._MakefileName
is None:
572 self
._MakefileName
= ''
573 return self
._MakefileName
575 ## Retrieve BsBaseAddress
577 def BsBaseAddress(self
):
578 if self
._BsBaseAddress
is None:
579 if self
._Header
is None:
580 self
._GetHeaderInfo
()
581 if self
._BsBaseAddress
is None:
582 self
._BsBaseAddress
= ''
583 return self
._BsBaseAddress
585 ## Retrieve RtBaseAddress
587 def RtBaseAddress(self
):
588 if self
._RtBaseAddress
is None:
589 if self
._Header
is None:
590 self
._GetHeaderInfo
()
591 if self
._RtBaseAddress
is None:
592 self
._RtBaseAddress
= ''
593 return self
._RtBaseAddress
595 ## Retrieve the top address for the load fix address
597 def LoadFixAddress(self
):
598 if self
._LoadFixAddress
is None:
599 if self
._Header
is None:
600 self
._GetHeaderInfo
()
602 if self
._LoadFixAddress
is None:
603 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
606 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
608 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
611 # If command line defined, should override the value in DSC file.
613 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
615 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
617 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS']))
619 if self
._LoadFixAddress
< 0:
620 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
621 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
622 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
624 return self
._LoadFixAddress
626 ## Retrieve RFCLanguage filter
628 def RFCLanguages(self
):
629 if self
._RFCLanguages
is None:
630 if self
._Header
is None:
631 self
._GetHeaderInfo
()
632 if self
._RFCLanguages
is None:
633 self
._RFCLanguages
= []
634 return self
._RFCLanguages
636 ## Retrieve ISOLanguage filter
638 def ISOLanguages(self
):
639 if self
._ISOLanguages
is None:
640 if self
._Header
is None:
641 self
._GetHeaderInfo
()
642 if self
._ISOLanguages
is None:
643 self
._ISOLanguages
= []
644 return self
._ISOLanguages
646 ## Retrieve the GUID string for VPD tool
648 def VpdToolGuid(self
):
649 if self
._VpdToolGuid
is None:
650 if self
._Header
is None:
651 self
._GetHeaderInfo
()
652 if self
._VpdToolGuid
is None:
653 self
._VpdToolGuid
= ''
654 return self
._VpdToolGuid
656 ## Retrieve [SkuIds] section information
659 if self
._SkuIds
is None:
660 self
._SkuIds
= OrderedDict()
661 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
662 for Record
in RecordList
:
664 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
665 File
=self
.MetaFile
, Line
=Record
[-1])
667 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
668 File
=self
.MetaFile
, Line
=Record
[-1])
669 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
670 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
671 File
=self
.MetaFile
, Line
=Record
[-1])
672 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
673 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID name is invalid. The correct format is '(a-zA-Z_)(a-zA-Z0-9_)*'",
674 File
=self
.MetaFile
, Line
=Record
[-1])
675 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
676 if TAB_DEFAULT
not in self
._SkuIds
:
677 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
678 if TAB_COMMON
not in self
._SkuIds
:
679 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
684 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
686 def _GetDefaultStores(self
):
687 if self
.DefaultStores
is None:
688 self
.DefaultStores
= OrderedDict()
689 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
690 for Record
in RecordList
:
692 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
693 File
=self
.MetaFile
, Line
=Record
[-1])
695 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
696 File
=self
.MetaFile
, Line
=Record
[-1])
697 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
698 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
699 File
=self
.MetaFile
, Line
=Record
[-1])
700 if not IsValidWord(Record
[1]):
701 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",
702 File
=self
.MetaFile
, Line
=Record
[-1])
703 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
704 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
705 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
706 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
707 return self
.DefaultStores
709 ## Retrieve [Components] section information
712 if self
._Modules
is not None:
715 self
._Modules
= OrderedDict()
716 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
717 Macros
= self
._Macros
718 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
719 for Record
in RecordList
:
720 DuplicatedFile
= False
722 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
726 # check the file validation
727 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
729 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
732 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
733 if self
._Arch
!= TAB_ARCH_COMMON
and ModuleFile
in self
._Modules
:
734 DuplicatedFile
= True
736 Module
= ModuleBuildClassObject()
737 Module
.MetaFile
= ModuleFile
739 # get module private library instance
740 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
741 for Record
in RecordList
:
742 LibraryClass
= Record
[0]
743 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
746 # check the file validation
747 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
749 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
752 if LibraryClass
== '' or LibraryClass
== 'NULL':
753 self
._NullLibraryNumber
+= 1
754 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
755 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
756 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
757 if LibraryPath
not in self
.LibraryInstances
:
758 self
.LibraryInstances
.append(LibraryPath
)
760 # get module private PCD setting
761 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
762 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
763 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
764 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
765 TokenList
= GetSplitValueList(Setting
)
766 DefaultValue
= TokenList
[0]
767 # the format is PcdName| Value | VOID* | MaxDatumSize
768 if len(TokenList
) > 2:
769 MaxDatumSize
= TokenList
[2]
772 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
773 Pcd
= PcdClassObject(
785 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
787 # get module private build options
788 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
789 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
790 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
791 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
793 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
794 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
796 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
797 if DuplicatedFile
and not RecordList
:
798 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
800 if len(RecordList
) != 1:
801 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
802 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
803 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
804 ModuleFile
.Arch
= self
._Arch
806 self
._Modules
[ModuleFile
] = Module
809 ## Retrieve all possible library instances used in this platform
811 def LibraryInstances(self
):
812 if self
._LibraryInstances
is None:
814 return self
._LibraryInstances
816 ## Retrieve [LibraryClasses] information
818 def LibraryClasses(self
):
819 if self
._LibraryClasses
is None:
820 self
._LibraryInstances
= []
822 # tdict is a special dict kind of type, used for selecting correct
823 # library instance for given library class and module type
825 LibraryClassDict
= tdict(True, 3)
826 # track all library class names
827 LibraryClassSet
= set()
828 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
829 Macros
= self
._Macros
830 for Record
in RecordList
:
831 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
832 if LibraryClass
== '' or LibraryClass
== 'NULL':
833 self
._NullLibraryNumber
+= 1
834 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
835 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
836 LibraryClassSet
.add(LibraryClass
)
837 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
838 # check the file validation
839 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
841 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
844 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
845 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
846 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
847 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
848 if LibraryInstance
not in self
._LibraryInstances
:
849 self
._LibraryInstances
.append(LibraryInstance
)
851 # resolve the specific library instance for each class and each module type
852 self
._LibraryClasses
= tdict(True)
853 for LibraryClass
in LibraryClassSet
:
854 # try all possible module types
855 for ModuleType
in SUP_MODULE_LIST
:
856 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
857 if LibraryInstance
is None:
859 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
861 # for Edk style library instances, which are listed in different section
862 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
863 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
864 for Record
in RecordList
:
865 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
867 # check the file validation
868 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
870 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
872 if File
not in self
._LibraryInstances
:
873 self
._LibraryInstances
.append(File
)
875 # we need the module name as the library class name, so we have
876 # to parse it here. (self._Bdb[] will trigger a file parse if it
877 # hasn't been parsed)
879 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
880 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
881 return self
._LibraryClasses
883 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
884 if self
._DecPcds
is None:
887 if GlobalData
.gFdfParser
:
888 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
891 for Inf
in FdfInfList
:
892 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
893 if ModuleFile
in self
._Modules
:
895 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
896 PkgSet
.update(ModuleData
.Packages
)
898 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
899 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
901 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
902 EdkLogger
.error('build', PARSER_ERROR
,
903 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
904 File
=self
.MetaFile
, Line
=LineNo
)
905 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
907 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
908 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
909 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
911 if ValueList
[2] == '-1':
912 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
913 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
915 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
916 if "{CODE(" not in ValueList
[Index
]:
918 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
919 except BadExpression
as Value
:
920 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
921 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
922 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
923 except EvaluationException
as Excpt
:
924 if hasattr(Excpt
, 'Pcd'):
925 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
926 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
927 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
928 " of the DSC file" % Excpt
.Pcd
,
929 File
=self
.MetaFile
, Line
=LineNo
)
931 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
932 File
=self
.MetaFile
, Line
=LineNo
)
934 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
935 File
=self
.MetaFile
, Line
=LineNo
)
938 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
940 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
941 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
942 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
943 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
944 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd datumtype used in DSC file is not the same as its declaration in DEC file.", File
=self
.MetaFile
, Line
=LineNo
,
945 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
946 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
947 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
948 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
951 def _FilterPcdBySkuUsage(self
, Pcds
):
952 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
953 sku_usage
= self
.SkuIdMgr
.SkuUsageType
954 if sku_usage
== SkuClass
.SINGLE
:
957 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
958 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
959 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
963 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
964 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
965 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
968 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
969 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
]]]
970 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
972 for skuid
in pcd
.SkuInfoList
:
973 skuobj
= pcd
.SkuInfoList
.get(skuid
)
974 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
975 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
976 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
977 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
980 def RecoverCommandLinePcd(self
):
981 def UpdateCommandLineValue(pcd
):
982 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
983 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
984 pcd
.PcdValueFromComm
= pcd
.DefaultValue
985 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
986 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
988 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
989 for pcd
in self
._Pcds
:
990 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
991 UpdateCommandLineValue(self
._Pcds
[pcd
])
993 def __ParsePcdFromCommandLine(self
):
994 if GlobalData
.BuildOptionPcd
:
995 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
996 if isinstance(pcd
, tuple):
998 (pcdname
, pcdvalue
) = pcd
.split('=')
1000 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1002 (Name1
, Name2
) = pcdname
.split('.', 1)
1004 (Name3
, FieldName
) = Name2
.split(".", 1)
1005 if ((Name3
, Name1
)) in self
.DecPcds
:
1006 HasTokenSpace
= True
1008 TokenSpaceGuidCName
= Name1
1012 TokenSpaceGuidCName
= ''
1013 HasTokenSpace
= False
1015 if ((Name2
, Name1
)) in self
.DecPcds
:
1016 HasTokenSpace
= True
1018 TokenSpaceGuidCName
= Name1
1023 TokenSpaceGuidCName
= ''
1024 HasTokenSpace
= False
1027 TokenCName
= pcdname
1028 TokenSpaceGuidCName
= ''
1029 HasTokenSpace
= False
1030 TokenSpaceGuidCNameList
= []
1033 DisplayName
= TokenCName
1035 DisplayName
= TokenCName
+ '.' + FieldName
1036 if not HasTokenSpace
:
1037 for key
in self
.DecPcds
:
1038 PcdItem
= self
.DecPcds
[key
]
1039 if TokenCName
== PcdItem
.TokenCName
:
1040 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1041 if len (TokenSpaceGuidCNameList
) < 1:
1042 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1043 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1044 PcdDatumType
= PcdItem
.DatumType
1050 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1053 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1054 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1058 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1060 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1061 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1063 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1065 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1066 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1068 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1069 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1071 if GlobalData
.BuildOptionPcd
:
1072 for pcd
in GlobalData
.BuildOptionPcd
:
1073 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1074 for BuildData
in self
._Bdb
._CACHE
_.values():
1075 if BuildData
.Arch
!= self
.Arch
:
1077 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1079 for key
in BuildData
.Pcds
:
1080 PcdItem
= BuildData
.Pcds
[key
]
1081 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1082 PcdItem
.DefaultValue
= pcdvalue
1083 PcdItem
.PcdValueFromComm
= pcdvalue
1084 #In command line, the latter full assign value in commandLine should override the former field assign value.
1085 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1088 if GlobalData
.BuildOptionPcd
:
1089 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1090 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1092 if (TokenSpaceGuid
, Token
) not in field_assign
:
1093 field_assign
[TokenSpaceGuid
, Token
] = []
1094 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1096 if (TokenSpaceGuid
, Token
) in field_assign
:
1097 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1098 field_assign
[TokenSpaceGuid
, Token
] = []
1099 for item
in delete_assign
:
1100 GlobalData
.BuildOptionPcd
.remove(item
)
1103 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1106 TokenCName
+= '.' + FieldName
1107 if PcdValue
.startswith('H'):
1108 if FieldName
and IsFieldValueAnArray(PcdValue
[1:]):
1109 PcdDatumType
= TAB_VOID
1111 if FieldName
and not IsArray
:
1114 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1115 except BadExpression
as Value
:
1116 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1117 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1118 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1119 if FieldName
and IsFieldValueAnArray(PcdValue
):
1120 PcdDatumType
= TAB_VOID
1122 if FieldName
and not IsArray
:
1125 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1126 except BadExpression
as Value
:
1127 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1128 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1129 elif PcdValue
.startswith('L'):
1130 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1131 if FieldName
and IsFieldValueAnArray(PcdValue
):
1132 PcdDatumType
= TAB_VOID
1134 if FieldName
and not IsArray
:
1137 PcdValue
= ValueExpressionEx(PcdValue
, 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
))
1142 if PcdValue
.upper() == 'FALSE':
1144 if PcdValue
.upper() == 'TRUE':
1147 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1148 PcdValue
= '"' + PcdValue
+ '"'
1149 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1150 PcdValue
= '"' + PcdValue
+ '"'
1154 if PcdValue
.upper().startswith('0X'):
1157 Num
= int(PcdValue
, Base
)
1159 PcdValue
= '"' + PcdValue
+ '"'
1160 if IsFieldValueAnArray(PcdValue
):
1161 PcdDatumType
= TAB_VOID
1166 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1167 except BadExpression
as Value
:
1168 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1169 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1172 ## Retrieve all PCD settings in platform
1175 if self
._Pcds
is None:
1176 self
._Pcds
= OrderedDict()
1177 self
.__ParsePcdFromCommandLine
()
1178 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1179 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1180 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1181 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1182 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1183 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1184 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1185 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1186 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1188 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1189 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1190 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1191 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1192 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1193 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1195 self
.RecoverCommandLinePcd()
1198 ## Retrieve [BuildOptions]
1200 def BuildOptions(self
):
1201 if self
._BuildOptions
is None:
1202 self
._BuildOptions
= OrderedDict()
1204 # Retrieve build option for EDKII and EDK style module
1206 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1207 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1208 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1209 if Dummy3
.upper() != TAB_COMMON
:
1211 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1213 # Only flags can be appended
1215 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1216 self
._BuildOptions
[CurKey
] = Option
1218 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1219 self
._BuildOptions
[CurKey
] += ' ' + Option
1220 return self
._BuildOptions
1222 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1223 if self
._ModuleTypeOptions
is None:
1224 self
._ModuleTypeOptions
= OrderedDict()
1225 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1226 options
= OrderedDict()
1227 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1228 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1229 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1230 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1231 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1232 Type
= Dummy2
+ '.' + Dummy3
1233 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1234 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1235 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1236 options
[Key
] = Option
1238 if ' ' + Option
not in options
[Key
]:
1239 options
[Key
] += ' ' + Option
1240 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1243 def GetStructurePcdInfo(PcdSet
):
1244 structure_pcd_data
= defaultdict(list)
1246 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1248 return structure_pcd_data
1251 def OverrideByFdf(StruPcds
,workspace
):
1252 if GlobalData
.gFdfParser
is None:
1254 StructurePcdInFdf
= OrderedDict()
1255 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1256 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1257 for item
in fdfpcd
:
1258 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1259 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1260 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1261 for Pcd
in StruPcds
.values():
1262 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1264 FieldValues
= OrderedDict()
1265 for item
in StructurePcdInFdf
:
1266 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1267 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1268 for field
in FieldValues
:
1269 if field
not in Pcd
.PcdFieldValueFromFdf
:
1270 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1271 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1272 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1273 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1278 def OverrideByComm(StruPcds
):
1279 StructurePcdInCom
= OrderedDict()
1280 for item
in GlobalData
.BuildOptionPcd
:
1281 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1282 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1283 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1284 for Pcd
in StruPcds
.values():
1285 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1287 FieldValues
= OrderedDict()
1288 for item
in StructurePcdInCom
:
1289 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1290 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1291 for field
in FieldValues
:
1292 if field
not in Pcd
.PcdFieldValueFromComm
:
1293 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1294 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1295 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1296 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1299 def OverrideByCommOverAll(self
,AllPcds
):
1300 def CheckStructureInComm(commpcds
):
1303 if len(commpcds
[0]) == 5:
1306 NoFiledValues
= OrderedDict()
1307 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1308 StructurePcdInCom
= OrderedDict()
1309 for item
in GlobalData
.BuildOptionPcd
:
1310 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1311 for item
in StructurePcdInCom
:
1313 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1315 for item
in GlobalData
.BuildOptionPcd
:
1316 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1317 for Guid
, Name
in NoFiledValues
:
1318 if (Name
, Guid
) in AllPcds
:
1319 Pcd
= AllPcds
.get((Name
, Guid
))
1320 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1321 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1323 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1324 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1325 for sku
in Pcd
.SkuInfoList
:
1326 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1327 if SkuInfo
.DefaultValue
:
1328 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1330 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1331 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1332 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1333 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1334 if Pcd
.DatumType
== TAB_VOID
:
1335 if not Pcd
.MaxDatumSize
:
1336 Pcd
.MaxDatumSize
= '0'
1337 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1338 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1339 MaxSize
= max(CurrentSize
, OptionSize
)
1340 Pcd
.MaxDatumSize
= str(MaxSize
)
1342 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1344 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1345 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1346 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1347 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1348 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1349 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1350 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1351 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1352 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1353 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1354 self
.Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1357 def OverrideByFdfOverAll(self
,AllPcds
):
1359 if GlobalData
.gFdfParser
is None:
1361 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1362 for Name
,Guid
,Field
in NoFiledValues
:
1365 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1366 if (Name
,Guid
) in AllPcds
:
1367 Pcd
= AllPcds
.get((Name
,Guid
))
1368 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1369 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1371 Pcd
.PcdValueFromComm
= Value
1372 Pcd
.DefaultValue
= Value
1373 for sku
in Pcd
.SkuInfoList
:
1374 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1375 if SkuInfo
.DefaultValue
:
1376 SkuInfo
.DefaultValue
= Value
1378 SkuInfo
.HiiDefaultValue
= Value
1379 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1380 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1381 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1382 if Pcd
.DatumType
== TAB_VOID
:
1383 if not Pcd
.MaxDatumSize
:
1384 Pcd
.MaxDatumSize
= '0'
1385 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1386 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1387 MaxSize
= max(CurrentSize
, OptionSize
)
1388 Pcd
.MaxDatumSize
= str(MaxSize
)
1390 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1392 PcdInDec
.PcdValueFromFdf
= Value
1393 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1394 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1395 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1396 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1397 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
1400 def ParsePcdNameStruct(self
,NamePart1
,NamePart2
):
1401 TokenSpaceCName
= PcdCName
= DimensionAttr
= Field
= ""
1402 if "." in NamePart1
:
1403 TokenSpaceCName
, TempPcdCName
= NamePart1
.split(".")
1404 if "[" in TempPcdCName
:
1405 PcdCName
= TempPcdCName
[:TempPcdCName
.index("[")]
1406 DimensionAttr
= TempPcdCName
[TempPcdCName
.index("["):]
1408 PcdCName
= TempPcdCName
1411 TokenSpaceCName
= NamePart1
1412 if "[" in NamePart2
:
1413 PcdCName
= NamePart2
[:NamePart2
.index("[")]
1414 DimensionAttr
= NamePart2
[NamePart2
.index("["):]
1416 PcdCName
= NamePart2
1418 return TokenSpaceCName
,PcdCName
,DimensionAttr
,Field
1420 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1422 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1423 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1424 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1425 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1426 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1427 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1430 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1431 SkuIds
= self
.SkuIds
1432 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1433 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1434 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1437 # Find out all possible PCD candidates for self._Arch
1440 for Type
in TypeList
:
1441 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1443 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1444 SkuName
= SkuName
.upper()
1445 default_store
= default_store
.upper()
1446 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1447 if SkuName
not in SkuIds
:
1449 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
1450 pcd_in_dec
= self
._DecPcds
.get((PCName
,TCName
), None)
1451 if pcd_in_dec
is None:
1452 EdkLogger
.error('build', PARSER_ERROR
,
1453 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1454 File
=self
.MetaFile
, Line
= Dummy5
)
1455 if SkuName
in SkuIds
and ("." in TokenSpaceGuid
or "[" in PcdCName
):
1456 if not isinstance (pcd_in_dec
, StructurePcd
):
1457 EdkLogger
.error('build', PARSER_ERROR
,
1458 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1459 File
=self
.MetaFile
, Line
= Dummy5
)
1461 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1463 # handle pcd value override
1464 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1465 S_pcd_set
= OrderedDict()
1466 for str_pcd
in StrPcdSet
:
1467 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1468 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1469 str_pcd_obj_str
= StructurePcd()
1470 str_pcd_obj_str
.copy(str_pcd_dec
)
1472 str_pcd_obj_str
.copy(str_pcd_obj
)
1473 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1474 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
}
1476 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
}
1477 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1478 if str_pcd_data
[4] in SkuIds
:
1479 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])
1480 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1482 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1483 for Pcd
in self
.DecPcds
:
1484 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1485 if Pcd
not in S_pcd_set
:
1486 str_pcd_obj_str
= StructurePcd()
1487 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1488 str_pcd_obj
= Pcds
.get(Pcd
, None)
1490 str_pcd_obj_str
.copy(str_pcd_obj
)
1491 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1492 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
}
1494 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
}
1495 S_pcd_set
[Pcd
] = str_pcd_obj_str
1496 self
.FilterStrcturePcd(S_pcd_set
)
1498 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1499 for stru_pcd
in S_pcd_set
.values():
1500 for skuid
in SkuIds
:
1501 if skuid
in stru_pcd
.SkuOverrideValues
:
1503 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1505 if skuid
not in stru_pcd
.SkuOverrideValues
:
1506 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1507 if nextskuid
== TAB_DEFAULT
:
1510 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1511 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})
1513 stru_pcd
.ValueChain
.add((skuid
, ''))
1514 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1515 for skuid
in SkuIds
:
1518 if skuid
not in stru_pcd
.SkuOverrideValues
:
1519 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1520 if nextskuid
== TAB_DEFAULT
:
1523 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1526 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1527 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1529 for defaultstoreid
in DefaultStores
:
1530 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1531 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = CopyDict(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1532 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1533 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1534 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1535 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1537 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1538 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1539 if str_pcd_obj
is None:
1540 print(PcdName
, PcdGuid
)
1542 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1543 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1544 if skuname
not in str_pcd_obj
.SkuInfoList
:
1545 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1547 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1548 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1549 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1550 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1551 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1552 str_pcd_obj
.DefaultValue
= PcdValue
1554 if skuname
not in str_pcd_obj
.SkuInfoList
:
1555 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1557 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1558 if nextskuid
== TAB_DEFAULT
:
1561 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1562 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
)
1563 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1564 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1566 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1567 for str_pcd_obj
in S_pcd_set
.values():
1568 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1569 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1571 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1572 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1573 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1574 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1576 for str_pcd_obj
in S_pcd_set
.values():
1578 str_pcd_obj
.MaxDatumSize
= DscBuildData
.GetStructurePcdMaxSize(str_pcd_obj
)
1579 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1580 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1584 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1585 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1586 del pcd
.SkuInfoList
[TAB_COMMON
]
1587 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1588 del pcd
.SkuInfoList
[TAB_COMMON
]
1590 map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1593 def PlatformUsedPcds(self
):
1595 if GlobalData
.gFdfParser
:
1596 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1597 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1598 AllModulePcds
= set()
1599 ModuleSet
= set(self
._Modules
.keys() + FdfModuleList
)
1600 for ModuleFile
in ModuleSet
:
1601 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1602 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1603 for ModuleFile
in self
.LibraryInstances
:
1604 ModuleData
= self
._Bdb
.CreateBuildObject(ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
)
1605 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1606 return AllModulePcds
1608 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1609 def FilterStrcturePcd(self
, S_pcd_set
):
1610 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.PlatformUsedPcds
1611 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1612 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1614 ## Retrieve non-dynamic PCD settings
1616 # @param Type PCD type
1618 # @retval a dict object contains settings of given PCD type
1620 def _GetPcd(self
, Type
):
1621 Pcds
= OrderedDict()
1623 # tdict is a special dict kind of type, used for selecting correct
1624 # PCD settings for certain ARCH
1626 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1628 PcdDict
= tdict(True, 4)
1630 # Find out all possible PCD candidates for self._Arch
1631 RecordList
= self
._RawData
[Type
, self
._Arch
]
1632 PcdValueDict
= OrderedDict()
1633 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1634 SkuName
= SkuName
.upper()
1635 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1636 if SkuName
not in AvailableSkuIdSet
:
1637 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1638 File
=self
.MetaFile
, Line
=Dummy5
)
1639 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1640 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
1641 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1642 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1644 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1645 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1648 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1650 if int(MaxDatumSize
, 0) > 0xFFFF:
1651 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1652 File
=self
.MetaFile
, Line
=Dummy4
)
1653 if int(MaxDatumSize
, 0) < 0:
1654 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1655 File
=self
.MetaFile
, Line
=Dummy4
)
1656 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1657 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1659 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1661 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.iteritems():
1662 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1663 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1664 elif TAB_DEFAULT
in PcdSetting
:
1665 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_DEFAULT
]
1666 elif TAB_COMMON
in PcdSetting
:
1667 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_COMMON
]
1673 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1676 self
._PCD
_TYPE
_STRING
_[Type
],
1685 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1686 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1687 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1688 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1689 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1693 def GetStructurePcdMaxSize(str_pcd
):
1694 pcd_default_value
= str_pcd
.DefaultValue
1695 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()]
1696 sku_values
.append(pcd_default_value
)
1698 def get_length(value
):
1699 Value
= value
.strip()
1701 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1703 if Value
.startswith('L"') and Value
.endswith('"'):
1704 return len(Value
[2:-1])
1705 if Value
[0] == '"' and Value
[-1] == '"':
1706 return len(Value
) - 2
1707 if Value
.strip().startswith("{CODE("):
1708 tmpValue
= RemoveCComments(Value
)
1709 return len(tmpValue
.split(","))
1710 if (Value
[0] == '{' and Value
[-1] == '}'):
1711 return len(Value
.split(","))
1712 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1713 return len(list(Value
[2:-1]))
1714 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1715 return len(Value
) - 2
1718 return str(max(get_length(item
) for item
in sku_values
))
1721 def ExecuteCommand (Command
):
1723 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1725 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1726 Result
= Process
.communicate()
1727 return Process
.returncode
, Result
[0], Result
[1]
1730 def IntToCString(Value
, ValueSize
):
1732 if not isinstance (Value
, str):
1733 for Index
in range(0, ValueSize
):
1734 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1736 Result
= Result
+ '"'
1739 def GenerateSizeFunction(self
, Pcd
):
1740 CApp
= "// Default Value in Dec \n"
1741 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1743 if (len(Pcd
.Capacity
) == 1 and Pcd
.Capacity
[0] != '0') or (len(Pcd
.Capacity
) >1 and reduce(lambda x
,y
:int(x
)*int(y
), Pcd
.Capacity
)) > 0:
1744 CApp
+= " *Size = (sizeof (%s) * (%s) > *Size) ? sizeof (%s) * (%s): *Size; \n" % (Pcd
.BaseDatumType
, "*".join(Pcd
.Capacity
),Pcd
.BaseDatumType
, "*".join(Pcd
.Capacity
))
1745 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1746 CApp
+= " *Size = (sizeof (%s_%s_INIT_Value) > *Size ? sizeof (%s_%s_INIT_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)
1747 for skuname
in Pcd
.SkuInfoList
:
1748 skuobj
= Pcd
.SkuInfoList
[skuname
]
1749 if skuobj
.VariableName
:
1750 for defaultstore
in skuobj
.DefaultStoreDict
:
1751 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
)
1753 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
)
1754 for index
in Pcd
.DefaultValues
:
1755 FieldList
= Pcd
.DefaultValues
[index
]
1758 for FieldName
in FieldList
:
1759 FieldName
= "." + FieldName
1760 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1761 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1763 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1764 except BadExpression
:
1765 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1766 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1767 Value
, ValueSize
= ParseFieldValue(Value
)
1768 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]);
1771 FieldName_ori
= FieldName
.strip('.')
1772 while '[' in FieldName
:
1773 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1774 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1775 FieldName
= FieldName
.split(']', 1)[1]
1776 FieldName
= NewFieldName
+ FieldName
1777 while '[' in FieldName
:
1778 FieldName
= FieldName
.rsplit('[', 1)[0]
1779 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s\n' % (Pcd
.DatumType
, FieldName
.strip("."), ArrayIndex
+ 1, FieldList
[FieldName_ori
][1], FieldList
[FieldName_ori
][2], FieldList
[FieldName_ori
][0])
1780 for skuname
in Pcd
.SkuOverrideValues
:
1781 if skuname
== TAB_COMMON
:
1783 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1784 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1785 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1786 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1789 for FieldName
in FieldList
:
1790 FieldName
= "." + FieldName
1791 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1792 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1794 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1795 except BadExpression
:
1796 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1797 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1798 Value
, ValueSize
= ParseFieldValue(Value
)
1799 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]);
1802 FieldName_ori
= FieldName
.strip('.')
1803 while '[' in FieldName
:
1804 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1805 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1806 FieldName
= FieldName
.split(']', 1)[1]
1807 FieldName
= NewFieldName
+ FieldName
1808 while '[' in FieldName
:
1809 FieldName
= FieldName
.rsplit('[', 1)[0]
1810 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), ArrayIndex
+ 1, FieldList
[FieldName_ori
][1], FieldList
[FieldName_ori
][2], FieldList
[FieldName_ori
][0])
1811 if Pcd
.PcdFieldValueFromFdf
:
1812 CApp
= CApp
+ "// From fdf \n"
1813 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1814 FieldName
= "." + FieldName
1815 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1816 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1818 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1819 except BadExpression
:
1820 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1821 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1822 Value
, ValueSize
= ParseFieldValue(Value
)
1823 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]);
1826 FieldName_ori
= FieldName
.strip('.')
1827 while '[' in FieldName
:
1828 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1829 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1830 FieldName
= FieldName
.split(']', 1)[1]
1831 FieldName
= NewFieldName
+ FieldName
1832 while '[' in FieldName
:
1833 FieldName
= FieldName
.rsplit('[', 1)[0]
1834 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %s Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), ArrayIndex
+ 1, Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][1], Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][2], Pcd
.PcdFieldValueFromFdf
[FieldName_ori
][0])
1835 if Pcd
.PcdFieldValueFromComm
:
1836 CApp
= CApp
+ "// From Command Line \n"
1837 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1838 FieldName
= "." + FieldName
1839 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1840 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1842 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1843 except BadExpression
:
1844 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1845 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1846 Value
, ValueSize
= ParseFieldValue(Value
)
1847 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]);
1850 FieldName_ori
= FieldName
.strip('.')
1851 while '[' in FieldName
:
1852 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1853 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1854 FieldName
= FieldName
.split(']', 1)[1]
1855 FieldName
= NewFieldName
+ FieldName
1856 while '[' in FieldName
:
1857 FieldName
= FieldName
.rsplit('[', 1)[0]
1858 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), ArrayIndex
+ 1, Pcd
.PcdFieldValueFromComm
[FieldName_ori
][1], Pcd
.PcdFieldValueFromComm
[FieldName_ori
][2], Pcd
.PcdFieldValueFromComm
[FieldName_ori
][0])
1859 if Pcd
.GetPcdMaxSize():
1860 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1865 def GenerateSizeStatments(Pcd
):
1867 r_datatype
= [Pcd
.BaseDatumType
]
1868 for dem
in Pcd
.Capacity
:
1870 r_datatype
.append("[1]")
1872 r_datatype
.append("[" + dem
+ "]")
1873 sizebasevalue
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), Pcd
.BaseDatumType
))
1874 CApp
= ' Size = sizeof(%s) > %s?sizeof(%s) : %s ;\n' % ( ("".join(r_datatype
), sizebasevalue
, "".join(r_datatype
), sizebasevalue
) )
1876 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1877 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1880 def GetIndicator(self
,index
,FieldName
,Pcd
):
1881 def cleanupindex(indexstr
):
1882 return indexstr
.strip("[").strip("]").strip()
1883 index_elements
= ArrayIndex
.findall(index
)
1884 pcd_capacity
= Pcd
.Capacity
1887 if len(pcd_capacity
)>2:
1888 for i
in xrange(0,len(index_elements
)):
1889 index_ele
= index_elements
[i
]
1890 index_num
= index_ele
.strip("[").strip("]").strip()
1891 if i
== len(index_elements
) -2:
1892 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
]))
1895 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]))
1896 elif len(pcd_capacity
) == 2:
1897 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
1898 elif len(pcd_capacity
) == 1:
1899 index_ele
= index_elements
[0]
1900 index_num
= index_ele
.strip("[").strip("]").strip()
1901 indicator
+= " + %s)" % (index_num
)
1905 indicator
+= "->" + FieldName
1908 def GetStarNum(self
,Pcd
):
1909 if not Pcd
.IsArray():
1911 elif Pcd
.IsSimpleTypeArray():
1912 return len(Pcd
.Capacity
)
1914 return len(Pcd
.Capacity
) + 1
1915 def GenerateDefaultValueAssignFunction(self
, Pcd
):
1916 CApp
= "// Default value in Dec \n"
1917 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
1918 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1919 CApp
= CApp
+ ' CHAR8 *Value;\n'
1920 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1921 IsArray
= IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1924 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1925 except BadExpression
:
1926 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1927 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1928 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1929 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1930 if isinstance(Value
, str):
1931 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1934 # Use memcpy() to copy value into field
1936 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1937 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value, sizeof(%s_%s_INIT_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1939 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1940 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1941 for index
in Pcd
.DefaultValues
:
1942 FieldList
= Pcd
.DefaultValues
[index
]
1945 for FieldName
in FieldList
:
1946 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1949 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1950 except BadExpression
:
1951 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1952 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1955 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1957 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]))
1959 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
1960 if isinstance(Value
, str):
1961 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1964 # Use memcpy() to copy value into field
1966 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1967 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1968 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
.DatumType
, FieldName
, ValueSize
, Pcd
.DatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1969 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1970 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
1973 if '[' in FieldName
and ']' in FieldName
:
1974 Index
= int(FieldName
.split('[')[1].split(']')[0])
1975 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
)
1977 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1979 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1984 def GenerateDefaultValueAssignStatement(Pcd
):
1985 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1988 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
1989 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
1990 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
1991 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1992 CApp
= CApp
+ ' CHAR8 *Value;\n'
1994 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
1995 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1996 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1997 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
1998 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2000 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2002 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2005 FieldList
= pcddefaultvalue
2006 IsArray
= IsFieldValueAnArray(FieldList
)
2008 if "{CODE(" not in FieldList
:
2010 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2011 except BadExpression
:
2012 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2013 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2014 Value
, ValueSize
= ParseFieldValue (FieldList
)
2016 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2017 if isinstance(Value
, str):
2018 if "{CODE(" in Value
:
2019 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2021 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
)
2024 # Use memcpy() to copy value into field
2027 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2029 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
)
2030 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2032 if isinstance(Value
, str):
2033 if "{CODE(" in Value
:
2034 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2036 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2039 # Use memcpy() to copy value into field
2042 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2044 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2045 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2047 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2048 if not inheritvalue
:
2050 for index
in inheritvalue
:
2051 FieldList
= inheritvalue
[index
]
2054 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2055 for FieldName
in FieldList
:
2056 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2057 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2060 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2061 except BadExpression
:
2062 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2063 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2065 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2067 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]))
2068 if isinstance(Value
, str):
2069 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2072 # Use memcpy() to copy value into field
2074 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2075 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2076 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
.DatumType
, FieldName
, ValueSize
, Pcd
.DatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2077 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2078 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2080 if '[' in FieldName
and ']' in FieldName
:
2081 Index
= int(FieldName
.split('[')[1].split(']')[0])
2082 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
)
2084 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2086 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2091 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2092 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2095 def GenerateCommandLineValue(self
, Pcd
):
2096 CApp
= "// Value in CommandLine\n"
2097 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2098 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2099 CApp
= CApp
+ ' CHAR8 *Value;\n'
2101 pcddefaultvalue
= Pcd
.PcdValueFromComm
2102 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2105 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2106 IsArray
= IsFieldValueAnArray(FieldList
)
2109 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2110 except BadExpression
:
2111 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2112 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2113 Value
, ValueSize
= ParseFieldValue (FieldList
)
2115 if isinstance(Value
, str):
2116 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2119 # Use memcpy() to copy value into field
2121 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2122 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2124 for FieldName
in FieldList
:
2125 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2128 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2129 except BadExpression
:
2130 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2131 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2135 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2137 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]))
2138 if isinstance(Value
, str):
2139 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2142 # Use memcpy() to copy value into field
2144 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2145 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2146 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
.DatumType
, FieldName
, ValueSize
, Pcd
.DatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2147 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2149 if '[' in FieldName
and ']' in FieldName
:
2150 Index
= int(FieldName
.split('[')[1].split(']')[0])
2151 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
)
2153 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2155 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2160 def GenerateCommandLineValueStatement(Pcd
):
2161 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2163 def GenerateFdfValue(self
,Pcd
):
2164 CApp
= "// Value in Fdf\n"
2165 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2166 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2167 CApp
= CApp
+ ' CHAR8 *Value;\n'
2169 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2170 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2173 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2174 IsArray
= IsFieldValueAnArray(FieldList
)
2177 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2178 except BadExpression
:
2179 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2180 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2181 Value
, ValueSize
= ParseFieldValue (FieldList
)
2183 if isinstance(Value
, str):
2184 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2187 # Use memcpy() to copy value into field
2189 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2190 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2192 for FieldName
in FieldList
:
2193 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2196 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2197 except BadExpression
:
2198 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2199 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2203 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2205 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]))
2206 if isinstance(Value
, str):
2207 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2210 # Use memcpy() to copy value into field
2212 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2213 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2214 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
.DatumType
, FieldName
, ValueSize
, Pcd
.DatumType
, FieldName
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2215 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2217 if '[' in FieldName
and ']' in FieldName
:
2218 Index
= int(FieldName
.split('[')[1].split(']')[0])
2219 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
)
2221 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2223 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2228 def GenerateFdfValueStatement(Pcd
):
2229 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2232 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2233 OverrideValues
= {DefaultStore
:{}}
2234 if Pcd
.SkuOverrideValues
:
2235 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2236 if not OverrideValues
:
2237 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2238 for DefaultStoreName
in OverrideValues
:
2239 CApp
= CApp
+ 'void\n'
2240 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2241 CApp
= CApp
+ ' void\n'
2242 CApp
= CApp
+ ' )\n'
2244 CApp
= CApp
+ ' UINT32 Size;\n'
2245 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2246 CApp
= CApp
+ ' CHAR8 *Value;\n'
2247 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2248 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2250 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2254 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2256 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2259 # Get current PCD value and size
2261 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2264 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2265 # the correct value. For structures with a flexible array member, the flexible
2266 # array member is detected, and the size is based on the highest index used with
2267 # the flexible array member. The flexible array member must be the last field
2268 # in a structure. The size formula for this case is:
2269 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2271 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
)
2274 # Allocate and zero buffer for the PCD
2275 # Must handle cases where current value is smaller, larger, or same size
2276 # Always keep that larger one as the current size
2278 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2279 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2280 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2283 # Copy current PCD value into allocated buffer.
2285 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2288 # Assign field values in PCD
2290 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2291 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2292 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2293 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2294 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2295 for defaultstorenameitem
in storeset
:
2296 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2297 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2298 if skuname
== SkuName
:
2301 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2302 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2303 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2304 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2306 # Set new PCD value and size
2308 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2313 CApp
= CApp
+ ' free (Pcd);\n'
2316 return InitByteValue
, CApp
2318 def GenerateArrayAssignment(self
, Pcd
):
2322 if not Pcd
.IsArray():
2325 for d
in Pcd
.Capacity
:
2328 Value
= Pcd
.DefaultValueFromDec
2329 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2330 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2332 realvalue
= Pcd
.DefaultValueFromDec
.strip()
2333 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2335 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2336 for skuname
in Pcd
.SkuInfoList
:
2337 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2338 if skuinfo
.VariableName
:
2339 for defaultstore
in skuinfo
.DefaultStoreDict
:
2340 Value
= skuinfo
[defaultstore
]
2341 if "{CODE(" in Value
:
2342 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2344 realvalue
= Value
.strip()
2345 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2347 Value
= skuinfo
.DefaultValue
2348 if "{CODE(" in Value
:
2349 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2351 realvalue
= Value
.strip()
2352 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2354 if "{CODE(" in Pcd
.DefaultValue
:
2355 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2357 realvalue
= Pcd
.DefaultValue
.strip()
2358 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2360 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2361 if not OverrideValues
:
2363 for key
in OverrideValues
:
2364 if OverrideValues
[key
]:
2368 def ParseCCFlags(self
, ccflag
):
2370 ccflaglist
= ccflag
.split(" ")
2372 while i
< len(ccflaglist
):
2373 item
= ccflaglist
[i
].strip()
2374 if item
in (r
"/D", r
"/U","-D","-U"):
2375 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2377 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2381 def GenerateByteArrayValue (self
, StructuredPcds
):
2383 # Generate/Compile/Run C application to determine if there are any flexible array members
2385 if not StructuredPcds
:
2389 CApp
= PcdMainCHeader
2391 IncludeFiles
= set()
2392 for PcdName
in StructuredPcds
:
2393 Pcd
= StructuredPcds
[PcdName
]
2394 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2395 if IncludeFile
not in IncludeFiles
:
2396 IncludeFiles
.add(IncludeFile
)
2397 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2399 for Pcd
in StructuredPcds
.values():
2400 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2401 for PcdName
in StructuredPcds
:
2402 Pcd
= StructuredPcds
[PcdName
]
2403 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2404 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2405 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2406 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2407 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2408 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2409 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2411 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2412 if SkuName
not in Pcd
.SkuOverrideValues
:
2414 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2415 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2416 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2417 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2418 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2420 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2421 if SkuName
not in Pcd
.SkuOverrideValues
:
2423 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2424 Pcd
= StructuredPcds
[PcdName
]
2425 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2427 CApp
= CApp
+ 'VOID\n'
2428 CApp
= CApp
+ 'PcdEntryPoint(\n'
2429 CApp
= CApp
+ ' VOID\n'
2430 CApp
= CApp
+ ' )\n'
2432 for Pcd
in StructuredPcds
.values():
2433 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
]]:
2434 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2436 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2437 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2439 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2440 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2443 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2445 if not os
.path
.exists(self
.OutputPath
):
2446 os
.makedirs(self
.OutputPath
)
2447 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2448 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2450 MakeApp
= PcdMakefileHeader
2451 if sys
.platform
== "win32":
2452 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2454 MakeApp
= MakeApp
+ PcdGccMakefile
2455 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2456 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2459 PlatformInc
= OrderedDict()
2460 for Cache
in self
._Bdb
._CACHE
_.values():
2461 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2464 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2465 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2466 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2467 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2470 for Pcd
in StructuredPcds
.values():
2471 for PackageDec
in Pcd
.PackageDecs
:
2472 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2473 if not os
.path
.exists(Package
):
2474 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2475 if Package
not in PcdDependDEC
:
2476 PcdDependDEC
.append(Package
)
2478 if PlatformInc
and PcdDependDEC
:
2479 for pkg
in PcdDependDEC
:
2480 if pkg
in PlatformInc
:
2481 for inc
in PlatformInc
[pkg
]:
2482 MakeApp
+= '-I' + str(inc
) + ' '
2483 IncSearchList
.append(inc
)
2484 MakeApp
= MakeApp
+ '\n'
2486 CC_FLAGS
= LinuxCFLAGS
2487 if sys
.platform
== "win32":
2488 CC_FLAGS
= WindowsCFLAGS
2489 BuildOptions
= OrderedDict()
2490 for Options
in self
.BuildOptions
:
2491 if Options
[2] != EDKII_NAME
:
2494 if Family
and Family
!= self
.ToolChainFamily
:
2496 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2501 if Target
== TAB_STAR
or Target
== self
._Target
:
2502 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2503 if 'COMMON' not in BuildOptions
:
2504 BuildOptions
['COMMON'] = set()
2505 if Arch
== TAB_STAR
:
2506 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2507 if Arch
in self
.SupArchList
:
2508 if Arch
not in BuildOptions
:
2509 BuildOptions
[Arch
] = set()
2510 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2513 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2514 if len(ArchBuildOptions
.keys()) == 1:
2515 BuildOptions
['COMMON'] |
= (ArchBuildOptions
.values()[0])
2516 elif len(ArchBuildOptions
.keys()) > 1:
2517 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2518 BuildOptions
['COMMON'] |
= CommonBuildOptions
2519 ValueList
= list(BuildOptions
['COMMON'])
2520 CC_FLAGS
+= " ".join(ValueList
)
2523 if sys
.platform
== "win32":
2524 MakeApp
= MakeApp
+ PcdMakefileEnd
2525 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2527 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2528 MakeApp
= MakeApp
+ '\n'
2529 IncludeFileFullPaths
= []
2530 for includefile
in IncludeFiles
:
2531 for includepath
in IncSearchList
:
2532 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2533 if os
.path
.exists(includefullpath
):
2534 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2537 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2538 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2539 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2540 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2541 for include_file
in IncFileList
:
2542 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2543 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2544 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2545 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2547 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2548 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2549 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2551 Dest_PcdValueInitExe
= PcdValueInitName
2552 if not sys
.platform
== "win32":
2553 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2555 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2557 if sys
.platform
== "win32":
2558 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2559 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2562 MakeCommand
= 'make -f %s' % (MakeFileName
)
2563 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2566 Messages
= Messages
.split('\n')
2569 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2570 File
= open (CAppBaseFileName
+ '.c', 'r')
2571 FileData
= File
.readlines()
2573 for Message
in Messages
:
2574 if " error" in Message
or "warning" in Message
:
2575 FileInfo
= Message
.strip().split('(')
2576 if len (FileInfo
) > 1:
2577 FileName
= FileInfo
[0]
2578 FileLine
= FileInfo
[1].split (')')[0]
2580 FileInfo
= Message
.strip().split(':')
2581 if len(FileInfo
) < 2:
2583 FileName
= FileInfo
[0]
2584 FileLine
= FileInfo
[1]
2585 if FileLine
.isdigit():
2586 error_line
= FileData
[int (FileLine
) - 1]
2587 if r
"//" in error_line
:
2588 c_line
, dsc_line
= error_line
.split(r
"//")
2590 dsc_line
= error_line
2591 message_itmes
= Message
.split(":")
2593 if "PcdValueInit.c" not in Message
:
2594 if not MessageGroup
:
2595 MessageGroup
.append(Message
)
2598 for item
in message_itmes
:
2599 if "PcdValueInit.c" in item
:
2600 Index
= message_itmes
.index(item
)
2601 message_itmes
[Index
] = dsc_line
.strip()
2603 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2606 MessageGroup
.append(Message
)
2608 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2610 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2612 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
2613 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2614 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2616 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2618 File
= open (OutputValueFile
, 'r')
2619 FileBuffer
= File
.readlines()
2622 StructurePcdSet
= []
2623 for Pcd
in FileBuffer
:
2624 PcdValue
= Pcd
.split ('|')
2625 PcdInfo
= PcdValue
[0].split ('.')
2626 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2627 return StructurePcdSet
2630 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2631 if not os
.path
.exists(OutputFile
):
2633 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2635 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2639 ## Retrieve dynamic PCD settings
2641 # @param Type PCD type
2643 # @retval a dict object contains settings of given PCD type
2645 def _GetDynamicPcd(self
, Type
):
2648 Pcds
= OrderedDict()
2650 # tdict is a special dict kind of type, used for selecting correct
2651 # PCD settings for certain ARCH and SKU
2653 PcdDict
= tdict(True, 4)
2655 # Find out all possible PCD candidates for self._Arch
2656 RecordList
= self
._RawData
[Type
, self
._Arch
]
2657 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2660 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2661 SkuName
= SkuName
.upper()
2662 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2663 if SkuName
not in AvailableSkuIdSet
:
2664 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2665 File
=self
.MetaFile
, Line
=Dummy5
)
2666 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2667 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2668 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2670 # Remove redundant PCD candidates, per the ARCH and SKU
2671 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2673 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2677 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2679 if int(MaxDatumSize
, 0) > 0xFFFF:
2680 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2681 File
=self
.MetaFile
, Line
=Dummy4
)
2682 if int(MaxDatumSize
, 0) < 0:
2683 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2684 File
=self
.MetaFile
, Line
=Dummy4
)
2685 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2686 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2687 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2688 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2689 if MaxDatumSize
.strip():
2690 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2693 if pcdObject
.MaxDatumSize
:
2694 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2697 if CurrentMaxSize
> PcdMaxSize
:
2698 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2700 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2703 self
._PCD
_TYPE
_STRING
_[Type
],
2708 OrderedDict({SkuName
: SkuInfo
}),
2713 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2714 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2715 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2717 for pcd
in Pcds
.values():
2718 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2719 # Only fix the value while no value provided in DSC file.
2720 for sku
in pcd
.SkuInfoList
.values():
2721 if not sku
.DefaultValue
:
2722 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2723 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2724 valuefromDec
= pcdDecObject
.DefaultValue
2725 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2726 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2727 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2728 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2729 del pcd
.SkuInfoList
[TAB_COMMON
]
2730 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2731 del pcd
.SkuInfoList
[TAB_COMMON
]
2733 map(self
.FilterSkuSettings
, Pcds
.values())
2737 def FilterSkuSettings(self
, PcdObj
):
2739 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2740 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2741 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2742 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2743 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2744 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2746 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2747 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2752 def CompareVarAttr(Attr1
, Attr2
):
2753 if not Attr1
or not Attr2
: # for empty string
2755 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2756 Attr1Set
= set(Attr1s
)
2757 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2758 Attr2Set
= set(Attr2s
)
2759 if Attr2Set
== Attr1Set
:
2764 def CompletePcdValues(self
, PcdSet
):
2765 Pcds
= OrderedDict()
2766 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2767 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2768 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2769 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2770 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2772 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2773 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2774 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2775 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2776 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2777 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2778 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2780 PcdType
= PcdObj
.Type
2781 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2782 for skuid
in PcdObj
.SkuInfoList
:
2783 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2784 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2785 for defaultstorename
in DefaultStores
:
2786 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2787 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
2788 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2789 for skuname
, skuid
in SkuIds
.items():
2790 if skuname
not in PcdObj
.SkuInfoList
:
2791 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2792 while nextskuid
not in PcdObj
.SkuInfoList
:
2793 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2794 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2795 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2796 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2797 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2798 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2799 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2801 ## Retrieve dynamic HII PCD settings
2803 # @param Type PCD type
2805 # @retval a dict object contains settings of given PCD type
2807 def _GetDynamicHiiPcd(self
, Type
):
2811 Pcds
= OrderedDict()
2812 UserDefinedDefaultStores
= []
2814 # tdict is a special dict kind of type, used for selecting correct
2815 # PCD settings for certain ARCH and SKU
2817 PcdDict
= tdict(True, 5)
2819 RecordList
= self
._RawData
[Type
, self
._Arch
]
2820 # Find out all possible PCD candidates for self._Arch
2821 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2822 DefaultStoresDefine
= self
._GetDefaultStores
()
2824 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
2825 SkuName
= SkuName
.upper()
2826 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2827 DefaultStore
= DefaultStore
.upper()
2828 if DefaultStore
== TAB_COMMON
:
2829 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2831 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
2832 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
2833 if SkuName
not in AvailableSkuIdSet
:
2834 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2835 File
=self
.MetaFile
, Line
=Dummy5
)
2836 if DefaultStore
not in DefaultStoresDefine
:
2837 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2838 File
=self
.MetaFile
, Line
=Dummy5
)
2839 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2840 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
2841 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
2844 # Remove redundant PCD candidates, per the ARCH and SKU
2845 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdSet
:
2847 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
2850 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2852 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2854 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2855 ExtraData
="[%s]" % VarAttribute
)
2857 FormatCorrect
= True
2858 if VariableOffset
.isdigit():
2859 if int(VariableOffset
, 10) > 0xFFFF:
2861 elif variablePattern
.match(VariableOffset
):
2862 if int(VariableOffset
, 16) > 0xFFFF:
2864 # For Offset written in "A.B"
2865 elif VariableOffset
.find('.') > -1:
2866 VariableOffsetList
= VariableOffset
.split(".")
2867 if not (len(VariableOffsetList
) == 2
2868 and IsValidWord(VariableOffsetList
[0])
2869 and IsValidWord(VariableOffsetList
[1])):
2870 FormatCorrect
= False
2872 FormatCorrect
= False
2873 if not FormatCorrect
:
2874 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2877 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2878 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2879 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2881 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2882 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
)]))
2884 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2885 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2886 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2887 if SkuName
in pcdObject
.SkuInfoList
:
2888 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2889 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2891 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2892 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2894 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2895 PcdClassObj
= PcdClassObject(
2898 self
._PCD
_TYPE
_STRING
_[Type
],
2903 OrderedDict({SkuName
: SkuInfo
}),
2906 pcdDecObject
.validateranges
,
2907 pcdDecObject
.validlists
,
2908 pcdDecObject
.expressions
,
2910 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
2911 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
2912 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
2914 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
2915 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2916 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2917 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
2918 for pcd
in Pcds
.values():
2919 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2920 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2921 pcd
.DatumType
= pcdDecObject
.DatumType
2922 # Only fix the value while no value provided in DSC file.
2923 for sku
in pcd
.SkuInfoList
.values():
2924 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2925 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2926 for default_store
in sku
.DefaultStoreDict
:
2927 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2928 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2929 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2930 valuefromDec
= pcdDecObject
.DefaultValue
2931 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
2932 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2933 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2934 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2935 del pcd
.SkuInfoList
[TAB_COMMON
]
2936 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2937 del pcd
.SkuInfoList
[TAB_COMMON
]
2939 if pcd
.MaxDatumSize
.strip():
2940 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2943 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
2944 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2946 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2947 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2948 if datalen
> MaxSize
:
2950 for defaultst
in skuobj
.DefaultStoreDict
:
2951 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2952 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
2953 pcd
.MaxDatumSize
= str(MaxSize
)
2954 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
2956 invalidpcd
= ",".join(invalidhii
)
2957 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
)
2959 map(self
.FilterSkuSettings
, Pcds
.values())
2964 def CheckVariableNameAssignment(Pcds
):
2966 for pcdname
in Pcds
:
2968 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
2969 if len(varnameset
) > 1:
2970 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
2972 return False, invalidhii
2975 ## Retrieve dynamic VPD PCD settings
2977 # @param Type PCD type
2979 # @retval a dict object contains settings of given PCD type
2981 def _GetDynamicVpdPcd(self
, Type
):
2984 Pcds
= OrderedDict()
2986 # tdict is a special dict kind of type, used for selecting correct
2987 # PCD settings for certain ARCH and SKU
2989 PcdDict
= tdict(True, 4)
2992 # Find out all possible PCD candidates for self._Arch
2993 RecordList
= self
._RawData
[Type
, self
._Arch
]
2994 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2996 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2997 SkuName
= SkuName
.upper()
2998 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2999 if SkuName
not in AvailableSkuIdSet
:
3000 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3001 File
=self
.MetaFile
, Line
=Dummy5
)
3002 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
3003 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3004 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3006 # Remove redundant PCD candidates, per the ARCH and SKU
3007 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3008 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3012 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3013 # For the Integer & Boolean type, the optional data can only be InitialValue.
3014 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3015 # until the DEC parser has been called.
3017 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3019 if int(MaxDatumSize
, 0) > 0xFFFF:
3020 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3021 File
=self
.MetaFile
, Line
=Dummy4
)
3022 if int(MaxDatumSize
, 0) < 0:
3023 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3024 File
=self
.MetaFile
, Line
=Dummy4
)
3025 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3026 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3027 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3028 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3029 if MaxDatumSize
.strip():
3030 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3033 if pcdObject
.MaxDatumSize
:
3034 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3037 if CurrentMaxSize
> PcdMaxSize
:
3038 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3040 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3043 self
._PCD
_TYPE
_STRING
_[Type
],
3048 OrderedDict({SkuName
: SkuInfo
}),
3053 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3054 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3055 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3056 for pcd
in Pcds
.values():
3057 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
3058 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3059 pcd
.DatumType
= pcdDecObject
.DatumType
3060 # Only fix the value while no value provided in DSC file.
3061 for sku
in pcd
.SkuInfoList
.values():
3062 if not sku
.DefaultValue
:
3063 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3064 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3065 valuefromDec
= pcdDecObject
.DefaultValue
3066 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3067 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3068 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3069 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3070 del pcd
.SkuInfoList
[TAB_COMMON
]
3071 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3072 del pcd
.SkuInfoList
[TAB_COMMON
]
3074 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3075 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3076 for pcd
in Pcds
.values():
3077 PcdValueTypeSet
= set()
3078 for sku
in pcd
.SkuInfoList
.values():
3079 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3080 if len(PcdValueTypeSet
) > 1:
3081 for sku
in pcd
.SkuInfoList
.values():
3082 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3084 map(self
.FilterSkuSettings
, Pcds
.values())
3087 ## Add external modules
3089 # The external modules are mostly those listed in FDF file, which don't
3092 # @param FilePath The path of module description file
3094 def AddModule(self
, FilePath
):
3095 FilePath
= NormPath(FilePath
)
3096 if FilePath
not in self
.Modules
:
3097 Module
= ModuleBuildClassObject()
3098 Module
.MetaFile
= FilePath
3099 self
.Modules
.append(Module
)
3102 def ToolChainFamily(self
):
3103 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3104 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
3105 if os
.path
.isfile(BuildConfigurationFile
) == True:
3106 TargetTxt
= TargetTxtClassObject()
3107 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
3108 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3109 if ToolDefinitionFile
== '':
3110 ToolDefinitionFile
= "tools_def.txt"
3111 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
3112 if os
.path
.isfile(ToolDefinitionFile
) == True:
3113 ToolDef
= ToolDefClassObject()
3114 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
3115 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
3116 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3117 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3118 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3119 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3121 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3122 return self
._ToolChainFamily
3124 ## Add external PCDs
3126 # The external PCDs are mostly those listed in FDF file to specify address
3127 # or offset information.
3129 # @param Name Name of the PCD
3130 # @param Guid Token space guid of the PCD
3131 # @param Value Value of the PCD
3133 def AddPcd(self
, Name
, Guid
, Value
):
3134 if (Name
, Guid
) not in self
.Pcds
:
3135 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3136 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3140 if self
._DecPcds
is None:
3142 if GlobalData
.gFdfParser
:
3143 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3145 for Inf
in FdfInfList
:
3146 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3147 if ModuleFile
in self
._Modules
:
3149 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3150 PkgSet
.update(ModuleData
.Packages
)
3151 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3152 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3153 return self
._DecPcds