1.在drivers/char/目录下建立一个first_driver_hello.c文件
文件的内容如下
/*************************************
NAME:first_driver_hello.c
COPYRIGHT:328977974@qq.com
**************************************/
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk("This is the first char driver!/n");
return 0;
}
static void hello_exit(void)
{
printk("GoodBye,good luck!/n");
}
module_init(hello_init);
module_exit(hello_exit);
2.在内核源码处添加对first_driver_hello.c驱动的支持
修改drivers/char 目录下的Kconfig文件,添加如下内容
config FIRST_DRIVER_HELLO
tristate "FIRST DRIVER HELLO"
depends on ARCH_S3C2440
help
BY 328977974@qq.com
3.修改drivers/char 目录下的Makefile文件
添加如下内容
obj-$(CONFIG_FIRST_DRIVER_HELLO) += first_drivers_hello.o
4.进入内核根目录下配置内核,输入make menuconfig
Device Drivers ->
Character devices ->
<M> FIRST DRIVERS HELLO
保存后使用命令 make SUBDIR=drivers/char/ modules
5.在drivers/char/ 目录下面会生成一个first_drivers_hello.ko的文件
将它复制到开发板下,用命令insmod first_drivers_hello.ko挂载驱动
就可以看到结果。
设备驱动编写流程之一
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:设备驱动编写流程之二
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Linux下PCI设备驱动开发详解(四)
一般来说,用模块方式编写PCI设备驱动,通常至少要实现以下几个部分:初始化设备模块、设备打开模块、数据读写模块、中断处理模块、设备释放模块、设备卸载模块。
驱动程序 PCI FPGA linux内核 probe -
bash脚本编程之一
bash脚本编程之一详解
Linux -
【深入Linux块设备驱动层次之一】整体层次
介绍了两个不同作者对linux 块设备驱动层次划分的框图,指出了其中的差异,分析了其中的原因。
Linux device block