modules: mbedtls: move CMakeLists.txt. into the main tree
We move the Zephyr-specific CMakeLists.txt file into the main Zephyr tree. We also move the zephyr_init.c source file. Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
parent
39c917788f
commit
c48c50db42
5 changed files with 114 additions and 1 deletions
|
@ -18,7 +18,6 @@ source "modules/Kconfig.imx"
|
|||
source "modules/Kconfig.infineon"
|
||||
source "modules/Kconfig.libmetal"
|
||||
source "modules/Kconfig.loramac-node"
|
||||
source "modules/Kconfig.mbedtls"
|
||||
source "modules/Kconfig.mcux"
|
||||
source "modules/Kconfig.microchip"
|
||||
source "modules/Kconfig.nuvoton"
|
||||
|
@ -51,6 +50,9 @@ comment "Unavailable modules, please install those via the project manifest."
|
|||
comment "hal_nordic module not available."
|
||||
depends on !ZEPHYR_HAL_NORDIC_MODULE
|
||||
|
||||
comment "mbedtls module not available."
|
||||
depends on !ZEPHYR_MBEDTLS_MODULE
|
||||
|
||||
comment "Trusted-firmware-m module not available."
|
||||
depends on !ZEPHYR_TRUSTED_FIRMWARE_M_MODULE
|
||||
|
||||
|
|
56
modules/mbedtls/CMakeLists.txt
Normal file
56
modules/mbedtls/CMakeLists.txt
Normal file
|
@ -0,0 +1,56 @@
|
|||
if(CONFIG_MBEDTLS)
|
||||
zephyr_interface_library_named(mbedTLS)
|
||||
|
||||
if(CONFIG_MBEDTLS_BUILTIN)
|
||||
target_compile_definitions(mbedTLS INTERFACE
|
||||
MBEDTLS_CONFIG_FILE="${CONFIG_MBEDTLS_CFG_FILE}"
|
||||
)
|
||||
|
||||
target_include_directories(mbedTLS INTERFACE
|
||||
${ZEPHYR_CURRENT_MODULE_DIR}/include
|
||||
${ZEPHYR_CURRENT_MODULE_DIR}/configs
|
||||
)
|
||||
|
||||
zephyr_library()
|
||||
|
||||
file(GLOB
|
||||
mbedtls_sources # This is an output parameter
|
||||
${ZEPHYR_CURRENT_MODULE_DIR}/library/*.c
|
||||
)
|
||||
|
||||
zephyr_library_sources(
|
||||
zephyr_init.c
|
||||
${mbedtls_sources}
|
||||
)
|
||||
|
||||
zephyr_library_app_memory(k_mbedtls_partition)
|
||||
if(CONFIG_ARCH_POSIX AND CONFIG_ASAN AND NOT CONFIG_64BIT)
|
||||
# i386 assembly code used in MBEDTLS does not compile with size optimization
|
||||
# if address sanitizer is enabled, as such switch default optimization level
|
||||
# to speed
|
||||
set_property(SOURCE ${ZEPHYR_CURRENT_MODULE_DIR}/library/bignum.c APPEND PROPERTY COMPILE_OPTIONS
|
||||
"${OPTIMIZE_FOR_SPEED_FLAG}")
|
||||
endif ()
|
||||
|
||||
zephyr_library_link_libraries(mbedTLS)
|
||||
else()
|
||||
assert(CONFIG_MBEDTLS_LIBRARY "MBEDTLS was enabled, but neither BUILTIN or LIBRARY was selected.")
|
||||
|
||||
# NB: CONFIG_MBEDTLS_LIBRARY is not regression tested and is
|
||||
# therefore susceptible to bit rot
|
||||
|
||||
target_include_directories(mbedTLS INTERFACE
|
||||
${CONFIG_MBEDTLS_INSTALL_PATH}
|
||||
)
|
||||
|
||||
zephyr_link_libraries(
|
||||
mbedtls_external
|
||||
-L${CONFIG_MBEDTLS_INSTALL_PATH}
|
||||
gcc
|
||||
)
|
||||
# Lib mbedtls_external depends on libgcc (I assume?) so to allow
|
||||
# mbedtls_external to link with gcc we need to ensure it is placed
|
||||
# after mbedtls_external on the linkers command line.
|
||||
endif()
|
||||
|
||||
endif()
|
|
@ -3,6 +3,9 @@
|
|||
# Copyright (c) 2016 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config ZEPHYR_MBEDTLS_MODULE
|
||||
bool
|
||||
|
||||
menuconfig MBEDTLS
|
||||
bool "mbedTLS Support"
|
||||
help
|
52
modules/mbedtls/zephyr_init.c
Normal file
52
modules/mbedtls/zephyr_init.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/** @file
|
||||
* @brief mbed TLS initialization
|
||||
*
|
||||
* Initialize the mbed TLS library like setup the heap etc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <init.h>
|
||||
#include <app_memory/app_memdomain.h>
|
||||
|
||||
#if defined(CONFIG_MBEDTLS)
|
||||
#if !defined(CONFIG_MBEDTLS_CFG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include CONFIG_MBEDTLS_CFG_FILE
|
||||
#endif /* CONFIG_MBEDTLS_CFG_FILE */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_MBEDTLS_ENABLE_HEAP) && \
|
||||
defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
#include <mbedtls/memory_buffer_alloc.h>
|
||||
|
||||
#if !defined(CONFIG_MBEDTLS_HEAP_SIZE)
|
||||
#error "Please set heap size to be used. Set value to CONFIG_MBEDTLS_HEAP_SIZE \
|
||||
option."
|
||||
#endif
|
||||
|
||||
static unsigned char _mbedtls_heap[CONFIG_MBEDTLS_HEAP_SIZE];
|
||||
|
||||
static void init_heap(void)
|
||||
{
|
||||
mbedtls_memory_buffer_alloc_init(_mbedtls_heap, sizeof(_mbedtls_heap));
|
||||
}
|
||||
#else
|
||||
#define init_heap(...)
|
||||
#endif /* CONFIG_MBEDTLS_ENABLE_HEAP && MBEDTLS_MEMORY_BUFFER_ALLOC_C */
|
||||
|
||||
static int _mbedtls_init(const struct device *device)
|
||||
{
|
||||
ARG_UNUSED(device);
|
||||
|
||||
init_heap();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(_mbedtls_init, POST_KERNEL, 0);
|
Loading…
Add table
Add a link
Reference in a new issue