Skip to contentSkip to conversation

hexdump: Introduce debug APIs

PATCH In review Andy Shevchenko 3 participants 6 messages Nov 9, 2021 – Mar 30, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hexdump: Introduce debug APIs

debug_hex_dump() and debug_hex_dump_bytes() conditionally print the dump based on DEBUG definition.

---
 include/hexdump.h |  4 ++++
 lib/hexdump.c     | 60 ++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 56 insertions(+), 8 deletions(-)
include/hexdump.h +4 -0
index f2ca4793d699..390af4c8da1e 100644
@@ -147,6 +147,8 @@ int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize,
  */
 int print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
 		   int groupsize, const void *buf, size_t len, bool ascii);
+int debug_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
+		   int groupsize, const void *buf, size_t len, bool ascii);
 
 /**
  * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
@@ -162,5 +164,7 @@ int print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
  */
 void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
 			  const void *buf, size_t len);
+void debug_hex_dump_bytes(const char *prefix_str, int prefix_type,
+			  const void *buf, size_t len);
 
 #endif /* HEXDUMP_H */
lib/hexdump.c +52 -8

93 lines not on this page · raw message

Signature · 1 line
2.33.0
#1 lore raw

PATCH 2/2 x86: scu: Add a few debug messages to the driver

For some devices that have slightly different firmware implementation it's good to see what's going on when communicating with the SCU. Add a few debug messages for that purpose.

---
 arch/x86/lib/scu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/lib/scu.c +8 -0
index 90ef239bcd3d..c7274e064647 100644
@@ -11,6 +11,7 @@
  */
 #include <common.h>
 #include <dm.h>
+#include <hexdump.h>
 #include <regmap.h>
 #include <syscon.h>
 #include <asm/cpu.h>
@@ -48,6 +49,7 @@ struct scu {
  */
 static void scu_ipc_send_command(struct ipc_regs *regs, u32 cmd)
 {
+	debug("%s(): 0x%08x\n", __func__, cmd);
 	writel(cmd, &regs->cmd);
 }
 
@@ -92,12 +94,18 @@ static int scu_ipc_cmd(struct ipc_regs *regs, u32 cmd, u32 sub,
 	for (i = 0; i < inlen; i++)
 		writel(*in++, &regs->wbuf[i]);
 
+	debug_hex_dump("SCU in", DUMP_PREFIX_OFFSET, 16, 4, in, inlen * 4, false);
+
 	scu_ipc_send_command(regs, (inlen << 16) | (sub << 12) | cmd);
 	err = scu_ipc_check_status(regs);
 
 	if (!err) {
+		u32 *buf = out;
+
 		for (i = 0; i < outlen; i++)
 			*out++ = readl(&regs->rbuf[i]);
+
+		debug_hex_dump("SCU out", DUMP_PREFIX_OFFSET, 16, 4, buf, outlen * 4, false);
 	}
 
 	return err;
Signature · 1 line
2.33.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] x86: scu: Add a few debug messages to the driver

Quoted 9 lines · Andy Shevchenko

For some devices that have slightly different firmware implementation it's good to see what's going on when communicating with the SCU. Add a few debug messages for that purpose.

---
 arch/x86/lib/scu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
#3 lore raw
In reply to Andy Shevchenko

Hi Andy,

Quoted 9 lines · Andy Shevchenko

debug_hex_dump() and debug_hex_dump_bytes() conditionally print the dump based on DEBUG definition.

---
 include/hexdump.h |  4 ++++
 lib/hexdump.c     | 60 ++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 56 insertions(+), 8 deletions(-)

+Heinrich Schuchardt

Is it possible to resolve this in the header file? It is a bit odd to have to add DEBUG to hexdump.c in order to get debug output.

Note also the logging system so you can do

log(LOG_CATEGORY, dbg ? LOGL_DEBUG : LOGL_INFO, "fmt ...", ...)

Regards,
Simon

#4 lore raw
Quoted 6 lines · Simon Glass
Quoted 4 lines · Andy Shevchenko

debug_hex_dump() and debug_hex_dump_bytes() conditionally print the dump based on DEBUG definition.

Quoted 7 lines
Quoted 5 lines
---
 include/hexdump.h |  4 ++++
 lib/hexdump.c     | 60 ++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 56 insertions(+), 8 deletions(-)

+Heinrich Schuchardt

Heinrich, it's several months passed. What should we do?

Quoted 6 lines

Is it possible to resolve this in the header file? It is a bit odd to have to add DEBUG to hexdump.c in order to get debug output.

Note also the logging system so you can do

log(LOG_CATEGORY, dbg ? LOGL_DEBUG : LOGL_INFO, "fmt ...", ...)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Simon Glass
Quoted 9 lines · Andy Shevchenko

debug_hex_dump() and debug_hex_dump_bytes() conditionally print the dump based on DEBUG definition.

---
  include/hexdump.h |  4 ++++
  lib/hexdump.c     | 60 ++++++++++++++++++++++++++++++++++++++++-------
  2 files changed, 56 insertions(+), 8 deletions(-)
Quoted 3 lines
Quoted 1 line

+Heinrich Schuchardt

Heinrich, it's several months passed. What should we do?

The logging system was designed by Simon.

Quoted 8 lines
Quoted 7 lines

Is it possible to resolve this in the header file? It is a bit odd to have to add DEBUG to hexdump.c in order to get debug output.

Note also the logging system so you can do

log(LOG_CATEGORY, dbg ? LOGL_DEBUG : LOGL_INFO, "fmt ...", ...)

I would do something like below.

Then you can use the log command to switch debug output on and off.

Best regards

Heinrich

include/hexdump.h +0 -0
@@ -148,6 +148,19 @@ int hex_dump_to_buffer(const void *buf, size_t len,

int rowsize, int groupsize,
int print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
int groupsize, const void *buf, size_t len, bool ascii);

+
+int log_hex_dump(enum log_category_t cat, enum log_level_t level,
+ const char *prefix_str, int prefix_type, int rowsize,
+ int groupsize, const void *buf, size_t len, bool ascii);
+
+#define print_hex_dump(args...) ({ \
+ log_hex_dump(LOG_CATEGORY, LOGL_INFO, args); \
+ })
+
+#define debug_hex_dump(args...) ({ \
+ log_hex_dump(LOG_CATEGORY, LOGL_DEBUG, args); \
+ })
+
/**
* print_hex_dump_bytes - shorthand form of print_hex_dump() with
default params
* @prefix_str: string to prefix each line with;

lib/hexdump.c +4 -2
index 149c93ead8..eb77a9cf94 100644
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <hexdump.h>
+#include <log.h>
 #include <mapmem.h>
 #include <linux/ctype.h>
 #include <linux/compat.h>
@@ -125,8 +126,9 @@ overflow1:
 	return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1;
 }
 
-int print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
-		   int groupsize, const void *buf, size_t len, bool ascii)
+int log_hex_dump(enum log_category_t cat, enum log_level_t level,
+		 const char *prefix_str, int prefix_type, int rowsize,
+		 int groupsize, const void *buf, size_t len, bool ascii)
 {
 	const u8 *ptr = buf;
 	int i, linelen, remaining = len;
@@ -146,15 +148,17 @@ int print_hex_dump(const char *prefix_str, int

prefix_type, int rowsize,

switch (prefix_type) {
case DUMP_PREFIX_ADDRESS:
- printf("%s%0*lx: %s\n", prefix_str,
- IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8,
- (ulong)map_to_sysmem(ptr) + i, linebuf);
+ log(cat, level,

+			    "%s%0*lx: %s\n", prefix_str,
+			    IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8,
+			    (ulong)map_to_sysmem(ptr) + i, linebuf);

break;
case DUMP_PREFIX_OFFSET:
- printf("%s%.8x: %s\n", prefix_str, i, linebuf);
+ log(cat, level,
+ "%s%.8x: %s\n", prefix_str, i, linebuf);
break;
default:
- printf("%s%s\n", prefix_str, linebuf);
+ log(cat, level, "%s%s\n", prefix_str, linebuf);
break;
}
if (!IS_ENABLED(CONFIG_SPL_BUILD) && ctrlc())