[U-Boot] [PATCH] common: nvedit to protect additional ethernet addresses Part 1/1

Stefan Althoefer stefan.althoefer at web.de
Fri Dec 5 22:22:54 CET 2008


This patches cmd_nvedit to reject changes for "ethaddr." in addition to "ethaddr"
and "serial#". This is intendend to protect changes to additional ethernet
addresses (e.g. "ethernet1").

The code was rewritten to be more clear.


Signed-off-by: Stefan Althoefer <stefan.althoefer at web.de>
---
diff -uprN u-boot-orig/common/cmd_nvedit.c u-boot/common/cmd_nvedit.c
--- u-boot-orig/common/cmd_nvedit.c	2008-12-02 17:25:31.000000000 +0100
+++ u-boot/common/cmd_nvedit.c	2008-12-05 16:46:25.000000000 +0100
@@ -143,6 +143,9 @@ int do_printenv (cmd_tbl_t *cmdtp, int f
 int _do_setenv (int flag, int argc, char *argv[])
 {
 	int   i, len, oldval;
+#ifndef CONFIG_ENV_OVERWRITE
+	int   protected;
+#endif
 	int   console = -1;
 	uchar *env, *nxt = NULL;
 	char *name;
@@ -176,23 +179,29 @@ int _do_setenv (int flag, int argc, char
 	 */
 	if (oldval >= 0) {
 #ifndef CONFIG_ENV_OVERWRITE
+		protected = 0;

-		/*
-		 * Ethernet Address and serial# can be set only once,
-		 * ver is readonly.
-		 */
-		if (
+		/* "serial#" is protect unless allowed by 0xdeaf4add flag */
 #ifdef CONFIG_HAS_UID
-		/* Allow serial# forced overwrite with 0xdeaf4add flag */
-		    ((strcmp (name, "serial#") == 0) && (flag != 0xdeaf4add)) ||
+		if ((strcmp (name, "serial#") == 0) && (flag != 0xdeaf4add))
 #else
-		    (strcmp (name, "serial#") == 0) ||
+		if (strcmp (name, "serial#") == 0)
 #endif
-		    ((strcmp (name, "ethaddr") == 0)
+			protected = 1;
+
+		/* "ethaddr" is protected unless allowed by OVERWRITE_ONCE */
+		if (strcmp (name, "ethaddr") == 0)
 #if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
-		     && (strcmp ((char *)env_get_addr(oldval),MK_STR(CONFIG_ETHADDR)) != 0)
+			if (strcmp ((char *)env_get_addr(oldval),MK_STR(CONFIG_ETHADDR)) != 0)
 #endif	/* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
-		    ) ) {
+				protected = 1;
+
+		/* "ethaddr." is always protected */
+		if (strncmp (name, "ethaddr", 7) == 0)
+			if (strlen (name) == 8)
+				protected = 1;
+
+		if (protected) {
 			printf ("Can't overwrite \"%s\"\n", name);
 			return 1;
 		}



More information about the U-Boot mailing list