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
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
46 PcdValueInitName
= 'PcdValueInit'
57 #include <PcdValueCommon.h>
67 return PcdValueMain (argc, argv);
71 PcdMakefileHeader
= '''
74 # This file is auto-generated by build utility
79 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
80 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
82 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
84 LIBS = $(LIB_PATH)\Common.lib
86 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
91 $(APPFILE): $(OBJECTS)
96 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
100 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
101 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
102 ## regular expressions for finding decimal and hex numbers
103 Pattern
= re
.compile('^[1-9]\d*|0$')
104 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
105 ## Regular expression for finding header file inclusions
106 from AutoGen
.GenMake
import gIncludePattern
108 ## Find dependencies for one source file
110 # By searching recursively "#include" directive in file, find out all the
111 # files needed by given source file. The dependecies will be only searched
112 # in given search path list.
114 # @param SearchPathList The list of search path
116 # @retval list The list of files the given source file depends on
118 def GetDependencyList(FileStack
, SearchPathList
):
120 DependencySet
= set(FileStack
)
121 while len(FileStack
) > 0:
123 FullPathDependList
= []
124 CurrentFileDependencyList
= []
126 CurrentFileDependencyList
= DepDb
[F
]
130 FileContent
= Fd
.read()
131 except BaseException
as X
:
132 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
134 if "Fd" in dir(locals()):
137 if len(FileContent
) == 0:
140 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
141 FileContent
= unicode(FileContent
, "utf-16")
142 IncludedFileList
= gIncludePattern
.findall(FileContent
)
144 for Inc
in IncludedFileList
:
146 Inc
= os
.path
.normpath(Inc
)
147 CurrentFileDependencyList
.append(Inc
)
148 DepDb
[F
] = CurrentFileDependencyList
150 CurrentFilePath
= os
.path
.dirname(F
)
151 PathList
= [CurrentFilePath
] + SearchPathList
152 for Inc
in CurrentFileDependencyList
:
153 for SearchPath
in PathList
:
154 FilePath
= os
.path
.join(SearchPath
, Inc
)
155 if not os
.path
.exists(FilePath
):
157 if FilePath
not in DependencySet
:
158 FileStack
.append(FilePath
)
159 FullPathDependList
.append(FilePath
)
161 DependencySet
.update(FullPathDependList
)
162 DependencyList
= list(DependencySet
) # remove duplicate ones
164 return DependencyList
166 class DscBuildData(PlatformBuildClassObject
):
167 # dict used to convert PCD type in database to string used by build tool
168 _PCD_TYPE_STRING_
= {
169 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
170 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
171 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
172 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
173 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
174 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
175 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
176 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
177 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
178 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
179 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
182 # dict used to convert part of [Defines] to members of DscBuildData directly
187 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
188 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
189 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
190 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
191 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
192 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
193 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
194 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
195 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
196 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
197 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
198 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
199 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
200 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
201 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
204 # used to compose dummy library class name for those forced library instances
205 _NullLibraryNumber
= 0
207 ## Constructor of DscBuildData
209 # Initialize object of DscBuildData
211 # @param FilePath The path of platform description file
212 # @param RawData The raw data of DSC file
213 # @param BuildDataBase Database used to retrieve module/package information
214 # @param Arch The target architecture
215 # @param Platform (not used for DscBuildData)
216 # @param Macros Macros used for replacement in DSC file
218 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
219 self
.MetaFile
= FilePath
220 self
._RawData
= RawData
221 self
._Bdb
= BuildDataBase
223 self
._Target
= Target
224 self
._Toolchain
= Toolchain
225 self
._ToolChainFamily
= None
227 self
._HandleOverridePath
()
228 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
229 self
.DefaultStores
= None
230 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
233 def OutputPath(self
):
234 if os
.getenv("WORKSPACE"):
235 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
237 return os
.path
.dirname(self
.DscFile
)
240 def __setitem__(self
, key
, value
):
241 self
.__dict
__[self
._PROPERTY
_[key
]] = value
244 def __getitem__(self
, key
):
245 return self
.__dict
__[self
._PROPERTY
_[key
]]
248 def __contains__(self
, key
):
249 return key
in self
._PROPERTY
_
251 ## Set all internal used members of DscBuildData to None
254 self
._PlatformName
= None
257 self
._DscSpecification
= None
258 self
._OutputDirectory
= None
259 self
._SupArchList
= None
260 self
._BuildTargets
= None
262 self
._PcdInfoFlag
= None
263 self
._VarCheckFlag
= None
264 self
._FlashDefinition
= None
265 self
._Prebuild
= None
266 self
._Postbuild
= None
267 self
._BuildNumber
= None
268 self
._MakefileName
= None
269 self
._BsBaseAddress
= None
270 self
._RtBaseAddress
= None
273 self
._LibraryInstances
= None
274 self
._LibraryClasses
= None
277 self
._BuildOptions
= None
278 self
._ModuleTypeOptions
= None
279 self
._LoadFixAddress
= None
280 self
._RFCLanguages
= None
281 self
._ISOLanguages
= None
282 self
._VpdToolGuid
= None
283 self
._MacroDict
= None
284 self
.DefaultStores
= None
285 self
.UsedStructurePcd
= 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
917 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
918 except BadExpression
as Value
:
919 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
920 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
921 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
922 except EvaluationException
as Excpt
:
923 if hasattr(Excpt
, 'Pcd'):
924 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
925 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
926 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
927 " of the DSC file" % Excpt
.Pcd
,
928 File
=self
.MetaFile
, Line
=LineNo
)
930 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
931 File
=self
.MetaFile
, Line
=LineNo
)
933 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
934 File
=self
.MetaFile
, Line
=LineNo
)
937 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
939 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
940 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
941 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
942 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
943 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
,
944 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
945 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
946 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
947 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
950 def _FilterPcdBySkuUsage(self
, Pcds
):
951 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
952 sku_usage
= self
.SkuIdMgr
.SkuUsageType
953 if sku_usage
== SkuClass
.SINGLE
:
956 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
957 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
958 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
962 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
963 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
964 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
967 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
968 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
]]]
969 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
971 for skuid
in pcd
.SkuInfoList
:
972 skuobj
= pcd
.SkuInfoList
.get(skuid
)
973 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
974 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
975 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
976 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
979 def RecoverCommandLinePcd(self
):
980 def UpdateCommandLineValue(pcd
):
981 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
982 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
983 pcd
.PcdValueFromComm
= pcd
.DefaultValue
984 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
985 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
987 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
988 for pcd
in self
._Pcds
:
989 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
990 UpdateCommandLineValue(self
._Pcds
[pcd
])
992 def __ParsePcdFromCommandLine(self
):
993 if GlobalData
.BuildOptionPcd
:
994 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
995 if isinstance(pcd
, tuple):
997 (pcdname
, pcdvalue
) = pcd
.split('=')
999 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1001 (Name1
, Name2
) = pcdname
.split('.', 1)
1003 (Name3
, FieldName
) = Name2
.split(".", 1)
1004 if ((Name3
, Name1
)) in self
.DecPcds
:
1005 HasTokenSpace
= True
1007 TokenSpaceGuidCName
= Name1
1011 TokenSpaceGuidCName
= ''
1012 HasTokenSpace
= False
1014 if ((Name2
, Name1
)) in self
.DecPcds
:
1015 HasTokenSpace
= True
1017 TokenSpaceGuidCName
= Name1
1022 TokenSpaceGuidCName
= ''
1023 HasTokenSpace
= False
1026 TokenCName
= pcdname
1027 TokenSpaceGuidCName
= ''
1028 HasTokenSpace
= False
1029 TokenSpaceGuidCNameList
= []
1032 DisplayName
= TokenCName
1034 DisplayName
= TokenCName
+ '.' + FieldName
1035 if not HasTokenSpace
:
1036 for key
in self
.DecPcds
:
1037 PcdItem
= self
.DecPcds
[key
]
1038 if TokenCName
== PcdItem
.TokenCName
:
1039 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1040 if len (TokenSpaceGuidCNameList
) < 1:
1041 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1042 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1043 PcdDatumType
= PcdItem
.DatumType
1049 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1052 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1053 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1057 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1059 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1060 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1062 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1064 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1065 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1067 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1068 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1070 if GlobalData
.BuildOptionPcd
:
1071 for pcd
in GlobalData
.BuildOptionPcd
:
1072 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1073 for BuildData
in self
._Bdb
._CACHE
_.values():
1074 if BuildData
.Arch
!= self
.Arch
:
1076 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1078 for key
in BuildData
.Pcds
:
1079 PcdItem
= BuildData
.Pcds
[key
]
1080 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1081 PcdItem
.DefaultValue
= pcdvalue
1082 PcdItem
.PcdValueFromComm
= pcdvalue
1083 #In command line, the latter full assign value in commandLine should override the former field assign value.
1084 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1087 if GlobalData
.BuildOptionPcd
:
1088 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1089 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1091 if (TokenSpaceGuid
, Token
) not in field_assign
:
1092 field_assign
[TokenSpaceGuid
, Token
] = []
1093 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1095 if (TokenSpaceGuid
, Token
) in field_assign
:
1096 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1097 field_assign
[TokenSpaceGuid
, Token
] = []
1098 for item
in delete_assign
:
1099 GlobalData
.BuildOptionPcd
.remove(item
)
1102 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1105 TokenCName
+= '.' + FieldName
1106 if PcdValue
.startswith('H'):
1107 if FieldName
and IsFieldValueAnArray(PcdValue
[1:]):
1108 PcdDatumType
= TAB_VOID
1110 if FieldName
and not IsArray
:
1113 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1114 except BadExpression
as Value
:
1115 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1116 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1117 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1118 if FieldName
and IsFieldValueAnArray(PcdValue
):
1119 PcdDatumType
= TAB_VOID
1121 if FieldName
and not IsArray
:
1124 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1125 except BadExpression
as Value
:
1126 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1127 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1128 elif PcdValue
.startswith('L'):
1129 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1130 if FieldName
and IsFieldValueAnArray(PcdValue
):
1131 PcdDatumType
= TAB_VOID
1133 if FieldName
and not IsArray
:
1136 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1137 except BadExpression
as Value
:
1138 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1139 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1141 if PcdValue
.upper() == 'FALSE':
1143 if PcdValue
.upper() == 'TRUE':
1146 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1147 PcdValue
= '"' + PcdValue
+ '"'
1148 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1149 PcdValue
= '"' + PcdValue
+ '"'
1153 if PcdValue
.upper().startswith('0X'):
1156 Num
= int(PcdValue
, Base
)
1158 PcdValue
= '"' + PcdValue
+ '"'
1159 if IsFieldValueAnArray(PcdValue
):
1160 PcdDatumType
= TAB_VOID
1165 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1166 except BadExpression
as Value
:
1167 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1168 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1171 ## Retrieve all PCD settings in platform
1174 if self
._Pcds
is None:
1175 self
._Pcds
= OrderedDict()
1176 self
.__ParsePcdFromCommandLine
()
1177 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1178 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1179 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1180 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1181 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1182 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1183 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1184 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1185 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1187 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1188 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1189 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1190 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1191 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1192 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1194 self
.RecoverCommandLinePcd()
1197 ## Retrieve [BuildOptions]
1199 def BuildOptions(self
):
1200 if self
._BuildOptions
is None:
1201 self
._BuildOptions
= OrderedDict()
1203 # Retrieve build option for EDKII and EDK style module
1205 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1206 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1207 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1208 if Dummy3
.upper() != TAB_COMMON
:
1210 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1212 # Only flags can be appended
1214 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1215 self
._BuildOptions
[CurKey
] = Option
1217 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1218 self
._BuildOptions
[CurKey
] += ' ' + Option
1219 return self
._BuildOptions
1221 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1222 if self
._ModuleTypeOptions
is None:
1223 self
._ModuleTypeOptions
= OrderedDict()
1224 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1225 options
= OrderedDict()
1226 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1227 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1228 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1229 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1230 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1231 Type
= Dummy2
+ '.' + Dummy3
1232 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1233 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1234 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1235 options
[Key
] = Option
1237 if ' ' + Option
not in options
[Key
]:
1238 options
[Key
] += ' ' + Option
1239 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1242 def GetStructurePcdInfo(PcdSet
):
1243 structure_pcd_data
= defaultdict(list)
1245 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1247 return structure_pcd_data
1250 def OverrideByFdf(StruPcds
,workspace
):
1251 if GlobalData
.gFdfParser
is None:
1253 StructurePcdInFdf
= OrderedDict()
1254 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1255 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1256 for item
in fdfpcd
:
1257 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1258 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1259 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1260 for Pcd
in StruPcds
.values():
1261 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1263 FieldValues
= OrderedDict()
1264 for item
in StructurePcdInFdf
:
1265 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1266 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1267 for field
in FieldValues
:
1268 if field
not in Pcd
.PcdFieldValueFromFdf
:
1269 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1270 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1271 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1272 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1277 def OverrideByComm(StruPcds
):
1278 StructurePcdInCom
= OrderedDict()
1279 for item
in GlobalData
.BuildOptionPcd
:
1280 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1281 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1282 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1283 for Pcd
in StruPcds
.values():
1284 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1286 FieldValues
= OrderedDict()
1287 for item
in StructurePcdInCom
:
1288 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1289 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1290 for field
in FieldValues
:
1291 if field
not in Pcd
.PcdFieldValueFromComm
:
1292 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1293 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1294 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1295 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1298 def OverrideByCommOverAll(self
,AllPcds
):
1299 def CheckStructureInComm(commpcds
):
1302 if len(commpcds
[0]) == 5:
1305 NoFiledValues
= OrderedDict()
1306 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1307 StructurePcdInCom
= OrderedDict()
1308 for item
in GlobalData
.BuildOptionPcd
:
1309 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1310 for item
in StructurePcdInCom
:
1312 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1314 for item
in GlobalData
.BuildOptionPcd
:
1315 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1316 for Guid
, Name
in NoFiledValues
:
1317 if (Name
, Guid
) in AllPcds
:
1318 Pcd
= AllPcds
.get((Name
, Guid
))
1319 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1320 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1322 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1323 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1324 for sku
in Pcd
.SkuInfoList
:
1325 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1326 if SkuInfo
.DefaultValue
:
1327 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1329 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1330 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1331 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1332 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1333 if Pcd
.DatumType
== TAB_VOID
:
1334 if not Pcd
.MaxDatumSize
:
1335 Pcd
.MaxDatumSize
= '0'
1336 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1337 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1338 MaxSize
= max(CurrentSize
, OptionSize
)
1339 Pcd
.MaxDatumSize
= str(MaxSize
)
1341 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1343 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1344 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1345 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1346 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1347 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1348 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1349 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1350 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1351 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1352 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1353 self
.Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1356 def OverrideByFdfOverAll(self
,AllPcds
):
1358 if GlobalData
.gFdfParser
is None:
1360 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1361 for Name
,Guid
,Field
in NoFiledValues
:
1364 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1365 if (Name
,Guid
) in AllPcds
:
1366 Pcd
= AllPcds
.get((Name
,Guid
))
1367 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1368 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1370 Pcd
.PcdValueFromComm
= Value
1371 Pcd
.DefaultValue
= Value
1372 for sku
in Pcd
.SkuInfoList
:
1373 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1374 if SkuInfo
.DefaultValue
:
1375 SkuInfo
.DefaultValue
= Value
1377 SkuInfo
.HiiDefaultValue
= Value
1378 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1379 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1380 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1381 if Pcd
.DatumType
== TAB_VOID
:
1382 if not Pcd
.MaxDatumSize
:
1383 Pcd
.MaxDatumSize
= '0'
1384 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1385 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1386 MaxSize
= max(CurrentSize
, OptionSize
)
1387 Pcd
.MaxDatumSize
= str(MaxSize
)
1389 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1391 PcdInDec
.PcdValueFromFdf
= Value
1392 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1393 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1394 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1395 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1396 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
1399 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1401 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1402 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1403 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1404 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1405 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1406 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1409 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1410 SkuIds
= self
.SkuIds
1411 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1412 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1413 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1416 # Find out all possible PCD candidates for self._Arch
1419 for Type
in TypeList
:
1420 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1422 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1423 SkuName
= SkuName
.upper()
1424 default_store
= default_store
.upper()
1425 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1426 if SkuName
not in SkuIds
:
1429 if SkuName
in SkuIds
and "." in TokenSpaceGuid
:
1430 S_PcdSet
.append([ TokenSpaceGuid
.split(".")[0], TokenSpaceGuid
.split(".")[1], PcdCName
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1432 # handle pcd value override
1433 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1434 S_pcd_set
= OrderedDict()
1435 for str_pcd
in StrPcdSet
:
1436 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1437 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1438 if not isinstance (str_pcd_dec
, StructurePcd
):
1439 EdkLogger
.error('build', PARSER_ERROR
,
1440 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1441 File
=self
.MetaFile
, Line
= StrPcdSet
[str_pcd
][0][5])
1443 str_pcd_obj_str
= StructurePcd()
1444 str_pcd_obj_str
.copy(str_pcd_dec
)
1446 str_pcd_obj_str
.copy(str_pcd_obj
)
1447 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1448 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
}
1450 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
}
1451 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1452 if str_pcd_data
[3] in SkuIds
:
1453 str_pcd_obj_str
.AddOverrideValue(str_pcd_data
[2], str(str_pcd_data
[6]), TAB_DEFAULT
if str_pcd_data
[3] == TAB_COMMON
else str_pcd_data
[3], TAB_DEFAULT_STORES_DEFAULT
if str_pcd_data
[4] == TAB_COMMON
else str_pcd_data
[4], 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
[5])
1454 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1456 EdkLogger
.error('build', PARSER_ERROR
,
1457 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1458 File
=self
.MetaFile
, Line
= StrPcdSet
[str_pcd
][0][5])
1459 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1460 for Pcd
in self
.DecPcds
:
1461 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1462 if Pcd
not in S_pcd_set
:
1463 str_pcd_obj_str
= StructurePcd()
1464 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1465 str_pcd_obj
= Pcds
.get(Pcd
, None)
1467 str_pcd_obj_str
.copy(str_pcd_obj
)
1468 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1469 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
}
1471 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
}
1472 S_pcd_set
[Pcd
] = str_pcd_obj_str
1473 self
.FilterStrcturePcd(S_pcd_set
)
1475 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1476 for stru_pcd
in S_pcd_set
.values():
1477 for skuid
in SkuIds
:
1478 if skuid
in stru_pcd
.SkuOverrideValues
:
1480 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1482 if skuid
not in stru_pcd
.SkuOverrideValues
:
1483 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1484 if nextskuid
== TAB_DEFAULT
:
1487 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1488 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})
1490 stru_pcd
.ValueChain
.add((skuid
, ''))
1491 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1492 for skuid
in SkuIds
:
1495 if skuid
not in stru_pcd
.SkuOverrideValues
:
1496 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1497 if nextskuid
== TAB_DEFAULT
:
1500 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1503 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1504 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1506 for defaultstoreid
in DefaultStores
:
1507 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1508 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = copy
.deepcopy(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1509 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1510 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1511 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1512 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1514 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1515 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1516 if str_pcd_obj
is None:
1517 print(PcdName
, PcdGuid
)
1519 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1520 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1521 if skuname
not in str_pcd_obj
.SkuInfoList
:
1522 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1524 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1525 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1526 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1527 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1528 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1529 str_pcd_obj
.DefaultValue
= PcdValue
1531 if skuname
not in str_pcd_obj
.SkuInfoList
:
1532 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1534 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1535 if nextskuid
== TAB_DEFAULT
:
1538 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1539 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
)
1540 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1541 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1543 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1544 for str_pcd_obj
in S_pcd_set
.values():
1545 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1546 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1548 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1549 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1550 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1551 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1553 for str_pcd_obj
in S_pcd_set
.values():
1555 str_pcd_obj
.MaxDatumSize
= self
.GetStructurePcdMaxSize(str_pcd_obj
)
1556 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1557 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1561 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1562 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1563 del pcd
.SkuInfoList
[TAB_COMMON
]
1564 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1565 del pcd
.SkuInfoList
[TAB_COMMON
]
1567 map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1569 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1570 def FilterStrcturePcd(self
, S_pcd_set
):
1571 if not self
.UsedStructurePcd
:
1573 if GlobalData
.gFdfParser
:
1574 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1575 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1576 AllModulePcds
= set()
1577 ModuleSet
= set(self
._Modules
.keys() + self
.LibraryInstances
+ FdfModuleList
)
1578 for ModuleFile
in ModuleSet
:
1579 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1580 AllModulePcds
= AllModulePcds |
set(ModuleData
.Pcds
.keys())
1582 self
.UsedStructurePcd
= AllModulePcds
1583 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.UsedStructurePcd
1584 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1585 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1587 ## Retrieve non-dynamic PCD settings
1589 # @param Type PCD type
1591 # @retval a dict object contains settings of given PCD type
1593 def _GetPcd(self
, Type
):
1594 Pcds
= OrderedDict()
1596 # tdict is a special dict kind of type, used for selecting correct
1597 # PCD settings for certain ARCH
1599 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1601 PcdDict
= tdict(True, 4)
1603 # Find out all possible PCD candidates for self._Arch
1604 RecordList
= self
._RawData
[Type
, self
._Arch
]
1605 PcdValueDict
= OrderedDict()
1606 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1607 SkuName
= SkuName
.upper()
1608 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1609 if SkuName
not in AvailableSkuIdSet
:
1610 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1611 File
=self
.MetaFile
, Line
=Dummy5
)
1612 if "." not in TokenSpaceGuid
:
1613 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1614 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1616 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1617 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1620 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1622 if int(MaxDatumSize
, 0) > 0xFFFF:
1623 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1624 File
=self
.MetaFile
, Line
=Dummy4
)
1625 if int(MaxDatumSize
, 0) < 0:
1626 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1627 File
=self
.MetaFile
, Line
=Dummy4
)
1628 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1629 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1631 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1633 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.iteritems():
1634 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1635 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1636 elif TAB_DEFAULT
in PcdSetting
:
1637 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_DEFAULT
]
1638 elif TAB_COMMON
in PcdSetting
:
1639 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_COMMON
]
1645 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1648 self
._PCD
_TYPE
_STRING
_[Type
],
1657 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1658 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1659 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1660 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1661 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1664 def GetStructurePcdMaxSize(self
, str_pcd
):
1665 pcd_default_value
= str_pcd
.DefaultValue
1666 sku_values
= [skuobj
.HiiDefaultValue
if str_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]] else skuobj
.DefaultValue
for skuobj
in str_pcd
.SkuInfoList
.values()]
1667 sku_values
.append(pcd_default_value
)
1669 def get_length(value
):
1670 Value
= value
.strip()
1672 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1674 if Value
.startswith('L"') and Value
.endswith('"'):
1675 return len(Value
[2:-1])
1676 if Value
[0] == '"' and Value
[-1] == '"':
1677 return len(Value
) - 2
1678 if Value
[0] == '{' and Value
[-1] == '}':
1679 return len(Value
.split(","))
1680 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1681 return len(list(Value
[2:-1]))
1682 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1683 return len(Value
) - 2
1686 return str(max(get_length(item
) for item
in sku_values
))
1689 def ExecuteCommand (Command
):
1691 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1693 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1694 Result
= Process
.communicate()
1695 return Process
.returncode
, Result
[0], Result
[1]
1698 def IntToCString(Value
, ValueSize
):
1700 if not isinstance (Value
, str):
1701 for Index
in range(0, ValueSize
):
1702 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1704 Result
= Result
+ '"'
1707 def GenerateSizeFunction(self
, Pcd
):
1708 CApp
= "// Default Value in Dec \n"
1709 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1710 for FieldList
in [Pcd
.DefaultValues
]:
1713 for FieldName
in FieldList
:
1714 FieldName
= "." + FieldName
1715 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1716 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1718 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1719 except BadExpression
:
1720 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1721 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1722 Value
, ValueSize
= ParseFieldValue(Value
)
1723 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]);
1726 FieldName_ori
= FieldName
.strip('.')
1727 while '[' in FieldName
:
1728 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1729 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1730 FieldName
= FieldName
.split(']', 1)[1]
1731 FieldName
= NewFieldName
+ FieldName
1732 while '[' in FieldName
:
1733 FieldName
= FieldName
.rsplit('[', 1)[0]
1734 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])
1735 for skuname
in Pcd
.SkuOverrideValues
:
1736 if skuname
== TAB_COMMON
:
1738 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1739 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1740 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
].get(defaultstorenameitem
)]:
1743 for FieldName
in FieldList
:
1744 FieldName
= "." + FieldName
1745 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1746 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1748 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1749 except BadExpression
:
1750 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1751 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1752 Value
, ValueSize
= ParseFieldValue(Value
)
1753 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]);
1756 FieldName_ori
= FieldName
.strip('.')
1757 while '[' in FieldName
:
1758 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1759 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1760 FieldName
= FieldName
.split(']', 1)[1]
1761 FieldName
= NewFieldName
+ FieldName
1762 while '[' in FieldName
:
1763 FieldName
= FieldName
.rsplit('[', 1)[0]
1764 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])
1765 if Pcd
.PcdFieldValueFromFdf
:
1766 CApp
= CApp
+ "// From fdf \n"
1767 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1768 FieldName
= "." + FieldName
1769 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1770 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1772 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1773 except BadExpression
:
1774 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1775 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1776 Value
, ValueSize
= ParseFieldValue(Value
)
1777 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]);
1780 FieldName_ori
= FieldName
.strip('.')
1781 while '[' in FieldName
:
1782 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1783 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1784 FieldName
= FieldName
.split(']', 1)[1]
1785 FieldName
= NewFieldName
+ FieldName
1786 while '[' in FieldName
:
1787 FieldName
= FieldName
.rsplit('[', 1)[0]
1788 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])
1789 if Pcd
.PcdFieldValueFromComm
:
1790 CApp
= CApp
+ "// From Command Line \n"
1791 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1792 FieldName
= "." + FieldName
1793 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1794 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1796 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1797 except BadExpression
:
1798 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1799 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1800 Value
, ValueSize
= ParseFieldValue(Value
)
1801 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]);
1804 FieldName_ori
= FieldName
.strip('.')
1805 while '[' in FieldName
:
1806 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1807 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1808 FieldName
= FieldName
.split(']', 1)[1]
1809 FieldName
= NewFieldName
+ FieldName
1810 while '[' in FieldName
:
1811 FieldName
= FieldName
.rsplit('[', 1)[0]
1812 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])
1813 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1818 def GenerateSizeStatments(Pcd
):
1819 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1820 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1823 def GenerateDefaultValueAssignFunction(self
, Pcd
):
1824 CApp
= "// Default value in Dec \n"
1825 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
)
1826 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1827 CApp
= CApp
+ ' CHAR8 *Value;\n'
1828 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1829 IsArray
= IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1832 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1833 except BadExpression
:
1834 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1835 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1836 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1837 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1838 if isinstance(Value
, str):
1839 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1842 # Use memcpy() to copy value into field
1844 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1845 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1846 for FieldList
in [Pcd
.DefaultValues
]:
1849 for FieldName
in FieldList
:
1850 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1853 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1854 except BadExpression
:
1855 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1856 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1859 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1861 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]))
1862 if isinstance(Value
, str):
1863 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1866 # Use memcpy() to copy value into field
1868 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1869 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1870 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])
1871 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1873 if '[' in FieldName
and ']' in FieldName
:
1874 Index
= int(FieldName
.split('[')[1].split(']')[0])
1875 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
)
1877 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1879 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1884 def GenerateDefaultValueAssignStatement(Pcd
):
1885 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1888 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
1889 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
1890 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.DatumType
)
1891 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1892 CApp
= CApp
+ ' CHAR8 *Value;\n'
1894 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
1895 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1896 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1897 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
1898 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
1900 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
1902 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
1903 for FieldList
in [pcddefaultvalue
, inherit_OverrideValues
.get(DefaultStoreName
)]:
1906 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1907 IsArray
= IsFieldValueAnArray(FieldList
)
1910 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
1911 except BadExpression
:
1912 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
1913 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1914 Value
, ValueSize
= ParseFieldValue (FieldList
)
1916 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
1917 if isinstance(Value
, str):
1918 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
)
1921 # Use memcpy() to copy value into field
1923 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
)
1924 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1926 if isinstance(Value
, str):
1927 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
1930 # Use memcpy() to copy value into field
1932 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
1933 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1935 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
1936 for FieldName
in FieldList
:
1937 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1940 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1941 except BadExpression
:
1942 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1943 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1945 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1947 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]))
1948 if isinstance(Value
, str):
1949 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1952 # Use memcpy() to copy value into field
1954 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1955 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1956 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])
1957 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1959 if '[' in FieldName
and ']' in FieldName
:
1960 Index
= int(FieldName
.split('[')[1].split(']')[0])
1961 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
)
1963 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1965 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1970 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
1971 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
1974 def GenerateCommandLineValue(self
, Pcd
):
1975 CApp
= "// Value in CommandLine\n"
1976 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
)
1977 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1978 CApp
= CApp
+ ' CHAR8 *Value;\n'
1980 pcddefaultvalue
= Pcd
.PcdValueFromComm
1981 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
1984 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1985 IsArray
= IsFieldValueAnArray(FieldList
)
1988 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
1989 except BadExpression
:
1990 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
1991 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1992 Value
, ValueSize
= ParseFieldValue (FieldList
)
1994 if isinstance(Value
, str):
1995 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
1998 # Use memcpy() to copy value into field
2000 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2001 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2003 for FieldName
in FieldList
:
2004 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2007 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2008 except BadExpression
:
2009 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2010 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2014 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2016 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]))
2017 if isinstance(Value
, str):
2018 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2021 # Use memcpy() to copy value into field
2023 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
2024 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2025 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])
2026 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2028 if '[' in FieldName
and ']' in FieldName
:
2029 Index
= int(FieldName
.split('[')[1].split(']')[0])
2030 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
)
2032 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2034 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2039 def GenerateCommandLineValueStatement(Pcd
):
2040 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2042 def GenerateFdfValue(self
,Pcd
):
2043 CApp
= "// Value in Fdf\n"
2044 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
)
2045 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2046 CApp
= CApp
+ ' CHAR8 *Value;\n'
2048 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2049 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2052 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2053 IsArray
= IsFieldValueAnArray(FieldList
)
2056 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2057 except BadExpression
:
2058 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2059 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2060 Value
, ValueSize
= ParseFieldValue (FieldList
)
2062 if isinstance(Value
, str):
2063 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2066 # Use memcpy() to copy value into field
2068 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2069 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2071 for FieldName
in FieldList
:
2072 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2075 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2076 except BadExpression
:
2077 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2078 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2082 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2084 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]))
2085 if isinstance(Value
, str):
2086 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2089 # Use memcpy() to copy value into field
2091 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
2092 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2093 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])
2094 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2096 if '[' in FieldName
and ']' in FieldName
:
2097 Index
= int(FieldName
.split('[')[1].split(']')[0])
2098 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
)
2100 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2102 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2107 def GenerateFdfValueStatement(Pcd
):
2108 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2111 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2112 OverrideValues
= {DefaultStore
:""}
2113 if Pcd
.SkuOverrideValues
:
2114 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2115 if not OverrideValues
:
2116 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2117 for DefaultStoreName
in OverrideValues
:
2118 CApp
= CApp
+ 'void\n'
2119 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2120 CApp
= CApp
+ ' void\n'
2121 CApp
= CApp
+ ' )\n'
2123 CApp
= CApp
+ ' UINT32 Size;\n'
2124 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2125 CApp
= CApp
+ ' CHAR8 *Value;\n'
2126 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2127 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2128 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.DatumType
, Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2131 if SkuName
in Pcd
.SkuInfoList
:
2132 DefaultValue
= Pcd
.SkuInfoList
[SkuName
].DefaultStoreDict
.get(DefaultStoreName
, Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
if Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
else Pcd
.SkuInfoList
[SkuName
].DefaultValue
)
2134 DefaultValue
= Pcd
.DefaultValue
2135 PcdDefaultValue
= StringToArray(DefaultValue
.strip())
2137 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2140 # Get current PCD value and size
2142 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2145 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2146 # the correct value. For structures with a flexible array member, the flexible
2147 # array member is detected, and the size is based on the highest index used with
2148 # the flexible array member. The flexible array member must be the last field
2149 # in a structure. The size formula for this case is:
2150 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2152 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
)
2155 # Allocate and zero buffer for the PCD
2156 # Must handle cases where current value is smaller, larger, or same size
2157 # Always keep that larger one as the current size
2159 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2160 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.DatumType
)
2161 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2164 # Copy current PCD value into allocated buffer.
2166 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2169 # Assign field values in PCD
2171 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2172 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2173 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2174 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2175 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2176 for defaultstorenameitem
in storeset
:
2177 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2178 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2179 if skuname
== SkuName
:
2182 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2183 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2184 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2185 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2187 # Set new PCD value and size
2189 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2194 CApp
= CApp
+ ' free (Pcd);\n'
2197 return InitByteValue
, CApp
2198 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2199 if not OverrideValues
:
2201 for key
in OverrideValues
:
2202 if OverrideValues
[key
]:
2206 def GenerateByteArrayValue (self
, StructuredPcds
):
2208 # Generate/Compile/Run C application to determine if there are any flexible array members
2210 if not StructuredPcds
:
2214 CApp
= PcdMainCHeader
2216 IncludeFiles
= set()
2217 for PcdName
in StructuredPcds
:
2218 Pcd
= StructuredPcds
[PcdName
]
2219 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2220 if IncludeFile
not in IncludeFiles
:
2221 IncludeFiles
.add(IncludeFile
)
2222 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2224 for PcdName
in StructuredPcds
:
2225 Pcd
= StructuredPcds
[PcdName
]
2226 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2227 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2228 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2229 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2230 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2231 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2232 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2234 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2235 if SkuName
not in Pcd
.SkuOverrideValues
:
2237 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2238 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2239 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2240 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2241 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2243 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2244 if SkuName
not in Pcd
.SkuOverrideValues
:
2246 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2247 Pcd
= StructuredPcds
[PcdName
]
2248 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2250 CApp
= CApp
+ 'VOID\n'
2251 CApp
= CApp
+ 'PcdEntryPoint(\n'
2252 CApp
= CApp
+ ' VOID\n'
2253 CApp
= CApp
+ ' )\n'
2255 for Pcd
in StructuredPcds
.values():
2256 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
]]:
2257 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2259 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2260 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2262 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2263 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2266 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2268 if not os
.path
.exists(self
.OutputPath
):
2269 os
.makedirs(self
.OutputPath
)
2270 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2271 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2273 MakeApp
= PcdMakefileHeader
2274 if sys
.platform
== "win32":
2275 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2277 MakeApp
= MakeApp
+ PcdGccMakefile
2278 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2279 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2282 PlatformInc
= OrderedDict()
2283 for Cache
in self
._Bdb
._CACHE
_.values():
2284 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2287 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2288 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2289 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2290 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2293 for Pcd
in StructuredPcds
.values():
2294 for PackageDec
in Pcd
.PackageDecs
:
2295 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2296 if not os
.path
.exists(Package
):
2297 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2298 if Package
not in PcdDependDEC
:
2299 PcdDependDEC
.append(Package
)
2301 if PlatformInc
and PcdDependDEC
:
2302 for pkg
in PcdDependDEC
:
2303 if pkg
in PlatformInc
:
2304 for inc
in PlatformInc
[pkg
]:
2305 MakeApp
+= '-I' + str(inc
) + ' '
2306 IncSearchList
.append(inc
)
2307 MakeApp
= MakeApp
+ '\n'
2309 CC_FLAGS
= LinuxCFLAGS
2310 if sys
.platform
== "win32":
2311 CC_FLAGS
= WindowsCFLAGS
2312 BuildOptions
= OrderedDict()
2313 for Options
in self
.BuildOptions
:
2314 if Options
[2] != EDKII_NAME
:
2317 if Family
and Family
!= self
.ToolChainFamily
:
2319 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2323 if Target
== "*" or Target
== self
._Target
:
2324 if Tag
== "*" or Tag
== self
._Toolchain
:
2326 if Tool
not in BuildOptions
:
2327 BuildOptions
[Tool
] = OrderedDict()
2328 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or self
.BuildOptions
[Options
].startswith('='):
2329 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
2331 # append options for the same tool except PATH
2333 BuildOptions
[Tool
][Attr
] += " " + self
.BuildOptions
[Options
]
2335 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
2337 for Tool
in BuildOptions
:
2338 for Attr
in BuildOptions
[Tool
]:
2340 Value
= BuildOptions
[Tool
][Attr
]
2341 ValueList
= Value
.split()
2343 for Id
, Item
in enumerate(ValueList
):
2344 if Item
in ['-D', '/D', '-U', '/U']:
2345 CC_FLAGS
+= ' ' + Item
2346 if Id
+ 1 < len(ValueList
):
2347 CC_FLAGS
+= ' ' + ValueList
[Id
+ 1]
2348 elif Item
.startswith(('-D', '/D', '-U', '/U')):
2349 CC_FLAGS
+= ' ' + Item
2352 if sys
.platform
== "win32":
2353 MakeApp
= MakeApp
+ PcdMakefileEnd
2354 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2356 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2357 MakeApp
= MakeApp
+ '\n'
2358 IncludeFileFullPaths
= []
2359 for includefile
in IncludeFiles
:
2360 for includepath
in IncSearchList
:
2361 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2362 if os
.path
.exists(includefullpath
):
2363 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2366 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2367 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2368 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2369 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2370 for include_file
in IncFileList
:
2371 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2372 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2373 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2374 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2376 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2377 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2378 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2380 Dest_PcdValueInitExe
= PcdValueInitName
2381 if not sys
.platform
== "win32":
2382 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2384 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2386 if sys
.platform
== "win32":
2387 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2388 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2391 MakeCommand
= 'make -f %s' % (MakeFileName
)
2392 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2395 Messages
= Messages
.split('\n')
2398 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2399 File
= open (CAppBaseFileName
+ '.c', 'r')
2400 FileData
= File
.readlines()
2402 for Message
in Messages
:
2403 if " error" in Message
or "warning" in Message
:
2404 FileInfo
= Message
.strip().split('(')
2405 if len (FileInfo
) > 1:
2406 FileName
= FileInfo
[0]
2407 FileLine
= FileInfo
[1].split (')')[0]
2409 FileInfo
= Message
.strip().split(':')
2410 FileName
= FileInfo
[0]
2411 FileLine
= FileInfo
[1]
2412 if FileLine
.isdigit():
2413 error_line
= FileData
[int (FileLine
) - 1]
2414 if r
"//" in error_line
:
2415 c_line
, dsc_line
= error_line
.split(r
"//")
2417 dsc_line
= error_line
2418 message_itmes
= Message
.split(":")
2420 if "PcdValueInit.c" not in Message
:
2421 if not MessageGroup
:
2422 MessageGroup
.append(Message
)
2425 for item
in message_itmes
:
2426 if "PcdValueInit.c" in item
:
2427 Index
= message_itmes
.index(item
)
2428 message_itmes
[Index
] = dsc_line
.strip()
2430 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2433 MessageGroup
.append(Message
)
2435 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2437 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2439 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
2440 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2441 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2443 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2445 File
= open (OutputValueFile
, 'r')
2446 FileBuffer
= File
.readlines()
2449 StructurePcdSet
= []
2450 for Pcd
in FileBuffer
:
2451 PcdValue
= Pcd
.split ('|')
2452 PcdInfo
= PcdValue
[0].split ('.')
2453 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2454 return StructurePcdSet
2457 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2458 if not os
.path
.exists(OutputFile
):
2460 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2462 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2466 ## Retrieve dynamic PCD settings
2468 # @param Type PCD type
2470 # @retval a dict object contains settings of given PCD type
2472 def _GetDynamicPcd(self
, Type
):
2475 Pcds
= OrderedDict()
2477 # tdict is a special dict kind of type, used for selecting correct
2478 # PCD settings for certain ARCH and SKU
2480 PcdDict
= tdict(True, 4)
2482 # Find out all possible PCD candidates for self._Arch
2483 RecordList
= self
._RawData
[Type
, self
._Arch
]
2484 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2487 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2488 SkuName
= SkuName
.upper()
2489 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2490 if SkuName
not in AvailableSkuIdSet
:
2491 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2492 File
=self
.MetaFile
, Line
=Dummy5
)
2493 if "." not in TokenSpaceGuid
:
2494 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2495 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2497 # Remove redundant PCD candidates, per the ARCH and SKU
2498 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2500 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2504 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2506 if int(MaxDatumSize
, 0) > 0xFFFF:
2507 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2508 File
=self
.MetaFile
, Line
=Dummy4
)
2509 if int(MaxDatumSize
, 0) < 0:
2510 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2511 File
=self
.MetaFile
, Line
=Dummy4
)
2512 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2513 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2514 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2515 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2516 if MaxDatumSize
.strip():
2517 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2520 if pcdObject
.MaxDatumSize
:
2521 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2524 if CurrentMaxSize
> PcdMaxSize
:
2525 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2527 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2530 self
._PCD
_TYPE
_STRING
_[Type
],
2535 OrderedDict({SkuName
: SkuInfo
}),
2540 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2541 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2542 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2544 for pcd
in Pcds
.values():
2545 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2546 # Only fix the value while no value provided in DSC file.
2547 for sku
in pcd
.SkuInfoList
.values():
2548 if not sku
.DefaultValue
:
2549 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2550 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2551 valuefromDec
= pcdDecObject
.DefaultValue
2552 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2553 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2554 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2555 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2556 del pcd
.SkuInfoList
[TAB_COMMON
]
2557 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2558 del pcd
.SkuInfoList
[TAB_COMMON
]
2560 map(self
.FilterSkuSettings
, Pcds
.values())
2564 def FilterSkuSettings(self
, PcdObj
):
2566 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2567 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2568 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2569 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2570 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2571 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2573 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2574 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2579 def CompareVarAttr(Attr1
, Attr2
):
2580 if not Attr1
or not Attr2
: # for empty string
2582 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2583 Attr1Set
= set(Attr1s
)
2584 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2585 Attr2Set
= set(Attr2s
)
2586 if Attr2Set
== Attr1Set
:
2591 def CompletePcdValues(self
, PcdSet
):
2592 Pcds
= OrderedDict()
2593 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2594 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2595 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2596 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2597 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2599 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2600 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2601 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2602 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2603 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2604 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2605 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2607 PcdType
= PcdObj
.Type
2608 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2609 for skuid
in PcdObj
.SkuInfoList
:
2610 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2611 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2612 for defaultstorename
in DefaultStores
:
2613 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2614 skuobj
.DefaultStoreDict
[defaultstorename
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
2615 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2616 for skuname
, skuid
in SkuIds
.items():
2617 if skuname
not in PcdObj
.SkuInfoList
:
2618 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2619 while nextskuid
not in PcdObj
.SkuInfoList
:
2620 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2621 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2622 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2623 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2624 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2625 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2626 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2628 ## Retrieve dynamic HII PCD settings
2630 # @param Type PCD type
2632 # @retval a dict object contains settings of given PCD type
2634 def _GetDynamicHiiPcd(self
, Type
):
2638 Pcds
= OrderedDict()
2639 UserDefinedDefaultStores
= []
2641 # tdict is a special dict kind of type, used for selecting correct
2642 # PCD settings for certain ARCH and SKU
2644 PcdDict
= tdict(True, 5)
2646 RecordList
= self
._RawData
[Type
, self
._Arch
]
2647 # Find out all possible PCD candidates for self._Arch
2648 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2649 DefaultStoresDefine
= self
._GetDefaultStores
()
2651 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
2652 SkuName
= SkuName
.upper()
2653 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2654 DefaultStore
= DefaultStore
.upper()
2655 if DefaultStore
== TAB_COMMON
:
2656 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2658 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
2659 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
2660 if SkuName
not in AvailableSkuIdSet
:
2661 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2662 File
=self
.MetaFile
, Line
=Dummy5
)
2663 if DefaultStore
not in DefaultStoresDefine
:
2664 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2665 File
=self
.MetaFile
, Line
=Dummy5
)
2666 if "." not in TokenSpaceGuid
:
2667 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
2668 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
2671 # Remove redundant PCD candidates, per the ARCH and SKU
2672 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdSet
:
2674 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
2677 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2679 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2681 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2682 ExtraData
="[%s]" % VarAttribute
)
2684 FormatCorrect
= True
2685 if VariableOffset
.isdigit():
2686 if int(VariableOffset
, 10) > 0xFFFF:
2688 elif variablePattern
.match(VariableOffset
):
2689 if int(VariableOffset
, 16) > 0xFFFF:
2691 # For Offset written in "A.B"
2692 elif VariableOffset
.find('.') > -1:
2693 VariableOffsetList
= VariableOffset
.split(".")
2694 if not (len(VariableOffsetList
) == 2
2695 and IsValidWord(VariableOffsetList
[0])
2696 and IsValidWord(VariableOffsetList
[1])):
2697 FormatCorrect
= False
2699 FormatCorrect
= False
2700 if not FormatCorrect
:
2701 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2704 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2705 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2706 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2708 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2709 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
)]))
2711 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2712 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2713 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2714 if SkuName
in pcdObject
.SkuInfoList
:
2715 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2716 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2718 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2719 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2721 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2722 PcdClassObj
= PcdClassObject(
2725 self
._PCD
_TYPE
_STRING
_[Type
],
2730 OrderedDict({SkuName
: SkuInfo
}),
2733 pcdDecObject
.validateranges
,
2734 pcdDecObject
.validlists
,
2735 pcdDecObject
.expressions
,
2737 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
2738 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
2739 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
2741 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
2742 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2743 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2744 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
2745 for pcd
in Pcds
.values():
2746 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2747 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2748 pcd
.DatumType
= pcdDecObject
.DatumType
2749 # Only fix the value while no value provided in DSC file.
2750 for sku
in pcd
.SkuInfoList
.values():
2751 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2752 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2753 for default_store
in sku
.DefaultStoreDict
:
2754 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2755 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2756 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2757 valuefromDec
= pcdDecObject
.DefaultValue
2758 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
2759 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2760 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2761 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2762 del pcd
.SkuInfoList
[TAB_COMMON
]
2763 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2764 del pcd
.SkuInfoList
[TAB_COMMON
]
2766 if pcd
.MaxDatumSize
.strip():
2767 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2770 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
2771 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2773 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2774 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2775 if datalen
> MaxSize
:
2777 for defaultst
in skuobj
.DefaultStoreDict
:
2778 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2779 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
2780 pcd
.MaxDatumSize
= str(MaxSize
)
2781 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
2783 invalidpcd
= ",".join(invalidhii
)
2784 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
)
2786 map(self
.FilterSkuSettings
, Pcds
.values())
2791 def CheckVariableNameAssignment(Pcds
):
2793 for pcdname
in Pcds
:
2795 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
2796 if len(varnameset
) > 1:
2797 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
2799 return False, invalidhii
2802 ## Retrieve dynamic VPD PCD settings
2804 # @param Type PCD type
2806 # @retval a dict object contains settings of given PCD type
2808 def _GetDynamicVpdPcd(self
, Type
):
2811 Pcds
= OrderedDict()
2813 # tdict is a special dict kind of type, used for selecting correct
2814 # PCD settings for certain ARCH and SKU
2816 PcdDict
= tdict(True, 4)
2819 # Find out all possible PCD candidates for self._Arch
2820 RecordList
= self
._RawData
[Type
, self
._Arch
]
2821 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2823 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2824 SkuName
= SkuName
.upper()
2825 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2826 if SkuName
not in AvailableSkuIdSet
:
2827 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2828 File
=self
.MetaFile
, Line
=Dummy5
)
2829 if "." not in TokenSpaceGuid
:
2830 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2831 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2833 # Remove redundant PCD candidates, per the ARCH and SKU
2834 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2835 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2839 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
2840 # For the Integer & Boolean type, the optional data can only be InitialValue.
2841 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
2842 # until the DEC parser has been called.
2844 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2846 if int(MaxDatumSize
, 0) > 0xFFFF:
2847 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2848 File
=self
.MetaFile
, Line
=Dummy4
)
2849 if int(MaxDatumSize
, 0) < 0:
2850 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2851 File
=self
.MetaFile
, Line
=Dummy4
)
2852 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
2853 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2854 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2855 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2856 if MaxDatumSize
.strip():
2857 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2860 if pcdObject
.MaxDatumSize
:
2861 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2864 if CurrentMaxSize
> PcdMaxSize
:
2865 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2867 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2870 self
._PCD
_TYPE
_STRING
_[Type
],
2875 OrderedDict({SkuName
: SkuInfo
}),
2880 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2881 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2882 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
2883 for pcd
in Pcds
.values():
2884 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2885 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2886 pcd
.DatumType
= pcdDecObject
.DatumType
2887 # Only fix the value while no value provided in DSC file.
2888 for sku
in pcd
.SkuInfoList
.values():
2889 if not sku
.DefaultValue
:
2890 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2891 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2892 valuefromDec
= pcdDecObject
.DefaultValue
2893 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
2894 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2895 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2896 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2897 del pcd
.SkuInfoList
[TAB_COMMON
]
2898 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2899 del pcd
.SkuInfoList
[TAB_COMMON
]
2901 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
2902 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
2903 for pcd
in Pcds
.values():
2904 PcdValueTypeSet
= set()
2905 for sku
in pcd
.SkuInfoList
.values():
2906 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
2907 if len(PcdValueTypeSet
) > 1:
2908 for sku
in pcd
.SkuInfoList
.values():
2909 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
2911 map(self
.FilterSkuSettings
, Pcds
.values())
2914 ## Add external modules
2916 # The external modules are mostly those listed in FDF file, which don't
2919 # @param FilePath The path of module description file
2921 def AddModule(self
, FilePath
):
2922 FilePath
= NormPath(FilePath
)
2923 if FilePath
not in self
.Modules
:
2924 Module
= ModuleBuildClassObject()
2925 Module
.MetaFile
= FilePath
2926 self
.Modules
.append(Module
)
2929 def ToolChainFamily(self
):
2930 self
._ToolChainFamily
= TAB_COMPILER_MSFT
2931 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
2932 if os
.path
.isfile(BuildConfigurationFile
) == True:
2933 TargetTxt
= TargetTxtClassObject()
2934 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
2935 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
2936 if ToolDefinitionFile
== '':
2937 ToolDefinitionFile
= "tools_def.txt"
2938 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
2939 if os
.path
.isfile(ToolDefinitionFile
) == True:
2940 ToolDef
= ToolDefClassObject()
2941 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
2942 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
2943 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
2944 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
2945 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
2946 self
._ToolChainFamily
= TAB_COMPILER_MSFT
2948 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
2949 return self
._ToolChainFamily
2951 ## Add external PCDs
2953 # The external PCDs are mostly those listed in FDF file to specify address
2954 # or offset information.
2956 # @param Name Name of the PCD
2957 # @param Guid Token space guid of the PCD
2958 # @param Value Value of the PCD
2960 def AddPcd(self
, Name
, Guid
, Value
):
2961 if (Name
, Guid
) not in self
.Pcds
:
2962 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
2963 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
2967 if self
._DecPcds
is None:
2969 if GlobalData
.gFdfParser
:
2970 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
2972 for Inf
in FdfInfList
:
2973 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
2974 if ModuleFile
in self
._Modules
:
2976 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
2977 PkgSet
.update(ModuleData
.Packages
)
2978 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
2979 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
2980 return self
._DecPcds