From d9660a40183181bcdc868f79800d17f05caa68ff Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Tue, 30 Jun 2020 18:24:00 +0800 Subject: [PATCH] new configure logic --- config/nrf5/nrf5-chip.mk | 2 +- configure.ac | 81 +++++++------------ examples/lock-app/nrf5/Makefile | 2 +- examples/lock-app/nrf5/main/main.cpp | 18 ++--- src/platform/Linux/ThreadStackManagerImpl.cpp | 7 +- src/platform/Linux/ThreadStackManagerImpl.h | 4 +- src/platform/Makefile.am | 6 +- src/platform/nRF5/CHIPDevicePlatformConfig.h | 2 +- src/platform/tests/Makefile.am | 6 +- src/platform/tests/TestThreadStackMgr.cpp | 13 ++- third_party/ot-br-posix/Makefile.am | 4 +- 11 files changed, 63 insertions(+), 82 deletions(-) diff --git a/config/nrf5/nrf5-chip.mk b/config/nrf5/nrf5-chip.mk index bf291bcb612f85..d4a75b9763e4b2 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 \ + --enable-openthread \ --disable-ipv4 \ --disable-tests \ --disable-tools \ diff --git a/configure.ac b/configure.ac index 1d47013129c491..e5cf59a42d27dc 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 # @@ -1785,16 +1755,16 @@ if test "${nl_cv_build_tests}" = "yes"; then fi # -# otbr-client +# openthread # -AC_ARG_ENABLE(otbr-client, - [AS_HELP_STRING([--enable-otbr-client], [Enable OpenThread Linux client])], +AC_ARG_ENABLE(openthread, + [AS_HELP_STRING([--enable-openthread], [Enable OpenThread])], [ case "${enableval}" in no|yes) - enable_otbr_client=${enableval} + enable_openthread=${enableval} ;; *) @@ -1803,33 +1773,42 @@ AC_ARG_ENABLE(otbr-client, esac ], - [ enable_otbr_client="no" ] + [ enable_openthread="no" ] ) -AC_MSG_NOTICE("enable_otbr_client=${enable_otbr_client}") +AC_MSG_NOTICE("enable_openthread=${enable_openthread}") -if test "${enable_otbr_client}" = "yes"; then - maybe_otbr_client_dirstem="ot-br-posix" - otbr_client_dirstem="third_party/${maybe_otbr_client_dirstem}/repo" +if test "${enable_openthread}" = "yes"; then + if test "${with_device_layer}" = "linux"; then + maybe_ot_br_client_dirstem="ot-br-posix" + ot_br_client_dirstem="third_party/${maybe_ot_br_client_dirstem}/repo" - AC_MSG_NOTICE([attempting to create internal ${otbrclient_dirstem}]) + AC_MSG_NOTICE([attempting to create internal ${ot_brclient_dirstem}]) + ${MAKE-make} --no-print-directory -C ${srcdir} -f Makefile-bootstrap ${ot_br_client_dirstem} - ${MAKE-make} --no-print-directory -C ${srcdir} -f Makefile-bootstrap ${otbr_client_dirstem} + if test $? -ne 0; then + AC_MSG_ERROR([failed to create ${ot_br_client_dirstem}. Please check your network connection or the correctness of 'repos.conf']) + fi - if test $? -ne 0; then - AC_MSG_ERROR([failed to create ${otbr_client_dirstem}. Please check your network connection or the correctness of 'repos.conf']) - fi + PKG_CHECK_MODULES([DBUS], dbus-1 >= 1.4) + AC_SUBST([DBUS_CFLAGS]) + AC_SUBST([DBUS_LIBS]) + AC_SUBST(OTBR_CLIENT_SUBDIRS, [${maybe_ot_br_client_dirstem}]) + else + openthread_dirstem="third_party/openthread/repo" - # otbrclient requires dbus - PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.4) - AC_SUBST([DBUS_CFLAGS]) - AC_SUBST([DBUS_LIBS]) + AC_MSG_NOTICE([attempting to create internal ${openthread_dirstem}]) + ${MAKE-make} --no-print-directory -C ${srcdir} -f Makefile-bootstrap ${openthread_dirstem} + if test $? -ne 0; then + AC_MSG_ERROR([failed to create ${ot_br_client_dirstem}. Please check your network connection or the correctness of 'repos.conf']) + fi + fi else - maybe_otbr_client_dirstem= + maybe_ot_br_client_dirstem= fi -AC_SUBST(OTBR_CLIENT_SUBDIRS, [${maybe_otbr_client_dirstem}]) -AM_CONDITIONAL([CHIP_WITH_OTBR_CLIENT], [test "${enable_otbr_client}" != "no"]) +AM_CONDITIONAL([CHIP_WITH_OT_BR_CLIENT], [test "${enable_openthread}" != "no" && test "${with_device_layer}" == "linux"]) +AM_CONDITIONAL([CHIP_WITH_OPENTHREAD], [test "${enable_openthread}" != "no" && test "${with_device_layer}" != "linux"]) # # Nlunit-test diff --git a/examples/lock-app/nrf5/Makefile b/examples/lock-app/nrf5/Makefile index 83e81f31587f2f..70f432f6614a10 100644 --- a/examples/lock-app/nrf5/Makefile +++ b/examples/lock-app/nrf5/Makefile @@ -178,7 +178,7 @@ INC_DIRS = \ DEFINES = \ BOARD_PCA10056 \ BSP_DEFINES_ONLY \ - CHIP_ENABLE_OPENTHREAD=1 \ + CHIP_WITH_OPENTHREAD=1 \ CONFIG_GPIO_AS_PINRESET \ ENABLE_FEM \ FLOAT_ABI_HARD \ diff --git a/examples/lock-app/nrf5/main/main.cpp b/examples/lock-app/nrf5/main/main.cpp index e9143574b9c33d..5d4be0e1c16db5 100644 --- a/examples/lock-app/nrf5/main/main.cpp +++ b/examples/lock-app/nrf5/main/main.cpp @@ -33,7 +33,7 @@ #include "nrf_crypto.h" #endif #include "mem_manager.h" -#if CHIP_ENABLE_OPENTHREAD +#if CHIP_WITH_OPENTHREAD extern "C" { #include "multiprotocol_802154_config.h" #include "nrf_802154.h" @@ -41,7 +41,7 @@ extern "C" { #include "nrf_cc310_platform_mutex.h" #include } -#endif // CHIP_ENABLE_OPENTHREAD +#endif // CHIP_WITH_OPENTHREAD #if NRF_LOG_ENABLED #include "nrf_log_backend_uart.h" @@ -50,7 +50,7 @@ extern "C" { #endif // NRF_LOG_ENABLED #include -#if CHIP_ENABLE_OPENTHREAD +#if CHIP_WITH_OPENTHREAD #include #include #include @@ -64,7 +64,7 @@ extern "C" { #include #include #include -#endif // CHIP_ENABLE_OPENTHREAD +#endif // CHIP_WITH_OPENTHREAD using namespace ::chip; using namespace ::chip::Inet; @@ -105,7 +105,7 @@ uint32_t LogTimestamp(void) static void OnSoCEvent(uint32_t sys_evt, void * p_context) { -#if CHIP_ENABLE_OPENTHREAD +#if CHIP_WITH_OPENTHREAD otSysSoftdeviceSocEvtHandler(sys_evt); #endif UNUSED_PARAMETER(p_context); @@ -221,7 +221,7 @@ int main(void) APP_ERROR_HANDLER(ret); } -#if CHIP_ENABLE_OPENTHREAD +#if CHIP_WITH_OPENTHREAD NRF_LOG_INFO("Initializing OpenThread stack"); mbedtls_platform_set_calloc_free(calloc, free); @@ -257,7 +257,7 @@ int main(void) NRF_LOG_INFO("ConnectivityMgr().SetThreadDeviceType() failed"); APP_ERROR_HANDLER(ret); } -#endif // CHIP_ENABLE_OPENTHREAD +#endif // CHIP_WITH_OPENTHREAD NRF_LOG_INFO("Starting CHIP task"); ret = PlatformMgr().StartEventLoopTask(); @@ -267,7 +267,7 @@ int main(void) APP_ERROR_HANDLER(ret); } -#if CHIP_ENABLE_OPENTHREAD +#if CHIP_WITH_OPENTHREAD NRF_LOG_INFO("Starting OpenThread task"); // Start OpenThread task @@ -277,7 +277,7 @@ int main(void) NRF_LOG_INFO("ThreadStackMgr().StartThreadTask() failed"); APP_ERROR_HANDLER(ret); } -#endif // CHIP_ENABLE_OPENTHREAD +#endif // CHIP_WITH_OPENTHREAD ret = GetAppTask().StartAppTask(); if (ret != NRF_SUCCESS) diff --git a/src/platform/Linux/ThreadStackManagerImpl.cpp b/src/platform/Linux/ThreadStackManagerImpl.cpp index 5da95da0759c2b..356316c4c9c2f5 100644 --- a/src/platform/Linux/ThreadStackManagerImpl.cpp +++ b/src/platform/Linux/ThreadStackManagerImpl.cpp @@ -55,8 +55,9 @@ using otbr::DBus::NeighborInfo; namespace chip { namespace DeviceLayer { -ThreadStackManagerImpl::ThreadStackManagerImpl(DBusConnection *aConnection) : - mThreadApi(nullptr), mConnection(aConnection), mNetworkInfo(), mAttached(false) {} +ThreadStackManagerImpl::ThreadStackManagerImpl(DBusConnection * aConnection) : + mThreadApi(nullptr), mConnection(aConnection), mNetworkInfo(), mAttached(false) +{} CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack() { @@ -174,7 +175,7 @@ bool ThreadStackManagerImpl::_IsThreadProvisioned() return mNetworkInfo.ThreadNetworkName[0] != '\0'; } -void ThreadStackManagerImpl::_ClearThreadProvision() +void ThreadStackManagerImpl::_ErasePersistentInfo() { mNetworkInfo = Internal::DeviceNetworkInfo{}; } diff --git a/src/platform/Linux/ThreadStackManagerImpl.h b/src/platform/Linux/ThreadStackManagerImpl.h index da0e48a4bccc71..d5ac792525cc6c 100644 --- a/src/platform/Linux/ThreadStackManagerImpl.h +++ b/src/platform/Linux/ThreadStackManagerImpl.h @@ -31,7 +31,7 @@ namespace DeviceLayer { class ThreadStackManagerImpl : public ThreadStackManager { public: - ThreadStackManagerImpl(DBusConnection *aConnection); + ThreadStackManagerImpl(DBusConnection * aConnection); CHIP_ERROR _InitThreadStack(); CHIP_ERROR _ProcessThreadActivity(); @@ -49,7 +49,7 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _SetThreadProvision(const Internal::DeviceNetworkInfo & netInfo); - void _ClearThreadProvision(); + void _ErasePersistentInfo(); bool _IsThreadProvisioned(); diff --git a/src/platform/Makefile.am b/src/platform/Makefile.am index 1efcd1063be484..3e29f26f645e51 100644 --- a/src/platform/Makefile.am +++ b/src/platform/Makefile.am @@ -116,7 +116,7 @@ libDeviceLayer_a_SOURCES = \ Globals.cpp \ $(NULL) -if CHIP_ENABLE_OPENTHREAD +if CHIP_WITH_OPENTHREAD libDeviceLayer_a_SOURCES += \ OpenThread/OpenThreadUtils.cpp \ $(NULL) @@ -142,7 +142,7 @@ libDeviceLayer_a_SOURCES += \ Linux/SystemTimeSupport.cpp \ $(NULL) -if CHIP_WITH_OTBR_CLIENT +if CHIP_WITH_OT_BR_CLIENT libDeviceLayer_a_SOURCES += \ Linux/ThreadStackManagerImpl.cpp \ $(NULL) @@ -169,7 +169,7 @@ libDeviceLayer_a_SOURCES += \ FreeRTOS/SystemTimeSupport.cpp \ $(NULL) -if CHIP_ENABLE_OPENTHREAD +if CHIP_WITH_OPENTHREAD libDeviceLayer_a_SOURCES += \ nRF5/ThreadStackManagerImpl.cpp \ $(NULL) diff --git a/src/platform/nRF5/CHIPDevicePlatformConfig.h b/src/platform/nRF5/CHIPDevicePlatformConfig.h index 72121484ad5526..7855fb34ace3b7 100644 --- a/src/platform/nRF5/CHIPDevicePlatformConfig.h +++ b/src/platform/nRF5/CHIPDevicePlatformConfig.h @@ -36,7 +36,7 @@ #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 -#if CHIP_ENABLE_OPENTHREAD +#if CHIP_WITH_OPENTHREAD #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1 #endif diff --git a/src/platform/tests/Makefile.am b/src/platform/tests/Makefile.am index b2b0fdfdef1e82..f01d2502bcc57f 100644 --- a/src/platform/tests/Makefile.am +++ b/src/platform/tests/Makefile.am @@ -69,7 +69,7 @@ AM_CPPFLAGS = \ $(NULL) if CHIP_DEVICE_LAYER_TARGET_LINUX -if CHIP_WITH_OTBR_CLIENT +if CHIP_WITH_OT_BR_CLIENT AM_CPPFLAGS += \ $(DBUS_CFLAGS) \ -I$(top_srcdir)/third_party/ot-br-posix/repo/include \ @@ -87,11 +87,13 @@ CHIP_LDADD = \ $(NULL) if CHIP_DEVICE_LAYER_TARGET_LINUX +if CHIP_WITH_OT_BR_CLIENT CHIP_LDADD += \ $(DBUS_LIBS) \ $(top_builddir)/third_party/ot-br-posix/libotbrclient.a \ $(NULL) endif +endif COMMON_LDADD = \ libPlatformTests.a \ @@ -112,7 +114,7 @@ check_PROGRAMS = \ $(NULL) if CHIP_DEVICE_LAYER_TARGET_LINUX -if CHIP_WITH_OTBR_CLIENT +if CHIP_WITH_OT_BR_CLIENT check_PROGRAMS += TestThreadStackMgr TestThreadStackMgr_LDADD = $(COMMON_LDADD) diff --git a/src/platform/tests/TestThreadStackMgr.cpp b/src/platform/tests/TestThreadStackMgr.cpp index 981ae67d015389..0d68affcb368c7 100644 --- a/src/platform/tests/TestThreadStackMgr.cpp +++ b/src/platform/tests/TestThreadStackMgr.cpp @@ -16,19 +16,18 @@ */ #include -#include #include +#include #include "platform/internal/CHIPDeviceLayerInternal.h" -#include "platform/ThreadStackManager.h" #include "platform/PlatformManager.h" - +#include "platform/ThreadStackManager.h" #if CHIP_DEVICE_LAYER_TARGET == LINUX struct DBusConnectionDeleter { - void operator()(DBusConnection *aConnection) { dbus_connection_unref(aConnection); } + void operator()(DBusConnection * aConnection) { dbus_connection_unref(aConnection); } }; using UniqueDBusConnection = std::unique_ptr; @@ -37,8 +36,8 @@ using UniqueDBusConnection = std::unique_ptr