[U-Boot] [PATCH 5/5] sf: Add sr-protect sub-command

George McCollister george.mccollister at gmail.com
Mon Oct 10 20:58:01 CEST 2016


Add an sf sub-command named sr-protect which allows the status register
protection method to be changed.

Valid settings are software, hardware, power and otp.

Signed-off-by: George McCollister <george.mccollister at gmail.com>
---
 cmd/sf.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/cmd/sf.c b/cmd/sf.c
index 65b117f..1a42bf6 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -380,6 +380,30 @@ static int do_spi_protect(int argc, char * const argv[])
 	return ret == 0 ? 0 : 1;
 }
 
+static int do_spi_sr_protect(int argc, char * const argv[])
+{
+	int ret;
+	enum srp_method method;
+
+	if (argc != 2)
+		return -1;
+
+	if (strcmp(argv[1], "software") == 0)
+		method = SRP_SOFTWARE;
+	else if (strcmp(argv[1], "hardware") == 0)
+		method = SRP_HARDWARE;
+	else if (strcmp(argv[1], "power") == 0)
+		method = SRP_POWER;
+	else if (strcmp(argv[1], "otp") == 0)
+		method = SRP_OTP;
+	else
+		return -1;  /* Unknown parameter */
+
+	ret = spi_flash_sr_protect(flash, method);
+
+	return ret == 0 ? 0 : 1;
+}
+
 #ifdef CONFIG_CMD_SF_TEST
 enum {
 	STAGE_ERASE,
@@ -574,6 +598,8 @@ static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc,
 		ret = do_spi_flash_erase(argc, argv);
 	else if (strcmp(cmd, "protect") == 0)
 		ret = do_spi_protect(argc, argv);
+	else if (strcmp(cmd, "sr-protect") == 0)
+		ret = do_spi_sr_protect(argc, argv);
 #ifdef CONFIG_CMD_SF_TEST
 	else if (!strcmp(cmd, "test"))
 		ret = do_spi_flash_test(argc, argv);
@@ -615,5 +641,7 @@ U_BOOT_CMD(
 	"					  or to start of mtd `partition'\n"
 	"sf protect lock/unlock sector len	- protect/unprotect 'len' bytes starting\n"
 	"					  at address 'sector'\n"
+	"sf sr-protect method			- set status register protect method to\n"
+	"					  software, hardware, power or otp\n"
 	SF_TEST_HELP
 );
-- 
2.9.3



More information about the U-Boot mailing list