ok6410 3.0.1内核调用V4L接口出错解决方法(转)

在做视频监控项目,以前一直用的是2.6.36的内核,一直很正常,但是这几天换3.0.1内核,启动程序,却出现了错误,如下:

  

./test_usb_camera 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
v4l2_open  id=2
Unable to handle kernel NULL pointer dereference at virtual address 00000060
pgd = cbc08000
[00000060] *pgd=5c7d6831, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#2]
Modules linked in:
CPU: 0    Tainted: G      D W    (3.0.1 #676)
PC is at video_devdata+0x18/0x30
LR is at dev_open+0x28/0x194
pc : [<c0352fbc>]    lr : [<c036359c>]    psr: 60000013
sp : cc7f5d30  ip : cc7f5d40  fp : cc7f5d3c
r10: c081b880  r9 : 00000026  r8 : cc7e78c8
r7 : cc423008  r6 : cc7e78c8  r5 : cc7bc200  r4 : cc423000
r3 : 00000003  r2 : c089e880  r1 : 00000000  r0 : cc7e78c8
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 00c5387d  Table: 5bc08008  DAC: 00000015
Process test_usb_camera (pid: 77, stack limit = 0xcc7f4268)
Stack: (0xcc7f5d30 to 0xcc7f6000)
5d20:                                     cc7f5d6c cc7f5d40 c036359c c0352fb0
5d40: c0363574 cc423000 cc7bc200 cc7e78c8 cc423008 cc7bc200 00000026 cc127180
5d60: cc7f5d8c cc7f5d70 c035333c c0363580 00000000 00000000 cc721ac0 cc7e78c8
5d80: cc7f5dbc cc7f5d90 c00ef5b0 c0353298 cc7f5e2c cc7f5ed0 00000000 cc7bc200
5da0: 00000000 cc7e78c8 c00ef490 cc127180 cc7f5df4 cc7f5dc0 c00ead14 c00ef49c
5dc0: cc080800 cc40ff00 cc7e78c8 cc7f5ed0 cc7bc200 00000000 cc7bce80 00000802
5de0: 00000026 00000000 cc7f5e1c cc7f5df8 c00eaf50 c00eabb4 cc7bce80 cc7f5e8c
5e00: cc7e78c8 cc7f5ed0 00000000 cc7f5e8c cc7f5e64 cc7f5e20 c00f8488 c00eaef4
5e20: cc7a3005 c088a480 cc7f5e64 cc40ff00 cc080800 cc7e78c8 cc7f5e64 cc7f5ed0
5e40: ffffff9c cc7f5f60 cc7f4000 cc7a3000 cc7f4000 cc7f5e8c cc7f5ec4 cc7f5e68
5e60: c00f992c c00f830c cc7f5e94 00000000 33db2580 00000000 66340397 bee98b70
5e80: 00000068 00000000 00000000 cc40ff00 cc127180 00000000 00000000 00000001
5ea0: cc7f5f60 cc7f5ed0 ffffff9c cc7a3000 cc7f4000 ffffff9c cc7f5f54 cc7f5ec8
5ec0: c00f9d04 c00f9874 00000041 00000000 cc40ff00 cc127180 d9d3cea0 00000006
5ee0: cc7a3005 cc40f820 cc07cc00 cc7e78c8 00000101 00000000 00000000 00000000
5f00: 00000000 00000000 00000004 cc7b50c0 cc7b50c8 cc7b50c4 00000000 cc7f4000
5f20: cc7f5f54 00000803 00000000 00000000 00000001 00000001 00000802 00000000
5f40: 00000004 cc7a3000 cc7f5f94 cc7f5f58 c00eaa78 c00f9cd8 00000000 00000000
5f60: 00000802 00000000 00000026 00000100 00000001 bee98e84 00067ecc 00000005
5f80: c0036ce8 00000000 cc7f5fa4 cc7f5f98 c00eab84 c00ea988 00000000 cc7f5fa8
5fa0: c0036b40 c00eab6c 00000001 bee98e84 000681c8 00000802 00000000 00085c8c
5fc0: 00000001 bee98e84 00067ecc 00000005 bee98d0c 00000000 000874b8 0000000a
5fe0: 00067ed4 bee98be0 000089b4 0001fe4c 40000010 000681c8 00000000 00000000
[<c0352fbc>] (video_devdata+0x18/0x30) from [<c036359c>] (dev_open+0x28/0x194)
[<c036359c>] (dev_open+0x28/0x194) from [<c035333c>] (v4l2_open+0xb0/0xd8)
[<c035333c>] (v4l2_open+0xb0/0xd8) from [<c00ef5b0>] (chrdev_open+0x120/0x1a4)
[<c00ef5b0>] (chrdev_open+0x120/0x1a4) from [<c00ead14>] (__dentry_open+0x16c/0x2c4)
[<c00ead14>] (__dentry_open+0x16c/0x2c4) from [<c00eaf50>] (nameidata_to_filp+0x68/0x70)
[<c00eaf50>] (nameidata_to_filp+0x68/0x70) from [<c00f8488>] (do_last+0x188/0x6b0)
[<c00f8488>] (do_last+0x188/0x6b0) from [<c00f992c>] (path_openat+0xc4/0x3a4)
[<c00f992c>] (path_openat+0xc4/0x3a4) from [<c00f9d04>] (do_filp_open+0x38/0x8c)
[<c00f9d04>] (do_filp_open+0x38/0x8c) from [<c00eaa78>] (do_sys_open+0xfc/0x1d0)
[<c00eaa78>] (do_sys_open+0xfc/0x1d0) from [<c00eab84>] (sys_open+0x24/0x28)
[<c00eab84>] (sys_open+0x24/0x28) from [<c0036b40>] (ret_fast_syscall+0x0/0x30)
Code: e24cb004 e590200c e5921020 e59f2010 (e5913060) 
---[ end trace da227214a82491ba ]---
Segmentation fault
[root@Enjoylinux /]# 
[root@Enjoylinux /]# 

完善OK6410摄像头驱动由上面的分析可知,OK6410新版本(3.0.1)的内核的dev_open函数是有问题的,实际上他是赋值给了v4l2_file_operations结构体的open成员,作为函数指针调用。他的实现部分的函数签名是int dev_open(struct file *file)在./drivers/media/video/gspca/gspca.c的1202行可以找到函数实现。而v4l2_file_operations的open成员的定义是int (*open) (struct node*,struct file *);所以在最终通过open成员函数指针调用dev_open的时候会出现打开失败的结果。我们要把v4l2_file_operations的open成员的定义改为int (*open) (struct file *);而且在相关的调用部分也要修改多了node参数的调用,即删掉node参数。

(1)头文件:./include/media/v4l2-dev.h的48行49行改为   int(*open) (struct file *);   int(*release) (struct file *); 

(2)C文件:./drivers/media/video/v4l2-dev.c第281行改为:       ret= vdev->fops->open(filp);

  第295行改为:       vdev->fops->release(filp);

(3)/driver/media/video/uvc/uvc_v4l2.c中 uvc_v4l2_open(struct inode *inode,struct file *file)函数 和uvc_v4l2_release(struct inode *inode,struct file *file)函数,

   改后为: uvc_v4l2_open(struct file *file) uvc_v4l2_release(struct file *file)

然后重新编译内核即可。

此外:要注意自己的摄像头头设备文件要和测试代码中一样!!!!!!!!

原文地址:https://www.cnblogs.com/chd-zhangbo/p/5466817.html