diff options
author | Simon Glass <sjg@chromium.org> | 2021-05-08 07:00:03 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-06-08 11:39:09 -0400 |
commit | 5d6d2b88389a99c9e20618593e64a9dd74862c8a (patch) | |
tree | ec4b3d88f4d0f8b4a8b1060823a28ddb07ad72ea /lib | |
parent | 19edf139e900ed61825b32bc7a261e5f6606b8b1 (diff) | |
download | u-boot-5d6d2b88389a99c9e20618593e64a9dd74862c8a.tar.gz |
hexdump: Support any rowsize
At present print_hex_dump() only supports either 16- or 32-byte lines.
With U-Boot we want to support any line length up to a maximum of 64.
Update the function to support this, with 0 defaulting to 16, as with
print_buffer().
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hexdump.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/hexdump.c b/lib/hexdump.c index a76ea707b6..a56e108164 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -16,6 +16,8 @@ #include <linux/log2.h> #include <asm/unaligned.h> +#define MAX_LINE_LENGTH_BYTES 64 + const char hex_asc[] = "0123456789abcdef"; const char hex_asc_upper[] = "0123456789ABCDEF"; @@ -30,8 +32,10 @@ int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, int ascii_column; int ret; - if (rowsize != 16 && rowsize != 32) + if (!rowsize) rowsize = 16; + else + rowsize = min(rowsize, MAX_LINE_LENGTH_BYTES); if (len > rowsize) /* limit to one line at a time */ len = rowsize; @@ -126,10 +130,12 @@ void print_hex_dump(const char *prefix_str, int prefix_type, int rowsize, { const u8 *ptr = buf; int i, linelen, remaining = len; - char linebuf[32 * 3 + 2 + 32 + 1]; + char linebuf[MAX_LINE_LENGTH_BYTES * 3 + 2 + MAX_LINE_LENGTH_BYTES + 1]; - if (rowsize != 16 && rowsize != 32) + if (!rowsize) rowsize = 16; + else + rowsize = min(rowsize, MAX_LINE_LENGTH_BYTES); for (i = 0; i < len; i += rowsize) { linelen = min(remaining, rowsize); |