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 Common
.String
import *
21 from Common
.DataType
import *
22 from Common
.Misc
import *
24 from Common
.Expression
import *
25 from CommonDataClass
.CommonClass
import SkuInfoClass
26 from Common
.TargetTxtClassObject
import *
27 from Common
.ToolDefClassObject
import *
28 from MetaDataTable
import *
29 from MetaFileTable
import *
30 from MetaFileParser
import *
32 from WorkspaceCommon
import GetDeclaredPcd
33 from Common
.Misc
import AnalyzeDscPcd
34 from Common
.Misc
import ProcessDuplicatedInf
36 from Common
.Parsing
import IsValidWord
37 from Common
.VariableAttributes
import VariableAttributes
38 import Common
.GlobalData
as GlobalData
40 from Common
.Misc
import SaveFileOnChange
41 from Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
42 from collections
import OrderedDict
,defaultdict
44 PcdValueInitName
= 'PcdValueInit'
55 #include <PcdValueCommon.h>
65 return PcdValueMain (argc, argv);
69 PcdMakefileHeader
= '''
72 # This file is auto-generated by build utility
77 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
78 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
80 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
82 LIBS = $(LIB_PATH)\Common.lib
84 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
88 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
92 variablePattern
= re
.compile(r
'[\t\s]*0[xX][a-fA-F0-9]+$')
94 ## regular expressions for finding decimal and hex numbers
95 Pattern
= re
.compile('^[1-9]\d*|0$')
96 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
97 ## Regular expression for finding header file inclusions
98 from AutoGen
.GenMake
import gIncludePattern
100 ## Find dependencies for one source file
102 # By searching recursively "#include" directive in file, find out all the
103 # files needed by given source file. The dependecies will be only searched
104 # in given search path list.
106 # @param SearchPathList The list of search path
108 # @retval list The list of files the given source file depends on
110 def GetDependencyList(FileStack
,SearchPathList
):
112 DependencySet
= set(FileStack
)
113 while len(FileStack
) > 0:
115 FullPathDependList
= []
116 CurrentFileDependencyList
= []
118 CurrentFileDependencyList
= DepDb
[F
]
122 FileContent
= Fd
.read()
123 except BaseException
, X
:
124 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
+ "\n\t" + str(X
))
126 if "Fd" in dir(locals()):
129 if len(FileContent
) == 0:
132 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
133 FileContent
= unicode(FileContent
, "utf-16")
134 IncludedFileList
= gIncludePattern
.findall(FileContent
)
136 for Inc
in IncludedFileList
:
138 Inc
= os
.path
.normpath(Inc
)
139 CurrentFileDependencyList
.append(Inc
)
140 DepDb
[F
] = CurrentFileDependencyList
142 CurrentFilePath
= os
.path
.dirname(F
)
143 PathList
= [CurrentFilePath
] + SearchPathList
144 for Inc
in CurrentFileDependencyList
:
145 for SearchPath
in PathList
:
146 FilePath
= os
.path
.join(SearchPath
, Inc
)
147 if not os
.path
.exists(FilePath
):
149 if FilePath
not in DependencySet
:
150 FileStack
.append(FilePath
)
151 FullPathDependList
.append(FilePath
)
153 DependencySet
.update(FullPathDependList
)
154 DependencyList
= list(DependencySet
) # remove duplicate ones
156 return DependencyList
158 class DscBuildData(PlatformBuildClassObject
):
159 # dict used to convert PCD type in database to string used by build tool
160 _PCD_TYPE_STRING_
= {
161 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
162 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
163 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
164 MODEL_PCD_DYNAMIC
: "Dynamic",
165 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
166 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
167 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
168 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
169 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
170 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
171 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
174 # dict used to convert part of [Defines] to members of DscBuildData directly
179 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
180 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
181 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
182 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
183 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
184 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
185 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
186 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
187 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
188 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
189 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
190 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
191 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
192 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
193 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
196 # used to compose dummy library class name for those forced library instances
197 _NullLibraryNumber
= 0
199 ## Constructor of DscBuildData
201 # Initialize object of DscBuildData
203 # @param FilePath The path of platform description file
204 # @param RawData The raw data of DSC file
205 # @param BuildDataBase Database used to retrieve module/package information
206 # @param Arch The target architecture
207 # @param Platform (not used for DscBuildData)
208 # @param Macros Macros used for replacement in DSC file
210 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
211 self
.MetaFile
= FilePath
212 self
._RawData
= RawData
213 self
._Bdb
= BuildDataBase
215 self
._Target
= Target
216 self
._Toolchain
= Toolchain
217 self
._ToolChainFamily
= None
219 self
._HandleOverridePath
()
220 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
221 self
.DefaultStores
= None
222 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
224 def OutputPath(self
):
225 if os
.getenv("WORKSPACE"):
226 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
,PcdValueInitName
)
228 return os
.path
.dirname(self
.DscFile
)
231 def __setitem__(self
, key
, value
):
232 self
.__dict
__[self
._PROPERTY
_[key
]] = value
235 def __getitem__(self
, key
):
236 return self
.__dict
__[self
._PROPERTY
_[key
]]
239 def __contains__(self
, key
):
240 return key
in self
._PROPERTY
_
242 ## Set all internal used members of DscBuildData to None
245 self
._PlatformName
= None
248 self
._DscSpecification
= None
249 self
._OutputDirectory
= None
250 self
._SupArchList
= None
251 self
._BuildTargets
= None
253 self
._PcdInfoFlag
= None
254 self
._VarCheckFlag
= None
255 self
._FlashDefinition
= None
256 self
._Prebuild
= None
257 self
._Postbuild
= None
258 self
._BuildNumber
= None
259 self
._MakefileName
= None
260 self
._BsBaseAddress
= None
261 self
._RtBaseAddress
= None
264 self
._LibraryInstances
= None
265 self
._LibraryClasses
= None
268 self
._BuildOptions
= None
269 self
._ModuleTypeOptions
= None
270 self
._LoadFixAddress
= None
271 self
._RFCLanguages
= None
272 self
._ISOLanguages
= None
273 self
._VpdToolGuid
= None
275 self
.DefaultStores
= None
278 ## handle Override Path of Module
279 def _HandleOverridePath(self
):
280 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
281 for Record
in RecordList
:
284 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
285 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
287 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
289 # Check if the source override path exists
290 if not os
.path
.isdir(SourceOverridePath
):
291 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
293 # Add to GlobalData Variables
294 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
296 ## Get current effective macros
297 def _GetMacros(self
):
298 if self
.__Macros
is None:
300 self
.__Macros
.update(GlobalData
.gPlatformDefines
)
301 self
.__Macros
.update(GlobalData
.gGlobalDefines
)
302 self
.__Macros
.update(GlobalData
.gCommandLineDefines
)
311 # Changing the default ARCH to another may affect all other information
312 # because all information in a platform may be ARCH-related. That's
313 # why we need to clear all internal used members, in order to cause all
314 # information to be re-retrieved.
316 # @param Value The value of ARCH
318 def _SetArch(self
, Value
):
319 if self
._Arch
== Value
:
324 ## Retrieve all information in [Defines] section
326 # (Retriving all [Defines] information in one-shot is just to save time.)
328 def _GetHeaderInfo(self
):
329 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
330 for Record
in RecordList
:
332 # items defined _PROPERTY_ don't need additional processing
334 # some special items in [Defines] section need special treatment
335 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
336 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
337 if ' ' in self
._OutputDirectory
:
338 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
339 File
=self
.MetaFile
, Line
=Record
[-1],
340 ExtraData
=self
._OutputDirectory
)
341 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
342 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
343 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
345 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
347 elif Name
== TAB_DSC_PREBUILD
:
348 PrebuildValue
= Record
[2]
349 if Record
[2][0] == '"':
350 if Record
[2][-1] != '"':
351 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
352 File
=self
.MetaFile
, Line
=Record
[-1])
353 PrebuildValue
= Record
[2][1:-1]
354 self
._Prebuild
= PrebuildValue
355 elif Name
== TAB_DSC_POSTBUILD
:
356 PostbuildValue
= Record
[2]
357 if Record
[2][0] == '"':
358 if Record
[2][-1] != '"':
359 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
360 File
=self
.MetaFile
, Line
=Record
[-1])
361 PostbuildValue
= Record
[2][1:-1]
362 self
._Postbuild
= PostbuildValue
363 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
364 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
365 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
366 self
._BuildTargets
= GetSplitValueList(Record
[2])
367 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
368 if self
._SkuName
is None:
369 self
._SkuName
= Record
[2]
370 if GlobalData
.gSKUID_CMD
:
371 self
._SkuName
= GlobalData
.gSKUID_CMD
372 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
373 self
._PcdInfoFlag
= Record
[2]
374 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
375 self
._VarCheckFlag
= Record
[2]
376 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
378 self
._LoadFixAddress
= int (Record
[2], 0)
380 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
381 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
382 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
383 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"',
384 File
=self
.MetaFile
, Line
=Record
[-1])
385 LanguageCodes
= Record
[2][1:-1]
386 if not LanguageCodes
:
387 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
388 File
=self
.MetaFile
, Line
=Record
[-1])
389 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
390 # check whether there is empty entries in the list
391 if None in LanguageList
:
392 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
393 File
=self
.MetaFile
, Line
=Record
[-1])
394 self
._RFCLanguages
= LanguageList
395 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
396 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
397 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
398 File
=self
.MetaFile
, Line
=Record
[-1])
399 LanguageCodes
= Record
[2][1:-1]
400 if not LanguageCodes
:
401 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
402 File
=self
.MetaFile
, Line
=Record
[-1])
403 if len(LanguageCodes
) % 3:
404 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
405 File
=self
.MetaFile
, Line
=Record
[-1])
407 for i
in range(0, len(LanguageCodes
), 3):
408 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
409 self
._ISOLanguages
= LanguageList
410 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
412 # try to convert GUID to a real UUID value to see whether the GUID is format
413 # for VPD_TOOL_GUID is correct.
418 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
419 self
._VpdToolGuid
= Record
[2]
421 self
[Name
] = Record
[2]
422 # set _Header to non-None in order to avoid database re-querying
423 self
._Header
= 'DUMMY'
425 ## Retrieve platform name
426 def _GetPlatformName(self
):
427 if self
._PlatformName
is None:
428 if self
._Header
is None:
429 self
._GetHeaderInfo
()
430 if self
._PlatformName
is None:
431 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
432 return self
._PlatformName
434 ## Retrieve file guid
435 def _GetFileGuid(self
):
436 if self
._Guid
is None:
437 if self
._Header
is None:
438 self
._GetHeaderInfo
()
439 if self
._Guid
is None:
440 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
443 ## Retrieve platform version
444 def _GetVersion(self
):
445 if self
._Version
is None:
446 if self
._Header
is None:
447 self
._GetHeaderInfo
()
448 if self
._Version
is None:
449 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
452 ## Retrieve platform description file version
453 def _GetDscSpec(self
):
454 if self
._DscSpecification
is None:
455 if self
._Header
is None:
456 self
._GetHeaderInfo
()
457 if self
._DscSpecification
is None:
458 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
459 return self
._DscSpecification
461 ## Retrieve OUTPUT_DIRECTORY
462 def _GetOutpuDir(self
):
463 if self
._OutputDirectory
is None:
464 if self
._Header
is None:
465 self
._GetHeaderInfo
()
466 if self
._OutputDirectory
is None:
467 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
468 return self
._OutputDirectory
470 ## Retrieve SUPPORTED_ARCHITECTURES
471 def _GetSupArch(self
):
472 if self
._SupArchList
is None:
473 if self
._Header
is None:
474 self
._GetHeaderInfo
()
475 if self
._SupArchList
is None:
476 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
477 return self
._SupArchList
479 ## Retrieve BUILD_TARGETS
480 def _GetBuildTarget(self
):
481 if self
._BuildTargets
is None:
482 if self
._Header
is None:
483 self
._GetHeaderInfo
()
484 if self
._BuildTargets
is None:
485 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
486 return self
._BuildTargets
488 def _GetPcdInfoFlag(self
):
489 if self
._PcdInfoFlag
is None or self
._PcdInfoFlag
.upper() == 'FALSE':
491 elif self
._PcdInfoFlag
.upper() == 'TRUE':
495 def _GetVarCheckFlag(self
):
496 if self
._VarCheckFlag
is None or self
._VarCheckFlag
.upper() == 'FALSE':
498 elif self
._VarCheckFlag
.upper() == 'TRUE':
503 # # Retrieve SKUID_IDENTIFIER
504 def _GetSkuName(self
):
505 if self
._SkuName
is None:
506 if self
._Header
is None:
507 self
._GetHeaderInfo
()
508 if self
._SkuName
is None:
509 self
._SkuName
= TAB_DEFAULT
512 ## Override SKUID_IDENTIFIER
513 def _SetSkuName(self
, Value
):
514 self
._SkuName
= Value
516 def _GetFdfFile(self
):
517 if self
._FlashDefinition
is None:
518 if self
._Header
is None:
519 self
._GetHeaderInfo
()
520 if self
._FlashDefinition
is None:
521 self
._FlashDefinition
= ''
522 return self
._FlashDefinition
524 def _GetPrebuild(self
):
525 if self
._Prebuild
is None:
526 if self
._Header
is None:
527 self
._GetHeaderInfo
()
528 if self
._Prebuild
is None:
530 return self
._Prebuild
532 def _GetPostbuild(self
):
533 if self
._Postbuild
is None:
534 if self
._Header
is None:
535 self
._GetHeaderInfo
()
536 if self
._Postbuild
is None:
538 return self
._Postbuild
540 ## Retrieve FLASH_DEFINITION
541 def _GetBuildNumber(self
):
542 if self
._BuildNumber
is None:
543 if self
._Header
is None:
544 self
._GetHeaderInfo
()
545 if self
._BuildNumber
is None:
546 self
._BuildNumber
= ''
547 return self
._BuildNumber
549 ## Retrieve MAKEFILE_NAME
550 def _GetMakefileName(self
):
551 if self
._MakefileName
is None:
552 if self
._Header
is None:
553 self
._GetHeaderInfo
()
554 if self
._MakefileName
is None:
555 self
._MakefileName
= ''
556 return self
._MakefileName
558 ## Retrieve BsBaseAddress
559 def _GetBsBaseAddress(self
):
560 if self
._BsBaseAddress
is None:
561 if self
._Header
is None:
562 self
._GetHeaderInfo
()
563 if self
._BsBaseAddress
is None:
564 self
._BsBaseAddress
= ''
565 return self
._BsBaseAddress
567 ## Retrieve RtBaseAddress
568 def _GetRtBaseAddress(self
):
569 if self
._RtBaseAddress
is None:
570 if self
._Header
is None:
571 self
._GetHeaderInfo
()
572 if self
._RtBaseAddress
is None:
573 self
._RtBaseAddress
= ''
574 return self
._RtBaseAddress
576 ## Retrieve the top address for the load fix address
577 def _GetLoadFixAddress(self
):
578 if self
._LoadFixAddress
is None:
579 if self
._Header
is None:
580 self
._GetHeaderInfo
()
582 if self
._LoadFixAddress
is None:
583 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
586 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
588 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
591 # If command line defined, should override the value in DSC file.
593 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
:
595 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
597 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']))
599 if self
._LoadFixAddress
< 0:
600 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
601 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
602 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
604 return self
._LoadFixAddress
606 ## Retrieve RFCLanguage filter
607 def _GetRFCLanguages(self
):
608 if self
._RFCLanguages
is None:
609 if self
._Header
is None:
610 self
._GetHeaderInfo
()
611 if self
._RFCLanguages
is None:
612 self
._RFCLanguages
= []
613 return self
._RFCLanguages
615 ## Retrieve ISOLanguage filter
616 def _GetISOLanguages(self
):
617 if self
._ISOLanguages
is None:
618 if self
._Header
is None:
619 self
._GetHeaderInfo
()
620 if self
._ISOLanguages
is None:
621 self
._ISOLanguages
= []
622 return self
._ISOLanguages
623 ## Retrieve the GUID string for VPD tool
624 def _GetVpdToolGuid(self
):
625 if self
._VpdToolGuid
is None:
626 if self
._Header
is None:
627 self
._GetHeaderInfo
()
628 if self
._VpdToolGuid
is None:
629 self
._VpdToolGuid
= ''
630 return self
._VpdToolGuid
632 ## Retrieve [SkuIds] section information
633 def _GetSkuIds(self
):
634 if self
._SkuIds
is None:
635 self
._SkuIds
= OrderedDict()
636 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
637 for Record
in RecordList
:
638 if Record
[0] in [None, '']:
639 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
640 File
=self
.MetaFile
, Line
=Record
[-1])
641 if Record
[1] in [None, '']:
642 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
643 File
=self
.MetaFile
, Line
=Record
[-1])
644 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
645 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
646 File
=self
.MetaFile
, Line
=Record
[-1])
647 if not IsValidWord(Record
[1]):
648 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",
649 File
=self
.MetaFile
, Line
=Record
[-1])
650 self
._SkuIds
[Record
[1].upper()] = (str(DscBuildData
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
651 if TAB_DEFAULT
not in self
._SkuIds
:
652 self
._SkuIds
[TAB_DEFAULT
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
653 if TAB_COMMON
not in self
._SkuIds
:
654 self
._SkuIds
[TAB_COMMON
] = ("0", TAB_DEFAULT
, TAB_DEFAULT
)
659 return int(intstr
,16) if intstr
.upper().startswith("0X") else int(intstr
)
661 def _GetDefaultStores(self
):
662 if self
.DefaultStores
is None:
663 self
.DefaultStores
= OrderedDict()
664 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
665 for Record
in RecordList
:
666 if Record
[0] in [None, '']:
667 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
668 File
=self
.MetaFile
, Line
=Record
[-1])
669 if Record
[1] in [None, '']:
670 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
671 File
=self
.MetaFile
, Line
=Record
[-1])
672 if not Pattern
.match(Record
[0]) and not HexPattern
.match(Record
[0]):
673 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
674 File
=self
.MetaFile
, Line
=Record
[-1])
675 if not IsValidWord(Record
[1]):
676 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_-.)*'",
677 File
=self
.MetaFile
, Line
=Record
[-1])
678 self
.DefaultStores
[Record
[1].upper()] = (DscBuildData
.ToInt(Record
[0]),Record
[1].upper())
679 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
680 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0,TAB_DEFAULT_STORES_DEFAULT
)
681 GlobalData
.gDefaultStores
= sorted(self
.DefaultStores
.keys())
682 return self
.DefaultStores
684 ## Retrieve [Components] section information
685 def _GetModules(self
):
686 if self
._Modules
is not None:
689 self
._Modules
= OrderedDict()
690 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
691 Macros
= self
._Macros
692 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
693 for Record
in RecordList
:
694 DuplicatedFile
= False
696 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
700 # check the file validation
701 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
703 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
706 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
707 if self
._Arch
!= TAB_ARCH_COMMON
and ModuleFile
in self
._Modules
:
708 DuplicatedFile
= True
710 Module
= ModuleBuildClassObject()
711 Module
.MetaFile
= ModuleFile
713 # get module private library instance
714 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
715 for Record
in RecordList
:
716 LibraryClass
= Record
[0]
717 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
720 # check the file validation
721 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
723 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
726 if LibraryClass
== '' or LibraryClass
== 'NULL':
727 self
._NullLibraryNumber
+= 1
728 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
729 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
730 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
731 if LibraryPath
not in self
.LibraryInstances
:
732 self
.LibraryInstances
.append(LibraryPath
)
734 # get module private PCD setting
735 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
736 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
737 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
738 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
739 TokenList
= GetSplitValueList(Setting
)
740 DefaultValue
= TokenList
[0]
741 # the format is PcdName| Value | VOID* | MaxDatumSize
742 if len(TokenList
) > 2:
743 MaxDatumSize
= TokenList
[2]
746 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
747 Pcd
= PcdClassObject(
759 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
761 # get module private build options
762 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
763 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
764 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
765 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
767 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
768 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
770 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
771 if DuplicatedFile
and not RecordList
:
772 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
774 if len(RecordList
) != 1:
775 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
776 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
777 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
778 ModuleFile
.Arch
= self
._Arch
780 self
._Modules
[ModuleFile
] = Module
783 ## Retrieve all possible library instances used in this platform
784 def _GetLibraryInstances(self
):
785 if self
._LibraryInstances
is None:
786 self
._GetLibraryClasses
()
787 return self
._LibraryInstances
789 ## Retrieve [LibraryClasses] information
790 def _GetLibraryClasses(self
):
791 if self
._LibraryClasses
is None:
792 self
._LibraryInstances
= []
794 # tdict is a special dict kind of type, used for selecting correct
795 # library instance for given library class and module type
797 LibraryClassDict
= tdict(True, 3)
798 # track all library class names
799 LibraryClassSet
= set()
800 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
801 Macros
= self
._Macros
802 for Record
in RecordList
:
803 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
,Dummy
, LineNo
= Record
804 if LibraryClass
== '' or LibraryClass
== 'NULL':
805 self
._NullLibraryNumber
+= 1
806 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
807 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
808 LibraryClassSet
.add(LibraryClass
)
809 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
810 # check the file validation
811 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
813 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
816 if ModuleType
!= TAB_COMMON
and ModuleType
not in SUP_MODULE_LIST
:
817 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
818 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
819 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
820 if LibraryInstance
not in self
._LibraryInstances
:
821 self
._LibraryInstances
.append(LibraryInstance
)
823 # resolve the specific library instance for each class and each module type
824 self
._LibraryClasses
= tdict(True)
825 for LibraryClass
in LibraryClassSet
:
826 # try all possible module types
827 for ModuleType
in SUP_MODULE_LIST
:
828 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
829 if LibraryInstance
is None:
831 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
833 # for Edk style library instances, which are listed in different section
834 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
835 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
836 for Record
in RecordList
:
837 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
839 # check the file validation
840 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
842 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
844 if File
not in self
._LibraryInstances
:
845 self
._LibraryInstances
.append(File
)
847 # we need the module name as the library class name, so we have
848 # to parse it here. (self._Bdb[] will trigger a file parse if it
849 # hasn't been parsed)
851 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
852 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
853 return self
._LibraryClasses
855 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
856 if self
._DecPcds
is None:
859 if GlobalData
.gFdfParser
:
860 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
863 for Inf
in FdfInfList
:
864 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
865 if ModuleFile
in self
._Modules
:
867 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
868 PkgSet
.update(ModuleData
.Packages
)
870 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
,PkgSet
)
871 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
873 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
874 EdkLogger
.error('build', PARSER_ERROR
,
875 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
876 File
=self
.MetaFile
, Line
=LineNo
)
877 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
879 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
880 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
881 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
883 if ValueList
[2] == '-1':
884 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
885 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
887 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
889 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
890 except BadExpression
, Value
:
891 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
892 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
893 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
894 except EvaluationException
, Excpt
:
895 if hasattr(Excpt
, 'Pcd'):
896 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
897 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
898 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
899 " of the DSC file" % Excpt
.Pcd
,
900 File
=self
.MetaFile
, Line
=LineNo
)
902 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
903 File
=self
.MetaFile
, Line
=LineNo
)
905 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
906 File
=self
.MetaFile
, Line
=LineNo
)
909 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
911 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
912 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
913 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
):
914 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
915 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
,
916 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
917 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
918 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
919 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
922 def _FilterPcdBySkuUsage(self
,Pcds
):
923 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
924 sku_usage
= self
.SkuIdMgr
.SkuUsageType
925 if sku_usage
== SkuClass
.SINGLE
:
928 Pcds
[pcdname
].SkuInfoList
= {TAB_DEFAULT
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
929 if type(pcd
) is StructurePcd
and pcd
.SkuOverrideValues
:
930 Pcds
[pcdname
].SkuOverrideValues
= {TAB_DEFAULT
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
934 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
935 if type(pcd
) is StructurePcd
and pcd
.SkuOverrideValues
:
936 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
938 def CompleteHiiPcdsDefaultStores(self
,Pcds
):
939 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
]]]
940 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
942 for skuid
in pcd
.SkuInfoList
:
943 skuobj
= pcd
.SkuInfoList
.get(skuid
)
944 if TAB_DEFAULT_STORES_DEFAULT
not in skuobj
.DefaultStoreDict
:
945 PcdDefaultStoreSet
= set([defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
])
946 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
947 skuobj
.DefaultStoreDict
[TAB_DEFAULT_STORES_DEFAULT
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
950 def RecoverCommandLinePcd(self
):
951 def UpdateCommandLineValue(pcd
):
952 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
953 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
954 pcd
.PcdValueFromComm
= pcd
.DefaultValue
955 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
956 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).HiiDefaultValue
958 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get(TAB_DEFAULT
).DefaultValue
959 for pcd
in self
._Pcds
:
960 if isinstance(self
._Pcds
[pcd
],StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
961 UpdateCommandLineValue(self
._Pcds
[pcd
])
963 def __ParsePcdFromCommandLine(self
):
964 if GlobalData
.BuildOptionPcd
:
965 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
966 if type(pcd
) is tuple:
968 (pcdname
, pcdvalue
) = pcd
.split('=')
970 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
972 (Name1
, Name2
) = pcdname
.split('.',1)
974 (Name3
, FieldName
) = Name2
.split(".",1)
975 if ((Name3
,Name1
)) in self
.DecPcds
:
978 TokenSpaceGuidCName
= Name1
982 TokenSpaceGuidCName
= ''
983 HasTokenSpace
= False
985 if ((Name2
,Name1
)) in self
.DecPcds
:
988 TokenSpaceGuidCName
= Name1
993 TokenSpaceGuidCName
= ''
994 HasTokenSpace
= False
998 TokenSpaceGuidCName
= ''
999 HasTokenSpace
= False
1000 TokenSpaceGuidCNameList
= []
1003 DisplayName
= TokenCName
1005 DisplayName
= TokenCName
+ '.' + FieldName
1006 if not HasTokenSpace
:
1007 for key
in self
.DecPcds
:
1008 PcdItem
= self
.DecPcds
[key
]
1009 if TokenCName
== PcdItem
.TokenCName
:
1010 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1011 if len (TokenSpaceGuidCNameList
) < 1:
1012 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1013 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1014 PcdDatumType
= PcdItem
.DatumType
1020 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1023 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
1024 PcdDatumType
= self
.DecPcds
[(TokenCName
, TokenSpaceGuidCName
)].DatumType
1028 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, DisplayName
))
1030 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (DisplayName
))
1031 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1033 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
, FieldName
)
1035 pcdvalue
= DscBuildData
.HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, pcdvalue
, PcdDatumType
, self
._GuidDict
)
1036 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, pcdvalue
)
1038 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
1039 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
,("build command options",1))
1041 for BuildData
in self
._Bdb
._CACHE
_.values():
1042 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1044 for key
in BuildData
.Pcds
:
1045 PcdItem
= BuildData
.Pcds
[key
]
1046 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1047 PcdItem
.DefaultValue
= pcdvalue
1050 def HandleFlexiblePcd(TokenSpaceGuidCName
, TokenCName
, PcdValue
, PcdDatumType
, GuidDict
, FieldName
=''):
1053 TokenCName
+= '.' + FieldName
1054 if PcdValue
.startswith('H'):
1055 if FieldName
and IsFieldValueAnArray(PcdValue
[1:]):
1056 PcdDatumType
= TAB_VOID
1058 if FieldName
and not IsArray
:
1061 PcdValue
= ValueExpressionEx(PcdValue
[1:], PcdDatumType
, GuidDict
)(True)
1062 except BadExpression
, Value
:
1063 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1064 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1065 elif PcdValue
.startswith("L'") or PcdValue
.startswith("'"):
1066 if FieldName
and IsFieldValueAnArray(PcdValue
):
1067 PcdDatumType
= TAB_VOID
1069 if FieldName
and not IsArray
:
1072 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1073 except BadExpression
, Value
:
1074 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1075 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1076 elif PcdValue
.startswith('L'):
1077 PcdValue
= 'L"' + PcdValue
[1:] + '"'
1078 if FieldName
and IsFieldValueAnArray(PcdValue
):
1079 PcdDatumType
= TAB_VOID
1081 if FieldName
and not IsArray
:
1084 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1085 except BadExpression
, Value
:
1086 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1087 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1089 if PcdValue
.upper() == 'FALSE':
1091 if PcdValue
.upper() == 'TRUE':
1094 if PcdDatumType
not in TAB_PCD_NUMERIC_TYPES
:
1095 PcdValue
= '"' + PcdValue
+ '"'
1099 if PcdValue
.upper().startswith('0X'):
1102 Num
= int(PcdValue
, Base
)
1104 PcdValue
= '"' + PcdValue
+ '"'
1105 if IsFieldValueAnArray(PcdValue
):
1106 PcdDatumType
= TAB_VOID
1111 PcdValue
= ValueExpressionEx(PcdValue
, PcdDatumType
, GuidDict
)(True)
1112 except BadExpression
, Value
:
1113 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1114 (TokenSpaceGuidCName
, TokenCName
, PcdValue
, Value
))
1117 ## Retrieve all PCD settings in platform
1119 if self
._Pcds
is None:
1120 self
._Pcds
= OrderedDict()
1121 self
.__ParsePcdFromCommandLine
()
1122 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1123 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1124 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1125 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1126 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1127 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1128 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1129 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1130 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1132 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1133 self
._Pcds
= self
.OverrideByFdfCommOverAll(self
._Pcds
)
1134 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1135 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1136 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1138 self
.RecoverCommandLinePcd()
1141 ## Retrieve [BuildOptions]
1142 def _GetBuildOptions(self
):
1143 if self
._BuildOptions
is None:
1144 self
._BuildOptions
= OrderedDict()
1146 # Retrieve build option for EDKII and EDK style module
1148 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1149 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1150 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1151 if Dummy3
.upper() != TAB_COMMON
:
1153 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1155 # Only flags can be appended
1157 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1158 self
._BuildOptions
[CurKey
] = Option
1160 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1161 self
._BuildOptions
[CurKey
] += ' ' + Option
1162 return self
._BuildOptions
1164 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1165 if self
._ModuleTypeOptions
is None:
1166 self
._ModuleTypeOptions
= OrderedDict()
1167 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1168 options
= OrderedDict()
1169 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1170 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1171 CommonDriverType
= '%s.%s' % (TAB_COMMON
, ModuleType
)
1172 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1173 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1174 Type
= Dummy2
+ '.' + Dummy3
1175 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1176 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1177 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1178 options
[Key
] = Option
1180 if ' ' + Option
not in options
[Key
]:
1181 options
[Key
] += ' ' + Option
1182 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1185 def GetStructurePcdInfo(PcdSet
):
1186 structure_pcd_data
= defaultdict(list)
1188 structure_pcd_data
[(item
[0],item
[1])].append(item
)
1190 return structure_pcd_data
1193 def OverrideByFdfComm(StruPcds
):
1194 StructurePcdInCom
= OrderedDict()
1195 for item
in GlobalData
.BuildOptionPcd
:
1196 if len(item
) == 5 and (item
[1],item
[0]) in StruPcds
:
1197 StructurePcdInCom
[(item
[0],item
[1],item
[2] )] = (item
[3],item
[4])
1198 GlobalPcds
= {(item
[0],item
[1]) for item
in StructurePcdInCom
}
1199 for Pcd
in StruPcds
.values():
1200 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1202 FieldValues
= OrderedDict()
1203 for item
in StructurePcdInCom
:
1204 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1205 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1206 for field
in FieldValues
:
1207 if field
not in Pcd
.PcdFieldValueFromComm
:
1208 Pcd
.PcdFieldValueFromComm
[field
] = ["","",""]
1209 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1210 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1211 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1214 def OverrideByFdfCommOverAll(self
,AllPcds
):
1215 def CheckStructureInComm(commpcds
):
1218 if len(commpcds
[0]) == 5:
1222 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1223 StructurePcdInCom
= {(item
[0],item
[1],item
[2] ):(item
[3],item
[4]) for item
in GlobalData
.BuildOptionPcd
} if GlobalData
.BuildOptionPcd
else {}
1224 NoFiledValues
= {(item
[0],item
[1]):StructurePcdInCom
[item
] for item
in StructurePcdInCom
if not item
[2]}
1226 NoFiledValues
= {(item
[0],item
[1]):[item
[2]] for item
in GlobalData
.BuildOptionPcd
}
1227 for Guid
,Name
in NoFiledValues
:
1228 if (Name
,Guid
) in AllPcds
:
1229 Pcd
= AllPcds
.get((Name
,Guid
))
1230 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1231 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1233 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1234 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1235 for sku
in Pcd
.SkuInfoList
:
1236 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1237 if SkuInfo
.DefaultValue
:
1238 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1240 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1241 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1242 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1243 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
]]:
1244 if Pcd
.DatumType
== TAB_VOID
:
1245 if not Pcd
.MaxDatumSize
:
1246 Pcd
.MaxDatumSize
= '0'
1247 CurrentSize
= int(Pcd
.MaxDatumSize
,16) if Pcd
.MaxDatumSize
.upper().startswith("0X") else int(Pcd
.MaxDatumSize
)
1248 OptionSize
= len((StringToArray(Pcd
.PcdValueFromComm
)).split(","))
1249 MaxSize
= max(CurrentSize
, OptionSize
)
1250 Pcd
.MaxDatumSize
= str(MaxSize
)
1252 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1254 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
,Name
)][0]
1255 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1256 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
],
1257 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FEATURE_FLAG
]]:
1258 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1259 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
,Name
)][0]
1261 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1263 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1264 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1265 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1266 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1267 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1268 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1271 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1272 SkuIds
= self
.SkuIdMgr
.AvailableSkuIdSet
1273 SkuIds
.update({TAB_DEFAULT
:0})
1274 DefaultStores
= {storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
}
1277 # Find out all possible PCD candidates for self._Arch
1280 for Type
in TypeList
:
1281 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1283 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
,Dummy5
in RecordList
:
1284 SkuName
= SkuName
.upper()
1285 default_store
= default_store
.upper()
1286 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1287 if SkuName
not in SkuIds
:
1290 if SkuName
in SkuIds
and "." in TokenSpaceGuid
:
1291 S_PcdSet
.append([ TokenSpaceGuid
.split(".")[0],TokenSpaceGuid
.split(".")[1], PcdCName
,SkuName
, default_store
,Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1293 # handle pcd value override
1294 StrPcdSet
= DscBuildData
.GetStructurePcdInfo(S_PcdSet
)
1295 S_pcd_set
= OrderedDict()
1296 for str_pcd
in StrPcdSet
:
1297 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1298 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1299 if not isinstance (str_pcd_dec
, StructurePcd
):
1300 EdkLogger
.error('build', PARSER_ERROR
,
1301 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1302 File
=self
.MetaFile
,Line
= StrPcdSet
[str_pcd
][0][5])
1304 str_pcd_obj_str
= StructurePcd()
1305 str_pcd_obj_str
.copy(str_pcd_dec
)
1307 str_pcd_obj_str
.copy(str_pcd_obj
)
1308 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1309 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
}
1311 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
}
1312 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1313 if str_pcd_data
[3] in SkuIds
:
1314 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])
1315 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1317 EdkLogger
.error('build', PARSER_ERROR
,
1318 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1319 File
=self
.MetaFile
,Line
= StrPcdSet
[str_pcd
][0][5])
1320 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1321 for Pcd
in self
.DecPcds
:
1322 if type (self
._DecPcds
[Pcd
]) is StructurePcd
:
1323 if Pcd
not in S_pcd_set
:
1324 str_pcd_obj_str
= StructurePcd()
1325 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1326 str_pcd_obj
= Pcds
.get(Pcd
, None)
1328 str_pcd_obj_str
.copy(str_pcd_obj
)
1329 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1330 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
}
1332 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
}
1333 S_pcd_set
[Pcd
] = str_pcd_obj_str
1335 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1336 for stru_pcd
in S_pcd_set
.values():
1337 for skuid
in SkuIds
:
1338 if skuid
in stru_pcd
.SkuOverrideValues
:
1340 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1342 if skuid
not in stru_pcd
.SkuOverrideValues
:
1343 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1344 if nextskuid
== TAB_DEFAULT
:
1347 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1348 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
})
1350 stru_pcd
.ValueChain
[(skuid
,'')]= (nextskuid
,'')
1351 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1352 for skuid
in SkuIds
:
1355 if skuid
not in stru_pcd
.SkuOverrideValues
:
1356 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1357 if nextskuid
== TAB_DEFAULT
:
1360 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1363 PcdDefaultStoreSet
= set([defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
]])
1364 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1366 for defaultstoreid
in DefaultStores
:
1367 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1368 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = copy
.deepcopy(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1369 stru_pcd
.ValueChain
[(skuid
,defaultstoreid
)]= (nextskuid
,mindefaultstorename
)
1370 S_pcd_set
= DscBuildData
.OverrideByFdfComm(S_pcd_set
)
1371 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1373 for (skuname
,StoreName
,PcdGuid
,PcdName
,PcdValue
) in Str_Pcd_Values
:
1374 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1375 if str_pcd_obj
is None:
1376 print PcdName
, PcdGuid
1378 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1379 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1380 if skuname
not in str_pcd_obj
.SkuInfoList
:
1381 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1383 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1384 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1385 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1386 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1387 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1388 str_pcd_obj
.DefaultValue
= PcdValue
1390 if skuname
not in str_pcd_obj
.SkuInfoList
:
1391 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1393 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1394 if nextskuid
== TAB_DEFAULT
:
1397 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1398 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
)
1399 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1400 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1402 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1403 for str_pcd_obj
in S_pcd_set
.values():
1404 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1405 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1407 PcdDefaultStoreSet
= set([defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
])
1408 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1409 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1410 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1412 for str_pcd_obj
in S_pcd_set
.values():
1414 str_pcd_obj
.MaxDatumSize
= self
.GetStructurePcdMaxSize(str_pcd_obj
)
1415 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1419 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1420 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
1421 del pcd
.SkuInfoList
[TAB_COMMON
]
1422 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
1423 del pcd
.SkuInfoList
[TAB_COMMON
]
1425 map(self
.FilterSkuSettings
,[Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1428 ## Retrieve non-dynamic PCD settings
1430 # @param Type PCD type
1432 # @retval a dict object contains settings of given PCD type
1434 def _GetPcd(self
, Type
):
1435 Pcds
= OrderedDict()
1437 # tdict is a special dict kind of type, used for selecting correct
1438 # PCD settings for certain ARCH
1440 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1442 PcdDict
= tdict(True, 3)
1444 # Find out all possible PCD candidates for self._Arch
1445 RecordList
= self
._RawData
[Type
, self
._Arch
]
1446 PcdValueDict
= OrderedDict()
1447 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1448 SkuName
= SkuName
.upper()
1449 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
1450 if SkuName
not in AvailableSkuIdSet
:
1451 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1452 File
=self
.MetaFile
, Line
=Dummy5
)
1453 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT
, TAB_COMMON
):
1454 if "." not in TokenSpaceGuid
:
1455 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1456 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1458 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1459 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1462 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1463 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1464 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1466 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1468 for ((PcdCName
,TokenSpaceGuid
),PcdSetting
) in PcdValueDict
.iteritems():
1472 if TAB_COMMON
in PcdSetting
:
1473 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_COMMON
]
1474 if TAB_DEFAULT
in PcdSetting
:
1475 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[TAB_DEFAULT
]
1476 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1477 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1479 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1482 self
._PCD
_TYPE
_STRING
_[Type
],
1495 def GetStructurePcdMaxSize(self
, str_pcd
):
1496 pcd_default_value
= str_pcd
.DefaultValue
1497 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()]
1498 sku_values
.append(pcd_default_value
)
1500 def get_length(value
):
1501 Value
= value
.strip()
1503 if Value
.startswith('GUID') and Value
.endswith(')'):
1505 if Value
.startswith('L"') and Value
.endswith('"'):
1506 return len(Value
[2:-1])
1507 if Value
[0] == '"' and Value
[-1] == '"':
1508 return len(Value
) - 2
1509 if Value
[0] == '{' and Value
[-1] == '}':
1510 return len(Value
.split(","))
1511 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1512 return len(list(Value
[2:-1]))
1513 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1514 return len(Value
) - 2
1517 return str(max([pcd_size
for pcd_size
in [get_length(item
) for item
in sku_values
]]))
1520 def ExecuteCommand (Command
):
1522 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1524 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1525 Result
= Process
.communicate()
1526 return Process
.returncode
, Result
[0], Result
[1]
1529 def IntToCString(Value
, ValueSize
):
1531 if not isinstance (Value
, str):
1532 for Index
in range(0, ValueSize
):
1533 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1535 Result
= Result
+ '"'
1539 def GetPcdMaxSize(Pcd
):
1540 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
1541 return MAX_SIZE_TYPE
[Pcd
.DatumType
]
1543 MaxSize
= int(Pcd
.MaxDatumSize
,10) if Pcd
.MaxDatumSize
else 0
1544 if Pcd
.PcdValueFromComm
:
1545 if Pcd
.PcdValueFromComm
.startswith("{") and Pcd
.PcdValueFromComm
.endswith("}"):
1546 return max([len(Pcd
.PcdValueFromComm
.split(",")),MaxSize
])
1547 elif Pcd
.PcdValueFromComm
.startswith("\"") or Pcd
.PcdValueFromComm
.startswith("\'"):
1548 return max([len(Pcd
.PcdValueFromComm
)-2+1,MaxSize
])
1549 elif Pcd
.PcdValueFromComm
.startswith("L\""):
1550 return max([2*(len(Pcd
.PcdValueFromComm
)-3+1),MaxSize
])
1552 return max([len(Pcd
.PcdValueFromComm
),MaxSize
])
1555 def GenerateSizeFunction(self
,Pcd
):
1556 CApp
= "// Default Value in Dec \n"
1557 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1558 for FieldList
in [Pcd
.DefaultValues
]:
1561 for FieldName
in FieldList
:
1562 FieldName
= "." + FieldName
1563 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1564 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1566 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1567 except BadExpression
:
1568 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1569 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1570 Value
, ValueSize
= ParseFieldValue(Value
)
1571 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]);
1574 FieldName_ori
= FieldName
.strip('.')
1575 while '[' in FieldName
:
1576 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1577 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1578 FieldName
= FieldName
.split(']', 1)[1]
1579 FieldName
= NewFieldName
+ FieldName
1580 while '[' in FieldName
:
1581 FieldName
= FieldName
.rsplit('[', 1)[0]
1582 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])
1583 for skuname
in Pcd
.SkuOverrideValues
:
1584 if skuname
== TAB_COMMON
:
1586 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1587 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1588 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
].get(defaultstorenameitem
)]:
1591 for FieldName
in FieldList
:
1592 FieldName
= "." + FieldName
1593 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1594 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1596 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1597 except BadExpression
:
1598 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1599 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1600 Value
, ValueSize
= ParseFieldValue(Value
)
1601 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]);
1604 FieldName_ori
= FieldName
.strip('.')
1605 while '[' in FieldName
:
1606 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1607 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1608 FieldName
= FieldName
.split(']', 1)[1]
1609 FieldName
= NewFieldName
+ FieldName
1610 while '[' in FieldName
:
1611 FieldName
= FieldName
.rsplit('[', 1)[0]
1612 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])
1613 if Pcd
.PcdFieldValueFromComm
:
1614 CApp
= CApp
+ "// From Command Line \n"
1615 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1616 FieldName
= "." + FieldName
1617 IsArray
= IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1618 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1620 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], TAB_VOID
, self
._GuidDict
)(True)
1621 except BadExpression
:
1622 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1623 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1624 Value
, ValueSize
= ParseFieldValue(Value
)
1625 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]);
1628 FieldName_ori
= FieldName
.strip('.')
1629 while '[' in FieldName
:
1630 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1631 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1632 FieldName
= FieldName
.split(']', 1)[1]
1633 FieldName
= NewFieldName
+ FieldName
1634 while '[' in FieldName
:
1635 FieldName
= FieldName
.rsplit('[', 1)[0]
1636 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])
1637 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (DscBuildData
.GetPcdMaxSize(Pcd
),DscBuildData
.GetPcdMaxSize(Pcd
),DscBuildData
.GetPcdMaxSize(Pcd
))
1642 def GenerateSizeStatments(Pcd
):
1643 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1644 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1647 def GenerateDefaultValueAssignFunction(self
,Pcd
):
1648 CApp
= "// Default value in Dec \n"
1649 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
)
1650 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1651 CApp
= CApp
+ ' CHAR8 *Value;\n'
1652 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1653 IsArray
= IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1656 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, TAB_VOID
)(True)
1657 except BadExpression
:
1658 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1659 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1660 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1661 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1662 if isinstance(Value
, str):
1663 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1666 # Use memcpy() to copy value into field
1668 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1669 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1670 for FieldList
in [Pcd
.DefaultValues
]:
1673 for FieldName
in FieldList
:
1674 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1677 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1678 except BadExpression
:
1679 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1680 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1],FieldList
[FieldName
][2]))
1683 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1685 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]))
1686 if isinstance(Value
, str):
1687 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1690 # Use memcpy() to copy value into field
1692 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1693 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1694 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1697 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1699 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1704 def GenerateDefaultValueAssignStatement(Pcd
):
1705 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1708 def GenerateInitValueFunction(self
,Pcd
,SkuName
,DefaultStoreName
):
1709 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
,DefaultStoreName
)
1710 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
,DefaultStoreName
,Pcd
.DatumType
)
1711 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1712 CApp
= CApp
+ ' CHAR8 *Value;\n'
1714 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT
, TAB_DEFAULT_STORES_DEFAULT
)
1715 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1716 if (SkuName
,DefaultStoreName
) == (TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
):
1717 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(TAB_DEFAULT
,{}).get(TAB_DEFAULT_STORES_DEFAULT
, Pcd
.DefaultValue
) if Pcd
.DefaultFromDSC
else Pcd
.DefaultValue
1719 if not Pcd
.DscRawValue
:
1720 # handle the case that structure pcd is not appear in DSC
1721 self
.CopyDscRawValue(Pcd
)
1722 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
,{}).get(DefaultStoreName
)
1723 for FieldList
in [pcddefaultvalue
,inherit_OverrideValues
.get(DefaultStoreName
)]:
1726 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1727 IsArray
= IsFieldValueAnArray(FieldList
)
1730 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
1731 except BadExpression
:
1732 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
1733 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1734 Value
, ValueSize
= ParseFieldValue (FieldList
)
1736 if (SkuName
,DefaultStoreName
) == (TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
):
1737 if isinstance(Value
, str):
1738 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
)
1741 # Use memcpy() to copy value into field
1743 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
)
1744 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1746 if isinstance(Value
, str):
1747 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
,{}).get(DefaultStoreName
))
1750 # Use memcpy() to copy value into field
1752 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
,{}).get(DefaultStoreName
))
1753 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1755 if (SkuName
,DefaultStoreName
) == (TAB_DEFAULT
,TAB_DEFAULT_STORES_DEFAULT
) or (( (SkuName
,'') not in Pcd
.ValueChain
) and ( (SkuName
,DefaultStoreName
) not in Pcd
.ValueChain
)):
1756 for FieldName
in FieldList
:
1757 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1760 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1761 except BadExpression
:
1762 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1763 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1765 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1767 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]))
1768 if isinstance(Value
, str):
1769 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1772 # Use memcpy() to copy value into field
1774 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1775 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1776 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1779 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1781 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1786 def GenerateInitValueStatement(Pcd
,SkuName
,DefaultStoreName
):
1787 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
,DefaultStoreName
)
1790 def GenerateCommandLineValue(self
,Pcd
):
1791 CApp
= "// Value in CommandLine\n"
1792 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
)
1793 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1794 CApp
= CApp
+ ' CHAR8 *Value;\n'
1796 pcddefaultvalue
= Pcd
.PcdValueFromComm
1797 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromComm
]:
1800 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1801 IsArray
= IsFieldValueAnArray(FieldList
)
1804 FieldList
= ValueExpressionEx(FieldList
, TAB_VOID
)(True)
1805 except BadExpression
:
1806 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
1807 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1808 Value
, ValueSize
= ParseFieldValue (FieldList
)
1810 if isinstance(Value
, str):
1811 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
1814 # Use memcpy() to copy value into field
1816 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (DscBuildData
.IntToCString(Value
, ValueSize
))
1817 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1819 for FieldName
in FieldList
:
1820 IsArray
= IsFieldValueAnArray(FieldList
[FieldName
][0])
1823 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], TAB_VOID
, self
._GuidDict
)(True)
1824 except BadExpression
:
1825 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1826 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1830 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1832 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]))
1833 if isinstance(Value
, str):
1834 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1837 # Use memcpy() to copy value into field
1839 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1840 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1841 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1844 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1846 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1851 def GenerateCommandLineValueStatement(Pcd
):
1852 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1855 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
1856 OverrideValues
= {DefaultStore
:""}
1857 if Pcd
.SkuOverrideValues
:
1858 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1859 for DefaultStoreName
in OverrideValues
:
1860 CApp
= CApp
+ 'void\n'
1861 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1862 CApp
= CApp
+ ' void\n'
1863 CApp
= CApp
+ ' )\n'
1865 CApp
= CApp
+ ' UINT32 Size;\n'
1866 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1867 CApp
= CApp
+ ' CHAR8 *Value;\n'
1868 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
1869 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
1870 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.DatumType
, Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
1873 if SkuName
in Pcd
.SkuInfoList
:
1874 DefaultValue
= Pcd
.SkuInfoList
[SkuName
].DefaultStoreDict
.get(DefaultStoreName
,Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
if Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
else Pcd
.SkuInfoList
[SkuName
].DefaultValue
)
1876 DefaultValue
= Pcd
.DefaultValue
1877 PcdDefaultValue
= StringToArray(DefaultValue
.strip())
1879 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
1882 # Get current PCD value and size
1884 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1887 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
1888 # the correct value. For structures with a flexible array member, the flexible
1889 # array member is detected, and the size is based on the highest index used with
1890 # the flexible array member. The flexible array member must be the last field
1891 # in a structure. The size formula for this case is:
1892 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
1894 CApp
= CApp
+ DscBuildData
.GenerateSizeStatments(Pcd
)
1897 # Allocate and zero buffer for the PCD
1898 # Must handle cases where current value is smaller, larger, or same size
1899 # Always keep that larger one as the current size
1901 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
1902 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.DatumType
)
1903 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
1906 # Copy current PCD value into allocated buffer.
1908 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
1911 # Assign field values in PCD
1913 CApp
= CApp
+ DscBuildData
.GenerateDefaultValueAssignStatement(Pcd
)
1914 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1915 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1916 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
1917 storeset
= [DefaultStoreName
] if DefaultStoreName
== TAB_DEFAULT_STORES_DEFAULT
else [TAB_DEFAULT_STORES_DEFAULT
, DefaultStoreName
]
1918 for defaultstorenameitem
in storeset
:
1919 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1920 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
,skuname
,defaultstorenameitem
)
1921 if skuname
== SkuName
:
1924 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
1925 CApp
= CApp
+ DscBuildData
.GenerateInitValueStatement(Pcd
,self
.SkuIdMgr
.SystemSkuId
,TAB_DEFAULT_STORES_DEFAULT
)
1926 CApp
= CApp
+ DscBuildData
.GenerateCommandLineValueStatement(Pcd
)
1928 # Set new PCD value and size
1930 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1935 CApp
= CApp
+ ' free (Pcd);\n'
1938 return InitByteValue
, CApp
1940 def GenerateByteArrayValue (self
, StructuredPcds
):
1942 # Generate/Compile/Run C application to determine if there are any flexible array members
1944 if not StructuredPcds
:
1948 CApp
= PcdMainCHeader
1951 IncludeFiles
= set()
1952 for PcdName
in StructuredPcds
:
1953 Pcd
= StructuredPcds
[PcdName
]
1954 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
1955 if IncludeFile
not in Includes
:
1956 Includes
[IncludeFile
] = True
1957 IncludeFiles
.add(IncludeFile
)
1958 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
1960 for PcdName
in StructuredPcds
:
1961 Pcd
= StructuredPcds
[PcdName
]
1962 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
1963 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
1964 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
1965 if not Pcd
.SkuOverrideValues
or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1966 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1967 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
,self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
)
1969 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
1970 if SkuName
not in Pcd
.SkuOverrideValues
:
1972 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
1973 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
,SkuName
,DefaultStoreName
)
1974 if not Pcd
.SkuOverrideValues
or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1975 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1976 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
, InitByteValue
, CApp
)
1978 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
1979 if SkuName
not in Pcd
.SkuOverrideValues
:
1981 for DefaultStoreName
in Pcd
.DefaultStoreName
:
1982 Pcd
= StructuredPcds
[PcdName
]
1983 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
1985 CApp
= CApp
+ 'VOID\n'
1986 CApp
= CApp
+ 'PcdEntryPoint(\n'
1987 CApp
= CApp
+ ' VOID\n'
1988 CApp
= CApp
+ ' )\n'
1990 for Pcd
in StructuredPcds
.values():
1991 if not Pcd
.SkuOverrideValues
or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1992 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, TAB_DEFAULT_STORES_DEFAULT
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1994 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
1995 if SkuName
not in Pcd
.SkuOverrideValues
:
1997 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
1998 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2001 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2003 if not os
.path
.exists(self
.OutputPath
):
2004 os
.makedirs(self
.OutputPath
)
2005 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2006 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2008 MakeApp
= PcdMakefileHeader
2009 if sys
.platform
== "win32":
2010 MakeApp
= MakeApp
+ 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2012 MakeApp
= MakeApp
+ PcdGccMakefile
2013 MakeApp
= MakeApp
+ 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2014 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2018 for Cache
in self
._Bdb
._CACHE
_.values():
2019 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2022 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2023 PlatformInc
[str(Cache
.MetaFile
.Path
)] = []
2024 PlatformInc
[str(Cache
.MetaFile
.Path
)].append (os
.path
.dirname(Cache
.MetaFile
.Path
))
2025 PlatformInc
[str(Cache
.MetaFile
.Path
)].extend (Cache
.CommonIncludes
)
2028 for Pcd
in StructuredPcds
.values():
2029 for PackageDec
in Pcd
.PackageDecs
:
2030 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2031 if not os
.path
.exists(Package
):
2032 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2033 if Package
not in PcdDependDEC
:
2034 PcdDependDEC
.append(Package
)
2036 if PlatformInc
and PcdDependDEC
:
2037 for pkg
in PcdDependDEC
:
2038 if pkg
in PlatformInc
:
2039 for inc
in PlatformInc
[pkg
]:
2040 MakeApp
+= '-I' + str(inc
) + ' '
2041 IncSearchList
.append(inc
)
2042 MakeApp
= MakeApp
+ '\n'
2044 CC_FLAGS
= LinuxCFLAGS
2045 if sys
.platform
== "win32":
2046 CC_FLAGS
= WindowsCFLAGS
2048 for Options
in self
.BuildOptions
:
2049 if Options
[2] != EDKII_NAME
:
2052 if Family
and Family
!= self
.ToolChainFamily
:
2054 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2058 if Target
== "*" or Target
== self
._Target
:
2059 if Tag
== "*" or Tag
== self
._Toolchain
:
2060 if Arch
== "*" or Arch
== self
.Arch
:
2061 if Tool
not in BuildOptions
:
2062 BuildOptions
[Tool
] = {}
2063 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or self
.BuildOptions
[Options
].startswith('='):
2064 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
2066 # append options for the same tool except PATH
2068 BuildOptions
[Tool
][Attr
] += " " + self
.BuildOptions
[Options
]
2070 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
2072 for Tool
in BuildOptions
:
2073 for Attr
in BuildOptions
[Tool
]:
2075 Value
= BuildOptions
[Tool
][Attr
]
2076 ValueList
= Value
.split()
2078 for Id
, Item
in enumerate(ValueList
):
2079 if Item
== '-D' or Item
== '/D':
2080 CC_FLAGS
+= ' ' + Item
2081 if Id
+ 1 < len(ValueList
):
2082 CC_FLAGS
+= ' ' + ValueList
[Id
+ 1]
2083 elif Item
.startswith('/D') or Item
.startswith('-D'):
2084 CC_FLAGS
+= ' ' + Item
2087 if sys
.platform
== "win32":
2088 MakeApp
= MakeApp
+ PcdMakefileEnd
2089 MakeApp
= MakeApp
+ '\n'
2090 IncludeFileFullPaths
= []
2091 for includefile
in IncludeFiles
:
2092 for includepath
in IncSearchList
:
2093 includefullpath
= os
.path
.join(str(includepath
),includefile
)
2094 if os
.path
.exists(includefullpath
):
2095 IncludeFileFullPaths
.append(os
.path
.normpath(includefullpath
))
2098 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Include")))
2099 SearchPathList
.append(os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, "BaseTools/Source/C/Common")))
2100 SearchPathList
.extend([str(item
) for item
in IncSearchList
])
2101 IncFileList
= GetDependencyList(IncludeFileFullPaths
,SearchPathList
)
2102 for include_file
in IncFileList
:
2103 MakeApp
+= "$(OBJECTS) : %s\n" % include_file
2104 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2105 MakeApp
+= "$(OBJECTS) : %s\n" % MakeFileName
2106 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2108 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2109 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2110 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2112 PcdValueInitExe
= PcdValueInitName
2113 if not sys
.platform
== "win32":
2114 PcdValueInitExe
= os
.path
.join(os
.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName
)
2116 PcdValueInitExe
= os
.path
.join(os
.getenv("EDK_TOOLS_PATH"), 'Bin', 'Win32', PcdValueInitName
) +".exe"
2119 if sys
.platform
== "win32":
2120 MakeCommand
= 'nmake -f %s' % (MakeFileName
)
2121 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2124 MakeCommand
= 'make -f %s' % (MakeFileName
)
2125 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (MakeCommand
)
2127 Messages
= Messages
.split('\n')
2130 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2131 File
= open (CAppBaseFileName
+ '.c', 'r')
2132 FileData
= File
.readlines()
2134 for Message
in Messages
:
2135 if " error" in Message
or "warning" in Message
:
2136 FileInfo
= Message
.strip().split('(')
2137 if len (FileInfo
) > 1:
2138 FileName
= FileInfo
[0]
2139 FileLine
= FileInfo
[1].split (')')[0]
2141 FileInfo
= Message
.strip().split(':')
2142 FileName
= FileInfo
[0]
2143 FileLine
= FileInfo
[1]
2144 if FileLine
.isdigit():
2145 error_line
= FileData
[int (FileLine
) - 1]
2146 if r
"//" in error_line
:
2147 c_line
,dsc_line
= error_line
.split(r
"//")
2149 dsc_line
= error_line
2150 message_itmes
= Message
.split(":")
2152 if "PcdValueInit.c" not in Message
:
2153 if not MessageGroup
:
2154 MessageGroup
.append(Message
)
2157 for item
in message_itmes
:
2158 if "PcdValueInit.c" in item
:
2159 Index
= message_itmes
.index(item
)
2160 message_itmes
[Index
] = dsc_line
.strip()
2162 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2165 MessageGroup
.append(Message
)
2167 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2169 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2171 if DscBuildData
.NeedUpdateOutput(OutputValueFile
, PcdValueInitExe
,InputValueFile
):
2172 Command
= PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2173 returncode
, StdOut
, StdErr
= DscBuildData
.ExecuteCommand (Command
)
2175 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2177 File
= open (OutputValueFile
, 'r')
2178 FileBuffer
= File
.readlines()
2181 StructurePcdSet
= []
2182 for Pcd
in FileBuffer
:
2183 PcdValue
= Pcd
.split ('|')
2184 PcdInfo
= PcdValue
[0].split ('.')
2185 StructurePcdSet
.append((PcdInfo
[0],PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2186 return StructurePcdSet
2189 def NeedUpdateOutput(OutputFile
, ValueCFile
, StructureInput
):
2190 if not os
.path
.exists(OutputFile
):
2192 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2194 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2198 ## Retrieve dynamic PCD settings
2200 # @param Type PCD type
2202 # @retval a dict object contains settings of given PCD type
2204 def _GetDynamicPcd(self
, Type
):
2207 Pcds
= OrderedDict()
2209 # tdict is a special dict kind of type, used for selecting correct
2210 # PCD settings for certain ARCH and SKU
2212 PcdDict
= tdict(True, 4)
2214 # Find out all possible PCD candidates for self._Arch
2215 RecordList
= self
._RawData
[Type
, self
._Arch
]
2216 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2219 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
2220 SkuName
= SkuName
.upper()
2221 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2222 if SkuName
not in AvailableSkuIdSet
:
2223 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2224 File
=self
.MetaFile
, Line
=Dummy5
)
2225 if "." not in TokenSpaceGuid
:
2226 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2227 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2229 # Remove redundant PCD candidates, per the ARCH and SKU
2230 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2232 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2236 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2237 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2238 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2239 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2240 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2241 if MaxDatumSize
.strip():
2242 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2245 if pcdObject
.MaxDatumSize
:
2246 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2249 if CurrentMaxSize
> PcdMaxSize
:
2250 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2252 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2255 self
._PCD
_TYPE
_STRING
_[Type
],
2260 {SkuName
: SkuInfo
},
2265 for pcd
in Pcds
.values():
2266 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2267 # Only fix the value while no value provided in DSC file.
2268 for sku
in pcd
.SkuInfoList
.values():
2269 if not sku
.DefaultValue
:
2270 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2271 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2272 valuefromDec
= pcdDecObject
.DefaultValue
2273 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', '', valuefromDec
)
2274 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2275 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2276 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2277 del pcd
.SkuInfoList
[TAB_COMMON
]
2278 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2279 del pcd
.SkuInfoList
[TAB_COMMON
]
2281 map(self
.FilterSkuSettings
,Pcds
.values())
2285 def FilterSkuSettings(self
, PcdObj
):
2287 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2288 if TAB_DEFAULT
in PcdObj
.SkuInfoList
and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
:
2289 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
[TAB_DEFAULT
]
2290 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2291 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuIdName
= TAB_DEFAULT
2292 PcdObj
.SkuInfoList
[TAB_DEFAULT
].SkuId
= '0'
2294 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2295 PcdObj
.SkuInfoList
= {TAB_DEFAULT
:PcdObj
.SkuInfoList
[TAB_DEFAULT
]}
2300 def CompareVarAttr(Attr1
, Attr2
):
2301 if not Attr1
or not Attr2
: # for empty string
2303 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2304 Attr1Set
= set(Attr1s
)
2305 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2306 Attr2Set
= set(Attr2s
)
2307 if Attr2Set
== Attr1Set
:
2312 def CopyDscRawValue(self
,Pcd
):
2313 if Pcd
.DscRawValue
is None:
2314 Pcd
.DscRawValue
= dict()
2315 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2316 if self
.SkuIdMgr
.SystemSkuId
not in Pcd
.DscRawValue
:
2317 Pcd
.DscRawValue
[self
.SkuIdMgr
.SystemSkuId
] = {}
2318 Pcd
.DscRawValue
[self
.SkuIdMgr
.SystemSkuId
][TAB_DEFAULT_STORES_DEFAULT
] = Pcd
.DefaultValue
2319 for skuname
in Pcd
.SkuInfoList
:
2320 Pcd
.DscRawValue
[skuname
] = {}
2321 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2322 for defaultstore
in Pcd
.SkuInfoList
[skuname
].DefaultStoreDict
:
2323 Pcd
.DscRawValue
[skuname
][defaultstore
] = Pcd
.SkuInfoList
[skuname
].DefaultStoreDict
[defaultstore
]
2325 Pcd
.DscRawValue
[skuname
][TAB_DEFAULT_STORES_DEFAULT
] = Pcd
.SkuInfoList
[skuname
].DefaultValue
2326 def CompletePcdValues(self
,PcdSet
):
2328 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2329 SkuIds
= {skuname
:skuid
for skuname
,skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!= TAB_COMMON
}
2330 DefaultStores
= set([storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
])
2331 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2332 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2333 self
.CopyDscRawValue(PcdObj
)
2334 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2335 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2336 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2337 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2338 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2339 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2340 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2342 PcdType
= PcdObj
.Type
2343 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2344 for skuid
in PcdObj
.SkuInfoList
:
2345 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2346 mindefaultstorename
= DefaultStoreObj
.GetMin(set([defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
]))
2347 for defaultstorename
in DefaultStores
:
2348 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2349 skuobj
.DefaultStoreDict
[defaultstorename
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
2350 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2351 for skuname
,skuid
in SkuIds
.items():
2352 if skuname
not in PcdObj
.SkuInfoList
:
2353 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2354 while nextskuid
not in PcdObj
.SkuInfoList
:
2355 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2356 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2357 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2358 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2359 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2360 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
[TAB_DEFAULT
].HiiDefaultValue
2361 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2363 ## Retrieve dynamic HII PCD settings
2365 # @param Type PCD type
2367 # @retval a dict object contains settings of given PCD type
2369 def _GetDynamicHiiPcd(self
, Type
):
2373 Pcds
= OrderedDict()
2375 # tdict is a special dict kind of type, used for selecting correct
2376 # PCD settings for certain ARCH and SKU
2378 PcdDict
= tdict(True, 5)
2380 RecordList
= self
._RawData
[Type
, self
._Arch
]
2381 # Find out all possible PCD candidates for self._Arch
2382 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2383 DefaultStoresDefine
= self
._GetDefaultStores
()
2385 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
,Dummy5
in RecordList
:
2386 SkuName
= SkuName
.upper()
2387 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2388 DefaultStore
= DefaultStore
.upper()
2389 if DefaultStore
== TAB_COMMON
:
2390 DefaultStore
= TAB_DEFAULT_STORES_DEFAULT
2391 if SkuName
not in AvailableSkuIdSet
:
2392 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2393 File
=self
.MetaFile
, Line
=Dummy5
)
2394 if DefaultStore
not in DefaultStoresDefine
:
2395 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2396 File
=self
.MetaFile
, Line
=Dummy5
)
2397 if "." not in TokenSpaceGuid
:
2398 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
,DefaultStore
, Dummy5
))
2399 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
,DefaultStore
] = Setting
2402 # Remove redundant PCD candidates, per the ARCH and SKU
2403 for PcdCName
, TokenSpaceGuid
, SkuName
,DefaultStore
, Dummy4
in PcdSet
:
2405 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
,DefaultStore
]
2408 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2410 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2412 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2413 ExtraData
="[%s]" % VarAttribute
)
2415 FormatCorrect
= True
2416 if VariableOffset
.isdigit():
2417 if int(VariableOffset
, 10) > 0xFFFF:
2419 elif variablePattern
.match(VariableOffset
):
2420 if int(VariableOffset
, 16) > 0xFFFF:
2422 # For Offset written in "A.B"
2423 elif VariableOffset
.find('.') > -1:
2424 VariableOffsetList
= VariableOffset
.split(".")
2425 if not (len(VariableOffsetList
) == 2
2426 and IsValidWord(VariableOffsetList
[0])
2427 and IsValidWord(VariableOffsetList
[1])):
2428 FormatCorrect
= False
2430 FormatCorrect
= False
2431 if not FormatCorrect
:
2432 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2435 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2436 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2437 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2439 if not DscBuildData
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2440 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
)]))
2442 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2443 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2444 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2445 if SkuName
in pcdObject
.SkuInfoList
:
2446 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2447 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2449 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
,DefaultStore
={DefaultStore
:DefaultValue
})
2450 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2452 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
,DefaultStore
={DefaultStore
:DefaultValue
})
2453 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2456 self
._PCD
_TYPE
_STRING
_[Type
],
2461 {SkuName
: SkuInfo
},
2464 pcdDecObject
.validateranges
,
2465 pcdDecObject
.validlists
,
2466 pcdDecObject
.expressions
,
2470 for pcd
in Pcds
.values():
2471 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2472 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2473 pcd
.DatumType
= pcdDecObject
.DatumType
2474 # Only fix the value while no value provided in DSC file.
2475 for sku
in pcd
.SkuInfoList
.values():
2476 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
is None):
2477 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2478 for default_store
in sku
.DefaultStoreDict
:
2479 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2480 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2481 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2482 valuefromDec
= pcdDecObject
.DefaultValue
2483 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
,VariableAttribute
=SkuInfoObj
.VariableAttribute
,DefaultStore
={DefaultStore
:valuefromDec
})
2484 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2485 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2486 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2487 del pcd
.SkuInfoList
[TAB_COMMON
]
2488 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2489 del pcd
.SkuInfoList
[TAB_COMMON
]
2491 if pcd
.MaxDatumSize
.strip():
2492 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2495 if pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
2496 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2498 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2499 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2500 if datalen
> MaxSize
:
2502 for defaultst
in skuobj
.DefaultStoreDict
:
2503 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2504 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
2505 pcd
.MaxDatumSize
= str(MaxSize
)
2506 rt
, invalidhii
= DscBuildData
.CheckVariableNameAssignment(Pcds
)
2508 invalidpcd
= ",".join(invalidhii
)
2509 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
)
2511 map(self
.FilterSkuSettings
,Pcds
.values())
2516 def CheckVariableNameAssignment(Pcds
):
2518 for pcdname
in Pcds
:
2520 varnameset
= set([sku
.VariableName
for (skuid
,sku
) in pcd
.SkuInfoList
.items()])
2521 if len(varnameset
) > 1:
2522 invalidhii
.append(".".join((pcdname
[1],pcdname
[0])))
2524 return False,invalidhii
2527 ## Retrieve dynamic VPD PCD settings
2529 # @param Type PCD type
2531 # @retval a dict object contains settings of given PCD type
2533 def _GetDynamicVpdPcd(self
, Type
):
2536 Pcds
= OrderedDict()
2538 # tdict is a special dict kind of type, used for selecting correct
2539 # PCD settings for certain ARCH and SKU
2541 PcdDict
= tdict(True, 4)
2544 # Find out all possible PCD candidates for self._Arch
2545 RecordList
= self
._RawData
[Type
, self
._Arch
]
2546 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2548 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
2549 SkuName
= SkuName
.upper()
2550 SkuName
= TAB_DEFAULT
if SkuName
== TAB_COMMON
else SkuName
2551 if SkuName
not in AvailableSkuIdSet
:
2552 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2553 File
=self
.MetaFile
, Line
=Dummy5
)
2554 if "." not in TokenSpaceGuid
:
2555 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2556 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2558 # Remove redundant PCD candidates, per the ARCH and SKU
2559 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2560 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2564 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
2565 # For the Integer & Boolean type, the optional data can only be InitialValue.
2566 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
2567 # until the DEC parser has been called.
2569 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2570 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
2571 if (PcdCName
, TokenSpaceGuid
) in Pcds
:
2572 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2573 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2574 if MaxDatumSize
.strip():
2575 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2578 if pcdObject
.MaxDatumSize
:
2579 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2582 if CurrentMaxSize
> PcdMaxSize
:
2583 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2585 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2588 self
._PCD
_TYPE
_STRING
_[Type
],
2593 {SkuName
: SkuInfo
},
2597 for pcd
in Pcds
.values():
2598 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2599 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2600 pcd
.DatumType
= pcdDecObject
.DatumType
2601 # Only fix the value while no value provided in DSC file.
2602 for sku
in pcd
.SkuInfoList
.values():
2603 if not sku
.DefaultValue
:
2604 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2605 if TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
not in pcd
.SkuInfoList
:
2606 valuefromDec
= pcdDecObject
.DefaultValue
2607 SkuInfo
= SkuInfoClass(TAB_DEFAULT
, '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
2608 pcd
.SkuInfoList
[TAB_DEFAULT
] = SkuInfo
2609 elif TAB_DEFAULT
not in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2610 pcd
.SkuInfoList
[TAB_DEFAULT
] = pcd
.SkuInfoList
[TAB_COMMON
]
2611 del pcd
.SkuInfoList
[TAB_COMMON
]
2612 elif TAB_DEFAULT
in pcd
.SkuInfoList
and TAB_COMMON
in pcd
.SkuInfoList
:
2613 del pcd
.SkuInfoList
[TAB_COMMON
]
2616 map(self
.FilterSkuSettings
,Pcds
.values())
2619 ## Add external modules
2621 # The external modules are mostly those listed in FDF file, which don't
2624 # @param FilePath The path of module description file
2626 def AddModule(self
, FilePath
):
2627 FilePath
= NormPath(FilePath
)
2628 if FilePath
not in self
.Modules
:
2629 Module
= ModuleBuildClassObject()
2630 Module
.MetaFile
= FilePath
2631 self
.Modules
.append(Module
)
2633 def _GetToolChainFamily(self
):
2634 self
._ToolChainFamily
= "MSFT"
2635 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
2636 if os
.path
.isfile(BuildConfigurationFile
) == True:
2637 TargetTxt
= TargetTxtClassObject()
2638 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
2639 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
2640 if ToolDefinitionFile
== '':
2641 ToolDefinitionFile
= "tools_def.txt"
2642 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
2643 if os
.path
.isfile(ToolDefinitionFile
) == True:
2644 ToolDef
= ToolDefClassObject()
2645 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
2646 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
2647 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
2648 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
2649 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
2650 self
._ToolChainFamily
= "MSFT"
2652 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
2653 return self
._ToolChainFamily
2655 ## Add external PCDs
2657 # The external PCDs are mostly those listed in FDF file to specify address
2658 # or offset information.
2660 # @param Name Name of the PCD
2661 # @param Guid Token space guid of the PCD
2662 # @param Value Value of the PCD
2664 def AddPcd(self
, Name
, Guid
, Value
):
2665 if (Name
, Guid
) not in self
.Pcds
:
2666 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
2667 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
2670 if self
._DecPcds
is None:
2672 if GlobalData
.gFdfParser
:
2673 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
2675 for Inf
in FdfInfList
:
2676 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
2677 if ModuleFile
in self
._Modules
:
2679 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
2680 PkgSet
.update(ModuleData
.Packages
)
2681 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
,PkgSet
)
2682 return self
._DecPcds
2683 _Macros
= property(_GetMacros
)
2684 Arch
= property(_GetArch
, _SetArch
)
2685 Platform
= property(_GetPlatformName
)
2686 PlatformName
= property(_GetPlatformName
)
2687 Guid
= property(_GetFileGuid
)
2688 Version
= property(_GetVersion
)
2689 DscSpecification
= property(_GetDscSpec
)
2690 OutputDirectory
= property(_GetOutpuDir
)
2691 SupArchList
= property(_GetSupArch
)
2692 BuildTargets
= property(_GetBuildTarget
)
2693 SkuName
= property(_GetSkuName
, _SetSkuName
)
2694 PcdInfoFlag
= property(_GetPcdInfoFlag
)
2695 VarCheckFlag
= property(_GetVarCheckFlag
)
2696 FlashDefinition
= property(_GetFdfFile
)
2697 Prebuild
= property(_GetPrebuild
)
2698 Postbuild
= property(_GetPostbuild
)
2699 BuildNumber
= property(_GetBuildNumber
)
2700 MakefileName
= property(_GetMakefileName
)
2701 BsBaseAddress
= property(_GetBsBaseAddress
)
2702 RtBaseAddress
= property(_GetRtBaseAddress
)
2703 LoadFixAddress
= property(_GetLoadFixAddress
)
2704 RFCLanguages
= property(_GetRFCLanguages
)
2705 ISOLanguages
= property(_GetISOLanguages
)
2706 VpdToolGuid
= property(_GetVpdToolGuid
)
2707 SkuIds
= property(_GetSkuIds
)
2708 Modules
= property(_GetModules
)
2709 LibraryInstances
= property(_GetLibraryInstances
)
2710 LibraryClasses
= property(_GetLibraryClasses
)
2711 Pcds
= property(_GetPcds
)
2712 BuildOptions
= property(_GetBuildOptions
)
2713 ToolChainFamily
= property(_GetToolChainFamily
)