[PATCH] fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED use

Joakim Tjernlund Joakim.Tjernlund at infinera.com
Sat Dec 18 19:23:18 CET 2021


Ping?
Maybe just revert commit 8a726b852502 ("fw_setenv: lock the flash only if it was locked before") ?

________________________________________
From: Joakim Tjernlund <Joakim.Tjernlund at infinera.com>
Sent: 13 December 2021 18:22
To: u-boot at lists.denx.de; joe.hershberger at ni.com; fr0st61te at 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 at 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));



More information about the U-Boot mailing list