#include#include static int __init hello_init(void){ printk("Hello init\n"); return 0;}static int __exit hello_exit(void){ printk("Hello exit\n");}module_init(hello_init);module_exit(hello_exit);
交叉编译 Makefile文件(ARM):
ifneq ($(KERNELRELEASE),)obj-m := hello.oelseKDIR := /usr/src/linux2.6.28all: make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux-clean: rm -f *.ko *.o *.mod.o *.mod.c *.symvers modul*endif
X86:
## Makefile template. obj-m := hello.oUNAME := $(shell uname -r)PWD := $(shell pwd)ADVMOD := hello defualt: @make -C /lib/modules/$(UNAME)/build SUBDIRS=$(PWD) modules clean: @rm -f *.o @rm -f *.ko @rm -f *.mod.c @rm -f .*.cmd @rm -rf .tmp_versions#endif
Linux下:
OBJ = qudongifneq ($(KERNELRELEASE),)obj-m := $(OBJ).oelseKDIR := /usr/src/linux-headers-3.2.0-20-generic-paeall: rmmod $(OBJ) make -C $(KDIR) M=$(PWD) modules insmod $(OBJ).koclean: rm -f *.ko *.o *.mod.o *.mod.c *.symvers modul*endif