免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5249 | 回复: 4
打印 上一主题 下一主题

多个文件编译驱动模块 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-12-05 12:42 |只看该作者 |倒序浏览
本帖最后由 Gen216ius 于 2010-12-05 14:17 编辑

编译一个驱动模块,这个模块的源代码(.c文件与.h文件)不在内核源码树下,但它包含了源码下的一些头文件.h及源文件.c。
比如说这个工程由以下文件来实现:
工程文件夹下
led.c
源码树文件夹下
gpio.c
gpio.h

现在led.c通过GPIO端口来控制,那么led.c中就调用了gpio.c中的文件。这样的Makefile要怎么写啊?!!!
我的Makefile如下

  1. obj-m        := led.o
  2. led-objs=gpio.o
  3. KDIR ?=/opt/mv_pro_4.0/montavista/pro/devkit/lsp/ti-davinci
  4. CC=arm_v5t_le-gcc

  5. all:
  6.         $(MAKE) -C $(KDIR) M=$(PWD) modules
  7.         $(CC) -o ledtest main.c

  8. clean:
  9.         rm -rf *.ko *.o *.mod.c .tmp_versions *.symvers gpiotest reg led
复制代码
可就是点不亮灯啊

奇怪现象:在gpio.c中修改led.c调用的函数名,但led.c中还是原来的,这使得led.c中根本就找不到实现函数,但这却不会出错!!说明led.c中根本就没有调用gpio.c的函数吧!!!

多个文件编译出一个驱动模块是怎么样写Makefile啊?!!!!!!麻烦大家指点一下哈!!!!谢谢!!!!!

论坛徽章:
0
2 [报告]
发表于 2010-12-05 15:56 |只看该作者
如果是多个源文件编译出一个模块,那么假设模块名是mytest.ko,那么源文件名不能有mytest.c,下面是一个例子:
  obj-m := mytest.o
  mytest-objs := file1.o file2.o file3.o

论坛徽章:
0
3 [报告]
发表于 2010-12-05 17:53 |只看该作者
本帖最后由 Gen216ius 于 2010-12-05 18:08 编辑

回复 2# EZWORD

谢谢EZWORD!!!

我的情况是这样的:
比如工程文件夹下只有一个文件file.c,而其他的文件(file2.c、file3.c)是在内核源码树下的,
file1.c中调用了file2.c或者file3.c中的函数。那么这个Makefile应该怎么样写呢?!!!

论坛徽章:
0
4 [报告]
发表于 2010-12-05 18:34 |只看该作者
本帖最后由 EZWORD 于 2010-12-05 18:36 编辑

上面说的很清楚呀,你的应该这样写

  1. KDIR ?=/opt/mv_pro_4.0/montavista/pro/devkit/lsp/ti-davinci

  2. CC=arm_v5t_le-gcc

  3. obj-m        := my_led.o

  4. my_led-objs:=gpio.o led.o

  5. all:

  6.         $(MAKE) -C $(KDIR) M=$(PWD) modules

  7.         $(CC) -o ledtest main.c



  8. clean:

  9.         rm -rf *.ko *.o *.mod.c .tmp_versions *.symvers gpiotest reg led

复制代码

论坛徽章:
0
5 [报告]
发表于 2010-12-05 22:59 |只看该作者
回复 4# EZWORD


        编译结果如下,并且灯还是没亮,请高手看看是不是哪里错了!!!!

  1. [root@localhost GPIOdriver]# ls
  2. loadmodules.sh  main.c  Makefile  ReadMe.txt  user_gpio.c  user_gpio.h
  3. [root@localhost GPIOdriver]# make all
  4. make -C /opt/mv_pro_4.0/montavista/pro/devkit/lsp/ti-davinci M=/opt/nfs/GPIOdriver modules
  5. make[1]: Entering directory `/opt/mv_pro_4.0/montavista/pro/devkit/lsp/ti-davinci'
  6.   CC [M]  /opt/nfs/GPIOdriver/user_gpio.o
  7. In file included from /opt/nfs/GPIOdriver/user_gpio.c:16:
  8. include/asm/arch/gio.h: In function `gpio_set':
  9. include/asm/arch/gio.h:114: warning: implicit declaration of function `__raw_writel'
  10. include/asm/arch/gio.h: In function `gpio_get_value':
  11. include/asm/arch/gio.h:165: warning: implicit declaration of function `__raw_readl'
  12. make[2]: *** 没有规则可以创建“/opt/nfs/GPIOdriver/led.o”需要的目标“/opt/nfs/GPIOdriver/gio.o”。 停止。
  13. make[1]: *** [_module_/opt/nfs/GPIOdriver] 错误 2
  14. make[1]: Leaving directory `/opt/mv_pro_4.0/montavista/pro/devkit/lsp/ti-davinci'
  15. make: *** [all] 错误 2
  16. [root@localhost GPIOdriver]#
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP