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文件夹下面去读取指定的模块,必须将模块放在此目录下面。
#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文件夹下面去读取指定的模块,必须将模块放在此目录下面。
相关文章推荐
- linux驱动程序开发的简单休眠
- Linux驱动程序开发005 - 内核同步技术
- Linux2.6内核PCI驱动程序开发
- 基于AT91RM9200与LINUX2.6.26内核的嵌入式平台开发全过程
- 基于AT91RM9200与LINUX2.6.26内核的嵌入式平台开发全过程
- Linux USB 驱动开发(五)—— USB驱动程序开发过程简单总结
- Linux驱动程序开发基础, -->内核模块编程,内核的调试方法
- Linux 内核开发—内核简单介绍
- Linux USB 驱动开发(五)—— USB驱动程序开发过程简单总结
- Linux内核开发之简单字符设备驱动(下)
- Linux2.6内核PCI驱动程序开发
- Linux2.6下开发简单的可加载内核模块
- 基于AT91RM9200与LINUX2.6.26内核的嵌入式平台开发全过程
- linux 设备驱动开发学习笔记(一):最简单的内核模块
- Linux2.6内核PCI驱动程序开发
- 基于AT91RM9200与LINUX2.6.26内核的嵌入式平台开发全过程
- Linux 内核开发—内核简单介绍
- Linux内核开发之将驱动程序添加到内核
- Linux内核开发之将驱动程序添加到内核
- Linux USB 驱动开发(五)—— USB驱动程序开发过程简单总结