Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my hello world driver module print anything?

I'm very new to kernel module programming and right now I'm trying to run the most basic hello world module program, however I could not get any output.

I have written the hello world program introduced in Linux Device Drivers 3rd ed and got some help from this website and this one.

hello.c

#include <linux/module.h>
#include <linux/kernel.h>

MODULE_LICENSE("GPL");

static int hello_init(void){
    printk("<1>Hello, world!\n");
    return 0;
}

static void hello_exit(void){
    printk(KERN_ALERT "Goodbye, world..\n");
}

module_init(hello_init);
module_exit(hello_exit);

The file is in /home/volkan/drive directory. Along with the c file, I have my Makefile

Makefile

obj-m += hello.o

From the terminal, I execute this command for compiling the module:

sudo make -C /lib/modules/3.8.0-19-generic/build M=/home/volkan/drive/ modules

Resulting in:

make: Entering directory `/usr/src/linux-headers-3.8.0-19-generic'
  CC [M]  /home/volkan/drive/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/volkan/drive/hello.mod.o
  LD [M]  /home/volkan/drive/hello.ko
make: Leaving directory `/usr/src/linux-headers-3.8.0-19-generic'

I assume up to this point, nothing went wrong. Now, I insert my module and then remove:

volkan@Varaquilex ~/drive $ sudo insmod ./hello.ko
volkan@Varaquilex ~/drive $ sudo rmmod hello
volkan@Varaquilex ~/drive $ 

There is no output. I also have little experience in linux, so explanatory answers are more than welcome. Am I doing something wrong? Why cannot I see any output?

like image 230
Varaquilex Avatar asked Dec 09 '13 16:12

Varaquilex


1 Answers

The kernel messages are logged in the kern.log file located in /var/log. Depending on your system, it may also be in dmesg. So you have to cat accordingly.

Use the command cat /var/log/kern.log

Dec  9 18:51:10 Varaquilex kernel: [ 2818.079572] <1>Hello, world!
Dec  9 18:55:02 Varaquilex kernel: [ 3050.256134] Goodbye, world..
like image 185
Varaquilex Avatar answered Nov 08 '22 12:11

Varaquilex