[edk2-devel][PATCH] BaseTools: Increase the DevicePath length for support more PCD value.

Xiaolu.Jiang posted 1 patch 2 weeks, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/20211116014214.745-1-xiaolu.jiang@intel.com
BaseTools/Source/C/DevicePath/DevicePath.c | 36 +++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)

[edk2-devel][PATCH] BaseTools: Increase the DevicePath length for support more PCD value.

Posted by Xiaolu.Jiang 2 weeks, 5 days ago
Currently the PCD Value only support 13 Guid,When use more 13 pcd will cause the build tool fail,
Need calculate the required memory,then allocate it.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3718

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>

Signed-off-by: Xiaolu Jiang <xiaolu.jiang@intel.com>
---
 BaseTools/Source/C/DevicePath/DevicePath.c | 36 +++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c
index c4d224ed61..8a0f5f4e2a 100644
--- a/BaseTools/Source/C/DevicePath/DevicePath.c
+++ b/BaseTools/Source/C/DevicePath/DevicePath.c
@@ -144,6 +144,40 @@ Returns:
   *UniString = '\0';
 }
 
+
+/**
+  Returns the length of a Null-terminated ASCII string.
+
+  This function returns the number of ASCII characters in the Null-terminated
+  ASCII string specified by String.
+
+  If Length > 0 and Destination is NULL, then ASSERT().
+  If Length > 0 and Source is NULL, then ASSERT().
+  If PcdMaximumAsciiStringLength is not zero and String contains more than
+  PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
+  then ASSERT().
+
+  @param  String  A pointer to a Null-terminated ASCII string.
+
+  @return The length of String.
+
+**/
+UINTN
+EFIAPI
+AsciiStrLen (
+  IN      CONST CHAR8               *String
+  )
+{
+  UINTN                             Length;
+
+  ASSERT (String != NULL);
+
+  for (Length = 0; *String != '\0'; String++, Length++) {
+
+  }
+  return Length;
+}
+
 int main(int argc, CHAR8 *argv[])
 {
   CHAR8 * Str;
@@ -170,7 +204,7 @@ int main(int argc, CHAR8 *argv[])
     fprintf(stderr, "Invalid option value, Device Path can't be NULL");
     return STATUS_ERROR;
   }
-  Str16 = (CHAR16 *)malloc(1024);
+  Str16 = (CHAR16 *)malloc((AsciiStrLen (Str) + 1) * sizeof (CHAR16));
   if (Str16 == NULL) {
     fprintf(stderr, "Resource, memory cannot be allocated");
     return STATUS_ERROR;
-- 
2.30.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#83769): https://edk2.groups.io/g/devel/message/83769
Mute This Topic: https://groups.io/mt/87089392/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


回复: [edk2-devel][PATCH] BaseTools: Increase the DevicePath length for support more PCD value.

Posted by gaoliming 1 week, 4 days ago
Xiaolu:
  BaseTools C source can directly use std libc API. You can use strlen() to
get the length of the input ascii string. 

  With this change, Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Xiaolu.Jiang
> 发送时间: 2021年11月16日 9:42
> 收件人: devel@edk2.groups.io
> 抄送: Xiaolu.Jiang <xiaolu.jiang@intel.com>; Bob Feng
> <bob.c.feng@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Yuwei
> Chen <yuwei.chen@intel.com>
> 主题: [edk2-devel][PATCH] BaseTools: Increase the DevicePath length for
> support more PCD value.
> 
> Currently the PCD Value only support 13 Guid,When use more 13 pcd will
> cause the build tool fail,
> Need calculate the required memory,then allocate it.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3718
> 
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Yuwei Chen <yuwei.chen@intel.com>
> 
> Signed-off-by: Xiaolu Jiang <xiaolu.jiang@intel.com>
> ---
>  BaseTools/Source/C/DevicePath/DevicePath.c | 36
> +++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c
> b/BaseTools/Source/C/DevicePath/DevicePath.c
> index c4d224ed61..8a0f5f4e2a 100644
> --- a/BaseTools/Source/C/DevicePath/DevicePath.c
> +++ b/BaseTools/Source/C/DevicePath/DevicePath.c
> @@ -144,6 +144,40 @@ Returns:
>    *UniString = '\0';
> 
>  }
> 
> 
> 
> +
> 
> +/**
> 
> +  Returns the length of a Null-terminated ASCII string.
> 
> +
> 
> +  This function returns the number of ASCII characters in the
> Null-terminated
> 
> +  ASCII string specified by String.
> 
> +
> 
> +  If Length > 0 and Destination is NULL, then ASSERT().
> 
> +  If Length > 0 and Source is NULL, then ASSERT().
> 
> +  If PcdMaximumAsciiStringLength is not zero and String contains more
than
> 
> +  PcdMaximumAsciiStringLength ASCII characters, not including the
> Null-terminator,
> 
> +  then ASSERT().
> 
> +
> 
> +  @param  String  A pointer to a Null-terminated ASCII string.
> 
> +
> 
> +  @return The length of String.
> 
> +
> 
> +**/
> 
> +UINTN
> 
> +EFIAPI
> 
> +AsciiStrLen (
> 
> +  IN      CONST CHAR8               *String
> 
> +  )
> 
> +{
> 
> +  UINTN                             Length;
> 
> +
> 
> +  ASSERT (String != NULL);
> 
> +
> 
> +  for (Length = 0; *String != '\0'; String++, Length++) {
> 
> +
> 
> +  }
> 
> +  return Length;
> 
> +}
> 
> +
> 
>  int main(int argc, CHAR8 *argv[])
> 
>  {
> 
>    CHAR8 * Str;
> 
> @@ -170,7 +204,7 @@ int main(int argc, CHAR8 *argv[])
>      fprintf(stderr, "Invalid option value, Device Path can't be NULL");
> 
>      return STATUS_ERROR;
> 
>    }
> 
> -  Str16 = (CHAR16 *)malloc(1024);
> 
> +  Str16 = (CHAR16 *)malloc((AsciiStrLen (Str) + 1) * sizeof (CHAR16));
> 
>    if (Str16 == NULL) {
> 
>      fprintf(stderr, "Resource, memory cannot be allocated");
> 
>      return STATUS_ERROR;
> 
> --
> 2.30.2.windows.1
> 
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#83769): https://edk2.groups.io/g/devel/message/83769
> Mute This Topic: https://groups.io/mt/87089392/4905953
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> [gaoliming@byosoft.com.cn]
> -=-=-=-=-=-=
> 





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#84042): https://edk2.groups.io/g/devel/message/84042
Mute This Topic: https://groups.io/mt/87282585/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel][PATCH] BaseTools: Increase the DevicePath length for support more PCD value.

Posted by Bob Feng 2 weeks, 5 days ago
This patch is good to me.

Reviewed-by: Bob Feng <bob.c.feng@intel.com>


-----Original Message-----
From: Jiang, Xiaolu <xiaolu.jiang@intel.com> 
Sent: Tuesday, November 16, 2021 9:42 AM
To: devel@edk2.groups.io
Cc: Jiang, Xiaolu <xiaolu.jiang@intel.com>; Feng, Bob C <bob.c.feng@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Chen, Christine <yuwei.chen@intel.com>
Subject: [edk2-devel][PATCH] BaseTools: Increase the DevicePath length for support more PCD value.

Currently the PCD Value only support 13 Guid,When use more 13 pcd will cause the build tool fail, Need calculate the required memory,then allocate it.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3718

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>

Signed-off-by: Xiaolu Jiang <xiaolu.jiang@intel.com>
---
 BaseTools/Source/C/DevicePath/DevicePath.c | 36 +++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c
index c4d224ed61..8a0f5f4e2a 100644
--- a/BaseTools/Source/C/DevicePath/DevicePath.c
+++ b/BaseTools/Source/C/DevicePath/DevicePath.c
@@ -144,6 +144,40 @@ Returns:
   *UniString = '\0'; } ++/**+  Returns the length of a Null-terminated ASCII string.++  This function returns the number of ASCII characters in the Null-terminated+  ASCII string specified by String.++  If Length > 0 and Destination is NULL, then ASSERT().+  If Length > 0 and Source is NULL, then ASSERT().+  If PcdMaximumAsciiStringLength is not zero and String contains more than+  PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,+  then ASSERT().++  @param  String  A pointer to a Null-terminated ASCII string.++  @return The length of String.++**/+UINTN+EFIAPI+AsciiStrLen (+  IN      CONST CHAR8               *String+  )+{+  UINTN                             Length;++  ASSERT (String != NULL);++  for (Length = 0; *String != '\0'; String++, Length++) {++  }+  return Length;+}+ int main(int argc, CHAR8 *argv[]) {   CHAR8 * Str;@@ -170,7 +204,7 @@ int main(int argc, CHAR8 *argv[])
     fprintf(stderr, "Invalid option value, Device Path can't be NULL");     return STATUS_ERROR;   }-  Str16 = (CHAR16 *)malloc(1024);+  Str16 = (CHAR16 *)malloc((AsciiStrLen (Str) + 1) * sizeof (CHAR16));   if (Str16 == NULL) {     fprintf(stderr, "Resource, memory cannot be allocated");     return STATUS_ERROR;-- 
2.30.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#83785): https://edk2.groups.io/g/devel/message/83785
Mute This Topic: https://groups.io/mt/87089392/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-