Skip to content

Commit e94b82c

Browse files
committed
[nrf fromlist] mbedtls: Separate psa_crypto_init in its own SYS_INIT
-This commit adds psa_init.c that contains a SYS_INIT to enforce early initialization of PSA crypto by calling psa_crypto_init() in PRE_KERNEL_1, before any other users (include entropy_psa_crypto). -This is separated from CONFIG_MBEDTLS_INIT which has a SYS_INIT that happens in POST_KERNEL and include initializing the Mbed TLS heap if this is enabled. -Removing unneeded doxygen @file entry for zephyr_init.c Signed-off-by: Frank Audun Kvamtrø <[email protected]> (Cherry-picked from commit 7b92773a7f71e17d21fe8c8f65aebe22ad2a115b)
1 parent f22cb03 commit e94b82c

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

modules/mbedtls/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ zephyr_interface_library_named(mbedTLS)
121121
zephyr_entropy.c
122122
)
123123

124+
if(CONFIG_MBEDTLS_PSA_CRYPTO_CLIENT)
125+
list(APPEND mbedtls_base_src psa_init.c)
126+
endif()
127+
124128
zephyr_library_sources(${mbedtls_base_src})
125129

126130
zephyr_library_sources_ifdef(CONFIG_MBEDTLS_DEBUG debug.c)

modules/mbedtls/psa_init.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <errno.h>
7+
#include <zephyr/init.h>
8+
#include <psa/crypto.h>
9+
10+
static int _psa_crypto_init(void)
11+
{
12+
if (psa_crypto_init() != PSA_SUCCESS) {
13+
return -EIO;
14+
}
15+
16+
return 0;
17+
}
18+
19+
/* Enforcing initialization of PSA crypto before any other users
20+
* like entropy_psa_crypto (which has a higher priority number).
21+
* This is done without dependency on CONFIG_MBEDTLS_INIT.
22+
*/
23+
SYS_INIT(_psa_crypto_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

modules/mbedtls/zephyr_init.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/** @file
2-
* @brief mbed TLS initialization
3-
*
4-
* Initialize the mbed TLS library like setup the heap etc.
5-
*/
6-
71
/*
82
* Copyright (c) 2017 Intel Corporation
93
* Copyright (c) 2024 Nordic Semiconductor ASA
@@ -53,12 +47,6 @@ static int _mbedtls_init(void)
5347
mbedtls_debug_set_threshold(CONFIG_MBEDTLS_DEBUG_LEVEL);
5448
#endif
5549

56-
#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_CLIENT)
57-
if (psa_crypto_init() != PSA_SUCCESS) {
58-
return -EIO;
59-
}
60-
#endif
61-
6250
return 0;
6351
}
6452

0 commit comments

Comments
 (0)