Skip to contentSkip to conversation

cmd_sf: Add print mesg for 'sf erase' command

PATCH New Jagannadha Sutradharudu Teki 2 participants 4 messages May 27, 2013 – Jun 2, 2013 1 message not in the archive Memory technology devices (MTD)

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v3 1/2 cmd_sf: Add print mesg for 'sf erase' command

This patch adds a print messages while using 'sf erase' command to make sure that how many bytes erased in flash device.

---
 common/cmd_sf.c             |    8 +++-----
 drivers/mtd/spi/spi_flash.c |    7 ++-----
 2 files changed, 5 insertions(+), 10 deletions(-)
common/cmd_sf.c +3 -5
index 1daff70..12d1aca 100644
@@ -305,12 +305,10 @@ static int do_spi_flash_erase(int argc, char * const argv[])
 	}
 
 	ret = spi_flash_erase(flash, offset, len);
-	if (ret) {
-		printf("SPI flash %s failed\n", argv[0]);
-		return 1;
-	}
+	printf("SF: %zu bytes @ %#x Erased: %s\n", (size_t)len, (u32)offset,
+			ret ? "ERROR" : "OK");
 
-	return 0;
+	return ret == 0 ? 0 : 1;
 }
 
 #ifdef CONFIG_CMD_SF_TEST
drivers/mtd/spi/spi_flash.c +2 -5
index d2bee3a..77938d3 100644
@@ -206,7 +206,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 
 int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	u32 start, end, erase_size;
+	u32 end, erase_size;
 	int ret;
 	u8 cmd[4];
 
@@ -226,8 +226,7 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 		cmd[0] = CMD_ERASE_4K;
 	else
 		cmd[0] = CMD_ERASE_64K;
-	start = offset;
-	end = start + len;
+	end = offset + len;
 
 	while (offset < end) {
 		spi_flash_addr(offset, cmd);
@@ -251,8 +250,6 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 			goto out;
 	}
 
-	debug("SF: Successfully erased %zu bytes @ %#x\n", len, start);
-
  out:
 	spi_release_bus(flash->spi);
 	return ret;
Signature · 1 line
1.7.4
#2 lore raw

PATCH v3 1/2 cmd_sf: Add print mesg for 'sf erase' command

Quoted 54 lines · Jagannadha Sutradharudu Teki

This patch adds a print messages while using 'sf erase' command to make sure that how many bytes erased in flash device.

---
common/cmd_sf.c | 8 +++-----

  drivers/mtd/spi/spi_flash.c |    7 ++-----
  2 files changed, 5 insertions(+), 10 deletions(-)
common/cmd_sf.c +3 -5
index 1daff70..12d1aca 100644
@@ -305,12 +305,10 @@ static int do_spi_flash_erase(int argc, char * const argv[])
  	}
 
  	ret = spi_flash_erase(flash, offset, len);
-	if (ret) {
-		printf("SPI flash %s failed\n", argv[0]);
-		return 1;
-	}
+	printf("SF: %zu bytes @ %#x Erased: %s\n", (size_t)len, (u32)offset,
+			ret ? "ERROR" : "OK");
 
-	return 0;
+	return ret == 0 ? 0 : 1;
  }
 
  #ifdef CONFIG_CMD_SF_TEST
drivers/mtd/spi/spi_flash.c +2 -3
index d2bee3a..77938d3 100644
@@ -206,7 +206,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 
  int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
  {
-	u32 start, end, erase_size;
+	u32 end, erase_size;
  	int ret;
  	u8 cmd[4];
 
@@ -226,8 +226,7 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
  		cmd[0] = CMD_ERASE_4K;
  	else
  		cmd[0] = CMD_ERASE_64K;
-	start = offset;
-	end = start + len;
+	end = offset + len;
 
  	while (offset < end) {
  		spi_flash_addr(offset, cmd);

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len) · line 255

Quoted 8 lines
drivers/mtd/spi/spi_flash.c +0 -2
@@ -251,8 +250,6 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
  			goto out;
  	}
 
-	debug("SF: Successfully erased %zu bytes @ %#x\n", len, start);
-
   out:
  	spi_release_bus(flash->spi);
  	return ret;

Applied to u-boot-spi/master

--
Thanks,
Jagan.

#3 lore raw

PATCH v3 2/2 cmd_sf: Add print mesgs on sf read/write commands

In reply to a message not in the archive

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.

---
 common/cmd_sf.c             |   26 +++++++++++++++-----------
 drivers/mtd/spi/spi_flash.c |    3 ---
 2 files changed, 15 insertions(+), 14 deletions(-)
common/cmd_sf.c +15 -11
index 12d1aca..3a40444 100644
@@ -234,7 +234,7 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
 	unsigned long len;
 	void *buf;
 	char *endp;
-	int ret;
+	int ret = 1;
 
 	if (argc < 4)
 		return -1;
@@ -264,19 +264,23 @@ 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;
+
+		read = strncmp(argv[0], "read", 4) == 0;
+		if (read)
+			ret = spi_flash_read(flash, offset, len, buf);
+		else
+			ret = spi_flash_write(flash, offset, len, buf);
+
+		printf("SF: %zu bytes @ %#x %s: %s\n", (size_t)len, (u32)offset,
+			read ? "Read" : "Written", ret ? "ERROR" : "OK");
+	}
 
 	unmap_physmem(buf, len);
 
-	if (ret) {
-		printf("SPI flash %s failed\n", argv[0]);
-		return 1;
-	}
-
-	return 0;
+	return ret == 0 ? 0 : 1;
 }
 
 static int do_spi_flash_erase(int argc, char * const argv[])
drivers/mtd/spi/spi_flash.c +0 -3
index 77938d3..aeb1ccb 100644
@@ -125,9 +125,6 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 		}
 	}
 
-	debug("SF: program %s %zu bytes @ %#x\n",
-	      ret ? "failure" : "success", len, offset);
-
 	spi_release_bus(flash->spi);
 	return ret;
 }
Signature · 1 line
1.7.4
#4 lore raw

PATCH v3 2/2 cmd_sf: Add print mesgs on sf read/write commands

Quoted 63 lines · Jagannadha Sutradharudu Teki

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.

---
common/cmd_sf.c | 26 +++++++++++++++-----------

  drivers/mtd/spi/spi_flash.c |    3 ---
  2 files changed, 15 insertions(+), 14 deletions(-)
common/cmd_sf.c +15 -11
index 12d1aca..3a40444 100644
@@ -234,7 +234,7 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
  	unsigned long len;
  	void *buf;
  	char *endp;
-	int ret;
+	int ret = 1;
 
  	if (argc < 4)
  		return -1;
@@ -264,19 +264,23 @@ 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;
+
+		read = strncmp(argv[0], "read", 4) == 0;
+		if (read)
+			ret = spi_flash_read(flash, offset, len, buf);
+		else
+			ret = spi_flash_write(flash, offset, len, buf);
+
+		printf("SF: %zu bytes @ %#x %s: %s\n", (size_t)len, (u32)offset,
+			read ? "Read" : "Written", ret ? "ERROR" : "OK");
+	}
 
  	unmap_physmem(buf, len);
 
-	if (ret) {
-		printf("SPI flash %s failed\n", argv[0]);
-		return 1;
-	}
-
-	return 0;
+	return ret == 0 ? 0 : 1;
  }
 
  static int do_spi_flash_erase(int argc, char * const argv[])
drivers/mtd/spi/spi_flash.c +0 -0
index 77938d3..aeb1ccb 100644

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 130

Quoted 9 lines
drivers/mtd/spi/spi_flash.c +0 -3
@@ -125,9 +125,6 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
  		}
  	}
 
-	debug("SF: program %s %zu bytes @ %#x\n",
-	      ret ? "failure" : "success", len, offset);
-
  	spi_release_bus(flash->spi);
  	return ret;
  }

Applied to u-boot-spi/master

--
Thanks,
Jagan.