Ref:
http://www.tldp.org/LDP/lkmpg/2.6/html/x121.html
1. Coding program : hello1.c
/*
* hello1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world - GW1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world - GW1.\n");
}
2. Coding program : Makefile
obj-m += hello1.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
3. Fixed try
$make
$insmod hello1.ko
$rmmod hello1
$dmesg