random: add MCUX TRNG driver
Provide a random driver wrapped around the MCUX TRNG driver. Change-Id: Icbd7ab587aa18ecbd7eae52290aaa5d8ee504cf2 Origin: Original Signed-off-by: Bogdan Davidoaia <bogdan.davidoaia@linaro.org>
This commit is contained in:
parent
50cb5a6bd3
commit
5473906993
5 changed files with 81 additions and 0 deletions
|
@ -45,6 +45,12 @@ config HAS_RNGA
|
|||
help
|
||||
Set if the random number generator accelerator (RNGA) module is present in the SoC.
|
||||
|
||||
config HAS_TRNG
|
||||
bool
|
||||
default n
|
||||
help
|
||||
Set if the true random number generator (TRNG) module is present in the SoC.
|
||||
|
||||
config HAS_LPUART
|
||||
bool
|
||||
default n
|
||||
|
|
|
@ -12,3 +12,12 @@ menuconfig RANDOM_MCUX_RNGA
|
|||
help
|
||||
This option enables the random number generator accelerator (RNGA)
|
||||
driver based on the MCUX RNGA driver.
|
||||
|
||||
menuconfig RANDOM_MCUX_TRNG
|
||||
bool "MCUX TRNG driver"
|
||||
depends on RANDOM_GENERATOR && HAS_TRNG
|
||||
default n
|
||||
select RANDOM_HAS_DRIVER
|
||||
help
|
||||
This option enables the true random number generator (TRNG)
|
||||
driver based on the MCUX TRNG driver.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
obj-$(CONFIG_RANDOM_MCUX_RNGA) += random_mcux_rnga.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
|
||||
|
|
64
drivers/random/random_mcux_trng.c
Normal file
64
drivers/random/random_mcux_trng.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Linaro Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <random.h>
|
||||
#include <drivers/rand32.h>
|
||||
#include <init.h>
|
||||
|
||||
#include "fsl_trng.h"
|
||||
|
||||
static int random_mcux_trng_get_entropy(struct device *dev, uint8_t *buffer,
|
||||
uint16_t length)
|
||||
{
|
||||
status_t status;
|
||||
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
status = TRNG_GetRandomData(TRNG0, buffer, length);
|
||||
__ASSERT_NO_MSG(!status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct random_driver_api random_mcux_trng_api_funcs = {
|
||||
.get_entropy = random_mcux_trng_get_entropy
|
||||
};
|
||||
|
||||
static int random_mcux_trng_init(struct device *);
|
||||
|
||||
DEVICE_AND_API_INIT(random_mcux_trng, CONFIG_RANDOM_NAME,
|
||||
random_mcux_trng_init, NULL, NULL,
|
||||
PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
||||
&random_mcux_trng_api_funcs);
|
||||
|
||||
static int random_mcux_trng_init(struct device *dev)
|
||||
{
|
||||
trng_config_t conf;
|
||||
status_t status;
|
||||
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
status = TRNG_GetDefaultConfig(&conf);
|
||||
__ASSERT_NO_MSG(!status);
|
||||
|
||||
status = TRNG_Init(TRNG0, &conf);
|
||||
__ASSERT_NO_MSG(!status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t sys_rand32_get(void)
|
||||
{
|
||||
uint32_t output;
|
||||
int rc;
|
||||
|
||||
rc = random_mcux_trng_get_entropy(DEVICE_GET(random_mcux_trng),
|
||||
(uint8_t *) &output, sizeof(output));
|
||||
__ASSERT_NO_MSG(!rc);
|
||||
|
||||
return output;
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
obj-$(CONFIG_ETH_MCUX) += fsl_enet.o
|
||||
obj-$(CONFIG_I2C_MCUX) += fsl_i2c.o
|
||||
obj-$(CONFIG_RANDOM_MCUX_RNGA) += fsl_rnga.o
|
||||
obj-$(CONFIG_RANDOM_MCUX_TRNG) += fsl_trng.o
|
||||
obj-$(CONFIG_SOC_FLASH_MCUX) += fsl_flash.o
|
||||
obj-$(CONFIG_SPI_MCUX) += fsl_dspi.o
|
||||
obj-$(CONFIG_UART_MCUX) += fsl_uart.o
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue