Take the 2-minute tour ×

For work reasons, I need to develop a LKM for Android platform. I'm not very sure how to cross compile my AndroidModule.c and what tools to use for that. I guess that I'll need the source code of Android in order to tell the compiler to link the libraries from there right? I will also need to download the ARM compiler for Android. I think with those three things is enough (LKM Code in C, Android Source Code, ARM compiler for android). The problem is that I can't find any tutorial that explains how to compile LKM for Android. I'll be very pleased to have more info about it.

share|improve this question
add comment

3 Answers

Here's a makefile that I use to build modules for Android. I'm assuming you have a copy of the linux source somewhere and that you have built the kernel for your phone. In your module directory I put a Makefile like this:

    obj-m := mymod.o
    COMPILER ?=/pathtoandroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
    ARCH ?=arm
    KERNELDIR ?= /home/kernel/androidkerneldir/
    PWD := $(shell pwd)
    EXTRACFLAGS += -I$(PWD)/somedirectory/shomewhere
    rm *.o *.ko
    adb push mymod.ko /system/lib/modules

This should do it for you. Make sure you have write permissions to /system directory.

share|improve this answer
add comment

Try the Android URL at the bottom it has detailed instructions on how to build the source.

Then follow this URL for final building (this is for dream release), I am assuming the procedure should hold good for other releases as well.

share|improve this answer
add comment

This should help.

To cross compile a module you'll need the kernel source code and the ARM compiler which is in the Android tool chain. You'll need a Makefile something along the lines of

obj-m:= AndroidModule.o

all: module

    $(MAKE) -C $(KERNELSRC) SUBDIRS=$(PWD) modules
    $(MAKE) -C $(KERNELSRC) SUBDIRS=$(PWD) clean
    @rm -f Module.symvers Module.markers modules.order

Then compile by configuring CROSS_COMPILE as the ARM compiler and KERNELSRC as the kernel source location, and calling make. Here's the command I use on 0xdriod.

CROSS_COMPILE=~/beagle-eclair/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- ARCH=arm KERNELSRC=~/kernel make
share|improve this answer
add comment

Your Answer


