开发板: TQ2440
1. hello.c
-
#include <linux/init.h>
-
#include <linux/module.h>
-
-
MODULE_LICENSE("GPL");
-
-
static int __init hello_init(void)
-
{
-
printk(KERN_ALERT "my first driver\n");
-
return 0;
-
}
-
-
static void __exit hello_exit(void)
-
{
-
printk(KERN_ALERT "goodbye my first dirver\n");
-
return ;
-
}
-
-
module_init(hello_init);
-
module_exit(hello_exit);
2. Makefile
-
#CROSS_COMPILE=/opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-
-
CROSS_COMPILE= /opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-
-
ARCH:=arm
-
CC=$(CROSS_COMPILE)gcc
-
LD=$(CROSS_COMPILE)ld
-
-
obj-m = hello.o
-
-
KDIR =/root/kernel/linux-2.6.30.4
-
PWD = $(shell pwd)
-
default:
-
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
-
clean:
-
rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.order
hello.rar(下载后将文件名改为hello.tar.gz)
3. 当需要在x86 和 arm上相互切换驱动时,不需要写两套Makefile,只需要加一个类型判断即可。
-
ARCH=x86
-
ifeq ($(ARCH), x86)
-
CROSS_COMPILE=
-
KDIR = /lib/modules/$(shell uname -r)/build
-
else
-
CROSS_COMPILE= /opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-
-
KDIR =/root/kernel/linux-2.6.30.4
-
endif
-
PWD = $(shell pwd)
-
-
obj-m := hello.o
-
all:
-
make -C $(KDIR) SUBDIRS=$(PWD) modules
-
clean:
-
rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.order
阅读(1529) | 评论(0) | 转发(1) |