From: Ivan Mikhaylov <fr0st61te@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 1/1] fw_setenv: lock the flash only if it was locked before
Date: Fri, 10 Jul 2020 19:54:18 +0300 [thread overview]
Message-ID: <20200710165418.15071-2-fr0st61te@gmail.com> (raw)
In-Reply-To: <20200710165418.15071-1-fr0st61te@gmail.com>
u-boot-env flash region lock/unlock may affect other regions than
u-boot-env, fw_setenv does this in a way 'Lock it in any cases'.
Change this to 'lock it if it was locked before'.
Signed-off-by: Ivan Mikhaylov <fr0st61te@gmail.com>
---
tools/env/fw_env.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 381739d28d..3c01f52f3b 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -989,6 +989,7 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count)
of the data */
loff_t blockstart; /* running start of the current block -
MEMGETBADBLOCK needs 64 bits */
+ int was_locked; /* flash lock flag */
int rc;
/*
@@ -1074,6 +1075,12 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count)
}
erase.length = erasesize;
+ if (DEVTYPE(dev) != MTD_ABSENT) {
+ was_locked = ioctl(fd, MEMISLOCKED, &erase);
+ /* treat any errors as unlocked flash */
+ if (was_locked < 0)
+ was_locked = 0;
+ }
/* This only runs once on NOR flash and SPI-dataflash */
while (processed < write_total) {
@@ -1093,7 +1100,8 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count)
if (DEVTYPE(dev) != MTD_ABSENT) {
erase.start = blockstart;
- ioctl(fd, MEMUNLOCK, &erase);
+ if (was_locked)
+ ioctl(fd, MEMUNLOCK, &erase);
/* These do not need an explicit erase cycle */
if (DEVTYPE(dev) != MTD_DATAFLASH)
if (ioctl(fd, MEMERASE, &erase) != 0) {
@@ -1121,8 +1129,10 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count)
return -1;
}
- if (DEVTYPE(dev) != MTD_ABSENT)
- ioctl(fd, MEMLOCK, &erase);
+ if (DEVTYPE(dev) != MTD_ABSENT) {
+ if (was_locked)
+ ioctl(fd, MEMLOCK, &erase);
+ }
processed += erasesize;
block_seek = 0;
@@ -1143,7 +1153,9 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
int rc;
struct erase_info_user erase;
char tmp = ENV_REDUND_OBSOLETE;
+ int was_locked; /* flash lock flag */
+ was_locked = ioctl(fd, MEMISLOCKED, &erase);
erase.start = DEVOFFSET(dev);
erase.length = DEVESIZE(dev);
/* This relies on the fact, that ENV_REDUND_OBSOLETE == 0 */
@@ -1153,9 +1165,11 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
DEVNAME(dev));
return rc;
}
- ioctl(fd, MEMUNLOCK, &erase);
+ if (was_locked)
+ ioctl(fd, MEMUNLOCK, &erase);
rc = write(fd, &tmp, sizeof(tmp));
- ioctl(fd, MEMLOCK, &erase);
+ if (was_locked)
+ ioctl(fd, MEMLOCK, &erase);
if (rc < 0)
perror("Could not set obsolete flag");
--
2.21.1
next prev parent reply other threads:[~2020-07-10 16:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-10 16:54 [PATCH 0/1] fw_setenv always locks flash whenever it tries to write Ivan Mikhaylov
2020-07-10 16:54 ` Ivan Mikhaylov [this message]
2020-07-31 21:40 ` [PATCH 1/1] fw_setenv: lock the flash only if it was locked before Tom Rini
2020-07-23 22:20 ` [PATCH 0/1] fw_setenv always locks flash whenever it tries to write Ivan Mikhaylov
2020-07-30 14:24 ` 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=20200710165418.15071-2-fr0st61te@gmail.com \
--to=fr0st61te@gmail.com \
--cc=u-boot@lists.denx.de \
/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.