首页 | 互联网 | IT动态 | Cisco | Windows | Linux | Java | .Net | Oracle | 华为 | 存储世界 | 服务器 | 网络设备 | IDC | 安全 | 求职招聘
IT培训 | 数字网校 | 技术专题 | 电子书下载 | 教学视频 | 网页设计 | 平面设计 | 解决方案 | 直播室 | 虚拟考场 | 搜索 | 博客 | 沙龙 | 论坛
中国IT实验室Linux频道
中国IT教育
首页 新手入门 Linux编程 系统管理 网络管理 Linux认证 Unix/BSD Linux数据库 Linux集群 Linux手册 Linux下载 论坛 专题 RSS
您现在的位置: 中国IT实验室 >> Linux >> 系统管理 >> 设备驱动 >> 文章正文

Linux驱动Invalid module format错误解决

文章来源中国IT实验室收集整理 作者佚名 更新时间2008-5-9 保存本文保存本文 推荐给好友推荐给好友 收藏本页收藏本页

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程序正常执行。

【责编:Zenghui】
中国IT教育
相关产品和培训
文章评论
 友情推荐链接
 专题推荐

 ·Linux Shell编程实用指南
 ·Linux日志分析与管理
 ·揭密Linux内存管理
 ·邮件服务Sendmail应用配置
 ·Linux 安全管理
 ·Linux 下DNS服务器架设攻略
 ·Linux 下的路由的配置与应用
 ·专题:Apache实用手册
 ·全面剖析Linux文件系统
 ·Linux常用命令全集
 今日更新
 认证培训
 频道精选
 Windows频道导航