mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] include: debug_ll: define puthexc_ll
@ 2022-10-19 12:38 Ahmad Fatoum
  2022-10-19 12:38 ` [PATCH 2/3] lib: hexdump: make available for PBL debugging Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2022-10-19 12:38 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

puthex_ll prints a single zero-padded unsigned long, which for a single
byte is not very readable, especially on 64-bit systems. Define
puthexc_ll() as well, which just accepts a byte and formats its nibbles
as hexadecimal characters.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/debug_ll.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/debug_ll.h b/include/debug_ll.h
index 735033b314cc..856a157bf52c 100644
--- a/include/debug_ll.h
+++ b/include/debug_ll.h
@@ -33,17 +33,25 @@ static inline void putc_ll(char value)
 	PUTC_LL(value);
 }
 
-static inline void puthex_ll(unsigned long value)
+static inline void puthexc_ll(unsigned char value)
 {
 	int i; unsigned char ch;
 
-	for (i = sizeof(unsigned long) * 2; i--; ) {
+	for (i = 2; i--; ) {
 		ch = ((value >> (i * 4)) & 0xf);
 		ch += (ch >= 10) ? 'a' - 10 : '0';
 		putc_ll(ch);
 	}
 }
 
+static inline void puthex_ll(unsigned long value)
+{
+	int i;
+
+	for (i = sizeof(unsigned long); i--; )
+		puthexc_ll(value >> (i * 8));
+}
+
 /*
  * Be careful with puts_ll, it only works if the binary is running at the
  * link address which often is not the case during early startup. If in doubt
@@ -66,6 +74,10 @@ static inline void putc_ll(char value)
 {
 }
 
+static inline void puthexc_ll(unsigned char value)
+{
+}
+
 static inline void puthex_ll(unsigned long value)
 {
 }
-- 
2.30.2




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

* [PATCH 2/3] lib: hexdump: make available for PBL debugging
  2022-10-19 12:38 [PATCH 1/3] include: debug_ll: define puthexc_ll Ahmad Fatoum
@ 2022-10-19 12:38 ` Ahmad Fatoum
  2022-10-19 12:38 ` [PATCH 3/3] pbl: decomp: print mismatched hashes on one line each Ahmad Fatoum
  2022-11-02  8:26 ` [PATCH 1/3] include: debug_ll: define puthexc_ll Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2022-10-19 12:38 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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@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




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

* [PATCH 3/3] pbl: decomp: print mismatched hashes on one line each
  2022-10-19 12:38 [PATCH 1/3] include: debug_ll: define puthexc_ll Ahmad Fatoum
  2022-10-19 12:38 ` [PATCH 2/3] lib: hexdump: make available for PBL debugging Ahmad Fatoum
@ 2022-10-19 12:38 ` Ahmad Fatoum
  2022-11-02  8:26 ` [PATCH 1/3] include: debug_ll: define puthexc_ll Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2022-10-19 12:38 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

With DEBUG_LL enabled, hashes are printed to show mismatches, but each
byte is padded with 6 or 14 zeroes and has a line just for itself.
Rework this, so it now looks a lot cleaner:

  CH 40e941dfcf53087b86e549fbc279cbc1d4fd87c64febb42af6324c5b3ec64e03
  IH 3aa627d34b97f4a6af6a4ebf022236dc4b025c5902296b694a65eb6b92f8d66d

While at it, print a hexdump of the first 64 bytes of the buffer
that could not be verified. This is only printed when DEBUG is
enabled and serves as a first aid to debugging as verification failure
is not an expected occurrence with firmware baked into barebox PBL.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 pbl/decomp.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/pbl/decomp.c b/pbl/decomp.c
index 553895bac5e8..ebdf81ddfbe5 100644
--- a/pbl/decomp.c
+++ b/pbl/decomp.c
@@ -70,20 +70,20 @@ int pbl_barebox_verify(const void *compressed_start, unsigned int len,
 	sha256_update(&d, compressed_start, len);
 	sha256_final(&d, computed_hash);
 	if (IS_ENABLED(CONFIG_DEBUG_LL)) {
-		putc_ll('C');
-		putc_ll('H');
-		putc_ll('\n');
-		for (i = 0; i < SHA256_DIGEST_SIZE; i++) {
-			puthex_ll(computed_hash[i]);
-			putc_ll('\n');
-		}
-		putc_ll('I');
-		putc_ll('H');
+		puts_ll("CH ");
+
+		for (i = 0; i < SHA256_DIGEST_SIZE; i++)
+			puthexc_ll(computed_hash[i]);
+
+		puts_ll("\nIH ");
+
+		for (i = 0; i < SHA256_DIGEST_SIZE; i++)
+			puthexc_ll(char_hash[i]);
+
 		putc_ll('\n');
-		for (i = 0; i < SHA256_DIGEST_SIZE; i++) {
-			puthex_ll(char_hash[i]);
-			putc_ll('\n');
-		}
+
+		pr_debug("Hexdump of first 64 bytes of %u\n", len);
+		print_hex_dump_bytes("", DUMP_PREFIX_ADDRESS, compressed_start, 64);
 	}
 
 	return memcmp(hash, computed_hash, SHA256_DIGEST_SIZE);
-- 
2.30.2




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

* Re: [PATCH 1/3] include: debug_ll: define puthexc_ll
  2022-10-19 12:38 [PATCH 1/3] include: debug_ll: define puthexc_ll Ahmad Fatoum
  2022-10-19 12:38 ` [PATCH 2/3] lib: hexdump: make available for PBL debugging Ahmad Fatoum
  2022-10-19 12:38 ` [PATCH 3/3] pbl: decomp: print mismatched hashes on one line each Ahmad Fatoum
@ 2022-11-02  8:26 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2022-11-02  8:26 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Wed, Oct 19, 2022 at 02:38:15PM +0200, Ahmad Fatoum wrote:
> puthex_ll prints a single zero-padded unsigned long, which for a single
> byte is not very readable, especially on 64-bit systems. Define
> puthexc_ll() as well, which just accepts a byte and formats its nibbles
> as hexadecimal characters.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  include/debug_ll.h | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/include/debug_ll.h b/include/debug_ll.h
> index 735033b314cc..856a157bf52c 100644
> --- a/include/debug_ll.h
> +++ b/include/debug_ll.h
> @@ -33,17 +33,25 @@ static inline void putc_ll(char value)
>  	PUTC_LL(value);
>  }
>  
> -static inline void puthex_ll(unsigned long value)
> +static inline void puthexc_ll(unsigned char value)
>  {
>  	int i; unsigned char ch;
>  
> -	for (i = sizeof(unsigned long) * 2; i--; ) {
> +	for (i = 2; i--; ) {
>  		ch = ((value >> (i * 4)) & 0xf);
>  		ch += (ch >= 10) ? 'a' - 10 : '0';
>  		putc_ll(ch);
>  	}
>  }
>  
> +static inline void puthex_ll(unsigned long value)
> +{
> +	int i;
> +
> +	for (i = sizeof(unsigned long); i--; )
> +		puthexc_ll(value >> (i * 8));
> +}
> +
>  /*
>   * Be careful with puts_ll, it only works if the binary is running at the
>   * link address which often is not the case during early startup. If in doubt
> @@ -66,6 +74,10 @@ static inline void putc_ll(char value)
>  {
>  }
>  
> +static inline void puthexc_ll(unsigned char value)
> +{
> +}
> +
>  static inline void puthex_ll(unsigned long value)
>  {
>  }
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

end of thread, other threads:[~2022-11-02  8:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 12:38 [PATCH 1/3] include: debug_ll: define puthexc_ll Ahmad Fatoum
2022-10-19 12:38 ` [PATCH 2/3] lib: hexdump: make available for PBL debugging Ahmad Fatoum
2022-10-19 12:38 ` [PATCH 3/3] pbl: decomp: print mismatched hashes on one line each Ahmad Fatoum
2022-11-02  8:26 ` [PATCH 1/3] include: debug_ll: define puthexc_ll Sascha Hauer

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