All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] Test program not accessing RTDM driver
@ 2016-01-11 14:33 Heinick, J Michael
  2016-01-11 14:54 ` Philippe Gerum
  2016-01-11 14:55 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 5+ messages in thread
From: Heinick, J Michael @ 2016-01-11 14:33 UTC (permalink / raw)
  To: xenomai


.........1.........2.........3.........4.........5.........6.........7....|

Currently, I have a RTDM driver that installs with insmod, creates the
node in /dev/rtdm, uninstalls with rmmod, and removes the node from
/dev/rtdm.  At this early stage this RTDM driver is only a skeleton that
should log a message with rtdm_printk whenever the open, close, read,
write, and ioctl handlers are called. So far I have been unable to get
any indication that any of the handlers I have written for the driver are
interacting with the small test program even though the program appears to
run without errors.

The ioctl call in the test program generates the following message in the
dmesg file:

[12503.672657] [Xenomai] tcgrtdmtest[3595] called regular ioctl() on /dev/rtdm/tcgrtdm

The example at http://git.xenomai.org/xenomai-jro.git/tree/demo/posix/cobalt/gpiopwm.c?h=410c
recently suggested by Jorge Ramirez Ortiz has been somewhat helpful, but
I still do not know what I am missing.  Are my rtdm_device and
rtdm_driver structures correct enough to get the handlers called, or is the
problem elsewhere?

Thanks for any help that you can provide.
Mike H.

Additional details on our situation are included below:

The code: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// ------------- tcgrtdmtest.c -----------
#include <xenomai/init.h>
#include <rtdm/rtdm.h>
#include <stdlib.h>
#include <errno.h>
#include <error.h>
#include <stdio.h>

int main()
  {
  int fd;
  unsigned int rply;
  rply = 987; // =0x3DB
  fd = open("/dev/rtdm/tcgrtdm",O_RDWR);
  perror("Open error: ");
  ioctl(fd,0x55,&rply);
  printf("reply = 0x%X\n",rply); // reply = 0xAB would be good
  close(fd);
  return 0;
  }


The makefile: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
XENO_CONFIG := /usr/xenomai/bin/xeno-config
CFLAGS := $(shell $(XENO_CONFIG) --posix --cflags)
LDLAGS := $(shell $(XENO_CONFIG) --posix --ldflags)
CC := $(shell $(XENO_CONFIG) --cc)

default:
        $(CC) -o tcgrtdmtest tcgrtdmtest.C $(CFLAGS) $(LDFLAGS)

The test program make result: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
$ make
gcc -o tcgrtdmtest tcgrtdmtest.C -I/usr/xenomai/include/cobalt -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -D__COBALT__ -D__COBALT_WRAP__
$

Output from test program vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
(Note: The 987 (0x3DB) sent to the driver by the test ptogram should
be changed to 0xAB and returned by the driver in the ioctl call, but
that is not happening.)
Open error: : Success
reply = 0x3DB


The driver: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// ------------------- tcgbc635rt.c ---------------------------
#include <rtdm/rtdm.h>
#include <rtdm/driver.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Michael Heinick");
MODULE_DESCRIPTION("RTDM Interface to BC635 TCG card");

int __init tcgrt_init(void);

void __exit tcgrt_exit(void);
static int tcgrtdmopen(struct rtdm_fd *fd, int oflags)
  {
  int status;
  printk(KERN_CRIT"TCG RTDM open:.\n");
  rtdm_printk(KERN_CRIT"TCG RTDM open:.\n");
  status = 0;
  return status;
  }

static void tcgrtdmclose(struct rtdm_fd *fd)
  {
  int status;
  printk("TCG RTDM close:.\n");
  rtdm_printk("TCG RTDM close:.\n");
  status =  0;
  return;
  }

static int tcgrtdmioctl(struct rtdm_fd *fd, unsigned int request,void __user *arg)
  {
  unsigned int rply;
  printk("TCG RTDM ioctl: 0x%X\n",request);
  if(!rtdm_rw_user_ok(fd,arg,sizeof(rply))) { return -EFAULT; }
  rtdm_copy_from_user(fd,&rply,arg,sizeof(rply));
  rtdm_printk("TCG RTDM ioctl: 0x%X arg = 0x%X\n",request,rply);
  rply = 0xAB; //Change rply to 0xAB for return to test application
  rtdm_copy_to_user(fd, arg, &rply, sizeof(rply));
  return request;
  }

static ssize_t tcgrtdmread(struct rtdm_fd *fd, void __user *buf, size_t size)
  {
  rtdm_printk("TCG RTDM read:.\n");
  size = 124;
  return size;
  }

static ssize_t tcgrtdmwrite(struct rtdm_fd *fd, const void __user *buf, size_t size)
  {
  rtdm_printk("TCG RTDM write:.\n");
  return size;
  }

static struct rtdm_driver driver = {
  .profile_info = RTDM_PROFILE_INFO(tcgrtdm,RTDM_CLASS_SERIAL,0,3),
  .device_flags = RTDM_NAMED_DEVICE | RTDM_EXCLUSIVE,
  .device_count = 1,
  .ops = {
    .open = tcgrtdmopen,
    .close = tcgrtdmclose,
    .read_nrt = tcgrtdmread,
    .write_nrt = tcgrtdmwrite,
    .ioctl_nrt = tcgrtdmioctl,
    },
  };
static struct rtdm_device device = {
  .driver = &driver,
  .label = "tcgrtdm"
  };

int __init tcgrt_init(void)
  {
  int status;
  rtdm_printk("TCG RTDM Driver Init.\n");
  status = rtdm_dev_register(&device);
  if(status == 0)
    {
    rtdm_printk("TCG RTDM Driver Registration succeeded.\n");
    }
  else
    {
    switch(status)
     {
      case -EINVAL:
        rtdm_printk("Registration: Invalid entries in device structure\n");
        break;
      case -EEXIST:
        rtdm_printk("Registration: Device name of Protocol ID already in use\n");
        break;
      case -ENOMEM:
        rtdm_printk("Registration: Memory allocation failed\n");
        break;
      default:
        rtdm_printk("Registration: Unknown error\n");
        break;
      } // End of status switch
    } // End of status not 0
  return status;
  }

void __exit tcgrt_exit(void)
  {
  rtdm_printk("Unregistration: Exiting TCG RTDM Driver\n");
  rtdm_dev_unregister(&device);
  }

#ifdef MODULE
module_init(tcgrt_init);
#endif
module_exit(tcgrt_exit);

The driver makefile: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
XENO_CONFIG := /usr/xenomai/bin/xeno-config
$(eval ccflags-y = $(shell $(XENO_CONFIG) --rtdm --cflags))
obj-m += tcgbc635rt.o

default:
       $(MAKE) -C $(KDIR) M=$(PWD) tcgbc635rt.ko

The driver make result: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
make -C /lib/modules/3.14.44-xeno02/build M=/home/guts/mike/tcg/rtdmdrvr tcgbc635rt.ko
make[1]: Entering directory `/home/guts/mike/xeno/linux-3.14.44'
  CC [M]  /home/guts/mike/tcg/rtdmdrvr/tcgbc635rt.o
  MODPOST 1 modules
  CC      /home/guts/mike/tcg/rtdmdrvr/tcgbc635rt.mod.o
  LD [M]  /home/guts/mike/tcg/rtdmdrvr/tcgbc635rt.ko
make[1]: Leaving directory `/home/guts/mike/xeno/linux-3.14.44'


Return from /usr/xenomai/bin/xeno-config --info vvvvvvvvvvvvvvvvvvvvvvvvvv
$ /usr/xenomai/bin/xeno-config --info
Xenomai version: Xenomai/cobalt v3.0.1
Linux htsi-linux 3.14.44-xeno02 #1 SMP PREEMPT Fri Nov 13 09:35:37 EST 2015 x86_64 x86_64 x86_64 GNU/Linux
Kernel parameters: BOOT_IMAGE=/vmlinuz-3.14.44-xeno02 root=UUID=ef5daf08-36a0-46b3-9ed4-4917b36301cf ro nomodeset quiet splash
I-pipe release #10 detected
Cobalt core 3.0.1 detected
Compiler: gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
Build args: --with-core=cobalt --enable-smp --enable-pshared --host=i686-linux host_alias=i686-linux
$


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

* Re: [Xenomai] Test program not accessing RTDM driver
  2016-01-11 14:33 [Xenomai] Test program not accessing RTDM driver Heinick, J Michael
@ 2016-01-11 14:54 ` Philippe Gerum
  2016-01-12 15:43   ` Heinick, J Michael
  2016-01-11 14:55 ` Gilles Chanteperdrix
  1 sibling, 1 reply; 5+ messages in thread
From: Philippe Gerum @ 2016-01-11 14:54 UTC (permalink / raw)
  To: Heinick, J Michael, xenomai

On 01/11/2016 03:33 PM, Heinick, J Michael wrote:
>
> .........1.........2.........3.........4.........5.........6.........7....|
>
> Currently, I have a RTDM driver that installs with insmod, creates the
> node in /dev/rtdm, uninstalls with rmmod, and removes the node from
> /dev/rtdm.  At this early stage this RTDM driver is only a skeleton that
> should log a message with rtdm_printk whenever the open, close, read,
> write, and ioctl handlers are called. So far I have been unable to get
> any indication that any of the handlers I have written for the driver are
> interacting with the small test program even though the program appears to
> run without errors.
>
> The ioctl call in the test program generates the following message in the
> dmesg file:
>
> [12503.672657] [Xenomai] tcgrtdmtest[3595] called regular ioctl() on /dev/rtdm/tcgrtdm
>
> The example at http://git.xenomai.org/xenomai-jro.git/tree/demo/posix/cobalt/gpiopwm.c?h=410c
> recently suggested by Jorge Ramirez Ortiz has been somewhat helpful, but
> I still do not know what I am missing.  Are my rtdm_device and
> rtdm_driver structures correct enough to get the handlers called, or is the
> problem elsewhere?
>
> Thanks for any help that you can provide.
> Mike H.

The issue is with the link stage of your user-space program: the posix 
I/O calls used in your code such as open/ioctl and friends should be 
provided by libcobalt.so, but they are not. When the substitution takes 
place, RTDM handles the calls, otherwise the calls are routed via the 
glibc/uclibc to the regular kernel, which ends up reaching a dummy 
placeholder driver, which eventually issues the warning message in the 
kernel log (foo[pid] called regular <func> on /dev/rtdm/device).

The substitution happens when the proper application build flags are 
used, based on the linker's --wrap switch. So the fix is likely to be 
applied to your application Makefile. Even if slightly outdated wrt 
Xenomai 3.x, the doc below gives some hints (you should assume 
libcobalt.so when reading libpthread_rt.so):

http://xenomai.org/2014/08/porting-a-linux-application-to-xenomai-dual-kernel/#Compilation_for_the_Xenomai_POSIX_skin

-- 
Philippe.


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

* Re: [Xenomai] Test program not accessing RTDM driver
  2016-01-11 14:33 [Xenomai] Test program not accessing RTDM driver Heinick, J Michael
  2016-01-11 14:54 ` Philippe Gerum
@ 2016-01-11 14:55 ` Gilles Chanteperdrix
  1 sibling, 0 replies; 5+ messages in thread
From: Gilles Chanteperdrix @ 2016-01-11 14:55 UTC (permalink / raw)
  To: Heinick, J Michael; +Cc: xenomai

On Mon, Jan 11, 2016 at 02:33:58PM +0000, Heinick, J Michael wrote:
> 
> .........1.........2.........3.........4.........5.........6.........7....|
> 
> Currently, I have a RTDM driver that installs with insmod, creates the
> node in /dev/rtdm, uninstalls with rmmod, and removes the node from
> /dev/rtdm.  At this early stage this RTDM driver is only a skeleton that
> should log a message with rtdm_printk whenever the open, close, read,
> write, and ioctl handlers are called. So far I have been unable to get
> any indication that any of the handlers I have written for the driver are
> interacting with the small test program even though the program appears to
> run without errors.
> 
> The ioctl call in the test program generates the following message in the
> dmesg file:
> 
> [12503.672657] [Xenomai] tcgrtdmtest[3595] called regular ioctl() on /dev/rtdm/tcgrtdm
> 
> The example at http://git.xenomai.org/xenomai-jro.git/tree/demo/posix/cobalt/gpiopwm.c?h=410c
> recently suggested by Jorge Ramirez Ortiz has been somewhat helpful, but
> I still do not know what I am missing.  Are my rtdm_device and
> rtdm_driver structures correct enough to get the handlers called, or is the
> problem elsewhere?
> 
> Thanks for any help that you can provide.
> Mike H.
> 
> Additional details on our situation are included below:
> 
> The code: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> // ------------- tcgrtdmtest.c -----------
> #include <xenomai/init.h>
> #include <rtdm/rtdm.h>
> #include <stdlib.h>
> #include <errno.h>
> #include <error.h>
> #include <stdio.h>
> 
> int main()
>   {
>   int fd;
>   unsigned int rply;
>   rply = 987; // =0x3DB
>   fd = open("/dev/rtdm/tcgrtdm",O_RDWR);

What happens if you try open("/dev/tcgrtdm", ...) ?

-- 
					    Gilles.
https://click-hack.org


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

* Re: [Xenomai] Test program not accessing RTDM driver
  2016-01-11 14:54 ` Philippe Gerum
@ 2016-01-12 15:43   ` Heinick, J Michael
  2016-01-12 16:24     ` Philippe Gerum
  0 siblings, 1 reply; 5+ messages in thread
From: Heinick, J Michael @ 2016-01-12 15:43 UTC (permalink / raw)
  To: xenomai



-----Original Message-----
From: Philippe Gerum [mailto:rpm@xenomai.org] 
Sent: Monday, January 11, 2016 9:54 AM
To: Heinick, J Michael; xenomai@xenomai.org
Subject: Re: [Xenomai] Test program not accessing RTDM driver

On 01/11/2016 03:33 PM, Heinick, J Michael wrote:
>
> .........1.........2.........3.........4.........5.........6.........7
> ....|
>
> Currently, I have a RTDM driver that installs with insmod, creates the 
> node in /dev/rtdm, uninstalls with rmmod, and removes the node from 
> /dev/rtdm.  At this early stage this RTDM driver is only a skeleton 
> that should log a message with rtdm_printk whenever the open, close, 
> read, write, and ioctl handlers are called. So far I have been unable 
> to get any indication that any of the handlers I have written for the 
> driver are interacting with the small test program even though the 
> program appears to run without errors.
>
> The ioctl call in the test program generates the following message in 
> the dmesg file:
>
> [12503.672657] [Xenomai] tcgrtdmtest[3595] called regular ioctl() on 
> /dev/rtdm/tcgrtdm
>
> The example at 
> http://git.xenomai.org/xenomai-jro.git/tree/demo/posix/cobalt/gpiopwm.
> c?h=410c recently suggested by Jorge Ramirez Ortiz has been somewhat 
> helpful, but I still do not know what I am missing.  Are my 
> rtdm_device and rtdm_driver structures correct enough to get the 
> handlers called, or is the problem elsewhere?
>
> Thanks for any help that you can provide.
> Mike H.

The issue is with the link stage of your user-space program: the posix I/O calls used in your code such as open/ioctl and friends should be provided by libcobalt.so, but they are not. When the substitution takes place, RTDM handles the calls, otherwise the calls are routed via the glibc/uclibc to the regular kernel, which ends up reaching a dummy placeholder driver, which eventually issues the warning message in the kernel log (foo[pid] called regular <func> on /dev/rtdm/device).

The substitution happens when the proper application build flags are used, based on the linker's --wrap switch. So the fix is likely to be applied to your application Makefile. Even if slightly outdated wrt Xenomai 3.x, the doc below gives some hints (you should assume libcobalt.so when reading libpthread_rt.so):

http://xenomai.org/2014/08/porting-a-linux-application-to-xenomai-dual-kernel/#Compilation_for_the_Xenomai_POSIX_skin

--
Philippe.

---------------------------------------------------------------------------------------------

Thank you, Philippe.

The makefile now looks like this:

XENO_CONFIG := /usr/xenomai/bin/xeno-config
CFLAGS := $(shell $(XENO_CONFIG) --posix --cflags)
LDLAGS := $(shell $(XENO_CONFIG) --posix --ldflags)
CC := $(shell $(XENO_CONFIG) --cc)

default:
	$(CC) -c -o tcgrtdmtest.o tcgrtdmtest.C $(CFLAGS) $(LDFLAGS)
	/usr/xenomai/bin/wrap-link.sh -v $(CC) -o tcgrtdmtest tcgrtdmtest.o -Wl,@/usr/xenomai/lib/cobalt.wrappers -L/usr/xenomai/lib -lcobalt -lpthread -lrt

Then I found out that I had to set LD_LIBRARY_PATH=/usr/xenomai/lib. 
Now when the test program runs I no longer get the message in the
dmesg file that the regular ioctl is being called.

But now the open statement is generating an "Operation not permitted" 
message in its ouput, and still not logging any messages in the
dmesg file.  It does this even when I run as superuser.

So, referring to the link:
  http://xenomai.org/2014/06/running-a-xenomai-application-as-a-regular-user/
I ran id to get my gid which turned out to be 1000, and then, as superuser,
entered  echo 1000 > sys/module/xenomai/parameters/allowed_group
There is no /dev/rtpipe.  I still get the same "Operation not permitted"
message, even as superuser.  What else should I check and do?

Again, your help is greatly appreciated,
Mike H.


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

* Re: [Xenomai] Test program not accessing RTDM driver
  2016-01-12 15:43   ` Heinick, J Michael
@ 2016-01-12 16:24     ` Philippe Gerum
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Gerum @ 2016-01-12 16:24 UTC (permalink / raw)
  To: Heinick, J Michael, xenomai

On 01/12/2016 04:43 PM, Heinick, J Michael wrote:
>
>
> -----Original Message-----
> From: Philippe Gerum [mailto:rpm@xenomai.org]
> Sent: Monday, January 11, 2016 9:54 AM
> To: Heinick, J Michael; xenomai@xenomai.org
> Subject: Re: [Xenomai] Test program not accessing RTDM driver
>
> On 01/11/2016 03:33 PM, Heinick, J Michael wrote:
>>
>> .........1.........2.........3.........4.........5.........6.........7
>> ....|
>>
>> Currently, I have a RTDM driver that installs with insmod, creates the
>> node in /dev/rtdm, uninstalls with rmmod, and removes the node from
>> /dev/rtdm.  At this early stage this RTDM driver is only a skeleton
>> that should log a message with rtdm_printk whenever the open, close,
>> read, write, and ioctl handlers are called. So far I have been unable
>> to get any indication that any of the handlers I have written for the
>> driver are interacting with the small test program even though the
>> program appears to run without errors.
>>
>> The ioctl call in the test program generates the following message in
>> the dmesg file:
>>
>> [12503.672657] [Xenomai] tcgrtdmtest[3595] called regular ioctl() on
>> /dev/rtdm/tcgrtdm
>>
>> The example at
>> http://git.xenomai.org/xenomai-jro.git/tree/demo/posix/cobalt/gpiopwm.
>> c?h=410c recently suggested by Jorge Ramirez Ortiz has been somewhat
>> helpful, but I still do not know what I am missing.  Are my
>> rtdm_device and rtdm_driver structures correct enough to get the
>> handlers called, or is the problem elsewhere?
>>
>> Thanks for any help that you can provide.
>> Mike H.
>
> The issue is with the link stage of your user-space program: the posix I/O calls used in your code such as open/ioctl and friends should be provided by libcobalt.so, but they are not. When the substitution takes place, RTDM handles the calls, otherwise the calls are routed via the glibc/uclibc to the regular kernel, which ends up reaching a dummy placeholder driver, which eventually issues the warning message in the kernel log (foo[pid] called regular <func> on /dev/rtdm/device).
>
> The substitution happens when the proper application build flags are used, based on the linker's --wrap switch. So the fix is likely to be applied to your application Makefile. Even if slightly outdated wrt Xenomai 3.x, the doc below gives some hints (you should assume libcobalt.so when reading libpthread_rt.so):
>
> http://xenomai.org/2014/08/porting-a-linux-application-to-xenomai-dual-kernel/#Compilation_for_the_Xenomai_POSIX_skin
>
> --
> Philippe.
>
> ---------------------------------------------------------------------------------------------
>
> Thank you, Philippe.
>
> The makefile now looks like this:
>
> XENO_CONFIG := /usr/xenomai/bin/xeno-config
> CFLAGS := $(shell $(XENO_CONFIG) --posix --cflags)
> LDLAGS := $(shell $(XENO_CONFIG) --posix --ldflags)
> CC := $(shell $(XENO_CONFIG) --cc)
>
> default:
> 	$(CC) -c -o tcgrtdmtest.o tcgrtdmtest.C $(CFLAGS) $(LDFLAGS)
> 	/usr/xenomai/bin/wrap-link.sh -v $(CC) -o tcgrtdmtest tcgrtdmtest.o -Wl,@/usr/xenomai/lib/cobalt.wrappers -L/usr/xenomai/lib -lcobalt -lpthread -lrt
>
> Then I found out that I had to set LD_LIBRARY_PATH=/usr/xenomai/lib.
> Now when the test program runs I no longer get the message in the
> dmesg file that the regular ioctl is being called.
>
> But now the open statement is generating an "Operation not permitted"
> message in its ouput, and still not logging any messages in the
> dmesg file.  It does this even when I run as superuser.
>
> So, referring to the link:
>    http://xenomai.org/2014/06/running-a-xenomai-application-as-a-regular-user/
> I ran id to get my gid which turned out to be 1000, and then, as superuser,
> entered  echo 1000 > sys/module/xenomai/parameters/allowed_group
> There is no /dev/rtpipe.  I still get the same "Operation not permitted"
> message, even as superuser.  What else should I check and do?
>

The link-wrap line should read:

/usr/xenomai/bin/wrap-link.sh -v $(CC) -o tcgrtdmtest tcgrtdmtest.o 
$(LFDLAGS)

The comment in wrap-link.sh may be misleading.

-- 
Philippe.


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

end of thread, other threads:[~2016-01-12 16:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-11 14:33 [Xenomai] Test program not accessing RTDM driver Heinick, J Michael
2016-01-11 14:54 ` Philippe Gerum
2016-01-12 15:43   ` Heinick, J Michael
2016-01-12 16:24     ` Philippe Gerum
2016-01-11 14:55 ` Gilles Chanteperdrix

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.