יום חמישי, 30 במאי 2013

usbfx2 device probing in linux

I wanted to exercise my USB device driver writing in Linux.
I wrote the following Skelton of USB device for my FX2 USB card
usbfx

  1: #include <linux/kernel.h>    /* We're doing kernel work */ 
  2: #include <linux/module.h>    /* Specifically, a module */ 
  3: #include <linux/fs.h> 
  4: #include <asm/uaccess.h>    /* for get_user and put_user */ 
  5: #include  <linux/slab.h> 
  6: #include <linux/timer.h> 
  7: #include <linux/mod_devicetable.h> 
  8: #include <linux/usb.h> 
  9:  
 10: #define SUCCESS 0 
 11: 
 12: #define DEBUG   
 13:   
 14: /*  
 15:  * Is the device open right now? Used to prevent 
 16:  * concurent access into the same device  
 17:  * http://www.osronline.com/hardware/osrfx2_32.pdf 
 18:  */ 
 19:  int Device_Open = 0; 
 20:  
 21: #define ML_VENDOR_ID 0x0547 
 22: #define ML_PRODUCT_ID 0x1002 
 23:   
 24: static struct usb_device_id ml_table [] = { 
 25:     { USB_DEVICE(ML_VENDOR_ID, ML_PRODUCT_ID) }, 
 26:     { } 
 27: }; 
 28: 
 29: MODULE_DEVICE_TABLE(usb, ml_table); 
 30: 
 31: static int ml_probe(struct usb_interface *interface, const struct usb_device_id  *id) 
 32: { 
 33:     /* called when a USB device is connected to the computer. */ 
 34:     printk(KERN_INFO "ml_probe");
 35: 
 36:   return 0;
 37: } 
 38:  
 39: static void ml_disconnect(struct usb_interface *interface) 
 40: { 
 41:     /* called when unplugging a USB device. */  
 42:     printk(KERN_INFO "ml_disconnect"); 
 43: } 
 44:   
 45: static struct usb_driver fx2_table = { 
 46:     .name = "myFx2", 
 47:     .id_table = ml_table, 
 48:     .probe = ml_probe, 
 49:     .disconnect = ml_disconnect, 
 50: }; 
 51:   
 52: /*  
 53:  * Initialize the module - Register the character device  
 54:  */ 
 55: int init_module() 
 56: {
 57:     int retval;
 58:      
 59:   printk(KERN_INFO "Initializing USB FX\n");
 60: 
 61:     retval = usb_register(&fx2_table);
 62:    
 63:     printk(KERN_ALERT"THE usb_register RET::%d\n",retval); 
 64:     
 65:   return 0; 
 66: }     
 67:  
 68: void cleanup_module() 
 69: { 
 70:      printk(KERN_INFO "cleanup_module\n"); 
 71: }
 72: 
 73: MODULE_LICENSE("GPL");

The make file :

  1: obj-m := usbfx.o 
  2: 
  3: KDIR  := /lib/modules/$(shell uname -r)/build
  4: PWD   := $(shell pwd)
  5: 
  6: default:
  7:     $(MAKE) -C $(KDIR) M=$(PWD) modules

After building the project with make I have tried to install it using the insmod command. and I got the following error:
"insmod: error inserting 'usbfx.ko': -1 Unknown symbol in module"
I tried to figure out the problem using dmseg comamnd .

The log entery of the problem:
[ 3569.172900] usbfx: Unknown symbol usb_register_driver (err 0)


The following article explain about the problem of GPL licensee shortcut.
I had line 73 in order to declare the module license as GPL

Trying to install the module now with insmod  then dmseg produce:


[ 4666.501865] Initializing USB FX
[ 4666.501894] usbcore: registered new interface driver myFx2
[ 4666.501897] THE usb_register RET::0
[ 4700.271816] usb 1-1.1: new high-speed USB device number 4 using ehci_hcd


Now connecting my usb fx device  to the usb port
dmseg produce
[ 4701.740804] ml_probe

אין תגובות:

הוסף רשומת תגובה