ncurses/htop cross compile - G1 Android Development

I'm not sure if this is the right forum but I figured I'd ask. I'm trying to get an ARM compiled version of htop working for my dream (more as a small test than anything) and I can't seem to get the ncurses libs and headers recognized for compiling htop.
I did get ncurses compiled using:
Code:
CC=/root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-gcc CXX=/root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-g++ \./configure arm-linux --host=arm-none-linux-gnueabi --with-shared --prefix=/root/mydroid/arm-2009q1 --disable-big-core --enable-termcap --disable-GPM--without-ada
the build seemed to go fine after the compile and the binaries are in fact reporting to be the correct arch:
Code:
# file lib/libncurses.so.5.7
lib/libncurses.so.5.7: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped
Then on to the configure of htop:
Code:
CPPFLAGS=-I/root/mydroid/arm-2009q1/include LDFLAGS=-I/root/mydroid/arm-2009q1/lib \./configure CC=/root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-gcc CXX=/root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-g++ --host=arm --build=arm-linux
I ran into a couple path issues with includes from curses.h but I was able to get past this using full path.
The build however fails misserably unable to find -lcurses
Code:
configure:21591: checking for refresh in -lncurses
configure:21626: /root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-gcc -o conftest -g -O2 -I/root/mydroid/arm-2009q1/include -I/root/mydroid/arm-2009q1/libconftest.c -lncurses -lm >&5
/root/mydroid/arm-2009q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lncurses
collect2: ld returned 1 exit status
That's all the drivel ... I was wondering if someone could kick me in the right direction for how to tell the cross compiler linker where the curses libraries are? I know on the base system I can use ldconfig etc but the ldconfig in the toolchain (all of them) appear to be an ARM binary
Code:
# find . -name ldconfig -exec file {} \;
./arm-none-linux-gnueabi/libc/usr/lib/bin/ldconfig: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
./arm-none-linux-gnueabi/libc/armv4t/usr/lib/bin/ldconfig: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
./arm-none-linux-gnueabi/libc/armv4t/sbin/ldconfig: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
./arm-none-linux-gnueabi/libc/thumb2/usr/lib/bin/ldconfig: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
./arm-none-linux-gnueabi/libc/thumb2/sbin/ldconfig: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
./arm-none-linux-gnueabi/libc/sbin/ldconfig: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
Anyone have any pointers or better ways to set up dev environments for cross-compiling? Or any ideas what I'm doing wrong? So far anything I've come up with is a cludge and not the right way of doing it I'm sure

I'm not sure about the right way to do this, but the path can be specified with -L, pretty much like the include path is specified with -I.
Cross-compiling packages isn't an easy task, as a lot of them depend on broken tools like libtool..

Zappletoo said:
I'm not sure about the right way to do this, but the path can be specified with -L, pretty much like the include path is specified with -I.
Cross-compiling packages isn't an easy task, as a lot of them depend on broken tools like libtool..
Click to expand...
Click to collapse
lmao ... one of my friends was a developer for libtool (Gord Matzigkeit) ... I think even he thought it needed to evolve .... I'll try more options tomorrow and see if I can pop in the -L option, might just have to get creative
Thanks!

I just built htop static vs uclibc for my latest build. I got tired of trying to make ncurses and bionic play nice together.

Try CFLAGS instead of CPPFLAGS, and use -L under LDFLAGS for the library include path instead of -I

cyanogen said:
I just built htop static vs uclibc for my latest build. I got tired of trying to make ncurses and bionic play nice together.
Click to expand...
Click to collapse
lol ... well there goes that one I was building this to use on your rom to hopefully help troubleshoot (not that there aren't enough tools already included, and not that there are a lot of issues ). Meh ... still a good learning experience for if i ever get any other ideas on trying to help/contribute/give feed back
I'll still see if I can get anything successfully built without having to mangle patches to get the compiles to play nice. Either way my assumption is even if I do get something built, yours will be a tighter binary.
Thanks again everyone, I'll post any progress if I get anywhere for posterity.

pokey9000 said:
Try CFLAGS instead of CPPFLAGS, and use -L under LDFLAGS for the library include path instead of -I
Click to expand...
Click to collapse
Well for what it's worth I did get it built with the help of this post and some more mangling.
Actual configure string:
Code:
htop-0.8.3# ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes CFLAGS=-I/root/mydroid/arm-2009q1/include LDFLAGS=-L/root/mydroid/arm-2009q1/lib \./configure CC=/root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-gcc CXX=/root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-g++ --host=arm --build=arm-linux --with-shared --disable-big-core --enable-termcap --disable-GPM --without-ada
After this the make ran with 0 issues ... after pushing the file to the phone however I still can't execute it. Luckily strace existed, sadly it's great for one offs but not great for real debugging .. what I get from the trace is:
Code:
# pwd && busybox ls -lh htop && strace /system/htop
/system
-rwxrwxrwx 1 0 0 164.3K Aug 13 13:04 htop
execve("/system/htop", ["/system/htop"], [/* 11 vars */]) = -1 ENOENT (No such file or directory)
write(2, "strace: exec", 12strace: exec) = 12
write(2, ": ", 2: ) = 2
write(2, "No such file or directory", 25No such file or directory) = 25
write(2, "\n", 1
) = 1
io_submit(1, -1344067161, {...} <unfinished ... exit status 1>
It would seem I have a lot more to learn than what I thought lol

SpEnTBoY said:
Well for what it's worth I did get it built with the help of this post and some more mangling.
Actual configure string:
Code:
htop-0.8.3# ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes CFLAGS=-I/root/mydroid/arm-2009q1/include LDFLAGS=-L/root/mydroid/arm-2009q1/lib \./configure CC=/root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-gcc CXX=/root/mydroid/arm-2009q1/bin/arm-none-linux-gnueabi-g++ --host=arm --build=arm-linux --with-shared --disable-big-core --enable-termcap --disable-GPM --without-ada
After this the make ran with 0 issues ... after pushing the file to the phone however I still can't execute it. Luckily strace existed, sadly it's great for one offs but not great for real debugging .. what I get from the trace is:
Code:
# pwd && busybox ls -lh htop && strace /system/htop
/system
-rwxrwxrwx 1 0 0 164.3K Aug 13 13:04 htop
execve("/system/htop", ["/system/htop"], [/* 11 vars */]) = -1 ENOENT (No such file or directory)
write(2, "strace: exec", 12strace: exec) = 12
write(2, ": ", 2: ) = 2
write(2, "No such file or directory", 25No such file or directory) = 25
write(2, "\n", 1
) = 1
io_submit(1, -1344067161, {...} <unfinished ... exit status 1>
It would seem I have a lot more to learn than what I thought lol
Click to expand...
Click to collapse
Did you solved your "-1 ENOENT (No such file or directory)write(2, "strace: exec", 12strace: exec)" error ?
I have the same problem cross compiling zsh :/
EDIT : solved by static linking

drakaz said:
Did you solved your "-1 ENOENT (No such file or directory)write(2, "strace: exec", 12strace: exec)" error ?
I have the same problem cross compiling zsh :/
Click to expand...
Click to collapse
Don't try to compile static binaries linked with glibc as this will not work
and is not supposed to work, because gnu libc links in other dynamic libraries
(libnss* and others) so what you obtain is not a really static library that fails
because it is looking for other dynamic libraries (ENOENT). Use uClibc for static builds.

can you please upload the compiled htop file? i cant compile myself.

Related

Got agcc, got Android source compiled, got Hello, World to work. How to do bash?

How do I port bash? DO I just export CC=~/bin/agcc and run make?
Is this the same with any console application I wish to port onto Android?
Where I'm at:
I got Hello, world! to work. The a.out binary gave this output warning during ld linkage - but the a.out binary ran on my Android phone under console emulation for sure!
Code:
[email protected]:~/mydroid/xdev$ cat hello.c
#include <stdio.h>
int main() {
printf("Hello, world!\n");
}
[email protected]:~/mydroid/xdev$ agcc hello.c
/home/kinesis/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: warning: /tmp/ccpQIsji.o uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
[email protected]:~/mydroid/xdev$ file a.out
a.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[email protected]:~/mydroid/xdev$
I can confirm that bash will work using this guide and the CodeSourcery G++ toolkit.
http://www.kbrandt.com/2009/06/how-to-cross-compile-the-bash-shell-for-android-15.html
The joy one feels after executing their own ARM bash binary is priceless.

[Tutorial] How to compile a kernel module outside the kernel

I've decided to make a short tutorial and present the way I compile kernel modules (outside the kernel sources).
I've built few kernel modules (governors - ineractive and smartass, cifs, nls, etc) and I started receiving private messages asking how I did it.
For kernel modules that come with the kernel itself - cifs / tun for example - they just work if you compile the kernel and activate correct config parameters.
Some other modules (such as the smartass governor that doesn't come with the kernel) you compile outside the kernel source. However they require changes since kernel does not export the symbols the module needs to use - so you have to know what k_all_syms are needed, grab them from the phone and update the kernel module.
So there will be changes there. However, the main steps are:
a) follow tutorials to get the kernel / android ndk to compile. People seem able to do this.
b) then take the module you want (For example cpufreq_smartass.c from here: http://pastebin.com/rR4QUCrk ) and copy it in a new folder on the disk.
c) create a Makefile like the one below, but with your paths of course:
Code:
KERNEL_DIR=/home/viulian/android_platform/kernel-2.1.A.0.435/kernel
obj-m := cpufreq_smartass.o
PWD := $(shell pwd)
default:
$(MAKE) ARCH=arm CROSS_COMPILE=/home/viulian/android_platform/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) clean
d) execute make
Of course, the module source needs to be adjusted as you need to put in the frequencies, and also update the k_all_syms pointers .. But you can retrieve them from /proc/kallsyms on the device itself - just look for the method name, and use the address you see in the log.
If you still can't get it to compile, try to compile a very basic hello_world kernel module. I used the code below when testing:
Code:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
MODULE_LICENSE("GPL");
MODULE_AUTHOR("viulian, 2011");
MODULE_DESCRIPTION("Demo module for X10i");
int init_module(void)
{
printk("<1>Hello world\n");
// A non 0 return means init_module failed; module can't be loaded.
return 0;
}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}
It is not perfect, but if you manage to insmod-it and check dmesg, you will see "Hello world" written there.
One more thing, linux kernel is fussy about the module versions. Even if nothing is changed between two kernel versions related to what a module needs, is enough a small difference in module's modinfo value to make the kernel to refuse the module.
For this, you need to trick your local kernel and adjust EXTRAVERSION value in kernel's main Makefile to have the exact version of the one on the device:
In X10 stock kernel (GB 2.3.3 release), the kernel version is 2.6.29-00054-g5f01537 visible in phone settings.
This means that the kernel on the phone will only accept modules that are compiled for that exact version. But the kernel version is just a string in the module .ko, so is a string comparison - the module might work perfectly, but is not loaded.
There is luck though, the string value comes from a define in kernel's Makefile, which you can change before you compile!
The Makefile in the kernel you are going to use to build the module will have to include these lines at the top:
Code:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 29
EXTRAVERSION = -00054-g5f01537
Other than that, it should work .. Expect phone reboots and difficulty to debug if stuff goes wrong. Android kernel doesn't come with syslog functionality, kernel prints are found in /proc/kmsg. Dmesg works, but you can't execute if if phone reboots.
I usually had to keep another adb shell opening with 'cat /proc/kmsg' which showed as much as possible from the module's outputs.
Happy compiling on your risk!
Good
Sent from my GT-S5570 using Tapatalk
Nice really nice.
Anyone help me.have someone who could compile the linux bluetooth modules please? Iam noob in linux
http://www.multiupload.com/58OPISAYNH
Anyone please can make a video tutorial?
That's really nice of you for sharing this.
Guide to Compiling Custom Kernel Modules in Android
I've spent the better part of today trying to figure out how to compile and load a custom kernel modules in android to aid me in my research. It has been in entirely frustrating experience, as there is almost no documentation on the topic that I can find. Below you will find my attempt at a guide. Hopefully this will help save someone else the hassle.
PREREQUISITES
Disclaimer: This list may be incomplete, since I've not tried it on a fresh install. Please let me know if I've missed anything.
Install the general android prereqs found here .
Download and un(zip|tar) the android NDK found here .
http://developer.android.com/sdk/ndk/index.html
Download and un(zip|tar) the android SDK found here .
http://developer.android.com/sdk/index.html
Download and untar the kernel source for your device. This can usually be found on the website of your device manufacturer or by a quick Google search.
Root your phone. In order to run custom kernel modules, you must have a rooted phone.
Plug your phone into your computer.
PREPARING YOUR KERNEL SOURCE
First we must retrieve and copy the kernel config from our device.
Code:
$ cd /path/to/android-sdk/tools
$ ./adk pull /proc/config.gz
$ gunzip ./config.gz
$ cp config /path/to/kernel/.config
Next we have to prepare our kernel source for our module.
Code:
$ cd /path/to/kernel
$ make ARCH=arm CROSS_COMPILE=/path/to/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- modules_prepare
PREPARING YOUR MODULE FOR COMPILATION
We need to create a Makefile to cross-compile our kernel module. The contents of your Makefile should be similar to the following:
Code:
obj-m := modulename.o
KDIR := /path/to/kernel
PWD := $(shell pwd)
CCPATH := /path/to/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
COMPILING AND INSTALLING YOUR MODULE
Code:
$ cd /path/to/module/src
$ make
$ cd /path/to/android-sdk/tools/
$ ./adb push /path/to/module/src/modulename.ko /sdcard/modulename.ko
RUNNING YOUR MODULE
Code:
$ cd /path/to/android-sdk/
$ ./adb shell
$ su
# insmod /sdcard/modulename.ko
---------- Post added at 07:40 PM ---------- Previous post was at 07:37 PM ----------
IMPORNTANT TOO
Preparing a build environment
To build an Android kernel, you need a cross-compiling toolchain. Theoretically, any will do, provided it targets ARM. I just used the one coming in the Android NDK:
$ wget http://dl.google.com/android/ndk/android-ndk-r6b-linux-x86.tar.bz2
$ tar -jxf android-ndk-r6b-linux-x86.tar.bz2
$ export ARCH=arm
$ export CROSS_COMPILE=$(pwd)/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
For the latter, you need to use a directory path containing prefixed versions (such as arm-eabi-gcc orarm-linux-androideabi-gcc), and include the prefix, but not “gcc”.
You will also need the adb tool coming from the Android SDK. You can install it this way:
$ wget http://dl.google.com/android/android-sdk_r12-linux_x86.tgz
$ tar -zxf android-sdk_r12-linux_x86.tgz
$ android-sdk-linux_x86/tools/android update sdk -u -t platform-tool
$ export PATH=$PATH:$(pwd)/android-sdk-linux_x86/platform-tools
not yet ((((
Come on, please make video tuto
that's interesting.
Thanks for sharing
Any takers to do a video status? Come on people it would be good for newbies like me and many that tme around. When teaching the community grows.
hi
i'm traing to compile module for acer a500.
but i have got an error: Nothing to be done for `default'.
my makefile:
Code:
obj-m += hello.o
KDIR := /home/hamster/android
PWD := $(shell pwd)
CCPATH := /home/hamster/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
acer kernel code is located in /home/hamster/android
could you help me?
thanks
Thanks man. The step "modules_prepare" is what did the trick for me!
Makefile including tabs
hamsterksu said:
hi
i'm traing to compile module for acer a500.
but i have got an error: Nothing to be done for `default'.
my makefile:
Code:
obj-m += hello.o
KDIR := /home/hamster/android
PWD := $(shell pwd)
CCPATH := /home/hamster/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
acer kernel code is located in /home/hamster/android
could you help me?
thanks
Click to expand...
Click to collapse
This is probably because you need to add a tab in front of your $(MAKE). Without the tab it will not recognize the command.
Help with compiling module
I am trying to compile a module for Galaxy S. I am getting this error.
# insmod hello_world.ko
insmod: init_module 'hello_world.ko' failed (Exec format error)
These are the module related options that I have enabled in the .config
CONFIG_MODULES=y
CONFIG_MODULE_FORCE_LOAD=y
CONFIG_MODULE_UNLOAD=y
CONFIG_MODULE_FORCE_UNLOAD=y
# CONFIG_MODVERSIONS is not set
# CONFIG_MODULE_SRCVERSION_ALL is not set
Further this is the cat /proc/kmsg out put
<3>[53597.457275] hello_world: version magic '2.6.35.7-I900XXJVP-CL264642 preempt mod_unload ARMv7 ' should be '2.6.35.7-I9000XXJVP-CL264642 preempt mod_unload ARMv7 '
Why am I getting this error??
These are the steps I followed,
1. Downloaded the GT-I9000_OpenSource_GB.zip from samsung open source.
2. Change the EXTRAVERSION to EXTRAVERSION = .7-I900XXJVP-CL264642 (kernel version shown on phone is [email protected] #2)
I tried with EXTRAVERSION = [email protected] as well.
3. Added this line to the main make file -
core-y := usr/ TestModule/
5. Place the TestModule/ with the module code on the root directory.
6. Created the TestModule/Makefile and added this entry
obj-m := hello_world.o
4. On the read me of the kernel source it says to install Sourcery G++ Lite 2009q3-68 toolchain for ARM EABI, which I did.
5. Execute 'make aries_eur_defconfig'.
6. Execute make (again this is how the readme in the source says)
I have compiled this module for the emulator and it works fine, What am I doing wrong here?
Thanks in advance.
hamsterksu said:
hi
but i have got an error: Nothing to be done for `default'.
Code:
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
Click to expand...
Click to collapse
be sure to have {tab} not space or other symbol before: $(MAKE) in:
Code:
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
Hello,
I'm trying to load a module in my GS3 but I encounter problems about version. Maybe it's just a mismatch between the kernel i use to compile and the one on my phone.
I have a 3.0.31-742798 kernel version on my GS3, so I put this info in the makefile like viulian said but it didn't work.
I manage to compile and put the module on the phone, but when I want to insmod it, I've got
Code:
insmod: init_module 'hello_world.ko' failed (Exec format error)
and the /proc/kmsg say
Code:
... disagrees about version of symbol module_layout
And there no config.gz on the /proc/ dir like fabricioemmerick suggest to use
EDIT: I try to modify the symbol by copying the one of module from the phone. Have another error.
btw , with modinfo I found that the compilation always add -gc33f1bc-dirty after the subversion. Maybe something in the compilation goes wrong. Still use the stock kernel and the toolchain from the ndk sourcecode
m00gle said:
Hello,
I'm trying to load a module in my GS3 but I encounter problems about version. Maybe it's just a mismatch between the kernel i use to compile and the one on my phone.
I have a 3.0.31-742798 kernel version on my GS3, so I put this info in the makefile like viulian said but it didn't work.
I manage to compile and put the module on the phone, but when I want to insmod it, I've got
Code:
insmod: init_module 'hello_world.ko' failed (Exec format error)
and the /proc/kmsg say
Code:
... disagrees about version of symbol module_layout
And there no config.gz on the /proc/ dir like fabricioemmerick suggest to use
EDIT: I try to modify the symbol by copying the one of module from the phone. Have another error.
btw , with modinfo I found that the compilation always add -gc33f1bc-dirty after the subversion. Maybe something in the compilation goes wrong. Still use the stock kernel and the toolchain from the ndk sourcecode
Click to expand...
Click to collapse
Maybe your kernel source code version and your phone kernel version is different. If both are 3.0.31 but just the subversion is different, you can
try "insmod -f" to load. The -f option will ignore the version.
How can I get a dmesg of a specific kernel module using adb shell or any other way?
ravike14 said:
How can I get a dmesg of a specific kernel module using adb shell or any other way?
Click to expand...
Click to collapse
I'm not sure I understand the question ... you can just dmesg and grep by the module name ? Or some string that the module outputs ? You have full control
viulian said:
I'm not sure I understand the question ... you can just dmesg and grep by the module name ? Or some string that the module outputs ? You have full control
Click to expand...
Click to collapse
That's the part I don't understand, the grep part.. When I enter grep with my commamd I get as it's not a recognized command.. I'm using Windows is that the reason?
I'm using 'adb shell dmesg > dmesg.txt' how do I add the grep part for it and and the module name.. I did alot research but all are Linux kernel specific debugging guides.. What would be the exact command to grep a specific module.ko logs?
Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app
ravike14 said:
I'm using 'adb shell dmesg > dmesg.txt' how do I add the grep part for it and and the module name.. I did alot research but all are Linux kernel specific debugging guides.. What would be the exact command to grep a specific module.ko logs?
Click to expand...
Click to collapse
I think I understand now
The order is this:
a) DroidSSHd from here: http://code.google.com/p/droidsshd/downloads/list
b) Busybox installer from the market.
c) Putty on your windows to connect to the phone
Now you can dmesg + grep once you are connected to the phone (don't forget to su before and allow DroidSSHd root).
You need to be connected to the phone since it is much more easier. Use the phone as your remote Linux machine.

[Q] executing self-compiled c/c++ code in connectbot: Syntax error: word unexpected

Hi all,
(see at the end for setup and device info)
(remove spaces in URLs since I am not allowed to post real URLs yet)
I am trying to compile my own c/c++ code and run it on my android phone.
I got the android toolchain and the program (hello world, "test" binary) compiles:
./agcc -c -o test hello.cpp
file test
test: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped
The program executable is "test". I copy it to my android to /data (since other folders apparently do not have execution permission yielding the "permission denied" error when trying to execute) and do "chmod a+x test"
When I start connectbot on my phone, navigate to /data and do "./test" then I get the error: Syntax error: word unexpected (expecting ")")
As if connectbot would try to execute this binary as a shell script.
In principle, a step-by-step manual how to compile and run c/c++ code on android would be here:
"http: //www . hytherion.com/beattidp/comput/android/linux-on-android.html"
But I get this strange error mentioned above.
any ideas?
setup:
=====
Phone: Samsung Galaxy S2
Android: 2.3.4
Kernel: GINGERBREAD.XWKI4 (rooted, works all fine)
Crosscompile Toolchain: from: ./repo init -u https: // android.googlesource.com/platform/manifest
Using acc script from "http: // plausible.org/andy/agcc"
Exporting: export PATH=[PathToToolchain]/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH
Hello World example:
// hello.cpp
#include <stdio.h>
int main()
{
int a=1;
printf("hello %d",a);
return 0;
}
compiling with: ./agcc -c -o test hello.cpp
bump bump?

Getting Working Wifi for Kernel builds

I have been buliding some kernels recently, but have been unable to get the wifi working.
I have tried it having the modules included in initramfs/lib/modules when ramdisk is created and i do mkbootimg, and have also tried just putting all the modules in the flash zip in /system/lib/modules, and excluded it from build process. Both result in no Wifi [Edit, putting the newly built correct modules in my working folders /lib/modules fixed wifi, must not have done it correctly before)
basic overview of what I've done (after zImage compile)
I use "./unpack-bootimg.pl boot.img" to pull the "ramdisk-contents" from the stock kernel, I renamed that folder "initramfs" and threw it in a folder along with my mkbootimg binary, and my zImage I just compiled.
I put the newly created modules from zImage build in my initramfs/libs/modules with
find -name '*.ko' -exec cp -av {} [path to desired folder] \;
I navigate to the initramfs folder and
find .|cpio -o -H newc > ../ramdisk
cd ..
gzip ramdisk
./mkbootimg --kernel ./zImage --ramdisk ./ramdisk.gz --board smdk4x12 --base 0x10000000 --pagesize 2048 --ramdiskaddr 0x11000000 -o boot.img
the resultant boot.img boots fine and shows all other changes, just cant seem to get the wifi working. Anyone have idea for getting wifi working on our Note 2 kernel builds?
Edit: I re-tried and this time it worked. Not sure what was different. Copied the newly created modules into my ramdisk folder (for me was /initramfs/lib/modules) and created my ramdisk.gz etc. made the boot.img and it's all good. The difference must've been having the correct modules in place prior to creating the ramdisk.cpio(then .cpio.gz).
Mods please move if you feel this is in wrong section now etc. Found the answer, thank you
It's only in the wrong section if you don't share what you did wrong, and how you fixed it.
Facing an almost similiar issue over here with the wifi modules. For me, I found that my boot.img is itself too large for initramfs to accomodate the compiled modules (optimization was off). So I put them in system/lib/modules and tried to insmod them.
Using the sbin's insmod gives me this:
Code:
[[email protected] android]$adb shell
[email protected]:/ $ su
[email protected]:/ # insmod /system/lib/modules/dhd.ko
insmod: init_module '/system/lib/modules/dhd.ko' failed (No such file or directory)
255|[email protected]:/ # busybox insmod /system/lib/modules/dhd.ko
insmod: can't insert '/system/lib/modules/dhd.ko': unknown symbol in module, or unknown parameter
2|[email protected]:/ #
I've turned off module versioning, and am not sure why there's a symbol error.
Droidzone said:
Facing an almost similiar issue over here with the wifi modules. For me, I found that my boot.img is itself too large for initramfs to accomodate the compiled modules (optimization was off). So I put them in system/lib/modules and tried to insmod them.
Using the sbin's insmod gives me this:
Code:
[[email protected] android]$adb shell
[email protected]:/ $ su
[email protected]:/ # insmod /system/lib/modules/dhd.ko
insmod: init_module '/system/lib/modules/dhd.ko' failed (No such file or directory)
255|[email protected]:/ # busybox insmod /system/lib/modules/dhd.ko
insmod: can't insert '/system/lib/modules/dhd.ko': unknown symbol in module, or unknown parameter
2|[email protected]:/ #
I've turned off module versioning, and am not sure why there's a symbol error.
Click to expand...
Click to collapse
Add --strip-debug into the LDFLAGS_MODULE of the main makefile and make sure the modules went through second stage compilation. The OS probably forwards some parameters and you can't just insmod it.
I fixed that issue..
The real reason is something queer and interesting. It was because I'd defined GREP_OPTIONS defined as '--color -in'. This seemed to interfere with the kernel scripts. Once the var was unset, problem was solved.
However the inability to load the module persists.
My main kernel has the version name "3.0.31-g5d44d80-dirty", and the vermagic of module seems to be "3.0.31-gc299ec6 SMP preempt mod_unload modversions ARMv7 p2v8".
This obviously leads to version mismatch, and inability to load the module. Do you know why this happens? The kernel and module were used from the same compilation session. In fact I havent even changed the version name in .config.
dmesg during insmod gives this error code which narrows down the issue:
Code:
c0 dhd: version magic '3.0.31-gc299ec6 SMP preempt mod_unload modversions ARMv7 p2v8 ' should be '3.0.31-g5d44d80-dirty SMP preempt mod_unload ARMv7 '
EDIT:
Maybe I had made a script error and forgot to replace the original kernel/module..That error has disappeared to be replaced by the former issue-unable to insert module. Module was compiled with debug symbols.
Insmod reports:
insmod: init_module '/system/lib/modules/dhd.ko' failed (No such file or directory)
Modprobe reports:
modprobe: chdir(3.0.31-ge52b835-dirty): No such file or directory
Kernel reports:
Code:
c0 dhd: Unknown symbol _GLOBAL_OFFSET_TABLE_ (err 0)
Trying to narrow it down to the source file. I'm expecting that some function has 'forgotten' to export symbol.
I'm wondering whether this is just me, or is Samsung source dump supposed to have these kind of errors on defconfig. First they "forget" to include cypress drivers. Now errors related to symbol export.
EDIT2:
Still no more closer to finding the cause of the error. Did a grep and these are the only things I found:
Code:
[[email protected] kernel_IN]$grep --color -inr '_GLOBAL_OFFSET_TABLE_' * | grep -v 'Binary file'
arch/powerpc/boot/crt0.S:42: addis r11,r10,(_GLOBAL_OFFSET_TABLE_-p_base)@ha
arch/powerpc/boot/crt0.S:43: lwz r11,(_GLOBAL_OFFSET_TABLE_-p_base)@l(r11)
arch/m32r/boot/compressed/head.S:39: seth r3, #high(_GLOBAL_OFFSET_TABLE_+8)
arch/m32r/boot/compressed/head.S:40: or3 r3, r3, #low(_GLOBAL_OFFSET_TABLE_+12)
arch/s390/kernel/module.c:149: "_GLOBAL_OFFSET_TABLE_") == 0)
arch/avr32/kernel/module.c:104: "_GLOBAL_OFFSET_TABLE_") == 0)
scripts/mod/modpost.c:565: if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
System.map:49417:c0b4f468 d _GLOBAL_OFFSET_TABLE_
The relevant segment of scripts/mod/modpost.c:
Code:
static int ignore_undef_symbol(struct elf_info *info, const char *symname)
{
/* ignore __this_module, it will be resolved shortly */
if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0)
return 1;
/* ignore global offset table */
if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
return 1;
Edit3: Solved.
AndreiLux said:
Add --strip-debug into the LDFLAGS_MODULE of the main makefile and make sure the modules went through second stage compilation. The OS probably forwards some parameters and you can't just insmod it.
Click to expand...
Click to collapse
I'd like to thank you for this information - this cut my dhd.ko from 4.6 MB to around 550 kB - and my resulting kernel as a result. Fully expect this will now get my kernel working as it should.
Droidzone said:
I fixed that issue..
The real reason is something queer and interesting. It was because I'd defined GREP_OPTIONS defined as '--color -in'. This seemed to interfere with the kernel scripts. Once the var was unset, problem was solved.
However the inability to load the module persists.
My main kernel has the version name "3.0.31-g5d44d80-dirty", and the vermagic of module seems to be "3.0.31-gc299ec6 SMP preempt mod_unload modversions ARMv7 p2v8".
This obviously leads to version mismatch, and inability to load the module. Do you know why this happens? The kernel and module were used from the same compilation session. In fact I havent even changed the version name in .config.
dmesg during insmod gives this error code which narrows down the issue:
Code:
c0 dhd: version magic '3.0.31-gc299ec6 SMP preempt mod_unload modversions ARMv7 p2v8 ' should be '3.0.31-g5d44d80-dirty SMP preempt mod_unload ARMv7 '
EDIT:
Maybe I had made a script error and forgot to replace the original kernel/module..That error has disappeared to be replaced by the former issue-unable to insert module. Module was compiled with debug symbols.
Insmod reports:
insmod: init_module '/system/lib/modules/dhd.ko' failed (No such file or directory)
Modprobe reports:
modprobe: chdir(3.0.31-ge52b835-dirty): No such file or directory
Kernel reports:
Code:
c0 dhd: Unknown symbol _GLOBAL_OFFSET_TABLE_ (err 0)
Trying to narrow it down to the source file. I'm expecting that some function has 'forgotten' to export symbol.
I'm wondering whether this is just me, or is Samsung source dump supposed to have these kind of errors on defconfig. First they "forget" to include cypress drivers. Now errors related to symbol export.
EDIT2:
Still no more closer to finding the cause of the error. Did a grep and these are the only things I found:
Code:
[[email protected] kernel_IN]$grep --color -inr '_GLOBAL_OFFSET_TABLE_' * | grep -v 'Binary file'
arch/powerpc/boot/crt0.S:42: addis r11,r10,(_GLOBAL_OFFSET_TABLE_-p_base)@ha
arch/powerpc/boot/crt0.S:43: lwz r11,(_GLOBAL_OFFSET_TABLE_-p_base)@l(r11)
arch/m32r/boot/compressed/head.S:39: seth r3, #high(_GLOBAL_OFFSET_TABLE_+8)
arch/m32r/boot/compressed/head.S:40: or3 r3, r3, #low(_GLOBAL_OFFSET_TABLE_+12)
arch/s390/kernel/module.c:149: "_GLOBAL_OFFSET_TABLE_") == 0)
arch/avr32/kernel/module.c:104: "_GLOBAL_OFFSET_TABLE_") == 0)
scripts/mod/modpost.c:565: if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
System.map:49417:c0b4f468 d _GLOBAL_OFFSET_TABLE_
The relevant segment of scripts/mod/modpost.c:
Code:
static int ignore_undef_symbol(struct elf_info *info, const char *symname)
{
/* ignore __this_module, it will be resolved shortly */
if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0)
return 1;
/* ignore global offset table */
if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
return 1;
Edit3: Solved.
Click to expand...
Click to collapse
How to Solved? Too detailed can you tell us a little bit?
wctliu said:
How to Solved? Too detailed can you tell us a little bit?
Click to expand...
Click to collapse
Used another toolchain.
Droidzone said:
Used another toolchain.
Click to expand...
Click to collapse
another toolchain????
Which version?
I uesd these:
/home/wctliu/toolchains/arm-eabi-4.4.3/bin/arm-eabi-
/home/wctliu/arm-2009q3/bin/arm-none-linux-gnueabi-
Which will cause the problem to occur?
wctliu said:
another toolchain????
Which version?
I uesd these:
/home/wctliu/toolchains/arm-eabi-4.4.3/bin/arm-eabi-
/home/wctliu/arm-2009q3/bin/arm-none-linux-gnueabi-
Which will cause the problem to occur?
Click to expand...
Click to collapse
Did you see and do the changes AndreiLux mentioned above to the makefile. That can be the difference of whether you get useable wifi modules. Simple place to start if your getting a working kernel but no wifi
Sent from my SPH-L900 using xda premium
sleshepic said:
Did you see and do the changes AndreiLux mentioned above to the makefile. That can be the difference of whether you get useable wifi modules. Simple place to start if your getting a working kernel but no wifi
Sent from my SPH-L900 using xda premium
Click to expand...
Click to collapse
YES i do it .
you can see this:
http://forum.xda-developers.com/showthread.php?t=2193358
and now, it's no wifi no exfat.
AndreiLux said:
Add --strip-debug into the LDFLAGS_MODULE of the main makefile and make sure the modules went through second stage compilation. The OS probably forwards some parameters and you can't just insmod it.
Click to expand...
Click to collapse
That is correct, the OS does pass parameters to the module when loading.
An example (from CM) can be seen at: https://github.com/CyanogenMod/andr...common/blob/cm-10.1/BoardCommonConfig.mk#L122
I cannot get Wifi to work either. I have the same exact problem as Droidzone with the "_GLOBAL_OFFSET_TABLE_" error.
I have checked that:
"LDFLAGS_MODULE = --strip-debug" is set in Makefile.
I'm using the 4.7 toolchain, but just tried the 4.6 to no avail.
Any help would be much appreciated.
Update: I was able to get it working by using CFLAGS_MODULE=-fno-pic as suggested in this guide.
Solved
I was running in the same issues. I solved my problem adding these to my kernel makefile:
LDFLAGS_MODULE = --strip-debug
CFLAGS_MODULE = -fno-pic
forfivo said:
I was running in the same issues. I solved my problem adding these to my kernel makefile:
LDFLAGS_MODULE = --strip-debug
CFLAGS_MODULE = -fno-pic
Click to expand...
Click to collapse
There must be something else goin on in my setup as this does not work for me to getting working WiFi. What is your build process?
Edit: or if you wouldn't mind shoot in me your kernel I'd be interested if it something small I'm missing like updater script etc
Edit2: I feel sometimes in android doing the same thing twice results in separate results. Crazy thx
Hey sorry to bump this. Not sure if anyone still remembers I have the same problem with my GT-B5330.
Even though I set in my kernel/Makefile :
CFLAGS_MODULE = -fno-pic
LDFLAGS_MODULE = --strip-debug
After building the kernel from source I get the dhd.ko file, copy it to ramdisk/lib/modules and then repack it with the zimage generated by the build.
Then i dd the newly created boot.img to the kernel partition.
lsmod doesnt show dhd.ko
and the file exists in system/lib/modules/dhd.ko
Toolchain arm-eabi-4.6
DroidFreak32 said:
Hey sorry to bump this. Not sure if anyone still remembers I have the same problem with my GT-B5330.
Even though I set in my kernel/Makefile :
CFLAGS_MODULE = -fno-pic
LDFLAGS_MODULE = --strip-debug
After building the kernel from source I get the dhd.ko file, copy it to ramdisk/lib/modules and then repack it with the zimage generated by the build.
Then i dd the newly created boot.img to the kernel partition.
lsmod doesnt show dhd.ko
and the file exists in system/lib/modules/dhd.ko
Toolchain arm-eabi-4.6
Click to expand...
Click to collapse
Are you able to test manually starting using insmod? If so, what is the result?
garwynn said:
Are you able to test manually starting using insmod? If so, what is the result?
Click to expand...
Click to collapse
I cannot insmod the module I get : /system/lib/module/dhd.ko invalid argument
DroidFreak32 said:
I cannot insmod the module I get : /system/lib/module/dhd.ko invalid argument
Click to expand...
Click to collapse
Can't get to my Linux env at the moment, but will follow up on this. Might even see if someone is willing to test for me.
garwynn said:
Can't get to my Linux env at the moment, but will follow up on this. Might even see if someone is willing to test for me.
Click to expand...
Click to collapse
Thanks man
Also I forgot to mention I use arm eabi 4.4.3 if that matters.

Static binaries will be bypass PIE in lollipod

Hi,
After researching why one binary is working in both systems (5.0 and 2.3.5) ive found that (is logic i know) static compiled binaries will be work in both versions.
The problem is that the binary will be increased in size a lot, but you don´t need to touch your application and just compile your c code and put in assets folder.
So all the static compiled binaries still will be working in both versions of Android
With the "file" command you can see if is statically compiled:
ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
This binary will work in any version of android and you have to compile with the static flag:
arm-linux-androideabi-gcc -static yourcode.c -o youbinary
I said the binary increase the size dramatically but for small binaries maybe its ok.
Regards,
Sylkat

Categories

Resources