Skip to content

Instantly share code, notes, and snippets.

@akarpenko
Created June 16, 2020 04:12
Show Gist options
  • Save akarpenko/e00a6a9d6fcec8c896598f32b7e2728e to your computer and use it in GitHub Desktop.
Save akarpenko/e00a6a9d6fcec8c896598f32b7e2728e to your computer and use it in GitHub Desktop.
diff --git a/cmd/sf.c b/cmd/sf.c
index d18f6a888c..aee54c4c28 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -318,6 +318,28 @@ 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 = 0x100;
+ unsigned long addr = 0x08000000;
+
+ char *buf = map_physmem(addr, len, MAP_WRBACK);
+ if (!buf && addr) {
+ puts("Failed to map physical memory\n");
+ return 1;
+ }
+
+ for(loff_t offset = 0; offset < flash->size; offset += len) {
+ ret = spi_flash_read(flash, offset, len, buf);
+ for(int i = 0; i < len; i++) {
+ putc(buf[i]);
+ }
+ }
+
+ unmap_physmem(buf, len);
+ return 1;
+}
+
static int do_spi_flash_erase(int argc, char *const argv[])
{
int ret;
@@ -571,6 +593,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