Compile binary for testing linux kernel exploit for arm architecture - Android

Hi,
i'm an android app developer. I have an HTC Desire and I would test kernel issue for root my device.
For check kernel or software issue, I compile on my linuxbox (on Intel) and binary file run in the same arch that compile it.
In an arm device like my android phone, how can I compile c source file?
We will say: "With an arm croos toolchain!"...
I have read http://www.hermann-uwe.de/blog/buil...-with-binutils-gcc-newlib-and-gdb-from-source that explain how to build the toolchain, but binary compiler that this steps create not compile a simple "Hello World" program:
Code:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
because not have stdio.h header... O_O
So I have downloaded the GNU ARM toolchain binary for linux, but the compiler don't work because I can't run it on my linuxbox...
Why?
mmm... So I have copied the "include" directory from GNU Arm ToolChain to toolchain compiled from source (how explaine the link above).
now stdio.h is present but...
Code:
/tmp/ccfmzOMU.s: Assembler messages:
/tmp/ccfmzOMU.s:11: Error: junk at end of line, first unrecognized character is `@'
/tmp/ccfmzOMU.s:12: Error: junk at end of line, first unrecognized character is `@'
/tmp/ccfmzOMU.s:13: Error: too many memory references for `mov'
/tmp/ccfmzOMU.s:14: Error: no such instruction: `stmfd sp!,{fp,ip,lr,pc}'
/tmp/ccfmzOMU.s:15: Error: too many memory references for `sub'
/tmp/ccfmzOMU.s:16: Error: no such instruction: `ldr r0,.L3'
/tmp/ccfmzOMU.s:17: Error: no such instruction: `bl printf'
/tmp/ccfmzOMU.s:18: Error: expecting operand after ','; got nothing
/tmp/ccfmzOMU.s:19: Error: too many memory references for `mov'
/tmp/ccfmzOMU.s:20: Error: no such instruction: `ldmfd sp,{fp,sp,pc}'
How can i build binary elf file for my Desire architecture?
Thanks in andvance!

I am unable to link to any resources here due to them being behind a corporate firewall, but this link I found might help:
http://www.ibm.com/developerworks/linux/library/l-arm-toolchain/index.html
Here is a link to the tools:
http://www.codesourcery.com/sgpp/lite/arm/portal/[email protected]=lite
Let me know if this is not what you are looking for.

Yes, this is what I need.
Thanks!
Now I've tried to compile my hello world in C for ARM, but the binary not run on my desire... I think that I have compiled with a mistake mcpu parameter.
The result is that if I copy helloworld binary in /data/local path in my Desire, set execution permission and execute the program:
Code:
$ ./helloworld
./helloworld
./helloworld: not found
the output of 'ls -l' command show that helloworld file exist and have 'x' permission...
So I think that is an incompatibily issue of the binary file...
Which one "-mcpu" value is correct for the Qualcomm Snapdragon QSD8250 inside HTC Desire?
I've tried any arm7* but it's the same... "not found".
Any ideas?

@azatoth
I get the same on my hero. Tried to run it on a other arm device (Linksys NSLU2) the same "not found" appears

mopodo said:
@azatoth
I get the same on my hero. Tried to run it on a other arm device (Linksys NSLU2) the same "not found" appears
Click to expand...
Click to collapse
Do you have found a solution for that?

I have no real way to test this, but the Snapdragon is a Cortex-A8 I believe... Try the following:
Code:
-mcpu=cortex-a8 -mfpu=neon
I hope this works, let me know if the behavior changes...

Vermithrax said:
I have no real way to test this, but the Snapdragon is a Cortex-A8 I believe... Try the following:
Code:
-mcpu=cortex-a8 -mfpu=neon
I hope this works, let me know if the behavior changes...
Click to expand...
Click to collapse
don't work yet... the response is always the same: not found...

you are linking to the wrong libc, you have to link to bionic... Are you using the full android build compiler?

Related

Howto get WiFi running on Ubuntu

Hey,
first of all, thanks to ph84 for helping me getting the wireless drivers running and all the others who take part on developing Linux on Folio 100.
After this HowTo you'll be able to use wireless on your Folio!
Just follow this post, but add "build-essential" to the --seed part of the rootstock command to get gcc basic libraries for building applications on the folio!
Download the latest version of the compat wireless drivers and the firmware
Put the sd-card/usb-stick in your computer where you extracted your rootstock image to
Extract the wireless drivers source to whatever directory you want
Copy the folio kernel source to /lib/modules/2.6.32.9/build
Extract the ath6kl folder from the firmware tar-file to /lib/firmware
Rename the bdata.SD31.bin to bdata.CUSTOM.bin (needs root access)
Then safely plug out your sd-card/usb-stick, put it into your folio and start it
Open up a shell and browse to the folder where you extracted the driver source to ($ cd /home/ubuntu/compat-wireless-2.6.39-rc1-3/)
select the drivers ($ ./scripts/driver-select ath6kl)
build the driver ($ make)
install the driver ($ sudo make install)
restart and your wireless adapter should be present in network manager
The only problem which is still open is that you aren't able to connect to your WPA-Access-Point directly.
You have to add your Wireless-LAN manually in the network manager..
Have fun with that
Hope we will get the sound and so on running soon!
Thx to erazor & ph84... they had make a great job.
hey EraZoR could you post the files from the build please? i dont have my folio handy and i only have the driver there...
it should be some files called compat-wireless*.so or so...
also, the firmware would be really usefull.
then i can put that in the howto and users dont have to compile for themselves (which takes about 700mb for sources and a lot for build-essential)...
Hi there
first of all thanks for your great work,
I'm trying to get wifi working on my ubuntu installation but i got stuck at step 10 when builiding the drivers. Do I have to copy any additional files or change settings?
make runs into these errors:
Code:
make -C /lib/modules/2.6.32.9/build M=/home/Philipp/compat-wireless-2.6.39-rc1-3 modules
make[1]: Entering directory `/lib/modules/2.6.32.9/build'
ERROR: Kernel configuration is invalid.
include/linux/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.
WARNING: Symbol version dump /lib/modules/2.6.32.9/build/Module.symvers
is missing; modules will have no dependencies and modversions.
make[1]: Leaving directory `/lib/modules/2.6.32.9/build'
it would be great if you could provide your buit files, I don't have to compile them myself though
Saint9192 said:
Hi there
first of all thanks for your great work,
I'm trying to get wifi working on my ubuntu installation ...
Click to expand...
Click to collapse
How have you installed ubuntu? I don't found *.rar file to complete ph84 howto.
gipposat said:
How have you installed ubuntu? I don't found *.rar file to complete ph84 howto.
Click to expand...
Click to collapse
I didn't found it either, so just left this step out .
I have used the attached .zip file to flash the tablet.
I found this one in a post from ph84 in DerArtem's Linux HowTo in this forum
when I tried to create a root file system using rootstock, I got an error while installing xulrunner, so I left out the
Code:
--seed xubuntu-desktop
parameter and just added the build-essential package via chroot.
result:
I don't have a GUI but I'm able to log into an runnig ubuntu
gipposat said:
How have you installed ubuntu? I don't found *.rar file to complete ph84 howto.
Click to expand...
Click to collapse
I did a ubuntu-minimal with the seed command and got a running Ubuntu system but only with shell access.
Sent from my HTC Desire using XDA Premium App
°EraZoR° said:
Hey,
...
Copy the folio kernel source to /lib/modules/2.6.32.9/build
...
Click to expand...
Click to collapse
Hi,
I haven't in my *.img file a folder /lib/modules/2.6.32.9/build, I just have /lib/modules; I have to create it or am I missing something?
Of what is shown on the link folio kernel source, I have to copy all or just the kernel folder?
Thanks
gipposat said:
Hi,
I haven't in my *.img file a folder /lib/modules/2.6.32.9/build, I just have /lib/modules; ...
Click to expand...
Click to collapse
Same thing for me.
You shuld just create the folder. As for what to download, there shuld be a link somewhere near the top of the page that says "download" and that will give you all you need. (The file list you see below is what is in the download, it is the source for the kernel and all the modules it needs)
Sent from my HTC Desire using XDA Premium App
Problem with make driver
I used rootstock with only "--seed build-essential", I got a .img file and created a sdcard. Then I have added wifi driver just like this HowTo; I have created a new "/2.6.32.9/build" folder and I copied all "folio kernel source". So I have a running Ubuntu system (only with shell access) but at step 10 when builiding the drivers I have this error:
"config.mk:204: WARNING: CONFIG_CFG80211_WEXT will be deactivated or not working because kernel was compiled with CONFIG_WIRELESS_EXT=n. Tools using wext interface like iwconfig will not work. To activate it build your kernel e.g. with CONFIG_LIBIPW=m."
FATAL: Could not load /lib/modules/2.6.32.9/modules.dep: No such file or directory.
FATAL: Could not load /lib/modules/2.6.32.9/modules.dep: No such file or directory.
...
What did I do wrong?
Thanks
gipposat;13007124
said:
...
when builiding the drivers I have this error:
"config.mk:204: WARNING: CONFIG_CFG80211_WEXT will be deactivated or not working because kernel was compiled with CONFIG_WIRELESS_EXT=n. Tools using wext interface like iwconfig will not work. To activate it build your kernel e.g. with CONFIG_LIBIPW=m."
FATAL: Could not load /lib/modules/2.6.32.9/modules.dep: No such file or directory.
FATAL: Could not load /lib/modules/2.6.32.9/modules.dep: No such file or directory.
...
Click to expand...
Click to collapse
I get exactly the same errors
when running on your folio, do a
$cp /proc/config.gz /some/dir
$tar xvf /some/dir/proc.gz
$cp /some/dir/.config /your/folio/sources/
and retry the build. otherwise it "looks" like you dont have that stuff built into the kernel because were using our own kernel configuration (because its a folio )
good luck
Hello, I get this error when I try to build the driver :
CC /home/azer/w/compat/compat.mod.o
/home/azer/w/compat/compat.mod.c:8: error: variable ‘__this_module’ has initializer but incomplete type
/home/azer/w/compat/compat.mod.c:9: error: unknown field ‘name’ specified in initializer
/home/azer/w/compat/compat.mod.c:9: warning: excess elements in struct initializer
/home/azer/w/compat/compat.mod.c:9: warning: (near initialization for ‘__this_module’)
/home/azer/w/compat/compat.mod.c:10: error: unknown field ‘init’ specified in initializer
/home/azer/w/compat/compat.mod.c:10: warning: excess elements in struct initializer
/home/azer/w/compat/compat.mod.c:10: warning: (near initialization for ‘__this_module’)
/home/azer/w/compat/compat.mod.c:14: error: unknown field ‘arch’ specified in initializer
/home/azer/w/compat/compat.mod.c:14: error: ‘MODULE_ARCH_INIT’ undeclared here (not in a function)
/home/azer/w/compat/compat.mod.c:14: warning: excess elements in struct initializer
/home/azer/w/compat/compat.mod.c:14: warning: (near initialization for ‘__this_module’)
make[2]: *** [/home/azer/w/compat/compat.mod.o] Error 1
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/lib/modules/2.6.32.9/build'
make: *** [modules] Error 2
Click to expand...
Click to collapse
Can somebody help to solve the problem please?
ph84 said:
when running on your folio, do a
$cp /proc/config.gz /some/dir
$tar xvf /some/dir/proc.gz
$cp /some/dir/.config /your/folio/sources/
Click to expand...
Click to collapse
This didn't work for me I still get the "kernel configuration invalid error"
Could somebody help me
gipposat said:
I used rootstock with only "--seed build-essential", I got a .img file and created a sdcard. Then I have added wifi driver just like this HowTo; I have created a new "/2.6.32.9/build" folder and I copied all "folio kernel source". So I have a running Ubuntu system (only with shell access) but at step 10 when builiding the drivers I have this error:
"config.mk:204: WARNING: CONFIG_CFG80211_WEXT will be deactivated or not working because kernel was compiled with CONFIG_WIRELESS_EXT=n. Tools using wext interface like iwconfig will not work. To activate it build your kernel e.g. with CONFIG_LIBIPW=m."
FATAL: Could not load /lib/modules/2.6.32.9/modules.dep: No such file or directory.
FATAL: Could not load /lib/modules/2.6.32.9/modules.dep: No such file or directory.
...
What did I do wrong?
Thanks
Click to expand...
Click to collapse
Type "sudo depmod -a" in a console, press enter and voilà.
zoken4 said:
Type "sudo depmod -a"
Click to expand...
Click to collapse
thanks zoken4 that worked like a charm ,
do you have any suggests about the invalid kernel configuration error i mentioned before
Saint9192 said:
thanks zoken4 that worked like a charm ,
do you have any suggests about the invalid kernel configuration error i mentioned before
Click to expand...
Click to collapse
You're welcome.
For the configuration error, you have to run "sudo make oldconfig && make prepare" in "/lib/modules/2.6.32.9/build/".
In a terminal : "cd /lib/modules/2.6.32.9/build/", and then "sudo make oldconfig && make prepare".
You'll maybe also have to run "sudo make scripts" after that.
ok I'll give it a try and report back
Ok I have the same error that all of you...
What are we doing wrong ??????
Solutions ?? ?!
thanks !

[HOWTO] Compile modules for stock kernels

I couldn't figure out how to compile a module for stock kernel - I kept getting the following in dmesg:
Code:
<module>: disagrees about version of symbol module_layout
I sent a message to Samsung Open Source Release Center on Friday and received a very helpful response yesterday. Basically, c1_rev02_defconfig contains some debug options that are not set in the actual kernel. These are the options that should not be set in the config:
Code:
CONFIG_DEBUG_PREEMPT
CONFIG_DEBUG_RT_MUTEXES
CONFIG_DEBUG_SPINLOCK
CONFIG_DEBUG_MUTEXES
CONFIG_PROFILING
CONFIG_PERF_EVENTS
CONFIG_PERF_COUNTERS
CONFIG_LATENCYTOP
CONFIG_FTRACE
You can use the attached script to modify all these values (the script was also supplied by Samsung, although it was syntactically incorrect and a couple of modifications were necessary to make it work). I have included a copy of the c1_rev02_defconfig with these modifications.
Using this config, I was finally able to compile modules that can actually be loaded on the device
Kudos to Samsung for sending me this information.
Nice info I guess that will help out the people who had issues with kernel modules on stock ROMs...
jps1974 said:
Kudos to Samsung for sending me this information.
Click to expand...
Click to collapse
No, that is the stuff they should put on their server. Makes you wonder what else they haven't released. Every time they make modifications to the GPL open source code (eg. kernel) and release a new version, they must release the code, and the exact same files they used to build it.
Thanks
That was the info I missed. I have successfully compiled cifs for kf1.
Sent from my GT-I9100 using XDA App
You know guys if there is a basic tutorial available online?.
Thank you!
Hi, I am new to compile modules for android (new to compile kernel anyway)
thanks for your info and config, I am now able to compile modules.
I had a problem on the compiled modules tho, wonder can anyone please point me some direction?
when I insmod the ko, dmesg gives me:
xyz.ko : no symbol version for module_layout
Any hint?
more info, I am compiling like:
I am aiming on compiling to for stock ROM, uname -r > 2.6.35.7-I9100XWKDD-CL161513
- I read, and follow base on http://forum.xda-developers.com/showthread.php?t=1113191
- kernel source from: SHW-M250L kernel source from OSRC, https://opensource.samsung.com/
- .config file of this post, select my wanted modules using make menuconfig
- then make ARCH=arm CROSS_COMPILE=__MYPATH__/bin/arm-none-eabi- modules
Thanks!
Hi,
I'm using insecure kernel :
Code:
#uname -r
2.6.35.7-I9100XWKE2-CL187606
I cross compiled modules using your config file but each time I'm trying to insmod it, I have: failed (Exec format error)
and busybox insmod gives me a invalid module format error
I use the commands :
Code:
make ARCH=arm CROSS_COMPILE=/opt/toolchains/arm-2009q3/bin/arm-none-linux-gnueabi- menuconfig
make ARCH=arm CROSS_COMPILE=/opt/toolchains/arm-2009q3/bin/arm-none-linux-gnueabi- modules
So I don't really know where I'm wrong here
alx5962 said:
Hi,
I'm using insecure kernel :
Code:
#uname -r
2.6.35.7-I9100XWKE2-CL187606
I cross compiled modules using your config file but each time I'm trying to insmod it, I have: failed (Exec format error)
and busybox insmod gives me a invalid module format error
I use the commands :
Code:
make ARCH=arm CROSS_COMPILE=/opt/toolchains/arm-2009q3/bin/arm-none-linux-gnueabi- menuconfig
make ARCH=arm CROSS_COMPILE=/opt/toolchains/arm-2009q3/bin/arm-none-linux-gnueabi- modules
So I don't really know where I'm wrong here
Click to expand...
Click to collapse
can you do a dmesg here?
I "think" I am on a same boat as you are on the error tho.....
I didn't checked dmesg, shame on me !
so the error is :
joydev: no symbol version for module_layout
I used your config file, do I need to fix config each time I update with menuconfig ?
alx5962 said:
I didn't checked dmesg, shame on me !
so the error is :
joydev: no symbol version for module_layout
I used your config file, do I need to fix config each time I update with menuconfig ?
Click to expand...
Click to collapse
dmesg is good to read, we are both compiling the same module (joydev)
the config file is not from me, is from jps1974.
no I don't think you need to fix unless you uses the build_kernel.sh unmod, since it cp the defconfig everytime, still I face the same problem...
Instead of SHW-M250L kernel source from OSRC, I just did a quick change to GT-I9100_HK_Opensource.zip
A little bit different on the package, but still the same work flow and results...
.config file:
cp ~/sgs2/9100i_hk/arch/arm/configs/c1_rev02_defconfig ~/sgs2/9100i_hk/kernel/.config
./fix_config.sh
make ARCH=arm CROSS_COMPILE=[PATH_TO_G++LITE_BIN] modules
compile without problem, but no luck, insmod still report:
insmod: init_module '/lib/modules/joydev.ko' failed (Exec format error)
dmesg | grep joy report:
joydev: no symbol version for module_layout
Any help, any directions?
Thanks in advance!!!
I used the european I9100 source from the samsung site and the config file from the opening post when I successfully compiled my modules.
Sent from my GT-I9100 using XDA App
richyy74 said:
I used the european I9100 source from the samsung site and the config file from the opening post when I successfully compiled my modules.
Sent from my GT-I9100 using XDA App
Click to expand...
Click to collapse
YES SIR, will do try this src next!!!!!
richyy74 would u mind share with us which kernel are you at on your phone?
and which version of toolchain u are using on the compile?
Thanks.
A bit of update, just try with GT-I9100_Opensource.zip, nope, still no luck........
I start to think would that be problem of toolchain (which in the readme of the zip from Samsung, they are using 2009q3 while I am using the current 2011 build), or it is possible problem because my/our unsecure kernel (2.6.35.7-I9100XWKDD-CL161513)...
update: Roll back on 2009q3, nope, no luck.............
I can only thinks that it is due to the kernel I am using.............
I compiled for ke7 and kf1 cifs, slow-work and cpu governor modules.
I used the 2009 gnu/linux toolchain from codesourcery /it ends with 67 something/
I never succeded with the version mentioned in the readme.
Sent from my GT-I9100 using XDA App
richyy74 said:
I compiled for ke7 and kf1 cifs, slow-work and cpu governor modules.
I used the 2009 gnu/linux toolchain from codesourcery /it ends with 67 something/
I never succeded with the version mentioned in the readme.
Sent from my GT-I9100 using XDA App
Click to expand...
Click to collapse
Thanks for your direction, will do more test after my "should have slept" 5 hours session.... which end up in data center instead of bed...
utp said:
Thanks for your direction, will do more test after my "should have slept" 5 hours session.... which end up in data center instead of bed...
Click to expand...
Click to collapse
The "exec format error" means that you compiled it for the wrong architecture.
To see which arch the kernel module was compiled for, 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.
So, at a terminal, type:
Code:
file -k /user/home/output/example.ko
It should output information on the file, which will clarify whether it was statically built, which architecture, etc. Examples:
Dynamically linked executable:
Code:
"ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped"
Statically linked executable:
Code:
"ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped"
Object file:
Code:
"ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped"
Most importantly, if it doesn't say 32bit ARM, it will not work.
So the module I cross-compiled gives me :
joydev.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped.
So it was correctly compiled, I may need to try another toolchain.
Using Sourcery G++ Lite 2009q3-68 for ARM EABI toolchain, still have the issue.
So as I use an insecure kernel, I may need to ask the author what compiler he used for it.

Best way to compile Busybox?

After searching around , it seems there are several ways to compile Busybox.
Codesourcery toolchain direct compile method
http://mobisocial.stanford.edu/news/2011/02/compile-busybox-on-android-os/
http://omappedia.org/wiki/Android_Installing_Busybox_Command_Line_Tools
Running make gives:
gcc: error trying to exec 'cc1': execvp: No such file or directory
What exact folder belongs in the path?
What exact statement belongs for the cross compiler prefix in make menuconfig?
Source integration method
https://github.com/Gnurou/busybox-android
This method wants you to include the files with the android source and rebuild.
Is there a way to instead compile this directly?
Scripted NDK compile method
http://matrixrewriter.com/wiki/tiki-index.php?page=Building+BusyBox+binaries+for+Android
This method goes well until near the end of the script when the script returns:
/usr/include/string.h.274: error: expected ')' before '!=' token
I am completely lost after searching for this error.
Which of these three methods, if any, is best? Is there another easier way?

[Q] Run Linux execute file on Android

Hello I Want to run This File in my phone (via terminal emulator).
but after type ./amxxpc i have error
line 1: syntax error: unexpected "("
how i can fix that?
File witch I Want to start is in scripting.zip
Bump!
cheqolada said:
Hello I Want to run This File in my phone (via terminal emulator).
but after type ./amxxpc i have error
line 1: syntax error: unexpected "("
how i can fix that?
File witch I Want to start is in scripting.zip
Click to expand...
Click to collapse
Not possible.
a) The file is compiled for the wrong architecture and can only be executed on a Intel 386 type machine.
b) The file is linked with the GNU libraries, and can not be executed in the Android (bionic) environment.
You need to solve those two issues by recompiling it for the ARM architecture using the Android bionic libraries.
Try to get source and to compile for your device.

[Q] Cross compiling Python module using Android gcc Long bit error

I am attempting to compile Python along with the modules "openssl pil zope2" for Android using the "Python-for-android" project (https://github.com/kivy/python-for-android).
However it is not successful and errors out with the below error:
Code:
Getting distribution for 'zope.security==3.7.4'.
In file included from
/home/zac/Documents/Projects/Apps/python-for-android/build/hostpython/Python-2.7.2/Include/Python.h:58:0,
from src/zope/security/_proxy.c:19:
/home/zac/Documents/Projects/Apps/python-for-android/build/hostpython/Python-2.7.2/Include/pyport.h:849:2:
error: #error "LONG_BIT definition appears wrong for platform (bad
gcc/glibc config?)."
[B]#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc
config?)."[/B]
^
src/zope/security/_proxy.c: In function 'init_proxy':
src/zope/security/_proxy.c:1006:3: warning: dereferencing type-punned
pointer will break strict-aliasing rules [-Wstrict-aliasing]
Py_INCREF(&SecurityProxyType);
^
error: Setup script exited with error: command
'arm-linux-androideabi-gcc' failed with exit status 1
An error occurred when trying to install zope.security 3.7.4. Look
above this message for any errors that were output by easy_install.
While:
Installing test.
Getting distribution for 'zope.security==3.7.4'.
Error: Couldn't install: zope.security 3.7.4
What I am wondering is if anyone else has ever had a similar issue when trying to use the Android gcc, I have build zope.security just fine using the ARM gcc so it is not a platform issue but some bug/issue with the provided Android gcc in the NDK

Categories

Resources