BeagleBone Tutorial: How to compile kernel modules and “hello world” on the BeagleBone
This tutorial shows the commands to compile and install the “hello world” of kernel module compilation using the stock Angstrom distribution that comes on the BeagleBone.
This only requires a few opkg commands. I didn’t see this anywhere on the newsgroups or forums…no idea why.
References
Linux Device Drivers, Third Edition (Chapter 2)
Introduction to Linux Kernel Programming, Lesson 4, Configuring and building your first kernel
Get to the latest version of everything
~# opkg update
~# opkg upgrade
Update refreshes the package list. Upgrade upgrades all packages to the latest versions, including the kernel.
Get the kernel source files and make stuff
~# opkg install kernel-headers
~# opkg install kernel-dev
If you screw something up later on, you can do a
~# opkg install kernel-headers —force-reinstall
~# opkg install kernel-dev —force-reinstall
The kernel source is now in /usr/src/kernel. I don’t know if it’s all there…but it’ll compile modules.
~# cd /usr/src/kernel
/usr/src/kernel# make scripts
“make scripts” compiles a few things used for the kernel module building.
Compile hello.c kernel module
/usr/src/kernel# cd test
/usr/src/kernel/test# make CROSS_COMPILE=”“
The ‘CROSS_COMPILE=”“’ is needed since it’s a native build.
You’ll get an error like this:
make: *** /lib/modules/3.2.28/build: No such file or directory. Stop.
Make this path a symbolic link to the kernel source directory with
ln -s /usr/src/kernel /lib/modules/3.2.28/build
Now, make the test again
/usr/src/kernel/test# make CROSS_COMPILE=”“
and install your first compiled kernel module
insmod kernel.ko
WOOOHOO!
Oh…wait…where’s the message that’s it’s supposed to print? Check the kernel messages…
/usr/src/kernel/test# dmesg
…
[ 6376.390960] Hello, world
WOOOOOOOOOHOOOOOOOOO!
Happy kernel module writing (if there is such a thing)! :D
I have written a full kernel module, interrupts and all, using only this source.
