How to compile a kernel module to Android Linux Kernel ?

3,182 views
Skip to first unread message

永振 田

unread,
Aug 2, 2009, 11:21:06 PM8/2/09
to Android Linux Kernel Development
Hi,all!
I'd like to compile a kernel module to Android Linux Kernel,but I have
no idea how to write the Makefile for the kernel module.
Here is my Makefile(just like pc):

obj-m= test_k.o
KERNELDIR= /home/tyz/0728/kernel/
CROSS_COMPILE= /home/tyz/0728/prebuilt/linux-x86/toolchain/arm-
eabi-4.2.1/bin/arm-eabi-
CC= $(CROSS_COMPILE)gcc
PWD= $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
rm Module.symvers



when make modules,the Makefile do nothing but list errors as follows:
tyz@debian:~/NetBeansProjects/test3GNetlink$ make modules
make -C /home/tyz/0728/kernel/ M=/home/tyz/NetBeansProjects/
test3GNetlink modules
make[1]: Entering directory `/home/tyz/0728/kernel'

ERROR: Kernel configuration is invalid.
include/linux/autoconf.h or include/config/auto.conf are
missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.


WARNING: Symbol version dump /home/tyz/0728/kernel/Module.symvers
is missing; modules will have no dependencies and
modversions.

CC [M] /home/tyz/NetBeansProjects/test3GNetlink/test_k.o
cc1: error: unrecognized command line option "-m64"
cc1: error: unrecognized command line option "-mno-red-zone"
cc1: error: unrecognized command line option "-mcmodel=kernel"
cc1: error: unrecognized command line option "-maccumulate-outgoing-
args"
cc1: error: unrecognized command line option "-mno-sse"
cc1: error: unrecognized command line option "-mno-mmx"
cc1: error: unrecognized command line option "-mno-sse2"
cc1: error: unrecognized command line option "-mno-3dnow"
make[2]: *** [/home/tyz/NetBeansProjects/test3GNetlink/test_k.o] error
1
make[1]: *** [_module_/home/tyz/NetBeansProjects/test3GNetlink] error
2
make[1]: Leaving directory `/home/tyz/0728/kernel'
make: *** [modules] error 2

Neo

unread,
Aug 4, 2009, 6:09:42 AM8/4/09
to Android Linux Kernel Development
Why do you have to write a Makefile for the compiling the kernel, it
is already there in kernel sources. So go there and just do a "make"
after setting the cross-compiler option.

lei

unread,
Aug 5, 2009, 3:48:10 AM8/5/09
to Android Linux Kernel Development
ARCH=ARM
> after setting the cross-compiler option.- Hide quoted text -
>
> - Show quoted text -

basteon

unread,
Aug 5, 2009, 10:39:56 AM8/5/09
to android...@googlegroups.com
use it...
may be very helpful add this script to android kernel building how-to ;)
#!/bin/sh
#######
#Actually, I getting it by this way...
#cd android
#repo init -u git://android.git.kernel.org/platform/manifest.git
#repo sync
#######
#But, if you want to get only tools, you must try this...
# git clone git://android.git.kernel.org/platform/prebuilt.git

#where your android tools
export CROSSTOOLS=/usr/src/android/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1
export PATH=$CROSSTOOLS/bin:$PATH

export CROSS_TARGET=arm-eabi

export CC="${CROSS_TARGET}-gcc"
export CXX="${CROSS_TARGET}-g++"
export AR="${CROSS_TARGET}-ar"
export AS="${CROSS_TARGET}-as"
export LD="${CROSS_TARGET}-ld"
export RANLIB="${CROSS_TARGET}-ranlib"
export READELF="${CROSS_TARGET}-readelf"
export STRIP="${CROSS_TARGET}-strip"

永振 田

unread,
Aug 6, 2009, 4:14:45 AM8/6/09
to Android Linux Kernel Development
Thanks,guys!
With your help,the problem was solved.
And here is the steps:
Without writing a Makefile for the module.
You just need to :
#cp $(YOUR_MODULE_FILES) $(YOUR_ANDROID_DIR)/kernel/drivers/char/
next,you should:
## set kernel config
#make ARCH=arm CROSS_COMPILE=arm-eabi- qsd8650_defconfig
#make -j4 ARCH=arm CROSS_COMPILE=arm-eabi- modules
then ,you get the result!

On 8月5日, 下午10时39分, basteon <bast...@gmail.com> wrote:
> use it...
> may be very helpful add this script to android kernel building how-to ;)
> #!/bin/sh
> #######
> #Actually, I getting it by this way...
> #cd android
> #repo init -u git://android.git.kernel.org/platform/manifest.git
> #repo sync
> #######
> #But, if you want to get only tools, you must try this...
> # git clone git://android.git.kernel.org/platform/prebuilt.git
>
> #where your android tools
> export CROSSTOOLS=/usr/src/android/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1
> export PATH=$CROSSTOOLS/bin:$PATH
>
> export CROSS_TARGET=arm-eabi
>
> export CC="${CROSS_TARGET}-gcc"
> export CXX="${CROSS_TARGET}-g++"
> export AR="${CROSS_TARGET}-ar"
> export AS="${CROSS_TARGET}-as"
> export LD="${CROSS_TARGET}-ld"
> export RANLIB="${CROSS_TARGET}-ranlib"
> export READELF="${CROSS_TARGET}-readelf"
> export STRIP="${CROSS_TARGET}-strip"
>

rk

unread,
Aug 20, 2009, 3:22:12 AM8/20/09
to Android Linux Kernel Development
Hi Guys,

I am not able to compile the kernel which I have with the source code/
downloaded from the git repo. Here is my problem thread. Can some one
help me

http://groups.google.com/group/android-kernel/browse_thread/thread/9b0975d78a28112


Thanks
Rk
> > >> - Show quoted text -- Hide quoted text -

Harish

unread,
Aug 20, 2009, 6:14:00 AM8/20/09
to Android Linux Kernel Development
To write a kernel module which placed external to core kernel
please go through the below website

http://tldp.org/LDP/lkmpg/2.6/html/x181.html

Regards
Harish
On Aug 20, 12:22 pm, rk <raj.10...@gmail.com> wrote:
> Hi Guys,
>
> I am not able to compile the kernel which I have with the source code/
> downloaded from the git repo. Here is my problem thread. Can some one
> help me
>
> http://groups.google.com/group/android-kernel/browse_thread/thread/9b...

Qiang Wang

unread,
Aug 20, 2009, 3:29:05 AM8/20/09
to android...@googlegroups.com
hi,
There is something wrong with the configure file.
You should check if you are use the arm compiler and configure file.

best regards
wangqiang

2009/8/20 rk <raj....@gmail.com>:
Reply all
Reply to author
Forward
0 new messages