#include <u-boot/crc.h>
/* lib/rand.c */
-#ifdef CONFIG_RANDOM_MACADDR
+#if defined(CONFIG_RANDOM_MACADDR) || \
+ defined(CONFIG_BOOTP_RANDOM_DELAY) || \
+ defined(CONFIG_CMD_LINK_LOCAL)
#define RAND_MAX -1U
void srand(unsigned int seed);
unsigned int rand(void);
COBJS-$(CONFIG_BOOTP_PXE) += uuid.o
COBJS-y += vsprintf.o
COBJS-$(CONFIG_RANDOM_MACADDR) += rand.o
+COBJS-$(CONFIG_BOOTP_RANDOM_DELAY) += rand.o
+COBJS-$(CONFIG_CMD_LINK_LOCAL) += rand.o
-COBJS := $(COBJS-y)
+COBJS := $(sort $(COBJS-y))
SRCS := $(COBJS:.o=.c)
OBJS := $(addprefix $(obj),$(COBJS))
COBJS-$(CONFIG_CMD_NET) += eth.o
COBJS-$(CONFIG_CMD_LINK_LOCAL) += link_local.o
COBJS-$(CONFIG_CMD_NET) += net.o
-COBJS-$(CONFIG_BOOTP_RANDOM_DELAY) += net_rand.o
-COBJS-$(CONFIG_CMD_LINK_LOCAL) += net_rand.o
COBJS-$(CONFIG_CMD_NFS) += nfs.o
COBJS-$(CONFIG_CMD_PING) += ping.o
COBJS-$(CONFIG_CMD_RARP) += rarp.o
static unsigned nprobes;
static unsigned nclaims;
static int ready;
+static unsigned int seed;
static void link_local_timeout(void);
unsigned tmp;
do {
- tmp = rand() & IN_CLASSB_HOST;
+ tmp = rand_r(&seed) & IN_CLASSB_HOST;
} while (tmp > (IN_CLASSB_HOST - 0x0200));
return (IPaddr_t) htonl((LINKLOCAL_ADDR + 0x0100) + tmp);
}
*/
static inline unsigned random_delay_ms(unsigned secs)
{
- return rand() % (secs * 1000);
+ return rand_r(&seed) % (secs * 1000);
}
static void configure_wait(void)
}
NetOurSubnetMask = IN_CLASSB_NET;
- srand_mac();
+ seed = seed_mac();
if (ip == 0)
ip = pick();
+++ /dev/null
-/*
- * Based on LiMon - BOOTP.
- *
- * Copyright 1994, 1995, 2000 Neil Russell.
- * (See License)
- * Copyright 2000 Roland Borde
- * Copyright 2000 Paolo Scaffardi
- * Copyright 2000-2004 Wolfgang Denk, wd@denx.de
- */
-
-#include <common.h>
-#include <net.h>
-#include "net_rand.h"
-
-static ulong seed1, seed2;
-
-void srand_mac(void)
-{
- ulong tst1, tst2, m_mask;
- ulong m_value = 0;
- int reg;
- unsigned char bi_enetaddr[6];
-
- /* get our mac */
- eth_getenv_enetaddr("ethaddr", bi_enetaddr);
-
- debug("BootpRequest => Our Mac: ");
- for (reg = 0; reg < 6; reg++)
- debug("%x%c", bi_enetaddr[reg], reg == 5 ? '\n' : ':');
-
- /* Mac-Manipulation 2 get seed1 */
- tst1 = 0;
- tst2 = 0;
- for (reg = 2; reg < 6; reg++) {
- tst1 = tst1 << 8;
- tst1 = tst1 | bi_enetaddr[reg];
- }
- for (reg = 0; reg < 2; reg++) {
- tst2 = tst2 | bi_enetaddr[reg];
- tst2 = tst2 << 8;
- }
-
- seed1 = tst1^tst2;
-
- /* Mirror seed1*/
- m_mask = 0x1;
- for (reg = 1; reg <= 32; reg++) {
- m_value |= (m_mask & seed1);
- seed1 = seed1 >> 1;
- m_value = m_value << 1;
- }
- seed1 = m_value;
- seed2 = 0xb78d0945;
-}
-
-unsigned long rand(void)
-{
- ulong sum;
-
- /* Random Number Generator */
- sum = seed1 + seed2;
- if (sum < seed1 || sum < seed2)
- sum++;
- seed2 = seed1;
- seed1 = sum;
-
- return sum;
-}
#ifndef __NET_RAND_H__
#define __NET_RAND_H__
-#define RAND_MAX 0xffffffff
+#include <common.h>
/*
- * Seed the random number generator using the eth0 MAC address
+ * Return a seed for the PRNG derived from the eth0 MAC address.
*/
-void srand_mac(void);
+static inline unsigned int seed_mac(void)
+{
+ unsigned char enetaddr[6];
+ unsigned int seed;
+
+ /* get our mac */
+ eth_getenv_enetaddr("ethaddr", enetaddr);
+
+ seed = enetaddr[5];
+ seed ^= enetaddr[4] << 8;
+ seed ^= enetaddr[3] << 16;
+ seed ^= enetaddr[2] << 24;
+ seed ^= enetaddr[1];
+ seed ^= enetaddr[0] << 8;
+
+ return seed;
+}
/*
- * Get a random number (after seeding with MAC address)
- *
- * @return random number
+ * Seed the random number generator using the eth0 MAC address.
*/
-unsigned long rand(void);
+static inline void srand_mac(void)
+{
+ srand(seed_mac());
+}
#endif /* __NET_RAND_H__ */