Chinaunix首页 | 论坛 | 博客
  • 博客访问: 149287
  • 博文数量: 25
  • 博客积分: 1632
  • 博客等级: 上尉
  • 技术积分: 324
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-02 21:19
文章分类

全部博文(25)

文章存档

2011年(13)

2010年(12)

我的朋友

分类:

2010-05-02 15:18:58

将hello world模块直接加入进内核,只需要修改kconfig和makfile文件!
首先将你的驱动程序放到内核目录下相应的地方,如把hello.c放到/workdir/LDD3/emboard-workdir/LDD3/kernel/linux-2.6.24/drivers/char下面:
# ls
hello.c  Makefile
将上面的hello.c复制到上面所示目录:
# cp ../../../../driver/hello/hello.c .
然后修改本目录下的"Kconfig"
# vim Kconfig
在合适的位置添加:(可以参考Kconfig其它驱动的写法)
########################################ADD##########################################
#      Author:          microcreat
#      Date:            20100415
#      Description:     Add the driver of hello in kernel!
config hello
    bool "hello driver"
########################################END########################################
保存退出:
然后修改Makefile文件.
# vim drivers/char/Makefile
添加下面的内容:
########################################ADD########################################
#      Author:          microcreat
#      Date:            20100415
#      Description:     Add the driver of hello in kernel!
obj-$(CONFIG_HELLO) += hello.o
########################################END########################################
保存退出:
然后退到内核根目录:
# make menuconfig
然后选择"Driver Drivers"
选择进入此目录:
进入选中选项:
现在可以看到我们的"hello"模块
可以选择是否编译进内核:
我们可以选择"help"看到我们的help信息:
我们可以修改这个help信息和"Kconfig"里的配置来修改:
########################################ADD########################################
#      Author:          microcreat
#      Date:            20100415
#      Description:     Add the driver of hello in kernel!
config hello
    #bool "hello driver"
    tristate "hello driver support" 
########################################END########################################
修改成上面的形式,然后去"make menuconfig"配制去看看!
可以看到,可以去配置"M"了!
各条目的选项为:y 表示 是 (相应功能将直接编译进内核),m 表示 模块 (相应功能将编译为一个模块),以及 n 表示 否 (相应功能不会包含进内核)。
你也可以为这个设备去书写配置说明;
########################################ADD########################################
#      Author:          microcreat
#      Date:            20100415
#      Description:     Add the driver of hello in kernel!
config hello
    #bool "hello driver"
    tristate "hello driver support"
    --help--
      if you say Y here, you will get support hello driver.
      chose N,you will not get the support hello driver.
      if you say M,this will to be a module!  
########################################END########################################
然后去"make menuconfig"界面去看下效果,可以进入"help"选项看到你所写的帮助文档!
保存退出,然后编译,这样就可以把驱动编译进入内核中了!
# make
# make bzImage
# make modules
# make modules_install
这样就可以把hello编译进入内核!
这个驱动不能做什么,我们可以慢慢的把hello慢慢完善,给它添加功能!
 
 
阅读(1719) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~