# Ubuntu 22.04+ build environment
sudo apt install build-essential clang flex bison gyp g++ git cmake ninja-build
sudo apt install libssl-dev libelf-dev libncurses-dev device-tree-compiler
git clone https://github.com/openwrt/openwrt.git
cd openwrt
# Switch to 23.05 branch
git checkout openwrt-23.05
# Add SpacemiT K1 target
echo "src-git spacemit https://github.com/spacemit/openwrt-spacemit.git;main" >> feeds.conf.default
./scripts/feeds update -a
./scripts/feeds install -a
# Configure for K1
make menuconfig
# Target: RISC-V
# Subtarget: SpacemiT K1
# Profile: K1-MUSE-Pi-Pro (or your board)
# Build (first build takes 2-4 hours)
make -j$(nproc) V=s
# Generate SD card image in bin/targets/
sudo dd if=bin/targets/riscv/spacemit/openwrt-spacemit-k1-sdcard.img of=/dev/sdX bs=4M
sync
opkg update
opkg install mwan3 luci-app-mwan3
# Configure in /etc/config/mwan3
config interface 'wan1'
option enabled '1'
list track_ip '8.8.8.8'
option reliability '1'
config interface 'wan2'
option enabled '1'
list track_ip '1.1.1.1'
option reliability '1'
config policy 'balanced'
list use_member 'wan1/1'
list use_member 'wan2/1'
OpenWrt 23.05 uses nftables (fw4) by default. To switch to iptables:
opkg remove fw4 nftables
opkg install iptables iptables-mod-*
opkg install firewall3
# Reconfigure: /etc/config/firewall
opkg install tc tcpdump
# Rate limit interface to 10Mbps
tc qdisc add dev eth0 root tbf rate 10mbit burst 32kbit latency 400ms
# HTB for hierarchical QoS
tc qdisc add dev eth0 root handle 1: htb
tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 50mbit ceil 100mbit
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 30mbit ceil 80mbit
opkg install weston qtbase qtdeclarative qtquickcontrols2
# Run Weston compositor
export XDG_RUNTIME_DIR=/tmp
weston --tty=1 --use-pixman &
# Run Qt app
export QT_QPA_PLATFORM=wayland
export WAYLAND_DISPLAY=wayland-0
./myapp
With dual RGMII + YT9512S switches (4 ports each = 8 total ports):
# /etc/config/network
config interface 'lan1'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'
config interface 'lan2'
option ifname 'eth1'
option proto 'static'
option ipaddr '192.168.2.1'
option netmask '255.255.255.0'
config interface 'wan'
option ifname 'eth0.2'
option proto 'dhcp'
Physical isolation: Each RGMII connects to a separate YT9512S switch, providing fully isolated network segments.
# Install K1 AI SDK
opkg install k1-ai-sdk k1-ai-runtime
# Run object detection
k1_ai_detect --model yolov5s.kmodel --input /dev/video0