Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ set(NRF_EXTRACT_CONTENT_COMMAND
"*.rst:boards:${NRF_RST_OUT}"
"*.rst:include:${NRF_RST_OUT}"
"*.rst:lib:${NRF_RST_OUT}"
"*.rst:drivers:${NRF_RST_OUT}"
"*.rst:scripts:${NRF_RST_OUT}"
"*.rst:applications:${NRF_RST_OUT}/doc/nrf"
"*.rst:samples:${NRF_RST_OUT}/doc/nrf"
Expand All @@ -159,6 +160,7 @@ set(NRF_EXTRACT_CONTENT_COMMAND
"changelog.rst:doc:${NRF_RST_OUT}/doc/nrf"
"*.rst:include:${NRF_RST_OUT}/doc/nrf"
"*.rst:lib:${NRF_RST_OUT}/doc/nrf"
"*.rst:drivers:${NRF_RST_OUT}/doc/nrf"
"*.rst:scripts:${NRF_RST_OUT}/doc/nrf"
)

Expand Down
3 changes: 3 additions & 0 deletions doc/nrf/drivers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ Here you can find documentation for these drivers, including API documentation.
:glob:

../../include/drivers/*
../../drivers/entropy/*
../../drivers/hw_cc310/*
../../drivers/net/*
2 changes: 2 additions & 0 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ add_subdirectory_ifdef(CONFIG_BT_LL_NRFXLIB bt_ll_nrfxlib)
add_subdirectory_ifdef(CONFIG_NRF9160_GPS nrf9160_gps)
add_subdirectory_ifdef(CONFIG_FPROTECT fprotect)
add_subdirectory(flash_patch)
add_subdirectory_ifdef(CONFIG_HW_CC310 hw_cc310)
add_subdirectory(entropy)
2 changes: 2 additions & 0 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ rsource "adp536x/Kconfig"
rsource "at_cmd/Kconfig"

rsource "gps_sim/Kconfig"
rsource "entropy/Kconfig"
rsource "hw_cc310/Kconfig"
rsource "nrf9160_gps/Kconfig"
rsource "lte_link_control/Kconfig"
rsource "net/Kconfig"
Expand Down
16 changes: 16 additions & 0 deletions drivers/entropy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
zephyr_library_amend()
zephyr_library_sources_if_kconfig(entropy_cc310.c)

# Link with the nrf_cc310 platform library if the following is met:
# -nRF52840 device
# -nRF9160 device that is not using SPM
# -nRF9150 device that is using SPM and in a secure image
# (CONFIG_SPM is not defined in a secure image)
if (CONFIG_SOC_NRF52840 OR (CONFIG_SOC_NRF9160 AND (NOT CONFIG_SPM)))
zephyr_link_libraries_ifdef(CONFIG_ENTROPY_CC310 ${IMAGE}platform_cc310)
endif ()
17 changes: 17 additions & 0 deletions drivers/entropy/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Kconfig - Arm CC310 entropy driver for nRF52840 and nRF9160
#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

config ENTROPY_CC310
bool "Arm CC310 RNG driver for Nordic devices"
depends on HW_CC310 || (SOC_NRF9160 && SPM)
depends on ENTROPY_GENERATOR
select ENTROPY_HAS_DRIVER
select ENTROPY_NRF_FORCE_ALT
default y
help
This option enables the Arm CC310 RNG devices in nRF52840 and nRF9160
devices. This is dependent on CC310 being enabled in nrf_security.
72 changes: 72 additions & 0 deletions drivers/entropy/entropy_cc310.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
*/

#include <init.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <zephyr.h>
#include <drivers/entropy.h>

#if CONFIG_ENTROPY_CC310

#if defined(CONFIG_SPM)
#include "secure_services.h"
#else
#include "nrf_cc310_platform_entropy.h"
#endif

static int entropy_cc310_rng_get_entropy(struct device *dev, u8_t *buffer,
u16_t length) {
int res = -EINVAL;
size_t olen;

__ASSERT_NO_MSG(dev != NULL);
__ASSERT_NO_MSG(buffer != NULL);

#if defined(CONFIG_SPM)
/** This is a call from a non-secure app that enables secure services,
* in which case entropy is gathered by calling through SPM
*/
res = spm_request_random_number(buffer, length, &olen);
if (olen != length) {
return -EINVAL;
}

#else
/** This is a call from a secure app, in which case entropy is gathered
* using CC310 HW using the nrf_cc310_platform library.
*/
res = nrf_cc310_platform_entropy_get(buffer, length, &olen);
if (olen != length) {
return -EINVAL;
}
#endif

return res;
}

static int entropy_cc310_rng_init(struct device *dev) {
/* No initialization is required */
(void)dev;

return 0;
}

static const struct entropy_driver_api entropy_cc310_rng_api = {
.get_entropy = entropy_cc310_rng_get_entropy
};

DEVICE_AND_API_INIT(entropy_cc310_rng, CONFIG_ENTROPY_NAME,
&entropy_cc310_rng_init,
NULL,
NULL,
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_cc310_rng_api);

#endif /* CONFIG_ENTROPY_CC310 */
28 changes: 28 additions & 0 deletions drivers/entropy/entropy_cc310.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _lib_entropy_cc310:

Entropy CC310 Driver
####################

The Entropy CC310 Driver can be used to to generate random data using the Arm
CryptoCell CC310 hardware.


When used in nRF52840 the Entropy CC310 Driver will gather entropy by using the
CC310 hardware through the :ref:`nrf_cc310_platform_readme`.


When used in the nRF9160 in a secure application, :ref:`ug_nrf9160`, or when the
Secure Partition Manager is not used, the Entropy CC310 Driver will gather
entropy by using the CC310 hardware through the :ref:`nrf_cc310_platform_readme`.


When used in the nRF9160 in a non-secure application, :ref:`ug_nrf9160`
the driver will gather entropy through the :ref:`lib_secure_services` library.

API documentation
*****************

| Header file: :file:`<NCS>/zephyr/include/drivers/entropy.h`
| Source file: :file:`drivers/entropy_cc310/entropy_cc310.c`

The Entropy CC310 Driver implements the Zephyr :ref:`zephyr:entropy_interface` API.
10 changes: 10 additions & 0 deletions drivers/hw_cc310/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
zephyr_library()
zephyr_library_sources(hw_cc310.c)

# Link with the nrf_cc310 platform library
zephyr_library_link_libraries(${IMAGE}platform_cc310)
36 changes: 36 additions & 0 deletions drivers/hw_cc310/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Kconfig - Arm CC310 hw driver for nRF52840 and nRF9160
#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

config HW_CC310_FORCE_ALT
bool
depends on SOC_COMPATIBLE_NRF
help
This option can be enabled to force an alternative implementation of
the Arm CC310 hardware driver.

if !HW_CC310_FORCE_ALT

menuconfig HW_CC310
bool "Arm CC310 hw driver for Nordic devices"
depends on SOC_NRF52840 || (SOC_NRF9160 && !SPM) || (SOC_NRF9160 && TRUSTED_EXECUTION_SECURE)
select NRF_CC310_PLATFORM
default y if SOC_NRF52840 || (SOC_NRF9160 && !SPM) || (SOC_NRF9160 && TRUSTED_EXECUTION_SECURE)
help
This option enables the Arm CC310 hw devices in nRF52840 and nRF9160 devices.

if HW_CC310

config HW_CC310_NAME
string "Entropy Device Name"
default "HW_CC310_0"
help
Specify the device name to be used for the HW_CC310 driver.


endif # HW_CC310

endif # !HW_CC310_FORCE_ALT
41 changes: 41 additions & 0 deletions drivers/hw_cc310/hw_cc310.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
*/

#include <init.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <zephyr.h>

#if CONFIG_HW_CC310

#include "nrf_cc310_platform.h"

static int hw_cc310_init(struct device *dev) {
int res;

__ASSERT_NO_MSG(dev != NULL);

/* Set the RTOS abort APIs */
nrf_cc310_platform_abort_init();

/* Set the RTOS mutex APIs */
nrf_cc310_platform_mutex_init();

/* Initialize the cc310 HW with or without RNG support */
#if CONFIG_ENTROPY_CC310
res = nrf_cc310_platform_init();
#else
res = nrf_cc310_platform_init_no_rng();
#endif
return res;
}

DEVICE_INIT(hw_cc310, CONFIG_HW_CC310_NAME, hw_cc310_init,
NULL, NULL, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

#endif /* CONFIG_HW_CC310 */
23 changes: 23 additions & 0 deletions drivers/hw_cc310/hw_cc310.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. _lib_hw_cc310:

Hardware CC310 Driver
#####################

The Hardware CC310 Driver ensures correct initialization of the :ref:`nrf_cc310_platform_readme`.

The Hardware CC310 Driver ensures the following functionality is correctly initialized:

* CC310 abort functions
* mutex initialization
* platform initialization with/without RNG

The following :option:`CONFIG_HW_CC310` Kconfig variable controls initialization of the Hardware
CC310 Driver.

API documentation
*****************

| Source file: :file:`drivers/hw_cc310/hw_cc310.c`

See the :ref:`crypto_api_nrf_cc310_platform` APIs for functions available after
`Hardware CC310 Driver`_ initialization.
4 changes: 2 additions & 2 deletions west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ manifest:
- name: zephyr
repo-path: fw-nrfconnect-zephyr
west-commands: scripts/west-commands.yml
revision: d6e67554cfeb28df5525e53c073f61a00836f283
revision: pull/219/head
- name: nffs
revision: bc62a2fa9d98ddb5d633c932ea199bc68e10f194
path: modules/fs/nffs
Expand Down Expand Up @@ -72,7 +72,7 @@ manifest:
revision: 30b7efa827b04d2e47840716b0372737fe7d6c92
- name: nrfxlib
path: nrfxlib
revision: 9f9bd638a5a7cce77ee47e195e6458822ffc5e75
revision:pull/88/head
- name: cmock
path: test/cmock
revision: c243b9a7a7b3c471023193992b46cf1bd1910450
Expand Down