Skip to content

Commit 5f7b952

Browse files
authored
Clone mbedTLS to third_party folder (project-chip#409)
* Clone mbedTLS to third_party folder * Fix copy paste error * Fix makefiles for mbedTLS * fix build * fix build * yet another build fix * fix test builds * fix distcheck * fix makefile
1 parent 198e9b7 commit 5f7b952

File tree

7 files changed

+164
-9
lines changed

7 files changed

+164
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ third_party/nlassert/
4040
third_party/nlfaultinjection/
4141
third_party/nlio/
4242
third_party/nlunit-test/
43+
third_party/mbedtls/

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"streambuf": "cpp",
6666
"cinttypes": "cpp",
6767
"typeinfo": "cpp",
68-
"*.ipp": "cpp"
68+
"*.ipp": "cpp",
69+
"aes.h": "c"
6970
},
7071
"files.eol": "\n",
7172
"editor.formatOnSave": true,

configure.ac

+43-6
Original file line numberDiff line numberDiff line change
@@ -1358,11 +1358,25 @@ fi
13581358
#
13591359
# mbedTLS
13601360
#
1361+
if test "${with_mbedtls}" != "internal"; then
1362+
with_mbedtls="no"
1363+
fi
13611364

1362-
NL_WITH_OPTIONAL_EXTERNAL_PACKAGE([mbedTLS],
1365+
NL_WITH_OPTIONAL_INTERNAL_PACKAGE(
1366+
[mbedTLS],
13631367
[MBEDTLS],
13641368
[mbedtls],
1365-
[-lmbedtls],
1369+
[],
1370+
[
1371+
# At this point, the internal mbedTLS package will be neither
1372+
# configured nor built, so the normal checks we undertake for an
1373+
# external package cannot be run here. Simply set the appropriate
1374+
# variables and trust all will be well.
1375+
1376+
MBEDTLS_CPPFLAGS="-I\${abs_top_srcdir}/third_party/mbedtls/repo/include"
1377+
MBEDTLS_LDFLAGS="-L${ac_pwd}/third_party/mbedtls"
1378+
MBEDTLS_LIBS="-lmbedtls"
1379+
],
13661380
[
13671381
# Check for required mbedTLS headers.
13681382
@@ -1376,14 +1390,29 @@ NL_WITH_OPTIONAL_EXTERNAL_PACKAGE([mbedTLS],
13761390
]
13771391
)
13781392

1379-
AM_CONDITIONAL([CHIP_WITH_MBEDTLS], [test "${nl_with_mbedtls}" != "no"])
1393+
# Depending on whether mbedTLS has been configured for an internal
1394+
# location, its directory stem within this package needs to be set
1395+
# accordingly. In addition, if the location is internal, then we need
1396+
# to attempt to pull it down using the bootstrap makefile.
1397+
1398+
if test "${nl_with_mbedtls}" = "internal"; then
1399+
maybe_mbedtls_dirstem="mbedtls"
1400+
mbedtls_dirstem="third_party/${maybe_mbedtls_dirstem}/repo"
1401+
1402+
AC_MSG_NOTICE([attempting to create internal ${mbedtls_dirstem}])
13801403

1381-
if test "${nl_with_mbedtls}" = "no"; then
1382-
AC_DEFINE([CHIP_WITH_MBEDTLS], [0], [Define to 1 to build CHIP with mbedTLS features])
1404+
${MAKE-make} --no-print-directory -C ${srcdir} -f Makefile-bootstrap ${mbedtls_dirstem}
1405+
1406+
if test $? -ne 0; then
1407+
AC_MSG_ERROR([failed to create ${mbedtls_dirstem}. Please check your network connection or the correctness of 'repos.conf'])
1408+
fi
13831409
else
1384-
AC_DEFINE([CHIP_WITH_MBEDTLS], [1], [Define to 1 to build CHIP with mbedTLS features])
1410+
maybe_mbedtls_dirstem=""
13851411
fi
13861412

1413+
AC_SUBST(MBEDTLS_SUBDIRS, [${maybe_mbedtls_dirstem}])
1414+
AM_CONDITIONAL([CHIP_WITH_MBEDTLS_INTERNAL], [test "${nl_with_mbedtls}" = "internal"])
1415+
13871416
#
13881417
# LwIP
13891418
#
@@ -1899,6 +1928,10 @@ if test "${nl_with_nlassert}" = "internal"; then
18991928
AC_CONFIG_SUBDIRS([third_party/nlassert/repo])
19001929
fi
19011930

1931+
if test "${nl_with_mbedtls}" = "internal"; then
1932+
AC_CONFIG_SUBDIRS([third_party/mbedtls/repo])
1933+
fi
1934+
19021935
if test "${nl_with_nlfaultinjection}" = "internal"; then
19031936
AC_CONFIG_SUBDIRS([third_party/nlfaultinjection/repo])
19041937
fi
@@ -1932,6 +1965,10 @@ src/platform/Makefile
19321965
tests/Makefile
19331966
])
19341967

1968+
if test "${nl_with_mbedtls}" = "internal"; then
1969+
AC_CONFIG_FILES([third_party/mbedtls/Makefile])
1970+
fi
1971+
19351972
#
19361973
# Generate the auto-generated files for the package
19371974
#

examples/lock-app/nrf5/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ INC_DIRS = \
148148
$(NRF5_SDK_ROOT)/external/freertos/portable/CMSIS/nrf52 \
149149
$(NRF5_SDK_ROOT)/external/freertos/portable/GCC/nrf52 \
150150
$(NRF5_SDK_ROOT)/external/freertos/source/include \
151-
$(NRF5_SDK_ROOT)/external/mbedtls/include \
152151
$(NRF5_SDK_ROOT)/external/segger_rtt \
153152
$(NRF5_SDK_ROOT)/integration/nrfx \
154153
$(NRF5_SDK_ROOT)/integration/nrfx/legacy \

repos.conf

+5
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@
1818
url = https://github.com/nestlabs/nlunit-test.git
1919
branch = master
2020
update = none
21+
[submodule "mbedtls"]
22+
path = third_party/mbedtls/repo
23+
url = https://github.com/ARMmbed/mbedtls.git
24+
branch = mbedtls-2.18
25+
update = none

third_party/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ DIST_SUBDIRS = \
4141
# of the 'distclean' target. Consequently, we conditionally include
4242
# them in DIST_SUBDIRS on invocation of 'distclean-recursive'
4343

44-
distclean-recursive: DIST_SUBDIRS += $(NLASSERT_SUBDIRS) $(NLFAULTINJECTION_SUBDIRS) $(NLIO_SUBDIRS) $(NLUNIT_TEST_SUBDIRS)
44+
distclean-recursive: DIST_SUBDIRS += $(NLASSERT_SUBDIRS) $(NLFAULTINJECTION_SUBDIRS) $(NLIO_SUBDIRS) $(NLUNIT_TEST_SUBDIRS) $(MBEDTLS_SUBDIRS)
4545

4646
# Always build (e.g. for 'make all') these subdirectories.
4747
#
@@ -54,6 +54,7 @@ SUBDIRS = \
5454
$(NLFAULTINJECTION_SUBDIRS) \
5555
$(NLIO_SUBDIRS) \
5656
$(NLUNIT_TEST_SUBDIRS) \
57+
$(MBEDTLS_SUBDIRS) \
5758
$(NULL)
5859

5960
include $(abs_top_nlbuild_autotools_dir)/automake/post.am

third_party/mbedtls/Makefile.am

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#
2+
# Copyright (c) 2020 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
#
18+
# Description:
19+
# This file is the GNU automake template for the CHIP in-package,
20+
# mbedTLS library.
21+
#
22+
#
23+
24+
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
25+
26+
lib_LIBRARIES = libmbedtls.a
27+
28+
libmbedtls_a_SOURCES = \
29+
repo/library/aes.c \
30+
repo/library/pem.c \
31+
repo/library/aesni.c \
32+
repo/library/pk.c \
33+
repo/library/arc4.c \
34+
repo/library/pkcs11.c \
35+
repo/library/aria.c \
36+
repo/library/pkcs12.c \
37+
repo/library/asn1parse.c \
38+
repo/library/pkcs5.c \
39+
repo/library/asn1write.c \
40+
repo/library/pkparse.c \
41+
repo/library/base64.c \
42+
repo/library/pk_wrap.c \
43+
repo/library/bignum.c \
44+
repo/library/pkwrite.c \
45+
repo/library/blowfish.c \
46+
repo/library/platform.c \
47+
repo/library/camellia.c \
48+
repo/library/platform_util.c \
49+
repo/library/ccm.c \
50+
repo/library/poly1305.c \
51+
repo/library/certs.c \
52+
repo/library/chacha20.c \
53+
repo/library/chachapoly.c \
54+
repo/library/cipher.c \
55+
repo/library/cipher_wrap.c \
56+
repo/library/cmac.c \
57+
repo/library/ripemd160.c \
58+
repo/library/ctr_drbg.c \
59+
repo/library/rsa.c \
60+
repo/library/debug.c \
61+
repo/library/rsa_internal.c \
62+
repo/library/des.c \
63+
repo/library/sha1.c \
64+
repo/library/dhm.c \
65+
repo/library/sha256.c \
66+
repo/library/ecdh.c \
67+
repo/library/sha512.c \
68+
repo/library/ecdsa.c \
69+
repo/library/ssl_cache.c \
70+
repo/library/ecjpake.c \
71+
repo/library/ssl_ciphersuites.c \
72+
repo/library/ecp.c \
73+
repo/library/ssl_cli.c \
74+
repo/library/ecp_curves.c \
75+
repo/library/ssl_cookie.c \
76+
repo/library/entropy.c \
77+
repo/library/ssl_srv.c \
78+
repo/library/error.c \
79+
repo/library/ssl_ticket.c \
80+
repo/library/gcm.c \
81+
repo/library/ssl_tls.c \
82+
repo/library/havege.c \
83+
repo/library/threading.c \
84+
repo/library/hkdf.c \
85+
repo/library/hmac_drbg.c \
86+
repo/library/version.c \
87+
repo/library/md2.c \
88+
repo/library/version_features.c \
89+
repo/library/md4.c \
90+
repo/library/x509.c \
91+
repo/library/md5.c \
92+
repo/library/x509_create.c \
93+
repo/library/md.c \
94+
repo/library/x509_crl.c \
95+
repo/library/memory_buffer_alloc.c \
96+
repo/library/x509_csr.c \
97+
repo/library/nist_kw.c \
98+
repo/library/x509write_crt.c \
99+
repo/library/oid.c \
100+
repo/library/x509write_csr.c \
101+
repo/library/padlock.c \
102+
repo/library/xtea.c \
103+
repo/library/md_wrap.c \
104+
$(NULL)
105+
106+
libmbedtls_a_CPPFLAGS = \
107+
-I$(top_srcdir)/third_party/mbedtls/repo/include \
108+
$(MBEDTLS_CPPFLAGS) \
109+
$(NULL)
110+
111+
include $(abs_top_nlbuild_autotools_dir)/automake/post.am

0 commit comments

Comments
 (0)