mbedtls: provide user mode access
The mbedtls library has some globals which results in faults when user mode tries to access them. Instantiate a memory partition for mbedtls's globals. The linker will place all globals found by building this library into this partition. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
62fad96802
commit
e686aefe09
7 changed files with 40 additions and 4 deletions
|
@ -1149,13 +1149,17 @@ if(CONFIG_USERSPACE)
|
||||||
if(CONFIG_NEWLIB_LIBC)
|
if(CONFIG_NEWLIB_LIBC)
|
||||||
set(NEWLIB_PART -l libc.a z_libc_partition)
|
set(NEWLIB_PART -l libc.a z_libc_partition)
|
||||||
endif()
|
endif()
|
||||||
|
if(CONFIG_MBEDTLS)
|
||||||
|
set(MBEDTLS_PART -l libext__lib__crypto__mbedtls.a k_mbedtls_partition)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${APP_SMEM_LD}
|
OUTPUT ${APP_SMEM_LD}
|
||||||
COMMAND ${PYTHON_EXECUTABLE}
|
COMMAND ${PYTHON_EXECUTABLE}
|
||||||
${ZEPHYR_BASE}/scripts/gen_app_partitions.py
|
${ZEPHYR_BASE}/scripts/gen_app_partitions.py
|
||||||
-d ${OBJ_FILE_DIR}
|
-d ${OBJ_FILE_DIR}
|
||||||
-o ${APP_SMEM_LD}
|
-o ${APP_SMEM_LD}
|
||||||
${NEWLIB_PART}
|
${NEWLIB_PART} ${MBEDTLS_PART}
|
||||||
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
||||||
DEPENDS
|
DEPENDS
|
||||||
kernel
|
kernel
|
||||||
|
|
|
@ -144,6 +144,7 @@
|
||||||
/ext/lib/crypto/mbedtls/ @nashif
|
/ext/lib/crypto/mbedtls/ @nashif
|
||||||
/ext/lib/crypto/tinycrypt/ @ceolin
|
/ext/lib/crypto/tinycrypt/ @ceolin
|
||||||
/include/adc.h @anangl
|
/include/adc.h @anangl
|
||||||
|
/include/app_memory/ @andrewboie
|
||||||
/include/arch/arc/ @vonhust @ruuddw
|
/include/arch/arc/ @vonhust @ruuddw
|
||||||
/include/arch/arc/arch.h @andrewboie
|
/include/arch/arc/arch.h @andrewboie
|
||||||
/include/arch/arc/v2/irq.h @andrewboie
|
/include/arch/arc/v2/irq.h @andrewboie
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
|
#include <app_memory/app_memdomain.h>
|
||||||
|
|
||||||
#if defined(CONFIG_MBEDTLS)
|
#if defined(CONFIG_MBEDTLS)
|
||||||
#if !defined(CONFIG_MBEDTLS_CFG_FILE)
|
#if !defined(CONFIG_MBEDTLS_CFG_FILE)
|
||||||
|
|
17
include/app_memory/partitions.h
Normal file
17
include/app_memory/partitions.h
Normal file
|
@ -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 <kernel.h> /* 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 */
|
|
@ -24,6 +24,14 @@
|
||||||
K_APPMEM_PARTITION_DEFINE(z_libc_partition);
|
K_APPMEM_PARTITION_DEFINE(z_libc_partition);
|
||||||
#endif
|
#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
|
#define LOG_LEVEL CONFIG_KERNEL_LOG_LEVEL
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
LOG_MODULE_DECLARE(kernel);
|
LOG_MODULE_DECLARE(kernel);
|
||||||
|
|
|
@ -5,12 +5,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ztest.h>
|
#include <ztest.h>
|
||||||
|
#include <app_memory/partitions.h>
|
||||||
|
|
||||||
extern void test_mbedtls(void);
|
extern void test_mbedtls(void);
|
||||||
|
|
||||||
/**test case main entry*/
|
/**test case main entry*/
|
||||||
void test_main(void)
|
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_test_suite(test_mbedtls_fn,
|
||||||
ztest_unit_test(test_mbedtls));
|
ztest_user_unit_test(test_mbedtls));
|
||||||
ztest_run_test_suite(test_mbedtls_fn);
|
ztest_run_test_suite(test_mbedtls_fn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
#if defined(MBEDTLS_RSA_C)
|
#if defined(MBEDTLS_RSA_C)
|
||||||
int rand(void)
|
int rand(void)
|
||||||
{
|
{
|
||||||
static u32_t seed = 7U;
|
static ZTEST_DMEM u32_t seed = 7U;
|
||||||
|
|
||||||
seed ^= seed << 13;
|
seed ^= seed << 13;
|
||||||
seed ^= seed >> 17;
|
seed ^= seed >> 17;
|
||||||
|
@ -155,7 +155,7 @@ static void create_entropy_seed_file(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||||
unsigned char buf[16384];
|
ZTEST_BMEM unsigned char buf[16000];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void test_mbedtls(void)
|
void test_mbedtls(void)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue