日期:2014-05-16  浏览次数:20990 次

Unable to handle kernel NULL pointer dereference at virtual address 00000000
本人利用arm11开发平台,想实现USB摄像头的图片采集功能;但是发现程序在linux虚拟机下可以运行(GCC),但是移植到arm11开发板上(arm-linux-gcc)后运行出错;我加入一些打印信息,发现只有打印出:
00000000000000000 , 1111111111111111和 2222222222222 后面的333333333333和444444444444没有答应出来;现在看来应该是ioctl(fd, VIDIOC_ENUM_FMT, &fmt1))的错误,不知道如何解决?
我的源代码如下

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h> 
#include <fcntl.h> 
#include <unistd.h>
#include <errno.h>
#include <malloc.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <asm/types.h> 
#include <linux/videodev2.h>
#define CLEAR(x) memset (&(x), 0, sizeof (x))

struct buffer {
        void * start;
        size_t length;
};

static char * dev_name = "/dev/video0";
static int fd = -1;
struct buffer * buffers = NULL;
static unsigned int n_buffers = 0;
FILE *file_fd;
static unsigned long file_length;
static unsigned char *file_name;

static int read_frame (void)
{
    struct v4l2_buffer buf;
    unsigned int i;
    CLEAR (buf);
    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
    int ff = ioctl (fd, VIDIOC_DQBUF, &buf);

    if(ff<0)
        printf("failture\n"); 
    assert (buf.index < n_buffers);

       printf ("buf.index dq is %d,\n",buf.index);

    fwrite(buffers[buf.index].start, buffers[buf.index].length, 1, file_fd); 
    ff=ioctl (fd, VIDIOC_QBUF, &buf); 
    if(ff<0)
        printf("failture VIDIOC_QBUF\n");
    return 1;
}
int main (int argc,char ** argv)
{
    struct v4l2_capability cap;
    struct v4l2_format fmt;
    unsigned int i;
    enum v4l2_buf_type type;
file_fd = fopen("jpgimage.jpg", "w");


    fd = open (dev_name, O_RDWR | O_NONBLOCK, 0);
        printf("000000000000000000000000000000000\n"); 

    int ff=ioctl (fd, VIDIOC_QUERYCAP, &cap);
    if(ff<0)
        printf("failture VIDIOC_QUERYCAP\n");
        printf("111111111111111111111111111111111\n"); 

        struct v