From 47f325f49752bc41994433427beac0f357ba1eb7 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Wed, 15 Jul 2020 00:10:33 +0800 Subject: [PATCH] [nrf5] build with internal OpenThread (#1579) This commit adds support to build with internal OpenThread on the Nordic platform. --- config/nrf5/nrf5-chip.mk | 2 +- configure.ac | 142 +++++++++++++++++++++------- examples/lighting-app/nrf5/Makefile | 28 ++---- examples/lock-app/nrf5/Makefile | 28 ++---- third_party/Makefile.am | 3 +- third_party/openthread/repo | 2 +- 6 files changed, 125 insertions(+), 80 deletions(-) diff --git a/config/nrf5/nrf5-chip.mk b/config/nrf5/nrf5-chip.mk index 8abc89e69daeb3..38ea27e1bf232d 100644 --- a/config/nrf5/nrf5-chip.mk +++ b/config/nrf5/nrf5-chip.mk @@ -109,7 +109,7 @@ CHIP_CONFIGURE_OPTIONS = \ --with-chip-ble-project-includes=$(CHIP_PROJECT_CONFIG) \ --with-chip-warm-project-includes=$(CHIP_PROJECT_CONFIG) \ --with-chip-device-project-includes=$(CHIP_PROJECT_CONFIG) \ - --with-openthread=$(NRF5_SDK_ROOT)/external/openthread \ + --with-openthread=internal \ --disable-ipv4 \ --disable-tests \ --disable-tools \ diff --git a/configure.ac b/configure.ac index a86ba6fa12f5fc..0ef74005fcbb35 100644 --- a/configure.ac +++ b/configure.ac @@ -904,36 +904,6 @@ NL_ENABLE_DOCS([auto],[NO]) AM_CONDITIONAL(CHIP_BUILD_DOCS, [test "${nl_cv_build_docs}" = "yes"]) -# -# OpenThread -# - -NL_WITH_OPTIONAL_INTERNAL_PACKAGE( - [OpenThread], - [OPENTHREAD], - [openthread], - [], - [ - AC_MSG_NOTICE([No internal OpenThread support yet!]) - with_openthread=no - ], - [ - # Check for required OpenThread headers. - AC_CHECK_HEADERS([openthread/dataset.h] [openthread/dataset_ftd.h] [openthread/error.h] [openthread/icmp6.h] [openthread/instance.h] [openthread/ip6.h] [openthread/link.h] [openthread/message.h] [openthread/netdata.h] [openthread/tasklet.h] [openthread/thread.h], - [], - [ - AC_MSG_ERROR(The nlio header "$ac_header" is required but cannot be found.) - ]) - ] -) -AM_CONDITIONAL([CHIP_ENABLE_OPENTHREAD], [test "${with_openthread}" != "no"]) -if test "${with_openthread}" != "no"; then - CHIP_ENABLE_OPENTHREAD=1 -else - CHIP_ENABLE_OPENTHREAD=0 -fi -AC_DEFINE_UNQUOTED([CHIP_ENABLE_OPENTHREAD],[${CHIP_ENABLE_OPENTHREAD}],[Define to 1 if you want to enable OpenThread.]) - # # Network Technology Layer # @@ -1043,6 +1013,8 @@ nrf5) CONFIG_DEVICE_LAYER=1 CHIP_DEVICE_LAYER_TARGET=nRF5 CHIP_DEVICE_LAYER_TARGET_NRF5=1 + CFLAGS="${CFLAGS} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -mabi=aapcs" + CXXFLAGS="${CXXFLAGS} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -mabi=aapcs" ;; linux) @@ -1616,6 +1588,106 @@ else AC_DEFINE([CHIP_WITH_MBEDTLS], [1], [Define to 1 to build CHIP with mbedTLS]) fi +# +# OpenThread +# + +NL_WITH_OPTIONAL_INTERNAL_PACKAGE( + [OpenThread], + [OPENTHREAD], + [openthread], + [], + [ + # use absolute path to support build out of source tree + chip_srcdir="$(cd ${srcdir} && pwd)" + + # bootstrap + test -f ${chip_srcdir}/third_party/openthread/repo/configure || (cd ${chip_srcdir}/third_party/openthread/repo && ./bootstrap) + + case "${with_device_layer}" in + nrf5) + OPENTHREAD_CPPFLAGS="-I\${abs_top_srcdir}/third_party/openthread/repo/include" + OPENTHREAD_LDFLAGS="-L${ac_pwd}/third_party/openthread" + OPENTHREAD_LIBS="-lopenthread-cli-ftd \ + -lopenthread-ftd \ + -lopenthread-platform-utils \ + -lopenthread-nrf52840-transport \ + -lopenthread-nrf52840-softdevice-sdk \ + -lnordicsemi-nrf52840-radio-driver-softdevice \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_cc310_backend.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_vanilla_backend.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedtls_base_vanilla.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a" + + # private definitions + ot_cppflags="-Wno-expansion-to-defined \ + -I${chip_srcdir}/third_party/openthread/repo/examples/platforms/nrf528xx/nrf52840 \ + -I${chip_srcdir}/third_party/openthread/repo/third_party/NordicSemiconductor/libraries/nrf_security/config \ + -I${chip_srcdir}/third_party/openthread/repo/third_party/NordicSemiconductor/libraries/nrf_security/include \ + -I${chip_srcdir}/third_party/openthread/repo/third_party/NordicSemiconductor/libraries/nrf_security/mbedtls_plat_config \ + -I${chip_srcdir}/third_party/openthread/repo/third_party/NordicSemiconductor/libraries/nrf_security/nrf_cc310_plat/include \ + -I${chip_srcdir}/third_party/mbedtls/repo/include \ + -DMBEDTLS_CONFIG_FILE=\ \ + -DMBEDTLS_USER_CONFIG_FILE=\ \ + -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\ \ + -DOPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\ \ + -DOPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE=1 \ + -DOPENTHREAD_CONFIG_JOINER_ENABLE=1 \ + -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1 \ + -DUART_AS_SERIAL_TRANSPORT=1" + + (mkdir -p ${ac_pwd}/third_party/openthread \ + && cd ${ac_pwd}/third_party/openthread \ + && CPPFLAGS="${ot_cppflags}" CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" ${chip_srcdir}/third_party/openthread/repo/configure \ + --disable-builtin-mbedtls \ + --disable-docs \ + --disable-executable \ + --disable-tools \ + --enable-cli \ + --enable-ftd \ + --host=arm-none-eabi \ + --prefix=${prefix} \ + --exec-prefix=${exec_prefix} \ + --with-examples=nrf52840) + + if test $? != 0; then + AC_MSG_ERROR([Failed to configure OpenThread!]) + fi + + maybe_openthread_dirstem="openthread" + ;; + + *) + AC_MSG_NOTICE([No internal OpenThread support yet!]) + nl_with_openthread=no + with_openthread=no + ;; + esac + ], + [ + # Check for required OpenThread headers. + AC_CHECK_HEADERS([openthread/dataset.h] [openthread/dataset_ftd.h] [openthread/error.h] [openthread/icmp6.h] [openthread/instance.h] [openthread/ip6.h] [openthread/link.h] [openthread/message.h] [openthread/netdata.h] [openthread/tasklet.h] [openthread/thread.h], + [], + [ + AC_MSG_ERROR(The OpenThread header "$ac_header" is required but cannot be found.) + ]) + maybe_openthread_dirstem="" + ] +) +AC_SUBST(OPENTHREAD_SUBDIRS, [${maybe_openthread_dirstem}]) +AM_CONDITIONAL([CHIP_ENABLE_OPENTHREAD], [test "${nl_with_openthread}" != "no"]) +if test "${nl_with_openthread}" != "no"; then + CHIP_ENABLE_OPENTHREAD=1 +else + CHIP_ENABLE_OPENTHREAD=0 +fi +AC_DEFINE_UNQUOTED([CHIP_ENABLE_OPENTHREAD],[${CHIP_ENABLE_OPENTHREAD}],[Define to 1 if you want to enable OpenThread.]) + # # LwIP # @@ -2139,9 +2211,9 @@ AC_SUBST(CRYPTO_CPPFLAGS) AC_SUBST(CRYPTO_LDFLAGS) AC_SUBST(CRYPTO_LIBS) -CPPFLAGS="${CPPFLAGS} ${CRYPTO_CPPFLAGS}" -LDFLAGS="${LDFLAGS} ${CRYPTO_LDFLAGS}" -LIBS="${LIBS} ${CRYPTO_LIBS}" +CPPFLAGS="${CPPFLAGS} ${CRYPTO_CPPFLAGS} ${OPENTHREAD_CPPFLAGS}" +LDFLAGS="${LDFLAGS} ${CRYPTO_LDFLAGS} ${OPENTHREAD_LDFLAGS}" +LIBS="${LIBS} ${CRYPTO_LIBS} ${OPENTHREAD_LIBS}" # Add any code coverage CPPFLAGS, LDFLAGS, and LIBS @@ -2319,6 +2391,10 @@ AC_MSG_NOTICE([ mbedTLS compile flags : ${MBEDTLS_CPPFLAGS:--} mbedTLS link flags : ${MBEDTLS_LDFLAGS:--} mbedTLS link libraries : ${MBEDTLS_LIBS:--} + OpenThread source : ${nl_with_openthread} + OpenThread compile flags : ${OPENTHREAD_CPPFLAGS:--} + OpenThread link flags : ${OPENTHREAD_LDFLAGS:--} + OpenThread link libraries : ${OPENTHREAD_LIBS:--} OpenSSL source : ${nl_with_openssl} OpenSSL compile flags : ${OPENSSL_CPPFLAGS:--} OpenSSL link flags : ${OPENSSL_LDFLAGS:--} diff --git a/examples/lighting-app/nrf5/Makefile b/examples/lighting-app/nrf5/Makefile index f2cc97e3bd1a85..56fa0a6fc30766 100644 --- a/examples/lighting-app/nrf5/Makefile +++ b/examples/lighting-app/nrf5/Makefile @@ -194,15 +194,9 @@ DEFINES = \ NRF52840_XXAA \ NRFX_PRS_ENABLED=0 \ NRF_SD_BLE_API_VERSION=7 \ - OPENTHREAD_CONFIG_COAP_API_ENABLE \ - OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=0 \ - OPENTHREAD_CONFIG_FILE=\"openthread-config-wrap.h\" \ - OPENTHREAD_FTD=1 \ PRINTF_DISABLE_SUPPORT_EXPONENTIAL \ S140 \ SOFTDEVICE_PRESENT \ - THREAD_EXAMPLE_COAP_SERVER=1 \ - THREAD_EXAMPLE_FREERTOS=1 \ UART0_ENABLED=0 \ UART1_ENABLED=1 \ USE_APP_CONFIG \ @@ -210,9 +204,12 @@ DEFINES = \ __STACK_SIZE=8192 \ LIBS = \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-cli-ftd.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-ftd.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-platform-utils.a \ + -lopenthread-cli-ftd \ + -lopenthread-ftd \ + -lopenthread-platform-utils \ + -lopenthread-nrf52840-transport \ + -lopenthread-nrf52840-softdevice-sdk \ + -lnordicsemi-nrf52840-radio-driver-softdevice \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ @@ -222,19 +219,6 @@ LIBS = \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-nrf52840-softdevice-sdk.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libnordicsemi-nrf52840-radio-driver-softdevice.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_cc310_backend.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_vanilla_backend.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-platform-utils.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_base_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-ftd.a \ CFLAGS = \ --specs=nano.specs diff --git a/examples/lock-app/nrf5/Makefile b/examples/lock-app/nrf5/Makefile index 0396de152b5361..ec385e33d1afdc 100644 --- a/examples/lock-app/nrf5/Makefile +++ b/examples/lock-app/nrf5/Makefile @@ -194,15 +194,9 @@ DEFINES = \ NRF52840_XXAA \ NRFX_PRS_ENABLED=0 \ NRF_SD_BLE_API_VERSION=7 \ - OPENTHREAD_CONFIG_COAP_API_ENABLE \ - OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=0 \ - OPENTHREAD_CONFIG_FILE=\"openthread-config-wrap.h\" \ - OPENTHREAD_FTD=1 \ PRINTF_DISABLE_SUPPORT_EXPONENTIAL \ S140 \ SOFTDEVICE_PRESENT \ - THREAD_EXAMPLE_COAP_SERVER=1 \ - THREAD_EXAMPLE_FREERTOS=1 \ UART0_ENABLED=0 \ UART1_ENABLED=1 \ USE_APP_CONFIG \ @@ -210,9 +204,12 @@ DEFINES = \ __STACK_SIZE=8192 \ LIBS = \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-cli-ftd.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-ftd.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-platform-utils.a \ + -lopenthread-cli-ftd \ + -lopenthread-ftd \ + -lopenthread-platform-utils \ + -lopenthread-nrf52840-transport \ + -lopenthread-nrf52840-softdevice-sdk \ + -lnordicsemi-nrf52840-radio-driver-softdevice \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ @@ -222,19 +219,6 @@ LIBS = \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-nrf52840-softdevice-sdk.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libnordicsemi-nrf52840-radio-driver-softdevice.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_cc310_backend.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_vanilla_backend.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-platform-utils.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_base_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-ftd.a \ CFLAGS = \ --specs=nano.specs diff --git a/third_party/Makefile.am b/third_party/Makefile.am index dd4ee9dc53f745..6aa2b2d47fa745 100644 --- a/third_party/Makefile.am +++ b/third_party/Makefile.am @@ -44,7 +44,7 @@ DIST_SUBDIRS = \ # of the 'distclean' target. Consequently, we conditionally include # them in DIST_SUBDIRS on invocation of 'distclean-recursive' -distclean-recursive: DIST_SUBDIRS += $(NLASSERT_SUBDIRS) $(NLFAULTINJECTION_SUBDIRS) $(NLIO_SUBDIRS) $(NLUNIT_TEST_SUBDIRS) $(MBEDTLS_SUBDIRS) $(OTBR_CLIENT_SUBDIRS) +distclean-recursive: DIST_SUBDIRS += $(NLASSERT_SUBDIRS) $(NLFAULTINJECTION_SUBDIRS) $(NLIO_SUBDIRS) $(NLUNIT_TEST_SUBDIRS) $(MBEDTLS_SUBDIRS) $(OPENTHREAD_SUBDIRS) $(OTBR_CLIENT_SUBDIRS) # Always build (e.g. for 'make all') these subdirectories. # @@ -58,6 +58,7 @@ SUBDIRS = \ $(NLIO_SUBDIRS) \ $(NLUNIT_TEST_SUBDIRS) \ $(MBEDTLS_SUBDIRS) \ + $(OPENTHREAD_SUBDIRS) \ $(OT_BR_POSIX_SUBDIRS) \ $(NULL) diff --git a/third_party/openthread/repo b/third_party/openthread/repo index 5f0e36eeb236a5..4806fa4d0dd454 160000 --- a/third_party/openthread/repo +++ b/third_party/openthread/repo @@ -1 +1 @@ -Subproject commit 5f0e36eeb236a507631e9c822e43f742b7b6738a +Subproject commit 4806fa4d0dd454d05452c1dbf219c7fb7ff2d3fa