[PATCH 2/3] lib: hexdump: make available for PBL debugging

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Oct 19 05:38:16 PDT 2022


While we have puthexc_ll() for PBL use, for quick debugging or for
debug prints with PBL_CONSOLE enabled, print_hex_dump_bytes() can
come in handy. Build it for optional use in PBL as well.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 lib/Makefile  |  2 +-
 lib/hexdump.c | 12 +++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/Makefile b/lib/Makefile
index 2308117fbdab..4717b8aec364 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -61,7 +61,7 @@ obj-y			+= wchar.o
 obj-y			+= libfile.o
 obj-y			+= bitmap.o
 obj-y			+= gcd.o
-obj-y			+= hexdump.o
+obj-pbl-y		+= hexdump.o
 obj-$(CONFIG_FONTS)	+= fonts/
 obj-$(CONFIG_BAREBOX_LOGO)     += logo/
 obj-y			+= reed_solomon/
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 033e1d28d171..a71474a55348 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -10,6 +10,7 @@
 #include <linux/log2.h>
 #include <linux/printk.h>
 #include <asm/unaligned.h>
+#include <pbl.h>
 
 const char hex_asc[] = "0123456789abcdef";
 EXPORT_SYMBOL(hex_asc);
@@ -243,9 +244,13 @@ void dev_print_hex_dump(struct device_d *dev, const char *level,
 	const u8 *ptr = buf;
 	int i, linelen, remaining = len;
 	unsigned char linebuf[32 * 3 + 2 + 32 + 1];
-	char *name;
+	char *name = "";
 
-	name = basprintf("%s%s", dev ? dev_name(dev) : "", dev ? ": " : "");
+	if (IN_PBL)
+		dev = NULL;
+
+	if (dev)
+		name = basprintf("%s: ", dev_name(dev));
 
 	if (rowsize != 16 && rowsize != 32)
 		rowsize = 16;
@@ -273,6 +278,7 @@ void dev_print_hex_dump(struct device_d *dev, const char *level,
 		}
 	}
 
-	free(name);
+	if (dev)
+		free(name);
 }
 EXPORT_SYMBOL(dev_print_hex_dump);
-- 
2.30.2




More information about the barebox mailing list