-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Adding CC310 entropy driver utilizing nrf_cc310_platform library #1268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rlubos
merged 5 commits into
nrfconnect:master
from
frkv:entropy-for-nrf_cc310_mbedcrypto-v0.9.0
Oct 29, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f3a2543
nrf_cc310: Adding CC310 entropy driver utilizing nrf_cc310_platform lib
frkv 334b959
drivers: entropy: add dependency of BT_LL_SW_LEGACY not set
tejlmand d722bbb
drivers: hw_cc310: Driver will default be deselected when using mcuboot
tejlmand 83e634f
sample: lwm2m carrier entropy dependency
tejlmand 47b6a10
entropy: cc310 dependency to mpu settings introduced
tejlmand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.conffiles that should be updated as well in mqtt and coap samples.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed