[U-Boot] [PATCH V2 2/3] lib: rand: add call to hw_rand() - hardware random number generator

Przemyslaw Marczak
2014-03-05T16:57:46Z

Changes:
- lib/rand.c: add call to hw_rand() (depends on CONFIG_RAND_HW_ACCEL)
- include/common.h: add hw_rand() declaration.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
cc: Michael Walle <michael@walle.cc>
cc: Tom Rini <trini@ti.com>
---
Changes v2:
- move function hw_rand() from rand() to rand_r() and ignore its argument

include/common.h | 3 +++
lib/rand.c | 3 +++
2 files changed, 6 insertions(+)

diff --git a/include/common.h b/include/common.h
index 96a45a6..58e2fbc 100644
--- a/include/common.h
+++ b/include/common.h
@@ -836,6 +836,9 @@ void srand(unsigned int seed);
unsigned int rand(void);
unsigned int rand_r(unsigned int *seedp);
#endif
+#ifdef CONFIG_RAND_HW_ACCEL
+unsigned int hw_rand(void);
+#endif

/* common/console.c */
int console_init_f(void); /* Before relocation; uses the serial stuff */
diff --git a/lib/rand.c b/lib/rand.c
index 5c367e1..0617063 100644
--- a/lib/rand.c
+++ b/lib/rand.c
@@ -14,6 +14,9 @@ static unsigned int y = 1U;

unsigned int rand_r(unsigned int *seedp)
{
+#ifdef CONFIG_RAND_HW_ACCEL
+ return hw_rand();
+#endif
*seedp ^= (*seedp << 13);
*seedp ^= (*seedp >> 17);
*seedp ^= (*seedp << 5);
--
1.7.9.5