Linux 内核针对驱动的处理有以下两种方式:
- 第一种方式:把所有需要的功能全部编译到内核中,这种方式会导致重新添加或者删除功
能的时候,需要重新编译内核。 - 第二种方式:动态的添加模块,也就是要介绍的“模块的方式添加驱动”。
- mini_linux_module.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Aiot");
static int hello_init(void)
{
printk(KERN_EMERG "HELLO WORLD enter!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_EMERG "HELLO WORLD exit!\n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile
编译驱动模块
将ko文件拷贝到开发板执行