Skip to content
Merged
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 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 ()
19 changes: 19 additions & 0 deletions drivers/entropy/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
depends on !BT_LL_SW_LEGACY
depends on !MPU_STACK_GUARD
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.
74 changes: 74 additions & 0 deletions drivers/entropy/entropy_cc310.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 */
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)
42 changes: 42 additions & 0 deletions drivers/hw_cc310/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Kconfig - Arm CC310 hw driver for nRF52840 and nRF9160
#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

# Defining MCUBOOT symbol here to avoid an issue discovered when building
# multi image zephyr/mcuboot.
config MCUBOOT
bool

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 n if MCUBOOT
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
42 changes: 42 additions & 0 deletions drivers/hw_cc310/hw_cc310.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 */
2 changes: 1 addition & 1 deletion lib/lwm2m_carrier/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ menuconfig LWM2M_CARRIER
depends on NEWLIB_LIBC
depends on BSD_LIBRARY && !BSD_LIBRARY_SYS_INIT
# Need a source of entropy
depends on TEST_RANDOM_GENERATOR
depends on ENTROPY_HAS_DRIVER
# Flash settings
depends on FLASH && FLASH_PAGE_LAYOUT
depends on MPU_ALLOW_FLASH_WRITE
Expand Down
3 changes: 0 additions & 3 deletions samples/nrf9160/coap_client/overlay-carrier.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ CONFIG_LWM2M_CARRIER=y
# The library requires newlibc
CONFIG_NEWLIB_LIBC=y

# The library needs a source of entropy
CONFIG_TEST_RANDOM_GENERATOR=y

CONFIG_BSD_LIBRARY=y
CONFIG_BSD_LIBRARY_SYS_INIT=n

Expand Down
3 changes: 0 additions & 3 deletions samples/nrf9160/lwm2m_carrier/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ CONFIG_LWM2M_CARRIER=y
# The library requires newlibc
CONFIG_NEWLIB_LIBC=y

# The library needs a source of entropy
CONFIG_TEST_RANDOM_GENERATOR=y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two overlay-carrier.conf files that should be updated as well in mqtt and coap samples.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


CONFIG_BSD_LIBRARY=y
CONFIG_BSD_LIBRARY_SYS_INIT=n

Expand Down
3 changes: 0 additions & 3 deletions samples/nrf9160/mqtt_simple/overlay-carrier.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ CONFIG_LWM2M_CARRIER=y
# The library requires newlibc
CONFIG_NEWLIB_LIBC=y

# The library needs a source of entropy
CONFIG_TEST_RANDOM_GENERATOR=y

CONFIG_BSD_LIBRARY=y
CONFIG_BSD_LIBRARY_SYS_INIT=n

Expand Down