Compiling kernel modules? - G1 Android Development

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)
Click to expand...
Click to collapse
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?

rale00 said:
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?
Click to expand...
Click to collapse
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

No joy here. I couldn't even figure out how to get it to compile a minimal "hello world" kernel module.

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

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)

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...

I am having same problem now. I am also using the toolchain from Android source...

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).

rale00 said:
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...
Click to expand...
Click to collapse
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..

yeah, that's the problem.
The version magic number doesn't match.
May I know where to get the RC19 source tree? Thanks.

JesusFreke said:
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..
Click to expand...
Click to collapse
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.

Any Help for Compiling and Debug Native Apps is here
http://honeypod.blogspot.com/2008/01/debug-native-application-for-android.html

Related

help porting a linux program to the android

hi all
i have created a custom rom for myself because i want to add a linux program: scanmem
i have copied the file in system/xbin
using this guide http://lukasz.szmit.eu/2009/12/making-your-own-rooted-android-rom.html on step6 for su command
the problem is that doesn't work ...
when i open a terminal in my desire and type :
su
scanmem
i receve this message:
scanmem: 1: syntax error: "(" unexpected
any help, suggestion ? scanmem is compiled for i386 32bit
kiokoman said:
any help, suggestion ? scanmem is compiled for i386 32bit
Click to expand...
Click to collapse
There's your problem.
Code:
[email protected]:/tmp$ file busybox
busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, stripped
[email protected]:/tmp$
If you don't have the source, time and a cross-compiler, you have a problem It's also Little Endian from memory.
This is the busybox binary I tested in case you want to strip it down: http://benno.id.au/blog/2007/11/14/android-busybox
i found a lot of information with google
http://www.kbrandt.com/2009/06/how-to-cross-compile-the-bash-shell-for-android-15.html
i have the source maybe i can compile for arm
kiokoman said:
i found a lot of information with google
http://www.kbrandt.com/2009/06/how-to-cross-compile-the-bash-shell-for-android-15.html
i have the source maybe i can compile for arm
Click to expand...
Click to collapse
Precisely. You should also check the dependencies (if any) and make sure you cross-compile those too.
jayshah said:
Precisely. You should also check the dependencies (if any) and make sure you cross-compile those too.
Click to expand...
Click to collapse
oh my god
depends on libc6 and readline6, i have to cross-compile half gnu/linux
out of my hand
Shame :/
Why did you need it anyway? Perhaps there is another way for what you want to achieve.
jayshah said:
Shame :/
Why did you need it anyway? Perhaps there is another way for what you want to achieve.
Click to expand...
Click to collapse
i think it was an easy program to port and with a frontend for android I would have used it as the first cheats system like cheat engine for pc
I made this. I compile scanmem fo my android phone (p500) from sourses.
He even gets up and running, but not quite.
Opt for a process (pid command)
It finds regions of memory. But during the search, crashes ". bus Error"
Maybe it's because of the specificity of an android, or due to the fact that I had to change all calls to readline lib, because otherwise the project will not compile.
I will continue to watch and understand ...
Done. Scanmem works fine on my phone.

[Q] Compile bash for droid?

I dont know if this is the proper place for this thread...and I know there is a bash compiled already floating around (which I have) but for the purposes of learning Im trying to create a custom ROM from scratch, building busybox,bash,froyo, etc..
I am trying to comile bash 4.1 from the source code, compiling process is pretty straightforward but im having trouble making it cross compile for ARM
Here is what spits out after I enter "file bash" after compiling.
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.15, not stripped
The part I'm missing is how to make it into the proper format which is:
ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, stripped
Any suggestions?
also is there a way to make it the default shell upon booting?
There's some toolchain tips here. Don't know if there any use to you.
http://android-tricks.blogspot.com/2009/02/hello-world-c-program-on-using-android.html
Pointed me in the right direction thanks .
heres the the code
I added the path of my arm-2010q1/bin to my .bashrc
then:
Code:
CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/opt/arm_bash/ -host=arm-linux --enable-static-link --without-bash-malloc
conigured what I needed to and it cross compiled successfully after make.
drew408 said:
also is there a way to make it the default shell upon booting?
Click to expand...
Click to collapse
http://forum.xda-developers.com/showthread.php?t=727566

[Q] Cross compiling C software for my android

Hi,
I've download the Android source with "repo", and it includes cross compiler toolchains for various architectures.
I want to build a package (for now, mtd-utils) for my android phone (a htc hero), but I'm having limited success understanding how to get this working. I was thinking there was something I could do, like change my $PATH and set up some other environment variables, that would use the tools from the toolchain instead of the system default ones, so that the binaries would be built for the phone instead of for my computer. But it certainly doesn't seem to be that easy...
I've reverted to attempting a "Hello world" program, but when I try to compile even that using the included toolchain tools, I run into trouble:
Code:
$ $HOME/src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-gcc -static -o hello hello.c
hello.c:1:19: error: stdio.h: No such file or directory
hello.c: In function 'main':
hello.c:5: warning: incompatible implicit declaration of built-in function 'printf'
so I tried a couple of other variants:
Code:
$ $HOME/src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-gcc -static -I $HOME/src/mydroid/bionic/libc/include -o hello hello.c
$ $HOME/src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-gcc -static -I $HOME/src/mydroid/ndk/build/platforms/android-8/arch-x86/usr/include/ -o hello hello.c
but they both give (different) errors about what other include files are missing when referenced from somewhere.
Is there some "easy" way to android-ify a source tree, so that I can build sources using the cross compiler toolchains? Or should I fetch a different cross compiler toolchain to use, like benno did in his document from 2007? He uses a codesourcery toolchain and builds with that instead (as referenced in other articles here on the subject).
Would much appreciate any shared tips or experiences on how to accomplish this.
The tool chain is fine the problem is non of the include/lib are set up correctly to find the needed version of the includes. Remember the default includes under linux depend on glibc and android only supplies bionic.
Have a look here for more info on setting up bionic:
http://android-dls.com/wiki/index.php?title=Compiling_for_Android
Though if you get the full source for glibc (or precompiled arm binaries) you could compile a dependant program staticly (I think that's what busybox does)
Building for older versions of Android
I was actually able to compile a program manually today, specifically one of the programs in the mtd-utils package. After lots of jumping back and forth, I have found out that the 64 bit version of Ubuntu is what I needed, and also sun-java-1.6, contrary to almost all information I found out there. Then I was able to build AOSP, and then I was able to get "agcc" working, the wrapper that sets environment variables automatically as needed.
So I compiled the app, but it didn't work on my Android. Trying to run it in an adb shell gave approximately this error (from memory):
/bin/sh: ./program: No such file or directory
though the program was there. I didn't use strace, but concluded that this is because of a missing shared library. I have a very recent version of AOSP, while the phone is running Android 2.0 or something like that, so that's a plausable reason why this is happening.
I tried to rebuild the program using "agcc -static ...", but that doesn't work because I don't have the static version of libc after building AOSP, so it just dies with a linker error complaining that it can't find -lc.
So now I need to figure out how to build for old Android version using my checked out version of AOSP, or I need to figure out how to check out an old version of AOSP using repo.
Any tips would be much appreciated.

WITS a81e and Milestone Overclock

.I have been trying to get my tablet wits a81e uses a omap3 chipset to load a module. it uses Android 2.2 and the uname -r on the unit is 2.6.32 instead of 2.6.32.9 like the other modules droid_22 and milestone leak that are supplied. i am trying to compile the module and when it creates it it appears to be based on the overclock-mod.c file instead of the overclock.c file. Is there somthing special I should be doing?
I am using ubuntu and the google ndk. I compile and I end up with the .ko file which will load. There are no kern messages other than the kernel is tained. If I run strings overclock.ko I only can basically see the .modinfo from the file.
I have worked on this forever....Can you give any suggestions?
TY
Bruce

Gingerbreak exploit file type

All, I need to edit the Gingerbreak exploit for rooting. Whwn I try to open in a text editor i get a bunch of gibbersih. What type of file is the actual exploit? (not the APK)
Thanks
It looks like it is an ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
I'm not an expert, but my guess is that you would need to make the changes to the source code and bake it in.
The code is binary and is compiled with the ARM C compiler. You can take a look at the C source code for gingerbreak here. See 2nd post.
http://forum.xda-developers.com/showthread.php?t=1044765

Categories

Resources