Skip to content

Commit c48c50d

Browse files
ioannisggalak
authored andcommitted
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 <[email protected]>
1 parent 39c9177 commit c48c50d

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

modules/Kconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ source "modules/Kconfig.imx"
1818
source "modules/Kconfig.infineon"
1919
source "modules/Kconfig.libmetal"
2020
source "modules/Kconfig.loramac-node"
21-
source "modules/Kconfig.mbedtls"
2221
source "modules/Kconfig.mcux"
2322
source "modules/Kconfig.microchip"
2423
source "modules/Kconfig.nuvoton"
@@ -51,6 +50,9 @@ comment "Unavailable modules, please install those via the project manifest."
5150
comment "hal_nordic module not available."
5251
depends on !ZEPHYR_HAL_NORDIC_MODULE
5352

53+
comment "mbedtls module not available."
54+
depends on !ZEPHYR_MBEDTLS_MODULE
55+
5456
comment "Trusted-firmware-m module not available."
5557
depends on !ZEPHYR_TRUSTED_FIRMWARE_M_MODULE
5658

modules/mbedtls/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
if(CONFIG_MBEDTLS)
2+
zephyr_interface_library_named(mbedTLS)
3+
4+
if(CONFIG_MBEDTLS_BUILTIN)
5+
target_compile_definitions(mbedTLS INTERFACE
6+
MBEDTLS_CONFIG_FILE="${CONFIG_MBEDTLS_CFG_FILE}"
7+
)
8+
9+
target_include_directories(mbedTLS INTERFACE
10+
${ZEPHYR_CURRENT_MODULE_DIR}/include
11+
${ZEPHYR_CURRENT_MODULE_DIR}/configs
12+
)
13+
14+
zephyr_library()
15+
16+
file(GLOB
17+
mbedtls_sources # This is an output parameter
18+
${ZEPHYR_CURRENT_MODULE_DIR}/library/*.c
19+
)
20+
21+
zephyr_library_sources(
22+
zephyr_init.c
23+
${mbedtls_sources}
24+
)
25+
26+
zephyr_library_app_memory(k_mbedtls_partition)
27+
if(CONFIG_ARCH_POSIX AND CONFIG_ASAN AND NOT CONFIG_64BIT)
28+
# i386 assembly code used in MBEDTLS does not compile with size optimization
29+
# if address sanitizer is enabled, as such switch default optimization level
30+
# to speed
31+
set_property(SOURCE ${ZEPHYR_CURRENT_MODULE_DIR}/library/bignum.c APPEND PROPERTY COMPILE_OPTIONS
32+
"${OPTIMIZE_FOR_SPEED_FLAG}")
33+
endif ()
34+
35+
zephyr_library_link_libraries(mbedTLS)
36+
else()
37+
assert(CONFIG_MBEDTLS_LIBRARY "MBEDTLS was enabled, but neither BUILTIN or LIBRARY was selected.")
38+
39+
# NB: CONFIG_MBEDTLS_LIBRARY is not regression tested and is
40+
# therefore susceptible to bit rot
41+
42+
target_include_directories(mbedTLS INTERFACE
43+
${CONFIG_MBEDTLS_INSTALL_PATH}
44+
)
45+
46+
zephyr_link_libraries(
47+
mbedtls_external
48+
-L${CONFIG_MBEDTLS_INSTALL_PATH}
49+
gcc
50+
)
51+
# Lib mbedtls_external depends on libgcc (I assume?) so to allow
52+
# mbedtls_external to link with gcc we need to ensure it is placed
53+
# after mbedtls_external on the linkers command line.
54+
endif()
55+
56+
endif()

modules/Kconfig.mbedtls renamed to modules/mbedtls/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Copyright (c) 2016 Intel Corporation
44
# SPDX-License-Identifier: Apache-2.0
55

6+
config ZEPHYR_MBEDTLS_MODULE
7+
bool
8+
69
menuconfig MBEDTLS
710
bool "mbedTLS Support"
811
help
File renamed without changes.

modules/mbedtls/zephyr_init.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/** @file
2+
* @brief mbed TLS initialization
3+
*
4+
* Initialize the mbed TLS library like setup the heap etc.
5+
*/
6+
7+
/*
8+
* Copyright (c) 2017 Intel Corporation
9+
*
10+
* SPDX-License-Identifier: Apache-2.0
11+
*/
12+
13+
#include <init.h>
14+
#include <app_memory/app_memdomain.h>
15+
16+
#if defined(CONFIG_MBEDTLS)
17+
#if !defined(CONFIG_MBEDTLS_CFG_FILE)
18+
#include "mbedtls/config.h"
19+
#else
20+
#include CONFIG_MBEDTLS_CFG_FILE
21+
#endif /* CONFIG_MBEDTLS_CFG_FILE */
22+
#endif
23+
24+
#if defined(CONFIG_MBEDTLS_ENABLE_HEAP) && \
25+
defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
26+
#include <mbedtls/memory_buffer_alloc.h>
27+
28+
#if !defined(CONFIG_MBEDTLS_HEAP_SIZE)
29+
#error "Please set heap size to be used. Set value to CONFIG_MBEDTLS_HEAP_SIZE \
30+
option."
31+
#endif
32+
33+
static unsigned char _mbedtls_heap[CONFIG_MBEDTLS_HEAP_SIZE];
34+
35+
static void init_heap(void)
36+
{
37+
mbedtls_memory_buffer_alloc_init(_mbedtls_heap, sizeof(_mbedtls_heap));
38+
}
39+
#else
40+
#define init_heap(...)
41+
#endif /* CONFIG_MBEDTLS_ENABLE_HEAP && MBEDTLS_MEMORY_BUFFER_ALLOC_C */
42+
43+
static int _mbedtls_init(const struct device *device)
44+
{
45+
ARG_UNUSED(device);
46+
47+
init_heap();
48+
49+
return 0;
50+
}
51+
52+
SYS_INIT(_mbedtls_init, POST_KERNEL, 0);

0 commit comments

Comments
 (0)