您的位置:首页 > 运维架构 > Linux

LINUX2.6.26内核简单驱动程序开发

2008-10-31 15:01 218 查看
驱动函数源码:
#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("GPL");

static int times=1;
module_param(times,int,S_IRUGO);

static int hello_init(void)
{
int i=0;
for(;i <times;i++)
printk(KERN_ALERT "hello,word/n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye,word/n");
}

module_init(hello_init);
module_exit(hello_exit);

Makefile文件源码,内核源码路径为/home/wfg/linux-2.6.26.3:
# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationship of files and target modules are listed here.
obj-m :=helloword.o
#obj-m :=gpio_driver.o
else
PWD :=$(shell pwd)
KEVER ?=$(shell uname -r)
#KDIR :=/home/wfg/linux-2.6.26.3/$(KEVER)/build
KDIR :=/home/wfg/linux-2.6.26.3
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions *.order *symvers
endif

编译通过:
wfg@wk-develop:~$ cd driver
wfg@wk-develop:~/driver$ make clean
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions *.order *symvers
wfg@wk-develop:~/driver$ make all
make -C /home/wfg/linux-2.6.26.3 M=/home/wfg/driver
make[1]: 正在进入目录 `/home/wfg/linux-2.6.26.3'
LD /home/wfg/driver/built-in.o
CC [M] /home/wfg/driver/helloword.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/wfg/driver/helloword.mod.o
LD [M] /home/wfg/driver/helloword.ko
make[1]:正在离开目录 `/home/wfg/linux-2.6.26.3'
wfg@wk-develop:~/driver$
将此helloword.ko驱动拖到NFS文件系统的LIB/MODULES目录下,执行时发现:
[sw-linux:]ls
helloword.ko kernel modules.dep.bb
[sw-linux:]insmod ./helloword.ko
insmod: module './helloword.ko' not found
[sw-linux:]

之前是因为LIB/MODULES文件夹没有所以产生CHDIR(2.6.26.3):No such files的错误
为什么呢? 问题解决中。。。。。。。

原因是insmod等模块加载命令需要在/lib/modules/2.6.26.3文件夹下面去读取指定的模块,必须将模块放在此目录下面。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: