对于linux驱动程序的学习,一直都没有停下过,工作上,总是硬件、驱动、系统、应用一块儿整,感觉自己虽然学的很多,但没有一点是可以说做得非常漂亮的。
现在开始,把LDD3重新理一遍
内核版本:企业版5 :linux 2.6.18
hello world 模块源程序
:
#include <linux/init.h>
#include <linux/module.h>//所有的模块代码都应包含的头文件
#include <linux/moduleparam.h>//
static char *who= "who";
static int time= 1;
module_param(time, int, S_IRUGO);
module_param(who, charp, S_IRUGO);//模块insmod 可选参数
static int hello_init(void)
{
int i=0;
for (i=0; i<time; i++)
printk(KERN_ALERT"HELLO,WORLD::::%s/n",who);
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT"GOOBYE,WORLD/n");
return 0;
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("Dual BSD/GPL");
EXPORT_SYMBOL(who);
EXPORT_SYMBOL(time);
Makefile内容:
obj-m:=hello.o hellop.o
KERNEL_DIR:=/lib/modules/$(shell uname -r)/build
PWD:=$(shell pwd)
all:
make -C $(KERNEL_DIR) M=$(PWD) modules
clean:
rm *.o *.ko *~ *.mod.c *.symvers