开发者

Cross compile LKM module for Android platform

For work reasons, I ne开发者_Go百科ed 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.


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:

ifneq ($(KERNELRELEASE),)
    obj-m := mymod.o
else
    COMPILER ?=/pathtoandroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
    CROSS_COMPILE ?=$(COMPILER)
    ARCH ?=arm
    KERNELDIR ?= /home/kernel/androidkerneldir/
    PWD := $(shell pwd)
    EXTRACFLAGS += -I$(PWD)/somedirectory/shomewhere
default:
    $(MAKE) -C $(KERNEL_DIR) M=`pwd` ARCH=$(ARCH) CROSS_COMPILE=$(COMPILER) EXTRA_CFLAGS=$(EXTRACFLAGS) modules
clean:
    rm *.o *.ko
install:
    adb push mymod.ko /system/lib/modules

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


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.


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

module:
    $(MAKE) -C $(KERNELSRC) SUBDIRS=$(PWD) modules
clean:
    $(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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜