Skip to content

Commit 28386b6

Browse files
abrodkinkeveryang
authored andcommitted
UPSTREAM: lib: Add hexdump
Often during debugging session it's very interesting to see what data we were dealing with. For example what we write or read to/from memory or peripherals. This change introduces functions that allow to dump binary data with one simple function invocation like: ------------------->8---------------- print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len); ------------------->8---------------- which gives us the following: ------------------->8---------------- 00000000: f2 b7 c9 88 62 61 75 64 72 61 74 65 3d 31 31 35 ....baudrate=115 00000010: 32 30 30 00 62 6f 6f 74 61 72 67 73 3d 63 6f 6e 200.bootargs=con 00000020: 73 6f 6c 65 3d 74 74 79 53 33 2c 31 31 35 32 30 sole=ttyS3,11520 00000030: 30 6e 38 00 62 6f 6f 74 64 65 6c 61 79 3d 33 00 0n8.bootdelay=3. 00000040: 62 6f 6f 74 66 69 6c 65 3d 75 49 6d 61 67 65 00 bootfile=uImage. 00000050: 66 64 74 63 6f 6e 74 72 6f 6c 61 64 64 72 3d 39 fdtcontroladdr=9 00000060: 66 66 62 31 62 61 30 00 6c 6f 61 64 61 64 64 72 ffb1ba0.loadaddr 00000070: 3d 30 78 38 32 30 30 30 30 30 30 00 73 74 64 65 =0x82000000.stde 00000080: 72 72 3d 73 65 72 69 61 6c 30 40 65 30 30 32 32 rr=serial0@e0022 00000090: 30 30 30 00 73 74 64 69 6e 3d 73 65 72 69 61 6c 000.stdin=serial 000000a0: 30 40 65 30 30 32 32 30 30 30 00 73 74 64 6f 75 [email protected] 000000b0: 74 3d 73 65 72 69 61 6c 30 40 65 30 30 32 32 30 t=serial0@e00220 000000c0: 30 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00.............. ... ------------------->8---------------- Source of hexdump.c was copied from Linux kernel v4.7-rc2. Signed-off-by: Alexey Brodkin <[email protected]> Cc: Anatolij Gustschin <[email protected]> Cc: Mario Six <[email protected]> Cc: Simon Glass <[email protected]> Cc: Tom Rini <[email protected]> Cc: Stefan Roese <[email protected]> Change-Id: I038b41f51d45d1b853da499578bf8ef384a63730 Signed-off-by: Jon Lin <[email protected]> (cherry picked from commit f8c987f)
1 parent 5296618 commit 28386b6

File tree

16 files changed

+378
-35
lines changed

16 files changed

+378
-35
lines changed

common/edid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <edid.h>
1919
#include <errno.h>
2020
#include <fdtdec.h>
21+
#include <hexdump.h>
2122
#include <malloc.h>
2223
#include <linux/compat.h>
2324
#include <linux/ctype.h>
@@ -4917,7 +4918,7 @@ bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
49174918
debug("EDID block is all zeroes\n");
49184919
} else {
49194920
debug("Raw EDID:\n");
4920-
print_hex_dump(KERN_ERR, " \t", DUMP_PREFIX_NONE, 16, 1,
4921+
print_hex_dump("", DUMP_PREFIX_NONE, 16, 1,
49214922
raw_edid, EDID_SIZE, false);
49224923
}
49234924
}

drivers/mtd/ubi/attach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
790790
ubi_dump_vid_hdr(vid_hdr);
791791
pr_err("hexdump of PEB %d offset %d, length %d",
792792
pnum, ubi->leb_start, ubi->leb_size);
793-
ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
793+
ubi_dbg_print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1,
794794
ubi->peb_buf, ubi->leb_size, 1);
795795
err = 1;
796796

drivers/mtd/ubi/debug.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Author: Artem Bityutskiy (Битюцкий Артём)
77
*/
88

9+
#include <hexdump.h>
910
#include <ubi_uboot.h>
1011
#include "ubi.h"
1112
#ifndef __UBOOT__
@@ -40,7 +41,7 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
4041

4142
ubi_msg(ubi, "dumping %d bytes of data from PEB %d, offset %d",
4243
len, pnum, offset);
43-
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
44+
print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
4445
out:
4546
vfree(buf);
4647
return;
@@ -61,7 +62,7 @@ void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
6162
pr_err("\timage_seq %d\n", be32_to_cpu(ec_hdr->image_seq));
6263
pr_err("\thdr_crc %#08x\n", be32_to_cpu(ec_hdr->hdr_crc));
6364
pr_err("erase counter header hexdump:\n");
64-
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
65+
print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1,
6566
ec_hdr, UBI_EC_HDR_SIZE, 1);
6667
}
6768

@@ -86,7 +87,7 @@ void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
8687
(unsigned long long)be64_to_cpu(vid_hdr->sqnum));
8788
pr_err("\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc));
8889
pr_err("Volume identifier header hexdump:\n");
89-
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
90+
print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1,
9091
vid_hdr, UBI_VID_HDR_SIZE, 1);
9192
}
9293

drivers/mtd/ubi/debug.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
1717
#include <linux/random.h>
1818
#endif
1919

20+
#include <hexdump.h>
21+
2022
#define ubi_assert(expr) do { \
2123
if (unlikely(!(expr))) { \
2224
pr_crit("UBI assert failed in %s at %u (pid %d)\n", \
@@ -25,8 +27,8 @@ void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
2527
} \
2628
} while (0)
2729

28-
#define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \
29-
print_hex_dump(l, ps, pt, r, g, b, len, a)
30+
#define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \
31+
print_hex_dump(ps, pt, r, g, b, len, a)
3032

3133
#define ubi_dbg_msg(type, fmt, ...) \
3234
pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \

drivers/mtd/ubi/io.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include <linux/err.h>
7979
#include <linux/slab.h>
8080
#else
81+
#include <hexdump.h>
8182
#include <ubi_uboot.h>
8283
#endif
8384

@@ -1353,11 +1354,11 @@ static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum,
13531354
ubi_msg(ubi, "data differ at position %d", i);
13541355
ubi_msg(ubi, "hex dump of the original buffer from %d to %d",
13551356
i, i + dump_len);
1356-
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1357+
print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1,
13571358
buf + i, dump_len, 1);
13581359
ubi_msg(ubi, "hex dump of the read buffer from %d to %d",
13591360
i, i + dump_len);
1360-
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1361+
print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1,
13611362
buf1 + i, dump_len, 1);
13621363
dump_stack();
13631364
err = -EINVAL;
@@ -1419,7 +1420,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
14191420
fail:
14201421
ubi_err(ubi, "self-check failed for PEB %d", pnum);
14211422
ubi_msg(ubi, "hex dump of the %d-%d region", offset, offset + len);
1422-
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
1423+
print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
14231424
err = -EINVAL;
14241425
error:
14251426
dump_stack();

drivers/usb/gadget/f_mass_storage.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
/* #define DUMP_MSGS */
242242

243243
#include <config.h>
244+
#include <hexdump.h>
244245
#include <malloc.h>
245246
#include <common.h>
246247
#include <console.h>

drivers/usb/gadget/storage_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
# define dump_msg(fsg, label, buf, length) do { \
126126
if (length < 512) { \
127127
DBG(fsg, "%s, length %u:\n", label, length); \
128-
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
128+
print_hex_dump("", DUMP_PREFIX_OFFSET, \
129129
16, 1, buf, length, 0); \
130130
} \
131131
} while (0)
@@ -140,7 +140,7 @@
140140
# ifdef VERBOSE_DEBUG
141141

142142
# define dump_cdb(fsg) \
143-
print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
143+
print_hex_dump("SCSI CDB: ", DUMP_PREFIX_NONE, \
144144
16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
145145

146146
# else

examples/api/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ OBJ-y += libgenwrap.o
3131
EXT_COBJ-y += lib/crc32.o
3232
EXT_COBJ-y += lib/ctype.o
3333
EXT_COBJ-y += lib/div64.o
34+
EXT_COBJ-y += lib/hexdump.o
3435
EXT_COBJ-y += lib/string.o
3536
EXT_COBJ-y += lib/time.o
3637
EXT_COBJ-y += lib/vsprintf.o

fs/ubifs/debug.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* various local functions of those subsystems.
1717
*/
1818

19+
#include <hexdump.h>
20+
1921
#ifndef __UBOOT__
2022
#include <linux/module.h>
2123
#include <linux/debugfs.h>
@@ -308,7 +310,7 @@ void ubifs_dump_node(const struct ubifs_info *c, const void *node)
308310
/* If the magic is incorrect, just hexdump the first bytes */
309311
if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) {
310312
pr_err("Not a node, first %zu bytes:", UBIFS_CH_SZ);
311-
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 32, 1,
313+
print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1,
312314
(void *)node, UBIFS_CH_SZ, 1);
313315
return;
314316
}
@@ -483,7 +485,7 @@ void ubifs_dump_node(const struct ubifs_info *c, const void *node)
483485
(int)le16_to_cpu(dn->compr_type));
484486
pr_err("\tdata size %d\n", dlen);
485487
pr_err("\tdata:\n");
486-
print_hex_dump(KERN_ERR, "\t", DUMP_PREFIX_OFFSET, 32, 1,
488+
print_hex_dump("\t", DUMP_PREFIX_OFFSET, 32, 1,
487489
(void *)&dn->data, dlen, 0);
488490
break;
489491
}

fs/ubifs/scan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#ifdef __UBOOT__
20+
#include <hexdump.h>
2021
#include <linux/err.h>
2122
#endif
2223
#include "ubifs.h"
@@ -237,7 +238,7 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
237238
if (len > 8192)
238239
len = 8192;
239240
ubifs_err(c, "first %d bytes from LEB %d:%d", len, lnum, offs);
240-
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 4, buf, len, 1);
241+
print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 4, buf, len, 1);
241242
}
242243

243244
/**

0 commit comments

Comments
 (0)