免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1915 | 回复: 6
打印 上一主题 下一主题

求助:关于linux device drivers的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-11-06 23:44 |只看该作者 |倒序浏览
我最近正在看linux device drivers 2nd edition
书中说了只保证程序能在2.0-.2.4.20里运行
为什么书中的内核模块不能在redhat9(内核版本2.4.20-8)里运行,如下面的例子:
#define MODULE
#include <linux/module.h>;
int init_module(void) { printk("<1>;Hello, world\n"; return 0; }
void cleanup_module(void) { printk("<1>;Goodbye cruel world\n"; }
系统说kernel init module不匹配,是不是我现在的内核版本太高了?谁做过这个?怎么解决?如何修改程序才能在redhat9里运行?我不想重装rh系统,先谢谢了

论坛徽章:
0
2 [报告]
发表于 2004-11-07 00:48 |只看该作者

求助:关于linux device drivers的问题

是编译错误还是运行错误?

论坛徽章:
0
3 [报告]
发表于 2004-11-07 02:10 |只看该作者

求助:关于linux device drivers的问题

原帖由 "yhj8341" 发表:
我最近正在看linux device drivers 2nd edition
书中说了只保证程序能在2.0-.2.4.20里运行
为什么书中的内核模块不能在redhat9(内核版本2.4.20-8)里运行,如下面的例子:
#define MODULE
#include <linu..........

你应该把出错信息完整贴上来

论坛徽章:
0
4 [报告]
发表于 2004-11-07 15:04 |只看该作者

求助:关于linux device drivers的问题

具体如下:
[root@localhost root]# vi hello.c
[root@localhost root]# cat hello.c
#define MODULE
#include <linux/module.h>;
                                                                                
int init_module(void) { printk("hello,world\n";return 0;}
void cleanup_module(void) { printk("Goodbye cruel world\n";}
[root@localhost root]# gcc -c hello.c
[root@localhost root]# insmod ./hello.o
./hello.o: kernel-module version mismatch
        ./hello.o was compiled for kernel version 2.4.20
        while this kernel is version 2.4.20-8.
[root@localhost root]#
请楼上的大哥赐教,先谢谢啦!

论坛徽章:
0
5 [报告]
发表于 2004-11-07 16:05 |只看该作者

求助:关于linux device drivers的问题

呵呵,这个问题很好解决了。我当年就遇到这个问题。
把version.h中的版本号"2.4.20-8"改"2.4.20"即可。当然最好把原来的version.h先做个备份。

论坛徽章:
0
6 [报告]
发表于 2004-11-07 19:09 |只看该作者

求助:关于linux device drivers的问题

我搜索到54个version.h文件,也不知道你说的是哪一个。是不是usr/include/linux里的那个?
我察看了里面的内容如下:
[root@localhost root]# cat /usr/include/linux/version.h
#define UTS_RELEASE "2.4.20"
#define LINUX_VERSION_CODE 132116
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << + (c))

已经是2.4.20了,没有2.4.20-8,不知道下面的两行是什么?

我把版本号改成了2.4.20-8并编译运行结果如下:
[root@localhost root]# gcc -c hello.c
[root@localhost root]# insmod ./hello.o
Warning: loading ./hello.o will taint the kernel: no license
  See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module hello loaded, with warnings
[root@localhost root]# gcc -c hello.c
[root@localhost root]# insmod ./hello.o
insmod: a module named hello already exists
[root@localhost root]# rmmod ./hello.o
rmmod: module ./hello.o is not loaded

并没有出现书中所说的结果(
root# insmod ./hello.o
hello,world        )

论坛徽章:
1
水瓶座
日期:2014-03-20 18:21:14
7 [报告]
发表于 2004-11-07 22:10 |只看该作者

求助:关于linux device drivers的问题

rmmod hello
原帖由 "yhj8341"]alhost root 发表:
# rmmod ./hello.o
rmmod: module ./hello.o is not loaded

并没有出现书中所说的结果(
root# insmod ./hello.o
hello,world        )
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP