Skip to content

examples/advanced/suit_update: simplify setup #21565

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 17 additions & 13 deletions examples/advanced/suit_update/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ endif

# Change this to 0 to not use ethos
USE_ETHOS ?= 1
# see SUIT_CLIENT and SUIT_COAP_SERVER
SUIT_COAP_SERVER_PREFIX ?= 2001:db8::/64
# you may need to run dist/tools/tapsetup/tapsetup to create tap0
SUIT_COAP_SERVER_IFACE ?= tap0

ifeq (1,$(USE_ETHOS))
USEMODULE += stdio_ethos
Expand All @@ -76,15 +80,8 @@ ifeq (1,$(USE_ETHOS))

# make sure ethos and uhcpd are built
TERMDEPS += host-tools

# For local testing, run
#
# $ cd dist/tools/ethos; sudo ./setup_network.sh riot0 2001:db8::0/64
#
#... in another shell and keep it running.
IFACE ?= riot0
TERMPROG = $(RIOTTOOLS)/ethos/ethos
TERMFLAGS = $(IFACE) $(PORT)
TERMPROG = $(RIOTTOOLS)/ethos/start_network.sh
TERMFLAGS = $(PORT) $(SUIT_COAP_SERVER_IFACE) $(SUIT_COAP_SERVER_PREFIX)
else
USEMODULE += netdev_default
endif
Expand All @@ -107,12 +104,12 @@ TESTRUNNER_RESET_AFTER_TERM ?= 1
# with ed25519 support.
TEST_ON_CI_BLACKLIST = all

# Add custom SUIT targets and constants before including the global Makefile.include
include $(CURDIR)/Makefile.suit.custom

# Include global Makefile.include first to apply board aliasses
include $(RIOTBASE)/Makefile.include

# Add custom SUIT targets
include $(CURDIR)/Makefile.suit.custom

# export IFACE for test
$(call target-export-variables,test-with-config test-with-config/check-config,IFACE)
# export BOARD
Expand All @@ -130,9 +127,16 @@ ifndef CONFIG_GNRC_PKTBUF_SIZE
endif
endif

.PHONY: host-tools
.PHONY: host-tools suit_coap_server

host-tools:
$(Q)env -u CC -u CFLAGS $(MAKE) -C $(RIOTTOOLS)

suit_coap_server:
aiocoap-fileserver --bind [::] $(SUIT_COAP_FSROOT)

include $(RIOTMAKE)/default-radio-settings.inc.mk

ifneq (1,$(USE_ETHOS))
TERMPROG := $(CURDIR)/start_network.sh -r $(SUIT_COAP_SERVER_PREFIX) -i $(SUIT_COAP_SERVER_IFACE) $(TERMPROG)
endif
8 changes: 3 additions & 5 deletions examples/advanced/suit_update/Makefile.suit.custom
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ EPOCH = $(call memoized,EPOCH,$(shell date +%s))
APP_VER ?= $(EPOCH)

# Default addressing if following README.native.md
ifneq (,$(filter native native32 native64,$(BOARD)))
SUIT_CLIENT ?= [2001:db8::2]
SUIT_COAP_SERVER ?= [2001:db8::1]
$(call target-export-variables,test-with-config,SUIT_COAP_SERVER)
endif
SUIT_CLIENT ?= [2001:db8::2]
SUIT_COAP_SERVER ?= [2001:db8::1]
$(call target-export-variables,test-with-config,SUIT_COAP_SERVER)

ifneq (,$(filter native native32 native64,$(BOARD)))
# Set settings for publishing fake fw payloads to native
Expand Down
92 changes: 92 additions & 0 deletions examples/advanced/suit_update/start_network.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new script is missing a license header and Shellcheck has some warnings too.

You can also use the new SPDX header style: see #21515

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh
#
# SPDX-FileCopyrightText: Copyright (C) 2025 ML!PA Consulting GmbH, All rights reserved

SCRIPT_DIR="$(dirname $(readlink -f $0))"

Check warning on line 5 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Quote this to prevent word splitting. [SC2046]

Check warning on line 5 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
RIOTBASE=${RIOTBASE:-${SCRIPT_DIR}/../../..}

init_iface() {
sudo sysctl -w net.ipv6.conf.${IFACE}.forwarding=1
sudo sysctl -w net.ipv6.conf.${IFACE}.accept_ra=0

Check warning on line 10 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
sudo ip a a fe80::${PREFIX_IID}/64 dev ${IFACE}

Check warning on line 11 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
sudo ip a a ${PREFIX}${PREFIX_IID}/128 dev ${IFACE}

Check warning on line 12 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
sudo ip link set ${IFACE} up

Check warning on line 13 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
}

deinit_iface() {
sudo ip a d fe80::${PREFIX_IID}/64 dev ${IFACE}

Check warning on line 17 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
sudo ip a d ${PREFIX}${PREFIX_IID}/128 dev ${IFACE}

Check warning on line 18 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
}

cleanup() {
echo "Cleaning up..."
deinit_iface
trap "" INT QUIT TERM EXIT
}

start_radvd() {
sudo sysctl net.ipv6.conf."${IFACE}".accept_ra=2
sudo sysctl net.ipv6.conf."${IFACE}".accept_ra_rt_info_max_plen=64
sudo ${RADVD} -c ${IFACE} ${PREFIX}/${PREFIX_LEN}

Check warning on line 30 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
}

USE_RADVD=0
POSITIONAL_ARGS=

while [ $# -gt 0 ]; do
case $1 in
-h|--help)
echo "Environment variables:"
echo ""
echo "Usage: $0 [-r|--radvd] <PREFIX_WITH_LENGTH>"
echo " [-i|--iface] <INTERFACE_NAME>"
exit 0
;;
-r|--radvd)
USE_RADVD=1
ARG_PREFIX="$2"
shift # past argument
shift # past value
;;
-i|--iface)
ARG_IFACE="$2"
shift # past argument
shift # past value
;;
*)
POSITIONAL_ARGS="$POSITIONAL_ARGS $1"
shift # past argument
;;
esac
done

eval "set -- $POSITIONAL_ARGS"

IFACE="${1:-tap0}"
PREFIX_IID="1"

if [ ! -z ${ARG_IFACE} ]; then

Check warning on line 68 in examples/advanced/suit_update/start_network.sh

View workflow job for this annotation

GitHub Actions / static-tests

Double quote to prevent globbing and word splitting. [SC2086]
IFACE=${ARG_IFACE}
else
IFACE="tap0"
fi

if [ ! -z ${ARG_PREFIX} ]; then
PREFIX=$(echo "$ARG_PREFIX" | cut -d'/' -f1)
PREFIX_LEN=$(echo "$ARG_PREFIX" | cut -d'/' -f2)
else
PREFIX="fd00:dead:beef::"
PREFIX_LEN="64"
fi

trap "cleanup" INT QUIT TERM EXIT

init_iface

if [ ${USE_RADVD} -eq 1 ]; then
RADVD=${RIOTBASE}/dist/tools/radvd/radvd.sh
start_radvd
fi

# calls TERMPROG with TERMFLAGS
${POSITIONAL_ARGS}
12 changes: 11 additions & 1 deletion sys/shell/cmds/suit.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ static int _suit_handler(int argc, char **argv)
}

if (strcmp(argv[1], "fetch") == 0) {
suit_worker_trigger(argv[2], strlen(argv[2]));
if (argc > 2) {
suit_worker_trigger(argv[2], strlen(argv[2]));
}
else {
#ifdef SUIT_MANIFEST_RESOURCE
suit_worker_trigger(SUIT_MANIFEST_RESOURCE, strlen(SUIT_MANIFEST_RESOURCE));
#else
printf("No manifest URL provided, and SUIT_MANIFEST_RESOURCE not defined.\n");
return -1;
#endif
}
}
else if (strcmp(argv[1], "seq_no") == 0) {
uint32_t seq_no = 0;
Expand Down
Loading