EmbLogic's Blog

Adding a character device driver to the system using cdev_add

Implementing cdev_add and cdev_init
RCS file: header.h,v
Working file: header.h
head: 1.4
branch:
locks: strict
raghav: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4;    selected revisions: 4
description:
This is a seperate header file where i have included all the necessary header file required for writing character
including linux/init.h and linux/module.h
—————————-
revision 1.4    locked by: raghav;
date: 2014/02/13 11:01:53;  author: raghav;  state: Exp;  lines: +33 -1
<included <linux/slab> for kalloc function to allocate memory to struct scull_dev
—————————-
revision 1.3
date: 2014/02/13 05:47:34;  author: raghav;  state: Exp;  lines: +0 -1
header file <init.h> is included to support module_init and module_exit
—————————-
revision 1.2
date: 2014/02/13 05:24:24;  author: raghav;  state: Exp;  lines: +0 -1
Included the module licence GPL to make it authorized
—————————-
revision 1.1
date: 2014/02/13 05:23:05;  author: raghav;  state: Exp;
Initial revision
=============================================================================
RCS file: entry.c,v
Working file: entry.c
head: 1.9
branch:
locks:
raghav: 1.9
access list:
symbolic names:
keyword substitution: kv
total revisions: 9;    selected revisions: 9
description:
program to insert a driver file inside our kernel
—————————-
revision 1.9    locked by: raghav;
date: 2014/02/13 11:12:56;  author: raghav;  state: Exp;  lines: +24 -14
cdev_add function is added the character device to the system
—————————-
revision 1.8
date: 2014/02/13 06:55:08;  author: raghav;  state: Exp;  lines: +8 -3
*** empty log message ***
—————————-
revision 1.7
date: 2014/02/13 05:43:43;  author: raghav;  state: Exp;  lines: +10 -15
included the alloc_chrdev_region to register the driver number and get the major and minor number using its first argument dev
Major no is allocated by kernel and minor no is allocated by driver to devices
—————————-
revision 1.6
date: 2014/02/11 12:33:38;  author: raghav;  state: Exp;  lines: +2 -2
ERROR: i was using name function name “out” for exit function
Now i changed it to outo , and now it works without showing any bug
—————————-
revision 1.5
date: 2014/02/11 12:31:14;  author: raghav;  state: Exp;  lines: +2 -1
ERROR: forget to write retern 0 in init function
—————————-
revision 1.4
date: 2014/02/11 12:27:34;  author: raghav;  state: Exp;  lines: +5 -5
creating  a seperate Makefile to execute both files init.o and exit.o
This make file is important as we can’t compile out init func seperately
—————————-
revision 1.3
date: 2014/02/11 12:17:12;  author: raghav;  state: Exp;  lines: +14 -0
using module init function to insert the file inside the kernel and exit function is used to remove the file from kernel
Make sure dont use the same function name as init and exit are built in name and already defined inside kernels else it will create a problem
—————————-
revision 1.2
date: 2014/02/11 12:12:17;  author: raghav;  state: Exp;  lines: +2 -1
Inclluding linux/module.h and linux/init.h
and including MODULE_LICENCE
—————————-
revision 1.1
date: 2014/02/11 12:10:44;  author: raghav;  state: Exp;
Initial revision
=============================================================================
RCS file: clean.c,v
Working file: clean.c
head: 1.5
branch:
locks: strict
raghav: 1.5
access list:
symbolic names:
keyword substitution: kv
total revisions: 5;    selected revisions: 5
description:
included the unregister_chrdev_region to unregister the device
to do so we need the major minor number.
which we’ll get from the first argv of alloc_chrdev_region
as i am using seperate files so , i have to use this dev_t dev as a extern in exit function
—————————-
revision 1.5    locked by: raghav;
date: 2014/02/13 11:20:48;  author: raghav;  state: Exp;  lines: +2 -0
adding kfree function to free the allocated memory of struct sculldev after removing and un registering the device
—————————-
revision 1.4
date: 2014/02/13 10:19:28;  author: raghav;  state: Exp;  lines: +1 -1
Error detected: In the second argument of unregister_chrdev_region func() we have to input only that number of drivers which we have registered.
suppose if we have register our driver for 10 devices then in the unregister fun() we have to unregister 10 devices i.e give 10 in the second argument of unregister function.
—————————-
revision 1.3
date: 2014/02/13 10:18:05;  author: raghav;  state: Exp;  lines: +6 -5
Error in un registering the driver from the driver table
—————————-
revision 1.2
date: 2014/02/13 06:09:06;  author: raghav;  state: Exp;  lines: +3 -5
included the unregister_chrdev_region to unregister the driver, but here its return type is void
—————————-
revision 1.1
date: 2014/02/13 05:58:43;  author: raghav;  state: Exp;
Initial revision
=============================================================================

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>