[U-Boot] [PATCH 07/30] bdinfo: get mac address from environment

Mike Frysinger vapier at gentoo.org
Tue Feb 17 06:10:28 CET 2009


Add a new print_eth() function to automate the eth*addr env var acquisition
and display.  Affects all arches.

Signed-off-by: Mike Frysinger <vapier at gentoo.org>
CC: Nobuhiro Iwamatsu <iwamatsu at nigauri.org>
CC: Scott McNutt <smcnutt at psyent.com>
CC: Shinya Kuribayashi <skuribay at ruby.dti.ne.jp>
CC: Michal Simek <monstr at seznam.cz>
CC: Daniel Hellstrom <daniel at gaisler.com>
CC: Ben Warren <biggerbadderben at gmail.com>
---
 common/cmd_bdinfo.c |  120 ++++++++++++++-------------------------------------
 1 files changed, 32 insertions(+), 88 deletions(-)

diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
index 6af5749..700314b 100644
--- a/common/cmd_bdinfo.c
+++ b/common/cmd_bdinfo.c
@@ -31,6 +31,8 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static void print_num(const char *, ulong);
 
+static void print_eth(int idx);
+
 #ifndef CONFIG_ARM	/* PowerPC and other */
 static void print_lnum(const char *, u64);
 
@@ -39,7 +41,6 @@ static void print_str(const char *, const char *);
 
 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	int i;
 	bd_t *bd = gd->bd;
 	char buf[32];
 
@@ -90,44 +91,21 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	print_str ("pevfreq",	    strmhz(buf, bd->bi_pevfreq));
 #endif
 
-	puts ("ethaddr     =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	}
-
+	print_eth(0);
 #if defined(CONFIG_HAS_ETH1)
-	puts ("\neth1addr    =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]);
-	}
+	print_eth(1);
 #endif
-
 #if defined(CONFIG_HAS_ETH2)
-       puts ("\neth2addr    =");
-       for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet2addr[i]);
-	}
+	print_eth(2);
 #endif
-
 #if defined(CONFIG_HAS_ETH3)
-       puts ("\neth3addr    =");
-       for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet3addr[i]);
-	}
+	print_eth(3);
 #endif
-
 #if defined(CONFIG_HAS_ETH4)
-       puts ("\neth4addr    =");
-       for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet4addr[i]);
-	}
+	print_eth(4);
 #endif
-
 #if defined(CONFIG_HAS_ETH5)
-       puts ("\neth5addr    =");
-       for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet5addr[i]);
-	}
+	print_eth(5);
 #endif
 
 #ifdef CONFIG_HERMES
@@ -142,7 +120,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	int i;
 	bd_t *bd = gd->bd;
 
 	print_num ("memstart",		(ulong)bd->bi_memstart);
@@ -151,10 +128,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	print_num ("flashsize",		(ulong)bd->bi_flashsize);
 	print_num ("flashoffset",	(ulong)bd->bi_flashoffset);
 
-	puts ("ethaddr     =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	}
+	print_eth(0);
 	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 	printf ("baudrate    = %ld bps\n", bd->bi_baudrate);
 
@@ -165,9 +139,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-#if defined(CONFIG_CMD_NET)
-	int i;
-#endif
 	bd_t *bd = gd->bd;
 
 	print_num ("mem start",		(ulong)bd->bi_memstart);
@@ -182,10 +153,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #endif
 
 #if defined(CONFIG_CMD_NET)
-	puts ("ethaddr     =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	}
+	print_eth(0);
 	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
 
@@ -197,7 +165,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	int i;
 	bd_t *bd = gd->bd;
 	print_num ("mem start      ",	(ulong)bd->bi_memstart);
 	print_lnum ("mem size       ",	(u64)bd->bi_memsize);
@@ -209,10 +176,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	print_num ("sram size      ",	(ulong)bd->bi_sramsize);
 #endif
 #if defined(CONFIG_CMD_NET)
-	puts ("ethaddr     =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	}
+	print_eth(0);
 	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
 	printf ("baudrate    = %ld bps\n", (ulong)bd->bi_baudrate);
@@ -223,9 +187,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 {
 	bd_t *bd = gd->bd;
-#if defined(CONFIG_CMD_NET)
-	int i;
-#endif
 
 #ifdef DEBUG
 	print_num("bd address             ", (ulong) bd);
@@ -247,10 +208,7 @@ int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 	       CONFIG_SYS_GBL_DATA_SIZE);
 
 #if defined(CONFIG_CMD_NET)
-	puts("ethaddr                =");
-	for (i = 0; i < 6; ++i) {
-		printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	}
+	print_eth(0);
 	printf("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
 	printf("baudrate               = %6ld bps\n", bd->bi_baudrate);
@@ -262,7 +220,6 @@ static void print_str(const char *, const char *);
 
 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	int i;
 	bd_t *bd = gd->bd;
 	char buf[32];
 
@@ -289,30 +246,15 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	print_str ("vcofreq",		strmhz(buf, bd->bi_vcofreq));
 #endif
 #if defined(CONFIG_CMD_NET)
-	puts ("ethaddr     =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	}
-
+	print_eth(0);
 #if defined(CONFIG_HAS_ETH1)
-	puts ("\neth1addr    =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]);
-	}
+	print_eth(1);
 #endif
-
 #if defined(CONFIG_HAS_ETH2)
-	puts ("\neth2addr    =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet2addr[i]);
-	}
+	print_eth(2);
 #endif
-
 #if defined(CONFIG_HAS_ETH3)
-	puts ("\neth3addr    =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet3addr[i]);
-	}
+	print_eth(3);
 #endif
 
 	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
@@ -327,7 +269,6 @@ static void print_str(const char *, const char *);
 
 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	int i;
 	bd_t *bd = gd->bd;
 	char buf[32];
 
@@ -345,9 +286,7 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	print_num("flashsize",   (ulong)bd->bi_flashsize);
 	print_num("flashoffset", (ulong)bd->bi_flashoffset);
 
-	puts("ethaddr     =");
-	for (i = 0; i < 6; ++i)
-		printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
+	print_eth(0);
 	printf("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 	printf("baudrate    = %d bps\n", bd->bi_baudrate);
 
@@ -358,7 +297,6 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	int i;
 	bd_t *bd = gd->bd;
 
 	print_num ("boot_params",	(ulong)bd->bi_boot_params);
@@ -368,10 +306,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	print_num ("flashsize",		(ulong)bd->bi_flashsize);
 	print_num ("flashoffset",	(ulong)bd->bi_flashoffset);
 
-	puts ("ethaddr     =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	}
+	print_eth(0);
 	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 	printf ("baudrate    = %d bps\n", bd->bi_baudrate);
 
@@ -397,11 +332,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	}
 
 #if defined(CONFIG_CMD_NET)
-	puts ("ethaddr     =");
-	for (i=0; i<6; ++i) {
-		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	}
-	puts  ( "\n" );
+	print_eth(0);
 	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
 	printf ("baudrate    = %d bps\n", bd->bi_baudrate);
@@ -416,6 +347,19 @@ static void print_num(const char *name, ulong value)
 	printf ("%-12s= 0x%08lX\n", name, value);
 }
 
+static void print_eth(int idx)
+{
+	char name[10], *val;
+	if (idx)
+		sprintf(name, "eth%iaddr", idx);
+	else
+		strcpy(name, "ethaddr");
+	val = getenv(name);
+	if (!val)
+		val = "(not set)";
+	printf("%-12s= %s\n", name, val);
+}
+
 #ifndef CONFIG_ARM
 static void print_lnum(const char *name, u64 value)
 {
-- 
1.6.1.3



More information about the U-Boot mailing list