[coreboot-gerrit] New patch to review for coreboot: 25ff80b lib/hexdump: Enable format match for hexdump -C
Leroy P Leahy (leroy.p.leahy@intel.com)
gerrit at coreboot.org
Fri May 15 00:42:46 CEST 2015
Leroy P Leahy (leroy.p.leahy at intel.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10207
-gerrit
commit 25ff80b076d1cc333536a270536b4d0343733f97
Author: Lee Leahy <leroy.p.leahy at intel.com>
Date: Thu May 14 14:50:42 2015 -0700
lib/hexdump: Enable format match for hexdump -C
Support formatting the output to match the Ubuntu bash command "hexdump
-C file". Use the following to display output in this format.
hexdump_bounds(buffer, size, buffer, ' ', (1 << 8), "|", "*", 0, 1);
printk(BIOS_DEBUG, "%p\n", (uint8_t *)size);
BRANCH=none
BUG=None
TEST=Build and run on cyan
Change-Id: Ia46aeed056b12abbadf8205b044944385d9410e1
Signed-off-by: Lee Leahy <leroy.p.leahy at intel.com>
---
src/include/lib.h | 4 ++++
src/lib/hexdump.c | 43 +++++++++++++++++++++++++++++++++----------
2 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/src/include/lib.h b/src/include/lib.h
index aa8fe4d..e72d331 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -46,6 +46,10 @@ int primitive_memtest(uintptr_t base, uintptr_t size);
int checkstack(void *top_of_stack, int core);
/* Defined in src/lib/hexdump.c */
+void hexdump_bounds(const void *memory, size_t length, const void *base,
+ char separator, uint32_t extra_space, const char *bounds,
+ const char *ellipse, uint32_t match_zeros_only,
+ uint32_t print_duplicate_lines);
void hexdump(const void *memory, size_t length);
void hexdump32(char LEVEL, const void *d, size_t len);
diff --git a/src/lib/hexdump.c b/src/lib/hexdump.c
index a15c5cd..13d373e 100644
--- a/src/lib/hexdump.c
+++ b/src/lib/hexdump.c
@@ -28,40 +28,63 @@ static int isprint(int c)
return (c >= 32 && c <= 126);
}
-void hexdump(const void *memory, size_t length)
+void hexdump_bounds(const void *memory, size_t length, const void *base,
+ char separator, uint32_t extra_spaces, const char *bounds,
+ const char *ellipse, uint32_t match_zeros_only,
+ uint32_t print_duplicate_lines)
{
int i;
uint8_t *m;
- int all_zero = 0;
+ int matched_lines = -1;
+ uint8_t *offset;
+ uint8_t previous_values[16];
m = (uint8_t *) memory;
+ offset = (uint8_t *)(m - (uint8_t *)base);
for (i = 0; i < length; i += 16) {
int j;
- all_zero++;
+ matched_lines++;
for (j = 0; j < 16; j++) {
- if (m[i + j] != 0) {
- all_zero = 0;
+ if (m[i + j] != (match_zeros_only ? 0 :
+ previous_values[j])) {
+ matched_lines = 0;
break;
}
}
-
- if (all_zero < 2) {
- printk(BIOS_DEBUG, "%p:", memory + i);
+ if (matched_lines == 0) {
for (j = 0; j < 16; j++)
+ previous_values[j] = m[i + j];
+ }
+
+ if (matched_lines < print_duplicate_lines) {
+ printk(BIOS_DEBUG, "%p%c", offset + i, separator);
+ for (j = 0; j < 16; j++) {
+ if ((extra_spaces & (1 << j)) != 0)
+ printk(BIOS_DEBUG, " ");
printk(BIOS_DEBUG, " %02x", m[i + j]);
+ }
printk(BIOS_DEBUG, " ");
+ if (bounds)
+ printk(BIOS_DEBUG, "%s", bounds);
for (j = 0; j < 16; j++)
printk(BIOS_DEBUG, "%c",
isprint(m[i + j]) ? m[i + j] : '.');
+ if (bounds)
+ printk(BIOS_DEBUG, "%s", bounds);
printk(BIOS_DEBUG, "\n");
- } else if (all_zero == 2) {
- printk(BIOS_DEBUG, "...\n");
+ } else if (matched_lines == print_duplicate_lines) {
+ printk(BIOS_DEBUG, "%s\n", ellipse);
}
}
}
+void hexdump(const void *memory, size_t length)
+{
+ hexdump_bounds(memory, length, NULL, ':', 0, NULL, "...", 1, 2);
+}
+
void hexdump32(char LEVEL, const void *d, size_t len)
{
int count = 0;
More information about the coreboot-gerrit
mailing list