[U-Boot] [PATCH 1/2] tools/env: Fix variable delete operation

Fix crash introduced by a073d63a36524453a817ab029fad5b188f46127e when attempting to delete a variable.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com --- tools/env/fw_env.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 520ce3f..906ccbf 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -493,6 +493,8 @@ int fw_setenv(int argc, char *argv[]) char *val = argv[i]; size_t val_len = strlen(val);
+ if (value) + value[len - 1] = ' '; value = realloc(value, len + val_len + 1); if (!value) { fprintf(stderr, @@ -503,9 +505,8 @@ int fw_setenv(int argc, char *argv[])
memcpy(value + len, val, val_len); len += val_len; - value[len++] = ' '; + value[len++] = '\0'; } - value[len - 1] = '\0';
fw_env_write(name, value);

Provide more information when using redundant environments Consistently print debug info to stderr
Signed-off-by: Joe Hershberger joe.hershberger@ni.com --- tools/env/fw_env.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 906ccbf..fecb077 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -738,8 +738,8 @@ static int flash_read_buf (int dev, int fd, void *buf, size_t count, return -1; } #ifdef DEBUG - fprintf (stderr, "Read 0x%x bytes at 0x%llx\n", - rc, blockstart + block_seek); + fprintf(stderr, "Read 0x%x bytes at 0x%llx on %s\n", + rc, blockstart + block_seek, DEVNAME(dev)); #endif processed += readlen; readlen = min (blocklen, count - processed); @@ -818,6 +818,18 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count, if (write_total != rc) return -1;
+#ifdef DEBUG + fprintf(stderr, "Preserving data "); + if (block_seek != 0) + fprintf(stderr, "0x%x - 0x%lx", 0, block_seek - 1); + if (block_seek + count != write_total) { + if (block_seek != 0) + fprintf(stderr, " and "); + fprintf(stderr, "0x%lx - 0x%x", + block_seek + count, write_total - 1); + } + fprintf(stderr, "\n"); +#endif /* Overwrite the old environment */ memcpy (data + block_seek, buf, count); } else { @@ -876,7 +888,8 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count, }
#ifdef DEBUG - printf ("Write 0x%x bytes at 0x%llx\n", erasesize, blockstart); + fprintf(stderr, "Write 0x%x bytes at 0x%llx\n", erasesize, + blockstart); #endif if (write (fd, data + processed, erasesize) != erasesize) { fprintf (stderr, "Write error on %s: %s\n", @@ -943,7 +956,7 @@ static int flash_write (int fd_current, int fd_target, int dev_target) }
#ifdef DEBUG - printf ("Writing new environment at 0x%lx on %s\n", + fprintf(stderr, "Writing new environment at 0x%lx on %s\n", DEVOFFSET (dev_target), DEVNAME (dev_target)); #endif rc = flash_write_buf(dev_target, fd_target, environment.image, @@ -957,7 +970,8 @@ static int flash_write (int fd_current, int fd_target, int dev_target) off_t offset = DEVOFFSET (dev_current) + offsetof (struct env_image_redundant, flags); #ifdef DEBUG - printf ("Setting obsolete flag in environment at 0x%lx on %s\n", + fprintf(stderr, + "Setting obsolete flag in environment at 0x%lx on %s\n", DEVOFFSET (dev_current), DEVNAME (dev_current)); #endif flash_flag_obsolete (dev_current, fd_current, offset); @@ -1224,6 +1238,9 @@ int fw_env_open(void) /* Other pointers are already set */ free (addr1); } +#ifdef DEBUG + fprintf(stderr, "Selected env in %s\n", DEVNAME(dev_current)); +#endif } return 0; }

On Mon, Oct 15, 2012 at 08:29:25PM -0500, Joe Hershberger wrote:
Provide more information when using redundant environments Consistently print debug info to stderr
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot/master, thanks!

On Mon, Oct 15, 2012 at 08:29:24PM -0500, Joe Hershberger wrote:
Fix crash introduced by a073d63a36524453a817ab029fad5b188f46127e when attempting to delete a variable.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot/master, thanks!
participants (2)
-
Joe Hershberger
-
Tom Rini