* [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use
@ 2021-12-08 14:33 Joakim Tjernlund
2021-12-13 17:22 ` Joakim Tjernlund
2021-12-20 16:16 ` Tom Rini
0 siblings, 2 replies; 6+ messages in thread
From: Joakim Tjernlund @ 2021-12-08 14:33 UTC (permalink / raw)
To: u-boot, Ivan Mikhaylov; +Cc: Joakim Tjernlund
Commit "fw_setenv: lock the flash only if it was locked before"
checks for Locked status with uninitialized erase data.
Address by moving the test for MEMISLOCKED.
Fixes: 8a726b852502 ("fw_setenv: lock the flash only if it was locked before")
Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
tools/env/fw_env.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index e39c39e23a..3da75be783 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1083,12 +1083,6 @@ 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) {
@@ -1108,6 +1102,10 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count)
if (DEVTYPE(dev) != MTD_ABSENT) {
erase.start = blockstart;
+ was_locked = ioctl(fd, MEMISLOCKED, &erase);
+ /* treat any errors as unlocked flash */
+ if (was_locked < 0)
+ was_locked = 0;
if (was_locked)
ioctl(fd, MEMUNLOCK, &erase);
/* These do not need an explicit erase cycle */
@@ -1163,7 +1161,6 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
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 */
@@ -1173,6 +1170,10 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
DEVNAME(dev));
return rc;
}
+ was_locked = ioctl(fd, MEMISLOCKED, &erase);
+ /* treat any errors as unlocked flash */
+ if (was_locked < 0)
+ was_locked = 0;
if (was_locked)
ioctl(fd, MEMUNLOCK, &erase);
rc = write(fd, &tmp, sizeof(tmp));
--
2.32.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use
2021-12-08 14:33 [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use Joakim Tjernlund
@ 2021-12-13 17:22 ` Joakim Tjernlund
2021-12-18 18:23 ` Joakim Tjernlund
2021-12-20 16:16 ` Tom Rini
1 sibling, 1 reply; 6+ messages in thread
From: Joakim Tjernlund @ 2021-12-13 17:22 UTC (permalink / raw)
To: u-boot, joe.hershberger, fr0st61te
+Joe Hershberger
Jocke
On Wed, 2021-12-08 at 15:33 +0100, Joakim Tjernlund wrote:
> Commit "fw_setenv: lock the flash only if it was locked before"
> checks for Locked status with uninitialized erase data.
> Address by moving the test for MEMISLOCKED.
>
> Fixes: 8a726b852502 ("fw_setenv: lock the flash only if it was locked before")
> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> ---
> tools/env/fw_env.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
> index e39c39e23a..3da75be783 100644
> --- a/tools/env/fw_env.c
> +++ b/tools/env/fw_env.c
> @@ -1083,12 +1083,6 @@ 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) {
> @@ -1108,6 +1102,10 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count)
>
> if (DEVTYPE(dev) != MTD_ABSENT) {
> erase.start = blockstart;
> + was_locked = ioctl(fd, MEMISLOCKED, &erase);
> + /* treat any errors as unlocked flash */
> + if (was_locked < 0)
> + was_locked = 0;
> if (was_locked)
> ioctl(fd, MEMUNLOCK, &erase);
> /* These do not need an explicit erase cycle */
> @@ -1163,7 +1161,6 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
> 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 */
> @@ -1173,6 +1170,10 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
> DEVNAME(dev));
> return rc;
> }
> + was_locked = ioctl(fd, MEMISLOCKED, &erase);
> + /* treat any errors as unlocked flash */
> + if (was_locked < 0)
> + was_locked = 0;
> if (was_locked)
> ioctl(fd, MEMUNLOCK, &erase);
> rc = write(fd, &tmp, sizeof(tmp));
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use
2021-12-13 17:22 ` Joakim Tjernlund
@ 2021-12-18 18:23 ` Joakim Tjernlund
2021-12-19 14:20 ` Ivan Mikhaylov
0 siblings, 1 reply; 6+ messages in thread
From: Joakim Tjernlund @ 2021-12-18 18:23 UTC (permalink / raw)
To: u-boot, joe.hershberger, fr0st61te
Ping?
Maybe just revert commit 8a726b852502 ("fw_setenv: lock the flash only if it was locked before") ?
________________________________________
From: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
Sent: 13 December 2021 18:22
To: u-boot@lists.denx.de; joe.hershberger@ni.com; fr0st61te@gmail.com
Subject: Re: [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use
+Joe Hershberger
Jocke
On Wed, 2021-12-08 at 15:33 +0100, Joakim Tjernlund wrote:
> Commit "fw_setenv: lock the flash only if it was locked before"
> checks for Locked status with uninitialized erase data.
> Address by moving the test for MEMISLOCKED.
>
> Fixes: 8a726b852502 ("fw_setenv: lock the flash only if it was locked before")
> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> ---
> tools/env/fw_env.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
> index e39c39e23a..3da75be783 100644
> --- a/tools/env/fw_env.c
> +++ b/tools/env/fw_env.c
> @@ -1083,12 +1083,6 @@ 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) {
> @@ -1108,6 +1102,10 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count)
>
> if (DEVTYPE(dev) != MTD_ABSENT) {
> erase.start = blockstart;
> + was_locked = ioctl(fd, MEMISLOCKED, &erase);
> + /* treat any errors as unlocked flash */
> + if (was_locked < 0)
> + was_locked = 0;
> if (was_locked)
> ioctl(fd, MEMUNLOCK, &erase);
> /* These do not need an explicit erase cycle */
> @@ -1163,7 +1161,6 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
> 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 */
> @@ -1173,6 +1170,10 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
> DEVNAME(dev));
> return rc;
> }
> + was_locked = ioctl(fd, MEMISLOCKED, &erase);
> + /* treat any errors as unlocked flash */
> + if (was_locked < 0)
> + was_locked = 0;
> if (was_locked)
> ioctl(fd, MEMUNLOCK, &erase);
> rc = write(fd, &tmp, sizeof(tmp));
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use
2021-12-18 18:23 ` Joakim Tjernlund
@ 2021-12-19 14:20 ` Ivan Mikhaylov
2021-12-19 15:28 ` Joakim Tjernlund
0 siblings, 1 reply; 6+ messages in thread
From: Ivan Mikhaylov @ 2021-12-19 14:20 UTC (permalink / raw)
To: Joakim Tjernlund, u-boot, joe.hershberger
On Sat, 2021-12-18 at 18:23 +0000, Joakim Tjernlund wrote:
> Ping?
> Maybe just revert commit 8a726b852502 ("fw_setenv: lock the flash
> only if it was locked before") ?
>
> ________________________________________
> From: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
> Sent: 13 December 2021 18:22
> To: u-boot@lists.denx.de; joe.hershberger@ni.com; fr0st61te@gmail.com
> Subject: Re: [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy
> MEMISLOCKED use
>
> +Joe Hershberger
>
> Jocke
>
> On Wed, 2021-12-08 at 15:33 +0100, Joakim Tjernlund wrote:
> > Commit "fw_setenv: lock the flash only if it was locked before"
> > checks for Locked status with uninitialized erase data.
> > Address by moving the test for MEMISLOCKED.
> >
> > Fixes: 8a726b852502 ("fw_setenv: lock the flash only if it was
> > locked before")
> > Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
Joakim, can you provide more detailed description about what you want
to fix or revert, please? In which case you see problems with
8a726b852502?
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use
2021-12-19 14:20 ` Ivan Mikhaylov
@ 2021-12-19 15:28 ` Joakim Tjernlund
0 siblings, 0 replies; 6+ messages in thread
From: Joakim Tjernlund @ 2021-12-19 15:28 UTC (permalink / raw)
To: u-boot, joe.hershberger, fr0st61te
On Sun, 2021-12-19 at 14:20 +0000, Ivan Mikhaylov wrote:
> On Sat, 2021-12-18 at 18:23 +0000, Joakim Tjernlund wrote:
> > Ping?
> > Maybe just revert commit 8a726b852502 ("fw_setenv: lock the flash
> > only if it was locked before") ?
> >
> > ________________________________________
> > From: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
> > Sent: 13 December 2021 18:22
> > To: u-boot@lists.denx.de; joe.hershberger@ni.com; fr0st61te@gmail.com
> > Subject: Re: [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy
> > MEMISLOCKED use
> >
> > +Joe Hershberger
> >
> > Jocke
> >
> > On Wed, 2021-12-08 at 15:33 +0100, Joakim Tjernlund wrote:
> > > Commit "fw_setenv: lock the flash only if it was locked before"
> > > checks for Locked status with uninitialized erase data.
> > > Address by moving the test for MEMISLOCKED.
> > >
> > > Fixes: 8a726b852502 ("fw_setenv: lock the flash only if it was
> > > locked before")
> > > Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
>
> Joakim, can you provide more detailed description about what you want
> to fix or revert, please? In which case you see problems with
> 8a726b852502?
>
> Thanks.
>
We see it when we set a variable to the same value it already had, then we get a locking error
from fw_setenv.
If you just look 1 min at the code you will see that 8a726b852502 sends garbage to MEMISLOCKED
Jocke
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use
2021-12-08 14:33 [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use Joakim Tjernlund
2021-12-13 17:22 ` Joakim Tjernlund
@ 2021-12-20 16:16 ` Tom Rini
1 sibling, 0 replies; 6+ messages in thread
From: Tom Rini @ 2021-12-20 16:16 UTC (permalink / raw)
To: Joakim Tjernlund; +Cc: u-boot, Ivan Mikhaylov
[-- Attachment #1: Type: text/plain, Size: 444 bytes --]
On Wed, Dec 08, 2021 at 03:33:11PM +0100, Joakim Tjernlund wrote:
> Commit "fw_setenv: lock the flash only if it was locked before"
> checks for Locked status with uninitialized erase data.
> Address by moving the test for MEMISLOCKED.
>
> Fixes: 8a726b852502 ("fw_setenv: lock the flash only if it was locked before")
> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
Applied to u-boot/master, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-12-20 16:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08 14:33 [PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use Joakim Tjernlund
2021-12-13 17:22 ` Joakim Tjernlund
2021-12-18 18:23 ` Joakim Tjernlund
2021-12-19 14:20 ` Ivan Mikhaylov
2021-12-19 15:28 ` Joakim Tjernlund
2021-12-20 16:16 ` Tom Rini
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.