flash: Enhance 'flash read' to read a block of data

It is annoying to read just a single word at a time. Update this
command to print any amount of data. This uses byte format at present.

We could perhaps support something like:

   flash read.8
   flash read.16
   flash read.32

to chose the size.

Example output (with line breaks to keep within git-style limit):

$ flash read FLASH_CTRL 0 20
00000000: 20 25 00 20 1d 26 00 08  69 68 00 08 45 26 00 08
   | %. .&.. ih..E&..|
00000010: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
   |........ ........|

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-05-06 15:02:21 -06:00 committed by Anas Nashif
commit 9ff7dfce23

View file

@ -8,6 +8,7 @@
#include <zephyr.h>
#include <shell/shell.h>
#include <sys/util.h>
#include <stdlib.h>
#include <string.h>
@ -136,6 +137,8 @@ static int cmd_read(const struct shell *shell, size_t argc, char *argv[])
{
struct device *flash_dev;
uint32_t addr;
int todo;
int upto;
int cnt;
int ret;
@ -150,16 +153,17 @@ static int cmd_read(const struct shell *shell, size_t argc, char *argv[])
cnt = 1;
}
while (cnt--) {
uint32_t data;
for (upto = 0; upto < cnt; upto += todo) {
uint8_t data[SHELL_HEXDUMP_BYTES_IN_LINE];
ret = flash_read(flash_dev, addr, &data, sizeof(data));
todo = MIN(cnt - upto, SHELL_HEXDUMP_BYTES_IN_LINE);
ret = flash_read(flash_dev, addr, data, todo);
if (ret != 0) {
shell_error(shell, "Read ERROR!");
return -EIO;
}
shell_print(shell, "0x%08x ", data);
addr += sizeof(data);
shell_hexdump_line(shell, addr, data, todo);
addr += todo;
}
shell_print(shell, "");