comodore-iec-emu/kernel/build-in-docker.sh
Christian Werner 914c92bdea
Some checks failed
Build kernel module / build (1:6.12.93-1+rpt1, bookworm) (pull_request) Successful in 8m4s
Build kernel module / build (1:6.18.34-1+rpt1, trixie) (pull_request) Failing after 2m31s
Build kernel module / release (pull_request) Has been skipped
feat(kernel): Add support for Debian suite configuration
Introduce `DEBIAN_SUITE` as a configurable argument in the Dockerfile, build
script, and CI workflow to align kernel builds with the target Raspberry Pi
OS release. Updated documentation to clarify the relationship between
suite versions and kernel compatibility.
2026-06-19 20:45:15 +02:00

54 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Build the IEC listener kernel module in an emulated arm64 container, so it can
# be compiled on a non-Pi (x86) host. The resulting iec_listener.ko is written
# back into this kernel/ directory on the host.
#
# Usage:
# ./build-in-docker.sh # build the module
# ./build-in-docker.sh clean # clean build artifacts
#
# Configurable via environment variables:
# SUITE Debian/RPi OS suite (default: bookworm; use trixie for 6.18.x)
# HEADERS_PKG headers package (default: linux-headers-rpi-v8, 64-bit Zero 2 W)
# e.g. linux-headers-rpi-v7 / -v6 for 32-bit, raspberrypi-kernel-headers
# KERNEL_VERSION exact version to pin, e.g. 1:6.6.51-1+rpt3 (default: latest in repo)
# IMAGE builder image tag (default: iec-kbuild)
#
# NOTE: each raspberrypi apt archive suite serves only the *latest* kernel in its
# pool (bookworm -> 6.12.x, trixie -> 6.18.x), so SUITE must match the kernel you
# target and pinning KERNEL_VERSION to an old release may fail to download. The
# reliable match strategy is to keep the Pi current (`sudo apt full-upgrade`) and
# build with the matching SUITE + default (latest) version. See docs/kernel-notes.md.
set -euo pipefail
cd "$(dirname "$0")"
IMAGE="${IMAGE:-iec-kbuild}"
SUITE="${SUITE:-bookworm}"
HEADERS_PKG="${HEADERS_PKG:-linux-headers-rpi-v8}"
KERNEL_VERSION="${KERNEL_VERSION:-}"
# 1. Make sure the host can run arm64 binaries under qemu (one-time, privileged).
if [ ! -e /proc/sys/fs/binfmt_misc/qemu-aarch64 ]; then
echo "==> registering qemu arm64 binfmt (one-time, needs a privileged container)"
docker run --privileged --rm tonistiigi/binfmt --install arm64
fi
# 2. Build the builder image (installs toolchain + matching kernel headers).
echo "==> building image '$IMAGE' (SUITE=$SUITE HEADERS_PKG=$HEADERS_PKG KERNEL_VERSION=${KERNEL_VERSION:-latest})"
docker build --platform linux/arm64 \
--build-arg DEBIAN_SUITE="$SUITE" \
--build-arg HEADERS_PKG="$HEADERS_PKG" \
--build-arg KERNEL_VERSION="$KERNEL_VERSION" \
-t "$IMAGE" .
# 3. Compile; mount this dir so the .ko lands on the host, owned by the caller.
echo "==> compiling module"
echo "working directory: $PWD"
docker run --rm --platform linux/arm64 \
-u "$(id -u):$(id -g)" -e HOME=/tmp \
-v "$PWD:/build" "$IMAGE" "$@"
echo "==> done"
ls -l iec_listener.ko 2>/dev/null || echo "(no iec_listener.ko produced — see output above)"