Compiling kernel modules for android

3,099 views
Skip to first unread message

Johnson Pinto

unread,
Jan 25, 2012, 4:29:27 AM1/25/12
to Android Linux Kernel Development
Hi,
Am using rowboat version of android. I want to build kernel module
'hello.c'

my android kernel is in the path ~/rowboat-android/kernel
I had extracted arm compiler in the path ~/tools/arm/arm-2008q3

My module and makefile is in the path ~/Desktop/test_kernelmod/

My makefile is:

obj-m := mymod.o
COMPILER :=/home/johnson/rowboat-android/prebuilt/linux-x86/
toolchain/arm-eabi-4.4.0/bin/arm-eabi-
CROSS_COMPILE := $(COMPILER)
ARCH := arm
KERNELDIR :=/home/johnson/rowboat-android/kernel

PWD := $(shell pwd)

default:
make -C $(KERNEL_DIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$
(COMPILER) modules

clean:
rm *.o; rm *.ko



I tried all the options by changing the KERNELDIR, and also the
COMPILER path but of no use..
I get the errror as :
make: *** M=/home/johnson/Desktop/test_kernelmod: No such file or
directory. Stop.
make: *** [default] Error 2

Can anyone say how to compile it ? what all changes to be made to
Makefile ?

Thanks,
Johnson

Kenneth Ko

unread,
Jan 28, 2012, 12:08:59 AM1/28/12
to android...@googlegroups.com
> KERNELDIR :=/home/johnson/rowboat-android/kernel

You may want to try KERNEL_DIR rather than KERNELDIR.

--Ken

> --
> unsubscribe: android-kerne...@googlegroups.com
> website: http://groups.google.com/group/android-kernel

jagan

unread,
Jan 28, 2012, 5:50:20 AM1/28/12
to android...@googlegroups.com
For creating kernel dynamic modules, needs a module library.

If you have no problem while compiling modules in kernel directory [means while kernel building time].
Create a directory in drivers folder, copy the *.c file write the Makefile & Kconfig for that.
Once kernel building was done, push that .ko to android fs.

Above procedure is little bit hard, but gives a fruitful result with defined procedure.

Regards,
Jagan.

Vladimir Murzin

unread,
Jan 29, 2012, 9:57:12 AM1/29/12
to android...@googlegroups.com

Hi,

Is compilation from shell working? I mean have you tried something like
$make -C /home/johnson/rowboat-android/kernel M=$PWD ARCH=arm
CROSS_COMPILE=/home/johnson/rowboat-android/prebuilt/linux-x86toolchain/arm-eabi-4.4.0/bin/arm-eabi-
modules

BTW, I think you should use arm-none-linux-gnueabi- toolchain instead
of arm-none-eabi

Best wishes
Vladimir Murzin

Gagan Chawla

unread,
Jan 27, 2012, 12:52:24 AM1/27/12
to android...@googlegroups.com
Hello Johnson,

Your file name is "hello.c"

for compiling that, You should write

obj-m := hello.o

in Makefile.

in your case, you have used "mymod.o" so it is trying to search "mymod.c" file in PWD but there is no such file thats why it throws the error.


Also, I doubt on KERNEL_DIR path. It should be the path where header files are present. May be you are write if it works fine [let me know also :) ]

Try using this.

obj-m := hello.o

all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

or you can use the following if you want your module name as "mymod.ko"

obj-m := mymod.o

mymod-objs := hello.o

all: make -C $(KERNELDIR) M=$(PWD) modules

clean: make -C $(KERNELDIR) M=$(PWD) clean


Warm Regards,
Gagan Chawla




Reply all
Reply to author
Forward
0 new messages