Last update: 2015.03.11 (Mi) 12:15:02 (UTC +0100 CET)
This is a way to learn how to write/programm device drivers for the Linux Kernel. The primary goal is to learn to use the available API (3.7.x or newer) and the pertinent concepts and write correct code and document it, in order to reduce the learning curve. Optimizations may be included/use if appropriate. Correctness comes first.
This is a working in progress, and therefore bugs/errors may be found. Suggestions, critiques, contributions are welcome. :)
Before starting, it is import to have already experience with C programming. C is the Linux Kernel "Lingua Franca". Almost 97% the source code is written C and a small part in Assembly. A good knowledge about hardware standards and how it works is strongly recommended, specially for device drivers, as well the operating system theory and concetps.
The Linux Kernel coding style is followed. You can find it here:
The Linux Stable tree is used in this project. Here is how to get the code:
mkdir ~/src
cd ~/src
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.gitI suggest to use a tagged version instead of the master tree, because you know where you are working on.
cd linux-stable
git co v3.14
One can replace the tag (in this case v3.14) by any other one. Then I suggest to make a symbolic link to your git tree. It makes your life easier if you need to change to other trees and one keeps a conssitent name:
cd ~/src
ln -s linux-stable linux
On the llkdd wiki there is a howto to compile and install the Linux kernel on the X86_64 archtecture.
The default path for the current Kernel source code points to $HOME/src/linux.
Put the kernel source code in this direcory or create a symlink to it. The next
step is change to one of the driver's directory and then execute make:
cd helloworld
makeand the corresponding device driver will be compiled.
To use the compiled driver:
sudo insmod drivername.koAnd it is loaded in memory. To remove it just type:
sudo rmmod drivername.koIn order to see the driver's messages in the kernel execute in a terminal:
journalctl -f _TRANSPORT=kernelif you use systemd or:
tail -f /var/log/kern.logif you use syslog-ng.
Copy the udev rules file, as root, to the udev configuration directory:
sudo cp -v 10-llkdd.rules /etc/udev/rules.dand update the udev configuration by running:
sudo udevadm control --reload-rulesHere is a short summary about the current drivers beeing developed and its status.
| driver | code | documentation |
|---|---|---|
| helloworld | 100% | 100% |
| one | 100% | 100% |
| intn | 100% | 50% |
| intn2 | 100% | 10% |
| procfs | 100% | 0% |
| usbstick | 20% | 0% |
| keylogger | 60% | 10% |
The code status columns means how many of the planned features were implemented, it does not mean the code has no bugs !
See more infos at the project wiki page.