Reputation: 1931
my problem is, I am trying to build a driver into the kernel. I decided to test my code with a simple Hello World program. The code looks like:
#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/printk.h>
int __init my_init(void)
{
printk(KERN_ALERT "Hello world\n");
return 0;
}
device_initcall(my_init);
//subsys_initcall(my_init);
Also, cat /proc/sys/kernel/printk shows 7 4 1 7 From the .config file, I find "CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4"
I am making the file using obj-y += in the Makefile. I find that 'make' can build the module, but no printk outputs are appearing in dmesg or under /var/log/ after boot.
I am wondering if the driver is not being built at all into the kernel. Is there any way of checking that?
Thanks, D.
Upvotes: 0
Views: 2374
Reputation: 1931
I solved the problem. I found out that the printk statements were actually getting printed on the console, but got wiped out from dmesg due to the large number of other messages getting printed. I increased the size of dmesg, and now it stores the printk statements.
Upvotes: 1
Reputation: 1881
You can use
lsmod command
OR
cat /proc/modules
command to check if your driver is loaded.
Looking at your code I feel __init should be replaced with module_init or __initcall. These kernel signatures ensure that the module init is called at insertion time.
You can test your driver by using insmod and check if it logs the message by calling dmesg.
Upvotes: 1