主题 : 求助!QQ2440 Linux2.6环境中编译driver的makefile 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 198
精华: 0
发帖: 4
金钱: 40 两
威望: 4 点
综合积分: 8 分
注册时间: 2008-03-01
最后登录: 2008-03-13
楼主  发表于: 2008-03-06 22:21

 求助!QQ2440 Linux2.6环境中编译driver的makefile

哪位大侠能够提供一个简单的makefile,编译一个linux2.6环境中的driver,假设内核源码为hello.c
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2008-03-06 22:33
这是Linux Device Driver 3rd edition里的一个例子,源文件在http://www.oreilly.com.cn/codeexample/ldd3/examples.tar.gz里面的misc-modules目录下

----------------------------------------------
# To build modules outside of the kernel tree, we run "make"
# in the kernel source tree; the Makefile these then includes this
# Makefile once again.
# This conditional selects whether we are being included from the
# kernel Makefile or not.
ifeq ($(KERNELRELEASE),)

    # Assume the source tree is where the running kernel was built
    # You should set KERNELDIR in the environment if it's elsewhere
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    # The current directory is passed to sub-makes as argument
    PWD := $(shell pwd)

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

modules_install:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean

else
    # called from kernel build system: just declare what our modules are
    obj-m := hello.o hellop.o seq.o jit.o jiq.o sleepy.o complete.o \
            silly.o faulty.o kdatasize.o kdataalign.o
endif
--------------------------------------------------------------------
"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: 198
精华: 0
发帖: 4
金钱: 40 两
威望: 4 点
综合积分: 8 分
注册时间: 2008-03-01
最后登录: 2008-03-13
2楼  发表于: 2008-03-13 07:19
搞定了已经 多谢
级别: 侠客
UID: 172
精华: 1
发帖: 48
金钱: 500 两
威望: 68 点
综合积分: 116 分
注册时间: 2008-02-27
最后登录: 2017-09-13
3楼  发表于: 2008-03-13 17:34
我下载了前面提供的driver和makefile 。我直接进入到misc-modules 下 make出错。

No rule to make target  './ driver和makefile
make[1]:Leaving directory /usr/src/kernel 2.6.18-53.el5-i686

请问怎样改才行? 麻烦了
级别: 侠客
UID: 172
精华: 1
发帖: 48
金钱: 500 两
威望: 68 点
综合积分: 116 分
注册时间: 2008-02-27
最后登录: 2017-09-13
4楼  发表于: 2008-03-13 17:34
我下载了前面提供的driver和makefile 。我直接进入到misc-modules 下 make出错。

No rule to make target  './ driver和makefile
make[1]:Leaving directory /usr/src/kernel 2.6.18-53.el5-i686

请问怎样改才行? 麻烦了
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
5楼  发表于: 2008-03-13 19:02
引用第4楼alexchen于2008-03-13 17:34发表的  :
我下载了前面提供的driver和makefile 。我直接进入到misc-modules 下 make出错。

No rule to make target  './ driver和makefile
make[1]:Leaving directory /usr/src/kernel 2.6.18-53.el5-i686

.......


提供一下你完整的操作步骤和shell上的输出吧
"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: 172
精华: 1
发帖: 48
金钱: 500 两
威望: 68 点
综合积分: 116 分
注册时间: 2008-02-27
最后登录: 2017-09-13
6楼  发表于: 2008-03-13 20:28
我mount  到mnt 出错,我放在home 目录下编译就通过了,生成好多个ko文件包括hello.ko 问什么makefile 那里没有指定是GCC或ARM-LINUX-GCC 呢?

刚学很多还不懂,太感谢了,给了这么多指导。
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
7楼  发表于: 2008-03-13 21:50
引用第6楼alexchen于2008-03-13 20:28发表的  :
我mount  到mnt 出错,我放在home 目录下编译就通过了,生成好多个ko文件包括hello.ko 问什么makefile 那里没有指定是GCC或ARM-LINUX-GCC 呢?

刚学很多还不懂,太感谢了,给了这么多指导。

想要知道的话就仔细读http://www.arm.linux.org.uk/docs/kerncomp.php吧,相信你英文没问题的:)
"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."