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

驱动函数源码:
#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文件夹下面去读取指定的模块,必须将模块放在此目录下面。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值