From bbc24200b4a320d82205a06f75f3e5eccb787ae6 Mon Sep 17 00:00:00 2001 From: "MOBICAPL\\arty" Date: Thu, 28 Jan 2021 10:19:33 +0100 Subject: [PATCH 01/27] First steps of integration: 1. Add vscode task to build nrf mbed shell example 2. Add mbed shell example directory with basic files 3. Add mbed_example script to build mbed's examples 4. Add mbed directory to config and app.cmake to build GN lib (only copy from nrfconnect example) --- .vscode/tasks.json | 14 ++++++++ config/mbed/app/app.cmake | 39 ++++++++++++++++++++++ examples/shell/mbed/CMakeLists.txt | 37 +++++++++++++++++++++ examples/shell/mbed/main.cpp | 13 ++++++++ examples/shell/mbed/mbed-os.lib | 1 + examples/shell/mbed/mbed_app.json | 7 ++++ scripts/examples/mbed_example.sh | 52 ++++++++++++++++++++++++++++++ 7 files changed, 163 insertions(+) create mode 100644 config/mbed/app/app.cmake create mode 100644 examples/shell/mbed/CMakeLists.txt create mode 100644 examples/shell/mbed/main.cpp create mode 100644 examples/shell/mbed/mbed-os.lib create mode 100644 examples/shell/mbed/mbed_app.json create mode 100644 scripts/examples/mbed_example.sh diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e8d081329152df..e13e4adafa35c9 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -231,6 +231,20 @@ "${workspaceFolder}/examples/pigweed-app/nrfconnect/build" ] } + }, + { + "label": "Build nRF mbed shell Example", + "type": "shell", + "command": "scripts/examples/mbed_example.sh", + "args": ["shell", "NRF52840_DK", "release"], + "group": "build", + "problemMatcher": { + "base": "$gcc", + "fileLocation": [ + "relative", + "${workspaceFolder}/examples/shell/mbed/build" + ] + } } ] } diff --git a/config/mbed/app/app.cmake b/config/mbed/app/app.cmake new file mode 100644 index 00000000000000..1e01e1a468b927 --- /dev/null +++ b/config/mbed/app/app.cmake @@ -0,0 +1,39 @@ +# +# Copyright (c) 2020 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. +# + +# +# @file +# CMake module for incorporating CHIP into an nRF Connect SDK +# application as an out-of-tree Zephyr module. +# + +# Use Device Tree overlay if exists in the application directory + +if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/dts.overlay") + set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/dts.overlay") +endif() + +# Add CHIP to the list of Zephyr modules + +list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_LIST_DIR}/../chip-module) + +# Load NCS/Zephyr build system + +find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) + +# Configure the application + +target_link_libraries(app PUBLIC chip) diff --git a/examples/shell/mbed/CMakeLists.txt b/examples/shell/mbed/CMakeLists.txt new file mode 100644 index 00000000000000..6bbe210f8c1416 --- /dev/null +++ b/examples/shell/mbed/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.19.0) + +get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH) +get_filename_component(APP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/.. REALPATH) + +set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "") +set(MBED_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.mbedbuild CACHE INTERNAL "") +set(APP_TARGET chip-mbed-shell-example) + +#set(CONF_FILE ${CHIP_ROOT}/config/mbed/app/sample-defaults.conf prj.conf) +include(${CHIP_ROOT}/config/mbed/app/app.cmake) + +include(${MBED_PATH}/tools/cmake/app.cmake) + +add_subdirectory(${MBED_PATH}) + +add_executable(${APP_TARGET} + main.cpp +) + +mbed_configure_app_target(${APP_TARGET}) + +mbed_set_mbed_target_linker_script(${APP_TARGET}) + +project(${APP_TARGET}) + +target_link_libraries(${APP_TARGET} mbed-os) + +mbed_set_post_build(${APP_TARGET}) + +option(VERBOSE_BUILD "Have a verbose build process") +if(VERBOSE_BUILD) + set(CMAKE_VERBOSE_MAKEFILE ON) +endif() \ No newline at end of file diff --git a/examples/shell/mbed/main.cpp b/examples/shell/mbed/main.cpp new file mode 100644 index 00000000000000..65077bac6c26f4 --- /dev/null +++ b/examples/shell/mbed/main.cpp @@ -0,0 +1,13 @@ +/* mbed Microcontroller Library + * Copyright (c) 2021 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mbed.h" + + +int main() +{ + printf("Hello, Mbed!\n"); + return 0; +} \ No newline at end of file diff --git a/examples/shell/mbed/mbed-os.lib b/examples/shell/mbed/mbed-os.lib new file mode 100644 index 00000000000000..b1f64f02f1511f --- /dev/null +++ b/examples/shell/mbed/mbed-os.lib @@ -0,0 +1 @@ +https://github.com/ARMmbed/mbed-os#master \ No newline at end of file diff --git a/examples/shell/mbed/mbed_app.json b/examples/shell/mbed/mbed_app.json new file mode 100644 index 00000000000000..42941828199ed5 --- /dev/null +++ b/examples/shell/mbed/mbed_app.json @@ -0,0 +1,7 @@ +{ + "target_overrides": { + "K64F": { + "platform.stdio-baud-rate": 9600 + } + } +} \ No newline at end of file diff --git a/scripts/examples/mbed_example.sh b/scripts/examples/mbed_example.sh new file mode 100644 index 00000000000000..3a2b6f33f26a87 --- /dev/null +++ b/scripts/examples/mbed_example.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2020 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. +# + +cd "$(dirname "$0")/../../examples" + +SUPPORTED_TOOLCHAIN=(GCC_ARM ARM) +SUPPORTED_TARGET_BOARD=(DISCO_L475VG_IOT01A NRF52840_DK) +SUPPORTED_APP=(shell) +SUPPORTED_PROFILES=(release develop debug) + +APP="${1:-shell}" +TARGET_BOARD="${2:-NRF52840_DK}" +TOOLCHAIN="${3:-GCC_ARM}" +PROFILE="${4:-release}" + +if [[ ! " ${SUPPORTED_TARGET_BOARD[@]} " =~ " ${TARGET_BOARD} " ]]; then + echo "ERROR: Target $TARGET_BOARD not supported" + exit 1 +fi + +if [[ ! " ${SUPPORTED_APP[@]} " =~ " ${APP} " ]]; then + echo "ERROR: Application $APP not supported" + exit 1 +fi + +if [[ ! " ${SUPPORTED_TOOLCHAIN[@]} " =~ " ${TOOLCHAIN} " ]]; then + echo "ERROR: Toolchain $TOOLCHAIN not supported" + exit 1 +fi + +if [[ ! " ${SUPPORTED_PROFILES[@]} " =~ " ${PROFILE} " ]]; then + echo "ERROR: Profile $PROFILE not supported" + exit 1 +fi + +echo "Build $APP app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile" +#mbed-tools compile -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP/mbed" --mbed-os-path "$MBED_OS_PATH" -p "$PROFILE" From d45b5b2b1574ffb22c2705ec8c5c6b81e38e6740 Mon Sep 17 00:00:00 2001 From: arty Date: Thu, 28 Jan 2021 18:47:00 +0100 Subject: [PATCH 02/27] Improve mbed_example script arguments parsing Change mbed-os path in CMakeLists Link chip library to mbed example app --- .vscode/tasks.json | 2 +- examples/shell/mbed/CMakeLists.txt | 6 ++-- .../shell/mbed/third_party/connectedhomeip | 1 + scripts/examples/mbed_example.sh | 36 ++++++++++++++++--- 4 files changed, 36 insertions(+), 9 deletions(-) create mode 120000 examples/shell/mbed/third_party/connectedhomeip diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e13e4adafa35c9..d3d064fa8125fe 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -236,7 +236,7 @@ "label": "Build nRF mbed shell Example", "type": "shell", "command": "scripts/examples/mbed_example.sh", - "args": ["shell", "NRF52840_DK", "release"], + "args": ["-a=shell", "-b=NRF52840_DK", "-p=release"], "group": "build", "problemMatcher": { "base": "$gcc", diff --git a/examples/shell/mbed/CMakeLists.txt b/examples/shell/mbed/CMakeLists.txt index 6bbe210f8c1416..ce3dc8dc7d9fe4 100644 --- a/examples/shell/mbed/CMakeLists.txt +++ b/examples/shell/mbed/CMakeLists.txt @@ -6,12 +6,11 @@ cmake_minimum_required(VERSION 3.19.0) get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH) get_filename_component(APP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/.. REALPATH) -set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "") +set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "") set(MBED_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.mbedbuild CACHE INTERNAL "") set(APP_TARGET chip-mbed-shell-example) -#set(CONF_FILE ${CHIP_ROOT}/config/mbed/app/sample-defaults.conf prj.conf) -include(${CHIP_ROOT}/config/mbed/app/app.cmake) +add_subdirectory(${CHIP_ROOT}/config/mbed) include(${MBED_PATH}/tools/cmake/app.cmake) @@ -28,6 +27,7 @@ mbed_set_mbed_target_linker_script(${APP_TARGET}) project(${APP_TARGET}) target_link_libraries(${APP_TARGET} mbed-os) +target_link_libraries(${APP_TARGET} PUBLIC chip) mbed_set_post_build(${APP_TARGET}) diff --git a/examples/shell/mbed/third_party/connectedhomeip b/examples/shell/mbed/third_party/connectedhomeip new file mode 120000 index 00000000000000..c866b86874994d --- /dev/null +++ b/examples/shell/mbed/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../.. \ No newline at end of file diff --git a/scripts/examples/mbed_example.sh b/scripts/examples/mbed_example.sh index 3a2b6f33f26a87..b8193105ddaff8 100644 --- a/scripts/examples/mbed_example.sh +++ b/scripts/examples/mbed_example.sh @@ -23,10 +23,34 @@ SUPPORTED_TARGET_BOARD=(DISCO_L475VG_IOT01A NRF52840_DK) SUPPORTED_APP=(shell) SUPPORTED_PROFILES=(release develop debug) -APP="${1:-shell}" -TARGET_BOARD="${2:-NRF52840_DK}" -TOOLCHAIN="${3:-GCC_ARM}" -PROFILE="${4:-release}" +APP=shell +TARGET_BOARD=NRF52840_DK +TOOLCHAIN=GCC_ARM +PROFILE=release + +for i in "$@"; do + case $i in + -a=* | --app=*) + APP="${i#*=}" + shift + ;; + -b=* | --board=*) + TARGET_BOARD="${i#*=}" + shift + ;; + -t=* | --toolchain=*) + TOOLCHAIN="${i#*=}" + shift + ;; + -p=* | --profile=*) + PROFILE="${i#*=}" + shift + ;; + *) + # unknown option + ;; + esac +done if [[ ! " ${SUPPORTED_TARGET_BOARD[@]} " =~ " ${TARGET_BOARD} " ]]; then echo "ERROR: Target $TARGET_BOARD not supported" @@ -49,4 +73,6 @@ if [[ ! " ${SUPPORTED_PROFILES[@]} " =~ " ${PROFILE} " ]]; then fi echo "Build $APP app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile" -#mbed-tools compile -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP/mbed" --mbed-os-path "$MBED_OS_PATH" -p "$PROFILE" +set -x +pwd +mbed-tools compile -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP/mbed" --mbed-os-path "$MBED_OS_PATH" -b "$PROFILE" From 16cf61517453f740650db262b7a4eb65d30cdd53 Mon Sep 17 00:00:00 2001 From: arty Date: Mon, 1 Feb 2021 14:52:42 +0100 Subject: [PATCH 03/27] Add CHIP GN build directory to mbed config Add CMakeList to mbed config - draft of cmake and gn integration Remove symbolic link from mbed example project directory Improve mbed project CMakeList - set CHIP_ROOT as relative path, correct chip library linking --- config/mbed/CMakeLists.txt | 199 ++++++++++++++++++ config/mbed/app/app.cmake | 39 ---- config/mbed/chip-gn/.gn | 26 +++ config/mbed/chip-gn/BUILD.gn | 38 ++++ config/mbed/chip-gn/args.gni | 26 +++ config/mbed/chip-gn/toolchain/BUILD.gn | 34 +++ examples/shell/mbed/CMakeLists.txt | 10 +- .../shell/mbed/third_party/connectedhomeip | 1 - 8 files changed, 327 insertions(+), 46 deletions(-) create mode 100644 config/mbed/CMakeLists.txt delete mode 100644 config/mbed/app/app.cmake create mode 100644 config/mbed/chip-gn/.gn create mode 100644 config/mbed/chip-gn/BUILD.gn create mode 100644 config/mbed/chip-gn/args.gni create mode 100644 config/mbed/chip-gn/toolchain/BUILD.gn delete mode 120000 examples/shell/mbed/third_party/connectedhomeip diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt new file mode 100644 index 00000000000000..d8c615aa036898 --- /dev/null +++ b/config/mbed/CMakeLists.txt @@ -0,0 +1,199 @@ +# +# Copyright (c) 2020 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. +# + +# +# @file +# CMake sub-project defining 'chip' target which represents CHIP library +# and other optional libraries like unit tests, built with 'mbed' +# platform. +# Since CHIP doesn't provide native CMake support, ExternalProject +# module is used to build the required artifacts with GN meta-build +# system. +# + +include(ExternalProject) + +# ============================================================================== +# Declare configuration variables and define constants +# ============================================================================== + +# C/C++ compiler flags passed to CHIP build system +list(APPEND CHIP_CFLAGS) + +# C compiler flags passed to CHIP build system +list(APPEND CHIP_CFLAGS_C) + +# C++ compiler flags passed to CHIP build system +list(APPEND CHIP_CFLAGS_CC) + +# CHIP libraries that the application should be linked with +list(APPEND CHIP_LIBRARIES) + +# GN meta-build system arguments in the form of 'key1 = value1\nkey2 = value2...' string +string(APPEND CHIP_GN_ARGS) + +# C/C++ compiler flags which should not be forwarded to CHIP +# build system (e.g. because CHIP configures them on its own) +set(CHIP_CFLAG_EXCLUDES + "-fno-asynchronous-unwind-tables" + "-fno-common" + "-fno-defer-pop" + "-fno-reorder-functions" + "-ffunction-sections" + "-fdata-sections" + "-g*" + "-O*" + "-W*" +) + +# ============================================================================== +# Helper macros +# ============================================================================== + +macro(chip_gn_arg_string ARG STRING) + string(APPEND CHIP_GN_ARGS "${ARG} = \"${STRING}\"\n") +endmacro() + +macro(chip_gn_arg_bool ARG BOOLEAN) + if (${BOOLEAN}) + string(APPEND CHIP_GN_ARGS "${ARG} = true\n") + else() + string(APPEND CHIP_GN_ARGS "${ARG} = false\n") + endif() +endmacro() + +macro(chip_gn_arg_cflags ARG CFLAGS) + set(CFLAG_EXCLUDES "[") + foreach(cflag ${CHIP_CFLAG_EXCLUDES}) + string(APPEND CFLAG_EXCLUDES "\"${cflag}\", ") + endforeach() + string(APPEND CFLAG_EXCLUDES "]") + string(APPEND CHIP_GN_ARGS "${ARG} = filter_exclude(string_split(\"${CFLAGS}\"), ${CFLAG_EXCLUDES})\n") +endmacro() + +macro(mbed_interface_library_named name) + add_library(${name} INTERFACE) + set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS ${name}) +endmacro() + +# ============================================================================== +# Prepare CHIP configuration based on the project configuration +# ============================================================================== + +if (NOT CHIP_ROOT) + get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../.. REALPATH) +endif() + +# Prepare compiler flags + +if (CONFIG_ARM) + list(APPEND CHIP_CFLAGS_C + --specs=nosys.specs + ) +endif() + +#convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS CHIP_CFLAGS) +#convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_C CHIP_CFLAGS_C) +#convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_CC CHIP_CFLAGS_CC) + +# Prepare CHIP libraries that the application should be linked with + +if (NOT CHIP_LIBRARIES) + set(CHIP_LIBRARIES -lCHIP) +endif() + +if (CONFIG_CHIP_LIB_SHELL) + list(APPEND CHIP_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/obj/third_party/connectedhomeip/src/lib/shell/lib/libCHIPShell.a) +endif() + +# Set up CHIP project configuration file + +if (CONFIG_CHIP_PROJECT_CONFIG) + get_filename_component(CHIP_PROJECT_CONFIG + ${CONFIG_CHIP_PROJECT_CONFIG} + REALPATH + BASE_DIR ${CMAKE_SOURCE_DIR} + ) + set(CHIP_PROJECT_CONFIG "<${CHIP_PROJECT_CONFIG}>") +else() + set(CHIP_PROJECT_CONFIG "") +endif() + +# ============================================================================== +# Generate configuration for CHIP GN build system +# ============================================================================== + +#chip_gn_arg_cflags("target_cflags" ${CHIP_CFLAGS}) +#chip_gn_arg_cflags("target_cflags_c" ${CHIP_CFLAGS_C}) +#chip_gn_arg_cflags("target_cflags_cc" ${CHIP_CFLAGS_CC}) +chip_gn_arg_string("mbed_ar" ${CMAKE_AR}) +chip_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER}) +chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) +#chip_gn_arg_string("chip_project_config_include" "${CHIP_PROJECT_CONFIG}") +#chip_gn_arg_string("chip_system_project_config_include" "${CHIP_PROJECT_CONFIG}") +#chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) +#chip_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD) +#chip_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4) +#chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) +#chip_gn_arg_bool ("chip_inet_config_enable_raw_endpoint" CONFIG_CHIP_BUILD_TESTS) +#chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) +#chip_gn_arg_bool ("chip_inet_config_enable_dns_resolver" CONFIG_CHIP_BUILD_TESTS) +#chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) + +if (BOARD STREQUAL "native_posix") + chip_gn_arg_string("target_cpu" "x86") +elseif (BOARD STREQUAL "native_posix_64") + chip_gn_arg_string("target_cpu" "x64") +endif() + +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS}) + +# ============================================================================== +# Define 'chip-gn' target that builds CHIP library(ies) with GN build system +# ============================================================================== +ExternalProject_Add( + chip-gn + PREFIX ${CMAKE_CURRENT_BINARY_DIR} + SOURCE_DIR ${CHIP_ROOT} + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} + CONFIGURE_COMMAND gn --root=${CHIP_ROOT}/config/mbed/chip-gn gen --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR} + BUILD_COMMAND ninja + INSTALL_COMMAND "" + BUILD_BYPRODUCTS ${CHIP_LIBRARIES} + BUILD_ALWAYS TRUE + USES_TERMINAL_CONFIGURE TRUE + USES_TERMINAL_BUILD TRUE +) + +# ============================================================================== +# Define 'chip' target that exposes CHIP headers & libraries to the application +# ============================================================================== +mbed_interface_library_named(chip) +target_compile_definitions(chip INTERFACE CHIP_HAVE_CONFIG_H) +target_include_directories(chip INTERFACE + ${CHIP_ROOT}/src + ${CHIP_ROOT}/src/app/server + ${CHIP_ROOT}/src/app/util + ${CHIP_ROOT}/src/include + ${CHIP_ROOT}/src/lib + ${CHIP_ROOT}/src/lib/core + ${CHIP_ROOT}/third_party/nlassert/repo/include + ${CMAKE_CURRENT_BINARY_DIR}/gen/include + ${CMAKE_CURRENT_BINARY_DIR}/gen/third_party/connectedhomeip/src/app/include +) +target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib) +target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group) +add_dependencies(chip chip-gn) diff --git a/config/mbed/app/app.cmake b/config/mbed/app/app.cmake deleted file mode 100644 index 1e01e1a468b927..00000000000000 --- a/config/mbed/app/app.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# -# Copyright (c) 2020 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. -# - -# -# @file -# CMake module for incorporating CHIP into an nRF Connect SDK -# application as an out-of-tree Zephyr module. -# - -# Use Device Tree overlay if exists in the application directory - -if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/dts.overlay") - set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/dts.overlay") -endif() - -# Add CHIP to the list of Zephyr modules - -list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_LIST_DIR}/../chip-module) - -# Load NCS/Zephyr build system - -find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) - -# Configure the application - -target_link_libraries(app PUBLIC chip) diff --git a/config/mbed/chip-gn/.gn b/config/mbed/chip-gn/.gn new file mode 100644 index 00000000000000..963f80dfb05f2e --- /dev/null +++ b/config/mbed/chip-gn/.gn @@ -0,0 +1,26 @@ +# Copyright (c) 2020 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. + +# The location of the build configuration file. +buildconfig = "//build/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + target_cpu = "arm" + target_os = "mbed-os" + + import("//args.gni") +} diff --git a/config/mbed/chip-gn/BUILD.gn b/config/mbed/chip-gn/BUILD.gn new file mode 100644 index 00000000000000..7e06a9ee688600 --- /dev/null +++ b/config/mbed/chip-gn/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2020 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. + +import("//build_overrides/chip.gni") + +import("//${chip_root}/build/chip/tests.gni") + +assert(current_os == "mbed-os") + +declare_args() { + chip_build_libshell = false +} + +group("dummy") { +} + +group("mbed") { + deps = [ "${chip_root}/src/lib" ] + + if (chip_build_libshell) { + deps += [ "${chip_root}/src/lib/shell" ] + } +} + +group("default") { + deps = [ ":mbed" ] +} diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni new file mode 100644 index 00000000000000..06ad3dabe697a9 --- /dev/null +++ b/config/mbed/chip-gn/args.gni @@ -0,0 +1,26 @@ +# Copyright (c) 2020 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. + +import("//build_overrides/chip.gni") + +chip_device_platform = "mbed" + +chip_build_tests = false + +chip_project_config_include = "" +chip_system_project_config_include = "" +chip_ble_project_config_include = "" + +custom_toolchain = "//toolchain:mbed" +mbedtls_target = "//:dummy" diff --git a/config/mbed/chip-gn/toolchain/BUILD.gn b/config/mbed/chip-gn/toolchain/BUILD.gn new file mode 100644 index 00000000000000..c67c41d16c2ec7 --- /dev/null +++ b/config/mbed/chip-gn/toolchain/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2020 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. + +import("//build_overrides/chip.gni") + +import("//build/toolchain/arm_gcc/arm_toolchain.gni") + +declare_args() { + mbed_ar = "" + mbed_cc = "" + mbed_cxx = "" +} + +gcc_toolchain("mbed") { + ar = mbed_ar + cc = mbed_cc + cxx = mbed_cxx + + toolchain_args = { + current_os = "mbed-os" + is_clang = false + } +} diff --git a/examples/shell/mbed/CMakeLists.txt b/examples/shell/mbed/CMakeLists.txt index ce3dc8dc7d9fe4..d2c8ea4bde42cd 100644 --- a/examples/shell/mbed/CMakeLists.txt +++ b/examples/shell/mbed/CMakeLists.txt @@ -3,18 +3,17 @@ cmake_minimum_required(VERSION 3.19.0) -get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH) +get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH) get_filename_component(APP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/.. REALPATH) set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "") set(MBED_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.mbedbuild CACHE INTERNAL "") set(APP_TARGET chip-mbed-shell-example) -add_subdirectory(${CHIP_ROOT}/config/mbed) - include(${MBED_PATH}/tools/cmake/app.cmake) +add_subdirectory(${MBED_PATH} ./mbed_build) -add_subdirectory(${MBED_PATH}) +add_subdirectory(${CHIP_ROOT}/config/mbed ./chip_build) add_executable(${APP_TARGET} main.cpp @@ -26,8 +25,7 @@ mbed_set_mbed_target_linker_script(${APP_TARGET}) project(${APP_TARGET}) -target_link_libraries(${APP_TARGET} mbed-os) -target_link_libraries(${APP_TARGET} PUBLIC chip) +target_link_libraries(${APP_TARGET} mbed-os chip) mbed_set_post_build(${APP_TARGET}) diff --git a/examples/shell/mbed/third_party/connectedhomeip b/examples/shell/mbed/third_party/connectedhomeip deleted file mode 120000 index c866b86874994d..00000000000000 --- a/examples/shell/mbed/third_party/connectedhomeip +++ /dev/null @@ -1 +0,0 @@ -../../../.. \ No newline at end of file From 9600912c398b556aaa99c695aba3e2f3f6ef1d94 Mon Sep 17 00:00:00 2001 From: arty Date: Mon, 1 Feb 2021 16:34:53 +0100 Subject: [PATCH 04/27] Add symbolic links to mbed GN build directory --- config/mbed/chip-gn/build | 1 + config/mbed/chip-gn/build_overrides | 1 + config/mbed/chip-gn/third_party/connectedhomeip | 1 + 3 files changed, 3 insertions(+) create mode 120000 config/mbed/chip-gn/build create mode 120000 config/mbed/chip-gn/build_overrides create mode 120000 config/mbed/chip-gn/third_party/connectedhomeip diff --git a/config/mbed/chip-gn/build b/config/mbed/chip-gn/build new file mode 120000 index 00000000000000..44735d58664596 --- /dev/null +++ b/config/mbed/chip-gn/build @@ -0,0 +1 @@ +../../../build \ No newline at end of file diff --git a/config/mbed/chip-gn/build_overrides b/config/mbed/chip-gn/build_overrides new file mode 120000 index 00000000000000..5140c246d723bf --- /dev/null +++ b/config/mbed/chip-gn/build_overrides @@ -0,0 +1 @@ +../../../examples/build_overrides/ \ No newline at end of file diff --git a/config/mbed/chip-gn/third_party/connectedhomeip b/config/mbed/chip-gn/third_party/connectedhomeip new file mode 120000 index 00000000000000..11a54ed360106c --- /dev/null +++ b/config/mbed/chip-gn/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../ \ No newline at end of file From 0f426a6850b7a42b32aa25a2d355ac8c1ddcc8fa Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 09:12:18 +0000 Subject: [PATCH 05/27] Add mbed platform to chip --- src/platform/BUILD.gn | 5 + src/platform/device.gni | 5 +- src/platform/mbed/BlePlatformConfig.h | 42 ++++++ src/platform/mbed/CHIPDevicePlatformConfig.h | 41 ++++++ src/platform/mbed/CHIPDevicePlatformEvent.h | 88 ++++++++++++ src/platform/mbed/CHIPPlatformConfig.h | 129 ++++++++++++++++++ src/platform/mbed/ConfigurationManagerImpl.h | 115 ++++++++++++++++ src/platform/mbed/ConnectivityManagerImpl.h | 128 +++++++++++++++++ .../DeviceNetworkProvisioningDelegateImpl.h | 43 ++++++ src/platform/mbed/InetPlatformConfig.h | 47 +++++++ src/platform/mbed/PlatformManagerImpl.h | 84 ++++++++++++ src/platform/mbed/SystemPlatformConfig.h | 58 ++++++++ src/platform/mbed/args.gni | 15 ++ 13 files changed, 799 insertions(+), 1 deletion(-) create mode 100644 src/platform/mbed/BlePlatformConfig.h create mode 100644 src/platform/mbed/CHIPDevicePlatformConfig.h create mode 100644 src/platform/mbed/CHIPDevicePlatformEvent.h create mode 100644 src/platform/mbed/CHIPPlatformConfig.h create mode 100644 src/platform/mbed/ConfigurationManagerImpl.h create mode 100644 src/platform/mbed/ConnectivityManagerImpl.h create mode 100644 src/platform/mbed/DeviceNetworkProvisioningDelegateImpl.h create mode 100644 src/platform/mbed/InetPlatformConfig.h create mode 100644 src/platform/mbed/PlatformManagerImpl.h create mode 100644 src/platform/mbed/SystemPlatformConfig.h create mode 100644 src/platform/mbed/args.gni diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index 020e8e974c17d0..1fb34374fb19ff 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -133,6 +133,11 @@ if (chip_device_platform != "none") { "CHIP_DEVICE_LAYER_TARGET_K32W=1", "CHIP_DEVICE_LAYER_TARGET=K32W", ] + } else if (chip_device_platform == "mbed") { + defines += [ + "CHIP_DEVICE_LAYER_TARGET_MBED=1", + "CHIP_DEVICE_LAYER_TARGET=mbed", + ] } } } else { diff --git a/src/platform/device.gni b/src/platform/device.gni index c0639e1f86f586..fd0d36c55ab40c 100644 --- a/src/platform/device.gni +++ b/src/platform/device.gni @@ -65,6 +65,8 @@ if (chip_device_platform == "cc13x2_26x2") { _chip_device_layer = "qpg6100" } else if (chip_device_platform == "k32w") { _chip_device_layer = "K32W" +} else if (chip_device_platform == "mbed") { + _chip_device_layer = "mbed" } if (chip_device_platform != "external") { @@ -103,5 +105,6 @@ assert( chip_device_platform == "esp32" || chip_device_platform == "external" || chip_device_platform == "linux" || chip_device_platform == "nrfconnect" || - chip_device_platform == "k32w" || chip_device_platform == "qpg6100", + chip_device_platform == "k32w" || chip_device_platform == "qpg6100" || + chip_device_platform == "mbed", "Please select a valid value for chip_device_platform") diff --git a/src/platform/mbed/BlePlatformConfig.h b/src/platform/mbed/BlePlatformConfig.h new file mode 100644 index 00000000000000..6ca764231b9593 --- /dev/null +++ b/src/platform/mbed/BlePlatformConfig.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for the CHIP BLE + * Layer on mbed platforms. + * + */ + +#pragma once + +// ==================== Platform Adaptations ==================== + +#define BLE_CONNECTION_OBJECT uint8_t +#define BLE_CONNECTION_UNINITIALIZED ((uint8_t) -1) +#define BLE_MAX_RECEIVE_WINDOW_SIZE 5 + +#define BLE_CONFIG_ERROR_TYPE int32_t +#define BLE_CONFIG_NO_ERROR 0 +#define BLE_CONFIG_ERROR_MIN 6000000 +#define BLE_CONFIG_ERROR_MAX 6000999 +#define _BLE_CONFIG_ERROR(e) (BLE_CONFIG_ERROR_MIN + (e)) + +// ========== Platform-specific Configuration Overrides ========= + +/* none so far */ diff --git a/src/platform/mbed/CHIPDevicePlatformConfig.h b/src/platform/mbed/CHIPDevicePlatformConfig.h new file mode 100644 index 00000000000000..e21613f72c0cc1 --- /dev/null +++ b/src/platform/mbed/CHIPDevicePlatformConfig.h @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2020 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. + */ + +/** + * @file + * Platform-specific configuration overrides for the chip Device Layer + * on mbed platform. + */ + +#pragma once + +// ==================== Platform Adaptations ==================== + +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 + +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0 +#define CHIP_DEVICE_CONFIG_THREAD_FTD 0 + +#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0 + +#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0 + +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY 3 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 4 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 5 diff --git a/src/platform/mbed/CHIPDevicePlatformEvent.h b/src/platform/mbed/CHIPDevicePlatformEvent.h new file mode 100644 index 00000000000000..4a5f85ad105d3e --- /dev/null +++ b/src/platform/mbed/CHIPDevicePlatformEvent.h @@ -0,0 +1,88 @@ +/* + * + * 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. + */ + +/** + * @file + * Defines platform-specific event types and data for the chip + * Device Layer on mbed platforms. + */ + +#pragma once + +#include + +namespace chip { +namespace System { +class PacketBuffer; +} // namespace System +} // namespace chip + +namespace chip { +namespace DeviceLayer { + +namespace DeviceEventType { + +/** + * Enumerates Zephyr platform-specific event types that are visible to the application. + */ +enum PublicPlatformSpecificEventTypes +{ + /* None currently defined */ +}; + +/** + * Enumerates mbed platform-specific event types that are internal to the chip Device Layer. + */ +enum InternalPlatformSpecificEventTypes +{ + +}; + +} // namespace DeviceEventType + +struct BleConnEventType +{ +}; + +struct BleCCCWriteEventType +{ +}; + +struct BleC1WriteEventType +{ +}; + +struct BleC2IndDoneEventType +{ +}; + +/** + * Represents platform-specific event information for Zephyr platforms. + */ +struct ChipDevicePlatformEvent final +{ + union + { + BleConnEventType BleConnEvent; + BleCCCWriteEventType BleCCCWriteEvent; + BleC1WriteEventType BleC1WriteEvent; + BleC2IndDoneEventType BleC2IndDoneEvent; + }; +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/mbed/CHIPPlatformConfig.h b/src/platform/mbed/CHIPPlatformConfig.h new file mode 100644 index 00000000000000..d93d480490bf8a --- /dev/null +++ b/src/platform/mbed/CHIPPlatformConfig.h @@ -0,0 +1,129 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for CHIP on + * mbed platforms. + */ + +#pragma once + +#include + +// ==================== General Platform Adaptations ==================== + +#define CHIP_CONFIG_ERROR_TYPE int32_t +#define CHIP_CONFIG_NO_ERROR 0 +#define CHIP_CONFIG_ERROR_MIN 4000000 +#define CHIP_CONFIG_ERROR_MAX 4000999 + +#define ASN1_CONFIG_ERROR_TYPE int32_t +#define ASN1_CONFIG_NO_ERROR 0 +#define ASN1_CONFIG_ERROR_MIN 5000000 +#define ASN1_CONFIG_ERROR_MAX 5000999 + +#define ChipDie() abort() + +#define CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE uint8_t +#define CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID 1 +#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 2 + +#define CHIP_CONFIG_TIME_ENABLE_CLIENT 1 +#define CHIP_CONFIG_TIME_ENABLE_SERVER 0 + +// ==================== Security Adaptations ==================== + +#define CHIP_CONFIG_USE_OPENSSL_ECC 0 +#define CHIP_CONFIG_USE_MICRO_ECC 0 + +#define CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 1 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0 + +// FIXME: EFR32 set to MBED-TLS (But this is third-party repo in CHIP, not SDK) + +#define CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_AES_IMPLEMENTATION_AESNI 0 +#define CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS 1 +#define CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM 0 + +// FIXME: EFR32 currently set to CHIP (Does this use Entropy.cpp ?) + +#define CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG 1 +#define CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0 + +#define CHIP_CONFIG_ENABLE_PASE_INITIATOR 0 +#define CHIP_CONFIG_ENABLE_PASE_RESPONDER 1 +#define CHIP_CONFIG_ENABLE_CASE_INITIATOR 1 + +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG0 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG1 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG2 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG3 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG4 1 + +#define CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 0 + +#define CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 0 + +// ==================== General Configuration Overrides ==================== + +#ifndef CHIP_CONFIG_MAX_PEER_NODES +#define CHIP_CONFIG_MAX_PEER_NODES 16 +#endif // CHIP_CONFIG_MAX_PEER_NODES + +#ifndef CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS +#define CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 16 +#endif // CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS + +#ifndef CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS +#define CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS 8 +#endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS + +#ifndef CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT +#define CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT 6 +#endif // CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT + +#ifndef CHIP_LOG_FILTERING +#define CHIP_LOG_FILTERING 0 +#endif // CHIP_LOG_FILTERING + +#ifndef CHIP_CONFIG_MAX_INTERFACES +#define CHIP_CONFIG_MAX_INTERFACES 4 +#endif // CHIP_CONFIG_MAX_INTERFACES + +#ifndef CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS +#define CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS 4 +#endif // CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS + +// ==================== Security Configuration Overrides ==================== + +#ifndef CHIP_CONFIG_MAX_APPLICATION_GROUPS +#define CHIP_CONFIG_MAX_APPLICATION_GROUPS 4 +#endif // CHIP_CONFIG_MAX_APPLICATION_GROUPS + +#ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION +#define CHIP_CONFIG_DEBUG_CERT_VALIDATION 0 +#endif // CHIP_CONFIG_DEBUG_CERT_VALIDATION + +#ifndef CHIP_CONFIG_ENABLE_CASE_RESPONDER +#define CHIP_CONFIG_ENABLE_CASE_RESPONDER 1 +#endif // CHIP_CONFIG_ENABLE_CASE_RESPONDER diff --git a/src/platform/mbed/ConfigurationManagerImpl.h b/src/platform/mbed/ConfigurationManagerImpl.h new file mode 100644 index 00000000000000..e6616c8616ed72 --- /dev/null +++ b/src/platform/mbed/ConfigurationManagerImpl.h @@ -0,0 +1,115 @@ +/* + * + * 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. + */ + +/** + * @file + * Provides an implementation of the ConfigurationManager object + * for mbed platforms. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the ConfigurationManager singleton object for the Zephyr platform. + */ +class ConfigurationManagerImpl final : public ConfigurationManager, + public Internal::GenericConfigurationManagerImpl +{ + // Allow the ConfigurationManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class ConfigurationManager; + + // Allow the GenericConfigurationManagerImpl base class to access helper methods and types + // defined on this class. +#ifndef DOXYGEN_SHOULD_SKIP_THIS + friend class Internal::GenericConfigurationManagerImpl; +#endif + +private: + // ===== Members that implement the ConfigurationManager public interface. + + CHIP_ERROR _Init(void); + CHIP_ERROR _GetPrimaryWiFiMACAddress(uint8_t * buf); + bool _CanFactoryReset(void); + void _InitiateFactoryReset(void); + CHIP_ERROR _ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value); + CHIP_ERROR _WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value); + + // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + + // ===== Members for internal use by the following friends. + + friend ConfigurationManager & ConfigurationMgr(void); + friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); + + static ConfigurationManagerImpl sInstance; + + // ===== Private members reserved for use by this class only. + + static void DoFactoryReset(intptr_t arg); +}; + +/** + * Returns the public interface of the ConfigurationManager singleton object. + * + * chip applications should use this to access features of the ConfigurationManager object + * that are common to all platforms. + */ +inline ConfigurationManager & ConfigurationMgr(void) +{ + return ConfigurationManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the ConfigurationManager singleton object. + * + * chip applications can use this to gain access to features of the ConfigurationManager + * that are specific to the nRF Connect SDK platform. + */ +inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) +{ + return ConfigurationManagerImpl::sInstance; +} + +inline bool ConfigurationManagerImpl::_CanFactoryReset() +{ + return true; +} + +inline CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, + uint32_t & value) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +inline CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +inline CHIP_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t * /* buf */) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/mbed/ConnectivityManagerImpl.h b/src/platform/mbed/ConnectivityManagerImpl.h new file mode 100644 index 00000000000000..2ab31062e68d27 --- /dev/null +++ b/src/platform/mbed/ConnectivityManagerImpl.h @@ -0,0 +1,128 @@ +/* + * + * Copyright (c) 2020 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. + */ + +#pragma once + +#include +#include +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include +#else +#include +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#else +#include +#endif +#include + +#include + +namespace chip { +namespace Inet { +class IPAddress; +} // namespace Inet +} // namespace chip + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the ConnectivityManager singleton object for Zephyr platforms. + */ +class ConnectivityManagerImpl final : public ConnectivityManager, + public Internal::GenericConnectivityManagerImpl, +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + public Internal::GenericConnectivityManagerImpl_BLE, +#else + public Internal::GenericConnectivityManagerImpl_NoBLE, +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + public Internal::GenericConnectivityManagerImpl_Thread, +#else + public Internal::GenericConnectivityManagerImpl_NoThread, +#endif + public Internal::GenericConnectivityManagerImpl_NoWiFi +{ + // Allow the ConnectivityManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class ConnectivityManager; + +private: + // ===== Members that implement the ConnectivityManager abstract interface. + + bool _HaveIPv4InternetConnectivity(void); + bool _HaveIPv6InternetConnectivity(void); + bool _HaveServiceConnectivity(void); + CHIP_ERROR _Init(void); + void _OnPlatformEvent(const ChipDeviceEvent * event); + + // ===== Members for internal use by the following friends. + + friend ConnectivityManager & ConnectivityMgr(void); + friend ConnectivityManagerImpl & ConnectivityMgrImpl(void); + + static ConnectivityManagerImpl sInstance; +}; + +inline bool ConnectivityManagerImpl::_HaveIPv4InternetConnectivity(void) +{ + return false; +} + +inline bool ConnectivityManagerImpl::_HaveIPv6InternetConnectivity(void) +{ + return false; +} + +inline bool ConnectivityManagerImpl::_HaveServiceConnectivity(void) +{ + return false; +} + +inline CHIP_ERROR ConnectivityManagerImpl::_Init(void) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) {} + +/** + * Returns the public interface of the ConnectivityManager singleton object. + * + * chip applications should use this to access features of the ConnectivityManager object + * that are common to all platforms. + */ +inline ConnectivityManager & ConnectivityMgr(void) +{ + return ConnectivityManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the ConnectivityManager singleton object. + * + * chip applications can use this to gain access to features of the ConnectivityManager + * that are specific to the ESP32 platform. + */ +inline ConnectivityManagerImpl & ConnectivityMgrImpl(void) +{ + return ConnectivityManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/mbed/DeviceNetworkProvisioningDelegateImpl.h b/src/platform/mbed/DeviceNetworkProvisioningDelegateImpl.h new file mode 100644 index 00000000000000..18905f1b9cb382 --- /dev/null +++ b/src/platform/mbed/DeviceNetworkProvisioningDelegateImpl.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2020 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. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { + +namespace Internal { + +template +class GenericDeviceNetworkProvisioningDelegateImpl; + +} // namespace Internal + +class DeviceNetworkProvisioningDelegateImpl final + : public Internal::GenericDeviceNetworkProvisioningDelegateImpl +{ +private: + friend class GenericDeviceNetworkProvisioningDelegateImpl; + + CHIP_ERROR _ProvisionWiFiNetwork(const char * ssid, const char * passwd) { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR _ProvisionThreadNetwork(DeviceLayer::Internal::DeviceNetworkInfo & threadData) { return CHIP_ERROR_NOT_IMPLEMENTED; } +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/mbed/InetPlatformConfig.h b/src/platform/mbed/InetPlatformConfig.h new file mode 100644 index 00000000000000..64c4c17e09385f --- /dev/null +++ b/src/platform/mbed/InetPlatformConfig.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for the CHIP Inet + * Layer on mbed platforms. + * + */ + +#pragma once + +#include + +// ==================== Platform Adaptations ==================== + +#define INET_CONFIG_ERROR_TYPE int32_t +#define INET_CONFIG_NO_ERROR 0 +#define INET_CONFIG_ERROR_MIN 1000000 +#define INET_CONFIG_ERROR_MAX 1000999 + +// #define INET_CONFIG_ENABLE_IPV4 0 + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef INET_CONFIG_NUM_TCP_ENDPOINTS +#define INET_CONFIG_NUM_TCP_ENDPOINTS 4 +#endif // INET_CONFIG_NUM_TCP_ENDPOINTS + +#ifndef INET_CONFIG_NUM_UDP_ENDPOINTS +#define INET_CONFIG_NUM_UDP_ENDPOINTS 4 +#endif // INET_CONFIG_NUM_UDP_ENDPOINTS diff --git a/src/platform/mbed/PlatformManagerImpl.h b/src/platform/mbed/PlatformManagerImpl.h new file mode 100644 index 00000000000000..d543d3f3999058 --- /dev/null +++ b/src/platform/mbed/PlatformManagerImpl.h @@ -0,0 +1,84 @@ +/* + * + * Copyright (c) 2020 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. + */ + +/** + * @file + * Provides an implementation of the PlatformManager object. + */ + +#pragma once + +#include +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the PlatformManager singleton object for the nRF Connect SDK platforms. + */ +class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl +{ + // Allow the PlatformManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend PlatformManager; + + // Allow the generic implementation base class to call helper methods on + // this class. +#ifndef DOXYGEN_SHOULD_SKIP_THIS + friend Internal::GenericPlatformManagerImpl; +#endif + +public: + // ===== Platform-specific members that may be accessed directly by the application. + + /* none so far */ + +private: + // ===== Methods that implement the PlatformManager abstract interface. + + CHIP_ERROR _InitChipStack(void) { return 0; } + void _LockChipStack() {} + bool _TryLockChipStack() { return true; } + void _UnlockChipStack() {} + void _PostEvent(const ChipDeviceEvent * event) {} + void _RunEventLoop() {} + CHIP_ERROR _StartEventLoopTask() { return 0; } + CHIP_ERROR _StartChipTimer(int64_t durationMS) { return 0; } + CHIP_ERROR _Shutdown() { return 0; } + + // ===== Members for internal use by the following friends. + + friend PlatformManager & PlatformMgr(void); + friend PlatformManagerImpl & PlatformMgrImpl(void); + friend class Internal::BLEManagerImpl; + + static PlatformManagerImpl sInstance; +}; + +/** + * Returns the public interface of the PlatformManager singleton object. + * + * chip applications should use this to access features of the PlatformManager object + * that are common to all platforms. + */ +inline PlatformManager & PlatformMgr(void) +{ + return PlatformManagerImpl::sInstance; +} +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/mbed/SystemPlatformConfig.h b/src/platform/mbed/SystemPlatformConfig.h new file mode 100644 index 00000000000000..17e798b318739a --- /dev/null +++ b/src/platform/mbed/SystemPlatformConfig.h @@ -0,0 +1,58 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for the CHIP System + * Layer on mbed Platforms. + * + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { +struct ChipDeviceEvent; +} // namespace DeviceLayer +} // namespace chip + +// ==================== Platform Adaptations ==================== + +#define CHIP_SYSTEM_CONFIG_POSIX_LOCKING 0 +#define CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING 0 +#define CHIP_SYSTEM_CONFIG_NO_LOCKING 1 +#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 +#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 +#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int +#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * + +#define CHIP_SYSTEM_CONFIG_ERROR_TYPE int32_t +#define CHIP_SYSTEM_CONFIG_NO_ERROR 0 +#define CHIP_SYSTEM_CONFIG_ERROR_MIN 7000000 +#define CHIP_SYSTEM_CONFIG_ERROR_MAX 7000999 +#define _CHIP_SYSTEM_CONFIG_ERROR(e) (CHIP_SYSTEM_CONFIG_ERROR_MIN + (e)) +#define CHIP_SYSTEM_LWIP_ERROR_MIN 3000000 +#define CHIP_SYSTEM_LWIP_ERROR_MAX 3000128 + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef CHIP_SYSTEM_CONFIG_NUM_TIMERS +#define CHIP_SYSTEM_CONFIG_NUM_TIMERS 16 +#endif // CHIP_SYSTEM_CONFIG_NUM_TIMERS diff --git a/src/platform/mbed/args.gni b/src/platform/mbed/args.gni new file mode 100644 index 00000000000000..d5dd553b24930d --- /dev/null +++ b/src/platform/mbed/args.gni @@ -0,0 +1,15 @@ +# Copyright (c) 2020 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. + +chip_device_platform = "mbed" From ef7ec00a14a262a7bfa66f7881113ba6dede9070 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 09:12:56 +0000 Subject: [PATCH 06/27] Add mbed os to mbedtls supported platforms --- src/crypto/crypto.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/crypto.gni b/src/crypto/crypto.gni index 5255ea1cd63038..c55ee4e9df3c39 100644 --- a/src/crypto/crypto.gni +++ b/src/crypto/crypto.gni @@ -19,7 +19,7 @@ declare_args() { if (chip_crypto == "") { if (current_os == "android" || current_os == "freertos" || - current_os == "zephyr") { + current_os == "zephyr" || current_os == "mbed") { chip_crypto = "mbedtls" } else { chip_crypto = "openssl" From 7246e421f3d69e9fa39dc1604a3b81b365d83969 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 09:14:08 +0000 Subject: [PATCH 07/27] Add mbed tls dummy config for mbed os --- config/mbed/chip-gn/mbedtls/mbed_tls_mbed_stub_config.h | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 config/mbed/chip-gn/mbedtls/mbed_tls_mbed_stub_config.h diff --git a/config/mbed/chip-gn/mbedtls/mbed_tls_mbed_stub_config.h b/config/mbed/chip-gn/mbedtls/mbed_tls_mbed_stub_config.h new file mode 100644 index 00000000000000..a9d9da1bbdc3a4 --- /dev/null +++ b/config/mbed/chip-gn/mbedtls/mbed_tls_mbed_stub_config.h @@ -0,0 +1,4 @@ +#pragma once + +#define MBEDTLS_NO_PLATFORM_ENTROPY +#undef MBEDTLS_FS_IO \ No newline at end of file From 11862bede6865845418f9be9a5cff025f2efdfcd Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 09:15:31 +0000 Subject: [PATCH 08/27] Update Mbed configuration --- config/mbed/chip-gn/.gn | 2 +- config/mbed/chip-gn/BUILD.gn | 14 +++++++++++++- config/mbed/chip-gn/args.gni | 10 +++++++++- config/mbed/chip-gn/toolchain/BUILD.gn | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/config/mbed/chip-gn/.gn b/config/mbed/chip-gn/.gn index 963f80dfb05f2e..0ae417efaade6f 100644 --- a/config/mbed/chip-gn/.gn +++ b/config/mbed/chip-gn/.gn @@ -20,7 +20,7 @@ check_system_includes = true default_args = { target_cpu = "arm" - target_os = "mbed-os" + target_os = "mbed" import("//args.gni") } diff --git a/config/mbed/chip-gn/BUILD.gn b/config/mbed/chip-gn/BUILD.gn index 7e06a9ee688600..c67851b089dad6 100644 --- a/config/mbed/chip-gn/BUILD.gn +++ b/config/mbed/chip-gn/BUILD.gn @@ -15,8 +15,10 @@ import("//build_overrides/chip.gni") import("//${chip_root}/build/chip/tests.gni") +import("//build_overrides/mbedtls.gni") +import("${mbedtls_root}/mbedtls.gni") -assert(current_os == "mbed-os") +assert(current_os == "mbed") declare_args() { chip_build_libshell = false @@ -36,3 +38,13 @@ group("mbed") { group("default") { deps = [ ":mbed" ] } + +mbedtls_target("mbedtls") { + include_dirs = [ + "mbedtls" + ] + + defines = [ + "MBEDTLS_CONFIG_FILE=" + ] +} diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni index 06ad3dabe697a9..62d40e8958c652 100644 --- a/config/mbed/chip-gn/args.gni +++ b/config/mbed/chip-gn/args.gni @@ -23,4 +23,12 @@ chip_system_project_config_include = "" chip_ble_project_config_include = "" custom_toolchain = "//toolchain:mbed" -mbedtls_target = "//:dummy" +mbedtls_target = "//:mbedtls" + + +treat_warnings_as_errors = false +chip_system_config_locking="none" +chip_with_lwip=true +chip_system_config_use_lwip=true +chip_system_config_use_sockets=false +chip_device_platform = "mbed" diff --git a/config/mbed/chip-gn/toolchain/BUILD.gn b/config/mbed/chip-gn/toolchain/BUILD.gn index c67c41d16c2ec7..7bb867bd7f713a 100644 --- a/config/mbed/chip-gn/toolchain/BUILD.gn +++ b/config/mbed/chip-gn/toolchain/BUILD.gn @@ -28,7 +28,7 @@ gcc_toolchain("mbed") { cxx = mbed_cxx toolchain_args = { - current_os = "mbed-os" + current_os = "mbed" is_clang = false } } From fbaddaa40bb479090801b53fc621426897abd2c2 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 09:15:54 +0000 Subject: [PATCH 09/27] HACK: define toolchain path in args --- config/mbed/chip-gn/args.gni | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni index 62d40e8958c652..6250c76869a822 100644 --- a/config/mbed/chip-gn/args.gni +++ b/config/mbed/chip-gn/args.gni @@ -32,3 +32,8 @@ chip_with_lwip=true chip_system_config_use_lwip=true chip_system_config_use_sockets=false chip_device_platform = "mbed" + +# TODO: remove +mbed_ar="/opt/ARM-software/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-ar" +mbed_cc="/opt/ARM-software/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc" +mbed_cxx="/opt/ARM-software/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-g++" From 121aa6edb511c699f0ab52d45bbd433a960517eb Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 10:22:05 +0000 Subject: [PATCH 10/27] Enable mbed compilation LWIP This is a temporary implementation until the real integration is made. --- config/mbed/chip-gn/args.gni | 1 + src/lwip/BUILD.gn | 12 +- src/lwip/mbed/arch/cc.h | 124 ++++++ src/lwip/mbed/arch/perf.h | 89 +++++ src/lwip/mbed/arch/sys_arch.h | 89 +++++ src/lwip/mbed/lwipopts.h | 493 ++++++++++++++++++++++++ src/lwip/mbed/sys_arch.c | 695 ++++++++++++++++++++++++++++++++++ 7 files changed, 1501 insertions(+), 2 deletions(-) create mode 100644 src/lwip/mbed/arch/cc.h create mode 100644 src/lwip/mbed/arch/perf.h create mode 100644 src/lwip/mbed/arch/sys_arch.h create mode 100644 src/lwip/mbed/lwipopts.h create mode 100644 src/lwip/mbed/sys_arch.c diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni index 6250c76869a822..426cca288fe8ae 100644 --- a/config/mbed/chip-gn/args.gni +++ b/config/mbed/chip-gn/args.gni @@ -30,6 +30,7 @@ treat_warnings_as_errors = false chip_system_config_locking="none" chip_with_lwip=true chip_system_config_use_lwip=true +lwip_platform = "mbed" chip_system_config_use_sockets=false chip_device_platform = "mbed" diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index 94aedd20b5fb55..d22bcf4f79da8a 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -30,7 +30,8 @@ if (lwip_platform == "") { assert(lwip_platform == "external" || lwip_platform == "standalone" || lwip_platform == "cc13x2_26x2" || lwip_platform == "efr32" || - lwip_platform == "k32w" || lwip_platform == "qpg6100", + lwip_platform == "k32w" || lwip_platform == "qpg6100" || + lwip_platform == "mbed", "Unsupported lwIP platform: ${lwip_platform}") if (lwip_platform != "external") { @@ -64,6 +65,10 @@ buildconfig_header("lwip_buildconfig") { if (current_os == "android") { defines += [ "LWIP_NO_STDINT_H=1" ] } + + if (lwip_platform == "mbed") { + defines += [ "LWIP_NO_STDINT_H=1", "IN_ADDR_T_DEFINED=1" ] + } } } @@ -82,7 +87,7 @@ if (current_os == "zephyr") { config("lwip_config") { include_dirs = [ lwip_platform ] - if (lwip_platform != "standalone") { + if (lwip_platform != "standalone" && lwip_platform != "mbed") { include_dirs += [ "freertos" ] } } @@ -99,6 +104,9 @@ if (current_os == "zephyr") { if (lwip_platform == "standalone") { public += [ "standalone/arch/sys_arch.h" ] sources += [ "standalone/sys_arch.c" ] + } else if (lwip_platform == "mbed") { + public += [ "mbed/arch/sys_arch.h" ] + sources += [ "mbed/sys_arch.c" ] } else { public += [ "${lwip_platform}/lwippools.h", diff --git a/src/lwip/mbed/arch/cc.h b/src/lwip/mbed/arch/cc.h new file mode 100644 index 00000000000000..350c01fbb39b7e --- /dev/null +++ b/src/lwip/mbed/arch/cc.h @@ -0,0 +1,124 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2014-2017 Nest Labs, Inc. + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * 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. + */ + +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef __ARCH_CC_H__ +#define __ARCH_CC_H__ + +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif + +/* Include some files for defining library routines */ +#include +#include +#include +#include + +#define LWIP_TIMEVAL_PRIVATE 0 + +/* Define platform endianness */ +#ifndef BYTE_ORDER +#define BYTE_ORDER LITTLE_ENDIAN +#endif /* BYTE_ORDER */ + +/* Define generic types used in lwIP */ +typedef unsigned char u8_t; +typedef signed char s8_t; +typedef unsigned short u16_t; +typedef signed short s16_t; +typedef unsigned int u32_t; +typedef signed int s32_t; + +typedef uintptr_t mem_ptr_t; + +/* Define (sn)printf formatters for these lwIP types */ +#define X8_F "02x" +#define U16_F "hu" +#define S16_F "hd" +#define X16_F "hx" +#define U32_F "u" +#define S32_F "d" +#define X32_F "x" + +/* If only we could use C99 and get %zu */ +#if defined(__x86_64__) +#define SZT_F "lu" +#else +#define SZT_F "u" +#endif + +/* Compiler hints for packing structures */ +#define PACK_STRUCT_FIELD(x) x +#define PACK_STRUCT_STRUCT __attribute__((packed)) +#define PACK_STRUCT_BEGIN +#define PACK_STRUCT_END + +/* prototypes for printf() and abort() */ +#include +#include +/* Plaform specific diagnostic output */ +#define LWIP_PLATFORM_DIAG(x) \ + do \ + { \ + printf x; \ + } while (0) + +#define LWIP_PLATFORM_ASSERT(x) \ + do \ + { \ + printf("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__); \ + fflush(NULL); \ + abort(); \ + } while (0) + +#define LWIP_RAND() ((u32_t) rand()) + +#endif /* __ARCH_CC_H__ */ diff --git a/src/lwip/mbed/arch/perf.h b/src/lwip/mbed/arch/perf.h new file mode 100644 index 00000000000000..11279c07fac627 --- /dev/null +++ b/src/lwip/mbed/arch/perf.h @@ -0,0 +1,89 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2014-2017 Nest Labs, Inc. + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * 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. + */ + +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef __ARCH_PERF_H__ +#define __ARCH_PERF_H__ + +#include + +#ifdef PERF +#define PERF_START \ + { \ + unsigned long __c1l, __c1h, __c2l, __c2h; \ + __asm__(".byte 0x0f, 0x31" : "=a"(__c1l), "=d"(__c1h)) +#define PERF_STOP(x) \ + __asm__(".byte 0x0f, 0x31" : "=a"(__c2l), "=d"(__c2h)); \ + perf_print(__c1l, __c1h, __c2l, __c2h, x); \ + } + +/*#define PERF_START do { \ + struct tms __perf_start, __perf_end; \ + times(&__perf_start) +#define PERF_STOP(x) times(&__perf_end); \ + perf_print_times(&__perf_start, &__perf_end, x);\ + } while(0)*/ +#else /* PERF */ +#define PERF_START /* null definition */ +#define PERF_STOP(x) /* null definition */ +#endif /* PERF */ + +void perf_print(unsigned long c1l, unsigned long c1h, unsigned long c2l, unsigned long c2h, char * key); + +void perf_print_times(struct tms * start, struct tms * end, char * key); + +void perf_init(char * fname); + +#define sys_profile_interval_set_pbuf_highwatermark(x, y) +#define sys_profile_pbuf_allocate(pbuf) +#define sys_profile_pbuf_free(pbuf) +#define sys_profile_pbuf_transfer(x, y) + +#endif /* __ARCH_PERF_H__ */ diff --git a/src/lwip/mbed/arch/sys_arch.h b/src/lwip/mbed/arch/sys_arch.h new file mode 100644 index 00000000000000..77488b26e786c4 --- /dev/null +++ b/src/lwip/mbed/arch/sys_arch.h @@ -0,0 +1,89 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2014-2017 Nest Labs, Inc. + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * 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. + */ + +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef __ARCH_SYS_ARCH_H__ +#define __ARCH_SYS_ARCH_H__ + +#include + +#define SYS_MBOX_NULL NULL +#define SYS_SEM_NULL NULL + +typedef u32_t sys_prot_t; + +struct sys_sem; +typedef struct sys_sem * sys_sem_t; +#define sys_sem_valid(sem) (((sem) != NULL) && (*(sem) != NULL)) +#define sys_sem_set_invalid(sem) \ + do \ + { \ + if ((sem) != NULL) \ + { \ + *(sem) = NULL; \ + } \ + } while (0) + +struct sys_mbox; +typedef struct sys_mbox * sys_mbox_t; +#define sys_mbox_valid(mbox) (((mbox) != NULL) && (*(mbox) != NULL)) +#define sys_mbox_set_invalid(mbox) \ + do \ + { \ + if ((mbox) != NULL) \ + { \ + *(mbox) = NULL; \ + } \ + } while (0) + +struct sys_thread; +typedef struct sys_thread * sys_thread_t; + +#endif /* __ARCH_SYS_ARCH_H__ */ diff --git a/src/lwip/mbed/lwipopts.h b/src/lwip/mbed/lwipopts.h new file mode 100644 index 00000000000000..c3243adbc1d01a --- /dev/null +++ b/src/lwip/mbed/lwipopts.h @@ -0,0 +1,493 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * Copyright (c) 2014-2018 Nest Labs, Inc. + * All rights reserved. + * + * 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. + */ + +/** + * @file + * This file describes compile-time constants for configuring LwIP + * for use in standalone (desktop) environments. + * + */ + +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +#if CHIP_HAVE_CONFIG_H +#include +#endif + +#include + +/** + * NO_SYS==1: Provides VERY minimal functionality. Otherwise, + * use lwIP facilities. + */ +#define NO_SYS 0 + +/** + * MEM_ALIGNMENT: should be set to the alignment of the CPU + * 4 byte alignment -> #define MEM_ALIGNMENT 4 + * 2 byte alignment -> #define MEM_ALIGNMENT 2 + */ +#define MEM_ALIGNMENT (4) + +/** + * MEM_SIZE: specify bigger memory size to pass LwIP-internal unit tests + * (only needed when building tests) + */ +#ifdef CHIP_WITH_TESTS +#define MEM_SIZE (16000) +#endif + +/** + * Use Malloc from LibC - saves code space + */ +#define MEM_LIBC_MALLOC (0) + +/** + * Do not use memory pools to create fixed, statically allocated pools of + * memory in lieu of the Standard C Library heap and APIs. + */ +#define MEM_USE_POOLS (0) + +/** + * Do not use custom memory pools for specific, named LwIP objects, sourced + * from lwippools.h. + */ +#define MEM_USE_CUSTOM_POOLS (MEM_USE_POOLS) + +/** + * MEMP_NUM_NETBUF: the number of struct netbufs. + * (only needed if you use the sequential API, like api_lib.c) + */ +#define MEMP_NUM_NETBUF (PBUF_POOL_SIZE) + +/** + * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. + * (requires the LWIP_TCP option) + */ +#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) + +/** + * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. + * + * This is just a default designed to be overriden by the FreeRTOS.mk makefile + * To perform this override, define the makefile variable LWIP_NUM_PACKET_BUFFERS_IN_POOL + */ +#ifndef PBUF_POOL_SIZE +#define PBUF_POOL_SIZE (10) +#endif + +/* + * IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled. + * Since the received pbufs are enqueued, be sure to configure + * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive + * packets even if the maximum amount of fragments is enqueued for reassembly! + * + */ +#if PBUF_POOL_SIZE > 2 +#ifndef IP_REASS_MAX_PBUFS +#define IP_REASS_MAX_PBUFS (PBUF_POOL_SIZE - 2) +#endif +#else +#define IP_REASS_MAX_PBUFS 0 +#define IP_REASSEMBLY 0 +#endif + +/** + * MEMP_NUM_REASSDATA: the number of IP packets simultaneously queued for + * reassembly (whole packets, not fragments!) + */ +#if IP_REASS_MAX_PBUFS > 1 +#ifndef MEMP_NUM_REASSDATA +#define MEMP_NUM_REASSDATA (IP_REASS_MAX_PBUFS - 1) +#endif +#else +#define MEMP_NUM_REASSDATA 0 +#endif + +#define PAYLOAD_MTU (1500) + +/** + * TCP_MSS: TCP Maximum segment size. (default is 536, a conservative default, + * you might want to increase this.) + * For the receive side, this MSS is advertised to the remote side + * when opening a connection. For the transmit size, this MSS sets + * an upper limit on the MSS advertised by the remote host. + */ +#define TCP_MSS (1152) + +/** + * PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is + * designed to accomodate single full size link-layer frame in one pbuf, including + * the link-layer header and any link-layer encapsulation header, and the pbuf + * structure itself. + */ + +#define PBUF_POOL_BUFSIZE \ + LWIP_MEM_ALIGN_SIZE(PAYLOAD_MTU + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN) + LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf) + 1) + +/** + * TCP_SND_BUF: TCP sender buffer space (bytes). + * must be at least as much as (2 * TCP_MSS) for things to work smoothly + */ +#define TCP_SND_BUF (6 * TCP_MSS) + +/** + * ETH_PAD_SIZE: the header space required preceeding the of each pbuf in the pbuf pool. The default is + * designed to accomodate single full size TCP frame in one pbuf, including + * TCP_MSS, IP header, and link header. + * + * This is zero since the role has been taken over by SUB_ETHERNET_HEADER_SPACE as ETH_PAD_SIZE was not always obeyed + */ +#define ETH_PAD_SIZE (0) + +/** + * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data + * to be sent into one single pbuf. This is for compatibility with DMA-enabled + * MACs that do not support scatter-gather. + * Beware that this might involve CPU-memcpy before transmitting that would not + * be needed without this flag! Use this only if you need to! + * + * @todo: TCP and IP-frag do not work with this, yet: + */ +#define LWIP_NETIF_TX_SINGLE_PBUF (0) + +/** Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores + * should be used instead + */ +#define LWIP_COMPAT_MUTEX (1) + +/** Define LWIP_COMPAT_MUTEX_ALLOWED if the platform concurrency model has no + * support for avoiding priority inversion deadlocks + */ +#define LWIP_COMPAT_MUTEX_ALLOWED (1) + +/** + * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain + * critical regions during buffer allocation, deallocation and memory + * allocation and deallocation. + */ +#define SYS_LIGHTWEIGHT_PROT (0) + +/** + * TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread. + * The stack size value itself is platform-dependent, but is passed to + * sys_thread_new() when the thread is created. + */ +#define TCPIP_THREAD_STACKSIZE (1300) + +/** + * TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread. + * The priority value itself is platform-dependent, but is passed to + * sys_thread_new() when the thread is created. + */ +#define TCPIP_THREAD_PRIO (7) + +#define TCP_LISTEN_BACKLOG (1) + +/** + * LWIP_DHCP==1: Enable DHCP module. + */ +#define LWIP_DHCP (1) + +/** + * Enable automatic IPv4 link-local address assignment. + */ +#define LWIP_AUTOIP 1 + +/** + * Allow DHCP and automatic IPv4 link-local address assignment to + * work cooperatively. + */ +#define LWIP_DHCP_AUTOIP_COOP 1 + +/** + * LWIP_PROVIDE_ERRNO: errno definitions from the Standard C Library. + */ +#undef LWIP_PROVIDE_ERRNO + +/** + * ERRNO: set errno on interface invocation failures + */ +#define ERRNO (1) + +/** + * MEMP_NUM_RAW_PCB: Number of raw connection PCBs + * (requires the LWIP_RAW option) + */ +#ifndef MEMP_NUM_RAW_PCB +#define MEMP_NUM_RAW_PCB (5) +#endif + +/** + * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One + * per active UDP "connection". + * (requires the LWIP_UDP option) + */ +#ifndef MEMP_NUM_UDP_PCB +#define MEMP_NUM_UDP_PCB (6) +#endif + +/** + * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. + * (requires NO_SYS==0) + * Must be larger than or equal to LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + + * PPP_SUPPORT Since each InetTimer requires one matching LwIP timeout (if built with LwIP option), the number should be expanded to + * be (All LwIP needs) + (max number of InetTimers) + */ +#define MEMP_NUM_SYS_TIMEOUT (48) + +/* ARP before DHCP causes multi-second delay - turn it off */ +#define DHCP_DOES_ARP_CHECK (0) + +/** + * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c + */ +#define LWIP_HAVE_LOOPIF (1) + +/** + * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP + * address equal to the netif IP address, looping them back up the stack. + */ +#define LWIP_NETIF_LOOPBACK (0) + +/** + * MEMP_NUM_NETCONN: the number of struct netconns. + * (only needed if you use the sequential API, like api_lib.c) + */ +#define MEMP_NUM_NETCONN (8) + +/** + * LWIP_SO_RCVTIMEO==1: Enable SO_RCVTIMEO processing. + */ +#define LWIP_SO_RCVTIMEO (1) + +/** + * LWIP_IGMP==1: Turn on IGMP module. + */ +#define LWIP_IGMP (1) + +/** + * SO_REUSE==1: Enable SO_REUSEADDR option. + * Required by IGMP for reuse of multicast address and port by other sockets + */ +#define SO_REUSE (1) + +/** + * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS + * transport. + */ +#define LWIP_DNS (1) + +/** + * LWIP_POSIX_SOCKETS_IO_NAMES==1: Enable POSIX-style sockets functions names. + * Disable this option if you use a POSIX operating system that uses the same + * names (read, write & close). (only used if you use sockets.c) + * + * We disable this because this otherwise collides with the Standard C + * Library where both LWIP and its headers are included. + */ +#define LWIP_POSIX_SOCKETS_IO_NAMES (0) + +#ifdef LWIP_SO_RCVBUF +#if (LWIP_SO_RCVBUF == 1) +#include /* Needed because RECV_BUFSIZE_DEFAULT is defined as INT_MAX */ +#endif /* if ( LWIP_SO_RCVBUF == 1 ) */ +#endif /* ifdef LWIP_SO_RCVBUF */ + +/** + * LWIP_STATS : Turn on statistics gathering + */ +#define LWIP_STATS (1) + +/** + * LWIP_IPV6==1: Enable IPv6 + */ +#ifndef LWIP_IPV6 +#define LWIP_IPV6 1 +#endif + +/** + * LWIP_IPV6_DHCP6==1: enable DHCPv6 stateful address autoconfiguration. + */ +#ifndef LWIP_IPV6_DHCP6 +#define LWIP_IPV6_DHCP6 1 +#endif + +/** + * LWIP_IPV6_MLD==1: Enable multicast listener discovery protocol. + */ +#ifndef LWIP_IPV6_MLD +#define LWIP_IPV6_MLD 1 +#endif + +/** + * MEMP_NUM_MLD6_GROUP: Maximum number of IPv6 multicast groups that + * can be joined. Allocate one (1) for the link local address + * solicited node multicast group, one (1) for the any/unspecified + * address solicited node multicast group (which seems to be used + * for/by DAD in this epoch of LwIP), and another four (4) for + * application groups. + */ +#define MEMP_NUM_MLD6_GROUP ((1 + 1) + 4) + +/** + * LWIP_IPV6_FORWARD==1: Enable IPv6 forwarding. + */ +#ifndef LWIP_IPV6_FORWARD +#define LWIP_IPV6_FORWARD 1 +#endif + +/** + * LWIP_IPV6_ROUTE_TABLE_SUPPORT==1: Enable support for a routing table and refering these during forwarding. + */ +#ifndef LWIP_IPV6_ROUTE_TABLE_SUPPORT +#define LWIP_IPV6_ROUTE_TABLE_SUPPORT 1 +#endif + +/** + * IPV6_FRAG_COPYHEADER==1: Enable copying of IPv6 fragment headers on 64-bit platforms. + */ +#ifndef IPV6_FRAG_COPYHEADER +#if defined(__x86_64__) +#define IPV6_FRAG_COPYHEADER 1 +#else +#define IPV6_FRAG_COPYHEADER 0 +#endif +#endif + +/** + * Debug printing + * By default enable debug printing for debug build, but set level to off + * This allows user to change any desired debug level to on. + */ +#ifdef LWIP_DEBUG + +#define MEMP_OVERFLOW_CHECK (1) +#define MEMP_SANITY_CHECK (1) + +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_ON +#define API_LIB_DEBUG LWIP_DBG_ON +#define API_MSG_DEBUG LWIP_DBG_ON +#define TCPIP_DEBUG LWIP_DBG_ON +#define NETIF_DEBUG LWIP_DBG_ON +#define SOCKETS_DEBUG LWIP_DBG_ON +#define DEMO_DEBUG LWIP_DBG_ON +#define IP_DEBUG LWIP_DBG_ON +#define IP6_DEBUG LWIP_DBG_ON +#define IP_REASS_DEBUG LWIP_DBG_ON +#define RAW_DEBUG LWIP_DBG_ON +#define ICMP_DEBUG LWIP_DBG_ON +#define UDP_DEBUG LWIP_DBG_ON +#define TCP_DEBUG LWIP_DBG_ON +#define TCP_INPUT_DEBUG LWIP_DBG_ON +#define TCP_OUTPUT_DEBUG LWIP_DBG_ON +#define TCP_RTO_DEBUG LWIP_DBG_ON +#define TCP_CWND_DEBUG LWIP_DBG_ON +#define TCP_WND_DEBUG LWIP_DBG_ON +#define TCP_FR_DEBUG LWIP_DBG_ON +#define TCP_QLEN_DEBUG LWIP_DBG_ON +#define TCP_RST_DEBUG LWIP_DBG_ON +#define PPP_DEBUG LWIP_DBG_OFF + +extern unsigned char gLwIP_DebugFlags; +#define LWIP_DBG_TYPES_ON gLwIP_DebugFlags + +#endif + +/** + * The WICED definition of PBUF_POOL_BUFSIZE includes a number of + * sizeof() instantiations which causes the C preprocessor to + * fail. Disable TCP configuration constant sanity checks to work + * around this. + */ +#define LWIP_DISABLE_TCP_SANITY_CHECKS (1) + +/** + * LwIP defaults the size of most mailboxes (i.e. message queues) to + * zero (0). That generally makes RTOSes such as FreeRTOS very + * unhappy. Specify reasonable defaults instead. + */ +#define TCPIP_MBOX_SIZE 6 + +#define DEFAULT_RAW_RECVMBOX_SIZE 6 + +#define DEFAULT_UDP_RECVMBOX_SIZE 6 + +#define DEFAULT_TCP_RECVMBOX_SIZE 6 + +/* + --------------------------------- + ---------- RAW options ---------- + --------------------------------- +*/ + +/** + * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. + */ +#define LWIP_RAW 1 + +/* + ---------------------------------------------- + ---------- Sequential layer options ---------- + ---------------------------------------------- +*/ + +/** + * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) + */ +#define LWIP_NETCONN 0 + +/* + ------------------------------------ + ---------- Socket options ---------- + ------------------------------------ +*/ + +/** + * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) + */ +#define LWIP_SOCKET 0 + +/** + * Enable locking in the lwip (tcpip) thread. + */ +#ifndef LWIP_TCPIP_CORE_LOCKING +#define LWIP_TCPIP_CORE_LOCKING 1 +#endif + +/** + * Enable support for TCP keepalives. + */ +#ifndef LWIP_TCP_KEEPALIVE +#define LWIP_TCP_KEEPALIVE 1 +#endif + +/** LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS: + * Ensure compatibilty with platforms where LwIP is configured not to define the host/network byte-order conversion + * functions normally provided in on POSIX systems. + */ +#ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS 1 +#endif + +#endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/mbed/sys_arch.c b/src/lwip/mbed/sys_arch.c new file mode 100644 index 00000000000000..3f8807b1da4884 --- /dev/null +++ b/src/lwip/mbed/sys_arch.c @@ -0,0 +1,695 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2014-2017 Nest Labs, Inc. + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * 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. + */ + +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +/* + * Wed Apr 17 16:05:29 EDT 2002 (James Roth) + * + * - Fixed an unlikely sys_thread_new() race condition. + * + * - Made current_thread() work with threads which where + * not created with sys_thread_new(). This includes + * the main thread and threads made with pthread_create(). + * + * - Catch overflows where more than SYS_MBOX_SIZE messages + * are waiting to be read. The sys_mbox_post() routine + * will block until there is more room instead of just + * leaking messages. + */ +#include "lwip/debug.h" + +#include +#include +#include +#include + + +#include "lwip/opt.h" +#include "lwip/stats.h" +#include "lwip/sys.h" + +#define UMAX(a, b) ((a) > (b) ? (a) : (b)) + +static struct timeval starttime; + +#define NO_SYS 1 + +#if !NO_SYS + +static struct sys_thread * threads = NULL; +static pthread_mutex_t threads_mutex = PTHREAD_MUTEX_INITIALIZER; + +struct sys_mbox_msg +{ + struct sys_mbox_msg * next; + void * msg; +}; + +#define SYS_MBOX_SIZE 128 + +struct sys_mbox +{ + int first, last; + void * msgs[SYS_MBOX_SIZE]; + struct sys_sem * not_empty; + struct sys_sem * not_full; + struct sys_sem * mutex; + int wait_send; +}; + +struct sys_sem +{ + unsigned int c; + pthread_cond_t cond; + pthread_mutex_t mutex; +}; + +struct sys_thread +{ + struct sys_thread * next; + pthread_t pthread; +}; + +#if SYS_LIGHTWEIGHT_PROT +static pthread_mutex_t lwprot_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_t lwprot_thread = (pthread_t) 0xDEAD; +static int lwprot_count = 0; +#endif /* SYS_LIGHTWEIGHT_PROT */ + +static struct sys_sem * sys_sem_new_internal(u8_t count); +static void sys_sem_free_internal(struct sys_sem * sem); + +static u32_t cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex, u32_t timeout); + +/*-----------------------------------------------------------------------------------*/ +static struct sys_thread * introduce_thread(pthread_t id) +{ + struct sys_thread * thread; + + thread = (struct sys_thread *) CHIPPlatformMemoryAlloc(sizeof(struct sys_thread)); + + if (thread != NULL) + { + pthread_mutex_lock(&threads_mutex); + thread->next = threads; + thread->pthread = id; + threads = thread; + pthread_mutex_unlock(&threads_mutex); + } + + return thread; +} +/*-----------------------------------------------------------------------------------*/ +static void finish_thread(struct sys_thread * thread) +{ + struct sys_thread * cursor; + struct sys_thread * previous; + + if (thread != NULL) + { + pthread_mutex_lock(&threads_mutex); + + previous = NULL; + cursor = threads; + while (cursor != NULL) + { + if (cursor == thread) + { + if (previous != NULL) + { + previous->next = cursor->next; + } + else + { + threads = cursor->next; + } + cursor->next = NULL; + cursor->pthread = 0; + break; + } + previous = cursor; + cursor = cursor->next; + } + + pthread_mutex_unlock(&threads_mutex); + CHIPPlatformMemoryFree(thread); + } +} +/*-----------------------------------------------------------------------------------*/ +sys_thread_t sys_thread_new(const char * name, lwip_thread_fn function, void * arg, int stacksize, int prio) +{ + int code; + pthread_t tmp; + struct sys_thread * st = NULL; + LWIP_UNUSED_ARG(name); + LWIP_UNUSED_ARG(stacksize); + LWIP_UNUSED_ARG(prio); + + code = pthread_create(&tmp, NULL, (void * (*) (void *) ) function, arg); + + if (0 == code) + { + st = introduce_thread(tmp); + } + + if (NULL == st) + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_create %d, st = 0x%lx", code, (unsigned long) st)); + abort(); + } + return st; +} +/*-----------------------------------------------------------------------------------*/ +err_t sys_thread_finish(sys_thread_t t) +{ + int code; + + code = pthread_join(t->pthread, NULL); + if (0 == code) + { + finish_thread(t); + return ERR_OK; + } + + return ERR_VAL; +} +/*-----------------------------------------------------------------------------------*/ +err_t sys_mbox_new_extra(void * pool, struct sys_mbox ** mb, int size) +{ + return sys_mbox_new(mb, size); +} + +err_t sys_mbox_new(struct sys_mbox ** mb, int size) +{ + struct sys_mbox * mbox; + LWIP_UNUSED_ARG(size); + + mbox = (struct sys_mbox *) CHIPPlatformMemoryAlloc(sizeof(struct sys_mbox)); + if (mbox == NULL) + { + return ERR_MEM; + } + mbox->first = mbox->last = 0; + mbox->not_empty = sys_sem_new_internal(0); + mbox->not_full = sys_sem_new_internal(0); + mbox->mutex = sys_sem_new_internal(1); + mbox->wait_send = 0; + + SYS_STATS_INC_USED(mbox); + *mb = mbox; + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +void sys_mbox_free(struct sys_mbox ** mb) +{ + if ((mb != NULL) && (*mb != SYS_MBOX_NULL)) + { + struct sys_mbox * mbox = *mb; + SYS_STATS_DEC(mbox.used); + sys_arch_sem_wait(&mbox->mutex, 0); + + sys_sem_free_internal(mbox->not_empty); + sys_sem_free_internal(mbox->not_full); + sys_sem_free_internal(mbox->mutex); + mbox->not_empty = mbox->not_full = mbox->mutex = NULL; + /* LWIP_DEBUGF("sys_mbox_free: mbox 0x%lx\n", mbox); */ + CHIPPlatformMemoryFree(mbox); + } +} +/*-----------------------------------------------------------------------------------*/ +err_t sys_mbox_trypost(struct sys_mbox ** mb, void * msg) +{ + u8_t first; + struct sys_mbox * mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; + + sys_arch_sem_wait(&mbox->mutex, 0); + + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_trypost: mbox %p msg %p\n", (void *) mbox, (void *) msg)); + + if ((mbox->last + 1) >= (mbox->first + SYS_MBOX_SIZE)) + { + sys_sem_signal(&mbox->mutex); + return ERR_MEM; + } + + mbox->msgs[mbox->last % SYS_MBOX_SIZE] = msg; + + if (mbox->last == mbox->first) + { + first = 1; + } + else + { + first = 0; + } + + mbox->last++; + + if (first) + { + sys_sem_signal(&mbox->not_empty); + } + + sys_sem_signal(&mbox->mutex); + + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +void sys_mbox_post(struct sys_mbox ** mb, void * msg) +{ + u8_t first; + struct sys_mbox * mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; + + sys_arch_sem_wait(&mbox->mutex, 0); + + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox %p msg %p\n", (void *) mbox, (void *) msg)); + + while ((mbox->last + 1) >= (mbox->first + SYS_MBOX_SIZE)) + { + mbox->wait_send++; + sys_sem_signal(&mbox->mutex); + sys_arch_sem_wait(&mbox->not_full, 0); + sys_arch_sem_wait(&mbox->mutex, 0); + mbox->wait_send--; + } + + mbox->msgs[mbox->last % SYS_MBOX_SIZE] = msg; + + if (mbox->last == mbox->first) + { + first = 1; + } + else + { + first = 0; + } + + mbox->last++; + + if (first) + { + sys_sem_signal(&mbox->not_empty); + } + + sys_sem_signal(&mbox->mutex); +} +/*-----------------------------------------------------------------------------------*/ +u32_t sys_arch_mbox_tryfetch(struct sys_mbox ** mb, void ** msg) +{ + struct sys_mbox * mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; + + sys_arch_sem_wait(&mbox->mutex, 0); + + if (mbox->first == mbox->last) + { + sys_sem_signal(&mbox->mutex); + return SYS_MBOX_EMPTY; + } + + if (msg != NULL) + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p msg %p\n", (void *) mbox, *msg)); + *msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE]; + } + else + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p, null msg\n", (void *) mbox)); + } + + mbox->first++; + + if (mbox->wait_send) + { + sys_sem_signal(&mbox->not_full); + } + + sys_sem_signal(&mbox->mutex); + + return 0; +} +/*-----------------------------------------------------------------------------------*/ +u32_t sys_arch_mbox_fetch(struct sys_mbox ** mb, void ** msg, u32_t timeout) +{ + u32_t time_needed = 0; + struct sys_mbox * mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; + + /* The mutex lock is quick so we don't bother with the timeout + stuff here. */ + sys_arch_sem_wait(&mbox->mutex, 0); + + while (mbox->first == mbox->last) + { + sys_sem_signal(&mbox->mutex); + + /* We block while waiting for a mail to arrive in the mailbox. We + must be prepared to timeout. */ + if (timeout != 0) + { + time_needed = sys_arch_sem_wait(&mbox->not_empty, timeout); + + if (time_needed == SYS_ARCH_TIMEOUT) + { + return SYS_ARCH_TIMEOUT; + } + } + else + { + sys_arch_sem_wait(&mbox->not_empty, 0); + } + + sys_arch_sem_wait(&mbox->mutex, 0); + } + + if (msg != NULL) + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", (void *) mbox, *msg)); + *msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE]; + } + else + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p, null msg\n", (void *) mbox)); + } + + mbox->first++; + + if (mbox->wait_send) + { + sys_sem_signal(&mbox->not_full); + } + + sys_sem_signal(&mbox->mutex); + + return time_needed; +} +/*-----------------------------------------------------------------------------------*/ +static struct sys_sem * sys_sem_new_internal(u8_t count) +{ + struct sys_sem * sem; + + sem = (struct sys_sem *) CHIPPlatformMemoryAlloc(sizeof(struct sys_sem)); + if (sem != NULL) + { + sem->c = count; + pthread_cond_init(&(sem->cond), NULL); + pthread_mutex_init(&(sem->mutex), NULL); + } + return sem; +} +/*-----------------------------------------------------------------------------------*/ +err_t sys_sem_new(struct sys_sem ** sem, u8_t count) +{ + SYS_STATS_INC_USED(sem); + *sem = sys_sem_new_internal(count); + if (*sem == NULL) + { + return ERR_MEM; + } + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static u32_t cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex, u32_t timeout) +{ + time_t tdiff; + time_t sec, usec; + struct timeval rtime1, rtime2; + struct timespec ts; + int retval; + + if (timeout > 0) + { + /* Get a timestamp and add the timeout value. */ + gettimeofday(&rtime1, NULL); + sec = rtime1.tv_sec; + usec = rtime1.tv_usec; + usec += timeout % 1000 * 1000; + sec += (int) (timeout / 1000) + (int) (usec / 1000000); + usec = usec % 1000000; + ts.tv_nsec = usec * 1000; + ts.tv_sec = sec; + + retval = pthread_cond_timedwait(cond, mutex, &ts); + + if (retval == ETIMEDOUT) + { + return SYS_ARCH_TIMEOUT; + } + + /* Calculate for how long we waited for the cond. */ + gettimeofday(&rtime2, NULL); + tdiff = (rtime2.tv_sec - rtime1.tv_sec) * 1000 + (rtime2.tv_usec - rtime1.tv_usec) / 1000; + + if (tdiff <= 0) + { + return 0; + } + + return (u32_t) tdiff; + } + + pthread_cond_wait(cond, mutex); + + return 0; +} +/*-----------------------------------------------------------------------------------*/ +u32_t sys_arch_sem_wait(struct sys_sem ** s, u32_t timeout) +{ + u32_t time_needed = 0; + struct sys_sem * sem; + LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); + sem = *s; + + pthread_mutex_lock(&(sem->mutex)); + while (sem->c <= 0) + { + if (timeout > 0) + { + time_needed = cond_wait(&(sem->cond), &(sem->mutex), timeout); + + if (time_needed == SYS_ARCH_TIMEOUT) + { + pthread_mutex_unlock(&(sem->mutex)); + return SYS_ARCH_TIMEOUT; + } + /* pthread_mutex_unlock(&(sem->mutex)); + return time_needed; */ + } + else + { + cond_wait(&(sem->cond), &(sem->mutex), 0); + } + } + sem->c--; + pthread_mutex_unlock(&(sem->mutex)); + return time_needed; +} +/*-----------------------------------------------------------------------------------*/ +void sys_sem_signal(struct sys_sem ** s) +{ + struct sys_sem * sem; + LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); + sem = *s; + + pthread_mutex_lock(&(sem->mutex)); + sem->c++; + + if (sem->c > 1) + { + sem->c = 1; + } + + pthread_cond_broadcast(&(sem->cond)); + pthread_mutex_unlock(&(sem->mutex)); +} +/*-----------------------------------------------------------------------------------*/ +static void sys_sem_free_internal(struct sys_sem * sem) +{ + pthread_cond_destroy(&(sem->cond)); + pthread_mutex_destroy(&(sem->mutex)); + CHIPPlatformMemoryFree(sem); +} +/*-----------------------------------------------------------------------------------*/ +void sys_sem_free(struct sys_sem ** sem) +{ + if ((sem != NULL) && (*sem != SYS_SEM_NULL)) + { + SYS_STATS_DEC(sem.used); + sys_sem_free_internal(*sem); + } +} +#endif /* !NO_SYS */ +/*-----------------------------------------------------------------------------------*/ +u32_t sys_now(void) +{ + struct timeval tv; + u32_t msec; + gettimeofday(&tv, NULL); + + msec = (u32_t)((tv.tv_sec - starttime.tv_sec) * 1000 + (tv.tv_usec - starttime.tv_usec) / 1000); + + return msec; +} +/*-----------------------------------------------------------------------------------*/ +void sys_init(void) +{ + gettimeofday(&starttime, NULL); +} +/*-----------------------------------------------------------------------------------*/ +#if SYS_LIGHTWEIGHT_PROT +/** sys_prot_t sys_arch_protect(void) + +This optional function does a "fast" critical region protection and returns +the previous protection level. This function is only called during very short +critical regions. An embedded system which supports ISR-based drivers might +want to implement this function by disabling interrupts. Task-based systems +might want to implement this by using a mutex or disabling tasking. This +function should support recursive calls from the same task or interrupt. In +other words, sys_arch_protect() could be called while already protected. In +that case the return value indicates that it is already protected. + +sys_arch_protect() is only required if your port is supporting an operating +system. +*/ +sys_prot_t sys_arch_protect(void) +{ + /* Note that for the UNIX port, we are using a lightweight mutex, and our + * own counter (which is locked by the mutex). The return code is not actually + * used. */ + if (lwprot_thread != pthread_self()) + { + /* We are locking the mutex where it has not been locked before * + * or is being locked by another thread */ + pthread_mutex_lock(&lwprot_mutex); + lwprot_thread = pthread_self(); + lwprot_count = 1; + } + else + /* It is already locked by THIS thread */ + lwprot_count++; + return 0; +} +/*-----------------------------------------------------------------------------------*/ + +/** void sys_arch_unprotect(sys_prot_t pval) + +This optional function does a "fast" set of critical region protection to the +value specified by pval. See the documentation for sys_arch_protect() for +more information. This function is only required if your port is supporting +an operating system. +*/ +void sys_arch_unprotect(sys_prot_t pval) +{ + LWIP_UNUSED_ARG(pval); + if (lwprot_thread == pthread_self()) + { + if (--lwprot_count == 0) + { + lwprot_thread = (pthread_t) 0xDEAD; + pthread_mutex_unlock(&lwprot_mutex); + } + } +} +#endif /* SYS_LIGHTWEIGHT_PROT */ + +/*-----------------------------------------------------------------------------------*/ + +#ifndef MAX_JIFFY_OFFSET +#define MAX_JIFFY_OFFSET ((~0U >> 1) - 1) +#endif + +#ifndef HZ +#define HZ 100 +#endif + +u32_t sys_jiffies(void) +{ + struct timeval tv; + unsigned long sec; + long usec; + + gettimeofday(&tv, NULL); + sec = tv.tv_sec - starttime.tv_sec; + usec = tv.tv_usec; + + if (sec >= (MAX_JIFFY_OFFSET / HZ)) + return MAX_JIFFY_OFFSET; + usec += 1000000L / HZ - 1; + usec /= 1000000L / HZ; + return HZ * sec + usec; +} + +#if PPP_DEBUG + +#include + +void ppp_trace(int level, const char * format, ...) +{ + va_list args; + + (void) level; + va_start(args, format); + vprintf(format, args); + va_end(args); +} +#endif + +#ifdef LWIP_DEBUG + +unsigned char gLwIP_DebugFlags = 0; + +#endif From 303bd6f10189c98fec4b14360b449c272def28a4 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 16:33:01 +0000 Subject: [PATCH 11/27] Add mbed custom shell streamer --- src/lib/core/core.gni | 2 +- src/lib/shell/BUILD.gn | 4 +++ src/lib/shell/streamer_mbed.cpp | 63 +++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/lib/shell/streamer_mbed.cpp diff --git a/src/lib/core/core.gni b/src/lib/core/core.gni index deecc5075e87bc..116cb6f58e0f74 100644 --- a/src/lib/core/core.gni +++ b/src/lib/core/core.gni @@ -44,7 +44,7 @@ declare_args() { } if (chip_target_style == "") { - if (current_os != "freertos" && current_os != "zephyr") { + if (current_os != "freertos" && current_os != "zephyr" && current_os != "mbed") { chip_target_style = "unix" } else { chip_target_style = "embedded" diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn index 956f59cf07d7cd..bc4ee515eea6ca 100644 --- a/src/lib/shell/BUILD.gn +++ b/src/lib/shell/BUILD.gn @@ -37,6 +37,10 @@ static_library("shell") { sources += [ "streamer_zephyr.cpp" ] } + if (current_os == "mbed") { + sources += [ "streamer_mbed.cpp" ] + } + cflags = [ "-Wconversion" ] public_deps = [ diff --git a/src/lib/shell/streamer_mbed.cpp b/src/lib/shell/streamer_mbed.cpp new file mode 100644 index 00000000000000..41654cac361013 --- /dev/null +++ b/src/lib/shell/streamer_mbed.cpp @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2020 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. + */ + +/** + * @file + * Source implementation of an input / output stream for stdio targets. + */ + +#include "shell.h" + +#include +#include +#include + +namespace chip { +namespace Shell { + +#ifndef SHELL_STREAMER_APP_SPECIFIC + +int streamer_stdio_init(streamer_t * streamer) +{ + return 0; +} + +ssize_t streamer_stdio_read(streamer_t * streamer, char * buf, size_t len) +{ + return fread(buf, 1, len, stdin); +} + +ssize_t streamer_stdio_write(streamer_t * streamer, const char * buf, size_t len) +{ + return fwrite(buf, 1, len, stdout); +} + +static streamer_t streamer_stdio = { + .init_cb = streamer_stdio_init, + .read_cb = streamer_stdio_read, + .write_cb = streamer_stdio_write, +}; + +streamer_t * streamer_get() +{ + return &streamer_stdio; +} + +#endif //#ifndef SHELL_STREAMER_APP_SPECIFIC + +} // namespace Shell +} // namespace chip From b8b390ba2e7b62582e020ba5dc91dc842825c835 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 16:34:07 +0000 Subject: [PATCH 12/27] Fix visibility of mbed ConnectivityManagerImpl::_OnPlatformEvent --- src/platform/mbed/ConnectivityManagerImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/mbed/ConnectivityManagerImpl.h b/src/platform/mbed/ConnectivityManagerImpl.h index 2ab31062e68d27..3882aec8fe89b6 100644 --- a/src/platform/mbed/ConnectivityManagerImpl.h +++ b/src/platform/mbed/ConnectivityManagerImpl.h @@ -100,7 +100,7 @@ inline CHIP_ERROR ConnectivityManagerImpl::_Init(void) return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) {} +inline void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) {} /** * Returns the public interface of the ConnectivityManager singleton object. From 56fd2d3627b61859637c999e818191a4f76d2238 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 16:34:59 +0000 Subject: [PATCH 13/27] Update Mbed plaform with Config stub. --- src/platform/BUILD.gn | 5 + src/platform/mbed/CHIPDevicePlatformConfig.h | 4 + .../mbed/ConfigurationManagerImpl.cpp | 41 +++++ src/platform/mbed/ConfigurationManagerImpl.h | 4 +- src/platform/mbed/MbedConfig.cpp | 154 ++++++++++++++++++ src/platform/mbed/MbedConfig.h | 118 ++++++++++++++ 6 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 src/platform/mbed/ConfigurationManagerImpl.cpp create mode 100644 src/platform/mbed/MbedConfig.cpp create mode 100644 src/platform/mbed/MbedConfig.h diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index 1fb34374fb19ff..a51823401fb464 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -530,6 +530,11 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { "qpg6100/ThreadStackManagerImpl.h", ] } + } else if (chip_device_platform == "mbed") { + sources += [ + "mbed/ConfigurationManagerImpl.cpp", + "mbed/MbedConfig.cpp" + ] } allow_circular_includes_from = [ "${chip_root}/src/lib/support" ] diff --git a/src/platform/mbed/CHIPDevicePlatformConfig.h b/src/platform/mbed/CHIPDevicePlatformConfig.h index e21613f72c0cc1..a51e0b5c16ba64 100644 --- a/src/platform/mbed/CHIPDevicePlatformConfig.h +++ b/src/platform/mbed/CHIPDevicePlatformConfig.h @@ -39,3 +39,7 @@ #define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY 3 #define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 4 #define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 5 + +// ========== Platform-specific Configuration Overrides ========= + +#define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0 \ No newline at end of file diff --git a/src/platform/mbed/ConfigurationManagerImpl.cpp b/src/platform/mbed/ConfigurationManagerImpl.cpp new file mode 100644 index 00000000000000..ffa05ff75aac72 --- /dev/null +++ b/src/platform/mbed/ConfigurationManagerImpl.cpp @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Nest Labs, Inc. + * + * 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. + */ + +/** + * @file + * Provides the implementation of the Device Layer ConfigurationManager object + * for mbed platforms. + */ +/* this file behaves like a config.h, comes first */ +#include + +#include + +#include + +namespace chip { +namespace DeviceLayer { + +using namespace ::chip::DeviceLayer::Internal; + +/** Singleton instance of the ConfigurationManager implementation object. + */ +ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/mbed/ConfigurationManagerImpl.h b/src/platform/mbed/ConfigurationManagerImpl.h index e6616c8616ed72..a916e77a229853 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.h +++ b/src/platform/mbed/ConfigurationManagerImpl.h @@ -24,6 +24,7 @@ #pragma once #include +#include namespace chip { namespace DeviceLayer { @@ -32,7 +33,8 @@ namespace DeviceLayer { * Concrete implementation of the ConfigurationManager singleton object for the Zephyr platform. */ class ConfigurationManagerImpl final : public ConfigurationManager, - public Internal::GenericConfigurationManagerImpl + public Internal::GenericConfigurationManagerImpl, + private Internal::MbedConfig { // Allow the ConfigurationManager interface class to delegate method calls to // the implementation methods provided by this class. diff --git a/src/platform/mbed/MbedConfig.cpp b/src/platform/mbed/MbedConfig.cpp new file mode 100644 index 00000000000000..8cc6c0bdb4cd2c --- /dev/null +++ b/src/platform/mbed/MbedConfig.cpp @@ -0,0 +1,154 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019-2020 Google LLC. + * Copyright (c) 2018 Nest Labs, Inc. + * All rights reserved. + * + * 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. + */ + +/** + * @file + * Utilities for interacting with the the ESP32 "NVS" key-value store. + */ +/* this file behaves like a config.h, comes first */ +#include + +#include + +#include +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +// *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices. + +// NVS namespaces used to store device configuration information. +const char MbedConfig::kConfigNamespace_ChipFactory[] = "chip-factory"; +const char MbedConfig::kConfigNamespace_ChipConfig[] = "chip-config"; +const char MbedConfig::kConfigNamespace_ChipCounters[] = "chip-counters"; + +// Keys stored in the chip-factory namespace +const MbedConfig::Key MbedConfig::kConfigKey_SerialNum = { kConfigNamespace_ChipFactory, "serial-num" }; +const MbedConfig::Key MbedConfig::kConfigKey_MfrDeviceId = { kConfigNamespace_ChipFactory, "device-id" }; +const MbedConfig::Key MbedConfig::kConfigKey_MfrDeviceCert = { kConfigNamespace_ChipFactory, "device-cert" }; +const MbedConfig::Key MbedConfig::kConfigKey_MfrDeviceICACerts = { kConfigNamespace_ChipFactory, "device-ca-certs" }; +const MbedConfig::Key MbedConfig::kConfigKey_MfrDevicePrivateKey = { kConfigNamespace_ChipFactory, "device-key" }; +const MbedConfig::Key MbedConfig::kConfigKey_ProductRevision = { kConfigNamespace_ChipFactory, "product-rev" }; +const MbedConfig::Key MbedConfig::kConfigKey_ManufacturingDate = { kConfigNamespace_ChipFactory, "mfg-date" }; +const MbedConfig::Key MbedConfig::kConfigKey_SetupPinCode = { kConfigNamespace_ChipFactory, "pin-code" }; +const MbedConfig::Key MbedConfig::kConfigKey_SetupDiscriminator = { kConfigNamespace_ChipFactory, "discriminator" }; + +// Keys stored in the chip-config namespace +const MbedConfig::Key MbedConfig::kConfigKey_FabricId = { kConfigNamespace_ChipConfig, "fabric-id" }; +const MbedConfig::Key MbedConfig::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" }; +const MbedConfig::Key MbedConfig::kConfigKey_PairedAccountId = { kConfigNamespace_ChipConfig, "account-id" }; +const MbedConfig::Key MbedConfig::kConfigKey_ServiceId = { kConfigNamespace_ChipConfig, "service-id" }; +const MbedConfig::Key MbedConfig::kConfigKey_GroupKeyIndex = { kConfigNamespace_ChipConfig, "group-key-index" }; +const MbedConfig::Key MbedConfig::kConfigKey_LastUsedEpochKeyId = { kConfigNamespace_ChipConfig, "last-ek-id" }; +const MbedConfig::Key MbedConfig::kConfigKey_FailSafeArmed = { kConfigNamespace_ChipConfig, "fail-safe-armed" }; +const MbedConfig::Key MbedConfig::kConfigKey_WiFiStationSecType = { kConfigNamespace_ChipConfig, "sta-sec-type" }; +const MbedConfig::Key MbedConfig::kConfigKey_OperationalDeviceId = { kConfigNamespace_ChipConfig, "op-device-id" }; +const MbedConfig::Key MbedConfig::kConfigKey_OperationalDeviceCert = { kConfigNamespace_ChipConfig, "op-device-cert" }; +const MbedConfig::Key MbedConfig::kConfigKey_OperationalDeviceICACerts = { kConfigNamespace_ChipConfig, "op-device-ca-certs" }; +const MbedConfig::Key MbedConfig::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_ChipConfig, "op-device-key" }; + +// Prefix used for NVS keys that contain Chip group encryption keys. +const char MbedConfig::kGroupKeyNamePrefix[] = "gk-"; + +CHIP_ERROR MbedConfig::ReadConfigValue(Key key, bool & val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::ReadConfigValue(Key key, uint32_t & val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::ReadConfigValue(Key key, uint64_t & val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::WriteConfigValue(Key key, bool val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::WriteConfigValue(Key key, uint32_t val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::WriteConfigValue(Key key, uint64_t val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::WriteConfigValueStr(Key key, const char * str) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::ClearConfigValue(Key key) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +bool MbedConfig::ConfigValueExists(Key key) +{ + return false; +} + +CHIP_ERROR MbedConfig::EnsureNamespace(const char * ns) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR MbedConfig::ClearNamespace(const char * ns) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +void MbedConfig::RunConfigUnitTest() {} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/mbed/MbedConfig.h b/src/platform/mbed/MbedConfig.h new file mode 100644 index 00000000000000..a4c59797ee3748 --- /dev/null +++ b/src/platform/mbed/MbedConfig.h @@ -0,0 +1,118 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019-2020 Google LLC. + * Copyright (c) 2018 Nest Labs, Inc. + * All rights reserved. + * + * 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. + */ + +/** + * @file + * Utilities for interacting with the the ESP32 "NVS" key-value store. + */ + +#pragma once + +#include + +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +/** + * Provides functions and definitions for accessing device configuration information on the ESP32. + * + * This class is designed to be mixed-in to concrete implementation classes as a means to + * provide access to configuration information to generic base classes. + */ +class MbedConfig +{ +public: + struct Key; + + // Maximum length of an NVS key name, as specified in the ESP-IDF documentation. + static constexpr size_t kMaxConfigKeyNameLength = 15; + + // NVS namespaces used to store device configuration information. + static const char kConfigNamespace_ChipFactory[]; + static const char kConfigNamespace_ChipConfig[]; + static const char kConfigNamespace_ChipCounters[]; + + // Key definitions for well-known keys. + static const Key kConfigKey_SerialNum; + static const Key kConfigKey_MfrDeviceId; + static const Key kConfigKey_MfrDeviceCert; + static const Key kConfigKey_MfrDeviceICACerts; + static const Key kConfigKey_MfrDevicePrivateKey; + static const Key kConfigKey_ProductRevision; + static const Key kConfigKey_ManufacturingDate; + static const Key kConfigKey_SetupPinCode; + static const Key kConfigKey_FabricId; + static const Key kConfigKey_ServiceConfig; + static const Key kConfigKey_PairedAccountId; + static const Key kConfigKey_ServiceId; + static const Key kConfigKey_FabricSecret; + static const Key kConfigKey_GroupKeyIndex; + static const Key kConfigKey_LastUsedEpochKeyId; + static const Key kConfigKey_FailSafeArmed; + static const Key kConfigKey_WiFiStationSecType; + static const Key kConfigKey_OperationalDeviceId; + static const Key kConfigKey_OperationalDeviceCert; + static const Key kConfigKey_OperationalDeviceICACerts; + static const Key kConfigKey_OperationalDevicePrivateKey; + static const Key kConfigKey_SetupDiscriminator; + + static const char kGroupKeyNamePrefix[]; + + // Config value accessors. + static CHIP_ERROR ReadConfigValue(Key key, bool & val); + static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val); + static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val); + static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen); + static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen); + static CHIP_ERROR WriteConfigValue(Key key, bool val); + static CHIP_ERROR WriteConfigValue(Key key, uint32_t val); + static CHIP_ERROR WriteConfigValue(Key key, uint64_t val); + static CHIP_ERROR WriteConfigValueStr(Key key, const char * str); + static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen); + static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen); + static CHIP_ERROR ClearConfigValue(Key key); + static bool ConfigValueExists(Key key); + + // NVS Namespace helper functions. + static CHIP_ERROR EnsureNamespace(const char * ns); + static CHIP_ERROR ClearNamespace(const char * ns); + + static void RunConfigUnitTest(void); +}; + +struct MbedConfig::Key +{ + const char * Namespace; + const char * Name; + + bool operator==(const Key & other) const; +}; + +inline bool MbedConfig::Key::operator==(const Key & other) const +{ + return strcmp(Namespace, other.Namespace) == 0 && strcmp(Name, other.Name) == 0; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip From 4ada0e7fea17249e8600d5b8b9d4a1234bad2c12 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 16:36:04 +0000 Subject: [PATCH 14/27] HACK: Hardcode libshell to mbed build --- config/mbed/chip-gn/args.gni | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni index 426cca288fe8ae..5d28d4cca6a7b2 100644 --- a/config/mbed/chip-gn/args.gni +++ b/config/mbed/chip-gn/args.gni @@ -34,6 +34,8 @@ lwip_platform = "mbed" chip_system_config_use_sockets=false chip_device_platform = "mbed" +chip_build_libshell = true + # TODO: remove mbed_ar="/opt/ARM-software/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-ar" mbed_cc="/opt/ARM-software/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc" From 4434643592a2cf7c70dab65d96e7144bbb3d8cdd Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 16:36:42 +0000 Subject: [PATCH 15/27] HACK: Disable args.gn creation from CMake. --- config/mbed/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt index d8c615aa036898..f067656071147d 100644 --- a/config/mbed/CMakeLists.txt +++ b/config/mbed/CMakeLists.txt @@ -139,9 +139,9 @@ endif() #chip_gn_arg_cflags("target_cflags" ${CHIP_CFLAGS}) #chip_gn_arg_cflags("target_cflags_c" ${CHIP_CFLAGS_C}) #chip_gn_arg_cflags("target_cflags_cc" ${CHIP_CFLAGS_CC}) -chip_gn_arg_string("mbed_ar" ${CMAKE_AR}) -chip_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER}) -chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) +#chip_gn_arg_string("mbed_ar" ${CMAKE_AR}) +#chip_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER}) +#chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) #chip_gn_arg_string("chip_project_config_include" "${CHIP_PROJECT_CONFIG}") #chip_gn_arg_string("chip_system_project_config_include" "${CHIP_PROJECT_CONFIG}") #chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) @@ -159,7 +159,7 @@ elseif (BOARD STREQUAL "native_posix_64") chip_gn_arg_string("target_cpu" "x64") endif() -file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS}) +#file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS}) # ============================================================================== # Define 'chip-gn' target that builds CHIP library(ies) with GN build system From f332045ea257168afda5687579abbde26d2b90ac Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 16:38:37 +0000 Subject: [PATCH 16/27] HACK: implement required builtin atomic for mbed targets. --- examples/shell/mbed/arch.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 examples/shell/mbed/arch.c diff --git a/examples/shell/mbed/arch.c b/examples/shell/mbed/arch.c new file mode 100644 index 00000000000000..b7548e4d71b0ea --- /dev/null +++ b/examples/shell/mbed/arch.c @@ -0,0 +1,13 @@ +#include "platform/mbed_toolchain.h" +#include "platform/mbed_atomic.h" + +// TODO: Remove! +// This file is a temporary workaround until atomic integration has been solved + +void __sync_synchronize() { + MBED_BARRIER(); +} + +unsigned int __atomic_fetch_add_4(volatile uint32_t *ptr, uint32_t val, int memorder) { + return core_util_atomic_fetch_add_explicit_u32(ptr, val, memorder); +} \ No newline at end of file From 15a24df746cdfd30ebb919e9dd49c8f434c6ef35 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 3 Feb 2021 16:39:25 +0000 Subject: [PATCH 17/27] Update Shell Mbed CMakeLists.txt to compile common and main file. --- examples/shell/mbed/CMakeLists.txt | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/examples/shell/mbed/CMakeLists.txt b/examples/shell/mbed/CMakeLists.txt index d2c8ea4bde42cd..700394c34c41ea 100644 --- a/examples/shell/mbed/CMakeLists.txt +++ b/examples/shell/mbed/CMakeLists.txt @@ -8,6 +8,7 @@ get_filename_component(APP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/.. REALPATH) set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "") set(MBED_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.mbedbuild CACHE INTERNAL "") +set(CONFIG_CHIP_LIB_SHELL 1) set(APP_TARGET chip-mbed-shell-example) include(${MBED_PATH}/tools/cmake/app.cmake) @@ -15,8 +16,33 @@ add_subdirectory(${MBED_PATH} ./mbed_build) add_subdirectory(${CHIP_ROOT}/config/mbed ./chip_build) -add_executable(${APP_TARGET} - main.cpp + +add_executable(${APP_TARGET}) + +target_include_directories(${APP_TARGET} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${APP_ROOT}/shell_common/include) + +# FIXME: These includes path should be propagated by chip +target_include_directories(${APP_TARGET} PRIVATE + ${CHIP_ROOT}/third_party/lwip/repo/lwip/src/include + ${CHIP_ROOT}/src/lwip/mbed +) + +# FIXME: These defines should be propagated by chip +target_compile_definitions(${APP_TARGET} PRIVATE + "LWIP_NO_STDINT_H=1" + "IN_ADDR_T_DEFINED=1" +) + +target_sources(${APP_TARGET} PRIVATE + ${APP_ROOT}/shell_common/cmd_base64.cpp + ${APP_ROOT}/shell_common/cmd_device.cpp + ${APP_ROOT}/shell_common/cmd_misc.cpp + ${APP_ROOT}/shell_common/cmd_otcli.cpp + ${APP_ROOT}/shell_common/cmd_btp.cpp + ${APP_ROOT}/standalone/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/arch.c ) mbed_configure_app_target(${APP_TARGET}) From 08297c7f22c01f1bd5f15d1e2ba3e4527178a71a Mon Sep 17 00:00:00 2001 From: arty Date: Thu, 4 Feb 2021 10:56:18 +0100 Subject: [PATCH 18/27] Add config.in file with project-specific configuration for mbed project Load configuration file during build process Cleanup in args.in Enable args.gn file generating with GN build configuration --- config/mbed/CMakeLists.txt | 43 ++++++++++++++++-------------- config/mbed/chip-gn/args.gni | 12 --------- examples/shell/mbed/CMakeLists.txt | 8 ++++-- examples/shell/mbed/config.in | 2 ++ 4 files changed, 31 insertions(+), 34 deletions(-) create mode 100644 examples/shell/mbed/config.in diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt index f067656071147d..c26b2493a4f588 100644 --- a/config/mbed/CMakeLists.txt +++ b/config/mbed/CMakeLists.txt @@ -93,18 +93,24 @@ endmacro() # Prepare CHIP configuration based on the project configuration # ============================================================================== +file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/config ConfigContents) +foreach(NameAndValue ${ConfigContents}) + # Strip leading spaces + string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) + # Find variable name + string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) + # Find the value + string(REPLACE "${Name}=" "" Value ${NameAndValue}) + # Set the variable + set(${Name} "${Value}") +endforeach() + if (NOT CHIP_ROOT) get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../.. REALPATH) endif() # Prepare compiler flags -if (CONFIG_ARM) - list(APPEND CHIP_CFLAGS_C - --specs=nosys.specs - ) -endif() - #convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS CHIP_CFLAGS) #convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_C CHIP_CFLAGS_C) #convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_CC CHIP_CFLAGS_CC) @@ -132,6 +138,10 @@ else() set(CHIP_PROJECT_CONFIG "") endif() +if (${CMAKE_BUILD_TYPE} STREQUAL "debug") + set(CONFIG_DEBUG "y") +endif() + # ============================================================================== # Generate configuration for CHIP GN build system # ============================================================================== @@ -139,19 +149,12 @@ endif() #chip_gn_arg_cflags("target_cflags" ${CHIP_CFLAGS}) #chip_gn_arg_cflags("target_cflags_c" ${CHIP_CFLAGS_C}) #chip_gn_arg_cflags("target_cflags_cc" ${CHIP_CFLAGS_CC}) -#chip_gn_arg_string("mbed_ar" ${CMAKE_AR}) -#chip_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER}) -#chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) -#chip_gn_arg_string("chip_project_config_include" "${CHIP_PROJECT_CONFIG}") -#chip_gn_arg_string("chip_system_project_config_include" "${CHIP_PROJECT_CONFIG}") -#chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) -#chip_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD) -#chip_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4) -#chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) -#chip_gn_arg_bool ("chip_inet_config_enable_raw_endpoint" CONFIG_CHIP_BUILD_TESTS) -#chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) -#chip_gn_arg_bool ("chip_inet_config_enable_dns_resolver" CONFIG_CHIP_BUILD_TESTS) -#chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) +chip_gn_arg_string("mbed_ar" ${CMAKE_AR}) +chip_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER}) +chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) +chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) +chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) +chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) if (BOARD STREQUAL "native_posix") chip_gn_arg_string("target_cpu" "x86") @@ -159,7 +162,7 @@ elseif (BOARD STREQUAL "native_posix_64") chip_gn_arg_string("target_cpu" "x64") endif() -#file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS}) +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS}) # ============================================================================== # Define 'chip-gn' target that builds CHIP library(ies) with GN build system diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni index 5d28d4cca6a7b2..7f721d08a68836 100644 --- a/config/mbed/chip-gn/args.gni +++ b/config/mbed/chip-gn/args.gni @@ -16,8 +16,6 @@ import("//build_overrides/chip.gni") chip_device_platform = "mbed" -chip_build_tests = false - chip_project_config_include = "" chip_system_project_config_include = "" chip_ble_project_config_include = "" @@ -25,18 +23,8 @@ chip_ble_project_config_include = "" custom_toolchain = "//toolchain:mbed" mbedtls_target = "//:mbedtls" - treat_warnings_as_errors = false -chip_system_config_locking="none" chip_with_lwip=true chip_system_config_use_lwip=true lwip_platform = "mbed" chip_system_config_use_sockets=false -chip_device_platform = "mbed" - -chip_build_libshell = true - -# TODO: remove -mbed_ar="/opt/ARM-software/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-ar" -mbed_cc="/opt/ARM-software/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc" -mbed_cxx="/opt/ARM-software/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-g++" diff --git a/examples/shell/mbed/CMakeLists.txt b/examples/shell/mbed/CMakeLists.txt index 700394c34c41ea..a937f1b6be3594 100644 --- a/examples/shell/mbed/CMakeLists.txt +++ b/examples/shell/mbed/CMakeLists.txt @@ -6,9 +6,14 @@ cmake_minimum_required(VERSION 3.19.0) get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH) get_filename_component(APP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/.. REALPATH) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/config.in + ${CMAKE_CURRENT_BINARY_DIR}/chip_build/config + @ONLY +) + set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "") set(MBED_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.mbedbuild CACHE INTERNAL "") -set(CONFIG_CHIP_LIB_SHELL 1) set(APP_TARGET chip-mbed-shell-example) include(${MBED_PATH}/tools/cmake/app.cmake) @@ -16,7 +21,6 @@ add_subdirectory(${MBED_PATH} ./mbed_build) add_subdirectory(${CHIP_ROOT}/config/mbed ./chip_build) - add_executable(${APP_TARGET}) target_include_directories(${APP_TARGET} PRIVATE diff --git a/examples/shell/mbed/config.in b/examples/shell/mbed/config.in new file mode 100644 index 00000000000000..475be00ab19c14 --- /dev/null +++ b/examples/shell/mbed/config.in @@ -0,0 +1,2 @@ +CONFIG_CHIP_BUILD_TESTS=n +CONFIG_CHIP_LIB_SHELL=y \ No newline at end of file From bc26fbd5927199f8f0e1cadd06b8da5dbc435fbe Mon Sep 17 00:00:00 2001 From: arty Date: Thu, 4 Feb 2021 15:57:07 +0100 Subject: [PATCH 19/27] Add config CHIP with LWIP parameter to config.in Move mbed includes path and defines to config layer and creating dependencies on project settings Move chip_with_lwip parameter to auto-generated GN config file --- config/mbed/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ config/mbed/chip-gn/args.gni | 2 -- examples/shell/mbed/CMakeLists.txt | 16 ++-------------- examples/shell/mbed/config.in | 3 ++- src/system/system.gni | 2 +- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt index c26b2493a4f588..d96e106413bae4 100644 --- a/config/mbed/CMakeLists.txt +++ b/config/mbed/CMakeLists.txt @@ -155,6 +155,7 @@ chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) +chip_gn_arg_bool ("chip_with_lwip" CONFIG_CHIP_WITH_LWIP) if (BOARD STREQUAL "native_posix") chip_gn_arg_string("target_cpu" "x86") @@ -200,3 +201,31 @@ target_include_directories(chip INTERFACE target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib) target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group) add_dependencies(chip chip-gn) + +# ============================================================================== +# Define mbed target configuration according to CHIP component usage +# ============================================================================== +# CHIP includes path +list(APPEND CHIP_INCLUDES) + +# CHIP defines +list(APPEND CHIP_DEFINES) + +if (${CONFIG_CHIP_WITH_LWIP}) + list(APPEND CHIP_INCLUDES + ${CHIP_ROOT}/third_party/lwip/repo/lwip/src/include + ${CHIP_ROOT}/src/lwip/mbed + ) + list(APPEND CHIP_DEFINES + "LWIP_NO_STDINT_H=1" + "IN_ADDR_T_DEFINED=1" + ) +endif() + +target_include_directories(${APP_TARGET} PRIVATE + ${CHIP_INCLUDES} +) + +target_compile_definitions(${APP_TARGET} PRIVATE + ${CHIP_DEFINES} +) diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni index 7f721d08a68836..069d7ca9ae2dab 100644 --- a/config/mbed/chip-gn/args.gni +++ b/config/mbed/chip-gn/args.gni @@ -24,7 +24,5 @@ custom_toolchain = "//toolchain:mbed" mbedtls_target = "//:mbedtls" treat_warnings_as_errors = false -chip_with_lwip=true -chip_system_config_use_lwip=true lwip_platform = "mbed" chip_system_config_use_sockets=false diff --git a/examples/shell/mbed/CMakeLists.txt b/examples/shell/mbed/CMakeLists.txt index a937f1b6be3594..6b91806c38ea26 100644 --- a/examples/shell/mbed/CMakeLists.txt +++ b/examples/shell/mbed/CMakeLists.txt @@ -19,26 +19,12 @@ set(APP_TARGET chip-mbed-shell-example) include(${MBED_PATH}/tools/cmake/app.cmake) add_subdirectory(${MBED_PATH} ./mbed_build) -add_subdirectory(${CHIP_ROOT}/config/mbed ./chip_build) - add_executable(${APP_TARGET}) target_include_directories(${APP_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${APP_ROOT}/shell_common/include) -# FIXME: These includes path should be propagated by chip -target_include_directories(${APP_TARGET} PRIVATE - ${CHIP_ROOT}/third_party/lwip/repo/lwip/src/include - ${CHIP_ROOT}/src/lwip/mbed -) - -# FIXME: These defines should be propagated by chip -target_compile_definitions(${APP_TARGET} PRIVATE - "LWIP_NO_STDINT_H=1" - "IN_ADDR_T_DEFINED=1" -) - target_sources(${APP_TARGET} PRIVATE ${APP_ROOT}/shell_common/cmd_base64.cpp ${APP_ROOT}/shell_common/cmd_device.cpp @@ -49,6 +35,8 @@ target_sources(${APP_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/arch.c ) +add_subdirectory(${CHIP_ROOT}/config/mbed ./chip_build) + mbed_configure_app_target(${APP_TARGET}) mbed_set_mbed_target_linker_script(${APP_TARGET}) diff --git a/examples/shell/mbed/config.in b/examples/shell/mbed/config.in index 475be00ab19c14..eae26cd1c42d61 100644 --- a/examples/shell/mbed/config.in +++ b/examples/shell/mbed/config.in @@ -1,2 +1,3 @@ CONFIG_CHIP_BUILD_TESTS=n -CONFIG_CHIP_LIB_SHELL=y \ No newline at end of file +CONFIG_CHIP_LIB_SHELL=y +CONFIG_CHIP_WITH_LWIP=y \ No newline at end of file diff --git a/src/system/system.gni b/src/system/system.gni index 72744392f314e3..0012f5e96c9354 100644 --- a/src/system/system.gni +++ b/src/system/system.gni @@ -18,7 +18,7 @@ import("${chip_root}/src/lwip/lwip.gni") declare_args() { # Use the lwIP library. - chip_system_config_use_lwip = chip_with_lwip && current_os == "freertos" + chip_system_config_use_lwip = chip_with_lwip && (current_os == "freertos" || current_os == "mbed") # Use BSD/POSIX socket API. chip_system_config_use_sockets = current_os != "freertos" From 8295f668061212144a8dbb0559d0bb3723c8d2e9 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 4 Feb 2021 21:57:52 +0000 Subject: [PATCH 20/27] Make mbed_example.sh executable --- scripts/examples/mbed_example.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/examples/mbed_example.sh diff --git a/scripts/examples/mbed_example.sh b/scripts/examples/mbed_example.sh old mode 100644 new mode 100755 From c2ef305cedb2a3d1b9a7065ee401417cc7d72ef7 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 4 Feb 2021 21:59:19 +0000 Subject: [PATCH 21/27] Mbed example build workflow --- .github/workflows/main.yml | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000000000..8fa276252436f9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,79 @@ +# Copyright (c) 2020 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. + +name: Build example - Mbed OS + +on: + push: + pull_request: + +jobs: + # TODO ESP32 https://github.com/project-chip/connectedhomeip/issues/1510 + mbedos: + name: Mbed OS + + env: + BUILD_TYPE: mbedos + + runs-on: ubuntu-latest + + container: + image: pan2048/chip-build-mbed-os:0.4.18 + volumes: + - "/tmp/bloat_reports:/tmp/bloat_reports" + - "/tmp/output_binaries:/tmp/output_binaries" + + steps: + - name: Checkout + uses: actions/checkout@v2 + # Fetch depth 0 to get all history and be able to check mergepoint for bloat report + with: + fetch-depth: 0 + submodules: true +# - name: Initialize CodeQL +# uses: github/codeql-action/init@v1 +# with: +# languages: "cpp, python" +# queries: +security-and-quality + - name: Build example Echo App + run: scripts/examples/mbed_example.sh +# - name: Copy aside build products +# run: | +# mkdir -p example_binaries/$BUILD_TYPE-build +# cp examples/all-clusters-app/esp32/build/chip-all-clusters-app.elf \ +# example_binaries/$BUILD_TYPE-build/chip-all-clusters-app.elf +# - name: Binary artifact suffix +# id: outsuffix +# uses: haya14busa/action-cond@v1.0.0 +# with: +# cond: ${{ github.event.pull_request.number == '' }} +# if_true: "${{ github.sha }}" +# if_false: "pull-${{ github.event.pull_request.number }}" +# - name: Copy aside bloat report & binaries +# run: | +# cp -r example_binaries/$BUILD_TYPE-build /tmp/output_binaries/ +# - name: Uploading Binaries +# uses: actions/upload-artifact@v1 +# with: +# name: +# ${{ env.BUILD_TYPE }}-example-build-${{ +# steps.outsuffix.outputs.value }} +# path: /tmp/output_binaries/${{ env.BUILD_TYPE }}-build + # - name: Remove third_party binaries for CodeQL Analysis + # run: find . -type d -name "third_party" -exec rm -rf {} + + # - name: Remove m5stack-tft binaries for CodeQL Analysis + # run: find . -type d -name "m5stack-tft" -exec rm -rf {} + +# - name: Perform CodeQL Analysis +# if: ${{ github.event_name == 'push' }} +# uses: github/codeql-action/analyze@v1 From 58313ed02749122f8b08b3d94142836c145d56f9 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 4 Feb 2021 22:00:50 +0000 Subject: [PATCH 22/27] Bump image version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8fa276252436f9..3224b37db26113 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: runs-on: ubuntu-latest container: - image: pan2048/chip-build-mbed-os:0.4.18 + image: pan2048/chip-build-mbed-os:0.5.0 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" - "/tmp/output_binaries:/tmp/output_binaries" From c7ad7c39259a9b5b7af4bd9a51bb29dc6a7c7ac8 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 4 Feb 2021 22:44:22 +0000 Subject: [PATCH 23/27] Do not use absolute path for mbed libCHIPShell --- config/mbed/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt index d96e106413bae4..5cf19d09dd7efb 100644 --- a/config/mbed/CMakeLists.txt +++ b/config/mbed/CMakeLists.txt @@ -122,7 +122,7 @@ if (NOT CHIP_LIBRARIES) endif() if (CONFIG_CHIP_LIB_SHELL) - list(APPEND CHIP_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/obj/third_party/connectedhomeip/src/lib/shell/lib/libCHIPShell.a) + list(APPEND CHIP_LIBRARIES -lCHIPShell) endif() # Set up CHIP project configuration file From 60271b4db010fcb28142f21e2cdc0d86bcc1635c Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 4 Feb 2021 22:45:39 +0000 Subject: [PATCH 24/27] Create symlink to build mbed shell example --- scripts/examples/mbed_example.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/examples/mbed_example.sh b/scripts/examples/mbed_example.sh index b8193105ddaff8..75eac2e2c1007c 100755 --- a/scripts/examples/mbed_example.sh +++ b/scripts/examples/mbed_example.sh @@ -75,4 +75,5 @@ fi echo "Build $APP app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile" set -x pwd -mbed-tools compile -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP/mbed" --mbed-os-path "$MBED_OS_PATH" -b "$PROFILE" +ln -s /opt/mbed-os +mbed-tools compile -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP/mbed" -b "$PROFILE" From a66aae29b4932c182c81569357360ad57a1835c9 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 4 Feb 2021 22:52:06 +0000 Subject: [PATCH 25/27] Fix symbolic link --- scripts/examples/mbed_example.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/examples/mbed_example.sh b/scripts/examples/mbed_example.sh index 75eac2e2c1007c..d7a44871917644 100755 --- a/scripts/examples/mbed_example.sh +++ b/scripts/examples/mbed_example.sh @@ -75,5 +75,5 @@ fi echo "Build $APP app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile" set -x pwd -ln -s /opt/mbed-os +ln -s /opt/mbed-os . mbed-tools compile -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP/mbed" -b "$PROFILE" From 98eb3b600b9f99c665163bcc250151a014771a4a Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 4 Feb 2021 22:56:53 +0000 Subject: [PATCH 26/27] Fix symbolic link ... again --- scripts/examples/mbed_example.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/examples/mbed_example.sh b/scripts/examples/mbed_example.sh index d7a44871917644..9691e7d35f50ba 100755 --- a/scripts/examples/mbed_example.sh +++ b/scripts/examples/mbed_example.sh @@ -75,5 +75,5 @@ fi echo "Build $APP app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile" set -x pwd -ln -s /opt/mbed-os . +ln -s /opt/mbed-os $APP/mbed/mbed-os mbed-tools compile -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP/mbed" -b "$PROFILE" From ad6107cba8493f5660d20c9548aa11a550c3542a Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 4 Feb 2021 23:07:10 +0000 Subject: [PATCH 27/27] Add upload steps to mbed build --- .github/workflows/main.yml | 48 ++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3224b37db26113..ea8f4488067467 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,6 @@ on: pull_request: jobs: - # TODO ESP32 https://github.com/project-chip/connectedhomeip/issues/1510 mbedos: name: Mbed OS @@ -31,7 +30,6 @@ jobs: container: image: pan2048/chip-build-mbed-os:0.5.0 volumes: - - "/tmp/bloat_reports:/tmp/bloat_reports" - "/tmp/output_binaries:/tmp/output_binaries" steps: @@ -46,30 +44,30 @@ jobs: # with: # languages: "cpp, python" # queries: +security-and-quality - - name: Build example Echo App + - name: Build example Shell App run: scripts/examples/mbed_example.sh -# - name: Copy aside build products -# run: | -# mkdir -p example_binaries/$BUILD_TYPE-build -# cp examples/all-clusters-app/esp32/build/chip-all-clusters-app.elf \ -# example_binaries/$BUILD_TYPE-build/chip-all-clusters-app.elf -# - name: Binary artifact suffix -# id: outsuffix -# uses: haya14busa/action-cond@v1.0.0 -# with: -# cond: ${{ github.event.pull_request.number == '' }} -# if_true: "${{ github.sha }}" -# if_false: "pull-${{ github.event.pull_request.number }}" -# - name: Copy aside bloat report & binaries -# run: | -# cp -r example_binaries/$BUILD_TYPE-build /tmp/output_binaries/ -# - name: Uploading Binaries -# uses: actions/upload-artifact@v1 -# with: -# name: -# ${{ env.BUILD_TYPE }}-example-build-${{ -# steps.outsuffix.outputs.value }} -# path: /tmp/output_binaries/${{ env.BUILD_TYPE }}-build + - name: Copy aside build products + run: | + mkdir -p example_binaries/$BUILD_TYPE-build + cp examples/shell/mbed/cmake_build/chip-mbed-shell-example.hex \ + example_binaries/$BUILD_TYPE-build/chip-mbed-shell-example.hex + - name: Binary artifact suffix + id: outsuffix + uses: haya14busa/action-cond@v1.0.0 + with: + cond: ${{ github.event.pull_request.number == '' }} + if_true: "${{ github.sha }}" + if_false: "pull-${{ github.event.pull_request.number }}" + - name: Copy aside binaries + run: | + cp -r example_binaries/$BUILD_TYPE-build /tmp/output_binaries/ + - name: Uploading Binaries + uses: actions/upload-artifact@v1 + with: + name: + ${{ env.BUILD_TYPE }}-example-build-${{ + steps.outsuffix.outputs.value }} + path: /tmp/output_binaries/${{ env.BUILD_TYPE }}-build # - name: Remove third_party binaries for CodeQL Analysis # run: find . -type d -name "third_party" -exec rm -rf {} + # - name: Remove m5stack-tft binaries for CodeQL Analysis