[edk2-devel] [PATCH v2] RedfishPkg/RedfishDebugLib: add function to print buffer.

Nickle Wang via groups.io posted 1 patch 3 months, 3 weeks ago
Failed in applying to current master (apply log)
RedfishPkg/Include/Library/RedfishDebugLib.h  | 20 ++++++++-
.../Library/RedfishDebugLib/RedfishDebugLib.c | 45 +++++++++++++++++--
2 files changed, 61 insertions(+), 4 deletions(-)
[edk2-devel] [PATCH v2] RedfishPkg/RedfishDebugLib: add function to print buffer.
Posted by Nickle Wang via groups.io 3 months, 3 weeks ago
Introduce DumpBuffer function to print the buffer content. This helps
developer to debug Redfish issue.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
---
 RedfishPkg/Include/Library/RedfishDebugLib.h  | 20 ++++++++-
 .../Library/RedfishDebugLib/RedfishDebugLib.c | 45 +++++++++++++++++--
 2 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h b/RedfishPkg/Include/Library/RedfishDebugLib.h
index 5f75bad12a..3430cf1d14 100644
--- a/RedfishPkg/Include/Library/RedfishDebugLib.h
+++ b/RedfishPkg/Include/Library/RedfishDebugLib.h
@@ -1,7 +1,7 @@
 /** @file
   This file defines the Redfish debug library interface.
 
-  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -138,4 +138,22 @@ DumpIpv4Address (
   IN EFI_IPv4_ADDRESS  *Ipv4Address
   );
 
+/**
+  Debug output raw data buffer.
+
+  @param[in]    ErrorLevel  DEBUG macro error level
+  @param[in]    Buffer      Debug output data buffer.
+  @param[in]    BufferSize  The size of Buffer in byte.
+
+  @retval EFI_SUCCESS             Debug dump finished.
+  @retval EFI_INVALID_PARAMETER   Buffer is NULL.
+
+**/
+EFI_STATUS
+DumpBuffer (
+  IN  UINTN  ErrorLevel,
+  IN  UINT8  *Buffer,
+  IN  UINTN  BufferSize
+  );
+
 #endif
diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
index efa9a5ca13..3728f51213 100644
--- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
+++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
@@ -1,7 +1,7 @@
 /** @file
   Redfish debug library to debug Redfish application.
 
-  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -19,8 +19,9 @@
 #define IS_EMPTY_STRING(a)  ((a) == NULL || (a)[0] == '\0')
 #endif
 
-#define REDFISH_JSON_STRING_LENGTH  200
-#define REDFISH_JSON_OUTPUT_FORMAT  (EDKII_JSON_COMPACT | EDKII_JSON_INDENT(2))
+#define REDFISH_JSON_STRING_LENGTH          200
+#define REDFISH_JSON_OUTPUT_FORMAT          (EDKII_JSON_COMPACT | EDKII_JSON_INDENT(2))
+#define REDFISH_PRINT_BUFFER_BYTES_PER_ROW  16
 
 /**
   Debug print the value of StatementValue.
@@ -366,3 +367,41 @@ DumpIpv4Address (
 
   return EFI_SUCCESS;
 }
+
+/**
+  Debug output raw data buffer.
+
+  @param[in]    ErrorLevel  DEBUG macro error level
+  @param[in]    Buffer      Debug output data buffer.
+  @param[in]    BufferSize  The size of Buffer in byte.
+
+  @retval EFI_SUCCESS             Debug dump finished.
+  @retval EFI_INVALID_PARAMETER   Buffer is NULL.
+
+**/
+EFI_STATUS
+DumpBuffer (
+  IN  UINTN  ErrorLevel,
+  IN  UINT8  *Buffer,
+  IN  UINTN  BufferSize
+  )
+{
+  UINTN  Index;
+
+  if (Buffer == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DEBUG ((ErrorLevel, "Address: 0x%p size: %d\n", Buffer, BufferSize));
+  for (Index = 0; Index < BufferSize; Index++) {
+    if (Index % REDFISH_PRINT_BUFFER_BYTES_PER_ROW == 0) {
+      DEBUG ((ErrorLevel, "\n%04X: ", Index));
+    }
+
+    DEBUG ((ErrorLevel, "%02X ", Buffer[Index]));
+  }
+
+  DEBUG ((ErrorLevel, "\n"));
+
+  return EFI_SUCCESS;
+}
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113439): https://edk2.groups.io/g/devel/message/113439
Mute This Topic: https://groups.io/mt/103617651/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v2] RedfishPkg/RedfishDebugLib: add function to print buffer.
Posted by Chang, Abner via groups.io 3 months, 3 weeks ago
[AMD Official Use Only - General]

Reviewed-by: Abner Chang <abner.chang@amd.com>

> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Tuesday, January 9, 2024 7:13 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>; Nick Ramirez <nramirez@nvidia.com>
> Subject: [PATCH v2] RedfishPkg/RedfishDebugLib: add function to print
> buffer.
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Introduce DumpBuffer function to print the buffer content. This helps
> developer to debug Redfish issue.
>
> Signed-off-by: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> Cc: Nick Ramirez <nramirez@nvidia.com>
> ---
>  RedfishPkg/Include/Library/RedfishDebugLib.h  | 20 ++++++++-
>  .../Library/RedfishDebugLib/RedfishDebugLib.c | 45 +++++++++++++++++--
>  2 files changed, 61 insertions(+), 4 deletions(-)
>
> diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h
> b/RedfishPkg/Include/Library/RedfishDebugLib.h
> index 5f75bad12a..3430cf1d14 100644
> --- a/RedfishPkg/Include/Library/RedfishDebugLib.h
> +++ b/RedfishPkg/Include/Library/RedfishDebugLib.h
> @@ -1,7 +1,7 @@
>  /** @file
>    This file defines the Redfish debug library interface.
>
> -  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
> @@ -138,4 +138,22 @@ DumpIpv4Address (
>    IN EFI_IPv4_ADDRESS  *Ipv4Address
>    );
>
> +/**
> +  Debug output raw data buffer.
> +
> +  @param[in]    ErrorLevel  DEBUG macro error level
> +  @param[in]    Buffer      Debug output data buffer.
> +  @param[in]    BufferSize  The size of Buffer in byte.
> +
> +  @retval EFI_SUCCESS             Debug dump finished.
> +  @retval EFI_INVALID_PARAMETER   Buffer is NULL.
> +
> +**/
> +EFI_STATUS
> +DumpBuffer (
> +  IN  UINTN  ErrorLevel,
> +  IN  UINT8  *Buffer,
> +  IN  UINTN  BufferSize
> +  );
> +
>  #endif
> diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
> b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
> index efa9a5ca13..3728f51213 100644
> --- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
> +++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Redfish debug library to debug Redfish application.
>
> -  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
> @@ -19,8 +19,9 @@
>  #define IS_EMPTY_STRING(a)  ((a) == NULL || (a)[0] == '\0')
>  #endif
>
> -#define REDFISH_JSON_STRING_LENGTH  200
> -#define REDFISH_JSON_OUTPUT_FORMAT  (EDKII_JSON_COMPACT |
> EDKII_JSON_INDENT(2))
> +#define REDFISH_JSON_STRING_LENGTH          200
> +#define REDFISH_JSON_OUTPUT_FORMAT          (EDKII_JSON_COMPACT |
> EDKII_JSON_INDENT(2))
> +#define REDFISH_PRINT_BUFFER_BYTES_PER_ROW  16
>
>  /**
>    Debug print the value of StatementValue.
> @@ -366,3 +367,41 @@ DumpIpv4Address (
>
>    return EFI_SUCCESS;
>  }
> +
> +/**
> +  Debug output raw data buffer.
> +
> +  @param[in]    ErrorLevel  DEBUG macro error level
> +  @param[in]    Buffer      Debug output data buffer.
> +  @param[in]    BufferSize  The size of Buffer in byte.
> +
> +  @retval EFI_SUCCESS             Debug dump finished.
> +  @retval EFI_INVALID_PARAMETER   Buffer is NULL.
> +
> +**/
> +EFI_STATUS
> +DumpBuffer (
> +  IN  UINTN  ErrorLevel,
> +  IN  UINT8  *Buffer,
> +  IN  UINTN  BufferSize
> +  )
> +{
> +  UINTN  Index;
> +
> +  if (Buffer == NULL) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  DEBUG ((ErrorLevel, "Address: 0x%p size: %d\n", Buffer, BufferSize));
> +  for (Index = 0; Index < BufferSize; Index++) {
> +    if (Index % REDFISH_PRINT_BUFFER_BYTES_PER_ROW == 0) {
> +      DEBUG ((ErrorLevel, "\n%04X: ", Index));
> +    }
> +
> +    DEBUG ((ErrorLevel, "%02X ", Buffer[Index]));
> +  }
> +
> +  DEBUG ((ErrorLevel, "\n"));
> +
> +  return EFI_SUCCESS;
> +}
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113509): https://edk2.groups.io/g/devel/message/113509
Mute This Topic: https://groups.io/mt/103617651/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v2] RedfishPkg/RedfishDebugLib: add function to print buffer.
Posted by Igor Kulchytskyy via groups.io 3 months, 3 weeks ago
Reviewed-by: Igor Kulchytskyy <igork@ami.com>

Regards,
Igor

-----Original Message-----
From: Nickle Wang <nicklew@nvidia.com>
Sent: Tuesday, January 9, 2024 6:13 AM
To: devel@edk2.groups.io
Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy <igork@ami.com>; Nick Ramirez <nramirez@nvidia.com>
Subject: [EXTERNAL] [PATCH v2] RedfishPkg/RedfishDebugLib: add function to print buffer.


**CAUTION: The e-mail below is from an external source. Please exercise caution before opening attachments, clicking links, or following guidance.**

Introduce DumpBuffer function to print the buffer content. This helps
developer to debug Redfish issue.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
---
 RedfishPkg/Include/Library/RedfishDebugLib.h  | 20 ++++++++-
 .../Library/RedfishDebugLib/RedfishDebugLib.c | 45 +++++++++++++++++--
 2 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h b/RedfishPkg/Include/Library/RedfishDebugLib.h
index 5f75bad12a..3430cf1d14 100644
--- a/RedfishPkg/Include/Library/RedfishDebugLib.h
+++ b/RedfishPkg/Include/Library/RedfishDebugLib.h
@@ -1,7 +1,7 @@
 /** @file
   This file defines the Redfish debug library interface.

-  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -138,4 +138,22 @@ DumpIpv4Address (
   IN EFI_IPv4_ADDRESS  *Ipv4Address
   );

+/**
+  Debug output raw data buffer.
+
+  @param[in]    ErrorLevel  DEBUG macro error level
+  @param[in]    Buffer      Debug output data buffer.
+  @param[in]    BufferSize  The size of Buffer in byte.
+
+  @retval EFI_SUCCESS             Debug dump finished.
+  @retval EFI_INVALID_PARAMETER   Buffer is NULL.
+
+**/
+EFI_STATUS
+DumpBuffer (
+  IN  UINTN  ErrorLevel,
+  IN  UINT8  *Buffer,
+  IN  UINTN  BufferSize
+  );
+
 #endif
diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
index efa9a5ca13..3728f51213 100644
--- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
+++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
@@ -1,7 +1,7 @@
 /** @file
   Redfish debug library to debug Redfish application.

-  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -19,8 +19,9 @@
 #define IS_EMPTY_STRING(a)  ((a) == NULL || (a)[0] == '\0')
 #endif

-#define REDFISH_JSON_STRING_LENGTH  200
-#define REDFISH_JSON_OUTPUT_FORMAT  (EDKII_JSON_COMPACT | EDKII_JSON_INDENT(2))
+#define REDFISH_JSON_STRING_LENGTH          200
+#define REDFISH_JSON_OUTPUT_FORMAT          (EDKII_JSON_COMPACT | EDKII_JSON_INDENT(2))
+#define REDFISH_PRINT_BUFFER_BYTES_PER_ROW  16

 /**
   Debug print the value of StatementValue.
@@ -366,3 +367,41 @@ DumpIpv4Address (

   return EFI_SUCCESS;
 }
+
+/**
+  Debug output raw data buffer.
+
+  @param[in]    ErrorLevel  DEBUG macro error level
+  @param[in]    Buffer      Debug output data buffer.
+  @param[in]    BufferSize  The size of Buffer in byte.
+
+  @retval EFI_SUCCESS             Debug dump finished.
+  @retval EFI_INVALID_PARAMETER   Buffer is NULL.
+
+**/
+EFI_STATUS
+DumpBuffer (
+  IN  UINTN  ErrorLevel,
+  IN  UINT8  *Buffer,
+  IN  UINTN  BufferSize
+  )
+{
+  UINTN  Index;
+
+  if (Buffer == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DEBUG ((ErrorLevel, "Address: 0x%p size: %d\n", Buffer, BufferSize));
+  for (Index = 0; Index < BufferSize; Index++) {
+    if (Index % REDFISH_PRINT_BUFFER_BYTES_PER_ROW == 0) {
+      DEBUG ((ErrorLevel, "\n%04X: ", Index));
+    }
+
+    DEBUG ((ErrorLevel, "%02X ", Buffer[Index]));
+  }
+
+  DEBUG ((ErrorLevel, "\n"));
+
+  return EFI_SUCCESS;
+}
--
2.34.1

-The information contained in this message may be confidential and proprietary to American Megatrends (AMI). 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.


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