Skip to main content

Posts

Showing posts from January, 2014

How to write Linux Kernel Modules

1) hello_driver.c program which conatins the init and exit functions /* This is my first driver module program */ #include<linux/init.h> #include<linux/module.h> #include<linux/kernel.h> static int __init hello_init(void) {         printk(KERN_ALERT "Hello my first module \n");         return 0; } static void __exit hello_exit(void) {         printk(KERN_ALERT "Good Bye \n"); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Hello world Module"); MODULE_AUTHOR("SURENDRA PATIL"); 2) Make file for the module ifneq ($(KERNELRELEASE),)         obj-m := hello_driver.o else         KDIR ?= /lib/modules/$(shell uname -r)/build         PWD :=$(shell pwd) default:         $(MAKE) -C $(KDIR) M=$(PWD) endif Note:Both file should be in the same directory. 3) when this make file is run hello_driver.ko will be produced.   4) insmod ./hello_driv