All of lore.kernel.org
 help / color / mirror / Atom feed
From: elison.niven at gmail.com <elison.niven@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] Generating random numbers
Date: Mon, 29 Aug 2011 10:32:40 +0530	[thread overview]
Message-ID: <CAAO=tyeYTt4M+54y_qovCK7vdQy_ssOktRdjbPF8+Pq0-YcCzQ@mail.gmail.com> (raw)

Hi,

I am trying to random my mac in u-boot on AT91RM9200 and AT91SAM9G45
processor.
My purpose is that before a MAC is assigned to the board at production, the
board
should use a random MAC address (and random IP) and also that it shouldn't
conflict
with other devices on the same network.

In lib_arm/board.c if the environment variables ethaddr and ipaddr are
not set, I generate a random MAC and IP.

bootcmd is set to tftp "filename";autoscr $(TFTP_LOAD_ADDR) in the config.h
file.
A tftp server on the network reads the filename(different for different
products)
and calls mkimage to create a u-boot script file that sets the correct MAC
address
and the correct bootcmd after getting one from the database.
This is to reduce the time at Production. At present they have to connect
each board's
serial cable and set the MAC address.

On the 9G45, I used the pseudo-random generator from board/esd/du440/du440.c
along
with a few combinations of udelay and get_timer and am able to get different
MAC
addresses over reboots and also different MAC addresses on similar boards.

start_time=get_timer(0);
udelay(start_time);
prng(start_time);
elapsed_time=get_timer(start_time);
udelay(elapsed_time); etc along with a few more loops.

However the same code generates the same sequence of random numbers on the
AT91RM9200.
I am not sure how this code generates different numbers every time on the
AT91SAM9G45 !

On the AT91RM9200, I also tried using bfin_gen_rand_mac from
arch/blackfin/include/asm/net.h,
However I always get the same sequence of random numbers.

/* make something up */
const char s[] = __DATE__;
size_t i;
u32 cycles;
for (i = 0; i < 6; ++i) {
 asm("%0 = CYCLES;" : "=r" (cycles));
mac_addr[i] = cycles ^ s[i];
}
mac_addr[0] = (mac_addr[0] | 0x02) & ~0x01; /* make it local unicast */

Is there any method to generate different sequences of random numbers by the
same code
executing on same machines? I could do this after the kernel starts using
/dev/urandom
and then use fw_setenv but I prefer to do it in U-boot.

Does using fw_setenv require the flash partition containing the U-boot
environment
variables be mounted as read-write? Because I mount it as read-only.

Thanks,
Elison

             reply	other threads:[~2011-08-29  5:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-29  5:02 elison.niven at gmail.com [this message]
2011-08-30 19:55 ` [U-Boot] Generating random numbers Wolfgang Denk
2011-08-30 20:10   ` elison.niven at gmail.com
2011-08-30 21:48     ` Albert ARIBAUD
2011-08-30 21:07   ` elison.niven at gmail.com
2011-08-31 16:54     ` elison.niven at gmail.com
2011-08-31 19:15       ` Wolfgang Denk
2011-08-31 21:55         ` Mike Frysinger
2011-09-01 14:00         ` elison.niven at gmail.com

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='CAAO=tyeYTt4M+54y_qovCK7vdQy_ssOktRdjbPF8+Pq0-YcCzQ@mail.gmail.com' \
    --to=elison.niven@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.