From 9acf1ca50d8b031511d146f6ffd73201fedce28c Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Tue, 5 Jun 2012 11:33:14 +0000 Subject: lib: add rand() function It's a PRNG using the simple and fast xorshift method. Signed-off-by: Michael Walle Cc: Wolfgang Denk --- lib/Makefile | 1 + lib/rand.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 lib/rand.c (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 1e8478f..0ca45fc 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -66,6 +66,7 @@ COBJS-y += string.o COBJS-y += time.o COBJS-$(CONFIG_BOOTP_PXE) += uuid.o COBJS-y += vsprintf.o +COBJS-$(CONFIG_RANDOM_MACADDR) += rand.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/lib/rand.c b/lib/rand.c new file mode 100644 index 0000000..c9764f5 --- /dev/null +++ b/lib/rand.c @@ -0,0 +1,48 @@ +/* + * Simple xorshift PRNG + * see http://www.jstatsoft.org/v08/i14/paper + * + * Copyright (c) 2012 Michael Walle + * Michael Walle + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include + +static unsigned int y = 1U; + +unsigned int rand_r(unsigned int *seedp) +{ + *seedp ^= (*seedp << 13); + *seedp ^= (*seedp >> 17); + *seedp ^= (*seedp << 5); + + return *seedp; +} + +unsigned int rand(void) +{ + return rand_r(&y); +} + +void srand(unsigned int seed) +{ + y = seed; +} -- cgit v1.1 From 99e139d5902e488eb779cd4f00c978f3803c39be Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Tue, 5 Jun 2012 11:33:15 +0000 Subject: net: use common rand()/srand() functions Replace rand() with the functions from lib/. The link-local network code stores its own seed, derived from the MAC address. Thus making it independent from calls to srand() in other modules. Signed-off-by: Michael Walle Acked-by: Joe Hershberger --- lib/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 0ca45fc..556601c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -67,8 +67,10 @@ COBJS-y += time.o 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)) -- cgit v1.1 From aca587b0dad5f760e7db0a49e928fd87affcd123 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Jan 2012 10:57:20 +0100 Subject: SPL: lib/Makefile: Add crc32.c to SPL build This is needed for the SPEAr SPL support, as SPEAr uses the mkimage header to wrap and validate the images (SPL & U-Boot). Signed-off-by: Stefan Roese --- lib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 556601c..c60c380 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -37,7 +37,6 @@ COBJS-$(CONFIG_BZIP2) += bzlib_huffman.o COBJS-$(CONFIG_USB_TTY) += circbuf.o COBJS-y += crc7.o COBJS-y += crc16.o -COBJS-y += crc32.o COBJS-y += display_options.o COBJS-y += errno.o COBJS-$(CONFIG_OF_CONTROL) += fdtdec.o @@ -60,6 +59,7 @@ endif ifdef CONFIG_SPL_BUILD COBJS-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o endif +COBJS-y += crc32.o COBJS-y += ctype.o COBJS-y += div64.o COBJS-y += string.o -- cgit v1.1