summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/util.c26
-rw-r--r--include/util.h13
2 files changed, 39 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c
index 054e8e839c..e93eeebb16 100644
--- a/common/util.c
+++ b/common/util.c
@@ -5,6 +5,7 @@
/* Utility functions for Chrome EC */
+#include "console.h"
#include "util.h"
size_t strlen(const char *s)
@@ -598,3 +599,28 @@ int parse_offset_size(int argc, char **argv, int shift,
return EC_SUCCESS;
}
+
+void hexdump(const uint8_t *data, int len)
+{
+ int i, j;
+
+ if (!data || !len)
+ return;
+
+ for (i = 0; i < len; i += 16) {
+ /* Left column (Hex) */
+ for (j = i; j < i + 16; j++) {
+ if (j < len)
+ ccprintf(" %02x", data[j]);
+ else
+ ccprintf(" ");
+ }
+ /* Right column (ASCII) */
+ ccprintf(" |");
+ for (j = i; j < i + 16; j++) {
+ int c = j < len ? data[j] : ' ';
+ ccprintf("%c", isprint(c) ? c : '.');
+ }
+ ccprintf("|\n");
+ }
+}
diff --git a/include/util.h b/include/util.h
index aa15ba4fa8..edef7d9b38 100644
--- a/include/util.h
+++ b/include/util.h
@@ -210,6 +210,19 @@ static inline int cond_went_true(cond_t *c) { return cond_went(c, 1); }
int parse_offset_size(int argc, char **argv, int shift,
int *offset, int *size);
+/**
+ * Print binary in hex and ASCII
+ *
+ * Sample output of hexdump(image_data.version, 30):
+ *
+ * 6e 61 6d 69 5f 76 32 2e 30 2e 37 37 34 2d 63 66 |nami_v2.0.774-cf|
+ * 34 62 64 33 34 38 30 00 00 00 00 00 00 00 |4bd3480....... |
+ *
+ * @param data Data to be dumped
+ * @param len Size of data
+ */
+void hexdump(const uint8_t *data, int len);
+
#ifdef CONFIG_ASSEMBLY_MULA32
/*
* Compute (a*b)+c[+d], where a, b, c[, d] are 32-bit integers, and the result