Skip to content

Commit 97f0ec1

Browse files
Add an OpenThread RCP firmware package based on openthread/ot-nrf528xx (#39)
* Mark host-only packages as build-only * Add an OpenThread RCP firmware package based on openthread/ot-nrf528xx This initial version targets the NRF528408 MDK dongle because the UF2 bootloader makes it very easy to flash with minimal tooling. Also add an otbr-rcp script for finding / managing USB RCPs and use it to add hot plugging support to the otbr-agent service. Miscellaneous improvements: - Avoid clobbering /etc/config/otbr-agent - Add default configuration for a 'thread' firewall zone - Minor patches to otbr-agent to improve RCP device handling * Address suggestion from review * Address parse_uint32 error hanling per review
1 parent 57281ce commit 97f0ec1

21 files changed

Lines changed: 1453 additions & 141 deletions

File tree

.config.ci

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ CONFIG_PACKAGE_matter-netman-mbedtls=m
66
CONFIG_PACKAGE_matter-netman-openssl=m
77
CONFIG_PACKAGE_mdnsresponder=m
88
CONFIG_PACKAGE_openthread-br=m
9+
CONFIG_PACKAGE_openthread-rcp-nrf52840-mdk=m
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright (c) 2026 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
include $(TOPDIR)/rules.mk
16+
17+
PKG_NAME:=arm-gnu-rm-toolchain
18+
UPSTREAM_VERSION:=10.3-2021.10
19+
PKG_VERSION:=$(subst -,.,$(UPSTREAM_VERSION))
20+
21+
PrebuiltTarball=gcc-arm-none-eabi-$(UPSTREAM_VERSION)-$(1).tar.bz2
22+
define Download/prebuilt
23+
URL:=https://developer.arm.com/-/media/files/downloads/gnu-rm/$(UPSTREAM_VERSION)/
24+
FILE:=$(call PrebuiltTarball,$(1))
25+
endef
26+
define Download/x86_64-linux
27+
$(call Download/prebuilt,x86_64-linux)
28+
MD5SUM:=2383e4eb4ea23f248d33adc70dc3227e
29+
endef
30+
define Download/aarch64-linux
31+
$(call Download/prebuilt,aarch64-linux)
32+
MD5SUM:=3fe3d8bb693bd0a6e4615b6569443d0d
33+
endef
34+
define Download/mac
35+
$(call Download/prebuilt,mac)
36+
MD5SUM:=7f2a7b7b23797302a9d6182c6e482449
37+
endef
38+
39+
PKG_LICENSE:=GPL-3.0-or-later LGPL-3.0-or-later MIT Zlib
40+
PKG_LICENSE_FILES:=license.txt
41+
42+
PKG_HOST_ONLY:=1
43+
44+
include $(INCLUDE_DIR)/package.mk
45+
include $(INCLUDE_DIR)/host-build.mk
46+
47+
define Package/arm-gnu-rm-toolchain
48+
SECTION:=devel
49+
CATEGORY:=Development
50+
TITLE:=arm-gnu-rm-toolchain
51+
URL:=https://developer.arm.com/downloads/-/gnu-rm
52+
BUILDONLY:=1
53+
endef
54+
55+
define Package/arm-gnu-rm-toolchain/description
56+
The GNU Arm Embedded Toolchain for 32-bit Arm Cortex-A, Arm Cortex-M, and Arm Cortex-R processor families.
57+
endef
58+
59+
PREBUILT_FLAVOR:=$(if $(filter Darwin,$(HOST_OS)),mac,$(HOST_ARCH)-$(call tolower,$(HOST_OS)))
60+
PREBUILT_TARBALL:=$(DL_DIR)/$(call PrebuiltTarball,$(PREBUILT_FLAVOR))
61+
$(if $(strip $(Download/$(PREBUILT_FLAVOR))),$(eval $(call Download,$(PREBUILT_FLAVOR))))
62+
63+
Host/Prepare:=$(empty)
64+
Host/Configure:=$(empty)
65+
66+
define Host/Compile
67+
test -f $(PREBUILT_TARBALL) || { echo "ERROR: Unsupported host platform '$(PREBUILT_FLAVOR)'"; false; }
68+
endef
69+
70+
define Host/Install
71+
bzcat $(PREBUILT_TARBALL) | $(HOST_TAR) -C $(1) --strip-components 1 -xf -
72+
endef
73+
74+
$(eval $(call BuildPackage,arm-gnu-rm-toolchain))
75+
$(eval $(call HostBuild))

devel/gn/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023 Project CHIP Authors
1+
# Copyright (c) 2023-2026 Project CHIP Authors
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ define Package/gn
4444
CATEGORY:=Development
4545
TITLE:=gn
4646
URL:=https://gn.googlesource.com/gn
47+
BUILDONLY:=1
4748
endef
4849

4950
define Package/gn/description

devel/python3-host-ssl/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2025 Project CHIP Authors
1+
# Copyright (c) 2025-2026 Project CHIP Authors
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ define Package/python3-host-ssl
2929
SECTION:=lang
3030
CATEGORY:=Languages
3131
TITLE:=Python3 host package SSL configuration
32+
BUILDONLY:=1
3233
endef
3334

3435
define Package/python3-host-ssl/description

third_party/openthread-br/Makefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
include $(TOPDIR)/rules.mk
3030

3131
PKG_NAME:=openthread-br
32-
PKG_RELEASE:=1
32+
PKG_RELEASE:=2
3333
PKG_SOURCE_URL:=https://github.com/openthread/ot-br-posix.git
3434
PKG_SOURCE_PROTO:=git-with-metadata
3535
PKG_SOURCE_MIRROR:=0 # don't try OpenWrt mirror
@@ -119,7 +119,7 @@ endef
119119

120120
# Disable firewall integration due to https://github.com/openthread/ot-br-posix/issues/1675
121121
CMAKE_OPTIONS+= \
122-
-DOTBR_GIT_VERSION=$(call GitWithMetadata/resolve,OTBR_GIT_VERSION) \
122+
-DOTBR_GIT_VERSION=$(call GitWithMetadata/resolve,OTBR_GIT_VERSION)$(if $(PKG_RELEASE),-r$(PKG_RELEASE)) \
123123
-DOT_PACKAGE_VERSION=$(call GitWithMetadata/resolve,OT_GIT_VERSION) \
124124
-DCMAKE_BUILD_TYPE=$(if $(CONFIG_DEBUG),Debug,Release) \
125125
-DCMAKE_INSTALL_PREFIX=/usr \
@@ -134,9 +134,10 @@ CMAKE_OPTIONS+= \
134134
-DOT_POSIX_SETTINGS_PATH=\"/etc/openthread\" \
135135
-DOT_READLINE=OFF
136136

137-
# OpenWrt uses /var/run instead of /run
138137
TARGET_CFLAGS+= \
139138
-DOPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME=\\\"/var/run/openthread-%s\\\" \
139+
-DOPENTHREAD_POSIX_CONFIG_SETTINGS_USE_INTERFACE_NAME=1 \
140+
-DOPENTHREAD_POSIX_CONFIG_TMP_STORAGE_ENABLE=0 \
140141
-DOPENTHREAD_CONFIG_LOG_PREPEND_UPTIME=0 \
141142
-DOPENTHREAD_CONFIG_LOG_PREPEND_LEVEL=0
142143

@@ -151,18 +152,18 @@ CMAKE_OPTIONS+= -DOTBR_MDNS=mDNSResponder
151152
endif
152153

153154
define Package/openthread-br/install
154-
$(INSTALL_DIR) $(1)/usr/sbin
155+
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/config $(1)/etc/uci-defaults $(1)/etc/hotplug.d/usb
155156
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/otbr-agent $(1)/usr/sbin
156157
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/ot-ctl $(1)/usr/sbin
157-
158-
$(INSTALL_DIR) $(1)/etc/init.d
159-
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/etc/init.d/* $(1)/etc/init.d
160-
161-
$(INSTALL_DIR) $(1)/etc/config
162-
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/config/* $(1)/etc/config
158+
$(INSTALL_BIN) ./files/otbr-rcp $(1)/usr/sbin
159+
$(INSTALL_BIN) ./files/otbr-agent.init $(1)/etc/init.d/otbr-agent
160+
$(INSTALL_CONF) ./files/otbr-agent.config $(1)/etc/config/otbr-agent
161+
$(INSTALL_DATA) ./files/otbr-agent.defaults $(1)/etc/uci-defaults/95-otbr-agent
162+
$(INSTALL_DATA) ./files/otbr-rcp.hotplug $(1)/etc/hotplug.d/usb/50-otbr-rcp
163163
endef
164164

165165
define Package/openthread-br/conffiles
166+
/etc/config/otbr-agent
166167
/etc/openthread/
167168
endef
168169

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config otbr-agent 'wpan0'
2+
option infra_if_name 'br-lan'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2026 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# If the firewall is configured and the default otbr-agent instance
16+
# exists, create a thread zone with forwarding to and from lan.
17+
uci -q get firewall >/dev/null \
18+
&& [ "$(uci -q get otbr-agent.wpan0)" = "otbr-agent" ] \
19+
&& ! uci -q get otbr-agent.wpan0.thread_if_name >/dev/null \
20+
&& ! uci -q show firewall | grep -q "^firewall\.@zone\[[0-9]*\]\.name='thread'" \
21+
&& uci batch <<EOF >/dev/null
22+
add firewall zone
23+
set firewall.@zone[-1].name='thread'
24+
set firewall.@zone[-1].input='ACCEPT'
25+
set firewall.@zone[-1].output='ACCEPT'
26+
set firewall.@zone[-1].forward='ACCEPT'
27+
set firewall.@zone[-1].family='ipv6'
28+
set firewall.@zone[-1].device='wpan0'
29+
add firewall forwarding
30+
set firewall.@forwarding[-1].src='thread'
31+
set firewall.@forwarding[-1].dest='lan'
32+
add firewall forwarding
33+
set firewall.@forwarding[-1].src='lan'
34+
set firewall.@forwarding[-1].dest='thread'
35+
commit firewall
36+
EOF
37+
38+
exit 0
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh /etc/rc.common
2+
3+
# Copyright (c) 2026 Project CHIP Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
START=90
18+
19+
USE_PROCD=1
20+
AGENT_PROG=/usr/sbin/otbr-agent
21+
RCP_PROG=/usr/sbin/otbr-rcp
22+
23+
validate_section_otbr()
24+
{
25+
uci_load_validate otbr-agent otbr-agent "$1" "$2" \
26+
'thread_if_name:string' \
27+
'infra_if_name:string' \
28+
'uart_device:string:any' \
29+
'uart_baudrate:uinteger:0' \
30+
'uart_flow_control:bool:1' \
31+
'rcp_hotplug:bool:1' \
32+
'rcp_firmware_update:bool:1'
33+
}
34+
35+
otbr_instance()
36+
{
37+
local cfg="$1"
38+
if [ "$2" != 0 ]; then
39+
echo "validation failed"
40+
return 1
41+
fi
42+
if [ -z "$infra_if_name" ]; then
43+
echo "missing infra_if_name"
44+
return 1
45+
fi
46+
47+
local radio_url
48+
if [ "${uart_device#/dev/}" != "${uart_device}" ]; then
49+
# Directly run otbr-agent with the specified /dev/* device
50+
set -- "$AGENT_PROG"
51+
radio_url="spinel+hdlc+uart://${uart_device}"
52+
else
53+
# Use the otbr-rcp wrapper to locate the device
54+
set -- "$RCP_PROG"
55+
[ "$rcp_hotplug" -eq 0 ] || set -- "$@" --wait
56+
[ "$rcp_firmware_update" -eq 0 ] || set -- "$@" --update
57+
set -- "$@" "$uart_device" --
58+
radio_url="%rcpurl%"
59+
fi
60+
radio_url="${radio_url}?uart-exclusive"
61+
[ "$uart_baudrate" -eq 0 ] || radio_url="${radio_url}&uart-baudrate=${uart_baudrate}"
62+
[ "$uart_flow_control" -eq 0 ] || radio_url="${radio_url}&uart-flow-control"
63+
64+
procd_open_instance
65+
procd_set_param command "$@" -I "${thread_if_name:-$cfg}" -B "$infra_if_name" "${radio_url}" "trel://${infra_if_name}"
66+
procd_set_param respawn
67+
procd_close_instance
68+
}
69+
70+
start_service()
71+
{
72+
config_load otbr-agent
73+
config_foreach validate_section_otbr otbr-agent otbr_instance
74+
}

0 commit comments

Comments
 (0)