[U-Boot] [U-Boot, v2 2/6] cmd_sf: Add print messages on flash read/write commands

Jagannadha Sutradharudu Teki jagannadh.teki at gmail.com
Wed Dec 19 17:27:39 CET 2012


This patch adds a print messages while using 'sf read' and
'sf write' commands to make sure that how many bytes read/written
from/into flash device.

Signed-off-by: Jagannadha Sutradharudu Teki <jagannadh.teki at gmail.com>
---
Changes in v2:
        Move print messages from spi_flash.c into cmd_sf.c

 common/cmd_sf.c             |   26 ++++++++++++++++----------
 drivers/mtd/spi/spi_flash.c |    3 ---
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index ddb1a65..efdd640 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -196,7 +196,7 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
 	unsigned long len;
 	void *buf;
 	char *endp;
-	int ret;
+	int ret = 0;
 
 	if (argc < 4)
 		return -1;
@@ -226,19 +226,25 @@ 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
-		ret = spi_flash_write(flash, offset, len, buf);
+	else if (strncmp(argv[0], "read", 4) == 0 ||
+			strncmp(argv[0], "write", 5) == 0) {
+		int read;
 
-	unmap_physmem(buf, len);
+		read = strncmp(argv[0], "read", 4) == 0;
+		printf("SF: %s flash... ", read ? "Reading" : "Writing");
 
-	if (ret) {
-		printf("SPI flash %s failed\n", argv[0]);
-		return 1;
+		if (read)
+			ret = spi_flash_read(flash, offset, len, buf);
+		else
+			ret = spi_flash_write(flash, offset, len, buf);
+
+		printf("%zu bytes @ %#x %s: %s\n", (size_t)len, (u32)offset,
+			read ? "read" : "written", ret ? "ERROR" : "OK");
 	}
 
-	return 0;
+	unmap_physmem(buf, len);
+
+	return ret == 0 ? 0 : 1;
 }
 
 static int do_spi_flash_erase(int argc, char * const argv[])
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 43e0334..9e8939c 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -115,9 +115,6 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 		byte_addr = 0;
 	}
 
-	debug("SF: program %s %zu bytes @ %#x\n",
-	      ret ? "failure" : "success", len, offset);
-
 	spi_release_bus(flash->spi);
 	return ret;
 }
-- 
1.7.0.4



More information about the U-Boot mailing list