我的主机是Ubuntu10.10,目标板上配置的linux2.6.33版本的内核,前两天碰到的问题是,在编写好的驱动目录下面使用make命令后报错如下:
ickens@ubuntu:~/Drivers$ make
make -C /home/dickens/linux-2.6.33 M=/home/dickens/Drivers modules
make[1]: 正在进入目录 `/home/dickens/linux-2.6.33'
CC [M] /home/dickens/Drivers/Led.o
In file included from include/linux/prefetch.h:14,
from include/linux/list.h:6,
from include/linux/kobject.h:20,
from include/linux/device.h:17,
from include/linux/dma-mapping.h:4,
from /home/dickens/Drivers/Led.c:2:
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h:117: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h:117: error: requested alignment is not a constant
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h:163: warning: "cache_line_size" redefined
include/linux/cache.h:64: note: this is the location of the previous definition
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h:243: error: requested alignment is not a constant
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h:274: error: requested alignment is not a constant
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h: In function ‘native_get_debugreg’:
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h:506: error: invalid application of ‘sizeof’ to incomplete type ‘struct bug_entry’
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h: In function ‘native_set_debugreg’:
/home/dickens/linux-2.6.33/arch/x86/include/asm/processor.h:533: error: invalid application of ‘sizeof’ to incomplete type ‘struct bug_entry
这些只是错误的一部分,我的makefile写法如下,
ARCH=arm
CROSS_COMPILE=arm-linux-
obj-m := Led.o
KDIR := /home/dickens/linux-2.6.33
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
其中,我的内核源码放在/home/dickens/linux-2.6.33 ,按道理路径不会有问题,我所用到的头文件也都存在,不应该有这么多错误,后来仔细分析发现,报错基本上都是在x86的体系文件下,仔细想想,目标板应该是Arm体系,固然不会是x86的结构,在网上搜了很久发现,在linux的顶层Makefile文件里面,有一个ARCH= 的选项,对比后发现,我下载的内核里面这一项写的事ARCH=x86 ,后来我把这一项直接改成ARCH=arm,保存,然后回到驱动程序的目录下,make 编译通过!