- Shell 49%
- Python 23%
- Docker 20%
- Makefile 7%
- HTML <1%
- 1 more language <1%
recoilwrt #
NAME #
recoilwrt - build custom OpenWrt firmware in Docker
SYNOPSIS #
./oxcaml/build.sh ARCH
./build.sh [TARGET]
./source/build.sh [TARGET]
./deploy.sh TARGET firmware|packages
./test/qemu-test.py [IMAGE]
DESCRIPTION #
recoilwrt builds an OpenWrt firmware image, plus a signed package repository for it, from the official OpenWrt Docker containers. Nothing is installed on the build machine except Docker.
The image is stock OpenWrt 25.12 with these changes:
- Packages: WireGuard, and the packages in
feed/:recoil(a hello world) andrecoilwww(a web server on port 8080). - SSH keys only. Root has no password, password logins are off, and LuCI is not installed.
- Transparent bridge. The WAN port and all LAN ports form one bridge. The router gets its address by DHCP from the upstream network and does no routing, NAT or DHCP serving. 192.168.1.1 remains as a second, fixed address for a machine cabled directly to it.
- Wifi, if configured. Each radio becomes an access point on the bridge.
- WireGuard tunnels, if configured. Each one gets a firewall zone of its own, which lets peers reach the router but not the LAN.
- Hostname
Recoilnet, if the router is still calledOpenWrt.
The settings are applied by the scripts in files/etc/uci-defaults/ on the
first boot of each new image, including after an upgrade that keeps settings.
So the image's settings win on every upgrade. Change the scripts rather than
the router to make a change permanent.
COMMANDS #
oxcaml/build.sh ARCH
: Builds recoilwww for arm64 or amd64 into out/oxcaml/ARCH/. The
source comes from the public oxmono repository at
https://tangled.org/anil.recoil.org/ox. Run it before build.sh for each
architecture you need.
build.sh [TARGET]
: Builds the firmware and package repository for TARGET (default x86-64)
from the OpenWrt release SDK and ImageBuilder. Output goes to
out/TARGET/targets/ (firmware) and out/TARGET/packages/ (repository).
source/build.sh [TARGET]
: Builds the same image from a full OpenWrt source tree, for a kernel the
release does not ship. By default the tree is the mediatek-7.4 branch of
https://tangled.org/recoil.org/openwrt: OpenWrt main with Linux
7.4-rc1 for x86-64 and mediatek/filogic. Same output layout as build.sh.
The first build takes about an hour on 16 cores. Later builds are
incremental.
deploy.sh TARGET firmware
: Copies the firmware to a running router and installs it with sysupgrade,
keeping its settings.
deploy.sh TARGET packages
: Installs or upgrades this repository's packages on a running router with
apk, without reflashing. Bump PKG_RELEASE in the package's Makefile
first, because apk only installs a higher version.
test/qemu-test.py [IMAGE]
: Boots the x86-64 image in QEMU, checks it over the serial console, then
runs both deploy.sh commands against it. Needs /dev/kvm and Python
pexpect.
TARGETS #
Each file in targets/ is a target:
| Target | Hardware |
|---|---|
x86-64 |
QEMU, for testing |
flint2 |
GL.iNet GL-MT6000 (Flint 2) |
To add one, create targets/NAME.env:
OPENWRT_TARGET=mediatek-filogic # target-subtarget, as in OpenWrt's Docker tags
PROFILE=glinet_gl-mt6000 # device profile (board_name on the device)
OXCAML_ARCH=arm64 # recoilwww build to include; empty for none
EXTRA_PACKAGES="" # extra packages; -name removes one
SYSUPGRADE_IMAGE='*-squashfs-sysupgrade.*' # image deploy.sh installs (default)
SITE CONFIGURATION #
Keys and passwords are kept outside the repository, in RECOILWRT_KEYDIR
(default ~/.config/recoilwrt):
authorized_keys
: Required. The SSH public keys that may log in as root.
apk-private-key.pem
: Signs the package repository. It is created on the first build. Routers
trust only the key their image was built with, so back it up.
wifi
: Optional. Without it the radios stay off. For example:
WIFI_SSID='MyNetwork'
WIFI_KEY='at-least-8-chars' # 8 to 63 characters
WIFI_COUNTRY='GB' # needed for 5 GHz
#WIFI_ENCRYPTION='sae-mixed' # default: WPA2 and WPA3
wireguard/NAME.conf
: Optional. A tunnel in the usual wg-quick format, as WireGuard providers and
wg-quick use. It becomes the network interface NAME (lowercase, at most
11 characters). Add one file per tunnel. Address, MTU, ListenPort,
PrivateKey and each peer's PublicKey, PresharedKey, Endpoint,
AllowedIPs and PersistentKeepalive are used. Other settings, such as
DNS, are ignored. A comment in a [Peer] section names the peer.
[Interface]
PrivateKey = ...
Address = fd00:1::5/128
MTU = 1280
[Peer]
# hub.example.org
PublicKey = ...
Endpoint = hub.example.org:51820
AllowedIPs = fd00::/48
PersistentKeepalive = 25
The wifi and wireguard files are copied into the firmware image, so treat
the images in out/ as secret: don't publish them.
ENVIRONMENT #
| Variable | Used by | Meaning |
|---|---|---|
RECOILWRT_KEYDIR |
builds | site configuration directory |
DOCKER_HOST |
builds | Docker daemon to build on (see NOTES) |
OXMONO |
oxcaml/build.sh |
local oxmono checkout to use instead of cloning |
OXMONO_REPO |
oxcaml/build.sh |
oxmono repository to clone (default tangled.org) |
OXMONO_REF |
oxcaml/build.sh |
branch or tag to build (default main) |
OPENWRT_SRC |
source/build.sh |
local OpenWrt tree to use instead of cloning |
OPENWRT_REPO |
source/build.sh |
OpenWrt repository to clone (default tangled.org) |
OPENWRT_REF |
source/build.sh |
branch or tag to build (default mediatek-7.4) |
TESTING_KERNEL |
source/build.sh |
1 (default) uses the target's testing kernel |
JOBS |
source/build.sh |
parallel jobs (default: all CPUs) |
ROUTER |
deploy.sh |
SSH destination (default root@192.168.1.1) |
ROUTER_PORT |
deploy.sh |
SSH port (default 22) |
EXPECT_KERNEL |
test/qemu-test.py |
fail unless this kernel version boots |
FILES #
| Path | Contents |
|---|---|
targets/ |
one file per target |
feed/ |
OpenWrt packages built into the image |
files/ |
files copied into the image |
files/etc/uci-defaults/ |
first-boot settings scripts |
out/ |
build output (not in git) |
EXAMPLES #
Build and test the x86-64 image:
./oxcaml/build.sh amd64 && ./build.sh x86-64 && ./test/qemu-test.py
Build for the Flint 2 and upgrade a router running an earlier build:
./oxcaml/build.sh arm64 && ./build.sh flint2
./deploy.sh flint2 firmware
Build the Flint 2 image with Linux 7.4 on a remote arm64 Docker host:
DOCKER_HOST=unix:///tmp/arm64.sock ./source/build.sh flint2
CUSTOMISING #
- Add a package of your own: create
feed/NAME/Makefile(an OpenWrt package Makefile) and addNAMEtoPACKAGESinstage.sh. - Add an upstream package: add it to
PACKAGESinstage.sh, or toEXTRA_PACKAGESfor one target. - Change a setting: edit or add a script in
files/etc/uci-defaults/. Scripts run on every upgrade, so they must work on a router that already has the setting. Don't put files infiles/etc/config/, because an upgrade that keeps settings overwrites them. - Drop recoilwww: delete
feed/recoilwww, remove it fromPACKAGESinstage.sh, and leaveOXCAML_ARCHempty in your targets. - Change OpenWrt release: set
OPENWRT_VERSIONinbuild.shandDockerfile. Check that Docker Hub hasopenwrt/sdk:TARGET-VERSION.
RECOVERY #
If a router can't be reached over SSH, use OpenWrt failsafe mode or the device's bootloader recovery.
On the Flint 2, hold reset while powering on until the LED settles. A "FIRMWARE UPDATE" page appears at 192.168.1.1. It accepts the sysupgrade image (it rejects the factory image):
F=out/flint2/targets/mediatek/filogic/*-squashfs-sysupgrade.bin
curl -F "firmware=@$F" http://192.168.1.1/upload # prints size and md5: check both
curl -m120 http://192.168.1.1/flashing.html & # starts writing
curl -m120 http://192.168.1.1/result # waits, then "success" or "failed"
Only fetch flashing.html after checking the upload. Fetching it starts the
write.
NOTES #
-
arm64 builds are much faster on an arm64 Docker host, such as Docker Desktop on an Apple silicon Mac. If
dockerisn't on that machine's SSH path, forward its socket instead of usingssh://:ssh -fN -L /tmp/arm64.sock:/Users/USER/.docker/run/docker.sock MAC export DOCKER_HOST=unix:///tmp/arm64.sockOn x86_64 with
qemu-user-binfmtinstalled, arm64 builds also work, but the OxCaml compiler alone takes about two hours. -
Packages installed with
apkare removed by the next firmware upgrade. Put anything permanent in the image. -
source/build.shstops if the kernel config is missing a setting for a new kernel version. Runmake kernel_oldconfigin the OpenWrt tree first.
LICENSE #
This repository is dedicated to the public domain under CC0 1.0 (see
LICENSE). The packages it builds keep their own licences: recoilwww is
ISC, and OpenWrt is mostly GPL-2.0.
SEE ALSO #
OpenWrt Docker images,
OpenWrt UCI,
AGENTS.md (notes for people changing this repository)