All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space
@ 2018-04-10 19:03 Pham, Phong
  2018-04-12  8:58 ` Philippe Gerum
  0 siblings, 1 reply; 8+ messages in thread
From: Pham, Phong @ 2018-04-10 19:03 UTC (permalink / raw)
  To: xenomai; +Cc: Hillman, Robert


Hi,

According to page 651
https://xenomai.org/documentation/xenomai-3/pdf/xeno3prm.pdf


This will make such region accessible via the mapper device using the following sequence of code, via
the default ->mmap() handler from the UDD core:
int fd, fdm;
void *p;
fd = open("/dev/foocard", O_RDWR);
fdm = open("/dev/foocard,mapper@2", O_RDWR);
p = mmap(NULL, 4096, PROT_READ|PROT_WRITE, 0, fdm, 0);


I have several questions:

1)      It looks like the 4th argument of mmap (the one to the left of "fdm") needs to be either MAP_SHARED or MAP_PRIVATE

2)      The "@" character right after "mapper" is not valid (ie. there should be no "@" character at all)

3)      /dev/foocard should be /dev/rtdm/foocard

here's my real question:

Assuming all 3 of the above is valid from user space, and on the kernel space, I followed the ex. to create memory region, etc. such that I do see my device

# ls -l dev/rtdm
crw-------    1 root     root      252,   0 Jan  1 00:00 autotune
crw-------    1 root     root      247,   0 Jan  1 00:00 eeprom
crw-------    1 root     root      246,   0 Jan  1 00:00 eeprom,mapper0
crw-------    1 root     root      254,   0 Jan  1 00:00 memdev-private
crw-------    1 root     root      254,   1 Jan  1 00:00 memdev-shared
crw-------    1 root     root      253,   0 Jan  1 00:00 memdev-sys
crw-------    1 root     root      249,   0 Jan  1 00:00 mmio
crw-------    1 root     root      248,   0 Jan  1 00:00 mmio,mapper0
crw-------    1 root     root      248,   1 Jan  1 00:00 mmio,mapper1
crw-------    1 root     root      248,   2 Jan  1 00:00 mmio,mapper2
crw-------    1 root     root      248,   3 Jan  1 00:00 mmio,mapper3
crw-------    1 root     root      248,   4 Jan  1 00:00 mmio,mapper4
crw-------    1 root     root      250,   0 Jan  1 00:00 switchtest
crw-------    1 root     root      251,   0 Jan  1 00:00 timerbench


like /dev/rtdm/eeprom and /dev/rtdm/eeprom,mapper0  etc. I don't see my kernel hook ever gets called


static struct udd_device eeprom = {
              .device_flags = RTDM_NAMED_DEVICE,
              .device_name = "eeprom",
              .ops = {
                             .close = phong_scs750_close,
                             .open = phong_scs750_open,
                             .mmap = phong_scs750_mmap,
              }

By that, I mean phong_scs750_open, phong_scs750_mmap never gets invoked.  mmap() from user space returns -1 with errno value of 19 (ENODEV).  Any advise?

Phong.
Notice: This e-mail and any files transmitted with it may contain Data Device Corporation's privileged and proprietary information. It is intended solely for the use of the individual or entity to whom it is addressed. If you are not the named recipient of this transmission, any disclosure, copying, distribution or reliance on the contents of this message is prohibited. If you received this e-mail in error, please destroy it and any attached files and notify me immediately.

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

* Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space
  2018-04-10 19:03 [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space Pham, Phong
@ 2018-04-12  8:58 ` Philippe Gerum
  2018-04-18  2:21   ` Pham, Phong
  2018-04-18 19:33   ` Pham, Phong
  0 siblings, 2 replies; 8+ messages in thread
From: Philippe Gerum @ 2018-04-12  8:58 UTC (permalink / raw)
  To: Pham, Phong, xenomai; +Cc: Hillman, Robert

On 04/10/2018 09:03 PM, Pham, Phong wrote:
> 
> Hi,
> 
> According to page 651
> https://xenomai.org/documentation/xenomai-3/pdf/xeno3prm.pdf
> 
> 
> This will make such region accessible via the mapper device using the following sequence of code, via
> the default ->mmap() handler from the UDD core:
> int fd, fdm;
> void *p;
> fd = open("/dev/foocard", O_RDWR);
> fdm = open("/dev/foocard,mapper@2", O_RDWR);
> p = mmap(NULL, 4096, PROT_READ|PROT_WRITE, 0, fdm, 0);
> 
> 
> I have several questions:
> 
> 1)      It looks like the 4th argument of mmap (the one to the left of "fdm") needs to be either MAP_SHARED or MAP_PRIVATE
> 
> 2)      The "@" character right after "mapper" is not valid (ie. there should be no "@" character at all)
> 
> 3)      /dev/foocard should be /dev/rtdm/foocard


Fixed, thanks.

https://xenomai.org/documentation/xenomai-3/html/xeno3prm/structudd__memregion.html#udd_memory_region

> 
> here's my real question:
> 
> Assuming all 3 of the above is valid from user space, and on the kernel space, I followed the ex. to create memory region, etc. such that I do see my device
> 
> # ls -l dev/rtdm
> crw-------    1 root     root      252,   0 Jan  1 00:00 autotune
> crw-------    1 root     root      247,   0 Jan  1 00:00 eeprom
> crw-------    1 root     root      246,   0 Jan  1 00:00 eeprom,mapper0
> crw-------    1 root     root      254,   0 Jan  1 00:00 memdev-private
> crw-------    1 root     root      254,   1 Jan  1 00:00 memdev-shared
> crw-------    1 root     root      253,   0 Jan  1 00:00 memdev-sys
> crw-------    1 root     root      249,   0 Jan  1 00:00 mmio
> crw-------    1 root     root      248,   0 Jan  1 00:00 mmio,mapper0
> crw-------    1 root     root      248,   1 Jan  1 00:00 mmio,mapper1
> crw-------    1 root     root      248,   2 Jan  1 00:00 mmio,mapper2
> crw-------    1 root     root      248,   3 Jan  1 00:00 mmio,mapper3
> crw-------    1 root     root      248,   4 Jan  1 00:00 mmio,mapper4
> crw-------    1 root     root      250,   0 Jan  1 00:00 switchtest
> crw-------    1 root     root      251,   0 Jan  1 00:00 timerbench
> 
> 
> like /dev/rtdm/eeprom and /dev/rtdm/eeprom,mapper0  etc. I don't see my kernel hook ever gets called
> 
> 
> static struct udd_device eeprom = {
>               .device_flags = RTDM_NAMED_DEVICE,
>               .device_name = "eeprom",
>               .ops = {
>                              .close = phong_scs750_close,
>                              .open = phong_scs750_open,
>                              .mmap = phong_scs750_mmap,
>               }
> 
> By that, I mean phong_scs750_open, phong_scs750_mmap never gets invoked.  mmap() from user space returns -1 with errno value of 19 (ENODEV).  Any advise?

Your app may be missing symbol wrapping. Please check out this doc:

https://xenomai.org/documentation/xenomai-3/html/xeno3prm/group__cobalt__api.html

-- 
Philippe.


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

* Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space
  2018-04-12  8:58 ` Philippe Gerum
@ 2018-04-18  2:21   ` Pham, Phong
  2018-04-18 19:33   ` Pham, Phong
  1 sibling, 0 replies; 8+ messages in thread
From: Pham, Phong @ 2018-04-18  2:21 UTC (permalink / raw)
  To: Philippe Gerum, xenomai; +Cc: Hillman, Robert


Hi Philippe and all,

Regarding "Your app may be missing symbol wrapping. Please check out this doc:

https://xenomai.org/documentation/xenomai-3/html/xeno3prm/group__cobalt__api.html"

Thanks for the tip.  In the Makefile fragment from this link:
https://xenomai.org/building-applications-with-xenomai-3-x/

I suggest you add the missing --posix in the LDFLAGS as well.  After all, I copied my app from this very snippet and that's why I get the error.

On the same idea (using LDFLAGS from xeno-config), I would like to create a dynamically linked library (.so).  Without the LDFLAGS from xeno-config, my library loads fine (but will fail when mmap is called); with the LDFLAGS that has --posix, I get this error when loading:

R_PPC_REL24 relocation at 0x0ffacd3c for symbol `mmap' out of range

Does this mean I have to recompile all of the Xenomai library with -fPIC?  I didn't see anything regarding that choice during "configure" but peeking into the configure script, there are a few -fPIC occurrences.  Currently, I am using "Building the PPC32 libraries" instruction and also I didn't need to perform ./script/bootstrap b/c I am building it from the release tarball.

$xenomai_root/configure --host=powerpc-linux --with-core=cobalt --enable-debug=symbols

Suggestion on the error above and/or compiling Xenomai library w/ -fPIC is appreciated.

Just fyi w/ regard to your updated "comment fix" on how to mmap(), I don't know if you need to update udd.h (right above struct udd_memregion) as well.  i.e. the same comment exists there but don't know if the comment there is retrieved from the location where you made the "comment fix".

Phong.

-----Original Message-----
From: Philippe Gerum [mailto:rpm@xenomai.org]
Sent: Thursday, April 12, 2018 1:58 AM
To: Pham, Phong; xenomai@xenomai.org
Cc: Hillman, Robert
Subject: Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space

On 04/10/2018 09:03 PM, Pham, Phong wrote:
>
> Hi,
>
> According to page 651
> https://xenomai.org/documentation/xenomai-3/pdf/xeno3prm.pdf
>
>
> This will make such region accessible via the mapper device using the
> following sequence of code, via the default ->mmap() handler from the UDD core:
> int fd, fdm;
> void *p;
> fd = open("/dev/foocard", O_RDWR);
> fdm = open("/dev/foocard,mapper@2", O_RDWR); p = mmap(NULL, 4096,
> PROT_READ|PROT_WRITE, 0, fdm, 0);
>
>
> I have several questions:
>
> 1)      It looks like the 4th argument of mmap (the one to the left of "fdm") needs to be either MAP_SHARED or MAP_PRIVATE
>
> 2)      The "@" character right after "mapper" is not valid (ie. there should be no "@" character at all)
>
> 3)      /dev/foocard should be /dev/rtdm/foocard


Fixed, thanks.

https://xenomai.org/documentation/xenomai-3/html/xeno3prm/structudd__memregion.html#udd_memory_region

>
> here's my real question:
>
> Assuming all 3 of the above is valid from user space, and on the
> kernel space, I followed the ex. to create memory region, etc. such
> that I do see my device
>
> # ls -l dev/rtdm
> crw-------    1 root     root      252,   0 Jan  1 00:00 autotune
> crw-------    1 root     root      247,   0 Jan  1 00:00 eeprom
> crw-------    1 root     root      246,   0 Jan  1 00:00 eeprom,mapper0
> crw-------    1 root     root      254,   0 Jan  1 00:00 memdev-private
> crw-------    1 root     root      254,   1 Jan  1 00:00 memdev-shared
> crw-------    1 root     root      253,   0 Jan  1 00:00 memdev-sys
> crw-------    1 root     root      249,   0 Jan  1 00:00 mmio
> crw-------    1 root     root      248,   0 Jan  1 00:00 mmio,mapper0
> crw-------    1 root     root      248,   1 Jan  1 00:00 mmio,mapper1
> crw-------    1 root     root      248,   2 Jan  1 00:00 mmio,mapper2
> crw-------    1 root     root      248,   3 Jan  1 00:00 mmio,mapper3
> crw-------    1 root     root      248,   4 Jan  1 00:00 mmio,mapper4
> crw-------    1 root     root      250,   0 Jan  1 00:00 switchtest
> crw-------    1 root     root      251,   0 Jan  1 00:00 timerbench
>
>
> like /dev/rtdm/eeprom and /dev/rtdm/eeprom,mapper0  etc. I don't see
> my kernel hook ever gets called
>
>
> static struct udd_device eeprom = {
>               .device_flags = RTDM_NAMED_DEVICE,
>               .device_name = "eeprom",
>               .ops = {
>                              .close = phong_scs750_close,
>                              .open = phong_scs750_open,
>                              .mmap = phong_scs750_mmap,
>               }
>
> By that, I mean phong_scs750_open, phong_scs750_mmap never gets invoked.  mmap() from user space returns -1 with errno value of 19 (ENODEV).  Any advise?

Your app may be missing symbol wrapping. Please check out this doc:

https://xenomai.org/documentation/xenomai-3/html/xeno3prm/group__cobalt__api.html


--
Philippe.
Notice: This e-mail and any files transmitted with it may contain Data Device Corporation's privileged and proprietary information. It is intended solely for the use of the individual or entity to whom it is addressed. If you are not the named recipient of this transmission, any disclosure, copying, distribution or reliance on the contents of this message is prohibited. If you received this e-mail in error, please destroy it and any attached files and notify me immediately.

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

* Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space
  2018-04-12  8:58 ` Philippe Gerum
  2018-04-18  2:21   ` Pham, Phong
@ 2018-04-18 19:33   ` Pham, Phong
  2018-04-18 19:58     ` Philippe Gerum
  1 sibling, 1 reply; 8+ messages in thread
From: Pham, Phong @ 2018-04-18 19:33 UTC (permalink / raw)
  To: Philippe Gerum, xenomai; +Cc: Hillman, Robert


Hi,

Instead of  symbol `mmap' out of range, I now have symbol `malloc' out of range.  I removed  all the -fPIC in my environment.  I have to recompile libc???  I never compiled libc and wants to avoid it.

Any suggestion on
R_PPC_REL24 relocation at 0x0ffacd3c for symbol `mmap/malloc' out of range

is appreciated.

This is after I add LDFLAGS (from xeno-config) during the process of creating a shared library.

Phong.

-----Original Message-----
From: Pham, Phong
Sent: Tuesday, April 17, 2018 7:22 PM
To: 'Philippe Gerum'; xenomai@xenomai.org
Cc: Hillman, Robert
Subject: RE: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space


Hi Philippe and all,

Regarding "Your app may be missing symbol wrapping. Please check out this doc:

https://xenomai.org/documentation/xenomai-3/html/xeno3prm/group__cobalt__api.html"

Thanks for the tip.  In the Makefile fragment from this link:
https://xenomai.org/building-applications-with-xenomai-3-x/

I suggest you add the missing --posix in the LDFLAGS as well.  After all, I copied my app from this very snippet and that's why I get the error.

On the same idea (using LDFLAGS from xeno-config), I would like to create a dynamically linked library (.so).  Without the LDFLAGS from xeno-config, my library loads fine (but will fail when mmap is called); with the LDFLAGS that has --posix, I get this error when loading:

R_PPC_REL24 relocation at 0x0ffacd3c for symbol `mmap' out of range

Does this mean I have to recompile all of the Xenomai library with -fPIC?  I didn't see anything regarding that choice during "configure" but peeking into the configure script, there are a few -fPIC occurrences.  Currently, I am using "Building the PPC32 libraries" instruction and also I didn't need to perform ./script/bootstrap b/c I am building it from the release tarball.

$xenomai_root/configure --host=powerpc-linux --with-core=cobalt --enable-debug=symbols

Suggestion on the error above and/or compiling Xenomai library w/ -fPIC is appreciated.

Just fyi w/ regard to your updated "comment fix" on how to mmap(), I don't know if you need to update udd.h (right above struct udd_memregion) as well.  i.e. the same comment exists there but don't know if the comment there is retrieved from the location where you made the "comment fix".

Phong.

-----Original Message-----
From: Philippe Gerum [mailto:rpm@xenomai.org]
Sent: Thursday, April 12, 2018 1:58 AM
To: Pham, Phong; xenomai@xenomai.org
Cc: Hillman, Robert
Subject: Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space

On 04/10/2018 09:03 PM, Pham, Phong wrote:
>
> Hi,
>
> According to page 651
> https://xenomai.org/documentation/xenomai-3/pdf/xeno3prm.pdf
>
>
> This will make such region accessible via the mapper device using the
> following sequence of code, via the default ->mmap() handler from the UDD core:
> int fd, fdm;
> void *p;
> fd = open("/dev/foocard", O_RDWR);
> fdm = open("/dev/foocard,mapper@2", O_RDWR); p = mmap(NULL, 4096,
> PROT_READ|PROT_WRITE, 0, fdm, 0);
>
>
> I have several questions:
>
> 1)      It looks like the 4th argument of mmap (the one to the left of "fdm") needs to be either MAP_SHARED or MAP_PRIVATE
>
> 2)      The "@" character right after "mapper" is not valid (ie. there should be no "@" character at all)
>
> 3)      /dev/foocard should be /dev/rtdm/foocard


Fixed, thanks.

https://xenomai.org/documentation/xenomai-3/html/xeno3prm/structudd__memregion.html#udd_memory_region

>
> here's my real question:
>
> Assuming all 3 of the above is valid from user space, and on the
> kernel space, I followed the ex. to create memory region, etc. such
> that I do see my device
>
> # ls -l dev/rtdm
> crw-------    1 root     root      252,   0 Jan  1 00:00 autotune
> crw-------    1 root     root      247,   0 Jan  1 00:00 eeprom
> crw-------    1 root     root      246,   0 Jan  1 00:00 eeprom,mapper0
> crw-------    1 root     root      254,   0 Jan  1 00:00 memdev-private
> crw-------    1 root     root      254,   1 Jan  1 00:00 memdev-shared
> crw-------    1 root     root      253,   0 Jan  1 00:00 memdev-sys
> crw-------    1 root     root      249,   0 Jan  1 00:00 mmio
> crw-------    1 root     root      248,   0 Jan  1 00:00 mmio,mapper0
> crw-------    1 root     root      248,   1 Jan  1 00:00 mmio,mapper1
> crw-------    1 root     root      248,   2 Jan  1 00:00 mmio,mapper2
> crw-------    1 root     root      248,   3 Jan  1 00:00 mmio,mapper3
> crw-------    1 root     root      248,   4 Jan  1 00:00 mmio,mapper4
> crw-------    1 root     root      250,   0 Jan  1 00:00 switchtest
> crw-------    1 root     root      251,   0 Jan  1 00:00 timerbench
>
>
> like /dev/rtdm/eeprom and /dev/rtdm/eeprom,mapper0  etc. I don't see
> my kernel hook ever gets called
>
>
> static struct udd_device eeprom = {
>               .device_flags = RTDM_NAMED_DEVICE,
>               .device_name = "eeprom",
>               .ops = {
>                              .close = phong_scs750_close,
>                              .open = phong_scs750_open,
>                              .mmap = phong_scs750_mmap,
>               }
>
> By that, I mean phong_scs750_open, phong_scs750_mmap never gets invoked.  mmap() from user space returns -1 with errno value of 19 (ENODEV).  Any advise?

Your app may be missing symbol wrapping. Please check out this doc:

https://xenomai.org/documentation/xenomai-3/html/xeno3prm/group__cobalt__api.html


--
Philippe.
Notice: This e-mail and any files transmitted with it may contain Data Device Corporation's privileged and proprietary information. It is intended solely for the use of the individual or entity to whom it is addressed. If you are not the named recipient of this transmission, any disclosure, copying, distribution or reliance on the contents of this message is prohibited. If you received this e-mail in error, please destroy it and any attached files and notify me immediately.

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

* Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space
  2018-04-18 19:33   ` Pham, Phong
@ 2018-04-18 19:58     ` Philippe Gerum
  2018-04-18 23:02       ` Pham, Phong
  0 siblings, 1 reply; 8+ messages in thread
From: Philippe Gerum @ 2018-04-18 19:58 UTC (permalink / raw)
  To: Pham, Phong, xenomai; +Cc: Hillman, Robert

On 04/18/2018 09:33 PM, Pham, Phong wrote:
> 
> Hi,
> 
> Instead of  symbol `mmap' out of range, I now have symbol `malloc' out of range.  I removed  all the -fPIC in my environment.  I have to recompile libc???  I never compiled libc and wants to avoid it.

Of course not.

> 
> Any suggestion on
> R_PPC_REL24 relocation at 0x0ffacd3c for symbol `mmap/malloc' out of range
> 

This is likely happening because the default auto-init glue module for a
final executable is mentioned in the flags, you either want to pass
--auto-init-solib if you do need auto-init for bootstrapping a DSO, or
--no-auto-init if you don't care about auto-bootstrap, along with
--ldflags to xeno-config.

http://www.xenomai.org/documentation/xenomai-3/html/man1/xeno-config/index.html

> 
> I suggest you add the missing --posix in the LDFLAGS as well.  After all, I copied my app from this very snippet and that's why I get the error.
> 

As mentioned in the doc you are referring to, this example is about
building a trivial VxWorks app, not a POSIX one.

-- 
Philippe.


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

* Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space
  2018-04-18 19:58     ` Philippe Gerum
@ 2018-04-18 23:02       ` Pham, Phong
  2018-04-19  7:26         ` Philippe Gerum
  0 siblings, 1 reply; 8+ messages in thread
From: Pham, Phong @ 2018-04-18 23:02 UTC (permalink / raw)
  To: Philippe Gerum, xenomai; +Cc: Hillman, Robert

“This is likely happening because the default auto-init glue module for a final executable is mentioned in the flags, you either want to pass --auto-init-solib if you do need auto-init for bootstrapping a DSO, or --no-auto-init if you don't care about auto-bootstrap, along with --ldflags to xeno-config.



http://www.xenomai.org/documentation/xenomai-3/html/man1/xeno-config/index.html“





I see.  After adding either --auto-init-solib or --no-auto-init when compiling for library, along with compiler option -fPIC, mmap() still returns -1; (W/out -fPIC, munmap() cannot be relocated (similar types of error like before).  However, errno is 0.  How come errno returns “no error” when mmap() returns failure?



Phong.



-----Original Message-----
From: Philippe Gerum [mailto:rpm@xenomai.org]
Sent: Wednesday, April 18, 2018 12:58 PM
To: Pham, Phong; xenomai@xenomai.org
Cc: Hillman, Robert
Subject: Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space



On 04/18/2018 09:33 PM, Pham, Phong wrote:

>

> Hi,

>

> Instead of  symbol `mmap' out of range, I now have symbol `malloc' out of range.  I removed  all the -fPIC in my environment.  I have to recompile libc???  I never compiled libc and wants to avoid it.



Of course not.



>

> Any suggestion on

> R_PPC_REL24 relocation at 0x0ffacd3c for symbol `mmap/malloc' out of

> range

>



This is likely happening because the default auto-init glue module for a final executable is mentioned in the flags, you either want to pass --auto-init-solib if you do need auto-init for bootstrapping a DSO, or --no-auto-init if you don't care about auto-bootstrap, along with --ldflags to xeno-config.



http://www.xenomai.org/documentation/xenomai-3/html/man1/xeno-config/index.html



>

> I suggest you add the missing --posix in the LDFLAGS as well.  After all, I copied my app from this very snippet and that's why I get the error.

>



As mentioned in the doc you are referring to, this example is about building a trivial VxWorks app, not a POSIX one.



--

Philippe.

Notice: This e-mail and any files transmitted with it may contain Data Device Corporation's privileged and proprietary information. It is intended solely for the use of the individual or entity to whom it is addressed. If you are not the named recipient of this transmission, any disclosure, copying, distribution or reliance on the contents of this message is prohibited. If you received this e-mail in error, please destroy it and any attached files and notify me immediately.

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

* Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space
  2018-04-18 23:02       ` Pham, Phong
@ 2018-04-19  7:26         ` Philippe Gerum
  2018-05-02  0:32           ` Pham, Phong
  0 siblings, 1 reply; 8+ messages in thread
From: Philippe Gerum @ 2018-04-19  7:26 UTC (permalink / raw)
  To: Pham, Phong, xenomai; +Cc: Hillman, Robert

On 04/19/2018 01:02 AM, Pham, Phong wrote:
> “This is likely happening because the default auto-init glue module for
> a final executable is mentioned in the flags, you either want to pass
> --auto-init-solib if you do need auto-init for bootstrapping a DSO, or
> --no-auto-init if you don't care about auto-bootstrap, along with
> --ldflags to xeno-config.
> 
>  
> 
> http://www.xenomai.org/documentation/xenomai-3/html/man1/xeno-config/index.html“
> 
>  
> 
>  
> 
> I see.  After adding either --auto-init-solib or --no-auto-init when
> compiling for library, along with compiler option -fPIC, mmap() still
> returns -1; (W/out -fPIC, munmap() cannot be relocated (similar types of
> error like before).

xeno-config --ldflags will return the Xenomai-related flags for linking,
which -fPIC is not. If you plan for building a DSO, you need to apply
the common rules stated in the ld documentation, which include
mentioning  -fPIC / -fpic for shared libs. This is not a Xenomai issue.

  However, errno is 0.  How come errno returns “no
> error” when mmap() returns failure?
> 

Please post a test code snippet illustrating the problem.

-- 
Philippe.


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

* Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space
  2018-04-19  7:26         ` Philippe Gerum
@ 2018-05-02  0:32           ` Pham, Phong
  0 siblings, 0 replies; 8+ messages in thread
From: Pham, Phong @ 2018-05-02  0:32 UTC (permalink / raw)
  To: Philippe Gerum, xenomai; +Cc: Hillman, Robert


Hi Philippe,

Below are the snippets compiled with -fPIC in the DSO.  If I don't compile with -fPIC, I get this error:

# bin/vxapp
bin/vxapp: error while loading shared libraries: /usr/xenomai/lib/libscs750.so: R_PPC_REL24 relocation at 0x0ffacec4 for symbol `munmap' out of range

If I do compile with -fPIC for my DSO, this is the snippet on the executable (ie. from your example, that would be "vxapp" executable.)

...
...
        int fd_eeprom = open("/dev/rtdm/eeprom,mapper0", O_RDWR);
        uint32_t baseAddr_eeprom = (volatile uint32_t)mmap(NULL, SCS_EEPROM_PHYSICAL_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd_eeprom, 0);
printf("%s():  baseAddr_eeprom = 0x%08x\n", __func__, baseAddr_eeprom);
...
...

Below is the snippet from my DSO:

...
...
    int fdm = open("/dev/rtdm/eeprom,mapper0", O_RDWR);
    uint32_t baseAddr = -2;

printf("%s(): baseAddr = 0x%08x, errno = %d\n", __func__, baseAddr, errno);
baseAddr = (volatile uint32_t)mmap(NULL, SCS_EEPROM_PHYSICAL_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fdm, 0);

if (baseAddr = -1)
{
printf("%s(): baseAddr = 0x%08x, errno = %d\n", __func__, baseAddr, errno);
}
....

For my DSO, LDFLAGS := $(shell $(XENO_CONFIG) --no-auto-init --posix --vxworks --ldflags) is in the makefile.  For my "vxapp", LDFLAGS := $(shell $(XENO_CONFIG) --posix --vxworks --ldflags)

Output:
scsEepromTest():  baseAddr_eeprom = 0x366ee000
sysEepromSet(): baseAddr = 0xfffffffe, errno = 0
sysEepromSet(): baseAddr = 0xffffffff, errno = 0

scsEepromTest() resides in the "vxapp" executable and sysEepromSet() resides in the DSO.

Phong.

-----Original Message-----
From: Philippe Gerum [mailto:rpm@xenomai.org]
Sent: Thursday, April 19, 2018 12:26 AM
To: Pham, Phong; xenomai@xenomai.org
Cc: Hillman, Robert
Subject: Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space

On 04/19/2018 01:02 AM, Pham, Phong wrote:
> “This is likely happening because the default auto-init glue module for
> a final executable is mentioned in the flags, you either want to pass
> --auto-init-solib if you do need auto-init for bootstrapping a DSO, or
> --no-auto-init if you don't care about auto-bootstrap, along with
> --ldflags to xeno-config.
>
>
>
> http://www.xenomai.org/documentation/xenomai-3/html/man1/xeno-config/index.html“
>
>
>
>
>
> I see.  After adding either --auto-init-solib or --no-auto-init when
> compiling for library, along with compiler option -fPIC, mmap() still
> returns -1; (W/out -fPIC, munmap() cannot be relocated (similar types of
> error like before).

xeno-config --ldflags will return the Xenomai-related flags for linking,
which -fPIC is not. If you plan for building a DSO, you need to apply
the common rules stated in the ld documentation, which include
mentioning  -fPIC / -fpic for shared libs. This is not a Xenomai issue.

  However, errno is 0.  How come errno returns “no
> error” when mmap() returns failure?
>

Please post a test code snippet illustrating the problem.

--
Philippe.
Notice: This e-mail and any files transmitted with it may contain Data Device Corporation's privileged and proprietary information. It is intended solely for the use of the individual or entity to whom it is addressed. If you are not the named recipient of this transmission, any disclosure, copying, distribution or reliance on the contents of this message is prohibited. If you received this e-mail in error, please destroy it and any attached files and notify me immediately.

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

end of thread, other threads:[~2018-05-02  0:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-10 19:03 [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space Pham, Phong
2018-04-12  8:58 ` Philippe Gerum
2018-04-18  2:21   ` Pham, Phong
2018-04-18 19:33   ` Pham, Phong
2018-04-18 19:58     ` Philippe Gerum
2018-04-18 23:02       ` Pham, Phong
2018-04-19  7:26         ` Philippe Gerum
2018-05-02  0:32           ` Pham, Phong

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.