一、Linux设备驱动 - HelloDriverModule

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文件拷贝到开发板执行
在这里插入图片描述

发布了29 篇原创文章 · 获赞 9 · 访问量 1837

猜你喜欢

转载自blog.csdn.net/m0_46291920/article/details/104555700