Skip to contentSkip to conversation

SPI flash enhancements: allow default bus and chip-selects

PATCH New Eric Nelson 4 participants 8 messages Jan 30, 2012 – Jan 31, 2012

lore
Share & tools
lore
#0 lore raw

cover SPI flash enhancements: allow default bus and chip-selects

Patch 1 modifies the 'sf' command to allow a default bus and chip-select to be specified by board headers. This allows a bare 'sf' probe command:
U-Boot> sf probe
instead of the more cumbersome usage when a GPIO is tacked onto the chip-select. Otherwise, this command-line would be needed to specify GP3:19 on SabreLite:

      U-Boot> sf probe 0x5300

Patch 2 provides a description of usage and configuration of CONFIG_CMD_SF.

#1 lore raw

PATCH 1/2 sf command: allow default bus and chip selects

This patch allows a board configuration file to provide default bus and chip-selects for SPI flash so that first argument to the 'sf' command is optional.

On boards that use the mxc_spi driver and a GPIO for chip select, this allows a much simpler command line:
U-Boot> sf probe
instead of

	U-Boot> sf probe 0x5300
---
 common/cmd_sf.c |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)
common/cmd_sf.c +21 -16
index 612fd18..98e4162 100644
@@ -17,6 +17,12 @@
 #ifndef CONFIG_SF_DEFAULT_MODE
 # define CONFIG_SF_DEFAULT_MODE		SPI_MODE_3
 #endif
+#ifndef CONFIG_SF_DEFAULT_CS
+# define CONFIG_SF_DEFAULT_CS		0
+#endif
+#ifndef CONFIG_SF_DEFAULT_BUS
+# define CONFIG_SF_DEFAULT_BUS		0
+#endif
 
 static struct spi_flash *flash;
 
@@ -63,27 +69,26 @@ static int sf_parse_len_arg(char *arg, ulong *len)
 
 static int do_spi_flash_probe(int argc, char * const argv[])
 {
-	unsigned int bus = 0;
-	unsigned int cs;
+	unsigned int bus = CONFIG_SF_DEFAULT_BUS;
+	unsigned int cs = CONFIG_SF_DEFAULT_CS;
 	unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
 	unsigned int mode = CONFIG_SF_DEFAULT_MODE;
 	char *endp;
 	struct spi_flash *new;
 
-	if (argc < 2)
-		return -1;
-
-	cs = simple_strtoul(argv[1], &endp, 0);
-	if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
-		return -1;
-	if (*endp == ':') {
-		if (endp[1] == 0)
-			return -1;
-
-		bus = cs;
-		cs = simple_strtoul(endp + 1, &endp, 0);
-		if (*endp != 0)
+	if (argc >= 2) {
+		cs = simple_strtoul(argv[1], &endp, 0);
+		if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
 			return -1;
+		if (*endp == ':') {
+			if (endp[1] == 0)
+				return -1;
+
+			bus = cs;
+			cs = simple_strtoul(endp + 1, &endp, 0);
+			if (*endp != 0)
+				return -1;
+		}
 	}
 
 	if (argc >= 3) {
@@ -299,7 +304,7 @@ usage:
 U_BOOT_CMD(
 	sf,	5,	1,	do_spi_flash,
 	"SPI flash sub-system",
-	"probe [bus:]cs [hz] [mode]	- init flash device on given SPI bus\n"
+	"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"
Signature · 1 line
1.7.1
#2 lore raw

PATCH 1/2 sf command: allow default bus and chip selects

Works fine.

Matthias

Quoted 14 lines · Eric Nelson

This patch allows a board configuration file to provide default bus and chip-selects for SPI flash so that first argument to the 'sf' command is optional.

On boards that use the mxc_spi driver and a GPIO for chip select, this allows a much simpler command line:
U-Boot> sf probe
instead of

	U-Boot> sf probe 0x5300
---
 common/cmd_sf.c |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)
#3 lore raw

PATCH 2/2 README: Add description of SPI Flash (SF) command configuration

In reply to Eric Nelson
---
 README |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
README +20 -0
index 9d713e8..4dbebcb 100644
@@ -809,6 +809,7 @@ The following options need to be configured:
 					  (requires CONFIG_CMD_I2C)
 		CONFIG_CMD_SETGETDCR	  Support for DCR Register access
 					  (4xx only)
+		CONFIG_CMD_SF		* Read/write/erase SPI NOR flash
 		CONFIG_CMD_SHA1SUM	  print sha1 memory digest
 					  (requires CONFIG_CMD_MEMORY)
 		CONFIG_CMD_SOURCE	  "source" command Support
@@ -2191,6 +2192,25 @@ The following options need to be configured:
 		allows to read/write in Dataflash via the standard
 		commands cp, md...
 
+- Serial Flash support
+		CONFIG_CMD_SF
+
+		Defining this option enables SPI flash commands
+		'sf probe/read/write/erase/update'.
+
+		Usage requires an initial 'probe' to define the serial
+		flash parameters, followed by read/write/erase/update
+		commands.
+
+		The following defaults may be provided by the platform
+		to handle the common case when only a single serial
+		flash is present on the system.
+
+		CONFIG_SF_DEFAULT_BUS		Bus identifier
+		CONFIG_SF_DEFAULT_CS		Chip-select
+		CONFIG_SF_DEFAULT_MODE 		(see include/spi.h)
+		CONFIG_SF_DEFAULT_SPEED		in Hz
+
 - SystemACE Support:
 		CONFIG_SYSTEMACE
 
Signature · 1 line
1.7.1
#4 lore raw

cover SPI flash enhancements: allow default bus and chip-selects

In reply to Eric Nelson
Quoted 9 lines · On Monday 30 January 2012 15:02:24 Eric Nelson wrote:

Patch 1 modifies the 'sf' command to allow a default bus and chip-select to be specified by board headers. This allows a bare 'sf' probe command:
U-Boot> sf probe
instead of the more cumbersome usage when a GPIO is tacked onto the chip-select. Otherwise, this command-line would be needed to specify GP3:19 on SabreLite:

      U-Boot> sf probe 0x5300

Patch 2 provides a description of usage and configuration of CONFIG_CMD_SF.

thanks, i'll merge both into my sf branch and then push to wolfgang for next merge window (if he doesn't pick things up directly himself)
-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/20120131/f5824209/attachment.pgp>

#5 lore raw

cover SPI flash enhancements: allow default bus and chip-selects

Quoted 9 lines · Mike Frysinger
Quoted 8 lines · On Monday 30 January 2012 15:02:24 Eric Nelson wrote:

Patch 1 modifies the 'sf' command to allow a default bus and chip-select to be specified by board headers. This allows a bare 'sf' probe command:
U-Boot> sf probe
instead of the more cumbersome usage when a GPIO is tacked onto the chip-select. Otherwise, this command-line would be needed to specify GP3:19 on SabreLite:

       U-Boot>  sf probe 0x5300
Quoted 5 lines
Quoted 1 line

Patch 2 provides a description of usage and configuration of CONFIG_CMD_SF.

thanks, i'll merge both into my sf branch and then push to wolfgang for next merge window (if he doesn't pick things up directly himself) -mike

Thanks Mike

#6 lore raw

cover SPI flash enhancements: allow default bus and chip-selects

In reply to Mike Frysinger
Quoted 9 lines · Mike Frysinger
Quoted 8 lines · On Monday 30 January 2012 15:02:24 Eric Nelson wrote:

Patch 1 modifies the 'sf' command to allow a default bus and chip-select to be specified by board headers. This allows a bare 'sf' probe command:
U-Boot> sf probe
instead of the more cumbersome usage when a GPIO is tacked onto the chip-select. Otherwise, this command-line would be needed to specify GP3:19 on SabreLite:

       U-Boot>  sf probe 0x5300
Quoted 4 lines
Quoted 1 line

Patch 2 provides a description of usage and configuration of CONFIG_CMD_SF.

thanks, i'll merge both into my sf branch and then push to wolfgang for next merge window (if he doesn't pick things up directly himself)

As we had the first version of the initial patch series already at the list while the last merge window was still open, I was hoping for a chance to get this into v2012.03 ;)

Anyway, many thanks and best regards

Dirk

#7 lore raw

cover SPI flash enhancements: allow default bus and chip-selects

Quoted 16 lines · On Tuesday 31 January 2012 11:21:29 Dirk Behme wrote:
Quoted 15 lines · Mike Frysinger
Quoted 13 lines · On Monday 30 January 2012 15:02:24 Eric Nelson wrote:

Patch 1 modifies the 'sf' command to allow a default bus and chip-select

to be specified by board headers. This allows a bare 'sf' probe command:
U-Boot> sf probe

instead of the more cumbersome usage when a GPIO is tacked onto the chip-select. Otherwise, this command-line would be needed

to specify GP3:19 on SabreLite:

       U-Boot>  sf probe 0x5300

Patch 2 provides a description of usage and configuration of CONFIG_CMD_SF.

Quoted 6 lines
Quoted 2 lines

thanks, i'll merge both into my sf branch and then push to wolfgang for next merge window (if he doesn't pick things up directly himself)

As we had the first version of the initial patch series already at the list while the last merge window was still open, I was hoping for a chance to get this into v2012.03 ;)

i'm fine with pushing them through this merge window. i tend to just try and avoid any back&forths with Wolfgang in case it missed the merge window. less hassle that way.
-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/20120131/a11473cd/attachment.pgp>