Chinaunix首页 | 论坛 | 博客
  • 博客访问: 109008
  • 博文数量: 50
  • 博客积分: 968
  • 博客等级: 少尉
  • 技术积分: 492
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-17 09:51
文章分类

全部博文(50)

文章存档

2012年(2)

2011年(48)

我的朋友

分类: 嵌入式

2011-06-14 11:22:50

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


阅读(1659) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~