主题 : 请问如何编写编译驱动程序模块的Makefile? 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 7451
精华: 1
发帖: 21
金钱: 230 两
威望: 200 点
综合积分: 62 分
注册时间: 2009-07-15
最后登录: 2017-09-13
楼主  发表于: 2009-07-21 22:47

 请问如何编写编译驱动程序模块的Makefile?

我想尝试着把自己写的linux2.6驱动程序模块,编译下载到板子上测试。想自己编写一个独立的Makefile文件,make即可。(不想使用手册上说的要修改Kconfig、再看一下make menuconfig,修改Makefile,最后再make modules)。以前在linux2.4中也是一个makefile文件就可以了,在2.6下,是不是也可以?
----------------------------------------------------------------------------------
我参考网上资料,写了一个:
ifneq ($(KERNELRELEASE),)
    obj-m := mymodule.o  
else
    KERNELDIR := /opt/FriendlyARM/mini2440/linux-2.6.29
  PWD := $(shell pwd)

default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif
make的时候,显示nothing to be done for default.请问问题出在哪里?
请指点!!谢谢。
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-07-22 09:06
贴出具体的信息
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
希望大家一起进!!
级别: 新手上路
UID: 83260
精华: 0
发帖: 3
金钱: 15 两
威望: 3 点
综合积分: 6 分
注册时间: 2012-12-04
最后登录: 2013-01-13
2楼  发表于: 2012-12-04 18:06
大家好,我在编译驱动模块的时候,make了之后报错,错误如下
make -C /root/linux-2.6.38 M=/root/newjob_mmap/6410_led modules
make[1]: Entering directory `/root/linux-2.6.38'

  ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.


  WARNING: Symbol version dump /root/linux-2.6.38/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /root/newjob_mmap/6410_led/led2440.o
cc1: 错误:无法识别的命令行选项“-mlittle-endian”
cc1: 错误:无法识别的命令行选项“-mabi=apcs-gnu”
make[2]: *** [/root/newjob_mmap/6410_led/led2440.o] 错误 1
make[1]: *** [_module_/root/newjob_mmap/6410_led] 错误 2
make[1]: Leaving directory `/root/linux-2.6.38'
make: *** [default] 错误 2


现在没有得到解决,希望有人能帮忙 谢谢!!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2012-12-04 18:21
ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.

这说明你的内核源代码没有配置过。保险的办法是你按照用户手册的步骤完整的编译一次内核镜像

CC [M]  /root/newjob_mmap/6410_led/led2440.o
cc1: 错误:无法识别的命令行选项“-mlittle-endian”
cc1: 错误:无法识别的命令行选项“-mabi=apcs-gnu”

这说明没有使用交叉编译器。你可以在make的命令行上指定CROSS_COMPILE=arm-linux- (前提是你的交叉编译器名字是arm-linux-gcc, 并且包含在PATH环境变量中)
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."