Skip to content

Commit 031762c

Browse files
frkvrlubos
authored andcommitted
nrf_cc310: Adding CC310 entropy driver utilizing nrf_cc310_platform lib
-Adding hw_cc310 driver with RTOS mutex/abort support -Changing entropy_cc310 driver to use nrf_cc310_platform library -Changing entropy_cc310 driver to support non-secure application Signed-off-by: Frank Audun Kvamtrø <[email protected]> Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 2ca6e9c commit 031762c

File tree

8 files changed

+199
-0
lines changed

8 files changed

+199
-0
lines changed

drivers/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ add_subdirectory_ifdef(CONFIG_BT_LL_NRFXLIB bt_ll_nrfxlib)
1515
add_subdirectory_ifdef(CONFIG_NRF9160_GPS nrf9160_gps)
1616
add_subdirectory_ifdef(CONFIG_FPROTECT fprotect)
1717
add_subdirectory(flash_patch)
18+
add_subdirectory_ifdef(CONFIG_HW_CC310 hw_cc310)
19+
add_subdirectory(entropy)

drivers/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ rsource "adp536x/Kconfig"
1010
rsource "at_cmd/Kconfig"
1111

1212
rsource "gps_sim/Kconfig"
13+
rsource "entropy/Kconfig"
14+
rsource "hw_cc310/Kconfig"
1315
rsource "nrf9160_gps/Kconfig"
1416
rsource "lte_link_control/Kconfig"
1517
rsource "net/Kconfig"

drivers/entropy/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2019 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
5+
#
6+
zephyr_library_amend()
7+
zephyr_library_sources_if_kconfig(entropy_cc310.c)
8+
9+
# Link with the nrf_cc310 platform library if the following is met:
10+
# -nRF52840 device
11+
# -nRF9160 device that is not using SPM
12+
# -nRF9150 device that is using SPM and in a secure image
13+
# (CONFIG_SPM is not defined in a secure image)
14+
if (CONFIG_SOC_NRF52840 OR (CONFIG_SOC_NRF9160 AND (NOT CONFIG_SPM)))
15+
zephyr_link_libraries_ifdef(CONFIG_ENTROPY_CC310 ${IMAGE}platform_cc310)
16+
endif ()

drivers/entropy/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Kconfig - Arm CC310 entropy driver for nRF52840 and nRF9160
2+
#
3+
# Copyright (c) 2019 Nordic Semiconductor
4+
#
5+
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
6+
#
7+
8+
config ENTROPY_CC310
9+
bool "Arm CC310 RNG driver for Nordic devices"
10+
depends on HW_CC310 || (SOC_NRF9160 && SPM)
11+
depends on ENTROPY_GENERATOR
12+
select ENTROPY_HAS_DRIVER
13+
select ENTROPY_NRF_FORCE_ALT
14+
default y
15+
help
16+
This option enables the Arm CC310 RNG devices in nRF52840 and nRF9160
17+
devices. This is dependent on CC310 being enabled in nrf_security.

drivers/entropy/entropy_cc310.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
5+
*/
6+
7+
#include <init.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <string.h>
11+
#include <assert.h>
12+
13+
#include <zephyr.h>
14+
#include <drivers/entropy.h>
15+
16+
#if CONFIG_ENTROPY_CC310
17+
18+
#if defined(CONFIG_SPM)
19+
#include "secure_services.h"
20+
#else
21+
#include "nrf_cc310_platform_entropy.h"
22+
#endif
23+
24+
static int entropy_cc310_rng_get_entropy(struct device *dev, u8_t *buffer,
25+
u16_t length)
26+
{
27+
int res = -EINVAL;
28+
size_t olen;
29+
30+
__ASSERT_NO_MSG(dev != NULL);
31+
__ASSERT_NO_MSG(buffer != NULL);
32+
33+
#if defined(CONFIG_SPM)
34+
/** This is a call from a non-secure app that enables secure services,
35+
* in which case entropy is gathered by calling through SPM
36+
*/
37+
res = spm_request_random_number(buffer, length, &olen);
38+
if (olen != length) {
39+
return -EINVAL;
40+
}
41+
42+
#else
43+
/** This is a call from a secure app, in which case entropy is gathered
44+
* using CC310 HW using the nrf_cc310_platform library.
45+
*/
46+
res = nrf_cc310_platform_entropy_get(buffer, length, &olen);
47+
if (olen != length) {
48+
return -EINVAL;
49+
}
50+
#endif
51+
52+
return res;
53+
}
54+
55+
static int entropy_cc310_rng_init(struct device *dev)
56+
{
57+
/* No initialization is required */
58+
(void)dev;
59+
60+
return 0;
61+
}
62+
63+
static const struct entropy_driver_api entropy_cc310_rng_api = {
64+
.get_entropy = entropy_cc310_rng_get_entropy
65+
};
66+
67+
DEVICE_AND_API_INIT(entropy_cc310_rng, CONFIG_ENTROPY_NAME,
68+
&entropy_cc310_rng_init,
69+
NULL,
70+
NULL,
71+
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
72+
&entropy_cc310_rng_api);
73+
74+
#endif /* CONFIG_ENTROPY_CC310 */

drivers/hw_cc310/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2019 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
5+
#
6+
zephyr_library()
7+
zephyr_library_sources(hw_cc310.c)
8+
9+
# Link with the nrf_cc310 platform library
10+
zephyr_library_link_libraries(${IMAGE}platform_cc310)

drivers/hw_cc310/Kconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Kconfig - Arm CC310 hw driver for nRF52840 and nRF9160
2+
#
3+
# Copyright (c) 2019 Nordic Semiconductor
4+
#
5+
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
6+
#
7+
8+
config HW_CC310_FORCE_ALT
9+
bool
10+
depends on SOC_COMPATIBLE_NRF
11+
help
12+
This option can be enabled to force an alternative implementation of
13+
the Arm CC310 hardware driver.
14+
15+
if !HW_CC310_FORCE_ALT
16+
17+
menuconfig HW_CC310
18+
bool "Arm CC310 hw driver for Nordic devices"
19+
depends on SOC_NRF52840 || (SOC_NRF9160 && !SPM) || (SOC_NRF9160 && TRUSTED_EXECUTION_SECURE)
20+
select NRF_CC310_PLATFORM
21+
default y if SOC_NRF52840 || (SOC_NRF9160 && !SPM) || (SOC_NRF9160 && TRUSTED_EXECUTION_SECURE)
22+
help
23+
This option enables the Arm CC310 hw devices in nRF52840 and nRF9160 devices.
24+
25+
if HW_CC310
26+
27+
config HW_CC310_NAME
28+
string "Entropy Device Name"
29+
default "HW_CC310_0"
30+
help
31+
Specify the device name to be used for the HW_CC310 driver.
32+
33+
34+
endif # HW_CC310
35+
36+
endif # !HW_CC310_FORCE_ALT

drivers/hw_cc310/hw_cc310.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
5+
*/
6+
7+
#include <init.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <string.h>
11+
12+
#include <zephyr.h>
13+
14+
#if CONFIG_HW_CC310
15+
16+
#include "nrf_cc310_platform.h"
17+
18+
static int hw_cc310_init(struct device *dev)
19+
{
20+
int res;
21+
22+
__ASSERT_NO_MSG(dev != NULL);
23+
24+
/* Set the RTOS abort APIs */
25+
nrf_cc310_platform_abort_init();
26+
27+
/* Set the RTOS mutex APIs */
28+
nrf_cc310_platform_mutex_init();
29+
30+
/* Initialize the cc310 HW with or without RNG support */
31+
#if CONFIG_ENTROPY_CC310
32+
res = nrf_cc310_platform_init();
33+
#else
34+
res = nrf_cc310_platform_init_no_rng();
35+
#endif
36+
return res;
37+
}
38+
39+
DEVICE_INIT(hw_cc310, CONFIG_HW_CC310_NAME, hw_cc310_init,
40+
NULL, NULL, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
41+
42+
#endif /* CONFIG_HW_CC310 */

0 commit comments

Comments
 (0)