All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: U-Boot Mailing List <u-boot@lists.denx.de>,
	Tom Rini <trini@konsulko.com>
Cc: Michael Walle <michael@walle.cc>,
	Jagan Teki <jagan@amarulasolutions.com>,
	 <Tudor.Ambarus@microchip.com>, Vignesh R <vigneshr@ti.com>,
	<baocheng.su@siemens.com>, chao zeng <chao.zeng@siemens.com>
Subject: [PATCH v6 2/2] sf: Query write-protection status before operating the flash
Date: Wed, 2 Mar 2022 15:01:56 +0100	[thread overview]
Message-ID: <5a760b8f30a392e82a2ea0cc4d3a158ea5880cfe.1646229716.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1646229716.git.jan.kiszka@siemens.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

Do not suggest successful operation if a flash area to be changed is
actually locked, thus will not execute the request. Rather report an
error and bail out. That's way more user-friendly than asking them to
manually check for this case.

Derived from original patch by Chao Zeng.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 cmd/sf.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/cmd/sf.c b/cmd/sf.c
index 8bdebd9fd8f..c97d0e28bb8 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -287,6 +287,12 @@ static int do_spi_flash_read_write(int argc, char *const argv[])
 		return 1;
 	}
 
+	if (strncmp(argv[0], "read", 4) != 0 && flash->flash_is_unlocked &&
+	    !flash->flash_is_unlocked(flash, offset, len)) {
+		printf("ERROR: flash area is locked\n");
+		return 1;
+	}
+
 	buf = map_physmem(addr, len, MAP_WRBACK);
 	if (!buf && addr) {
 		puts("Failed to map physical memory\n");
@@ -343,6 +349,12 @@ static int do_spi_flash_erase(int argc, char *const argv[])
 		return 1;
 	}
 
+	if (flash->flash_is_unlocked &&
+	    !flash->flash_is_unlocked(flash, offset, len)) {
+		printf("ERROR: flash area is locked\n");
+		return 1;
+	}
+
 	ret = spi_flash_erase(flash, offset, size);
 	printf("SF: %zu bytes @ %#x Erased: ", (size_t)size, (u32)offset);
 	if (ret)
-- 
2.34.1


  parent reply	other threads:[~2022-03-02 14:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 14:01 [PATCH v6 0/2] sf: Check protection before writing/erasing flash Jan Kiszka
2022-03-02 14:01 ` [PATCH v6 1/2] mtd: spi: Convert is_locked callback to is_unlocked Jan Kiszka
2022-03-02 14:01 ` Jan Kiszka [this message]
2022-05-28 12:07 ` [PATCH v6 0/2] sf: Check protection before writing/erasing flash Jan Kiszka
2022-05-31 19:45   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5a760b8f30a392e82a2ea0cc4d3a158ea5880cfe.1646229716.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=Tudor.Ambarus@microchip.com \
    --cc=baocheng.su@siemens.com \
    --cc=chao.zeng@siemens.com \
    --cc=jagan@amarulasolutions.com \
    --cc=michael@walle.cc \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.