diff --git a/CMakeLists.txt b/CMakeLists.txt index 9157f2445f2..2170567d3df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1149,13 +1149,17 @@ if(CONFIG_USERSPACE) if(CONFIG_NEWLIB_LIBC) set(NEWLIB_PART -l libc.a z_libc_partition) endif() + if(CONFIG_MBEDTLS) + set(MBEDTLS_PART -l libext__lib__crypto__mbedtls.a k_mbedtls_partition) + endif() + add_custom_command( OUTPUT ${APP_SMEM_LD} COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_app_partitions.py -d ${OBJ_FILE_DIR} -o ${APP_SMEM_LD} - ${NEWLIB_PART} + ${NEWLIB_PART} ${MBEDTLS_PART} $<$:--verbose> DEPENDS kernel diff --git a/CODEOWNERS b/CODEOWNERS index f97b412d99f..70d35c553ca 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -144,6 +144,7 @@ /ext/lib/crypto/mbedtls/ @nashif /ext/lib/crypto/tinycrypt/ @ceolin /include/adc.h @anangl +/include/app_memory/ @andrewboie /include/arch/arc/ @vonhust @ruuddw /include/arch/arc/arch.h @andrewboie /include/arch/arc/v2/irq.h @andrewboie diff --git a/ext/lib/crypto/mbedtls/zephyr_init.c b/ext/lib/crypto/mbedtls/zephyr_init.c index 0f6fbb67737..715fb6c1a08 100644 --- a/ext/lib/crypto/mbedtls/zephyr_init.c +++ b/ext/lib/crypto/mbedtls/zephyr_init.c @@ -11,6 +11,7 @@ */ #include +#include #if defined(CONFIG_MBEDTLS) #if !defined(CONFIG_MBEDTLS_CFG_FILE) diff --git a/include/app_memory/partitions.h b/include/app_memory/partitions.h new file mode 100644 index 00000000000..1b5fb84ef27 --- /dev/null +++ b/include/app_memory/partitions.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2019 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_APP_MEMORY_PARTITIONS_H +#define ZEPHYR_APP_MEMORY_PARTITIONS_H + +#ifdef CONFIG_USERSPACE +#include /* For struct k_mem_partition */ + +#if defined(CONFIG_MBEDTLS) +extern struct k_mem_partition k_mbedtls_partition; +#endif /* CONFIG_MBEDTLS */ +#endif /* CONFIG_USERSPACE */ +#endif /* ZEPHYR_APP_MEMORY_PARTITIONS_H */ diff --git a/kernel/userspace.c b/kernel/userspace.c index ee7a7098e53..24e32ca98a6 100644 --- a/kernel/userspace.c +++ b/kernel/userspace.c @@ -24,6 +24,14 @@ K_APPMEM_PARTITION_DEFINE(z_libc_partition); #endif +/* TODO: Find a better place to put this. Since we pull the entire + * libext__lib__crypto__mbedtls.a globals into app shared memory + * section, we can't put this in ext/lib/crypto/mbedtls/zephyr_init.c + */ +#ifdef CONFIG_MBEDTLS +K_APPMEM_PARTITION_DEFINE(k_mbedtls_partition); +#endif + #define LOG_LEVEL CONFIG_KERNEL_LOG_LEVEL #include LOG_MODULE_DECLARE(kernel); diff --git a/tests/crypto/mbedtls/src/main.c b/tests/crypto/mbedtls/src/main.c index 277e4e2d1d5..b3c52708ed7 100644 --- a/tests/crypto/mbedtls/src/main.c +++ b/tests/crypto/mbedtls/src/main.c @@ -5,12 +5,17 @@ */ #include +#include + extern void test_mbedtls(void); /**test case main entry*/ void test_main(void) { +#ifdef CONFIG_USERSPACE + k_mem_domain_add_partition(&ztest_mem_domain, &k_mbedtls_partition); +#endif ztest_test_suite(test_mbedtls_fn, - ztest_unit_test(test_mbedtls)); + ztest_user_unit_test(test_mbedtls)); ztest_run_test_suite(test_mbedtls_fn); } diff --git a/tests/crypto/mbedtls/src/mbedtls.c b/tests/crypto/mbedtls/src/mbedtls.c index 38cfadab891..3c9eb448388 100644 --- a/tests/crypto/mbedtls/src/mbedtls.c +++ b/tests/crypto/mbedtls/src/mbedtls.c @@ -75,7 +75,7 @@ #if defined(MBEDTLS_RSA_C) int rand(void) { - static u32_t seed = 7U; + static ZTEST_DMEM u32_t seed = 7U; seed ^= seed << 13; seed ^= seed >> 17; @@ -155,7 +155,7 @@ static void create_entropy_seed_file(void) #endif #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) -unsigned char buf[16384]; +ZTEST_BMEM unsigned char buf[16000]; #endif void test_mbedtls(void)