]> git.sur5r.net Git - u-boot/commitdiff
env: Handle write-once ethaddr and serial# generically
authorJoe Hershberger <joe.hershberger@ni.com>
Wed, 12 Dec 2012 04:16:37 +0000 (22:16 -0600)
committerTom Rini <trini@ti.com>
Thu, 13 Dec 2012 18:46:57 +0000 (11:46 -0700)
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>
common/env_flags.c
include/env_flags.h
tools/env/fw_env.c

index 4caf12e697035f3c912cb309065f6376fc264920..336cae4e9ff0fd1b810fc228adca9f4ee80c2886 100644 (file)
@@ -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)
index 0bdae078389e169d981ed0055278b69e4b86148d..d1aa1440f704dd2a58aef381c8427d02d746edad 100644 (file)
@@ -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
index a596a1b0dc84fbb4be9f864cf1b043c53d541d24..90c7a5d3f39fa37f76005f354976e8f9c8c1270e 100644 (file)
@@ -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 {