From: "Feng, Bob C" <bob.c.feng@intel.com>
To: Felix Polyudov <Felixp@ami.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Gao, Liming" <liming.gao@intel.com>
Subject: Re: [Patch] BaseTools: Correct the value assignment for StructurePcd
Date: Tue, 19 Feb 2019 00:49:29 +0000 [thread overview]
Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D160089092@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <9333E191E0D52B4999CE63A99BA663A00302C637BE@atlms1.us.megatrends.com>
Hi Felix,
Good point. I'll update the patch.
Thanks,
Bob
-----Original Message-----
From: Felix Polyudov [mailto:Felixp@ami.com]
Sent: Tuesday, February 19, 2019 12:57 AM
To: Feng, Bob C <bob.c.feng@intel.com>; edk2-devel@lists.01.org
Cc: Gao, Liming <liming.gao@intel.com>
Subject: RE: [edk2] [Patch] BaseTools: Correct the value assignment for StructurePcd
Bob,
I think silent trimming of input data is not a good idea.
The build tool should either report an error (my preference) or a warning that DSC or DEC input value is too long.
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Feng, Bob C
Sent: Saturday, February 16, 2019 12:55 AM
To: edk2-devel@lists.01.org
Cc: Liming Gao
Subject: [edk2] [Patch] BaseTools: Correct the value assignment for StructurePcd
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 only copy the data as same as that Pcd Array size.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
.../Python/Workspace/BuildClassObject.py | 57 ++++---
.../Source/Python/Workspace/DscBuildData.py | 145 ++++++++++++++----
2 files changed, 147 insertions(+), 55 deletions(-)
diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index 1df042f41c..d6168b62d5 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -76,34 +76,45 @@ class PcdClassObject(object):
self.UserDefinedDefaultStoresFlag = UserDefinedDefaultStoresFlag
self._Capacity = None
@property
def Capacity(self):
- self._Capacity = []
- dimension = ArrayIndex.findall(self._DatumType)
- for item in dimension:
- maxsize = item.lstrip("[").rstrip("]").strip()
- if not maxsize:
- maxsize = "-1"
- maxsize = str(int(maxsize,16)) if maxsize.startswith(("0x","0X")) else maxsize
- self._Capacity.append(maxsize)
- if hasattr(self, "SkuOverrideValues"):
- for sku in self.SkuOverrideValues:
- for defaultstore in self.SkuOverrideValues[sku]:
- fields = self.SkuOverrideValues[sku][defaultstore]
- for demesionattr in fields:
- deme = ArrayIndex.findall(demesionattr)
- for i in range(len(deme)-1):
- if int(deme[i].lstrip("[").rstrip("]").strip()) > int(self._Capacity[i]):
- print ("error")
- if hasattr(self,"DefaultValues"):
- for demesionattr in self.DefaultValues:
- deme = ArrayIndex.findall(demesionattr)
- for i in range(len(deme)-1):
- if int(deme[i].lstrip("[").rstrip("]").strip()) > int(self._Capacity[i]):
- print ("error")
+ if self._Capacity is None:
+ self._Capacity = []
+ dimension = ArrayIndex.findall(self._DatumType)
+ for item in dimension:
+ maxsize = item.lstrip("[").rstrip("]").strip()
+ if not maxsize:
+ maxsize = "-1"
+ maxsize = str(int(maxsize,16)) if maxsize.startswith(("0x","0X")) else maxsize
+ self._Capacity.append(maxsize)
+ if hasattr(self, "SkuOverrideValues"):
+ for sku in self.SkuOverrideValues:
+ for defaultstore in self.SkuOverrideValues[sku]:
+ fields = self.SkuOverrideValues[sku][defaultstore]
+ for demesionattr in fields:
+ 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":
+ raise ("error")
+ if hasattr(self,"DefaultValues"):
+ for demesionattr in self.DefaultValues:
+ 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":
+ raise ("error")
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
def DatumType(self):
return self._DatumType
@DatumType.setter
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index e45beb3924..09d917c5db 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1763,27 +1763,41 @@ class DscBuildData(PlatformBuildClassObject):
return Result
def GenerateSizeFunction(self, Pcd):
CApp = "// Default Value in Dec \n"
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.To
+ kenCName)
if Pcd.Type in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET:
for skuname in Pcd.SkuInfoList:
skuobj = Pcd.SkuInfoList[skuname]
if skuobj.VariableName:
for defaultstore in skuobj.DefaultStoreDict:
pcddef = self.GetPcdDscRawDefaultValue(Pcd,skuname,defaultstore)
- if pcddef and "{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)
+ if pcddef:
+ 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:
pcddef = self.GetPcdDscRawDefaultValue(Pcd,skuname,TAB_DEFAULT_STORES_DEFAULT)
- if pcddef and "{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)
+ if pcddef:
+ 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:
pcddef = self.GetPcdDscRawDefaultValue(Pcd,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT)
- if pcddef and "{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)
+ if pcddef:
+ 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))
for index in Pcd.DefaultValues:
FieldList = Pcd.DefaultValues[index]
if not FieldList:
continue
for FieldName in FieldList:
@@ -1891,10 +1905,11 @@ class DscBuildData(PlatformBuildClassObject):
while '[' in FieldName and not Pcd.IsArray:
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])
if Pcd.GetPcdMaxSize():
CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize())
+
CApp = CApp + "}\n"
return CApp
@staticmethod
def GenerateSizeStatments(Pcd,skuname,defaultstorename):
@@ -1971,10 +1986,11 @@ class DscBuildData(PlatformBuildClassObject):
def GenerateDefaultValueAssignFunction(self, Pcd):
CApp = "// Default value in Dec \n"
CApp = CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.BaseDatumType)
CApp = CApp + ' UINT32 FieldSize;\n'
CApp = CApp + ' CHAR8 *Value;\n'
+ CApp = CApp + ' UINT32 PcdArraySize;\n'
DefaultValueFromDec = Pcd.DefaultValueFromDec
IsArray = _IsFieldValueAnArray(Pcd.DefaultValueFromDec)
if IsArray:
try:
DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, TAB_VOID)(True) @@ -1982,18 +1998,35 @@ class DscBuildData(PlatformBuildClassObject):
EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" %
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))
DefaultValueFromDec = StringToArray(DefaultValueFromDec)
Value, ValueSize = ParseFieldValue (DefaultValueFromDec)
if IsArray:
- #
- # Use memcpy() to copy value into field
- #
- if "{CODE(" in Pcd.DefaultValueFromDec:
- CApp = CApp + ' memcpy (Pcd, %s_%s_INIT_Value, sizeof(%s_%s_INIT_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
+ #
+ # Use memcpy() to copy value into field
+ #
+ if Pcd.IsArray():
+ pcdarraysize = Pcd.PcdArraySize()
+ if "{CODE(" in Pcd.DefaultValueFromDec:
+ if Pcd.Capacity[-1] != "-1":
+ CApp = CApp + ' PcdArraySize = sizeof(%s_%s_INIT_Value) < %d * sizeof(%s)? sizeof(%s_%s_INIT_Value): %d * sizeof(%s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType)
+ else:
+ 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 + ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarraysize,ValueSize,Pcd.BaseDatumType,pcdarraysize)
+ else:
+ 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:
- CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
- CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize)
+ if "{CODE(" in Pcd.DefaultValueFromDec:
+ 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):
CApp = CApp + ' Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)
for index in Pcd.DefaultValues:
FieldList = Pcd.DefaultValues[index]
if not FieldList:
@@ -2052,10 +2085,11 @@ class DscBuildData(PlatformBuildClassObject):
def GenerateInitValueFunction(self, Pcd, 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 + ' UINT32 FieldSize;\n'
CApp = CApp + ' CHAR8 *Value;\n'
+ CApp = CApp + ' UINT32 PcdArraySize;\n'
CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT)
inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName]
pcddefaultvalue = self.GetPcdDscRawDefaultValue(Pcd, SkuName, DefaultStoreName) @@ -2072,37 +2106,83 @@ class DscBuildData(PlatformBuildClassObject):
Value, ValueSize = ParseFieldValue (FieldList)
if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT):
if isinstance(Value, str):
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 + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s)? sizeof(%s_%s_%s_%s_Value): %d * sizeof(%s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType)
+ CApp = CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
+ else:
+ 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:
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:
- #
- # Use memcpy() to copy value into field
- #
- if Pcd.IsArray() and "{CODE(" in pcddefaultvalue:
- 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)
+ #
+ # Use memcpy() to copy value into field
+ #
+ if Pcd.IsArray():
+ pcdarraysize = Pcd.PcdArraySize()
+ if "{CODE(" in pcddefaultvalue:
+ if Pcd.Capacity[-1] != "-1":
+ CApp = CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s)? sizeof(%s_%s_%s_%s_Value): %d * sizeof(%s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType)
+ else:
+ 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 + ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarraysize,ValueSize,Pcd.BaseDatumType,pcdarraysize)
+ else:
+ 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:
- 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)
+ if "{CODE(" in pcddefaultvalue:
+ 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:
if isinstance(Value, str):
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 + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s)? sizeof(%s_%s_%s_%s_Value): %d * sizeof(%s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType)
+ CApp = CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
+ else:
+ 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:
CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName))
elif IsArray:
- #
- # Use memcpy() to copy value into field
- #
- if Pcd.IsArray() and "{CODE(" in pcddefaultvalue:
- 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)
+ #
+ # Use memcpy() to copy value into field
+ #
+ if Pcd.IsArray():
+ pcdarraysize = Pcd.PcdArraySize()
+ if "{CODE(" in pcddefaultvalue:
+ if Pcd.Capacity[-1] != "-1":
+ CApp = CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s)? sizeof(%s_%s_%s_%s_Value): %d * sizeof(%s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType)
+ else:
+ 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 + ' PcdArraySize = %d < sizeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarraysize,ValueSize,Pcd.BaseDatumType,pcdarraysize)
+ else:
+ 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:
- 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)
+ if "{CODE(" in pcddefaultvalue:
+ 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)
if not inheritvalue:
inheritvalue = []
for index in inheritvalue:
@@ -2324,10 +2404,13 @@ class DscBuildData(PlatformBuildClassObject):
# the flexible array member. The flexible array member must be the last field
# in a structure. The size formula for this case is:
# OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
#
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
# Must handle cases where current value is smaller, larger, or same size
# Always keep that larger one as the current size @@ -2374,12 +2457,10 @@ class DscBuildData(PlatformBuildClassObject):
def GenerateArrayAssignment(self, Pcd):
CApp = ""
if not Pcd:
return CApp
- if not Pcd.IsArray():
- return CApp
Demesion = ""
for d in Pcd.Capacity:
Demesion += "[]"
Value = Pcd.DefaultValueFromDec
--
2.18.0.windows.1
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Please consider the environment before printing this email.
The information contained in this message may be confidential and proprietary to American Megatrends, Inc. This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.
prev parent reply other threads:[~2019-02-19 0:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-16 5:54 [Patch] BaseTools: Correct the value assignment for StructurePcd Feng, Bob C
2019-02-18 16:57 ` Felix Polyudov
2019-02-19 0:49 ` Feng, Bob C [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=08650203BA1BD64D8AD9B6D5D74A85D160089092@SHSMSX101.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox