hello.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
MODULE_LICENSE(“Dual BSD/GPL”);//设备注册
MODULE_AUTHOR(“YYZ”);//作者信息
static int hello_init(void)
{
printk(KERN_EMERG “hello module has been mount!\n”);
return 0;
}
static void hello_exit(void)
{
printk(KERN_EMERG “hello module has been remove!\n”);
platform_driver_unregister(&hello_driver);
}
module_init(hello_init);
module_exit(hello_exit);
Makefile:
obj-m := hello.o
KERNEL_DIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
make -C
(
K
E
R
N
E
L
D
I
R
)
S
U
B
D
I
R
S
=
(KERNEL_DIR) SUBDIRS=
(KERNELDIR)SUBDIRS=(PWD) modules
clean:
rm *.o *.ko *.mod.c
.PHONY:clean