Scull在2.6.35-30内核中的编译解决方案

  LDD3作为从事驱动开发工作人员的必要参考资料,认真研究书中的附带源码具有很高的参考价值,但由于代码基于2.6.10内核,部分内核API较老,导致在2.6.35-30等较新内核上编译不能通过,由于工作需要,特花了一段时间进行整理,本篇文章对示例源码中的第一个驱动程序SCULL进行整理,供各位同仁参考:

1、修改Makefile的第24行
   
如果是基于PC,则
KERNELDIR ?= /lib/modules/$(shell uname -r)/build(我的PC中linux内核是2.6.35版本)
如果是基于ARM,则改变为:
KERNELDIR ?= ../../../../linux/linux-2.6.35-30(arm开发板上所需内核的源码目录)

2、进入scull目录,执行make,有如下错误:

  1. make -/lib/modules/2.6.35-30-generic/build M=/media/orientation/driver/ldd3/examples/scull LDDINC=/media/orientation/driver/ldd3/examples/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.32-28-generic'
  3. scripts/Makefile.build:49: *** CFLAGS was changed in "/media/orientation/driver/ldd3/examples/scull/Makefile". Fix it to use EXTRA_CFLAGS. Stop.
  4. make[1]: *** [_module_/media/orientation/driver/ldd3/examples/scull] Error 2
  5. make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-28-generic'
  6. make: *** [modules] Error 2
3、根据错误提示,修改Makefile中 12、13行代码如下:

  1. EXTRA_CFLAGS += $(DEBFLAGS)
  2. EXTRA_CFLAGS += -I$(LDDINC)
4、接着make,错误如下:

  1. make -/lib/modules/2.6.35-30-generic/build M=/media/orientation/driver/ldd3/examples/scull LDDINC=/media/orientation/driver/ldd3/examples/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.32-28-generic'
  3.   CC [M] /media/orientation/driver/ldd3/examples/scull/main.o
  4. /media/orientation/driver/ldd3/examples/scull/main.c:17:26: error: linux/config.h: No such file or directory
  5. make[2]: *** [/media/orientation/driver/ldd3/examples/scull/main.o] Error 1
  6. make[1]: *** [_module_/media/orientation/driver/ldd3/examples/scull] Error 2
  7. make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-28-generic'
  8. make: *** [modules] Error 2
  9. root@ubuntu:/media/orientation/driver/ldd3/examples/scull# vim Makefile
  10. root@ubuntu:/media/orientation/driver/ldd3/examples/scull# make
  11. make -/lib/modules/2.6.32-28-generic/build M=/media/orientation/driver/ldd3/examples/scull LDDINC=/media/orientation/driver/ldd3/examples/scull/../include modules
  12. make[1]: Entering directory `/usr/src/linux-headers-2.6.32-28-generic'
  13.   CC [M] /media/orientation/driver/ldd3/examples/scull/main.o
  14. /media/orientation/driver/ldd3/examples/scull/main.c:17:26: error: linux/config.h: No such file or directory
  15. make[2]: *** [/media/orientation/driver/ldd3/examples/scull/main.o] Error 1
  16. make[1]: *** [_module_/media/orientation/driver/ldd3/examples/scull] Error 2
  17. make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-28-generic
5、 根据提示,查看2.6.35.30源码发现linux/config.h文件不存在,直接在main.c里将他屏蔽,接着编译,仍有错误:

  1. make -/lib/modules/2.6.35-30-generic/build M=/media/orientation/driver/ldd3/examples/scull LDDINC=/media/orientation/driver/ldd3/examples/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.32-28-generic'
  3.   CC [M] /media/orientation/driver/ldd3/examples/scull/main.o
  4.   CC [M] /media/orientation/driver/ldd3/examples/scull/pipe.o
  5. /media/orientation/driver/ldd3/examples/scull/pipe.c: In function ‘scull_p_read’:
  6. /media/orientation/driver/ldd3/examples/scull/pipe.c:131: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
  7. /media/orientation/driver/ldd3/examples/scull/pipe.c:131: error: (Each undeclared identifier is reported only once
  8. /media/orientation/driver/ldd3/examples/scull/pipe.c:131: error: for each function it appears in.)
  9. /media/orientation/driver/ldd3/examples/scull/pipe.c:131: error: implicit declaration of function ‘signal_pending’
  10. /media/orientation/driver/ldd3/examples/scull/pipe.c:131: error: implicit declaration of function ‘schedule’
  11. /media/orientation/driver/ldd3/examples/scull/pipe.c: In function ‘scull_getwritespace’:
  12. /media/orientation/driver/ldd3/examples/scull/pipe.c:168: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
  13. /media/orientation/driver/ldd3/examples/scull/pipe.c: In function ‘scull_p_write’:
  14. /media/orientation/driver/ldd3/examples/scull/pipe.c:219: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
  15. /media/orientation/driver/ldd3/examples/scull/pipe.c:223: error: ‘SIGIO’ undeclared (first use in this function)
  16. /media/orientation/driver/ldd3/examples/scull/pipe.c:223: error: ‘POLL_IN’ undeclared (first use in this function)
  17. make[2]: *** [/media/orientation/driver/ldd3/examples/scull/pipe.o] Error 1
  18. make[1]: *** [_module_/media/orientation/driver/ldd3/examples/scull] Error 2
  19. make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-28-generic'
  20. make: *** [modules] Error 2
6、 根据提示,TASK_INTERRUPTIBLE没有声明,我们在源码里面搜索,发现该宏定义在<linux/sched.h>中,故在pipe.c中加入该头文件,接着make:

  1. make -/lib/modules/2.6.35-30-generic/build M=/media/orientation/driver/ldd3/examples/scull LDDINC=/media/orientation/driver/ldd3/examples/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.35-30-generic'
  3.   CC [M] /media/orientation/driver/ldd3/examples/scull/pipe.o
  4.   CC [M] /media/orientation/driver/ldd3/examples/scull/access.o
  5. /media/orientation/driver/ldd3/examples/scull/access.c: In function ‘scull_u_open’:
  6. /media/orientation/driver/ldd3/examples/scull/access.c:106: error: dereferencing pointer to incomplete type
  7. /media/orientation/driver/ldd3/examples/scull/access.c:107: error: dereferencing pointer to incomplete type
  8. /media/orientation/driver/ldd3/examples/scull/access.c:114: error: dereferencing pointer to incomplete type
  9. /media/orientation/driver/ldd3/examples/scull/access.c: In function ‘scull_w_available’:
  10. /media/orientation/driver/ldd3/examples/scull/access.c:165: error: dereferencing pointer to incomplete type
  11. /media/orientation/driver/ldd3/examples/scull/access.c:166: error: dereferencing pointer to incomplete type
  12. /media/orientation/driver/ldd3/examples/scull/access.c: In function ‘scull_w_open’:
  13. /media/orientation/driver/ldd3/examples/scull/access.c:179: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
  14. /media/orientation/driver/ldd3/examples/scull/access.c:179: error: (Each undeclared identifier is reported only once
  15. /media/orientation/driver/ldd3/examples/scull/access.c:179: error: for each function it appears in.)
  16. /media/orientation/driver/ldd3/examples/scull/access.c:179: error: implicit declaration offunction ‘signal_pending’
  17. /media/orientation/driver/ldd3/examples/scull/access.c:179: error: implicit declaration offunction ‘schedule’
  18. /media/orientation/driver/ldd3/examples/scull/access.c:184: error: dereferencing pointer to incomplete type
  19. /media/orientation/driver/ldd3/examples/scull/access.c: In function ‘scull_w_release’:
  20. /media/orientation/driver/ldd3/examples/scull/access.c:205: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
    1. /media/orientation/driver/ldd3/examples/scull/access.c: In function ‘scull_c_open’:
    2. /media/orientation/driver/ldd3/examples/scull/access.c:277: error: dereferencing pointer to incomplete type
    3. /media/orientation/driver/ldd3/examples/scull/access.c:281: error: dereferencing pointer to incomplete type
    4. make[2]: *** [/media/orientation/driver/ldd3/examples/scull/access.o] Error 1
    5. make[1]: *** [_module_/media/orientation/driver/ldd3/examples/scull] Error 2
    6. make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-28-generic'
    7. make: *** [modules] Error 2
7、 根据提示,同上所述,我们需要在access.c中加入头文件<sched.h>,接着编译:

  1. make -/lib/modules/2.6.35-30-generic/build M=/media/orientation/driver/ldd3/examples/scull LDDINC=/media/orientation/driver/ldd3/examples/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.32-28-generic'
  3.   CC [M] /media/orientation/driver/ldd3/examples/scull/access.o
  4. /media/orientation/driver/ldd3/examples/scull/access.c: In function ‘scull_u_open’:
  5. /media/orientation/driver/ldd3/examples/scull/access.c:106: error: ‘struct task_struct’ has no member named ‘uid’
  6. /media/orientation/driver/ldd3/examples/scull/access.c:107: error: ‘struct task_struct’ has no member named ‘euid’
  7. /media/orientation/driver/ldd3/examples/scull/access.c:114: error: ‘struct task_struct’ has no member named ‘uid’
  8. /media/orientation/driver/ldd3/examples/scull/access.c: In function ‘scull_w_available’:
  9. /media/orientation/driver/ldd3/examples/scull/access.c:165: error: ‘struct task_struct’ has no member named ‘uid’
  10. /media/orientation/driver/ldd3/examples/scull/access.c:166: error: ‘struct task_struct’ has no member named ‘euid’
  11. /media/orientation/driver/ldd3/examples/scull/access.c: In function ‘scull_w_open’:
  12. /media/orientation/driver/ldd3/examples/scull/access.c:184: error: ‘struct task_struct’ has no member named ‘uid’
  13. make[2]: *** [/media/orientation/driver/ldd3/examples/scull/access.o] Error 1
  14. make[1]: *** [_module_/media/orientation/driver/ldd3/examples/scull] Error 2
  15. make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-28-generic'
  16. make: *** [modules] Error 2
8、 根据提示,错误在于task_struct结构体没有uid,euid成员变量,查看源码发现struct task_struct定义在include/linux/sched.h中,确实没有这两个成员,逐个成员分析发现,这两个成员在2.6.35内核中放在const struct cred *cred成员中了,所以,我们尝试将所有出现错误的地方做如下改动:

  1. current->uid 修改为 current->cred->uid
  2. current->euid 修改为 current->cred->euid
9、 接着make,发现成功编译。


你可能感兴趣的:(Scull在2.6.35-30内核中的编译解决方案)