Skip to content

Commit

Permalink
ESP32 - Upgrade CHIP to ESP-IDF release v4.1 (project-chip#2558)
Browse files Browse the repository at this point in the history
* ESP32 - Upgrade CHIP to ESP-IDF release v4.1

* update workflows to 0.4.4

* move to 0.4.7

* upload logs from the correct place

* no realpath on macos, write my own

* turn off ipv6 scoping in lwip

* restyle

* * fix flashing scripts to work on MacOS
* expand app partition to full extent of 2MB part

* undo attempted log fixup

* move docker images up to 4.7

* restyled

Co-authored-by: Rob Walker <[email protected]>
  • Loading branch information
dhrishi and Rob Walker authored Sep 14, 2020
1 parent 5d4da3f commit e43ecb9
Show file tree
Hide file tree
Showing 35 changed files with 326 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dockerfile": "Dockerfile",
"args": {
// "BUILD_VERSION": "$(cat integrations/docker/images/chip-build/version)" // trying to get this to work
"BUILD_VERSION": "0.4.6"
"BUILD_VERSION": "0.4.7"
}
},
"remoteUser": "vscode",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-android:0.4.6
image: connectedhomeip/chip-build-android:0.4.7
volumes:
- "/tmp/log_output:/tmp/test_logs"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bloat_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build:0.4.6
image: connectedhomeip/chip-build:0.4.7

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build:0.4.6
image: connectedhomeip/chip-build:0.4.7
volumes:
- "/tmp/log_output:/tmp/test_logs"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/examples-autotools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-esp32:0.4.6
image: connectedhomeip/chip-build-esp32:0.4.7
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
- "/tmp/output_binaries:/tmp/output_binaries"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/examples-gn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-esp32:0.4.6
image: connectedhomeip/chip-build-esp32:0.4.7
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
- "/tmp/output_binaries:/tmp/output_binaries"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-nrf-platform:0.4.1
image: connectedhomeip/chip-build-nrf-platform:0.4.7
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
- "/tmp/output_binaries:/tmp/output_binaries"
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build:0.4.6
image: connectedhomeip/chip-build:0.4.7
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
- "/tmp/output_binaries:/tmp/output_binaries"
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-efr32:0.4.6
image: connectedhomeip/chip-build-efr32:0.4.7
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
- "/tmp/output_binaries:/tmp/output_binaries"
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-nrf-platform:0.4.6
image: connectedhomeip/chip-build-nrf-platform:0.4.7
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
- "/tmp/output_binaries:/tmp/output_binaries"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/qemu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-esp32-qemu:0.4.6
image: connectedhomeip/chip-build-esp32-qemu:0.4.7
volumes:
- "/tmp/log_output:/tmp/test_logs"

Expand Down
6 changes: 3 additions & 3 deletions examples/wifi-echo/server/esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/third_party/connectedhomeip/config/esp32
$(PROJECT_PATH)/../../../common/QRCode \
$(PROJECT_PATH)/../../../common/screen-framework \

CXXFLAGS += -std=c++11 -Os
CPPFLAGS += -Os
CFLAGS += -Os
CXXFLAGS += -std=c++11 -Os -DLWIP_IPV6_SCOPES=0
CPPFLAGS += -Os -DLWIP_IPV6_SCOPES=0
CFLAGS += -Os -DLWIP_IPV6_SCOPES=0

CHIP_BUILD_WITH_GN ?= ""

Expand Down
4 changes: 2 additions & 2 deletions examples/wifi-echo/server/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ Development Framework and the xtensa-esp32-elf toolchain.
The VSCode devcontainer has these components pre-installed, so you can skip this
step. To install these components manually, follow these steps:

- Clone the Expressif ESP-IDF and checkout version 4.0
- Clone the Espressif ESP-IDF and checkout release tag v4.1

$ mkdir ${HOME}/tools
$ cd ${HOME}/tools
$ git clone https://github.com/espressif/esp-idf.git
$ cd esp-idf
$ git checkout release/v4.0
$ git checkout tags/v4.1
$ git submodule update --init
$ export IDF_PATH=${HOME}/tools/esp-idf
$ ./install.sh
Expand Down
1 change: 0 additions & 1 deletion examples/wifi-echo/server/esp32/main/EchoClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "nvs_flash.h"
#include "tcpip_adapter.h"
#include <string.h>
#include <sys/param.h>

Expand Down
7 changes: 4 additions & 3 deletions examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "RendezvousSession.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "esp_netif.h"
#include <platform/CHIPDeviceLayer.h>
#include <support/CodeUtils.h>

Expand Down Expand Up @@ -56,11 +57,11 @@ void EchoDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, int
ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
tcpip_adapter_ip_info_t ipInfo;
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo) == ESP_OK)
esp_netif_ip_info_t ipInfo;
if (esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &ipInfo) == ESP_OK)
{
char ipAddrStr[INET_ADDRSTRLEN];
IPAddress::FromIPv4(ipInfo.ip).ToString(ipAddrStr, sizeof(ipAddrStr));
esp_ip4addr_ntoa(&ipInfo.ip, ipAddrStr, sizeof(ipAddrStr));
ESP_LOGI(TAG, "Server ready at: %s:%d", ipAddrStr, CHIP_PORT);

// Since the commissioner device does not yet have a mechanism to discover the IP address
Expand Down
10 changes: 3 additions & 7 deletions examples/wifi-echo/server/esp32/main/EchoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "nvs_flash.h"
#include "tcpip_adapter.h"

#include <algorithm>
#include <stdint.h>
Expand Down Expand Up @@ -254,12 +253,9 @@ void PairingComplete(Optional<NodeId> peerNodeId, uint16_t peerKeyId, uint16_t l
// The echo server assumes the platform's networking has been setup already
void startServer()
{
CHIP_ERROR err = CHIP_NO_ERROR;
struct netif * ipV6NetIf = NULL;
tcpip_adapter_get_netif(TCPIP_ADAPTER_IF_AP, (void **) &ipV6NetIf);

err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(ipV6NetIf),
CHIP_ERROR err = CHIP_NO_ERROR;
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(NULL),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
SuccessOrExit(err);

Expand Down
12 changes: 5 additions & 7 deletions examples/wifi-echo/server/esp32/main/wifi-echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@
#include "RendezvousSession.h"
#include "ScreenManager.h"
#include "WiFiWidget.h"
#include "esp_event_loop.h"
#include "esp_heap_caps_init.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_spi_flash.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "nvs_flash.h"

#include "tcpip_adapter.h"

#include <cmath>
#include <cstdio>
#include <string>
Expand Down Expand Up @@ -348,10 +346,10 @@ void SetupPretendDevices()

void GetGatewayIP(char * ip_buf, size_t ip_len)
{
tcpip_adapter_ip_info_t ip;
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip);
IPAddress::FromIPv4(ip.ip).ToString(ip_buf, ip_len);
ESP_LOGE(TAG, "Got gateway ip %s", ip_buf);
esp_netif_ip_info_t ipInfo;
esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_AP_DEF"), &ipInfo);
esp_ip4addr_ntoa(&ipInfo.ip, ip_buf, ip_len);
ESP_LOGI(TAG, "Got gateway ip %s", ip_buf);
}

bool isRendezvousBLE()
Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# temporary wrapper build script until we can build something better
# https://github.com/project-chip/connectedhomeip/issues/710
#

set -e
find . -name Dockerfile | while read -r dockerfile; do
dir=${dockerfile%/*}
(cd "$dir" && ./build.sh "$@") || exit $?
Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/chip-build-esp32/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN set -x \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y python \
&& mkdir -p /opt/expressif \
&& cd /opt/expressif \
&& git clone --progress -b release/v4.0 https://github.com/espressif/esp-idf.git \
&& git clone --progress -b v4.1 https://github.com/espressif/esp-idf.git \
&& cd esp-idf \
&& git submodule update --init --progress \
&& IDF_TOOLS_PATH=/opt/expressif/tools ./install.sh \
Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/chip-build/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.6
0.4.7
4 changes: 2 additions & 2 deletions scripts/tools/build_esp32_flash_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

here=$(cd "$(dirname "$0")" && pwd)
build_dir="$(dirname "$1")"
bootload_file="$build_dir"/bootloader/bootloader.bin
partitions_file="$build_dir"/partitions_singleapp.bin
bootload_file="$build_dir"/bootloader.bin
partitions_file="$build_dir"/partitions.bin

"$here"/flash_image_builder.sh 0x400000 "$2" 0x1000="$bootload_file" 0x8000="$partitions_file" 0x10000="$1"
25 changes: 25 additions & 0 deletions scripts/tools/esp32_qemu_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ die() {
exit 1
}

realpath() {
path=$1 # input

[[ -z $path ]] && return 0

# trim trailing slashes
while [[ ${#path} -gt 1 && $path = */ ]]; do
path=${path%/}
done

# if we're at root we're done
if [[ $path = / ]]; then
echo "$path"
return 0
fi

[[ $path != /* ]] && path=$PWD/$path

if [[ -d $path ]]; then
(cd "$path" && pwd)
else
echo "$(realpath "${path%/*}")/${path##*/}"
fi
}

[[ $# -eq 1 ]] || usage "Incorrect number of arguments"

[[ -n $QEMU_ESP32 ]] || die "Environment variable QEMU_ESP32 is undefined."
Expand Down
6 changes: 4 additions & 2 deletions scripts/tools/flash_image_builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# source binaries at specific offset in the image
#

set -e

usage() {
exitcode=0
if [[ -n "$1" ]]; then
Expand Down Expand Up @@ -54,8 +56,8 @@ for item in "${@:3}"; do
[[ -r $file ]] || usage "Cannot read file $file"
[[ $written -le $offset ]] || usage "Writing $file at $offset will overwrite previous segment"

filesize=$(stat -c%s "$file")
written=$((written + filesize))
read -r _perms _ _user _group filesize _rest < <(ls -l "$file")
((written += filesize))
[[ $written -lt $image_size ]] || usage "Writing $file at $offset will overflow image"

dd if="$file" of="$2" conv=notrunc bs="$offset" seek=1
Expand Down
8 changes: 4 additions & 4 deletions src/lib/support/CHIPArgParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,10 @@ bool ParseSubnetId(const char * str, uint16_t & subnetId)
*/
bool ParseHexString(const char * hexStr, uint32_t strLen, uint8_t * outBuf, uint32_t outBufSize, uint32_t & outDataLen)
{
bool isFirstNibble = true;
uint8_t firstNibbleVal;
const char * p = hexStr;
uint32_t dataLen = 0;
bool isFirstNibble = true;
uint8_t firstNibbleVal = 0;
const char * p = hexStr;
uint32_t dataLen = 0;

outDataLen = 0;

Expand Down
21 changes: 20 additions & 1 deletion src/platform/ESP32/CHIPDevicePlatformEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,26 @@ struct ChipDevicePlatformEvent final
{
union
{
system_event_t ESPSystemEvent;
struct
{
esp_event_base_t Base;
int32_t Id;
union
{
ip_event_got_ip_t IpGotIp;
ip_event_got_ip6_t IpGotIp6;
ip_event_ap_staipassigned_t IpApStaIpAssigned;
wifi_event_sta_scan_done_t WifiStaScanDone;
wifi_event_sta_connected_t WifiStaConnected;
wifi_event_sta_disconnected_t WifiStaDisconnected;
wifi_event_sta_authmode_change_t WifiStaAuthModeChange;
wifi_event_sta_wps_er_pin_t WifiStaWpsErPin;
wifi_event_sta_wps_fail_reason_t WifiStaWpsErFailed;
wifi_event_ap_staconnected_t WifiApStaConnected;
wifi_event_ap_stadisconnected_t WifiApStaDisconnected;
wifi_event_ap_probe_req_rx_t WifiApProbeReqRecved;
} Data;
} ESPSystemEvent;
};
};

Expand Down
Loading

0 comments on commit e43ecb9

Please sign in to comment.