2008-07-09 10:56:41     mmap user space application

Document created by Aaronwu Employee on Aug 7, 2013
Version 1Show Document
  • View in full screen mode

2008-07-09 10:56:41     mmap user space application

kang p (INDIA)

Message: 58558   

 

Hello,

 

I'm using the latest 2008R1 -  BF533 EZKit.

Have any one tested the mmap example given in the,

 

https://docs.blackfin.uclinux.org/doku.php?id=mmap

 

I tried the Example 2 ,mmap fails.

 

Do we need to change the kernel memory allocation

as mentioned in,

 

https://docs.blackfin.uclinux.org/doku.php?id=kernel_space_memory_allocation

 

 

regards

Kang

QuoteReplyEditDelete

 

 

2008-07-09 23:02:58     Re: mmap user space application

Sonic Zhang (CHINA)

Message: 58580   

 

This example is borrowed from the book "Linux Device Driver". It looks is for MMU architecture.

 

What are you doing? You don't need a driver to map user space application.

 

 

QuoteReplyEditDelete

 

 

2008-07-12 06:25:55     Re: mmap user space application

kang p (INDIA)

Message: 58721   

 

Trying to test as given in the example,

 

https://docs.blackfin.uclinux.org/doku.php?id=kernel_space_memory_allocation

 

Will mmap system call work from user space in uClinux ?

 

 

 

 

QuoteReplyEditDelete

 

 

2008-07-13 23:03:41     Re: mmap user space application

Yi Li (CHINA)

Message: 58736   

 

I still cannot understand what you want to do.

 

Of course you can use mmap() in user space.

QuoteReplyEditDelete

 

 

2008-07-14 14:24:46     Re: mmap user space application

kang p (INDIA)

Message: 58768   

 

Using the mmap system call,can we share the memory space between the kernel space and user space.I'm trying to understand ,how the mmap works for the framebuffer device drivers.

 

where can i find sample mmap implementaion in uClinux ?

 

 

QuoteReplyEditDelete

 

 

2008-07-14 14:36:25     Re: mmap user space application

Michael Hennerich (GERMANY)

Message: 58769   

 

Mplayer, SDL, directfb, etc.

 

Typically the MAP_SHARED doesn't succeed on NOMMU - change it to MAP_PRIVATE.

 

Here is aexample  mplayer patch.

 

Index: MPlayer-1.0rc1/libvo/vo_fbdev.c

===================================================================

--- MPlayer-1.0rc1/libvo/vo_fbdev.c (revision 31)

+++ MPlayer-1.0rc1/libvo/vo_fbdev.c (working copy)

@@ -1003,10 +1003,15 @@ static int config(uint32_t width, uint32

#endif

  {

      int x_offset=0,y_offset=0;

-     if ((frame_buffer = (uint8_t *) mmap(0, fb_size, PROT_READ | PROT_WRITE,

-        MAP_SHARED, fb_dev_fd, 0)) == (uint8_t *) -1) {

-  mp_msg(MSGT_VO, MSGL_ERR, "Can't mmap %s: %s\n", fb_dev_name, strerror(errno));

-  return 1;

+     frame_buffer = (uint8_t *) mmap(0, fb_size, PROT_READ | PROT_WRITE,

+                                     MAP_SHARED, fb_dev_fd, 0);

+     if (frame_buffer == MAP_FAILED) {

+  frame_buffer = (uint8_t *) mmap(0, fb_size, PROT_READ | PROT_WRITE,

+                                  MAP_PRIVATE, fb_dev_fd, 0);

+  if (frame_buffer == MAP_FAILED) {

+      mp_msg(MSGT_VO, MSGL_ERR, "Can't mmap %s: %s\n", fb_dev_name, strerror(errno));

+      return 1;

+  }

      }

 

      center = frame_buffer +

QuoteReplyEditDelete

 

 

2008-07-15 12:37:52     Re: mmap user space application

kang p (INDIA)

Message: 58864   

 

I have attached my mmap test application(user space and kernel space).It results in mmap fail .

What could be the reason ?

 

 

thanks in advance.

 

bfin_mmap_uspace.c

bfin_mmap_kspace.c

QuoteReplyEditDelete

 

 

2008-07-15 19:41:23     Re: mmap user space application

Mike Frysinger (UNITED STATES)

Message: 58878   

 

what exactly is errno set to when you execute your userspace code and mmap() fails ?  did you make sure your driver's mmap code is being called ?

QuoteReplyEditDelete

 

 

2008-07-16 09:17:25     Re: mmap user space application

kang p (INDIA)

Message: 58950   

 

 

p = ( char *) mmap(NULL, 1024, PROT_READ,

                           MAP_PRIVATE,fd,0x3300000); //0x500000); // 0x1000

        if ( p == MAP_FAILED ) {

                printf(" failed to mmap device \n");

                exit(1);

        }

 

error code returned is "MAP_FAILED"

 

It doesnt call the driver mmap code.

I traced the mmap call in the kernel,it fails in the do_mmap_pgoff function call in the file nommu.c.

 

Please suggest ,how to proceed further.

 

Thanks in advance.

QuoteReplyEditDelete

 

 

2008-07-16 21:34:05     Re: mmap user space application

Mike Frysinger (UNITED STATES)

Message: 58980   

 

you're checking the return value, not the errno.  the latter may contain useful information.

QuoteReplyEditDelete

 

 

2008-07-17 11:20:45     Re: mmap user space application

kang p (INDIA)

Message: 59022   

 

Hi Mike,

 

do_mmap_pgoff call returns the error code -19.

It means ENODEV, Correct ?

 

I have created device file as mentioned in docs blackfin.

{ “mknod simple c 254 0” to create the ”/dev/simple” device for applications to open }

 

Anything related to the device file attributes?

 

Thanks again.

QuoteReplyEditDelete

 

 

2008-07-17 21:43:36     Re: mmap user space application

Mike Frysinger (UNITED STATES)

Message: 59044   

 

that most likely will not work

 

check your /proc/devices to see what the real major number is ... or load the example module with the module parameter set so you dont get a dynamically allocated major number

QuoteReplyEditDelete

 

 

2008-07-18 10:28:39     Re: mmap user space application

kang p (INDIA)

Message: 59095   

 

Instead of dynamic creation of the device file,i created at the module init.

 

cat /proc/devices

 

Character devices:

  1 mem

  5 /dev/tty

  5 /dev/console

  5 /dev/ptmx

10 misc

128 ptm

136 pts

204 ttyBF

253 /dev/simple

254 rtc

 

Block devices:

  1 ramdisk

31 mtdblock

 

Also verified with ls -l /dev/simple.Have added /dev/simple entry in the device_table.txt with major number 253.

do_mmap_pgoff call returns the error code -22.It means EINVAL.Do i miss anything w.r.t kernel code?

 

Now the Application returns in open system call itself,

 

#define SIMPLE_DEVICE "/dev/simple"

 

  fd = open(SIMPLE_DEVICE,O_RDWR);

  if ( fd < 0 ) {

              printf("error in device \n");

              exit(1);

  }

 

Have attached the mmap kernel code.

 

thanks.

 

 

bfin_mmap_kspace_2.c

QuoteReplyEditDelete

 

 

2008-07-21 13:37:36     Re: mmap user space application

kang p (INDIA)

Message: 59154   

 

Hi,

Can anyone help me on this issue?

Thanks for your help.

 

regards

Kang

QuoteReplyEditDelete

 

 

2008-07-22 00:35:00     Re: mmap user space application

Mike Frysinger (UNITED STATES)

Message: 59172   

 

review the wiki again.  ive updated it.

QuoteReplyEditDelete

 

 

2008-07-22 03:23:05     Re: mmap user space application

kang p (INDIA)

Message: 59176   

 

can you please send me the link.

 

Couldnt get any clue in solving this problem ,with the explanation provided in the docs blackfin.

 

https://docs.blackfin.uclinux.org/doku.php?id=mmap

 

 

 

 

QuoteReplyEditDelete

 

 

2008-07-22 03:32:13     Re: mmap user space application

Mike Frysinger (UNITED STATES)

Message: 59177   

 

you just posted the relevant link.  the kernel module and example userspace code there works on my board.

Outcomes