public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools: Fixed a code bug for Pcd Array.
@ 2019-02-16  5:54 Feng, Bob C
  2019-02-19  9:21 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Feng, Bob C @ 2019-02-16  5:54 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

For example, PCD gUefiOvmfPkgTokenSpaceGuid.Test001 datatype is Array:
TEST1[2]
and the filed TEST1UINT64ARRAY in TEST1 is also an array:
UINT64 TEST1UINT64ARRAY[2];

Then the following filed assignment in DSC will cause build failure.
gUefiOvmfPkgTokenSpaceGuid.Test001[0].TEST1UINT64ARRAY|{'A','B'}

The root cause is build tool generate incorrect PcdValueInit.c File.

This patch is going to fix this issue.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/Python/Workspace/DscBuildData.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 1fd1639ab6..e45beb3924 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -2015,14 +2015,13 @@ class DscBuildData(PlatformBuildClassObject):
                 indicator = self.GetIndicator(index, FieldName,Pcd)
                 if IsArray:
                     #
                     # Use memcpy() to copy value into field
                     #
-                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
+                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName)
                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                    CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                     CApp = CApp + '  memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize)
                 elif isinstance(Value, str):
                     CApp = CApp + '  %s = %s; // From %s Line %d Value %s\n' % (indicator, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                 else:
                     if '[' in FieldName and ']' in FieldName:
@@ -2130,12 +2129,11 @@ class DscBuildData(PlatformBuildClassObject):
                     #
                     # Use memcpy() to copy value into field
                     #
                         CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName)
                         CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                        CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                        CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
+                        CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                         CApp = CApp + '  memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize)
                     else:
                         if '[' in FieldName and ']' in FieldName:
                             Index = int(FieldName.split('[')[1].split(']')[0])
                             CApp = CApp + '  __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0], FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2], FieldName)
@@ -2200,11 +2198,11 @@ class DscBuildData(PlatformBuildClassObject):
                 #
                 # Use memcpy() to copy value into field
                 #
                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName)
                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
                 else:
                     if '[' in FieldName and ']' in FieldName:
                         Index = int(FieldName.split('[')[1].split(']')[0])
                         CApp = CApp + '  __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0], FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2], FieldName)
@@ -2268,11 +2266,11 @@ class DscBuildData(PlatformBuildClassObject):
                 #
                 # Use memcpy() to copy value into field
                 #
                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName)
                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
                 else:
                     if '[' in FieldName and ']' in FieldName:
                         Index = int(FieldName.split('[')[1].split(']')[0])
                         CApp = CApp + '  __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0], FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2], FieldName)
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch] BaseTools: Fixed a code bug for Pcd Array.
  2019-02-16  5:54 [Patch] BaseTools: Fixed a code bug for Pcd Array Feng, Bob C
@ 2019-02-19  9:21 ` Gao, Liming
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Liming @ 2019-02-19  9:21 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel@lists.01.org

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Feng, Bob C
>Sent: Saturday, February 16, 2019 1:54 PM
>To: edk2-devel@lists.01.org
>Cc: Gao, Liming <liming.gao@intel.com>
>Subject: [edk2] [Patch] BaseTools: Fixed a code bug for Pcd Array.
>
>For example, PCD gUefiOvmfPkgTokenSpaceGuid.Test001 datatype is Array:
>TEST1[2]
>and the filed TEST1UINT64ARRAY in TEST1 is also an array:
>UINT64 TEST1UINT64ARRAY[2];
>
>Then the following filed assignment in DSC will cause build failure.
>gUefiOvmfPkgTokenSpaceGuid.Test001[0].TEST1UINT64ARRAY|{'A','B'}
>
>The root cause is build tool generate incorrect PcdValueInit.c File.
>
>This patch is going to fix this issue.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Bob Feng <bob.c.feng@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>---
> BaseTools/Source/Python/Workspace/DscBuildData.py | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
>diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
>b/BaseTools/Source/Python/Workspace/DscBuildData.py
>index 1fd1639ab6..e45beb3924 100644
>--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
>@@ -2015,14 +2015,13 @@ class DscBuildData(PlatformBuildClassObject):
>                 indicator = self.GetIndicator(index, FieldName,Pcd)
>                 if IsArray:
>                     #
>                     # Use memcpy() to copy value into field
>                     #
>-                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.DatumType, FieldName)
>+                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.BaseDatumType, FieldName)
>                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' %
>(DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize,
>Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>-                    CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 &&
>FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
>+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize,
>Pcd.BaseDatumType, FieldName, FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>                     CApp = CApp + '  memcpy (&%s, Value, (FieldSize > 0 && FieldSize
>< %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize)
>                 elif isinstance(Value, str):
>                     CApp = CApp + '  %s = %s; // From %s Line %d Value %s\n' %
>(indicator, Value, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>                 else:
>                     if '[' in FieldName and ']' in FieldName:
>@@ -2130,12 +2129,11 @@ class DscBuildData(PlatformBuildClassObject):
>                     #
>                     # Use memcpy() to copy value into field
>                     #
>                         CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.BaseDatumType, FieldName)
>                         CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' %
>(DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>-                        CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize,
>Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>-                        CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 &&
>FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
>+                        CApp = CApp + '
>__STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s)
>== 0), "Input buffer exceeds the buffer array"); // From %s Line %d
>Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize,
>Pcd.BaseDatumType, FieldName, FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>                         CApp = CApp + '  memcpy (&%s, Value, (FieldSize > 0 && FieldSize
>< %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize)
>                     else:
>                         if '[' in FieldName and ']' in FieldName:
>                             Index = int(FieldName.split('[')[1].split(']')[0])
>                             CApp = CApp + '  __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd-
>>%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array
>number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0],
>FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2],
>FieldName)
>@@ -2200,11 +2198,11 @@ class DscBuildData(PlatformBuildClassObject):
>                 #
>                 # Use memcpy() to copy value into field
>                 #
>                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.BaseDatumType, FieldName)
>                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' %
>(DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize,
>Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize,
>Pcd.BaseDatumType, FieldName, FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 &&
>FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
>                 else:
>                     if '[' in FieldName and ']' in FieldName:
>                         Index = int(FieldName.split('[')[1].split(']')[0])
>                         CApp = CApp + '  __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd-
>>%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array
>number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0],
>FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2],
>FieldName)
>@@ -2268,11 +2266,11 @@ class DscBuildData(PlatformBuildClassObject):
>                 #
>                 # Use memcpy() to copy value into field
>                 #
>                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.BaseDatumType, FieldName)
>                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' %
>(DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize,
>Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize,
>Pcd.BaseDatumType, FieldName, FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 &&
>FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
>                 else:
>                     if '[' in FieldName and ']' in FieldName:
>                         Index = int(FieldName.split('[')[1].split(']')[0])
>                         CApp = CApp + '  __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd-
>>%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array
>number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0],
>FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2],
>FieldName)
>--
>2.18.0.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-19  9:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-16  5:54 [Patch] BaseTools: Fixed a code bug for Pcd Array Feng, Bob C
2019-02-19  9:21 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox