linux 驱动开发 Invalid module format 和 File exists 错误解决方法
2015-04-12 15:00
489 查看
原文 http://blog.csdn.net/pottichu/article/details/1892245
我想,很多刚开始学习linux 驱动程序的朋友都和我一样,遇到过类似的问题。
1. 编译错误(其实这个问题和 Makefile有很大关系)
2. Invalid module format 错误
3. insmod: error inserting './hello.ko': -1 File exists
开发环境
内核版本: 2.6.22 (我下载的最新版本)
gcc : gcc (GCC) 4.1.2
hello.c 程序可以参考
http://dev.yesky.com/154/2621154.shtml
Makefile
gcc -D__KERNEL__ -DMODULE -DLINUX -I /usr/local/src/linux2.4/include -c -o hello.o hello.c
上面这种写法适合 2.4 版本的内核, 在2.6下用这种写法很可能导致许多编译错误,
即使编译通过也会产生 Invalid module format 错误。
至于原因请参考
http://blog.csdn.net/pottichu/archive/2007/11/19/1892203.aspx
2.6下正确的 Makefie 如下:
# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.
mymodule-objs := hello.o
obj-m := hello.o
else
PWD := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif
使用上面的 Makefie 同时也解决了 Invalid module format 错误
insmod: error inserting './hello.ko': -1 File exists 错误 解决
第一次insmod ./hello.ko 没有输出表示你的模块被正常载入了,后来的错误是你重复载入这个模块导致的
用命令 lsmod | grep hello 看看是不是有这个模块?
用命令 tail /var/log/messages
有没有 hello,world
OK 我的第一个module 程序终于正常执行了。
我想,很多刚开始学习linux 驱动程序的朋友都和我一样,遇到过类似的问题。
1. 编译错误(其实这个问题和 Makefile有很大关系)
2. Invalid module format 错误
3. insmod: error inserting './hello.ko': -1 File exists
开发环境
内核版本: 2.6.22 (我下载的最新版本)
gcc : gcc (GCC) 4.1.2
hello.c 程序可以参考
http://dev.yesky.com/154/2621154.shtml
Makefile
gcc -D__KERNEL__ -DMODULE -DLINUX -I /usr/local/src/linux2.4/include -c -o hello.o hello.c
上面这种写法适合 2.4 版本的内核, 在2.6下用这种写法很可能导致许多编译错误,
即使编译通过也会产生 Invalid module format 错误。
至于原因请参考
http://blog.csdn.net/pottichu/archive/2007/11/19/1892203.aspx
2.6下正确的 Makefie 如下:
# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.
mymodule-objs := hello.o
obj-m := hello.o
else
PWD := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif
使用上面的 Makefie 同时也解决了 Invalid module format 错误
insmod: error inserting './hello.ko': -1 File exists 错误 解决
第一次insmod ./hello.ko 没有输出表示你的模块被正常载入了,后来的错误是你重复载入这个模块导致的
用命令 lsmod | grep hello 看看是不是有这个模块?
用命令 tail /var/log/messages
有没有 hello,world
OK 我的第一个module 程序终于正常执行了。
相关文章推荐
- linux 驱动开发 Invalid module format 错误解决方法
- linux 驱动开发 Invalid module format 错误解决方法
- Linux加载驱动"invalid module format"错误的一种可能解决办法
- Linux 2.6.x 内核模块加载错误 “Invalid module format” 解决办法
- Linux 2.6.x 内核模块加载错误 “Invalid module format” 解决办法
- Linux 2.6.x 内核模块加载错误 “Invalid module format” 解决办法
- Linux 2.6.x 内核模块加载错误 “Invalid module format” 解决办法
- Linux 2.6.x 内核模块加载错误 “Invalid module format” 解决办法
- module编译和insmod invalid format问题解决方法
- 关于微信公众号开发config:invalid signature错误的解决方法
- three.js_82 出现WebGL: INVALID_OPERATION: copyTexImage2D: framebuffer is incompatible format错误解决方法
- module编译和insmod invalid format问题解决方法
- 第一个驱动helloworld module加载insmod “Invalid module format ”问题解决
- Linux启动网卡时出现RTNETLINK answers: File exists错误解决方法
- Eclipse下开发安卓出现"Convert To Dalvik Format"错误解决方法
- linux RTNETLINK answers: File exists错误解决方法
- linux ---------驱动开发遇到的问题及解决方法
- module编译和insmod invalid format问题解决方法
- Linux启动网卡时出现RTNETLINK answers: File exists错误解决方法
- 出现insmod: can't insert 'kernel_hello.ko': invalid module format解决方法