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

silabs-multiprotocol: Add amd64 support #2757

Merged
merged 9 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions silabs-multiprotocol/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.8.0

- Initial AMD64/x86-64 support (zigbeed via QEMU)

## 0.7.2

- Fix OTBR enable flag (allow to disable the OTBR)
Expand Down
229 changes: 229 additions & 0 deletions silabs-multiprotocol/Dockerfile.amd64
Original file line number Diff line number Diff line change
@@ -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" \
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"]
1 change: 1 addition & 0 deletions silabs-multiprotocol/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion silabs-multiprotocol/config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,6 +8,7 @@ url: >
arch:
- armv7
- aarch64
- amd64
hassio_api: true
# IPC is only used within the Add-on
host_ipc: false
Expand Down
12 changes: 12 additions & 0 deletions silabs-multiprotocol/execvp-aarch64.patch
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions silabs-multiprotocol/rootfs.amd64/usr/local/bin/zigbeed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "Starting zigbeed with aarch64 emulation..."
agners marked this conversation as resolved.
Show resolved Hide resolved
exec /usr/bin/qemu-aarch64 /usr/local/bin/zigbeed.aarch64 "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -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}