Today I build a evironment for linux kernel development. Summary the hello module in here.
Evironment:
Ubuntu 10.04
sudo apt-get install build-essential
sudo apt-get install linux-source
sudo apt-get install kernel-package
Source code :
hello.c :
#include "linux/init.h"
#include "linux/module.h"
static int hello_init(void)
{
printk(KERN_ALERT "Hello World linux_driver_module\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbey linux_driver_module\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("tangzhankun");
Makefile :
obj-m := hello.o
KDIR = /lib/modules/$(shell uname -r)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
.PHONY:clean
clean:
rm -f *.mod.c *.mod.o *.ko *.o *.tmp_versions
Test commands :
make
insmod ./hello.ko
rmmod ./hello.ko
dmesg | tail
[ 4893.510678] Hello World linux_driver_module
[ 5120.600441] Goodbey linux_driver_module