Skip to content

Commit 26bb7fb

Browse files
frkvtejlmand
authored andcommitted
Adding CC310 entropy driver utilizing nrf_cc310_platform library
-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 930bfb0 commit 26bb7fb

File tree

9 files changed

+198
-2
lines changed

9 files changed

+198
-2
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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
int res = -EINVAL;
27+
size_t olen;
28+
29+
__ASSERT_NO_MSG(dev != NULL);
30+
__ASSERT_NO_MSG(buffer != NULL);
31+
32+
#if defined(CONFIG_SPM)
33+
/** This is a call from a non-secure app that enables secure services,
34+
* in which case entropy is gathered by calling through SPM
35+
*/
36+
res = spm_request_random_number(buffer, length, &olen);
37+
if (olen != length) {
38+
return -EINVAL;
39+
}
40+
41+
#else
42+
/** This is a call from a secure app, in which case entropy is gathered
43+
* using CC310 HW using the nrf_cc310_platform library.
44+
*/
45+
res = nrf_cc310_platform_entropy_get(buffer, length, &olen);
46+
if (olen != length) {
47+
return -EINVAL;
48+
}
49+
#endif
50+
51+
return res;
52+
}
53+
54+
static int entropy_cc310_rng_init(struct device *dev) {
55+
/* No initialization is required */
56+
(void)dev;
57+
58+
return 0;
59+
}
60+
61+
static const struct entropy_driver_api entropy_cc310_rng_api = {
62+
.get_entropy = entropy_cc310_rng_get_entropy
63+
};
64+
65+
DEVICE_AND_API_INIT(entropy_cc310_rng, CONFIG_ENTROPY_NAME,
66+
&entropy_cc310_rng_init,
67+
NULL,
68+
NULL,
69+
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
70+
&entropy_cc310_rng_api);
71+
72+
#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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
int res;
20+
21+
__ASSERT_NO_MSG(dev != NULL);
22+
23+
/* Set the RTOS abort APIs */
24+
nrf_cc310_platform_abort_init();
25+
26+
/* Set the RTOS mutex APIs */
27+
nrf_cc310_platform_mutex_init();
28+
29+
/* Initialize the cc310 HW with or without RNG support */
30+
#if CONFIG_ENTROPY_CC310
31+
res = nrf_cc310_platform_init();
32+
#else
33+
res = nrf_cc310_platform_init_no_rng();
34+
#endif
35+
return res;
36+
}
37+
38+
DEVICE_INIT(hw_cc310, CONFIG_HW_CC310_NAME, hw_cc310_init,
39+
NULL, NULL, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
40+
41+
#endif /* CONFIG_HW_CC310 */

west.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ manifest:
3838
- name: zephyr
3939
repo-path: fw-nrfconnect-zephyr
4040
west-commands: scripts/west-commands.yml
41-
revision: d6e67554cfeb28df5525e53c073f61a00836f283
41+
revision: pull/219/head
4242
- name: nffs
4343
revision: bc62a2fa9d98ddb5d633c932ea199bc68e10f194
4444
path: modules/fs/nffs
@@ -72,7 +72,7 @@ manifest:
7272
revision: 30b7efa827b04d2e47840716b0372737fe7d6c92
7373
- name: nrfxlib
7474
path: nrfxlib
75-
revision: 9f9bd638a5a7cce77ee47e195e6458822ffc5e75
75+
revision:pull/88/head
7676
- name: cmock
7777
path: test/cmock
7878
revision: c243b9a7a7b3c471023193992b46cf1bd1910450

0 commit comments

Comments
 (0)