[U-Boot] [PATCH 01/27] net: new utility functions for working with enetaddr's

Wolfgang Denk wd at denx.de
Mon Feb 16 23:28:24 CET 2009


Dear Mike Frysinger,

In message <1234596190-524-2-git-send-email-vapier at gentoo.org> you wrote:
> Declare new utility functions for converting between the environment
> variables (eth*addr) and the binary MAC address representation.  This way
> we can unify all the random places that already do this kind of thing.
...
> +#ifdef CONFIG_CMD_NET
> +char *str_enetaddr(char *buf, const uchar *enetaddr)
> +{
> +	sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
> +		enetaddr[0], enetaddr[1], enetaddr[2],
> +		enetaddr[3], enetaddr[4], enetaddr[5]);
> +	return buf;
> +}
> +
> +void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
> +{
> +	char *end;
> +	int i;

Empty line here...

> +	for (i = 0; i < 6; ++i) {
> +		enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
> +		if (addr)
> +			addr = (*end) ? end + 1 : end;
> +	}
> +}
> +
> +int eth_getenv_enetaddr(char *name, uchar *enetaddr)
> +{
> +	int ret = 0;
> +	char *addr = getenv(name);

Empty line here...

> +	if (!addr)
> +		ret = -1;
> +	eth_parse_enetaddr(addr, enetaddr);
> +	return ret;
> +}
> +
> +int eth_setenv_enetaddr(char *name, const uchar *enetaddr)
> +{
> +	char buf[20];

Empty line here...

and so on...

> +	return setenv(name, str_enetaddr(buf, enetaddr));
...

> +					printf ("Address in SROM is         %s\n",
> +						str_enetaddr(enetvar, dev->enetaddr));
> +					printf ("Address in environment is  %s\n",
> +						str_enetaddr(enetvar, env_enetaddr));

Hm... Linux has a printk() format specifier for MAC addresses. Sounds
like a clever idea to me. Maybe we should borrow that code?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
You can do this in a number of ways.     IBM chose to do all of them.
Why do you find that funny?        -- D. Taylor, Computer Science 350


More information about the U-Boot mailing list