FORUMS
Remove All Ads from XDA

[Tutorial] How to compile a kernel

686 posts
Thanks Meter: 350
 
By djjonastybe, Senior Member on 15th July 2012, 10:20 AM
Post Reply Email Thread
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.


If this guide helped you feel free to donate.

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

Coming soon
- Links to useful mods: deep idle, live oc, BLN, ...
- How to compile a custom kernel: eg air kernel
- A list of useful files and folders in the downloaded kernel source


Setting up the environment & building the kernel for the first time
  1. Ubuntu 10.04 64-Bit (recommended)
    Ubuntu 12.04 64-Bit

    Note that you cannot compile AOSP ROMs with Ubuntu 12.04. Ubuntu 12.04 is fine for kernels.

    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
  2. Installing latest updates & reboot.
    Quote:

    $ sudo apt-get update
    $ sudo apt-get dist-upgrade
    $ sudo reboot

  3. 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 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

  4. Install all required packages to play with Android.
    Ubuntu 10.04
    Quote:

    $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc

    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

  5. 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.

  6. When building a kernel, you only need to start from here. Pick the appropriate branch from the git manually. I used the one below as an example. What I did was visiting the git repository each time and picked the appropriate branch.
    https://android.googlesource.com/device/samsung/crespo
    Quote:

    $ mkdir ~/Documents/kernel
    $ cd ~/Documents/kernel
    $ git clone https://android.googlesource.com/device/samsung/crespo -b ics-plus-aosp

    Again pick the right branch from https://android.googlesource.com/kernel/samsung.git
    Quote:

    $ cd crespo
    $ git clone https://android.googlesource.com/kernel/samsung.git -b android-samsung-3.0-ics-mr1

  7. Ensure the toolchain is in your path.
    • Default, Easy solution
      Quote:

      $ git clone https://android.googlesource.com/platform/prebuilt -b ics-plus-aosp
      $ 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 ics-plus-aosp
      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/crespo

      I hope you understand why I mentioned the bandwidth-friendly solution. With little insight you could have come up with it yourself.
  8. Now let's build the kernel
    Quote:

    $ export ARCH=arm
    $ export SUBARCH=arm
    $ export CROSS_COMPILE=arm-eabi-
    $ cd samsung
    $ make ARCH=arm herring_defconfig (maybe ARCH=arm is unneeded here but added it to be sure)
    $ make


  9. 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 'herring', shouldn't this be crespo? No, actually not. Herring is the board name, while crespo is the codename of the Nexus S. 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, ...
I am making the patch files currently
The Following 21 Users Say Thank You to djjonastybe For This Useful Post: [ View ] Gift djjonastybe Ad-Free
 
 
15th July 2012, 01:56 PM |#2  
boog's Avatar
Inactive Recognized Developer
Flag Trenton, Ohio
Thanks Meter: 584
 
More
Quote:
Originally Posted by djjonastybe

[B][COLOR="Red"]

$ export ARCH=arm
$ export SUBARCH=arm
$ export CROSS_COMPILE=arm-eabi-
$ cd omap
$ git checkout <commit_from_first_step> What to put here???
$ make panda_defconfig
$ make

You should have everything now ready to compile the aosp kernel

My method is:

$cd /path/to/kernel/source

$export ARCH=arm
$export CROSS_COMPILE=arm-eabi-
$export PATH=$PATH:~/path/to/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
$make herring_defconfig
$make

Just change the '/path/to' to match yours You can also make it a script.

The checkout command I don't use (but I do have all of the aosp source and 'set the environment' first '. build/envsetup.sh && lunch full_crespo-userdebug'). You can clone from git and it will all be in the folder you cloned in. To pull the latest, just use 'git pull'.

Hope that helps.
15th July 2012, 04:21 PM |#3  
snandlal's Avatar
Senior Member
Thanks Meter: 474
 
Donate to Me
More
How do you use linaro toolchain?
15th July 2012, 09:19 PM |#4  
boog's Avatar
Inactive Recognized Developer
Flag Trenton, Ohio
Thanks Meter: 584
 
More
Quote:
Originally Posted by snandlal

How do you use linaro toolchain?

I haven't used it, but theoretically you could export the path to the linaro tool chain instead of Google's gcc.

I have heard (have not confirmed) that there could be issues that may be introduced by using a different tool chain.

Sent from my Nexus S using xda app-developers app
15th July 2012, 11:33 PM |#5  
OP Senior Member
Flag Tienen
Thanks Meter: 350
 
Donate to Me
More
Now I need this:

Quote:

$ make ARCH=arm CROSS_COMPILE=arm-eabi- -j4
scripts/kconfig/conf --silentoldconfig Kconfig

*** Error during update of the configuration.

make[2]: *** [silentoldconfig] Error 1
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target `include/config/auto.conf', needed by `include/config/kernel.release'. Stop.

16th July 2012, 12:00 AM |#6  
snandlal's Avatar
Senior Member
Thanks Meter: 474
 
Donate to Me
More
Quote:
Originally Posted by boog

I haven't used it, but theoretically you could export the path to the linaro tool chain instead of Google's gcc.

I have heard (have not confirmed) that there could be issues that may be introduced by using a different tool chain.

Sent from my Nexus S using xda app-developers app


Cool, thanx
16th July 2012, 12:32 AM |#7  
boog's Avatar
Inactive Recognized Developer
Flag Trenton, Ohio
Thanks Meter: 584
 
More
Quote:
Originally Posted by djjonastybe

Now I need this:

Interesting....Sounds like it is maybe missing the files. I went back and reread your original instructions and instead of

try
Quote:

git clone https://android.googlesource.com/kernel/samsung.git -b android-samsung-3.0-ics-mr1

Leave off the sudo, you don't need it for doing things in your own home directory, you'll end up with a bunch of files that belong to root.
The Following User Says Thank You to boog For This Useful Post: [ View ] Gift boog Ad-Free
16th July 2012, 07:29 AM |#8  
OP Senior Member
Flag Tienen
Thanks Meter: 350
 
Donate to Me
More
Quote:
Originally Posted by boog

Interesting....Sounds like it is maybe missing the files. I went back and reread your original instructions and instead of



try


Leave off the sudo, you don't need it for doing things in your own home directory, you'll end up with a bunch of files that belong to root.

I think you are giving me wrong instructions? You mixed things up I think

I also noticed that gcc was not found because it had the wrong permissions. 'chmod 755 *' fixed it.

I am now trying again. I made a mistake.
16th July 2012, 08:49 AM |#9  
OP Senior Member
Flag Tienen
Thanks Meter: 350
 
Donate to Me
More
guide complete. thank you boog for helping. I hope I can help some people with this. It took some time to sort out.
16th July 2012, 11:14 AM |#10  
boog's Avatar
Inactive Recognized Developer
Flag Trenton, Ohio
Thanks Meter: 584
 
More
Quote:
Originally Posted by djjonastybe

I think you are giving me wrong instructions? You mixed things up I think

I also noticed that gcc was not found because it had the wrong permissions. 'chmod 755 *' fixed it.

I am now trying again. I made a mistake.

Ahh, ok, then it was probably due to checking out as sudo. Not trying to give wrong instructions. Just trying to help.

If you had to chmod them, it was possibly because the files might have belonged to root instead of your user, I didn't think of that.

I think the guide should help people get started tinkering with kernels
The Following User Says Thank You to boog For This Useful Post: [ View ] Gift boog Ad-Free
16th July 2012, 04:29 PM |#11  
OP Senior Member
Flag Tienen
Thanks Meter: 350
 
Donate to Me
More
Quote:
Originally Posted by boog

Ahh, ok, then it was probably due to checking out as sudo. Not trying to give wrong instructions. Just trying to help.

If you had to chmod them, it was possibly because the files might have belonged to root instead of your user, I didn't think of that.

I think the guide should help people get started tinkering with kernels

I really hope this too. I have been willing to do this since October 2011, but never got to it because I always thought it would be too difficult. Now I spent 3-4 days figuring everything out, with your help.

I still have few things on my list like adding a tutorial here on how to rename the kernel, and links to specific mods like Ezekeel's mods.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes