Hello friends! I am Sagar Suman, a Software Engineer by profession and Linux enthusiast.
From today we will learn how to write Linux kernel driver one by one. First of all we will start by knowing about kernel modules. Kernel modules are part of a kernel which can be loaded/unloaded during runtime of a kernel. Most of the devices drivers today are loadable kernel module only.
Below is code of a simple hello world kernel module. We will go through the code in detail below.
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sagar Suman");
MODULE_DESCRIPTION("simple Hello world module");
static int __init hello_start(void)
{
printk(KERN_INFO "Loading the module\n");
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Exiting from the module\n");
}
module_init(hello_start);
module_exit(hello_end);