Posts

Showing posts from December, 2015
Basic Steps to registering character device driver 1) Create the object of structure named as dev_t which contains two things as major number and minor number. 2) Call function alloc_chardev_region() which is use to create device file by allocating major number and minor number implicitely. 3) If we call this function then there is no need to create device file explicitely. 4) At the time of removing device driver we have to call unregister_chardev_region() function. 5) Compile that driver and insert into kernel using insmod command. 6) We can check the list of devices which are loaded currently by the kernel by opening the file /proc/devices. 7) Major number and minor number gets display in our log file as /var/log/syslog. -------------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
KERNEL MODULE PROGRAMS:- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Program No. : 1 -------------------------------------------------------------------------------------------------------------------------- // hello-1.c ------------------------------------------------------------------------------------------------------------------------- // This header file is require for all kernel module. #include<linux/module.h> // This header file is require for KERN_INFO macro. #include<linux/kernel.h> // This function gets called automatically when module gets loaded by insmod command // This function returns 0 if it successfully executed otherwise it returns non zero value int init_module(void) { printk(KERN_INFO "Jay ShreeKrishna: module inserted 1\n"); return 0; } // This function gets called automatically when module gets removed from memor

Library Development in Linux

1) Library is a set of functions which are used by another executable files. 2) Library are consider as dependable executable, which is not directly run because we have to need some executable files for linking purpose. 3) According to the linking there are two types of library:-    i)  Static link library.    ii) Dynamic link library.   -------------------------------------------------------------------------------------------------------------------------- 1) Static Link Library in Linux:-     i) This type of library gets link to executable at compile time.       ii) Contents of this library are attach with the executable file permanently due to which a size of              executable file get increase permanently.       iii) In case of static library same library can be loaded multiple times in memory due to which                   there is an memory wastage.       iv) The extension of static link library is generally " .a " . --------

Writing the first kernel module

Steps to create user defined kernel module...... 1) Before writing any kernel module we have to check whether require header files such as kernel.h, init.h and module.h are available with our kernel source code or not. If it is not available in our kernel module then we have to download by using...  i) In Ubuntu:-                        sudo apt-get install build-essential linux-headers-$(uname -r).  ii) In Linux:-                        main menu-->system setting-->administration-->add/remove application/software. 2) Create new folder in desktop and create two new file in that folder. One file having extention .c which contains the source code of our kernel module and other file is Makefile which is build our kernel module. Both this file is reside in our same folder. 3) Write the source code of kernel module in .c file. 4) Write a command to build our kernel module in our Makefile. 5) Run " make " utility which is use to run Makefile. If there is err