[U-Boot] Generating random numbers
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
Re: [U-Boot] Generating random numbers
On Wed, Aug 31, 2011 at 1:25 AM, Wolfgang Denk wrote: > Dear "elison.ni...@gmail.com", > > In message tyeytt4m+54y_qovck7vdqy_ssoktrdjbpf8+pq0-yc...@mail.gmail.com> you wrote: > > > > I am trying to random my mac in u-boot on AT91RM9200 and AT91SAM9G45 > > processor. > > This approach is inherently wrong, and I'm actually happy if you > find it difficult to implement. Otherwise we would probably have > rejected your code when you submit the patches. > > MAC addresses are supposed to be NOT random. Please see the related > FAQ, for example > http://www.denx.de/wiki/view/DULG/WhereCanIGetAValidMACAddress > > Hi, I do realize that. The "random" MAC address is not forever. It is only to get the "actual" MAC in the first boot so as to not set the environment variables manually. Thanks, Elison ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] Generating random numbers
On Wed, Aug 31, 2011 at 1:25 AM, Wolfgang Denk wrote: This approach is inherently wrong, and I'm actually happy if you > find it difficult to implement. Otherwise we would probably have > rejected your code when you submit the patches. > > Why does arch/blackfin/include/asm/net.h have bfin_gen_rand_mac ? Thanks, Elison ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] Generating random numbers
Tue Aug 30 23:48:41, Albert ARIBAUD albert.u.boot at aribaud.net wrote: > This differs from your use case which apparently is "use a random MAC so > that with some yet-undefined mechanism we can ask for a real MAC because > we don't want to set the real MAC in the environment" -- to me it looks > not like a degenerate case but a nominal use case. How am I supposed to set the real MAC in the environment? Build separate images for each board? I do not want that. > Now I may have misunderstood your case, of course. Feel free to provide > more context. I think I have pretty much summarized it in the first mail of this thread. Thanks, Elison ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] Generating random numbers
On Thu, Sep 1, 2011 at 12:45 AM, Wolfgang Denk wrote: > Dear "elison.ni...@gmail.com", > > In message > you > wrote: >> >> How am I supposed to set the real MAC in the environment? Build >> separate images for each board? I do not want that. > > Not that is finally a good question, and one where answering makes > sense again. > > There are many ways, depending on how you organized the production > and/or testing of your boards. > > Of course, you can also pre-program your flashes before even fitting > the chips on the boards. There are programmers that support auto- > incrementing serial numbers or automatic insertion of data blocks > retrieved from some sort of production database. Yes, this is what I am looking into. Seems the most fitting in my case. > There is a zillion of methods to do what you want, you just have to > pick one that fits your board and your productions and test > environment best. And any of these is way better than using random > MAC addresses. > Thanks a lot ! Thanks, Elison ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot