Compiling kernel modules for an Android phone

I recently got a USB OTG cable for my mobile phone and I wanted to use my PL2303 USB to UART convertor with it. It is great for the embedded system projects I'm working on. You can follow the below procedure to do it yourself.


Phone kernel : Linux 2.6.32.60-Kappa1.6
PC O/S : Ubuntu 13.04 32bit

1) Check for your kernel info using "uname -a" on either terminal emulator or ADB (use "adb shell" and run it).
My result:  Linux version 2.6.32.60-Kappa1.6 (Ka@Kappa) (gcc version 4.7.3 20130102 (prerelease) (Linaro GCC 4.7-2013.01) ) #94 PREEMPT Sun Apr 28 23:46:13 CEST 2013

2) Get the appropriate kernel source for your kernel. I got 2.6.32.60-Kappa1.6 kernel source from a GIT host using, (If you don't have git installed, you can install it by sudo apt-get install git)
git clone https://github.com/KaSt/Kappa.git

3) Download the appropriate cross-compiler toolchain, I'm using Linaro GCC 4.7-2013.01 toolchain.

4) Extract toolchain to somewhere, I extracted it to, /home/buddika/linaro

5) Set path variable to the bin directory of the toolchain using,
export PATH=/home/buddika/linaro/bin/:$PATH

6) Copy the kernel configuration file to the main folder where kernel source it. I executed following command at there,
cp /home/buddika/kernel/Kappa/arch/arm/configs/ka_coconut_defconfig .config

7) Check MakeFile and config files and edit them to match the kernel magic version(in my case 2.6.32.60-Kappa1.6). I had to edit following line on config file,
CONFIG_LOCALVERSION="$(KERNEL_LOCAL_VERSION)-Kappa $(KAREL)" to
CONFIG_LOCALVERSION="$(KERNEL_LOCAL_VERSION)-Kappa1.6"

8) Check the toolchain's binary directory and find the prefix for the compiler, if you see file like arm-linux-gnueabihf-gcc , the prefix is "arm-linux-gnueabihf-". Note this down for steps below.

9) Go to the kernel source directory, Let's clean the old binary files which may be there.
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make clean

10) Let's run menuconfig to configure the kernel options. This will give you a GUI where you can enable features. Select features you need as modules (in my case usbserial...etc) and press M to build them as modules.
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make menuconfig

11) Finally build the selected features as kernel modules. :)
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make modules

Now you can find the compiled kernel modules at "drivers/usb/serial/" folder in the kernel source folder. If you enabled other functions please check the appropriate folder.

I will show you how to use these newly compiled modules on your phone to use USB to UART module in the next post :D
Share on Google Plus
    Blogger Comment

0 comments:

Post a Comment