diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-02-02 20:40:57 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-02-04 11:11:35 +0100 |
commit | 582523142975c7993af81ff8007ff8e0e96f6dee (patch) | |
tree | 42e3e840486d70f317274b60d9f44f0ca3090511 /include | |
parent | 576d407abb53cf73e211f5eb67bf6c1e2d7cf731 (diff) | |
download | barebox-582523142975c7993af81ff8007ff8e0e96f6dee.tar.gz barebox-582523142975c7993af81ff8007ff8e0e96f6dee.tar.xz |
printk: port over Linux print_hex_dump_bytes/print_hex_dump_debug
print_hex_dump in barebox always prints a hex dump. Most users use
it for debugging though, so import Linux helpers to do so to cut
down on the #ifdef DEBUG.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r-- | include/printk.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/printk.h b/include/printk.h index 9941ddb12c..f92e477298 100644 --- a/include/printk.h +++ b/include/printk.h @@ -160,4 +160,32 @@ extern void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii); +#if LOGLEVEL <= MSG_DEBUG +#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) +#else +static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, + int rowsize, int groupsize, + const void *buf, size_t len, bool ascii) +{ +} +#endif + +/** + * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params + * @prefix_str: string to prefix each line with; + * caller supplies trailing spaces for alignment if desired + * @prefix_type: controls whether prefix of an offset, address, or none + * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) + * @buf: data blob to dump + * @len: number of bytes in the @buf + * + * Calls print_hex_dump(), with log level of KERN_DEBUG, + * rowsize of 16, groupsize of 1, and ASCII output included. + */ +#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ + print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true) + #endif |