Recently I bought a 7" eGalax touchscreen from eBay, and got it working by downloading a kernel from this site. However, I wanted to have a go at compiling this kernel from newer source by myself.
I found a lot of information out there on cross compiling the kernel for the raspberry pi, but I couldn't find a single set of idiot-proof instructions that I could get to work. This article is for my own reference, and includes text from lots of other places (links at bottom).
To run this I downloaded Ubuntu 12.10 which I burnt to a CD. This creates a bootable live Ubuntu or gives the option to install. So I got an old hard disk, and put it into one of my PC's, booted up from the CD and installed Ubuntu on the disk.
First, install the package dependencies, git and the cross-compilation toolchain:
sudo apt-get install git-core gcc-4.6-arm-linux-gnueabi
sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-4.6 /usr/bin/arm-linux-gnueabi-gcc
Next you need to get the source code for the pi kernel, and some tools. There are two ways to get this, either via git, which I couldn't seem to use because of my slow internet connection, or otherwise by downloading an archive
git clone https://github.com/raspberrypi/tools.git
git clone https://github.com/raspberrypi/linux.git
by archive download
then extract the archives (tar -zxvf filename) and rename the linux-* source directory so it is called linux, and the master-tools to be called tools.
Next you need to generate a .config file. (cd into the linux dir)
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_defconfig
(you can substitute bcmrpi_cutdown_defconfig for bcmrpi_defconfig to create a smaller kernel, if you care.)
To make changes to the configuration, I had to run make menuconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
(I had to install the curses lib to get the menu working sudo apt-get install libncurses5-dev)
From this I had to select Device Drivers->Input Device Support->TouchScreens. Select (press space bar) so that Touchscreens has a * beside it, and once you've done that press enter for a further submenu. In this menu you need to select USB touchscreen Driver which contains the driver for the eGalax touchscreen as one of its sub-components. NOTE: there may be other eGalax entries in the list above this that you do not have to select (don't select eGalax multitouch).
Once these selections are made just keep pressing ESC-ESC to get out (or select exit from the bottom) and when you get to the yes/no prompt, select yes to save the config.
Now we are ready to start the build. You can speed up the compilation process by enabling parallel make with the -j flag. The recommended use is ‘processor cores + 1', e.g. 3 if you have a dual core processor:
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k -j3
This takes about 20 minutes on my PC (dell 755)
Assuming the compilation was sucessful, create a directory for the modules:
Then compile and ‘install’ the loadable modules to the temp directory:
make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
Now we need to use imagetool-uncompressed.py from the tools repo to get the kernel ready for the Pi.
This creates a kernel.img in the current directory. Plug in the SD card of the existing Debian image that you wish to install the new kernel on. Delete the existing kernel.img and replace it with the new one, substituting “boot-partition-uuid” with the identifier of the partion as it is mounted in Ubuntu.
sudo rm /media/boot-partition-uuid/kernel.img
sudo mv kernel.img /media/boot-partition-uuid/
Next, remove the existing /lib/modules and lib/firmware directories, substituting “rootfs-partition-uuid” with the identifier of the root filesystem partion mounted in Ubuntu.
sudo rm -rf /media/rootfs-partition-uuid/lib/modules/
sudo rm -rf /media/rootfs-partition-uuid/lib/firmware/
Go to the destination directory of the previous make modules_install, and copy the new modules and firmware in their place:
sudo cp -a lib/modules/ /media/rootfs-partition-uuid/lib/
sudo cp -a lib/firmware/ /media/rootfs-partition-uuid/lib/
That’s it! Eject the SD card, and boot the new kernel on the Raspberry Pi!