Results 1 to 9 of 9
i am writing a kernel module program to access information about usb device.
#include <linux/kernel.h>
#include <linux/module.h>
void init_module(){
printk("this is the module entry point");
struct usb_device newdevice;
usb_get_device(&newdevice);
}
...
- 04-27-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 13
kernel module problem
i am writing a kernel module program to access information about usb device.
#include <linux/kernel.h>
#include <linux/module.h>
void init_module(){
printk("this is the module entry point");
struct usb_device newdevice;
usb_get_device(&newdevice);
}
void cleanup_module() {
printk("module exit from kernel");
}
can i declare data structre like this in init module function. and can call fucntion like this. this program is not working properly.
- 04-27-2009 #2Just Joined!
- Join Date
- Jun 2006
- Posts
- 29
Hi,
I don't find "usb_get_device()" in linux kernel
In which kernel u found this ??
- 04-27-2009 #3Just Joined!
- Join Date
- Mar 2009
- Posts
- 13
sorry for that, this is usb_get_dev() in usb.h file.
after inserting module this is giving error unknown symbol in module.
- 04-29-2009 #4Just Joined!
- Join Date
- Jun 2006
- Posts
- 29
Hi,
- u missed adding usb headers
- Man page of USB_GET_DEV
- cat /proc/kallsyms | grep usb_get_dev
this command gives u that symbol is in kernel or not
try above things
cheers
- 04-29-2009 #5Just Joined!
- Join Date
- Mar 2009
- Posts
- 13
My program is:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h> /* For current */
#include <linux/tty.h> /* For the tty declarations */
#include <linux/version.h> /* For LINUX_VERSION_CODE */
#include <linux/kernel.h>
#include <linux/tty_driver.h>
#include <linux/usb.h>
struct usb_device *outdev;
struct sysinfo oursysinfo;
EXPORT_SYMBOL_NOVERS(usb_get_dev);
#ifndef EXPORT_SYMTAB
#define EXPORT_SYMTAB
#endif
#include <linux/autoconf.h>
#if defined (CONFIG_MODVERSIONS) && !defined(MODVERSION)
#define MODVERSION
#endif
#if defined (MODVERSIONS) && !defined (__GENKSYMS__)
#include <linux/modversion.h>
#include "export.ver"
#endif
static void fun_call(){
usb_get_dev(outdev);
}
static void print_string(char *str)
{
struct tty_struct *my_tty;
my_tty = current->signal->tty;
if(my_tty != NULL) {
((my_tty->driver->ops)->write)( my_tty, str,strlen(str));
}
}
static int __init print_string_init(void)
{
printk("hi");
print_string("The module has been inserted. Hello world!");
int i=0;
fun_call();
print_string("structure has been allocated");
return 0;
}
static void __exit print_string_exit(void)
{
printk("bye");
print_string("The module has been removed. Farewell world!");
}
module_init(print_string_init);
module_exit(print_string_exit);
Result of cat /proc/kallsyms | grep usb_get_dev
f88f5a18 r __ksymtab_usb_get_dev [usbcore]
f88f5ef4 r __kstrtab_usb_get_dev [usbcore]
f88f5c8c r __kcrctab_usb_get_dev [usbcore]
f88df580 t usb_get_dev [usbcore]
f88e85e0 t usb_get_device_descriptor [usbcore]
7463f464 a __crc_usb_get_dev [usbcore]
i am using ubuntu 8.01 operating system
after make command run output is:
make -C /lib/modules/2.6.27-7-generic/build M=/home/gaurav/Programs modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.27-7-generic'
CC [M] /home/gaurav/Programs/usbmodule.o
/home/gaurav/Programs/usbmodule.c:14: warning: data definition has no type or storage class
/home/gaurav/Programs/usbmodule.c:14: warning: type defaults to ‘int’ in declaration of ‘EXPORT_SYMBOL_NOVERS’
/home/gaurav/Programs/usbmodule.c:14: warning: parameter names (without types) in function declaration
/home/gaurav/Programs/usbmodule.c:29: warning: function declaration isn’t a prototype
/home/gaurav/Programs/usbmodule.c: In function ‘print_string_init’:
/home/gaurav/Programs/usbmodule.c:53: warning: ISO C90 forbids mixed declarations and code
/home/gaurav/Programs/usbmodule.c:53: warning: unused variable ‘i’
Building modules, stage 2.
MODPOST 1 modules
LD [M] /home/gaurav/Programs/usbmodule.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-7-generic'
after inserting module error is:
insmod: error inserting 'usbmodule.ko': -1 Unknown symbol in module
TELL ME.
- 04-29-2009 #6Just Joined!
- Join Date
- Mar 2009
- Posts
- 13
Can you tell me how i can check i have library for this usb_get_dev function or not
i have library file in /lib directory. libusb-0.1.so.4
libusb-0.1.so.4.4.4
libusb.so
and in /usr/lib/
libusb-0.1.so.4
libusb-0.1.so.4.4.4
libusb.so
where will be the kernel directory?
- 04-30-2009 #7Just Joined!
- Join Date
- Mar 2009
- Posts
- 4
void init_module(){
printk("this is the module entry point");
struct usb_device newdevice;
usb_get_device(&newdevice);
}
this is wrong . u have to change like this
int [/U] init_module(){
printk("this is the module entry point");
struct usb_device newdevice;
usb_get_device(&newdevice);
return 0;
}
- 05-01-2009 #8
hi guys,
probably problem with extension u using for kernel module.
Fedora .ko
RTlinux .o
xenomai .so
i faced same problem while loading Fedora compiled module in RT.
wat os u using????
- 05-05-2009 #9Just Joined!
- Join Date
- Jun 2006
- Posts
- 29
It seems there is a problem in below line
((my_tty->driver->ops)->write)( my_tty, str,strlen(str));
struct tty_driver has no ops variable ???
check in tty_driver.h file
by commenting ((my_tty->driver->ops)->write)( my_tty, str,strlen(str)); I'm able to insmod module.


Reply With Quote
