From 463cf04f8d25c5998f125e218b4cb33bf9936658 Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Fri, 16 Jun 2017 17:13:45 +0200 Subject: [PATCH] shell: flash display offsets --- source/shell/flash.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/shell/flash.c b/source/shell/flash.c index 538b459..355cc80 100644 --- a/source/shell/flash.c +++ b/source/shell/flash.c @@ -54,17 +54,19 @@ static void parse_hex(FILE *fp, char *buf, size_t len) } } -static void print_hex_ascii(const char *buf, size_t len) +static void print_hex_ascii(uint32_t offset, const char *buf, size_t len) { size_t n, i; uint8_t c; for (; len; buf += n, len -= n) { n = min(len, 16); - + + printf("%04" PRIx32 ": ", offset); + for (i = 0; i < 16; ++i) { c = (i < n) ? buf[i] : 0; - printf("%02x ", c); + printf("%02x", c); } printf(" "); @@ -75,6 +77,8 @@ static void print_hex_ascii(const char *buf, size_t len) } printf("\n"); + + offset += n; } } @@ -155,7 +159,7 @@ static void do_flash_read(const char *s) while (len) { nbytes = min(len, 256); flash_read(flash, addr, buf, nbytes); - print_hex_ascii(buf, nbytes); + print_hex_ascii(addr, buf, nbytes); addr += nbytes; len -= nbytes; @@ -199,7 +203,7 @@ static void do_flash_write(const char *s) nbytes = min(len, 256); parse_hex(stdin, buf, nbytes); printf("\n"); - print_hex_ascii(buf, nbytes); + print_hex_ascii(addr, buf, nbytes); flash_write(flash, addr, buf, nbytes); addr += nbytes;