自己写了个usb test driver,Makefile相关行如下
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
运行$make 生成对应的.ko文件,然后加载该模块:
sudo insmod usb_test_drv.ko
[sudo] password for minipc:
insmod: ERROR: could not insert module usb_test_drv.ko: Invalid module format
在网上搜解决方案,说是编译环境的核的版本号必须和现在运行的核的版本号一致。但是我确实是按照这样去make这个.ko文件。运行命令查找该模块信息,$modinfo usb_test_drv.ko
modinfo usb_test_drv.ko
filename: /home/minipc/linux_usb_driver/usb_test_drv.ko
description: USB test Driver
author: Jason Lee
license: GPL
srcversion: 3A7EC96DAAD77A9F0717507
alias: usb:v10D6p1101d*dc*dsc*dp*ic*isc*ip*in*
depends:
retpoline: Y
name: usb_test_drv
vermagic: 5.19.0-rc3+ SMP preempt mod_unload modversions
注意最后一行vermagic: 5.19.0-rc3+ 是内核版本号,与当前运行的内核版本号一致,我再用同样命令查看已有module的信息,发现vermagic一模一样。
查看dmesg
dmesg | tail
[ 15.398577] wlp2s0: capabilities/regulatory prevented using AP HT/VHT configuration, downgraded
[ 15.402385] wlp2s0: send auth to b8:3a:08:95:e6:11 (try 1/3)
[ 15.404712] wlp2s0: authenticated
[ 15.405197] wlp2s0: waiting for beacon from b8:3a:08:95:e6:11
[ 15.489074] wlp2s0: associate with b8:3a:08:95:e6:11 (try 1/3)
[ 15.510601] wlp2s0: RX AssocResp from b8:3a:08:95:e6:11 (capab=0x411 status=0 aid=4)
[ 15.523525] wlp2s0: associated
[ 16.637403] IPv6: ADDRCONF(NETDEV_CHANGE): wlp2s0: link becomes ready
[ 16.715343] rfkill: input handler disabled
[ 2208.432216] usb_test_drv: disagrees about version of symbol module_layout
最后一行:usb_test_drv: disagrees about version of symbol module_layout
看来还是版本不一致。又在网上查了一些方案,发现不仅要内核版本号一致,config也要保持一致。我记起来以前改过config,通过$make menuconfig,但是没有重新编译内核。但是这次make的这个usb_test_drv是用新的config编译出来的,这可能是导致问题的原因。
于是cd到内核source code的根目录,依次运行:
$make
$make modules_install
$make install
然后重启机器,再运行$sudo insmod usb_test_drv.ko, 没有报错 。再查看
$ lsmod | grep usb
usb_test_drv 16384 0
usbhid 57344 0
usb_storage 73728 0
hid 143360 2 usbhid,hid_generic
第一行就是该驱动。顺利安装成功。
文章来源地址https://www.toymoban.com/news/detail-514420.html文章来源:https://www.toymoban.com/news/detail-514420.html
到了这里,关于insmod error could not insert module ... invalid module format [已解决]的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!