Got agcc, got Android source compiled, got Hello, World to work. How to do bash? - Android Software/Hacking General [Developers Only]

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.

Related

ncurses/htop cross compile

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.

[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?

samba compile issue

I'm compiling samba-3.6.22 for android with the sourcery arm-2010q1 compiler. The compile itself goes fine, but when I copy smbd to my device it's not recognized as a binary. I get the error
Code:
sh: ./smbd: No such file or directory
file under linux tells me:
Code:
smbd: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
What am I overlooking?

[Resolved] [SOLVED] "[arch/x86/kernel] Error 2" Error while compiling X86 Kernel

So after I successfully install kali linux on my Galaxy tab 3 10.1 P5220 LTE, I decided to mod the original kernel from the opensource samsung site. Everything goes well until i am going to compile it with "make" or "make ARCH=i386",it keep showing the following error:
This is the error in the terminal,
Code:
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `relocs'.
CHK include/linux/version.h
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
CC arch/x86/kernel/apic/io_apic.o
cc1: warnings being treated as errors
arch/x86/kernel/apic/io_apic.c: In function 'ioapic_read_entry':
arch/x86/kernel/apic/io_apic.c:471: error: 'eu' is used uninitialized in this function
make[3]: *** [arch/x86/kernel/apic/io_apic.o] Error 1
make[2]: *** [arch/x86/kernel/apic] Error 2
make[1]: *** [arch/x86/kernel] Error 2
make: *** [arch/x86] Error 2
and this is Line 422 to line 480 of io_apic.o
Code:
static void __io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
{
struct io_apic __iomem *io_apic = io_apic_base(apic);
if (sis_apic_bug)
writel(reg, &io_apic->index);
writel(value, &io_apic->data);
}
static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
{
struct irq_pin_list *entry;
unsigned long flags;
raw_spin_lock_irqsave(&ioapic_lock, flags);
for_each_irq_pin(entry, cfg->irq_2_pin) {
unsigned int reg;
int pin;
pin = entry->pin;
reg = io_apic_read(entry->apic, 0x10 + pin*2);
/* Is the remote IRR bit set? */
if (reg & IO_APIC_REDIR_REMOTE_IRR) {
raw_spin_unlock_irqrestore(&ioapic_lock, flags);
return true;
}
}
raw_spin_unlock_irqrestore(&ioapic_lock, flags);
return false;
}
union entry_union {
struct { u32 w1, w2; };
struct IO_APIC_route_entry entry;
};
static struct IO_APIC_route_entry __ioapic_read_entry(int apic, int pin)
{
union entry_union eu;
eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
return eu.entry;
}
static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
{
union entry_union eu;
unsigned long flags;
raw_spin_lock_irqsave(&ioapic_lock, flags);
eu.entry = __ioapic_read_entry(apic, pin);
raw_spin_unlock_irqrestore(&ioapic_lock, flags);
return eu.entry;
}
so is there anything that i can do to fix this error and compile successfully? I am using Kali Linux to compile it btw. Thanks in advance!
My Suggestion, not a complain.
First I suggest you delete [Urgent] from Title. Why, because to the one that could help you that [Urgent] means nothing. In fact there is people here that may skip your thread just not to get involved in this [Urgent] matter. Sadly out TAB3 10.1 tablet has very little audience, so you never know when you question in fact will be answer, if they are answer at all.
On the original question. problem compiling X86 Kernel.
You need to compile all this kernels with gcc 4.6. If not you end up in all sort of errors. So if you had install a new Linux Distro, the first thing you need to do is to install gcc 4.6 and make it your default compilation environment.
In Ubuntu this is done with
Code:
sudo apt-get install gcc-4.6 g++-4.6 gcc-4.6-multilib g++-4.6-multilib
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
I suggest you google for help since you claim to use Kali (not Ubuntu).
You need to ensure that you use a 32bit environment!!! So in my case I do own a 64bit Desktop but I have install a 32bit version of Ubuntu to ensure maximum compatibility and less none sense errors.
Even more Readme tell us .
Code:
- get Toolchain
From google aosp(http://source.android.com/source/downloading.html)
recommend : android-4.2.2_r1 release.
But ripo of android-4.2.2_r1 release takes for ever and finally is incomplete!.
I suggest you get AndroidNDK and setup at least 4.2.2, I my self download usually "android-14" to ensure that my compilations of NDK are as compatible as it can be with older android phone models. But For Kernel Toolchain almost any one is good.
So you toolchain should be at
Code:
androidndk/toolchains/x86-4.6/prebuilt/linux-x86/bin
So your kernel Makefile modification should look like
Code:
CROSS_COMPILE ?= /<user directory>/bin/androidndk/toolchains/x86-4.6/prebuilt/linux-x86/bin/i686-linux-android-
I hope this help you and others if needed.
Now I took your last post and copied here
Jacker31 said:
Well it have been a long story, I posted a thread about my error, here : http://forum.xda-developers.com/general/help/question-error-2-error-compiling-x86-t3047439 but in the end i found out i used the wrong toolchain. So i redownloaded the correct version and try again. It works but another error popup, its about some Broadcom error. I can successfully compile it after i disabled it in menuconfig. But instead of getting a Zimage i got a Bzimage. So Idk what to do with it. I googled a tones of information but still have no idea what to do with that bzimage. I used Kali Linux to compile and those kernel files are from http://opensource.samsung.com/reception/receptionSub.do?method=sub&sub=F&searchValue=p5220 GT-P5220_SEA_KK_Opensource. Now i am trying to install builduntu and try to compile it again. Any tips or helps? especially with that bzimage
Click to expand...
Click to collapse
I have compiled the original open source kernels without errors. As why you get "Broadcom error." I do not Know. I suggest You ensure you can compile the original sources of the kernel without errors before you begin any modification.
I Know when you compile successfully you end up with bzImage inside "arch/x86/boot". This is fine. the difference between "bzImage" and "zImage" is the compression method. It is seems that the bootloader can detect and adjust to any of those formats. So you only need to rename it to where ever is you need. To include bzImage in a boot.img I use AIK as suggested by my friend moonbutt74.
http://forum.xda-developers.com/showthread.php?t=2073775
So in my case I almost always end up renaming "bzImage" to "boot.img-zImage" and placecing it inside the "AIK/split_img" folder.
r2d23cpo said:
My Suggestion, not a complain.
First I suggest you delete [Urgent] from Title. Why, because to the one that could help you that [Urgent] means nothing. In fact there is people here that may skip your thread just not to get involved in this [Urgent] matter. Sadly out TAB3 10.1 tablet has very little audience, so you never know when you question in fact will be answer, if they are answer at all.
On the original question. problem compiling X86 Kernel.
You need to compile all this kernels with gcc 4.6. If not you end up in all sort of errors. So if you had install a new Linux Distro, the first thing you need to do is to install gcc 4.6 and make it your default compilation environment.
In Ubuntu this is done with
Code:
sudo apt-get install gcc-4.6 g++-4.6 gcc-4.6-multilib g++-4.6-multilib
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
I suggest you google for help since you claim to use Kali (not Ubuntu).
You need to ensure that you use a 32bit environment!!! So in my case I do own a 64bit Desktop but I have install a 32bit version of Ubuntu to ensure maximum compatibility and less none sense errors.
Even more Readme tell us .
Code:
- get Toolchain
From google aosp(http://source.android.com/source/downloading.html)
recommend : android-4.2.2_r1 release.
But ripo of android-4.2.2_r1 release takes for ever and finally is incomplete!.
I suggest you get AndroidNDK and setup at least 4.2.2, I my self download usually "android-14" to ensure that my compilations of NDK are as compatible as it can be with older android phone models. But For Kernel Toolchain almost any one is good.
So you toolchain should be at
Code:
androidndk/toolchains/x86-4.6/prebuilt/linux-x86/bin
So your kernel Makefile modification should look like
Code:
CROSS_COMPILE ?= /<user directory>/bin/androidndk/toolchains/x86-4.6/prebuilt/linux-x86/bin/i686-linux-android-
I hope this help you and others if needed.
Now I took your last post and copied here
I have compiled the original open source kernels without errors. As why you get "Broadcom error." I do not Know. I suggest You ensure you can compile the original sources of the kernel without errors before you begin any modification.
I Know when you compile successfully you end up with bzImage inside "arch/x86/boot". This is fine. the difference between "bzImage" and "zImage" is the compression method. It is seems that the bootloader can detect and adjust to any of those formats. So you only need to rename it to where ever is you need. To include bzImage in a boot.img I use AIK as suggested by my friend moonbutt74.
http://forum.xda-developers.com/showthread.php?t=2073775
So in my case I almost always end up renaming "bzImage" to "boot.img-zImage" and placecing it inside the "AIK/split_img" folder.
Click to expand...
Click to collapse
Thanks for that reply, i already fix that error by downloading the exact same toolchain in the README_KERNEL. Now i am trying to workout why my fastboot cannot detect my p5220 and how to compile it into a flashable .zip file so i can flash it with cwm or philz.
Are you planning to release a tutorial how you managed to install kali on your galaxy tab?
Sure, I will write it how, you will see it in any minutes now.
Are you planning to release a tutorial how you managed to install kali on your galaxy tab?
Click to expand...
Click to collapse
@Max4000
http://forum.xda-developers.com/gal...-to-run-kali-linux-galaxy-tab-3-10-1-t3050203
here you go...

[TUTORIAL/REFERENCE] Building the android kernel (Mac OS)

Many people have MacBooks and they MacBooks have a terminal. This terminal runs bash and other unix commands, so why can't we compile a kernel. That's what I thought at first... Then the errors started...
I will not be responsible if you bork, brick, or blow up your devices in the process​
Notes: This is using clang, gcc should also work using this procedure, just with a few alterations exactly like compiling on linux
This guide is intended to help people compile their kernel on OSX
Step 1: Getting the dependencies and setting up build environment
Installing package managers:
Xcode HAS to be installed for this to work! If you just want the command line tools, type "xcode-select --install". To set the OS to use the command line tools from the app, type "xcode-select --switch /Applications/Xcode.app/Contents/Developer"
Install homebrew here: http://brew.sh
Install macports here (Follow source instructions): http://https://guide.macports.org/chunked/installing.macports.html
Set up build environment:
The android developers website gives great instructions on how to do this, but they use macports, which I tend to stay away from. However, this guide will use macports until I can figure out the homebrew alternatives for these packages
MacPorts packages: gmake libsdl git gnupg bison (exclude the git packages if you already have them)
Reference site: https://source.android.com/setup/build/initializing
Case Sensitive disk image - Android anything won't build unless the filesystem is case sensitive (APFS isn't), so we need to create a sparseimage for it
Go into disk utility and hit file, new image, blank image or Command-N
Set (in this order) Image Format: sparse disk image, Format: Mac OS Extended (Journaled, case-sensitive), Size: 20GB, Name: Android
Create the new image
Edit your bash profile by entering "open -a TextEdit ~/.bash_profile" and make a mountAndroid function
mountandroid() { hdiutil attach ~/android.sparseimage -mountpoint /Volumes/android; }
Open a new terminal window and type mountandroid
Your new disk image is mounted at /Volumes/android
Setting the PATH:
Open your bash_profile
add this line:
export PATH="/usr/local/bin:$PATH"
export PATH="/opt/local/bin:$PATH"
Save and open a new window
Step 2 - Cloning the kernel: I don't know where you get your kernels from, but you should know the basics on how to clone a source, clone the source to /Volumes/android
Step 3 - Getting the Toolchain: For now, I use prebuilts via the NDK, However, Crosstool-ng is a viable option
Download the NDK here https://developer.android.com/ndk/downloads/
Make a standalone Toolchain inside your case sensitive image (For arm64 devices: use the guide for BOTH arm and arm64)
https://developer.android.com/ndk/guides/standalone_toolchain
Step 4 - Linking it all together:
Creating a script to use (inside kernel source folder)
make O=out ARCH=arm64 **Your_defconfig**
make -j4 O=out ARCH=arm64 CC='/Volumes/android/**Toolchain folder**/bin/clang' CLANG_TRIPLE=aarch64-linux-gnu CROSS_COMPILE_ARM32='/Volumes/android/**Toolchain arm folder**/bin/arm-linux-androideabi-' CROSS_COMPILE='/Volumes/android/**Toolchain arm folder**/bin/aarch64-linux-android-'
The arm64 devices have to use the CROSS_COMPILE_ARM32 line, if you don't have this, just omit the line
Then just type ./**Script Name**.sh (make sure to chmod +x or 755 it first) and you're good to go!
Step 5 - Errors... Those stupid errors!: There are a few known errors that can be easily fixed, but they're very annoying
elf.h error - Open the file /usr/local/include and make a new file, elf.h
Paste this in there:
#include "../opt/libelf/include/libelf/gelf.h"
#define R_386_NONE 0
#define R_386_32 1
#define R_386_PC32 2
#define R_ARM_NONE 0
#define R_ARM_PC24 1
#define R_ARM_ABS32 2
#define R_MIPS_NONE 0
#define R_MIPS_16 1
#define R_MIPS_32 2
#define R_MIPS_REL32 3
#define R_MIPS_26 4
#define R_MIPS_HI16 5
#define R_MIPS_LO16 6
#define R_IA64_IMM64 0x23 /* symbol + addend, mov imm64 */
#define R_PPC_ADDR32 1 /* 32bit absolute address */
#define R_PPC64_ADDR64 38 /* doubleword64 S + A */
#define R_SH_DIR32 1
#define R_SPARC_64 32 /* Direct 64 bit */
#define R_X86_64_64 1 /* Direct 64 bit */
#define R_390_32 4 /* Direct 32 bit. */
#define R_390_64 22 /* Direct 64 bit. */
#define R_MIPS_64 18
#define EF_ARM_EABIMASK 0XFF000000
#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK)
vdsomunge.c errors (all fixed with this simple file from torvalds himself)
Replace your arch/arm/vdso/vdsomunge.c file with this one
vdso_offset_sigtramp undeclared (shows signal.c in terminal)
change the file arch/arm64/vdso/gen_vdso_offsets.sh
Replace the last line to this - 's/^\([0-9a-fA-F]*\) . VDSO_\([a-zA-Z0-9_]*\)$/\#define vdso_offset_\2 0x\1/p'
This removes the "t" in the "2t0x" part
So, after this, your kernel should be built without any complications! I have some requests in the post below, so help me out and gimme a thanks!
Things I need help finding:
Building crosstool-ng on mac
building Dragon TC on mac or a clang 8.0 toolchain
Please put your solutions in the comments so I can include them in the main thread
thanks for the guide!
I'm having one problem though
Code:
Undefined symbols for architecture x86_64:
"_OPENSSL_init_crypto", referenced from:
_main in cc6WbheD.o
ld: symbol(s) not found for architecture x86_64
I posted a complete revision alongside a recent kernel, but below is a summary of the changes / updates for using this guide in 2021
StarKissed/StarKissed_I005_1
Contribute to StarKissed/StarKissed_I005_1 development by creating an account on GitHub.
github.com
Disclaimer: As of June 2021, Android no longer supports building on Mac
arch/arm64/vdso/gen_vdso_offsets.sh =>
arch/arm64/kernel/vdso/gen_vdso_offsets.sh
Code:
brew install gnu-sed
export PATH=/usr/local/opt/gnu-sed/libexec/gnubin:$PATH
readlink: illegal option -- f
usage: readlink [-n] [file ...]
Code:
brew install coreutils
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH
find: -printf: unknown primary or operator
Code:
brew install findutils
export PATH=/usr/local/opt/findutils/libexec/gnubin:$PATH
Homebrew alternatives
Code:
brew install make
brew install sdl
brew install gnupg
brew install bison
Quick Homebrew Alternatives
Enter "homebrew [command name]" in google search
Enter command from https://formulae.brew.sh/formula/
juampapo546 said:
thanks for the guide!
I'm having one problem though
Code:
Undefined symbols for architecture x86_64:
"_OPENSSL_init_crypto", referenced from:
_main in cc6WbheD.o
ld: symbol(s) not found for architecture x86_64
Click to expand...
Click to collapse
Code:
brew install openssl
export PKG_CONFIG_PATH=/usr/local/opt/[email protected]/lib/pkgconfig:$PKG_CONFIG_PATH
You may also need to explicitly include in scripts/Makefile
Code:
HOST_EXTRACFLAGS += -I$(srctree)/tools/include
ifeq ($(shell uname),Darwin)
HOST_EXTRACFLAGS += -I/usr/local/opt/[email protected]/include -L/usr/local/opt/[email protected]/lib
endif

Categories

Resources