Skip to content

Commit 699437e

Browse files
author
Jamie Smith
authored
Allow Mbed CE to be built as an Arduino core (#206)
* Various changes for Arduino core support * Apply Arduino Mbed TLS patches * Apply linker script patch, add missing CXX standard * Fix SDBlockDevice compile error, fix "no rule to make mbed-target-config.h" * Fix missing source file for RPi Pico * Fix missing licenses
1 parent 8e38d02 commit 699437e

File tree

41 files changed

+3469
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3469
-126
lines changed

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ endif()
228228

229229
# Generate target config header and include it in all files
230230
if(NOT MBED_IS_NATIVE_BUILD)
231-
mbed_write_target_config_header(${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h MBED_TARGET_DEFINITIONS MBED_CONFIG_DEFINITIONS)
232-
target_compile_options(mbed-core-flags INTERFACE -include ${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h)
231+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated-headers)
232+
mbed_write_target_config_header(${CMAKE_CURRENT_BINARY_DIR}/generated-headers/mbed-target-config.h MBED_TARGET_DEFINITIONS MBED_CONFIG_DEFINITIONS)
233+
target_compile_options(mbed-core-flags INTERFACE -include ${CMAKE_CURRENT_BINARY_DIR}/generated-headers/mbed-target-config.h)
234+
target_include_directories(mbed-core-flags INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/generated-headers)
233235
endif()
234236

235237
# Include mbed.h and config from generate folder
@@ -283,7 +285,7 @@ if(NOT MBED_IS_NATIVE_BUILD)
283285
mbed_create_distro(mbed-os ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources)
284286

285287
# Set up the linker script and hook it up to the top-level OS targets
286-
mbed_setup_linker_script(mbed-baremetal mbed-os ${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h)
288+
mbed_setup_linker_script(mbed-baremetal mbed-os ${CMAKE_CURRENT_BINARY_DIR}/generated-headers/mbed-target-config.h)
287289

288290
# Make sure that things linking mbed-core-flags can also get the target-specific include dirs and flags.
289291
mbed_extract_flags(${MBED_TARGET_CMAKE_NAME}-flags ${MBED_TARGET_CMAKE_NAME})

connectivity/mbedtls/include/mbedtls/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@
12041204
*
12051205
* Enable functions that use the filesystem.
12061206
*/
1207-
//#define MBEDTLS_FS_IO
1207+
#define MBEDTLS_FS_IO
12081208

12091209
/**
12101210
* \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
@@ -3227,7 +3227,7 @@
32273227
* on it, and considering stronger message digests instead.
32283228
*
32293229
*/
3230-
//#define MBEDTLS_SHA1_C
3230+
#define MBEDTLS_SHA1_C
32313231

32323232
/**
32333233
* \def MBEDTLS_SHA256_C

connectivity/mbedtls/mbed_lib.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

connectivity/mbedtls/mbed_lib.json5

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "mbedtls",
3+
"config": {
4+
"entropy-nv-seed": {
5+
"macro_name": "MBEDTLS_ENTROPY_NV_SEED",
6+
"help": "Set to 1 to enable Mbed TLS's Non-Volatile Storage entropy source. This source allows usage of Mbed TLS on devices which do not have a cryptographic RNG.",
7+
"value": null,
8+
// Note: see here for details on how to implement the seed I/O: https://os.mbed.com/docs/mbed-os/v6.16/porting/entropy-sources.html
9+
}
10+
}
11+
}

connectivity/mbedtls/platform/inc/platform_mbed.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
* \ingroup public-crypto
3232
*/
3333

34+
#if CONFIG_MBEDTLS_ENTROPY_NV_SEED
35+
#define MBEDTLS_ENTROPY_NV_SEED
36+
#endif
37+
3438
#if defined(FEATURE_EXPERIMENTAL_API) && defined(FEATURE_PSA)
3539

3640
#if defined(MBEDTLS_ENTROPY_NV_SEED)
@@ -72,9 +76,6 @@
7276
#include "mbedtls_device.h"
7377
#endif
7478

75-
// Include SHA1 certificate support. Used for a lot of root CAs.
76-
#define MBEDTLS_SHA1_C 1
77-
7879
/*
7980
* MBEDTLS_ERR_PLATFORM_HW_FAILED is deprecated and should not be used.
8081
*/

connectivity/mbedtls/source/x509_crt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@
7474
#if !defined(_WIN32) || defined(EFIX64) || defined(EFI32)
7575
#include <sys/types.h>
7676
#include <sys/stat.h>
77+
#if defined(__MBED__)
78+
#include <platform/mbed_retarget.h>
79+
#else
7780
#include <dirent.h>
81+
#endif /* __MBED__ */
7882
#endif /* !_WIN32 || EFIX64 || EFI32 */
7983
#endif
8084

connectivity/mbedtls/tools/importer/adjust-config.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22
#
33
# This file is part of mbed TLS (https://tls.mbed.org)
44
#
5-
# Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
5+
# Copyright (c) 2023, Arm Limited, All Rights Reserved
6+
#
7+
# SPDX-License-Identifier: Apache-2.0
8+
# Licensed under the Apache License, Version 2.0 (the License); you may
9+
# not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# * http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
16+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
619
#
720
# Purpose
821
#
@@ -53,7 +66,6 @@ conf unset MBEDTLS_TIMING_C
5366

5467
# not supported on all targets with mbed OS, nor used by mbed Client
5568
conf unset MBEDTLS_HAVE_TIME_DATE
56-
conf unset MBEDTLS_FS_IO
5769
conf unset MBEDTLS_PSA_ITS_FILE_C
5870
conf unset MBEDTLS_PSA_CRYPTO_STORAGE_C
5971
conf set MBEDTLS_NO_PLATFORM_ENTROPY
@@ -89,7 +101,6 @@ conf unset MBEDTLS_PEM_WRITE_C
89101
conf unset MBEDTLS_PKCS5_C
90102
conf unset MBEDTLS_PKCS12_C
91103
conf unset MBEDTLS_RIPEMD160_C
92-
conf unset MBEDTLS_SHA1_C
93104
conf unset MBEDTLS_XTEA_C
94105

95106
conf set MBEDTLS_CMAC_C

connectivity/mbedtls/tools/importer/adjust-no-entropy-config.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22
#
33
# This file is part of mbed TLS (https://tls.mbed.org)
44
#
5-
# Copyright (c) 2018, ARM Limited, All Rights Reserved
5+
# Copyright (c) 2018, Arm Limited, All Rights Reserved
6+
#
7+
# SPDX-License-Identifier: Apache-2.0
8+
# Licensed under the Apache License, Version 2.0 (the License); you may
9+
# not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# * http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
16+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
619
#
720
# Purpose
821
#

connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ int mbedtls_x509_crt_parse(mbedtls_x509_crt *a, const unsigned char *b, size_t c
303303
return mbedtls_stub.expected_int;
304304
}
305305

306+
int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *a, const char *b)
307+
{
308+
// means 5 valid certificates found
309+
return 5;
310+
}
311+
306312
int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix,
307313
const mbedtls_x509_crt *crt)
308314
{

connectivity/netsocket/include/netsocket/TLSSocketWrapper.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,46 @@ class TLSSocketWrapper : public Socket {
116116
*/
117117
nsapi_error_t set_root_ca_cert(const char *root_ca_pem);
118118

119+
/**
120+
* @brief Sets the Root CA certificate to a collection of files on the filesystem.
121+
*
122+
* All files in the supplied directory will be scanned. Note that to set up a filesystem,
123+
* you must mount one or more block devices before calling this function.
124+
*
125+
* @note Must be called before calling connect()
126+
*
127+
* @param root_ca_path Path containing Root CA Certificate files in any Mbed TLS-supported format.
128+
* This can point to a directory on any mounted filesystem.
129+
* @retval NSAPI_ERROR_OK on success.
130+
* @retval NSAPI_ERROR_NO_MEMORY in case there is not enough memory to allocate certificate.
131+
* @retval NSAPI_ERROR_PARAMETER in case the provided root_ca parameter failed parsing.
132+
*
133+
*/
134+
nsapi_error_t set_root_ca_cert_path(const char *root_ca_path);
135+
136+
/** Appends the certificate to an existing CA chain.
137+
*
138+
* @note Must be called before calling connect()
139+
*
140+
* @param root_ca Root CA Certificate in any Mbed TLS-supported format.
141+
* @param len Length of certificate (including terminating 0 for PEM).
142+
* @retval NSAPI_ERROR_OK on success.
143+
* @retval NSAPI_ERROR_NO_MEMORY in case there is not enough memory to allocate certificate.
144+
* @retval NSAPI_ERROR_PARAMETER in case the provided root_ca parameter failed parsing.
145+
*/
146+
nsapi_error_t append_root_ca_cert(const void *root_ca, size_t len);
147+
148+
/** Appends the certificate to an existing CA chain.
149+
*
150+
* @note Must be called before calling connect()
151+
*
152+
* @param root_ca_pem Root CA Certificate in PEM format.
153+
* @retval NSAPI_ERROR_OK on success.
154+
* @retval NSAPI_ERROR_NO_MEMORY in case there is not enough memory to allocate certificate.
155+
* @retval NSAPI_ERROR_PARAMETER in case the provided root_ca parameter failed parsing.
156+
*/
157+
nsapi_error_t append_root_ca_cert(const char *root_ca_pem);
158+
119159
/** Sets client certificate, and client private key.
120160
*
121161
* @param client_cert Client certification in PEM or DER format.

0 commit comments

Comments
 (0)