Patchwork [U-Boot,2/3] cmd_sf: add 'release' command

login
register
mail settings
Submitter Valentin Longchamp
Date Sept. 17, 2013, 6:46 a.m.
Message ID <1379400379-5759-3-git-send-email-valentin.longchamp@keymile.com>
Download mbox | patch
Permalink /patch/275383/
State Under Review
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Comments

Valentin Longchamp - Sept. 17, 2013, 6:46 a.m.
The release command is the pendant of the probe command. This command
allows to call spi_flash_free from the command line. This may be
necessary for some boards where sf probe does change the state of the
hardware (like with some pin multiplexing changes for instance).

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
---
 common/cmd_sf.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Patch

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 4af0f0a..b8ef3f4 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -133,6 +133,14 @@  static int do_spi_flash_probe(int argc, char * const argv[])
 	return 0;
 }
 
+static int do_spi_flash_release(int argc, char * const argv[])
+{
+	if (flash)
+		spi_flash_free(flash);
+	flash = NULL;
+
+	return 0;
+}
 /**
  * Write a block of data to SPI flash, first checking if it is different from
  * what is already there.
@@ -501,6 +509,8 @@  static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc,
 		ret = do_spi_flash_read_write(argc, argv);
 	else if (strcmp(cmd, "erase") == 0)
 		ret = do_spi_flash_erase(argc, argv);
+	else if (strcmp(cmd, "release") == 0)
+		ret = do_spi_flash_release(argc, argv);
 #ifdef CONFIG_CMD_SF_TEST
 	else if (!strcmp(cmd, "test"))
 		ret = do_spi_flash_test(argc, argv);
@@ -535,6 +545,7 @@  U_BOOT_CMD(
 	"sf erase offset [+]len		- erase `len' bytes from `offset'\n"
 	"				  `+len' round up `len' to block size\n"
 	"sf update addr offset len	- erase and write `len' bytes from memory\n"
-	"				  at `addr' to flash at `offset'"
+	"				  at `addr' to flash at `offset'\n"
+	"sf release			- release the current flash device"
 	SF_TEST_HELP
 );