Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,768,353 Members 46,497 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
ezterry
Old
(Last edited by ezterry; 25th February 2013 at 12:52 AM.)
#1  
ezterry's Avatar
Retired Recognized Developer - OP
Thanks Meter 1000
Posts: 1,823
Join Date: Jan 2010
Location: Asheville, NC

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

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.
Dream Sapphire:
> Radio 2708+ (+15MB kernels)
> MT3G ota froyo rom dream sapphire port
> ezGingerbread (rom/source): Dream/Sapphire
> DS JTAG: Soft load of SPL (to unbrick/re-root) / JTAG WIKI


Acer A500:
> ezT20 kernel A500 and A100
> A500 Public Recovery (Clockwork Mod based recovery + source for the A500)
> Acer A500 ICS Rooted w/ Busybox
> Acer_A500 OTA 7.014.14 --HC 3.2.1-- Rooted w/ Busybox


Donations for beer/rent are always appreciated.
Twitter: xdaterry -~- Google+: profile -~- GitHub: ezterry
The Following 61 Users Say Thank You to ezterry For This Useful Post: [ Click to Expand ]
 
msri3here
Old
#2  
Senior Member
Thanks Meter 86
Posts: 334
Join Date: Aug 2010
Location: Pune

 
DONATE TO ME
Excellent!!! thanks Man!!! Has been looking for one of these
The Following User Says Thank You to msri3here For This Useful Post: [ Click to Expand ]
 
ezterry
Old
#3  
ezterry's Avatar
Retired Recognized Developer - OP
Thanks Meter 1000
Posts: 1,823
Join Date: Jan 2010
Location: Asheville, NC

 
DONATE TO ME
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)
Dream Sapphire:
> Radio 2708+ (+15MB kernels)
> MT3G ota froyo rom dream sapphire port
> ezGingerbread (rom/source): Dream/Sapphire
> DS JTAG: Soft load of SPL (to unbrick/re-root) / JTAG WIKI


Acer A500:
> ezT20 kernel A500 and A100
> A500 Public Recovery (Clockwork Mod based recovery + source for the A500)
> Acer A500 ICS Rooted w/ Busybox
> Acer_A500 OTA 7.014.14 --HC 3.2.1-- Rooted w/ Busybox


Donations for beer/rent are always appreciated.
Twitter: xdaterry -~- Google+: profile -~- GitHub: ezterry
 
...Awesome...
Old
#4  
...Awesome...'s Avatar
Recognized Developer / Retired Forum Moderator
Thanks Meter 7253
Posts: 3,211
Join Date: Jul 2010
Location: Chicago

 
DONATE TO ME
FINALLY!!! Great Instructions followed them to the T and BAM got my kernel compiled!!!

 
Roqu3
Old
#5  
Senior Member
Thanks Meter 185
Posts: 254
Join Date: May 2011
wow your toolchain is so small, many thanks, just compiled a kernel for my LG P500 gonna test it, thanks again
 
Hammerfest
Old
#6  
Hammerfest's Avatar
Senior Member
Thanks Meter 278
Posts: 1,588
Join Date: Apr 2008
Location: San Antonio, TX

 
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!
Have I in some way helped you?
Perhaps I made a post of an issue that you also have?
Think i'm such a nice/swell guy*
Then hit the THANKS button!

*
I'm not, I'm annoying, if you think otherwise
please seek medical/mental assistance ASAP!

TouchPro, TouchPro2, HeroC, HD2, Evo3D, EvoShift, PhotonQ, GalaxyNote, MORE...
 
krabappel2548
Old
(Last edited by krabappel2548; 23rd June 2012 at 01:52 PM.)
#7  
krabappel2548's Avatar
Recognized Contributor / Recognized Developer
Thanks Meter 13383
Posts: 6,144
Join Date: Nov 2011
Location: Neerpelt

 
DONATE TO ME
EDIT: never mind, problem solved, what I need to know now won't be solved here
I'm back with development, but not superactive yet.

Consider donating to me if you like my work. this would help me buy future devices.
 

Devices I have:
- Xperia Z1

Current devices I develop for:
- Xperia Z1
- Xperia Z Ultra

What I did and do:
- Member of Team AC!D, developer of Xperia Z Revolution Rom, Xperia ZL Revolution rom, Xperia S Revolution rom, Xperia Carbon rom's with tweaked kernel, and more!
 
SystemErrorOne
Old
#8  
SystemErrorOne's Avatar
Recognized Contributor
Thanks Meter 303
Posts: 450
Join Date: Jun 2011
Location: Jacksonville
I wish i knew how to go about doing this..
 
manoranjan2050
Old
#9  
manoranjan2050's Avatar
Senior Member
Thanks Meter 1352
Posts: 1,075
Join Date: Dec 2011
Location: JAGATSINGHPUR

 
DONATE TO ME
Thumbs up Thanks

Thanks For ........... i Really need It .........
The Following User Says Thank You to manoranjan2050 For This Useful Post: [ Click to Expand ]
 
Black_jackss
Old
#10  
Black_jackss's Avatar
Senior Member
Thanks Meter 126
Posts: 700
Join Date: Aug 2011
Location: Pekanbaru
Quote:
Originally Posted by Hammerfest View Post
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
We are all going to be die anyway

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

Advanced Search
Display Modes