2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 ## Platform build information from DSC file
17 # This class is used to retrieve information stored in database and convert them
18 # into PlatformBuildClassObject form for easier use for AutoGen.
20 from __future__
import print_function
21 from __future__
import absolute_import
22 from Common
.StringUtils
import *
23 from Common
.DataType
import *
24 from Common
.Misc
import *
26 from Common
.Expression
import *
27 from CommonDataClass
.CommonClass
import SkuInfoClass
28 from Common
.TargetTxtClassObject
import *
29 from Common
.ToolDefClassObject
import *
30 from .MetaDataTable
import *
31 from .MetaFileTable
import *
32 from .MetaFileParser
import *
34 from .WorkspaceCommon
import GetDeclaredPcd
35 from Common
.Misc
import AnalyzeDscPcd
36 from Common
.Misc
import ProcessDuplicatedInf
38 from Common
.Parsing
import IsValidWord
39 from Common
.VariableAttributes
import VariableAttributes
40 import Common
.GlobalData
as GlobalData
42 from Common
.Misc
import SaveFileOnChange
43 from Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
44 from collections
import OrderedDict
, defaultdict
46 PcdValueInitName
= 'PcdValueInit'
57 #include <PcdValueCommon.h>
67 return PcdValueMain (argc, argv);
71 PcdMakefileHeader
= '''
74 # This file is auto-generated by build utility
79 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
80 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
82 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
84 LIBS = $(LIB_PATH)\Common.lib
86 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
91 $(APPFILE): $(OBJECTS)
96 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
100 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
101 SkuIdPattern
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*$')
102 ## regular expressions for finding decimal and hex numbers
103 Pattern
= re
.compile('^[1-9]\d*|0$')
104 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
105 ## Regular expression for finding header file inclusions
106 from AutoGen
.GenMake
import gIncludePattern
108 ## Find dependencies for one source file
110 # By searching recursively "#include" directive in file, find out all the
111 # files needed by given source file. The dependecies will be only searched
112 # in given search path list.
114 # @param SearchPathList The list of search path
116 # @retval list The list of files the given source file depends on
118 def GetDependencyList(FileStack
, SearchPathList
):
120 DependencySet
= set(FileStack
)
121 while len(FileStack
) > 0:
123 FullPathDependList
= []
124 CurrentFileDependencyList
= []
126 CurrentFileDependencyList
= DepDb
[F
]
130 FileContent
= Fd
.read()
131 except BaseException
as X
:
132 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
134 if "Fd" in dir(locals()):
137 if len(FileContent
) == 0:
140 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
141 FileContent
= unicode(FileContent
, "utf-16")
142 IncludedFileList
= gIncludePattern
.findall(FileContent
)
144 for Inc
in IncludedFileList
:
146 Inc
= os
.path
.normpath(Inc
)
147 CurrentFileDependencyList
.append(Inc
)
148 DepDb
[F
] = CurrentFileDependencyList
150 CurrentFilePath
= os
.path
.dirname(F
)
151 PathList
= [CurrentFilePath
] + SearchPathList
152 for Inc
in CurrentFileDependencyList
:
153 for SearchPath
in PathList
:
154 FilePath
= os
.path
.join(SearchPath
, Inc
)
155 if not os
.path
.exists(FilePath
):
157 if FilePath
not in DependencySet
:
158 FileStack
.append(FilePath
)
159 FullPathDependList
.append(FilePath
)
161 DependencySet
.update(FullPathDependList
)
162 DependencyList
= list(DependencySet
) # remove duplicate ones
164 return DependencyList
166 class DscBuildData(PlatformBuildClassObject
):
167 # dict used to convert PCD type in database to string used by build tool
168 _PCD_TYPE_STRING_
= {
169 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
170 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
171 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
172 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
173 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
174 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
175 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
176 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
177 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
178 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
179 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
182 # dict used to convert part of [Defines] to members of DscBuildData directly
187 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
188 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
189 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
190 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
191 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
192 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
193 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
194 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
195 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
196 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
197 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
198 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
199 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
200 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
201 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
204 # used to compose dummy library class name for those forced library instances
205 _NullLibraryNumber
= 0
207 ## Constructor of DscBuildData
209 # Initialize object of DscBuildData
211 # @param FilePath The path of platform description file
212 # @param RawData The raw data of DSC file
213 # @param BuildDataBase Database used to retrieve module/package information
214 # @param Arch The target architecture
215 # @param Platform (not used for DscBuildData)
216 # @param Macros Macros used for replacement in DSC file
218 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
219 self
.MetaFile
= FilePath
220 self
._RawData
= RawData
221 self
._Bdb
= BuildDataBase
223 self
._Target
= Target
224 self
._Toolchain
= Toolchain
225 self
._ToolChainFamily
= None
227 self
._HandleOverridePath
()
228 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
229 self
.DefaultStores
= None
230 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
233 def OutputPath(self
):
234 if os
.getenv("WORKSPACE"):
235 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
, PcdValueInitName
)
237 return os
.path
.dirname(self
.DscFile
)
240 def __setitem__(self
, key
, value
):
241 self
.__dict
__[self
._PROPERTY
_[key
]] = value
244 def __getitem__(self
, key
):
245 return self
.__dict
__[self
._PROPERTY
_[key
]]
248 def __contains__(self
, key
):
249 return key
in self
._PROPERTY
_
251 ## Set all internal used members of DscBuildData to None
254 self
._PlatformName
= None
257 self
._DscSpecification
= None
258 self
._OutputDirectory
= None
259 self
._SupArchList
= None
260 self
._BuildTargets
= None
262 self
._PcdInfoFlag
= None
263 self
._VarCheckFlag
= None
264 self
._FlashDefinition
= None
265 self
._Prebuild
= None
266 self
._Postbuild
= None
267 self
._BuildNumber
= None
268 self
._MakefileName
= None
269 self
._BsBaseAddress
= None
270 self
._RtBaseAddress
= None
273 self
._LibraryInstances
= None
274 self
._LibraryClasses
= None
277 self
._BuildOptions
= None
278 self
._ModuleTypeOptions
= None
279 self
._LoadFixAddress
= None
280 self
._RFCLanguages
= None
281 self
._ISOLanguages
= None
282 self
._VpdToolGuid
= None
283 self
._MacroDict
= None
284 self
.DefaultStores
= None
286 ## handle Override Path of Module
287 def _HandleOverridePath(self
):
288 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
289 for Record
in RecordList
:
292 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
293 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
295 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
297 # Check if the source override path exists
298 if not os
.path
.isdir(SourceOverridePath
):
299 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
301 # Add to GlobalData Variables
302 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
304 ## Get current effective macros
307 if self
._MacroDict
is None:
309 self
._MacroDict
.update(GlobalData
.gPlatformDefines
)
310 self
._MacroDict
.update(GlobalData
.gGlobalDefines
)
311 self
._MacroDict
.update(GlobalData
.gCommandLineDefines
)
312 return self
._MacroDict
319 ## Retrieve all information in [Defines] section
321 # (Retriving all [Defines] information in one-shot is just to save time.)
323 def _GetHeaderInfo(self
):
324 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
325 for Record
in RecordList
:
327 # items defined _PROPERTY_ don't need additional processing
329 # some special items in [Defines] section need special treatment
330 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
331 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
332 if ' ' in self
._OutputDirectory
:
333 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
334 File
=self
.MetaFile
, Line
=Record
[-1],
335 ExtraData
=self
._OutputDirectory
)
336 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
337 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
338 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
340 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
342 elif Name
== TAB_DSC_PREBUILD
:
343 PrebuildValue
= Record
[2]
344 if Record
[2][0] == '"':
345 if Record
[2][-1] != '"':
346 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
347 File
=self
.MetaFile
, Line
=Record
[-1])
348 PrebuildValue
= Record
[2][1:-1]
349 self
._Prebuild
= PrebuildValue
350 elif Name
== TAB_DSC_POSTBUILD
:
351 PostbuildValue
= Record
[2]
352 if Record
[2][0] == '"':
353 if Record
[2][-1] != '"':
354 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
355 File
=self
.MetaFile
, Line
=Record
[-1])
356 PostbuildValue
= Record
[2][1:-1]
357 self
._Postbuild
= PostbuildValue
358 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
359 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
360 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
361 self
._BuildTargets
= GetSplitValueList(Record
[2])
362 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
363 if self
._SkuName
is None:
364 self
._SkuName
= Record
[2]
365 if GlobalData
.gSKUID_CMD
:
366 self
._SkuName
= GlobalData
.gSKUID_CMD
367 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
368 self
._PcdInfoFlag
= Record
[2]
369 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
370 self
._VarCheckFlag
= Record
[2]
371 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
373 self
._LoadFixAddress
= int (Record
[2], 0)
375 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
376 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
377 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
378 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"',
379 File
=self
.MetaFile
, Line
=Record
[-1])
380 LanguageCodes
= Record
[2][1:-1]
381 if not LanguageCodes
:
382 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
383 File
=self
.MetaFile
, Line
=Record
[-1])
384 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
385 # check whether there is empty entries in the list
386 if None in LanguageList
:
387 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
388 File
=self
.MetaFile
, Line
=Record
[-1])
389 self
._RFCLanguages
= LanguageList
390 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
391 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
392 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
393 File
=self
.MetaFile
, Line
=Record
[-1])
394 LanguageCodes
= Record
[2][1:-1]
395 if not LanguageCodes
:
396 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
397 File
=self
.MetaFile
, Line
=Record
[-1])
398 if len(LanguageCodes
) % 3:
399 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
400 File
=self
.MetaFile
, Line
=Record
[-1])
402 for i
in range(0, len(LanguageCodes
), 3):
403 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
404 self
._ISOLanguages
= LanguageList
405 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
407 # try to convert GUID to a real UUID value to see whether the GUID is format
408 # for VPD_TOOL_GUID is correct.
413 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
414 self
._VpdToolGuid
= Record
[2]
416 self
[Name
] = Record
[2]
417 # set _Header to non-None in order to avoid database re-querying
418 self
._Header
= 'DUMMY'
420 ## Retrieve platform name
422 def PlatformName(self
):
423 if self
._PlatformName
is None:
424 if self
._Header
is None:
425 self
._GetHeaderInfo
()
426 if self
._PlatformName
is None:
427 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
428 return self
._PlatformName
432 return self
.PlatformName
434 ## Retrieve file guid
437 if self
._Guid
is None:
438 if self
._Header
is None:
439 self
._GetHeaderInfo
()
440 if self
._Guid
is None:
441 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
444 ## Retrieve platform version
447 if self
._Version
is None:
448 if self
._Header
is None:
449 self
._GetHeaderInfo
()
450 if self
._Version
is None:
451 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
454 ## Retrieve platform description file version
456 def DscSpecification(self
):
457 if self
._DscSpecification
is None:
458 if self
._Header
is None:
459 self
._GetHeaderInfo
()
460 if self
._DscSpecification
is None:
461 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
462 return self
._DscSpecification
464 ## Retrieve OUTPUT_DIRECTORY
466 def OutputDirectory(self
):
467 if self
._OutputDirectory
is None:
468 if self
._Header
is None:
469 self
._GetHeaderInfo
()
470 if self
._OutputDirectory
is None:
471 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
472 return self
._OutputDirectory
474 ## Retrieve SUPPORTED_ARCHITECTURES
476 def SupArchList(self
):
477 if self
._SupArchList
is None:
478 if self
._Header
is None:
479 self
._GetHeaderInfo
()
480 if self
._SupArchList
is None:
481 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
482 return self
._SupArchList
484 ## Retrieve BUILD_TARGETS
486 def BuildTargets(self
):
487 if self
._BuildTargets
is None:
488 if self
._Header
is None:
489 self
._GetHeaderInfo
()
490 if self
._BuildTargets
is None:
491 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
492 return self
._BuildTargets
495 def PcdInfoFlag(self
):
496 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
498 elif self
._PcdInfoFlag
.upper() == 'TRUE':
504 def VarCheckFlag(self
):
505 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
507 elif self
._VarCheckFlag
.upper() == 'TRUE':
512 # # Retrieve SKUID_IDENTIFIER
515 if self
._SkuName
is None:
516 if self
._Header
is None:
517 self
._GetHeaderInfo
()
518 if self
._SkuName
is None:
519 self
._SkuName
= TAB_DEFAULT
522 ## Override SKUID_IDENTIFIER
524 def SkuName(self
, Value
):
525 self
._SkuName
= Value
528 def FlashDefinition(self
):
529 if self
._FlashDefinition
is None:
530 if self
._Header
is None:
531 self
._GetHeaderInfo
()
532 if self
._FlashDefinition
is None:
533 self
._FlashDefinition
= ''
534 return self
._FlashDefinition
538 if self
._Prebuild
is None:
539 if self
._Header
is None:
540 self
._GetHeaderInfo
()
541 if self
._Prebuild
is None:
543 return self
._Prebuild
547 if self
._Postbuild
is None:
548 if self
._Header
is None:
549 self
._GetHeaderInfo
()
550 if self
._Postbuild
is None:
552 return self
._Postbuild
554 ## Retrieve FLASH_DEFINITION
556 def BuildNumber(self
):
557 if self
._BuildNumber
is None:
558 if self
._Header
is None:
559 self
._GetHeaderInfo
()
560 if self
._BuildNumber
is None:
561 self
._BuildNumber
= ''
562 return self
._BuildNumber
564 ## Retrieve MAKEFILE_NAME
566 def MakefileName(self
):
567 if self
._MakefileName
is None:
568 if self
._Header
is None:
569 self
._GetHeaderInfo
()
570 if self
._MakefileName
is None:
571 self
._MakefileName
= ''
572 return self
._MakefileName
574 ## Retrieve BsBaseAddress
576 def BsBaseAddress(self
):
577 if self
._BsBaseAddress
is None:
578 if self
._Header
is None:
579 self
._GetHeaderInfo
()
580 if self
._BsBaseAddress
is None:
581 self
._BsBaseAddress
= ''
582 return self
._BsBaseAddress
584 ## Retrieve RtBaseAddress
586 def RtBaseAddress(self
):
587 if self
._RtBaseAddress
is None:
588 if self
._Header
is None:
589 self
._GetHeaderInfo
()
590 if self
._RtBaseAddress
is None:
591 self
._RtBaseAddress
= ''
592 return self
._RtBaseAddress
594 ## Retrieve the top address for the load fix address
596 def LoadFixAddress(self
):
597 if self
._LoadFixAddress
is None:
598 if self
._Header
is None:
599 self
._GetHeaderInfo
()
601 if self
._LoadFixAddress
is None:
602 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
605 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
607 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
610 # If command line defined, should override the value in DSC file.
612 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
614 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
616 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']))
618 if self
._LoadFixAddress
< 0:
619 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
620 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
621 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
623 return self
._LoadFixAddress
625 ## Retrieve RFCLanguage filter
627 def RFCLanguages(self
):
628 if self
._RFCLanguages
is None:
629 if self
._Header
is None:
630 self
._GetHeaderInfo
()
631 if self
._RFCLanguages
is None:
632 self
._RFCLanguages
= []
633 return self
._RFCLanguages
635 ## Retrieve ISOLanguage filter
637 def ISOLanguages(self
):
638 if self
._ISOLanguages
is None:
639 if self
._Header
is None:
640 self
._GetHeaderInfo
()
641 if self
._ISOLanguages
is None:
642 self
._ISOLanguages
= []
643 return self
._ISOLanguages
645 ## Retrieve the GUID string for VPD tool
647 def VpdToolGuid(self
):
648 if self
._VpdToolGuid
is None:
649 if self
._Header
is None:
650 self
._GetHeaderInfo
()
651 if self
._VpdToolGuid
is None:
652 self
._VpdToolGuid
= ''
653 return self
._VpdToolGuid
655 ## Retrieve [SkuIds] section information
658 if self
._SkuIds
is None:
659 self
._SkuIds
= OrderedDict()
660 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
661 for Record
in RecordList
:
663 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
664 File
=self
.MetaFile
, Line
=Record
[-1])
666 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
667 File
=self
.MetaFile
, Line
=Record
[-1])
668 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
669 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
670 File
=self
.MetaFile
, Line
=Record
[-1])
671 if not SkuIdPattern
.match(Record
[1]) or (Record
[2] and not SkuIdPattern
.match(Record
[2])):
672 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_)*'",
673 File
=self
.MetaFile
, Line
=Record
[-1])
674 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
675 if TAB_DEFAULT
not in self
._SkuIds
:
676 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
677 if TAB_COMMON
not in self
._SkuIds
:
678 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
683 return int(intstr
, 16) if intstr
.upper().startswith("0X") else int(intstr
)
685 def _GetDefaultStores(self
):
686 if self
.DefaultStores
is None:
687 self
.DefaultStores
= OrderedDict()
688 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
689 for Record
in RecordList
:
691 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
692 File
=self
.MetaFile
, Line
=Record
[-1])
694 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
695 File
=self
.MetaFile
, Line
=Record
[-1])
696 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
697 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
698 File
=self
.MetaFile
, Line
=Record
[-1])
699 if not IsValidWord(Record
[1]):
700 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_-.)*'",
701 File
=self
.MetaFile
, Line
=Record
[-1])
702 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]), Record
[1].upper())
703 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
704 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0, TAB_DEFAULT_STORES_DEFAULT
)
705 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
706 return self
.DefaultStores
708 ## Retrieve [Components] section information
711 if self
._Modules
is not None:
714 self
._Modules
= OrderedDict()
715 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
716 Macros
= self
._Macros
717 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
718 for Record
in RecordList
:
719 DuplicatedFile
= False
721 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
725 # check the file validation
726 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
728 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
731 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
732 if self
._Arch
!= TAB_ARCH_COMMON
and ModuleFile
in self
._Modules
:
733 DuplicatedFile
= True
735 Module
= ModuleBuildClassObject()
736 Module
.MetaFile
= ModuleFile
738 # get module private library instance
739 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
740 for Record
in RecordList
:
741 LibraryClass
= Record
[0]
742 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
745 # check the file validation
746 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
748 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
751 if LibraryClass
== '' or LibraryClass
== 'NULL':
752 self
._NullLibraryNumber
+= 1
753 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
754 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
755 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
756 if LibraryPath
not in self
.LibraryInstances
:
757 self
.LibraryInstances
.append(LibraryPath
)
759 # get module private PCD setting
760 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
761 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
762 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
763 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
764 TokenList
= GetSplitValueList(Setting
)
765 DefaultValue
= TokenList
[0]
766 # the format is PcdName| Value | VOID* | MaxDatumSize
767 if len(TokenList
) > 2:
768 MaxDatumSize
= TokenList
[2]
771 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
772 Pcd
= PcdClassObject(
784 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
786 # get module private build options
787 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
788 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
789 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
790 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
792 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
793 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
795 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
796 if DuplicatedFile
and not RecordList
:
797 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
799 if len(RecordList
) != 1:
800 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
801 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
802 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
803 ModuleFile
.Arch
= self
._Arch
805 self
._Modules
[ModuleFile
] = Module
808 ## Retrieve all possible library instances used in this platform
810 def LibraryInstances(self
):
811 if self
._LibraryInstances
is None:
813 return self
._LibraryInstances
815 ## Retrieve [LibraryClasses] information
817 def LibraryClasses(self
):
818 if self
._LibraryClasses
is None:
819 self
._LibraryInstances
= []
821 # tdict is a special dict kind of type, used for selecting correct
822 # library instance for given library class and module type
824 LibraryClassDict
= tdict(True, 3)
825 # track all library class names
826 LibraryClassSet
= set()
827 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
828 Macros
= self
._Macros
829 for Record
in RecordList
:
830 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, Dummy
, LineNo
= Record
831 if LibraryClass
== '' or LibraryClass
== 'NULL':
832 self
._NullLibraryNumber
+= 1
833 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
834 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
835 LibraryClassSet
.add(LibraryClass
)
836 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
837 # check the file validation
838 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
840 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
843 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
844 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
845 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
846 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
847 if LibraryInstance
not in self
._LibraryInstances
:
848 self
._LibraryInstances
.append(LibraryInstance
)
850 # resolve the specific library instance for each class and each module type
851 self
._LibraryClasses
= tdict(True)
852 for LibraryClass
in LibraryClassSet
:
853 # try all possible module types
854 for ModuleType
in SUP_MODULE_LIST
:
855 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
856 if LibraryInstance
is None:
858 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
860 # for Edk style library instances, which are listed in different section
861 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
862 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
863 for Record
in RecordList
:
864 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
866 # check the file validation
867 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
869 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
871 if File
not in self
._LibraryInstances
:
872 self
._LibraryInstances
.append(File
)
874 # we need the module name as the library class name, so we have
875 # to parse it here. (self._Bdb[] will trigger a file parse if it
876 # hasn't been parsed)
878 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
879 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
880 return self
._LibraryClasses
882 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
883 if self
._DecPcds
is None:
886 if GlobalData
.gFdfParser
:
887 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
890 for Inf
in FdfInfList
:
891 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
892 if ModuleFile
in self
._Modules
:
894 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
895 PkgSet
.update(ModuleData
.Packages
)
897 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
898 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
900 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
901 EdkLogger
.error('build', PARSER_ERROR
,
902 "Pcd (%s.%s) defined in DSC is not declared in DEC files referenced in INF files in FDF. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
903 File
=self
.MetaFile
, Line
=LineNo
)
904 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
906 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
907 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
908 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
910 if ValueList
[2] == '-1':
911 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
912 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
914 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
916 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
917 except BadExpression
as Value
:
918 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
919 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
920 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
921 except EvaluationException
as Excpt
:
922 if hasattr(Excpt
, 'Pcd'):
923 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
924 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
925 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
926 " of the DSC file" % Excpt
.Pcd
,
927 File
=self
.MetaFile
, Line
=LineNo
)
929 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
930 File
=self
.MetaFile
, Line
=LineNo
)
932 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
933 File
=self
.MetaFile
, Line
=LineNo
)
936 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
938 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
939 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
940 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
):
941 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
942 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
,
943 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
944 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
945 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
946 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
949 def _FilterPcdBySkuUsage(self
, Pcds
):
950 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
951 sku_usage
= self
.SkuIdMgr
.SkuUsageType
952 if sku_usage
== SkuClass
.SINGLE
:
955 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
956 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
957 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
961 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
962 if isinstance(pcd
, StructurePcd
) and pcd
.SkuOverrideValues
:
963 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
966 def CompleteHiiPcdsDefaultStores(self
, Pcds
):
967 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
]]]
968 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
970 for skuid
in pcd
.SkuInfoList
:
971 skuobj
= pcd
.SkuInfoList
.get(skuid
)
972 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
973 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
)
974 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
975 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
978 def RecoverCommandLinePcd(self
):
979 def UpdateCommandLineValue(pcd
):
980 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
981 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
982 pcd
.PcdValueFromComm
= pcd
.DefaultValue
983 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
984 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
986 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
987 for pcd
in self
._Pcds
:
988 if isinstance(self
._Pcds
[pcd
], StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
989 UpdateCommandLineValue(self
._Pcds
[pcd
])
991 def __ParsePcdFromCommandLine(self
):
992 if GlobalData
.BuildOptionPcd
:
993 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
994 if isinstance(pcd
, tuple):
996 (pcdname
, pcdvalue
) = pcd
.split('=')
998 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
1000 (Name1
, Name2
) = pcdname
.split('.', 1)
1002 (Name3
, FieldName
) = Name2
.split(".", 1)
1003 if ((Name3
, Name1
)) in self
.DecPcds
:
1004 HasTokenSpace
= True
1006 TokenSpaceGuidCName
= Name1
1010 TokenSpaceGuidCName
= ''
1011 HasTokenSpace
= False
1013 if ((Name2
, Name1
)) in self
.DecPcds
:
1014 HasTokenSpace
= True
1016 TokenSpaceGuidCName
= Name1
1021 TokenSpaceGuidCName
= ''
1022 HasTokenSpace
= False
1025 TokenCName
= pcdname
1026 TokenSpaceGuidCName
= ''
1027 HasTokenSpace
= False
1028 TokenSpaceGuidCNameList
= []
1031 DisplayName
= TokenCName
1033 DisplayName
= TokenCName
+ '.' + FieldName
1034 if not HasTokenSpace
:
1035 for key
in self
.DecPcds
:
1036 PcdItem
= self
.DecPcds
[key
]
1037 if TokenCName
== PcdItem
.TokenCName
:
1038 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1039 if len (TokenSpaceGuidCNameList
) < 1:
1040 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1041 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1042 PcdDatumType
= PcdItem
.DatumType
1048 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1051 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1052 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1056 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1058 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1059 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1061 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1063 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1064 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1066 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1067 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, ("build command options", 1))
1069 if GlobalData
.BuildOptionPcd
:
1070 for pcd
in GlobalData
.BuildOptionPcd
:
1071 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1072 for BuildData
in self
._Bdb
._CACHE
_.values():
1073 if BuildData
.Arch
!= self
.Arch
:
1075 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1077 for key
in BuildData
.Pcds
:
1078 PcdItem
= BuildData
.Pcds
[key
]
1079 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1080 PcdItem
.DefaultValue
= pcdvalue
1081 PcdItem
.PcdValueFromComm
= pcdvalue
1082 #In command line, the latter full assign value in commandLine should override the former field assign value.
1083 #For example, --pcd Token.pcd.field="" --pcd Token.pcd=H"{}"
1086 if GlobalData
.BuildOptionPcd
:
1087 for pcdTuple
in GlobalData
.BuildOptionPcd
:
1088 TokenSpaceGuid
, Token
, Field
= pcdTuple
[0], pcdTuple
[1], pcdTuple
[2]
1090 if (TokenSpaceGuid
, Token
) not in field_assign
:
1091 field_assign
[TokenSpaceGuid
, Token
] = []
1092 field_assign
[TokenSpaceGuid
, Token
].append(pcdTuple
)
1094 if (TokenSpaceGuid
, Token
) in field_assign
:
1095 delete_assign
.extend(field_assign
[TokenSpaceGuid
, Token
])
1096 field_assign
[TokenSpaceGuid
, Token
] = []
1097 for item
in delete_assign
:
1098 GlobalData
.BuildOptionPcd
.remove(item
)
1101 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1104 TokenCName
+= '.' + FieldName
1105 if PcdValue
.startswith('H'):
1106 if FieldName
and IsFieldValueAnArray(PcdValue
[1:]):
1107 PcdDatumType
= TAB_VOID
1109 if FieldName
and not IsArray
:
1112 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1113 except BadExpression
as Value
:
1114 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1115 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1116 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1117 if FieldName
and IsFieldValueAnArray(PcdValue
):
1118 PcdDatumType
= TAB_VOID
1120 if FieldName
and not IsArray
:
1123 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1124 except BadExpression
as Value
:
1125 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1126 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1127 elif PcdValue
.startswith('L'):
1128 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1129 if FieldName
and IsFieldValueAnArray(PcdValue
):
1130 PcdDatumType
= TAB_VOID
1132 if FieldName
and not IsArray
:
1135 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1136 except BadExpression
as Value
:
1137 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1138 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1140 if PcdValue
.upper() == 'FALSE':
1142 if PcdValue
.upper() == 'TRUE':
1145 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1146 PcdValue
= '"' + PcdValue
+ '"'
1147 elif not PcdValue
.isdigit() and not PcdValue
.upper().startswith('0X'):
1148 PcdValue
= '"' + PcdValue
+ '"'
1152 if PcdValue
.upper().startswith('0X'):
1155 Num
= int(PcdValue
, Base
)
1157 PcdValue
= '"' + PcdValue
+ '"'
1158 if IsFieldValueAnArray(PcdValue
):
1159 PcdDatumType
= TAB_VOID
1164 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1165 except BadExpression
as Value
:
1166 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1167 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1170 ## Retrieve all PCD settings in platform
1173 if self
._Pcds
is None:
1174 self
._Pcds
= OrderedDict()
1175 self
.__ParsePcdFromCommandLine
()
1176 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1177 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1178 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1179 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1180 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1181 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1182 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1183 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1184 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1186 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1187 self
._Pcds
= self
.OverrideByFdfOverAll(self
._Pcds
)
1188 self
._Pcds
= self
.OverrideByCommOverAll(self
._Pcds
)
1189 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1190 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1191 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1193 self
.RecoverCommandLinePcd()
1196 ## Retrieve [BuildOptions]
1198 def BuildOptions(self
):
1199 if self
._BuildOptions
is None:
1200 self
._BuildOptions
= OrderedDict()
1202 # Retrieve build option for EDKII and EDK style module
1204 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1205 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1206 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1207 if Dummy3
.upper() != TAB_COMMON
:
1209 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1211 # Only flags can be appended
1213 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1214 self
._BuildOptions
[CurKey
] = Option
1216 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1217 self
._BuildOptions
[CurKey
] += ' ' + Option
1218 return self
._BuildOptions
1220 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1221 if self
._ModuleTypeOptions
is None:
1222 self
._ModuleTypeOptions
= OrderedDict()
1223 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1224 options
= OrderedDict()
1225 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1226 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1227 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1228 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1229 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1230 Type
= Dummy2
+ '.' + Dummy3
1231 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1232 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1233 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1234 options
[Key
] = Option
1236 if ' ' + Option
not in options
[Key
]:
1237 options
[Key
] += ' ' + Option
1238 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1241 def GetStructurePcdInfo(PcdSet
):
1242 structure_pcd_data
= defaultdict(list)
1244 structure_pcd_data
[(item
[0], item
[1])].append(item
)
1246 return structure_pcd_data
1249 def OverrideByFdf(StruPcds
,workspace
):
1250 if GlobalData
.gFdfParser
is None:
1252 StructurePcdInFdf
= OrderedDict()
1253 fdfpcd
= GlobalData
.gFdfParser
.Profile
.PcdDict
1254 fdfpcdlocation
= GlobalData
.gFdfParser
.Profile
.PcdLocalDict
1255 for item
in fdfpcd
:
1256 if len(item
[2]) and (item
[0],item
[1]) in StruPcds
:
1257 StructurePcdInFdf
[(item
[1],item
[0],item
[2] )] = fdfpcd
[item
]
1258 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInFdf
}
1259 for Pcd
in StruPcds
.values():
1260 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1262 FieldValues
= OrderedDict()
1263 for item
in StructurePcdInFdf
:
1264 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1265 FieldValues
[item
[2]] = StructurePcdInFdf
[item
]
1266 for field
in FieldValues
:
1267 if field
not in Pcd
.PcdFieldValueFromFdf
:
1268 Pcd
.PcdFieldValueFromFdf
[field
] = ["","",""]
1269 Pcd
.PcdFieldValueFromFdf
[field
][0] = FieldValues
[field
]
1270 Pcd
.PcdFieldValueFromFdf
[field
][1] = os
.path
.relpath(fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][0],workspace
)
1271 Pcd
.PcdFieldValueFromFdf
[field
][2] = fdfpcdlocation
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
,field
)][1]
1276 def OverrideByComm(StruPcds
):
1277 StructurePcdInCom
= OrderedDict()
1278 for item
in GlobalData
.BuildOptionPcd
:
1279 if len(item
) == 5 and (item
[1], item
[0]) in StruPcds
:
1280 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1281 GlobalPcds
= {(item
[0], item
[1]) for item
in StructurePcdInCom
}
1282 for Pcd
in StruPcds
.values():
1283 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in GlobalPcds
:
1285 FieldValues
= OrderedDict()
1286 for item
in StructurePcdInCom
:
1287 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (item
[0], item
[1]) and item
[2]:
1288 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1289 for field
in FieldValues
:
1290 if field
not in Pcd
.PcdFieldValueFromComm
:
1291 Pcd
.PcdFieldValueFromComm
[field
] = ["", "", ""]
1292 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1293 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1294 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1297 def OverrideByCommOverAll(self
,AllPcds
):
1298 def CheckStructureInComm(commpcds
):
1301 if len(commpcds
[0]) == 5:
1304 NoFiledValues
= OrderedDict()
1305 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1306 StructurePcdInCom
= OrderedDict()
1307 for item
in GlobalData
.BuildOptionPcd
:
1308 StructurePcdInCom
[(item
[0], item
[1], item
[2] )] = (item
[3], item
[4])
1309 for item
in StructurePcdInCom
:
1311 NoFiledValues
[(item
[0], item
[1])] = StructurePcdInCom
[item
]
1313 for item
in GlobalData
.BuildOptionPcd
:
1314 NoFiledValues
[(item
[0], item
[1])] = [item
[2]]
1315 for Guid
, Name
in NoFiledValues
:
1316 if (Name
, Guid
) in AllPcds
:
1317 Pcd
= AllPcds
.get((Name
, Guid
))
1318 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
), None), StructurePcd
):
1319 self
._DecPcds
.get((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1321 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1322 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1323 for sku
in Pcd
.SkuInfoList
:
1324 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1325 if SkuInfo
.DefaultValue
:
1326 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1328 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1329 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1330 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)][0]
1331 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1332 if Pcd
.DatumType
== TAB_VOID
:
1333 if not Pcd
.MaxDatumSize
:
1334 Pcd
.MaxDatumSize
= '0'
1335 CurrentSize
= int(Pcd
.MaxDatumSize
, 16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1336 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1337 MaxSize
= max(CurrentSize
, OptionSize
)
1338 Pcd
.MaxDatumSize
= str(MaxSize
)
1340 PcdInDec
= self
.DecPcds
.get((Name
, Guid
))
1342 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
, Name
)][0]
1343 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1344 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1345 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
],
1346 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1347 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1348 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1349 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
, Name
)][0]
1350 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC
],
1351 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX
]]:
1352 self
.Pcds
[Name
, Guid
].SkuInfoList
= {TAB_DEFAULT
:SkuInfoClass(TAB_DEFAULT
, self
.SkuIds
[TAB_DEFAULT
][0], '', '', '', '', '', NoFiledValues
[( Guid
, Name
)][0])}
1355 def OverrideByFdfOverAll(self
,AllPcds
):
1357 if GlobalData
.gFdfParser
is None:
1359 NoFiledValues
= GlobalData
.gFdfParser
.Profile
.PcdDict
1360 for Name
,Guid
,Field
in NoFiledValues
:
1363 Value
= NoFiledValues
[(Name
,Guid
,Field
)]
1364 if (Name
,Guid
) in AllPcds
:
1365 Pcd
= AllPcds
.get((Name
,Guid
))
1366 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1367 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= Value
1369 Pcd
.PcdValueFromComm
= Value
1370 Pcd
.DefaultValue
= Value
1371 for sku
in Pcd
.SkuInfoList
:
1372 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1373 if SkuInfo
.DefaultValue
:
1374 SkuInfo
.DefaultValue
= Value
1376 SkuInfo
.HiiDefaultValue
= Value
1377 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1378 SkuInfo
.DefaultStoreDict
[defaultstore
] = Value
1379 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1380 if Pcd
.DatumType
== TAB_VOID
:
1381 if not Pcd
.MaxDatumSize
:
1382 Pcd
.MaxDatumSize
= '0'
1383 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1384 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1385 MaxSize
= max(CurrentSize
, OptionSize
)
1386 Pcd
.MaxDatumSize
= str(MaxSize
)
1388 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1390 PcdInDec
.PcdValueFromFdf
= Value
1391 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1392 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1393 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1394 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1395 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
1398 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1400 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1401 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1402 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1403 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1404 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1405 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1408 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1409 SkuIds
= self
.SkuIds
1410 self
.SkuIdMgr
.AvailableSkuIdSet
.update({TAB_DEFAULT
:0})
1411 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1412 DefaultStores
.add(TAB_DEFAULT_STORES_DEFAULT
)
1415 # Find out all possible PCD candidates for self._Arch
1418 for Type
in TypeList
:
1419 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1421 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
, Dummy5
in RecordList
:
1422 SkuName
= SkuName
.upper()
1423 default_store
= default_store
.upper()
1424 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1425 if SkuName
not in SkuIds
:
1428 if SkuName
in SkuIds
and "." in TokenSpaceGuid
:
1429 S_PcdSet
.append([ TokenSpaceGuid
.split(".")[0], TokenSpaceGuid
.split(".")[1], PcdCName
, SkuName
, default_store
, Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1431 # handle pcd value override
1432 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1433 S_pcd_set
= OrderedDict()
1434 for str_pcd
in StrPcdSet
:
1435 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1436 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1437 if not isinstance (str_pcd_dec
, StructurePcd
):
1438 EdkLogger
.error('build', PARSER_ERROR
,
1439 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1440 File
=self
.MetaFile
, Line
= StrPcdSet
[str_pcd
][0][5])
1442 str_pcd_obj_str
= StructurePcd()
1443 str_pcd_obj_str
.copy(str_pcd_dec
)
1445 str_pcd_obj_str
.copy(str_pcd_obj
)
1446 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1447 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
}
1449 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
}
1450 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1451 if str_pcd_data
[3] in SkuIds
:
1452 str_pcd_obj_str
.AddOverrideValue(str_pcd_data
[2], str(str_pcd_data
[6]), TAB_DEFAULT
if str_pcd_data
[3] == TAB_COMMON
else str_pcd_data
[3], TAB_DEFAULT_STORES_DEFAULT
if str_pcd_data
[4] == TAB_COMMON
else str_pcd_data
[4], self
.MetaFile
.File
if self
.WorkspaceDir
not in self
.MetaFile
.File
else self
.MetaFile
.File
[len(self
.WorkspaceDir
) if self
.WorkspaceDir
.endswith(os
.path
.sep
) else len(self
.WorkspaceDir
)+1:], LineNo
=str_pcd_data
[5])
1453 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1455 EdkLogger
.error('build', PARSER_ERROR
,
1456 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1457 File
=self
.MetaFile
, Line
= StrPcdSet
[str_pcd
][0][5])
1458 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1459 for Pcd
in self
.DecPcds
:
1460 if isinstance(self
._DecPcds
[Pcd
], StructurePcd
):
1461 if Pcd
not in S_pcd_set
:
1462 str_pcd_obj_str
= StructurePcd()
1463 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1464 str_pcd_obj
= Pcds
.get(Pcd
, None)
1466 str_pcd_obj_str
.copy(str_pcd_obj
)
1467 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1468 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
}
1470 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
}
1471 S_pcd_set
[Pcd
] = str_pcd_obj_str
1473 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1474 for stru_pcd
in S_pcd_set
.values():
1475 for skuid
in SkuIds
:
1476 if skuid
in stru_pcd
.SkuOverrideValues
:
1478 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1480 if skuid
not in stru_pcd
.SkuOverrideValues
:
1481 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1482 if nextskuid
== TAB_DEFAULT
:
1485 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1486 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})
1488 stru_pcd
.ValueChain
.add((skuid
, ''))
1489 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1490 for skuid
in SkuIds
:
1493 if skuid
not in stru_pcd
.SkuOverrideValues
:
1494 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1495 if nextskuid
== TAB_DEFAULT
:
1498 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1501 PcdDefaultStoreSet
= set(defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
])
1502 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1504 for defaultstoreid
in DefaultStores
:
1505 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1506 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = copy
.deepcopy(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1507 stru_pcd
.ValueChain
.add((skuid
, defaultstoreid
))
1508 S_pcd_set
= DscBuildData
.OverrideByFdf(S_pcd_set
,self
.WorkspaceDir
)
1509 S_pcd_set
= DscBuildData
.OverrideByComm(S_pcd_set
)
1510 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1512 for (skuname
, StoreName
, PcdGuid
, PcdName
, PcdValue
) in Str_Pcd_Values
:
1513 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1514 if str_pcd_obj
is None:
1515 print(PcdName
, PcdGuid
)
1517 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1518 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1519 if skuname
not in str_pcd_obj
.SkuInfoList
:
1520 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1522 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1523 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1524 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1525 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1526 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1527 str_pcd_obj
.DefaultValue
= PcdValue
1529 if skuname
not in str_pcd_obj
.SkuInfoList
:
1530 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1532 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1533 if nextskuid
== TAB_DEFAULT
:
1536 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1537 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
)
1538 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1539 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1541 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1542 for str_pcd_obj
in S_pcd_set
.values():
1543 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1544 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1546 PcdDefaultStoreSet
= set(defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
)
1547 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1548 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1549 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1551 for str_pcd_obj
in S_pcd_set
.values():
1553 str_pcd_obj
.MaxDatumSize
= self
.GetStructurePcdMaxSize(str_pcd_obj
)
1554 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1555 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
].CustomAttribute
['IsStru']=True
1559 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1560 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1561 del pcd
.SkuInfoList
[TAB_COMMON
]
1562 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1563 del pcd
.SkuInfoList
[TAB_COMMON
]
1565 map(self
.FilterSkuSettings
, [Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1568 ## Retrieve non-dynamic PCD settings
1570 # @param Type PCD type
1572 # @retval a dict object contains settings of given PCD type
1574 def _GetPcd(self
, Type
):
1575 Pcds
= OrderedDict()
1577 # tdict is a special dict kind of type, used for selecting correct
1578 # PCD settings for certain ARCH
1580 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1582 PcdDict
= tdict(True, 4)
1584 # Find out all possible PCD candidates for self._Arch
1585 RecordList
= self
._RawData
[Type
, self
._Arch
]
1586 PcdValueDict
= OrderedDict()
1587 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
1588 SkuName
= SkuName
.upper()
1589 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1590 if SkuName
not in AvailableSkuIdSet
:
1591 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1592 File
=self
.MetaFile
, Line
=Dummy5
)
1593 if "." not in TokenSpaceGuid
:
1594 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1595 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1597 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1598 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1601 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1603 if int(MaxDatumSize
, 0) > 0xFFFF:
1604 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1605 File
=self
.MetaFile
, Line
=Dummy4
)
1606 if int(MaxDatumSize
, 0) < 0:
1607 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
1608 File
=self
.MetaFile
, Line
=Dummy4
)
1609 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1610 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1612 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1614 for ((PcdCName
, TokenSpaceGuid
), PcdSetting
) in PcdValueDict
.iteritems():
1615 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1616 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1617 elif TAB_DEFAULT
in PcdSetting
:
1618 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_DEFAULT
]
1619 elif TAB_COMMON
in PcdSetting
:
1620 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_COMMON
]
1626 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1629 self
._PCD
_TYPE
_STRING
_[Type
],
1638 for SkuName
in PcdValueDict
[PcdCName
, TokenSpaceGuid
]:
1639 Settings
= PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
]
1640 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
1641 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
1642 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = Settings
[0]
1645 def GetStructurePcdMaxSize(self
, str_pcd
):
1646 pcd_default_value
= str_pcd
.DefaultValue
1647 sku_values
= [skuobj
.HiiDefaultValue
if str_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]] else skuobj
.DefaultValue
for skuobj
in str_pcd
.SkuInfoList
.values()]
1648 sku_values
.append(pcd_default_value
)
1650 def get_length(value
):
1651 Value
= value
.strip()
1653 if Value
.startswith(TAB_GUID
) and Value
.endswith(')'):
1655 if Value
.startswith('L"') and Value
.endswith('"'):
1656 return len(Value
[2:-1])
1657 if Value
[0] == '"' and Value
[-1] == '"':
1658 return len(Value
) - 2
1659 if Value
[0] == '{' and Value
[-1] == '}':
1660 return len(Value
.split(","))
1661 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1662 return len(list(Value
[2:-1]))
1663 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1664 return len(Value
) - 2
1667 return str(max(get_length(item
) for item
in sku_values
))
1670 def ExecuteCommand (Command
):
1672 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1674 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1675 Result
= Process
.communicate()
1676 return Process
.returncode
, Result
[0], Result
[1]
1679 def IntToCString(Value
, ValueSize
):
1681 if not isinstance (Value
, str):
1682 for Index
in range(0, ValueSize
):
1683 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1685 Result
= Result
+ '"'
1688 def GenerateSizeFunction(self
, Pcd
):
1689 CApp
= "// Default Value in Dec \n"
1690 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1691 for FieldList
in [Pcd
.DefaultValues
]:
1694 for FieldName
in FieldList
:
1695 FieldName
= "." + FieldName
1696 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1697 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1699 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1700 except BadExpression
:
1701 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1702 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1703 Value
, ValueSize
= ParseFieldValue(Value
)
1704 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]);
1707 FieldName_ori
= FieldName
.strip('.')
1708 while '[' in FieldName
:
1709 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1710 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1711 FieldName
= FieldName
.split(']', 1)[1]
1712 FieldName
= NewFieldName
+ FieldName
1713 while '[' in FieldName
:
1714 FieldName
= FieldName
.rsplit('[', 1)[0]
1715 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])
1716 for skuname
in Pcd
.SkuOverrideValues
:
1717 if skuname
== TAB_COMMON
:
1719 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1720 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1721 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
].get(defaultstorenameitem
)]:
1724 for FieldName
in FieldList
:
1725 FieldName
= "." + FieldName
1726 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1727 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1729 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1730 except BadExpression
:
1731 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1732 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1733 Value
, ValueSize
= ParseFieldValue(Value
)
1734 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]);
1737 FieldName_ori
= FieldName
.strip('.')
1738 while '[' in FieldName
:
1739 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1740 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1741 FieldName
= FieldName
.split(']', 1)[1]
1742 FieldName
= NewFieldName
+ FieldName
1743 while '[' in FieldName
:
1744 FieldName
= FieldName
.rsplit('[', 1)[0]
1745 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])
1746 if Pcd
.PcdFieldValueFromFdf
:
1747 CApp
= CApp
+ "// From fdf \n"
1748 for FieldName
in Pcd
.PcdFieldValueFromFdf
:
1749 FieldName
= "." + FieldName
1750 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0])
1751 if IsArray
and not (Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0].endswith('}')):
1753 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1754 except BadExpression
:
1755 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1756 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromFdf
[FieldName
.strip(".")][2]))
1757 Value
, ValueSize
= ParseFieldValue(Value
)
1758 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]);
1761 FieldName_ori
= FieldName
.strip('.')
1762 while '[' in FieldName
:
1763 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1764 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1765 FieldName
= FieldName
.split(']', 1)[1]
1766 FieldName
= NewFieldName
+ FieldName
1767 while '[' in FieldName
:
1768 FieldName
= FieldName
.rsplit('[', 1)[0]
1769 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])
1770 if Pcd
.PcdFieldValueFromComm
:
1771 CApp
= CApp
+ "// From Command Line \n"
1772 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1773 FieldName
= "." + FieldName
1774 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1775 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1777 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1778 except BadExpression
:
1779 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1780 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1781 Value
, ValueSize
= ParseFieldValue(Value
)
1782 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]);
1785 FieldName_ori
= FieldName
.strip('.')
1786 while '[' in FieldName
:
1787 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1788 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1789 FieldName
= FieldName
.split(']', 1)[1]
1790 FieldName
= NewFieldName
+ FieldName
1791 while '[' in FieldName
:
1792 FieldName
= FieldName
.rsplit('[', 1)[0]
1793 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])
1794 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize(), Pcd
.GetPcdMaxSize())
1799 def GenerateSizeStatments(Pcd
):
1800 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1801 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1804 def GenerateDefaultValueAssignFunction(self
, Pcd
):
1805 CApp
= "// Default value in Dec \n"
1806 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
)
1807 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1808 CApp
= CApp
+ ' CHAR8 *Value;\n'
1809 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1810 IsArray
= IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1813 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1814 except BadExpression
:
1815 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1816 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1817 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1818 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1819 if isinstance(Value
, str):
1820 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1823 # Use memcpy() to copy value into field
1825 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1826 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1827 for FieldList
in [Pcd
.DefaultValues
]:
1830 for FieldName
in FieldList
:
1831 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1834 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1835 except BadExpression
:
1836 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1837 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1840 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1842 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]))
1843 if isinstance(Value
, str):
1844 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1847 # Use memcpy() to copy value into field
1849 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1850 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1851 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])
1852 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1854 if '[' in FieldName
and ']' in FieldName
:
1855 Index
= int(FieldName
.split('[')[1].split(']')[0])
1856 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
)
1858 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1860 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1865 def GenerateDefaultValueAssignStatement(Pcd
):
1866 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1869 def GenerateInitValueFunction(self
, Pcd
, SkuName
, DefaultStoreName
):
1870 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
, DefaultStoreName
)
1871 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
, Pcd
.DatumType
)
1872 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1873 CApp
= CApp
+ ' CHAR8 *Value;\n'
1875 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
1876 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1877 if Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
or Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1878 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
1879 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
, {}).get(TAB_DEFAULT_STORES_DEFAULT
) if Pcd
.DefaultFromDSC
else None
1881 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
)
1883 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
, {}).get(TAB_DEFAULT_STORES_DEFAULT
)
1884 for FieldList
in [pcddefaultvalue
, inherit_OverrideValues
.get(DefaultStoreName
)]:
1887 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1888 IsArray
= IsFieldValueAnArray(FieldList
)
1891 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
1892 except BadExpression
:
1893 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
1894 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1895 Value
, ValueSize
= ParseFieldValue (FieldList
)
1897 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
):
1898 if isinstance(Value
, str):
1899 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
)
1902 # Use memcpy() to copy value into field
1904 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
)
1905 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1907 if isinstance(Value
, str):
1908 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
1911 # Use memcpy() to copy value into field
1913 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
, {}).get(DefaultStoreName
))
1914 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1916 if (SkuName
, DefaultStoreName
) == (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
, '') not in Pcd
.ValueChain
) and ( (SkuName
, DefaultStoreName
) not in Pcd
.ValueChain
)):
1917 for FieldName
in FieldList
:
1918 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1921 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1922 except BadExpression
:
1923 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1924 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1926 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1928 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]))
1929 if isinstance(Value
, str):
1930 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1933 # Use memcpy() to copy value into field
1935 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1936 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1937 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])
1938 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1940 if '[' in FieldName
and ']' in FieldName
:
1941 Index
= int(FieldName
.split('[')[1].split(']')[0])
1942 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
)
1944 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1946 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1951 def GenerateInitValueStatement(Pcd
, SkuName
, DefaultStoreName
):
1952 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, SkuName
, DefaultStoreName
)
1955 def GenerateCommandLineValue(self
, Pcd
):
1956 CApp
= "// Value in CommandLine\n"
1957 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
)
1958 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1959 CApp
= CApp
+ ' CHAR8 *Value;\n'
1961 pcddefaultvalue
= Pcd
.PcdValueFromComm
1962 for FieldList
in [pcddefaultvalue
, Pcd
.PcdFieldValueFromComm
]:
1965 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1966 IsArray
= IsFieldValueAnArray(FieldList
)
1969 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
1970 except BadExpression
:
1971 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
1972 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1973 Value
, ValueSize
= ParseFieldValue (FieldList
)
1975 if isinstance(Value
, str):
1976 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
1979 # Use memcpy() to copy value into field
1981 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
1982 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1984 for FieldName
in FieldList
:
1985 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1988 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1989 except BadExpression
:
1990 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1991 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1995 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1997 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]))
1998 if isinstance(Value
, str):
1999 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2002 # Use memcpy() to copy value into field
2004 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
2005 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2006 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])
2007 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2009 if '[' in FieldName
and ']' in FieldName
:
2010 Index
= int(FieldName
.split('[')[1].split(']')[0])
2011 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
)
2013 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2015 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2020 def GenerateCommandLineValueStatement(Pcd
):
2021 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2023 def GenerateFdfValue(self
,Pcd
):
2024 CApp
= "// Value in Fdf\n"
2025 CApp
= CApp
+ "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
)
2026 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2027 CApp
= CApp
+ ' CHAR8 *Value;\n'
2029 pcddefaultvalue
= Pcd
.PcdValueFromFdf
2030 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromFdf
]:
2033 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
2034 IsArray
= IsFieldValueAnArray(FieldList
)
2037 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
2038 except BadExpression
:
2039 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Fdf: %s" %
2040 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
2041 Value
, ValueSize
= ParseFieldValue (FieldList
)
2043 if isinstance(Value
, str):
2044 CApp
= CApp
+ ' Pcd = %s; // From Fdf \n' % (Value
)
2047 # Use memcpy() to copy value into field
2049 CApp
= CApp
+ ' Value = %s; // From Fdf .\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
2050 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
2052 for FieldName
in FieldList
:
2053 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
2056 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
2057 except BadExpression
:
2058 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
2059 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
2063 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
2065 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]))
2066 if isinstance(Value
, str):
2067 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2070 # Use memcpy() to copy value into field
2072 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
2073 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2074 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])
2075 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
2077 if '[' in FieldName
and ']' in FieldName
:
2078 Index
= int(FieldName
.split('[')[1].split(']')[0])
2079 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
)
2081 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2083 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
2088 def GenerateFdfValueStatement(Pcd
):
2089 CApp
= ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2092 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
2093 OverrideValues
= {DefaultStore
:""}
2094 if Pcd
.SkuOverrideValues
:
2095 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
2096 if not OverrideValues
:
2097 OverrideValues
= {TAB_DEFAULT_STORES_DEFAULT
:Pcd
.DefaultValues
}
2098 for DefaultStoreName
in OverrideValues
:
2099 CApp
= CApp
+ 'void\n'
2100 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2101 CApp
= CApp
+ ' void\n'
2102 CApp
= CApp
+ ' )\n'
2104 CApp
= CApp
+ ' UINT32 Size;\n'
2105 CApp
= CApp
+ ' UINT32 FieldSize;\n'
2106 CApp
= CApp
+ ' CHAR8 *Value;\n'
2107 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
2108 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
2109 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.DatumType
, Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
2112 if SkuName
in Pcd
.SkuInfoList
:
2113 DefaultValue
= Pcd
.SkuInfoList
[SkuName
].DefaultStoreDict
.get(DefaultStoreName
, Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
if Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
else Pcd
.SkuInfoList
[SkuName
].DefaultValue
)
2115 DefaultValue
= Pcd
.DefaultValue
2116 PcdDefaultValue
= StringToArray(DefaultValue
.strip())
2118 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
2121 # Get current PCD value and size
2123 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2126 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
2127 # the correct value. For structures with a flexible array member, the flexible
2128 # array member is detected, and the size is based on the highest index used with
2129 # the flexible array member. The flexible array member must be the last field
2130 # in a structure. The size formula for this case is:
2131 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
2133 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
)
2136 # Allocate and zero buffer for the PCD
2137 # Must handle cases where current value is smaller, larger, or same size
2138 # Always keep that larger one as the current size
2140 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
2141 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.DatumType
)
2142 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
2145 # Copy current PCD value into allocated buffer.
2147 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
2150 # Assign field values in PCD
2152 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
2153 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2154 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2155 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
2156 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
2157 for defaultstorenameitem
in storeset
:
2158 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
2159 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, skuname
, defaultstorenameitem
)
2160 if skuname
== SkuName
:
2163 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
2164 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2165 CApp
= CApp
+ DscBuildData
.GenerateFdfValueStatement(Pcd
)
2166 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
2168 # Set new PCD value and size
2170 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2175 CApp
= CApp
+ ' free (Pcd);\n'
2178 return InitByteValue
, CApp
2179 def SkuOverrideValuesEmpty(self
,OverrideValues
):
2180 if not OverrideValues
:
2182 for key
in OverrideValues
:
2183 if OverrideValues
[key
]:
2187 def ParseCCFlags(self
, ccflag
):
2191 if ch
in (r
"/", "-"):
2193 ccflags
.add(flag
.strip())
2198 ccflags
.add(flag
.strip())
2200 def GenerateByteArrayValue (self
, StructuredPcds
):
2202 # Generate/Compile/Run C application to determine if there are any flexible array members
2204 if not StructuredPcds
:
2208 CApp
= PcdMainCHeader
2210 IncludeFiles
= set()
2211 for PcdName
in StructuredPcds
:
2212 Pcd
= StructuredPcds
[PcdName
]
2213 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
2214 if IncludeFile
not in IncludeFiles
:
2215 IncludeFiles
.add(IncludeFile
)
2216 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2218 for PcdName
in StructuredPcds
:
2219 Pcd
= StructuredPcds
[PcdName
]
2220 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2221 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2222 CApp
= CApp
+ self
.GenerateFdfValue(Pcd
)
2223 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2224 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2225 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2226 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
2228 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2229 if SkuName
not in Pcd
.SkuOverrideValues
:
2231 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2232 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
, SkuName
, DefaultStoreName
)
2233 if self
.SkuOverrideValuesEmpty(Pcd
.SkuOverrideValues
) or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2234 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2235 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
2237 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2238 if SkuName
not in Pcd
.SkuOverrideValues
:
2240 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2241 Pcd
= StructuredPcds
[PcdName
]
2242 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2244 CApp
= CApp
+ 'VOID\n'
2245 CApp
= CApp
+ 'PcdEntryPoint(\n'
2246 CApp
= CApp
+ ' VOID\n'
2247 CApp
= CApp
+ ' )\n'
2249 for Pcd
in StructuredPcds
.values():
2250 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
]]:
2251 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2253 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2254 if SkuName
not in self
.SkuIdMgr
.AvailableSkuIdSet
:
2256 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2257 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2260 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2262 if not os
.path
.exists(self
.OutputPath
):
2263 os
.makedirs(self
.OutputPath
)
2264 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2265 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2267 MakeApp
= PcdMakefileHeader
2268 if sys
.platform
== "win32":
2269 MakeApp
= MakeApp
+ 'APPFILE = %s\%s.exe\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2271 MakeApp
= MakeApp
+ PcdGccMakefile
2272 MakeApp
= MakeApp
+ 'APPFILE = %s/%s\n' % (self
.OutputPath
, PcdValueInitName
) + 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2273 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2276 PlatformInc
= OrderedDict()
2277 for Cache
in self
._Bdb
._CACHE
_.values():
2278 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2281 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2282 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2283 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2284 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2287 for Pcd
in StructuredPcds
.values():
2288 for PackageDec
in Pcd
.PackageDecs
:
2289 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2290 if not os
.path
.exists(Package
):
2291 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2292 if Package
not in PcdDependDEC
:
2293 PcdDependDEC
.append(Package
)
2295 if PlatformInc
and PcdDependDEC
:
2296 for pkg
in PcdDependDEC
:
2297 if pkg
in PlatformInc
:
2298 for inc
in PlatformInc
[pkg
]:
2299 MakeApp
+= '-I' + str(inc
) + ' '
2300 IncSearchList
.append(inc
)
2301 MakeApp
= MakeApp
+ '\n'
2303 CC_FLAGS
= LinuxCFLAGS
2304 if sys
.platform
== "win32":
2305 CC_FLAGS
= WindowsCFLAGS
2306 BuildOptions
= OrderedDict()
2307 for Options
in self
.BuildOptions
:
2308 if Options
[2] != EDKII_NAME
:
2311 if Family
and Family
!= self
.ToolChainFamily
:
2313 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2318 if Target
== TAB_STAR
or Target
== self
._Target
:
2319 if Tag
== TAB_STAR
or Tag
== self
._Toolchain
:
2320 if 'COMMON' not in BuildOptions
:
2321 BuildOptions
['COMMON'] = set()
2322 if Arch
== TAB_STAR
:
2323 BuildOptions
['COMMON'].add(self
.BuildOptions
[Options
])
2324 if Arch
in self
.SupArchList
:
2325 if Arch
not in BuildOptions
:
2326 BuildOptions
[Arch
] = set()
2327 BuildOptions
[Arch
] |
= self
.ParseCCFlags(self
.BuildOptions
[Options
])
2330 ArchBuildOptions
= {arch
:flags
for arch
,flags
in BuildOptions
.items() if arch
!= 'COMMON'}
2331 if len(ArchBuildOptions
.keys()) == 1:
2332 BuildOptions
['COMMON'] |
= (ArchBuildOptions
.values()[0])
2333 elif len(ArchBuildOptions
.keys()) > 1:
2334 CommonBuildOptions
= reduce(lambda x
,y
: x
&y
, ArchBuildOptions
.values())
2335 BuildOptions
['COMMON'] |
= CommonBuildOptions
2336 ValueList
= list(BuildOptions
['COMMON'])
2337 CC_FLAGS
+= " ".join([item
for item
in ValueList
if item
.startswith(('-D', '/D', '-U', '/U'))])
2340 if sys
.platform
== "win32":
2341 MakeApp
= MakeApp
+ PcdMakefileEnd
2342 MakeApp
= MakeApp
+ AppTarget
% ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
2344 MakeApp
= MakeApp
+ AppTarget
% ("""\tcp $(APPLICATION) $(APPFILE) """)
2345 MakeApp
= MakeApp
+ '\n'
2346 IncludeFileFullPaths
= []
2347 for includefile
in IncludeFiles
:
2348 for includepath
in IncSearchList
:
2349 includefullpath
= os
.path
.join(str(includepath
), includefile
)
2350 if os
.path
.exists(includefullpath
):
2351 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2354 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2355 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2356 SearchPathList
.extend(str(item
) for item
in IncSearchList
)
2357 IncFileList
= GetDependencyList(IncludeFileFullPaths
, SearchPathList
)
2358 for include_file
in IncFileList
:
2359 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2360 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2361 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2362 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2364 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2365 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2366 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2368 Dest_PcdValueInitExe
= PcdValueInitName
2369 if not sys
.platform
== "win32":
2370 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2372 Dest_PcdValueInitExe
= os
.path
.join(self
.OutputPath
, PcdValueInitName
) +".exe"
2374 if sys
.platform
== "win32":
2375 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2376 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2379 MakeCommand
= 'make -f %s' % (MakeFileName
)
2380 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2383 Messages
= Messages
.split('\n')
2386 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2387 File
= open (CAppBaseFileName
+ '.c', 'r')
2388 FileData
= File
.readlines()
2390 for Message
in Messages
:
2391 if " error" in Message
or "warning" in Message
:
2392 FileInfo
= Message
.strip().split('(')
2393 if len (FileInfo
) > 1:
2394 FileName
= FileInfo
[0]
2395 FileLine
= FileInfo
[1].split (')')[0]
2397 FileInfo
= Message
.strip().split(':')
2398 FileName
= FileInfo
[0]
2399 FileLine
= FileInfo
[1]
2400 if FileLine
.isdigit():
2401 error_line
= FileData
[int (FileLine
) - 1]
2402 if r
"//" in error_line
:
2403 c_line
, dsc_line
= error_line
.split(r
"//")
2405 dsc_line
= error_line
2406 message_itmes
= Message
.split(":")
2408 if "PcdValueInit.c" not in Message
:
2409 if not MessageGroup
:
2410 MessageGroup
.append(Message
)
2413 for item
in message_itmes
:
2414 if "PcdValueInit.c" in item
:
2415 Index
= message_itmes
.index(item
)
2416 message_itmes
[Index
] = dsc_line
.strip()
2418 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2421 MessageGroup
.append(Message
)
2423 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2425 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2427 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, Dest_PcdValueInitExe
, InputValueFile
):
2428 Command
= Dest_PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2429 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2431 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2433 File
= open (OutputValueFile
, 'r')
2434 FileBuffer
= File
.readlines()
2437 StructurePcdSet
= []
2438 for Pcd
in FileBuffer
:
2439 PcdValue
= Pcd
.split ('|')
2440 PcdInfo
= PcdValue
[0].split ('.')
2441 StructurePcdSet
.append((PcdInfo
[0], PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2442 return StructurePcdSet
2445 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2446 if not os
.path
.exists(OutputFile
):
2448 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2450 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2454 ## Retrieve dynamic PCD settings
2456 # @param Type PCD type
2458 # @retval a dict object contains settings of given PCD type
2460 def _GetDynamicPcd(self
, Type
):
2463 Pcds
= OrderedDict()
2465 # tdict is a special dict kind of type, used for selecting correct
2466 # PCD settings for certain ARCH and SKU
2468 PcdDict
= tdict(True, 4)
2470 # Find out all possible PCD candidates for self._Arch
2471 RecordList
= self
._RawData
[Type
, self
._Arch
]
2472 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2475 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2476 SkuName
= SkuName
.upper()
2477 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2478 if SkuName
not in AvailableSkuIdSet
:
2479 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2480 File
=self
.MetaFile
, Line
=Dummy5
)
2481 if "." not in TokenSpaceGuid
:
2482 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2483 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2485 # Remove redundant PCD candidates, per the ARCH and SKU
2486 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2488 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2492 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2494 if int(MaxDatumSize
, 0) > 0xFFFF:
2495 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2496 File
=self
.MetaFile
, Line
=Dummy4
)
2497 if int(MaxDatumSize
, 0) < 0:
2498 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2499 File
=self
.MetaFile
, Line
=Dummy4
)
2500 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2501 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2502 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2503 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2504 if MaxDatumSize
.strip():
2505 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2508 if pcdObject
.MaxDatumSize
:
2509 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2512 if CurrentMaxSize
> PcdMaxSize
:
2513 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2515 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2518 self
._PCD
_TYPE
_STRING
_[Type
],
2523 OrderedDict({SkuName
: SkuInfo
}),
2528 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2529 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2530 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = PcdValue
2532 for pcd
in Pcds
.values():
2533 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2534 # Only fix the value while no value provided in DSC file.
2535 for sku
in pcd
.SkuInfoList
.values():
2536 if not sku
.DefaultValue
:
2537 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2538 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2539 valuefromDec
= pcdDecObject
.DefaultValue
2540 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2541 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2542 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2543 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2544 del pcd
.SkuInfoList
[TAB_COMMON
]
2545 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2546 del pcd
.SkuInfoList
[TAB_COMMON
]
2548 map(self
.FilterSkuSettings
, Pcds
.values())
2552 def FilterSkuSettings(self
, PcdObj
):
2554 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2555 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2556 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2557 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2558 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2559 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2561 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2562 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2567 def CompareVarAttr(Attr1
, Attr2
):
2568 if not Attr1
or not Attr2
: # for empty string
2570 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2571 Attr1Set
= set(Attr1s
)
2572 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2573 Attr2Set
= set(Attr2s
)
2574 if Attr2Set
== Attr1Set
:
2579 def CompletePcdValues(self
, PcdSet
):
2580 Pcds
= OrderedDict()
2581 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2582 SkuIds
= {skuname
:skuid
for skuname
, skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2583 DefaultStores
= set(storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
)
2584 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2585 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2587 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2588 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2589 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2590 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2591 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2592 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2593 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2595 PcdType
= PcdObj
.Type
2596 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2597 for skuid
in PcdObj
.SkuInfoList
:
2598 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2599 mindefaultstorename
= DefaultStoreObj
.GetMin(set(defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
))
2600 for defaultstorename
in DefaultStores
:
2601 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2602 skuobj
.DefaultStoreDict
[defaultstorename
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
2603 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2604 for skuname
, skuid
in SkuIds
.items():
2605 if skuname
not in PcdObj
.SkuInfoList
:
2606 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2607 while nextskuid
not in PcdObj
.SkuInfoList
:
2608 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2609 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2610 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2611 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2612 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2613 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2614 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2616 ## Retrieve dynamic HII PCD settings
2618 # @param Type PCD type
2620 # @retval a dict object contains settings of given PCD type
2622 def _GetDynamicHiiPcd(self
, Type
):
2626 Pcds
= OrderedDict()
2627 UserDefinedDefaultStores
= []
2629 # tdict is a special dict kind of type, used for selecting correct
2630 # PCD settings for certain ARCH and SKU
2632 PcdDict
= tdict(True, 5)
2634 RecordList
= self
._RawData
[Type
, self
._Arch
]
2635 # Find out all possible PCD candidates for self._Arch
2636 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2637 DefaultStoresDefine
= self
._GetDefaultStores
()
2639 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
, Dummy5
in RecordList
:
2640 SkuName
= SkuName
.upper()
2641 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2642 DefaultStore
= DefaultStore
.upper()
2643 if DefaultStore
== TAB_COMMON
:
2644 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2646 #The end user define [DefaultStores] and [SKUID_IDENTIFIER.Menufacturing] in DSC
2647 UserDefinedDefaultStores
.append((PcdCName
, TokenSpaceGuid
))
2648 if SkuName
not in AvailableSkuIdSet
:
2649 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2650 File
=self
.MetaFile
, Line
=Dummy5
)
2651 if DefaultStore
not in DefaultStoresDefine
:
2652 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2653 File
=self
.MetaFile
, Line
=Dummy5
)
2654 if "." not in TokenSpaceGuid
:
2655 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy5
))
2656 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
] = Setting
2659 # Remove redundant PCD candidates, per the ARCH and SKU
2660 for PcdCName
, TokenSpaceGuid
, SkuName
, DefaultStore
, Dummy4
in PcdSet
:
2662 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
, DefaultStore
]
2665 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2667 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2669 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2670 ExtraData
="[%s]" % VarAttribute
)
2672 FormatCorrect
= True
2673 if VariableOffset
.isdigit():
2674 if int(VariableOffset
, 10) > 0xFFFF:
2676 elif variablePattern
.match(VariableOffset
):
2677 if int(VariableOffset
, 16) > 0xFFFF:
2679 # For Offset written in "A.B"
2680 elif VariableOffset
.find('.') > -1:
2681 VariableOffsetList
= VariableOffset
.split(".")
2682 if not (len(VariableOffsetList
) == 2
2683 and IsValidWord(VariableOffsetList
[0])
2684 and IsValidWord(VariableOffsetList
[1])):
2685 FormatCorrect
= False
2687 FormatCorrect
= False
2688 if not FormatCorrect
:
2689 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2692 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2693 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2694 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2696 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2697 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
)]))
2699 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2700 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2701 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2702 if SkuName
in pcdObject
.SkuInfoList
:
2703 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2704 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2706 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2707 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2709 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
, DefaultStore
={DefaultStore
:DefaultValue
})
2710 PcdClassObj
= PcdClassObject(
2713 self
._PCD
_TYPE
_STRING
_[Type
],
2718 OrderedDict({SkuName
: SkuInfo
}),
2721 pcdDecObject
.validateranges
,
2722 pcdDecObject
.validlists
,
2723 pcdDecObject
.expressions
,
2725 if (PcdCName
, TokenSpaceGuid
) in UserDefinedDefaultStores
:
2726 PcdClassObj
.UserDefinedDefaultStoresFlag
= True
2727 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObj
2729 Pcds
[PcdCName
, TokenSpaceGuid
].CustomAttribute
['DscPosition'] = int(Dummy4
)
2730 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2731 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2732 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][DefaultStore
] = DefaultValue
2733 for pcd
in Pcds
.values():
2734 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2735 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2736 pcd
.DatumType
= pcdDecObject
.DatumType
2737 # Only fix the value while no value provided in DSC file.
2738 for sku
in pcd
.SkuInfoList
.values():
2739 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2740 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2741 for default_store
in sku
.DefaultStoreDict
:
2742 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2743 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2744 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2745 valuefromDec
= pcdDecObject
.DefaultValue
2746 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
, VariableAttribute
=SkuInfoObj
.VariableAttribute
, DefaultStore
={DefaultStore
:valuefromDec
})
2747 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2748 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2749 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2750 del pcd
.SkuInfoList
[TAB_COMMON
]
2751 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2752 del pcd
.SkuInfoList
[TAB_COMMON
]
2754 if pcd
.MaxDatumSize
.strip():
2755 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2758 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
2759 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2761 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2762 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2763 if datalen
> MaxSize
:
2765 for defaultst
in skuobj
.DefaultStoreDict
:
2766 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2767 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
2768 pcd
.MaxDatumSize
= str(MaxSize
)
2769 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
2771 invalidpcd
= ",".join(invalidhii
)
2772 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
)
2774 map(self
.FilterSkuSettings
, Pcds
.values())
2779 def CheckVariableNameAssignment(Pcds
):
2781 for pcdname
in Pcds
:
2783 varnameset
= set(sku
.VariableName
for (skuid
, sku
) in pcd
.SkuInfoList
.items())
2784 if len(varnameset
) > 1:
2785 invalidhii
.append(".".join((pcdname
[1], pcdname
[0])))
2787 return False, invalidhii
2790 ## Retrieve dynamic VPD PCD settings
2792 # @param Type PCD type
2794 # @retval a dict object contains settings of given PCD type
2796 def _GetDynamicVpdPcd(self
, Type
):
2799 Pcds
= OrderedDict()
2801 # tdict is a special dict kind of type, used for selecting correct
2802 # PCD settings for certain ARCH and SKU
2804 PcdDict
= tdict(True, 4)
2807 # Find out all possible PCD candidates for self._Arch
2808 RecordList
= self
._RawData
[Type
, self
._Arch
]
2809 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2811 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
, Dummy5
in RecordList
:
2812 SkuName
= SkuName
.upper()
2813 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2814 if SkuName
not in AvailableSkuIdSet
:
2815 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2816 File
=self
.MetaFile
, Line
=Dummy5
)
2817 if "." not in TokenSpaceGuid
:
2818 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2819 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2821 # Remove redundant PCD candidates, per the ARCH and SKU
2822 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2823 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2827 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
2828 # For the Integer & Boolean type, the optional data can only be InitialValue.
2829 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
2830 # until the DEC parser has been called.
2832 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2834 if int(MaxDatumSize
, 0) > 0xFFFF:
2835 EdkLogger
.error('build', FORMAT_INVALID
, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2836 File
=self
.MetaFile
, Line
=Dummy4
)
2837 if int(MaxDatumSize
, 0) < 0:
2838 EdkLogger
.error('build', FORMAT_INVALID
, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid
, PcdCName
)),
2839 File
=self
.MetaFile
, Line
=Dummy4
)
2840 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
2841 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2842 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2843 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2844 if MaxDatumSize
.strip():
2845 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2848 if pcdObject
.MaxDatumSize
:
2849 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2852 if CurrentMaxSize
> PcdMaxSize
:
2853 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2855 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2858 self
._PCD
_TYPE
_STRING
_[Type
],
2863 OrderedDict({SkuName
: SkuInfo
}),
2868 if SkuName
not in Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
:
2869 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
] = {}
2870 Pcds
[PcdCName
, TokenSpaceGuid
].DscRawValue
[SkuName
][TAB_DEFAULT_STORES_DEFAULT
] = InitialValue
2871 for pcd
in Pcds
.values():
2872 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2873 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2874 pcd
.DatumType
= pcdDecObject
.DatumType
2875 # Only fix the value while no value provided in DSC file.
2876 for sku
in pcd
.SkuInfoList
.values():
2877 if not sku
.DefaultValue
:
2878 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2879 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2880 valuefromDec
= pcdDecObject
.DefaultValue
2881 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
2882 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2883 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2884 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2885 del pcd
.SkuInfoList
[TAB_COMMON
]
2886 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2887 del pcd
.SkuInfoList
[TAB_COMMON
]
2889 #For the same one VOID* pcd, if the default value type of one SKU is "Unicode string",
2890 #the other SKUs are "OtherVOID*"(ASCII string or byte array),Then convert "Unicode string" to "byte array".
2891 for pcd
in Pcds
.values():
2892 PcdValueTypeSet
= set()
2893 for sku
in pcd
.SkuInfoList
.values():
2894 PcdValueTypeSet
.add("UnicodeString" if sku
.DefaultValue
.startswith(('L"',"L'")) else "OtherVOID*")
2895 if len(PcdValueTypeSet
) > 1:
2896 for sku
in pcd
.SkuInfoList
.values():
2897 sku
.DefaultValue
= StringToArray(sku
.DefaultValue
) if sku
.DefaultValue
.startswith(('L"',"L'")) else sku
.DefaultValue
2899 map(self
.FilterSkuSettings
, Pcds
.values())
2902 ## Add external modules
2904 # The external modules are mostly those listed in FDF file, which don't
2907 # @param FilePath The path of module description file
2909 def AddModule(self
, FilePath
):
2910 FilePath
= NormPath(FilePath
)
2911 if FilePath
not in self
.Modules
:
2912 Module
= ModuleBuildClassObject()
2913 Module
.MetaFile
= FilePath
2914 self
.Modules
.append(Module
)
2917 def ToolChainFamily(self
):
2918 self
._ToolChainFamily
= TAB_COMPILER_MSFT
2919 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
2920 if os
.path
.isfile(BuildConfigurationFile
) == True:
2921 TargetTxt
= TargetTxtClassObject()
2922 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
2923 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
2924 if ToolDefinitionFile
== '':
2925 ToolDefinitionFile
= "tools_def.txt"
2926 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
2927 if os
.path
.isfile(ToolDefinitionFile
) == True:
2928 ToolDef
= ToolDefClassObject()
2929 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
2930 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
2931 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
2932 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
2933 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
2934 self
._ToolChainFamily
= TAB_COMPILER_MSFT
2936 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
2937 return self
._ToolChainFamily
2939 ## Add external PCDs
2941 # The external PCDs are mostly those listed in FDF file to specify address
2942 # or offset information.
2944 # @param Name Name of the PCD
2945 # @param Guid Token space guid of the PCD
2946 # @param Value Value of the PCD
2948 def AddPcd(self
, Name
, Guid
, Value
):
2949 if (Name
, Guid
) not in self
.Pcds
:
2950 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
2951 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
2955 if self
._DecPcds
is None:
2957 if GlobalData
.gFdfParser
:
2958 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
2960 for Inf
in FdfInfList
:
2961 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
2962 if ModuleFile
in self
._Modules
:
2964 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
2965 PkgSet
.update(ModuleData
.Packages
)
2966 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
, PkgSet
)
2967 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
2968 return self
._DecPcds