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