diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 03cd57039415..6716a7064016 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -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" @@ -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" ) diff --git a/doc/nrf/drivers.rst b/doc/nrf/drivers.rst index d412e031a766..b497c6f95def 100644 --- a/doc/nrf/drivers.rst +++ b/doc/nrf/drivers.rst @@ -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/* diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 8c2cdcccaefb..a63594934b76 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -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) diff --git a/drivers/Kconfig b/drivers/Kconfig index 07f46b282349..e5cb020ac910 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -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" diff --git a/drivers/entropy/CMakeLists.txt b/drivers/entropy/CMakeLists.txt new file mode 100644 index 000000000000..85e8599ad828 --- /dev/null +++ b/drivers/entropy/CMakeLists.txt @@ -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 () diff --git a/drivers/entropy/Kconfig b/drivers/entropy/Kconfig new file mode 100644 index 000000000000..94d43d80af92 --- /dev/null +++ b/drivers/entropy/Kconfig @@ -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. diff --git a/drivers/entropy/entropy_cc310.c b/drivers/entropy/entropy_cc310.c new file mode 100644 index 000000000000..67411a10dd34 --- /dev/null +++ b/drivers/entropy/entropy_cc310.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2019 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#include +#include +#include +#include +#include + +#include +#include + +#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 */ diff --git a/drivers/entropy/entropy_cc310.rst b/drivers/entropy/entropy_cc310.rst new file mode 100644 index 000000000000..4688612124bf --- /dev/null +++ b/drivers/entropy/entropy_cc310.rst @@ -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:`/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. diff --git a/drivers/hw_cc310/CMakeLists.txt b/drivers/hw_cc310/CMakeLists.txt new file mode 100644 index 000000000000..a6cd66eead94 --- /dev/null +++ b/drivers/hw_cc310/CMakeLists.txt @@ -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) diff --git a/drivers/hw_cc310/Kconfig b/drivers/hw_cc310/Kconfig new file mode 100644 index 000000000000..83009c0251d1 --- /dev/null +++ b/drivers/hw_cc310/Kconfig @@ -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 diff --git a/drivers/hw_cc310/hw_cc310.c b/drivers/hw_cc310/hw_cc310.c new file mode 100644 index 000000000000..833151e21aa4 --- /dev/null +++ b/drivers/hw_cc310/hw_cc310.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#include +#include +#include +#include + +#include + +#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 */ diff --git a/drivers/hw_cc310/hw_cc310.rst b/drivers/hw_cc310/hw_cc310.rst new file mode 100644 index 000000000000..c2602bb78b5c --- /dev/null +++ b/drivers/hw_cc310/hw_cc310.rst @@ -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. diff --git a/west.yml b/west.yml index c39bcf79de17..1a0e32050475 100644 --- a/west.yml +++ b/west.yml @@ -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 @@ -72,7 +72,7 @@ manifest: revision: 30b7efa827b04d2e47840716b0372737fe7d6c92 - name: nrfxlib path: nrfxlib - revision: 9f9bd638a5a7cce77ee47e195e6458822ffc5e75 + revision:pull/88/head - name: cmock path: test/cmock revision: c243b9a7a7b3c471023193992b46cf1bd1910450