Skip to content

Commit

Permalink
flash_test: Show printable characters along when read
Browse files Browse the repository at this point in the history
So far flash read displayed data in hexadecimal format only.
Now additional ascii values are shown for printable
characters, which is common practice

Old format:

compat> flash 0 read 0x1d110100 0x20
Read 0x1d110100 + 32
  0x1d110100: 0x09 0x0f 0x00 0x6c 0x6f 0x67 0x2d 0x73
  0x1d110108: 0x74 0x6f 0x72 0x61 0x67 0x65 0x20 0xff

New format:

compat> flash 0 read 0x1d110100 0x20
Read 0x1d110100 + 32
  0x1d110100: 0x09 0x0f 0x00 0x6c 0x6f 0x67 0x2d 0x73  ...log-s
  0x1d110108: 0x74 0x6f 0x72 0x61 0x67 0x65 0x20 0xff  torage .

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
  • Loading branch information
kasjer committed Jun 27, 2024
1 parent 6177f10 commit 1525006
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions test/flash_test/src/flash_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <shell/shell.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

static int flash_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv,
struct streamer *streamer);
Expand All @@ -48,7 +49,6 @@ flash_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv,
int sec_cnt;
int i;
int devid;
int soff;
char *eptr;
char tmp_buf[32];
char pr_str[80];
Expand Down Expand Up @@ -157,21 +157,20 @@ flash_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv,
(long unsigned int) off);
break;
}
for (i = 0, soff = 0; i < sec_cnt; i++) {
soff += snprintf(pr_str + soff, sizeof(pr_str) - soff,
"0x%02x ", tmp_buf[i] & 0xff);
if (i % 8 == 7) {
streamer_printf(streamer, " 0x%lx: %s\n",
(long unsigned int) off, pr_str);
soff = 0;
off += 8;
for (i = 0; i < sec_cnt; i++) {
int n = i & 7;
if (n == 0) {
streamer_printf(streamer, " 0x%lx: ", (long unsigned int)off + i);
}
snprintf(pr_str + n * 5, 6, "0x%02x ", tmp_buf[i] & 0xff);
pr_str[41 + n] = isprint((uint8_t)tmp_buf[i]) ? tmp_buf[i] : '.';
if (n == 7 || i + 1 == sec_cnt) {
pr_str[41 + n + 1] = '\0';
memset(pr_str + (5 * n + 5), ' ', 5 * (7 - n) + 1);
streamer_printf(streamer, "%s\n", pr_str);
}
}
if (i % 8) {
streamer_printf(streamer, " 0x%lx: %s\n",
(long unsigned int) off, pr_str);
off += i;
}
off += sec_cnt;
}
} else if (!strcmp(argv[2], "write")) {
streamer_printf(streamer, "Write 0x%lx + %lx\n",
Expand Down

0 comments on commit 1525006

Please sign in to comment.