I need to prepare an apt
-package for stuff to enable building kernel modules for a custom Linux. I have cross-built on a different machine the kernel headers and modules using headers_install
and modules_install
make
-targets. After copying the generated directories I'm still not able to build kernel modules on the target machine since /lib/modules/$(shell uname -r)/build
is missing.
Here is my question. What are the minimal dependencies I need to include to my package in order to enable module builds (alongside with the generated kernel headers and modules mentioned above)?
Thanks in advance.
After some experimenting I've got to a working solution:
#!/bin/bash
ARCH=arm
SRC_DIR=$1
MOD_DIR=$2
BUILD_DIR=$MOD_DIR/build
set -ex
cd $SRC_DIR
make modules_install INSTALL_HDR_PATH=$MOD_DIR
rm $MOD_DIR/{build,source}
mkdir $BUILD_DIR
cp $SRC_DIR/{.config,Makefile,System.map,Module.symvers} $BUILD_DIR
mkdir -p $BUILD_DIR/arch/$ARCH
cp $SRC_DIR/arch/$ARCH/Makefile $BUILD_DIR/arch/$ARCH/
cp -r $SRC_DIR/scripts $BUILD_DIR/
# Build a headers tree manually, because
# `make headers_install` doesn't put everything needed.
cp -r $SRC_DIR/include $BUILD_DIR/
cp -r $SRC_DIR/arch/$ARCH/include/* $BUILD_DIR/include/
cp -r $SRC_DIR/include/generated/* $BUILD_DIR/include/
cp -r $SRC_DIR/arch/$ARCH/include/generated/* $BUILD_DIR/include/
cp $SRC_DIR/include/linux/kconfig.h $BUILD_DIR/include/linux/
This script is fed with a path to a kernel source tree after the latter was built natively (not cross-platform).