[U-Boot] MAC Address reading procedure in board.c
Drasko DRASKOVIC
drasko.draskovic at gmail.com
Mon May 25 17:56:36 CEST 2009
Hi all,
I have been looking at MAC addr obtaining procedure in lib_arm/board.c and I
am puzzled with this implementation :
/* MAC Address */
{
int i;
ulong reg;
char *s, *e;
char tmp[64];
i = getenv_r ("ethaddr", tmp, sizeof (tmp));
s = (i > 0) ? tmp : NULL;
*for (reg = 0; reg < 6; ++reg) {
gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16) : 0;
if (s)
s = (*e) ? e + 1 : e;*
}
}
Here are my questions:
1) In which format is kept the addr in environment (i.e. why do we allocate
64 byte buffer tmp)? This is a little bit tricky to see from the code, so I
thought maybe somebody will know.
2) In my opinion - there should be some delimiters (maybe ':') in this eth
addr string in environment, so we are here jumping over them :*
if (s)
s = (*e) ? e + 1 : e;
*but I still cannot see - how long are these strings between delimiters?
(Because when you call simple_strtoul(), it will proceed to the first
non-digit character, so who knows how long. As long as simple_stroul() is
concerned, if it do not meet nonhexdigit char, it can go to Moon and
beyond). Why we did not took two chars to represent each of 6 bytes +
delimiters (':'), which would make 6*2 + 5 = 11, which should be the length
of the tmp buffer. Then take two-by-two chars and transform them into
number.
What am I missing here?
Thanks and best regards,
Drasko
More information about the U-Boot
mailing list