设备驱动编写流程之一
2010-03-09 09:51
176 查看
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挂载驱动
就可以看到结果。
文件的内容如下
/*************************************
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字符设备驱动编写基本流程
- 设备驱动编写流程之一
- 字符设备驱动编写流程以及大概框架
- 设备驱动编写流程之二
- 设备驱动编写流程之二
- Linux字符设备驱动编写流程
- Linux字符设备驱动编写流程
- Linux驱动USB驱动程序之USB设备驱动程序1简单编写
- linux2.6设备驱动编写
- 代码:编写一个简单的字符设备驱动
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解
- 编写块设备驱动之内存模拟磁盘
- 嵌入式Linux字符设备驱动LED驱动编写
- platform设备注册的时候,去platform总线上寻找相应驱动的流程
- 【转】Linux I2C设备驱动编写(二)
- linux内核数据包转发流程(一):网络设备驱动
- Linux 字符设备驱动开发基础(二)—— 编写简单 PWM 设备驱动
- Linux 字符设备驱动开发基础(二)—— 编写简单 PWM 设备驱动
- 学习笔记 --- LINUX USB设备驱动的编写
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解