读书人

framebuffer mmap失败解决方法

发布时间: 2012-05-27 05:42:30 作者: rapoo

framebuffer mmap失败
int fbfd,screensize;

// Open the file for reading and writing

fbfd = open( ptr, O_RDWR); // ptr为/dev/fb0

if (fbfd < 0)

{

printf( "Error: cannot open framebuffer device.%x\n ",fbfd);

return ERR_FRAME_BUFFER;

}

printf( "The framebuffer device was opened successfully.\n ");



vd-> fbfd = fbfd;// 保存打开FrameBuffer设备的句柄



// Get fixed screen information获取FrameBuffer固定不变的信息

if (ioctl(fbfd, FBIOGET_FSCREENINFO, &vd-> finfo))

{

printf( "Error reading fixed information.\n ");

return ERR_FRAME_BUFFER;

}


// Get variable screen information 获取FrameBuffer屏幕可变的信息

if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vd-> vinfo))

{

printf( "Error reading variable information.\n ");

return ERR_FRAME_BUFFER;

}


printf( "%dx%d, %dbpp, xoffset=%d ,yoffset=%d \n ", vd-> vinfo.xres, vd-> vinfo.yres, vd-> vinfo.bits_per_pixel,vd-> vinfo.xoffset,vd-> vinfo.yoffset );


// Figure out the size of the screen in bytes

screensize = vd-> vinfo.xres * vd-> vinfo.yres * vd-> vinfo.bits_per_pixel / 8;

printf( "\nscreensize=%d\n ",screensize );


// Map the device to memory

vd-> fbp = (char *)mmap(0,screensizes,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0); // 影射Framebuffer设备到内存

printf( "errno is: %d\n ",errno);

if ((int)vd-> fbp == -1)

{

printf( "Error: failed to map framebuffer device to memory.\n ");

return ERR_FRAME_BUFFER;

}

printf( "The framebuffer device was mapped to memory successfully.\n ");

return 0;

结果如下
root@embededsys-computer://work/nfsdir/rootfs# gcc -o video video.c
video.c: In function ‘udps_respon’:
video.c:418: warning: format not a string literal and no format arguments
root@embededsys-computer://work/nfsdir/rootfs# ./video
The framebuffer device was opened successfully.
640x480, 4bpp, xoffset=0 ,yoffset=0

screensize=153600
errno is: 22
Error: failed to map framebuffer device to memory.

可我把vd-> fbp = (char *)mmap(0,screensizes,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0);screensizes改成10000后没有报错 我设置的太大了吗


[解决办法]
你可以把错误信息打出来看看

读书人网 >驱动开发

热点推荐