How to build a Kernel and load kernel modules -Kaushik Kanetkar
1-New linux kernel of Ubuntu flavor
The way you got a kernel of Ubuntu flavor on the BeagleXm in Lab0 , same way you have to get another new kernel using this document :- > http://ecee.colorado.edu/~ecen5623/ecen/labs/Linux/BeagleUbuntu_Kaushik.pdf
The URL which you used (ynazz.ibawizard…) , you can use this one now http://ynezz.ibawizard.net/beagleboard/oneiric/ and then type in whichever version you want. I have ubuntu-11.10-r5-minimal-armel.tar.xz. – my kernel version being 3.2.23-x14
Get all the packages on it as we did in Lab0. Do a uname –r and note the kernel version.
When you see /usr/src , there will not be any file over there right now. Also, you might see /lib/modules/`uname –r`/build but its not a folder. So delete the ‘build’ present over there and do a ‘mkdir build’
2-Getting the headers
Your next job is to get the kernel headers. Go to http://www.rcn-ee.net/deb/oneiric-armel/v3.2.23-x14/
You will find the linux-headers over there. Do a wget of the link of headers on your beagle itself. wget http://www.rcn-ee.net/deb/oneiric-armel/v3.2.23-x14/linux-headers- 3.2.23-x14_1.0oneiric_armel.deb
You will get a .deb file.
To install this package, run the following. dpkg --install linux-headers-3.2.23-x14_1.0oneiric_armel.deb
Once this is done, now you can see the headers appearing inside /usr/src
We will now create a symlink using the following command. ln –s /usr/src/linux-headers-3.2.23-x14 /lib/modules/`uname –r`/build
^^(this name of linux-headers may not be the exact same as I have written here so please check in your system)
In your /home/ubuntu folder, you need to have two files hello.c and Makefile which I have provided.
Run a “make” over there now.
You will see some errors stating….
“ from include/linux/jiffies.h:8, from include/linux/ktime.h:25, from include/linux/timer.h:5, from include/linux/workqueue.h:8, from include/linux/kmod.h:26, from include/linux/module.h:13”
If you have got these errors, then no worries, you are on the right track
3-Getting the patches and kernel source (The fun part)
Be in /home right now.
Go to http://www.rcn-ee.net/deb/oneiric-armel/v3.2.23-x14/
You will find the patch-*.diff.gz Do a wget on it.
You will also find “defconfig” over there. Do a wget on it too.
Go to http://www.kernel.org/pub/linux/kernel/ Locate your kernel with respect to the “’uname –r”
Mine was here. http://www.kernel.org/pub/linux/kernel/v3.x/ This one: linux-3.2.23.tar.bz2
So, do a wget http://www.kernel.org/pub/linux/kernel/v3.x/linux- 3.2.23.tar.bz2
Go inside the /lib/modules/`uname –r`/build folder.
You have to untar the kernel source over here. tar –xvf /path-to-source.tar.bz2 -> Source is linux-3.2.23.tar.bz2 cd linux-3.2.23 zcat /home/patch-*.diff.gz | patch –p1 cp /home/defcong .config
Symlink it again. ln –s /usr/src/linux-headers-3.2.23-x14 /lib/modules/`uname –r`/build/linux- 3.2.23
In the Makefile inside the /home/ubuntu folder, change the $(KERNELDIR) to the following
/lib/modules/`uname –r`/build/linux-3.2.23
Go inside the /lib/modules/`uname –r`/build/linux-3.2.23 and now run make oldconfig && make prepare
4-Getting the .ko file and loading the driver
Now do a “make” inside the /home/ubuntu.
You will now get a hello.ko.
(It does pop up a warning saying: missing Module.symvers, so right don’t worry about that)
Next step is placing our hello.ko module inside the kernel.
Do the following. cp hello.ko /lib/modules/`uname –r`/kernel/drivers/input/joystick/
^^I had tested it over here, hence this driver path.
Now run, depmod
Do a reboot of the beagleXm.
When the system boots up, be a sudo su and again run depmod.
Followed by, modprobe –f hello
If there wasn’t any error and it went onto the next line, you can check for the printk at tail –f /var/log/syslog
You will see something like “init_module()”
Run, rmmod hello
Now, check tail –f /var/log/syslog and you will see something like “cleanup_module”