fix(build): detect native ARM64 host and skip cross-compiler requirement
Some checks failed
CI / Go Tests (push) Successful in 1m32s
CI / Shellcheck (push) Failing after 39s
CI / Build Go Binaries (amd64, linux, linux-amd64) (push) Failing after 1m27s
CI / Build Go Binaries (arm64, linux, linux-arm64) (push) Failing after 2m32s

build-kernel-arm64.sh and build-kernel-rpi.sh both insisted on
aarch64-linux-gnu-gcc (the cross-compiler from x86), which fails on a native
ARM64 build host like the Odroid runner. Detect uname -m and use the host's
gcc with an empty CROSS_COMPILE on aarch64 hosts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-14 10:56:39 -06:00
parent 80aca5e372
commit c20f5a2e8c
2 changed files with 48 additions and 20 deletions

View File

@@ -35,11 +35,24 @@ if [ -f "$CUSTOM_IMAGE" ] && [ -d "$CUSTOM_MODULES" ]; then
exit 0
fi
# --- Verify cross-compiler ---
if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
echo "ERROR: aarch64-linux-gnu-gcc not found"
echo "Install: apt-get install gcc-aarch64-linux-gnu"
exit 1
# --- Toolchain selection: native on arm64 hosts, cross-compile elsewhere ---
HOST_ARCH="$(uname -m)"
if [ "$HOST_ARCH" = "aarch64" ] || [ "$HOST_ARCH" = "arm64" ]; then
if ! command -v gcc >/dev/null 2>&1; then
echo "ERROR: gcc not found"
echo "Install: apt-get install build-essential"
exit 1
fi
CROSS_COMPILE=""
echo "==> Native ARM64 build (host arch: $HOST_ARCH)"
else
if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
echo "ERROR: aarch64-linux-gnu-gcc not found"
echo "Install: apt-get install gcc-aarch64-linux-gnu"
exit 1
fi
CROSS_COMPILE="aarch64-linux-gnu-"
echo "==> Cross-building RPi kernel from $HOST_ARCH"
fi
echo "==> Building RPi kernel (raspberrypi/linux)..."
@@ -65,7 +78,7 @@ cd "$KERNEL_BUILD_DIR"
# --- Apply base config (Pi 4 = bcm2711) ---
echo "==> Applying bcm2711_defconfig..."
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
make ARCH=arm64 CROSS_COMPILE="$CROSS_COMPILE" bcm2711_defconfig
# --- Apply container config overrides ---
CONFIG_FRAGMENT="$PROJECT_ROOT/build/config/kernel-container.fragment"
@@ -98,7 +111,7 @@ if [ -f "$CONFIG_FRAGMENT" ]; then
fi
# Resolve dependencies
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- olddefconfig
make ARCH=arm64 CROSS_COMPILE="$CROSS_COMPILE" olddefconfig
# --- Build kernel + modules + DTBs ---
NPROC=$(nproc 2>/dev/null || echo 4)
@@ -106,7 +119,7 @@ echo ""
echo "==> Building RPi kernel (${NPROC} parallel jobs)..."
echo " This may take 20-30 minutes..."
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j"$NPROC" Image modules dtbs 2>&1
make ARCH=arm64 CROSS_COMPILE="$CROSS_COMPILE" -j"$NPROC" Image modules dtbs 2>&1
echo "==> RPi kernel build complete"
@@ -117,7 +130,7 @@ cp arch/arm64/boot/Image "$CUSTOM_IMAGE"
echo "==> Installing modules (stripped)..."
rm -rf "$CUSTOM_MODULES"
mkdir -p "$CUSTOM_MODULES"
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
make ARCH=arm64 CROSS_COMPILE="$CROSS_COMPILE" \
INSTALL_MOD_STRIP=1 modules_install INSTALL_MOD_PATH="$CUSTOM_MODULES"
# Remove build/source symlinks