example.c
#include< linux/init.h >
#include< linux module.h >
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
編譯Linux Driver的Makefile檔案
注意:make前面的空白一定要是tab,否則無法編譯
Makefile
obj-m := example.o ifeq ($(KERNELDIR),) KERNELDIR=/lib/modules/$(shell uname -r)/build endif all: make -C $(KERNELDIR) M=$(PWD) modules clean: make -C $(KERNELDIR) M=$(PWD) clean
使用insmod ./example.ko安裝Driver
rmmod example解除安裝Driver
使用dmesg | tail查看輸出文字
創用CC,轉貼或引用請註明出處

沒有留言:
張貼留言