Post Reply
Smile

[Q] init_module 'hello.ko' failed (Exec format error) in android emulator

6th April 2012, 02:39 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Apr 2012
hi ,

I am working on my project for android kernel module development i am getting error
like

insmod: init_module 'hello.ko' failed (Exec format error) in android

after performing all process as described below

First we must retrieve and copy the kernel config from our device.
$ cd /path/to/android-sdk/tools
$ ./adk pull /proc/config.gz
$ gunzip ./config.gz
$ cp config /path/to/kernel/.config

changed config file as
CONFIG_MODULES=y

then current config is like this

CONFIG_MODULES=y
CONFIG_MODULE_FORCE_LOAD=y
CONFIG_MODULE_UNLOAD=y
CONFIG_MODULE_FORCE_UNLOAD=y
CONFIG_MODVERSIONS=y
CONFIG_MODULE_SRCVERSION_ALL=y

Next we have to prepare our kernel source for our module.
$ cd /path/to/kernel
$ export ARCH=arm
$ export CROSS_COMPILE=/path/to/android-ndk/toolchains/arm-eabi-4.4.3/prebuilt/linux-x86/bin/arm-eabi-
$ make

then zimage is created and loaded it into emulator succefully.


PREPARING MODULE FOR COMPILATION

i created a Makefile to cross-compile our kernel module. The contents of your Makefile is:

VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 29
EXTRAVERSION = -00054-gef9c64a

obj-m += hello.o

KDIR=~/Sukha_android/goldfish/
PWD := $(shell pwd)


default:
make -C $(KDIR) ARCH=arm CROSS_COMPILE=~/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- SUBDIRS=$(PWD) modules

clean:
make -C $(KDIR) ARCH=arm CROSS_COMPILE=~/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- SUBDIRS=$(PWD) clean


My Hello.c is :

#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */

MODULE_LICENSE("GPL");
MODULE_AUTHOR("suhas, 2012");
MODULE_DESCRIPTION("Demo module");

int init_module(void)
{
printk("<1>Hello world\n");
return 0;
}

void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}



COMPILING AND INSTALLING MODULE
$ cd /path/to/module/src
$ make
$ cd /path/to/android-sdk/tools/
$ ./adb push /path/to/module/src/hello.ko /data

RUNNING YOUR MODULE
$ cd /path/to/android-sdk/
$ ./adb shell
$ su
# insmod /data/hello.ko

then getting error

insmod: init_module 'hello.ko' failed (Exec format error) in android

after :
dmesg:

unknown relocation: 27 when insmod

occured please help me i ts very important for me.

Regards,
Suhas
7th April 2012, 06:22 AM   |  #2  
Modulüs's Avatar
Senior Member
Flag Mumbai
Thanks Meter: 148
 
505 posts
Join Date:Joined: Jan 2012
More
I guess it should be a ".so" file and not ".ko"..

Sent from my GT-S5830 using Tapatalk
28th February 2014, 01:06 PM   |  #3  
Junior Member
Thanks Meter: 0
 
3 posts
Join Date:Joined: Jul 2013
Quote:
Originally Posted by suhascomp.143

dmesg:

unknown relocation: 27 when insmod

Try to add EXTRA_CFLAGS=-fno-pic compilation option inside your mod makefile.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Q&A, Help & Troubleshooting by ThreadRank