aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Hershberger <joe.hershberger@ni.com>2012-12-11 22:16:37 -0600
committerTom Rini <trini@ti.com>2012-12-13 11:46:57 -0700
commit1d6cd0a3f69b549a3fc7e735a045279e7a14947e (patch)
tree4abb7a50269c09b33e599f291bf6295b863e28e0
parent9d8d661d7fda6ccda1d5fc31565f207b7648bc6d (diff)
downloadu-boot-linaro-stable-1d6cd0a3f69b549a3fc7e735a045279e7a14947e.tar.gz
env: Handle write-once ethaddr and serial# generically
Use the variable access flags to implement the protection for ethaddr and serial# instead of hard-coding them. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
-rw-r--r--common/env_flags.c19
-rw-r--r--include/env_flags.h22
-rw-r--r--tools/env/fw_env.c17
3 files changed, 22 insertions, 36 deletions
diff --git a/common/env_flags.c b/common/env_flags.c
index 4caf12e69..336cae4e9 100644
--- a/common/env_flags.c
+++ b/common/env_flags.c
@@ -503,25 +503,6 @@ int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
/* Default value for NULL to protect string-manipulating functions */
newval = newval ? : "";
-#ifndef CONFIG_ENV_OVERWRITE
- /*
- * Some variables like "ethaddr" and "serial#" can be set only once and
- * cannot be deleted, unless CONFIG_ENV_OVERWRITE is defined.
- */
- if (op != env_op_create && /* variable exists */
- (flag & H_FORCE) == 0) { /* and we are not forced */
- if (strcmp(name, "serial#") == 0 ||
- (strcmp(name, "ethaddr") == 0
-#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
- && strcmp(oldval, __stringify(CONFIG_ETHADDR)) != 0
-#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
- )) {
- printf("Can't overwrite \"%s\"\n", name);
- return 1;
- }
- }
-#endif
-
/* validate the value to match the variable type */
if (op != env_op_delete) {
enum env_flags_vartype type = (enum env_flags_vartype)
diff --git a/include/env_flags.h b/include/env_flags.h
index 0bdae0783..d1aa1440f 100644
--- a/include/env_flags.h
+++ b/include/env_flags.h
@@ -53,7 +53,29 @@ enum env_flags_varaccess {
#define CONFIG_ENV_FLAGS_LIST_STATIC ""
#endif
+#ifdef CONFIG_CMD_NET
+#ifdef CONFIG_ENV_OVERWRITE
+#define ETHADDR_FLAGS "ethaddr:ma,"
+#else
+#ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
+#define ETHADDR_FLAGS "ethaddr:mc,"
+#else
+#define ETHADDR_FLAGS "ethaddr:mo,"
+#endif
+#endif
+#else
+#define ETHADDR_FLAGS ""
+#endif
+
+#ifndef CONFIG_ENV_OVERWRITE
+#define SERIAL_FLAGS "serial#:so,"
+#else
+#define SERIAL_FLAGS ""
+#endif
+
#define ENV_FLAGS_LIST_STATIC \
+ ETHADDR_FLAGS \
+ SERIAL_FLAGS \
CONFIG_ENV_FLAGS_LIST_STATIC
#ifdef CONFIG_CMD_ENV_FLAGS
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index a596a1b0d..90c7a5d3f 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -369,23 +369,6 @@ int fw_env_write(char *name, char *value)
return 0;
if (deleting || overwriting) {
-#ifndef CONFIG_ENV_OVERWRITE
- /*
- * Ethernet Address and serial# can be set only once
- */
- if (
- (strcmp(name, "serial#") == 0) ||
- ((strcmp(name, "ethaddr") == 0)
-#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
- && (strcmp(oldval, __stringify(CONFIG_ETHADDR)) != 0)
-#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
- ) ) {
- fprintf (stderr, "Can't overwrite \"%s\"\n", name);
- errno = EROFS;
- return -1;
- }
-#endif /* CONFIG_ENV_OVERWRITE */
-
if (*++nxt == '\0') {
*env = '\0';
} else {