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文件
- #include <linux/init.h>
-
#include <linux/module.h>
-
-
static int hello_init()
-
{
-
printk(KERN_ALERT "Hello,world\n");
-
return 0;
-
}
-
static void hello_exit()
-
{
-
printk(KERN_ALERT "Goodbye,cruel world\n");
-
}
-
module_init(hello_init);
-
module_exit(hello_exit);
-
MODULE_LICENSE("Dual BSD/GPL");
Makefile文件
- CONFIG_HELLO_WORLD ?= m
-
ifneq ($(KERNELRELEASE),)
-
hello_world-objs := hello.o
-
obj-$(CONFIG_HELLO_WORLD) += hello_world.o
-
else
-
KERNELDIR=/home/zhb/software/linux-2.6.30.4/
-
PWD := $(shell pwd)
-
modules:
-
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
-
endif
-
clean:
- rm -rf *.o *.ko *.order *.symvers *.mod.c *.markers
Kconfig文件(和driver/char/Kconfig不是同一个文件)
- config HELLO_WORLD
-
tristate "helloworld"
-
default m
-
help
-
this is a test
阅读(1718) | 评论(0) | 转发(0) |