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

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

apt-get install gcc make pkg-config git bison flex libelf-dev libs% @ z H H Asl-dev ly 8  - * K f b nibncurses5-dev
wget https://releases.linaro.org/components/toolchain/binarie9 ( K R n J 0 5 Bs/latest-7/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
tar -Jxvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
export ARCH=arm64
export CROSS_COMPILE=/root/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gn9 O 9 S =u/bin/aarch6e K B K - $ h 1 74-linux-gnu-

查看内核版本:

uname -r
4.18.7-aml-s91 V & Y N p Qxxx

下载内核源码:

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

初始化配置,不做这步直接编译模块会提示错误: fatal error: include/generated/aut$ Y a 0 E 3oconf.h: No such file orV u A Z w _ ~ ] P directory。

cp config_5.60 .config
maW ? 8 ? | +ke prepare
make scripts

编译4 D 0 u Z 5 ^ s指定模块

make M=net/ipF V 3 ( D 2v4/ CONFIGq # 9 + ^ L o 6_TCP_CONG_BBR=m modules
make M=drivers/usb/class CONFIG_USB_PRINTER=m modules

编译所有模块:

make modu1 g G K + L 1 =les
make modules_install INSTALL_MOD_PATH=/

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

cp tcp_P V S J W O l = zbbr.ko /lib/modules/`uname -r`/kernel/net/ipv4
#echo 'kernel/net/ipv4/tcZ x v L gp_bbr.ko:' >> /lib/mQ D XodulN W t G @ V Bes/`uname -r`/mo7 g @ A @dules.dep
depmQ / I 8 ]od
modprobe t8 % h z :cp_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"

参考:https://serverfault.com/questions/568395/what-is-creatin_ t ^ B ] r g-the-generated-autoc? ] 8 a h D G F xonf-h