Compiling kernel modules?

Search This thread

rale00

Member
Nov 8, 2008
19
0
I'm trying to compile bnep as a module (needed for Bluetooth PAN), but I keep running into the following error when I try to load it:

insmod: init_module 'bnep.ko' failed (Exec format error)

I'm using kernel-android-msm-htc-2.6.25 and arm-eabi-4.2.1-gcc from the android source, so I'm not sure what's wrong. Anyone have any pointers?
 

JesusFreke

Inactive Recognized Developer
Oct 23, 2008
736
54
Dallas
I'm trying to compile bnep as a module (needed for Bluetooth PAN), but I keep running into the following error when I try to load it:



I'm using kernel-android-msm-htc-2.6.25 and arm-eabi-4.2.1-gcc from the android source, so I'm not sure what's wrong. Anyone have any pointers?

hmm. good question. Unfortunately I don't have any advice right now :\. But it sounds interesting and now I want to see if I can build a minimal do-nothing kernel module and get it to load.

More to come :D
 

JesusFreke

Inactive Recognized Developer
Oct 23, 2008
736
54
Dallas
No joy here. I couldn't even figure out how to get it to compile a minimal "hello world" kernel module.
 

blues

Member
Sep 10, 2007
35
1
I am trying to make a driver too. But I am still not sure how to compile a module.

I was trying to make the whole source tree from my redhat machine, but no luck.

So instead, I plan to just compile my driver by using the toolchain from android source.

But I am sure how to make a makefile for this.
Could you share it?

Thanks,
Blues
 

ieatlint

Member
Nov 8, 2008
7
0
The "exec format error" means that you compiled it for the wrong architecture.

For a quick reference to seeing what arch for which a binary is compiled, use the "file" command found on any Linux computer (but not present on the phone itself).
The file command is an extremely useful function for identifying files -- including files that are packaged together, such as the .img files in the updates (see the -k option).

Dynamically linked executable:
"ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped"

Statically linked executable:
"ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped"

Object file:
"ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped"

More specifically, if it doesn't say 32bit ARM, it will not work.
This may prove useful to some:
http://www.gentoo.org/proj/en/base/embedded/handbook/index.xml?part=1&chap=6
(And the compilers references in "CROSS_COMPILING" must be in your path -- see also the CC variable)
 

rale00

Member
Nov 8, 2008
19
0
This is file on wlan.ko pulled directly from the phone - a known working module:

wlan.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped

This is the module I compiled:

bnep.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped


There must be something else at work here...
 

blues

Member
Sep 10, 2007
35
1
I am having same problem now. I am also using the toolchain from Android source...
 

beartard

Senior Member
Jun 20, 2008
481
14
Winter Haven, Florida, USA
I haven't gotten this deep into Android yet, but make sure the kernel source tree you're compiling against is the same version as the kernel on the phone. Modules compiled for a different kernel version will not load on another one (usually).
 

JesusFreke

Inactive Recognized Developer
Oct 23, 2008
736
54
Dallas
This is file on wlan.ko pulled directly from the phone - a known working module:

wlan.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped

This is the module I compiled:

bnep.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped


There must be something else at work here...



Right after you try to insmod the module, type dmesg. Look through the last part of the output and see if there is anything helpful..
 

blues

Member
Sep 10, 2007
35
1
yeah, that's the problem.
The version magic number doesn't match.

May I know where to get the RC19 source tree? Thanks.
 

rale00

Member
Nov 8, 2008
19
0
Right after you try to insmod the module, type dmesg. Look through the last part of the output and see if there is anything helpful..

Thanks, that was the key. Apparently kernel/scripts/setlocalversion queries git for part of the version string. I ended up just changing it to print "-01843-gfea26b0", which is the string for RC30, and the module worked fine.