005 Character Device Drivers DevelopmentIssues, queries, suggestions or discussion related to Linux Device drivers, character device drivers, Linux based character driver and related issues.
A.To insert our driver modules we either use insmod or modprobe.
Modprobe search in lib/modules/kernel-version path.Modprobe resolve the module dependencies during module insertion, if we insert a module which is dependent on other module, their dependencies are resolved by modules.dep file present in /lib/modules and all the related modules are inserted in one go.
->create soft link of the modules you want to play with in lib/modules/kernel-version
ln -s /module-path /lib/modules/kernel-version
->depmod -a
to resolve dependencies between modules..(if dependent module is inserted using modprobe its dependency module is also inserted).Entry is created in modules.dep file for the modules and their dependencies.
->to insert use -->>modprobe mylkm
->to remove use -->modprobe -r mylkm
mylkm is module name
if remove the dependency module both rmmod or modprobe -r gives prompt module in use,and removing dependent module removes the both.
one of the important task for our char device driver is to preserve a major number and minor no. for no. of devices so our driver can interface through these numbers from kernel space to each device's app.
# These device numbers are preserved by alloc_chrdev_region( ) , which garauntees you to provide a dynamically available major no..
second , the cdev structure inside kernel is responsible for providing information regarding with character device, now as we are creating our own operational routines such as read , write, close etc. we have to tell the kernel about these file operations by means of
struct file operations fops=
{
operational routines;
}
and it's link and initialization with our character driver we are using cdev_init( ) macro .
once our structure cdev has been initialized , we can add this structure to the kernel by means of the cdev_add( )
functions . this cdev_add ( ) function adds each device minor number to the major of our character device driver.
first we take extern int some variable then we define it in the init function in which alloc_chardev_region() is used to register device and initialize it with their respective macros and use the global variable as an argument in alloc_chrdev_region() so that device file can get minor number and as far as major number is concerned it is also initalized with its macro but major number is given by kernel. Kernel give the maximum possible number to the device file which is being created through test file