summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-11-30 09:57:30 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-12-03 08:37:42 +0100
commit67a6c4417abf1904e9b415c939a2f501cb4216e0 (patch)
treef1e57d2d02919dff7c217b305bf8cee0b5557126 /common
parent5f46b42be1c9856e37e3e4c4fb3c1b8489f9ea95 (diff)
downloadbarebox-67a6c4417abf1904e9b415c939a2f501cb4216e0.tar.gz
barebox-67a6c4417abf1904e9b415c939a2f501cb4216e0.tar.xz
Add pr_memory_display
pr_memory_display is a memory_display variant that takes a MSG_* loglevel priority with which the hexdump is printed. Like the normal pr_* function this is optimized out when the priority is below the compile time priority. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/memory_display.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/common/memory_display.c b/common/memory_display.c
index 03d418b33b..cd0eadf88d 100644
--- a/common/memory_display.c
+++ b/common/memory_display.c
@@ -4,11 +4,21 @@
#define DISP_LINE_LEN 16
-int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int swab)
+
+int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbytes,
+ int size, int swab, const char *fmt, ...)
{
unsigned long linebytes, i;
unsigned char *cp;
unsigned char line[sizeof("00000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................")];
+ struct va_format vaf;
+ int ret;
+ va_list args;
+
+ va_start(args, fmt);
+
+ vaf.fmt = fmt;
+ vaf.va = &args;
/* Print the lines.
*
@@ -98,11 +108,28 @@ int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int
cp++;
}
- printf("%s\n", line);
+ if (level >= MSG_EMERG)
+ pr_print(level, "%pV%s\n", &vaf, line);
+ else
+ printf("%s\n", line);
+
nbytes -= linebytes;
- if (ctrlc())
- return -EINTR;
+ if (ctrlc()) {
+ ret = -EINTR;
+ goto out;
+ }
+
} while (nbytes > 0);
- return 0;
+ va_end(args);
+ ret = 0;
+out:
+
+ return ret;
}
+
+int memory_display(const void *addr, loff_t offs, unsigned nbytes,
+ int size, int swab)
+{
+ return pr_memory_display(-1, addr, offs, nbytes, size, swab);
+} \ No newline at end of file