>From fdeee62f0902b25be1a2a6bf52fb714b0f4f9e59 Mon Sep 17 00:00:00 2001 From: Stefan Althoefer <[EMAIL PROTECTED]> Date: Sun, 7 Dec 2008 14:17:08 +0100 Subject: [PATCH] common: nvedit to protect additional ethernet addresses
This adds "eth[0-9]+addr" to the protected environment variables that can only be written once. Code for detecting protected variables was restructured. Signed-off-by: Stefan Althoefer <[EMAIL PROTECTED]> --- This time I left god comments ;-) Also, as "grep -r sscanf u-boot" did not match, I hand-crafted the expression matching (hoping to not have overseen the u-boot regexp library). eth0addr will also match. I found no globally available MAX_ETH_ADDRS, so I dropped this idea. If one defines eth666addr, he will just find that he cannot delete it anymore. No more harm. common/cmd_nvedit.c | 30 ++++++++++++++++++++++++------ 1 files changed, 24 insertions(+), 6 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index d280cb0..18ac349 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -143,6 +143,11 @@ int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) int _do_setenv (int flag, int argc, char *argv[]) { int i, len, oldval; +#ifndef CONFIG_ENV_OVERWRITE + int protected; + int ethnum; + char *s; +#endif int console = -1; uchar *env, *nxt = NULL; char *name; @@ -181,18 +186,31 @@ int _do_setenv (int flag, int argc, char *argv[]) * Ethernet Address and serial# can be set only once, * ver is readonly. */ - if ( + protected = 0; #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; + + 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) + /* Allow "ethaddr" overwrite to change pre-configured address */ + if (strcmp ((char *)env_get_addr(oldval),MK_STR(CONFIG_ETHADDR)) != 0) #endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */ - ) ) { + protected = 1; + + /* "eth[0-9]+addr" is always protected */ + if (strncmp (name, "eth", 3) == 0) { + ethnum = simple_strtoul (name+3, &s, 10); + if (s != name + 3) + if (strcmp (s, "addr") == 0) + protected = 1; + } + + if (protected) { printf ("Can't overwrite \"%s\"\n", name); return 1; } -- 1.5.4.5 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot