Monday, 29 September 2014

Linux Kernel Modules

Things to be Discussed here:

  • Kernel
  • Fundamentals about Kernel
  • What is Linux Kernel Module?
  • Use of Linux Kernel Module

Kernel:

Whenever user initiates task, system starts many processes to complete the task.But to serve various processes with limited available resources, there must be an in-charge or manager of the system, to look after.
Kernel works as that in-charge, responsible for allocating resources, memory management,process management, file system and networking.

Linux comes-up with various versions of kernel, including various experimental ones.
Let us say for example, linux version "3.16.2" is the latest kernel version. Here, "3" is the major number associated with the kernel, "16" is the minor number (which, when even implies stable version and odd implies experimental version) and "2" implies number of revisions done for that version.

Major                     Minor                   Revisions
   3                              16                             2

(Note you can always download and get updated about the latest and stable version of linux kernel from website kernel.org )


Fundamentals about Kernel:

As we all know, in order to design the brain of majority if electronics and embedded devices, we need to deal with kernel level programming. Let us look at it, in more technical terms.


                                              -----------------------------    
                                                    APPLICATION
                                              -----------------------------
                                                           SHELL
                                              -----------------------------
                                                OPERATING SYSTEM
                                              -----------------------------
                                                         KERNEL
                                              -----------------------------
                                                        HARDWARE
                                              -----------------------------

Kernel is the core/nucleous of an operating sytem, that interacts with the hardware.It is the first thing to be loaded, as soon as system boots.

As shown above, the various layers to go through an embedded device are mentioned.
In order to interact with hardware, the user needs to access the kernel space by APIs.
Using APIs, one can interact with the hardware (via kernel space) from the user space(containing application).

User enters the data in the user interpreter SHELL, which is passed to the previleged Kernel Mode, that talks to the hardware.


Linux Kernel Module:

Linux kernel has the ability to extend at runtime the set of features offered by the kernel. This means that you can add functionality to the kernel while the system is up and running. 

Each piece of code that can be loaded and unloaded into the kernel at runtime is called a module

Module extends the functionality of the kernel without the need to reboot the system. 
The Linux kernel offers support for quite a few different types (or classes) of modules, including, but not limited to, device drivers. Each module is made up of object code (not linked into a complete executable) that can be dynamically linked to the running kernel. 


Kernel Modules are used for:

Creating Device Drivers
Creating Virtual Devices
New System Calls etc.


In our next post:
  • Kernel Module Utilities
  • Device File Concept
  • Implementation with Example
  • And much more..