2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2019, 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 TargetTxtClassObject
29 from Common
.ToolDefClassObject
import ToolDefClassObject
30 from .MetaDataTable
import *
31 from .MetaFileTable
import *
32 from .MetaFileParser
import *
34 from .WorkspaceCommon
import GetDeclaredPcd
35 from Common
.Misc
import AnalyzeDscPcd
36 from Common
.Misc
import ProcessDuplicatedInf
,RemoveCComments
38 from Common
.Parsing
import IsValidWord
39 from Common
.VariableAttributes
import VariableAttributes
40 import Common
.GlobalData
as GlobalData
42 from Common
.Misc
import SaveFileOnChange
43 from Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
44 from collections
import OrderedDict
, defaultdict
45 from .BuildClassObject
import ArrayIndex
47 def _IsFieldValueAnArray (Value
):
49 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
51 if Value
.startswith('L"') and Value
.endswith('"') and len(list(Value
[2:-1])) > 1:
53 if Value
[0] == '"' and Value
[-1] == '"' and len(list(Value
[1:-1])) > 1:
55 if Value
[0] == '{' and Value
[-1] == '}':
57 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
59 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
63 PcdValueInitName
= 'PcdValueInit'
74 #include <PcdValueCommon.h>
84 return PcdValueMain (argc, argv);
88 PcdMakefileHeader
= '''
91 # This file is auto-generated by build utility
96 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
97 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
99 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
101 LIBS = $(LIB_PATH)\Common.lib
103 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
108 $(APPFILE): $(OBJECTS)
113 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
117 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
118 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
119 ## regular expressions for finding decimal and hex numbers
120 Pattern
= re
.compile('^[1-9]\d*|0$')
121 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
122 ## Regular expression for finding header file inclusions
123 from AutoGen
.GenMake
import gIncludePattern
125 ## Find dependencies for one source file
127 # By searching recursively "#include" directive in file, find out all the
128 # files needed by given source file. The dependecies will be only searched
129 # in given search path list.
131 # @param SearchPathList The list of search path
133 # @retval list The list of files the given source file depends on
135 def GetDependencyList(FileStack
, SearchPathList
):
137 DependencySet
= set(FileStack
)
138 while len(FileStack
) > 0:
140 FullPathDependList
= []
141 CurrentFileDependencyList
= []
143 CurrentFileDependencyList
= DepDb
[F
]
147 FileContent
= Fd
.read()
148 except BaseException
as X
:
149 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
151 if "Fd" in dir(locals()):
154 if len(FileContent
) == 0:
157 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
158 FileContent
= unicode(FileContent
, "utf-16")
159 IncludedFileList
= gIncludePattern
.findall(FileContent
)
161 for Inc
in IncludedFileList
:
163 Inc
= os
.path
.normpath(Inc
)
164 CurrentFileDependencyList
.append(Inc
)
165 DepDb
[F
] = CurrentFileDependencyList
167 CurrentFilePath
= os
.path
.dirname(F
)
168 PathList
= [CurrentFilePath
] + SearchPathList
169 for Inc
in CurrentFileDependencyList
:
170 for SearchPath
in PathList
:
171 FilePath
= os
.path
.join(SearchPath
, Inc
)
172 if not os
.path
.exists(FilePath
):
174 if FilePath
not in DependencySet
:
175 FileStack
.append(FilePath
)
176 FullPathDependList
.append(FilePath
)
178 DependencySet
.update(FullPathDependList
)
179 DependencyList
= list(DependencySet
) # remove duplicate ones
181 return DependencyList
183 class DscBuildData(PlatformBuildClassObject
):
184 # dict used to convert PCD type in database to string used by build tool
185 _PCD_TYPE_STRING_
= {
186 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
187 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
188 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
189 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
190 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
191 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
192 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
193 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
194 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
195 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
196 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
199 # dict used to convert part of [Defines] to members of DscBuildData directly
204 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
205 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
206 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
207 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
208 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
209 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
210 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
211 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
212 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
213 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
214 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
215 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
216 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
217 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
218 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
221 # used to compose dummy library class name for those forced library instances
222 _NullLibraryNumber
= 0
224 ## Constructor of DscBuildData
226 # Initialize object of DscBuildData
228 # @param FilePath The path of platform description file
229 # @param RawData The raw data of DSC file
230 # @param BuildDataBase Database used to retrieve module/package information
231 # @param Arch The target architecture
232 # @param Platform (not used for DscBuildData)
233 # @param Macros Macros used for replacement in DSC file
235 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
236 self
.MetaFile
= FilePath
237 self
._RawData
= RawData
238 self
._Bdb
= BuildDataBase
240 self
._Target
= Target
241 self
._Toolchain
= Toolchain
242 self
._ToolChainFamily
= None
244 self
._HandleOverridePath
()
245 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
246 self
.DefaultStores
= None
247 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
250 def OutputPath(self
):
251 if os
.getenv("WORKSPACE"):
252 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
254 return os
.path
.dirname(self
.DscFile
)
257 def __setitem__(self
, key
, value
):
258 self
.__dict
__[self
._PROPERTY
_[key
]] = value
261 def __getitem__(self
, key
):
262 return self
.__dict
__[self
._PROPERTY
_[key
]]
265 def __contains__(self
, key
):
266 return key
in self
._PROPERTY
_
268 ## Set all internal used members of DscBuildData to None
271 self
._PlatformName
= None
274 self
._DscSpecification
= None
275 self
._OutputDirectory
= None
276 self
._SupArchList
= None
277 self
._BuildTargets
= None
279 self
._PcdInfoFlag
= None
280 self
._VarCheckFlag
= None
281 self
._FlashDefinition
= None
282 self
._Prebuild
= None
283 self
._Postbuild
= None
284 self
._BuildNumber
= None
285 self
._MakefileName
= None
286 self
._BsBaseAddress
= None
287 self
._RtBaseAddress
= None
290 self
._LibraryInstances
= None
291 self
._LibraryClasses
= None
294 self
._BuildOptions
= None
295 self
._ModuleTypeOptions
= None
296 self
._LoadFixAddress
= None
297 self
._RFCLanguages
= None
298 self
._ISOLanguages
= None
299 self
._VpdToolGuid
= None
300 self
._MacroDict
= None
301 self
.DefaultStores
= None
303 ## handle Override Path of Module
304 def _HandleOverridePath(self
):
305 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
306 for Record
in RecordList
:
309 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
310 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
312 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
314 # Check if the source override path exists
315 if not os
.path
.isdir(SourceOverridePath
):
316 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
318 # Add to GlobalData Variables
319 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
321 ## Get current effective macros
324 if self
._MacroDict
is None:
326 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
327 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
328 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
329 return self
._MacroDict
336 ## Retrieve all information in [Defines] section
338 # (Retriving all [Defines] information in one-shot is just to save time.)
340 def _GetHeaderInfo(self
):
341 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
342 for Record
in RecordList
:
344 # items defined _PROPERTY_ don't need additional processing
346 # some special items in [Defines] section need special treatment
347 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
348 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
349 if ' ' in self
._OutputDirectory
:
350 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
351 File
=self
.MetaFile
, Line
=Record
[-1],
352 ExtraData
=self
._OutputDirectory
)
353 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
354 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
355 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
357 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
359 elif Name
== TAB_DSC_PREBUILD
:
360 PrebuildValue
= Record
[2]
361 if Record
[2][0] == '"':
362 if Record
[2][-1] != '"':
363 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
364 File
=self
.MetaFile
, Line
=Record
[-1])
365 PrebuildValue
= Record
[2][1:-1]
366 self
._Prebuild
= PrebuildValue
367 elif Name
== TAB_DSC_POSTBUILD
:
368 PostbuildValue
= Record
[2]
369 if Record
[2][0] == '"':
370 if Record
[2][-1] != '"':
371 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
372 File
=self
.MetaFile
, Line
=Record
[-1])
373 PostbuildValue
= Record
[2][1:-1]
374 self
._Postbuild
= PostbuildValue
375 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
376 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
377 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
378 self
._BuildTargets
= GetSplitValueList(Record
[2])
379 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
380 if self
._SkuName
is None:
381 self
._SkuName
= Record
[2]
382 if GlobalData
.gSKUID_CMD
:
383 self
._SkuName
= GlobalData
.gSKUID_CMD
384 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
385 self
._PcdInfoFlag
= Record
[2]
386 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
387 self
._VarCheckFlag
= Record
[2]
388 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
390 self
._LoadFixAddress
= int (Record
[2], 0)
392 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
393 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
394 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
395 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"',
396 File
=self
.MetaFile
, Line
=Record
[-1])
397 LanguageCodes
= Record
[2][1:-1]
398 if not LanguageCodes
:
399 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
400 File
=self
.MetaFile
, Line
=Record
[-1])
401 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
402 # check whether there is empty entries in the list
403 if None in LanguageList
:
404 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
405 File
=self
.MetaFile
, Line
=Record
[-1])
406 self
._RFCLanguages
= LanguageList
407 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
408 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
409 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
410 File
=self
.MetaFile
, Line
=Record
[-1])
411 LanguageCodes
= Record
[2][1:-1]
412 if not LanguageCodes
:
413 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
414 File
=self
.MetaFile
, Line
=Record
[-1])
415 if len(LanguageCodes
) % 3:
416 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
417 File
=self
.MetaFile
, Line
=Record
[-1])
419 for i
in range(0, len(LanguageCodes
), 3):
420 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
421 self
._ISOLanguages
= LanguageList
422 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
424 # try to convert GUID to a real UUID value to see whether the GUID is format
425 # for VPD_TOOL_GUID is correct.
430 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
431 self
._VpdToolGuid
= Record
[2]
433 self
[Name
] = Record
[2]
434 # set _Header to non-None in order to avoid database re-querying
435 self
._Header
= 'DUMMY'
437 ## Retrieve platform name
439 def PlatformName(self
):
440 if self
._PlatformName
is None:
441 if self
._Header
is None:
442 self
._GetHeaderInfo
()
443 if self
._PlatformName
is None:
444 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
445 return self
._PlatformName
449 return self
.PlatformName
451 ## Retrieve file guid
454 if self
._Guid
is None:
455 if self
._Header
is None:
456 self
._GetHeaderInfo
()
457 if self
._Guid
is None:
458 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
461 ## Retrieve platform version
464 if self
._Version
is None:
465 if self
._Header
is None:
466 self
._GetHeaderInfo
()
467 if self
._Version
is None:
468 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
471 ## Retrieve platform description file version
473 def DscSpecification(self
):
474 if self
._DscSpecification
is None:
475 if self
._Header
is None:
476 self
._GetHeaderInfo
()
477 if self
._DscSpecification
is None:
478 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
479 return self
._DscSpecification
481 ## Retrieve OUTPUT_DIRECTORY
483 def OutputDirectory(self
):
484 if self
._OutputDirectory
is None:
485 if self
._Header
is None:
486 self
._GetHeaderInfo
()
487 if self
._OutputDirectory
is None:
488 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
489 return self
._OutputDirectory
491 ## Retrieve SUPPORTED_ARCHITECTURES
493 def SupArchList(self
):
494 if self
._SupArchList
is None:
495 if self
._Header
is None:
496 self
._GetHeaderInfo
()
497 if self
._SupArchList
is None:
498 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
499 return self
._SupArchList
501 ## Retrieve BUILD_TARGETS
503 def BuildTargets(self
):
504 if self
._BuildTargets
is None:
505 if self
._Header
is None:
506 self
._GetHeaderInfo
()
507 if self
._BuildTargets
is None:
508 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
509 return self
._BuildTargets
512 def PcdInfoFlag(self
):
513 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
515 elif self
._PcdInfoFlag
.upper() == 'TRUE':
521 def VarCheckFlag(self
):
522 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
524 elif self
._VarCheckFlag
.upper() == 'TRUE':
529 # # Retrieve SKUID_IDENTIFIER
532 if self
._SkuName
is None:
533 if self
._Header
is None:
534 self
._GetHeaderInfo
()
535 if self
._SkuName
is None:
536 self
._SkuName
= TAB_DEFAULT
539 ## Override SKUID_IDENTIFIER
541 def SkuName(self
, Value
):
542 self
._SkuName
= Value
545 def FlashDefinition(self
):
546 if self
._FlashDefinition
is None:
547 if self
._Header
is None:
548 self
._GetHeaderInfo
()
549 if self
._FlashDefinition
is None:
550 self
._FlashDefinition
= ''
551 return self
._FlashDefinition
555 if self
._Prebuild
is None:
556 if self
._Header
is None:
557 self
._GetHeaderInfo
()
558 if self
._Prebuild
is None:
560 return self
._Prebuild
564 if self
._Postbuild
is None:
565 if self
._Header
is None:
566 self
._GetHeaderInfo
()
567 if self
._Postbuild
is None:
569 return self
._Postbuild
571 ## Retrieve FLASH_DEFINITION
573 def BuildNumber(self
):
574 if self
._BuildNumber
is None:
575 if self
._Header
is None:
576 self
._GetHeaderInfo
()
577 if self
._BuildNumber
is None:
578 self
._BuildNumber
= ''
579 return self
._BuildNumber
581 ## Retrieve MAKEFILE_NAME
583 def MakefileName(self
):
584 if self
._MakefileName
is None:
585 if self
._Header
is None:
586 self
._GetHeaderInfo
()
587 if self
._MakefileName
is None:
588 self
._MakefileName
= ''
589 return self
._MakefileName
591 ## Retrieve BsBaseAddress
593 def BsBaseAddress(self
):
594 if self
._BsBaseAddress
is None:
595 if self
._Header
is None:
596 self
._GetHeaderInfo
()
597 if self
._BsBaseAddress
is None:
598 self
._BsBaseAddress
= ''
599 return self
._BsBaseAddress
601 ## Retrieve RtBaseAddress
603 def RtBaseAddress(self
):
604 if self
._RtBaseAddress
is None:
605 if self
._Header
is None:
606 self
._GetHeaderInfo
()
607 if self
._RtBaseAddress
is None:
608 self
._RtBaseAddress
= ''
609 return self
._RtBaseAddress
611 ## Retrieve the top address for the load fix address
613 def LoadFixAddress(self
):
614 if self
._LoadFixAddress
is None:
615 if self
._Header
is None:
616 self
._GetHeaderInfo
()
618 if self
._LoadFixAddress
is None:
619 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
622 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
624 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
627 # If command line defined, should override the value in DSC file.
629 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
631 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
633 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']))
635 if self
._LoadFixAddress
< 0:
636 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
637 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
638 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
640 return self
._LoadFixAddress
642 ## Retrieve RFCLanguage filter
644 def RFCLanguages(self
):
645 if self
._RFCLanguages
is None:
646 if self
._Header
is None:
647 self
._GetHeaderInfo
()
648 if self
._RFCLanguages
is None:
649 self
._RFCLanguages
= []
650 return self
._RFCLanguages
652 ## Retrieve ISOLanguage filter
654 def ISOLanguages(self
):
655 if self
._ISOLanguages
is None:
656 if self
._Header
is None:
657 self
._GetHeaderInfo
()
658 if self
._ISOLanguages
is None:
659 self
._ISOLanguages
= []
660 return self
._ISOLanguages
662 ## Retrieve the GUID string for VPD tool
664 def VpdToolGuid(self
):
665 if self
._VpdToolGuid
is None:
666 if self
._Header
is None:
667 self
._GetHeaderInfo
()
668 if self
._VpdToolGuid
is None:
669 self
._VpdToolGuid
= ''
670 return self
._VpdToolGuid
672 ## Retrieve [SkuIds] section information
675 if self
._SkuIds
is None:
676 self
._SkuIds
= OrderedDict()
677 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
678 for Record
in RecordList
:
680 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
681 File
=self
.MetaFile
, Line
=Record
[-1])
683 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
684 File
=self
.MetaFile
, Line
=Record
[-1])
685 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
686 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
687 File
=self
.MetaFile
, Line
=Record
[-1])
688 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
689 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_)*'",
690 File
=self
.MetaFile
, Line
=Record
[-1])
691 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
692 if TAB_DEFAULT
not in self
._SkuIds
:
693 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
694 if TAB_COMMON
not in self
._SkuIds
:
695 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
700 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
702 def _GetDefaultStores(self
):
703 if self
.DefaultStores
is None:
704 self
.DefaultStores
= OrderedDict()
705 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
706 for Record
in RecordList
:
708 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
709 File
=self
.MetaFile
, Line
=Record
[-1])
711 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
712 File
=self
.MetaFile
, Line
=Record
[-1])
713 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
714 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
715 File
=self
.MetaFile
, Line
=Record
[-1])
716 if not IsValidWord(Record
[1]):
717 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_-.)*'",
718 File
=self
.MetaFile
, Line
=Record
[-1])
719 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
720 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
721 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
722 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
723 return self
.DefaultStores
725 def OverrideDuplicateModule(self
):
726 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
727 Macros
= self
._Macros
729 for Record
in RecordList
:
731 file_guid
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
732 file_guid_str
= file_guid
[0][2] if file_guid
else "NULL"
733 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
734 if self
._Arch
!= TAB_ARCH_COMMON
and (file_guid_str
,str(ModuleFile
)) in Components
:
735 self
._RawData
.DisableOverrideComponent(Components
[(file_guid_str
,str(ModuleFile
))])
736 Components
[(file_guid_str
,str(ModuleFile
))] = ModuleId
737 self
._RawData
._PostProcessed
= False
738 ## Retrieve [Components] section information
741 if self
._Modules
is not None:
743 self
.OverrideDuplicateModule()
744 self
._Modules
= OrderedDict()
745 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
746 Macros
= self
._Macros
747 for Record
in RecordList
:
748 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
752 # check the file validation
753 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
755 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
758 Module
= ModuleBuildClassObject()
759 Module
.MetaFile
= ModuleFile
761 # get module private library instance
762 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
763 for Record
in RecordList
:
764 LibraryClass
= Record
[0]
765 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
768 # check the file validation
769 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
771 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
774 if LibraryClass
== '' or LibraryClass
== 'NULL':
775 self
._NullLibraryNumber
+= 1
776 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
777 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
778 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
779 if LibraryPath
not in self
.LibraryInstances
:
780 self
.LibraryInstances
.append(LibraryPath
)
782 # get module private PCD setting
783 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
784 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
785 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
786 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
787 TokenList
= GetSplitValueList(Setting
)
788 DefaultValue
= TokenList
[0]
789 # the format is PcdName| Value | VOID* | MaxDatumSize
790 if len(TokenList
) > 2:
791 MaxDatumSize
= TokenList
[2]
794 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
795 Pcd
= PcdClassObject(
807 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
809 # get module private build options
810 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
811 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
812 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
813 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
815 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
816 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
818 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
820 if len(RecordList
) != 1:
821 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
822 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
823 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
824 ModuleFile
.Arch
= self
._Arch
826 self
._Modules
[ModuleFile
] = Module
829 ## Retrieve all possible library instances used in this platform
831 def LibraryInstances(self
):
832 if self
._LibraryInstances
is None:
834 return self
._LibraryInstances
836 ## Retrieve [LibraryClasses] information
838 def LibraryClasses(self
):
839 if self
._LibraryClasses
is None:
840 self
._LibraryInstances
= []
842 # tdict is a special dict kind of type, used for selecting correct
843 # library instance for given library class and module type
845 LibraryClassDict
= tdict(True, 3)
846 # track all library class names
847 LibraryClassSet
= set()
848 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
849 Macros
= self
._Macros
850 for Record
in RecordList
:
851 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
852 if LibraryClass
== '' or LibraryClass
== 'NULL':
853 self
._NullLibraryNumber
+= 1
854 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
855 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
856 LibraryClassSet
.add(LibraryClass
)
857 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
858 # check the file validation
859 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
861 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
864 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
865 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
866 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
867 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
868 if LibraryInstance
not in self
._LibraryInstances
:
869 self
._LibraryInstances
.append(LibraryInstance
)
871 # resolve the specific library instance for each class and each module type
872 self
._LibraryClasses
= tdict(True)
873 for LibraryClass
in LibraryClassSet
:
874 # try all possible module types
875 for ModuleType
in SUP_MODULE_LIST
:
876 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
877 if LibraryInstance
is None:
879 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
881 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
882 for Record
in RecordList
:
883 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
885 # check the file validation
886 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
888 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
890 if File
not in self
._LibraryInstances
:
891 self
._LibraryInstances
.append(File
)
893 # we need the module name as the library class name, so we have
894 # to parse it here. (self._Bdb[] will trigger a file parse if it
895 # hasn't been parsed)
897 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
898 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
899 return self
._LibraryClasses
901 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
902 if not self
._DecPcds
:
905 if GlobalData
.gFdfParser
:
906 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
909 for Inf
in FdfInfList
:
910 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
911 if ModuleFile
in self
._Modules
:
913 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
914 PkgSet
.update(ModuleData
.Packages
)
916 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
917 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
919 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
920 EdkLogger
.error('build', PARSER_ERROR
,
921 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
922 File
=self
.MetaFile
, Line
=LineNo
)
923 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
925 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
926 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
927 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
929 if ValueList
[2] == '-1':
930 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
931 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
933 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
934 if "{CODE(" not in ValueList
[Index
]:
936 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
937 except BadExpression
as Value
:
938 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
939 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
940 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
941 except EvaluationException
as Excpt
:
942 if hasattr(Excpt
, 'Pcd'):
943 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
944 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
945 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
946 " of the DSC file" % Excpt
.Pcd
,
947 File
=self
.MetaFile
, Line
=LineNo
)
949 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
950 File
=self
.MetaFile
, Line
=LineNo
)
952 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
953 File
=self
.MetaFile
, Line
=LineNo
)
956 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
958 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
959 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
960 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
961 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
962 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
,
963 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
964 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
965 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
966 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
969 def _FilterPcdBySkuUsage(self
, Pcds
):
970 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
971 sku_usage
= self
.SkuIdMgr
.SkuUsageType
972 if sku_usage
== SkuClass
.SINGLE
:
975 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
976 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
977 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
981 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
982 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
983 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
986 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
987 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
]]]
988 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
990 for skuid
in pcd
.SkuInfoList
:
991 skuobj
= pcd
.SkuInfoList
.get(skuid
)
992 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
993 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
994 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
995 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
998 def RecoverCommandLinePcd(self
):
999 def UpdateCommandLineValue(pcd
):
1000 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1001 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1002 pcd
.PcdValueFromComm
= pcd
.DefaultValue
1003 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1004 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
1006 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
1007 for pcd
in self
._Pcds
:
1008 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
1009 UpdateCommandLineValue(self
._Pcds
[pcd
])
1011 def __ParsePcdFromCommandLine(self
):
1012 if GlobalData
.BuildOptionPcd
:
1013 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
1014 if isinstance(pcd
, tuple):
1016 (pcdname
, pcdvalue
) = pcd
.split('=')
1018 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1020 (Name1
, Name2
) = pcdname
.split('.', 1)
1022 (Name3
, FieldName
) = Name2
.split(".", 1)
1023 if ((Name3
, Name1
)) in self
.DecPcds
:
1024 HasTokenSpace
= True
1026 TokenSpaceGuidCName
= Name1
1030 TokenSpaceGuidCName
= ''
1031 HasTokenSpace
= False
1033 if ((Name2
, Name1
)) in self
.DecPcds
:
1034 HasTokenSpace
= True
1036 TokenSpaceGuidCName
= Name1
1041 TokenSpaceGuidCName
= ''
1042 HasTokenSpace
= False
1045 TokenCName
= pcdname
1046 TokenSpaceGuidCName
= ''
1047 HasTokenSpace
= False
1048 TokenSpaceGuidCNameList
= []
1051 DisplayName
= TokenCName
1053 DisplayName
= TokenCName
+ '.' + FieldName
1054 if not HasTokenSpace
:
1055 for key
in self
.DecPcds
:
1056 PcdItem
= self
.DecPcds
[key
]
1057 if TokenCName
== PcdItem
.TokenCName
:
1058 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1059 if len (TokenSpaceGuidCNameList
) < 1:
1060 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1061 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1062 PcdDatumType
= PcdItem
.DatumType
1068 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1071 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1072 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1076 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1078 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1079 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1081 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1083 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1084 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1086 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1087 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1089 if GlobalData
.BuildOptionPcd
:
1090 for pcd
in GlobalData
.BuildOptionPcd
:
1091 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1092 for BuildData
in self
._Bdb
._CACHE
_.values():
1093 if BuildData
.Arch
!= self
.Arch
:
1095 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1097 for key
in BuildData
.Pcds
:
1098 PcdItem
= BuildData
.Pcds
[key
]
1099 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1100 PcdItem
.DefaultValue
= pcdvalue
1101 PcdItem
.PcdValueFromComm
= pcdvalue
1102 #In command line, the latter full assign value in commandLine should override the former field assign value.
1103 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1106 if GlobalData
.BuildOptionPcd
:
1107 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1108 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1110 if (TokenSpaceGuid
, Token
) not in field_assign
:
1111 field_assign
[TokenSpaceGuid
, Token
] = []
1112 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1114 if (TokenSpaceGuid
, Token
) in field_assign
:
1115 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1116 field_assign
[TokenSpaceGuid
, Token
] = []
1117 for item
in delete_assign
:
1118 GlobalData
.BuildOptionPcd
.remove(item
)
1121 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1124 TokenCName
+= '.' + FieldName
1125 if PcdValue
.startswith('H'):
1126 if FieldName
and _IsFieldValueAnArray(PcdValue
[1:]):
1127 PcdDatumType
= TAB_VOID
1129 if FieldName
and not IsArray
:
1132 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1133 except BadExpression
as Value
:
1134 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1135 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1136 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1137 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1138 PcdDatumType
= TAB_VOID
1140 if FieldName
and not IsArray
:
1143 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1144 except BadExpression
as Value
:
1145 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1146 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1147 elif PcdValue
.startswith('L'):
1148 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1149 if FieldName
and _IsFieldValueAnArray(PcdValue
):
1150 PcdDatumType
= TAB_VOID
1152 if FieldName
and not IsArray
:
1155 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1156 except BadExpression
as Value
:
1157 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1158 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1160 if PcdValue
.upper() == 'FALSE':
1162 if PcdValue
.upper() == 'TRUE':
1165 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1166 PcdValue
= '"' + PcdValue
+ '"'
1167 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1168 PcdValue
= '"' + PcdValue
+ '"'
1172 if PcdValue
.upper().startswith('0X'):
1175 Num
= int(PcdValue
, Base
)
1177 PcdValue
= '"' + PcdValue
+ '"'
1178 if _IsFieldValueAnArray(PcdValue
):
1179 PcdDatumType
= TAB_VOID
1184 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1185 except BadExpression
as Value
:
1186 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1187 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1190 ## Retrieve all PCD settings in platform
1193 if self
._Pcds
is None:
1194 self
._Pcds
= OrderedDict()
1195 self
.__ParsePcdFromCommandLine
()
1196 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1197 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1198 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1199 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1200 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1201 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1202 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1203 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1204 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1206 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1207 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1208 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1209 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1210 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1211 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1213 self
.RecoverCommandLinePcd()
1216 ## Retrieve [BuildOptions]
1218 def BuildOptions(self
):
1219 if self
._BuildOptions
is None:
1220 self
._BuildOptions
= OrderedDict()
1222 # Retrieve build option for EDKII and EDK style module
1224 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1225 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1226 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1227 if Dummy3
.upper() != TAB_COMMON
:
1229 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1231 # Only flags can be appended
1233 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1234 self
._BuildOptions
[CurKey
] = Option
1236 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1237 self
._BuildOptions
[CurKey
] += ' ' + Option
1238 return self
._BuildOptions
1240 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1241 if self
._ModuleTypeOptions
is None:
1242 self
._ModuleTypeOptions
= OrderedDict()
1243 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1244 options
= OrderedDict()
1245 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1246 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1247 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1248 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1249 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1250 Type
= Dummy2
+ '.' + Dummy3
1251 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1252 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1253 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1254 options
[Key
] = Option
1256 if ' ' + Option
not in options
[Key
]:
1257 options
[Key
] += ' ' + Option
1258 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1261 def GetStructurePcdInfo(PcdSet
):
1262 structure_pcd_data
= defaultdict(list)
1264 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1266 return structure_pcd_data
1269 def OverrideByFdf(StruPcds
,workspace
):
1270 if GlobalData
.gFdfParser
is None:
1272 StructurePcdInFdf
= OrderedDict()
1273 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1274 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1275 for item
in fdfpcd
:
1276 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1277 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1278 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1279 for Pcd
in StruPcds
.values():
1280 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1282 FieldValues
= OrderedDict()
1283 for item
in StructurePcdInFdf
:
1284 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1285 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1286 for field
in FieldValues
:
1287 if field
not in Pcd
.PcdFieldValueFromFdf
:
1288 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1289 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1290 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1291 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1296 def OverrideByComm(StruPcds
):
1297 StructurePcdInCom
= OrderedDict()
1298 for item
in GlobalData
.BuildOptionPcd
:
1299 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1300 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1301 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1302 for Pcd
in StruPcds
.values():
1303 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1305 FieldValues
= OrderedDict()
1306 for item
in StructurePcdInCom
:
1307 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1308 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1309 for field
in FieldValues
:
1310 if field
not in Pcd
.PcdFieldValueFromComm
:
1311 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1312 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1313 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1314 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1317 def OverrideByCommOverAll(self
,AllPcds
):
1318 def CheckStructureInComm(commpcds
):
1321 if len(commpcds
[0]) == 5:
1324 NoFiledValues
= OrderedDict()
1325 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1326 StructurePcdInCom
= OrderedDict()
1327 for item
in GlobalData
.BuildOptionPcd
:
1328 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1329 for item
in StructurePcdInCom
:
1331 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1333 for item
in GlobalData
.BuildOptionPcd
:
1334 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1335 for Guid
, Name
in NoFiledValues
:
1336 if (Name
, Guid
) in AllPcds
:
1337 Pcd
= AllPcds
.get((Name
, Guid
))
1338 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1339 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1341 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1342 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1343 for sku
in Pcd
.SkuInfoList
:
1344 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1345 if SkuInfo
.DefaultValue
:
1346 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1348 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1349 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1350 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1351 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1352 if Pcd
.DatumType
== TAB_VOID
:
1353 if not Pcd
.MaxDatumSize
:
1354 Pcd
.MaxDatumSize
= '0'
1355 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1356 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1357 MaxSize
= max(CurrentSize
, OptionSize
)
1358 Pcd
.MaxDatumSize
= str(MaxSize
)
1360 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1362 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1363 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1364 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1365 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1366 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1367 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1368 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1369 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1370 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1371 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1372 self
.Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1375 def OverrideByFdfOverAll(self
,AllPcds
):
1377 if GlobalData
.gFdfParser
is None:
1379 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1380 for Name
,Guid
,Field
in NoFiledValues
:
1383 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1384 if (Name
,Guid
) in AllPcds
:
1385 Pcd
= AllPcds
.get((Name
,Guid
))
1386 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1387 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1389 Pcd
.PcdValueFromComm
= Value
1390 Pcd
.DefaultValue
= Value
1391 for sku
in Pcd
.SkuInfoList
:
1392 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1393 if SkuInfo
.DefaultValue
:
1394 SkuInfo
.DefaultValue
= Value
1396 SkuInfo
.HiiDefaultValue
= Value
1397 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1398 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1399 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1400 if Pcd
.DatumType
== TAB_VOID
:
1401 if not Pcd
.MaxDatumSize
:
1402 Pcd
.MaxDatumSize
= '0'
1403 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1404 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1405 MaxSize
= max(CurrentSize
, OptionSize
)
1406 Pcd
.MaxDatumSize
= str(MaxSize
)
1408 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1410 PcdInDec
.PcdValueFromFdf
= Value
1411 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1412 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1413 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1414 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1415 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
1418 def ParsePcdNameStruct(self
,NamePart1
,NamePart2
):
1419 TokenSpaceCName
= PcdCName
= DimensionAttr
= Field
= ""
1420 if "." in NamePart1
:
1421 TokenSpaceCName
, TempPcdCName
= NamePart1
.split(".")
1422 if "[" in TempPcdCName
:
1423 PcdCName
= TempPcdCName
[:TempPcdCName
.index("[")]
1424 DimensionAttr
= TempPcdCName
[TempPcdCName
.index("["):]
1426 PcdCName
= TempPcdCName
1429 TokenSpaceCName
= NamePart1
1430 if "[" in NamePart2
:
1431 PcdCName
= NamePart2
[:NamePart2
.index("[")]
1432 DimensionAttr
= NamePart2
[NamePart2
.index("["):]
1434 PcdCName
= NamePart2
1436 return TokenSpaceCName
,PcdCName
,DimensionAttr
,Field
1438 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1440 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1441 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1442 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1443 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1444 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1445 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1448 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1449 SkuIds
= self
.SkuIds
1450 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1451 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1452 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1455 # Find out all possible PCD candidates for self._Arch
1458 for Type
in TypeList
:
1459 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1461 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1462 SkuName
= SkuName
.upper()
1463 default_store
= default_store
.upper()
1464 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1465 if SkuName
not in SkuIds
:
1467 TCName
,PCName
,DimensionAttr
,Field
= self
.ParsePcdNameStruct(TokenSpaceGuid
, PcdCName
)
1468 pcd_in_dec
= self
._DecPcds
.get((PCName
,TCName
), None)
1469 if pcd_in_dec
is None:
1470 EdkLogger
.error('build', PARSER_ERROR
,
1471 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1472 File
=self
.MetaFile
, Line
= Dummy5
)
1473 if SkuName
in SkuIds
and ("." in TokenSpaceGuid
or "[" in PcdCName
):
1474 if not isinstance (pcd_in_dec
, StructurePcd
):
1475 EdkLogger
.error('build', PARSER_ERROR
,
1476 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (TCName
, PCName
, self
._Arch
),
1477 File
=self
.MetaFile
, Line
= Dummy5
)
1479 S_PcdSet
.append([ TCName
,PCName
,DimensionAttr
,Field
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1481 # handle pcd value override
1482 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1483 S_pcd_set
= OrderedDict()
1484 for str_pcd
in StrPcdSet
:
1485 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1486 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1487 str_pcd_obj_str
= StructurePcd()
1488 str_pcd_obj_str
.copy(str_pcd_dec
)
1490 str_pcd_obj_str
.copy(str_pcd_obj
)
1491 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1492 str_pcd_obj_str
.DefaultFromDSC
= {skuname
:{defaultstore
: str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.get(defaultstore
, str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
) for defaultstore
in DefaultStores
} for skuname
in str_pcd_obj
.SkuInfoList
}
1494 str_pcd_obj_str
.DefaultFromDSC
= {skuname
:{defaultstore
: str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.get(defaultstore
, str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
) for defaultstore
in DefaultStores
} for skuname
in str_pcd_obj
.SkuInfoList
}
1495 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1496 if str_pcd_data
[4] in SkuIds
:
1497 str_pcd_obj_str
.AddOverrideValue(str_pcd_data
[3], str(str_pcd_data
[7]), TAB_DEFAULT
if str_pcd_data
[4] == TAB_COMMON
else str_pcd_data
[4], TAB_DEFAULT_STORES_DEFAULT
if str_pcd_data
[5] == TAB_COMMON
else str_pcd_data
[5], self
.MetaFile
.File
if self
.WorkspaceDir
not in self
.MetaFile
.File
else self
.MetaFile
.File
[len(self
.WorkspaceDir
) if self
.WorkspaceDir
.endswith(os
.path
.sep
) else len(self
.WorkspaceDir
)+1:], LineNo
=str_pcd_data
[6],DimensionAttr
= str_pcd_data
[2])
1498 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1500 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1501 for Pcd
in self
.DecPcds
:
1502 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1503 if Pcd
not in S_pcd_set
:
1504 str_pcd_obj_str
= StructurePcd()
1505 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1506 str_pcd_obj
= Pcds
.get(Pcd
, None)
1508 str_pcd_obj_str
.copy(str_pcd_obj
)
1509 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1510 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
}
1512 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
}
1513 S_pcd_set
[Pcd
] = str_pcd_obj_str
1514 self
.FilterStrcturePcd(S_pcd_set
)
1516 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1517 for stru_pcd
in S_pcd_set
.values():
1518 for skuid
in SkuIds
:
1519 if skuid
in stru_pcd
.SkuOverrideValues
:
1521 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1523 if skuid
not in stru_pcd
.SkuOverrideValues
:
1524 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1525 if nextskuid
== TAB_DEFAULT
:
1528 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1529 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})
1531 stru_pcd
.ValueChain
.add((skuid
, ''))
1532 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1533 for skuid
in SkuIds
:
1536 if skuid
not in stru_pcd
.SkuOverrideValues
:
1537 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1538 if nextskuid
== TAB_DEFAULT
:
1541 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1544 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1545 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1547 for defaultstoreid
in DefaultStores
:
1548 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1549 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = CopyDict(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1550 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1551 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1552 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1553 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1555 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1556 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1557 if str_pcd_obj
is None:
1558 print(PcdName
, PcdGuid
)
1560 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1561 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1562 if skuname
not in str_pcd_obj
.SkuInfoList
:
1563 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1565 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1566 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1567 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1568 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1569 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1570 str_pcd_obj
.DefaultValue
= PcdValue
1572 if skuname
not in str_pcd_obj
.SkuInfoList
:
1573 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1575 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1576 if nextskuid
== TAB_DEFAULT
:
1579 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1580 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
)
1581 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1582 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1584 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1585 for str_pcd_obj
in S_pcd_set
.values():
1586 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1587 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1589 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1590 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1591 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1592 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1594 for str_pcd_obj
in S_pcd_set
.values():
1596 str_pcd_obj
.MaxDatumSize
= DscBuildData
.GetStructurePcdMaxSize(str_pcd_obj
)
1597 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1598 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1602 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1603 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1604 del pcd
.SkuInfoList
[TAB_COMMON
]
1605 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1606 del pcd
.SkuInfoList
[TAB_COMMON
]
1608 map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1611 def PlatformUsedPcds(self
):
1613 if GlobalData
.gFdfParser
:
1614 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1615 FdfModuleList
= [PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
) for Inf
in FdfInfList
]
1616 AllModulePcds
= set()
1617 ModuleSet
= set(self
._Modules
.keys() + FdfModuleList
)
1618 for ModuleFile
in ModuleSet
:
1619 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
1620 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1621 for ModuleFile
in self
.LibraryInstances
:
1622 ModuleData
= self
._Bdb
.CreateBuildObject(ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
)
1623 AllModulePcds
= AllModulePcds | ModuleData
.PcdsName
1624 return AllModulePcds
1626 #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
1627 def FilterStrcturePcd(self
, S_pcd_set
):
1628 UnusedStruPcds
= set(S_pcd_set
.keys()) - self
.PlatformUsedPcds
1629 for (Token
, TokenSpaceGuid
) in UnusedStruPcds
:
1630 del S_pcd_set
[(Token
, TokenSpaceGuid
)]
1632 ## Retrieve non-dynamic PCD settings
1634 # @param Type PCD type
1636 # @retval a dict object contains settings of given PCD type
1638 def _GetPcd(self
, Type
):
1639 Pcds
= OrderedDict()
1641 # tdict is a special dict kind of type, used for selecting correct
1642 # PCD settings for certain ARCH
1644 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1646 PcdDict
= tdict(True, 4)
1648 # Find out all possible PCD candidates for self._Arch
1649 RecordList
= self
._RawData
[Type
, self
._Arch
]
1650 PcdValueDict
= OrderedDict()
1651 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1652 SkuName
= SkuName
.upper()
1653 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1654 if SkuName
not in AvailableSkuIdSet
:
1655 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1656 File
=self
.MetaFile
, Line
=Dummy5
)
1657 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1658 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
1659 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1660 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1662 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1663 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1666 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1668 if int(MaxDatumSize
, 0) > 0xFFFF:
1669 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1670 File
=self
.MetaFile
, Line
=Dummy4
)
1671 if int(MaxDatumSize
, 0) < 0:
1672 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1673 File
=self
.MetaFile
, Line
=Dummy4
)
1674 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1675 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1677 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1679 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.items():
1680 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1681 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1682 elif TAB_DEFAULT
in PcdSetting
:
1683 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_DEFAULT
]
1684 elif TAB_COMMON
in PcdSetting
:
1685 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_COMMON
]
1691 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1694 self
._PCD
_TYPE
_STRING
_[Type
],
1703 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1704 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1705 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1706 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1707 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1711 def GetStructurePcdMaxSize(str_pcd
):
1712 pcd_default_value
= str_pcd
.DefaultValue
1713 sku_values
= [skuobj
.HiiDefaultValue
if str_pcd
.Type
in [DscBuildData
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], DscBuildData
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]] else skuobj
.DefaultValue
for skuobj
in str_pcd
.SkuInfoList
.values()]
1714 sku_values
.append(pcd_default_value
)
1716 def get_length(value
):
1717 Value
= value
.strip()
1719 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1721 if Value
.startswith('L"') and Value
.endswith('"'):
1722 return len(Value
[2:-1])
1723 if Value
[0] == '"' and Value
[-1] == '"':
1724 return len(Value
) - 2
1725 if Value
.strip().startswith("{CODE("):
1726 tmpValue
= RemoveCComments(Value
)
1727 return len(tmpValue
.split(","))
1728 if (Value
[0] == '{' and Value
[-1] == '}'):
1729 return len(Value
.split(","))
1730 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1731 return len(list(Value
[2:-1]))
1732 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1733 return len(Value
) - 2
1736 return str(max(get_length(item
) for item
in sku_values
))
1739 def ExecuteCommand (Command
):
1741 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1743 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1744 Result
= Process
.communicate()
1745 return Process
.returncode
, Result
[0], Result
[1]
1748 def IntToCString(Value
, ValueSize
):
1750 if not isinstance (Value
, str):
1751 for Index
in range(0, ValueSize
):
1752 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1754 Result
= Result
+ '"'
1757 def GenerateSizeFunction(self
, Pcd
):
1758 CApp
= "// Default Value in Dec \n"
1759 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1761 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
1762 for skuname
in Pcd
.SkuInfoList
:
1763 skuobj
= Pcd
.SkuInfoList
[skuname
]
1764 if skuobj
.VariableName
:
1765 for defaultstore
in skuobj
.DefaultStoreDict
:
1766 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,defaultstore
)
1767 if pcddef
and "{CODE(" in pcddef
:
1768 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
)
1770 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1771 if pcddef
and "{CODE(" in pcddef
:
1772 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
)
1774 pcddef
= self
.GetPcdDscRawDefaultValue(Pcd
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1775 if pcddef
and "{CODE(" in pcddef
:
1776 CApp
+= " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
)
1777 for index
in Pcd
.DefaultValues
:
1778 FieldList
= Pcd
.DefaultValues
[index
]
1781 for FieldName
in FieldList
:
1782 FieldName
= "." + FieldName
1783 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1784 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1786 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1787 except BadExpression
:
1788 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1789 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1790 Value
, ValueSize
= ParseFieldValue(Value
)
1791 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]);
1794 FieldName_ori
= FieldName
.strip('.')
1795 while '[' in FieldName
:
1796 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1797 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1798 FieldName
= FieldName
.split(']', 1)[1]
1799 FieldName
= NewFieldName
+ FieldName
1800 while '[' in FieldName
:
1801 FieldName
= FieldName
.rsplit('[', 1)[0]
1802 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])
1803 for skuname
in Pcd
.SkuOverrideValues
:
1804 if skuname
== TAB_COMMON
:
1806 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1807 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1808 for index
in Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
]:
1809 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
][defaultstorenameitem
][index
]]:
1812 for FieldName
in FieldList
:
1813 FieldName
= "." + FieldName
1814 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1815 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1817 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1818 except BadExpression
:
1819 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1820 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1821 Value
, ValueSize
= ParseFieldValue(Value
)
1822 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]);
1825 FieldName_ori
= FieldName
.strip('.')
1826 while '[' in FieldName
:
1827 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1828 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1829 FieldName
= FieldName
.split(']', 1)[1]
1830 FieldName
= NewFieldName
+ FieldName
1831 while '[' in FieldName
:
1832 FieldName
= FieldName
.rsplit('[', 1)[0]
1833 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])
1834 if Pcd
.PcdFieldValueFromFdf
:
1835 CApp
= CApp
+ "// From fdf \n"
1836 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1837 FieldName
= "." + FieldName
1838 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1839 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1841 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1842 except BadExpression
:
1843 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1844 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1845 Value
, ValueSize
= ParseFieldValue(Value
)
1846 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]);
1849 FieldName_ori
= FieldName
.strip('.')
1850 while '[' in FieldName
:
1851 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1852 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1853 FieldName
= FieldName
.split(']', 1)[1]
1854 FieldName
= NewFieldName
+ FieldName
1855 while '[' in FieldName
:
1856 FieldName
= FieldName
.rsplit('[', 1)[0]
1857 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])
1858 if Pcd
.PcdFieldValueFromComm
:
1859 CApp
= CApp
+ "// From Command Line \n"
1860 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1861 FieldName
= "." + FieldName
1862 IsArray
= _IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1863 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1865 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1866 except BadExpression
:
1867 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1868 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1869 Value
, ValueSize
= ParseFieldValue(Value
)
1870 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]);
1873 FieldName_ori
= FieldName
.strip('.')
1874 while '[' in FieldName
:
1875 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1876 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1877 FieldName
= FieldName
.split(']', 1)[1]
1878 FieldName
= NewFieldName
+ FieldName
1879 while '[' in FieldName
:
1880 FieldName
= FieldName
.rsplit('[', 1)[0]
1881 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])
1882 if Pcd
.GetPcdMaxSize():
1883 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1888 def GenerateSizeStatments(Pcd
,skuname
,defaultstorename
):
1890 r_datatype
= [Pcd
.BaseDatumType
]
1891 lastoneisEmpty
= False
1892 for dem
in Pcd
.Capacity
:
1894 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. " %
1895 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))))
1896 if dem
== '0' or dem
== "-1":
1897 r_datatype
.append("[1]")
1898 lastoneisEmpty
= True
1900 r_datatype
.append("[" + dem
+ "]")
1902 if Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_HII
, MODEL_PCD_DYNAMIC_HII
]:
1903 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultStoreDict
.get(defaultstorename
)
1904 elif Pcd
.Type
in [MODEL_PCD_DYNAMIC_EX_DEFAULT
,MODEL_PCD_DYNAMIC_VPD
,MODEL_PCD_DYNAMIC_DEFAULT
,MODEL_PCD_DYNAMIC_EX_VPD
]:
1905 PcdDefValue
= Pcd
.SkuInfoList
.get(skuname
).DefaultValue
1907 PcdDefValue
= Pcd
.DefaultValue
1909 if "{CODE(" not in PcdDefValue
:
1910 sizebasevalue_plus
= "(%s / sizeof(%s) + 1)" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), "".join(r_datatype
)))
1911 sizebasevalue
= "(%s / sizeof(%s))" % ((DscBuildData
.GetStructurePcdMaxSize(Pcd
), "".join(r_datatype
)))
1912 sizeof
= "sizeof(%s)" % Pcd
.BaseDatumType
1913 CApp
= ' Size = %s %% %s ? %s : %s ;\n' % ( (DscBuildData
.GetStructurePcdMaxSize(Pcd
), sizeof
, sizebasevalue_plus
, sizebasevalue
))
1915 CApp
= " Size = 0;\n"
1917 CApp
= ' Size = sizeof(%s);\n' % ("".join(r_datatype
) )
1919 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1920 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1923 def GetIndicator(self
,index
,FieldName
,Pcd
):
1924 def cleanupindex(indexstr
):
1925 return indexstr
.strip("[").strip("]").strip()
1926 index_elements
= ArrayIndex
.findall(index
)
1927 pcd_capacity
= Pcd
.Capacity
1930 if len(pcd_capacity
)>2:
1931 for i
in xrange(0,len(index_elements
)):
1932 index_ele
= index_elements
[i
]
1933 index_num
= index_ele
.strip("[").strip("]").strip()
1934 if i
== len(index_elements
) -2:
1935 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[i
+1])),Pcd
.BaseDatumType
,reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[:-1]), cleanupindex(index_elements
[i
]))
1938 indicator
+= " + %d*%s*Size/sizeof(%s)/%d" %(int(cleanupindex(index_elements
[i
])),reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[i
+1:-1]),Pcd
.BaseDatumType
,reduce(lambda x
,y
: int(x
)*int(y
),pcd_capacity
[:-1]))
1939 elif len(pcd_capacity
) == 2:
1940 indicator
+= "+ %d*Size/sizeof(%s)/%d + %s)" %(int(cleanupindex(index_elements
[0])),Pcd
.BaseDatumType
,int(pcd_capacity
[0]), index_elements
[1].strip("[").strip("]").strip())
1941 elif len(pcd_capacity
) == 1:
1942 index_ele
= index_elements
[0]
1943 index_num
= index_ele
.strip("[").strip("]").strip()
1944 indicator
+= " + %s)" % (index_num
)
1948 indicator
+= "->" + FieldName
1951 def GetStarNum(self
,Pcd
):
1952 if not Pcd
.IsArray():
1954 elif Pcd
.IsSimpleTypeArray():
1955 return len(Pcd
.Capacity
)
1957 return len(Pcd
.Capacity
) + 1
1958 def GenerateDefaultValueAssignFunction(self
, Pcd
):
1959 CApp
= "// Default value in Dec \n"
1960 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
1961 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1962 CApp
= CApp
+ ' CHAR8 *Value;\n'
1963 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1964 IsArray
= _IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1967 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1968 except BadExpression
:
1969 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1970 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1971 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1972 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1973 if isinstance(Value
, str):
1974 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1977 # Use memcpy() to copy value into field
1979 if "{CODE(" in Pcd
.DefaultValueFromDec
:
1980 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_INIT_Value, sizeof(%s_%s_INIT_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1982 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1983 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1984 for index
in Pcd
.DefaultValues
:
1985 FieldList
= Pcd
.DefaultValues
[index
]
1988 for FieldName
in FieldList
:
1989 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
1992 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1993 except BadExpression
:
1994 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1995 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1998 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2000 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]))
2002 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2003 if isinstance(Value
, str):
2004 CApp
= CApp
+ ' %s = %s; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2007 # Use memcpy() to copy value into field
2009 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
2010 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2011 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])
2012 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2013 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2016 if '[' in FieldName
and ']' in FieldName
:
2017 Index
= int(FieldName
.split('[')[1].split(']')[0])
2018 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
)
2020 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2022 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2027 def GenerateDefaultValueAssignStatement(Pcd
):
2028 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2031 def GetPcdDscRawDefaultValue(self
,Pcd
, SkuName
,DefaultStoreName
):
2032 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2033 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2034 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
2036 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
2038 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
2040 return pcddefaultvalue
2041 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
2042 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
2043 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.BaseDatumType
)
2044 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2045 CApp
= CApp
+ ' CHAR8 *Value;\n'
2047 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2048 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2050 pcddefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, SkuName
, DefaultStoreName
)
2052 FieldList
= pcddefaultvalue
2053 IsArray
= _IsFieldValueAnArray(FieldList
)
2055 if "{CODE(" not in FieldList
:
2057 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2058 except BadExpression
:
2059 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
2060 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2061 Value
, ValueSize
= ParseFieldValue (FieldList
)
2063 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
2064 if isinstance(Value
, str):
2065 if "{CODE(" in Value
:
2066 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2068 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
)
2071 # Use memcpy() to copy value into field
2073 if Pcd
.IsArray() and "{CODE(" in pcddefaultvalue
:
2074 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2076 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
)
2077 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2079 if isinstance(Value
, str):
2080 if "{CODE(" in Value
:
2081 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2083 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2086 # Use memcpy() to copy value into field
2088 if Pcd
.IsArray() and "{CODE(" in pcddefaultvalue
:
2089 CApp
= CApp
+ ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
,Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
, DefaultStoreName
)
2091 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
2092 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2094 inheritvalue
= inherit_OverrideValues
.get(DefaultStoreName
)
2095 if not inheritvalue
:
2097 for index
in inheritvalue
:
2098 FieldList
= inheritvalue
[index
]
2101 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
2102 for FieldName
in FieldList
:
2103 indicator
= self
.GetIndicator(index
, FieldName
,Pcd
)
2104 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2107 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2108 except BadExpression
:
2109 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2110 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2112 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2114 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]))
2115 if isinstance(Value
, str):
2116 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2119 # Use memcpy() to copy value into field
2121 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2122 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2123 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])
2124 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2125 CApp
= CApp
+ ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator
, ValueSize
, ValueSize
)
2127 if '[' in FieldName
and ']' in FieldName
:
2128 Index
= int(FieldName
.split('[')[1].split(']')[0])
2129 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
)
2131 CApp
= CApp
+ ' %s = %dULL; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2133 CApp
= CApp
+ ' %s = %d; // From %s Line %d Value %s\n' % (indicator
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2138 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
2139 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
2142 def GenerateCommandLineValue(self
, Pcd
):
2143 CApp
= "// Value in CommandLine\n"
2144 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.BaseDatumType
)
2145 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2146 CApp
= CApp
+ ' CHAR8 *Value;\n'
2148 pcddefaultvalue
= Pcd
.PcdValueFromComm
2149 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
2152 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2153 IsArray
= _IsFieldValueAnArray(FieldList
)
2156 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2157 except BadExpression
:
2158 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
2159 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2160 Value
, ValueSize
= ParseFieldValue (FieldList
)
2162 if isinstance(Value
, str):
2163 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
2166 # Use memcpy() to copy value into field
2168 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2169 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2171 for FieldName
in FieldList
:
2172 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2175 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2176 except BadExpression
:
2177 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2178 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2182 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2184 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]))
2185 if isinstance(Value
, str):
2186 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2189 # Use memcpy() to copy value into field
2191 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2192 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2193 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])
2194 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2196 if '[' in FieldName
and ']' in FieldName
:
2197 Index
= int(FieldName
.split('[')[1].split(']')[0])
2198 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
)
2200 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2202 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2207 def GenerateCommandLineValueStatement(Pcd
):
2208 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2210 def GenerateFdfValue(self
,Pcd
):
2211 CApp
= "// Value in Fdf\n"
2212 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.BaseDatumType
)
2213 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2214 CApp
= CApp
+ ' CHAR8 *Value;\n'
2216 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2217 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2220 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2221 IsArray
= _IsFieldValueAnArray(FieldList
)
2224 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2225 except BadExpression
:
2226 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2227 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2228 Value
, ValueSize
= ParseFieldValue (FieldList
)
2230 if isinstance(Value
, str):
2231 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2234 # Use memcpy() to copy value into field
2236 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2237 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2239 for FieldName
in FieldList
:
2240 IsArray
= _IsFieldValueAnArray(FieldList
[FieldName
][0])
2243 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2244 except BadExpression
:
2245 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2246 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2250 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2252 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]))
2253 if isinstance(Value
, str):
2254 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2257 # Use memcpy() to copy value into field
2259 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.BaseDatumType
, FieldName
)
2260 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2261 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])
2262 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2264 if '[' in FieldName
and ']' in FieldName
:
2265 Index
= int(FieldName
.split('[')[1].split(']')[0])
2266 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
)
2268 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2270 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2275 def GenerateFdfValueStatement(Pcd
):
2276 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2279 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2280 OverrideValues
= {DefaultStore
:{}}
2281 if Pcd
.SkuOverrideValues
:
2282 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2283 if not OverrideValues
:
2284 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2285 for DefaultStoreName
in OverrideValues
:
2286 CApp
= CApp
+ 'void\n'
2287 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2288 CApp
= CApp
+ ' void\n'
2289 CApp
= CApp
+ ' )\n'
2291 CApp
= CApp
+ ' UINT32 Size;\n'
2292 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2293 CApp
= CApp
+ ' CHAR8 *Value;\n'
2294 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2295 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2297 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.BaseDatumType
,Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2301 PcdDefaultValue
= StringToArray(Pcd
.DefaultValueFromDec
.strip())
2303 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2306 # Get current PCD value and size
2308 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2311 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2312 # the correct value. For structures with a flexible array member, the flexible
2313 # array member is detected, and the size is based on the highest index used with
2314 # the flexible array member. The flexible array member must be the last field
2315 # in a structure. The size formula for this case is:
2316 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2318 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
,SkuName
,DefaultStoreName
)
2321 # Allocate and zero buffer for the PCD
2322 # Must handle cases where current value is smaller, larger, or same size
2323 # Always keep that larger one as the current size
2325 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2326 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.BaseDatumType
,)
2327 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2330 # Copy current PCD value into allocated buffer.
2332 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2335 # Assign field values in PCD
2337 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2338 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2339 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2340 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2341 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2342 for defaultstorenameitem
in storeset
:
2343 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2344 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2345 if skuname
== SkuName
:
2348 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2349 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2350 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2351 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2353 # Set new PCD value and size
2355 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2360 CApp
= CApp
+ ' free (Pcd);\n'
2363 return InitByteValue
, CApp
2365 def GenerateArrayAssignment(self
, Pcd
):
2369 if not Pcd
.IsArray():
2372 for d
in Pcd
.Capacity
:
2375 Value
= Pcd
.DefaultValueFromDec
2376 if "{CODE(" in Pcd
.DefaultValueFromDec
:
2377 realvalue
= Pcd
.DefaultValueFromDec
.strip()[6:-2] # "{CODE(").rstrip(")}"
2378 CApp
+= "static %s %s_%s_INIT_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2380 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET
:
2381 for skuname
in Pcd
.SkuInfoList
:
2382 skuinfo
= Pcd
.SkuInfoList
[skuname
]
2383 if skuinfo
.VariableName
:
2384 for defaultstore
in skuinfo
.DefaultStoreDict
:
2385 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, defaultstore
)
2386 if pcddscrawdefaultvalue
:
2387 Value
= skuinfo
[defaultstore
]
2388 if "{CODE(" in Value
:
2389 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2390 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,defaultstore
,Demesion
,realvalue
)
2392 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, skuname
, TAB_DEFAULT_STORES_DEFAULT
)
2393 if pcddscrawdefaultvalue
:
2394 Value
= skuinfo
.DefaultValue
2395 if "{CODE(" in Value
:
2396 realvalue
= Value
.strip()[6:-2] # "{CODE(").rstrip(")}"
2397 CApp
+= "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,skuname
,TAB_DEFAULT_STORES_DEFAULT
,Demesion
,realvalue
)
2399 pcddscrawdefaultvalue
= self
.GetPcdDscRawDefaultValue(Pcd
, TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
2400 if pcddscrawdefaultvalue
:
2401 if "{CODE(" in Pcd
.DefaultValue
:
2402 realvalue
= Pcd
.DefaultValue
.strip()[6:-2] # "{CODE(").rstrip(")}"
2403 CApp
+= "static %s %s_%s_DEFAULT_STANDARD_Value%s = %s;\n" % (Pcd
.BaseDatumType
,Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
,Demesion
,realvalue
)
2407 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2408 if not OverrideValues
:
2410 for key
in OverrideValues
:
2411 if OverrideValues
[key
]:
2415 def ParseCCFlags(self
, ccflag
):
2417 ccflaglist
= ccflag
.split(" ")
2419 while i
< len(ccflaglist
):
2420 item
= ccflaglist
[i
].strip()
2421 if item
in (r
"/D", r
"/U","-D","-U"):
2422 ccflags
.add(" ".join((ccflaglist
[i
],ccflaglist
[i
+1])))
2424 elif item
.startswith((r
"/D", r
"/U","-D","-U")):
2428 def GenerateByteArrayValue (self
, StructuredPcds
):
2430 # Generate/Compile/Run C application to determine if there are any flexible array members
2432 if not StructuredPcds
:
2436 CApp
= PcdMainCHeader
2438 IncludeFiles
= set()
2439 for PcdName
in StructuredPcds
:
2440 Pcd
= StructuredPcds
[PcdName
]
2441 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2442 if IncludeFile
not in IncludeFiles
:
2443 IncludeFiles
.add(IncludeFile
)
2444 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2446 for Pcd
in StructuredPcds
.values():
2447 CApp
= CApp
+ self
.GenerateArrayAssignment(Pcd
)
2448 for PcdName
in StructuredPcds
:
2449 Pcd
= StructuredPcds
[PcdName
]
2450 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2451 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2452 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2453 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2454 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2455 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2456 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2458 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2459 if SkuName
not in Pcd
.SkuOverrideValues
:
2461 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2462 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2463 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2464 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2465 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2467 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2468 if SkuName
not in Pcd
.SkuOverrideValues
:
2470 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2471 Pcd
= StructuredPcds
[PcdName
]
2472 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2474 CApp
= CApp
+ 'VOID\n'
2475 CApp
= CApp
+ 'PcdEntryPoint(\n'
2476 CApp
= CApp
+ ' VOID\n'
2477 CApp
= CApp
+ ' )\n'
2479 for Pcd
in StructuredPcds
.values():
2480 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
]]:
2481 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2483 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2484 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2486 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2487 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2490 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2492 if not os
.path
.exists(self
.OutputPath
):
2493 os
.makedirs(self
.OutputPath
)
2494 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2495 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2497 MakeApp
= PcdMakefileHeader
2498 if sys
.platform
== "win32":
2499 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2501 MakeApp
= MakeApp
+ PcdGccMakefile
2502 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2503 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2506 PlatformInc
= OrderedDict()
2507 for Cache
in self
._Bdb
._CACHE
_.values():
2508 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2511 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2512 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2513 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2514 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2517 for Pcd
in StructuredPcds
.values():
2518 for PackageDec
in Pcd
.PackageDecs
:
2519 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2520 if not os
.path
.exists(Package
):
2521 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2522 if Package
not in PcdDependDEC
:
2523 PcdDependDEC
.append(Package
)
2525 if PlatformInc
and PcdDependDEC
:
2526 for pkg
in PcdDependDEC
:
2527 if pkg
in PlatformInc
:
2528 for inc
in PlatformInc
[pkg
]:
2529 MakeApp
+= '-I' + str(inc
) + ' '
2530 IncSearchList
.append(inc
)
2531 MakeApp
= MakeApp
+ '\n'
2533 CC_FLAGS
= LinuxCFLAGS
2534 if sys
.platform
== "win32":
2535 CC_FLAGS
= WindowsCFLAGS
2536 BuildOptions
= OrderedDict()
2537 for Options
in self
.BuildOptions
:
2538 if Options
[2] != EDKII_NAME
:
2541 if Family
and Family
!= self
.ToolChainFamily
:
2543 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2548 if Target
== TAB_STAR
or Target
== self
._Target
:
2549 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2550 if 'COMMON' not in BuildOptions
:
2551 BuildOptions
['COMMON'] = set()
2552 if Arch
== TAB_STAR
:
2553 BuildOptions
['COMMON']|
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2554 if Arch
in self
.SupArchList
:
2555 if Arch
not in BuildOptions
:
2556 BuildOptions
[Arch
] = set()
2557 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2560 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2561 if len(ArchBuildOptions
.keys()) == 1:
2562 BuildOptions
['COMMON'] |
= (ArchBuildOptions
.values()[0])
2563 elif len(ArchBuildOptions
.keys()) > 1:
2564 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2565 BuildOptions
['COMMON'] |
= CommonBuildOptions
2566 ValueList
= list(BuildOptions
['COMMON'])
2567 CC_FLAGS
+= " ".join(ValueList
)
2570 if sys
.platform
== "win32":
2571 MakeApp
= MakeApp
+ PcdMakefileEnd
2572 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2574 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2575 MakeApp
= MakeApp
+ '\n'
2576 IncludeFileFullPaths
= []
2577 for includefile
in IncludeFiles
:
2578 for includepath
in IncSearchList
:
2579 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2580 if os
.path
.exists(includefullpath
):
2581 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2584 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2585 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2586 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2587 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2588 for include_file
in IncFileList
:
2589 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2590 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2591 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2592 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2594 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2595 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2596 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2598 Dest_PcdValueInitExe
= PcdValueInitName
2599 if not sys
.platform
== "win32":
2600 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2602 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2604 if sys
.platform
== "win32":
2605 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2606 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2609 MakeCommand
= 'make -f %s' % (MakeFileName
)
2610 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2613 Messages
= Messages
.split('\n')
2616 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2617 File
= open (CAppBaseFileName
+ '.c', 'r')
2618 FileData
= File
.readlines()
2620 for Message
in Messages
:
2621 if " error" in Message
or "warning" in Message
:
2622 FileInfo
= Message
.strip().split('(')
2623 if len (FileInfo
) > 1:
2624 FileName
= FileInfo
[0]
2625 FileLine
= FileInfo
[1].split (')')[0]
2627 FileInfo
= Message
.strip().split(':')
2628 if len(FileInfo
) < 2:
2630 FileName
= FileInfo
[0]
2631 FileLine
= FileInfo
[1]
2632 if FileLine
.isdigit():
2633 error_line
= FileData
[int (FileLine
) - 1]
2634 if r
"//" in error_line
:
2635 c_line
, dsc_line
= error_line
.split(r
"//")
2637 dsc_line
= error_line
2638 message_itmes
= Message
.split(":")
2640 if "PcdValueInit.c" not in Message
:
2641 if not MessageGroup
:
2642 MessageGroup
.append(Message
)
2645 for item
in message_itmes
:
2646 if "PcdValueInit.c" in item
:
2647 Index
= message_itmes
.index(item
)
2648 message_itmes
[Index
] = dsc_line
.strip()
2650 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2653 MessageGroup
.append(Message
)
2655 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2657 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2659 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
2660 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2661 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2663 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2665 File
= open (OutputValueFile
, 'r')
2666 FileBuffer
= File
.readlines()
2669 StructurePcdSet
= []
2670 for Pcd
in FileBuffer
:
2671 PcdValue
= Pcd
.split ('|')
2672 PcdInfo
= PcdValue
[0].split ('.')
2673 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2674 return StructurePcdSet
2677 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2678 if not os
.path
.exists(OutputFile
):
2680 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2682 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2686 ## Retrieve dynamic PCD settings
2688 # @param Type PCD type
2690 # @retval a dict object contains settings of given PCD type
2692 def _GetDynamicPcd(self
, Type
):
2695 Pcds
= OrderedDict()
2697 # tdict is a special dict kind of type, used for selecting correct
2698 # PCD settings for certain ARCH and SKU
2700 PcdDict
= tdict(True, 4)
2702 # Find out all possible PCD candidates for self._Arch
2703 RecordList
= self
._RawData
[Type
, self
._Arch
]
2704 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2707 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2708 SkuName
= SkuName
.upper()
2709 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2710 if SkuName
not in AvailableSkuIdSet
:
2711 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2712 File
=self
.MetaFile
, Line
=Dummy5
)
2713 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2714 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2715 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2717 # Remove redundant PCD candidates, per the ARCH and SKU
2718 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2720 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2724 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2726 if int(MaxDatumSize
, 0) > 0xFFFF:
2727 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2728 File
=self
.MetaFile
, Line
=Dummy4
)
2729 if int(MaxDatumSize
, 0) < 0:
2730 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2731 File
=self
.MetaFile
, Line
=Dummy4
)
2732 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2733 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2734 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2735 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2736 if MaxDatumSize
.strip():
2737 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2740 if pcdObject
.MaxDatumSize
:
2741 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2744 if CurrentMaxSize
> PcdMaxSize
:
2745 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2747 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2750 self
._PCD
_TYPE
_STRING
_[Type
],
2755 OrderedDict({SkuName
: SkuInfo
}),
2760 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2761 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2762 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2764 for pcd
in Pcds
.values():
2765 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2766 # Only fix the value while no value provided in DSC file.
2767 for sku
in pcd
.SkuInfoList
.values():
2768 if not sku
.DefaultValue
:
2769 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2770 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2771 valuefromDec
= pcdDecObject
.DefaultValue
2772 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2773 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2774 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2775 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2776 del pcd
.SkuInfoList
[TAB_COMMON
]
2777 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2778 del pcd
.SkuInfoList
[TAB_COMMON
]
2780 map(self
.FilterSkuSettings
, Pcds
.values())
2784 def FilterSkuSettings(self
, PcdObj
):
2786 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2787 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2788 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2789 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2790 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2791 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2793 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2794 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2799 def CompareVarAttr(Attr1
, Attr2
):
2800 if not Attr1
or not Attr2
: # for empty string
2802 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2803 Attr1Set
= set(Attr1s
)
2804 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2805 Attr2Set
= set(Attr2s
)
2806 if Attr2Set
== Attr1Set
:
2811 def CompletePcdValues(self
, PcdSet
):
2812 Pcds
= OrderedDict()
2813 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2814 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2815 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2816 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2817 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2819 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2820 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2821 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2822 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2823 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2824 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2825 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2827 PcdType
= PcdObj
.Type
2828 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2829 for skuid
in PcdObj
.SkuInfoList
:
2830 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2831 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2832 for defaultstorename
in DefaultStores
:
2833 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2834 skuobj
.DefaultStoreDict
[defaultstorename
] = skuobj
.DefaultStoreDict
[mindefaultstorename
]
2835 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2836 for skuname
, skuid
in SkuIds
.items():
2837 if skuname
not in PcdObj
.SkuInfoList
:
2838 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2839 while nextskuid
not in PcdObj
.SkuInfoList
:
2840 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2841 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2842 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2843 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2844 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2845 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2846 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2848 ## Retrieve dynamic HII PCD settings
2850 # @param Type PCD type
2852 # @retval a dict object contains settings of given PCD type
2854 def _GetDynamicHiiPcd(self
, Type
):
2858 Pcds
= OrderedDict()
2859 UserDefinedDefaultStores
= []
2861 # tdict is a special dict kind of type, used for selecting correct
2862 # PCD settings for certain ARCH and SKU
2864 PcdDict
= tdict(True, 5)
2866 RecordList
= self
._RawData
[Type
, self
._Arch
]
2867 # Find out all possible PCD candidates for self._Arch
2868 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2869 DefaultStoresDefine
= self
._GetDefaultStores
()
2871 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
2872 SkuName
= SkuName
.upper()
2873 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2874 DefaultStore
= DefaultStore
.upper()
2875 if DefaultStore
== TAB_COMMON
:
2876 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2878 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
2879 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
2880 if SkuName
not in AvailableSkuIdSet
:
2881 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2882 File
=self
.MetaFile
, Line
=Dummy5
)
2883 if DefaultStore
not in DefaultStoresDefine
:
2884 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2885 File
=self
.MetaFile
, Line
=Dummy5
)
2886 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
2887 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
2888 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
2891 # Remove redundant PCD candidates, per the ARCH and SKU
2892 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdSet
:
2894 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
2897 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2899 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2901 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2902 ExtraData
="[%s]" % VarAttribute
)
2904 FormatCorrect
= True
2905 if VariableOffset
.isdigit():
2906 if int(VariableOffset
, 10) > 0xFFFF:
2908 elif variablePattern
.match(VariableOffset
):
2909 if int(VariableOffset
, 16) > 0xFFFF:
2911 # For Offset written in "A.B"
2912 elif VariableOffset
.find('.') > -1:
2913 VariableOffsetList
= VariableOffset
.split(".")
2914 if not (len(VariableOffsetList
) == 2
2915 and IsValidWord(VariableOffsetList
[0])
2916 and IsValidWord(VariableOffsetList
[1])):
2917 FormatCorrect
= False
2919 FormatCorrect
= False
2920 if not FormatCorrect
:
2921 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2924 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2925 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2926 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2928 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2929 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
)]))
2931 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2932 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2933 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2934 if SkuName
in pcdObject
.SkuInfoList
:
2935 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2936 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2938 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2939 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2941 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2942 PcdClassObj
= PcdClassObject(
2945 self
._PCD
_TYPE
_STRING
_[Type
],
2950 OrderedDict({SkuName
: SkuInfo
}),
2953 pcdDecObject
.validateranges
,
2954 pcdDecObject
.validlists
,
2955 pcdDecObject
.expressions
,
2957 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
2958 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
2959 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
2961 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
2962 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2963 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2964 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
2965 for pcd
in Pcds
.values():
2966 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2967 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2968 pcd
.DatumType
= pcdDecObject
.DatumType
2969 # Only fix the value while no value provided in DSC file.
2970 for sku
in pcd
.SkuInfoList
.values():
2971 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2972 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2973 for default_store
in sku
.DefaultStoreDict
:
2974 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2975 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2976 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2977 valuefromDec
= pcdDecObject
.DefaultValue
2978 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
2979 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2980 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2981 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2982 del pcd
.SkuInfoList
[TAB_COMMON
]
2983 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2984 del pcd
.SkuInfoList
[TAB_COMMON
]
2986 if pcd
.MaxDatumSize
.strip():
2987 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2990 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
2991 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2993 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2994 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2995 if datalen
> MaxSize
:
2997 for defaultst
in skuobj
.DefaultStoreDict
:
2998 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2999 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
3000 pcd
.MaxDatumSize
= str(MaxSize
)
3001 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
3003 invalidpcd
= ",".join(invalidhii
)
3004 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
)
3006 map(self
.FilterSkuSettings
, Pcds
.values())
3011 def CheckVariableNameAssignment(Pcds
):
3013 for pcdname
in Pcds
:
3015 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
3016 if len(varnameset
) > 1:
3017 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
3019 return False, invalidhii
3022 ## Retrieve dynamic VPD PCD settings
3024 # @param Type PCD type
3026 # @retval a dict object contains settings of given PCD type
3028 def _GetDynamicVpdPcd(self
, Type
):
3031 Pcds
= OrderedDict()
3033 # tdict is a special dict kind of type, used for selecting correct
3034 # PCD settings for certain ARCH and SKU
3036 PcdDict
= tdict(True, 4)
3039 # Find out all possible PCD candidates for self._Arch
3040 RecordList
= self
._RawData
[Type
, self
._Arch
]
3041 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
3043 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
3044 SkuName
= SkuName
.upper()
3045 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
3046 if SkuName
not in AvailableSkuIdSet
:
3047 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
3048 File
=self
.MetaFile
, Line
=Dummy5
)
3049 if "." not in TokenSpaceGuid
and "[" not in PcdCName
:
3050 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
3051 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
3053 # Remove redundant PCD candidates, per the ARCH and SKU
3054 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
3055 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
3059 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
3060 # For the Integer & Boolean type, the optional data can only be InitialValue.
3061 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
3062 # until the DEC parser has been called.
3064 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
3066 if int(MaxDatumSize
, 0) > 0xFFFF:
3067 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3068 File
=self
.MetaFile
, Line
=Dummy4
)
3069 if int(MaxDatumSize
, 0) < 0:
3070 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
3071 File
=self
.MetaFile
, Line
=Dummy4
)
3072 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
3073 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
3074 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
3075 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
3076 if MaxDatumSize
.strip():
3077 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
3080 if pcdObject
.MaxDatumSize
:
3081 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
3084 if CurrentMaxSize
> PcdMaxSize
:
3085 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
3087 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
3090 self
._PCD
_TYPE
_STRING
_[Type
],
3095 OrderedDict({SkuName
: SkuInfo
}),
3100 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
3101 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
3102 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
3103 for pcd
in Pcds
.values():
3104 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
3105 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
3106 pcd
.DatumType
= pcdDecObject
.DatumType
3107 # Only fix the value while no value provided in DSC file.
3108 for sku
in pcd
.SkuInfoList
.values():
3109 if not sku
.DefaultValue
:
3110 sku
.DefaultValue
= pcdDecObject
.DefaultValue
3111 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
3112 valuefromDec
= pcdDecObject
.DefaultValue
3113 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
3114 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
3115 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3116 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
3117 del pcd
.SkuInfoList
[TAB_COMMON
]
3118 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
3119 del pcd
.SkuInfoList
[TAB_COMMON
]
3121 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
3122 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
3123 for pcd
in Pcds
.values():
3124 PcdValueTypeSet
= set()
3125 for sku
in pcd
.SkuInfoList
.values():
3126 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
3127 if len(PcdValueTypeSet
) > 1:
3128 for sku
in pcd
.SkuInfoList
.values():
3129 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
3131 map(self
.FilterSkuSettings
, Pcds
.values())
3134 ## Add external modules
3136 # The external modules are mostly those listed in FDF file, which don't
3139 # @param FilePath The path of module description file
3141 def AddModule(self
, FilePath
):
3142 FilePath
= NormPath(FilePath
)
3143 if FilePath
not in self
.Modules
:
3144 Module
= ModuleBuildClassObject()
3145 Module
.MetaFile
= FilePath
3146 self
.Modules
.append(Module
)
3149 def ToolChainFamily(self
):
3150 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3151 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
3152 if os
.path
.isfile(BuildConfigurationFile
) == True:
3153 TargetTxt
= TargetTxtClassObject()
3154 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
3155 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
3156 if ToolDefinitionFile
== '':
3157 ToolDefinitionFile
= "tools_def.txt"
3158 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
3159 if os
.path
.isfile(ToolDefinitionFile
) == True:
3160 ToolDef
= ToolDefClassObject()
3161 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
3162 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
3163 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
3164 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
3165 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
3166 self
._ToolChainFamily
= TAB_COMPILER_MSFT
3168 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
3169 return self
._ToolChainFamily
3171 ## Add external PCDs
3173 # The external PCDs are mostly those listed in FDF file to specify address
3174 # or offset information.
3176 # @param Name Name of the PCD
3177 # @param Guid Token space guid of the PCD
3178 # @param Value Value of the PCD
3180 def AddPcd(self
, Name
, Guid
, Value
):
3181 if (Name
, Guid
) not in self
.Pcds
:
3182 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
3183 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
3187 if self
._DecPcds
is None:
3189 if GlobalData
.gFdfParser
:
3190 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
3192 for Inf
in FdfInfList
:
3193 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
3194 if ModuleFile
in self
._Modules
:
3196 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
3197 PkgSet
.update(ModuleData
.Packages
)
3198 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
3199 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
3200 return self
._DecPcds