Introduce public APIs for random number generation

Convert the existing non-public random number generation APIs
into public APIs (i.e. sys_rand32_init and sys_rand32_get).

Change-Id: Id93e81e351a66d02c08cf3f5d2dd54a3b4b213c5
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
This commit is contained in:
Dmitriy Korovkin 2015-05-25 12:22:44 -04:00 committed by Anas Nashif
commit ec8a461bfb
6 changed files with 45 additions and 23 deletions

View file

@ -69,6 +69,14 @@ const char * const build_timestamp = BUILD_TIMESTAMP;
#define PRINT_BOOT_BANNER() printk(BOOT_BANNER " %s\n", build_timestamp)
#endif
/* random number generator items */
#if defined(CONFIG_TEST_RANDOM_GENERATOR) || \
defined(CONFIG_CUSTOM_RANDOM_GENERATOR)
#define RAND32_INIT() sys_rand32_init()
#else
#define RAND32_INIT()
#endif
/* stack space for the background (or idle) task context */
static char __noinit main_task_stack[CONFIG_MAIN_STACK_SIZE];
@ -201,8 +209,7 @@ extern void *__stack_chk_guard;
#define STACK_CANARY_INIT() \
do { \
register void *tmp; \
_Rand32Init(); \
tmp = (void *)_Rand32Get(); \
tmp = (void *)sys_rand32_get(); \
__asm__ volatile(_MOVE_INSTR "%1, %0;\n\t" \
: "=m"(__stack_chk_guard) \
: "r"(tmp)); \
@ -241,6 +248,15 @@ FUNC_NORETURN void _Cstart(void)
_InitHardware();
/*
* Initialize random number generator
* As a platform may implement it in hardware, it has to be
* initialized after rest of hardware initialization and
* before stack canaries that use it
*/
RAND32_INIT();
/* initialize stack canaries */
STACK_CANARY_INIT();