OpenWrt on RISC-V: Complete Guide

OpenWrt · 68 views · Updated 2026-08-07

OpenWrt on RISC-V: Complete Guide

Why OpenWrt on RISC-V?

OpenWrt on RISC-V combines:
  • Open source router OS with 20+ years of development
  • Open architecture free from licensing restrictions
  • ARM alternative for sovereign networking infrastructure
  • Custom hardware without vendor lock-in

Supported RISC-V Platforms

PlatformOpenWrt VersionStatus
SpacemiT K123.05Production-ready
SpacemiT K323.05+Community port
SiFive FU54023.05Stable
Allwinner D122.03Stable
T-Head TH1520snapshotExperimental

Building OpenWrt for RISC-V

1. Environment Setup

sudo apt install build-essential clang flex bison gyp g++   git cmake ninja-build libssl-dev libelf-dev libncurses-dev   device-tree-compiler python3 python3-pyelftools

2. Source Code

git clone https://github.com/openwrt/openwrt.git
cd openwrt
git checkout openwrt-23.05

3. Configuration

make menuconfig
# Target System → RISC-V
# Subtarget → (select your board)
# Target Profile → (select your board)

# Essential packages
# → Base system → fdisk, lsblk, cURL
# → Network → mwan3, iptables, tc, tcpdump
# → LuCI → luci-app-mwan3, luci-app-firewall
# → Utilities → usbutils, pciutils

4. Build

make -j$(nproc) V=s 2>&1 | tee build.log

Custom Package Development

Create a Package

package/utils/myapp/
├── Makefile
└── src/
    ├── Makefile
    └── myapp.c

package/utils/myapp/Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=myapp
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk

define Package/myapp
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=My Custom App
  DEPENDS:=+libpthread
endef

define Package/myapp/description
  Custom application for RISC-V OpenWrt
endef

define Build/Compile
    $(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/myapp src/myapp.c
endef

define Package/myapp/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/myapp $(1)/usr/bin/
endef

$(eval $(call BuildPackage,myapp))

nftables vs iptables

OpenWrt 23.05 defaults to nftables (fw4). If you need iptables:

# Remove nftables
opkg remove fw4 nftables-json

# Install iptables
opkg install firewall3 iptables iptables-mod-conntrack-extra     iptables-mod-filter iptables-mod-nat-extra iptables-mod-ipopt     iptables-mod-ipsec iptables-mod-ulog iptables-mod-tproxy     iptables-mod-hashlimit iptables-mod-quic2

# Set fw3 as firewall
uci set firewall.@defaults[0].fw3_compat='1'
uci commit firewall
/etc/init.d/firewall restart

GPIO Control

# Export GPIO
echo 32 > /sys/class/gpio/export

# Set direction
echo out > /sys/class/gpio/gpio32/direction

# Set value
echo 1 > /sys/class/gpio/gpio32/value

# K1 GPIO mapping (check your board DTS)
# Pin header → GPIO number mapping varies by board

PCIe Devices

# List PCIe devices
lspci

# K1 has 5x PCIe Gen2 lanes
# Common uses: WiFi6 cards, NVMe SSD, FPGA accelerators

# Load driver for specific device
modprobe mt7921e  # MediaTek WiFi6

Resources


Request Hardware Ask in Forum