Created
June 17, 2020 00:08
-
-
Save akarpenko/2a180f6ca7b820df7d76edb5086c5c53 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..b62e333c60 100644 | |
--- a/cmd/sf.c | |
+++ b/cmd/sf.c | |
@@ -318,6 +318,45 @@ static int do_spi_flash_read_write(int argc, char *const argv[]) | |
return ret == 0 ? 0 : 1; | |
} | |
+static void putc2(char ch) { | |
+ int loop = 0; | |
+ while (*(volatile uint32_t*)(0x80074018) & 0x00000020) { | |
+ loop++; | |
+ if (loop > 100000) | |
+ break; | |
+ } | |
+ *(volatile uint32_t*)(0x80074000) = ch; | |
+} | |
+ | |
+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++) { | |
+ putc2(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 +610,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