Created
June 16, 2020 23:02
-
-
Save akarpenko/0217e375acd7be20d998e7522c3ae2af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cmd/sf.c b/cmd/sf.c | |
index d18f6a888c..ed04f3f011 100644 | |
--- a/cmd/sf.c | |
+++ b/cmd/sf.c | |
@@ -318,6 +318,35 @@ static int do_spi_flash_read_write(int argc, char *const argv[]) | |
return ret == 0 ? 0 : 1; | |
} | |
+static int do_spi_flash_dump(int argc, char *const argv[]) { | |
+ int ret = 1; | |
+ const loff_t len = 0x200; | |
+ unsigned long addr = 0x08000000; | |
+ | |
+ char *buf = map_physmem(addr, len, MAP_WRBACK); | |
+ if (!buf && addr) { | |
+ puts("Failed to map physical memory\n"); | |
+ return 1; | |
+ } | |
+ | |
+ printf("Dumping %u bytes:", flash->size); | |
+ | |
+ for(loff_t offset = 0; offset < flash->size; ) { | |
+ ret = spi_flash_read(flash, offset, len, buf); | |
+ if(ret) { | |
+ continue; | |
+ } | |
+ for(int i = 0; i < len; i++) { | |
+ putc(buf[i]); | |
+ } | |
+ offset += len; | |
+ } | |
+ printf("End of dump\n"); | |
+ | |
+ unmap_physmem(buf, len); | |
+ return 1; | |
+} | |
+ | |
static int do_spi_flash_erase(int argc, char *const argv[]) | |
{ | |
int ret; | |
@@ -571,6 +600,8 @@ static int do_spi_flash(struct cmd_tbl *cmdtp, int flag, int argc, | |
if (strcmp(cmd, "read") == 0 || strcmp(cmd, "write") == 0 || | |
strcmp(cmd, "update") == 0) | |
ret = do_spi_flash_read_write(argc, argv); | |
+ else if (strcmp(cmd, "dump") == 0) | |
+ ret = do_spi_flash_dump(argc, argv); | |
else if (strcmp(cmd, "erase") == 0) | |
ret = do_spi_flash_erase(argc, argv); | |
else if (strcmp(cmd, "protect") == 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment