#!/bin/bash # 编译配方目录里的 kernel/。源码是仓库里的这一版,容器里不再克隆、检出或改配置。 # # docker run --rm \ # -v "${PWD}/image/debian/UFI003_MB_V02:/recipe" \ # -v "${PWD}/image/debian/UFI003_MB_V02/dist:/out" \ # debian:trixie bash /recipe/build-kernel.sh set -euo pipefail export DEBIAN_FRONTEND=noninteractive export ARCH=arm64 export CROSS_COMPILE=aarch64-linux-gnu- log() { echo "=== $(date -Is) $* ==="; } SRC=/recipe/kernel if [ ! -f /recipe/build-kernel.sh ]; then SRC=/src fi if [ ! -f "$SRC/Makefile" ] || [ ! -f "$SRC/arch/arm64/configs/ufi003_defconfig" ]; then echo "缺少内核源码:$SRC" >&2 exit 1 fi if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1 || ! command -v dpkg-buildpackage >/dev/null 2>&1; then log "install toolchain" dpkg --add-architecture arm64 apt-get update apt-get install -y git gcc-aarch64-linux-gnu bison flex libssl-dev libssl-dev:arm64 libelf-dev debhelper bc rsync kmod cpio fi jobs="$(nproc)" log "cpus ${jobs}" # 复制到容器里的 ext4 再编译。Windows 挂载盘上直接编译既慢,也会把产物写回源码目录。 rm -rf /tmp/kbuild mkdir -p /tmp/kbuild/linux log "copy source" cp -a "$SRC"/. /tmp/kbuild/linux/ cd /tmp/kbuild/linux log "configure" make ufi003_defconfig if ! grep -q '^CONFIG_RPMSG_CTRL=y' .config; then echo "ufi003_defconfig 没有打开 CONFIG_RPMSG_CTRL。请直接改内核配置,不要在编译时临时打开。" >&2 exit 1 fi log "build" export DPKG_FLAGS="-j${jobs}" make deb-pkg -j"${jobs}" log "collect" mkdir -p /out rm -f /out/*.deb /out/*.buildinfo /out/*.changes cp -f /tmp/kbuild/*.deb /tmp/kbuild/*.buildinfo /tmp/kbuild/*.changes /out/ 2>/dev/null || cp -f /tmp/kbuild/*.deb /out/ ls -lh /out log "done"