diff --git a/silabs-multiprotocol/CHANGELOG.md b/silabs-multiprotocol/CHANGELOG.md index 8763e9e34f3..5fb089583de 100644 --- a/silabs-multiprotocol/CHANGELOG.md +++ b/silabs-multiprotocol/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.8.0 + +- Initial AMD64/x86-64 support (zigbeed via QEMU) +- Increase multicast table size to 16 (as expected by ZHA by default) + ## 0.7.2 - Fix OTBR enable flag (allow to disable the OTBR) diff --git a/silabs-multiprotocol/Dockerfile b/silabs-multiprotocol/Dockerfile index 5250daabe90..c44ca0933c8 100644 --- a/silabs-multiprotocol/Dockerfile +++ b/silabs-multiprotocol/Dockerfile @@ -116,7 +116,7 @@ RUN \ CC="${DEBIAN_CROSS_PREFIX}-gcc" \ LD="${DEBIAN_CROSS_PREFIX}-gcc" \ CXX="${DEBIAN_CROSS_PREFIX}-g++" \ - C_FLAGS="-std=gnu99" \ + C_FLAGS="-std=gnu99 -DEMBER_MULTICAST_TABLE_SIZE=16" \ debug FROM $BUILD_FROM diff --git a/silabs-multiprotocol/Dockerfile.amd64 b/silabs-multiprotocol/Dockerfile.amd64 new file mode 100644 index 00000000000..984470092a3 --- /dev/null +++ b/silabs-multiprotocol/Dockerfile.amd64 @@ -0,0 +1,229 @@ +ARG BUILD_FROM +ARG BUILD_ARCH +FROM --platform=linux/amd64 debian:bullseye AS cross-builder-base + +ENV \ + LANG="C.UTF-8" \ + DEBIAN_FRONTEND="noninteractive" \ + CURL_CA_BUNDLE="/etc/ssl/certs/ca-certificates.crt" + +WORKDIR /usr/src + +# Allow to reuse downloaded packages (these are only staged build images) +# hadolint ignore=DL3009 +RUN \ + set -x \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + bash \ + curl \ + ca-certificates \ + build-essential \ + git + +FROM --platform=linux/amd64 cross-builder-base AS cross-builder-aarch64 + +COPY debian-arm64.cmake /usr/src/debian.cmake + +ENV DEBIAN_ARCH=arm64 +ENV DEBIAN_CROSS_PREFIX=aarch64-linux-gnu +ENV SLC_ARCH=linux_arch_64 + +RUN \ + set -x \ + && dpkg --add-architecture arm64 \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + crossbuild-essential-arm64 + +FROM --platform=linux/amd64 cross-builder-base AS cpcd-builder + +ARG CPCD_VERSION=v4.1.2 + +RUN \ + set -x \ + && apt-get install -y --no-install-recommends \ + cmake \ + "libmbedtls-dev" \ + "libmbedtls12" \ + && git clone --depth 1 -b "${CPCD_VERSION}" \ + https://github.com/SiliconLabs/cpc-daemon.git \ + && mkdir cpc-daemon/build && cd cpc-daemon/build \ + && cmake ../ \ + -DENABLE_ENCRYPTION=FALSE \ + && make \ + && make install + + +FROM --platform=linux/amd64 cross-builder-aarch64 AS cpcd-cross-builder + +ARG CPCD_VERSION=v4.1.2 + +RUN \ + set -x \ + && apt-get install -y --no-install-recommends \ + cmake \ + "libmbedtls-dev:${DEBIAN_ARCH}" \ + "libmbedtls12:${DEBIAN_ARCH}" \ + && git clone --depth 1 -b "${CPCD_VERSION}" \ + https://github.com/SiliconLabs/cpc-daemon.git \ + && mkdir cpc-daemon/build && cd cpc-daemon/build \ + && cmake ../ \ + -DCMAKE_TOOLCHAIN_FILE=../debian.cmake \ + -DENABLE_ENCRYPTION=FALSE \ + && make \ + && make install + +FROM --platform=linux/amd64 cross-builder-aarch64 AS zigbeed-cross-builder + +ARG GECKO_SDK_VERSION=v4.1.3 + +RUN \ + set -x \ + && apt-get install -y --no-install-recommends \ + python3 \ + python3-jinja2 \ + python3-pip \ + openjdk-11-jre \ + git-lfs \ + unzip \ + && curl -O https://www.silabs.com/documents/login/software/slc_cli_linux.zip \ + && unzip slc_cli_linux.zip \ + && cd slc_cli/ && chmod +x slc + +ENV PATH="/usr/src/slc_cli/:$PATH" + +RUN \ + set -x \ + && git clone --depth 1 -b ${GECKO_SDK_VERSION} \ + https://github.com/SiliconLabs/gecko_sdk.git + +# zigbeed links against libcpc.so +COPY --from=cpcd-cross-builder /usr/local/ /usr/aarch64-linux-gnu/ +COPY 0001-Use-TCP-socket-instead-of-serial-port.patch /usr/src +COPY execvp-aarch64.patch /usr/src + +RUN \ + set -x \ + && cd gecko_sdk \ + && slc signature trust --sdk=. \ + && cd protocol/zigbee \ + && slc generate \ + --sdk=../.. \ + --with="${SLC_ARCH}" -p=app/zigbeed/zigbeed.slcp \ + --export-destination=app/zigbeed/output \ + --copy-sdk-sources --copy-proj-sources \ + && cd app/zigbeed/output \ + && patch -p1 < /usr/src/0001-Use-TCP-socket-instead-of-serial-port.patch \ + && patch -p1 < /usr/src/execvp-aarch64.patch \ + && make -f zigbeed.Makefile \ + AR="${DEBIAN_CROSS_PREFIX}-ar" \ + CC="${DEBIAN_CROSS_PREFIX}-gcc" \ + LD="${DEBIAN_CROSS_PREFIX}-gcc" \ + CXX="${DEBIAN_CROSS_PREFIX}-g++" \ + C_FLAGS="-std=gnu99 -DEMBER_MULTICAST_TABLE_SIZE=16" \ + debug + +FROM $BUILD_FROM + +RUN \ + set -x \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + libmbedtls12 \ + socat \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /usr/src/* + + +COPY --from=zigbeed-cross-builder \ + /usr/src/gecko_sdk/util/third_party/ot-br-posix /usr/src/ot-br-posix +COPY --from=zigbeed-cross-builder \ + /usr/src/gecko_sdk/util/third_party/openthread /usr/src/openthread +COPY --from=cpcd-builder /usr/local/ /usr/local/ + +ENV BORDER_ROUTING=1 +ENV BACKBONE_ROUTER=1 +ENV OTBR_OPTIONS "-DOTBR_DBUS=OFF -DOT_MULTIPAN_RCP=ON -DOT_POSIX_CONFIG_RCP_BUS=CPC -DOT_LINK_RAW=1 -DOTBR_VENDOR_NAME=HomeAssistant -DOTBR_PRODUCT_NAME=OpenThreadBorderRouter" +ENV WEB_GUI=1 +ENV DOCKER 1 + +COPY 0001-Avoid-writing-to-system-console.patch /usr/src +COPY replace-the-source-of-mDNSResponder.patch /usr/src + +# Required and installed during build (script/bootstrap), could be removed +ENV OTBR_BUILD_DEPS build-essential ninja-build cmake wget ca-certificates \ + libreadline-dev libncurses-dev libcpputest-dev libdbus-1-dev libavahi-common-dev \ + libavahi-client-dev libboost-dev libboost-filesystem-dev libboost-system-dev \ + libnetfilter-queue-dev + +# Build OTBR natively from Gecko SDK sources +WORKDIR /usr/src +RUN \ + set -x \ + && apt-get update \ + # Install npm/nodejs for WebUI manually to avoid systemd getting pulled in \ + && apt-get install -y --no-install-recommends \ + nodejs \ + npm \ + iproute2 \ + patch \ + python3 \ + python3-dev \ + python3-pip \ + python3-aiohttp \ + python3-cryptography \ + python3-yarl \ + lsb-release \ + sudo \ + && cd ot-br-posix \ + && patch -p1 < /usr/src/replace-the-source-of-mDNSResponder.patch \ + && chmod +x ./script/bootstrap \ + && ./script/bootstrap \ + && ln -s ../../../openthread/ third_party/openthread/repo \ + && chmod +x ./script/* \ + && patch -p1 < /usr/src/0001-Avoid-writing-to-system-console.patch \ + && ./script/setup \ + && pip install universal-silabs-flasher==0.0.7 \ + && apt-get purge -y --auto-remove \ + build-essential \ + patch \ + python3-pip \ + python3-dev \ + git \ + git-lfs \ + libmbedtls-dev \ + ${OTBR_BUILD_DEPS} \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /usr/src/* + +COPY --from=cpcd-cross-builder /usr/local/lib/* /usr/lib/aarch64-linux-gnu/ + +RUN \ + set -x \ + && dpkg --add-architecture arm64 \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + qemu-user \ + libmbedtls12:arm64 \ + libstdc++6:arm64 \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /usr/src/* + +COPY --from=zigbeed-cross-builder \ + /usr/src/gecko_sdk/protocol/zigbee/app/zigbeed/output/build/debug/zigbeed \ + /usr/local/bin/zigbeed.aarch64 + +RUN ldconfig && touch /accept_silabs_msla + +COPY rootfs / +COPY rootfs.amd64 / + +ENV \ + S6_STAGE2_HOOK=/etc/s6-overlay/scripts/otbr-enable-check.sh + +HEALTHCHECK --interval=10s --start-period=120s CMD [ "$(s6-svstat -u /run/service/zigbeed)" = "true" ] + +# use s6-overlay as init system +WORKDIR / +ENTRYPOINT ["/init"] diff --git a/silabs-multiprotocol/build.yaml b/silabs-multiprotocol/build.yaml index b0ac06731ba..611f9adc36f 100644 --- a/silabs-multiprotocol/build.yaml +++ b/silabs-multiprotocol/build.yaml @@ -2,6 +2,7 @@ build_from: aarch64: ghcr.io/home-assistant/aarch64-base-debian:bullseye armv7: ghcr.io/home-assistant/armv7-base-debian:bullseye + amd64: ghcr.io/home-assistant/amd64-base-debian:bullseye args: CPCD_VERSION: v4.1.2 GECKO_SDK_VERSION: v4.1.3 diff --git a/silabs-multiprotocol/config.yaml b/silabs-multiprotocol/config.yaml index aab5d847260..29ffaf38d92 100644 --- a/silabs-multiprotocol/config.yaml +++ b/silabs-multiprotocol/config.yaml @@ -1,5 +1,5 @@ --- -version: 0.7.2 +version: 0.8.0 slug: silabs_multiprotocol name: Silicon Labs Multiprotocol description: Zigbee and OpenThread multiprotocol add-on @@ -8,6 +8,7 @@ url: > arch: - armv7 - aarch64 + - amd64 hassio_api: true # IPC is only used within the Add-on host_ipc: false diff --git a/silabs-multiprotocol/execvp-aarch64.patch b/silabs-multiprotocol/execvp-aarch64.patch new file mode 100644 index 00000000000..b4113daee71 --- /dev/null +++ b/silabs-multiprotocol/execvp-aarch64.patch @@ -0,0 +1,12 @@ +diff --git a/main.c b/main.c +index 31a0352..0e5f1ed 100644 +--- a/main.c ++++ b/main.c +@@ -96,6 +96,7 @@ int main(void) + if (setjmp(gResetJump)) { + serialShutdown(); + fprintf(stderr, "Restarting\n"); ++ argv[0] = "/usr/local/bin/zigbeed"; + execvp(argv[0], argv); + } + #endif //UNIX_HOST diff --git a/silabs-multiprotocol/rootfs.amd64/usr/local/bin/zigbeed b/silabs-multiprotocol/rootfs.amd64/usr/local/bin/zigbeed new file mode 100755 index 00000000000..3df8a3446a8 --- /dev/null +++ b/silabs-multiprotocol/rootfs.amd64/usr/local/bin/zigbeed @@ -0,0 +1,4 @@ +#!/bin/sh + +# Starting zigbeed with aarch64 emulation... +exec /usr/bin/qemu-aarch64 /usr/local/bin/zigbeed.aarch64 "$@" diff --git a/silabs-multiprotocol/rootfs/etc/s6-overlay/s6-rc.d/zigbeed/run b/silabs-multiprotocol/rootfs/etc/s6-overlay/s6-rc.d/zigbeed/run index 46f04f4dac9..dd2c2c3e6d8 100755 --- a/silabs-multiprotocol/rootfs/etc/s6-overlay/s6-rc.d/zigbeed/run +++ b/silabs-multiprotocol/rootfs/etc/s6-overlay/s6-rc.d/zigbeed/run @@ -14,7 +14,6 @@ if ! bashio::var.has_value "${ezsp_listen_port}"; then fi bashio::log.info "Starting zigbeed..." -exec "/usr/bin/stdbuf" -o0 \ - /usr/local/bin/zigbeed --radio-url "spinel+cpc://cpcd_0?iid=1" \ +exec /usr/local/bin/zigbeed --radio-url "spinel+cpc://cpcd_0?iid=1" \ --ezsp-listen ${ezsp_listen} \ --ezsp-listen-port ${ezsp_listen_port}