Message ID | 1555496657-9241-1-git-send-email-mark.jonas@de.bosch.com |
---|---|
State | Accepted |
Headers | show |
Series | [libubootenv] Address redundant environment flags with offset | expand |
Hi Leo, On 17/04/19 12:24, Mark Jonas wrote: > From: Leo Ruan <tingquan.ruan@cn.bosch.com> > > When fw_setenv calls function 'set_obsolete_flag' to set environment > flags from active to obsolete, the flags are addressed without an > offset from struct uboot_env_redund. Thus the redundant environment > flags are not updated, but the first byte of CRC32 is clean. The > redundant environment becomes invalid. > Thanks for catching this. > The issue is fixed by adding flags offset for setting obsolete flag. > > Signed-off-by: Leo Ruan <tingquan.ruan@cn.bosch.com> > Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com> > --- > src/uboot_env.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/src/uboot_env.c b/src/uboot_env.c > index 8e08097..74944fc 100644 > --- a/src/uboot_env.c > +++ b/src/uboot_env.c > @@ -373,22 +373,30 @@ devwrite_out: > > static int set_obsolete_flag(struct uboot_flash_env *dev) > { > + uint8_t offsetflags = offsetof(struct uboot_env_redund, flags); > unsigned char flag = 0; > struct erase_info_user erase; > + int ret = 0; > > dev->fd = open(dev->devname, O_RDWR); > if (dev->fd < 0) > return -EBADF; > - if (lseek(dev->fd, dev->offset, SEEK_SET) < 0) { > + if (lseek(dev->fd, dev->offset + offsetflags, SEEK_SET) < 0) { > close(dev->fd); > return -EBADF; > } > erase.start = dev->offset; > erase.length = dev->sectorsize; > ioctl(dev->fd, MEMUNLOCK, &erase); > - if (write(dev->fd, &flag, sizeof(flag)) != sizeof(flag)) > - return -EIO; > + ret = write(dev->fd, &flag, sizeof(flag)); > + if (ret == sizeof(flag)) > + ret = 0; > + else if (ret >= 0) > + ret = -EIO; > + ioctl (dev->fd, MEMLOCK, &erase); > close(dev->fd); > + > + return ret; > } > > int libuboot_env_store(struct uboot_ctx *ctx) > @@ -400,7 +408,6 @@ int libuboot_env_store(struct uboot_ctx *ctx) > bool saveflags = false; > size_t size; > uint8_t offsetdata; > - uint8_t offsetflags = offsetof(struct uboot_env_redund, flags); > int ret; > int copy; > > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/src/uboot_env.c b/src/uboot_env.c index 8e08097..74944fc 100644 --- a/src/uboot_env.c +++ b/src/uboot_env.c @@ -373,22 +373,30 @@ devwrite_out: static int set_obsolete_flag(struct uboot_flash_env *dev) { + uint8_t offsetflags = offsetof(struct uboot_env_redund, flags); unsigned char flag = 0; struct erase_info_user erase; + int ret = 0; dev->fd = open(dev->devname, O_RDWR); if (dev->fd < 0) return -EBADF; - if (lseek(dev->fd, dev->offset, SEEK_SET) < 0) { + if (lseek(dev->fd, dev->offset + offsetflags, SEEK_SET) < 0) { close(dev->fd); return -EBADF; } erase.start = dev->offset; erase.length = dev->sectorsize; ioctl(dev->fd, MEMUNLOCK, &erase); - if (write(dev->fd, &flag, sizeof(flag)) != sizeof(flag)) - return -EIO; + ret = write(dev->fd, &flag, sizeof(flag)); + if (ret == sizeof(flag)) + ret = 0; + else if (ret >= 0) + ret = -EIO; + ioctl (dev->fd, MEMLOCK, &erase); close(dev->fd); + + return ret; } int libuboot_env_store(struct uboot_ctx *ctx) @@ -400,7 +408,6 @@ int libuboot_env_store(struct uboot_ctx *ctx) bool saveflags = false; size_t size; uint8_t offsetdata; - uint8_t offsetflags = offsetof(struct uboot_env_redund, flags); int ret; int copy;