U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] MAC Address reading procedure in board.c
Date: Mon, 25 May 2009 17:56:36 +0200	[thread overview]
Message-ID: <5ec3d7930905250856k6cffb4ber261bd99f15868c19@mail.gmail.com> (raw)

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

             reply	other threads:[~2009-05-25 15:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-25 15:56 Drasko DRASKOVIC [this message]
2009-05-25 18:32 ` [U-Boot] MAC Address reading procedure in board.c Wolfgang Denk
2009-05-26  8:47   ` Drasko DRASKOVIC

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ec3d7930905250856k6cffb4ber261bd99f15868c19@mail.gmail.com \
    --to=drasko.draskovic@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox