Wednesday, August 28, 2013

Raspberry Pi (RPi) kernel build for eGalax touchscreen support

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

mkdir raspberrypi
cd raspberrypi

by git:
git clone https://github.com/raspberrypi/tools.git
git clone https://github.com/raspberrypi/linux.git
cd linux

by archive download

wget https://github.com/raspberrypi/linux/archive/rpi-3.10.y.tar.gz
wget https://github.com/raspberrypi/tools/archive/master.tar.gz

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:

mkdir ../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.

cd ../tools/mkimage/
./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image

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:

cd ../../modules/
sudo cp -a lib/modules/ /media/rootfs-partition-uuid/lib/
sudo cp -a lib/firmware/ /media/rootfs-partition-uuid/lib/
sync

That’s it! Eject the SD card, and boot the new kernel on the Raspberry Pi!








Referenced articles:
http://elinux.org/RPi_Kernel_Compilation
http://mitchtech.net/raspberry-pi-kernel-compile/
http://www.engineering-diy.blogspot.ro/2013/01/adding-7inch-display-with-touchscreen.html

35 comments:

Devil said...

Hi Simon,

I have tried using image from Andre's blog (http://engineering-diy.blogspot.in/2013/01/adding-7inch-display-with-touchscreen.html)

but unfortunately it does not work on my raspberry pi. If you can share your image it will be a great help. I have bought the same 7" touchscreen. I am not good at compiling kernals :(

Simon said...

I've been on holiday for a week, and this week is looking hectic, so I'm not sure when I'd get a chance to upload an image.

Simon said...

The image from engineering-diy.blogspot.in should work - it worked for me when I tried it - are you sure you followed all the steps?

Unknown said...

Hi Simon,
Please let us your work, can not offer you to download your great work?
Great thanks Form Germany
Stefan

Unknown said...
This comment has been removed by the author.
Devil said...

HI Simon,

I have followed all the steps this time I have compiled the kernel by my self following instruction mentioned here (http://mitchtech.net/raspberry-pi-kernel-compile/) they are similar to Andre's blog.

I have copied the compiled kernel image, modules and firmware but When I start my raspberry pi it doesnot boot and only pwr led is glowing.

I also tried the image provided by Andre on this page (http://engineering-diy.blogspot.in/2013/02/raspberry-pi-raspbian-xbmc-and-egalax-7.html) but again same situation no boot and just pwr led glowing.

Can you please help me out.

Simon said...

It's hard to diagnose something like this remotely. Can you build a default kernel that works? That would be a good starting place, so just get all the code, don't change any of the config options, and just build, and see if that works.

KarlTrout said...

worked like a charm, one thing to mention. i had to copy /lib/firmware/rtlwifi/* bock into my firmware directory because it was not compiled... I would suggest for newer less experience users to have them create a tar file and backup of there directories instead of rm 'ing them..

Simon said...

Thanks for the comment KarlTrout. I have just tried to use the instructions to build the kernel for a friend, and it seems with the latest updated image they don't work. Reverting back to any 2013 image seems to work, but something has changed in the last 3 months that means the driver is no longer effective. For me the mouse pointer simply stays along the top of the screen.

I built a kernel, applied it to an image that was updated and upgraded mid December 2013, and it worked fine, then on that same image I did a further update and upgrade, and applied the kernel again, and it failed to work. Investigation continues

Unknown said...

Check your connections on the ribbon cable for the touch panel, I had the same problem where the pointer would just stay on the edge of the screen. I have used this method and got the screen working but now it seems my wifi is not working and my game controller stops working after 5 min of use.

Simon said...

Brock,

It was a firmware issue, because reverting back the firmware fixed it.

For your problem, are you using a USB hub to power your touchscreen USB? If not then I've found it draws too much power, and makes operation unstable. A USB hub, or a USB +5v injector lead fixes this.

Unknown said...

Yes I have all my deviced plugged into a powered usb hub, and the wifi and controller work fine on the origional kernel but when i recompile with your instructions the wifi no longer works

Unknown said...

I was able to get it working by copying over my old firmware files to the new firmware folder made in your tutorial.

Unknown said...

could you please leave a link to download the working firmware? Seems that I have same problem now of cursor staying at top of screen.

Simon said...

Brock,

I have uploaded the contents of my firmware and modules directory, and also the kernel to dropbox. Simply remove and replace your /lib/modules and /lib/firmware with the ones in this archive. The matching kernel is also in the /boot directory

https://dl.dropboxusercontent.com/u/7297788/eGalax-touch-firmware.tar.gz

Unknown said...

Wow thanks a lot it worked!! I also figured out that it was not me making mistakes with my own kernel. It turns out my problem was the case that I had my screen in was causing the touch panel to detect a touch. Just had to move the screen away from touching the case and works great now.

Unknown said...
This comment has been removed by the author.
Simon said...

Hi John,

My article is on cross-compiling - so building the kernel on another linux machine running ubuntu and then copying the files across to the pi.

What does the error message say exactly? if you are already root user then you don't need to use sudo at the start of the commands.

Unknown said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
Unknown said...

I got the 99-calibration.conf to save but it still says no calibratable devices are found in xinput_calibrator

Simon said...

John, These instructions are for cross compile only, so they wont work running from your pi.

You need to get a copy of ubuntu installed onto an old pc and then follow the instructions.

xinputcalibrator will not work until you get the updated kernel built and installed.

You might find further help by asking on the raspberry pi forums. (and you're welcome to ask here for more too)

Unknown said...
This comment has been removed by the author.
Unknown said...

When I try to cross-compile (granted im using ubuntu 14.04 64bit with 32libs) i get this error still using your guide..

ubuntu@ubuntu:~/raspberrypi/linux$ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi
make: /usr/bin/arm-linux-gnueabigcc: Command not found
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
CC kernel/bounds.s
/bin/sh: 1: /usr/bin/arm-linux-gnueabigcc: not found
make[1]: *** [kernel/bounds.s] Error 127
make: *** [prepare0] Error 2



and still with gnueabi;

ubuntu@ubuntu:~/raspberrypi/linux$ sudo apt-get install git-core gcc-4.6-arm-linux-gnueabi
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package gcc-4.6-arm-linux-gnueabi
E: Couldn't find any package by regex 'gcc-4.6-arm-linux-gnueabi'

Unknown said...

Well I got it to work using gnueabihf -

"make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf-"

It's compiling!!! I'm documenting my progress - Thank you for trying to help so far Simon and thank you again for your guide.

Although for some reason I'm having an issue with the NOOBS SDHC card.... I try to move the kernel.img and I'm just getting this error..

ubuntu@ubuntu:~/raspberrypi/tools/mkimage$ sudo rm /media/boot-partition-uuid/kernel.img
rm: cannot remove ‘/media/boot-partition-uuid/kernel.img’: No such file or directory
ubuntu@ubuntu:~/raspberrypi/tools/mkimage$ sudo mv kernel.img /media/boot-partition-uuid/
mv: cannot move ‘kernel.img’ to ‘/media/boot-partition-uuid/’: Not a directory



I don't have a /media/boot-partition-uuid/ anywhere... All I find is SETTINGS in /boot/ ~ But I also cannot access the NOOBS in the SDHC..

I try to enter the volume and it says "unable to access "4.2 GB volume" Device /dev/loop1 is already mounted at '/Media/ubuntu/561d7033-c329-634e-9b5d-52dd5e9d1d0c"

Simon said...

John

boot-partition-uuid needs to be replaced with the uuid from your own boot partition, which looks like 561d7033-c329-634e-9b5d-52dd5e9d1d0c according to your error.

I've never used NOOBS so I'm not familiar with the layout, so I'm afraid I can be no help there.

Also if "sudo apt-get install package" cant find package, then you can use sudo apt-cache search package to find the proper name for the package (maybe the version number has changed). Search will return any partial matches

nachi said...

Hi,
Excellent tutorial indeed and I was able to get the touchscreen working with RaspberryPi. Thanks!

A query I have is, can I change the "double click" functionality of Raspbian into a single click like most touch screen OS. Let me know if any of you have figured a way to do this. :-)
Thanks & Regards,
Nachiketh

deepesh said...

Hi I have been trying your article ,finally i was able to complete the tutorial , but the touch does not seem to work , is thier a way to troubleshoot or check if the galaxy touchscreen drivers are loaded .

Simon said...

deepesh, its so long ago that I would be surprised if the instructions will work for today's Raspbian.

lsusb should list if the touchscreen is plugged in and the driver is recognised.

if the driver is working properly, when you touch the screen you will see the LED on the USB module come on and go off, if it comes on and stays on then the USB driver is not consuming the events from the touchscreen.

Apart from this, I'd recommend starting a thread on the raspberry pi forums, as someone else will probably be able to help you. http://www.raspberrypi.org/

deepesh said...
This comment has been removed by the author.
deepesh said...

Thanks simon ,

I have started a thread with Raspi forums ,
I did some additional troubleshooting and just wanted to mention it , that the touchscreen works with ubuntu 14.04 , so i tried things on comparison basis ..

when i did dmesg | grep -i usb on raspi it returns .
[ 3.471379] usb 1-1.4: Product: USB TouchController
[ 3.484165] usb 1-1.4: Manufacturer: eGalax Inc.
[ 3.736826] usb 1-1.2: new low-speed USB device number 5 using dwc_otg
[ 3.889922] usb 1-1.2: New USB device found, idVendor=1a2c, idProduct=0c21
[ 3.899177] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0

when i did the same on ubuntu 14.04

[ 5138.037116] usb 2-1.2: Product: USB TouchController
[ 5138.037119] usb 2-1.2: Manufacturer: eGalax Inc.
[ 5138.084038] input: eGalax Inc. USB TouchController as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/input/input10 .

Thanks .

Chris said...

For those who wants the kernel for last version of rasbian (february 2015) : 3.18.5, here is mine :
https://1fichier.com/?tg19bswby2

Chris said...

Hello everybody.
For the lucky ones who has a RPI 2 like me, here is the kernel to enable eGalax touchscreen.
You must have 3.18.5-rebase kernel.
https://1fichier.com/?7uwem02si9

Andy Seredy said...

Thanks for putting up your Kernal Guys. Though I think I did something wrong. After I replaced the Kernel and FM/mod folders, Everything booted up fine, and I was able to use my touch screen just fine, but when I tried to execute some shell scripts which controlled the Pi's GPIOs I was given "Command not found" errors, so I tried to chmod +x them (again)... didn't work...

Then I made the biggest noob move of all.. I tried an update/upgrade... now everything is effed. haha. USB input devices are detected, but dont work.. Everything (mouse, keyboard, touchscreen).

Curiously, my rootFS is on a USB drive, and that works fine. Guess I'll start from scratch. Cheers,

PS. I tried AUX's kernel on a rPi B+

Andy Seredy said...

First off (my noob mstake) DO NOT apt-get upgrade && update. It will jack up you hacked kernel.

hey all,
Quick update. If your GPIO's no longer work after modding your kernel, try this:

gpio -v

If that returns "not found", then you have to reinstall wiringPi.

Search that term, follow the simple directions and things will work again.

Hope it helps.