[U-Boot] [PATCH 02/12] cmd_sf: Add rd_inst argument to 'sf read' command

Jagannadha Sutradharudu Teki jagannadh.teki at gmail.com
Mon Dec 31 12:13:41 CET 2012


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 at 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(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index e7843f3..88b18f8 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -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"
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 8ba2c65..0c64ac2 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -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;
 
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h
index 0d416b3..dcf8813 100644
--- a/drivers/mtd/spi/spi_flash_internal.h
+++ b/drivers/mtd/spi/spi_flash_internal.h
@@ -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);
 
 /*
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 9b3a6a1..6728796 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -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,
diff --git a/include/spi_flash_inst.h b/include/spi_flash_inst.h
index 139f45b..7c1b910 100644
--- a/include/spi_flash_inst.h
+++ b/include/spi_flash_inst.h
@@ -27,4 +27,7 @@
 /* Write commands */
 #define CMD_PAGE_PROGRAM		0x02
 
+/* Read commands */
+#define CMD_READ_ARRAY_FAST		0x0b
+
 #endif /* _SPI_FLASH_INST_H_ */
-- 
1.7.0.4



More information about the U-Boot mailing list