subsys: Add random subsystem

Some "random" drivers are not drivers at all: they just implement the
function `sys_rand32_get()`.  Move those to a random subsystem in
preparation for a reorganization.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
This commit is contained in:
Leandro Pereira 2017-10-13 15:45:02 -07:00 committed by Anas Nashif
commit adce1d1888
36 changed files with 70 additions and 64 deletions

View file

@ -31,7 +31,7 @@
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#define ARCV2_TIMER0_INT_LVL IRQ_TIMER0 #define ARCV2_TIMER0_INT_LVL IRQ_TIMER0
#define ARCV2_TIMER0_INT_PRI 0 #define ARCV2_TIMER0_INT_PRI 0

View file

@ -40,7 +40,7 @@
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#define ARCV2_TIMER0_INT_LVL IRQ_TIMER0 #define ARCV2_TIMER0_INT_LVL IRQ_TIMER0
#define ARCV2_TIMER0_INT_PRI 0 #define ARCV2_TIMER0_INT_PRI 0

View file

@ -31,7 +31,7 @@
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#define ARCV2_TIMER0_INT_LVL IRQ_TIMER0 #define ARCV2_TIMER0_INT_LVL IRQ_TIMER0
#define ARCV2_TIMER0_INT_PRI 0 #define ARCV2_TIMER0_INT_PRI 0

View file

@ -105,7 +105,7 @@
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <quark_se/shared_mem.h> #include <quark_se/shared_mem.h>
#define INT_ENABLE_ARC ~(0x00000001 << 8) #define INT_ENABLE_ARC ~(0x00000001 << 8)

View file

@ -17,7 +17,7 @@
#include <nrf.h> #include <nrf.h>
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#endif /* !_ASMLANGUAGE */ #endif /* !_ASMLANGUAGE */

View file

@ -17,7 +17,7 @@
#include <nrf.h> #include <nrf.h>
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#endif /* !_ASMLANGUAGE */ #endif /* !_ASMLANGUAGE */

View file

@ -125,7 +125,7 @@ extern "C" {
#include <fsl_common.h> #include <fsl_common.h>
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
/* For IMG_MANAGER */ /* For IMG_MANAGER */
#if defined(CONFIG_SOC_FLASH_MCUX) #if defined(CONFIG_SOC_FLASH_MCUX)

View file

@ -54,7 +54,7 @@ extern "C" {
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#endif /* !_ASMLANGUAGE */ #endif /* !_ASMLANGUAGE */

View file

@ -127,7 +127,7 @@ extern "C" {
#include <fsl_common.h> #include <fsl_common.h>
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#endif /* !_ASMLANGUAGE */ #endif /* !_ASMLANGUAGE */

View file

@ -26,7 +26,7 @@
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <stm32f0xx.h> #include <stm32f0xx.h>

View file

@ -26,7 +26,7 @@
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <stm32f1xx.h> #include <stm32f1xx.h>

View file

@ -27,7 +27,7 @@
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <stm32f3xx.h> #include <stm32f3xx.h>

View file

@ -26,7 +26,7 @@
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <stm32f4xx.h> #include <stm32f4xx.h>

View file

@ -73,7 +73,7 @@ extern "C" {
#include <device.h> #include <device.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/rand32.h> #include <random/rand32.h>
/* uart configuration settings */ /* uart configuration settings */
#if defined(CONFIG_UART_STELLARIS) #if defined(CONFIG_UART_STELLARIS)

View file

@ -19,7 +19,7 @@
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <device.h> #include <device.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#endif #endif
#define INT_VEC_IRQ0 0x20 /* vector number for IRQ0 */ #define INT_VEC_IRQ0 0x20 /* vector number for IRQ0 */

View file

@ -19,7 +19,7 @@
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <device.h> #include <device.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#endif #endif
/* /*

View file

@ -19,7 +19,7 @@
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <device.h> #include <device.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#endif #endif
#ifdef CONFIG_IOAPIC #ifdef CONFIG_IOAPIC

View file

@ -23,7 +23,7 @@
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include <string.h> #include <string.h>
#include <rand32.h> #include <random/rand32.h>
#include <gpio.h> #include <gpio.h>

View file

@ -20,7 +20,7 @@
#include <net/net_if.h> #include <net/net_if.h>
#include <net/net_pkt.h> #include <net/net_pkt.h>
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include <rand32.h> #include <random/rand32.h>
#include "fsl_xcvr.h" #include "fsl_xcvr.h"

View file

@ -23,7 +23,7 @@
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include <string.h> #include <string.h>
#include <rand32.h> #include <random/rand32.h>
#include <gpio.h> #include <gpio.h>

View file

@ -23,7 +23,7 @@
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include <string.h> #include <string.h>
#include <rand32.h> #include <random/rand32.h>
#include <net/ieee802154_radio.h> #include <net/ieee802154_radio.h>
#include <drivers/clock_control/nrf5_clock_control.h> #include <drivers/clock_control/nrf5_clock_control.h>

View file

@ -17,7 +17,6 @@ if RANDOM_GENERATOR
source "drivers/random/Kconfig.mcux" source "drivers/random/Kconfig.mcux"
source "drivers/random/Kconfig.stm32" source "drivers/random/Kconfig.stm32"
source "drivers/random/Kconfig.esp32" source "drivers/random/Kconfig.esp32"
config RANDOM_HAS_DRIVER config RANDOM_HAS_DRIVER
@ -48,35 +47,4 @@ config SYS_LOG_RANDOM_LEVEL
- 3 INFO: write SYS_LOG_INF in addition to previous levels - 3 INFO: write SYS_LOG_INF in addition to previous levels
- 4 DEBUG: write SYS_LOG_DBG in addition to previous levels - 4 DEBUG: write SYS_LOG_DBG in addition to previous levels
config TEST_RANDOM_GENERATOR
bool
prompt "Non-random number generator"
depends on RANDOM_GENERATOR && ! RANDOM_HAS_DRIVER
default n
help
This option signifies that the kernel's random number APIs are
permitted to return values that are not truly random.
This capability is provided for testing purposes, when a truly random
number generator is not available. The non-random number generator
should not be used in a production environment.
config X86_TSC_RANDOM_GENERATOR
bool
prompt "x86 timestamp counter based number generator"
depends on TEST_RANDOM_GENERATOR && X86
default y
help
This options enables number generator based on timestamp counter
of x86 boards, obtained with rdtsc instruction.
config TIMER_RANDOM_GENERATOR
bool
prompt "System timer clock based number generator"
depends on TEST_RANDOM_GENERATOR && !X86_TSC_RANDOM_GENERATOR
default y
help
This options enables number generator based on system timer
clock. This number generator is not random and used for
testing only.
endif endif

View file

@ -1,7 +1,5 @@
obj-$(CONFIG_RANDOM_MCUX_RNGA) += random_mcux_rnga.o obj-$(CONFIG_RANDOM_MCUX_RNGA) += random_mcux_rnga.o
obj-$(CONFIG_RANDOM_MCUX_TRNG) += random_mcux_trng.o obj-$(CONFIG_RANDOM_MCUX_TRNG) += random_mcux_trng.o
obj-$(CONFIG_TIMER_RANDOM_GENERATOR) = rand32_timer.o
obj-$(CONFIG_X86_TSC_RANDOM_GENERATOR) += rand32_timestamp.o
obj-$(CONFIG_RANDOM_STM32_RNG) += random_stm32_rng.o obj-$(CONFIG_RANDOM_STM32_RNG) += random_stm32_rng.o
obj-$(CONFIG_RANDOM_ESP32_RNG) += random_esp32.o obj-$(CONFIG_RANDOM_ESP32_RNG) += random_esp32.o

View file

@ -6,7 +6,7 @@
#include <device.h> #include <device.h>
#include <random.h> #include <random.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <init.h> #include <init.h>
#include "fsl_rnga.h" #include "fsl_rnga.h"

View file

@ -6,7 +6,7 @@
#include <device.h> #include <device.h>
#include <random.h> #include <random.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <init.h> #include <init.h>
#include "fsl_trng.h" #include "fsl_trng.h"

View file

@ -7,7 +7,7 @@
#include <kernel.h> #include <kernel.h>
#include <device.h> #include <device.h>
#include <random.h> #include <random.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <init.h> #include <init.h>
#include <misc/__assert.h> #include <misc/__assert.h>
#include <misc/util.h> #include <misc/util.h>

View file

@ -26,7 +26,7 @@
#include <misc/slist.h> #include <misc/slist.h>
#include <misc/util.h> #include <misc/util.h>
#include <kernel_version.h> #include <kernel_version.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <kernel_arch_thread.h> #include <kernel_arch_thread.h>
#include <syscall.h> #include <syscall.h>

View file

@ -16,7 +16,7 @@
#include <kernel.h> #include <kernel.h>
#include <misc/printk.h> #include <misc/printk.h>
#include <misc/stack.h> #include <misc/stack.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <linker/sections.h> #include <linker/sections.h>
#include <toolchain.h> #include <toolchain.h>
#include <kernel_structs.h> #include <kernel_structs.h>

View file

@ -10,7 +10,7 @@
#include <logging/sys_log.h> #include <logging/sys_log.h>
#include <board.h> #include <board.h>
#include <drivers/rand32.h> #include <random/rand32.h>
#include <errno.h> #include <errno.h>
#include <gpio.h> #include <gpio.h>
#include <net/net_app.h> #include <net/net_app.h>

View file

@ -26,3 +26,5 @@ source "subsys/shell/Kconfig"
source "subsys/usb/Kconfig" source "subsys/usb/Kconfig"
source "subsys/dfu/Kconfig" source "subsys/dfu/Kconfig"
source "subsys/random/Kconfig"

View file

@ -6,6 +6,7 @@ obj-$(CONFIG_CONSOLE_SHELL) += shell/
obj-$(CONFIG_CONSOLE_PULL) += console/ obj-$(CONFIG_CONSOLE_PULL) += console/
obj-$(CONFIG_DISK_ACCESS) += disk/ obj-$(CONFIG_DISK_ACCESS) += disk/
obj-$(CONFIG_CPLUSPLUS) += cpp/ obj-$(CONFIG_CPLUSPLUS) += cpp/
obj-$(CONFIG_MCUBOOT_IMG_MANAGER) += dfu/
obj-y += logging/ obj-y += logging/
obj-y += debug/ obj-y += debug/
obj-$(CONFIG_MCUBOOT_IMG_MANAGER) += dfu/ obj-y += random/

35
subsys/random/Kconfig Normal file
View file

@ -0,0 +1,35 @@
# Kconfig - random configuration options
#
# Copyright (c) 2017 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
config TEST_RANDOM_GENERATOR
bool
prompt "Non-random number generator"
depends on RANDOM_GENERATOR && ! RANDOM_HAS_DRIVER
default n
help
This option signifies that the kernel's random number APIs are
permitted to return values that are not truly random.
This capability is provided for testing purposes, when a truly random
number generator is not available. The non-random number generator
should not be used in a production environment.
config X86_TSC_RANDOM_GENERATOR
bool
prompt "x86 timestamp counter based number generator"
depends on TEST_RANDOM_GENERATOR && X86
help
This options enables number generator based on timestamp counter
of x86 boards, obtained with rdtsc instruction.
config TIMER_RANDOM_GENERATOR
bool
prompt "System timer clock based number generator"
depends on TEST_RANDOM_GENERATOR
help
This options enables number generator based on system timer
clock. This number generator is not random and used for
testing only.

2
subsys/random/Makefile Normal file
View file

@ -0,0 +1,2 @@
obj-$(CONFIG_TIMER_RANDOM_GENERATOR) = rand32_timer.o
obj-$(CONFIG_X86_TSC_RANDOM_GENERATOR) += rand32_timestamp.o

View file

@ -14,7 +14,7 @@
* provide a random number generator. * provide a random number generator.
*/ */
#include <drivers/rand32.h> #include <random/rand32.h>
#include <drivers/system_timer.h> #include <drivers/system_timer.h>
#include <kernel.h> #include <kernel.h>
#include <atomic.h> #include <atomic.h>

View file

@ -16,7 +16,7 @@
#include <kernel.h> #include <kernel.h>
#include <arch/cpu.h> #include <arch/cpu.h>
#include <drivers/rand32.h> #include <random/rand32.h>
/** /**
* *