LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 858|回复: 14

请问关于驱动的版本控制问题

[复制链接]
发表于 2004-12-29 00:34:37 | 显示全部楼层 |阅读模式
操作系统是fc3 。

一开始代码如下:
#define MODULE
#include <linux/module.h>

int init_module(void)
{
  printk("<1>hello,world\n");
  return 0;
}

void cleanup_module(void)
{
  printk("<1>goodbye\n");
}
编译后,输入insmod ./hello.o
insmod: error inserting './helloworld.o': -1 Invalid module format
然后翻书,书上说可能是版本控制功能的缘故
然后翻到书上相应页,添加如下代码
#include <linux/config.h>
#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
#define MODVERSIONS
#endif

#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif

重新编译,输入insmod ./hello.o
还是出现insmod: error inserting './helloworld.o': -1 Invalid module format


小弟是菜菜鸟,刚开始学编写linux驱动,请各位前辈指点指点怎么才能装载我编译的这个模块
发表于 2004-12-29 14:28:19 | 显示全部楼层
2.6的module不在适用以前的编译方法

在你的driver代码目录下,新建一Makefile,内容如下:
obj-m:=<你的源文件名(不含后缀)>.o



运行:
make -C <kernel source's path> SUBDIRS=<your driver's path> modules

然后会得到一个*.ko的模块文件。
 楼主| 发表于 2004-12-29 19:54:00 | 显示全部楼层
这正是我担心的地方,我是在网上down的iso安装的。书上说内核的源代码会在/usr/src目录下,但在我的系统里这个目录里面确是空的。

以上代码上的.h文件我倒是可以在系统里面找到的

我知道我问的问题很弱,但我还是要问。要编译象驱动程序这样的模块一定需要内核源码么?若没有那该怎么办?下载fc3的内核代码,然后解压?
发表于 2004-12-30 16:20:10 | 显示全部楼层
Post by sleepwalker
这正是我担心的地方,我是在网上down的iso安装的。书上说内核的源代码会在/usr/src目录下,但在我的系统里这个目录里面确是空的。

以上代码上的.h文件我倒是可以在系统里面找到的

我知道我问的问题很弱,但我还是要问。要编译象驱动程序这样的模块一定需要内核源码么?若没有那该怎么办?下载fc3的内核代码,然后解压?

下载一个内核重新编译一下,FC3真的很过分,我也完全安装了一份,结果没有内核源代码
 楼主| 发表于 2004-12-30 23:41:58 | 显示全部楼层
多谢斑竹:)

小弟还有一点不明白,内核代码下载下来后,一定要重新编译内核代码?

为了装linux,我的本本已经被折磨的不象样了,里面有太多的有用数据,实在不想再格硬盘了
 楼主| 发表于 2004-12-31 11:06:32 | 显示全部楼层
i have downloaded the kernel-2.6.9-1.667.src.rpm and try to follow the release notes's instruction.

first ,i typed " rpm -ivh kernel-2.6.9-1.667.src.rpm"

but in the second step i got some problems:
i have changed the directory to /usr/src/redhat/specs following the instruction. But the next command in instrution confused me .
the command is "rpmbuild -bp --target=<arch> kernel.spec"
After i typed the command "rpmbuild -bp --target=/usr/src/redhat/BUILD kernel-2.6.spec" , an error occured :
Building target platforms: /usr/src/redhat/BUILD
Building for target /usr/src/redhat/BUILD
error: Architecture is not included: /usr/src/redhat/build

i guess i have something wrong about understanding the meaning of "desired architecture".

please help me

thanks
 楼主| 发表于 2004-12-31 14:30:22 | 显示全部楼层
我已经编译好内核了,但是还是编译不了模块

我输入的命令是 gcc -c /lib/modules/2.6.9-1.667/build /usr/programing/helloworld.c modules

错误提示是gcc: modules: 没有那个文件或目录

然后我看了一下,目录里多了一个helloworld.o的文件

但是还是不可以insmod
发表于 2004-12-31 15:03:05 | 显示全部楼层
请参考楼上第二贴的编译方法
 楼主| 发表于 2004-12-31 15:59:35 | 显示全部楼层
惭愧,看错了。现在已经纠正过来,但还是没编译成功

make -C /lib/modules/2.6.9-1.667/build SUBDIRS=$PWD modules
make: Entering directory `/lib/modules/2.6.9-1.667/build'
  Building modules, stage 2.
  MODPOST
make: Leaving directory `/lib/modules/2.6.9-1.667/build'

但我ls了一下,没有helloworld.ko文件,甚至什么新文件都没产生
 楼主| 发表于 2004-12-31 16:11:46 | 显示全部楼层
这次我编译成功了,总算出现了.o和.ko文件。主要改了两个东西:
1,把前面加的的那段代码去掉了
2,把Makefile里的内容改成斑竹建议的内容(我看的the linux kernel module programming guide里的格式是在“=”前加上符号“+”的)
现在虽然编译成功,但加载的时候还是那个错误。

是不是除了要重新编译内核使内核不允许模块版本控制功能,就没有其他办法了?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表