您的位置:首页 > 其它

设备驱动编写流程之一

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挂载驱动

就可以看到结果。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: