@@ -235,7 +235,7 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
unsigned long len;
void *buf;
char *endp;
- u8 wr_inst;
+ u8 wr_inst, rd_inst;
int ret;
if (argc < 5)
@@ -266,9 +266,17 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
if (strcmp(argv[0], "update") == 0)
ret = spi_flash_update(flash, offset, len, buf);
- else if (strcmp(argv[0], "read") == 0)
- ret = spi_flash_read(flash, offset, len, buf);
- else {
+ else if (strcmp(argv[0], "read") == 0) {
+ if (strcmp(argv[1], "afr") == 0)
+ rd_inst = CMD_READ_ARRAY_FAST;
+ else {
+ printf("SF: Unknown %s rd_inst on 'sf read'\n",
+ argv[1]);
+ return 1;
+ }
+
+ ret = spi_flash_read(flash, rd_inst, offset, len, buf);
+ } else {
if (strcmp(argv[1], "pp") == 0)
wr_inst = CMD_PAGE_PROGRAM;
else {
@@ -535,8 +543,11 @@ U_BOOT_CMD(
"SPI flash sub-system",
"probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n"
" and chip select\n"
- "sf read addr offset len - read `len' bytes starting at\n"
- " `offset' to memory at `addr'\n"
+ "sf read rd_inst addr offset len\n"
+ " - read `len' bytes starting at\n"
+ " `offset' to memory at `addr' using\n"
+ " afr `rd_inst' read instruction\n"
+ " afr (Array Fast Read, 0bh)\n"
"sf write wr_inst addr offset len\n"
" - write `len' bytes from memory\n"
" at `addr' to flash at `offset' using\n"
@@ -135,12 +135,12 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
return ret;
}
-int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
+int spi_flash_cmd_read_fast(struct spi_flash *flash, u8 rd_inst, u32 offset,
size_t len, void *data)
{
u8 cmd[5];
- cmd[0] = CMD_READ_ARRAY_FAST;
+ cmd[0] = rd_inst;
spi_flash_addr(offset, cmd);
cmd[4] = 0x00;
@@ -43,7 +43,7 @@ int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);
int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
size_t cmd_len, void *data, size_t data_len);
-int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
+int spi_flash_cmd_read_fast(struct spi_flash *flash, u8 rd_inst, u32 offset,
size_t len, void *data);
/*
@@ -39,8 +39,8 @@ struct spi_flash {
/* Erase (sector) size */
u32 sector_size;
- int (*read)(struct spi_flash *flash, u32 offset,
- size_t len, void *buf);
+ int (*read)(struct spi_flash *flash, u8 rd_inst,
+ u32 offset, size_t len, void *buf);
int (*write)(struct spi_flash *flash, u8 wr_inst,
u32 offset, size_t len, const void *buf);
int (*erase)(struct spi_flash *flash, u32 offset,
@@ -51,10 +51,10 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
unsigned int max_hz, unsigned int spi_mode);
void spi_flash_free(struct spi_flash *flash);
-static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
- size_t len, void *buf)
+static inline int spi_flash_read(struct spi_flash *flash, u8 rd_inst,
+ u32 offset, size_t len, void *buf)
{
- return flash->read(flash, offset, len, buf);
+ return flash->read(flash, rd_inst, offset, len, buf);
}
static inline int spi_flash_write(struct spi_flash *flash, u8 wr_inst,
@@ -27,4 +27,7 @@
/* Write commands */
#define CMD_PAGE_PROGRAM 0x02
+/* Read commands */
+#define CMD_READ_ARRAY_FAST 0x0b
+
#endif /* _SPI_FLASH_INST_H_ */
This patch provides a support to add a read instruction(rd_inst) argument to 'sf read' command. User will dynamically use the specific read instruction while reading the flash using 'sf read' command. Currently added an existing read instruction called afr(Array Fast Read). Example: read 0x2000 length bytes starting at offset 0x0 to memory at 0x10000 using afr read instruction. u-boot> sf read afr 0x10000 0x0 0x2000 Signed-off-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com> --- common/cmd_sf.c | 23 +++++++++++++++++------ drivers/mtd/spi/spi_flash.c | 4 ++-- drivers/mtd/spi/spi_flash_internal.h | 2 +- include/spi_flash.h | 10 +++++----- include/spi_flash_inst.h | 3 +++ 5 files changed, 28 insertions(+), 14 deletions(-)