- #include <linux/init.h>
- #include <linux/module.h>
- MODULE_LICENSE("Dual BSD/GPL");
- static int hello_init(void)
- {
- printk(KERN_ALERT "Hello, world\n");
- return 0;
- }
- static void hello_exit(void)
- {
- printk(KERN_ALERT "Goodbye, cruel world\n");
- return 0;
- }
- module_init(hello_init);
- module_exit(hello_exit);
Makefile:
- KERNELDIR=/opt/EmbedSky/linux-2.6.30.4
- PWD:=$(shell pwd)
- INSTALLDIR=$(PWD)
- CC=arm-linux-gcc
- obj-m := hello.o
- modules:
- $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
- clean:
- rm -rf *.o *.ko *.mod.c *.markers *.order *.symvers
- .PHONY:modules clean
make的时候出现如下错误:
- make[1]: Entering directory `/opt/EmbedSky/linux-2.6.30.4'
- ERROR: Kernel configuration is invalid.
- include/linux/autoconf.h or include/config/auto.conf are missing.
- Run 'make oldconfig && make prepare' on kernel src to fix it.
- WARNING: Symbol version dump /opt/EmbedSky/linux-2.6.30.4/Module.symvers
- is missing; modules will have no dependencies and modversions.
原来是内核没有编译, 果断配置内核, 然后make
内核编译完之后, 再到hello模块那里make