public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06
@ 2011-04-12  6:35 Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 1/9] sf: punt unused spi_flash_region struct Mike Frysinger
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

Some bug fixes for the recent SPI flash cleanups, some more cleanups
based on work by Richard, support for +len when erasing SPI flashes,
and more cleanups I noticed should be done while doing all of that.

Mike Frysinger (7):
  sf: punt unused spi_flash_region struct
  sf: atmel: undo unification of status polling
  sf: sst: setup read func
  sf: localize erase funcs
  sf: use print_size() for sector_size output
  cmd_sf: drop device status message when probing
  cmd_sf: use cmd_usage() in more places

Richard Retanubun (2):
  sf: add struct spi_flash.sector_size parameter
  cmd_sf: add handler for +len arg for erase command

 common/cmd_sf.c                      |  111 +++++++++++++++++++++++-----------
 drivers/mtd/spi/atmel.c              |   40 ++++++++++---
 drivers/mtd/spi/eon.c                |   13 +---
 drivers/mtd/spi/macronix.c           |   17 ++----
 drivers/mtd/spi/ramtron.c            |    5 +-
 drivers/mtd/spi/spansion.c           |   15 +----
 drivers/mtd/spi/spi_flash.c          |    9 ++-
 drivers/mtd/spi/spi_flash_internal.h |    2 +-
 drivers/mtd/spi/sst.c                |   13 ++---
 drivers/mtd/spi/stmicro.c            |   15 +----
 drivers/mtd/spi/winbond.c            |   13 +---
 include/spi_flash.h                  |    7 +--
 12 files changed, 144 insertions(+), 116 deletions(-)

-- 
1.7.5.rc1

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 1/9] sf: punt unused spi_flash_region struct
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 2/9] sf: atmel: undo unification of status polling Mike Frysinger
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 include/spi_flash.h |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/include/spi_flash.h b/include/spi_flash.h
index 1f8ba29..89cc3a7 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -26,11 +26,6 @@
 #include <spi.h>
 #include <linux/types.h>
 
-struct spi_flash_region {
-	unsigned int	count;
-	unsigned int	size;
-};
-
 struct spi_flash {
 	struct spi_slave *spi;
 
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 2/9] sf: atmel: undo unification of status polling
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 1/9] sf: punt unused spi_flash_region struct Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 3/9] sf: add struct spi_flash.sector_size parameter Mike Frysinger
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

The AT45 flashes are completely different (at the command set and
status register level) from all other SPI flashes, so we can't unify
their logic with common code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/spi/atmel.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi/atmel.c b/drivers/mtd/spi/atmel.c
index a9910b1..10df387 100644
--- a/drivers/mtd/spi/atmel.c
+++ b/drivers/mtd/spi/atmel.c
@@ -113,8 +113,35 @@ static const struct atmel_spi_flash_params atmel_spi_flash_table[] = {
 
 static int at45_wait_ready(struct spi_flash *flash, unsigned long timeout)
 {
-	return spi_flash_cmd_poll_bit(flash, timeout,
-		CMD_AT45_READ_STATUS, AT45_STATUS_READY);
+	struct spi_slave *spi = flash->spi;
+	unsigned long timebase;
+	int ret;
+	u8 cmd = CMD_AT45_READ_STATUS;
+	u8 status;
+
+	timebase = get_timer(0);
+
+	ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
+	if (ret)
+		return -1;
+
+	do {
+		ret = spi_xfer(spi, 8, NULL, &status, 0);
+		if (ret)
+			return -1;
+
+		if (status & AT45_STATUS_READY)
+			break;
+	} while (get_timer(timebase) < timeout);
+
+	/* Deactivate CS */
+	spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
+
+	if (status & AT45_STATUS_READY)
+		return 0;
+
+	/* Timed out */
+	return -1;
 }
 
 /*
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 3/9] sf: add struct spi_flash.sector_size parameter
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 1/9] sf: punt unused spi_flash_region struct Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 2/9] sf: atmel: undo unification of status polling Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 4/9] sf: sst: setup read func Mike Frysinger
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

From: Richard Retanubun <RichardRetanubun@ruggedcom.com>

This patch adds a new member to struct spi_flash (u16 sector_size)
and updates the spi flash drivers to start populating it.

This parameter can be used by spi flash commands that need to round
up units of operation to the flash's sector_size.

Having this number in one place also allows duplicated code to be
further collapsed into one common location (such as erase parameter
and the detected message).

Signed-off-by: Richard Retanubun <RichardRetanubun@RuggedCom.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/spi/atmel.c              |    5 +----
 drivers/mtd/spi/eon.c                |   11 +++--------
 drivers/mtd/spi/macronix.c           |   15 ++++-----------
 drivers/mtd/spi/ramtron.c            |    3 ---
 drivers/mtd/spi/spansion.c           |   13 +++----------
 drivers/mtd/spi/spi_flash.c          |    9 +++++++--
 drivers/mtd/spi/spi_flash_internal.h |    2 +-
 drivers/mtd/spi/sst.c                |   10 +++-------
 drivers/mtd/spi/stmicro.c            |   13 +++----------
 drivers/mtd/spi/winbond.c            |   11 +++--------
 include/spi_flash.h                  |    2 ++
 11 files changed, 30 insertions(+), 64 deletions(-)

diff --git a/drivers/mtd/spi/atmel.c b/drivers/mtd/spi/atmel.c
index 10df387..d17ebf6 100644
--- a/drivers/mtd/spi/atmel.c
+++ b/drivers/mtd/spi/atmel.c
@@ -522,14 +522,11 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
 		goto err;
 	}
 
+	asf->flash.sector_size = page_size;
 	asf->flash.size = page_size * params->pages_per_block
 				* params->blocks_per_sector
 				* params->nr_sectors;
 
-	printf("SF: Detected %s with page size %u, total ",
-	       params->name, page_size);
-	print_size(asf->flash.size, "\n");
-
 	return &asf->flash;
 
 err:
diff --git a/drivers/mtd/spi/eon.c b/drivers/mtd/spi/eon.c
index 01caed5..a3640f4 100644
--- a/drivers/mtd/spi/eon.c
+++ b/drivers/mtd/spi/eon.c
@@ -121,11 +121,7 @@ static int eon_write(struct spi_flash *flash,
 
 int eon_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	struct eon_spi_flash *eon = to_eon_spi_flash(flash);
-	return spi_flash_cmd_erase(flash, CMD_EN25Q128_BE,
-		eon->params->page_size * eon->params->pages_per_sector *
-			eon->params->sectors_per_block;
-		offset, len);
+	return spi_flash_cmd_erase(flash, CMD_EN25Q128_BE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
@@ -158,11 +154,10 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
 	eon->flash.write = eon_write;
 	eon->flash.erase = eon_erase;
 	eon->flash.read = spi_flash_cmd_read_fast;
+	eon->flash.sector_size = params->page_size * params->pages_per_sector
+	    * params->sectors_per_block;
 	eon->flash.size = params->page_size * params->pages_per_sector
 	    * params->nr_sectors;
 
-	debug("SF: Detected %s with page size %u, total %u bytes\n",
-	      params->name, params->page_size, eon->flash.size);
-
 	return &eon->flash;
 }
diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c
index 4155d4d..a0512d1 100644
--- a/drivers/mtd/spi/macronix.c
+++ b/drivers/mtd/spi/macronix.c
@@ -177,11 +177,7 @@ static int macronix_write(struct spi_flash *flash,
 
 int macronix_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	struct macronix_spi_flash *mcx = to_macronix_spi_flash(flash);
-	return spi_flash_cmd_erase(flash, CMD_MX25XX_BE,
-		mcx->params->page_size * mcx->params->pages_per_sector *
-			mcx->params->sectors_per_block,
-		offset, len);
+	return spi_flash_cmd_erase(flash, CMD_MX25XX_BE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
@@ -215,12 +211,9 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
 	mcx->flash.write = macronix_write;
 	mcx->flash.erase = macronix_erase;
 	mcx->flash.read = spi_flash_cmd_read_fast;
-	mcx->flash.size = params->page_size * params->pages_per_sector
-	    * params->sectors_per_block * params->nr_blocks;
-
-	printf("SF: Detected %s with page size %u, total ",
-	       params->name, params->page_size);
-	print_size(mcx->flash.size, "\n");
+	mcx->flash.sector_size = params->page_size * params->pages_per_sector
+		* params->sectors_per_block;
+	mcx->flash.size = mcx->flash.sector_size * params->nr_blocks;
 
 	return &mcx->flash;
 }
diff --git a/drivers/mtd/spi/ramtron.c b/drivers/mtd/spi/ramtron.c
index 171390d..453dd3f 100644
--- a/drivers/mtd/spi/ramtron.c
+++ b/drivers/mtd/spi/ramtron.c
@@ -312,8 +312,5 @@ found:
 	sn->flash.erase = ramtron_erase;
 	sn->flash.size = params->size;
 
-	printf("SF: Detected %s with size ", params->name);
-	print_size(sn->flash.size, "\n");
-
 	return &sn->flash;
 }
diff --git a/drivers/mtd/spi/spansion.c b/drivers/mtd/spi/spansion.c
index d54a5fa..f138d73 100644
--- a/drivers/mtd/spi/spansion.c
+++ b/drivers/mtd/spi/spansion.c
@@ -198,10 +198,7 @@ static int spansion_write(struct spi_flash *flash,
 
 int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash);
-	return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE,
-		spsn->params->page_size * spsn->params->pages_per_sector,
-		offset, len);
+	return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
@@ -240,12 +237,8 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
 	spsn->flash.write = spansion_write;
 	spsn->flash.erase = spansion_erase;
 	spsn->flash.read = spi_flash_cmd_read_fast;
-	spsn->flash.size = params->page_size * params->pages_per_sector
-	    * params->nr_sectors;
-
-	printf("SF: Detected %s with page size %u, total ",
-	       params->name, params->page_size);
-	print_size(spsn->flash.size, "\n");
+	spsn->flash.sector_size = params->page_size * params->pages_per_sector;
+	spsn->flash.size = spsn->flash.sector_size * params->nr_sectors;
 
 	return &spsn->flash;
 }
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 5c261f1..ccb7e31 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -131,12 +131,13 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 }
 
 int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
-			u32 erase_size, u32 offset, size_t len)
+			u32 offset, size_t len)
 {
-	u32 start, end;
+	u32 start, end, erase_size;
 	int ret;
 	u8 cmd[4];
 
+	erase_size = flash->sector_size;
 	if (offset % erase_size || len % erase_size) {
 		debug("SF: Erase offset/length not multiple of erase size\n");
 		return -1;
@@ -296,6 +297,10 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 		goto err_manufacturer_probe;
 	}
 
+	printf("SF: Detected %s with page size %u, total ",
+	       flash->name, flash->sector_size);
+	print_size(flash->size, "\n");
+
 	spi_release_bus(spi);
 
 	return flash;
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h
index d7bcd6d..fc109ce 100644
--- a/drivers/mtd/spi/spi_flash_internal.h
+++ b/drivers/mtd/spi/spi_flash_internal.h
@@ -64,7 +64,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
 
 /* Erase sectors. */
 int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
-			u32 erase_size, u32 offset, size_t len);
+			u32 offset, size_t len);
 
 /* Manufacturer-specific probe functions */
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode);
diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c
index 792d04d..29bb88b 100644
--- a/drivers/mtd/spi/sst.c
+++ b/drivers/mtd/spi/sst.c
@@ -201,8 +201,7 @@ sst_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf)
 
 int sst_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	return spi_flash_cmd_erase(flash, CMD_SST_SE, SST_SECTOR_SIZE,
-		offset, len);
+	return spi_flash_cmd_erase(flash, CMD_SST_SE, offset, len);
 }
 
 static int
@@ -256,11 +255,8 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
 
 	stm->flash.write = sst_write;
 	stm->flash.erase = sst_erase;
-	stm->flash.size = SST_SECTOR_SIZE * params->nr_sectors;
-
-	printf("SF: Detected %s with page size %u, total ",
-	       params->name, SST_SECTOR_SIZE);
-	print_size(stm->flash.size, "\n");
+	stm->flash.sector_size = SST_SECTOR_SIZE;
+	stm->flash.size = stm->flash.sector_size * params->nr_sectors;
 
 	/* Flash powers up read-only, so clear BP# bits */
 	sst_unlock(&stm->flash);
diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c
index 7ef690d..a1980b1 100644
--- a/drivers/mtd/spi/stmicro.c
+++ b/drivers/mtd/spi/stmicro.c
@@ -199,10 +199,7 @@ static int stmicro_write(struct spi_flash *flash,
 
 int stmicro_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	struct stmicro_spi_flash *stm = to_stmicro_spi_flash(flash);
-	return spi_flash_cmd_erase(flash, CMD_M25PXX_SE,
-		stm->params->page_size * stm->params->pages_per_sector,
-		offset, len);
+	return spi_flash_cmd_erase(flash, CMD_M25PXX_SE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
@@ -249,12 +246,8 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
 	stm->flash.write = stmicro_write;
 	stm->flash.erase = stmicro_erase;
 	stm->flash.read = spi_flash_cmd_read_fast;
-	stm->flash.size = params->page_size * params->pages_per_sector
-	    * params->nr_sectors;
-
-	printf("SF: Detected %s with page size %u, total ",
-	       params->name, params->page_size);
-	print_size(stm->flash.size, "\n");
+	stm->flash.sector_size = params->page_size * params->pages_per_sector;
+	stm->flash.size = stm->flash.sector_size * params->nr_sectors;
 
 	return &stm->flash;
 }
diff --git a/drivers/mtd/spi/winbond.c b/drivers/mtd/spi/winbond.c
index e88802f..72d94ad 100644
--- a/drivers/mtd/spi/winbond.c
+++ b/drivers/mtd/spi/winbond.c
@@ -172,10 +172,7 @@ out:
 
 int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	struct winbond_spi_flash *stm = to_winbond_spi_flash(flash);
-	return spi_flash_cmd_erase(flash, CMD_W25_SE,
-		(1 << stm->params->l2_page_size) * stm->params->pages_per_sector,
-		offset, len);
+	return spi_flash_cmd_erase(flash, CMD_W25_SE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
@@ -213,13 +210,11 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
 	stm->flash.write = winbond_write;
 	stm->flash.erase = winbond_erase;
 	stm->flash.read = spi_flash_cmd_read_fast;
+	stm->flash.sector_size = (1 << stm->params->l2_page_size) *
+		stm->params->pages_per_sector;
 	stm->flash.size = page_size * params->pages_per_sector
 				* params->sectors_per_block
 				* params->nr_blocks;
 
-	printf("SF: Detected %s with page size %u, total ",
-	       params->name, page_size);
-	print_size(stm->flash.size, "\n");
-
 	return &stm->flash;
 }
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 89cc3a7..a384071 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -33,6 +33,8 @@ struct spi_flash {
 
 	u32		size;
 
+	u32		sector_size;
+
 	int		(*read)(struct spi_flash *flash, u32 offset,
 				size_t len, void *buf);
 	int		(*write)(struct spi_flash *flash, u32 offset,
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 4/9] sf: sst: setup read func
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
                   ` (2 preceding siblings ...)
  2011-04-12  6:35 ` [U-Boot] [PATCH 3/9] sf: add struct spi_flash.sector_size parameter Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 5/9] sf: localize erase funcs Mike Frysinger
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

The previous unification patch missed setting up the sst read func.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/spi/sst.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c
index 29bb88b..38983bd 100644
--- a/drivers/mtd/spi/sst.c
+++ b/drivers/mtd/spi/sst.c
@@ -255,6 +255,7 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
 
 	stm->flash.write = sst_write;
 	stm->flash.erase = sst_erase;
+	stm->flash.read = spi_flash_cmd_read_fast;
 	stm->flash.sector_size = SST_SECTOR_SIZE;
 	stm->flash.size = stm->flash.sector_size * params->nr_sectors;
 
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 5/9] sf: localize erase funcs
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
                   ` (3 preceding siblings ...)
  2011-04-12  6:35 ` [U-Boot] [PATCH 4/9] sf: sst: setup read func Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 6/9] cmd_sf: add handler for +len arg for erase command Mike Frysinger
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

No need for these to be exported as they are only accessed indirectly
via function pointers.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/spi/atmel.c    |    4 ++--
 drivers/mtd/spi/eon.c      |    2 +-
 drivers/mtd/spi/macronix.c |    2 +-
 drivers/mtd/spi/ramtron.c  |    2 +-
 drivers/mtd/spi/spansion.c |    2 +-
 drivers/mtd/spi/sst.c      |    2 +-
 drivers/mtd/spi/stmicro.c  |    2 +-
 drivers/mtd/spi/winbond.c  |    2 +-
 8 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/spi/atmel.c b/drivers/mtd/spi/atmel.c
index d17ebf6..1ecece0 100644
--- a/drivers/mtd/spi/atmel.c
+++ b/drivers/mtd/spi/atmel.c
@@ -328,7 +328,7 @@ out:
 /*
  * TODO: the two erase funcs (_p2/_at45) should get unified ...
  */
-int dataflash_erase_p2(struct spi_flash *flash, u32 offset, size_t len)
+static int dataflash_erase_p2(struct spi_flash *flash, u32 offset, size_t len)
 {
 	struct atmel_spi_flash *asf = to_atmel_spi_flash(flash);
 	unsigned long page_size;
@@ -387,7 +387,7 @@ out:
 	return ret;
 }
 
-int dataflash_erase_at45(struct spi_flash *flash, u32 offset, size_t len)
+static int dataflash_erase_at45(struct spi_flash *flash, u32 offset, size_t len)
 {
 	struct atmel_spi_flash *asf = to_atmel_spi_flash(flash);
 	unsigned long page_addr;
diff --git a/drivers/mtd/spi/eon.c b/drivers/mtd/spi/eon.c
index a3640f4..e3de3aa 100644
--- a/drivers/mtd/spi/eon.c
+++ b/drivers/mtd/spi/eon.c
@@ -119,7 +119,7 @@ static int eon_write(struct spi_flash *flash,
 	return ret;
 }
 
-int eon_erase(struct spi_flash *flash, u32 offset, size_t len)
+static int eon_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	return spi_flash_cmd_erase(flash, CMD_EN25Q128_BE, offset, len);
 }
diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c
index a0512d1..ff66f2a 100644
--- a/drivers/mtd/spi/macronix.c
+++ b/drivers/mtd/spi/macronix.c
@@ -175,7 +175,7 @@ static int macronix_write(struct spi_flash *flash,
 	return ret;
 }
 
-int macronix_erase(struct spi_flash *flash, u32 offset, size_t len)
+static int macronix_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	return spi_flash_cmd_erase(flash, CMD_MX25XX_BE, offset, len);
 }
diff --git a/drivers/mtd/spi/ramtron.c b/drivers/mtd/spi/ramtron.c
index 453dd3f..078d16c 100644
--- a/drivers/mtd/spi/ramtron.c
+++ b/drivers/mtd/spi/ramtron.c
@@ -233,7 +233,7 @@ static int ramtron_write(struct spi_flash *flash,
 		CMD_RAMTRON_WRITE);
 }
 
-int ramtron_erase(struct spi_flash *flash, u32 offset, size_t len)
+static int ramtron_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	debug("SF: Erase of RAMTRON FRAMs is pointless\n");
 	return -1;
diff --git a/drivers/mtd/spi/spansion.c b/drivers/mtd/spi/spansion.c
index f138d73..a3401b3 100644
--- a/drivers/mtd/spi/spansion.c
+++ b/drivers/mtd/spi/spansion.c
@@ -196,7 +196,7 @@ static int spansion_write(struct spi_flash *flash,
 	return ret;
 }
 
-int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
+static int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, offset, len);
 }
diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c
index 38983bd..0733deb 100644
--- a/drivers/mtd/spi/sst.c
+++ b/drivers/mtd/spi/sst.c
@@ -199,7 +199,7 @@ sst_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf)
 	return ret;
 }
 
-int sst_erase(struct spi_flash *flash, u32 offset, size_t len)
+static int sst_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	return spi_flash_cmd_erase(flash, CMD_SST_SE, offset, len);
 }
diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c
index a1980b1..a1959ca 100644
--- a/drivers/mtd/spi/stmicro.c
+++ b/drivers/mtd/spi/stmicro.c
@@ -197,7 +197,7 @@ static int stmicro_write(struct spi_flash *flash,
 	return ret;
 }
 
-int stmicro_erase(struct spi_flash *flash, u32 offset, size_t len)
+static int stmicro_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	return spi_flash_cmd_erase(flash, CMD_M25PXX_SE, offset, len);
 }
diff --git a/drivers/mtd/spi/winbond.c b/drivers/mtd/spi/winbond.c
index 72d94ad..e8d30ae 100644
--- a/drivers/mtd/spi/winbond.c
+++ b/drivers/mtd/spi/winbond.c
@@ -170,7 +170,7 @@ out:
 	return ret;
 }
 
-int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
+static int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	return spi_flash_cmd_erase(flash, CMD_W25_SE, offset, len);
 }
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 6/9] cmd_sf: add handler for +len arg for erase command
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
                   ` (4 preceding siblings ...)
  2011-04-12  6:35 ` [U-Boot] [PATCH 5/9] sf: localize erase funcs Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-14 20:52   ` Richard Retanubun
  2011-04-12  6:35 ` [U-Boot] [PATCH 7/9] sf: use print_size() for sector_size output Mike Frysinger
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

From: Richard Retanubun <RichardRetanubun@ruggedcom.com>

This patch adds [+]len handler for the erase command that will
automatically round up the requested erase length to the flash's
sector_size.

Signed-off-by: Richard Retanubun <RichardRetanubun@RuggedCom.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
Richard: I noticed some issues in your original patch, so please try
	this one instead and see if it still works for you.

 common/cmd_sf.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 6e7be81..afbef99 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -19,6 +19,47 @@
 
 static struct spi_flash *flash;
 
+
+/*
+ * This function computes the length argument for the erase command.
+ * The length on which the command is to operate can be given in two forms:
+ * 1. <cmd> offset len  - operate on <'offset',  'len')
+ * 2. <cmd> offset +len - operate on <'offset',  'round_up(len)')
+ * If the second form is used and the length doesn't fall on the
+ * sector boundary, than it will be adjusted to the next sector boundary.
+ * If it isn't in the flash, the function will fail (return -1).
+ * Input:
+ *    arg: length specification (i.e. both command arguments)
+ * Output:
+ *    len: computed length for operation
+ * Return:
+ *    1: success
+ *   -1: failure (bad format, bad address).
+ */
+static int sf_parse_len_arg(char *arg, ulong *len)
+{
+	char *ep;
+	char round_up_len; /* indicates if the "+length" form used */
+	ulong len_arg;
+
+	round_up_len = 0;
+	if (*arg == '+') {
+		round_up_len = 1;
+		++arg;
+	}
+
+	len_arg = simple_strtoul(arg, &ep, 16);
+	if (ep == arg || *ep != '\0')
+		return -1;
+
+	if (round_up_len && flash->sector_size > 0)
+		*len = ROUND(len_arg - 1, flash->sector_size);
+	else
+		*len = len_arg;
+
+	return 1;
+}
+
 static int do_spi_flash_probe(int argc, char * const argv[])
 {
 	unsigned int bus = 0;
@@ -135,8 +176,9 @@ static int do_spi_flash_erase(int argc, char * const argv[])
 	offset = simple_strtoul(argv[1], &endp, 16);
 	if (*argv[1] == 0 || *endp != 0)
 		goto usage;
-	len = simple_strtoul(argv[2], &endp, 16);
-	if (*argv[2] == 0 || *endp != 0)
+
+	ret = sf_parse_len_arg(argv[2], &len);
+	if (ret != 1)
 		goto usage;
 
 	ret = spi_flash_erase(flash, offset, len);
@@ -148,7 +190,7 @@ static int do_spi_flash_erase(int argc, char * const argv[])
 	return 0;
 
 usage:
-	puts("Usage: sf erase offset len\n");
+	puts("Usage: sf erase offset [+]len\n");
 	return 1;
 }
 
@@ -189,5 +231,6 @@ U_BOOT_CMD(
 	"				  `offset' to memory at `addr'\n"
 	"sf write addr offset len	- write `len' bytes from memory\n"
 	"				  at `addr' to flash at `offset'\n"
-	"sf erase offset len		- erase `len' bytes from `offset'"
+	"sf erase offset [+]len		- erase `len' bytes from `offset'\n"
+	"				  `+len' round up `len' to block size"
 );
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 7/9] sf: use print_size() for sector_size output
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
                   ` (5 preceding siblings ...)
  2011-04-12  6:35 ` [U-Boot] [PATCH 6/9] cmd_sf: add handler for +len arg for erase command Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 8/9] cmd_sf: drop device status message when probing Mike Frysinger
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/spi/spi_flash.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index ccb7e31..c75b716 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -297,8 +297,8 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 		goto err_manufacturer_probe;
 	}
 
-	printf("SF: Detected %s with page size %u, total ",
-	       flash->name, flash->sector_size);
+	printf("SF: Detected %s with page size ", flash->name);
+	print_size(flash->sector_size, ", total ");
 	print_size(flash->size, "\n");
 
 	spi_release_bus(spi);
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 8/9] cmd_sf: drop device status message when probing
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
                   ` (6 preceding siblings ...)
  2011-04-12  6:35 ` [U-Boot] [PATCH 7/9] sf: use print_size() for sector_size output Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-12  6:35 ` [U-Boot] [PATCH 9/9] cmd_sf: use cmd_usage() in more places Mike Frysinger
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

The common spi flash layer displays useful info when probing, so no
need for us to duplicate that.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 common/cmd_sf.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index afbef99..3abc4ff 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -106,9 +106,6 @@ static int do_spi_flash_probe(int argc, char * const argv[])
 		spi_flash_free(flash);
 	flash = new;
 
-	printf("%u KiB %s at %u:%u is now current device\n",
-			flash->size >> 10, flash->name, bus, cs);
-
 	return 0;
 
 usage:
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 9/9] cmd_sf: use cmd_usage() in more places
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
                   ` (7 preceding siblings ...)
  2011-04-12  6:35 ` [U-Boot] [PATCH 8/9] cmd_sf: drop device status message when probing Mike Frysinger
@ 2011-04-12  6:35 ` Mike Frysinger
  2011-04-13 19:28 ` [U-Boot] [PATCH 7/6] sf: sst: add support for SST25VF064C Mike Frysinger
  2011-04-13 19:40 ` [U-Boot] Pull request u-boot-blackfin.git (sf branch) Mike Frysinger
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-12  6:35 UTC (permalink / raw)
  To: u-boot

Requires a little reworking of the code flow with sub-functions, but
not a big deal.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 common/cmd_sf.c |   59 +++++++++++++++++++++++++++----------------------------
 1 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 3abc4ff..11a491d 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -70,30 +70,30 @@ static int do_spi_flash_probe(int argc, char * const argv[])
 	struct spi_flash *new;
 
 	if (argc < 2)
-		goto usage;
+		return -1;
 
 	cs = simple_strtoul(argv[1], &endp, 0);
 	if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
-		goto usage;
+		return -1;
 	if (*endp == ':') {
 		if (endp[1] == 0)
-			goto usage;
+			return -1;
 
 		bus = cs;
 		cs = simple_strtoul(endp + 1, &endp, 0);
 		if (*endp != 0)
-			goto usage;
+			return -1;
 	}
 
 	if (argc >= 3) {
 		speed = simple_strtoul(argv[2], &endp, 0);
 		if (*argv[2] == 0 || *endp != 0)
-			goto usage;
+			return -1;
 	}
 	if (argc >= 4) {
 		mode = simple_strtoul(argv[3], &endp, 16);
 		if (*argv[3] == 0 || *endp != 0)
-			goto usage;
+			return -1;
 	}
 
 	new = spi_flash_probe(bus, cs, speed, mode);
@@ -107,10 +107,6 @@ static int do_spi_flash_probe(int argc, char * const argv[])
 	flash = new;
 
 	return 0;
-
-usage:
-	puts("Usage: sf probe [bus:]cs [hz] [mode]\n");
-	return 1;
 }
 
 static int do_spi_flash_read_write(int argc, char * const argv[])
@@ -123,17 +119,17 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
 	int ret;
 
 	if (argc < 4)
-		goto usage;
+		return -1;
 
 	addr = simple_strtoul(argv[1], &endp, 16);
 	if (*argv[1] == 0 || *endp != 0)
-		goto usage;
+		return -1;
 	offset = simple_strtoul(argv[2], &endp, 16);
 	if (*argv[2] == 0 || *endp != 0)
-		goto usage;
+		return -1;
 	len = simple_strtoul(argv[3], &endp, 16);
 	if (*argv[3] == 0 || *endp != 0)
-		goto usage;
+		return -1;
 
 	buf = map_physmem(addr, len, MAP_WRBACK);
 	if (!buf) {
@@ -154,10 +150,6 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
 	}
 
 	return 0;
-
-usage:
-	printf("Usage: sf %s addr offset len\n", argv[0]);
-	return 1;
 }
 
 static int do_spi_flash_erase(int argc, char * const argv[])
@@ -168,15 +160,15 @@ static int do_spi_flash_erase(int argc, char * const argv[])
 	int ret;
 
 	if (argc < 3)
-		goto usage;
+		return -1;
 
 	offset = simple_strtoul(argv[1], &endp, 16);
 	if (*argv[1] == 0 || *endp != 0)
-		goto usage;
+		return -1;
 
 	ret = sf_parse_len_arg(argv[2], &len);
 	if (ret != 1)
-		goto usage;
+		return -1;
 
 	ret = spi_flash_erase(flash, offset, len);
 	if (ret) {
@@ -185,24 +177,25 @@ static int do_spi_flash_erase(int argc, char * const argv[])
 	}
 
 	return 0;
-
-usage:
-	puts("Usage: sf erase offset [+]len\n");
-	return 1;
 }
 
 static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	const char *cmd;
+	int ret;
 
 	/* need@least two arguments */
 	if (argc < 2)
 		goto usage;
 
 	cmd = argv[1];
+	--argc;
+	++argv;
 
-	if (strcmp(cmd, "probe") == 0)
-		return do_spi_flash_probe(argc - 1, argv + 1);
+	if (strcmp(cmd, "probe") == 0) {
+		ret = do_spi_flash_probe(argc, argv);
+		goto done;
+	}
 
 	/* The remaining commands require a selected device */
 	if (!flash) {
@@ -211,9 +204,15 @@ static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
 	}
 
 	if (strcmp(cmd, "read") == 0 || strcmp(cmd, "write") == 0)
-		return do_spi_flash_read_write(argc - 1, argv + 1);
-	if (strcmp(cmd, "erase") == 0)
-		return do_spi_flash_erase(argc - 1, argv + 1);
+		ret = do_spi_flash_read_write(argc, argv);
+	else if (strcmp(cmd, "erase") == 0)
+		ret = do_spi_flash_erase(argc, argv);
+	else
+		ret = -1;
+
+done:
+	if (ret != -1)
+		return ret;
 
 usage:
 	return cmd_usage(cmdtp);
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 7/6] sf: sst: add support for SST25VF064C
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
                   ` (8 preceding siblings ...)
  2011-04-12  6:35 ` [U-Boot] [PATCH 9/9] cmd_sf: use cmd_usage() in more places Mike Frysinger
@ 2011-04-13 19:28 ` Mike Frysinger
  2011-04-13 19:40 ` [U-Boot] Pull request u-boot-blackfin.git (sf branch) Mike Frysinger
  10 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-13 19:28 UTC (permalink / raw)
  To: u-boot

From: James Kosin <jkosin@intcomgrp.com>

Signed-off-by: James Kosin <jkosin@intcomgrp.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/spi/sst.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c
index 0733deb..4dc2db2 100644
--- a/drivers/mtd/spi/sst.c
+++ b/drivers/mtd/spi/sst.c
@@ -71,6 +71,10 @@ static const struct sst_spi_flash_params sst_spi_flash_table[] = {
 		.nr_sectors = 1024,
 		.name = "SST25VF032B",
 	},{
+		.idcode1 = 0x4b,
+		.nr_sectors = 2048,
+		.name = "SST25VF064C",
+	},{
 		.idcode1 = 0x01,
 		.nr_sectors = 16,
 		.name = "SST25WF512",
-- 
1.7.5.rc1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] Pull request u-boot-blackfin.git (sf branch)
  2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
                   ` (9 preceding siblings ...)
  2011-04-13 19:28 ` [U-Boot] [PATCH 7/6] sf: sst: add support for SST25VF064C Mike Frysinger
@ 2011-04-13 19:40 ` Mike Frysinger
  2011-04-13 20:12   ` Wolfgang Denk
  10 siblings, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2011-04-13 19:40 UTC (permalink / raw)
  To: u-boot

The following changes since commit b16aadf411280fc426d7488ddd8a5b2038b7194d:

  disk/part.c: fix potential stack overflow bug (2011-04-12 22:58:35 +0200)

are available in the git repository at:
  git://www.denx.de/git/u-boot-blackfin.git sf

James Kosin (1):
      sf: sst: add support for SST25VF064C

Mike Frysinger (7):
      sf: punt unused spi_flash_region struct
      sf: atmel: undo unification of status polling
      sf: sst: setup read func
      sf: localize erase funcs
      sf: use print_size() for sector_size output
      cmd_sf: drop device status message when probing
      cmd_sf: use cmd_usage() in more places

Richard Retanubun (2):
      sf: add struct spi_flash.sector_size parameter
      cmd_sf: add handler for +len arg for erase command

 common/cmd_sf.c                      |  111 +++++++++++++++++++++++-----------
 drivers/mtd/spi/atmel.c              |   40 ++++++++++---
 drivers/mtd/spi/eon.c                |   13 +---
 drivers/mtd/spi/macronix.c           |   17 ++----
 drivers/mtd/spi/ramtron.c            |    5 +-
 drivers/mtd/spi/spansion.c           |   15 +----
 drivers/mtd/spi/spi_flash.c          |    9 ++-
 drivers/mtd/spi/spi_flash_internal.h |    2 +-
 drivers/mtd/spi/sst.c                |   17 +++---
 drivers/mtd/spi/stmicro.c            |   15 +----
 drivers/mtd/spi/winbond.c            |   13 +---
 include/spi_flash.h                  |    7 +--
 12 files changed, 148 insertions(+), 116 deletions(-)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] Pull request u-boot-blackfin.git (sf branch)
  2011-04-13 19:40 ` [U-Boot] Pull request u-boot-blackfin.git (sf branch) Mike Frysinger
@ 2011-04-13 20:12   ` Wolfgang Denk
  0 siblings, 0 replies; 15+ messages in thread
From: Wolfgang Denk @ 2011-04-13 20:12 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <1302723612-22844-1-git-send-email-vapier@gentoo.org> you wrote:
> The following changes since commit b16aadf411280fc426d7488ddd8a5b2038b7194d:
> 
>   disk/part.c: fix potential stack overflow bug (2011-04-12 22:58:35 +0200)
> 
> are available in the git repository at:
>   git://www.denx.de/git/u-boot-blackfin.git sf
> 
> James Kosin (1):
>       sf: sst: add support for SST25VF064C
> 
> Mike Frysinger (7):
>       sf: punt unused spi_flash_region struct
>       sf: atmel: undo unification of status polling
>       sf: sst: setup read func
>       sf: localize erase funcs
>       sf: use print_size() for sector_size output
>       cmd_sf: drop device status message when probing
>       cmd_sf: use cmd_usage() in more places
> 
> Richard Retanubun (2):
>       sf: add struct spi_flash.sector_size parameter
>       cmd_sf: add handler for +len arg for erase command
> 
>  common/cmd_sf.c                      |  111 +++++++++++++++++++++++-----------
>  drivers/mtd/spi/atmel.c              |   40 ++++++++++---
>  drivers/mtd/spi/eon.c                |   13 +---
>  drivers/mtd/spi/macronix.c           |   17 ++----
>  drivers/mtd/spi/ramtron.c            |    5 +-
>  drivers/mtd/spi/spansion.c           |   15 +----
>  drivers/mtd/spi/spi_flash.c          |    9 ++-
>  drivers/mtd/spi/spi_flash_internal.h |    2 +-
>  drivers/mtd/spi/sst.c                |   17 +++---
>  drivers/mtd/spi/stmicro.c            |   15 +----
>  drivers/mtd/spi/winbond.c            |   13 +---
>  include/spi_flash.h                  |    7 +--
>  12 files changed, 148 insertions(+), 116 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Men don't talk peace unless they're ready to back it up with war.
	-- Col. Green, "The Savage Curtain", stardate 5906.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 6/9] cmd_sf: add handler for +len arg for erase command
  2011-04-12  6:35 ` [U-Boot] [PATCH 6/9] cmd_sf: add handler for +len arg for erase command Mike Frysinger
@ 2011-04-14 20:52   ` Richard Retanubun
  2011-04-15  7:49     ` Mike Frysinger
  0 siblings, 1 reply; 15+ messages in thread
From: Richard Retanubun @ 2011-04-14 20:52 UTC (permalink / raw)
  To: u-boot

On 04/12/11 02:35, Mike Frysinger wrote:
> From: Richard Retanubun<RichardRetanubun@ruggedcom.com>
>
> This patch adds [+]len handler for the erase command that will
> automatically round up the requested erase length to the flash's
> sector_size.
>
> Signed-off-by: Richard Retanubun<RichardRetanubun@RuggedCom.com>
> Signed-off-by: Mike Frysinger<vapier@gentoo.org>
> ---
> Richard: I noticed some issues in your original patch, so please try
> 	this one instead and see if it still works for you.
Hi Mike,

Code looks okay. I won't have time to test for a while. Feel free to mainline if it works for you
if it makes problems for me, I'll figure it out and poke you then.

- Richard

>
>   common/cmd_sf.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++----
>   1 files changed, 47 insertions(+), 4 deletions(-)
>
> diff --git a/common/cmd_sf.c b/common/cmd_sf.c
> index 6e7be81..afbef99 100644
> --- a/common/cmd_sf.c
> +++ b/common/cmd_sf.c
> @@ -19,6 +19,47 @@
>
>   static struct spi_flash *flash;
>
> +
> +/*
> + * This function computes the length argument for the erase command.
> + * The length on which the command is to operate can be given in two forms:
> + * 1.<cmd>  offset len  - operate on<'offset',  'len')
> + * 2.<cmd>  offset +len - operate on<'offset',  'round_up(len)')
> + * If the second form is used and the length doesn't fall on the
> + * sector boundary, than it will be adjusted to the next sector boundary.
> + * If it isn't in the flash, the function will fail (return -1).
> + * Input:
> + *    arg: length specification (i.e. both command arguments)
> + * Output:
> + *    len: computed length for operation
> + * Return:
> + *    1: success
> + *   -1: failure (bad format, bad address).
> + */
> +static int sf_parse_len_arg(char *arg, ulong *len)
> +{
> +	char *ep;
> +	char round_up_len; /* indicates if the "+length" form used */
> +	ulong len_arg;
> +
> +	round_up_len = 0;
> +	if (*arg == '+') {
> +		round_up_len = 1;
> +		++arg;
> +	}
> +
> +	len_arg = simple_strtoul(arg,&ep, 16);
> +	if (ep == arg || *ep != '\0')
> +		return -1;
> +
> +	if (round_up_len&&  flash->sector_size>  0)
> +		*len = ROUND(len_arg - 1, flash->sector_size);
> +	else
> +		*len = len_arg;
> +
> +	return 1;
> +}
> +
>   static int do_spi_flash_probe(int argc, char * const argv[])
>   {
>   	unsigned int bus = 0;
> @@ -135,8 +176,9 @@ static int do_spi_flash_erase(int argc, char * const argv[])
>   	offset = simple_strtoul(argv[1],&endp, 16);
>   	if (*argv[1] == 0 || *endp != 0)
>   		goto usage;
> -	len = simple_strtoul(argv[2],&endp, 16);
> -	if (*argv[2] == 0 || *endp != 0)
> +
> +	ret = sf_parse_len_arg(argv[2],&len);
> +	if (ret != 1)
>   		goto usage;
>
>   	ret = spi_flash_erase(flash, offset, len);
> @@ -148,7 +190,7 @@ static int do_spi_flash_erase(int argc, char * const argv[])
>   	return 0;
>
>   usage:
> -	puts("Usage: sf erase offset len\n");
> +	puts("Usage: sf erase offset [+]len\n");
>   	return 1;
>   }
>
> @@ -189,5 +231,6 @@ U_BOOT_CMD(
>   	"				  `offset' to memory at `addr'\n"
>   	"sf write addr offset len	- write `len' bytes from memory\n"
>   	"				  at `addr' to flash at `offset'\n"
> -	"sf erase offset len		- erase `len' bytes from `offset'"
> +	"sf erase offset [+]len		- erase `len' bytes from `offset'\n"
> +	"				  `+len' round up `len' to block size"
>   );

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH 6/9] cmd_sf: add handler for +len arg for erase command
  2011-04-14 20:52   ` Richard Retanubun
@ 2011-04-15  7:49     ` Mike Frysinger
  0 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2011-04-15  7:49 UTC (permalink / raw)
  To: u-boot

On Thursday, April 14, 2011 16:52:36 Richard Retanubun wrote:
> On 04/12/11 02:35, Mike Frysinger wrote:
> > This patch adds [+]len handler for the erase command that will
> > automatically round up the requested erase length to the flash's
> > sector_size.
> > ---
> > Richard: I noticed some issues in your original patch, so please try
> > 	this one instead and see if it still works for you.
> 
> Code looks okay. I won't have time to test for a while. Feel free to
> mainline if it works for you if it makes problems for me, I'll figure it
> out and poke you then.

ive already pushed it ;)

mainly the thing i noticed was that the boundary cases werent working as 
expected.  e.g. if the sector size was 0x10000, doing +0x10000 would round up 
to 0x20000.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110415/18c4d755/attachment.pgp 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2011-04-15  7:49 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-12  6:35 [U-Boot] [PATCH 0/9] SPI Flash updates for 2011.06 Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 1/9] sf: punt unused spi_flash_region struct Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 2/9] sf: atmel: undo unification of status polling Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 3/9] sf: add struct spi_flash.sector_size parameter Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 4/9] sf: sst: setup read func Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 5/9] sf: localize erase funcs Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 6/9] cmd_sf: add handler for +len arg for erase command Mike Frysinger
2011-04-14 20:52   ` Richard Retanubun
2011-04-15  7:49     ` Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 7/9] sf: use print_size() for sector_size output Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 8/9] cmd_sf: drop device status message when probing Mike Frysinger
2011-04-12  6:35 ` [U-Boot] [PATCH 9/9] cmd_sf: use cmd_usage() in more places Mike Frysinger
2011-04-13 19:28 ` [U-Boot] [PATCH 7/6] sf: sst: add support for SST25VF064C Mike Frysinger
2011-04-13 19:40 ` [U-Boot] Pull request u-boot-blackfin.git (sf branch) Mike Frysinger
2011-04-13 20:12   ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox