BaseTools: Correct the value assignment for StructurePcd

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1752

This patch is to fix the code bug in StructurePcd overall
value assignment logic. If a Pcd Array size is fixed but the
size of actual value in Dsc or Dec is bigger than the Pcd
array size, the tool will report error about such setting and
stop build.

The patch is tested minplatform, Ovmf, structure pcd regression test
These tests are build pass. The patch also tested the following cases.
Our cases focused on PcdArraySize. 1.flexiable PcdArraySize.
 2.Fixed PcdArraySize, Pcd overall value exceeds the size of PcdArray.
 3.Fixed PcdArraySize, Pcd overall value Not exceeds the size of PcdArray.

Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Fan, ZhijuX 2019-05-09 17:19:56 +08:00 committed by Feng, Bob C
parent 70023bab7e
commit afe8c4110c
4 changed files with 219 additions and 75 deletions

View File

@ -37,6 +37,7 @@ from Common.MultipleWorkspace import MultipleWorkspace as mws
from CommonDataClass.Exceptions import BadExpression from CommonDataClass.Exceptions import BadExpression
from Common.caching import cached_property from Common.caching import cached_property
ArrayIndex = re.compile("\[\s*[0-9a-fA-FxX]*\s*\]")
## Regular expression used to find out place holders in string template ## Regular expression used to find out place holders in string template
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE) gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)

View File

@ -10,10 +10,12 @@ from Common.DataType import *
import collections import collections
import re import re
from collections import OrderedDict from collections import OrderedDict
from Common.Misc import CopyDict from Common.Misc import CopyDict,ArrayIndex
import copy import copy
import Common.EdkLogger as EdkLogger
from Common.BuildToolError import OPTION_VALUE_INVALID
StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_\[\]]*$') StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_\[\]]*$')
ArrayIndex = re.compile("\[\s*[0-9a-fA-FxX]*\s*\]")
## PcdClassObject ## PcdClassObject
# #
# This Class is used for PcdObject # This Class is used for PcdObject
@ -62,6 +64,7 @@ class PcdClassObject(object):
self.expressions = expressions if expressions is not None else [] self.expressions = expressions if expressions is not None else []
self.DscDefaultValue = None self.DscDefaultValue = None
self.DscRawValue = {} self.DscRawValue = {}
self.DscRawValueInfo = {}
if IsDsc: if IsDsc:
self.DscDefaultValue = Value self.DscDefaultValue = Value
self.PcdValueFromComm = "" self.PcdValueFromComm = ""
@ -72,30 +75,47 @@ class PcdClassObject(object):
@property @property
def Capacity(self): def Capacity(self):
self._Capacity = [] if self._Capacity is None:
dimension = ArrayIndex.findall(self._DatumType) self._Capacity = []
for item in dimension: dimension = ArrayIndex.findall(self._DatumType)
maxsize = item.lstrip("[").rstrip("]").strip() for item in dimension:
if not maxsize: maxsize = item.lstrip("[").rstrip("]").strip()
maxsize = "-1" if not maxsize:
maxsize = str(int(maxsize,16)) if maxsize.startswith(("0x","0X")) else maxsize maxsize = "-1"
self._Capacity.append(maxsize) maxsize = str(int(maxsize,16)) if maxsize.startswith(("0x","0X")) else maxsize
if hasattr(self, "SkuOverrideValues"): self._Capacity.append(maxsize)
for sku in self.SkuOverrideValues: if hasattr(self, "SkuOverrideValues"):
for defaultstore in self.SkuOverrideValues[sku]: for sku in self.SkuOverrideValues:
fields = self.SkuOverrideValues[sku][defaultstore] for defaultstore in self.SkuOverrideValues[sku]:
for demesionattr in fields: fields = self.SkuOverrideValues[sku][defaultstore]
deme = ArrayIndex.findall(demesionattr) for demesionattr in fields:
for i in range(len(deme)-1): fieldinfo = fields[demesionattr]
if int(deme[i].lstrip("[").rstrip("]").strip()) > int(self._Capacity[i]): deme = ArrayIndex.findall(demesionattr)
print ("error") for i in range(len(deme)):
if hasattr(self,"DefaultValues"): if int(deme[i].lstrip("[").rstrip("]").strip()) >= int(self._Capacity[i]):
for demesionattr in self.DefaultValues: if self._Capacity[i] != "-1":
deme = ArrayIndex.findall(demesionattr) firstfieldinfo = list(fieldinfo.values())[0]
for i in range(len(deme)-1): EdkLogger.error('Build', OPTION_VALUE_INVALID, "For Pcd %s, Array Index exceed the Array size. From %s Line %s \n " %
if int(deme[i].lstrip("[").rstrip("]").strip()) > int(self._Capacity[i]): (".".join((self.TokenSpaceGuidCName, self.TokenCName)), firstfieldinfo[1],firstfieldinfo[2] ))
print ("error") if hasattr(self,"DefaultValues"):
for demesionattr in self.DefaultValues:
fieldinfo = self.DefaultValues[demesionattr]
deme = ArrayIndex.findall(demesionattr)
for i in range(len(deme)):
if int(deme[i].lstrip("[").rstrip("]").strip()) >= int(self._Capacity[i]):
if self._Capacity[i] != "-1":
firstfieldinfo = list(fieldinfo.values())[0]
EdkLogger.error('Build', OPTION_VALUE_INVALID, "For Pcd %s, Array Index exceed the Array size. From %s Line %s \n " %
(".".join((self.TokenSpaceGuidCName, self.TokenCName)), firstfieldinfo[1],firstfieldinfo[2] ))
return self._Capacity return self._Capacity
def PcdArraySize(self):
if self.Capacity[-1] == "-1":
return -1
size = 1
for de in self.Capacity:
size = size * int(de)
return size
@property @property
def DatumType(self): def DatumType(self):
return self._DatumType return self._DatumType
@ -227,6 +247,7 @@ class PcdClassObject(object):
new_pcd.PcdValueFromFdf = self.PcdValueFromFdf new_pcd.PcdValueFromFdf = self.PcdValueFromFdf
new_pcd.UserDefinedDefaultStoresFlag = self.UserDefinedDefaultStoresFlag new_pcd.UserDefinedDefaultStoresFlag = self.UserDefinedDefaultStoresFlag
new_pcd.DscRawValue = self.DscRawValue new_pcd.DscRawValue = self.DscRawValue
new_pcd.DscRawValueInfo = self.DscRawValueInfo
new_pcd.CustomAttribute = self.CustomAttribute new_pcd.CustomAttribute = self.CustomAttribute
new_pcd.validateranges = [item for item in self.validateranges] new_pcd.validateranges = [item for item in self.validateranges]
new_pcd.validlists = [item for item in self.validlists] new_pcd.validlists = [item for item in self.validlists]
@ -262,6 +283,7 @@ class StructurePcd(PcdClassObject):
self.PcdDefineLineNo = 0 self.PcdDefineLineNo = 0
self.PkgPath = "" self.PkgPath = ""
self.DefaultValueFromDec = "" self.DefaultValueFromDec = ""
self.DefaultValueFromDecInfo = None
self.ValueChain = set() self.ValueChain = set()
self.PcdFieldValueFromComm = OrderedDict() self.PcdFieldValueFromComm = OrderedDict()
self.PcdFieldValueFromFdf = OrderedDict() self.PcdFieldValueFromFdf = OrderedDict()
@ -277,8 +299,9 @@ class StructurePcd(PcdClassObject):
self.DefaultValues[DimensionAttr][FieldName] = [Value.strip(), FileName, LineNo] self.DefaultValues[DimensionAttr][FieldName] = [Value.strip(), FileName, LineNo]
return self.DefaultValues[DimensionAttr][FieldName] return self.DefaultValues[DimensionAttr][FieldName]
def SetDecDefaultValue(self, DefaultValue): def SetDecDefaultValue(self, DefaultValue,decpath=None,lineno=None):
self.DefaultValueFromDec = DefaultValue self.DefaultValueFromDec = DefaultValue
self.DefaultValueFromDecInfo = (decpath,lineno)
def AddOverrideValue (self, FieldName, Value, SkuName, DefaultStoreName, FileName="", LineNo=0, DimensionAttr = '-1'): def AddOverrideValue (self, FieldName, Value, SkuName, DefaultStoreName, FileName="", LineNo=0, DimensionAttr = '-1'):
if SkuName not in self.SkuOverrideValues: if SkuName not in self.SkuOverrideValues:
self.SkuOverrideValues[SkuName] = OrderedDict() self.SkuOverrideValues[SkuName] = OrderedDict()
@ -313,6 +336,7 @@ class StructurePcd(PcdClassObject):
self.validlists = PcdObject.validlists if PcdObject.validlists else self.validlists self.validlists = PcdObject.validlists if PcdObject.validlists else self.validlists
self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions
self.DscRawValue = PcdObject.DscRawValue if PcdObject.DscRawValue else self.DscRawValue self.DscRawValue = PcdObject.DscRawValue if PcdObject.DscRawValue else self.DscRawValue
self.DscRawValueInfo = PcdObject.DscRawValueInfo if PcdObject.DscRawValueInfo else self.DscRawValueInfo
self.PcdValueFromComm = PcdObject.PcdValueFromComm if PcdObject.PcdValueFromComm else self.PcdValueFromComm self.PcdValueFromComm = PcdObject.PcdValueFromComm if PcdObject.PcdValueFromComm else self.PcdValueFromComm
self.PcdValueFromFdf = PcdObject.PcdValueFromFdf if PcdObject.PcdValueFromFdf else self.PcdValueFromFdf self.PcdValueFromFdf = PcdObject.PcdValueFromFdf if PcdObject.PcdValueFromFdf else self.PcdValueFromFdf
self.CustomAttribute = PcdObject.CustomAttribute if PcdObject.CustomAttribute else self.CustomAttribute self.CustomAttribute = PcdObject.CustomAttribute if PcdObject.CustomAttribute else self.CustomAttribute
@ -323,6 +347,7 @@ class StructurePcd(PcdClassObject):
self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues
self.PcdMode = PcdObject.PcdMode if PcdObject.PcdMode else self.PcdMode self.PcdMode = PcdObject.PcdMode if PcdObject.PcdMode else self.PcdMode
self.DefaultValueFromDec = PcdObject.DefaultValueFromDec if PcdObject.DefaultValueFromDec else self.DefaultValueFromDec self.DefaultValueFromDec = PcdObject.DefaultValueFromDec if PcdObject.DefaultValueFromDec else self.DefaultValueFromDec
self.DefaultValueFromDecInfo = PcdObject.DefaultValueFromDecInfo if PcdObject.DefaultValueFromDecInfo else self.DefaultValueFromDecInfo
self.SkuOverrideValues = PcdObject.SkuOverrideValues if PcdObject.SkuOverrideValues else self.SkuOverrideValues self.SkuOverrideValues = PcdObject.SkuOverrideValues if PcdObject.SkuOverrideValues else self.SkuOverrideValues
self.StructName = PcdObject.DatumType if PcdObject.DatumType else self.StructName self.StructName = PcdObject.DatumType if PcdObject.DatumType else self.StructName
self.PcdDefineLineNo = PcdObject.PcdDefineLineNo if PcdObject.PcdDefineLineNo else self.PcdDefineLineNo self.PcdDefineLineNo = PcdObject.PcdDefineLineNo if PcdObject.PcdDefineLineNo else self.PcdDefineLineNo
@ -336,6 +361,7 @@ class StructurePcd(PcdClassObject):
self.sharedcopy(new_pcd) self.sharedcopy(new_pcd)
new_pcd.DefaultValueFromDec = self.DefaultValueFromDec new_pcd.DefaultValueFromDec = self.DefaultValueFromDec
new_pcd.DefaultValueFromDecInfo = self.DefaultValueFromDecInfo
new_pcd.PcdMode = self.PcdMode new_pcd.PcdMode = self.PcdMode
new_pcd.StructName = self.DatumType new_pcd.StructName = self.DatumType
new_pcd.PcdDefineLineNo = self.PcdDefineLineNo new_pcd.PcdDefineLineNo = self.PcdDefineLineNo

View File

@ -395,7 +395,7 @@ class DecBuildData(PackageBuildClassObject):
struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName = pcdname.split(".") struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName = pcdname.split(".")
struct_pcd.PcdDefineLineNo = LineNo struct_pcd.PcdDefineLineNo = LineNo
struct_pcd.PkgPath = self.MetaFile.File struct_pcd.PkgPath = self.MetaFile.File
struct_pcd.SetDecDefaultValue(item.DefaultValue) struct_pcd.SetDecDefaultValue(item.DefaultValue,self.MetaFile.File,LineNo)
else: else:
DemesionAttr, Fields = self.ParsePcdName(item.TokenCName) DemesionAttr, Fields = self.ParsePcdName(item.TokenCName)
struct_pcd.AddDefaultValue(Fields, item.DefaultValue, self.MetaFile.File, LineNo,DemesionAttr) struct_pcd.AddDefaultValue(Fields, item.DefaultValue, self.MetaFile.File, LineNo,DemesionAttr)

View File

@ -27,7 +27,7 @@ from .MetaFileParser import *
from .WorkspaceCommon import GetDeclaredPcd from .WorkspaceCommon import GetDeclaredPcd
from Common.Misc import AnalyzeDscPcd from Common.Misc import AnalyzeDscPcd
from Common.Misc import ProcessDuplicatedInf,RemoveCComments from Common.Misc import ProcessDuplicatedInf,RemoveCComments,ArrayIndex
import re import re
from Common.Parsing import IsValidWord from Common.Parsing import IsValidWord
from Common.VariableAttributes import VariableAttributes from Common.VariableAttributes import VariableAttributes
@ -37,7 +37,6 @@ from functools import reduce
from Common.Misc import SaveFileOnChange from Common.Misc import SaveFileOnChange
from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject
from collections import OrderedDict, defaultdict from collections import OrderedDict, defaultdict
from .BuildClassObject import ArrayIndex
def _IsFieldValueAnArray (Value): def _IsFieldValueAnArray (Value):
Value = Value.strip() Value = Value.strip()
@ -943,7 +942,7 @@ class DscBuildData(PlatformBuildClassObject):
EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo, EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,
ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName)) ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT, MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE): if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT, MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE):
if self._DecPcds[PcdCName, TokenSpaceGuid].BaseDatumType.strip() != ValueList[1].strip(): if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() != ValueList[1].strip():
DecPcd = self._DecPcds[PcdCName, TokenSpaceGuid] DecPcd = self._DecPcds[PcdCName, TokenSpaceGuid]
EdkLogger.error('build', FORMAT_INVALID, EdkLogger.error('build', FORMAT_INVALID,
"Pcd datumtype used in DSC file is not the same as its declaration. DatumType:%s"%DecPcd.DatumType, "Pcd datumtype used in DSC file is not the same as its declaration. DatumType:%s"%DecPcd.DatumType,
@ -1664,17 +1663,17 @@ class DscBuildData(PlatformBuildClassObject):
EdkLogger.error('build', FORMAT_INVALID, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid, PcdCName)), EdkLogger.error('build', FORMAT_INVALID, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid, PcdCName)),
File=self.MetaFile, Line=Dummy4) File=self.MetaFile, Line=Dummy4)
if (PcdCName, TokenSpaceGuid) in PcdValueDict: if (PcdCName, TokenSpaceGuid) in PcdValueDict:
PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue, DatumType, MaxDatumSize) PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue, DatumType, MaxDatumSize,Dummy4)
else: else:
PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, DatumType, MaxDatumSize)} PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, DatumType, MaxDatumSize,Dummy4)}
for ((PcdCName, TokenSpaceGuid), PcdSetting) in PcdValueDict.items(): for ((PcdCName, TokenSpaceGuid), PcdSetting) in PcdValueDict.items():
if self.SkuIdMgr.SystemSkuId in PcdSetting: if self.SkuIdMgr.SystemSkuId in PcdSetting:
PcdValue, DatumType, MaxDatumSize = PcdSetting[self.SkuIdMgr.SystemSkuId] PcdValue, DatumType, MaxDatumSize,_ = PcdSetting[self.SkuIdMgr.SystemSkuId]
elif TAB_DEFAULT in PcdSetting: elif TAB_DEFAULT in PcdSetting:
PcdValue, DatumType, MaxDatumSize = PcdSetting[TAB_DEFAULT] PcdValue, DatumType, MaxDatumSize,_ = PcdSetting[TAB_DEFAULT]
elif TAB_COMMON in PcdSetting: elif TAB_COMMON in PcdSetting:
PcdValue, DatumType, MaxDatumSize = PcdSetting[TAB_COMMON] PcdValue, DatumType, MaxDatumSize,_ = PcdSetting[TAB_COMMON]
else: else:
PcdValue = None PcdValue = None
DatumType = None DatumType = None
@ -1696,7 +1695,9 @@ class DscBuildData(PlatformBuildClassObject):
Settings = PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] Settings = PcdValueDict[PcdCName, TokenSpaceGuid][SkuName]
if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue: if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue:
Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {} Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}
Pcds[PcdCName, TokenSpaceGuid].DscRawValueInfo[SkuName] = {}
Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = Settings[0] Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = Settings[0]
Pcds[PcdCName, TokenSpaceGuid].DscRawValueInfo[SkuName][TAB_DEFAULT_STORES_DEFAULT] = (self.MetaFile.File,Settings[3])
return Pcds return Pcds
@staticmethod @staticmethod
@ -1749,24 +1750,41 @@ class DscBuildData(PlatformBuildClassObject):
def GenerateSizeFunction(self, Pcd): def GenerateSizeFunction(self, Pcd):
CApp = "// Default Value in Dec \n" CApp = "// Default Value in Dec \n"
CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
if Pcd.IsArray():
if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":
CApp += " *Size = (sizeof (%s) > *Size ? sizeof (%s) : *Size);\n" % (Pcd.DatumType,Pcd.DatumType)
else:
if "{CODE(" in Pcd.DefaultValueFromDec:
CApp += " *Size = (sizeof (%s_%s_INIT_Value) > *Size ? sizeof (%s_%s_INIT_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd.TokenCName,Pcd.TokenSpaceGuidCName,Pcd.TokenCName)
if Pcd.Type in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET: if Pcd.Type in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET:
for skuname in Pcd.SkuInfoList: for skuname in Pcd.SkuInfoList:
skuobj = Pcd.SkuInfoList[skuname] skuobj = Pcd.SkuInfoList[skuname]
if skuobj.VariableName: if skuobj.VariableName:
for defaultstore in skuobj.DefaultStoreDict: for defaultstore in skuobj.DefaultStoreDict:
pcddef = self.GetPcdDscRawDefaultValue(Pcd,skuname,defaultstore) pcddef = self.GetPcdDscRawDefaultValue(Pcd,skuname,defaultstore)
if pcddef and "{CODE(" in pcddef: if pcddef:
CApp += " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,defaultstore,Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,defaultstore) if "{CODE(" in pcddef:
CApp += " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,defaultstore,Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,defaultstore)
else:
CApp += " *Size = %s > *Size ? %s : *Size;\n" % (self.GetStructurePcdMaxSize(Pcd),self.GetStructurePcdMaxSize(Pcd))
else: else:
pcddef = self.GetPcdDscRawDefaultValue(Pcd,skuname,TAB_DEFAULT_STORES_DEFAULT) pcddef = self.GetPcdDscRawDefaultValue(Pcd,skuname,TAB_DEFAULT_STORES_DEFAULT)
if pcddef and "{CODE(" in pcddef: if pcddef:
CApp += " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT) if "{CODE(" in pcddef:
CApp += " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT)
else:
CApp += " *Size = %s > *Size ? %s : *Size;\n" % (self.GetStructurePcdMaxSize(Pcd),self.GetStructurePcdMaxSize(Pcd))
else: else:
pcddef = self.GetPcdDscRawDefaultValue(Pcd,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT) pcddef = self.GetPcdDscRawDefaultValue(Pcd,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT)
if pcddef and "{CODE(" in pcddef: if pcddef:
CApp += " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuidCName,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT) if "{CODE(" in pcddef:
CApp += " *Size = (sizeof (%s_%s_%s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuidCName,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT)
else:
CApp += " *Size = %s > *Size ? %s : *Size;\n" % (self.GetStructurePcdMaxSize(Pcd),self.GetStructurePcdMaxSize(Pcd))
ActualCap = []
for index in Pcd.DefaultValues: for index in Pcd.DefaultValues:
if index:
ActualCap.append(index)
FieldList = Pcd.DefaultValues[index] FieldList = Pcd.DefaultValues[index]
if not FieldList: if not FieldList:
continue continue
@ -1787,18 +1805,20 @@ class DscBuildData(PlatformBuildClassObject):
FieldName_ori = FieldName.strip('.') FieldName_ori = FieldName.strip('.')
while '[' in FieldName: while '[' in FieldName:
NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]' NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0]) Array_Index = int(FieldName.split('[', 1)[1].split(']', 1)[0])
FieldName = FieldName.split(']', 1)[1] FieldName = FieldName.split(']', 1)[1]
FieldName = NewFieldName + FieldName FieldName = NewFieldName + FieldName
while '[' in FieldName and not Pcd.IsArray(): while '[' in FieldName and not Pcd.IsArray():
FieldName = FieldName.rsplit('[', 1)[0] FieldName = FieldName.rsplit('[', 1)[0]
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]) CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), Array_Index + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
for skuname in Pcd.SkuOverrideValues: for skuname in Pcd.SkuOverrideValues:
if skuname == TAB_COMMON: if skuname == TAB_COMMON:
continue continue
for defaultstorenameitem in Pcd.SkuOverrideValues[skuname]: for defaultstorenameitem in Pcd.SkuOverrideValues[skuname]:
CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (skuname, defaultstorenameitem) CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)
for index in Pcd.SkuOverrideValues[skuname][defaultstorenameitem]: for index in Pcd.SkuOverrideValues[skuname][defaultstorenameitem]:
if index:
ActualCap.append(index)
for FieldList in [Pcd.SkuOverrideValues[skuname][defaultstorenameitem][index]]: for FieldList in [Pcd.SkuOverrideValues[skuname][defaultstorenameitem][index]]:
if not FieldList: if not FieldList:
continue continue
@ -1819,12 +1839,12 @@ class DscBuildData(PlatformBuildClassObject):
FieldName_ori = FieldName.strip('.') FieldName_ori = FieldName.strip('.')
while '[' in FieldName: while '[' in FieldName:
NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]' NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0]) Array_Index = int(FieldName.split('[', 1)[1].split(']', 1)[0])
FieldName = FieldName.split(']', 1)[1] FieldName = FieldName.split(']', 1)[1]
FieldName = NewFieldName + FieldName FieldName = NewFieldName + FieldName
while '[' in FieldName and not Pcd.IsArray(): while '[' in FieldName and not Pcd.IsArray():
FieldName = FieldName.rsplit('[', 1)[0] FieldName = FieldName.rsplit('[', 1)[0]
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]) CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), Array_Index + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
if Pcd.PcdFieldValueFromFdf: if Pcd.PcdFieldValueFromFdf:
CApp = CApp + "// From fdf \n" CApp = CApp + "// From fdf \n"
for FieldName in Pcd.PcdFieldValueFromFdf: for FieldName in Pcd.PcdFieldValueFromFdf:
@ -1844,12 +1864,12 @@ class DscBuildData(PlatformBuildClassObject):
FieldName_ori = FieldName.strip('.') FieldName_ori = FieldName.strip('.')
while '[' in FieldName: while '[' in FieldName:
NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]' NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0]) Array_Index = int(FieldName.split('[', 1)[1].split(']', 1)[0])
FieldName = FieldName.split(']', 1)[1] FieldName = FieldName.split(']', 1)[1]
FieldName = NewFieldName + FieldName FieldName = NewFieldName + FieldName
while '[' in FieldName: while '[' in FieldName:
FieldName = FieldName.rsplit('[', 1)[0] FieldName = FieldName.rsplit('[', 1)[0]
CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %s Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromFdf[FieldName_ori][1], Pcd.PcdFieldValueFromFdf[FieldName_ori][2], Pcd.PcdFieldValueFromFdf[FieldName_ori][0]) CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %s Value %s \n' % (Pcd.DatumType, FieldName.strip("."), Array_Index + 1, Pcd.PcdFieldValueFromFdf[FieldName_ori][1], Pcd.PcdFieldValueFromFdf[FieldName_ori][2], Pcd.PcdFieldValueFromFdf[FieldName_ori][0])
if Pcd.PcdFieldValueFromComm: if Pcd.PcdFieldValueFromComm:
CApp = CApp + "// From Command Line \n" CApp = CApp + "// From Command Line \n"
for FieldName in Pcd.PcdFieldValueFromComm: for FieldName in Pcd.PcdFieldValueFromComm:
@ -1869,16 +1889,37 @@ class DscBuildData(PlatformBuildClassObject):
FieldName_ori = FieldName.strip('.') FieldName_ori = FieldName.strip('.')
while '[' in FieldName: while '[' in FieldName:
NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]' NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0]) Array_Index = int(FieldName.split('[', 1)[1].split(']', 1)[0])
FieldName = FieldName.split(']', 1)[1] FieldName = FieldName.split(']', 1)[1]
FieldName = NewFieldName + FieldName FieldName = NewFieldName + FieldName
while '[' in FieldName and not Pcd.IsArray(): while '[' in FieldName and not Pcd.IsArray():
FieldName = FieldName.rsplit('[', 1)[0] FieldName = FieldName.rsplit('[', 1)[0]
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]) CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), Array_Index + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValueFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0])
if Pcd.GetPcdMaxSize(): if Pcd.GetPcdMaxSize():
CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize()) CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize())
ArraySizeByAssign = self.CalculateActualCap(ActualCap)
if ArraySizeByAssign > 1:
CApp = CApp + " *Size = (%d > *Size ? %d : *Size); \n" % (ArraySizeByAssign, ArraySizeByAssign)
CApp = CApp + "}\n" CApp = CApp + "}\n"
return CApp return CApp
def CalculateActualCap(self,ActualCap):
if not ActualCap:
return 1
maxsize = 1
for item in ActualCap:
index_elements = ArrayIndex.findall(item)
rt = 1
for index_e in index_elements:
index_num = index_e.lstrip("[").rstrip("]").strip()
if not index_num:
# Not support flexiable pcd array assignment
return 1
index_num = int(index_num,16) if index_num.startswith(("0x","0X")) else int(index_num)
rt = rt * (index_num+1)
if rt >maxsize:
maxsize = rt
return maxsize
@staticmethod @staticmethod
def GenerateSizeStatments(Pcd,skuname,defaultstorename): def GenerateSizeStatments(Pcd,skuname,defaultstorename):
@ -1957,6 +1998,7 @@ class DscBuildData(PlatformBuildClassObject):
CApp = CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.BaseDatumType) CApp = CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.BaseDatumType)
CApp = CApp + ' UINT32 FieldSize;\n' CApp = CApp + ' UINT32 FieldSize;\n'
CApp = CApp + ' CHAR8 *Value;\n' CApp = CApp + ' CHAR8 *Value;\n'
CApp = CApp + ' UINT32 PcdArraySize;\n'
DefaultValueFromDec = Pcd.DefaultValueFromDec DefaultValueFromDec = Pcd.DefaultValueFromDec
IsArray = _IsFieldValueAnArray(Pcd.DefaultValueFromDec) IsArray = _IsFieldValueAnArray(Pcd.DefaultValueFromDec)
if IsArray: if IsArray:
@ -1968,14 +2010,29 @@ class DscBuildData(PlatformBuildClassObject):
DefaultValueFromDec = StringToArray(DefaultValueFromDec) DefaultValueFromDec = StringToArray(DefaultValueFromDec)
Value, ValueSize = ParseFieldValue (DefaultValueFromDec) Value, ValueSize = ParseFieldValue (DefaultValueFromDec)
if IsArray: if IsArray:
# #
# Use memcpy() to copy value into field # Use memcpy() to copy value into field
# #
if "{CODE(" in Pcd.DefaultValueFromDec: if Pcd.IsArray():
CApp = CApp + ' memcpy (Pcd, %s_%s_INIT_Value, sizeof(%s_%s_INIT_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName) pcdarraysize = Pcd.PcdArraySize()
if "{CODE(" in Pcd.DefaultValueFromDec:
if Pcd.Capacity[-1] != "-1":
CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From %s Line %s \n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])
CApp = CApp + ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
CApp = CApp + ' memcpy (Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
else:
if Pcd.Capacity[-1] != "-1":
CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From %s Line %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])
CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize
CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
CApp = CApp + ' memcpy (Pcd, Value, PcdArraySize);\n'
else: else:
CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec) if "{CODE(" in Pcd.DefaultValueFromDec:
CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize) CApp = CApp + ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
CApp = CApp + ' memcpy (Pcd, &%s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
else:
CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)
elif isinstance(Value, str): elif isinstance(Value, str):
CApp = CApp + ' Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec) CApp = CApp + ' Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)
for index in Pcd.DefaultValues: for index in Pcd.DefaultValues:
@ -2033,14 +2090,29 @@ class DscBuildData(PlatformBuildClassObject):
pcddefaultvalue = Pcd.DscRawValue.get(SkuName, {}).get(TAB_DEFAULT_STORES_DEFAULT) pcddefaultvalue = Pcd.DscRawValue.get(SkuName, {}).get(TAB_DEFAULT_STORES_DEFAULT)
return pcddefaultvalue return pcddefaultvalue
def GetPcdDscRawValueInfo(self,Pcd, SkuName,DefaultStoreName):
DscValueInfo = Pcd.DscRawValueInfo.get(SkuName, {}).get(DefaultStoreName)
if DscValueInfo:
dscfilepath,lineno = DscValueInfo
else:
dscfilepath = self.MetaFile.File
lineno = ""
return dscfilepath,lineno
def GenerateInitValueFunction(self, Pcd, SkuName, DefaultStoreName): def GenerateInitValueFunction(self, Pcd, SkuName, DefaultStoreName):
CApp = "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName, DefaultStoreName) CApp = "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName, DefaultStoreName)
CApp = CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, SkuName, DefaultStoreName, Pcd.BaseDatumType) CApp = CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, SkuName, DefaultStoreName, Pcd.BaseDatumType)
CApp = CApp + ' UINT32 FieldSize;\n' CApp = CApp + ' UINT32 FieldSize;\n'
CApp = CApp + ' CHAR8 *Value;\n' CApp = CApp + ' CHAR8 *Value;\n'
CApp = CApp + ' UINT32 PcdArraySize;\n'
CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT) CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT)
inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName] inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName]
dscfilepath,lineno = self.GetPcdDscRawValueInfo(Pcd, SkuName, DefaultStoreName)
if lineno:
valuefrom = "%s Line %s" % (dscfilepath,str(lineno))
else:
valuefrom = dscfilepath
pcddefaultvalue = self.GetPcdDscRawDefaultValue(Pcd, SkuName, DefaultStoreName) pcddefaultvalue = self.GetPcdDscRawDefaultValue(Pcd, SkuName, DefaultStoreName)
if pcddefaultvalue: if pcddefaultvalue:
@ -2058,33 +2130,71 @@ class DscBuildData(PlatformBuildClassObject):
if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT): if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT):
if isinstance(Value, str): if isinstance(Value, str):
if "{CODE(" in Value: if "{CODE(" in Value:
CApp = CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName) if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":
pcdarraysize = Pcd.PcdArraySize()
CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType, valuefrom)
CApp = CApp+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
CApp = CApp + ' memcpy (Pcd, &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
else: else:
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) 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)
elif IsArray: elif IsArray:
# #
# Use memcpy() to copy value into field # Use memcpy() to copy value into field
# #
if Pcd.IsArray() and "{CODE(" in pcddefaultvalue: if Pcd.IsArray():
CApp = CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName) pcdarraysize = Pcd.PcdArraySize()
if "{CODE(" in pcddefaultvalue:
if Pcd.Capacity[-1] != "-1":
CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
CApp = CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
CApp = CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
else:
if Pcd.Capacity[-1] != "-1":
CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize
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)
CApp = CApp + ' memcpy (Pcd, Value, PcdArraySize);\n'
else: else:
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) if "{CODE(" in pcddefaultvalue:
CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize) CApp = CApp + ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarraysize,ValueSize,Pcd.BaseDatumType,pcdarraysize)
CApp = CApp + ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
else:
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)
CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)
else: else:
if isinstance(Value, str): if isinstance(Value, str):
if "{CODE(" in Value: if "{CODE(" in Value:
CApp = CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName) if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":
pcdarraysize = Pcd.PcdArraySize()
CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
CApp = CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n '% (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
CApp = CApp + ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
else: else:
CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName)) CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName))
elif IsArray: elif IsArray:
# #
# Use memcpy() to copy value into field # Use memcpy() to copy value into field
# #
if Pcd.IsArray() and "{CODE(" in pcddefaultvalue: if Pcd.IsArray():
CApp = CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value, sizeof(%s_%s_%s_%s_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName) pcdarraysize = Pcd.PcdArraySize()
if "{CODE(" in pcddefaultvalue:
if Pcd.Capacity[-1] != "-1":
CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
CApp = CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
else:
if Pcd.Capacity[-1] != "-1":
CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize
CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
CApp = CApp + ' memcpy (Pcd, Value, PcdArraySize);\n'
else: else:
CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName)) if "{CODE(" in pcddefaultvalue:
CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize) CApp = CApp + ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarraysize,ValueSize,Pcd.BaseDatumType,pcdarraysize)
CApp = CApp + ' memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
else:
CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName))
CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)
inheritvalue = inherit_OverrideValues.get(DefaultStoreName) inheritvalue = inherit_OverrideValues.get(DefaultStoreName)
if not inheritvalue: if not inheritvalue:
@ -2310,6 +2420,9 @@ class DscBuildData(PlatformBuildClassObject):
# OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1) # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
# #
CApp = CApp + DscBuildData.GenerateSizeStatments(Pcd,SkuName,DefaultStoreName) CApp = CApp + DscBuildData.GenerateSizeStatments(Pcd,SkuName,DefaultStoreName)
if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":
CApp = CApp + ' OriginalSize = OriginalSize < sizeof(%s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd.BaseDatumType,Pcd.PcdArraySize(),Pcd.BaseDatumType,Pcd.PcdArraySize())
CApp = CApp + ' Size = sizeof(%s) * %d; \n' % (Pcd.BaseDatumType,Pcd.PcdArraySize())
# #
# Allocate and zero buffer for the PCD # Allocate and zero buffer for the PCD
@ -2360,8 +2473,6 @@ class DscBuildData(PlatformBuildClassObject):
CApp = "" CApp = ""
if not Pcd: if not Pcd:
return CApp return CApp
if not Pcd.IsArray():
return CApp
Demesion = "" Demesion = ""
for d in Pcd.Capacity: for d in Pcd.Capacity:
Demesion += "[]" Demesion += "[]"
@ -2753,7 +2864,9 @@ class DscBuildData(PlatformBuildClassObject):
if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue: if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue:
Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {} Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}
Pcds[PcdCName, TokenSpaceGuid].DscRawValueInfo[SkuName] = {}
Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = PcdValue Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = PcdValue
Pcds[PcdCName, TokenSpaceGuid].DscRawValueInfo[SkuName][TAB_DEFAULT_STORES_DEFAULT] = (self.MetaFile.File,Dummy4)
for pcd in Pcds.values(): for pcd in Pcds.values():
pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName] pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]
@ -2955,7 +3068,9 @@ class DscBuildData(PlatformBuildClassObject):
Pcds[PcdCName, TokenSpaceGuid].CustomAttribute['DscPosition'] = int(Dummy4) Pcds[PcdCName, TokenSpaceGuid].CustomAttribute['DscPosition'] = int(Dummy4)
if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue: if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue:
Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {} Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}
Pcds[PcdCName, TokenSpaceGuid].DscRawValueInfo[SkuName] = {}
Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][DefaultStore] = DefaultValue Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][DefaultStore] = DefaultValue
Pcds[PcdCName, TokenSpaceGuid].DscRawValueInfo[SkuName][DefaultStore] = (self.MetaFile.File,Dummy4)
for pcd in Pcds.values(): for pcd in Pcds.values():
pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName] pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]
pcd.DatumType = pcdDecObject.DatumType pcd.DatumType = pcdDecObject.DatumType
@ -3093,7 +3208,9 @@ class DscBuildData(PlatformBuildClassObject):
if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue: if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue:
Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {} Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}
Pcds[PcdCName, TokenSpaceGuid].DscRawValueInfo[SkuName] = {}
Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = InitialValue Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = InitialValue
Pcds[PcdCName, TokenSpaceGuid].DscRawValueInfo[SkuName][TAB_DEFAULT_STORES_DEFAULT] = (self.MetaFile.File,Dummy4)
for pcd in Pcds.values(): for pcd in Pcds.values():
pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName] pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]
pcd.DatumType = pcdDecObject.DatumType pcd.DatumType = pcdDecObject.DatumType