BBB Kernel Modules
Here you'll find information on kernel modules, i.e. the device drivers that extends the kernel so it will be able to handle specific hardware.
First you'll need to download a few things before starting to develop kernel modules.
$] apt-get update $] apt-cache search linux-headers-$(uname -r)
will update your local copy of the content on the remote repositories and then search through for the linux-headers.
Expect an output something like:
linux-headers-3.8.13-bone70 - Linux kernel headers for 3.8.13-bone70 on armhf
$] apt-get install linux-headers-$(uname -r) Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: linux-headers-3.8.13-bone70 0 upgraded, 1 newly installed, 0 to remove and 161 not upgraded. Need to get 8430 kB of archives. ...
will install these development files on your BBB.
If you look into /usr/src/linux-headers-3.8.13-bone70 you'll find a Makefile. This is the main makefile for the kernel development. This is the one being use by the scull examples.
Add a user
If you havn't added yourself as a user do that now. You can develop and compile the kernel modules as an ordinary user. And this is the preferable way.
$] useradd -d /home/<desired login name> -m -s `which bash` <desired login name> $] passwd <desired login name> #enter your desired password twice $] groupadd moduledev $] usermod <desired login name> -G moduledev $] mkdir -p /home/emb $] chown <desired login name>:moduledev /home/emb
The first line adds the new user, the second forces a password on that account and the third adds a development group to use for development and finaly the login name just created is added to the moduledev group. Then we create a work directory to develop modules in - /home/emb and assigns it to the moduledev group and <desired login name> as the owner.
Login as this new user now.
The Linux Device Driver book examples
Along with the book "Linux Device Drivers" came a bunch of example drivers - the scull drivers.
So get a copy of the drivers to /home/emb - do use you own login name now!
$] cd /home/emb $] git clone https://github.com/martinezjavier/ldd3.git
thanks to Javier Martinez Canillas, most of the drivers has been fixed so that they will compile in relatively resent kernels.
Change the group ownership if you expect more persons to use this directory, for instance when working on a shared server.
$]chgrp -R moduledev examples
Enter the Linux Device Driver directory
$] cd ldd3
Working with the example drivers
First create a little helper script in the examples directory. The script will setup an environment variable KERNELDIR, needed to locate the kernel development directory
#!/bin/bash # # Preparation for the compilation of the scull example code # KERNELDIR=/usr/src/linux-headers-`uname -r`/ export KERNELDIR
Make it executable
$] chmod +x settings.sh
Every time you enter this directory execute this
$] . settings.sh
NOTE the . is the same as writing source
If you forget to set this environment variable it won't work as expected.
Compile the driver. (You may first have to cd into the specific drivers directory. In the example below it is the scull driver.)
$] cd scull $] make modules
If no errors you have SUCCESS.
Now try to insert the module into the kernel and remove it again. Do as the book instruct you to do.