mirror of https://github.com/acidanthera/audk.git
BaseTools: add new command line option to support override PCD value
this patch add new feature to support override PCD value on the command line. The value from the command line is the highest priority. 1.Add option(--pcd) to support both PcdName and TokenSpaceGuild.PcdName 2.For void* type PCD, use following format: cstring PCD: --pcd PcdName="string" unicodestring PCD: --pcd PcdName=L"string" CArray PCD: --pcd PcdName=B"{0x1, 0x2}" 3.Build Report, use *B to show the PCD value was overridden in the command line. 4.Error Condition: Report error if the PCD is not found Report error if the PcdName is found under multiple different TokenSpaceGuid Report error if PCD value syntax is incorrect Report error if void* type PCD value exceed its max size Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
db27e9f3d8
commit
763e8edf61
|
@ -350,6 +350,67 @@ class WorkspaceAutoGen(AutoGen):
|
|||
DecPcds = {}
|
||||
DecPcdsKey = set()
|
||||
PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)
|
||||
if GlobalData.BuildOptionPcd:
|
||||
for i, pcd in enumerate(GlobalData.BuildOptionPcd):
|
||||
(pcdname, pcdvalue) = pcd.split('=')
|
||||
if not pcdvalue:
|
||||
EdkLogger.error('build', AUTOGEN_ERROR, "No Value specified for the PCD %s." % (pcdname))
|
||||
if '.' in pcdname:
|
||||
(TokenSpaceGuidCName, TokenCName) = pcdname.split('.')
|
||||
HasTokenSpace = True
|
||||
else:
|
||||
TokenCName = pcdname
|
||||
TokenSpaceGuidCName = ''
|
||||
HasTokenSpace = False
|
||||
TokenSpaceGuidCNameList = []
|
||||
FoundFlag = False
|
||||
PcdDatumType = ''
|
||||
NewValue = ''
|
||||
for package in PGen.PackageList:
|
||||
for key in package.Pcds:
|
||||
PcdItem = package.Pcds[key]
|
||||
if HasTokenSpace:
|
||||
if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):
|
||||
PcdDatumType = PcdItem.DatumType
|
||||
NewValue = self._BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
|
||||
FoundFlag = True
|
||||
else:
|
||||
if PcdItem.TokenCName == TokenCName:
|
||||
if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:
|
||||
if len (TokenSpaceGuidCNameList) < 1:
|
||||
TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)
|
||||
PcdDatumType = PcdItem.DatumType
|
||||
TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName
|
||||
NewValue = self._BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
|
||||
FoundFlag = True
|
||||
else:
|
||||
EdkLogger.error(
|
||||
'build',
|
||||
AUTOGEN_ERROR,
|
||||
"The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])
|
||||
)
|
||||
|
||||
GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)
|
||||
|
||||
if not FoundFlag:
|
||||
if HasTokenSpace:
|
||||
EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, TokenCName))
|
||||
else:
|
||||
EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (TokenCName))
|
||||
|
||||
for BuildData in PGen.BuildDatabase._CACHE_.values():
|
||||
if BuildData.Arch != Arch:
|
||||
continue
|
||||
if BuildData.MetaFile.Ext == '.dec':
|
||||
continue
|
||||
for key in BuildData.Pcds:
|
||||
PcdItem = BuildData.Pcds[key]
|
||||
if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName):
|
||||
PcdItem.DefaultValue = NewValue
|
||||
|
||||
if (TokenCName, TokenSpaceGuidCName) in PcdSet:
|
||||
PcdSet[(TokenCName, TokenSpaceGuidCName)] = NewValue
|
||||
|
||||
#Collect package set information from INF of FDF
|
||||
PkgSet = set()
|
||||
for Inf in ModuleList:
|
||||
|
@ -418,6 +479,32 @@ class WorkspaceAutoGen(AutoGen):
|
|||
|
||||
return True
|
||||
|
||||
def _BuildOptionPcdValueFormat(self, TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):
|
||||
if PcdDatumType == 'VOID*':
|
||||
if Value.startswith('L'):
|
||||
if not Value[1]:
|
||||
EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
|
||||
Value = Value[0] + '"' + Value[1:] + '"'
|
||||
elif Value.startswith('B'):
|
||||
if not Value[1]:
|
||||
EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
|
||||
Value = Value[1:]
|
||||
else:
|
||||
if not Value[0]:
|
||||
EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
|
||||
Value = '"' + Value + '"'
|
||||
|
||||
IsValid, Cause = CheckPcdDatum(PcdDatumType, Value)
|
||||
if not IsValid:
|
||||
EdkLogger.error('build', FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))
|
||||
if PcdDatumType == 'BOOLEAN':
|
||||
Value = Value.upper()
|
||||
if Value == 'TRUE' or Value == '1':
|
||||
Value = '1'
|
||||
elif Value == 'FALSE' or Value == '0':
|
||||
Value = '0'
|
||||
return Value
|
||||
|
||||
## _CheckDuplicateInFV() method
|
||||
#
|
||||
# Check whether there is duplicate modules/files exist in FV section.
|
||||
|
@ -953,6 +1040,18 @@ class PlatformAutoGen(AutoGen):
|
|||
# This interface should be invoked explicitly when platform action is created.
|
||||
#
|
||||
def CollectPlatformDynamicPcds(self):
|
||||
# Override the platform Pcd's value by build option
|
||||
if GlobalData.BuildOptionPcd:
|
||||
for key in self.Platform.Pcds:
|
||||
PlatformPcd = self.Platform.Pcds[key]
|
||||
for PcdItem in GlobalData.BuildOptionPcd:
|
||||
if (PlatformPcd.TokenSpaceGuidCName, PlatformPcd.TokenCName) == (PcdItem[0], PcdItem[1]):
|
||||
PlatformPcd.DefaultValue = PcdItem[2]
|
||||
if PlatformPcd.SkuInfoList:
|
||||
Sku = PlatformPcd.SkuInfoList[PlatformPcd.SkuInfoList.keys()[0]]
|
||||
Sku.DefaultValue = PcdItem[2]
|
||||
break
|
||||
|
||||
# for gathering error information
|
||||
NoDatumTypePcdList = set()
|
||||
PcdNotInDb = []
|
||||
|
|
|
@ -766,6 +766,13 @@ def GetPcdSize(Pcd):
|
|||
def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
|
||||
TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]
|
||||
PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber
|
||||
|
||||
if GlobalData.BuildOptionPcd:
|
||||
for PcdItem in GlobalData.BuildOptionPcd:
|
||||
if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):
|
||||
Pcd.DefaultValue = PcdItem[2]
|
||||
break
|
||||
|
||||
#
|
||||
# Write PCDs
|
||||
#
|
||||
|
@ -1054,7 +1061,13 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
|
|||
FixPcdSizeTokenName = '_PCD_SIZE_' + Pcd.TokenCName
|
||||
PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + Pcd.TokenCName +'_SIZE'
|
||||
PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + Pcd.TokenCName
|
||||
|
||||
|
||||
if GlobalData.BuildOptionPcd:
|
||||
for PcdItem in GlobalData.BuildOptionPcd:
|
||||
if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):
|
||||
Pcd.DefaultValue = PcdItem[2]
|
||||
break
|
||||
|
||||
#
|
||||
# Write PCDs
|
||||
#
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
## @file
|
||||
# Routines for generating Pcd Database
|
||||
#
|
||||
# Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -1141,6 +1141,12 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
|
|||
CName = Pcd.TokenCName
|
||||
TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName
|
||||
|
||||
if GlobalData.BuildOptionPcd:
|
||||
for PcdItem in GlobalData.BuildOptionPcd:
|
||||
if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):
|
||||
Pcd.DefaultValue = PcdItem[2]
|
||||
break
|
||||
|
||||
EdkLogger.debug(EdkLogger.DEBUG_3, "PCD: %s %s (%s : %s)" % (CName, TokenSpaceGuidCName, Pcd.Phase, Phase))
|
||||
|
||||
if Pcd.Phase == 'PEI':
|
||||
|
@ -1455,6 +1461,11 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
|
|||
TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName
|
||||
if Pcd.Phase != Phase:
|
||||
continue
|
||||
if GlobalData.BuildOptionPcd:
|
||||
for PcdItem in GlobalData.BuildOptionPcd:
|
||||
if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):
|
||||
Pcd.DefaultValue = PcdItem[2]
|
||||
break
|
||||
|
||||
TokenSpaceGuid = GuidStructureStringToGuidValueName(Pcd.TokenSpaceGuidValue) #(Platform.PackageList, TokenSpaceGuidCName))
|
||||
GeneratedTokenNumber = Platform.PcdTokenNumber[CName, TokenSpaceGuidCName] - 1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
## @file
|
||||
# This file is used to define common static strings used by INF/DEC/DSC files
|
||||
#
|
||||
# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -77,3 +77,4 @@ gFdfParser = None
|
|||
#
|
||||
gTempInfs = []
|
||||
|
||||
BuildOptionPcd = []
|
||||
|
|
|
@ -42,6 +42,7 @@ from Common.DataType import TAB_BRG_LIBRARY
|
|||
from Common.DataType import TAB_BACK_SLASH
|
||||
from Common.LongFilePathSupport import OpenLongFilePath as open
|
||||
from Common.MultipleWorkspace import MultipleWorkspace as mws
|
||||
import Common.GlobalData as GlobalData
|
||||
|
||||
## Pattern to extract contents in EDK DXS files
|
||||
gDxsDependencyPattern = re.compile(r"DEPENDENCY_START(.+)DEPENDENCY_END", re.DOTALL)
|
||||
|
@ -727,6 +728,7 @@ class PcdReport(object):
|
|||
#
|
||||
FileWrite(File, gSectionStart)
|
||||
FileWrite(File, "Platform Configuration Database Report")
|
||||
FileWrite(File, " *B - PCD override in the build option")
|
||||
FileWrite(File, " *P - Platform scoped PCD override in DSC file")
|
||||
FileWrite(File, " *F - Platform scoped PCD override in FDF file")
|
||||
FileWrite(File, " *M - Module scoped PCD override")
|
||||
|
@ -767,6 +769,15 @@ class PcdReport(object):
|
|||
InfDefault, PcdValue = ModulePcdSet[Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Type]
|
||||
if InfDefault == "":
|
||||
InfDefault = None
|
||||
|
||||
BuildOptionMatch = False
|
||||
if GlobalData.BuildOptionPcd:
|
||||
for pcd in GlobalData.BuildOptionPcd:
|
||||
if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (pcd[0], pcd[1]):
|
||||
PcdValue = pcd[2]
|
||||
BuildOptionMatch = True
|
||||
break
|
||||
|
||||
if First:
|
||||
if ModulePcdSet == None:
|
||||
FileWrite(File, "")
|
||||
|
@ -812,7 +823,9 @@ class PcdReport(object):
|
|||
#
|
||||
# Report PCD item according to their override relationship
|
||||
#
|
||||
if DecMatch and InfMatch:
|
||||
if BuildOptionMatch:
|
||||
FileWrite(File, ' *B %-*s: %6s %10s = %-22s' % (self.MaxLen, Pcd.TokenCName, TypeName, '(' + Pcd.DatumType + ')', PcdValue.strip()))
|
||||
elif DecMatch and InfMatch:
|
||||
FileWrite(File, ' %-*s: %6s %10s = %-22s' % (self.MaxLen, Pcd.TokenCName, TypeName, '(' + Pcd.DatumType + ')', PcdValue.strip()))
|
||||
else:
|
||||
if DscMatch:
|
||||
|
@ -840,17 +853,18 @@ class PcdReport(object):
|
|||
FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'DEC DEFAULT', DecDefaultValue.strip()))
|
||||
|
||||
if ModulePcdSet == None:
|
||||
ModuleOverride = self.ModulePcdOverride.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName), {})
|
||||
for ModulePath in ModuleOverride:
|
||||
ModuleDefault = ModuleOverride[ModulePath]
|
||||
if Pcd.DatumType in ('UINT8', 'UINT16', 'UINT32', 'UINT64'):
|
||||
ModulePcdDefaultValueNumber = int(ModuleDefault.strip(), 0)
|
||||
Match = (ModulePcdDefaultValueNumber == PcdValueNumber)
|
||||
else:
|
||||
Match = (ModuleDefault.strip() == PcdValue.strip())
|
||||
if Match:
|
||||
continue
|
||||
FileWrite(File, ' *M %-*s = %s' % (self.MaxLen + 19, ModulePath, ModuleDefault.strip()))
|
||||
if not BuildOptionMatch:
|
||||
ModuleOverride = self.ModulePcdOverride.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName), {})
|
||||
for ModulePath in ModuleOverride:
|
||||
ModuleDefault = ModuleOverride[ModulePath]
|
||||
if Pcd.DatumType in ('UINT8', 'UINT16', 'UINT32', 'UINT64'):
|
||||
ModulePcdDefaultValueNumber = int(ModuleDefault.strip(), 0)
|
||||
Match = (ModulePcdDefaultValueNumber == PcdValueNumber)
|
||||
else:
|
||||
Match = (ModuleDefault.strip() == PcdValue.strip())
|
||||
if Match:
|
||||
continue
|
||||
FileWrite(File, ' *M %-*s = %s' % (self.MaxLen + 19, ModulePath, ModuleDefault.strip()))
|
||||
|
||||
if ModulePcdSet == None:
|
||||
FileWrite(File, gSectionEnd)
|
||||
|
|
|
@ -53,7 +53,7 @@ import Common.GlobalData as GlobalData
|
|||
# Version and Copyright
|
||||
VersionNumber = "0.60" + ' ' + gBUILD_VERSION
|
||||
__version__ = "%prog Version " + VersionNumber
|
||||
__copyright__ = "Copyright (c) 2007 - 2014, Intel Corporation All rights reserved."
|
||||
__copyright__ = "Copyright (c) 2007 - 2016, Intel Corporation All rights reserved."
|
||||
|
||||
## standard targets of build command
|
||||
gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run']
|
||||
|
@ -747,6 +747,7 @@ class Build():
|
|||
self.BuildReport = BuildReport(BuildOptions.ReportFile, BuildOptions.ReportType)
|
||||
self.TargetTxt = TargetTxtClassObject()
|
||||
self.ToolDef = ToolDefClassObject()
|
||||
GlobalData.BuildOptionPcd = BuildOptions.OptionPcd
|
||||
#Set global flag for build mode
|
||||
GlobalData.gIgnoreSource = BuildOptions.IgnoreSources
|
||||
|
||||
|
@ -1929,6 +1930,7 @@ def MyOptionParser():
|
|||
Parser.add_option("--conf", action="store", type="string", dest="ConfDirectory", help="Specify the customized Conf directory.")
|
||||
Parser.add_option("--check-usage", action="store_true", dest="CheckUsage", default=False, help="Check usage content of entries listed in INF file.")
|
||||
Parser.add_option("--ignore-sources", action="store_true", dest="IgnoreSources", default=False, help="Focus to a binary build and ignore all source files")
|
||||
Parser.add_option("--pcd", action="append", dest="OptionPcd", help="Set PCD value by command line. Format: 'PcdName=Value' ")
|
||||
|
||||
(Opt, Args) = Parser.parse_args()
|
||||
return (Opt, Args)
|
||||
|
|
Loading…
Reference in New Issue