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
_______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot