From 9ff7dfce2391a246e7cdcc959ea1f49754d44b1d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 6 May 2020 15:02:21 -0600 Subject: [PATCH] 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 --- drivers/flash/flash_shell.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/flash/flash_shell.c b/drivers/flash/flash_shell.c index ae32a5655c5..6838c188f9b 100644 --- a/drivers/flash/flash_shell.c +++ b/drivers/flash/flash_shell.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -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, "");