Update: hardware-tested vendor-based build and developer notes
Hi everyone,
Following the link to the related WR5000 development thread, here is an update from testing on my own unit.
I have some hardware-tested results to share for a Cudy WR5000 V1.0 / EU1.0. With Codex assistance I built and booted a customized version of Cudy's R124 vendor OpenWrt 21.02 tree, Linux 5.4.281.
This provides a working legacy reference for this board. I have not ported the UBI root-device patch to Linux 6.12, which is the issue discussed in the related development thread, and this should not be described as completed upstream support.
Hardware confirmed on my unit
- MediaTek MT7987A, quad-core Cortex-A53, 512 MiB DDR3.
- ESMT F50L1G41LC SPI NAND, 128 MiB, 2048-byte data pages + 64-byte OOB, 128 KiB eraseblocks.
- MT7992 radio and AN8855 LAN switch.
- Stock U-Boot 2025.04-rc2; the tested stock firmware was Cudy 2.5.19.
- The manufacturer's R124 profile/DTS matches the board and console output.
Results checked on the device
- An initramfs image was transferred with TFTP and booted with
bootm from RAM.
- A rebuilt kernel and SquashFS rootfs were installed into one firmware slot, read back, and compared by SHA256.
- Booting from NAND and subsequent software reboots worked. U-Boot reported
Firmware integrity verification passed.
/rom is SquashFS and the writable overlay is UBIFS. The other kernel/rootfs slot was retained.
- WAN DHCP, the LAN bridge, LuCI, SSH, and LED triggers were exercised.
- Both radio AP interfaces initialized and reported the configured SSIDs. This uses the matching proprietary stock driver/firmware, not an upstream mt76 implementation. I have not validated Wi-Fi client association, MLO, mesh, advertised maximum rates, or long-term stability.
- A matching AmneziaWG module/tools build passed its crypto self-tests and an actual tunnel/SSH test, including 16 MiB in each direction with integrity checking. This is an optional legacy-tree add-on, not evidence of upstream board support.
Findings relevant to this thread
-
In the GPL archive I used, the existing MediaTek patch is at:
target/linux/mediatek/patches-5.4-mtk-wifi7/999-2329-ubi-add-configurable-rootdev.patch
The original author is Sam Shih / MediaTek. An unmodified copy is included below for reference, with attribution intact. It is a 5.4 patch, not a proposed 6.12 port.
-
The actual slot-0 kernel command line includes:
ubi.rootfs_volume=rootfs
boot_param.boot_kernel_part=kernel
boot_param.boot_rootfs_part=rootfs
boot_param.upgrade_kernel_part=kernel2
boot_param.upgrade_rootfs_part=rootfs2
boot_param.env_part=u-boot-env
boot_param.rootfs_data_part=rootfs_data
boot_param.boot_image_slot=0
boot_param.upgrade_image_slot=1
The volume table and limited kernel-slot sizes are in the notes below; please inspect each device before assuming the same layout.
-
I added a rootfs SHA256 node to the kernel FIT, using the SquashFS bytes_used length. The stock bootloader accepted and checked this image through the manual boot/install route. Bootloader integrity checks were not disabled. This does not demonstrate that the stock web updater will accept the image or that a signed transition image can be skipped on other units.
-
Two vendor-tree DHCP issues surfaced: the script used udhcpc -a while BusyBox's ARP-probe feature was disabled, and the vendor AP-mode branch could flush br-lan addresses when the vendor mode setting was absent. I enabled the required BusyBox feature and let netifd own LAN addressing independently of WAN DHCP.
-
For the pinned AWG/Zinc backport on this ARM64 CONFIG_PREEMPT_NONE kernel, encrypt/decrypt workers had to release their SIMD/NEON context before cond_resched(). The tested compatibility patch and exact source commits are included; it needs independent review before use on other kernels.
Source material and limits
The source appendix below contains selected source patches, the vendor R124 DTS and legacy UBI patch, FIT/hash tooling, pinned AWG package recipes, sanitized boot evidence and build notes. It contains no ready-to-flash images, stock radio binaries, Factory/NVRAM dumps, device keys, authorized SSH keys, or personal VPN configuration. The working image on my router is personalized and is not a public release.
The GPL source was obtained from Cudy's WR5000 V1 download page. Archive SHA256:
b734bb5e6ee5a64678997481a9bcf76dfd7538577d7062652f68047a8e3199a8
My goal in sharing this is to provide measured boot/storage details and a tested legacy baseline that may help someone working on the modern kernel port. I would welcome review, particularly around the 6.12 UBI/root-device handling and the eventual upstream wireless path.
Source appendix
The forum only accepts image attachments, so I am including the developer kit as readable source below instead of uploading a ZIP. These are experimental legacy-tree references for review, not a ready-to-flash firmware.
README.md
# Cudy WR5000 V1 R124 — legacy developer reference
This is a source-and-observation kit, not a firmware release or a Linux 6.12 port.
Read FORUM-POST-EN.md first. The original vendor/MediaTek attribution in copied files is retained.
## Provenance
Vendor source: https://www.cudy.com/en-us/pages/download-center/wr5000-1-0
Archive: GPL_TR3600_WR5000.tar.gz
SHA256: b734bb5e6ee5a64678997481a9bcf76dfd7538577d7062652f68047a8e3199a8
Vendor base: OpenWrt 21.02 fork, Linux 5.4.281, GCC 8.4.0, mediatek/mt7987, R124.
AWG module commit: 4569c4c67f3a57414969260cafbbd04694fbaae0
AWG tools commit: ee0f0a9aa34ff0a0da4b3433b9512781cfe02843
The package recipes record archive SHA256 values. Original project licenses apply.
## Build findings
The manufacturer's R124 configuration is the starting point (`make R124_oemconfig`).
The stock build was not a complete open-radio build: its external MTK feed was unavailable during the session and radio source was incomplete. Matching proprietary modules/firmware were extracted locally from this unit's stock firmware, with matching kernel vermagic; none are included here.
This kit alone is not a one-command, clean-room recipe for reproducing a complete radio-enabled image.
The relevant BusyBox setting is CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_ARPING=y.
vendor-dhcp-lan.patch removes vendor-mode-dependent mutation of br-lan during WAN DHCP events. Review AP-mode requirements before applying it elsewhere.
The FIT tool runs on the unwrapped sysupgrade TAR before append-metadata. It accepts only the observed R124 tar layout and hashes SquashFS bytes_used. The build hook used was:
define Build/cudy-rootfs-hash
/usr/bin/python3 $(TOPDIR)/scripts/cudy-rootfs-hash.py $@
endef
R124 image pipeline:
sysupgrade-tar | cudy-rootfs-hash | append-metadata
The Python tool needs fdtput from device-tree-compiler. Copy tools/cudy-rootfs-hash.py to the SDK scripts/ directory, then review/apply r124-rootfs-fit-hash.patch. TAR/FIT checksum handling is separate from stock OEM web-image wrapping/signatures. Stock web installation was not validated. No installer is provided. The build-fixes/ patches address legacy build dependencies; the device retained its original BL2/FIP/bootloader binaries.
The AWG package patch is specific to the pinned legacy/kernel combination. Kernel self-tests and real tunnel transfers passed on the tested unit; it has not been independently audited or validated on other kernels. Match kernel ABI exactly.
## Storage/recovery observations
The NAND is 128 MiB SPI NAND, not a 16 MiB SPI NOR. A data-only ECC read lacks OOB and is not a programmer-ready raw dump. Device calibration and boot partitions must remain per-unit.
The stock U-Boot allowed manual RAM boot. Default vendor boot-menu delay was zero; setting a five-second menu delay enabled reliable console interception on this unit. Boot environment behavior is device-specific.
TFTP RAM boot used router 192.168.1.112, server 192.168.1.88, load address 0x48000000. RAM boot with bootm was tested. Do not feed initramfs images to an automatic recovery.bin firmware-writing flow.
The stock dual-image volume layout is an observation, not permission to assume the same IDs or capacities on another unit. The kernel volumes were only 3809280 bytes each. Bootloader image/hash checks and web-updater signature acceptance are different checks.
## Test scope
Validated: RAM boot; NAND boot/reboot; image readback hashes; unchanged boot/calibration partitions; WAN DHCP; LAN bridge; LuCI/SSH services; LED triggers; radio AP-interface initialization; a matching AWG module and real encrypted tunnel transfers.
Not validated: modern 6.12 rootdev port, upstream mt76 operation, Wi-Fi client association, MLO/mesh, IPv6/full-tunnel operation, line-rate 1/2.5GbE, or long-term reliability. The PC test interface was a 100Mb/s USB NIC and showed intermittent link renegotiation during some transfers.
## Sharing boundary
No binaries, complete rootfs overlays, device dumps, SSH authorized keys, SSH host private keys, VPN keys/configuration, per-unit Wi-Fi profiles, serial numbers, or operator endpoint addresses are included. Cosmetic theme and operator-specific reset/VPN policies are not necessary for upstream hardware support and are excluded from this kit.
Files under vendor-reference and build-fixes are references/patches with their existing provenance. This archive does not grant additional rights to proprietary stock components, which are not included.
stock-ubi-volumes.json
{
"scope": "observed on one WR5000 V1.0 EU1.0 before customization; not a repartitioning recipe",
"volumes": [
{
"id": 0,
"name": "u-boot-env",
"bytes": 1142784
},
{
"id": 1,
"name": "kernel",
"bytes": 3809280
},
{
"id": 2,
"name": "kernel2",
"bytes": 3809280
},
{
"id": 3,
"name": "rootfs",
"bytes": 23998464
},
{
"id": 4,
"name": "rootfs2",
"bytes": 23871488
},
{
"id": 5,
"name": "rootfs_data",
"bytes": 42029056
}
]
}
boot-storage-excerpt.txt
Selected hardware/boot lines from the tested device. Not a full boot log.
NOTICE: CPU: MT7987A
NOTICE: EMI: Detected DRAM size: 512 MB
NOTICE: Detected SPI-NAND: ESMT F50L1G41LC
NOTICE: Page size 2048, Block size 131072, size 134217728
U-Boot 2025.04-rc2 (Jun 08 2026 - 07:56:03 +0000), Build: jenkins-mtk_mt7987_router_v2.5-13
Trying to boot from image slot 0
Read 64 bytes from volume kernel to 0000000048000000
Read 3700269 bytes from volume kernel to 0000000048000000
Hash(es) for rootfs: sha256+
Firmware integrity verification passed
[ 0.000000] Machine model: MediaTek MT7987A SPIM-NAND RFB dual-image/R124
[ 0.000000] Kernel command line: console=ttyS0,115200n1 loglevel=8 earlycon=uart8250,mmio32,0x11000000 pci=pcie_bus_perf ubi.rootfs_volume=rootfs boot_param.boot_kernel_part=kernel boot_param.boot_rootfs_part=rootfs boot_param.upgrade_kernel_part=kernel2 boot_param.upgrade_rootfs_part=rootfs2 boot_param.env_part=u-boot-env boot_param.rootfs_data_part=rootfs_data boot_param.boot_image_slot=0 boot_param.upgrade_image_slot=1 boot_param.dual_boot
vendor-reference/R124.dts
/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
/dts-v1/;
#include "mt7987a.dtsi"
#include "mt7987-netsys-gmac123.dtsi"
#include "mt7987-spim-nand.dtsi"
#include <dt-bindings/input/input.h>
/ {
model = "MediaTek MT7987A SPIM-NAND RFB dual-image/R124";
compatible = "mediatek,mt7987a-spim-snand",
"mediatek,mt7987a", "mediatek,mt7987";
chosen {
bootargs = "console=ttyS0,115200n1 loglevel=8 \
earlycon=uart8250,mmio32,0x11000000 \
pci=pcie_bus_perf";
};
gpio-leds {
compatible = "gpio-leds";
internet {
label = "oem:green:internet";
gpios = <&pio 46 GPIO_ACTIVE_LOW>;
};
status {
label = "oem:green:status";
gpios = <&pio 29 GPIO_ACTIVE_LOW>;
};
wan {
label = "oem:green:wan";
gpios = <&pio 10 GPIO_ACTIVE_HIGH>;
};
lan {
label = "oem:green:lan";
gpios = <&pio 26 GPIO_ACTIVE_HIGH>;
};
wifi {
label = "oem:green:wifi";
gpios = <&pio 48 GPIO_ACTIVE_LOW>;
};
wifi5g {
label = "oem:green:wifi5g";
gpios = <&pio 49 GPIO_ACTIVE_LOW>;
};
};
gpio-keys-polled {
compatible = "gpio-keys-polled";
#address-cells = <1>;
#size-cells = <0>;
poll-interval = <20>;
reset {
label = "reset";
linux,code = <KEY_RESTART>;
gpios = <&pio 1 GPIO_ACTIVE_LOW>;
};
wps {
label = "wps";
linux,code = <KEY_WPS_BUTTON>;
gpios = <&pio 0 GPIO_ACTIVE_LOW>;
};
};
nmbm_spim_nand {
/delete-node/ partitions@0;
partitions: partitions@0 {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "BL2";
reg = <0x00000 0x0100000>;
read-only;
};
partition@100000 {
label = "backup";
reg = <0x0100000 0x0080000>;
};
factory: partition@180000 {
label = "Factory";
reg = <0x180000 0x0400000>;
};
bdinfo: partition@580000 {
label = "bdinfo";
reg = <0x580000 0x0040000>;
};
partition@5C0000 {
label = "FIP";
reg = <0x5C0000 0x0200000>;
};
partition@7C0000 {
label = "ubi";
reg = <0x7C0000 0x7040000>;
};
};
};
};
&mdio {
/delete-property/ reset-gpios;
/delete-property/ reset-delay-us;
};
ð {
lower-mtd-name = "bdinfo";
};
&gmac0 {
mtd-mac-address = <&bdinfo 0xDE00>;
};
&gmac1 {
mtd-mac-address = <&bdinfo 0xDE00>;
mtd-mac-address-increment = <1>;
};
&cpu_trip_active2 {
temperature = <120000>;
};
vendor-reference/999-2329-ubi-add-configurable-rootdev.patch
From 27ae9a1b684cd183ccf6881d32710b8890113d20 Mon Sep 17 00:00:00 2001
From: Sam Shih <sam.shih@mediatek.com>
Date: Fri, 2 Jun 2023 13:06:14 +0800
Subject: [PATCH]
[spi-and-storage][999-2329-ubi-add-configurable-rootdev.patch]
---
drivers/mtd/ubi/block.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index 873f9cb24..33e969fd3 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -97,6 +97,12 @@ static DEFINE_IDR(ubiblock_minor_idr);
static DEFINE_MUTEX(devices_mutex);
static int ubiblock_major;
+static char rootfs_volume[256] = "rootfs";
+module_param_string(rootfs_volume, rootfs_volume, sizeof(rootfs_volume), 0444);
+
+static bool no_default_rootdev;
+module_param(no_default_rootdev, bool, 0444);
+
static int __init ubiblock_set_param(const char *val,
const struct kernel_param *kp)
{
@@ -460,8 +466,9 @@ int ubiblock_create(struct ubi_volume_info *vi)
dev->ubi_num, dev->vol_id, vi->name);
mutex_unlock(&devices_mutex);
- if (!strcmp(vi->name, "rootfs") &&
+ if (!strcmp(vi->name, rootfs_volume) &&
IS_ENABLED(CONFIG_MTD_ROOTFS_ROOT_DEV) &&
+ !no_default_rootdev &&
ROOT_DEV == 0) {
pr_notice("ubiblock: device ubiblock%d_%d (%s) set to be root filesystem\n",
dev->ubi_num, dev->vol_id, vi->name);
@@ -681,7 +688,7 @@ static void __init ubiblock_create_auto_rootfs(void)
struct ubi_volume_info vi;
for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++) {
- desc = ubi_open_volume_nm(ubi_num, "rootfs", UBI_READONLY);
+ desc = ubi_open_volume_nm(ubi_num, rootfs_volume, UBI_READONLY);
if (IS_ERR(desc))
continue;
--
2.34.1
tools/cudy-rootfs-hash.py
#!/usr/bin/env python3
from pathlib import Path
import sys,tarfile,tempfile,subprocess,struct,hashlib,io,os
image=Path(sys.argv[1])
with tarfile.open(image,'r:') as archive:
members=archive.getmembers()
names={m.name.rstrip('/') for m in members}
expected={'sysupgrade-R124','sysupgrade-R124/CONTROL','sysupgrade-R124/kernel','sysupgrade-R124/root'}
if names!=expected:raise RuntimeError('Unexpected R124 tar layout')
content={m.name:archive.extractfile(m).read() for m in members if m.isfile()}
root=content['sysupgrade-R124/root']
if root[:4]!=b'hsqs':raise RuntimeError('Expected SquashFS')
used=struct.unpack_from('<Q',root,40)[0]
if not 96<used<=len(root):raise RuntimeError('Invalid SquashFS length')
with tempfile.TemporaryDirectory(prefix='cudy-fit-') as tmp:
kernel=Path(tmp)/'kernel.fit'
kernel.write_bytes(content['sysupgrade-R124/kernel'])
subprocess.run(['fdtput','-r',str(kernel),'/rootfs'],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
subprocess.run(['fdtput','-c',str(kernel),'/rootfs'],check=True)
subprocess.run(['fdtput','-t','x',str(kernel),'/rootfs','size',format(used,'x')],check=True)
subprocess.run(['fdtput','-c',str(kernel),'/rootfs/hash-1'],check=True)
subprocess.run(['fdtput','-t','s',str(kernel),'/rootfs/hash-1','algo','sha256'],check=True)
subprocess.run(['fdtput','-t','bx',str(kernel),'/rootfs/hash-1','value',*[format(b,'02x') for b in hashlib.sha256(root[:used]).digest()]],check=True)
content['sysupgrade-R124/kernel']=kernel.read_bytes()
new=image.with_name(image.name+'.with-rootfs-hash')
with tarfile.open(new,'w:',format=tarfile.GNU_FORMAT) as archive:
for member in members:
if member.isfile():
data=content[member.name];member.size=len(data)
archive.addfile(member,io.BytesIO(data))
else:archive.addfile(member)
os.replace(new,image)
print('R124 rootfs SHA256 added to kernel FIT')
r124-rootfs-fit-hash.patch
--- a/target/linux/mediatek/image/Makefile
+++ b/target/linux/mediatek/image/Makefile
@@ -85,6 +85,10 @@
FIT_KEY_NAME :=
endef
+define Build/cudy-rootfs-hash
+ /usr/bin/python3 $(TOPDIR)/scripts/cudy-rootfs-hash.py $@
+endef
+
include $(SUBTARGET).mk
define Image/Build
--- a/target/linux/mediatek/image/mt7987.mk
+++ b/target/linux/mediatek/image/mt7987.mk
@@ -51,7 +51,7 @@
UBOOTENV_IN_UBI := 1
DUAL_IMAGE := 1
ROOTFS_DATA_SIZE := 40MiB
- IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
+ IMAGE/sysupgrade.bin := sysupgrade-tar | cudy-rootfs-hash | append-metadata
endef
TARGET_DEVICES += R124
vendor-dhcp-lan.patch
--- a/package/network/config/netifd/files/lib/netifd/dhcp.script
+++ b/package/network/config/netifd/files/lib/netifd/dhcp.script
@@ -87,12 +87,7 @@
[ -n "$lease" ] && json_add_int leasetime "$lease"
proto_close_data
- [ "router" = "$(uci -q get system.board.type)" -o "passthrough" = "$(uci -q get system.board.type)" ] || {
- local br_ip=$(ifconfig br-lan | grep inet | awk '{print $2}' | awk -F: '{print $2}')
- [ x"$br_ip" != x"$ip" ] && {
- ip -4 addr flush dev br-lan
- }
- }
+ # LAN addressing is owned by netifd, independently of the WAN DHCP lease.
proto_send_update "$INTERFACE"
if [ "$IFACE6RD" != 0 -a -n "$ip6rd" ]; then
@@ -129,15 +124,7 @@
deconfig_interface() {
proto_init_update "*" 0
proto_send_update "$INTERFACE"
- [ "router" = "$(uci -q get system.board.type)" -o "passthrough" = "$(uci -q get system.board.type)" ] || {
- local br_ip=$(ifconfig br-lan | grep inet | awk '{print $2}' | awk -F: '{print $2}')
- local lan_ip=$(uci -q get network.lan.ipaddr)
- local lan_mask=$(uci -q get network.lan.netmask)
- [ x"$br_ip" != x"$lan_ip" ] && {
- ip -4 addr flush dev br-lan
- ifconfig br-lan $lan_ip netmask $lan_mask
- }
- }
+ # LAN addressing is owned by netifd, independently of the WAN DHCP lease.
}
case "$1" in
build-fixes/oem-sign-openssl3.patch
--- /opt/cudy-source/oem-sign-Makefile.original 2026-11-03 15:26:16.661486364 +0300
+++ tools/oem-sign/src/Makefile 2026-11-03 15:26:16.712783239 +0300
@@ -1,6 +1,6 @@
CC=gcc
CFLAGS=
-WFLAGS=-Wall -Werror
+WFLAGS=-Wall -Werror -Wno-error=deprecated-declarations
ifeq ($(shell uname -s),Darwin)
WFLAGS=-Wall
endif
build-fixes/uboot-dts-copy.patch
--- a/package/extra/mtk_mt7993/uboot-atf-mtk/Makefile
+++ b/package/extra/mtk_mt7993/uboot-atf-mtk/Makefile
@@ -39,7 +39,7 @@
$(CP) src/* $(PKG_BUILD_DIR)
$(Build/Patch)
[ ! -e $(OemUbootDefconfig) ] || cp -f $(OemUbootDefconfig) $(PKG_BUILD_DIR)/uboot/configs
- [ ! -e $(OemUbootDTS) ] || cp -f $(OemUbootDTS) $(PKG_BUILD_DIR)/uboot/arch/arm/dts/
+ $(foreach dts,$(OemUbootDTS),cp -f $(dts) $(PKG_BUILD_DIR)/uboot/arch/arm/dts/;)
[ ! -e $(OemAtfDefconfig) ] || cp -f $(OemAtfDefconfig) $(PKG_BUILD_DIR)/atf/.config
[ ! -e $(OemUbootKconfig) ] || cp -f $(OemUbootKconfig) $(PKG_BUILD_DIR)/uboot/arch/arm/mach-mediatek/Kconfig
endef
build-fixes/uboot-host-openssl.patch
--- a/package/extra/mtk_mt7993/uboot-atf-mtk/Makefile
+++ b/package/extra/mtk_mt7993/uboot-atf-mtk/Makefile
@@ -49,7 +49,9 @@
endef
define Build/Compile
- $(MAKE) -C $(PKG_BUILD_DIR)/uboot CROSS_COMPILE=/usr/bin/aarch64-linux-gnu-
+ $(MAKE) -C $(PKG_BUILD_DIR)/uboot CROSS_COMPILE=/usr/bin/aarch64-linux-gnu- \
+ HOSTCFLAGS="-O2 -I$(STAGING_DIR_HOST)/include" \
+ HOSTLDFLAGS="-L$(STAGING_DIR_HOST)/lib"
$(CP) $(PKG_BUILD_DIR)/uboot/$(UBOOT_BINARY) $(PKG_BUILD_DIR)/atf/
$(MAKE) -C $(PKG_BUILD_DIR)/atf all fip
$(MAKE) cross_tools -C $(PKG_BUILD_DIR)/uboot CROSS_COMPILE=$(TOOLCHAIN_DIR)/bin/aarch64-openwrt-linux- \
package/extra/amneziawg-pinned/Makefile
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=amneziawg-pinned
PKG_VERSION:=3.1.20260812
PKG_RELEASE:=1
PKG_SOURCE:=4569c4c67f3a57414969260cafbbd04694fbaae0.tar.gz
PKG_SOURCE_URL:=https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/archive/
PKG_HASH:=6d7608935adbcdd4c6e9fed705951e2ee85311ac212a8e8f1274abcf9b06f83e
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/amneziawg-linux-kernel-module-4569c4c67f3a57414969260cafbbd04694fbaae0
PKG_LICENSE:=GPL-2.0-only
include $(INCLUDE_DIR)/package.mk
define KernelPackage/amneziawg
SUBMENU:=Network Support
TITLE:=Pinned AmneziaWG for Cudy R124
DEPENDS:=+kmod-udptunnel4 +kmod-udptunnel6
FILES:=$(PKG_BUILD_DIR)/src/amneziawg.ko
AUTOLOAD:=$(call AutoLoad,35,amneziawg)
endef
define Build/Compile
+$(KERNEL_MAKE) M="$(PKG_BUILD_DIR)/src" WIREGUARD_VERSION=$(PKG_VERSION) CONFIG_WIREGUARD_DEBUG=y modules
endef
$(eval $(call KernelPackage,amneziawg))
package/extra/amneziawg-pinned/patches/010-cudy-linux-5.4-compat.patch
diff --git a/src/Kbuild b/src/Kbuild
index a154c7b..f2b2998 100644
--- a/src/Kbuild
+++ b/src/Kbuild
@@ -22,3 +22,13 @@ endif
include $(src)/compat/Kbuild.include
obj-$(if $(KBUILD_EXTMOD),m,$(CONFIG_AMNEZIAWG)) := amneziawg.o
+
+# Stable/vendor kernels may backport this API without changing major version.
+ifneq ($(shell grep -s -F "extern const struct header_ops ip_tunnel_header_ops;" $(srctree)/include/net/ip_tunnels.h),)
+ccflags-y += -DAWG_HAVE_IP_TUNNEL_HEADER_OPS
+endif
+
+# Use this module's Zinc API consistently on the pinned legacy kernel.
+ifeq ($(VERSION).$(PATCHLEVEL),5.4)
+LINUXINCLUDE := -I$(src)/compat/crypto/blake2s/include -I$(src)/compat/crypto/chacha20poly1305/include -I$(src)/compat/crypto/curve25519/include -I$(src)/crypto/include $(LINUXINCLUDE)
+endif
diff --git a/src/compat/compat-asm.h b/src/compat/compat-asm.h
index 345087b..21a8cce 100644
--- a/src/compat/compat-asm.h
+++ b/src/compat/compat-asm.h
@@ -53,7 +53,7 @@
#define SYM_FUNC_END ENDPROC
#endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 200)
#define blake2s_compress_ssse3 zinc_blake2s_compress_ssse3
#define blake2s_compress_avx512 zinc_blake2s_compress_avx512
#define poly1305_init_arm zinc_poly1305_init_arm
diff --git a/src/compat/compat.h b/src/compat/compat.h
index 3b8606d..56c50a1 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -901,7 +901,7 @@ static inline void skb_mark_not_on_list(struct sk_buff *skb)
#define blake2s_update zinc_blake2s_update
#define blake2s_final zinc_blake2s_final
#endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 200) && LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
#define blake2s_hmac zinc_blake2s_hmac
#define chacha20 zinc_chacha20
#define hchacha20 zinc_hchacha20
@@ -1087,7 +1087,7 @@ static inline void skb_reset_redirect(struct sk_buff *skb)
#define pre_exit exit
#endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0) && !defined(AWG_HAVE_IP_TUNNEL_HEADER_OPS)
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
diff --git a/src/crypto/zinc/selftest/blake2s.c b/src/crypto/zinc/selftest/blake2s.c
index 1b5c210..4c689a0 100644
--- a/src/crypto/zinc/selftest/blake2s.c
+++ b/src/crypto/zinc/selftest/blake2s.c
@@ -2072,7 +2072,7 @@ static bool __init blake2s_selftest(void)
buf[i] = (u8)i;
for (i = 0; i < ARRAY_SIZE(blake2s_keyed_testvecs); ++i) {
- blake2s(hash, buf, key, BLAKE2S_HASH_SIZE, i, BLAKE2S_KEY_SIZE);
+ blake2s(key, BLAKE2S_KEY_SIZE, buf, i, hash, BLAKE2S_HASH_SIZE);
if (memcmp(hash, blake2s_keyed_testvecs[i], BLAKE2S_HASH_SIZE)) {
pr_err("blake2s keyed self-test %zu: FAIL\n", i + 1);
success = false;
@@ -2080,7 +2080,7 @@ static bool __init blake2s_selftest(void)
}
for (i = 0; i < ARRAY_SIZE(blake2s_testvecs); ++i) {
- blake2s(hash, buf, NULL, BLAKE2S_HASH_SIZE, i, 0);
+ blake2s(NULL, 0, buf, i, hash, BLAKE2S_HASH_SIZE);
if (memcmp(hash, blake2s_testvecs[i], BLAKE2S_HASH_SIZE)) {
pr_err("blake2s unkeyed self-test %zu: FAIL\n", i + i);
success = false;
diff --git a/src/main.c b/src/main.c
index 3692785..84218c5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,6 +5,7 @@
*/
#include "version.h"
+#include "crypto/zinc.h"
#include "device.h"
#include "noise.h"
#include "queueing.h"
diff --git a/src/receive.c b/src/receive.c
index 9fffe87..7ac4c14 100644
--- a/src/receive.c
+++ b/src/receive.c
@@ -607,11 +607,15 @@ void wg_packet_decrypt_worker(struct work_struct *work)
COMPAT_MAYBE_SIMD_CONTEXT(&simd_context))) ?
PACKET_STATE_CRYPTED : PACKET_STATE_DEAD;
wg_queue_enqueue_per_peer_rx(skb, state);
+/* Release legacy Zinc/NEON state before any voluntary scheduling.
+ * CONFIG_PREEMPT_NONE still permits cond_resched(). */
#ifdef COMPAT_CRYPTO_IS_ZINC
- simd_relax(&simd_context);
+ simd_put(&simd_context);
+#endif
+ cond_resched();
+#ifdef COMPAT_CRYPTO_IS_ZINC
+ simd_get(&simd_context);
#endif
- if (need_resched())
- cond_resched();
}
#ifdef COMPAT_CRYPTO_IS_ZINC
diff --git a/src/send.c b/src/send.c
index b3f80b0..6017779 100644
--- a/src/send.c
+++ b/src/send.c
@@ -405,11 +405,15 @@ void wg_packet_encrypt_worker(struct work_struct *work)
}
wg_queue_enqueue_per_peer_tx(first, state);
+/* Release legacy Zinc/NEON state before any voluntary scheduling.
+ * CONFIG_PREEMPT_NONE still permits cond_resched(). */
#ifdef COMPAT_CRYPTO_IS_ZINC
- simd_relax(&simd_context);
+ simd_put(&simd_context);
+#endif
+ cond_resched();
+#ifdef COMPAT_CRYPTO_IS_ZINC
+ simd_get(&simd_context);
#endif
- if (need_resched())
- cond_resched();
}
#ifdef COMPAT_CRYPTO_IS_ZINC
simd_put(&simd_context);
package/extra/amneziawg-tools-pinned/Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=amneziawg-tools-pinned
PKG_VERSION:=3.1.20260812
PKG_RELEASE:=1
PKG_SOURCE:=ee0f0a9aa34ff0a0da4b3433b9512781cfe02843.tar.gz
PKG_SOURCE_URL:=https://github.com/amnezia-vpn/amneziawg-tools/archive/
PKG_HASH:=22438f231d39ea27e4bdc69707ec3103357f3cecc9ad3eecba18a61e5b39c9b9
PKG_BUILD_DIR:=$(BUILD_DIR)/amneziawg-tools-ee0f0a9aa34ff0a0da4b3433b9512781cfe02843
PKG_LICENSE:=GPL-2.0-only
include $(INCLUDE_DIR)/package.mk
define Package/amneziawg-tools
SECTION:=net
CATEGORY:=Network
TITLE:=Pinned AmneziaWG configuration utility
DEPENDS:=+kmod-amneziawg
endef
define Build/Compile
+CFLAGS="$(TARGET_CFLAGS)" LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(PKG_BUILD_DIR)/src CC="$(TARGET_CC)" WITH_WGQUICK=no WITH_SYSTEMDUNITS=no WITH_BASHCOMPLETION=no
endef
define Package/amneziawg-tools/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/wg $(1)/usr/bin/awg
endef
$(eval $(call BuildPackage,amneziawg-tools))