OpenStick adventures Part 3: WireGuard Kernel module

This post recovers an OpenStick’s running kernel configuration, builds a matching kernel with the WireGuard module enabled, and tests it before flashing permanantly.
The device in this session is a Yiming UZ801-v3 with a Qualcomm MSM8916 and an ARM64 Linux installation.

Two of my OpenStick flashed modems. One has been modified with a 3v3 to 5v board to allow it to communicate with a drone flight controller.

Two of my OpenStick flashed modems. One has been modified with a 3v3 to 5v board to allow it to communicate with a drone flight controller on the UART port.

ItemObserved value
SSH connectionuser@192.168.200.1, through the openstick alias
Original kernel6.7.0-rc4-msm8916-g6cc2342c6a72-dirty
Matching sourcemsm8916-mainline/linux, commit 6cc2342c6a7227a05ca94c836df42d5ba273eef2
New kernel6.7.0-rc4-msm8916-wireguard-g6cc2342c6a72
Build toolchainGCC 13.3.0 and binutils 2.42
Board compatibilityyiming,uz801-v3, qcom,msm8916
Boot partition/dev/disk/by-partlabel/boot, resolving to /dev/mmcblk0p12, 64 MiB
Boot layoutaboot and a single boot partition; no A/B slots detected
Original boot formatAndroid boot image, gzip-compressed kernel with an appended DTB, Zstandard initramfs
Installed userspace implementationwireguard-go v0.0.20220316
Installed toolswireguard-tools v1.0.20210914
Kernel WireGuard version1.0.0

As the existing kernel was build with uncommitted source changes it cannot be fully reconstructed from /proc/config.gz.
This build matches its base commit and configuration, not necessarily every original source change.

I’m running debian on a 9+ year old PC so compiling the kernel usually takes some time.
Allow several GB of free storage for source and build output. I am cross compiling on my desktop rather than compiling on the stick itself (future project? I like the idea of the device being “self sufficient”).

sudo apt-get update
sudo apt-get install \
    git make gcc gcc-13-aarch64-linux-gnu binutils-aarch64-linux-gnu \
    flex bison bc libssl-dev libelf-dev \
    python3 zstd cpio abootimg fastboot

export WORK="$HOME/openstick-wireguard"
export RELEASE="6.7.0-rc4-msm8916-wireguard-g6cc2342c6a72"
mkdir -p "$WORK"
df -h "$WORK"
aarch64-linux-gnu-gcc-13 --version
fastboot --version

Configure ~/.ssh/config if the alias does not already exist:

Host openstick
    HostName 192.168.200.1
    User user

I have also configured SSH key authentication, this dramatically sped up development.

Check the connection and device identity:

ssh -G openstick | grep -E '^(hostname|user|port) '
ssh openstick 'uname -a; cat /proc/version'
ssh openstick 'tr "\000" "\n" < /proc/device-tree/compatible'
ssh openstick 'lsblk -o NAME,SIZE,FSTYPE,PARTLABEL,MOUNTPOINTS'

Before rebooting, confirm physical access and the board’s fastboot-entry procedure.
An SSH connection cannot recover a kernel that never brings up USB networking.
Do not assume this layout applies to another OpenStick variant.
Do not flash aboot, erase partitions, or change the partition table.

Recover the running configuration

Do this while the original kernel is running:

ssh openstick 'cat /proc/config.gz' > "$WORK/config.gz"
gzip -t "$WORK/config.gz"
gzip -dc "$WORK/config.gz" > "$WORK/config.running"

grep -E 'CONFIG_(LOCALVERSION|MODULES|MODVERSIONS|WIREGUARD)' \
    "$WORK/config.running"

The original configuration includes:

CONFIG_LOCALVERSION="-msm8916"
CONFIG_LOCALVERSION_AUTO=y
CONFIG_MODULES=y
# CONFIG_MODVERSIONS is not set
# CONFIG_WIREGUARD is not set

If /proc/config.gz is unavailable, check /boot/config-$(uname -r) on the device.
Keep config.running unchanged as the baseline.

Back up the boot partition

The backup script reads the boot partition.
It checks the image size, compares SHA-256 with a second read of the partition, and writes SHA256SUMS.

scp scripts/backup-openstick-boot.sh openstick:~/
ssh -t openstick 'sudo bash ~/backup-openstick-boot.sh /home/user'

Watch the dd byte counter.
For this device, expect 67,108,864 bytes and a final boot.img: OK.
The script prints a unique directory such as /home/user/boot-backup-20261129T120159Z-IS2ICK.

The script creates root-owned, private files.
Before copying them with the unprivileged SSH account, change ownership of that specific backup directory.
Run on the device, replacing the example directory with the printed path:

BACKUP=/home/user/boot-backup-20261129T120159Z-IS2ICK
sudo chown -R user:user "$BACKUP"
cd "$BACKUP"
sha256sum -c SHA256SUMS

Copy it to the host and verify again:

scp -r 'openstick:/home/user/boot-backup-20261129T120159Z-IS2ICK' "$WORK/"
export BACKUP="$WORK/boot-backup-20261129T120159Z-IS2ICK"
(cd "$BACKUP" && sha256sum -c SHA256SUMS)

If the device has multiple backups, select the one created before flashing.
Keep a second copy off the device.
A copy of /boot/vmlinuz-* is not a substitute for the complete boot-partition image.

Fetch the matching source

Use a separate checkout rather than changing another kernel working tree:

git init "$WORK/source"
git -C "$WORK/source" remote add origin https://github.com/msm8916-mainline/linux
git -C "$WORK/source" fetch --depth=1 origin \
    6cc2342c6a7227a05ca94c836df42d5ba273eef2
git -C "$WORK/source" checkout --detach FETCH_HEAD

git -C "$WORK/source" rev-parse HEAD
head -n 6 "$WORK/source/Makefile"

Expect the full commit above and Linux 6.7.0-rc4.
This shallow checkout also keeps the release suffix used in this session.

Enable WireGuard and review configuration changes

mkdir -p "$WORK/build"
cp "$WORK/config.running" "$WORK/build/.config"
"$WORK/source/scripts/config" --file "$WORK/build/.config" --module WIREGUARD
wireguard-go
make -C "$WORK/source" O="$WORK/build" ARCH=arm64 \
    CROSS_COMPILE=aarch64-linux-gnu- CC=aarch64-linux-gnu-gcc-13 \
    LOCALVERSION=-wireguard olddefconfig

cp "$WORK/build/.config" "$WORK/config.wireguard"
"$WORK/source/scripts/diffconfig" \
    "$WORK/config.running" "$WORK/config.wireguard" | tee "$WORK/config.diff"
grep '^CONFIG_WIREGUARD=' "$WORK/config.wireguard"

Expect CONFIG_WIREGUARD=m.
Kconfig also enables its required crypto libraries, including Curve25519 and ChaCha20-Poly1305.
Compiler-version and capability symbols change when using a newer compiler.
Review config.diff; do not assume WireGuard is the only changed line.

The command-line LOCALVERSION=-wireguard separates new modules from the installed kernel’s modules.
Do not rename a module or force its release string to load it into the old kernel.
The old kernel’s unknown source changes make that unsafe, even without symbol versioning.

Build and monitor progress

Run in Bash so pipefail preserves a failed build’s exit status:

set -o pipefail
make -C "$WORK/source" O="$WORK/build" ARCH=arm64 \
    CROSS_COMPILE=aarch64-linux-gnu- CC=aarch64-linux-gnu-gcc-13 \
    LOCALVERSION=-wireguard -j4 Image modules dtbs \
    2>&1 | tee "$WORK/build.log"

In another terminal, set WORK to the same directory and check progress:

export WORK="$HOME/openstick-wireguard"
tail -f "$WORK/build.log"
# Ctrl-C stops tail, not the build in the other terminal.

CC, LD, DTC, and MODPOST lines show compilation, linking, device-tree processing, and module processing.
These are activity indicators, not a percentage estimate.
Stop if the build exits with an error.
Do not package stale output after a failed build.

After successful completion:

cat "$WORK/build/include/config/kernel.release"
file "$WORK/build/arch/arm64/boot/Image"
file "$WORK/build/drivers/net/wireguard/wireguard.ko"
test -s "$WORK/build/Module.symvers"
test -s "$WORK/build/arch/arm64/boot/dts/qcom/msm8916-yiming-uz801v3.dtb"

Expect the new release, an ARM64 kernel image, and an AArch64 relocatable WireGuard module.
The board DTB is built for completeness; the test image below preserves the original appended DTB.

Package and install modules alongside the old ones

Stage modules locally before touching the device:

make -C "$WORK/source" O="$WORK/build" ARCH=arm64 \
    CROSS_COMPILE=aarch64-linux-gnu- CC=aarch64-linux-gnu-gcc-13 \
    LOCALVERSION=-wireguard \
    INSTALL_MOD_PATH="$WORK/staging" INSTALL_MOD_STRIP=1 modules_install

tar -C "$WORK/staging" --exclude='*/build' --exclude='*/source' \
    -czf "$WORK/modules.tar.gz" lib/modules
cp "$WORK/build/arch/arm64/boot/Image" "$WORK/Image"
cp "$WORK/build/Module.symvers" "$WORK/Module.symvers"

tar -tzf "$WORK/modules.tar.gz" | grep '/wireguard.ko$'
(cd "$WORK" && sha256sum Image modules.tar.gz config.wireguard > SHA256SUMS)
(cd "$WORK" && sha256sum -c SHA256SUMS)

Install under the new release directory without deleting the original modules:

scp "$WORK/modules.tar.gz" openstick:~/modules-wireguard.tar.gz
ssh -t openstick \
    "sudo tar -xzf ~/modules-wireguard.tar.gz -C / && sudo depmod '$RELEASE' && sync"

ssh openstick \
    "test -s /lib/modules/$RELEASE/modules.dep && \
     test -s /lib/modules/$RELEASE/kernel/drivers/net/wireguard/wireguard.ko && \
     echo 'New module files are installed'"

Prepare a boot image for the temporary test

Do not pass the raw ARM64 Image to fastboot flash boot.
The bootloader expects an Android boot image.
Preserve the original addresses, page size, command line, and device tree.

Extract the verified backup:

mkdir -p "$WORK/boot-test"
cd "$WORK/boot-test"
abootimg -x "$BACKUP/boot.img"
cat bootimg.cfg
file zImage initrd.img

For this device, bootimg.cfg reports:

bootsize = 0x4000000
pagesize = 0x800
kerneladdr = 0x80080000
ramdiskaddr = 0x82000000
secondaddr = 0x80f00000
tagsaddr = 0x81e00000

The extracted zImage is gzip-compressed despite its filename.
The initramfs uses Zstandard.
If another device’s formats differ, stop and adapt the packaging procedure.
Do not copy this device’s root PARTUUID into another device’s boot command line.

Replace the compressed kernel while preserving the appended DTB:

python3 - <<'PY'
from pathlib import Path
import gzip
import struct
import zlib

decoder = zlib.decompressobj(31)
decoder.decompress(Path("zImage").read_bytes())
dtb = decoder.unused_data
if not decoder.eof or dtb[:4] != bytes.fromhex("d00dfeed"):
    raise SystemExit("Expected a gzip kernel followed by one DTB")
if len(dtb) < 8 or struct.unpack(">I", dtb[4:8])[0] != len(dtb):
    raise SystemExit("Unexpected appended DTB layout")
Path("original.dtb").write_bytes(dtb)
kernel = gzip.compress(Path("../Image").read_bytes(), mtime=0)
Path("Image.gz-dtb").write_bytes(kernel + dtb)
print(f"Preserved original DTB: {len(dtb)} bytes")
PY

The original initramfs contains modules for the old release.
Append a second CPIO archive containing the new modules rather than removing the original archive.
Linux initramfs processing supports concatenated CPIO archives.

mkdir -p initramfs-add/usr/lib/modules
tar -xzf ../modules.tar.gz -C initramfs-add/usr/lib/modules --strip-components=2
zstd -dc initrd.img > initramfs-test.cpio
(
    cd initramfs-add
    find . -print0 | cpio --null -o -H newc --owner=0:0
) >> initramfs-test.cpio
zstd -q -f initramfs-test.cpio -o initrd-test.img

abootimg --create ../boot-wireguard-test.img \
    -f bootimg.cfg -k Image.gz-dtb -r initrd-test.img
abootimg -i ../boot-wireguard-test.img

cd "$WORK"
sha256sum boot-wireguard-test.img > boot-wireguard-test.img.sha256
sha256sum -c boot-wireguard-test.img.sha256
stat -c '%n: %s bytes' boot-wireguard-test.img

Expect a 64 MiB Android boot image with the original load addresses and command line.
The session’s new kernel payload was approximately 6.82 MiB; its updated ramdisk was approximately 8.28 MiB.
Exact compressed sizes can vary with the toolchain.
If packaging fails because the image is too large, do not enlarge the partition or flash truncated output.

RAM-boot the new kernel without flashing

Keep physical access and the original backup available.
The next command disconnects SSH:

ssh -t openstick 'sudo systemctl reboot bootloader'

Check USB enumeration, then boot the test image:

fastboot devices
fastboot boot "$WORK/boot-wireguard-test.img"

Expect a device serial from fastboot devices and successful transfer/boot messages.
If multiple devices appear, select this device explicitly with fastboot -s SERIAL.
For host permission errors, configure USB permissions or use sudo fastboot.

If rebooting does not enter fastboot, use the board’s physical entry procedure.
If fastboot boot is unsupported, stop; do not substitute fastboot flash.

Wait for networking, then inspect:

ssh openstick 'uname -r'
ssh -t openstick 'sudo dmesg | tail -n 80'

Expect the new release.
A transfer success alone does not establish that Linux booted successfully.
Confirm SSH, storage, USB networking, and any modem functionality required by your installation.

If Linux hangs, power-cycle the device.
The unchanged boot partition should boot the original kernel again.
This is manual recovery, not automatic fallback.

Verify kernel WireGuard

First check module loading and interface creation:

ssh -t openstick 'sudo modprobe wireguard'
ssh openstick 'cat /sys/module/wireguard/version'
ssh openstick 'lsmod | grep "^wireguard "'
ssh -t openstick \
    'sudo ip link add wg-kernel-check type wireguard && \
     ip -d link show wg-kernel-check && \
     sudo ip link delete wg-kernel-check'

Expect version 1.0.0, a loaded module, and an interface whose detailed output identifies it as wireguard.
If the temporary interface already exists from an interrupted check, inspect it before deleting or reusing it.
Do not delete your production interface.

Check the actual tunnel separately:

ssh openstick 'ip -d link show wg0'
ssh openstick 'ps -eo pid,comm | grep -E "wireguard-go|boringtun" || true'
ssh -t openstick 'sudo wg show wg0'

A kernel WireGuard interface reports the wireguard link type.
A userspace implementation normally uses a TUN interface and a separate daemon.
An installed wireguard-go package does not mean that daemon is running.
Likewise, a loaded kernel module does not prove that every tunnel uses it.

If wg0 remains a userspace TUN interface, migrate it through its existing tunnel manager during a maintenance window.
Do not stop a tunnel carrying your only management connection.

For a configured kernel tunnel, generate traffic to a known peer and inspect:

# Run on the device; substitute a real, reachable peer tunnel address.
ping -c 3 PEER_TUNNEL_IP
sudo wg show wg0 latest-handshakes
sudo wg show wg0 transfer

Look for a recent handshake and increasing traffic counters.

Make the tested kernel persistent

Flash only after the temporary test passes and the backup is verified off-device.
The prepared test image can also serve as the persistent boot image.
The new modules must already exist on the root filesystem.

cd "$WORK"
sha256sum -c boot-wireguard-test.img.sha256
ssh -t openstick 'sudo systemctl reboot bootloader'
fastboot devices
fastboot flash boot "$WORK/boot-wireguard-test.img" && fastboot reboot

Expect successful write and reboot messages.
Do not continue after a flash error.
This writes the boot partition and removes the temporary-test safety property.
The device has no established automatic rollback mechanism.

After boot:

ssh openstick 'uname -r'
ssh -t openstick 'sudo modprobe wireguard'
ssh openstick 'cat /sys/module/wireguard/version; ip -d link show type wireguard'

To confirm persistence, reboot normally and repeat the checks:

ssh -t openstick 'sudo systemctl reboot'
# Wait for SSH to return.
ssh openstick 'uname -r'

This installation writes an Android boot image directly.
It does not register a distribution kernel package or update /boot/vmlinuz-*.
Preserve the image, configuration, module archive, source commit, and checksums for future maintenance.

Restore the original kernel if needed

Enter fastboot using physical recovery access if Linux does not boot.
On the host:

(cd "$BACKUP" && sha256sum -c SHA256SUMS)
fastboot devices
fastboot flash boot "$BACKUP/boot.img" && fastboot reboot

After SSH returns:

ssh openstick 'uname -r'

Expect 6.7.0-rc4-msm8916-g6cc2342c6a72-dirty.
The original module directory remains available because installation did not overwrite it.

The build completed successfully with the recovered configuration, WireGuard, and its dependencies.
The latest session check reports 6.7.0-rc4-msm8916-wireguard-g6cc2342c6a72, kernel WireGuard 1.0.0, and a kernel-type wg0.

Leave a Reply

Your email address will not be published. Required fields are marked *