summaryrefslogtreecommitdiff
path: root/common/log.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-05-08 07:00:06 -0600
committerTom Rini <trini@konsulko.com>2021-06-08 11:39:09 -0400
commit58b4b7133aba6fbb2409a975478157f9277c2e91 (patch)
tree134665e40bcbbfd82b1e42729c11f00de345390d /common/log.c
parent0cceb99ac59b1d383488ea3ce6511ffc01da5332 (diff)
log: Add support for logging a buffer
The print_buffer() function is very useful for debugging. Add a version of this in the log system also. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/log.c')
-rw-r--r--common/log.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/log.c b/common/log.c
index ea407c6db9..1aaa6c1527 100644
--- a/common/log.c
+++ b/common/log.c
@@ -284,6 +284,36 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
return 0;
}
+#define MAX_LINE_LENGTH_BYTES 64
+#define DEFAULT_LINE_LENGTH_BYTES 16
+
+int _log_buffer(enum log_category_t cat, enum log_level_t level,
+ const char *file, int line, const char *func, ulong addr,
+ const void *data, uint width, uint count, uint linelen)
+{
+ if (linelen * width > MAX_LINE_LENGTH_BYTES)
+ linelen = MAX_LINE_LENGTH_BYTES / width;
+ if (linelen < 1)
+ linelen = DEFAULT_LINE_LENGTH_BYTES / width;
+
+ while (count) {
+ uint thislinelen;
+ char buf[HEXDUMP_MAX_BUF_LENGTH(width * linelen)];
+
+ thislinelen = hexdump_line(addr, data, width, count, linelen,
+ buf, sizeof(buf));
+ assert(thislinelen >= 0);
+ _log(cat, level, file, line, func, "%s\n", buf);
+
+ /* update references */
+ data += thislinelen * width;
+ addr += thislinelen * width;
+ count -= thislinelen;
+ }
+
+ return 0;
+}
+
int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[],
enum log_level_t level, const char *file_list,
int flags)