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

ESP32 gn support #2325

Merged
merged 21 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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" ]
}
41 changes: 41 additions & 0 deletions config/esp32/args.gni
Original file line number Diff line number Diff line change
@@ -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.

# 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 = ""

mbedtls_target = "//mbedtls:mbedtls"
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
42 changes: 29 additions & 13 deletions config/esp32/components/chip/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,18 @@ 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
endif

# Tell the ESP-IDF build system that the CHIP component defines its own build
# and clean targets.
Expand Down Expand Up @@ -193,13 +188,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 : $(OUTPUT_DIR)
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 esp32_ar = \"$(AR)\" >> $(OUTPUT_DIR)/args.gn
echo esp32_cc = \"$(CC)\" >> $(OUTPUT_DIR)/args.gn
echo esp32_cxx = \"$(CXX)\" >> $(OUTPUT_DIR)/args.gn
echo esp32_cpu = \"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
22 changes: 22 additions & 0 deletions config/esp32/mbedtls/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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")

# ESP32 has its own mbedtls, so nothing to do, just provide a target
group("mbedtls") {
}
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() {
esp32_ar = ""
esp32_cc = ""
esp32_cxx = ""
esp32_cpu = ""
}

gcc_toolchain("esp32") {
ar = esp32_ar
cc = esp32_cc
cxx = esp32_cxx

toolchain_args = {
current_os = "freertos"
current_cpu = esp32_cpu
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.
2 changes: 1 addition & 1 deletion src/ble/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ buildconfig_header("ble_buildconfig") {
defines +=
[ "BLE_PROJECT_CONFIG_INCLUDE=${chip_ble_project_config_include}" ]
}
if (chip_ble_project_config_include != "") {
if (chip_ble_platform_config_include != "") {
defines +=
[ "BLE_PLATFORM_CONFIG_INCLUDE=${chip_ble_platform_config_include}" ]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this block intended to be added? It looks like BLE_PLATFORM_CONFIG_INCLUDE is set twice here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the upper 'if' condition had a typo, fixed.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andrei is adding this to arch.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
29 changes: 29 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,29 @@ 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",
]
} else if (chip_device_platform == "efr32") {
sources += [
"EFR32/BLEManagerImpl.cpp",
Expand Down
Loading