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

Viewed 1946

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?

1 Answers
Related