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 Common
.Misc
import SaveFileOnChange
41 from Workspace
.BuildClassObject
import PlatformBuildClassObject
, StructurePcd
, PcdClassObject
, ModuleBuildClassObject
42 from collections
import OrderedDict
45 # Treat CHAR16 as a synonym for UINT16. CHAR16 support is required for VFR C structs
47 PcdValueInitName
= 'PcdValueInit'
48 PcdSupportedBaseTypes
= ['BOOLEAN', 'UINT8', 'UINT16', 'UINT32', 'UINT64', 'CHAR16']
49 PcdSupportedBaseTypeWidth
= {'BOOLEAN':8, 'UINT8':8, 'UINT16':16, 'UINT32':32, 'UINT64':64}
50 PcdUnsupportedBaseTypes
= ['INT8', 'INT16', 'INT32', 'INT64', 'CHAR8', 'UINTN', 'INTN', 'VOID']
61 #include <PcdValueCommon.h>
71 return PcdValueMain (argc, argv);
75 PcdMakefileHeader
= '''
78 # This file is auto-generated by build utility
83 WindowsCFLAGS
= 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
84 LinuxCFLAGS
= 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
86 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
88 LIBS = $(LIB_PATH)\Common.lib
90 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
94 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
98 class DscBuildData(PlatformBuildClassObject
):
99 # dict used to convert PCD type in database to string used by build tool
100 _PCD_TYPE_STRING_
= {
101 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
102 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
103 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
104 MODEL_PCD_DYNAMIC
: "Dynamic",
105 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
106 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
107 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
108 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
109 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
110 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
111 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
114 # dict used to convert part of [Defines] to members of DscBuildData directly
119 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
120 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
121 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
122 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
123 # TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
124 # TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
125 # TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
126 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
127 # TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
128 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
129 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
130 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
131 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
132 # TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
133 # TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
136 # used to compose dummy library class name for those forced library instances
137 _NullLibraryNumber
= 0
139 ## Constructor of DscBuildData
141 # Initialize object of DscBuildData
143 # @param FilePath The path of platform description file
144 # @param RawData The raw data of DSC file
145 # @param BuildDataBase Database used to retrieve module/package information
146 # @param Arch The target architecture
147 # @param Platform (not used for DscBuildData)
148 # @param Macros Macros used for replacement in DSC file
150 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
='COMMON', Target
=None, Toolchain
=None):
151 self
.MetaFile
= FilePath
152 self
._RawData
= RawData
153 self
._Bdb
= BuildDataBase
155 self
._Target
= Target
156 self
._Toolchain
= Toolchain
157 self
._ToolChainFamily
= None
159 self
._HandleOverridePath
()
160 self
.WorkspaceDir
= os
.getenv("WORKSPACE") if os
.getenv("WORKSPACE") else ""
161 self
.DefaultStores
= None
162 self
.SkuIdMgr
= SkuClass(self
.SkuName
, self
.SkuIds
)
164 def OutputPath(self
):
165 if os
.getenv("WORKSPACE"):
166 return os
.path
.join(os
.getenv("WORKSPACE"), self
.OutputDirectory
, self
._Target
+ "_" + self
._Toolchain
,PcdValueInitName
)
168 return os
.path
.dirname(self
.DscFile
)
171 def __setitem__(self
, key
, value
):
172 self
.__dict
__[self
._PROPERTY
_[key
]] = value
175 def __getitem__(self
, key
):
176 return self
.__dict
__[self
._PROPERTY
_[key
]]
179 def __contains__(self
, key
):
180 return key
in self
._PROPERTY
_
182 ## Set all internal used members of DscBuildData to None
185 self
._PlatformName
= None
188 self
._DscSpecification
= None
189 self
._OutputDirectory
= None
190 self
._SupArchList
= None
191 self
._BuildTargets
= None
193 self
._PcdInfoFlag
= None
194 self
._VarCheckFlag
= None
195 self
._FlashDefinition
= None
196 self
._Prebuild
= None
197 self
._Postbuild
= None
198 self
._BuildNumber
= None
199 self
._MakefileName
= None
200 self
._BsBaseAddress
= None
201 self
._RtBaseAddress
= None
204 self
._LibraryInstances
= None
205 self
._LibraryClasses
= None
208 self
._BuildOptions
= None
209 self
._ModuleTypeOptions
= None
210 self
._LoadFixAddress
= None
211 self
._RFCLanguages
= None
212 self
._ISOLanguages
= None
213 self
._VpdToolGuid
= None
215 self
.DefaultStores
= None
218 ## handle Override Path of Module
219 def _HandleOverridePath(self
):
220 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
221 Macros
= self
._Macros
222 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
223 for Record
in RecordList
:
226 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
227 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
229 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
231 # Check if the source override path exists
232 if not os
.path
.isdir(SourceOverridePath
):
233 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
235 # Add to GlobalData Variables
236 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
238 ## Get current effective macros
239 def _GetMacros(self
):
240 if self
.__Macros
== None:
242 self
.__Macros
.update(GlobalData
.gPlatformDefines
)
243 self
.__Macros
.update(GlobalData
.gGlobalDefines
)
244 self
.__Macros
.update(GlobalData
.gCommandLineDefines
)
253 # Changing the default ARCH to another may affect all other information
254 # because all information in a platform may be ARCH-related. That's
255 # why we need to clear all internal used members, in order to cause all
256 # information to be re-retrieved.
258 # @param Value The value of ARCH
260 def _SetArch(self
, Value
):
261 if self
._Arch
== Value
:
266 ## Retrieve all information in [Defines] section
268 # (Retriving all [Defines] information in one-shot is just to save time.)
270 def _GetHeaderInfo(self
):
271 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
272 for Record
in RecordList
:
274 # items defined _PROPERTY_ don't need additional processing
276 # some special items in [Defines] section need special treatment
277 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
278 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
279 if ' ' in self
._OutputDirectory
:
280 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
281 File
=self
.MetaFile
, Line
=Record
[-1],
282 ExtraData
=self
._OutputDirectory
)
283 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
284 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
285 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
287 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
289 elif Name
== TAB_DSC_PREBUILD
:
290 PrebuildValue
= Record
[2]
291 if Record
[2][0] == '"':
292 if Record
[2][-1] != '"':
293 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD
,
294 File
=self
.MetaFile
, Line
=Record
[-1])
295 PrebuildValue
= Record
[2][1:-1]
296 self
._Prebuild
= PrebuildValue
297 elif Name
== TAB_DSC_POSTBUILD
:
298 PostbuildValue
= Record
[2]
299 if Record
[2][0] == '"':
300 if Record
[2][-1] != '"':
301 EdkLogger
.error('build', FORMAT_INVALID
, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD
,
302 File
=self
.MetaFile
, Line
=Record
[-1])
303 PostbuildValue
= Record
[2][1:-1]
304 self
._Postbuild
= PostbuildValue
305 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
306 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
307 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
308 self
._BuildTargets
= GetSplitValueList(Record
[2])
309 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
310 if self
._SkuName
== None:
311 self
._SkuName
= Record
[2]
312 if GlobalData
.gSKUID_CMD
:
313 self
._SkuName
= GlobalData
.gSKUID_CMD
314 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
315 self
._PcdInfoFlag
= Record
[2]
316 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
317 self
._VarCheckFlag
= Record
[2]
318 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
320 self
._LoadFixAddress
= int (Record
[2], 0)
322 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
323 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
324 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
325 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"',
326 File
=self
.MetaFile
, Line
=Record
[-1])
327 LanguageCodes
= Record
[2][1:-1]
328 if not LanguageCodes
:
329 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
330 File
=self
.MetaFile
, Line
=Record
[-1])
331 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
332 # check whether there is empty entries in the list
333 if None in LanguageList
:
334 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
335 File
=self
.MetaFile
, Line
=Record
[-1])
336 self
._RFCLanguages
= LanguageList
337 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
338 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
339 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
340 File
=self
.MetaFile
, Line
=Record
[-1])
341 LanguageCodes
= Record
[2][1:-1]
342 if not LanguageCodes
:
343 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
344 File
=self
.MetaFile
, Line
=Record
[-1])
345 if len(LanguageCodes
) % 3:
346 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
347 File
=self
.MetaFile
, Line
=Record
[-1])
349 for i
in range(0, len(LanguageCodes
), 3):
350 LanguageList
.append(LanguageCodes
[i
:i
+ 3])
351 self
._ISOLanguages
= LanguageList
352 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
354 # try to convert GUID to a real UUID value to see whether the GUID is format
355 # for VPD_TOOL_GUID is correct.
360 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
361 self
._VpdToolGuid
= Record
[2]
363 self
[Name
] = Record
[2]
364 # set _Header to non-None in order to avoid database re-querying
365 self
._Header
= 'DUMMY'
367 ## Retrieve platform name
368 def _GetPlatformName(self
):
369 if self
._PlatformName
== None:
370 if self
._Header
== None:
371 self
._GetHeaderInfo
()
372 if self
._PlatformName
== None:
373 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
374 return self
._PlatformName
376 ## Retrieve file guid
377 def _GetFileGuid(self
):
378 if self
._Guid
== None:
379 if self
._Header
== None:
380 self
._GetHeaderInfo
()
381 if self
._Guid
== None:
382 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
385 ## Retrieve platform version
386 def _GetVersion(self
):
387 if self
._Version
== None:
388 if self
._Header
== None:
389 self
._GetHeaderInfo
()
390 if self
._Version
== None:
391 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
394 ## Retrieve platform description file version
395 def _GetDscSpec(self
):
396 if self
._DscSpecification
== None:
397 if self
._Header
== None:
398 self
._GetHeaderInfo
()
399 if self
._DscSpecification
== None:
400 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
401 return self
._DscSpecification
403 ## Retrieve OUTPUT_DIRECTORY
404 def _GetOutpuDir(self
):
405 if self
._OutputDirectory
== None:
406 if self
._Header
== None:
407 self
._GetHeaderInfo
()
408 if self
._OutputDirectory
== None:
409 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
410 return self
._OutputDirectory
412 ## Retrieve SUPPORTED_ARCHITECTURES
413 def _GetSupArch(self
):
414 if self
._SupArchList
== None:
415 if self
._Header
== None:
416 self
._GetHeaderInfo
()
417 if self
._SupArchList
== None:
418 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
419 return self
._SupArchList
421 ## Retrieve BUILD_TARGETS
422 def _GetBuildTarget(self
):
423 if self
._BuildTargets
== None:
424 if self
._Header
== None:
425 self
._GetHeaderInfo
()
426 if self
._BuildTargets
== None:
427 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
428 return self
._BuildTargets
430 def _GetPcdInfoFlag(self
):
431 if self
._PcdInfoFlag
== None or self
._PcdInfoFlag
.upper() == 'FALSE':
433 elif self
._PcdInfoFlag
.upper() == 'TRUE':
437 def _GetVarCheckFlag(self
):
438 if self
._VarCheckFlag
== None or self
._VarCheckFlag
.upper() == 'FALSE':
440 elif self
._VarCheckFlag
.upper() == 'TRUE':
445 # # Retrieve SKUID_IDENTIFIER
446 def _GetSkuName(self
):
447 if self
._SkuName
== None:
448 if self
._Header
== None:
449 self
._GetHeaderInfo
()
450 if self
._SkuName
== None:
451 self
._SkuName
= 'DEFAULT'
454 ## Override SKUID_IDENTIFIER
455 def _SetSkuName(self
, Value
):
456 self
._SkuName
= Value
458 def _GetFdfFile(self
):
459 if self
._FlashDefinition
== None:
460 if self
._Header
== None:
461 self
._GetHeaderInfo
()
462 if self
._FlashDefinition
== None:
463 self
._FlashDefinition
= ''
464 return self
._FlashDefinition
466 def _GetPrebuild(self
):
467 if self
._Prebuild
== None:
468 if self
._Header
== None:
469 self
._GetHeaderInfo
()
470 if self
._Prebuild
== None:
472 return self
._Prebuild
474 def _GetPostbuild(self
):
475 if self
._Postbuild
== None:
476 if self
._Header
== None:
477 self
._GetHeaderInfo
()
478 if self
._Postbuild
== None:
480 return self
._Postbuild
482 ## Retrieve FLASH_DEFINITION
483 def _GetBuildNumber(self
):
484 if self
._BuildNumber
== None:
485 if self
._Header
== None:
486 self
._GetHeaderInfo
()
487 if self
._BuildNumber
== None:
488 self
._BuildNumber
= ''
489 return self
._BuildNumber
491 ## Retrieve MAKEFILE_NAME
492 def _GetMakefileName(self
):
493 if self
._MakefileName
== None:
494 if self
._Header
== None:
495 self
._GetHeaderInfo
()
496 if self
._MakefileName
== None:
497 self
._MakefileName
= ''
498 return self
._MakefileName
500 ## Retrieve BsBaseAddress
501 def _GetBsBaseAddress(self
):
502 if self
._BsBaseAddress
== None:
503 if self
._Header
== None:
504 self
._GetHeaderInfo
()
505 if self
._BsBaseAddress
== None:
506 self
._BsBaseAddress
= ''
507 return self
._BsBaseAddress
509 ## Retrieve RtBaseAddress
510 def _GetRtBaseAddress(self
):
511 if self
._RtBaseAddress
== None:
512 if self
._Header
== None:
513 self
._GetHeaderInfo
()
514 if self
._RtBaseAddress
== None:
515 self
._RtBaseAddress
= ''
516 return self
._RtBaseAddress
518 ## Retrieve the top address for the load fix address
519 def _GetLoadFixAddress(self
):
520 if self
._LoadFixAddress
== None:
521 if self
._Header
== None:
522 self
._GetHeaderInfo
()
524 if self
._LoadFixAddress
== None:
525 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
528 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
530 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
533 # If command line defined, should override the value in DSC file.
535 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
.keys():
537 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
539 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']))
541 if self
._LoadFixAddress
< 0:
542 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
543 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
544 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
546 return self
._LoadFixAddress
548 ## Retrieve RFCLanguage filter
549 def _GetRFCLanguages(self
):
550 if self
._RFCLanguages
== None:
551 if self
._Header
== None:
552 self
._GetHeaderInfo
()
553 if self
._RFCLanguages
== None:
554 self
._RFCLanguages
= []
555 return self
._RFCLanguages
557 ## Retrieve ISOLanguage filter
558 def _GetISOLanguages(self
):
559 if self
._ISOLanguages
== None:
560 if self
._Header
== None:
561 self
._GetHeaderInfo
()
562 if self
._ISOLanguages
== None:
563 self
._ISOLanguages
= []
564 return self
._ISOLanguages
565 ## Retrieve the GUID string for VPD tool
566 def _GetVpdToolGuid(self
):
567 if self
._VpdToolGuid
== None:
568 if self
._Header
== None:
569 self
._GetHeaderInfo
()
570 if self
._VpdToolGuid
== None:
571 self
._VpdToolGuid
= ''
572 return self
._VpdToolGuid
574 ## Retrieve [SkuIds] section information
575 def _GetSkuIds(self
):
576 if self
._SkuIds
== None:
577 self
._SkuIds
= sdict()
578 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
579 for Record
in RecordList
:
580 if Record
[0] in [None, '']:
581 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
582 File
=self
.MetaFile
, Line
=Record
[-1])
583 if Record
[1] in [None, '']:
584 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
585 File
=self
.MetaFile
, Line
=Record
[-1])
586 Pattern
= re
.compile('^[1-9]\d*|0$')
587 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
588 if Pattern
.match(Record
[0]) == None and HexPattern
.match(Record
[0]) == None:
589 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
590 File
=self
.MetaFile
, Line
=Record
[-1])
591 if not IsValidWord(Record
[1]):
592 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_-.)*'",
593 File
=self
.MetaFile
, Line
=Record
[-1])
594 self
._SkuIds
[Record
[1].upper()] = (str(self
.ToInt(Record
[0])), Record
[1].upper(), Record
[2].upper())
595 if 'DEFAULT' not in self
._SkuIds
:
596 self
._SkuIds
['DEFAULT'] = ("0","DEFAULT","DEFAULT")
597 if 'COMMON' not in self
._SkuIds
:
598 self
._SkuIds
['COMMON'] = ("0","DEFAULT","DEFAULT")
600 def ToInt(self
,intstr
):
601 return int(intstr
,16) if intstr
.upper().startswith("0X") else int(intstr
)
602 def _GetDefaultStores(self
):
603 if self
.DefaultStores
== None:
604 self
.DefaultStores
= sdict()
605 RecordList
= self
._RawData
[MODEL_EFI_DEFAULT_STORES
, self
._Arch
]
606 for Record
in RecordList
:
607 if Record
[0] in [None, '']:
608 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID number',
609 File
=self
.MetaFile
, Line
=Record
[-1])
610 if Record
[1] in [None, '']:
611 EdkLogger
.error('build', FORMAT_INVALID
, 'No DefaultStores ID name',
612 File
=self
.MetaFile
, Line
=Record
[-1])
613 Pattern
= re
.compile('^[1-9]\d*|0$')
614 HexPattern
= re
.compile(r
'0[xX][0-9a-fA-F]+$')
615 if Pattern
.match(Record
[0]) == None and HexPattern
.match(Record
[0]) == None:
616 EdkLogger
.error('build', FORMAT_INVALID
, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
617 File
=self
.MetaFile
, Line
=Record
[-1])
618 if not IsValidWord(Record
[1]):
619 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_-.)*'",
620 File
=self
.MetaFile
, Line
=Record
[-1])
621 self
.DefaultStores
[Record
[1].upper()] = (self
.ToInt(Record
[0]),Record
[1].upper())
622 if TAB_DEFAULT_STORES_DEFAULT
not in self
.DefaultStores
:
623 self
.DefaultStores
[TAB_DEFAULT_STORES_DEFAULT
] = (0,TAB_DEFAULT_STORES_DEFAULT
)
624 GlobalData
.gDefaultStores
= self
.DefaultStores
.keys()
625 if GlobalData
.gDefaultStores
:
626 GlobalData
.gDefaultStores
.sort()
627 return self
.DefaultStores
629 ## Retrieve [Components] section information
630 def _GetModules(self
):
631 if self
._Modules
!= None:
634 self
._Modules
= sdict()
635 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
636 Macros
= self
._Macros
637 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
638 for Record
in RecordList
:
639 DuplicatedFile
= False
641 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
645 # check the file validation
646 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
648 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
651 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
652 if self
._Arch
!= 'COMMON' and ModuleFile
in self
._Modules
:
653 DuplicatedFile
= True
655 Module
= ModuleBuildClassObject()
656 Module
.MetaFile
= ModuleFile
658 # get module private library instance
659 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
660 for Record
in RecordList
:
661 LibraryClass
= Record
[0]
662 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
665 # check the file validation
666 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
668 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
671 if LibraryClass
== '' or LibraryClass
== 'NULL':
672 self
._NullLibraryNumber
+= 1
673 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
674 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
675 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
676 if LibraryPath
not in self
.LibraryInstances
:
677 self
.LibraryInstances
.append(LibraryPath
)
679 # get module private PCD setting
680 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
681 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
682 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
683 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
684 TokenList
= GetSplitValueList(Setting
)
685 DefaultValue
= TokenList
[0]
686 # the format is PcdName| Value | VOID* | MaxDatumSize
687 if len(TokenList
) > 2:
688 MaxDatumSize
= TokenList
[2]
691 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
692 Pcd
= PcdClassObject(
704 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
706 # get module private build options
707 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
708 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
709 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
710 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
712 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
713 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
715 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
716 if DuplicatedFile
and not RecordList
:
717 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
719 if len(RecordList
) != 1:
720 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
721 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
722 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
723 ModuleFile
.Arch
= self
._Arch
725 self
._Modules
[ModuleFile
] = Module
728 ## Retrieve all possible library instances used in this platform
729 def _GetLibraryInstances(self
):
730 if self
._LibraryInstances
== None:
731 self
._GetLibraryClasses
()
732 return self
._LibraryInstances
734 ## Retrieve [LibraryClasses] information
735 def _GetLibraryClasses(self
):
736 if self
._LibraryClasses
== None:
737 self
._LibraryInstances
= []
739 # tdict is a special dict kind of type, used for selecting correct
740 # library instance for given library class and module type
742 LibraryClassDict
= tdict(True, 3)
743 # track all library class names
744 LibraryClassSet
= set()
745 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
746 Macros
= self
._Macros
747 for Record
in RecordList
:
748 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
,Dummy
, LineNo
= Record
749 if LibraryClass
== '' or LibraryClass
== 'NULL':
750 self
._NullLibraryNumber
+= 1
751 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
752 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
753 LibraryClassSet
.add(LibraryClass
)
754 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
755 # check the file validation
756 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
758 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
761 if ModuleType
!= 'COMMON' and ModuleType
not in SUP_MODULE_LIST
:
762 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
763 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
764 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
765 if LibraryInstance
not in self
._LibraryInstances
:
766 self
._LibraryInstances
.append(LibraryInstance
)
768 # resolve the specific library instance for each class and each module type
769 self
._LibraryClasses
= tdict(True)
770 for LibraryClass
in LibraryClassSet
:
771 # try all possible module types
772 for ModuleType
in SUP_MODULE_LIST
:
773 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
774 if LibraryInstance
== None:
776 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
778 # for Edk style library instances, which are listed in different section
779 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
780 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
781 for Record
in RecordList
:
782 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
784 # check the file validation
785 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
787 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
789 if File
not in self
._LibraryInstances
:
790 self
._LibraryInstances
.append(File
)
792 # we need the module name as the library class name, so we have
793 # to parse it here. (self._Bdb[] will trigger a file parse if it
794 # hasn't been parsed)
796 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
797 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
798 return self
._LibraryClasses
800 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
801 if self
._DecPcds
== None:
804 if GlobalData
.gFdfParser
:
805 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
808 for Inf
in FdfInfList
:
809 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
810 if ModuleFile
in self
._Modules
:
812 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
813 PkgSet
.update(ModuleData
.Packages
)
815 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
,PkgSet
)
816 self
._GuidDict
.update(GlobalData
.gPlatformPcds
)
818 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
819 EdkLogger
.error('build', PARSER_ERROR
,
820 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
821 File
=self
.MetaFile
, Line
=LineNo
)
822 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
824 if PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
825 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
826 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
828 if ValueList
[2] == '-1':
829 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
830 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
832 DatumType
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
834 ValueList
[Index
] = ValueExpressionEx(ValueList
[Index
], DatumType
, self
._GuidDict
)(True)
835 except BadExpression
, Value
:
836 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, File
=self
.MetaFile
, Line
=LineNo
,
837 ExtraData
="PCD [%s.%s] Value \"%s\" " % (
838 TokenSpaceGuid
, PcdCName
, ValueList
[Index
]))
839 except EvaluationException
, Excpt
:
840 if hasattr(Excpt
, 'Pcd'):
841 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
842 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
843 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
844 " of the DSC file" % Excpt
.Pcd
,
845 File
=self
.MetaFile
, Line
=LineNo
)
847 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
848 File
=self
.MetaFile
, Line
=LineNo
)
850 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
851 File
=self
.MetaFile
, Line
=LineNo
)
854 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
856 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
857 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
858 if PcdType
in (MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
):
859 if self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
.strip() != ValueList
[1].strip():
860 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
,
861 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
862 if (TokenSpaceGuid
+ '.' + PcdCName
) in GlobalData
.gPlatformPcds
:
863 if GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] != ValueList
[Index
]:
864 GlobalData
.gPlatformPcds
[TokenSpaceGuid
+ '.' + PcdCName
] = ValueList
[Index
]
867 def _FilterPcdBySkuUsage(self
,Pcds
):
868 available_sku
= self
.SkuIdMgr
.AvailableSkuIdSet
869 sku_usage
= self
.SkuIdMgr
.SkuUsageType
870 if sku_usage
== SkuClass
.SINGLE
:
873 Pcds
[pcdname
].SkuInfoList
= {"DEFAULT":pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
874 if type(pcd
) is StructurePcd
and pcd
.SkuOverrideValues
:
875 Pcds
[pcdname
].SkuOverrideValues
= {"DEFAULT":pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
879 Pcds
[pcdname
].SkuInfoList
= {skuid
:pcd
.SkuInfoList
[skuid
] for skuid
in pcd
.SkuInfoList
if skuid
in available_sku
}
880 if type(pcd
) is StructurePcd
and pcd
.SkuOverrideValues
:
881 Pcds
[pcdname
].SkuOverrideValues
= {skuid
:pcd
.SkuOverrideValues
[skuid
] for skuid
in pcd
.SkuOverrideValues
if skuid
in available_sku
}
883 def CompleteHiiPcdsDefaultStores(self
,Pcds
):
884 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
]]]
885 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
887 for skuid
in pcd
.SkuInfoList
:
888 skuobj
= pcd
.SkuInfoList
.get(skuid
)
889 if "STANDARD" not in skuobj
.DefaultStoreDict
:
890 PcdDefaultStoreSet
= set([defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
])
891 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
892 skuobj
.DefaultStoreDict
['STANDARD'] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
895 def RecoverCommandLinePcd(self
):
896 def UpdateCommandLineValue(pcd
):
897 if pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
898 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
899 pcd
.PcdValueFromComm
= pcd
.DefaultValue
900 elif pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
901 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get("DEFAULT").HiiDefaultValue
903 pcd
.PcdValueFromComm
= pcd
.SkuInfoList
.get("DEFAULT").DefaultValue
904 for pcd
in self
._Pcds
:
905 if isinstance(self
._Pcds
[pcd
],StructurePcd
) and (self
._Pcds
[pcd
].PcdValueFromComm
or self
._Pcds
[pcd
].PcdFieldValueFromComm
):
906 UpdateCommandLineValue(self
._Pcds
[pcd
])
908 def GetFieldValueFromComm(self
,ValueStr
,TokenSpaceGuidCName
, TokenCName
, FieldName
):
909 PredictedFieldType
= "VOID*"
910 if ValueStr
.startswith('L'):
912 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"{...}"')
913 ValueStr
= ValueStr
[0] + '"' + ValueStr
[1:] + '"'
914 PredictedFieldType
= "VOID*"
915 elif ValueStr
.startswith('H') or ValueStr
.startswith('{'):
916 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
))
917 ValueStr
= ValueStr
[1:]
918 PredictedFieldType
= "VOID*"
919 elif ValueStr
.upper() in ['TRUE', '0X1', '0X01', '1', 'FALSE', '0X0', '0X00', '0']:
920 PredictedFieldType
= "BOOLEAN"
921 elif ValueStr
.isdigit() or ValueStr
.upper().startswith('0X'):
922 PredictedFieldType
= TAB_UINT16
925 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"{...}"')
926 ValueStr
= '"' + ValueStr
+ '"'
927 PredictedFieldType
= "VOID*"
928 IsValid
, Cause
= CheckPcdDatum(PredictedFieldType
, ValueStr
)
930 EdkLogger
.error("build", FORMAT_INVALID
, Cause
, ExtraData
="%s.%s.%s from command line" % (TokenSpaceGuidCName
, TokenCName
, FieldName
))
931 if PredictedFieldType
== 'BOOLEAN':
932 ValueStr
= ValueStr
.upper()
933 if ValueStr
== 'TRUE' or ValueStr
== '1':
935 elif ValueStr
== 'FALSE' or ValueStr
== '0':
938 def __ParsePcdFromCommandLine(self
):
939 if GlobalData
.BuildOptionPcd
:
940 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
941 if type(pcd
) is tuple:
943 (pcdname
, pcdvalue
) = pcd
.split('=')
945 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
947 (Name1
, Name2
) = pcdname
.split('.',1)
949 (Name3
, FieldName
) = Name2
.split(".",1)
950 if ((Name3
,Name1
)) in self
.DecPcds
:
953 TokenSpaceGuidCName
= Name1
957 TokenSpaceGuidCName
= ''
958 HasTokenSpace
= False
960 if ((Name2
,Name1
)) in self
.DecPcds
:
963 TokenSpaceGuidCName
= Name1
968 TokenSpaceGuidCName
= ''
969 HasTokenSpace
= False
973 TokenSpaceGuidCName
= ''
974 HasTokenSpace
= False
975 TokenSpaceGuidCNameList
= []
979 if not HasTokenSpace
:
980 for key
in self
.DecPcds
:
981 if TokenCName
== key
[0]:
982 if TokenSpaceGuidCName
:
986 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, TokenSpaceGuidCName
, key
[1])
989 TokenSpaceGuidCName
= key
[1]
992 if (TokenCName
, TokenSpaceGuidCName
) in self
.DecPcds
:
995 NewValue
= self
.GetFieldValueFromComm(pcdvalue
, TokenSpaceGuidCName
, TokenCName
, FieldName
)
996 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
,NewValue
,("build command options",1))
998 # Replace \' to ', \\\' to \'
999 pcdvalue
= pcdvalue
.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
1000 for key
in self
.DecPcds
:
1001 PcdItem
= self
.DecPcds
[key
]
1003 if (PcdItem
.TokenCName
, PcdItem
.TokenSpaceGuidCName
) == (TokenCName
, TokenSpaceGuidCName
):
1004 PcdDatumType
= PcdItem
.DatumType
1005 if pcdvalue
.startswith('H'):
1007 pcdvalue
= ValueExpressionEx(pcdvalue
[1:], PcdDatumType
, self
._GuidDict
)(True)
1008 except BadExpression
, Value
:
1009 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1010 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1011 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1012 pcdvalue
= 'H' + pcdvalue
1013 elif pcdvalue
.startswith("L'"):
1015 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1016 except BadExpression
, Value
:
1017 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1018 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1019 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1020 pcdvalue
= 'H' + pcdvalue
1021 elif pcdvalue
.startswith("'"):
1023 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1024 except BadExpression
, Value
:
1025 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1026 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1027 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1028 pcdvalue
= 'H' + pcdvalue
1029 elif pcdvalue
.startswith('L'):
1030 pcdvalue
= 'L"' + pcdvalue
[1:] + '"'
1032 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1033 except BadExpression
, Value
:
1034 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1035 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1038 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1039 except BadExpression
, Value
:
1041 pcdvalue
= '"' + pcdvalue
+ '"'
1042 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1043 except BadExpression
, Value
:
1044 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1045 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1046 NewValue
= BuildOptionPcdValueFormat(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
1049 if PcdItem
.TokenCName
== TokenCName
:
1050 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
1051 if len (TokenSpaceGuidCNameList
) < 1:
1052 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
1053 PcdDatumType
= PcdItem
.DatumType
1054 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
1055 if pcdvalue
.startswith('H'):
1057 pcdvalue
= ValueExpressionEx(pcdvalue
[1:], PcdDatumType
, self
._GuidDict
)(True)
1058 except BadExpression
, Value
:
1059 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1060 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1061 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
,'BOOLEAN']:
1062 pcdvalue
= 'H' + pcdvalue
1063 elif pcdvalue
.startswith("L'"):
1065 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(
1067 except BadExpression
, Value
:
1068 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1069 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1070 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1071 pcdvalue
= 'H' + pcdvalue
1072 elif pcdvalue
.startswith("'"):
1074 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(
1076 except BadExpression
, Value
:
1077 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1078 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1079 if PcdDatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, 'BOOLEAN']:
1080 pcdvalue
= 'H' + pcdvalue
1081 elif pcdvalue
.startswith('L'):
1082 pcdvalue
= 'L"' + pcdvalue
[1:] + '"'
1084 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(
1086 except BadExpression
, Value
:
1087 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1088 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1091 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1092 except BadExpression
, Value
:
1094 pcdvalue
= '"' + pcdvalue
+ '"'
1095 pcdvalue
= ValueExpressionEx(pcdvalue
, PcdDatumType
, self
._GuidDict
)(True)
1096 except BadExpression
, Value
:
1097 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %
1098 (TokenSpaceGuidCName
, TokenCName
, pcdvalue
, Value
))
1099 NewValue
= BuildOptionPcdValueFormat(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
1105 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
1107 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, FieldName
,NewValue
,("build command options",1))
1110 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, TokenCName
))
1112 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (TokenCName
))
1113 for BuildData
in self
._Bdb
._CACHE
_.values():
1114 if BuildData
.MetaFile
.Ext
== '.dec' or BuildData
.MetaFile
.Ext
== '.dsc':
1116 for key
in BuildData
.Pcds
:
1117 PcdItem
= BuildData
.Pcds
[key
]
1118 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
) and FieldName
=="":
1119 PcdItem
.DefaultValue
= NewValue
1120 ## Retrieve all PCD settings in platform
1122 if self
._Pcds
== None:
1123 self
._Pcds
= sdict()
1124 self
.__ParsePcdFromCommandLine
()
1125 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1126 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1127 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1128 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
1129 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
1130 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
1131 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
1132 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
1133 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
1135 self
._Pcds
= self
.CompletePcdValues(self
._Pcds
)
1136 self
._Pcds
= self
.OverrideByFdfCommOverAll(self
._Pcds
)
1137 self
._Pcds
= self
.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST
, self
._Pcds
)
1138 self
._Pcds
= self
.CompleteHiiPcdsDefaultStores(self
._Pcds
)
1139 self
._Pcds
= self
._FilterPcdBySkuUsage
(self
._Pcds
)
1141 self
.RecoverCommandLinePcd()
1144 def _dumpPcdInfo(self
,Pcds
):
1147 if not pcdobj
.TokenCName
.startswith("Test"):
1149 for skuid
in pcdobj
.SkuInfoList
:
1150 if pcdobj
.Type
in (self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]):
1151 for storename
in pcdobj
.SkuInfoList
[skuid
].DefaultStoreDict
:
1152 print "PcdCName: %s, SkuName: %s, StoreName: %s, Value: %s" % (".".join((pcdobj
.TokenSpaceGuidCName
, pcdobj
.TokenCName
)), skuid
,storename
,str(pcdobj
.SkuInfoList
[skuid
].DefaultStoreDict
[storename
]))
1154 print "PcdCName: %s, SkuName: %s, Value: %s" % (".".join((pcdobj
.TokenSpaceGuidCName
, pcdobj
.TokenCName
)), skuid
,str(pcdobj
.SkuInfoList
[skuid
].DefaultValue
))
1155 ## Retrieve [BuildOptions]
1156 def _GetBuildOptions(self
):
1157 if self
._BuildOptions
== None:
1158 self
._BuildOptions
= sdict()
1160 # Retrieve build option for EDKII and EDK style module
1162 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
1163 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
1164 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1165 if Dummy3
.upper() != 'COMMON':
1167 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
1169 # Only flags can be appended
1171 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1172 self
._BuildOptions
[CurKey
] = Option
1174 if ' ' + Option
not in self
._BuildOptions
[CurKey
]:
1175 self
._BuildOptions
[CurKey
] += ' ' + Option
1176 return self
._BuildOptions
1178 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
1179 if self
._ModuleTypeOptions
== None:
1180 self
._ModuleTypeOptions
= sdict()
1181 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
1183 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
1184 DriverType
= '%s.%s' % (Edk
, ModuleType
)
1185 CommonDriverType
= '%s.%s' % ('COMMON', ModuleType
)
1186 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
]
1187 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1188 Type
= Dummy2
+ '.' + Dummy3
1189 if Type
.upper() == DriverType
.upper() or Type
.upper() == CommonDriverType
.upper():
1190 Key
= (ToolChainFamily
, ToolChain
, Edk
)
1191 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
1192 options
[Key
] = Option
1194 if ' ' + Option
not in options
[Key
]:
1195 options
[Key
] += ' ' + Option
1196 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
1198 def GetStructurePcdInfo(self
, PcdSet
):
1199 structure_pcd_data
= {}
1201 if (item
[0],item
[1]) not in structure_pcd_data
:
1202 structure_pcd_data
[(item
[0],item
[1])] = []
1203 structure_pcd_data
[(item
[0],item
[1])].append(item
)
1205 return structure_pcd_data
1206 def OverrideByFdfComm(self
,StruPcds
):
1207 StructurePcdInCom
= OrderedDict()
1208 for item
in GlobalData
.BuildOptionPcd
:
1209 if len(item
) == 5 and (item
[1],item
[0]) in StruPcds
:
1210 StructurePcdInCom
[(item
[0],item
[1],item
[2] )] = (item
[3],item
[4])
1211 GlobalPcds
= set([(item
[0],item
[1]) for item
in StructurePcdInCom
.keys()])
1212 for Pcd
in StruPcds
.values():
1213 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) not in GlobalPcds
:
1215 FieldValues
= OrderedDict()
1216 for item
in StructurePcdInCom
:
1217 if (Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
) == (item
[0],item
[1]) and item
[2]:
1218 FieldValues
[item
[2]] = StructurePcdInCom
[item
]
1219 for field
in FieldValues
:
1220 if field
not in Pcd
.PcdFieldValueFromComm
:
1221 Pcd
.PcdFieldValueFromComm
[field
] = ["","",""]
1222 Pcd
.PcdFieldValueFromComm
[field
][0] = FieldValues
[field
][0]
1223 Pcd
.PcdFieldValueFromComm
[field
][1] = FieldValues
[field
][1][0]
1224 Pcd
.PcdFieldValueFromComm
[field
][2] = FieldValues
[field
][1][1]
1226 def OverrideByFdfCommOverAll(self
,AllPcds
):
1227 def CheckStructureInComm(commpcds
):
1230 if len(commpcds
[0]) == 5:
1234 if CheckStructureInComm(GlobalData
.BuildOptionPcd
):
1235 StructurePcdInCom
= {(item
[0],item
[1],item
[2] ):(item
[3],item
[4]) for item
in GlobalData
.BuildOptionPcd
} if GlobalData
.BuildOptionPcd
else {}
1236 NoFiledValues
= {(item
[0],item
[1]):StructurePcdInCom
[item
] for item
in StructurePcdInCom
if not item
[2]}
1238 NoFiledValues
= {(item
[0],item
[1]):[item
[2]] for item
in GlobalData
.BuildOptionPcd
}
1239 for Guid
,Name
in NoFiledValues
:
1240 if (Name
,Guid
) in AllPcds
:
1241 Pcd
= AllPcds
.get((Name
,Guid
))
1242 if isinstance(self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
), None),StructurePcd
):
1243 self
._DecPcds
.get((Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)).PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1245 Pcd
.PcdValueFromComm
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1246 Pcd
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1247 for sku
in Pcd
.SkuInfoList
:
1248 SkuInfo
= Pcd
.SkuInfoList
[sku
]
1249 if SkuInfo
.DefaultValue
:
1250 SkuInfo
.DefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1252 SkuInfo
.HiiDefaultValue
= NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1253 for defaultstore
in SkuInfo
.DefaultStoreDict
:
1254 SkuInfo
.DefaultStoreDict
[defaultstore
] = NoFiledValues
[(Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
)][0]
1255 if Pcd
.DatumType
== "VOID*":
1256 if Pcd
.MaxDatumSize
is None:
1257 Pcd
.MaxDatumSize
= '0'
1258 MaxSize
= int(Pcd
.MaxDatumSize
,10)
1259 if Pcd
.DefaultValue
.startswith("{") and Pcd
.DefaultValue
.endswith("}"):
1260 MaxSize
= max([len(Pcd
.DefaultValue
.split(",")),MaxSize
])
1261 elif Pcd
.DefaultValue
.startswith("\"") or Pcd
.DefaultValue
.startswith("\'"):
1262 MaxSize
= max([len(Pcd
.DefaultValue
)-2+1,MaxSize
])
1263 elif Pcd
.DefaultValue
.startswith("L\""):
1264 MaxSize
= max([2*(len(Pcd
.DefaultValue
)-3+1),MaxSize
])
1266 MaxSize
= max([len(Pcd
.DefaultValue
),MaxSize
])
1267 Pcd
.MaxDatumSize
= str(MaxSize
)
1269 PcdInDec
= self
.DecPcds
.get((Name
,Guid
))
1271 PcdInDec
.PcdValueFromComm
= NoFiledValues
[(Guid
,Name
)][0]
1272 if PcdInDec
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1273 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1274 self
.Pcds
[Name
, Guid
] = copy
.deepcopy(PcdInDec
)
1275 self
.Pcds
[Name
, Guid
].DefaultValue
= NoFiledValues
[( Guid
,Name
)][0]
1277 def UpdateStructuredPcds(self
, TypeList
, AllPcds
):
1279 DynamicPcdType
= [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
1280 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1281 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
1282 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
1283 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
1284 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]
1287 DefaultStoreMgr
= DefaultStore(self
.DefaultStores
)
1288 SkuIds
= self
.SkuIdMgr
.AvailableSkuIdSet
1289 SkuIds
.update({'DEFAULT':0})
1290 DefaultStores
= set([storename
for pcdobj
in AllPcds
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
.keys()])
1293 # Find out all possible PCD candidates for self._Arch
1296 for Type
in TypeList
:
1297 RecordList
.extend(self
._RawData
[Type
, self
._Arch
])
1299 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, default_store
, Dummy4
,Dummy5
in RecordList
:
1300 SkuName
= SkuName
.upper()
1301 default_store
= default_store
.upper()
1302 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
1303 if SkuName
not in SkuIds
:
1306 if SkuName
in SkuIds
and "." in TokenSpaceGuid
:
1307 S_PcdSet
.append([ TokenSpaceGuid
.split(".")[0],TokenSpaceGuid
.split(".")[1], PcdCName
,SkuName
, default_store
,Dummy5
, AnalyzePcdExpression(Setting
)[0]])
1309 # handle pcd value override
1310 StrPcdSet
= self
.GetStructurePcdInfo(S_PcdSet
)
1311 S_pcd_set
= OrderedDict()
1312 for str_pcd
in StrPcdSet
:
1313 str_pcd_obj
= Pcds
.get((str_pcd
[1], str_pcd
[0]), None)
1314 str_pcd_dec
= self
._DecPcds
.get((str_pcd
[1], str_pcd
[0]), None)
1315 if not isinstance (str_pcd_dec
, StructurePcd
):
1316 EdkLogger
.error('build', PARSER_ERROR
,
1317 "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1318 File
=self
.MetaFile
,Line
= StrPcdSet
[str_pcd
][0][5])
1320 str_pcd_obj_str
= StructurePcd()
1321 str_pcd_obj_str
.copy(str_pcd_dec
)
1323 str_pcd_obj_str
.copy(str_pcd_obj
)
1324 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1325 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
}
1327 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
}
1328 for str_pcd_data
in StrPcdSet
[str_pcd
]:
1329 if str_pcd_data
[3] in SkuIds
:
1330 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
if self
.WorkspaceDir
not in self
.MetaFile
.File
else self
.MetaFile
.File
[len(self
.WorkspaceDir
) if self
.WorkspaceDir
.endswith(os
.path
.sep
) else len(self
.WorkspaceDir
)+1:],LineNo
=str_pcd_data
[5])
1331 S_pcd_set
[str_pcd
[1], str_pcd
[0]] = str_pcd_obj_str
1333 EdkLogger
.error('build', PARSER_ERROR
,
1334 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd
[0], str_pcd
[1], self
._Arch
),
1335 File
=self
.MetaFile
,Line
= StrPcdSet
[str_pcd
][0][5])
1336 # Add the Structure PCD that only defined in DEC, don't have override in DSC file
1337 for Pcd
in self
.DecPcds
:
1338 if type (self
._DecPcds
[Pcd
]) is StructurePcd
:
1339 if Pcd
not in S_pcd_set
:
1340 str_pcd_obj_str
= StructurePcd()
1341 str_pcd_obj_str
.copy(self
._DecPcds
[Pcd
])
1342 str_pcd_obj
= Pcds
.get(Pcd
, None)
1344 str_pcd_obj_str
.copy(str_pcd_obj
)
1345 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1346 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
}
1348 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
}
1349 S_pcd_set
[Pcd
] = str_pcd_obj_str
1351 GlobalData
.gStructurePcd
[self
.Arch
] = S_pcd_set
1352 for stru_pcd
in S_pcd_set
.values():
1353 for skuid
in SkuIds
:
1354 if skuid
in stru_pcd
.SkuOverrideValues
:
1356 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuid
)
1358 if skuid
not in stru_pcd
.SkuOverrideValues
:
1359 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1360 if nextskuid
== "DEFAULT":
1363 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1364 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
})
1366 stru_pcd
.ValueChain
[(skuid
,'')]= (nextskuid
,'')
1367 if stru_pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1368 for skuid
in SkuIds
:
1371 if skuid
not in stru_pcd
.SkuOverrideValues
:
1372 while nextskuid
not in stru_pcd
.SkuOverrideValues
:
1373 if nextskuid
== "DEFAULT":
1376 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1379 PcdDefaultStoreSet
= set([defaultstorename
for defaultstorename
in stru_pcd
.SkuOverrideValues
[nextskuid
]])
1380 mindefaultstorename
= DefaultStoreMgr
.GetMin(PcdDefaultStoreSet
)
1382 for defaultstoreid
in DefaultStores
:
1383 if defaultstoreid
not in stru_pcd
.SkuOverrideValues
[skuid
]:
1384 stru_pcd
.SkuOverrideValues
[skuid
][defaultstoreid
] = copy
.deepcopy(stru_pcd
.SkuOverrideValues
[nextskuid
][mindefaultstorename
])
1385 stru_pcd
.ValueChain
[(skuid
,defaultstoreid
)]= (nextskuid
,mindefaultstorename
)
1386 S_pcd_set
= self
.OverrideByFdfComm(S_pcd_set
)
1387 Str_Pcd_Values
= self
.GenerateByteArrayValue(S_pcd_set
)
1389 for (skuname
,StoreName
,PcdGuid
,PcdName
,PcdValue
) in Str_Pcd_Values
:
1390 str_pcd_obj
= S_pcd_set
.get((PcdName
, PcdGuid
))
1391 if str_pcd_obj
is None:
1392 print PcdName
, PcdGuid
1394 if str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1395 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1396 if skuname
not in str_pcd_obj
.SkuInfoList
:
1397 str_pcd_obj
.SkuInfoList
[skuname
] = SkuInfoClass(SkuIdName
=skuname
, SkuId
=self
.SkuIds
[skuname
][0], HiiDefaultValue
=PcdValue
, DefaultStore
= {StoreName
:PcdValue
})
1399 str_pcd_obj
.SkuInfoList
[skuname
].HiiDefaultValue
= PcdValue
1400 str_pcd_obj
.SkuInfoList
[skuname
].DefaultStoreDict
.update({StoreName
:PcdValue
})
1401 elif str_pcd_obj
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1402 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1403 if skuname
in (self
.SkuIdMgr
.SystemSkuId
, 'DEFAULT', 'COMMON'):
1404 str_pcd_obj
.DefaultValue
= PcdValue
1406 if skuname
not in str_pcd_obj
.SkuInfoList
:
1407 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
1409 while nextskuid
not in str_pcd_obj
.SkuInfoList
:
1410 if nextskuid
== "DEFAULT":
1413 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
1414 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
)
1415 str_pcd_obj
.SkuInfoList
[skuname
].SkuId
= self
.SkuIds
[skuname
][0]
1416 str_pcd_obj
.SkuInfoList
[skuname
].SkuIdName
= skuname
1418 str_pcd_obj
.SkuInfoList
[skuname
].DefaultValue
= PcdValue
1419 for str_pcd_obj
in S_pcd_set
.values():
1420 if str_pcd_obj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
1421 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
1423 PcdDefaultStoreSet
= set([defaultstorename
for skuobj
in str_pcd_obj
.SkuInfoList
.values() for defaultstorename
in skuobj
.DefaultStoreDict
])
1424 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
1425 mindefaultstorename
= DefaultStoreObj
.GetMin(PcdDefaultStoreSet
)
1426 str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].HiiDefaultValue
= str_pcd_obj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
].DefaultStoreDict
[mindefaultstorename
]
1428 for str_pcd_obj
in S_pcd_set
.values():
1430 str_pcd_obj
.MaxDatumSize
= self
.GetStructurePcdMaxSize(str_pcd_obj
)
1431 Pcds
[str_pcd_obj
.TokenCName
, str_pcd_obj
.TokenSpaceGuidCName
] = str_pcd_obj
1435 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
1436 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
1437 del(pcd
.SkuInfoList
['COMMON'])
1438 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
1439 del(pcd
.SkuInfoList
['COMMON'])
1441 map(self
.FilterSkuSettings
,[Pcds
[pcdkey
] for pcdkey
in Pcds
if Pcds
[pcdkey
].Type
in DynamicPcdType
])
1444 ## Retrieve non-dynamic PCD settings
1446 # @param Type PCD type
1448 # @retval a dict object contains settings of given PCD type
1450 def _GetPcd(self
, Type
):
1453 # tdict is a special dict kind of type, used for selecting correct
1454 # PCD settings for certain ARCH
1456 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
1458 PcdDict
= tdict(True, 3)
1460 # Find out all possible PCD candidates for self._Arch
1461 RecordList
= self
._RawData
[Type
, self
._Arch
]
1462 PcdValueDict
= sdict()
1463 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
1464 SkuName
= SkuName
.upper()
1465 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
1466 if SkuName
not in AvailableSkuIdSet
:
1467 EdkLogger
.error('build ', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
1468 File
=self
.MetaFile
, Line
=Dummy5
)
1469 if SkuName
in (self
.SkuIdMgr
.SystemSkuId
, 'DEFAULT', 'COMMON'):
1470 if "." not in TokenSpaceGuid
:
1471 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
1472 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
, SkuName
] = Setting
1474 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdSet
:
1475 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
, SkuName
]
1478 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1479 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
1480 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
, DatumType
, MaxDatumSize
)
1482 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
, DatumType
, MaxDatumSize
)}
1484 PcdsKeys
= PcdValueDict
.keys()
1485 for PcdCName
, TokenSpaceGuid
in PcdsKeys
:
1487 PcdSetting
= PcdValueDict
[PcdCName
, TokenSpaceGuid
]
1491 if 'COMMON' in PcdSetting
:
1492 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
['COMMON']
1493 if 'DEFAULT' in PcdSetting
:
1494 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
['DEFAULT']
1495 if self
.SkuIdMgr
.SystemSkuId
in PcdSetting
:
1496 PcdValue
, DatumType
, MaxDatumSize
= PcdSetting
[self
.SkuIdMgr
.SystemSkuId
]
1498 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1501 self
._PCD
_TYPE
_STRING
_[Type
],
1514 def __UNICODE2OCTList(self
,Value
):
1515 Value
= Value
.strip()
1519 Temp
= '%04X' % ord(Item
)
1520 List
.append('0x' + Temp
[2:4])
1521 List
.append('0x' + Temp
[0:2])
1525 def __STRING2OCTList(self
,Value
):
1527 Value
= Value
.strip('"')
1529 Temp
= '%02X' % ord(char
)
1530 OCTList
.append('0x' + Temp
)
1531 OCTList
.append('0x00')
1534 def GetStructurePcdMaxSize(self
, str_pcd
):
1535 pcd_default_value
= str_pcd
.DefaultValue
1536 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()]
1537 sku_values
.append(pcd_default_value
)
1539 def get_length(value
):
1540 Value
= value
.strip()
1542 if Value
.startswith('GUID') and Value
.endswith(')'):
1544 if Value
.startswith('L"') and Value
.endswith('"'):
1545 return len(Value
[2:-1])
1546 if Value
[0] == '"' and Value
[-1] == '"':
1547 return len(Value
) - 2
1548 if Value
[0] == '{' and Value
[-1] == '}':
1549 return len(Value
.split(","))
1550 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1551 return len(list(Value
[2:-1]))
1552 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1553 return len(Value
) - 2
1556 return str(max([pcd_size
for pcd_size
in [get_length(item
) for item
in sku_values
]]))
1558 def IsFieldValueAnArray (self
, Value
):
1559 Value
= Value
.strip()
1560 if Value
.startswith('GUID') and Value
.endswith(')'):
1562 if Value
.startswith('L"') and Value
.endswith('"') and len(list(Value
[2:-1])) > 1:
1564 if Value
[0] == '"' and Value
[-1] == '"' and len(list(Value
[1:-1])) > 1:
1566 if Value
[0] == '{' and Value
[-1] == '}':
1568 if Value
.startswith("L'") and Value
.endswith("'") and len(list(Value
[2:-1])) > 1:
1570 if Value
[0] == "'" and Value
[-1] == "'" and len(list(Value
[1:-1])) > 1:
1574 def ExecuteCommand (self
, Command
):
1576 Process
= subprocess
.Popen(Command
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
1578 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % Command
)
1579 Result
= Process
.communicate()
1580 return Process
.returncode
, Result
[0], Result
[1]
1582 def IntToCString(self
, Value
, ValueSize
):
1584 if not isinstance (Value
, str):
1585 for Index
in range(0, ValueSize
):
1586 Result
= Result
+ '\\x%02x' % (Value
& 0xff)
1588 Result
= Result
+ '"'
1591 def GetPcdMaxSize(self
,Pcd
):
1592 MaxSize
= int(Pcd
.MaxDatumSize
,10) if Pcd
.MaxDatumSize
else 0
1593 if Pcd
.DatumType
not in ['BOOLEAN','UINT8','UINT16','UINT32','UINT64']:
1594 if Pcd
.PcdValueFromComm
:
1595 if Pcd
.PcdValueFromComm
.startswith("{") and Pcd
.PcdValueFromComm
.endswith("}"):
1596 MaxSize
= max([len(Pcd
.PcdValueFromComm
.split(",")),MaxSize
])
1597 elif Pcd
.PcdValueFromComm
.startswith("\"") or Pcd
.PcdValueFromComm
.startswith("\'"):
1598 MaxSize
= max([len(Pcd
.PcdValueFromComm
)-2+1,MaxSize
])
1599 elif Pcd
.PcdValueFromComm
.startswith("L\""):
1600 MaxSize
= max([2*(len(Pcd
.PcdValueFromComm
)-3+1),MaxSize
])
1602 MaxSize
= max([len(Pcd
.PcdValueFromComm
),MaxSize
])
1603 elif Pcd
.DatumType
not in ['BOOLEAN','UINT8']:
1605 elif Pcd
.DatumType
== 'UINT16':
1607 elif Pcd
.DatumType
== 'UINT32':
1609 elif Pcd
.DatumType
== 'UINT64':
1612 def GenerateSizeFunction(self
,Pcd
):
1613 CApp
= "// Default Value in Dec \n"
1614 CApp
= CApp
+ "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1615 for FieldList
in [Pcd
.DefaultValues
]:
1618 for FieldName
in FieldList
:
1619 FieldName
= "." + FieldName
1620 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1621 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1623 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], "VOID*", self
._GuidDict
)(True)
1624 except BadExpression
:
1625 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1626 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1627 Value
, ValueSize
= ParseFieldValue(Value
)
1628 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]);
1631 FieldName_ori
= FieldName
.strip('.')
1632 while '[' in FieldName
:
1633 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1634 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1635 FieldName
= FieldName
.split(']', 1)[1]
1636 FieldName
= NewFieldName
+ FieldName
1637 while '[' in FieldName
:
1638 FieldName
= FieldName
.rsplit('[', 1)[0]
1639 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])
1640 for skuname
in Pcd
.SkuOverrideValues
:
1641 if skuname
== "COMMON":
1643 for defaultstorenameitem
in Pcd
.SkuOverrideValues
[skuname
]:
1644 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1645 for FieldList
in [Pcd
.SkuOverrideValues
[skuname
].get(defaultstorenameitem
)]:
1648 for FieldName
in FieldList
:
1649 FieldName
= "." + FieldName
1650 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
.strip(".")][0])
1651 if IsArray
and not (FieldList
[FieldName
.strip(".")][0].startswith('{GUID') and FieldList
[FieldName
.strip(".")][0].endswith('}')):
1653 Value
= ValueExpressionEx(FieldList
[FieldName
.strip(".")][0], "VOID*", self
._GuidDict
)(True)
1654 except BadExpression
:
1655 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1656 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), FieldList
[FieldName
.strip(".")][1], FieldList
[FieldName
.strip(".")][2]))
1657 Value
, ValueSize
= ParseFieldValue(Value
)
1658 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]);
1661 FieldName_ori
= FieldName
.strip('.')
1662 while '[' in FieldName
:
1663 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1664 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1665 FieldName
= FieldName
.split(']', 1)[1]
1666 FieldName
= NewFieldName
+ FieldName
1667 while '[' in FieldName
:
1668 FieldName
= FieldName
.rsplit('[', 1)[0]
1669 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])
1670 if Pcd
.PcdFieldValueFromComm
:
1671 CApp
= CApp
+ "// From Command Line \n"
1672 for FieldName
in Pcd
.PcdFieldValueFromComm
:
1673 FieldName
= "." + FieldName
1674 IsArray
= self
.IsFieldValueAnArray(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0])
1675 if IsArray
and not (Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].startswith('{GUID') and Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0].endswith('}')):
1677 Value
= ValueExpressionEx(Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0], "VOID*", self
._GuidDict
)(True)
1678 except BadExpression
:
1679 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1680 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
.strip('.'))), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2]))
1681 Value
, ValueSize
= ParseFieldValue(Value
)
1682 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd
.DatumType
, FieldName
.strip("."), ValueSize
, Pcd
.DatumType
, FieldName
.strip("."), ValueSize
, Pcd
.DatumType
, FieldName
.strip("."), Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][1], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][2], Pcd
.PcdFieldValueFromComm
[FieldName
.strip(".")][0]);
1685 FieldName_ori
= FieldName
.strip('.')
1686 while '[' in FieldName
:
1687 NewFieldName
= NewFieldName
+ FieldName
.split('[', 1)[0] + '[0]'
1688 ArrayIndex
= int(FieldName
.split('[', 1)[1].split(']', 1)[0])
1689 FieldName
= FieldName
.split(']', 1)[1]
1690 FieldName
= NewFieldName
+ FieldName
1691 while '[' in FieldName
:
1692 FieldName
= FieldName
.rsplit('[', 1)[0]
1693 CApp
= CApp
+ ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd
.DatumType
, FieldName
.strip("."), ArrayIndex
+ 1, Pcd
.PcdFieldValueFromComm
[FieldName_ori
][1], Pcd
.PcdFieldValueFromComm
[FieldName_ori
][2], Pcd
.PcdFieldValueFromComm
[FieldName_ori
][0])
1694 CApp
= CApp
+ " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (self
.GetPcdMaxSize(Pcd
),self
.GetPcdMaxSize(Pcd
),self
.GetPcdMaxSize(Pcd
))
1697 def GenerateSizeStatments(self
,Pcd
):
1698 CApp
= ' Size = sizeof(%s);\n' % (Pcd
.DatumType
)
1699 CApp
= CApp
+ ' Cal_%s_%s_Size(&Size);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1701 def GenerateDefaultValueAssignFunction(self
,Pcd
):
1702 CApp
= "// Default value in Dec \n"
1703 CApp
= CApp
+ "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
)
1704 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1705 CApp
= CApp
+ ' CHAR8 *Value;\n'
1706 DefaultValueFromDec
= Pcd
.DefaultValueFromDec
1707 IsArray
= self
.IsFieldValueAnArray(Pcd
.DefaultValueFromDec
)
1710 DefaultValueFromDec
= ValueExpressionEx(Pcd
.DefaultValueFromDec
, "VOID*")(True)
1711 except BadExpression
:
1712 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DEC: %s" %
1713 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, DefaultValueFromDec
))
1714 DefaultValueFromDec
= StringToArray(DefaultValueFromDec
)
1715 Value
, ValueSize
= ParseFieldValue (DefaultValueFromDec
)
1716 if isinstance(Value
, str):
1717 CApp
= CApp
+ ' Pcd = %s; // From DEC Default Value %s\n' % (Value
, Pcd
.DefaultValueFromDec
)
1720 # Use memcpy() to copy value into field
1722 CApp
= CApp
+ ' Value = %s; // From DEC Default Value %s\n' % (self
.IntToCString(Value
, ValueSize
), Pcd
.DefaultValueFromDec
)
1723 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1724 for FieldList
in [Pcd
.DefaultValues
]:
1727 for FieldName
in FieldList
:
1728 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
][0])
1731 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], "VOID*", self
._GuidDict
)(True)
1732 except BadExpression
:
1733 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1734 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1],FieldList
[FieldName
][2]))
1737 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1739 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]))
1740 if isinstance(Value
, str):
1741 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1744 # Use memcpy() to copy value into field
1746 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1747 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (self
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1748 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1751 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1753 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1756 def GenerateDefaultValueAssignStatement(self
,Pcd
):
1757 CApp
= ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1759 def GenerateInitValueFunction(self
,Pcd
,SkuName
,DefaultStoreName
):
1760 CApp
= "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName
,DefaultStoreName
)
1761 CApp
= CApp
+ "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
,DefaultStoreName
,Pcd
.DatumType
)
1762 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1763 CApp
= CApp
+ ' CHAR8 *Value;\n'
1765 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % ('DEFAULT', 'STANDARD')
1766 inherit_OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1767 if (SkuName
,DefaultStoreName
) == ('DEFAULT','STANDARD'):
1768 pcddefaultvalue
= Pcd
.DefaultFromDSC
.get('DEFAULT',{}).get('STANDARD', Pcd
.DefaultValue
) if Pcd
.DefaultFromDSC
else Pcd
.DefaultValue
1770 if not Pcd
.DscRawValue
:
1771 # handle the case that structure pcd is not appear in DSC
1772 self
.CopyDscRawValue(Pcd
)
1773 pcddefaultvalue
= Pcd
.DscRawValue
.get(SkuName
,{}).get(DefaultStoreName
)
1774 for FieldList
in [pcddefaultvalue
,inherit_OverrideValues
.get(DefaultStoreName
)]:
1777 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1778 IsArray
= self
.IsFieldValueAnArray(FieldList
)
1781 FieldList
= ValueExpressionEx(FieldList
, "VOID*")(True)
1782 except BadExpression
:
1783 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from DSC: %s" %
1784 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1785 Value
, ValueSize
= ParseFieldValue (FieldList
)
1787 if (SkuName
,DefaultStoreName
) == ('DEFAULT','STANDARD'):
1788 if isinstance(Value
, str):
1789 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DefaultFromDSC
.get('DEFAULT',{}).get('STANDARD', Pcd
.DefaultValue
) if Pcd
.DefaultFromDSC
else Pcd
.DefaultValue
)
1792 # Use memcpy() to copy value into field
1794 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (self
.IntToCString(Value
, ValueSize
), Pcd
.DefaultFromDSC
.get('DEFAULT',{}).get('STANDARD', Pcd
.DefaultValue
) if Pcd
.DefaultFromDSC
else Pcd
.DefaultValue
)
1795 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1797 if isinstance(Value
, str):
1798 CApp
= CApp
+ ' Pcd = %s; // From DSC Default Value %s\n' % (Value
, Pcd
.DscRawValue
.get(SkuName
,{}).get(DefaultStoreName
))
1801 # Use memcpy() to copy value into field
1803 CApp
= CApp
+ ' Value = %s; // From DSC Default Value %s\n' % (self
.IntToCString(Value
, ValueSize
), Pcd
.DscRawValue
.get(SkuName
,{}).get(DefaultStoreName
))
1804 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1806 if (SkuName
,DefaultStoreName
) == ('DEFAULT','STANDARD') or (( (SkuName
,'') not in Pcd
.ValueChain
) and ( (SkuName
,DefaultStoreName
) not in Pcd
.ValueChain
)):
1807 for FieldName
in FieldList
:
1808 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
][0])
1811 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], "VOID*", self
._GuidDict
)(True)
1812 except BadExpression
:
1813 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1814 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1816 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1818 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]))
1819 if isinstance(Value
, str):
1820 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1823 # Use memcpy() to copy value into field
1825 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1826 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (self
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1827 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1830 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1832 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1835 def GenerateInitValueStatement(self
,Pcd
,SkuName
,DefaultStoreName
):
1836 CApp
= ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,SkuName
,DefaultStoreName
)
1838 def GenerateCommandLineValue(self
,Pcd
):
1839 CApp
= "// Value in CommandLine\n"
1840 CApp
= CApp
+ "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
,Pcd
.DatumType
)
1841 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1842 CApp
= CApp
+ ' CHAR8 *Value;\n'
1844 pcddefaultvalue
= Pcd
.PcdValueFromComm
1845 for FieldList
in [pcddefaultvalue
,Pcd
.PcdFieldValueFromComm
]:
1848 if pcddefaultvalue
and FieldList
== pcddefaultvalue
:
1849 IsArray
= self
.IsFieldValueAnArray(FieldList
)
1852 FieldList
= ValueExpressionEx(FieldList
, "VOID*")(True)
1853 except BadExpression
:
1854 EdkLogger
.error("Build", FORMAT_INVALID
, "Invalid value format for %s.%s, from Command: %s" %
1855 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldList
))
1856 Value
, ValueSize
= ParseFieldValue (FieldList
)
1858 if isinstance(Value
, str):
1859 CApp
= CApp
+ ' Pcd = %s; // From Command Line \n' % (Value
)
1862 # Use memcpy() to copy value into field
1864 CApp
= CApp
+ ' Value = %s; // From Command Line.\n' % (self
.IntToCString(Value
, ValueSize
))
1865 CApp
= CApp
+ ' memcpy (Pcd, Value, %d);\n' % (ValueSize
)
1867 for FieldName
in FieldList
:
1868 IsArray
= self
.IsFieldValueAnArray(FieldList
[FieldName
][0])
1871 FieldList
[FieldName
][0] = ValueExpressionEx(FieldList
[FieldName
][0], "VOID*", self
._GuidDict
)(True)
1872 except BadExpression
:
1873 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid value format for %s. From %s Line %d " %
1874 (".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, FieldName
)), FieldList
[FieldName
][1], FieldList
[FieldName
][2]))
1878 Value
, ValueSize
= ParseFieldValue (FieldList
[FieldName
][0])
1880 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]))
1881 if isinstance(Value
, str):
1882 CApp
= CApp
+ ' Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1885 # Use memcpy() to copy value into field
1887 CApp
= CApp
+ ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd
.DatumType
, FieldName
)
1888 CApp
= CApp
+ ' Value = %s; // From %s Line %d Value %s\n' % (self
.IntToCString(Value
, ValueSize
), FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1889 CApp
= CApp
+ ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName
, ValueSize
, ValueSize
)
1892 CApp
= CApp
+ ' Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1894 CApp
= CApp
+ ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName
, Value
, FieldList
[FieldName
][1], FieldList
[FieldName
][2], FieldList
[FieldName
][0])
1897 def GenerateCommandLineValueStatement(self
,Pcd
):
1898 CApp
= ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1900 def GenerateInitializeFunc(self
, SkuName
, DefaultStore
, Pcd
, InitByteValue
, CApp
):
1901 OverrideValues
= {DefaultStore
:""}
1902 if Pcd
.SkuOverrideValues
:
1903 OverrideValues
= Pcd
.SkuOverrideValues
[SkuName
]
1904 for DefaultStoreName
in OverrideValues
.keys():
1905 CApp
= CApp
+ 'void\n'
1906 CApp
= CApp
+ 'Initialize_%s_%s_%s_%s(\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1907 CApp
= CApp
+ ' void\n'
1908 CApp
= CApp
+ ' )\n'
1910 CApp
= CApp
+ ' UINT32 Size;\n'
1911 CApp
= CApp
+ ' UINT32 FieldSize;\n'
1912 CApp
= CApp
+ ' CHAR8 *Value;\n'
1913 CApp
= CApp
+ ' UINT32 OriginalSize;\n'
1914 CApp
= CApp
+ ' VOID *OriginalPcd;\n'
1915 CApp
= CApp
+ ' %s *Pcd; // From %s Line %d \n' % (Pcd
.DatumType
, Pcd
.PkgPath
, Pcd
.PcdDefineLineNo
)
1918 if SkuName
in Pcd
.SkuInfoList
:
1919 DefaultValue
= Pcd
.SkuInfoList
[SkuName
].DefaultStoreDict
.get(DefaultStoreName
,Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
if Pcd
.SkuInfoList
[SkuName
].HiiDefaultValue
else Pcd
.SkuInfoList
[SkuName
].DefaultValue
)
1921 DefaultValue
= Pcd
.DefaultValue
1922 PcdDefaultValue
= StringToArray(DefaultValue
.strip())
1924 InitByteValue
+= '%s.%s.%s.%s|%s|%s\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Pcd
.DatumType
, PcdDefaultValue
)
1927 # Get current PCD value and size
1929 CApp
= CApp
+ ' OriginalPcd = PcdGetPtr (%s, %s, %s, %s, &OriginalSize);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1932 # Determine the size of the PCD. For simple structures, sizeof(TYPE) provides
1933 # the correct value. For structures with a flexible array member, the flexible
1934 # array member is detected, and the size is based on the highest index used with
1935 # the flexible array member. The flexible array member must be the last field
1936 # in a structure. The size formula for this case is:
1937 # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
1939 CApp
= CApp
+ self
.GenerateSizeStatments(Pcd
)
1942 # Allocate and zero buffer for the PCD
1943 # Must handle cases where current value is smaller, larger, or same size
1944 # Always keep that larger one as the current size
1946 CApp
= CApp
+ ' Size = (OriginalSize > Size ? OriginalSize : Size);\n'
1947 CApp
= CApp
+ ' Pcd = (%s *)malloc (Size);\n' % (Pcd
.DatumType
)
1948 CApp
= CApp
+ ' memset (Pcd, 0, Size);\n'
1951 # Copy current PCD value into allocated buffer.
1953 CApp
= CApp
+ ' memcpy (Pcd, OriginalPcd, OriginalSize);\n'
1956 # Assign field values in PCD
1958 CApp
= CApp
+ self
.GenerateDefaultValueAssignStatement(Pcd
)
1959 if Pcd
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
1960 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
1961 for skuname
in self
.SkuIdMgr
.GetSkuChain(SkuName
):
1962 storeset
= [DefaultStoreName
] if DefaultStoreName
== 'STANDARD' else ['STANDARD', DefaultStoreName
]
1963 for defaultstorenameitem
in storeset
:
1964 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: %s \n" % (skuname
, defaultstorenameitem
)
1965 CApp
= CApp
+ self
.GenerateInitValueStatement(Pcd
,skuname
,defaultstorenameitem
)
1966 if skuname
== SkuName
:
1969 CApp
= CApp
+ "// SkuName: %s, DefaultStoreName: STANDARD \n" % self
.SkuIdMgr
.SystemSkuId
1970 CApp
= CApp
+ self
.GenerateInitValueStatement(Pcd
,self
.SkuIdMgr
.SystemSkuId
,"STANDARD")
1971 CApp
= CApp
+ self
.GenerateCommandLineValueStatement(Pcd
)
1973 # Set new PCD value and size
1975 CApp
= CApp
+ ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
1980 CApp
= CApp
+ ' free (Pcd);\n'
1983 return InitByteValue
, CApp
1985 def GenerateByteArrayValue (self
, StructuredPcds
):
1987 # Generate/Compile/Run C application to determine if there are any flexible array members
1989 if not StructuredPcds
:
1993 CApp
= PcdMainCHeader
1996 for PcdName
in StructuredPcds
:
1997 Pcd
= StructuredPcds
[PcdName
]
1998 for IncludeFile
in Pcd
.StructuredPcdIncludeFile
:
1999 if IncludeFile
not in Includes
:
2000 Includes
[IncludeFile
] = True
2001 CApp
= CApp
+ '#include <%s>\n' % (IncludeFile
)
2003 for PcdName
in StructuredPcds
:
2004 Pcd
= StructuredPcds
[PcdName
]
2005 CApp
= CApp
+ self
.GenerateSizeFunction(Pcd
)
2006 CApp
= CApp
+ self
.GenerateDefaultValueAssignFunction(Pcd
)
2007 CApp
= CApp
+ self
.GenerateCommandLineValue(Pcd
)
2008 if not Pcd
.SkuOverrideValues
or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2009 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2010 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
,self
.SkuIdMgr
.SystemSkuId
, 'STANDARD')
2012 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2013 if SkuName
not in Pcd
.SkuOverrideValues
:
2015 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2016 CApp
= CApp
+ self
.GenerateInitValueFunction(Pcd
,SkuName
,DefaultStoreName
)
2017 if not Pcd
.SkuOverrideValues
or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],
2018 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2019 InitByteValue
, CApp
= self
.GenerateInitializeFunc(self
.SkuIdMgr
.SystemSkuId
, 'STANDARD', Pcd
, InitByteValue
, CApp
)
2021 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2022 if SkuName
not in Pcd
.SkuOverrideValues
:
2024 for DefaultStoreName
in Pcd
.DefaultStoreName
:
2025 Pcd
= StructuredPcds
[PcdName
]
2026 InitByteValue
, CApp
= self
.GenerateInitializeFunc(SkuName
, DefaultStoreName
, Pcd
, InitByteValue
, CApp
)
2028 CApp
= CApp
+ 'VOID\n'
2029 CApp
= CApp
+ 'PcdEntryPoint(\n'
2030 CApp
= CApp
+ ' VOID\n'
2031 CApp
= CApp
+ ' )\n'
2033 for Pcd
in StructuredPcds
.values():
2034 if not Pcd
.SkuOverrideValues
or Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
],self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2035 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (self
.SkuIdMgr
.SystemSkuId
, 'STANDARD', Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2037 for SkuName
in self
.SkuIdMgr
.SkuOverrideOrder():
2038 if SkuName
not in Pcd
.SkuOverrideValues
:
2040 for DefaultStoreName
in Pcd
.SkuOverrideValues
[SkuName
]:
2041 CApp
= CApp
+ ' Initialize_%s_%s_%s_%s();\n' % (SkuName
, DefaultStoreName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
2044 CApp
= CApp
+ PcdMainCEntry
+ '\n'
2046 if not os
.path
.exists(self
.OutputPath
):
2047 os
.makedirs(self
.OutputPath
)
2048 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2049 SaveFileOnChange(CAppBaseFileName
+ '.c', CApp
, False)
2051 MakeApp
= PcdMakefileHeader
2052 if sys
.platform
== "win32":
2053 MakeApp
= MakeApp
+ 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s\%s.obj\n' % (self
.OutputPath
, PcdValueInitName
) + 'INC = '
2055 MakeApp
= MakeApp
+ PcdGccMakefile
2056 MakeApp
= MakeApp
+ 'APPNAME = %s\n' % (PcdValueInitName
) + 'OBJECTS = %s/%s.o\n' % (self
.OutputPath
, PcdValueInitName
) + \
2057 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
2060 for Cache
in self
._Bdb
._CACHE
_.values():
2061 if Cache
.MetaFile
.Ext
.lower() != '.dec':
2064 if str(Cache
.MetaFile
.Path
) not in PlatformInc
:
2065 PlatformInc
[str(Cache
.MetaFile
.Path
)] = Cache
.CommonIncludes
2068 for Pcd
in StructuredPcds
.values():
2069 for PackageDec
in Pcd
.PackageDecs
:
2070 Package
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, PackageDec
))
2071 if not os
.path
.exists(Package
):
2072 EdkLogger
.error('Build', RESOURCE_NOT_AVAILABLE
, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
2073 if Package
not in PcdDependDEC
:
2074 PcdDependDEC
.append(Package
)
2076 if PlatformInc
and PcdDependDEC
:
2077 for pkg
in PcdDependDEC
:
2078 if pkg
in PlatformInc
:
2079 for inc
in PlatformInc
[pkg
]:
2080 MakeApp
+= '-I' + str(inc
) + ' '
2081 MakeApp
= MakeApp
+ '\n'
2083 CC_FLAGS
= LinuxCFLAGS
2084 if sys
.platform
== "win32":
2085 CC_FLAGS
= WindowsCFLAGS
2087 for Options
in self
.BuildOptions
:
2088 if Options
[2] != EDKII_NAME
:
2091 if Family
and Family
!= self
.ToolChainFamily
:
2093 Target
, Tag
, Arch
, Tool
, Attr
= Options
[1].split("_")
2097 if Target
== "*" or Target
== self
._Target
:
2098 if Tag
== "*" or Tag
== self
._Toolchain
:
2099 if Arch
== "*" or Arch
== self
.Arch
:
2100 if Tool
not in BuildOptions
:
2101 BuildOptions
[Tool
] = {}
2102 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or self
.BuildOptions
[Options
].startswith('='):
2103 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
2105 # append options for the same tool except PATH
2107 BuildOptions
[Tool
][Attr
] += " " + self
.BuildOptions
[Options
]
2109 BuildOptions
[Tool
][Attr
] = self
.BuildOptions
[Options
]
2111 for Tool
in BuildOptions
:
2112 for Attr
in BuildOptions
[Tool
]:
2114 Value
= BuildOptions
[Tool
][Attr
]
2115 ValueList
= Value
.split()
2117 for Id
, Item
in enumerate(ValueList
):
2118 if Item
== '-D' or Item
== '/D':
2119 CC_FLAGS
+= ' ' + Item
2120 if Id
+ 1 < len(ValueList
):
2121 CC_FLAGS
+= ' ' + ValueList
[Id
+ 1]
2122 elif Item
.startswith('/D') or Item
.startswith('-D'):
2123 CC_FLAGS
+= ' ' + Item
2126 if sys
.platform
== "win32":
2127 MakeApp
= MakeApp
+ PcdMakefileEnd
2128 MakeFileName
= os
.path
.join(self
.OutputPath
, 'Makefile')
2129 SaveFileOnChange(MakeFileName
, MakeApp
, False)
2131 InputValueFile
= os
.path
.join(self
.OutputPath
, 'Input.txt')
2132 OutputValueFile
= os
.path
.join(self
.OutputPath
, 'Output.txt')
2133 SaveFileOnChange(InputValueFile
, InitByteValue
, False)
2135 PcdValueInitExe
= PcdValueInitName
2136 if not sys
.platform
== "win32":
2137 PcdValueInitExe
= os
.path
.join(os
.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName
)
2139 PcdValueInitExe
= os
.path
.join(os
.getenv("EDK_TOOLS_PATH"), 'Bin', 'Win32', PcdValueInitName
) +".exe"
2140 if not os
.path
.exists(PcdValueInitExe
) or self
.NeedUpdateOutput(OutputValueFile
, CAppBaseFileName
+ '.c',MakeFileName
,InputValueFile
):
2142 if sys
.platform
== "win32":
2143 MakeCommand
= 'nmake clean & nmake -f %s' % (MakeFileName
)
2144 returncode
, StdOut
, StdErr
= self
.ExecuteCommand (MakeCommand
)
2147 MakeCommand
= 'make clean & make -f %s' % (MakeFileName
)
2148 returncode
, StdOut
, StdErr
= self
.ExecuteCommand (MakeCommand
)
2150 Messages
= Messages
.split('\n')
2153 CAppBaseFileName
= os
.path
.join(self
.OutputPath
, PcdValueInitName
)
2154 File
= open (CAppBaseFileName
+ '.c', 'r')
2155 FileData
= File
.readlines()
2157 for Message
in Messages
:
2158 if " error" in Message
or "warning" in Message
:
2159 FileInfo
= Message
.strip().split('(')
2160 if len (FileInfo
) > 1:
2161 FileName
= FileInfo
[0]
2162 FileLine
= FileInfo
[1].split (')')[0]
2164 FileInfo
= Message
.strip().split(':')
2165 FileName
= FileInfo
[0]
2166 FileLine
= FileInfo
[1]
2167 if FileLine
.isdigit():
2168 error_line
= FileData
[int (FileLine
) - 1]
2169 if r
"//" in error_line
:
2170 c_line
,dsc_line
= error_line
.split(r
"//")
2172 dsc_line
= error_line
2173 message_itmes
= Message
.split(":")
2175 if "PcdValueInit.c" not in Message
:
2176 if not MessageGroup
:
2177 MessageGroup
.append(Message
)
2180 for item
in message_itmes
:
2181 if "PcdValueInit.c" in item
:
2182 Index
= message_itmes
.index(item
)
2183 message_itmes
[Index
] = dsc_line
.strip()
2185 MessageGroup
.append(":".join(message_itmes
[Index
:]).strip())
2188 MessageGroup
.append(Message
)
2190 EdkLogger
.error("build", PCD_STRUCTURE_PCD_ERROR
, "\n".join(MessageGroup
) )
2192 EdkLogger
.error('Build', COMMAND_FAILURE
, 'Can not execute command: %s' % MakeCommand
)
2193 Command
= PcdValueInitExe
+ ' -i %s -o %s' % (InputValueFile
, OutputValueFile
)
2194 returncode
, StdOut
, StdErr
= self
.ExecuteCommand (Command
)
2196 EdkLogger
.warn('Build', COMMAND_FAILURE
, 'Can not collect output from command: %s' % Command
)
2198 File
= open (OutputValueFile
, 'r')
2199 FileBuffer
= File
.readlines()
2202 StructurePcdSet
= []
2203 for Pcd
in FileBuffer
:
2204 PcdValue
= Pcd
.split ('|')
2205 PcdInfo
= PcdValue
[0].split ('.')
2206 StructurePcdSet
.append((PcdInfo
[0],PcdInfo
[1], PcdInfo
[2], PcdInfo
[3], PcdValue
[2].strip()))
2207 return StructurePcdSet
2209 def NeedUpdateOutput(self
,OutputFile
, ValueCFile
, MakeFile
, StructureInput
):
2210 if not os
.path
.exists(OutputFile
):
2212 if os
.stat(OutputFile
).st_mtime
<= os
.stat(ValueCFile
).st_mtime
:
2214 if os
.stat(OutputFile
).st_mtime
<= os
.stat(MakeFile
).st_mtime
:
2216 if os
.stat(OutputFile
).st_mtime
<= os
.stat(StructureInput
).st_mtime
:
2220 ## Retrieve dynamic PCD settings
2222 # @param Type PCD type
2224 # @retval a dict object contains settings of given PCD type
2226 def _GetDynamicPcd(self
, Type
):
2231 # tdict is a special dict kind of type, used for selecting correct
2232 # PCD settings for certain ARCH and SKU
2234 PcdDict
= tdict(True, 4)
2236 # Find out all possible PCD candidates for self._Arch
2237 RecordList
= self
._RawData
[Type
, self
._Arch
]
2238 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2241 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
2242 SkuName
= SkuName
.upper()
2243 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
2244 if SkuName
not in AvailableSkuIdSet
:
2245 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2246 File
=self
.MetaFile
, Line
=Dummy5
)
2247 if "." not in TokenSpaceGuid
:
2248 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2249 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2251 # Remove redundant PCD candidates, per the ARCH and SKU
2252 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2254 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2258 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2259 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', '', PcdValue
)
2260 if (PcdCName
, TokenSpaceGuid
) in Pcds
.keys():
2261 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2262 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2263 if MaxDatumSize
.strip():
2264 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2267 if pcdObject
.MaxDatumSize
:
2268 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2271 if CurrentMaxSize
> PcdMaxSize
:
2272 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2274 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2277 self
._PCD
_TYPE
_STRING
_[Type
],
2282 {SkuName
: SkuInfo
},
2287 for pcd
in Pcds
.values():
2288 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2289 # Only fix the value while no value provided in DSC file.
2290 for sku
in pcd
.SkuInfoList
.values():
2291 if (sku
.DefaultValue
== "" or sku
.DefaultValue
==None):
2292 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2293 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
2294 valuefromDec
= pcdDecObject
.DefaultValue
2295 SkuInfo
= SkuInfoClass('DEFAULT', '0', '', '', '', '', '', valuefromDec
)
2296 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
2297 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2298 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
2299 del(pcd
.SkuInfoList
['COMMON'])
2300 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2301 del(pcd
.SkuInfoList
['COMMON'])
2303 map(self
.FilterSkuSettings
,Pcds
.values())
2307 def FilterSkuSettings(self
, PcdObj
):
2309 if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
:
2310 if 'DEFAULT' in PcdObj
.SkuInfoList
.keys() and self
.SkuIdMgr
.SystemSkuId
not in PcdObj
.SkuInfoList
.keys():
2311 PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
] = PcdObj
.SkuInfoList
['DEFAULT']
2312 PcdObj
.SkuInfoList
= {'DEFAULT':PcdObj
.SkuInfoList
[self
.SkuIdMgr
.SystemSkuId
]}
2313 PcdObj
.SkuInfoList
['DEFAULT'].SkuIdName
= 'DEFAULT'
2314 PcdObj
.SkuInfoList
['DEFAULT'].SkuId
= '0'
2316 elif self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.DEFAULT
:
2317 PcdObj
.SkuInfoList
= {'DEFAULT':PcdObj
.SkuInfoList
['DEFAULT']}
2322 def CompareVarAttr(self
, Attr1
, Attr2
):
2323 if not Attr1
or not Attr2
: # for empty string
2325 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
2326 Attr1Set
= set(Attr1s
)
2327 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
2328 Attr2Set
= set(Attr2s
)
2329 if Attr2Set
== Attr1Set
:
2333 def CopyDscRawValue(self
,Pcd
):
2334 if Pcd
.DscRawValue
is None:
2335 Pcd
.DscRawValue
= dict()
2336 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_FIXED_AT_BUILD
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_PATCHABLE_IN_MODULE
]]:
2337 if self
.SkuIdMgr
.SystemSkuId
not in Pcd
.DscRawValue
:
2338 Pcd
.DscRawValue
[self
.SkuIdMgr
.SystemSkuId
] = {}
2339 Pcd
.DscRawValue
[self
.SkuIdMgr
.SystemSkuId
]['STANDARD'] = Pcd
.DefaultValue
2340 for skuname
in Pcd
.SkuInfoList
:
2341 Pcd
.DscRawValue
[skuname
] = {}
2342 if Pcd
.Type
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2343 for defaultstore
in Pcd
.SkuInfoList
[skuname
].DefaultStoreDict
:
2344 Pcd
.DscRawValue
[skuname
][defaultstore
] = Pcd
.SkuInfoList
[skuname
].DefaultStoreDict
[defaultstore
]
2346 Pcd
.DscRawValue
[skuname
]['STANDARD'] = Pcd
.SkuInfoList
[skuname
].DefaultValue
2347 def CompletePcdValues(self
,PcdSet
):
2349 DefaultStoreObj
= DefaultStore(self
._GetDefaultStores
())
2350 SkuIds
= {skuname
:skuid
for skuname
,skuid
in self
.SkuIdMgr
.AvailableSkuIdSet
.items() if skuname
!='COMMON'}
2351 DefaultStores
= set([storename
for pcdobj
in PcdSet
.values() for skuobj
in pcdobj
.SkuInfoList
.values() for storename
in skuobj
.DefaultStoreDict
.keys()])
2352 for PcdCName
, TokenSpaceGuid
in PcdSet
:
2353 PcdObj
= PcdSet
[(PcdCName
, TokenSpaceGuid
)]
2354 self
.CopyDscRawValue(PcdObj
)
2355 if PcdObj
.Type
not in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_DEFAULT
],
2356 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
],
2357 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_VPD
],
2358 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_DEFAULT
],
2359 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
],
2360 self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_VPD
]]:
2361 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2363 PcdType
= PcdObj
.Type
2364 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2365 for skuid
in PcdObj
.SkuInfoList
:
2366 skuobj
= PcdObj
.SkuInfoList
[skuid
]
2367 mindefaultstorename
= DefaultStoreObj
.GetMin(set([defaultstorename
for defaultstorename
in skuobj
.DefaultStoreDict
]))
2368 for defaultstorename
in DefaultStores
:
2369 if defaultstorename
not in skuobj
.DefaultStoreDict
:
2370 skuobj
.DefaultStoreDict
[defaultstorename
] = copy
.deepcopy(skuobj
.DefaultStoreDict
[mindefaultstorename
])
2371 skuobj
.HiiDefaultValue
= skuobj
.DefaultStoreDict
[mindefaultstorename
]
2372 for skuname
,skuid
in SkuIds
.items():
2373 if skuname
not in PcdObj
.SkuInfoList
:
2374 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(skuname
)
2375 while nextskuid
not in PcdObj
.SkuInfoList
:
2376 nextskuid
= self
.SkuIdMgr
.GetNextSkuId(nextskuid
)
2377 PcdObj
.SkuInfoList
[skuname
] = copy
.deepcopy(PcdObj
.SkuInfoList
[nextskuid
])
2378 PcdObj
.SkuInfoList
[skuname
].SkuId
= skuid
2379 PcdObj
.SkuInfoList
[skuname
].SkuIdName
= skuname
2380 if PcdType
in [self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_HII
], self
._PCD
_TYPE
_STRING
_[MODEL_PCD_DYNAMIC_EX_HII
]]:
2381 PcdObj
.DefaultValue
= PcdObj
.SkuInfoList
.values()[0].HiiDefaultValue
if self
.SkuIdMgr
.SkuUsageType
== self
.SkuIdMgr
.SINGLE
else PcdObj
.SkuInfoList
["DEFAULT"].HiiDefaultValue
2382 Pcds
[PcdCName
, TokenSpaceGuid
]= PcdObj
2384 ## Retrieve dynamic HII PCD settings
2386 # @param Type PCD type
2388 # @retval a dict object contains settings of given PCD type
2390 def _GetDynamicHiiPcd(self
, Type
):
2396 # tdict is a special dict kind of type, used for selecting correct
2397 # PCD settings for certain ARCH and SKU
2399 PcdDict
= tdict(True, 5)
2401 RecordList
= self
._RawData
[Type
, self
._Arch
]
2402 # Find out all possible PCD candidates for self._Arch
2403 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2404 DefaultStoresDefine
= self
._GetDefaultStores
()
2406 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, DefaultStore
, Dummy4
,Dummy5
in RecordList
:
2407 SkuName
= SkuName
.upper()
2408 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
2409 DefaultStore
= DefaultStore
.upper()
2410 if DefaultStore
== "COMMON":
2411 DefaultStore
= "STANDARD"
2412 if SkuName
not in AvailableSkuIdSet
:
2413 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2414 File
=self
.MetaFile
, Line
=Dummy5
)
2415 if DefaultStore
not in DefaultStoresDefine
:
2416 EdkLogger
.error('build', PARAMETER_INVALID
, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore
,
2417 File
=self
.MetaFile
, Line
=Dummy5
)
2418 if "." not in TokenSpaceGuid
:
2419 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
,DefaultStore
, Dummy5
))
2420 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
,DefaultStore
] = Setting
2423 # Remove redundant PCD candidates, per the ARCH and SKU
2424 for PcdCName
, TokenSpaceGuid
, SkuName
,DefaultStore
, Dummy4
in PcdSet
:
2426 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
,DefaultStore
]
2429 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2431 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
2433 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
2434 ExtraData
="[%s]" % VarAttribute
)
2436 FormatCorrect
= True
2437 if VariableOffset
.isdigit():
2438 if int(VariableOffset
, 10) > 0xFFFF:
2440 elif re
.match(r
'[\t\s]*0[xX][a-fA-F0-9]+$', VariableOffset
):
2441 if int(VariableOffset
, 16) > 0xFFFF:
2443 # For Offset written in "A.B"
2444 elif VariableOffset
.find('.') > -1:
2445 VariableOffsetList
= VariableOffset
.split(".")
2446 if not (len(VariableOffsetList
) == 2
2447 and IsValidWord(VariableOffsetList
[0])
2448 and IsValidWord(VariableOffsetList
[1])):
2449 FormatCorrect
= False
2451 FormatCorrect
= False
2452 if not FormatCorrect
:
2453 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2456 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
, PcdCName
)))
2457 if (VariableName
, VariableGuid
) not in VariableAttrs
:
2458 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
2460 if not self
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
2461 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
)]))
2463 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
2464 if (PcdCName
, TokenSpaceGuid
) in Pcds
.keys():
2465 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2466 if SkuName
in pcdObject
.SkuInfoList
:
2467 Skuitem
= pcdObject
.SkuInfoList
[SkuName
]
2468 Skuitem
.DefaultStoreDict
.update({DefaultStore
:DefaultValue
})
2470 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
,DefaultStore
={DefaultStore
:DefaultValue
})
2471 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2473 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
=VarAttribute
,DefaultStore
={DefaultStore
:DefaultValue
})
2474 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2477 self
._PCD
_TYPE
_STRING
_[Type
],
2482 {SkuName
: SkuInfo
},
2485 pcdDecObject
.validateranges
,
2486 pcdDecObject
.validlists
,
2487 pcdDecObject
.expressions
,
2491 for pcd
in Pcds
.values():
2492 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2493 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2494 pcd
.DatumType
= pcdDecObject
.DatumType
2495 # Only fix the value while no value provided in DSC file.
2496 for sku
in pcd
.SkuInfoList
.values():
2497 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
== None):
2498 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
2499 for default_store
in sku
.DefaultStoreDict
:
2500 sku
.DefaultStoreDict
[default_store
]=pcdDecObject
.DefaultValue
2501 pcd
.DefaultValue
= pcdDecObject
.DefaultValue
2502 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
2503 valuefromDec
= pcdDecObject
.DefaultValue
2504 SkuInfo
= SkuInfoClass('DEFAULT', '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
,VariableAttribute
=SkuInfoObj
.VariableAttribute
,DefaultStore
={DefaultStore
:valuefromDec
})
2505 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
2506 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2507 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
2508 del(pcd
.SkuInfoList
['COMMON'])
2509 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2510 del(pcd
.SkuInfoList
['COMMON'])
2512 if pcd
.MaxDatumSize
.strip():
2513 MaxSize
= int(pcd
.MaxDatumSize
, 0)
2516 if pcd
.DatumType
not in ['BOOLEAN','UINT8','UINT16','UINT32','UINT64']:
2517 for (_
, skuobj
) in pcd
.SkuInfoList
.items():
2519 skuobj
.HiiDefaultValue
= StringToArray(skuobj
.HiiDefaultValue
)
2520 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
2521 if datalen
> MaxSize
:
2523 for defaultst
in skuobj
.DefaultStoreDict
:
2524 skuobj
.DefaultStoreDict
[defaultst
] = StringToArray(skuobj
.DefaultStoreDict
[defaultst
])
2525 pcd
.DefaultValue
= StringToArray(pcd
.DefaultValue
)
2526 pcd
.MaxDatumSize
= str(MaxSize
)
2527 rt
, invalidhii
= self
.CheckVariableNameAssignment(Pcds
)
2529 invalidpcd
= ",".join(invalidhii
)
2530 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
)
2532 map(self
.FilterSkuSettings
,Pcds
.values())
2536 def CheckVariableNameAssignment(self
,Pcds
):
2538 for pcdname
in Pcds
:
2540 varnameset
= set([sku
.VariableName
for (skuid
,sku
) in pcd
.SkuInfoList
.items()])
2541 if len(varnameset
) > 1:
2542 invalidhii
.append(".".join((pcdname
[1],pcdname
[0])))
2544 return False,invalidhii
2547 ## Retrieve dynamic VPD PCD settings
2549 # @param Type PCD type
2551 # @retval a dict object contains settings of given PCD type
2553 def _GetDynamicVpdPcd(self
, Type
):
2558 # tdict is a special dict kind of type, used for selecting correct
2559 # PCD settings for certain ARCH and SKU
2561 PcdDict
= tdict(True, 4)
2564 # Find out all possible PCD candidates for self._Arch
2565 RecordList
= self
._RawData
[Type
, self
._Arch
]
2566 AvailableSkuIdSet
= copy
.copy(self
.SkuIds
)
2568 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
,Dummy5
in RecordList
:
2569 SkuName
= SkuName
.upper()
2570 SkuName
= 'DEFAULT' if SkuName
== 'COMMON' else SkuName
2571 if SkuName
not in AvailableSkuIdSet
:
2572 EdkLogger
.error('build', PARAMETER_INVALID
, 'Sku %s is not defined in [SkuIds] section' % SkuName
,
2573 File
=self
.MetaFile
, Line
=Dummy5
)
2574 if "." not in TokenSpaceGuid
:
2575 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
, Dummy5
))
2576 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
2578 # Remove redundant PCD candidates, per the ARCH and SKU
2579 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
2580 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
2584 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
2585 # For the Integer & Boolean type, the optional data can only be InitialValue.
2586 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
2587 # until the DEC parser has been called.
2589 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
2590 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
][0], '', '', '', '', VpdOffset
, InitialValue
)
2591 if (PcdCName
, TokenSpaceGuid
) in Pcds
.keys():
2592 pcdObject
= Pcds
[PcdCName
, TokenSpaceGuid
]
2593 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
2594 if MaxDatumSize
.strip():
2595 CurrentMaxSize
= int(MaxDatumSize
.strip(), 0)
2598 if pcdObject
.MaxDatumSize
:
2599 PcdMaxSize
= int(pcdObject
.MaxDatumSize
, 0)
2602 if CurrentMaxSize
> PcdMaxSize
:
2603 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
2605 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
2608 self
._PCD
_TYPE
_STRING
_[Type
],
2613 {SkuName
: SkuInfo
},
2617 for pcd
in Pcds
.values():
2618 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
2619 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
, pcd
.TokenSpaceGuidCName
]
2620 pcd
.DatumType
= pcdDecObject
.DatumType
2621 # Only fix the value while no value provided in DSC file.
2622 for sku
in pcd
.SkuInfoList
.values():
2623 if (sku
.DefaultValue
== "" or sku
.DefaultValue
==None):
2624 sku
.DefaultValue
= pcdDecObject
.DefaultValue
2625 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
2626 valuefromDec
= pcdDecObject
.DefaultValue
2627 SkuInfo
= SkuInfoClass('DEFAULT', '0', '', '', '', '', SkuInfoObj
.VpdOffset
, valuefromDec
)
2628 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
2629 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2630 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
2631 del(pcd
.SkuInfoList
['COMMON'])
2632 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
2633 del(pcd
.SkuInfoList
['COMMON'])
2636 map(self
.FilterSkuSettings
,Pcds
.values())
2639 ## Add external modules
2641 # The external modules are mostly those listed in FDF file, which don't
2644 # @param FilePath The path of module description file
2646 def AddModule(self
, FilePath
):
2647 FilePath
= NormPath(FilePath
)
2648 if FilePath
not in self
.Modules
:
2649 Module
= ModuleBuildClassObject()
2650 Module
.MetaFile
= FilePath
2651 self
.Modules
.append(Module
)
2653 def _GetToolChainFamily(self
):
2654 self
._ToolChainFamily
= "MSFT"
2655 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, "target.txt"))
2656 if os
.path
.isfile(BuildConfigurationFile
) == True:
2657 TargetTxt
= TargetTxtClassObject()
2658 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
2659 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
2660 if ToolDefinitionFile
== '':
2661 ToolDefinitionFile
= "tools_def.txt"
2662 ToolDefinitionFile
= os
.path
.normpath(mws
.join(self
.WorkspaceDir
, 'Conf', ToolDefinitionFile
))
2663 if os
.path
.isfile(ToolDefinitionFile
) == True:
2664 ToolDef
= ToolDefClassObject()
2665 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
2666 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
2667 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
2668 or self
._Toolchain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
2669 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]:
2670 self
._ToolChainFamily
= "MSFT"
2672 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
._Toolchain
]
2673 return self
._ToolChainFamily
2675 ## Add external PCDs
2677 # The external PCDs are mostly those listed in FDF file to specify address
2678 # or offset information.
2680 # @param Name Name of the PCD
2681 # @param Guid Token space guid of the PCD
2682 # @param Value Value of the PCD
2684 def AddPcd(self
, Name
, Guid
, Value
):
2685 if (Name
, Guid
) not in self
.Pcds
:
2686 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
2687 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
2690 if self
._DecPcds
== None:
2692 if GlobalData
.gFdfParser
:
2693 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
2695 for Inf
in FdfInfList
:
2696 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
2697 if ModuleFile
in self
._Modules
:
2699 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
2700 PkgSet
.update(ModuleData
.Packages
)
2701 self
._DecPcds
, self
._GuidDict
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
,PkgSet
)
2702 return self
._DecPcds
2703 _Macros
= property(_GetMacros
)
2704 Arch
= property(_GetArch
, _SetArch
)
2705 Platform
= property(_GetPlatformName
)
2706 PlatformName
= property(_GetPlatformName
)
2707 Guid
= property(_GetFileGuid
)
2708 Version
= property(_GetVersion
)
2709 DscSpecification
= property(_GetDscSpec
)
2710 OutputDirectory
= property(_GetOutpuDir
)
2711 SupArchList
= property(_GetSupArch
)
2712 BuildTargets
= property(_GetBuildTarget
)
2713 SkuName
= property(_GetSkuName
, _SetSkuName
)
2714 PcdInfoFlag
= property(_GetPcdInfoFlag
)
2715 VarCheckFlag
= property(_GetVarCheckFlag
)
2716 FlashDefinition
= property(_GetFdfFile
)
2717 Prebuild
= property(_GetPrebuild
)
2718 Postbuild
= property(_GetPostbuild
)
2719 BuildNumber
= property(_GetBuildNumber
)
2720 MakefileName
= property(_GetMakefileName
)
2721 BsBaseAddress
= property(_GetBsBaseAddress
)
2722 RtBaseAddress
= property(_GetRtBaseAddress
)
2723 LoadFixAddress
= property(_GetLoadFixAddress
)
2724 RFCLanguages
= property(_GetRFCLanguages
)
2725 ISOLanguages
= property(_GetISOLanguages
)
2726 VpdToolGuid
= property(_GetVpdToolGuid
)
2727 SkuIds
= property(_GetSkuIds
)
2728 Modules
= property(_GetModules
)
2729 LibraryInstances
= property(_GetLibraryInstances
)
2730 LibraryClasses
= property(_GetLibraryClasses
)
2731 Pcds
= property(_GetPcds
)
2732 BuildOptions
= property(_GetBuildOptions
)
2733 ToolChainFamily
= property(_GetToolChainFamily
)