All of lore.kernel.org
 help / color / mirror / Atom feed
* Gives Bus error in memcpy() in coping /dev/fb0 to a file.
@ 2007-03-07 11:50 Vishal Soni
  2007-03-08 13:05 ` Antonino A. Daplas
  2007-03-09  4:59 ` Vishal Soni
  0 siblings, 2 replies; 8+ messages in thread
From: Vishal Soni @ 2007-03-07 11:50 UTC (permalink / raw)
  To: linux-fbdev-devel

[-- Attachment #1: Type: text/plain, Size: 670 bytes --]

hello,

I am trying to get the snapshot of the screen through a c program by mmaping
the framebuffer device /dev/fb0 .
For this i compiled kernel with virtual framebuffer support and passing
vga=791 as boot line argument.

Though i am able to get snapshot by
[root@tw pcapp]# cat /dev/fb0 > frame

and see it on the screen by
[root@tw pcapp]# cat frame > /dev/fb0

But when i try to capture the frame buffer using the below c code, It gives
bus error @ memcpy()

Output :::::::::

[root@tw pcapp]# ./pcapp
1024x768, 16bpp
framebuffer device mapped to memory @ 0xb7db3000.
FB_FRAME mapped to memory @ 0xb7c33000.
Bus error
[root@tw pcapp]#

Any pointers plz !!!!!
Vishal

[-- Attachment #2: pcapp.c --]
[-- Type: text/x-csrc, Size: 1694 bytes --]

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>

#define FB_FILE "/dev/fb0"
#define FB_FRAME "fb_frame"

int main (int argc, char *argv[])
{
	int fdin = -1;
	int fdout = -1;
	char *src = NULL;
	char *dst = NULL;
	struct fb_var_screeninfo vinfo;
	long int screensize = 0;

	if ((fdin = open (FB_FILE, O_RDONLY)) < 0) {
		printf ("Faile to open %s file", FB_FILE);
		return 0;
	}

	/* open/create the output file */
	if ((fdout = open (FB_FRAME, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
		printf ("faile to open %s for writing", FB_FRAME);
		return -1;
	}

	// Get variable screen information
	if (ioctl(fdin, FBIOGET_VSCREENINFO, &vinfo)) {
		printf("Error reading variable information.\n");
		return -1;
	}

	printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );

	// Calculate the size of the screen in bytes
	screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
	
	// Map the device to memory
	src = (char *)mmap(0, screensize, PROT_READ, MAP_SHARED, fdin, 0);
	if ((int)src == -1) {
		printf("Error: failed to map framebuffer device to memory.\n");
		return -1;
	}

	/* mmap the FB_FRAME file */
	dst = mmap (0, screensize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fdout, 0);
	if ((int)dst == -1) {
		printf("FB_FRAME:: mmap error  ");
		return -1;
	}
	
	printf("framebuffer device mapped to memory @ %p.\n", src);
	printf("FB_FRAME mapped to memory @ %p.\n", dst);
	/* copy /dev/fb0 to fb_frame file */
	memcpy (dst, src, screensize);
	close(fdin);
	close(fdout);
	return 0;
} 

[-- Attachment #3: Type: text/plain, Size: 345 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #4: Type: text/plain, Size: 182 bytes --]

_______________________________________________
Linux-fbdev-devel mailing list
Linux-fbdev-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-fbdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Gives Bus error in memcpy() in coping /dev/fb0 to a file.
  2007-03-07 11:50 Gives Bus error in memcpy() in coping /dev/fb0 to a file Vishal Soni
@ 2007-03-08 13:05 ` Antonino A. Daplas
  2007-03-08 17:39   ` Nuno Lucas
       [not found]   ` <200703091021.46041.vishal.soni@samsung.com>
  2007-03-09  4:59 ` Vishal Soni
  1 sibling, 2 replies; 8+ messages in thread
From: Antonino A. Daplas @ 2007-03-08 13:05 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: Vishal Soni

On Wed, 2007-03-07 at 17:20 +0530, Vishal Soni wrote:
> hello,
> 
> I am trying to get the snapshot of the screen through a c program by mmaping
> the framebuffer device /dev/fb0 .
> For this i compiled kernel with virtual framebuffer support and passing
> vga=791 as boot line argument.
> 
> Though i am able to get snapshot by
> [root@tw pcapp]# cat /dev/fb0 > frame
> 
> and see it on the screen by
> [root@tw pcapp]# cat frame > /dev/fb0
> 
> But when i try to capture the frame buffer using the below c code, It gives
> bus error @ memcpy()
> 
> Output :::::::::
> 
> [root@tw pcapp]# ./pcapp
> 1024x768, 16bpp
> framebuffer device mapped to memory @ 0xb7db3000.
> FB_FRAME mapped to memory @ 0xb7c33000.
> Bus error

I don't think vfb's framebuffer can be mmapped.  It's fixable, but
nobody seems to have a need for it,  yet.

Tony



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Gives Bus error in memcpy() in coping /dev/fb0 to a file.
  2007-03-08 13:05 ` Antonino A. Daplas
@ 2007-03-08 17:39   ` Nuno Lucas
  2007-03-08 21:49     ` Antonino A. Daplas
       [not found]   ` <200703091021.46041.vishal.soni@samsung.com>
  1 sibling, 1 reply; 8+ messages in thread
From: Nuno Lucas @ 2007-03-08 17:39 UTC (permalink / raw)
  To: linux-fbdev-devel

On 3/8/07, Antonino A. Daplas <adaplas@gmail.com> wrote:
> On Wed, 2007-03-07 at 17:20 +0530, Vishal Soni wrote:
> > hello,
> >
> > I am trying to get the snapshot of the screen through a c program by mmaping
> > the framebuffer device /dev/fb0 .
> > For this i compiled kernel with virtual framebuffer support and passing
> > vga=791 as boot line argument.
> >
> > Though i am able to get snapshot by
> > [root@tw pcapp]# cat /dev/fb0 > frame
> >
> > and see it on the screen by
> > [root@tw pcapp]# cat frame > /dev/fb0
> >
> > But when i try to capture the frame buffer using the below c code, It gives
> > bus error @ memcpy()
> >
> > Output :::::::::
> >
> > [root@tw pcapp]# ./pcapp
> > 1024x768, 16bpp
> > framebuffer device mapped to memory @ 0xb7db3000.
> > FB_FRAME mapped to memory @ 0xb7c33000.
> > Bus error
>
> I don't think vfb's framebuffer can be mmapped.  It's fixable, but
> nobody seems to have a need for it,  yet.

Having read about the Hecuba driver, using the deferred IO patch,
isn't that a better starting point for a virtual fb driver? One could
just ignore the deferred IO and have an instant virtual frame buffer.
With just a little bit of effort and one could even make a
para-virtual driver for Xen and/or KVM.

I'm just a curious soul lying on this list but would appreciate
someone to correct my thinking.


Best regards,
~Nuno Lucas

P.S.- Just for background, I'm one of those who have the aspiration of
actually doing some kernel hacking but real life always gets on the
way ;-)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Gives Bus error in memcpy() in coping /dev/fb0 to a file.
  2007-03-08 17:39   ` Nuno Lucas
@ 2007-03-08 21:49     ` Antonino A. Daplas
  0 siblings, 0 replies; 8+ messages in thread
From: Antonino A. Daplas @ 2007-03-08 21:49 UTC (permalink / raw)
  To: linux-fbdev-devel

On Thu, 2007-03-08 at 17:39 +0000, Nuno Lucas wrote:
> On 3/8/07, Antonino A. Daplas <adaplas@gmail.com> wrote:
> > On Wed, 2007-03-07 at 17:20 +0530, Vishal Soni wrote:
> > > hello,
> > >
> > > I am trying to get the snapshot of the screen through a c program by mmaping
> > > the framebuffer device /dev/fb0 .
> > > For this i compiled kernel with virtual framebuffer support and passing
> > > vga=791 as boot line argument.
> > >
> > > Though i am able to get snapshot by
> > > [root@tw pcapp]# cat /dev/fb0 > frame
> > >
> > > and see it on the screen by
> > > [root@tw pcapp]# cat frame > /dev/fb0
> > >
> > > But when i try to capture the frame buffer using the below c code, It gives
> > > bus error @ memcpy()
> > >
> > > Output :::::::::
> > >
> > > [root@tw pcapp]# ./pcapp
> > > 1024x768, 16bpp
> > > framebuffer device mapped to memory @ 0xb7db3000.
> > > FB_FRAME mapped to memory @ 0xb7c33000.
> > > Bus error
> >
> > I don't think vfb's framebuffer can be mmapped.  It's fixable, but
> > nobody seems to have a need for it,  yet.
> 
> Having read about the Hecuba driver, using the deferred IO patch,
> isn't that a better starting point for a virtual fb driver? One could
> just ignore the deferred IO and have an instant virtual frame buffer.
> With just a little bit of effort and one could even make a
> para-virtual driver for Xen and/or KVM.
> 
> I'm just a curious soul lying on this list but would appreciate
> someone to correct my thinking.
> 

Yes, something like that without the mkwrite method.

The classic method was to use get_free_pages to allocate the memory and
mark the range as reserved and io.

Tony


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Gives Bus error in memcpy() in coping /dev/fb0 to a file.
  2007-03-07 11:50 Gives Bus error in memcpy() in coping /dev/fb0 to a file Vishal Soni
  2007-03-08 13:05 ` Antonino A. Daplas
@ 2007-03-09  4:59 ` Vishal Soni
  2007-03-09  9:09   ` Vishal Soni
  1 sibling, 1 reply; 8+ messages in thread
From: Vishal Soni @ 2007-03-09  4:59 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: Antonino A. Daplas

On Thursday 08 March 2007 18:35, Antonino A. Daplas wrote:
> On Wed, 2007-03-07 at 17:20 +0530, Vishal Soni wrote:
> > [root@tw pcapp]# ./pcapp
> > 1024x768, 16bpp
> > framebuffer device mapped to memory @ 0xb7db3000.
> > FB_FRAME mapped to memory @ 0xb7c33000.
> > Bus error
>
> I don't think vfb's framebuffer can be mmapped.  It's fixable, but
> nobody seems to have a need for it,  yet.
>
> Tony
fb is getting successfully mapped.. its just that memcpy gives bus error when
i try to copy the mapped memory of ""framebuffer device"" to a
"""mapped file""""

Well, I am able to get the ball rolling by writing the mapped framebuffer onto
the file by using the below write system call

write(fdout, src, screensize);
/* where fdout = open("./fb_frame", O_RDWR);
and src = (char *)mmap(0, screensize, PROT_READ|PROT_WRITE, MAP_SHARED, fdin,
0); // fdin=open("/dev/fb0", O_RDONLY)
*/

Interesting is that.... why the below code gives problem in memcpy 'ng
with bus error

memcpy(dst, src, screensize);
/*
where src = mmap (0, screensize, PROT_READ, MAP_PRIVATE, fdin, 0));
and
fdin is descriptor of "/dev/fb0"
and
dst = mmap (0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fdout,
0);
and
fdout is descriptor of "./fb_frame" file
*/

Had this fdin not been descriptor of device file "/dev/fb0" but an ordinary
file this method of copying the two files works.

Any clues !!!!!!

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Gives Bus error in memcpy() in coping /dev/fb0 to a file.
       [not found]   ` <200703091021.46041.vishal.soni@samsung.com>
@ 2007-03-09  8:54     ` Antonino A. Daplas
  0 siblings, 0 replies; 8+ messages in thread
From: Antonino A. Daplas @ 2007-03-09  8:54 UTC (permalink / raw)
  To: Vishal Soni; +Cc: linux-fbdev-devel

On Fri, 2007-03-09 at 10:21 +0530, Vishal Soni wrote:
> On Thursday 08 March 2007 18:35, Antonino A. Daplas wrote:
> > On Wed, 2007-03-07 at 17:20 +0530, Vishal Soni wrote:
> > > [root@tw pcapp]# ./pcapp
> > > 1024x768, 16bpp
> > > framebuffer device mapped to memory @ 0xb7db3000.
> > > FB_FRAME mapped to memory @ 0xb7c33000.
> > > Bus error
> >
> > I don't think vfb's framebuffer can be mmapped.  It's fixable, but
> > nobody seems to have a need for it,  yet.
> >
> > Tony
> fb is getting successfully mapped.. its just that memcpy gives bus error when 
> i try to copy the mapped memory of framebuffer device to a "mapped file,"
> 
> Well, I am able to get the ball rolling by writing the mapped framebuffer onto 
> the file by using write system call

Unless you modified vfb yourself, it's not possible because
fix->smem_start is not set all (it's pointing to NULL). What's actually
being mmapped is physical addres 0UL.

Tony



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Gives Bus error in memcpy() in coping /dev/fb0 to a file.
  2007-03-09  4:59 ` Vishal Soni
@ 2007-03-09  9:09   ` Vishal Soni
  2007-03-09 17:55     ` Antonino A. Daplas
  0 siblings, 1 reply; 8+ messages in thread
From: Vishal Soni @ 2007-03-09  9:09 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: Antonino A. Daplas

> > > I don't think vfb's framebuffer can be mmapped.  It's fixable, but
> > > nobody seems to have a need for it,  yet.
> > >
> > > Tony
> >
> > fb is getting successfully mapped.. its just that memcpy gives bus error
> > when i try to copy the mapped memory of framebuffer device to a "mapped
> > file,"
> >
> > Well, I am able to get the ball rolling by writing the mapped framebuffer
> > onto the file by using write system call
>
> Unless you modified vfb yourself, it's not possible because
> fix->smem_start is not set all (it's pointing to NULL). What's actually
> being mmapped is physical addres 0UL.
what i wanted to do......as i wrote in my very first mail........ i
have got that, now i am able to capture the snapshot using c program
and the results are output on my screen....
      printf("frame bufffer mapped  @ %p\n", src);
      for(i = 0; i < vinfo.xres*vinfo.yres*vinfo.bits_per_pixel/8; i++)
                *src++ = 0xBB;

Framebuffer is getting mapped... by mmap system call
  // Map the device to memory
        src = (char *)mmap(0, screensize, PROT_READ|PROT_WRITE,
MAP_SHARED, fdin, 0);
        if ((int)src == -1) {
                printf("Error: failed to map framebuffer device to memory.\n");
                return -1;
        }

and therefore  physical addres 0UL is not what is mapped.....its the
framebuffer.
doubt in my last mail was w.r.t memcpy().

thanx,
vishal.
> Tony

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Gives Bus error in memcpy() in coping /dev/fb0 to a file.
  2007-03-09  9:09   ` Vishal Soni
@ 2007-03-09 17:55     ` Antonino A. Daplas
  0 siblings, 0 replies; 8+ messages in thread
From: Antonino A. Daplas @ 2007-03-09 17:55 UTC (permalink / raw)
  To: Vishal Soni; +Cc: linux-fbdev-devel

On Fri, 2007-03-09 at 14:39 +0530, Vishal Soni wrote:
> > > > I don't think vfb's framebuffer can be mmapped.  It's fixable, but
> > > > nobody seems to have a need for it,  yet.
> > > >
> > > > Tony
> > >
> > > fb is getting successfully mapped.. its just that memcpy gives bus error
> > > when i try to copy the mapped memory of framebuffer device to a "mapped
> > > file,"
> > >
> > > Well, I am able to get the ball rolling by writing the mapped framebuffer
> > > onto the file by using write system call
> >
> > Unless you modified vfb yourself, it's not possible because
> > fix->smem_start is not set all (it's pointing to NULL). What's actually
> > being mmapped is physical addres 0UL.
> what i wanted to do......as i wrote in my very first mail........ i
> have got that, now i am able to capture the snapshot using c program
> and the results are output on my screen....
>       printf("frame bufffer mapped  @ %p\n", src);
>       for(i = 0; i < vinfo.xres*vinfo.yres*vinfo.bits_per_pixel/8; i++)
>                 *src++ = 0xBB;
> 
> Framebuffer is getting mapped... by mmap system call
>   // Map the device to memory
>         src = (char *)mmap(0, screensize, PROT_READ|PROT_WRITE,
> MAP_SHARED, fdin, 0);
>         if ((int)src == -1) {
>                 printf("Error: failed to map framebuffer device to memory.\n");
>                 return -1;
>         }
> 
> and therefore  physical addres 0UL is not what is mapped.....its the
> framebuffer.
> doubt in my last mail was w.r.t memcpy().

Well you had me confused, you mentioned virtual framebuffer, but I think
you are actually using the VESA framebuffer.

Anyway, the bus error is because the source file is truncated to zero
size. Try instead to open a file whose size is >= screensize.

Tony



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-03-09 17:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-07 11:50 Gives Bus error in memcpy() in coping /dev/fb0 to a file Vishal Soni
2007-03-08 13:05 ` Antonino A. Daplas
2007-03-08 17:39   ` Nuno Lucas
2007-03-08 21:49     ` Antonino A. Daplas
     [not found]   ` <200703091021.46041.vishal.soni@samsung.com>
2007-03-09  8:54     ` Antonino A. Daplas
2007-03-09  4:59 ` Vishal Soni
2007-03-09  9:09   ` Vishal Soni
2007-03-09 17:55     ` Antonino A. Daplas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.