内核2.6.10
//hello.h
#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>
//hello.c
#include"hello.h"
int hello_init(void) //2.6.10内核前面没有_init
{
printk("hello.ko is install \n");
return 0;
}
void hello_exit(void) //2.6.10内核前没有_exit
{
printk("hello.ko is uninstalled!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("ang");
//Makefile
obj-m:=hello.o #产生hello 模块的目标文件
CURRENT_PATH := $(shell pwd) #模块所在的当前路径
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
all:
make -C $(KERNELDIR) M=$(CURRENT_PATH) modules #编译模块
clean:
make -C $(KERNELDIR) M=$(CURRENT_PATH) clean