|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
#include <ctype.h> |
|
|
|
|
#include <inttypes.h> |
|
|
|
|
#include <stdint.h> |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
@ -11,12 +12,14 @@ |
|
|
|
|
#include <shell.h> |
|
|
|
|
|
|
|
|
|
static void do_flash_probe(const char *s); |
|
|
|
|
static void do_flash_info(const char *s); |
|
|
|
|
static void do_flash_read(const char *s); |
|
|
|
|
static void do_flash_write(const char *s); |
|
|
|
|
static void do_flash_erase(const char *s); |
|
|
|
|
|
|
|
|
|
static struct cmd flash_cmds[] = { |
|
|
|
|
{ "probe", do_flash_probe }, |
|
|
|
|
{ "info", do_flash_info }, |
|
|
|
|
{ "read", do_flash_read }, |
|
|
|
|
{ "write", do_flash_write }, |
|
|
|
|
{ "erase", do_flash_erase }, |
|
|
|
@ -73,6 +76,25 @@ static void print_hex_ascii(const char *buf, size_t len) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void print_size(size_t size) |
|
|
|
|
{ |
|
|
|
|
if (size == 0) { |
|
|
|
|
printf("0"); |
|
|
|
|
#if defined(TIB) |
|
|
|
|
} else if (size % TIB == 0) { |
|
|
|
|
printf("%" PRSZu " TiB", size / TIB); |
|
|
|
|
#endif |
|
|
|
|
} else if (size % GIB == 0) { |
|
|
|
|
printf("%" PRSZu " GiB", size / GIB); |
|
|
|
|
} else if (size % MIB == 0) { |
|
|
|
|
printf("%" PRSZu " MiB", size / MIB); |
|
|
|
|
} else if (size % KIB == 0) { |
|
|
|
|
printf("%" PRSZu " KiB", size / KIB); |
|
|
|
|
} else { |
|
|
|
|
printf("%" PRSZu " B", size); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_flash_probe(const char *s) |
|
|
|
|
{ |
|
|
|
|
(void)s; |
|
|
|
@ -87,6 +109,24 @@ static void do_flash_probe(const char *s) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_flash_info(const char *s) |
|
|
|
|
{ |
|
|
|
|
size_t size; |
|
|
|
|
|
|
|
|
|
(void)s; |
|
|
|
|
|
|
|
|
|
if (!flash) { |
|
|
|
|
fprintf(stderr, "error: no flash device probed.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
size = flash_get_size(flash); |
|
|
|
|
|
|
|
|
|
printf("Capacity: %" PRSZu " blocks (", size / (4 * KIB)); |
|
|
|
|
print_size(size); |
|
|
|
|
printf(")\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_flash_read(const char *s) |
|
|
|
|
{ |
|
|
|
|
char buf[256], *end = NULL; |
|
|
|
|