Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->网络应用 ->正文

Linux驱动Invalid module format错误解决

来源: 作者:Webmaster 时间:2008-08-18 点击: [收藏] [投稿]

1.编译错误(其实这个问题和 Makefile有很大关系)

2.Invalid module format 错误

3.insmod: error inserting './hello.ko': -1 File exists

开发环境

内核版本:2.6.22(我下载的最新版本)

gcc:gcc (GCC) 4.1.2

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 错误。

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

module程序正常执行。

(责任编辑:云子)



 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:Linux操作系统上去掉文件属性的命令介绍   下一篇:技巧:为Fedora Linux 8设置本地更新源

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号