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 *
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 Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
43 # Treat CHAR16 as a synonym for UINT16. CHAR16 support is required for VFR C structs
45 PcdValueInitName
= 'PcdValueInit'
46 PcdSupportedBaseTypes
= ['BOOLEAN', 'UINT8', 'UINT16', 'UINT32', 'UINT64', 'CHAR16']
47 PcdSupportedBaseTypeWidth
= {'BOOLEAN':8, 'UINT8':8, 'UINT16':16, 'UINT32':32, 'UINT64':64}
48 PcdUnsupportedBaseTypes
= ['INT8', 'INT16', 'INT32', 'INT64', 'CHAR8', 'UINTN', 'INTN', 'VOID']
59 #include <PcdValueCommon.h>
69 return PcdValueMain (argc, argv);
73 PcdMakefileHeader
= '''
76 # This file is auto-generated by build utility
81 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
82 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
84 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
86 LIBS = $(LIB_PATH)\Common.lib
88 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
93 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
97 class DscBuildData(PlatformBuildClassObject
):
98 # dict used to convert PCD type in database to string used by build tool
100 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
101 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
102 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
103 MODEL_PCD_DYNAMIC
: "Dynamic",
104 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
105 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
106 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
107 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
108 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
109 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
110 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
113 # dict used to convert part of [Defines] to members of DscBuildData directly
118 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
119 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
120 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
121 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
122 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
123 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
124 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
125 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
126 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
127 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
128 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
129 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
130 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
131 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
132 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
135 # used to compose dummy library class name for those forced library instances
136 _NullLibraryNumber
= 0
138 ## Constructor of DscBuildData
140 # Initialize object of DscBuildData
142 # @param FilePath The path of platform description file
143 # @param RawData The raw data of DSC file
144 # @param BuildDataBase Database used to retrieve module/package information
145 # @param Arch The target architecture
146 # @param Platform (not used for DscBuildData)
147 # @param Macros Macros used for replacement in DSC file
149 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
='COMMON', Target
=None, Toolchain
=None):
150 self
.MetaFile
= FilePath
151 self
._RawData
= RawData
152 self
._Bdb
= BuildDataBase
154 self
._Target
= Target
155 self
._Toolchain
= Toolchain
156 self
._ToolChainFamily
= None
158 self
._HandleOverridePath
()
159 if os
.getenv("WORKSPACE"):
160 self
.OutputPath
= os
.path
.join(os
.getenv("WORKSPACE"), 'Build', PcdValueInitName
)
162 self
.OutputPath
= os
.path
.dirname(self
.DscFile
)
163 self
.DefaultStores
= None
164 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
167 def __setitem__(self
, key
, value
):
168 self
.__dict
__[self
._PROPERTY
_[key
]] = value
171 def __getitem__(self
, key
):
172 return self
.__dict
__[self
._PROPERTY
_[key
]]
175 def __contains__(self
, key
):
176 return key
in self
._PROPERTY
_
178 ## Set all internal used members of DscBuildData to None
181 self
._PlatformName
= None
184 self
._DscSpecification
= None
185 self
._OutputDirectory
= None
186 self
._SupArchList
= None
187 self
._BuildTargets
= None
189 self
._PcdInfoFlag
= None
190 self
._VarCheckFlag
= None
191 self
._FlashDefinition
= None
192 self
._Prebuild
= None
193 self
._Postbuild
= None
194 self
._BuildNumber
= None
195 self
._MakefileName
= None
196 self
._BsBaseAddress
= None
197 self
._RtBaseAddress
= None
200 self
._LibraryInstances
= None
201 self
._LibraryClasses
= None
204 self
._BuildOptions
= None
205 self
._ModuleTypeOptions
= None
206 self
._LoadFixAddress
= None
207 self
._RFCLanguages
= None
208 self
._ISOLanguages
= None
209 self
._VpdToolGuid
= None
211 self
.DefaultStores
= None
214 ## handle Override Path of Module
215 def _HandleOverridePath(self
):
216 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
217 Macros
= self
._Macros
218 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
219 for Record
in RecordList
:
222 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
223 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
225 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
227 # Check if the source override path exists
228 if not os
.path
.isdir(SourceOverridePath
):
229 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
231 # Add to GlobalData Variables
232 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
234 ## Get current effective macros
235 def _GetMacros(self
):
236 if self
.__Macros
== None:
238 self
.__Macros
.update(GlobalData
.gPlatformDefines
)
239 self
.__Macros
.update(GlobalData
.gGlobalDefines
)
240 self
.__Macros
.update(GlobalData
.gCommandLineDefines
)
249 # Changing the default ARCH to another may affect all other information
250 # because all information in a platform may be ARCH-related. That's
251 # why we need to clear all internal used members, in order to cause all
252 # information to be re-retrieved.
254 # @param Value The value of ARCH
256 def _SetArch(self
, Value
):
257 if self
._Arch
== Value
:
262 ## Retrieve all information in [Defines] section
264 # (Retriving all [Defines] information in one-shot is just to save time.)
266 def _GetHeaderInfo(self
):
267 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
268 for Record
in RecordList
:
270 # items defined _PROPERTY_ don't need additional processing
272 # some special items in [Defines] section need special treatment
273 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
274 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
275 if ' ' in self
._OutputDirectory
:
276 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
277 File
=self
.MetaFile
, Line
=Record
[-1],
278 ExtraData
=self
._OutputDirectory
)
279 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
280 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
281 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
283 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
285 elif Name
== TAB_DSC_PREBUILD
:
286 PrebuildValue
= Record
[2]
287 if Record
[2][0] == '"':
288 if Record
[2][-1] != '"':
289 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
290 File
=self
.MetaFile
, Line
=Record
[-1])
291 PrebuildValue
= Record
[2][1:-1]
292 self
._Prebuild
= PrebuildValue
293 elif Name
== TAB_DSC_POSTBUILD
:
294 PostbuildValue
= Record
[2]
295 if Record
[2][0] == '"':
296 if Record
[2][-1] != '"':
297 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
298 File
=self
.MetaFile
, Line
=Record
[-1])
299 PostbuildValue
= Record
[2][1:-1]
300 self
._Postbuild
= PostbuildValue
301 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
302 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
303 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
304 self
._BuildTargets
= GetSplitValueList(Record
[2])
305 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
306 if self
._SkuName
== None:
307 self
._SkuName
= Record
[2]
308 if GlobalData
.gSKUID_CMD
:
309 self
._SkuName
= GlobalData
.gSKUID_CMD
310 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
311 self
._PcdInfoFlag
= Record
[2]
312 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
313 self
._VarCheckFlag
= Record
[2]
314 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
316 self
._LoadFixAddress
= int (Record
[2], 0)
318 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
319 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
320 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
321 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"',
322 File
=self
.MetaFile
, Line
=Record
[-1])
323 LanguageCodes
= Record
[2][1:-1]
324 if not LanguageCodes
:
325 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
326 File
=self
.MetaFile
, Line
=Record
[-1])
327 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
328 # check whether there is empty entries in the list
329 if None in LanguageList
:
330 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
331 File
=self
.MetaFile
, Line
=Record
[-1])
332 self
._RFCLanguages
= LanguageList
333 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
334 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
335 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
336 File
=self
.MetaFile
, Line
=Record
[-1])
337 LanguageCodes
= Record
[2][1:-1]
338 if not LanguageCodes
:
339 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
340 File
=self
.MetaFile
, Line
=Record
[-1])
341 if len(LanguageCodes
) % 3:
342 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
343 File
=self
.MetaFile
, Line
=Record
[-1])
345 for i
in range(0, len(LanguageCodes
), 3):
346 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
347 self
._ISOLanguages
= LanguageList
348 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
350 # try to convert GUID to a real UUID value to see whether the GUID is format
351 # for VPD_TOOL_GUID is correct.
356 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
357 self
._VpdToolGuid
= Record
[2]
359 self
[Name
] = Record
[2]
360 # set _Header to non-None in order to avoid database re-querying
361 self
._Header
= 'DUMMY'
363 ## Retrieve platform name
364 def _GetPlatformName(self
):
365 if self
._PlatformName
== None:
366 if self
._Header
== None:
367 self
._GetHeaderInfo
()
368 if self
._PlatformName
== None:
369 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
370 return self
._PlatformName
372 ## Retrieve file guid
373 def _GetFileGuid(self
):
374 if self
._Guid
== None:
375 if self
._Header
== None:
376 self
._GetHeaderInfo
()
377 if self
._Guid
== None:
378 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
381 ## Retrieve platform version
382 def _GetVersion(self
):
383 if self
._Version
== None:
384 if self
._Header
== None:
385 self
._GetHeaderInfo
()
386 if self
._Version
== None:
387 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
390 ## Retrieve platform description file version
391 def _GetDscSpec(self
):
392 if self
._DscSpecification
== None:
393 if self
._Header
== None:
394 self
._GetHeaderInfo
()
395 if self
._DscSpecification
== None:
396 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
397 return self
._DscSpecification
399 ## Retrieve OUTPUT_DIRECTORY
400 def _GetOutpuDir(self
):
401 if self
._OutputDirectory
== None:
402 if self
._Header
== None:
403 self
._GetHeaderInfo
()
404 if self
._OutputDirectory
== None:
405 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
406 return self
._OutputDirectory
408 ## Retrieve SUPPORTED_ARCHITECTURES
409 def _GetSupArch(self
):
410 if self
._SupArchList
== None:
411 if self
._Header
== None:
412 self
._GetHeaderInfo
()
413 if self
._SupArchList
== None:
414 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
415 return self
._SupArchList
417 ## Retrieve BUILD_TARGETS
418 def _GetBuildTarget(self
):
419 if self
._BuildTargets
== None:
420 if self
._Header
== None:
421 self
._GetHeaderInfo
()
422 if self
._BuildTargets
== None:
423 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
424 return self
._BuildTargets
426 def _GetPcdInfoFlag(self
):
427 if self
._PcdInfoFlag
== None or self
._PcdInfoFlag
.upper() == 'FALSE':
429 elif self
._PcdInfoFlag
.upper() == 'TRUE':
433 def _GetVarCheckFlag(self
):
434 if self
._VarCheckFlag
== None or self
._VarCheckFlag
.upper() == 'FALSE':
436 elif self
._VarCheckFlag
.upper() == 'TRUE':
441 # # Retrieve SKUID_IDENTIFIER
442 def _GetSkuName(self
):
443 if self
._SkuName
== None:
444 if self
._Header
== None:
445 self
._GetHeaderInfo
()
446 if self
._SkuName
== None:
447 self
._SkuName
= 'DEFAULT'
450 ## Override SKUID_IDENTIFIER
451 def _SetSkuName(self
, Value
):
452 self
._SkuName
= Value
454 def _GetFdfFile(self
):
455 if self
._FlashDefinition
== None:
456 if self
._Header
== None:
457 self
._GetHeaderInfo
()
458 if self
._FlashDefinition
== None:
459 self
._FlashDefinition
= ''
460 return self
._FlashDefinition
462 def _GetPrebuild(self
):
463 if self
._Prebuild
== None:
464 if self
._Header
== None:
465 self
._GetHeaderInfo
()
466 if self
._Prebuild
== None:
468 return self
._Prebuild
470 def _GetPostbuild(self
):
471 if self
._Postbuild
== None:
472 if self
._Header
== None:
473 self
._GetHeaderInfo
()
474 if self
._Postbuild
== None:
476 return self
._Postbuild
478 ## Retrieve FLASH_DEFINITION
479 def _GetBuildNumber(self
):
480 if self
._BuildNumber
== None:
481 if self
._Header
== None:
482 self
._GetHeaderInfo
()
483 if self
._BuildNumber
== None:
484 self
._BuildNumber
= ''
485 return self
._BuildNumber
487 ## Retrieve MAKEFILE_NAME
488 def _GetMakefileName(self
):
489 if self
._MakefileName
== None:
490 if self
._Header
== None:
491 self
._GetHeaderInfo
()
492 if self
._MakefileName
== None:
493 self
._MakefileName
= ''
494 return self
._MakefileName
496 ## Retrieve BsBaseAddress
497 def _GetBsBaseAddress(self
):
498 if self
._BsBaseAddress
== None:
499 if self
._Header
== None:
500 self
._GetHeaderInfo
()
501 if self
._BsBaseAddress
== None:
502 self
._BsBaseAddress
= ''
503 return self
._BsBaseAddress
505 ## Retrieve RtBaseAddress
506 def _GetRtBaseAddress(self
):
507 if self
._RtBaseAddress
== None:
508 if self
._Header
== None:
509 self
._GetHeaderInfo
()
510 if self
._RtBaseAddress
== None:
511 self
._RtBaseAddress
= ''
512 return self
._RtBaseAddress
514 ## Retrieve the top address for the load fix address
515 def _GetLoadFixAddress(self
):
516 if self
._LoadFixAddress
== None:
517 if self
._Header
== None:
518 self
._GetHeaderInfo
()
520 if self
._LoadFixAddress
== None:
521 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
524 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
526 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
529 # If command line defined, should override the value in DSC file.
531 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
.keys():
533 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
535 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']))
537 if self
._LoadFixAddress
< 0:
538 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
539 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
540 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
542 return self
._LoadFixAddress
544 ## Retrieve RFCLanguage filter
545 def _GetRFCLanguages(self
):
546 if self
._RFCLanguages
== None:
547 if self
._Header
== None:
548 self
._GetHeaderInfo
()
549 if self
._RFCLanguages
== None:
550 self
._RFCLanguages
= []
551 return self
._RFCLanguages
553 ## Retrieve ISOLanguage filter
554 def _GetISOLanguages(self
):
555 if self
._ISOLanguages
== None:
556 if self
._Header
== None:
557 self
._GetHeaderInfo
()
558 if self
._ISOLanguages
== None:
559 self
._ISOLanguages
= []
560 return self
._ISOLanguages
561 ## Retrieve the GUID string for VPD tool
562 def _GetVpdToolGuid(self
):
563 if self
._VpdToolGuid
== None:
564 if self
._Header
== None:
565 self
._GetHeaderInfo
()
566 if self
._VpdToolGuid
== None:
567 self
._VpdToolGuid
= ''
568 return self
._VpdToolGuid
570 ## Retrieve [SkuIds] section information
571 def _GetSkuIds(self
):
572 if self
._SkuIds
== None:
573 self
._SkuIds
= sdict()
574 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
575 for Record
in RecordList
:
576 if Record
[0] in [None, '']:
577 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
578 File
=self
.MetaFile
, Line
=Record
[-1])
579 if Record
[1] in [None, '']:
580 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
581 File
=self
.MetaFile
, Line
=Record
[-1])
582 Pattern
= re
.compile('^[1-9]\d*|0$')
583 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
584 if Pattern
.match(Record
[0]) == None and HexPattern
.match(Record
[0]) == None:
585 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
586 File
=self
.MetaFile
, Line
=Record
[-1])
587 if not IsValidWord(Record
[1]):
588 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_-.)*'",
589 File
=self
.MetaFile
, Line
=Record
[-1])
590 self
._SkuIds
[Record
[1].upper()] = (str(self
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
591 if 'DEFAULT' not in self
._SkuIds
:
592 self
._SkuIds
['DEFAULT'] = ("0","DEFAULT","DEFAULT")
593 if 'COMMON' not in self
._SkuIds
:
594 self
._SkuIds
['COMMON'] = ("0","DEFAULT","DEFAULT")
596 def ToInt(self
,intstr
):
597 return int(intstr
,16) if intstr
.upper().startswith("0X") else int(intstr
)
598 def _GetDefaultStores(self
):
599 if self
.DefaultStores
== None:
600 self
.DefaultStores
= sdict()
601 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
602 for Record
in RecordList
:
603 if Record
[0] in [None, '']:
604 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
605 File
=self
.MetaFile
, Line
=Record
[-1])
606 if Record
[1] in [None, '']:
607 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
608 File
=self
.MetaFile
, Line
=Record
[-1])
609 Pattern
= re
.compile('^[1-9]\d*|0$')
610 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
611 if Pattern
.match(Record
[0]) == None and HexPattern
.match(Record
[0]) == None:
612 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
613 File
=self
.MetaFile
, Line
=Record
[-1])
614 if not IsValidWord(Record
[1]):
615 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_-.)*'",
616 File
=self
.MetaFile
, Line
=Record
[-1])
617 self
.DefaultStores
[Record
[1].upper()] = (self
.ToInt(Record
[0]),Record
[1].upper())
618 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
619 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0,TAB_DEFAULT_STORES_DEFAULT
)
620 GlobalData
.gDefaultStores
= self
.DefaultStores
.keys()
621 if GlobalData
.gDefaultStores
:
622 GlobalData
.gDefaultStores
.sort()
623 return self
.DefaultStores
625 ## Retrieve [Components] section information
626 def _GetModules(self
):
627 if self
._Modules
!= None:
630 self
._Modules
= sdict()
631 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
632 Macros
= self
._Macros
633 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
634 for Record
in RecordList
:
635 DuplicatedFile
= False
637 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
641 # check the file validation
642 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
644 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
647 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
648 if self
._Arch
!= 'COMMON' and ModuleFile
in self
._Modules
:
649 DuplicatedFile
= True
651 Module
= ModuleBuildClassObject()
652 Module
.MetaFile
= ModuleFile
654 # get module private library instance
655 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
656 for Record
in RecordList
:
657 LibraryClass
= Record
[0]
658 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
661 # check the file validation
662 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
664 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
667 if LibraryClass
== '' or LibraryClass
== 'NULL':
668 self
._NullLibraryNumber
+= 1
669 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
670 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
671 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
672 if LibraryPath
not in self
.LibraryInstances
:
673 self
.LibraryInstances
.append(LibraryPath
)
675 # get module private PCD setting
676 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
677 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
678 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
679 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
680 TokenList
= GetSplitValueList(Setting
)
681 DefaultValue
= TokenList
[0]
682 # the format is PcdName| Value | VOID* | MaxDatumSize
683 if len(TokenList
) > 2:
684 MaxDatumSize
= TokenList
[2]
687 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
688 Pcd
= PcdClassObject(
700 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
702 # get module private build options
703 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
704 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
705 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
706 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
708 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
709 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
711 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
712 if DuplicatedFile
and not RecordList
:
713 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
715 if len(RecordList
) != 1:
716 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
717 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
718 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
719 ModuleFile
.Arch
= self
._Arch
721 self
._Modules
[ModuleFile
] = Module
724 ## Retrieve all possible library instances used in this platform
725 def _GetLibraryInstances(self
):
726 if self
._LibraryInstances
== None:
727 self
._GetLibraryClasses
()
728 return self
._LibraryInstances
730 ## Retrieve [LibraryClasses] information
731 def _GetLibraryClasses(self
):
732 if self
._LibraryClasses
== None:
733 self
._LibraryInstances
= []
735 # tdict is a special dict kind of type, used for selecting correct
736 # library instance for given library class and module type
738 LibraryClassDict
= tdict(True, 3)
739 # track all library class names
740 LibraryClassSet
= set()
741 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
742 Macros
= self
._Macros
743 for Record
in RecordList
:
744 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
,Dummy
, LineNo
= Record
745 if LibraryClass
== '' or LibraryClass
== 'NULL':
746 self
._NullLibraryNumber
+= 1
747 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
748 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
749 LibraryClassSet
.add(LibraryClass
)
750 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
751 # check the file validation
752 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
754 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
757 if ModuleType
!= 'COMMON' and ModuleType
not in SUP_MODULE_LIST
:
758 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
759 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
760 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
761 if LibraryInstance
not in self
._LibraryInstances
:
762 self
._LibraryInstances
.append(LibraryInstance
)
764 # resolve the specific library instance for each class and each module type
765 self
._LibraryClasses
= tdict(True)
766 for LibraryClass
in LibraryClassSet
:
767 # try all possible module types
768 for ModuleType
in SUP_MODULE_LIST
:
769 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
770 if LibraryInstance
== None:
772 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
774 # for Edk style library instances, which are listed in different section
775 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
776 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
777 for Record
in RecordList
:
778 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
780 # check the file validation
781 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
783 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
785 if File
not in self
._LibraryInstances
:
786 self
._LibraryInstances
.append(File
)
788 # we need the module name as the library class name, so we have
789 # to parse it here. (self._Bdb[] will trigger a file parse if it
790 # hasn't been parsed)
792 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
793 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
794 return self
._LibraryClasses
796 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
797 if self
._DecPcds
== None:
800 if GlobalData
.gFdfParser
:
801 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
804 for Inf
in FdfInfList
:
805 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
806 if ModuleFile
in self
._Modules
:
808 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
809 PkgSet
.update(ModuleData
.Packages
)
811 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
,PkgSet
)
812 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
814 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
815 EdkLogger
.error('build', PARSER_ERROR
,
816 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
817 File
=self
.MetaFile
, Line
=LineNo
)
818 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
820 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
821 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
822 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
824 if ValueList
[2] == '-1':
825 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
826 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
828 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
830 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
831 except BadExpression
, Value
:
832 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
833 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
834 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
835 except EvaluationException
, Excpt
:
836 if hasattr(Excpt
, 'Pcd'):
837 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
838 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
839 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
840 " of the DSC file" % Excpt
.Pcd
,
841 File
=self
.MetaFile
, Line
=LineNo
)
843 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
844 File
=self
.MetaFile
, Line
=LineNo
)
846 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
847 File
=self
.MetaFile
, Line
=LineNo
)
850 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
852 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
853 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
854 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
):
855 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
856 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
,
857 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
858 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
859 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
860 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
863 def _FilterPcdBySkuUsage(self
,Pcds
):
864 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
865 sku_usage
= self
.SkuIdMgr
.SkuUsageType
866 if sku_usage
== SkuClass
.SINGLE
:
869 Pcds
[pcdname
].SkuInfoList
= {"DEFAULT":pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
870 if type(pcd
) is StructurePcd
and pcd
.SkuOverrideValues
:
871 Pcds
[pcdname
].SkuOverrideValues
= {"DEFAULT":pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
875 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
876 if type(pcd
) is StructurePcd
and pcd
.SkuOverrideValues
:
877 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
879 def CompleteHiiPcdsDefaultStores(self
,Pcds
):
880 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
]]]
881 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
883 for skuid
in pcd
.SkuInfoList
:
884 skuobj
= pcd
.SkuInfoList
.get(skuid
)
885 if "STANDARD" not in skuobj
.DefaultStoreDict
:
886 PcdDefaultStoreSet
= set([defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
])
887 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
888 skuobj
.DefaultStoreDict
['STANDARD'] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
891 def RecoverCommandLinePcd(self
):
893 if GlobalData
.BuildOptionPcd
:
894 for pcd
in GlobalData
.BuildOptionPcd
:
896 pcdset
.append((pcd
[0],pcd
[1],pcd
[3]))
898 if (pcd
[1],pcd
[0]) not in self
._Pcds
:
899 pcdvalue
= pcd
[3] if len(pcd
) == 4 else pcd
[2]
900 pcdset
.append((pcd
[0],pcd
[1],pcdvalue
))
902 # remove the settings from command line since it has been handled.
903 GlobalData
.BuildOptionPcd
= pcdset
904 def GetFieldValueFromComm(self
,ValueStr
,TokenSpaceGuidCName
, TokenCName
, FieldName
):
905 PredictedFieldType
= "VOID*"
906 if ValueStr
.startswith('L'):
908 EdkLogger
.error("build", FORMAT_INVALID
, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')
909 ValueStr
= ValueStr
[0] + '"' + ValueStr
[1:] + '"'
910 PredictedFieldType
= "VOID*"
911 elif ValueStr
.startswith('H') or ValueStr
.startswith('{'):
912 EdkLogger
.error("build", FORMAT_INVALID
, 'Currently we do not support assign H"{...}" format for Pcd field.', ExtraData
="%s.%s.%s from command line" % (TokenSpaceGuidCName
, TokenCName
, FieldName
))
913 ValueStr
= ValueStr
[1:]
914 PredictedFieldType
= "VOID*"
915 elif ValueStr
.upper() in ['TRUE', '0X1', '0X01', '1', 'FALSE', '0X0', '0X00', '0']:
916 PredictedFieldType
= "BOOLEAN"
917 elif ValueStr
.isdigit() or ValueStr
.upper().startswith('0X'):
918 PredictedFieldType
= TAB_UINT16
921 EdkLogger
.error("build", FORMAT_INVALID
, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')
922 ValueStr
= '"' + ValueStr
+ '"'
923 PredictedFieldType
= "VOID*"
924 IsValid
, Cause
= CheckPcdDatum(PredictedFieldType
, ValueStr
)
926 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s.%s from command line" % (TokenSpaceGuidCName
, TokenCName
, FieldName
))
927 if PredictedFieldType
== 'BOOLEAN':
928 ValueStr
= ValueStr
.upper()
929 if ValueStr
== 'TRUE' or ValueStr
== '1':
931 elif ValueStr
== 'FALSE' or ValueStr
== '0':
934 def __ParsePcdFromCommandLine(self
):
935 if GlobalData
.BuildOptionPcd
:
936 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
937 if type(pcd
) is tuple:
939 (pcdname
, pcdvalue
) = pcd
.split('=')
941 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
943 (Name1
, Name2
) = pcdname
.split('.',1)
945 (Name3
, FieldName
) = Name2
.split(".",1)
946 if ((Name3
,Name1
)) in self
.DecPcds
:
949 TokenSpaceGuidCName
= Name1
953 TokenSpaceGuidCName
= ''
954 HasTokenSpace
= False
956 if ((Name2
,Name1
)) in self
.DecPcds
:
959 TokenSpaceGuidCName
= Name1
964 TokenSpaceGuidCName
= ''
965 HasTokenSpace
= False
969 TokenSpaceGuidCName
= ''
970 HasTokenSpace
= False
971 TokenSpaceGuidCNameList
= []
975 if not HasTokenSpace
:
976 for key
in self
.DecPcds
:
977 if TokenCName
== key
[0]:
978 if TokenSpaceGuidCName
:
982 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, TokenSpaceGuidCName
, key
[1])
985 TokenSpaceGuidCName
= key
[1]
988 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
991 NewValue
= self
.GetFieldValueFromComm(pcdvalue
, TokenSpaceGuidCName
, TokenCName
, FieldName
)
992 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
,NewValue
,("build command options",1))
994 # Replace \' to ', \\\' to \'
995 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
996 for key
in self
.DecPcds
:
997 PcdItem
= self
.DecPcds
[key
]
999 if (PcdItem
.TokenCName
, PcdItem
.TokenSpaceGuidCName
) == (TokenCName
, TokenSpaceGuidCName
):
1000 PcdDatumType
= PcdItem
.DatumType
1001 if pcdvalue
.startswith('H'):
1003 pcdvalue
= ValueExpressionEx(pcdvalue
[1:], PcdDatumType
, self
._GuidDict
)(True)
1004 except BadExpression
, Value
:
1005 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1006 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1007 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1008 pcdvalue
= 'H' + pcdvalue
1009 elif pcdvalue
.startswith("L'"):
1011 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1012 except BadExpression
, Value
:
1013 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1014 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1015 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1016 pcdvalue
= 'H' + pcdvalue
1017 elif pcdvalue
.startswith("'"):
1019 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1020 except BadExpression
, Value
:
1021 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1022 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1023 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1024 pcdvalue
= 'H' + pcdvalue
1025 elif pcdvalue
.startswith('L'):
1026 pcdvalue
= 'L"' + pcdvalue
[1:] + '"'
1028 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1029 except BadExpression
, Value
:
1030 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1031 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1034 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1035 except BadExpression
, Value
:
1037 pcdvalue
= '"' + pcdvalue
+ '"'
1038 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1039 except BadExpression
, Value
:
1040 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1041 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1042 NewValue
= BuildOptionPcdValueFormat(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
1045 if PcdItem
.TokenCName
== TokenCName
:
1046 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1047 if len (TokenSpaceGuidCNameList
) < 1:
1048 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1049 PcdDatumType
= PcdItem
.DatumType
1050 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1051 if pcdvalue
.startswith('H'):
1053 pcdvalue
= ValueExpressionEx(pcdvalue
[1:], PcdDatumType
, self
._GuidDict
)(True)
1054 except BadExpression
, Value
:
1055 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1056 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1057 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
,'BOOLEAN']:
1058 pcdvalue
= 'H' + pcdvalue
1059 elif pcdvalue
.startswith("L'"):
1061 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(
1063 except BadExpression
, Value
:
1064 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1065 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1066 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1067 pcdvalue
= 'H' + pcdvalue
1068 elif pcdvalue
.startswith("'"):
1070 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(
1072 except BadExpression
, Value
:
1073 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1074 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1075 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1076 pcdvalue
= 'H' + pcdvalue
1077 elif pcdvalue
.startswith('L'):
1078 pcdvalue
= 'L"' + pcdvalue
[1:] + '"'
1080 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(
1082 except BadExpression
, Value
:
1083 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1084 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1087 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1088 except BadExpression
, Value
:
1090 pcdvalue
= '"' + pcdvalue
+ '"'
1091 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1092 except BadExpression
, Value
:
1093 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1094 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1095 NewValue
= BuildOptionPcdValueFormat(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
1101 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1103 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
,NewValue
,("build command options",1))
1106 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, TokenCName
))
1108 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (TokenCName
))
1109 for BuildData
in self
._Bdb
._CACHE
_.values():
1110 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1112 for key
in BuildData
.Pcds
:
1113 PcdItem
= BuildData
.Pcds
[key
]
1114 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1115 PcdItem
.DefaultValue
= NewValue
1116 ## Retrieve all PCD settings in platform
1118 if self
._Pcds
== None:
1119 self
._Pcds
= sdict()
1120 self
.__ParsePcdFromCommandLine
()
1121 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1122 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1123 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1124 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1125 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1126 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1127 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1128 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1129 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1131 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1132 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1133 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1134 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1135 self
._Pcds
= self
.OverrideByFdfCommOverAll(self
._Pcds
)
1136 self
.RecoverCommandLinePcd()
1139 def _dumpPcdInfo(self
,Pcds
):
1142 if not pcdobj
.TokenCName
.startswith("Test"):
1144 for skuid
in pcdobj
.SkuInfoList
:
1145 if pcdobj
.Type
in (self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]):
1146 for storename
in pcdobj
.SkuInfoList
[skuid
].DefaultStoreDict
:
1147 print "PcdCName: %s, SkuName: %s, StoreName: %s, Value: %s" % (".".join((pcdobj
.TokenSpaceGuidCName
, pcdobj
.TokenCName
)), skuid
,storename
,str(pcdobj
.SkuInfoList
[skuid
].DefaultStoreDict
[storename
]))
1149 print "PcdCName: %s, SkuName: %s, Value: %s" % (".".join((pcdobj
.TokenSpaceGuidCName
, pcdobj
.TokenCName
)), skuid
,str(pcdobj
.SkuInfoList
[skuid
].DefaultValue
))
1150 ## Retrieve [BuildOptions]
1151 def _GetBuildOptions(self
):
1152 if self
._BuildOptions
== None:
1153 self
._BuildOptions
= sdict()
1155 # Retrieve build option for EDKII and EDK style module
1157 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1158 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1159 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1160 if Dummy3
.upper() != 'COMMON':
1162 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1164 # Only flags can be appended
1166 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1167 self
._BuildOptions
[CurKey
] = Option
1169 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1170 self
._BuildOptions
[CurKey
] += ' ' + Option
1171 return self
._BuildOptions
1173 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1174 if self
._ModuleTypeOptions
== None:
1175 self
._ModuleTypeOptions
= sdict()
1176 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1178 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1179 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1180 CommonDriverType
= '%s.%s' % ('COMMON', ModuleType
)
1181 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1182 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1183 Type
= Dummy2
+ '.' + Dummy3
1184 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1185 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1186 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1187 options
[Key
] = Option
1189 if ' ' + Option
not in options
[Key
]:
1190 options
[Key
] += ' ' + Option
1191 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1193 def GetStructurePcdInfo(self
, PcdSet
):
1194 structure_pcd_data
= {}
1196 if (item
[0],item
[1]) not in structure_pcd_data
:
1197 structure_pcd_data
[(item
[0],item
[1])] = []
1198 structure_pcd_data
[(item
[0],item
[1])].append(item
)
1200 return structure_pcd_data
1201 def OverrideByFdfComm(self
,StruPcds
):
1202 StructurePcdInCom
= {(item
[0],item
[1],item
[2] ):(item
[3],item
[4]) for item
in GlobalData
.BuildOptionPcd
if len(item
) == 5 and (item
[1],item
[0]) in StruPcds
} if GlobalData
.BuildOptionPcd
else {}
1203 GlobalPcds
= set([(item
[0],item
[1]) for item
in StructurePcdInCom
.keys()])
1204 for Pcd
in StruPcds
.values():
1205 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1207 FieldValues
= {item
[2]:StructurePcdInCom
[item
] for item
in StructurePcdInCom
if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]}
1208 for sku
in Pcd
.SkuOverrideValues
:
1209 for defaultstore
in Pcd
.SkuOverrideValues
[sku
]:
1210 for field
in FieldValues
:
1211 if field
not in Pcd
.SkuOverrideValues
[sku
][defaultstore
]:
1212 Pcd
.SkuOverrideValues
[sku
][defaultstore
][field
] = ["","",""]
1213 Pcd
.SkuOverrideValues
[sku
][defaultstore
][field
][0] = FieldValues
[field
][0]
1214 Pcd
.SkuOverrideValues
[sku
][defaultstore
][field
][1] = FieldValues
[field
][1][0]
1215 Pcd
.SkuOverrideValues
[sku
][defaultstore
][field
][2] = FieldValues
[field
][1][1]
1217 def OverrideByFdfCommOverAll(self
,AllPcds
):
1218 def CheckStructureInComm(commpcds
):
1221 if len(commpcds
[0]) == 5:
1225 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1226 StructurePcdInCom
= {(item
[0],item
[1],item
[2] ):(item
[3],item
[4]) for item
in GlobalData
.BuildOptionPcd
} if GlobalData
.BuildOptionPcd
else {}
1227 NoFiledValues
= {(item
[0],item
[1]):StructurePcdInCom
[item
] for item
in StructurePcdInCom
if not item
[2]}
1229 NoFiledValues
= {(item
[0],item
[1]):[item
[2]] for item
in GlobalData
.BuildOptionPcd
}
1230 for Guid
,Name
in NoFiledValues
:
1231 if (Name
,Guid
) in AllPcds
:
1232 Pcd
= AllPcds
.get((Name
,Guid
))
1233 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1234 for sku
in Pcd
.SkuInfoList
:
1235 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1236 if SkuInfo
.DefaultValue
:
1237 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1239 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1240 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1241 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1243 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1245 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1246 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1247 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1248 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
,Name
)][0]
1250 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1252 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1253 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1254 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1255 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1256 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1257 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1260 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1261 SkuIds
= self
.SkuIdMgr
.AvailableSkuIdSet
1262 SkuIds
.update({'DEFAULT':0})
1263 DefaultStores
= set([storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
.keys()])
1266 # Find out all possible PCD candidates for self._Arch
1269 for Type
in TypeList
:
1270 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1272 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
,Dummy5
in RecordList
:
1273 SkuName
= SkuName
.upper()
1274 default_store
= default_store
.upper()
1275 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
1276 if SkuName
not in SkuIds
:
1279 if SkuName
in SkuIds
and "." in TokenSpaceGuid
:
1280 S_PcdSet
.append([ TokenSpaceGuid
.split(".")[0],TokenSpaceGuid
.split(".")[1], PcdCName
,SkuName
, default_store
,Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1282 # handle pcd value override
1283 StrPcdSet
= self
.GetStructurePcdInfo(S_PcdSet
)
1285 for str_pcd
in StrPcdSet
:
1286 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1287 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1288 if not isinstance (str_pcd_dec
, StructurePcd
):
1289 EdkLogger
.error('build', PARSER_ERROR
,
1290 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1291 File
=self
.MetaFile
,Line
= StrPcdSet
[str_pcd
][0][5])
1293 str_pcd_obj_str
= StructurePcd()
1294 str_pcd_obj_str
.copy(str_pcd_dec
)
1296 str_pcd_obj_str
.copy(str_pcd_obj
)
1297 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1298 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
}
1300 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
}
1301 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1302 if str_pcd_data
[3] in SkuIds
:
1303 str_pcd_obj_str
.AddOverrideValue(str_pcd_data
[2], str(str_pcd_data
[6]), 'DEFAULT' if str_pcd_data
[3] == 'COMMON' else str_pcd_data
[3],'STANDARD' if str_pcd_data
[4] == 'COMMON' else str_pcd_data
[4], self
.MetaFile
.File
,LineNo
=str_pcd_data
[5])
1304 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1306 EdkLogger
.error('build', PARSER_ERROR
,
1307 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1308 File
=self
.MetaFile
,Line
= StrPcdSet
[str_pcd
][0][5])
1309 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1310 for Pcd
in self
.DecPcds
:
1311 if type (self
._DecPcds
[Pcd
]) is StructurePcd
:
1312 if Pcd
not in S_pcd_set
:
1313 str_pcd_obj_str
= StructurePcd()
1314 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1315 str_pcd_obj
= Pcds
.get(Pcd
, None)
1317 str_pcd_obj_str
.copy(str_pcd_obj
)
1318 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1319 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
}
1321 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
}
1322 S_pcd_set
[Pcd
] = str_pcd_obj_str
1324 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1325 for stru_pcd
in S_pcd_set
.values():
1326 for skuid
in SkuIds
:
1327 if skuid
in stru_pcd
.SkuOverrideValues
:
1329 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1331 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1332 if nextskuid
== "DEFAULT":
1335 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1336 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 {'STANDARD':stru_pcd
.DefaultValues
})
1337 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1338 for skuid
in SkuIds
:
1341 if skuid
not in stru_pcd
.SkuOverrideValues
:
1342 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1343 if nextskuid
== "DEFAULT":
1346 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1349 PcdDefaultStoreSet
= set([defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
]])
1350 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1352 for defaultstoreid
in DefaultStores
:
1353 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1354 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = copy
.deepcopy(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1355 S_pcd_set
= self
.OverrideByFdfComm(S_pcd_set
)
1356 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1358 for (skuname
,StoreName
,PcdGuid
,PcdName
,PcdValue
) in Str_Pcd_Values
:
1359 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1360 if str_pcd_obj
is None:
1361 print PcdName
, PcdGuid
1363 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1364 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1365 if skuname
not in str_pcd_obj
.SkuInfoList
:
1366 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1368 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1369 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1370 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1371 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1372 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, 'DEFAULT', 'COMMON'):
1373 str_pcd_obj
.DefaultValue
= PcdValue
1375 if skuname
not in str_pcd_obj
.SkuInfoList
:
1376 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1378 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1379 if nextskuid
== "DEFAULT":
1382 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1383 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
)
1384 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1385 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1387 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1388 for str_pcd_obj
in S_pcd_set
.values():
1389 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1390 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1392 PcdDefaultStoreSet
= set([defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
])
1393 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1394 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1395 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1397 for str_pcd_obj
in S_pcd_set
.values():
1399 str_pcd_obj
.MaxDatumSize
= self
.GetStructurePcdMaxSize(str_pcd_obj
)
1400 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1404 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
1405 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
1406 del(pcd
.SkuInfoList
['COMMON'])
1407 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
1408 del(pcd
.SkuInfoList
['COMMON'])
1410 map(self
.FilterSkuSettings
,[Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1413 ## Retrieve non-dynamic PCD settings
1415 # @param Type PCD type
1417 # @retval a dict object contains settings of given PCD type
1419 def _GetPcd(self
, Type
):
1422 # tdict is a special dict kind of type, used for selecting correct
1423 # PCD settings for certain ARCH
1425 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1427 PcdDict
= tdict(True, 3)
1429 # Find out all possible PCD candidates for self._Arch
1430 RecordList
= self
._RawData
[Type
, self
._Arch
]
1431 PcdValueDict
= sdict()
1432 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1433 SkuName
= SkuName
.upper()
1434 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
1435 if SkuName
not in AvailableSkuIdSet
:
1436 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1437 File
=self
.MetaFile
, Line
=Dummy5
)
1438 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, 'DEFAULT', 'COMMON'):
1439 if "." not in TokenSpaceGuid
:
1440 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1441 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1443 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1444 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1447 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1448 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1449 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1451 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1453 PcdsKeys
= PcdValueDict
.keys()
1454 for PcdCName
, TokenSpaceGuid
in PcdsKeys
:
1456 PcdSetting
= PcdValueDict
[PcdCName
, TokenSpaceGuid
]
1460 if 'COMMON' in PcdSetting
:
1461 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
['COMMON']
1462 if 'DEFAULT' in PcdSetting
:
1463 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
['DEFAULT']
1464 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1465 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1467 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1470 self
._PCD
_TYPE
_STRING
_[Type
],
1483 def __UNICODE2OCTList(self
,Value
):
1484 Value
= Value
.strip()
1488 Temp
= '%04X' % ord(Item
)
1489 List
.append('0x' + Temp
[2:4])
1490 List
.append('0x' + Temp
[0:2])
1494 def __STRING2OCTList(self
,Value
):
1496 Value
= Value
.strip('"')
1498 Temp
= '%02X' % ord(char
)
1499 OCTList
.append('0x' + Temp
)
1500 OCTList
.append('0x00')
1503 def GetStructurePcdMaxSize(self
, str_pcd
):
1504 pcd_default_value
= str_pcd
.DefaultValue
1505 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()]
1506 sku_values
.append(pcd_default_value
)
1508 def get_length(value
):
1509 Value
= value
.strip()
1511 if Value
.startswith('GUID') and Value
.endswith(')'):
1513 if Value
.startswith('L"') and Value
.endswith('"'):
1514 return len(Value
[2:-1])
1515 if Value
[0] == '"' and Value
[-1] == '"':
1516 return len(Value
) - 2
1517 if Value
[0] == '{' and Value
[-1] == '}':
1518 return len(Value
.split(","))
1519 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1520 return len(list(Value
[2:-1]))
1521 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1522 return len(Value
) - 2
1525 return str(max([pcd_size
for pcd_size
in [get_length(item
) for item
in sku_values
]]))
1527 def IsFieldValueAnArray (self
, Value
):
1528 Value
= Value
.strip()
1529 if Value
.startswith('GUID') and Value
.endswith(')'):
1531 if Value
.startswith('L"') and Value
.endswith('"') and len(list(Value
[2:-1])) > 1:
1533 if Value
[0] == '"' and Value
[-1] == '"' and len(list(Value
[1:-1])) > 1:
1535 if Value
[0] == '{' and Value
[-1] == '}':
1537 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1538 print 'foo = ', list(Value
[2:-1])
1540 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1541 print 'bar = ', list(Value
[1:-1])
1545 def ExecuteCommand (self
, Command
):
1547 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1549 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1550 Result
= Process
.communicate()
1551 return Process
.returncode
, Result
[0], Result
[1]
1553 def IntToCString(self
, Value
, ValueSize
):
1555 if not isinstance (Value
, str):
1556 for Index
in range(0, ValueSize
):
1557 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1559 Result
= Result
+ '"'
1562 def GenerateInitializeFunc(self
, SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
):
1563 OverrideValues
= {DefaultStoreName
:""}
1564 if Pcd
.SkuOverrideValues
:
1565 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1566 for DefaultStoreName
in OverrideValues
.keys():
1567 CApp
= CApp
+ 'void\n'
1568 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1569 CApp
= CApp
+ ' void\n'
1570 CApp
= CApp
+ ' )\n'
1572 CApp
= CApp
+ ' UINT32 Size;\n'
1573 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1574 CApp
= CApp
+ ' CHAR8 *Value;\n'
1575 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
1576 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
1577 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.DatumType
, Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
1580 if SkuName
in Pcd
.SkuInfoList
:
1581 DefaultValue
= Pcd
.SkuInfoList
[SkuName
].DefaultStoreDict
.get(DefaultStoreName
,Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
) if Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
else Pcd
.SkuInfoList
[SkuName
].DefaultValue
1583 DefaultValue
= Pcd
.DefaultValue
1584 PcdDefaultValue
= StringToArray(DefaultValue
.strip())
1586 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
1589 # Get current PCD value and size
1591 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1594 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
1595 # the correct value. For structures with a flexible array member, the flexible
1596 # array member is detected, and the size is based on the highest index used with
1597 # the flexible array member. The flexible array member must be the last field
1598 # in a structure. The size formula for this case is:
1599 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
1601 CApp
= CApp
+ ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1602 CApp
= CApp
+ "// Default Value in Dec \n"
1603 for FieldList
in [Pcd
.DefaultValues
]:
1606 for FieldName
in FieldList
:
1607 FieldName
= "." + FieldName
1608 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1611 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], "VOID*", self
._GuidDict
)(True)
1612 except BadExpression
:
1613 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1614 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1615 Value
, ValueSize
= ParseFieldValue(Value
)
1616 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]);
1619 FieldName_ori
= FieldName
.strip('.')
1620 while '[' in FieldName
:
1621 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1622 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1623 FieldName
= FieldName
.split(']', 1)[1]
1624 FieldName
= NewFieldName
+ FieldName
1625 while '[' in FieldName
:
1626 FieldName
= FieldName
.rsplit('[', 1)[0]
1627 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])
1628 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
1629 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[skuname
]
1630 storeset
= [DefaultStoreName
] if DefaultStoreName
== 'STANDARD' else ['STANDARD', DefaultStoreName
]
1631 for defaultstorenameitem
in storeset
:
1632 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1633 for FieldList
in [inherit_OverrideValues
.get(defaultstorenameitem
)]:
1636 for FieldName
in FieldList
:
1637 FieldName
= "." + FieldName
1638 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1641 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], "VOID*", self
._GuidDict
)(True)
1642 except BadExpression
:
1643 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1644 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1645 Value
, ValueSize
= ParseFieldValue(Value
)
1646 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]);
1649 FieldName_ori
= FieldName
.strip('.')
1650 while '[' in FieldName
:
1651 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1652 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1653 FieldName
= FieldName
.split(']', 1)[1]
1654 FieldName
= NewFieldName
+ FieldName
1655 while '[' in FieldName
:
1656 FieldName
= FieldName
.rsplit('[', 1)[0]
1657 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])
1658 if skuname
== SkuName
:
1662 # Allocate and zero buffer for the PCD
1663 # Must handle cases where current value is smaller, larger, or same size
1664 # Always keep that larger one as the current size
1666 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
1667 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.DatumType
)
1668 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
1671 # Copy current PCD value into allocated buffer.
1673 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
1676 # Assign field values in PCD
1678 CApp
= CApp
+ "// Default value in Dec \n"
1679 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1680 IsArray
= self
.IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1683 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, "VOID*")(True)
1684 except BadExpression
:
1685 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1686 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1687 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1688 if isinstance(Value
, str):
1689 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1692 # Use memcpy() to copy value into field
1694 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (self
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1695 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1696 for FieldList
in [Pcd
.DefaultValues
]:
1699 for FieldName
in FieldList
:
1700 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
][0])
1703 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], "VOID*", self
._GuidDict
)(True)
1704 except BadExpression
:
1705 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1706 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1],FieldList
[FieldName
][2]))
1709 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1711 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]))
1712 if isinstance(Value
, str):
1713 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1716 # Use memcpy() to copy value into field
1718 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1719 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (self
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1720 CApp
= CApp
+ ' memcpy (&Pcd->%s[0], Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1723 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1725 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1726 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
1727 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[skuname
]
1728 storeset
= [DefaultStoreName
] if DefaultStoreName
== 'STANDARD' else ['STANDARD', DefaultStoreName
]
1729 for defaultstorenameitem
in storeset
:
1730 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1731 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get(skuname
,{}).get(defaultstorenameitem
, Pcd
.DefaultValue
) if Pcd
.DefaultFromDSC
else Pcd
.DefaultValue
1732 for FieldList
in [pcddefaultvalue
,inherit_OverrideValues
.get(defaultstorenameitem
)]:
1735 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1736 IsArray
= self
.IsFieldValueAnArray(FieldList
)
1739 FieldList
= ValueExpressionEx(FieldList
, "VOID*")(True)
1740 except BadExpression
:
1741 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
1742 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1743 Value
, ValueSize
= ParseFieldValue (FieldList
)
1744 if isinstance(Value
, str):
1745 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DefaultFromDSC
.get(skuname
,{}).get(defaultstorenameitem
, Pcd
.DefaultValue
) if Pcd
.DefaultFromDSC
else Pcd
.DefaultValue
)
1748 # Use memcpy() to copy value into field
1750 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (self
.IntToCString(Value
, ValueSize
), Pcd
.DefaultFromDSC
.get(skuname
,{}).get(defaultstorenameitem
, Pcd
.DefaultValue
) if Pcd
.DefaultFromDSC
else Pcd
.DefaultValue
)
1751 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1753 for FieldName
in FieldList
:
1754 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
][0])
1757 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], "VOID*", self
._GuidDict
)(True)
1758 except BadExpression
:
1759 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1760 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1762 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1764 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]))
1765 if isinstance(Value
, str):
1766 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1769 # Use memcpy() to copy value into field
1771 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1772 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (self
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1773 CApp
= CApp
+ ' memcpy (&Pcd->%s[0], Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1776 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1778 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1779 if skuname
== SkuName
:
1782 # Set new PCD value and size
1784 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1789 CApp
= CApp
+ ' free (Pcd);\n'
1792 return InitByteValue
, CApp
1794 def GenerateByteArrayValue (self
, StructuredPcds
):
1796 # Generate/Compile/Run C application to determine if there are any flexible array members
1798 if not StructuredPcds
:
1802 CApp
= PcdMainCHeader
1805 for PcdName
in StructuredPcds
:
1806 Pcd
= StructuredPcds
[PcdName
]
1807 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
1808 if IncludeFile
not in Includes
:
1809 Includes
[IncludeFile
] = True
1810 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
1813 for PcdName
in StructuredPcds
:
1814 Pcd
= StructuredPcds
[PcdName
]
1815 if not Pcd
.SkuOverrideValues
:
1816 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, 'STANDARD', Pcd
, InitByteValue
, CApp
)
1818 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
1819 if SkuName
not in Pcd
.SkuOverrideValues
:
1821 for DefaultStoreName
in Pcd
.DefaultStoreName
:
1822 Pcd
= StructuredPcds
[PcdName
]
1823 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
1825 CApp
= CApp
+ 'VOID\n'
1826 CApp
= CApp
+ 'PcdEntryPoint(\n'
1827 CApp
= CApp
+ ' VOID\n'
1828 CApp
= CApp
+ ' )\n'
1830 for Pcd
in StructuredPcds
.values():
1831 if not Pcd
.SkuOverrideValues
:
1832 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, 'STANDARD', Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1834 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
1835 if SkuName
not in Pcd
.SkuOverrideValues
:
1837 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
1838 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1841 CApp
= CApp
+ PcdMainCEntry
+ '\n'
1843 if not os
.path
.exists(self
.OutputPath
):
1844 os
.makedirs(self
.OutputPath
)
1845 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
1846 File
= open (CAppBaseFileName
+ '.c', 'w')
1850 MakeApp
= PcdMakefileHeader
1851 if sys
.platform
== "win32":
1852 MakeApp
= MakeApp
+ 'ARCH = IA32\nAPPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
1854 MakeApp
= MakeApp
+ PcdGccMakefile
1855 MakeApp
= MakeApp
+ 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
1856 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
1859 for Cache
in self
._Bdb
._CACHE
_.values():
1860 if Cache
.MetaFile
.Ext
.lower() != '.dec':
1863 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
1864 PlatformInc
[str(Cache
.MetaFile
.Path
)] = Cache
.Includes
1867 for Pcd
in StructuredPcds
.values():
1868 for PackageDec
in Pcd
.PackageDecs
:
1869 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
1870 if not os
.path
.exists(Package
):
1871 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1872 if Package
not in PcdDependDEC
:
1873 PcdDependDEC
.append(Package
)
1875 if PlatformInc
and PcdDependDEC
:
1876 for pkg
in PcdDependDEC
:
1877 if pkg
in PlatformInc
:
1878 for inc
in PlatformInc
[pkg
]:
1879 MakeApp
+= '-I' + str(inc
) + ' '
1880 MakeApp
= MakeApp
+ '\n'
1882 CC_FLAGS
= LinuxCFLAGS
1883 if sys
.platform
== "win32":
1884 CC_FLAGS
= WindowsCFLAGS
1886 for Options
in self
.BuildOptions
:
1887 if Options
[2] != EDKII_NAME
:
1890 if Family
and Family
!= self
.ToolChainFamily
:
1892 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
1896 if Target
== "*" or Target
== self
._Target
:
1897 if Tag
== "*" or Tag
== self
._Toolchain
:
1898 if Arch
== "*" or Arch
== self
.Arch
:
1899 if Tool
not in BuildOptions
:
1900 BuildOptions
[Tool
] = {}
1901 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or self
.BuildOptions
[Options
].startswith('='):
1902 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
1904 # append options for the same tool except PATH
1906 BuildOptions
[Tool
][Attr
] += " " + self
.BuildOptions
[Options
]
1908 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
1910 for Tool
in BuildOptions
:
1911 for Attr
in BuildOptions
[Tool
]:
1913 Value
= BuildOptions
[Tool
][Attr
]
1914 ValueList
= Value
.split()
1916 for Id
, Item
in enumerate(ValueList
):
1917 if Item
== '-D' or Item
== '/D':
1918 CC_FLAGS
+= ' ' + Item
1919 if Id
+ 1 < len(ValueList
):
1920 CC_FLAGS
+= ' ' + ValueList
[Id
+ 1]
1921 elif Item
.startswith('/D') or Item
.startswith('-D'):
1922 CC_FLAGS
+= ' ' + Item
1925 if sys
.platform
== "win32":
1926 MakeApp
= MakeApp
+ PcdMakefileEnd
1927 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
1928 File
= open (MakeFileName
, 'w')
1932 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
1933 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
1934 File
= open (InputValueFile
, 'w')
1935 File
.write(InitByteValue
)
1939 if sys
.platform
== "win32":
1940 MakeCommand
= 'nmake clean & nmake -f %s' % (MakeFileName
)
1941 returncode
, StdOut
, StdErr
= self
.ExecuteCommand (MakeCommand
)
1944 MakeCommand
= 'make clean & make -f %s' % (MakeFileName
)
1945 returncode
, StdOut
, StdErr
= self
.ExecuteCommand (MakeCommand
)
1947 Messages
= Messages
.split('\n')
1950 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
1951 File
= open (CAppBaseFileName
+ '.c', 'r')
1952 FileData
= File
.readlines()
1954 for Message
in Messages
:
1955 if " error" in Message
or "warning" in Message
:
1956 FileInfo
= Message
.strip().split('(')
1957 if len (FileInfo
) > 1:
1958 FileName
= FileInfo
[0]
1959 FileLine
= FileInfo
[1].split (')')[0]
1961 FileInfo
= Message
.strip().split(':')
1962 FileName
= FileInfo
[0]
1963 FileLine
= FileInfo
[1]
1964 if FileLine
.isdigit():
1965 error_line
= FileData
[int (FileLine
) - 1]
1966 if r
"//" in error_line
:
1967 c_line
,dsc_line
= error_line
.split(r
"//")
1969 dsc_line
= error_line
1970 message_itmes
= Message
.split(":")
1972 if "PcdValueInit.c" not in Message
:
1973 if not MessageGroup
:
1974 MessageGroup
.append(Message
)
1977 for item
in message_itmes
:
1978 if "PcdValueInit.c" in item
:
1979 Index
= message_itmes
.index(item
)
1980 message_itmes
[Index
] = dsc_line
.strip()
1982 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
1985 MessageGroup
.append(Message
)
1987 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
1989 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
1991 PcdValueInitExe
= PcdValueInitName
1992 if not sys
.platform
== "win32":
1993 PcdValueInitExe
= os
.path
.join(os
.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName
)
1995 Command
= PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
1996 returncode
, StdOut
, StdErr
= self
.ExecuteCommand (Command
)
1998 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2001 File
= open (OutputValueFile
, 'r')
2002 FileBuffer
= File
.readlines()
2005 StructurePcdSet
= []
2006 for Pcd
in FileBuffer
:
2007 PcdValue
= Pcd
.split ('|')
2008 PcdInfo
= PcdValue
[0].split ('.')
2009 StructurePcdSet
.append((PcdInfo
[0],PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2010 return StructurePcdSet
2012 ## Retrieve dynamic PCD settings
2014 # @param Type PCD type
2016 # @retval a dict object contains settings of given PCD type
2018 def _GetDynamicPcd(self
, Type
):
2023 # tdict is a special dict kind of type, used for selecting correct
2024 # PCD settings for certain ARCH and SKU
2026 PcdDict
= tdict(True, 4)
2028 # Find out all possible PCD candidates for self._Arch
2029 RecordList
= self
._RawData
[Type
, self
._Arch
]
2030 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2033 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
2034 SkuName
= SkuName
.upper()
2035 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
2036 if SkuName
not in AvailableSkuIdSet
:
2037 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2038 File
=self
.MetaFile
, Line
=Dummy5
)
2039 if "." not in TokenSpaceGuid
:
2040 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2041 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2043 # Remove redundant PCD candidates, per the ARCH and SKU
2044 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2046 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2050 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2051 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2052 if (PcdCName
, TokenSpaceGuid
) in Pcds
.keys():
2053 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2054 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2055 if MaxDatumSize
.strip():
2056 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2059 if pcdObject
.MaxDatumSize
:
2060 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2063 if CurrentMaxSize
> PcdMaxSize
:
2064 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2066 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2069 self
._PCD
_TYPE
_STRING
_[Type
],
2074 {SkuName
: SkuInfo
},
2079 for pcd
in Pcds
.values():
2080 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2081 # Only fix the value while no value provided in DSC file.
2082 for sku
in pcd
.SkuInfoList
.values():
2083 if (sku
.DefaultValue
== "" or sku
.DefaultValue
==None):
2084 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2085 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
2086 valuefromDec
= pcdDecObject
.DefaultValue
2087 SkuInfo
= SkuInfoClass('DEFAULT', '0', '', '', '', '', '', valuefromDec
)
2088 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
2089 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2090 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
2091 del(pcd
.SkuInfoList
['COMMON'])
2092 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2093 del(pcd
.SkuInfoList
['COMMON'])
2095 map(self
.FilterSkuSettings
,Pcds
.values())
2099 def FilterSkuSettings(self
, PcdObj
):
2101 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2102 if 'DEFAULT' in PcdObj
.SkuInfoList
.keys() and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
.keys():
2103 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
['DEFAULT']
2104 PcdObj
.SkuInfoList
= {'DEFAULT':PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2105 PcdObj
.SkuInfoList
['DEFAULT'].SkuIdName
= 'DEFAULT'
2106 PcdObj
.SkuInfoList
['DEFAULT'].SkuId
= '0'
2108 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2109 PcdObj
.SkuInfoList
= {'DEFAULT':PcdObj
.SkuInfoList
['DEFAULT']}
2114 def CompareVarAttr(self
, Attr1
, Attr2
):
2115 if not Attr1
or not Attr2
: # for empty string
2117 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2118 Attr1Set
= set(Attr1s
)
2119 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2120 Attr2Set
= set(Attr2s
)
2121 if Attr2Set
== Attr1Set
:
2125 def CompletePcdValues(self
,PcdSet
):
2127 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2128 SkuIds
= {skuname
:skuid
for skuname
,skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!='COMMON'}
2129 DefaultStores
= set([storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
.keys()])
2130 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2131 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2132 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2133 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2134 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2135 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2136 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2137 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2138 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2140 PcdType
= PcdObj
.Type
2141 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2142 for skuid
in PcdObj
.SkuInfoList
:
2143 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2144 mindefaultstorename
= DefaultStoreObj
.GetMin(set([defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
]))
2145 for defaultstorename
in DefaultStores
:
2146 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2147 skuobj
.DefaultStoreDict
[defaultstorename
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
2148 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2149 for skuname
,skuid
in SkuIds
.items():
2150 if skuname
not in PcdObj
.SkuInfoList
:
2151 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2152 while nextskuid
not in PcdObj
.SkuInfoList
:
2153 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2154 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2155 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2156 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2157 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2158 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
["DEFAULT"].HiiDefaultValue
2159 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2161 ## Retrieve dynamic HII PCD settings
2163 # @param Type PCD type
2165 # @retval a dict object contains settings of given PCD type
2167 def _GetDynamicHiiPcd(self
, Type
):
2173 # tdict is a special dict kind of type, used for selecting correct
2174 # PCD settings for certain ARCH and SKU
2176 PcdDict
= tdict(True, 5)
2178 RecordList
= self
._RawData
[Type
, self
._Arch
]
2179 # Find out all possible PCD candidates for self._Arch
2180 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2181 DefaultStoresDefine
= self
._GetDefaultStores
()
2183 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
,Dummy5
in RecordList
:
2184 SkuName
= SkuName
.upper()
2185 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
2186 DefaultStore
= DefaultStore
.upper()
2187 if DefaultStore
== "COMMON":
2188 DefaultStore
= "STANDARD"
2189 if SkuName
not in AvailableSkuIdSet
:
2190 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2191 File
=self
.MetaFile
, Line
=Dummy5
)
2192 if DefaultStore
not in DefaultStoresDefine
:
2193 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2194 File
=self
.MetaFile
, Line
=Dummy5
)
2195 if "." not in TokenSpaceGuid
:
2196 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
,DefaultStore
, Dummy5
))
2197 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
,DefaultStore
] = Setting
2200 # Remove redundant PCD candidates, per the ARCH and SKU
2201 for PcdCName
, TokenSpaceGuid
, SkuName
,DefaultStore
, Dummy4
in PcdSet
:
2203 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
,DefaultStore
]
2206 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2208 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2210 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2211 ExtraData
="[%s]" % VarAttribute
)
2213 FormatCorrect
= True
2214 if VariableOffset
.isdigit():
2215 if int(VariableOffset
, 10) > 0xFFFF:
2217 elif re
.match(r
'[\t\s]*0[xX][a-fA-F0-9]+$', VariableOffset
):
2218 if int(VariableOffset
, 16) > 0xFFFF:
2220 # For Offset written in "A.B"
2221 elif VariableOffset
.find('.') > -1:
2222 VariableOffsetList
= VariableOffset
.split(".")
2223 if not (len(VariableOffsetList
) == 2
2224 and IsValidWord(VariableOffsetList
[0])
2225 and IsValidWord(VariableOffsetList
[1])):
2226 FormatCorrect
= False
2228 FormatCorrect
= False
2229 if not FormatCorrect
:
2230 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2233 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2234 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2235 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2237 if not self
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2238 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
)]))
2240 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2241 if (PcdCName
, TokenSpaceGuid
) in Pcds
.keys():
2242 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2243 if SkuName
in pcdObject
.SkuInfoList
:
2244 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2245 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2247 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
,DefaultStore
={DefaultStore
:DefaultValue
})
2248 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2250 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
,DefaultStore
={DefaultStore
:DefaultValue
})
2251 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2254 self
._PCD
_TYPE
_STRING
_[Type
],
2259 {SkuName
: SkuInfo
},
2262 pcdDecObject
.validateranges
,
2263 pcdDecObject
.validlists
,
2264 pcdDecObject
.expressions
,
2268 for pcd
in Pcds
.values():
2269 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2270 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2271 pcd
.DatumType
= pcdDecObject
.DatumType
2272 # Only fix the value while no value provided in DSC file.
2273 for sku
in pcd
.SkuInfoList
.values():
2274 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
== None):
2275 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2276 for default_store
in sku
.DefaultStoreDict
:
2277 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2278 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2279 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
2280 valuefromDec
= pcdDecObject
.DefaultValue
2281 SkuInfo
= SkuInfoClass('DEFAULT', '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
,VariableAttribute
=SkuInfoObj
.VariableAttribute
,DefaultStore
={DefaultStore
:valuefromDec
})
2282 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
2283 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2284 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
2285 del(pcd
.SkuInfoList
['COMMON'])
2286 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2287 del(pcd
.SkuInfoList
['COMMON'])
2289 if pcd
.MaxDatumSize
.strip():
2290 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2293 if pcdDecObject
.DatumType
== 'VOID*':
2294 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2296 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2297 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2298 if datalen
> MaxSize
:
2300 for defaultst
in skuobj
.DefaultStoreDict
:
2301 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2302 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
2303 pcd
.MaxDatumSize
= str(MaxSize
)
2304 rt
, invalidhii
= self
.CheckVariableNameAssignment(Pcds
)
2306 invalidpcd
= ",".join(invalidhii
)
2307 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
)
2309 map(self
.FilterSkuSettings
,Pcds
.values())
2313 def CheckVariableNameAssignment(self
,Pcds
):
2315 for pcdname
in Pcds
:
2317 varnameset
= set([sku
.VariableName
for (skuid
,sku
) in pcd
.SkuInfoList
.items()])
2318 if len(varnameset
) > 1:
2319 invalidhii
.append(".".join((pcdname
[1],pcdname
[0])))
2321 return False,invalidhii
2324 ## Retrieve dynamic VPD PCD settings
2326 # @param Type PCD type
2328 # @retval a dict object contains settings of given PCD type
2330 def _GetDynamicVpdPcd(self
, Type
):
2335 # tdict is a special dict kind of type, used for selecting correct
2336 # PCD settings for certain ARCH and SKU
2338 PcdDict
= tdict(True, 4)
2341 # Find out all possible PCD candidates for self._Arch
2342 RecordList
= self
._RawData
[Type
, self
._Arch
]
2343 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2345 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
2346 SkuName
= SkuName
.upper()
2347 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
2348 if SkuName
not in AvailableSkuIdSet
:
2349 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2350 File
=self
.MetaFile
, Line
=Dummy5
)
2351 if "." not in TokenSpaceGuid
:
2352 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2353 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2355 # Remove redundant PCD candidates, per the ARCH and SKU
2356 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2357 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2361 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
2362 # For the Integer & Boolean type, the optional data can only be InitialValue.
2363 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
2364 # until the DEC parser has been called.
2366 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2367 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
2368 if (PcdCName
, TokenSpaceGuid
) in Pcds
.keys():
2369 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2370 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2371 if MaxDatumSize
.strip():
2372 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2375 if pcdObject
.MaxDatumSize
:
2376 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2379 if CurrentMaxSize
> PcdMaxSize
:
2380 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2382 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2385 self
._PCD
_TYPE
_STRING
_[Type
],
2390 {SkuName
: SkuInfo
},
2394 for pcd
in Pcds
.values():
2395 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2396 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2397 pcd
.DatumType
= pcdDecObject
.DatumType
2398 # Only fix the value while no value provided in DSC file.
2399 for sku
in pcd
.SkuInfoList
.values():
2400 if (sku
.DefaultValue
== "" or sku
.DefaultValue
==None):
2401 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2402 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
2403 valuefromDec
= pcdDecObject
.DefaultValue
2404 SkuInfo
= SkuInfoClass('DEFAULT', '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
2405 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
2406 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2407 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
2408 del(pcd
.SkuInfoList
['COMMON'])
2409 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2410 del(pcd
.SkuInfoList
['COMMON'])
2413 map(self
.FilterSkuSettings
,Pcds
.values())
2416 ## Add external modules
2418 # The external modules are mostly those listed in FDF file, which don't
2421 # @param FilePath The path of module description file
2423 def AddModule(self
, FilePath
):
2424 FilePath
= NormPath(FilePath
)
2425 if FilePath
not in self
.Modules
:
2426 Module
= ModuleBuildClassObject()
2427 Module
.MetaFile
= FilePath
2428 self
.Modules
.append(Module
)
2430 def _GetToolChainFamily(self
):
2431 self
._ToolChainFamily
= "MSFT"
2432 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
2433 if os
.path
.isfile(BuildConfigurationFile
) == True:
2434 TargetTxt
= TargetTxtClassObject()
2435 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
2436 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
2437 if ToolDefinitionFile
== '':
2438 ToolDefinitionFile
= "tools_def.txt"
2439 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
2440 if os
.path
.isfile(ToolDefinitionFile
) == True:
2441 ToolDef
= ToolDefClassObject()
2442 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
2443 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
2444 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
2445 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
2446 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
2447 self
._ToolChainFamily
= "MSFT"
2449 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
2450 return self
._ToolChainFamily
2452 ## Add external PCDs
2454 # The external PCDs are mostly those listed in FDF file to specify address
2455 # or offset information.
2457 # @param Name Name of the PCD
2458 # @param Guid Token space guid of the PCD
2459 # @param Value Value of the PCD
2461 def AddPcd(self
, Name
, Guid
, Value
):
2462 if (Name
, Guid
) not in self
.Pcds
:
2463 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
2464 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
2467 if self
._DecPcds
== None:
2469 if GlobalData
.gFdfParser
:
2470 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
2472 for Inf
in FdfInfList
:
2473 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
2474 if ModuleFile
in self
._Modules
:
2476 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
2477 PkgSet
.update(ModuleData
.Packages
)
2478 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
,PkgSet
)
2479 return self
._DecPcds
2480 _Macros
= property(_GetMacros
)
2481 Arch
= property(_GetArch
, _SetArch
)
2482 Platform
= property(_GetPlatformName
)
2483 PlatformName
= property(_GetPlatformName
)
2484 Guid
= property(_GetFileGuid
)
2485 Version
= property(_GetVersion
)
2486 DscSpecification
= property(_GetDscSpec
)
2487 OutputDirectory
= property(_GetOutpuDir
)
2488 SupArchList
= property(_GetSupArch
)
2489 BuildTargets
= property(_GetBuildTarget
)
2490 SkuName
= property(_GetSkuName
, _SetSkuName
)
2491 PcdInfoFlag
= property(_GetPcdInfoFlag
)
2492 VarCheckFlag
= property(_GetVarCheckFlag
)
2493 FlashDefinition
= property(_GetFdfFile
)
2494 Prebuild
= property(_GetPrebuild
)
2495 Postbuild
= property(_GetPostbuild
)
2496 BuildNumber
= property(_GetBuildNumber
)
2497 MakefileName
= property(_GetMakefileName
)
2498 BsBaseAddress
= property(_GetBsBaseAddress
)
2499 RtBaseAddress
= property(_GetRtBaseAddress
)
2500 LoadFixAddress
= property(_GetLoadFixAddress
)
2501 RFCLanguages
= property(_GetRFCLanguages
)
2502 ISOLanguages
= property(_GetISOLanguages
)
2503 VpdToolGuid
= property(_GetVpdToolGuid
)
2504 SkuIds
= property(_GetSkuIds
)
2505 Modules
= property(_GetModules
)
2506 LibraryInstances
= property(_GetLibraryInstances
)
2507 LibraryClasses
= property(_GetLibraryClasses
)
2508 Pcds
= property(_GetPcds
)
2509 BuildOptions
= property(_GetBuildOptions
)
2510 ToolChainFamily
= property(_GetToolChainFamily
)