在ubuntu11.04下直接就可以编写驱动程序,并进行编译。
___________________________________________________________________
hello.c
#include "linux/init.h"
#include "linux/module.h"
static int hello_init(void)
{
printk(KERN_INFO "Hello World linux_driver_module\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_INFO "Goodbey linux_driver_module\n");
}
module_init(hello_init);
module_exit(hello_exit);
_____________________________________________________________________________________
Makefile:
#Makefile 2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax dependency relationship of files and target modules are listed here.
mymodule-objs:=hello.o
obj-m:=hello.o
else
PWD:=$(shell pwd)
KVER?=$(shell uname -r)
KDIR:=/lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.com *.o *.mod.c *.ko .tmp_versions
endif
_______________________________________________________________
步骤:
1.sudo make all;
2.生成hello.ko文件
3.insmod hello.ko
4.lsmod,可以看到hello模块
5.rmmod hello.ko
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)