如何用arm-linux-gcc编译驱动程序,Makefile文件怎么写?
本人是新手,前天编写一个最简单驱动到嵌入式ARM板上时出现了错误,然后试了很多方法都不成功,不知道怎么写和配置。请各位先辈指点一下。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
本人是新手,前天编写一个最简单驱动到嵌入式ARM板上时出现了错误,然后试了很多方法都不成功,不知道怎么写和配置。请各位先辈指点一下。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(9)
参考本版精华贴,肯定会找到满意的回答
回复 2# T-Bagwell
没有啊,哪一个有?我就是不明白怎么移植。我是这样写的:刚开始我直接参考桌面平台的写Makefile:
KVERS = $(shell uname -r)
# Kernel modules
obj-m += hello.o
# Specify flags for the module compilation.
#EXTRA_CFLAGS=-g -O0
build: kernel_modules
kernel_modules:
make -C /lib/modules/$(KVERS)/build M=$(CURDIR) modules
clean:
make -C /lib/modules/$(KVERS)/build M=$(CURDIR) clean
在PC上编译生成了.ko文件,然后我下载到ARM板上运行insmod hello.ko时出现错误:can't insert 'hello.ko':invalid module format .
我就想不通,我想可能要修改什么配置吧,然后网上搜索看到要这样修改:在内核源代码目录下修改Makefile:
找到下列行:
ARCH ?=$(SUBARCH)
CROSS_COMPILE ?=
改成:
ARCH := arm
CROSS_COMPILE =/usr/local/arm-linux/bin/arm-linux-gcc
这样把系统添加对ARM的支持。
但是这样编译时却没有通过了。。。
最后我在一些资料上看到一个现成的用arm-linux-gcc编译的驱动的Makefile文件,这样的:
ifneq ($(KERNELRELEASE),)
obj-m:=hello.o
else
KDIR:=/lib/modules/$(shell uname -r)/build
all:
make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux-
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif
我看到以为找到了,便仿照之用来编译,但是make却又出现如下错误:
[root@FedoraFor2440 cs]# make
make -C /lib/modules/2.6.27.5-117.fc10.i686/build M=/home/admin/cs modules ARCH=arm CROSS_COMPILE=arm-linux-
make[1]: Entering directory `/usr/src/kernels/2.6.27.5-117.fc10.i686'
CC [M] /home/admin/cs/hello.o
In file included from include/asm/system.h:10,
from include/asm/processor.h:17,
from include/linux/prefetch.h:14,
from include/linux/list.h:6,
from include/linux/module.h:9,
from /home/admin/cs/hello.c:9:
include/linux/kernel.h:195: warning: 'regparm' attribute directive ignored
include/linux/kernel.h:197: warning: 'regparm' attribute directive ignored
include/linux/kernel.h:217: warning: 'regparm' attribute directive ignored
In file included from include/linux/thread_info.h:47,
from include/linux/preempt.h:9,
from include/linux/spinlock.h:50,
from include/linux/seqlock.h:29,
from include/linux/time.h:8,
from include/linux/stat.h:60,
from include/linux/module.h:10,
from /home/admin/cs/hello.c:9:
include/asm/thread_info.h:174: error: invalid register name for 'current_stack_pointer'
In file included from include/linux/rwsem.h:22,
from include/linux/notifier.h:14,
from include/linux/memory_hotplug.h:6,
from include/linux/mmzone.h:560,
from include/linux/gfp.h:4,
from include/linux/kmod.h:22,
from include/linux/module.h:13,
from /home/admin/cs/hello.c:9:
include/asm/rwsem.h:48: warning: 'regparm' attribute directive ignored
include/asm/rwsem.h:50: warning: 'regparm' attribute directive ignored
include/asm/rwsem.h:52: warning: 'regparm' attribute directive ignored
include/asm/rwsem.h:54: warning: 'regparm' attribute directive ignored
In file included from include/asm/smp.h:12,
from include/linux/smp.h:28,
from include/linux/topology.h:33,
from include/linux/mmzone.h:683,
from include/linux/gfp.h:4,
from include/linux/kmod.h:22,
from include/linux/module.h:13,
from /home/admin/cs/hello.c:9:
include/asm/mpspec.h:9:25: error: mach_mpspec.h: No such file or directory
In file included from include/asm/smp.h:12,
from include/linux/smp.h:28,
from include/linux/topology.h:33,
from include/linux/mmzone.h:683,
from include/linux/gfp.h:4,
from include/linux/kmod.h:22,
from include/linux/module.h:13,
from /home/admin/cs/hello.c:9:
include/asm/mpspec.h:39: error: 'MAX_MP_BUSSES' undeclared here (not in a function)
In file included from include/asm/smp.h:15,
from include/linux/smp.h:28,
from include/linux/topology.h:33,
from include/linux/mmzone.h:683,
from include/linux/gfp.h:4,
from include/linux/kmod.h:22,
from include/linux/module.h:13,
from /home/admin/cs/hello.c:9:
include/asm/io_apic.h:149: error: 'MAX_IRQ_SOURCES' undeclared here (not in a function)
In file included from include/linux/smp.h:28,
from include/linux/topology.h:33,
from include/linux/mmzone.h:683,
from include/linux/gfp.h:4,
from include/linux/kmod.h:22,
from include/linux/module.h:13,
from /home/admin/cs/hello.c:9:
include/asm/smp.h:187:28: error: mach_apicdef.h: No such file or directory
In file included from include/linux/smp.h:28,
from include/linux/topology.h:33,
from include/linux/mmzone.h:683,
from include/linux/gfp.h:4,
from include/linux/kmod.h:22,
from include/linux/module.h:13,
from /home/admin/cs/hello.c:9:
include/asm/smp.h: In function 'hard_smp_processor_id':
include/asm/smp.h:191: error: implicit declaration of function 'GET_APIC_ID'
make[2]: *** [/home/admin/cs/hello.o] 错误 1
make[1]: *** [_module_/home/admin/cs] 错误 2
make[1]: Leaving directory `/usr/src/kernels/2.6.27.5-117.fc10.i686'
make: *** [all] 错误 2
[root@FedoraFor2440 cs]# make
我就郁闷了,现在也没办法。。。
http://bbs.chinaunix.net/viewthread.php?tid=1921952
回复 4# T-Bagwell
http://bbs.chinaunix.net/viewthread.php?tid=1921952 上面说的方法我还是不是很明白啊,我现在简直没办法了,昨天晚我看到一个资料上面写的helloworld驱动的例子有两份Makefile,一份是x86机子上的,一份是arm平台上的,arm上的这样写:
ifneq ($(KERNELRELEASE),)
obj-m:=hello.o
else
KDIR:=/usr/src/kernels/opt/EmbedSky/linux-2.6.30.4/
all:
make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPLIE=arm-linux-
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif
看到后我想应该是要用用于移植的内核来编译吧,于是我干脆把资料提供的内核拷贝到PC的Linux系统中然后解压、编译直至安装,然后就再模仿例子写了Makefile如上所示,然后make后终于通过编译成功了,然后我再下载到arm板上安装,却又出现下面的错误:insmod: can't insert 'hello.ko': unknown symbol in module, or unknown parameter。我就又彻底晕了。到底是怎么回事,应该怎么办的呢?
回复 1# psp3000pes
编辑 Makefile 如下。
obj-m += hello-1.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
然后 make.
如果 是给embedded 系统编译 module, 先把 embedded 系统的kernel 搞好,编译一道。然后 编辑 Makefile 如下。
obj-m += hello-1.o
all:
make -C /dirto/kernel/src M=$(PWD) modules
clean:
make -C /dirto/kernel/src M=$(PWD) clean
然后 make.
看上去没啥问题
确认以下几项
1.编译kernel 的编译器和你编译driver的编译器是同一个版本
2.make你的driver的时候有警告信息没有,有的话贴出来,或者make -n,然后把信息贴出来
3.用file命令看看你编译出来的.ko的信息,贴出来
4.把你的操作步骤发一下,大伙看一下
应该不是大问题
编译器版本?
编译kernel配置的config做成附件发上来看看吧
回复 6# T-Bagwell
哦,好,编译器好像是Arm-linux-gcc 4.3.2 ,我编译内核的配置是按照开发板提供的《天嵌科技出品Linux移植之step by step》设置的
补充:最好先make以下kernel