Friday, February 28, 2014

Linux Device Drivers - Hello World Programme

This is my first Linux device driver program. Lets start from scratch .

Hello.c

#include <linux/init.h>    ##
#include <linux/module.h>
#include <linux/sched.h>
#include <asm/current.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}

Makefile

obj-m=hello.o
KDIR= /lib/modules/$(shell uname -r)/build
all:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
       rm -rf *.o *.ko *.mod.* .c* .t*

No comments:

Post a Comment