Loadable Kernel Module

1,851 views
Skip to first unread message

perumal316

unread,
Oct 1, 2009, 4:09:33 AM10/1/09
to Android Linux Kernel Development
Hi,

I want to load my own kernel modules into the Android. I downloaded
the Android kernel source and change the config file to enable modules
loading (CONFIG_MODULES=y). I built the source and also managed to
load up the emulator using the new kernel image.

But I tried to load a module using insmod helloworld.ko, I still get
the error message,"init_module 'helloworld.ko' failed (operation not
permitted)".

Any idea why it is still not working? Must I change any other
configurations? Or must I built my module in a particular way?
Currently this module can work in Linux v2.6

Thanks in advance.

Regards,
Perumal

poseidon

unread,
Oct 16, 2009, 1:15:43 PM10/16/09
to Android Linux Kernel Development
Emulator do not support modules. You will have to get that running on
a real hardware.

- Basil

Chew Esmero

unread,
Oct 20, 2009, 9:06:42 AM10/20/09
to Android Linux Kernel Development
Did you build the module against your new kernel? (i.e. ARCH=arm
KERNEL_DIR=<android-root-dir>/kernel make). I've encountered that
error message before and it seems that the booted kernel still do not
allow "Enable Loadable Module" .config support. Are you sure emulator
is booted with the new kernel? (i.e. emulator -kernel <new-kernel> -
show-kernel -avd <name-of-avd>)

perumal316

unread,
Oct 29, 2009, 1:01:57 AM10/29/09
to Android Linux Kernel Development

Thanks,Yes, now it can be loaded when the emulator is booted with the
new kernel.
But must I always build the module against my new kernel and boot with
the new kernel to load a new module?
Is it possible to insmod <module>, similar like in Linux to load a
module?
I have tried in emulator's terminal and in shell but keep on getting
the "init module failed, Exec Format Error or init module
failed,operation not permitted" error messages.

Regards,
Perumal

Chew Esmero

unread,
Oct 29, 2009, 1:23:01 AM10/29/09
to Android Linux Kernel Development
Yes, it is possible. Exec Format Error: it seems that your module is
not built using the headers of your goldfish kernel. Try this simple
makefile when building your new driver (assuming hello.c as source):

obj-m := hello.o

CROSS_COMPILE=arm-eabi-
KERNEL_DIR ?= ~/goldfish/kernel/

all:
$(MAKE) -C $(KERNEL_DIR) M=`pwd` ARCH=arm CROSS_COMPILE=$
(CROSS_COMPILE) modules

clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
modules.order Module.symvers Module.markers

You need to take note that you need to export first CROSS_COMPILE
variable to your current shell. (i.e. #export CROSS_COMPILE=~/<your-
android-dir>/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin) Then you
issue the command #make. I think this will resolve the Exec Format
Error problem.

As for the 'operation not permitted' problem in #insmod, it seems that
the "Loadable Module Support" in your goldfish's kernel config is
still not enabled. You can try this:

<goldfish-kernel># ARCH=arm make goldfish_defconfig
<goldfish-kernel># ARCH=arm make menuconfig

[*] Enable loadable module support ---> (make sure to have this one)

<goldfish-kernel># ARCH=arm ARCH=arm CROSS_COMPILE=arm-eabi- make

Your final kernel will be arch/arm/boot/zImage. After booting emulator
using that kernel, you can now do your #insmod in emulator shell.

Hope that helps.

perumal316

unread,
Oct 29, 2009, 3:33:20 AM10/29/09
to Android Linux Kernel Development
Hi,

I tried enabling the module support and boot the emulator using that
kernel but still getting the same error when insmod a module from the
terminal in emulator.

I also changing the Make file as specified and make the program but
get a long list of errors like "undeclared identifier" and cannnot
find header files and others.

If there anything else I must do, like only need to enable module
support or must enable any other options too?

Thanks in Advance,
Perumal

Chew Esmero

unread,
Oct 29, 2009, 4:16:04 AM10/29/09
to Android Linux Kernel Development
Only "Enable loadable module support". I think you really need to
build your driver with KERNEL_DIR pointing to your goldfish kernel
directory and using the cross-compiler provided with Android source.
If not, your driver will be built using your host's kernel headers.
The output module is not recognizable in Android kernel.

Chew Esmero

unread,
Oct 29, 2009, 4:20:00 AM10/29/09
to Android Linux Kernel Development
By the way, I'm using SDK 1.5 and android-goldfish-2.6.27. I also
tested android-goldfish-2.6.29 and still ok. Haven't tried the with
1.6 but I think it's still applicable.

Eduardo Acker

unread,
Oct 29, 2009, 10:57:51 PM10/29/09
to android...@googlegroups.com
Hi Chew,

I'm a newbie in linux/android and Im having some problems to compile the my module.
i dowloaded the android-goldfish-2.6.29 snapshot and the android plataform.
Compiled the kernel with your instructions to ARCH and CROSS_COMPILE and have no problem, but when i try to compile the module it givesthe error:
- entering directory /home/acker/goldfish/kernel
- no rule to process the target "modules"

any idea of what  i did wrong?

thanks for the help,
Eduardo Acker


2009/10/29 Chew Esmero <chew....@gmail.com>

perumal316

unread,
Oct 29, 2009, 11:35:00 PM10/29/09
to Android Linux Kernel Development
Hi,

I also faced similar problem, your MakeFile may need changes, below is
the makefile i used:

ifeq ($(KERNELRELEASE),)

KERNELDIR ?= /goldfish/kernel
PWD := $(shell pwd)

.PHONY: build clean

build:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c
else

$(info Building with KERNELRELEASE = ${KERNELRELEASE})
obj-m := hello.o

endif

Or you can also try the one mentioned by Mr Chew above.
Also as mentioned by him above set the path to your CROSS_COMPILE
directory before make.

Regards,
Perumal

On Oct 30, 10:57 am, Eduardo Acker <izayahighfat...@gmail.com> wrote:
> Hi Chew,
>
> I'm a newbie in linux/android and Im having some problems to compile the my
> module.
> i dowloaded the android-goldfish-2.6.29 snapshot and the android plataform.
> Compiled the kernel with your instructions to ARCH and CROSS_COMPILE and
> have no problem, but when i try to compile the module it givesthe error:
> - entering directory /home/acker/goldfish/kernel
> - no rule to process the target "modules"
>
> any idea of what  i did wrong?
>
> thanks for the help,
> Eduardo Acker
>
> 2009/10/29 Chew Esmero <chew.esm...@gmail.com>

Chew Esmero

unread,
Oct 30, 2009, 12:10:41 AM10/30/09
to Android Linux Kernel Development
Hi Perumal,

I'm confused when you say that it's already working in shell but not
in emulator. Working in shell meaning you insmod the hello.ko to your
host? If so, then the module was not properly built. If module is
properly built against the goldfish kernel, output module would be for
ARM architecture therefore you cant insmod it to your host (assuming
your host is x86). Only in emulator since emulator is an emulated ARM
architecture.

perumal316

unread,
Oct 30, 2009, 12:30:33 AM10/30/09
to Android Linux Kernel Development
Hi Mr Chew,

I have built the module against the goldfish kernel. Then I start the
emulator then in a terminal (adb shell) then insmod it and it is
working. But within the emulator there is a terminal emulator. If I
insmod there the module is not loaded ("Operation Not Permitted").
Since it is working in the shell, it should also work within the
terminal emulator but not sure why it is not working. Is there any way
to verify I have root access in terminal emulator?

Regards,
Perumal

Chew Esmero

unread,
Oct 30, 2009, 12:45:49 AM10/30/09
to Android Linux Kernel Development
Oh, sorry. Didn't get it right.

Terminal emulator in Android has no root privileges unfortunately. May
I ask why would you do it in terminal emulator when you can do it in
adb (already root)?

Chew Esmero

unread,
Oct 30, 2009, 12:59:47 AM10/30/09
to Android Linux Kernel Development
No problem. Happy coding. =)

perumal316

unread,
Nov 5, 2009, 8:58:05 PM11/5/09
to Android Linux Kernel Development
Hi Mr Chew,

When I rmmod my modules. i keep on getting "rmmod: delete_module
failed (errno 38)" error message. Any idea what is causing this? My
exit portion of the code is similar to those I tried in Linux. It
works fine in Linux.

Regards,
Perumal

Chew Esmero

unread,
Nov 5, 2009, 9:22:15 PM11/5/09
to Android Linux Kernel Development
Haven't encountered that error. Try checking your kernel .config and
include "Module unloading" & "Forced module
unloading" under the "Enable loadable module support" menu.

perumal316

unread,
Nov 5, 2009, 10:22:08 PM11/5/09
to Android Linux Kernel Development
Thanks Mr Chew,

I managed to solve it. I didn't enable module unloading and forced
module unloading previously. After enabling and making the kernel
again, I can unload the modules.

Regards,
Perumal

perumal316

unread,
Dec 15, 2009, 11:20:42 PM12/15/09
to Android Linux Kernel Development
Hi,

I currently working on a monitoring tool in a form of LKM, which I
want to use to monitor the system calls made and aruguments passed
during the calls.

I can access into the system call table and replace system calls
(using the LKM) but this is only for one system call.

Any idea how to capture parameters passed and monitor the system calls
made by applications?

Regards,
Perumal
Reply all
Reply to author
Forward
0 new messages