U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] MAC Address reading procedure in board.c
@ 2009-05-25 15:56 Drasko DRASKOVIC
  2009-05-25 18:32 ` Wolfgang Denk
  0 siblings, 1 reply; 3+ messages in thread
From: Drasko DRASKOVIC @ 2009-05-25 15:56 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-05-26  8:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-25 15:56 [U-Boot] MAC Address reading procedure in board.c Drasko DRASKOVIC
2009-05-25 18:32 ` Wolfgang Denk
2009-05-26  8:47   ` Drasko DRASKOVIC

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox