Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Restyle WIP: ESP32 gn support #2326

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions config/esp32/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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

# Allow loading paths relative to //gn.
secondary_source = "//third_party/connectedhomeip/gn/"

default_args = {
target_cpu = "esp32"
target_os = "freertos"

import("//args.gni")
}
32 changes: 32 additions & 0 deletions config/esp32/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.

# Options from standalone-chip.mk that differ from configure defaults. These
# options are used from examples/.

import("//build_overrides/chip.gni")

config("esp32_config") {
defines = []
if (is_debug) {
defines = [ "BUILD_RELEASE=0" ]
} else {
defines = [ "BUILD_RELEASE=1" ]
}
}

group("esp32") {
deps = [ "${chip_root}/src/lib" ]
public_configs = [ ":esp32_config" ]
}
40 changes: 40 additions & 0 deletions config/esp32/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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.

# Options from standalone-chip.mk that differ from configure defaults. These
# options are used from examples/.

#import("//build_overrides/chip.gni")

chip_device_platform = "esp32"

chip_project_config_include = ""
chip_system_project_config_include = ""
chip_ble_project_config_include = ""

lwip_platform = "esp32"
lwip_ipv6 = true
lwip_ipv4 = true
lwip_api = true

chip_build_tests = false
chip_inet_config_enable_raw_endpoint = false
chip_inet_config_enable_dns_resolver = false

#Enabling this causes some error
#chip_inet_config_enable_tun_endpoint = false
chip_inet_config_enable_tcp_endpoint = true
chip_inet_config_enable_udp_endpoint = true

custom_toolchain = "//third_party/connectedhomeip/config/esp32/toolchain:esp32"
1 change: 1 addition & 0 deletions config/esp32/build_overrides
9 changes: 0 additions & 9 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@ menu "CHIP Core"

This value can be overridden by the application at runtime.

config SHORT_ERROR_STR
bool "Use Short Error Strings"
default n
help
Configure the CHIP ErrorStr() function to return short error strings
containing only the error, without any descriptive text.

This option is generally used to reduce flash usage.

# TODO: add log level selection

endmenu # "General Options"
Expand Down
39 changes: 29 additions & 10 deletions config/esp32/components/chip/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,17 @@ COMPONENT_ADD_INCLUDEDIRS = project-config \
$(REL_CHIP_ROOT)/src/include/ \
$(REL_CHIP_ROOT)/src/lib \
$(REL_CHIP_ROOT)/src/ \
$(REL_OUTPUT_DIR)/src/include \
$(REL_CHIP_ROOT)/src/system \
$(IDF_PATH)/components/mbedtls/mbedtls/include \
$(REL_CHIP_ROOT)/src/app \

$(REL_CHIP_ROOT)/third_party/nlassert/repo/include \
$(REL_OUTPUT_DIR)/gen/third_party/connectedhomeip/src/app/include \
$(REL_OUTPUT_DIR)/gen/include

# Linker flags to be included when building other components that use CHIP.
COMPONENT_ADD_LDFLAGS = -L$(OUTPUT_DIR)/lib/ \
-lCHIP \
-lInetLayer \
-lSystemLayer \
-lDeviceLayer \
-lChipCrypto \
-lSetupPayload
-lCHIP

ifneq (,$(findstring CHIP_SUPPORT_FOREIGN_TEST_DRIVERS,$(CXXFLAGS)))
COMPONENT_ADD_LDFLAGS += -lnlfaultinjection
Expand Down Expand Up @@ -193,13 +191,34 @@ $(OUTPUT_DIR) :
echo "MKDIR $@"
@mkdir -p "$@"

install-chip : configure-chip

fix_cflags = $(filter-out -DHAVE_CONFIG_H,\
$(filter-out -D,\
$(filter-out IDF_VER%,\
$(sort $(1)) -D$(filter IDF_VER%,$(1))\
)))
CHIP_CFLAGS = $(call fix_cflags,$(CFLAGS) $(CPPFLAGS))
CHIP_CXXFLAGS = $(call fix_cflags,$(CXXFLAGS) $(CPPFLAGS))

install-chip :
echo "INSTALL CHIP..."
MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory install
echo > $(OUTPUT_DIR)/args.gn
echo "import(\"//args.gni\")" >> $(OUTPUT_DIR)/args.gn
echo target_cflags_c = [$(foreach word,$(CHIP_CFLAGS),\"$(word)\",)] | sed -e 's/=\"/=\\"/g;s/\"\"/\\"\"/g;' >> $(OUTPUT_DIR)/args.gn
echo target_cflags_cc = [$(foreach word,$(CHIP_CXXFLAGS),\"$(word)\",)] | sed -e 's/=\"/=\\"/g;s/\"\"/\\"\"/g;' >> $(OUTPUT_DIR)/args.gn
echo ar_ext = \"$(AR)\" >> $(OUTPUT_DIR)/args.gn
echo cc_ext = \"$(CC)\" >> $(OUTPUT_DIR)/args.gn
echo cxx_ext = \"$(CXX)\" >> $(OUTPUT_DIR)/args.gn
echo cpu_ext = \"esp32\" >> $(OUTPUT_DIR)/args.gn
echo "Written file $(OUTPUT_DIR)/args.gn"
# MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory install
cd $(COMPONENT_PATH); gn gen $(OUTPUT_DIR)
cd $(COMPONENT_PATH); ninja -C $(OUTPUT_DIR) esp32


build : install-chip
echo "CHIP built and installed..."
cp ${OUTPUT_DIR}/lib/libCHIP.a ${OUTPUT_DIR}/libchip.a
cp -a ${OUTPUT_DIR}/lib/libCHIP.a ${OUTPUT_DIR}/libchip.a

clean:
echo "RM $(OUTPUT_DIR)"
Expand Down
1 change: 1 addition & 0 deletions config/esp32/third_party/connectedhomeip
37 changes: 37 additions & 0 deletions config/esp32/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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/gcc_toolchain.gni")

declare_args() {
ar_ext = ""
cc_ext = ""
cxx_ext = ""
cpu_ext = ""
}

gcc_toolchain("esp32") {
ar = ar_ext
cc = cc_ext
cxx = cxx_ext

toolchain_args = {
current_os = "freertos"
current_cpu = cpu_ext
is_clang = false
import("${chip_root}/src/platform/ESP32/args.gni")
}
}
2 changes: 1 addition & 1 deletion examples/wifi-echo/server/esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/third_party/connectedhomeip/config/esp32
$(PROJECT_PATH)/../../../common/screen-framework \

CXXFLAGS += -std=c++11 -Os
CPPFLAGS += -Os
CPPFLAGS += -Os -DCHIP_SEPARATE_CONFIG_H
CFLAGS += -Os

include $(IDF_PATH)/make/project.mk
13 changes: 13 additions & 0 deletions gn/build_overrides/esp32.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
4 changes: 4 additions & 0 deletions src/ble/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ buildconfig_header("ble_buildconfig") {
defines +=
[ "BLE_PLATFORM_CONFIG_INCLUDE=${chip_ble_platform_config_include}" ]
}
if (chip_device_platform == "esp32") {
defines +=
[ "BLE_PLATFORM_CONFIG_INCLUDE=${chip_ble_platform_config_include}" ]
}
}

source_set("ble_config_header") {
Expand Down
6 changes: 5 additions & 1 deletion src/crypto/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ static_library("crypto") {
public_configs = []
if (chip_crypto == "mbedtls") {
sources += [ "CHIPCryptoPALmbedTLS.cpp" ]
public_deps += [ "${mbedtls_root}:mbedtls" ]

# ESP32 has its own mbedTLS
if (target_cpu != "esp32") {
public_deps += [ "${mbedtls_root}:mbedtls" ]
}
} else if (chip_crypto == "openssl") {
sources += [ "CHIPCryptoPALOpenSSL.cpp" ]
public_configs += [ ":openssl_config" ]
Expand Down
3 changes: 3 additions & 0 deletions src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ static_library("inet") {
public_deps = [
":inet_config_header",
"${chip_root}/src/lib/support",
"${chip_root}/src/lwip:lwip_buildconfig",
"${chip_root}/src/system",
"${nlio_root}:nlio",
]

public_configs = [ "${chip_root}/src/lwip:lwip_config" ]

if (chip_inet_config_enable_raw_endpoint) {
sources += [
"RawEndPoint.cpp",
Expand Down
3 changes: 3 additions & 0 deletions src/inet/RawEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#include <lwip/ip.h>
#include <lwip/raw.h>
#include <lwip/tcpip.h>
#if CHIP_SEPARATE_CONFIG_H
#include <lwip/lwip_buildconfig.h>
#endif // CHIP_SEPARATE_CONFIG_H
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
Expand Down
3 changes: 3 additions & 0 deletions src/inet/UDPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include <lwip/ip.h>
#include <lwip/tcpip.h>
#include <lwip/udp.h>
#if CHIP_SEPARATE_CONFIG_H
#include <lwip/lwip_buildconfig.h>
#endif // CHIP_SEPARATE_CONFIG_H
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
Expand Down
19 changes: 10 additions & 9 deletions src/lwip/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (lwip_platform == "") {
}

assert(lwip_platform == "standalone" || lwip_platform == "nrf5" ||
lwip_platform == "efr32",
lwip_platform == "esp32" || lwip_platform == "efr32",
"Unsupported lwIP platform: ${lwip_platform}")

if (lwip_platform == "nrf5") {
Expand All @@ -47,15 +47,16 @@ buildconfig_header("lwip_buildconfig") {
header_dir = "lwip"

# Automatically enable LWIP_DEBUG for internal is_debug builds.
if (lwip_debug) {
lwip_debug = 1
} else {
lwip_debug = 0
defines = []
if (lwip_platform != "esp32") {
if (lwip_debug) {
lwip_debug = 1
} else {
lwip_debug = 0
}
defines += [ "LWIP_DEBUG=${lwip_debug}" ]
}
defines = [
"LWIP_DEBUG=${lwip_debug}",
"HAVE_LWIP_UDP_BIND_NETIF=1",
]
defines += [ "HAVE_LWIP_UDP_BIND_NETIF=1" ]

if (current_os == "android") {
defines += [ "LWIP_NO_STDINT_H=1" ]
Expand Down
30 changes: 30 additions & 0 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
"CHIP_DEVICE_LAYER_TARGET=EFR32",
]
}
if (chip_device_platform == "esp32") {
defines += [
"CHIP_DEVICE_LAYER_TARGET_ESP32=1",
"CHIP_DEVICE_LAYER_TARGET=ESP32",
]
}
}

config("platform_config") {
Expand Down Expand Up @@ -261,6 +267,30 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
"nRF5/ThreadStackManagerImpl.h",
]
}
} else if (chip_device_platform == "esp32") {
sources += [
"ESP32/BLEManagerImpl.cpp",
"ESP32/BLEManagerImpl.h",
"ESP32/CHIPDevicePlatformConfig.h",
"ESP32/CHIPDevicePlatformEvent.h",
"ESP32/ConfigurationManagerImpl.cpp",
"ESP32/ConfigurationManagerImpl.h",
"ESP32/ConnectivityManagerImpl.cpp",
"ESP32/ConnectivityManagerImpl.h",
"ESP32/ESP32Config.cpp",
"ESP32/ESP32Config.h",
"ESP32/ESP32Utils.cpp",
"ESP32/ESP32Utils.h",
"ESP32/Logging.cpp",
"ESP32/LwIPCoreLock.cpp",
"ESP32/NetworkProvisioningServerImpl.h",
"ESP32/PlatformManagerImpl.cpp",
"ESP32/PlatformManagerImpl.h",
"ESP32/SoftwareUpdateManagerImpl.h",
"ESP32/SystemTimeSupport.cpp",
"FreeRTOS/SystemTimeSupport.cpp",
]
# public_configs += [ "${chip_root}/src/crypto:crypto_config" ]
} else if (chip_device_platform == "efr32") {
sources += [
"EFR32/BLEManagerImpl.cpp",
Expand Down
1 change: 0 additions & 1 deletion src/platform/ESP32/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
#define CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS
#define CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS CONFIG_MAX_EXCHANGE_CONTEXTS
#define CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD CONFIG_RMP_TIMER_DEFAULT_PERIOD
#define CHIP_CONFIG_SHORT_ERROR_STR CONFIG_SHORT_ERROR_STR
#define CHIP_CONFIG_MAX_SESSION_KEYS CONFIG_MAX_SESSION_KEYS
#define CHIP_CONFIG_USE_APP_GROUP_KEYS_FOR_MSG_ENC CONFIG_USE_APP_GROUP_KEYS_FOR_MSG_ENC
#define CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS
Expand Down
Loading