BBB Developing Device Drivers
This section is inspired by Derek Molloy's fine writing about device driver development.
I downloaded the 2015-03-01 image and ran it from the SD card. See BBB New Debian Image. It is important that you use the correct version of the headers. I, for instance, upgraded the kernel on the stock distribution and as a consequence I couldn't find the correct headers. Hence the installation on a SD card with a up to date image.
Then follow these instructions:
First download the header files that will enable you to develop a device driver.
]$ apt-get update ]$ apt-cache search linux-headers-`uname -r`
NOTE: Do remember to use the correct "reverse"-ping ` which mean that the output of the command enclosed in ` and ` will replace the `uname -r`. Alternatively use the notation $(uname -r)
Provided you get a sensible result in the search continue with
]$ apt-get install linux-headers-3.8.13-bone70
Now you are ready for developing device drivers directly on the BBB. If you would like to perform cross development the header files shall be installed on your development PC by downloading the files from a repository somewhere on the Internet. See Derek Molloy's blog post for further details.
I've developed a very simple device driver, a test program and a build script. Download File:Example.tar to your BBB in a suitable directory, e.g. /root/basic-drv/ and unpack it.
Execute the build.sh script
Expect an output like shown below:
root@beaglebone:~/basic-drv# ./build.sh Cleaning everything before testing rm -rf *.mod.* *.o *.ko .basic* ./.tmp* test-drv Module.markers Module.symvers Making the kernel module make -C /lib/modules/3.8.13-bone70/build SUBDIRS=/root/basic-drv modules make: Entering directory `/usr/src/linux-headers-3.8.13-bone70' CC [M] /root/basic-drv/basic-drv.o Building modules, stage 2. MODPOST 1 modules CC /root/basic-drv/basic-drv.mod.o LD [M] /root/basic-drv/basic-drv.ko make: Leaving directory `/usr/src/linux-headers-3.8.13-bone70' Making the test program gcc -o test-drv test-drv.c Inserting the module into the kernel Running the test program. Watch for 0x00 Value : 0x00 Removing the module from the kernel again Showing you the last ten lines of the messages log May 2 09:20:22 beaglebone kernel: [ 7034.531259] Writing... May 2 09:20:22 beaglebone kernel: [ 7034.531273] Reading... May 2 09:20:22 beaglebone kernel: [ 7034.532301] Device closed May 2 09:20:22 beaglebone kernel: [ 7034.574910] Module basic-drv ended... May 2 09:30:50 beaglebone kernel: [ 7662.721965] Module basic-drv started... May 2 09:30:50 beaglebone kernel: [ 7662.771044] Device open May 2 09:30:50 beaglebone kernel: [ 7662.771089] Writing... May 2 09:30:50 beaglebone kernel: [ 7662.771106] Reading... May 2 09:30:50 beaglebone kernel: [ 7662.772247] Device closed May 2 09:30:50 beaglebone kernel: [ 7662.815822] Module basic-drv ended... root@beaglebone:~/basic-drv#
Dive into the basic-drv.c code and understand what is happening. Also look at the test-drv.c code.
Continue with Derek Molloy's fine blog posts on device driver development. There are four blog posts in all.