您的位置:首页 > 其它

解决insmod: error inserting 'hello.ko': -1 Invalid module format

2016-07-03 14:23 253 查看
实现 功能:在PC的LINUX实现驱动测试,不用在2440上测试

解决insmod: error inserting 'hello.ko': -1 Invalid module format

第一次写Linux驱动,环境搭建了好久,第一次可能是由于GCC的版本问题,编译出来的驱动只能insmod,而无法rmmod

然后是make时使用的内核版本和本系统的版本不一致,

导致出现insmod: error inserting 'hello.o' :-l invalid module format错误

 

我一直在玩开发板,下载的是linux-2.6.30内核,以前为 开发板编译驱动时,比较顺利。

而我的上位机linux系统是fedora10  实验需要,需要为我的上位机写一个驱动。可是写好了以后,

当我 insmod hello.ko时,却一直有一个错误

         insmod: error inserting 'hello.ko': -1 Invalid module format。

网上一查,原因很明确:编译时用的hello.ko的kenerl 不是 我的pc的kenerl版本。

但解决起来,就比较麻烦了,百度一下,说什么要重新编译pc上的内核,还要修改grub。

PC机上的驱动,其实与开发板上的驱动 一点关系都没有。

我只要以pc机的内核为基准,在makefile 那改变内核路径就可以了,可以顺利地编译了!

注意,我是在fedora10 下

cd /usr/src

ls

发现内核头文件,如下

/usr/src/kernels/2.6.27.5-117.fc10.i686

 

解决方法:为生成hello.ko

其Makefile改为如下内容:

 

###############

  1 KERNELDIR=/usr/src/kernels/2.6.27.5-117.fc10.i686  //在此添加内核路径

  2

  3 PWD:=$(shell pwd)

  4 INSTALLDIR=$(PWD)

  5 #CC=arm-linux-gcc   

  6 CC=gcc

  8 obj-m := hello.o

  9 modules:    

 10         $(MAKE) -C $(KERNELDIR) M=$(PWD) modules 

 11

 12 clean:    

 13         rm -rf *.o *.ko *.mod.c *.markers *.order *.symvers    

 14 .PHONY:modules clean

 

////////////

make

insmod hello.ko
看输出信息
cat /var/log/messages | tail -6
ubleshootd_t:s0 key=(null)

Oct  2 11:08:07 tdp setroubleshoot: SELinux is preventing updatedb (locate_t) "sys_resource" locate_t. For complete SELinux messages. run sealert -l 42f53b70-53bb-42db-b6cb-39c247a562ea

Oct  2 11:44:19 tdp kernel: Hello, world!!

Oct  2 11:44:19 tdp kernel: this is my hello world!!

哈哈 ,成功啦
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: