免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 710 | 回复: 0
打印 上一主题 下一主题

HelloWorld模块加入内核 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:41 |只看该作者 |倒序浏览
1.将linux内核包解压

2.make编译内核

3.make menuconfig

4.将helloword模块加入内核

(1)copy helloworld 到 driver/char/helloworld

(2)vim Kconfig

加入

config HELLO_WORLD

tristate "helloworld"

default m

help

this is a test

(3)vim driver/char/Kconfig

在endmenu前加入
source  "driver/char/helloworld/Kconfig"

(4)vim driver/char/Makefile

obj-$(CONFIG_HELLO_WORLD)+=helloword/(是文件夹)


hello.c文件

  1. #include <linux/init.h>
  2. #include <linux/module.h>

  3. static int hello_init()
  4. {
  5.     printk(KERN_ALERT "Hello,world\n");
  6.     return 0;
  7. }
  8. static void hello_exit()
  9. {
  10.     printk(KERN_ALERT "Goodbye,cruel world\n");
  11. }
  12. module_init(hello_init);
  13. module_exit(hello_exit);
  14. MODULE_LICENSE("Dual BSD/GPL");
Makefile文件

  1. CONFIG_HELLO_WORLD ?= m
  2. ifneq ($(KERNELRELEASE),)
  3. hello_world-objs := hello.o
  4. obj-$(CONFIG_HELLO_WORLD) += hello_world.o
  5. else
  6. KERNELDIR=/home/zhb/software/linux-2.6.30.4/
  7. PWD := $(shell pwd)
  8. modules:
  9. $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
  10. endif
  11.  clean:
  12. rm -rf *.o *.ko *.order *.symvers *.mod.c *.markers

Kconfig文件(和driver/char/Kconfig不是同一个文件)

  1. config HELLO_WORLD
  2. tristate "helloworld"
  3. default m
  4. help
  5.     this is a test


您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP