Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,730,807 Members 43,379 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
suhascomp.143
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 1
Join Date: Apr 2012
Smile [Q] init_module 'hello.ko' failed (Exec format error) in android emulator

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
 
Modulüs
Old
#2  
Modulüs's Avatar
Senior Member
Thanks Meter 148
Posts: 505
Join Date: Jan 2012
Location: Mumbai
I guess it should be a ".so" file and not ".ko"..

Sent from my GT-S5830 using Tapatalk
| Twitter |
 
deadeert
Old
#3  
Junior Member
Thanks Meter 0
Posts: 3
Join Date: 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.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes