Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zephyr standalone platform update #34135

Merged
merged 21 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/zephyr/app/enable-gnu-std.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ add_library(gnu17 INTERFACE)
target_compile_options(gnu17
INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17>
-D_SYS__PTHREADTYPES_H_)
target_link_libraries(app PRIVATE gnu17)
-D_DEFAULT_SOURCE)
target_link_libraries(app PRIVATE gnu17)
68 changes: 48 additions & 20 deletions config/zephyr/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,27 @@ endif()
get_filename_component(GN_ROOT_TARGET ${CHIP_ROOT}/config/zephyr/chip-gn REALPATH)
get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake REALPATH)

# Additional configuration
if (CONFIG_CHIP_PW_RPC)
set(CONFIG_CHIP_LIB_PW_RPC YES)
endif()

# Get common Cmake sources
include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake)
include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake)

# Prepare compiler flags
matter_add_flags(-isystem${ZEPHYR_BASE}/../modules/crypto/mbedtls/include/)

if (CONFIG_POSIX_API)
matter_add_flags(-D_SYS__PTHREADTYPES_H_)
matter_add_flags(-D_DEFAULT_SOURCE)
matter_add_flags(-isystem${ZEPHYR_BASE}/include/zephyr/posix)
endif()

if(CONFIG_MBEDTLS)
zephyr_include_directories($<TARGET_PROPERTY:mbedTLS,INTERFACE_INCLUDE_DIRECTORIES>)
zephyr_compile_definitions($<TARGET_PROPERTY:mbedTLS,INTERFACE_COMPILE_DEFINITIONS>)
endif()

zephyr_get_compile_flags(ZEPHYR_CFLAGS_C C)
matter_add_cflags(${ZEPHYR_CFLAGS_C})
matter_add_cflags("${ZEPHYR_CFLAGS_C}")
zephyr_get_compile_flags(ZEPHYR_CFLAGS_CC CXX)
matter_add_cxxflags(${ZEPHYR_CFLAGS_CC})
matter_add_cxxflags("${ZEPHYR_CFLAGS_CC}")
zephyr_get_gnu_cpp_standard(ZEPHYR_GNU_CPP_STD)
matter_add_cxxflags(${ZEPHYR_GNU_CPP_STD})
matter_add_cxxflags("${ZEPHYR_GNU_CPP_STD}")

# Set up custom OpenThread configuration

Expand All @@ -81,29 +79,59 @@ matter_common_gn_args(
DEBUG CONFIG_DEBUG
LIB_SHELL CONFIG_CHIP_LIB_SHELL
LIB_TESTS CONFIG_CHIP_BUILD_TESTS
LIB_PW_RPC CONFIG_CHIP_PW_RPC
PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG}
)
matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR})
matter_add_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
matter_add_gn_arg_string("zephyr_cxx" ${CMAKE_CXX_COMPILER})
matter_add_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD)
matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD)
matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4)
matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS)

matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR})
matter_add_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
matter_add_gn_arg_string("zephyr_cxx" ${CMAKE_CXX_COMPILER})
matter_add_gn_arg_bool ("chip_logging" CONFIG_LOG)
matter_add_gn_arg_bool ("chip_error_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 1)
matter_add_gn_arg_bool ("chip_progress_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 3)
matter_add_gn_arg_bool ("chip_detail_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 4)
matter_add_gn_arg_bool ("chip_automation_logging" FALSE)
matter_add_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD)
matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD)
matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_CHIP_IPV4)
matter_add_gn_arg_bool ("chip_enable_wifi" CONFIG_WIFI)
matter_add_gn_arg_bool ("chip_config_network_layer_ble" CONFIG_BT)
matter_add_gn_arg_bool ("chip_mdns_minimal" CONFIG_WIFI)
matter_add_gn_arg_bool ("chip_mdns_minimal" CONFIG_NET_L2_ETHERNET)
matter_add_gn_arg_bool ("chip_mdns_platform" CONFIG_NET_L2_OPENTHREAD)
matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS)
matter_add_gn_arg_bool ("chip_inet_config_enable_udp_endpoint" CONFIG_NET_UDP)
matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_NET_TCP)
matter_add_gn_arg_bool ("chip_malloc_sys_heap" CONFIG_CHIP_MALLOC_SYS_HEAP)


if (CONFIG_CHIP_ENABLE_DNSSD_SRP)
matter_add_gn_arg_string("chip_mdns" "platform")
endif()

if(CONFIG_WIFI)
matter_add_gn_arg_string("chip_mdns" "minimal")
elseif (CONFIG_NET_L2_ETHERNET)
matter_add_gn_arg_string("chip_mdns" "minimal")
elseif (CONFIG_NET_L2_OPENTHREAD)
matter_add_gn_arg_string("chip_mdns" "platform")
else()
matter_add_gn_arg_string("chip_mdns" "none")
endif()

if (CONFIG_CHIP_PW_RPC)
set(PIGWEED_DIR "//third_party/pigweed/repo")
matter_add_gn_arg_string("pw_assert_BACKEND" ${PIGWEED_DIR}/pw_assert_log:check_backend)
matter_add_gn_arg_string("pw_log_BACKEND" ${PIGWEED_DIR}/pw_log_basic)
matter_add_gn_arg("pw_build_LINK_DEPS" [\"${PIGWEED_DIR}/pw_assert:impl\",\ \"${PIGWEED_DIR}/pw_log:impl\"])
endif()

matter_generate_args_tmp_file()

# ==============================================================================
# Build chip library
# ==============================================================================
matter_build(chip
LIB_SHELL ${CONFIG_CHIP_LIB_SHELL}
LIB_PW_RPC ${CONFIG_CHIP_PW_RPC}
LIB_TESTS ${CONFIG_CHIP_BUILD_TESTS}
GN_DEPENDENCIES kernel
)
Expand Down
68 changes: 68 additions & 0 deletions config/zephyr/chip-module/Kconfig.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Bluetooth Low Energy configs
config BT
bool
default y

config BT_PERIPHERAL
bool
default y

config BT_PERIPHERAL_PREF_MIN_INT
int
default 36

config BT_PERIPHERAL_PREF_MAX_INT
int
default 36

config BT_GAP_AUTO_UPDATE_CONN_PARAMS
bool
default y

config BT_GATT_DYNAMIC_DB
bool
default y

config BT_DEVICE_NAME_DYNAMIC
bool
default y

config BT_DEVICE_NAME_MAX
int
default 15

config BT_MAX_CONN
int
default 1

config BT_L2CAP_TX_MTU
int
default 247

config BT_BUF_ACL_RX_SIZE
int
default 251

config BT_BUF_ACL_TX_SIZE
int
default 251

config BT_RX_STACK_SIZE
int
default 1200
71 changes: 0 additions & 71 deletions config/zephyr/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@

if CHIP

config LOG
bool
default y

if LOG

choice LOG_MODE
default LOG_MODE_MINIMAL
endchoice

choice MATTER_LOG_LEVEL_CHOICE
default MATTER_LOG_LEVEL_DBG
endchoice

config LOG_DEFAULT_LEVEL
int
default 2

endif

# disable synchronous printk to avoid blocking IRQs which
# may affect time sensitive components
config PRINTK_SYNC
Expand Down Expand Up @@ -119,58 +99,7 @@ config NET_BUF_TX_COUNT
int
default 80

# Bluetooth Low Energy configs
config BT
bool
default y

config BT_PERIPHERAL
bool
default y

config BT_PERIPHERAL_PREF_MIN_INT
int
default 36

config BT_PERIPHERAL_PREF_MAX_INT
int
default 36

config BT_GAP_AUTO_UPDATE_CONN_PARAMS
bool
default y

config BT_GATT_DYNAMIC_DB
bool
default y

config BT_DEVICE_NAME_DYNAMIC
bool
default y

config BT_DEVICE_NAME_MAX
int
default 15

config BT_MAX_CONN
int
default 1

config BT_L2CAP_TX_MTU
int
default 247

config BT_BUF_ACL_RX_SIZE
int
default 251

config BT_BUF_ACL_TX_SIZE
int
default 251

config BT_RX_STACK_SIZE
int
default 1200

config CHIP_OTA_REQUESTOR
bool
Expand Down
64 changes: 64 additions & 0 deletions config/zephyr/chip-module/Kconfig.mbedtls
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if CHIP

config MBEDTLS
default y

config MBEDTLS_ENTROPY_ENABLED
default y

config MBEDTLS_ENTROPY_ENABLED
default y

config MBEDTLS_ZEPHYR_ENTROPY
default y

config MBEDTLS_ENABLE_HEAP
default y

config MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
default y

config MBEDTLS_ECP_ALL_ENABLED
default y

config MBEDTLS_ECP_C
default y

config MBEDTLS_PKCS5_C
default y

config MBEDTLS_HKDF_C
default y

config MBEDTLS_CIPHER_CCM_ENABLED
default y

config MBEDTLS_CTR_DRBG_ENABLED
default y

config MBEDTLS_CIPHER_AES_ENABLED
default y

config MBEDTLS_ECDH_C
default y

config MBEDTLS_ECDSA_C
default y

endif #CHIP
12 changes: 12 additions & 0 deletions src/inet/InetConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,16 @@
#define HAVE_SO_BINDTODEVICE 0
#endif

/**
* @def INET_CONFIG_UDP_SOCKET_MREQN
*
* @brief
* Should be set to 1 if your platform can handle struct ip_mreqn,
* mandatory in UDPEndPointSocket.cpp
*/

#ifndef INET_CONFIG_UDP_SOCKET_MREQN
#define INET_CONFIG_UDP_SOCKET_MREQN 0
#endif

// clang-format on
11 changes: 11 additions & 0 deletions src/inet/UDPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,22 @@ CHIP_ERROR UDPEndPointImplSockets::IPv4JoinLeaveMulticastGroupImpl(InterfaceId a
interfaceAddr.s_addr = htonl(INADDR_ANY);
}

#if INET_CONFIG_UDP_SOCKET_MREQN
struct ip_mreqn lMulticastRequest;
memset(&lMulticastRequest, 0, sizeof(lMulticastRequest));
lMulticastRequest.imr_ifindex = aInterfaceId.GetPlatformInterface(); /* Network interface index */
lMulticastRequest.imr_address = interfaceAddr; /* IP address of local interface */
lMulticastRequest.imr_multiaddr = aAddress.ToIPv4(); /* IP multicast group address*/

#else

struct ip_mreq lMulticastRequest;
memset(&lMulticastRequest, 0, sizeof(lMulticastRequest));
lMulticastRequest.imr_interface = interfaceAddr;
lMulticastRequest.imr_multiaddr = aAddress.ToIPv4();

#endif

const int command = join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP;
if (setsockopt(mSocket, IPPROTO_IP, command, &lMulticastRequest, sizeof(lMulticastRequest)) != 0)
{
Expand Down
1 change: 1 addition & 0 deletions src/platform/Zephyr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static_library("Zephyr") {
"ConnectivityManagerImpl.h",
"DiagnosticDataProviderImpl.cpp",
"DiagnosticDataProviderImpl.h",
"DiagnosticDataProviderImplGetter.cpp",
"InetPlatformConfig.h",
"KeyValueStoreManagerImpl.cpp",
"KeyValueStoreManagerImpl.h",
Expand Down
Loading
Loading