Writing device drivers in Linux: A brief tutorial

A quick and easy intro to writing device drivers for Linux like a true kernel developer!

Download the whole article as PDF

Short URL: http://fsmsh.com/1238

Write a full post in response to this!


“Do you pine for the nice days of Minix-1.1, when men were men and wrote their own device drivers?” Linus Torvalds

Pre-requisites

In order to develop Linux device drivers, it is necessary to have an understanding of the following:

  • C programming. Some in-depth knowledge of C programming is needed, like pointer usage, bit manipulating functions, etc.
  • Microprocessor programming. It is necessary to know how microcomputers work internally: memory addressing, interrupts, etc. All of these concepts should be familiar to an assembler programmer.

There are several different devices in Linux. For simplicity, this brief tutorial will only cover type char devices loaded as modules. Kernel 2.6.x will be used (in particular, kernel 2.6.8 under Debian Sarge, which is now Debian Stable).

User space and kernel space

When you write device drivers, it’s important to make the distinction between “user space” and “kernel space”.

  • Kernel space. Linux (which is a kernel) manages the machine’s hardware in a simple and efficient manner, offering the user a simple and uniform programming interface. In the same way, the kernel, and in particular its device drivers, form a bridge or interface between the end-user/programmer and the hardware. Any subroutines or functions forming part of the kernel (modules and device drivers, for example) are considered to be part of kernel space.
  • User space. End-user programs, like the UNIX shell or other GUI based applications (kpresenter for example), are part of the user space. Obviously, these applications need to interact with the system’s hardware . However, they don’t do so directly, but through the kernel supported functions.

All of this is shown in figure 1.

Figure 1: User space where applications reside, and kernel space where modules or device drivers reside
Figure 1: User space where applications reside, and kernel space where modules or device drivers reside

Interfacing functions between user space and kernel space

The kernel offers several subroutines or functions in user space, which allow the end-user application programmer to interact with the hardware. Usually, in UNIX or Linux systems, this dialogue is performed through functions or subroutines in order to read and write files. The reason for this is that in Unix devices are seen, from the point of view of the user, as files.

On the other hand, in kernel space Linux also offers several functions or subroutines to perform the low level interactions directly with the hardware, and allow the transfer of information from kernel to user space.

Usually, for each function in user space (allowing the use of devices or files), there exists an equivalent in kernel space (allowing the transfer of information from the kernel to the user and vice-versa). This is shown in Table 1, which is, at this point, empty. It will be filled when the different device drivers concepts are introduced.

Events User functions Kernel functions
Load module
Open device
Read device
Write device
Close device
Remove module

Table 1. Device driver events and their associated interfacing functions in kernel space and user space.

Interfacing functions between kernel space and the hardware device

There are also functions in kernel space which control the device or exchange information between the kernel and the hardware. Table 2 illustrates these concepts. This table will also be filled as the concepts are introduced.

Don't miss out on the other pages!
123456789next ›last »

Write a full post in response to this!

2

Do you like this post?
Vote for it!

Copyright information

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at http://www.gnu.org/copyleft/fdl.html.

Biography

Xavier Calbet: Xavier Calbet (xcalbet AT googlemail DOT com) is a long time free software user who started using Linux distributions in the ancient times when Slackware had to be installed using tens of floppy disks. He is currently working on his two pet projects: a meteorological field and satellite image display system, SAPO, and the best available free numerical computer language to date, PDL (Perl Data Language).

circulus's picture

Great,

Submitted by circulus on Thu, 2006-04-27 11:03.

Vote!
0

Very nice well written, this nice step by step tutorial is exactly for me.

---
"... Nothing Runs Like A Python ..."

Anonymous visitor's picture

Excellent job

Submitted by Anonymous visitor on Wed, 2006-10-04 11:31.

Vote!
0

Thanks for the Excellent job of making LINUX drivers easy to understand in a very very short time.

deepak george's picture

Great................

Submitted by deepak george (not verified) on Thu, 2007-09-13 09:50.

Vote!
0

Great................

Anonymous visitor's picture

Thank you

Submitted by Anonymous visitor on Mon, 2006-08-14 20:13.

Vote!
0

Great tutorial!

Anonymous visitor's picture

Amazing

Submitted by Anonymous visitor on Wed, 2006-08-16 13:10.

Vote!
0

I am amazed!! How have you managed to get this thing so simple? A real good job.

Sundip Sharma

Anonymous visitor's picture

WOW !!!!!! simply fantastic work

Submitted by Anonymous visitor on Wed, 2006-08-30 08:12.

Vote!
0

Thanks
a great article with ample scope of learning the skeleton of linux device drivers and the commonly used functions in them.........so simple and presented in quite an interesting way, so never lets u feel bored.
great work

Anonymous visitor's picture

Great simple tutorial

Submitted by Anonymous visitor on Thu, 2006-08-31 00:29.

Vote!
0

After kernel 2.4 the kernel compilation and adding up of modules has changed drastically. This tutorial helped me compile and insert my module. Thanks. Effort whole heartedly appreciated.

Kabeer Ahmed.

Anonymous visitor's picture

WOW!!!!!!!!!!!1 Great.....

Submitted by Anonymous visitor on Thu, 2006-08-31 17:30.

Vote!
0

A great article with ample scope of learning with
nice step by step procedure..

Thank's
Prakash.

Anonymous visitor's picture

Its a good

Submitted by Anonymous visitor on Fri, 2006-09-08 12:40.

Vote!
0

Its a good information.

Regards, Rajesh

Anonymous visitor's picture

No word's to say

Submitted by Anonymous visitor on Sun, 2006-09-17 17:37.

Vote!
0

Great Work !!!

Anonymous visitor's picture

Linux is not an OS

Submitted by Anonymous visitor on Fri, 2006-09-22 11:41.

Vote!
0

"Linux's kernel" has no sense, because Linux is a kernel

Vishwanatha K's picture

Query on reading from the device

Submitted by Vishwanatha K on Fri, 2006-09-29 10:16.

Vote!
0

Hi All,

I actually tried memory.ko as below:

$echo -n abcdef > /dev/memory

$cat /dev/memory
f
But I've got only the last written character i.e., 'f'.

I changed the code so that the buffer can hold upto 10 bytes (by giving 10 as a parameter to kmalloc and read,write calls) but still I'm getting the last input character. Can any one post teh answer here...

--
Regards,
Vishwa

bzamora's picture

Character driver...

Submitted by bzamora on Tue, 2008-01-08 23:32.

Vote!
0

Hi Vishwa,

On page 4 of the tutorial, where the author shows the mknod command, he states that the c identifies this driver as a character driver. My guess is that is the reason that you only see the last letter. I believe character drivers will only allow you to receive the most recent character that was written... ie the 'f'.

Anonymous visitor's picture

A really Helpful link

Submitted by Anonymous visitor on Tue, 2006-10-03 10:08.

Vote!
0

A really good and Helpful link for newbies!!!!

jadhav_raghav's picture

To start my career as programmer in device drivers

Submitted by jadhav_raghav on Thu, 2006-10-12 14:48.

Vote!
0

hi,

This one is good article.
I want to learn more on this, and can u help me get more info about device drivers.

Thanks,
Raghavendra

Anonymous visitor's picture

WOW A MASTERPIECE

Submitted by Anonymous visitor on Fri, 2006-10-20 11:06.

Vote!
0

Gud work by u.A gud guide for a layman in the fiels of device drivers

Heartly appreciated

Anonymous visitor's picture

problem with driver software

Submitted by Anonymous visitor on Tue, 2006-10-31 10:23.

Vote!
0

hello sir whhen i have compiled my sorce code then i face an error that "fops size is not known " pleee send me some information to remove this error
mu email id is erabhinandan@gmail.com

Anonymous visitor's picture

Linux extra-versioning problem and another useful link

Submitted by Anonymous visitor on Tue, 2006-10-31 11:10.

Vote!
0

Thank you for your excellent tutorial!

That's true that the first step is always the more hard to achieve, and guides like this really simplify the achievement of the basic know-how necessary to get real job done.

When I first tried the tutorial I get this error when trying to insmod my module nothing.ko:
insmod: error inserting nothing.ko: -1 Invalid module format

while dmesg gave me:
nothing: version magic '2.6.17.11.061003.eramil SMP mod_unload PENTIUM4 REGPARM gcc-4.1' should be '2.6.17.11.061003.eramil SMP mod_unload PENTIUM4 REGPARM gcc-4.0'

It was that I like to add a customized extra version to my kernel compiling it, while the extra version in the source tree Makefile was still ".11".
To fix this I changed manually the Makefile, updating the extra version line with the current linux extra version, then I started to compile with make (but I control-C-ed quite soon, after the compilation of the version.h file, that you can eventually change by hand).

Then, since I compiled the kernel with gcc-4.0 and I had installed the gcc-4.1 version, I changed the gcc symlink with:
sudo ln -sf /usr/bin/gcc-4.0 /usr/bin/gcc
Now the gcc symlink (used to compile the module) points to the same version of gcc used to compile the kernel: trick done!

Another useful link:
http://www.openaddict.com/documents/lkmpg/x30.html

HTH

Cheers

Anonymous visitor's picture

Compiling with Kernel Version 2.4.20-8

Submitted by Anonymous visitor on Thu, 2006-11-02 04:54.

Vote!
0

hi,
This is Priya here. I have installed Redhat Linux verion 9 on my system. Kernel version 2.4.20-8. Could I Please know how to compile and insert the modules given in this tutorial, with the associated makefiles.Please help me. My mail id :priyasophy_1982@yahoo.com

Anonymous visitor's picture

Reply

Submitted by Anonymous visitor on Fri, 2007-01-26 15:37.

Vote!
0

Its better if you use kernel 2.6.x.x.2.Because the Linux systems now supports 2.6 kernel and the interface for 2.6 is simple and totally different than 2.4.Mention the topic on which you are working.
If I have a knowldge about that i will surely help you.Do post ur queries on prem38_kamble @rediffmail.com

Zafeer's picture

This makefile worked for me.

Submitted by Zafeer (not verified) on Thu, 2007-11-01 05:22.

Vote!
0

This makefile worked for me. I got it off another site:

obj-m += memory.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

So the only difference is you only compile memory.c, although you can just add more files after memory.o like hello.o, etc to compile hello.c
Hope this helps.

bzamora's picture

Works with CentOS 5...

Submitted by bzamora on Tue, 2008-01-08 23:25.

Vote!
0

Hi...

Thanks for this sample. This worked great with CentOS 5.

Anonymous visitor's picture

very nice work !!!!!!!!!!

Submitted by Anonymous visitor on Mon, 2006-11-06 08:35.

Vote!
0

I appreciate for the effort took for explaining device driver writing in step by step manner...

really great work...

Thank you,
Murali

Anonymous visitor's picture

thanks alot .............

Submitted by Anonymous visitor on Tue, 2006-11-14 10:50.

Vote!
0

thanks man .. .. nice tutorial

regards
SuLtAn

Anonymous visitor's picture

REALLY A GREAT HELP FOR

Submitted by Anonymous visitor on Tue, 2006-11-21 11:43.

Vote!
0

REALLY A GREAT HELP FOR STARTERS...

ARUN

Anonymous visitor's picture

Cannot unload module

Submitted by Anonymous visitor on Sat, 2006-11-25 06:31.

Vote!
0

Dear sir,

This is a very good tutorial you have here. It is very cool as it explains the fundamental really well.

I tried out the first 2 section of the tutorial but am stuck.

I have created the module nothing.ko and inserted it into the kernel.
I am able to see the module using lsmod

When I tried to rmmod, the system keeps giving me the following error:
ERROR: Removing 'nothing': Device or resource busy

My lsmod | grep nothing gives me
nothing 2688 0 [permanent]

Is there a way to unload this module

Very much appreciate your help

Thanks,
Alex

Anonymous visitor's picture

Not accurate article!

Submitted by Anonymous visitor on Sat, 2006-11-25 19:21.

Vote!
0

My comments:

To be complete tutorial it must be accurate. It is not so.

For example, memory driver part is completely hide extensions of files and creating makefile in case if you build module from multiply files.
I think it should be added directly in article or,as minimum, in comments.

Anonymous visitor's picture

d BEST

Submitted by Anonymous visitor on Tue, 2006-11-28 12:22.

Vote!
0

Thank you very much for posting such an astonish article for all..

God Bless all..

Anonymous visitor's picture

GOOD

Submitted by Anonymous visitor on Tue, 2006-11-28 13:10.

Vote!
0

Thank u for giving an easy to learn tutorial about device drivers..

U can also add some more details about functions which will be more helpful...

Anonymous visitor's picture

Very Good

Submitted by Anonymous visitor on Tue, 2006-12-05 10:01.

Vote!
0

The Tutorial help me lot

Anonymous visitor's picture

good article

Submitted by Anonymous visitor on Wed, 2006-12-20 01:47.

Vote!
0

As the title says,....
Simple to understand and grasp the important things.
Thanks a lot m8
George

Anonymous visitor's picture

NICE ONE

Submitted by Anonymous visitor on Wed, 2006-12-20 13:39.

Vote!
0

VERY NICE ARTICLE.

THANKS A LOT.
K.RAJASEKAR

Anonymous visitor's picture

good job

Submitted by Anonymous visitor on Sun, 2006-12-24 15:25.

Vote!
0

good job

Anonymous visitor's picture

Its the Best that I have come accross

Submitted by Anonymous visitor on Mon, 2006-12-25 06:52.

Vote!
0

It motivates a non-driver-writer to jump into the arena that is always thought to be only for the real techies.

Anonymous visitor's picture

Very well done

Submitted by Anonymous visitor on Tue, 2006-12-26 00:02.

Vote!
0

Really good tutorial on drivers. I challenge us to do the exercises, specifically a device that doesn't work yet.

Thanks for this important contribution!

Regards,

Anonymous visitor's picture

Help on Kernel Keyboard Driver

Submitted by Anonymous visitor on Tue, 2006-12-26 05:33.

Vote!
0

Hai everyone,

IN LINUX KERNEL VERSION-2.6.8-24 THE KEYBOARD DRIVER FILE KEYBOARD.C IS USED.I WOULD LIKE TO MODIFY THIS FILE SUCH THAT ON A TOGGLE KEY I WOULD LIKE TO READ DATA FROM A FILE.I USED SYSTEM CALLS LIKE OPEN,CLOSE,READ.BUT AN ERROR MESSAGE SAYING THAT THE HEADER FILE UNISTD.H INCLUDING THIS CALLS IS NOT AVAILABLE IS ENCOUNTERED.CAN ANY BODY HELP ME IN THIS CONTEXT.

Anonymous visitor's picture

After you've done that

Submitted by Anonymous visitor (not verified) on Fri, 2007-04-27 22:07.

Vote!
0

After you've done that you could write a driver that prevents your caps-lock key from getting stuck.

Anonymous visitor's picture

hi

Submitted by Anonymous visitor on Tue, 2007-01-02 17:12.

Vote!
0

good job done

Anonymous visitor's picture

Only bit-1 lights up after module loads

Submitted by Anonymous visitor on Fri, 2007-01-19 01:42.

Vote!
0

First off, thanks for the great tutorial, Xavier.

I am trying to complete the LED section of the tutorial. I am running Ubuntu Server 6.10, kernel 2.6.17-10, and I removed lp, parport_pc, and parport. I have successfully compiled parlelport.ko and I can verify that the module has loaded with:
$ cat /proc/ioports
..
0378-0378 : parlelport

The circuit shows many lights blinking at boot time. After boot, bit-2 and bit-3 stay lit. They remain that way until the computer is rebooted -- or until the monitor goes to sleep. All lights go black while the monitor sleeps. The only response I can generate is that bit-1 lights after inserting parlelport.ko. It stays lit until the computer is rebooted.

The only thing that looks suspicious is this:

$:~/dev$ make -C /usr/src/linux-source-2.6.17 M=`pwd` modules
make: Entering directory `/usr/src/linux-source-2.6.17'
CC [M] /home/sam/dev/parlelport.o
/home/sam/dev/parlelport.c:31: warning: initialization from incompatible pointer type
..

Line 31 corresponds to:
write: parlelport_write

But my parlelport_write() is the same as the tutorial's.

Any pointers?

Thanks,
Sam

Anonymous visitor's picture

I have more or less the same

Submitted by Anonymous visitor on Sun, 2007-02-11 12:00.

Vote!
0

I have more or less the same issue.
after booting the LED is OFF but when I remove all parport related modules, the LED gets ON and the parlelport driver does not work. If I manage to avoid parport module at boot and insmod parlelport after boot, things seems OK (I can set On or Off the LED).
I guess the parport driver when manualy unloaded (rmmod) let the chipset in a state that prevent from outputting data from the port (may in input mode in place of output mode)

I tried to force the output mode (0x37A control reg) with no success

leneth's picture

how did you remove lp, parport_pc, and parport

Submitted by leneth (not verified) on Wed, 2007-08-22 10:19.

Vote!
0

Hi!
How did you remove lp, parport_pc, and parport ? I think i need to do this becuase i will get a device or resource busy error.

Thanks,
Leneth

Anonymous visitor's picture

Very Well Explained

Submitted by Anonymous visitor on Thu, 2007-01-25 23:29.

Vote!
0

Fantastic Job. You have described the driver structure in simple and best manner.
Thanks.AJ

Anonymous visitor's picture

Damn useful !!! Well done

Submitted by Anonymous visitor on Thu, 2007-02-01 19:41.

Vote!
0

Damn useful !!! Well done buddy :-*

Anonymous visitor's picture

Good one.

Submitted by Anonymous visitor on Mon, 2007-02-05 07:18.

Vote!
0

Hello,

Really nice tutorial...it helped me a lot..Practical Egs are good..

Keep the good work going..

Anonymous visitor's picture

Excellent, Quick & Handy..,

Submitted by Anonymous visitor on Thu, 2007-02-08 07:05.

Vote!
0

This is really nice & handy tutorial.
Can this guy give similar tutorials for GCC,Shell Scripting..? It would be really good to have such tutorials..

Anonymous visitor's picture

Very Helpful!

Submitted by Anonymous visitor on Mon, 2007-02-12 22:14.

Vote!
0

A really handy overview!

Anonymous visitor's picture

write a kernel for linux

Submitted by Anonymous visitor on Sun, 2007-03-04 20:06.

Vote!
0

how we write a kernel for linux? what is code of this problem?

Anonymous visitor's picture

SIMPLE & COOL

Submitted by Anonymous visitor on Mon, 2007-03-05 10:50.

Vote!
0

The tutorial has been simple, I had no idea where to start with.
This has given me a good introduction to DD programming & kernel modules.
-Arjun

Anonymous visitor's picture

Compilation problem

Submitted by Anonymous visitor on Thu, 2007-03-08 21:58.

Vote!
0

I am using Fedora core 5. I could not compile the very first version of "nothing" with just licence line in it.

Here is what I got.

make -C /usr/src/linux/kernel M=`pwd` modules
make: Entering directory `/usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15.i686/kernel'
make: *** No rule to make target `modules'. Stop.
make: Leaving directory `/usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15.i686/kernel'

Is the procedure different for Fedora? Thanks in advance.

kirz's picture

Great

Submitted by kirz on Fri, 2007-03-16 12:42.

Vote!
0

Its really simple and informative.....

Anonymous visitor's picture

Good work

Submitted by Anonymous visitor on Fri, 2007-03-16 17:19.

Vote!
0

A really interesting tutorial. A little short but the main explanations are present.
Thanks.

KirgliZ

Anonymous visitor's picture

tutorial(device driver)

Submitted by Anonymous visitor on Thu, 2007-03-22 05:31.

Vote!
0

its really excellent....
amazing...
His presentation is too good and simple....

kirz's picture

Yeah

Submitted by kirz on Thu, 2007-03-29 11:44.

Vote!
0

Simply simple :)

Anonymous visitor's picture

Efficient work

Submitted by Anonymous visitor on Wed, 2007-04-04 05:55.

Vote!
0

Really good work.

Anonymous visitor's picture

Thank you so much!

Submitted by Anonymous visitor on Sat, 2007-04-07 04:37.

Vote!
0

You wrote so clearly and easily to understand.

Anonymous visitor's picture

great tutorial for newbies

Submitted by Anonymous visitor on Sat, 2007-04-07 07:56.

Vote!
0

This tutorial gives great confidence to develop device driver for someone who is neo in this field. Great job !!!!!!!!!!

solar_sea's picture

Great job.

Submitted by solar_sea (not verified) on Tue, 2007-04-17 18:22.

Vote!
0

I really like it and it's written in a very nice way, thanks! :)

Anonymous visitor's picture

Great Work Sir. Its truly

Submitted by Anonymous visitor (not verified) on Wed, 2007-04-18 13:07.

Vote!
0

Great Work Sir. Its truly helpful for begineers like us. We hope to have some more from you.

Anonymous visitor's picture

Pretty Good and Easy to Understand

Submitted by Anonymous visitor (not verified) on Tue, 2007-04-24 14:32.

Vote!
0

Dear sir...
its really very useful.can u elaborate the drivers on keyboard also.

Anonymous visitor's picture

Very interesting. Have never

Submitted by Anonymous visitor (not verified) on Tue, 2007-05-01 06:10.

Vote!
0

Very interesting. Have never really read much about driver development. Nice work.

gandy909's picture

Printable version?

Submitted by gandy909 (not verified) on Tue, 2007-05-01 18:15.

Vote!
0

Is there a printable version of this article? I don't find a link to one...
Thanks.

Raquel's picture

There is no such thing as

Submitted by Raquel (not verified) on Tue, 2007-05-01 19:12.

Vote!
0

There is no such thing as "quick" and "easy" when it comes to writing drivers. Thank you :)

P.S: great tutorial

Anonymous visitor's picture

Debian etch, is now the

Submitted by Anonymous visitor (not verified) on Wed, 2007-05-02 00:49.

Vote!
0

Debian etch, is now the stable release version.

Anonymous visitor's picture

Similar Tutorial for NT

Submitted by Anonymous visitor (not verified) on Thu, 2007-05-10 12:33.

Vote!
0

I can write a similar tutorial using LEDs if anyone is interested for DOS.

I am interested in Windows NT, please give us similar simple tutotrial for Windows NT device drivers.

Great Work.

Ja

Anonymous visitor's picture

Great work.

Submitted by Anonymous visitor (not verified) on Sat, 2007-06-02 14:45.

Vote!
0

I am really impressed the way author has presented this wonderful article..he has explained in such a simple and nice manner..

Great going..

so happy hacking..

Anonymous visitor's picture

Submitted by Anonymous

Submitted by Anonymous visitor (not verified) on Tue, 2007-06-12 15:45.

Vote!
0

Submitted by Anonymous visitor (not verified) on Thu, 2007-05-10 12:33.

I can write a similar tutorial using LEDs if anyone is interested for DOS.

I am interested in Windows NT, please give us similar simple tutotrial for Windows NT device drivers.

Great Work.

Danboy's picture

This is FREE SOFTWARE Magazine

Submitted by Danboy on Tue, 2007-06-12 23:31.

Vote!
0

I'm afraid that if you are interested in Windows NT you'll have to find another magazine to make your requests to. You won't be seeing any Windows NT tutorials on this site unless they tell you how to wipe it from your computer and replace it with a nice GNU/Linux replacement.

It's amazing that you are smart enough to understand this article but yet you can't work out that no one here would want to write NT tutorials.

Ulhas Dhuri's picture

Gud tutorial ,keep the good work going!

Submitted by Ulhas Dhuri (not verified) on Fri, 2007-06-29 09:19.

Vote!
0

Hi,

Its a good tutorial, I must say. You have gracefully handled this linux device driver tutorial. It would be a great benefit to newbies ,if u can come up with futher advance topics of kernel programming in your own style of writing.

Metoule's picture

French tutorial

Submitted by Metoule (not verified) on Mon, 2007-07-09 20:58.

Vote!
0

Amazing tutorial ! It made me want to develop my own driver!
For French speaking people, you can find another tutorial here: http://broux.developpez.com/articles/c/driver-c-linux/

dalex's picture

Excellent article

Submitted by dalex on Wed, 2007-07-11 14:16.

Vote!
0

I only wish there were more tutorials like that...

skypjack's picture

Tip-Top

Submitted by skypjack on Sat, 2007-07-14 08:45.

Vote!
0

I quote above comment, an excellent article!
Congratulations and ... Thanks! :-)

Jakobularius's picture

Very nice tutorial that gets you up and running quickly

Submitted by Jakobularius on Tue, 2007-07-17 06:17.

Vote!
0

The tutorial provides a nice intro to really mastering your Linux machine!

Anonymous visitor's picture

Its

Submitted by Anonymous visitor (not verified) on Tue, 2007-07-24 06:26.

Vote!
0

Its fantastic...!!!!!!!!!!!!!

prince2007's picture

HELP needed about device driver writing

Submitted by prince2007 (not verified) on Mon, 2007-07-30 01:07.

Vote!
0

hi,
this ia a excellent tutorial, i am using rhel5 2.6.18-8.el5
i like to learn this device driver programming but i am gating
error: linux/module.h: No such file or directory
so how to get this file. if i download this file will it work?
plz inform me princei007@yahoo.com

Anonymous visitor's picture

I'm having the same problem

Submitted by Anonymous visitor (not verified) on Wed, 2007-08-01 08:25.

Vote!
0

I'm having the same problem with ubuntu

Anonymous visitor's picture

Good tutorial

Submitted by Anonymous visitor (not verified) on Wed, 2007-08-08 18:16.

Vote!
0

Good job.

I have searched and read many,

Atlast I found this tutorial, its amazingly easy to get the picture of writing a driver.

thanks
by
karthi

Mohan's picture

outb is not working

Submitted by Mohan (not verified) on Tue, 2007-08-28 14:24.

Vote!
0

I wrote a small application to test the parallel port and whatever data I am writting, it is getting displayed on LED array. However when I tried to use outb from driver, it is not working. I have removed lp, parport_pc, parport modules. I put some debug messages and it is showing outb is executing properly. Even /proc/ioports is showing ports are allocated for me. I am using Fedora v6. Do you have any clue on this?

Anonymous visitor's picture

help needed

Submitted by Anonymous visitor (not verified) on Thu, 2007-09-06 07:19.

Vote!
0

Hi
help me for writng USB device driver. from where i start my work.
thanks

Anonymous visitor's picture

Good article!

Submitted by Anonymous visitor (not verified) on Tue, 2007-09-25 06:37.

Vote!
0

Good starting point for beginners. Thank you!

vonbrand's picture

Is the code available?

Submitted by vonbrand on Wed, 2007-09-26 19:58.

Vote!
0

I'm interested both in the source code (C, Makefile) and in the article itself.

Anonymous visitor's picture

i was running away from

Submitted by Anonymous visitor (not verified) on Fri, 2007-09-28 19:17.

Vote!
0

i was running away from device drivers from last 3 weeks but this tutorial made it so easy. withing 2 hrs i had the idea wat dey r nd hw to make dem work..excellent tutorial. great work.thanx a lot

Redmond's picture

How I got it working

Submitted by Redmond (not verified) on Sat, 2007-09-29 08:06.

Vote!
0

I had some trouble getting the parlelport driver working on my slackware 12 2.6.21.
The problem was that ever time I boot my machine the pin 4 led would not shut off, and
all other leds could not be turned on or off by echo or lights.o. All of this was caused by modules lp,parport,and parport_pc. The solution was to comment out the lines that load the modules in /etc/rc.d/rc.modules-[kernel version here]. There pretty hard
to miss. Add the modules to /etc/modprobe.d/blacklist did not help though I did that t and it may be part of the solution.

P.S. I love this tutorial, you wrote that it was originally written in Spanish, If English is not your first language I can't tell.

Anonymous visitor's picture

The simplest, compact

Submitted by Anonymous visitor (not verified) on Mon, 2007-10-01 10:54.

Vote!
0

The simplest, compact tutorial to anyone to jump start on the driver.

Manish A's picture

Best tutuorial

Submitted by Manish A (not verified) on Wed, 2007-10-10 22:37.

Vote!
0

This is the best tutorial I've read on the web. And I'm not speaking only of linux device driver tutorials.

Thanks!!

shekhar's picture

device driver

Submitted by shekhar (not verified) on Thu, 2007-10-18 09:12.

Vote!
0

Thx.
this article is very useful.
it helped me lot in understanding character driver.

but i have problem with assigning the more space to memory buffer.
even i icreased it to 10 from 1 i am able to get only last character,
why this is so?

anantbhasu's picture

well written

Submitted by anantbhasu (not verified) on Mon, 2007-10-22 07:47.

Vote!
0

quite a precise and well written startup material for device drivers' developers
-AB

Oliver Thane's picture

compile process

Submitted by Oliver Thane (not verified) on Fri, 2007-10-26 22:28.

Vote!
0

Thanks for the excellent tutorial. However I am stuck in the position where by I must use Kernel 2.4 for the module I am working on. The driver it self has been mostly developed and I am just debugging some glitches.

I have the problem that in order to compile the module to work on the target embedded device I must be in Kernel version 2.4.20-20. Despite my efforts my network card only works in 2.4.20-8SMP and when I compile the drive in this mode it will not run on the embedded target. The solution currently is to reboot after every build into the 2.4.20-8SMP, which is not great.

I will look into fixing the network card problem but I am quit interested in learning how to compile drivers for versions of the OS not currently running (and especially in 2.4). I cannot seem to find much on the net so if anyone knows where to look or can help it would be much appreciated.

Anonymous visitor's picture

Could someone give some

Submitted by Anonymous visitor (not verified) on Wed, 2007-10-31 21:18.

Vote!
0

Could someone give some inside or where to find detailed info on supporting/writing drivers for dual core or multiprocessor HW with under 2.6? TIA

Roya_Gh's picture

do u have a simple source code of usb or pci modules?

Submitted by Roya_Gh (not verified) on Fri, 2007-11-09 11:02.

Vote!
0

hello,
i'm a student of computer eng(hardware)and at the moment i'm working on a project which is about USB driver programming in linux.i use kernell 2.6.18(fedora core). i have run a simple module in it(i mean that famous hello module)but after that i tried to run some other modules such as pci modules but i faced with some problems...maybe the program it self has some problems...so...is there any persons here that has a source code of a simple usb or pci drivers?i would be really thankful for your attention.

Sid B's picture

Great Work!!!

Submitted by Sid B (not verified) on Mon, 2007-11-12 05:39.

Vote!
0

Its really a wonderfull piece of documentation for beginners trying to deveplop Linux device drivers.

Brett Zamora's picture

Very well written...

Submitted by Brett Zamora (not verified) on Tue, 2007-11-20 22:11.

Vote!
0

Excellent presentation. I look forward to actually building the examples.

Anonymous visitor's picture

Help

Submitted by Anonymous visitor (not verified) on Fri, 2007-11-23 14:29.

Vote!
0

I am using knoppix Live CD. And I don't know how to compile my modules in knoppix. If anyone can help I will be thankful.

Anonymous visitor's picture

Awsome!

Submitted by Anonymous visitor (not verified) on Tue, 2007-11-27 18:36.

Vote!
0

Never seen an article describing device driver writing this simple.

metacrease's picture

Excellent article!

Submitted by metacrease (not verified) on Mon, 2007-12-03 08:17.

Vote!
0

Excellent article!

sowmya.kethireddy's picture

Really nice article

Submitted by sowmya.kethireddy on Tue, 2008-01-29 08:57.

Vote!
0

hi,
I'm new to linux. I'm searching for easily understandable article. I found this. ThanQ verymuch to the author.

newto linux's picture

Problems in Ubuntu on memory and parlelport drivers

Submitted by newto linux on Thu, 2008-02-14 16:08.

Vote!
1

Hello, I am new to linux, so please forgive me.
I have been able to compile and run the first two drivers in the tutorial but once I try the multi file ones i have issues the memory drive and the parlelport driver will not compile.

The lines in brackets like this one: '<'parlelport modified init module'>' ...without the '' I just have them so the brackets will show up and not be filtered.

that refrence other files I have created like the tutorial said to do are generating the
following error:
In file included from /usr/src/parport/parlelport.c:2:
/usr/src/parport/parlelport init module: In function ‘parlelport_init’:
/usr/src/parport/parlelport init module:14: error: expected expression before ‘<’ token

I have literally copied and pasted the example code... what am I missing?

I am using UBUNTU
Thanks

admin's picture

Solution

Submitted by admin on Fri, 2008-02-15 14:30.

Vote!
0

Hi,

I _urge_ you to ask the same question in the Ubuntu Forums ( http://ubuntuforums.org/ ). They are fantastic, and will definitely help you!

Bye,

Merc.

thainam's picture

Compile these examples for ARM architecture

Submitted by thainam on Mon, 2008-08-11 11:31.

Vote!
0

Hi, thank you for your article, it's great. I compiled them and work ok on Ubuntu:
obj-m += parlelport.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

However, I installed them on Iliad tablet, it said different architecture(it bases on ARM architecture). Could you show me how to these drivers for Iliad tablet?

Once again, thank you very much.

azad's picture

driver

Submitted by azad on Thu, 2008-09-11 10:33.

Vote!
0

Hello to everybody,

I have read the script to Linux driver. I would like to know how one makes the circuit LEDs.

Many greetings

Azad

BilalMehdi's picture

Nonexistant resource 00000000378

Submitted by BilalMehdi on Fri, 2008-10-03 17:41.

Vote!
0

Hi...

I tried the parallel port driver .. but ... I am having some problems...

1. I dont see 0378 memory allocated to my module with cat /proc/ioports command. (I dont see memory location 0378 in the list)
2. I cant see the state of the port with cat /dev/parlel_port
3. When I remove my module .. I get a message in the log "Trying to free nonexistant resource 0000000378-00000000378" ... (No error message is logged during insmod)

Athough I did remove parport and parport_pc module... (I was unable to load my module without unloading these modules)

If someone knows how to fix it.. please post a reply here..

Thanx in advance

saurabhg84's picture

Procedure to unload the current parallel port driver

Submitted by saurabhg84 on Mon, 2010-02-08 10:28.

Vote!
0

Firstly, let me say...this is an awesome tutorial but the only thing missing out here is an elaborate procedure to unload the driver which is present by default on all systems having a parallel port. For some reason rmmod/modprobe did not work out here and the solution as someone has pointed out in one of the earlier comments is to modify the startup scipt to NOT load the parallel port driver at startup. In Ubuntu, I used the following steps to unload the driver during startup and now it works brilliantly:

Steps to unload paralel port driver:
1. Make the following changes in the /etc/rc1.d :
K80cups: modprobe -q lp || true
K80cups: modprobe -q ppdev || true
Uncomment the above 2 lines of the scripts
2. Make the following changes in the /etc/rc2.d :
S50cups: modprobe -q ppdev || true
S50cups: modprobe -q lp || true
Uncomment the above 2 lines of the scripts
3. Add the following lines to the file /etc/modprobe.d/blacklist.conf:
blacklist ppdev
blacklist parport_pc
blacklist parport
blacklist lp
Restart PC at this point
4. Unload the remaining modules manually using rmmod (if any)
5. Follow remaining instructions given in the tutorial
6. Load custom module (sudo insmod parlelport.ko)

Hope this helps...

Courtesy: Redmond who has posted one of the earlier comment



CariNet: Cloud computing is a reality.

Other sites

Odiogo

Free Software Magazine uses Apollo, project management and CRM for its everyday activities!