insmod提示invalid module format

insmod: error could not insert module test.ko: -1 Invalid module format

原因:驱动文件编译的内核版本与当前运行系统的内核版本不一致导致。

1. 通过modinfo 查看test.ko的内核版本vermagic

2. 通过uname -r查看系统的内核版本

 

对于嵌入系统,当确认系统的内核版本与编译版本差异不大,又急用ko时,可以去编译环境下find关键字UTS_RELEASE, 将该定义宏修改为要运行系统内核版本,再重新编译一版驱动,就可以通过magic校验。

UTS_RELEASE通常可能会在如下头文件中定义:

include/linux/vermagic.h

include/generated/utsrelease.h

 

对于本地系统,部分可以做如下调整。

/usr/src/linux/Makefile:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 130
EXTRAVERSION = -extversion

/usr/src/linux/.config:

CONFIG_LOCALVERSION="-debug"

然后,执行make时:

localhost linux # make
scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
对应的utsrelease.h的内容为:
#define UTS_RELEASE "2.6.130-extversion-debug"

 

posted @ 2020-10-16 11:50  sciapex  阅读(8515)  评论(0编辑  收藏  举报