ubuntu下交叉编译arm64/armbian内核模块

转自 ubuntu下交叉编译arm64/armbian内核模块

安装编译环境及下载交叉编译工具:

apt update
apt -y install gcc make pkg-config git bison flex libelf-dev libssl-dev libncurses5-dev bc
wget https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
tar -Jxf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz 
export ARCH=arm64 
export CROSS_COMPILE=`pwd`/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

查看armbian内核版本:

uname -r
4.18.7-aml-s9xxx

下载内核源码:

#git clone https://github.com/150balbes/Amlogic_s905-kernel.git
#使用4.18.7内核
#git checkout 20181012
git clone -b 20181012 --depth 1 https://github.com/w22gb8/Amlogic_s905-kernel.git
cd Amlogic_s905-kernel

初始化配置,不做这步直接编译模块会提示错误: fatal error: include/generated/autoconf.h: No such file or directory。

cp config_5.60 .config
make prepare
make scripts

编译指定模块:

make M=net/ipv4/ CONFIG_TCP_CONG_BBR=m modules
make M=drivers/usb/class CONFIG_USB_PRINTER=m modules

编译所有模块:

make modules 
make modules_install INSTALL_MOD_PATH=/

复制模块到目标机器对应目录并加载:

cp tcp_bbr.ko /lib/modules/`uname -r`/kernel/net/ipv4
#echo 'kernel/net/ipv4/tcp_bbr.ko:' >> /lib/modules/`uname -r`/modules.dep
depmod 
modprobe tcp_bbr

加载模块时出现invalid module format的错误,是version magic版本不一致或crc校验不通过,可通过modinfo查看本机模块和新编译模块version magic版本信息,通过dmesg查看log出现以下错误:

sch_fq: version magic '4.18.7 SMP preempt mod_unload aarch64' should be '4.18.7-aml-s9xxx SMP preempt mod_unload aarch64'

可见内核版本后缀不一样,在编译时添加版本后缀:

make LOCALVERSION="-aml-s9xxx"

编译模块时添加版本后缀无效?那就在初始时添加,后续编译时不要再次添加。

make LOCALVERSION="-aml-s9xxx" modules_prepare

参考:
https://serverfault.com/questions/568395/what-is-creating-the-generated-autoconf-h
https://wiki.archlinux.org/index.php/Compile_kernel_module

你可能感兴趣的:(ubuntu下交叉编译arm64/armbian内核模块)