Compiling additional driver modules for Kernel in Android (Or Linux).

I had to compile some modules for android image that came preinstalled on Cubieboard. However, i was unable to do so, as the sources were not available. So i compiled another android image using the sources available on Cubieboard’s website and modified the defconfig file to have my modules created while compiling the OS image.

In order to compile the drivers following two conditions should be met, apart from availability of Kernel sources

  • The code written in the source files should be compatible with your CPU type. Some modules doesn’t support Allwinnner A10 CPUs.
  • Some modules are dependent on other modules, like in case driver for PL2303 USB to Serial converter, it needs two modules. PL2303.ko is dependent on usbserial.ko.You should select the dependent modules as well.

First, you will need to setup the right environment for this compilation process. following is a nice link which shows how to setup the environment. Using Ubuntu 10.04 is a proven and most stable method. Skip steps 5, 6 and 8. Follow step 8 only if you want to build entire kernel with ‘cubieboard_defconfig’ for cubieboard.

Following steps will show how to compile modules.

Using the Menuconfig command, enable the Module (ensure to select “M” instead of “Y” ). And then use the Make command in following manner to compile the single module only. I assume that you are comfortable with linux.

make < Optional ARCH= Path to arm-eabi- directory >  <path to the .c file of module>
e.g. make ARCH=< Path to arm-eabi- directory )  /kernel/drivers/input/sun4i-ts.c
You will also have to carefully read and understand the error messages displayed. When the modules are interdependent, try.
make  < Optional ARCH= Path to arm-eabi- directory > <path to the directory containing c file of module>
e.g. make ARCH=< Path to arm-eabi- directory ) /kernel/drivers/input/
This will compile all enabled modules in the folder. Once compiled, a .ko file will be created, which is the module you need to load as driver. Copy the .ko file to /system/lib/modules/ (normally ) and load it using insmod <filename.ko> or insmod <path to .ko file>. You can see the error / success log using dmesg command and verify whether the module is loaded using lsmod <modulename> command.
rmmod <modulename> unloads the modules.



Leave a Reply