All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] Generating random numbers
@ 2011-08-29  5:02 elison.niven at gmail.com
  2011-08-30 19:55 ` Wolfgang Denk
  0 siblings, 1 reply; 9+ messages in thread
From: elison.niven at gmail.com @ 2011-08-29  5:02 UTC (permalink / raw)
  To: u-boot

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

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

end of thread, other threads:[~2011-09-01 14:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-29  5:02 [U-Boot] Generating random numbers elison.niven at gmail.com
2011-08-30 19:55 ` 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

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.