Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[EXPERIMENTAL/TOOLS/GUIDE/ADV.] Toolchain gcc 4.6.3 Cygwin/Linux/OSX; kernel builds

OP ezterry

1st June 2012, 10:24 PM   |  #1  
ezterry's Avatar
OP Retired Recognized Developer
Flag Asheville, NC
Thanks Meter: 1,002
 
1,823 posts
Join Date:Joined: Jan 2010
Donate to Me
More
The following contains binaries, and instructions for use of an experimental newer toolchain than those included in the android pre-built package.

This is provided to allow existing linux kernel developers experiment with the updated version of GCC (besides the complicated building instructions the code just has a small patch for a known issue with android and 4.6.* otherwise is directly from GNU (see build information below)

The packages I'm also providing to help developers current on windows (With cygwin but no other virtual environment) to start exploring android Linux kernel development for their devices. (In addition to a OSX toolchain for more advanced mac users)

due to the slight differences between kernels on different devices this How To is intended to be used for advanced users who can adjust for the differences required for the devices specific kernel.

I may add additional guides to this thread if I find a need for them.

Binary Toolchains

I have two versions of a GCC-4.6.3 toolchain

1) For x86 linux: toolchain-4.6.3.tar.bz2 (Sha1: c8c57aba6ad92e9acddf29ba8620ba880be09a81)

2) For Cygwin (windows): toolchain-4.6.3.cygwin.tar.bz2 (Sha1: 6947e1c1ba95195019f542eb8ba0708667b63eca)

3) For OSX (mac/darwin): toolchain-4.6.3.darwin.tar.bz2 (Sha1: 9a977f0672863fdd9501383a6ad1e30723281f68)

> The linux version was built via this script: http://pastebin.com/b2dZ8YtG (or in the included toolchain_notes.txt)
> The cygwin/darwin version uses the same source however has a slightly modified script (see the included toolchain_notes.txt for the updated script)


System Requirements

Note I have a 64bit debian linux box, and a 64bit version of WIndows7 Pro running cygwin, while I believe these binaries ought to be compatible with all x86 linux and cygwin installs these have not been tested by a wide number of people yet.

> Linux users: If you have a working android build environment likely no additional requirements are needed. In addition you must build any kernel/android utilities from a case sensitive filesystem or disk image.

> OSx users: the cygwin packages will give you an idea of what is required, please also see the README in the tar.bz2 about manually installing elf.h

> Cygwin users: as its unlikely you have compiled a kernel with cygwin up to this point you may wish to ensure the following packages are installed (as well as any cygwin recommends to be used with them):
vim
vim-common
make
cmake
lzop
gcc
gcc-core
gcc-g++
wget
git
git-compleation
libncurses-devel
python
Cygwin users must also set their NTFS file partition to allow case sensitive files:

To do this open regedit and change:

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\kernel\obcaseinsensitive

to 0

after this reboot and the NTFS kernel will allow cygwin to use case sensitive files (ie 'AbC' and 'aBc' as two different files)
Advanced Kernel Building Guide

Since may devices are slightly different this can only be a high level kernel building guide
Please ask for any specific directions from the current kernel maintainer.

To most people who have built kernels before this will look familiar, the most important part is preparing your local environment to use the new toolchain,

1) If you have not already download the tar.bz2 above, (pick the one for the computer you are preparing to build kernels on)

2) extract the file (for the sake of this guide I will assume it is extracted into a ~/android directory)

ie on cygwin you might:

mkdir -p ~/android
cd ~/android
tar -xjvf toolchain-4.6.3.cygwin.tar.bz2


Note: steps one and two are just properly installing the toolchain, you will not need
to repeat them to build a different kernel.

2.b) OSX Only: check elf.h

open ~/android/toolchain-4.6.3/README in a text editor and check if elf.h is installed, otherwise manually install it as per the readme

3) fetch your kernel source into the ~/android directory and change into the
source codes root directory

(this can be via a git repo or tarball)

example if you wanted my ACER a100/a500 source you might run:

git clone git://github.com/ezterry/AcerTabKernel.git
cd AcerTabKernel


change this to match the source you are fetching

4) In the root directory of the kernel source (~/android/AcerTabKernel in the about a100/a500 example) update the environment for the cross compiler

add the toolchain to your path:
export PATH=$HOME/android/toolchain-4.6.3/bin:$PATH
set the cross compile:
export ARCH=arm
export CROSS_COMPILE=arm-linux-androideabi-
export KERNEL_DIR=`pwd`
(this will need to be done once for each terminal you use to run any of the following make commands)

5) Grab your configuration

From the device:
adb pull /proc/config.gz
gzip -dc config.gz > .config


or from a prepared configuration if it's included in your code base by running

make _defconfig

example for the a100/a500 code base is 'make vangogh_defconfig' for the a100 and 'make picasso_defconfig' for the a500

6) Customize configuration

just run menuconfig and use the UI to update settings
make menuconfig
7) building the kernel (zImage)

This is normal at this point with 'make -j'
so for a quad core CPU you can run
make -j5
(note: the wrong number in the -j argument will not harm the build but may slow down the building process by either using too few threads or needing to keep track of too many)

8) If it worked you will now have the kernel in arch/arm/boot/zImage
this can be injected into the boot.img (as the kernel, using an existing ramdisk) as is


If it failed for your kernel your kernel source may need one of the common patches

9) Building modules
the following will prepare the modules in subdirectory mod:
make modules
rm -rf mod
mkdir mod
cp `find ./ | grep .ko$` modules.order mod/
After these commands [if no errors] you can simply copy the contents of mod/ to /system/lib/modules on your device, note it is recommended usually to remove the existing contents of /system/lib/modules unless there is a closed source module required from the previous build despite the new kernel.

Common Patches Required

If your kernel has not been built for the new toolchain or on cygwin before you may require some of these common patchs: (I've thus far only tested this on my Acer A100/A500 source)

wireless/bcm4329 for GCC-4.6.3:
https://github.com/ezterry/AcerTabKe...d5a1c04e1e264c

linux kernel module patch for cygwin (broken elf.h):
https://github.com/ezterry/AcerTabKe...75b2f6d3ff556c

Error compiling security/smc/bridge_pub2sec.S (I required the cygwin elf patch and this patch to build the Franco galaxy nexus kernel)
0001-Fix-build-error-with-4.6.3-toolchain-smc-0.patch
(use 'git am 0001-Fix-build-error-with-4.6.3-toolchain-smc-0.patch' to apply)

OSX stat patches (fixes errors between GNU and BSD stat):
https://github.com/ezterry/AcerTabKe...cdc0534aaeb35a

Errors loading newly built modules (modules appear to build cleanly but wont install):
simply add -fno-pic to CFLAGS_MODULE
https://github.com/ezterry/AcerTabKe...15af43de2f644a

(I can add others here if highlighted to me, and as I find them)

Other Toolchain uses

The linux toolchain can be used to build android components, however this requires various manipulation to the android /build git repository as currently various other toolchains have hard coded paths into the prebuilt repo. If you intend to incorporate this into your build it may be best to inject the toolchain into your prebuilt repo rather than expect your users to download the links above, ensure to keep the compile notes as it explains how to get the source code to the toolchains)

On cygwin/osx it may also be possible to build android applications however I've not yet tested this as the scripts to make a proper build are complex when attempted outside the android build tree.
Last edited by ezterry; 25th February 2013 at 01:52 AM.
The Following 62 Users Say Thank You to ezterry For This Useful Post: [ View ]
4th June 2012, 03:21 PM   |  #2  
Senior Member
Flag Pune
Thanks Meter: 94
 
361 posts
Join Date:Joined: Aug 2010
Donate to Me
More
Excellent!!! thanks Man!!! Has been looking for one of these
The Following User Says Thank You to msri3here For This Useful Post: [ View ]
5th June 2012, 07:28 PM   |  #3  
ezterry's Avatar
OP Retired Recognized Developer
Flag Asheville, NC
Thanks Meter: 1,002
 
1,823 posts
Join Date:Joined: Jan 2010
Donate to Me
More
Added in the OSX version of the toolchain (and some related patches)

Also if you are having problems with your modules built with this toolchain a CFLAG fixes it. (see note in common patches)
23rd June 2012, 04:32 AM   |  #4  
...Awesome...'s Avatar
Recognized Developer / Retired Forum Moderator
Flag Chicago
Thanks Meter: 7,273
 
3,206 posts
Join Date:Joined: Jul 2010
Donate to Me
More
FINALLY!!! Great Instructions followed them to the T and BAM got my kernel compiled!!!
23rd June 2012, 06:25 AM   |  #5  
Senior Member
Thanks Meter: 185
 
254 posts
Join Date:Joined: May 2011
wow your toolchain is so small, many thanks, just compiled a kernel for my LG P500 gonna test it, thanks again
23rd June 2012, 06:29 AM   |  #6  
Hammerfest's Avatar
Senior Member
Flag San Antonio, TX
Thanks Meter: 278
 
1,590 posts
Join Date:Joined: Apr 2008
Donate to Me
Bookmarked for testing when I wake up...

I can almost put: "Building under Windows is not currently supported." (quote from google), unofficially at least, out of my mind...



I have been spoiled by Windows for far too long I fear, my attempt for this last week at getting Linux setup and building CM9 has been nothing but a complete FAILURE, too many single line entrys for different distributions/package combo's, commands I dont know and cant find because of wildcard portions of them and lack of understanding, and not enough scripts like the wonderful Compile CM9 script someone put up (cant run it because all the pre-req's arent setup).

Good god Ill be jumping for joy if this works tomorrow on WinBlows!
23rd June 2012, 12:22 PM   |  #7  
krabappel2548's Avatar
Recognized Contributor / Recognized Developer
Flag Zichem
Thanks Meter: 15,572
 
6,362 posts
Join Date:Joined: Nov 2011
Donate to Me
More
EDIT: never mind, problem solved, what I need to know now won't be solved here
Last edited by krabappel2548; 23rd June 2012 at 02:52 PM.
23rd June 2012, 05:34 PM   |  #8  
SystemErrorOne's Avatar
Recognized Contributor
Flag Jacksonville
Thanks Meter: 326
 
482 posts
Join Date:Joined: Jun 2011
More
I wish i knew how to go about doing this..
23rd June 2012, 08:25 PM   |  #9  
manoranjan2050's Avatar
Senior Member
Flag JAGATSINGHPUR
Thanks Meter: 1,374
 
1,085 posts
Join Date:Joined: Dec 2011
Donate to Me
More
Thumbs up Thanks
Thanks For ........... i Really need It .........
The Following User Says Thank You to manoranjan2050 For This Useful Post: [ View ]
24th June 2012, 11:03 AM   |  #10  
Black_jackss's Avatar
Senior Member
Flag Pekanbaru
Thanks Meter: 126
 
700 posts
Join Date:Joined: Aug 2011
More
Quote:
Originally Posted by Hammerfest

Bookmarked for testing when I wake up...

I can almost put: "Building under Windows is not currently supported." (quote from google), unofficially at least, out of my mind...



I have been spoiled by Windows for far too long I fear, my attempt for this last week at getting Linux setup and building CM9 has been nothing but a complete FAILURE, too many single line entrys for different distributions/package combo's, commands I dont know and cant find because of wildcard portions of them and lack of understanding, and not enough scripts like the wonderful Compile CM9 script someone put up (cant run it because all the pre-req's arent setup).

Good god Ill be jumping for joy if this works tomorrow on WinBlows!

If you succeed tell me how to do it in a more familiar way :P

Post Reply Subscribe to Thread

Tags
cygwin, kernel guide
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes