public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] avoid flash writes for new keys, with no values with fw_setenv
@ 2011-12-21  8:59 Sridhar Addagada
  2012-01-05 16:19 ` Wolfgang Denk
  0 siblings, 1 reply; 2+ messages in thread
From: Sridhar Addagada @ 2011-12-21  8:59 UTC (permalink / raw)
  To: u-boot

This will avoid flash writes for fw_setenv command where the key is not present the environment and no value has been provided.

Signed-off-by: Sridhar Addagada <sridhar_a@yahoo.com>
---
tools/env/fw_env.c |   11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 996682e..68597a5 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -366,7 +366,7 @@ int fw_env_close(void)
*/
int fw_env_write(char *name, char *value)
{
-	int len;
+	int len, found = 0;
char *env, *nxt;
char *oldval = NULL;

@@ -415,7 +415,7 @@ int fw_env_write(char *name, char *value)

/* Delete only ? */
if (!value || !strlen(value))
-		return 0;
+		return (found ? 0 : -1);

/*
* Append new definition at the end
@@ -460,7 +460,7 @@ int fw_env_write(char *name, char *value)
*/
int fw_setenv(int argc, char *argv[])
{
-	int i, len;
+	int r, i, len;
char *name;
char *value = NULL;
char *tmpval = NULL;
@@ -501,12 +501,13 @@ int fw_setenv(int argc, char *argv[])
*tmpval++ = *val++;
}

-	fw_env_write(name, value);
+	r = fw_env_write(name, value);

if (value)
free(value);

-	return fw_env_close();
+    // avoid flash write for new keys, with no values.
+	return ((-1 == r) ? r : fw_env_close());
}

/*
-- 
1.7.3.GIT

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-05 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-21  8:59 [U-Boot] [PATCH] avoid flash writes for new keys, with no values with fw_setenv Sridhar Addagada
2012-01-05 16:19 ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox