第一個的程式 hello world for device drivers
#######################################################
[root@localhost hello]# cat hello.c
#include < linux/kernel.h >
#include < linux/module.h >
#include < linux/init.h >
static int __init hello_init(void){
printk("<1>Hello, World!!\n");
return 0;
}
static void __exit hello_exit(void){
printk("<1>Bye!Bye!!\n");
}
module_init(hello_init);
module_exit(hello_exit);
[root@localhost hello]#
#######################################################
[root@localhost hello]# cat Makefile
obj-m += hello.o
all:
make -C /lib/modules/2.6.9/build M=/mnt/driver/hello modules
# 上列可改成
# make V=1 -C /lib/modules/`uname -r`/build M=`pwd` modules
# #號為註解
clean:
make -C /lib/modules/2.6.9/build M=/mnt/driver/hello clean
[root@localhost hello]#
#######################################################
[root@localhost hello]# insmod hello.ko
Hello, World!!
[root@localhost hello]# rmmod hello
Bye!Bye!!
[root@localhost hello]#
沒有留言:
張貼留言