#include
#include
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello,world tapas\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Good Bye,cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
and the corresponding make file for this is
obj-m+=hello.o
all:
make -C /lib/modules/$(uname -r)/build/M=$(PWD) modules
clean:
make -C /lib/modules/$(uname -r)/build/M=$(PWD) clean
clean-files:=Module.symvers
and to compile
make -C /lib/modules/`uname -r`/build/ M=`pwd`
thats it.
I got following output
tapas@tapas-laptop:~/LKP/pandora/temp$ make -C /lib/modules/`uname -r`/build/ M=`pwd`
make: Entering directory `/usr/src/linux-headers-2.6.28-11-generic'
LD /home/tapas/LKP/pandora/temp/built-in.o
CC [M] /home/tapas/LKP/pandora/temp/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/tapas/LKP/pandora/temp/hello.mod.o
LD [M] /home/tapas/LKP/pandora/temp/hello.ko
make: Leaving directory `/usr/src/linux-headers-2.6.28-11-generic'
Now you can see it
log in as root
dmesg -c > /dev/null
sudo insmod hello.ko
then
dmesg
and following output
sudo dmesg
[ 6134.945901] Good Bye,cruel world
[ 6158.783790] Hello,world tapas
No comments:
Post a Comment