[U-Boot] [PATCH 05/27] bdinfo: get mac address from environment

Mike Frysinger
2009-02-14T07:22:48Z

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@gentoo.org>
CC: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
CC: Scott McNutt <smcnutt@psyent.com>
CC: Shinya Kuribayashi <skuribay@ruby.dti.ne.jp>
CC: Michal Simek <monstr@seznam.cz>
CC: Daniel Hellstrom <daniel@gaisler.com>
CC: Ben Warren <biggerbadderben@gmail.com>
---
common/cmd_bdinfo.c | 136 +++++++++++++++------------------------------------
1 files changed, 40 insertions(+), 96 deletions(-)

diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
index b2d6f84..1c2f875 100644
--- a/common/cmd_bdinfo.c
+++ b/common/cmd_bdinfo.c
@@ -32,6 +32,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);

@@ -40,7 +42,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];

@@ -91,44 +92,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
@@ -143,7 +121,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);
@@ -152,11 +129,8 @@ 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]);
- }
- puts ("\nip_addr = ");
+ print_eth(0);
+ puts ("ip_addr = ");
print_IPaddr (bd->bi_ip_addr);
printf ("\nbaudrate = %ld bps\n", bd->bi_baudrate);

@@ -167,9 +141,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);
@@ -184,11 +155,8 @@ 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]);
- }
- puts ("\nip_addr = ");
+ print_eth(0);
+ puts ("ip_addr = ");
print_IPaddr (bd->bi_ip_addr);
#endif

@@ -200,7 +168,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);
@@ -212,11 +179,8 @@ 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]);
- }
- puts ("\nip_addr = ");
+ print_eth(0);
+ puts ("ip_addr = ");
print_IPaddr (bd->bi_ip_addr);
#endif
printf ("\nbaudrate = %ld bps\n", (ulong)bd->bi_baudrate);
@@ -227,9 +191,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);
@@ -251,11 +212,8 @@ 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]);
- }
- puts("\nIP addr = ");
+ print_eth(0);
+ puts("IP addr = ");
print_IPaddr(bd->bi_ip_addr);
#endif
printf("\nbaudrate = %6ld bps\n", bd->bi_baudrate);
@@ -267,7 +225,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];

@@ -294,33 +251,18 @@ 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

- puts ("\nip_addr = ");
+ puts ("ip_addr = ");
print_IPaddr (bd->bi_ip_addr);
#endif
printf ("\nbaudrate = %ld bps\n", bd->bi_baudrate);
@@ -333,7 +275,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];

@@ -351,10 +292,8 @@ 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]);
- puts("\nip_addr = ");
+ print_eth(0);
+ puts("ip_addr = ");
print_IPaddr(bd->bi_ip_addr);
printf("\nbaudrate = %d bps\n", bd->bi_baudrate);

@@ -365,7 +304,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);
@@ -375,11 +313,8 @@ 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]);
- }
- puts ("\nip_addr = ");
+ print_eth(0);
+ puts ("ip_addr = ");
print_IPaddr (bd->bi_ip_addr);
printf ("\nbaudrate = %d bps\n", bd->bi_baudrate);

@@ -405,12 +340,8 @@ 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"
- "ip_addr = ");
+ print_eth(0);
+ puts ("ip_addr = ");
print_IPaddr (bd->bi_ip_addr);
#endif
printf ("\n"
@@ -426,6 +357,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