Click to See Complete Forum and Search --> : unable to register kernel module
vijays
04-17-2008, 02:07 AM
Hi,
I am using linux 2.4.20 on mips malta board.
I am trying to insmod a kernel module , and it is not giving any error.
' lsmod ' is showing the new module, but module is not in the /proc/devices file.
I am using gcc version 3.3.1 and busy box version is v0.65.5
It seems 'register_chrdev' is not working.
I am using following Sample code.
int hello_init(void)
{
int ret=0;
printk(KERN_INFO "Hello world .\n");
/* A non 0 return means init_module failed; module can't be loaded */
ret = register_chrdev(TXC_LINUX_MAJOR,TXC_LINUX_DRIVER_N AME,&txc_fops);
if (ret < 0)
{
printk("<1>Registering %s Driver Failed\n",TXC_LINUX_DRIVER_NAME);
return ret;
}
return 0;
}
void hello_exit(void)
{
int ret=0;
ret = unregister_chrdev(TXC_LINUX_MAJOR,TXC_LINUX_DRIVER _NAME);
if(ret < 0 )
{
printk("<1>De-Registering %s Driver Failed\n",TXC_LINUX_DRIVER_NAME);
}
printk("<1>%s Driver Unloaded.\n",TXC_LINUX_DRIVER_NAME);
printk(KERN_INFO "Goodbye world .\n");
}
Also I am unable to see printk message on the console, and looked up into
/var/log/ I found this folder empty. it seems that print is not enabled in the
kernel image so ho it can be enabled.
Thanks in advance to help me out.
Regards,
Vijay
bwkaz
04-17-2008, 07:09 PM
If you don't see the printk message on the console, does this device have dmesg installed? (It should, but you never know.) Running that should print the entire kernel ring buffer, including the printk calls that your module is making.
As far as /proc/devices, is your test module using the same major number as any other device in your kernel? There might be something extra you have to do before you get listed in /proc/devices as well, I don't think I ever looked into that in such an old kernel. (;)) Whether the register_chrdev is working or not, you should be able to get some info from dmesg. :)
vijays
04-22-2008, 03:10 AM
Thanks For reply,
I could not find /var/log/dmesg? How i can get / enable it.
I find that klogd and syslogd services are not enabled. How these can be enabled?
[Is it through 'make menuconfig'].
Also i tried with TXC_LINUX_MAJOR = 0. But no result.
------ Complete module code -------
MODULE_LICENSE("Dual BSD/GPL");
#define TXC_LINUX_MAJOR 0 // also tried with the different unused numbers
#define TXC_LINUX_DRIVER_NAME "txcHello"
int hello_init(void)
{
int ret=0;
printk(KERN_INFO "Hello world .\n");
ret = register_chrdev(TXC_LINUX_MAJOR,TXC_LINUX_DRIVER_N AME,&txc_fops);
if (ret < 0)
{
printk("<1>Registering %s Driver Failed\n",TXC_LINUX_DRIVER_NAME);
return ret;
}
return 0;
}
void hello_exit(void)
{
int ret=0;
ret = unregister_chrdev(TXC_LINUX_MAJOR,TXC_LINUX_DRIVER _NAME);
if(ret < 0 )
{
printk("<1>De-Registering %s Driver Failed\n",TXC_LINUX_DRIVER_NAME);
}
printk("<1>%s Driver Unloaded.\n",TXC_LINUX_DRIVER_NAME);
printk(KERN_INFO "Goodbye world .\n");
}
module_init(hello_init);
module_exit(hello_exit);
-------------
'lsmod' lists this module in the loaded module list.
loadable module support is enabled in the kernel image. Using NFS.
Any additional option do I need to be enable for 'kernel module' support?
What else is supposed to do to list in the /dev/devices..
''If register_chrdev() is successful then it will be listed in /dev/devices...''
Can this statement be considered right..
Thanks,
Vijay
bwkaz
04-22-2008, 06:57 PM
I could not find /var/log/dmesg? Right, you couldn't find it. That's because it's not a file. It's a program; run it directly. :)
I find that klogd and syslogd services are not enabled. How these can be enabled? If you run the dmesg program to print the buffer, then you don't need either klogd or syslogd. (But the method to use to turn them on will depend on the distro that you're using on this device.)
[Is it through 'make menuconfig']. No. klogd and syslogd are both userspace processes; menuconfig is only for the kernel configuration.
But you don't need them anyway...
Also i tried with TXC_LINUX_MAJOR = 0. But no result. Since I don't have the documentation for register_chrdev, are you allowed to pass zero for the major number? Look in the docs (or in the source for the function) to double check. But this isn't the problem yet...
[you posted tons of code here] OK, a couple things. I don't think they make any difference yet, but if you post your code again:
First, indent your code. When everything is lined up along the left margin, it's extremely hard to tell what I'm looking at.
Second, use tags (surround your code with [code] and ), so your indentation stays in your post. (The forum will also scroll your code for you if you do that, so your post doesn't end up way too long.)
Any additional option do I need to be enable for 'kernel module' support? Not if lsmod shows your module.
What else is supposed to do to list in the /dev/devices..
''If register_chrdev() is successful then it will be listed in /dev/devices...''
Can this statement be considered right.. I assume you mean /proc/devices, since that's what your original post referred to? I'm not sure what's required for that, as I use kernel 2.6, which doesn't care about it anymore. (I think the file might still be there, but it's not used for anything.) Under 2.6, udev does all device file management for you.
But again, this doesn't matter yet. Get the log messages working first, then move on to why register_chrdev doesn't do what you want it to do. :)
vijays
04-24-2008, 03:08 AM
Thanks For reply,
I could not find /var/log/dmesg? How i can get / enable it.
I find that klogd and syslogd services are not enabled. How these can be enabled?
[Is it through 'make menuconfig'].
Also i tried with TXC_LINUX_MAJOR = 0. But no result.
------ Complete module code -------
MODULE_LICENSE("Dual BSD/GPL");
#define TXC_LINUX_MAJOR 0 // also tried with the different unused numbers
#define TXC_LINUX_DRIVER_NAME "txcHello"
int hello_init(void)
{
int ret=0;
printk(KERN_INFO "Hello world .\n");
ret = register_chrdev(TXC_LINUX_MAJOR,TXC_LINUX_DRIVER_N AME,&txc_fops);
if (ret < 0)
{
printk("<1>Registering %s Driver Failed\n",TXC_LINUX_DRIVER_NAME);
return ret;
}
return 0;
}
void hello_exit(void)
{
int ret=0;
ret = unregister_chrdev(TXC_LINUX_MAJOR,TXC_LINUX_DRIVER _NAME);
if(ret < 0 )
{
printk("<1>De-Registering %s Driver Failed\n",TXC_LINUX_DRIVER_NAME);
}
printk("<1>%s Driver Unloaded.\n",TXC_LINUX_DRIVER_NAME);
printk(KERN_INFO "Goodbye world .\n");
}
module_init(hello_init);
module_exit(hello_exit);
-------------
'lsmod' lists this module in the loaded module list.
loadable module support is enabled in the kernel image. Using NFS.
Any additional option do I need to be enable for 'kernel module' support?
What else is supposed to do to list in the /dev/devices..
''If register_chrdev() is successful then it will be listed in /dev/devices...''
Can this statement be considered right..
Thanks,
Vijay
bwkaz
04-24-2008, 07:09 PM
As I tried to say in my last message, just run the dmesg program. It's not a file, it's a program that you run from the shell. That's the first step.