Skip to content

Commit

Permalink
ESP32: Enable gn support (first cut)
Browse files Browse the repository at this point in the history
  • Loading branch information
kedars committed Aug 25, 2020
1 parent ba63884 commit f421f55
Show file tree
Hide file tree
Showing 21 changed files with 283 additions and 42 deletions.
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")
}
36 changes: 36 additions & 0 deletions config/esp32/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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"
]
}
39 changes: 39 additions & 0 deletions config/esp32/args.gni
Original file line number Diff line number Diff line change
@@ -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.

# 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.
8 changes: 6 additions & 2 deletions src/ble/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ buildconfig_header("ble_buildconfig") {
[ "BLE_PROJECT_CONFIG_INCLUDE=${chip_ble_project_config_include}" ]
}
if (chip_ble_project_config_include != "") {
defines +=
[ "BLE_PLATFORM_CONFIG_INCLUDE=${chip_ble_platform_config_include}" ]
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}" ]
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ static_library("inet") {
"${chip_root}/src/lib/support",
"${chip_root}/src/system",
"${nlio_root}:nlio",
"${chip_root}/src/lwip:lwip_buildconfig",
]

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

if (chip_inet_config_enable_raw_endpoint) {
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
8 changes: 0 additions & 8 deletions src/lib/core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ import("${chip_root}/gn/chip/tests.gni")
import("${chip_root}/src/inet/inet.gni")
import("core.gni")

declare_args() {
cflags_c_ext = []
cflags_cc_ext = []
}

buildconfig_header("chip_buildconfig") {
header = "CHIPBuildConfig.h"
header_dir = "core"
Expand Down Expand Up @@ -115,9 +110,6 @@ static_library("core") {
"CHIPTLVWriter.cpp",
]

cflags_c = cflags_c_ext
cflags_cc = cflags_cc_ext

public_deps = [
":chip_config_header",
"${chip_root}/src/ble",
Expand Down
19 changes: 12 additions & 7 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,13 +47,18 @@ 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}",
defines += [
"HAVE_LWIP_UDP_BIND_NETIF=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/ConfigurationManagerImpl.cpp",
"ESP32/PlatformManagerImpl.cpp",
"ESP32/ConnectivityManagerImpl.cpp",
"ESP32/ESP32Config.cpp",
"ESP32/ESP32Utils.cpp",
"ESP32/Logging.cpp",
"ESP32/SystemTimeSupport.cpp",
"ESP32/LwIPCoreLock.cpp",
"ESP32/CHIPDevicePlatformConfig.h",
"ESP32/ConnectivityManagerImpl.h",
"ESP32/BLEManagerImpl.h",
"ESP32/ConfigurationManagerImpl.h",
"ESP32/PlatformManagerImpl.h",
"ESP32/SoftwareUpdateManagerImpl.h",
"ESP32/CHIPDevicePlatformEvent.h",
"ESP32/NetworkProvisioningServerImpl.h",
"ESP32/ESP32Utils.h",
"ESP32/ESP32Config.h",
"FreeRTOS/SystemTimeSupport.cpp",
]
# public_configs += [ "${chip_root}/src/crypto:crypto_config" ]
} else if (chip_device_platform == "efr32") {
sources += [
"EFR32/BLEManagerImpl.cpp",
Expand Down
Loading

0 comments on commit f421f55

Please sign in to comment.