5,593,793 Members 46,420 Now Online
XDA Developers Android and Mobile Development Forum

[Tutorial] How to compile your first Nexus Kernel

Tip us?
 
djjonastybe
Old
(Last edited by djjonastybe; 14th August 2012 at 10:51 AM.)
#1  
Senior Member - OP
Thanks Meter 347
Posts: 686
Join Date: Sep 2010
Location: Tienen

 
DONATE TO ME
Default [Tutorial] How to compile your first Nexus Kernel

If you see mistakes please contact me. If you think something can be shorter, easier, feel free to suggest.

I have spent a lot of time figuring this out. Not to mention making this guide.

I DO NOT RESPOND TO PRIVATE MESSAGES. EVERYTHING YOU NEED IS IN HERE.


If this guide helped you feel free to donate.

There is more to come, using different toolchains, important files, adding overclocking etc.


Setting up the environment & building the kernel for the first time
  1. Ubuntu 12.04 64-Bit
  2. Linux Mint 13 64-Bit

    Compiling Jelly Bean AOSP ROMs with these 2 is possible WITHOUT ADDITIONAL WORK.

    If you want to use virtualization software, do NOT use Virtualbox. You can run into networking issues and so on. I suggest using VMWare Player instead, which is available for free on http://www.vmware.com
  3. Installing latest updates & reboot.
    Quote:
    $ sudo apt-get update
    $ sudo apt-get dist-upgrade
    $ sudo reboot
  4. Now we will download and install the latest Java 6 JDK from here. Look for Java 6 SE Update 33 or a later update version. Don't download Java 7 JDK. I am downloading the file below for this guide.
    Quote:
    Linux x64 68.69 MB jdk-6u33-linux-x64.bin
    This guide assumes you have downloaded the file in the folder
    Quote:
    ~/Downloads
    Quote:
    $ cd ~/Downloads
    $ sudo chmod +x jdk-6u33-linux-x64.bin
    $ ./jdk-6u33-linux-x64.bin
    $ sudo mkdir /usr/lib/jvm
    $ sudo mv jdk1.6.0_33 /usr/lib/jvm/jdk1.6.0_33
    $ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_33/bin/javac 1
    $ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_33/bin/java 1
    $ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_33/bin/javaws 1
    $ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_33/bin/jar 1
    $ sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.6.0_33/bin/javadoc 1
    $ sudo update-alternatives --config javac
    $ sudo update-alternatives --config java
    $ sudo update-alternatives --config javaws
    $ sudo update-alternatives --config jar
    $ sudo update-alternatives --config javadoc
    $ java --version
    $ ls -la /etc/alternatives/java*
    Now reboot is optional but welcome. Let's play safe.
    Quote:
    $ sudo reboot
  5. Install all required packages to play with Android.
    Ubuntu 12.04
    Quote:
    $ sudo apt-get update
    $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git
    $ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
    $ sudo reboot
  6. Configure USB ports.
    Quote:
    $ sudo gedit /etc/udev/rules.d/51-android.rules
    This file should get the contents:
    Quote:
    # adb protocol on passion (Nexus One)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"
    # fastboot protocol on passion (Nexus One)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"
    # adb protocol on crespo/crespo4g (Nexus S)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"
    # fastboot protocol on crespo/crespo4g (Nexus S)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
    # adb protocol on stingray/wingray (Xoom)
    SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"
    # fastboot protocol on stingray/wingray (Xoom)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"
    # adb protocol on maguro/toro (Galaxy Nexus)
    SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"
    # fastboot protocol on maguro/toro (Galaxy Nexus)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"
    # adb protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"
    # fastboot protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"
    # usbboot protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"
    # usbboot protocol on panda (PandaBoard ES)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"
    Don't forget to replace the red marked text with your username from Ubuntu or Linux Mint.

  7. When building a kernel, you only need to start from here. Pick the appropriate branch from the git manually. My example below shows how to download the required files to build a Jelly Bean kernel. What I did was visiting the git repository each time and picked the appropriate branch.
    https://android.googlesource.com/device/samsung/maguro
    Quote:
    $ mkdir ~/Documents/kernel
    $ cd ~/Documents/kernel
    $ git clone https://android.googlesource.com/device/samsung/maguro -b jb-release
    Again pick the right branch from https://android.googlesource.com/kernel/omap.git
    Quote:
    $ cd maguro
    $ git clone https://android.googlesource.com/kernel/omap.git -b android-omap-tuna-3.0-jb-pre1
  8. Ensure the toolchain is in your path.
    • Default, Easy solution
      Quote:
      $ git clone https://android.googlesource.com/platform/prebuilt -b jb-release
      $ export PATH=$(pwd)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH
      $(pwd) is a variable holding the current working directory.
    • Bandwidth-friendly solution
      You can also download the toolchain to another directory. Bit first write down the directory you are working at.
      Quote:
      mkdir ~/Documents/toolchain
      cd ~/Documents/toolchain
      $ git clone https://android.googlesource.com/platform/prebuilt -b jb-release
      export PATH=~/Documents/toolchain/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH
      Instead of specifying the location of the toolchain with a relative path, we must specify the absolute path here.

      Now we go back to where we were working.
      Quote:
      cd ~/Documents/kernel/maguro
      I hope you understand why I mentioned the bandwidth-friendly solution. With little insight you could have come up with it yourself.
  9. Now let's build the kernel
    Quote:
    $ cd omap
    $ export ARCH=arm
    $ export SUBARCH=arm
    $ export CROSS_COMPILE=arm-eabi-
    $ make tuna_defconfig
    $ make

  10. Now you need to put it in a flashable zip.


Possible issues, things to avoid, FAQ
- Avoid downloading the kernel sources to directories which might require root/superuser access. This is one of the reasons I downloaded all sources to '~/Documents'. This will save a lot of time messing with chmod or chown commands.
- What is 'tuna', shouldn't this be maguro? No, actually not. Tuna is the board name, while maguro is the codename of the Nexus. Something you might want to remember when building kernels.


Interesting files and locations
  • <kernel_directory>/samsung/arch/arm/mach-s5pv210/cpu-freq.c
    Overclocking
    Voltages


Links to mods, source code, ...
Only do these when you are in the omap directory

Getting access to Ezekeel's work
Quote:
git remote add ezekeel https://github.com/Ezekeel/GLaDOS-nexus-prime.git
git fetch ezekeel
If you want to change the text marked in red make sure to change the other one as well. You can think of this as a nickname for the remote repository.

Example of cherry-picking CUSTOM VOLTAGE
1. Go here: https://github.com/Ezekeel/GLaDOS-ne...stomvoltage_JB
2. Copy the SHA of the commit
3.
Quote:
git cherry-pick 05ab84fa9bc1fa86e5a99c54266873e433ff15e2
template
Quote:
git cherry-pick <SHA>
When encountering conflicts, you are on your own. I figured most of this out on my own. So if I can do it you can too.

Getting access to Francisco Franco's work
Quote:
git remote add franco https://github.com/franciscofranco/Tuna_JB_pre1.git
git fetch franco
Getting access to http://www.kernel.org
Quote:
git remote add kerneldotorg git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
git fetch kerneldotorg
The Following 39 Users Say Thank You to djjonastybe For This Useful Post: [ Click to Expand ]
 
sert00
Old
(Last edited by sert00; 12th August 2012 at 03:26 PM.)
#2  
sert00's Avatar
Senior Member
Thanks Meter 504
Posts: 1,082
Join Date: May 2011
Location: cesena,IT
red 2 days ago yours guide linked in sig.you sad that with ubuntu 12.10 aosp rom are impossible to compile,it's fine only for kernel and for aosp rom should use version 10.xx.now instead you say 12.xx is good for kernel and rom compiling,but from JB and so on.(Compiling AOSP ROMs with these 2 is possible. Only Jelly Bean and later though will compile without additional work)
after that,i think (after reading yours words)that until iCS 12.xx doesn't compile and from jb a so on 12.xx works good?i'm right or i I misunderstood?i'm totally noob on this things,compiled my fist rom 15 days ago,begin with JB but compiled already in mint mate 13,mint cynnamon 13,ubuntu 10.10 and 12.04\10.
very thanks for this guide man,it's very usefull and having already the environment setted it's very fast also.followed instruction in yours sig days ago and with no luck.now i retry with this!on mint 13 cynnamon 64bit now.regards cherrypicking...what you wrote is all we have to known for or is a base?
rated 5 stars and thanked.like this 3ads aims to help everyone begin do things yourselves on android
My current mobile devices:
Samsung galaxy nexus maguro version 16Gb
Asus transformer WiFi-only 16Gb
Asus nexus 7 WiFi-only 16Gb
My current system embedded boards in use:
Arduino UNO (x2)
Arduino Mega 2560 (ADK support with USBHost Shield)
My current ARM boards:
Raspberry Pi rev.B
Hardkernel odroid-U2 with Exynos4412 PRIME x2 and all optional addons
Hardkernel odroid-XU-E with Exynos5410 x1 and all optional addons
The Following User Says Thank You to sert00 For This Useful Post: [ Click to Expand ]
 
teshxx
Old
#3  
teshxx's Avatar
Senior Member
Thanks Meter 3140
Posts: 1,603
Join Date: Jul 2010
Location: FL

 
DONATE TO ME
Good tutorial. Thanks for taking the time to write this.
If you think I was helpful buy me a brew or coffee or hookah
================================================
-- ---
================================================
[-::REF::-] Kernel Governors Explained!
[-::SGH-T889::-] Factory Images, Roms, Kernels, & Modems
[-::SGH-T889V::-] Factory Images, Roms, Modems, & Kernels
================================================
 
Serious_Beans
Old
#4  
Serious_Beans's Avatar
Senior Member
Thanks Meter 343
Posts: 2,307
Join Date: Feb 2011
Location: New York

 
DONATE TO ME
How many gigs do I need to compile the kernel? I only have a 120gb ssd and 75gb free.

Sent from my Galaxy Nexus using Tapatalk 2
 
sert00
Old
#5  
sert00's Avatar
Senior Member
Thanks Meter 504
Posts: 1,082
Join Date: May 2011
Location: cesena,IT
you are safe..
My current mobile devices:
Samsung galaxy nexus maguro version 16Gb
Asus transformer WiFi-only 16Gb
Asus nexus 7 WiFi-only 16Gb
My current system embedded boards in use:
Arduino UNO (x2)
Arduino Mega 2560 (ADK support with USBHost Shield)
My current ARM boards:
Raspberry Pi rev.B
Hardkernel odroid-U2 with Exynos4412 PRIME x2 and all optional addons
Hardkernel odroid-XU-E with Exynos5410 x1 and all optional addons
 
RcrdBrt
Old
#6  
RcrdBrt's Avatar
Senior Member
Thanks Meter 457
Posts: 477
Join Date: May 2011
Location: Italy

 
DONATE TO ME
Quote:
Originally Posted by Serious_Beans View Post
How many gigs do I need to compile the kernel? I only have a 120gb ssd and 75gb free.

Sent from my Galaxy Nexus using Tapatalk 2
They are enough



For kernel compiling we don't need any version of java

Inviato dal mio Galaxy Nexus con Tapatalk 2
The Following User Says Thank You to RcrdBrt For This Useful Post: [ Click to Expand ]
 
djjonastybe
Old
#7  
Senior Member - OP
Thanks Meter 347
Posts: 686
Join Date: Sep 2010
Location: Tienen

 
DONATE TO ME
Quote:
Originally Posted by sert00 View Post
red 2 days ago yours guide linked in sig.you sad that with ubuntu 12.10 aosp rom are impossible to compile,it's fine only for kernel and for aosp rom should use version 10.xx.now instead you say 12.xx is good for kernel and rom compiling,but from JB and so on.(Compiling AOSP ROMs with these 2 is possible. Only Jelly Bean and later though will compile without additional work)
after that,i think (after reading yours words)that until iCS 12.xx doesn't compile and from jb a so on 12.xx works good?i'm right or i I misunderstood?i'm totally noob on this things,compiled my fist rom 15 days ago,begin with JB but compiled already in mint mate 13,mint cynnamon 13,ubuntu 10.10 and 12.04\10.
very thanks for this guide man,it's very usefull and having already the environment setted it's very fast also.followed instruction in yours sig days ago and with no luck.now i retry with this!on mint 13 cynnamon 64bit now.regards cherrypicking...what you wrote is all we have to known for or is a base?
rated 5 stars and thanked.like this 3ads aims to help everyone begin do things yourselves on android
ICS didn't compile here on Ubuntu 12.04. I believe I needed to do some additional work. ICS was also released before Ubuntu 12.04 was released. Jelly Bean will compile just fine.

The only thing that was difficult to figure out was how to setup the Java 6 JDK properly which I had to figure out by trial and error.

The cherry-picking is handy when you want to 'steal' someone else his work. Let's say 99% of the developers do this all the time here on XDA. I wanted to explain how to cherry-picking because it's useful to know. I spent a long time getting here.
Quote:
Originally Posted by Serious_Beans View Post
How many gigs do I need to compile the kernel? I only have a 120gb ssd and 75gb free.

Sent from my Galaxy Nexus using Tapatalk 2
I think 4-5GB if you download everything. If you only download the Jelly Bean things by only downloading the branch you need you will use about maybe 1GB I am not sure. Try it out.

Download the toolchain to a separate directory. This will save lots of bandwidth in the future.
The Following User Says Thank You to djjonastybe For This Useful Post: [ Click to Expand ]
snowman77 Old
#8  
Guest
Thanks Meter
Posts: n/a
Good job on this guide. I learnt this ages ago though

Sent from my Galaxy Nexus using xda premium
 
dxdiag32
Old
#9  
dxdiag32's Avatar
Senior Member
Thanks Meter 269
Posts: 846
Join Date: Feb 2011
Location: Chongqing
i'm interesting about linaro but i don't know how set it up,can you say something about this?:P

Sent from my Galaxy Nexus
Devices
-Samsung Galaxy 3
-LG Optimus Black
-Samsung Focus
-Samsung Galaxy S III
-Samsung Galaxy Nexus
-LG Optimus G
Sina MicroBlog
Google+
 
djjonastybe
Old
#10  
Senior Member - OP
Thanks Meter 347
Posts: 686
Join Date: Sep 2010
Location: Tienen

 
DONATE TO ME
Quote:
Originally Posted by dxdiag32 View Post
i'm interesting about linaro but i don't know how set it up,can you say something about this?:P

Sent from my Galaxy Nexus
Linaro is easy.

Google to download the linaro toolchain from their website. And then it's a bit trial and error to fill in:
CROSS_COMPILE line
it's not arm-eabi- anymore buy gnu-arm-eabi or something similar. It has to do with the directory structure or the filenames.

If you get a compile error about vfp or something you must correct this in a make file.

Take a look in francisco franco's github account or AIR Kernel. They have commit which describe what they did if they ran into compile errors. Normally you won't have to change anything I think.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes