[Guide] How to build kernel from source on ubuntu 13.10...

Search This thread

k2wl

Senior Member
Apr 19, 2008
3,166
7,574
Here are the steps to build your own kernel from source. This guide is showing you how to build your first the stock kernel on your own..... It is kick start for making things on your own way....

This guide applies to i9082/i9082L and general devices also.:eek::laugh:

This guide assumes you have basic knowledge of linux and linux system configuration.

Prerequisites
1. Ubuntu 13.10
2. patience...lots and lots of patience.
Here starts the fun:-

1. Installing ubuntu 13.10.

This can be done in 3 ways and I am not gonna cover it all.
- along with windows ,i.e dual boot
- in virtualbox within windows
- as a windows application installation with "wubi" installer

For starting user i think second option, i.e installing in virtualbox is best.
here's starting tutorials
http://www.youtube.com/watch?v=tDDRFiwHujg

NOTE - you should have atleast 100 Gb partion for virtualbox.
2. Getting the kernel source.

Download source from http://opensource.samsung.com/
Type i9082 in search box and download "GT-I9082_SEA_JB_Opensource_Update1.zip"

After download unzip the source into new folder in home directory.
Type in terminal from you kernel directory.

Code:
unzip GT-I9082_SEA_JB_Opensource_Update1.zip


Then extract tar.

Code:
mkdir kernel
tar xzf kernel.tar.gz -C kernel


3. Setting up building environment.

Initializing a fresh Android Build Environment in Ubuntu 13.10 sucks, right? The instructions at the AOSP page are outdated and inaccurate. Near as I can tell, they try to have you install 2 JDKs, the first one not even being the correct link for Saucy Salamander, and the second being OpenJDK. Which might work. But I dunno about all that, I’d rather have Oracle’s official stamp when it comes to building for Android.
Currently most of the guides are up to 12.04 LTS, which is fine and dandy, but being on the cutting edge is nice too.
This guide applies to all variations of Ubuntu 13.10 Saucy Salamander 64 bit. Do not use the 32 Bit version. Also, PAY CLOSE ATTENTION when to use “sudo” and when to not. It can make things funky if you do something as root that you shouldn’t.
Much thanks goes out to Google, ProTekk, Canonical, and everyone else that I read a random paragraph here and snippet there.

First, let’s set up the correct JDK.

Many of you probably have some kind of wrong Java installed unless you’re starting with a fresh Ubuntu base, and even then maybe.

Let’s get rid of that. Copy and paste this into a Terminal window:

Code:
sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
Follow the instructions to remove OpenJDK.

If you must keep it, it’s possible. But I’m not going to tell you how to do it here. I don’t want any chance of confusion or mistake.

Now copy and paste the following into the Terminal:

Code:
sudo add-apt-repository ppa:webupd8team/java
This will add the correct PPA to your system for updated builds of Java 6 JDK that are compatible with 13.10.

No more unrecognized Java version errors! And it will update automatically with the rest of your system.

Next, we actually need to install the package. More copy-paste:

Code:
sudo apt-get update && sudo apt-get install oracle-java6-installer
Follow the on-screen instructions. You have to Accept the Licensing Agreement to complete the install. Hopefully no human centipede clauses.

Let’s make sure the correct version of Java is activated, run the following Terminal command:

Code:
java -version
You should see something like the following:

Code:
java version “1.6.0_45″
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)
Ok, back to a fresh Terminal prompt. Time for installing the guts to build stuff in Ubuntu:

Code:
sudo apt-get install git-core gnupg ccache lzop flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5 lib32z1 lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python
When that is done installing, run the following command in your Terminal window:

Code:
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
That’s it on the package side of things.

You guessed it, time for more Terminal. This really is the easiest way, seriously. And it’s totally worth it when you’re basking in the glory of a bunch of people on XDA.

The binary for a program called “repo” will let you talk to git servers and download all that precious source code. That second part after the && allows it to be executable:

Code:
mkdir ~/bin && curl http://commondatastorage.googleapis.com/git-repo-downloads/repo ~/bin/repo && chmod a+x ~/bin/repo
Use your favorite text editor to open ~/.bashrc

I like nano:

Code:
sudo nano ~/.bashrc
At the very bottom, add the following line:

Code:
export PATH=~/bin:$PATH
Save it. In nano that would be Ctrl-O and then Enter. Then Ctrl-X to exit back to a prompt. Restart bash:

Code:
source ~/.bashrc
That should be everything. Now you’re ready to build Android the right way. Luck!


4. Installing toolchain


Anyway, first order of the day is to get the official arm toolchain, which I'm going to install in /usr/local/share/ since I plan to keep using it for some time:

Code:
# cd /usr/local/share/
# git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
Cloning into 'arm-eabi-4.6'...
remote: Sending approximately 124.64 MiB ...
remote: Counting objects: 33, done
remote: Finding sources: 100% (33/33)
remote: Total 580 (delta 146), reused 580 (delta 146)
Receiving objects: 100% (580/580), 124.64 MiB | 715 KiB/s, done.
Resolving deltas: 100% (146/146), done.
Now, let's add that arm toolchain to our path:

Code:
# export PATH=$PATH:/usr/local/share/arm-eabi-4.6/bin
# arm-eabi-gcc --version
arm-eabi-gcc (GCC) 4.6.x-google 20120106 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5. Compiling kernel

Now we need to set the variables that will tell the OS that we're cross compiling (again, something that you may want to do in your .profile using something like alias cross='export ARCH="arm";export SUBARCH="arm";export CROSS_COMPILE="arm-eabi-"'):

Code:
# export ARCH=arm
# export SUBARCH=arm
# export CROSS_COMPILE=arm-eabi-
Finally, we can initialize our default config and get going:
Prepare source for new compilation

Code:
make bcm28155_capri_ss_baffin_rev05_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/lex.zconf.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
arch/arm/mach-capri/custom_boards/Kconfig:19:warning: defaults for choice values not supported
arch/arm/mach-capri/custom_boards/Kconfig:25:warning: defaults for choice values not supported
arch/arm/mach-capri/custom_boards/Kconfig:31:warning: defaults for choice values not supported
arch/arm/mach-capri/custom_boards/Kconfig:37:warning: defaults for choice values not supported
#
# configuration written to .config
#
Code:
# make -j* 
(...)
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready
* stands for number of cpus your computer has.like my has 4 so I will make it j4

* bcm28155_capri_ss_baffin_rev05_defconfig is stock config, for cm11 you will have diffrent config and for some cutom kernel something else.

6. Crafting an Android boot.img

The format of this Android boot images can be found in the bootimg.h of the mkbootimg tool from the android platform/system/core source. I guess we have to start somewhere, and we'll need to produce our own images, so let's start by fetching and recompiling mkbootimg then.

Code:
# git clone https://android.googlesource.com/platform/system/core bootimg-tools
Cloning into 'bootimg-tools'...
remote: Counting objects: 92, done
remote: Finding sources: 100% (92/92)
remote: Total 19302 (delta 11674), reused 19302 (delta 11674)
Receiving objects: 100% (19302/19302), 5.87 MiB | 655 KiB/s, done.
Resolving deltas: 100% (11674/11674), done.
# cd bootimg-tools/libmincrypt/
# gcc -c *.c -I../include
# ar rcs libmincrypt.a *.o
# cd ../mkbootimg
# gcc mkbootimg.c -o mkbootimg -I../include ../libmincrypt/libmincrypt.a
mkbootimg.c: In function 'main':
mkbootimg.c:245:9: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
# cp mkbootimg /usr/local/bin/
# cd ../cpio
# gcc mkbootfs.c  -o mkbootfs -I../include
# cp mkbootfs /usr/local/bin/
New improved bootimg-tools can be found at.

Code:
# wget https://github.com/pbatard/bootimg-tools/archive/master.zip
lets compile from there

Code:
# cd /usr/src/android/bootimg-tools/mkbootimg/
# wget https://raw.github.com/pbatard/bootimg-tools/master/mkbootimg/unmkbootimg.c
# gcc -o unmkbootimg unmkbootimg.c
# cp unmkbootimg /usr/local/bin/
Now at last, you have the minimum of unmkbootimg, mkbootimg and mkbootfs installed in your path, and we can get going with our testing of the kernel.
I'll assume that you have a /usr/src/android/boot where you copied your boot.img, so let's get going....

Code:
# cd /usr/src/android/boot/
# ls
boot.img
# unmkbootimg -i boot.img
kernel written to 'kernel' (4738320 bytes)
ramdisk written to 'ramdisk.cpio.gz' (516287 bytes)

To rebuild this boot image, you can use the command:
  mkbootimg --base 0 --pagesize 4096 --kernel_offset 0xa2008000 --ramdisk_offset 0xa3000000 --second_offset 0xa2f00000 --tags_offset 0xa2000100 --cmdline 'console=ttyS0,115200n8 mem=832M@0xA2000000 androidboot.console=ttyS0 vc-cma-mem=0/176M@0xCB000000' --kernel kernel --ramdisk ramdisk.cpio.gz -o boot.img
Code:
# ls
boot.img  kernel  ramdisk.cpio.gz
As an aside that you don't need to run, but since it should be elementary that this is the basic functionality you want from a proper boot image unpack tool, we can confirm that the data provided by the unpack tool will produce a boot.img that is binary identical to the original one-

Code:
# mkbootimg --base 0 --pagesize 4096 --kernel_offset 0xa2008000 --ramdisk_offset 0xa3000000 --second_offset 0xa2f00000 --tags_offset 0xa2000100 --cmdline 'console=ttyS0,115200n8 mem=832M@0xA2000000 androidboot.console=ttyS0 vc-cma-mem=0/176M@0xCB000000' --kernel kernel --ramdisk ramdisk.cpio.gz -o myboot.img
Code:
# ls
boot.img  kernel  myboot.img  ramdisk.cpio.gz
# cmp -l boot.img myboot.img
#
Moving on. Since we just want to test a kernel, we shouldn't really have to touch the cpio image (ramdisk), but then again, my goal here is to give you as many pointers as I can, so we might as well see how we craft our own ramdisk while we're at it. What we're going to do here, as an academical exercise, is add an it_works file at the root of the filesystem, which we'll look for after we booted, to confirm that can use our modified stuff all the way through.

Code:
# mkdir ramdisk
# cd ramdisk
# gunzip -c ../ramdisk.cpio.gz | cpio -iu
1841 blocks

# ls
charger                           init.superuser.rc
data                              init.trace.rc
default.prop                      init.usb.rc
dev                               lpm.rc
file_contexts                     proc
fstab.capri_ss_baffin             property_contexts
fstab.goldfish                    res
init                              sbin
init.bcm281x5.usb.rc              seapp_contexts
init.capri_ss_baffin.rc           sepolicy
init.cm.rc                        sys
init.environ.rc                   system
init.goldfish.rc                  ueventd.capri_ss_baffin.rc
init.log.rc                       ueventd.goldfish.rc
init.rc                           ueventd.rc
init.recovery.capri_ss_baffin.rc

# touch it-works
# ls


charger                           init.superuser.rc
data                              init.trace.rc
default.prop                      init.usb.rc
dev                               it-works
file_contexts                     lpm.rc
fstab.capri_ss_baffin             proc
fstab.goldfish                    property_contexts
init                              res
init.bcm281x5.usb.rc              sbin
init.capri_ss_baffin.rc           seapp_contexts
init.cm.rc                        sepolicy
init.environ.rc                   sys
init.goldfish.rc                  system
init.log.rc                       ueventd.capri_ss_baffin.rc
init.rc                           ueventd.goldfish.rc
init.recovery.capri_ss_baffin.rc  ueventd.rc


# find . | cpio -o -H newc | gzip > ../myramdisk.cpio.gz

1850 blocks

# cd ..
# ls
boot.img  kernel  myramdisk.cpio.gz  ramdisk/  ramdisk.cpio.gz
We're finally set for the last part, where we copy the kernel we compiled earlier, and invoke mkbootimg with the set of parameters we got from unmkbootimg, and use both our modified kernel and cpio image:

Code:
# cp ~/kernel/arch/arm/boot/zImage .
# ls
boot.img  kernel  myramdisk.cpio.gz  ramdisk/  ramdisk.cpio.gz  zImage*
# mkbootimg --base 0 --pagesize 4096 --kernel_offset  0xa2008000 --ramdisk_offset 0xa3000000 --second_offset 0xa2f00000  --tags_offset 0xa2000100 --cmdline 'console=ttyS0,115200n8  mem=832M@0xA2000000 androidboot.console=ttyS0  vc-cma-mem=0/176M@0xCB000000' --kernel zImage --ramdisk myramdisk.cpio.gz  -o myboot.img
# ls
boot.img  kernel  myboot.img  myramdisk.cpio.gz  ramdisk/  ramdisk.cpio.gz  zImage*
7. testing new boot.img

Finally, a custom boot.img we can test. Let's press on by copying this myboot.img file into the directory we have adb and fastboot installed and run the following ser of commands which, unlike what many other guides seem to advise (what the heck, guys?), is NOT going to flash the kernel/boot.img but simply run it from memory. This means that, in case there's any mishap, you can simply power the "grand" off and you'll be good as new:

Code:
# ./adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
# ./adb reboot bootloader
# ./fastboot boot myboot.img
downloading 'boot.img'...
OKAY [  0.223s]
booting...
OKAY [  0.023s]
finished. total time: 0.246s
All in all, this looks fairly good. And a quick look to the root filesystem (through adb shell or through ssh) will also confirm that our it_works file is there, so we can also add whatever we want on the initial filesystem. Neat!

From there on, you can go ahead and tweak your kernel and initial filesystem exactly as you see fit. And after you have tested that everything works as it should, you can go ahead and flash the boot partition with your shiny custom boot.img, using:

ODIN or cwm flashable zip

This is last part...

8. making flashable files

Tar your boot.img file so it can be flashed with Odin.
tar cvf mynewkernel.tar boot.img
md5sum -t
mynewkernel.tar >> mynewkernel.tar
mv
mynewkernel.tar mynewkernel.tar.md5
Note:- myboot.img is renamed to boot.img

9.Flashing kernel through ODIN

Flash mynewkernel.tar.md5 with odin under PDA. Please follow the flashing guides found in other posts.

Hope i help few of you...
Please HIT thanks if you find this helpful.:laugh::eek:
 
Last edited:

k2wl

Senior Member
Apr 19, 2008
3,166
7,574
Thankyou k2wl for this tutorial :)and pls also tell how to get pawitp source code for rom and kernel from his repositries : https://github.com/pawitp/android_device_samsung_i9082
https://github.com/pawitp/android_kernel_samsung_i9082

Repo tool is not working because there is no android manifest file in his repository
Pls help me

run the following in terminal

$git clone https://github.com/pawitp/android_device_samsung_i9082.git

and

$ git clone https://github.com/pawitp/android_kernel_samsung_i9082.git
 
  • Like
Reactions: mr.phantom

mr.phantom

Senior Member
Oct 15, 2012
451
412
27
Chandigarh
ashishbansal.in
Last edited:

k2wl

Senior Member
Apr 19, 2008
3,166
7,574
hi

well i already have done that cloning for cm11 but it had only downloaded files around 200KB and i dont think so that cm11 source code would be that much small :confused:

That's not cm11 source. For that u need another tutorial.
Meanwhile try wiki.CyanogenMod.org
It has instructions for Building for new device
 
  • Like
Reactions: mr.phantom

jayc137

Senior Member
Sep 5, 2012
1,815
865
Mumbai
Code:
unmkbootimg.c:25:21: fatal error: bootimg.h: No such file or directory
 #include "bootimg.h"
                     ^
compilation terminated.

Getting this while compiling unmkbootimg
 

raghavsharmaxda

Senior Member
Dec 14, 2013
852
397
28
mumbai
i actually am surprises that there are many unofficial CMs in high ends with HALO IN IT.. though our developers try to make rom as close to real one as possible...what if the users want halo integration (as developers only know it :/)
help..
 

k2wl

Senior Member
Apr 19, 2008
3,166
7,574
i actually am surprises that there are many unofficial CMs in high ends with HALO IN IT.. though our developers try to make rom as close to real one as possible...what if the users want halo integration (as developers only know it :/)
help..

try compiling as a root.

How to convert zImage to boot.img
Or do I have to directly copy it ?

Sent from my GT-I9082 using Tapatalk


read the last section of post, it covers the conversion of zimage to boot.img...
seems you compiled successfully.
congrats.:victory:
 

jayc137

Senior Member
Sep 5, 2012
1,815
865
Mumbai
But what about boot.img ?
We need a boot.img in /android/boot ?
Now at last, you have the minimum of unmkbootimg, mkbootimg and mkbootfs installed in your path, and we can get going with our testing of the kernel.
I'll assume that you have a /usr/src/android/boot where you copied your boot.img, so let's get going....
 
  • Like
Reactions: majidalwrafi
T

TripRex

Guest
Hi @k2wl.For the part "make -j8",if you don't mind putting a sign for others to only compile at the amount of their CPU have otherwise it will caused some error for others who are compiling

1 CPU= make -j1 with least error



Sent from my iPad using Tapatalk
 
Last edited:

k2wl

Senior Member
Apr 19, 2008
3,166
7,574
But what about boot.img ?
We need a boot.img in /android/boot ?

take one from my stock kernel zip....

Hi @k2wl.For the part "make -j8",if you don't mind putting a sign for others to only compile at the amount of their CPU have otherwise it will caused some error for others who are compiling

1 CPU= make -j1 with least error



Sent from my iPad using Tapatalk

thanks for suggestion.

Really nice guide especially about packing the initramfs with the zimage to make boot.img.

Sent from my GT-I9082 using Tapatalk

thanks....will modify more..
 

jayc137

Senior Member
Sep 5, 2012
1,815
865
Mumbai
Thanks to ya k2wl
eba9e4un.jpg


Sent from my GT-I9082 using Tapatalk
 

k2wl

Senior Member
Apr 19, 2008
3,166
7,574
happy developing.....glad i helped you...
keep trying for learning new features...
 

xenon92

Inactive Recognized Developer
May 20, 2013
762
3,469
shubhangrathore.com
OnePlus 9 Pro
Hey @k2wl

Just wanted to say thank you for this comprehensive guide. Very detailed.

I never had any interest in tweaking a kernel. I am more of a java guy. But after reading your guide, I thought, why not?!

So I started working on it. Now I have a fully functional kernel compiled separately from the ROMs that I compile. :)

I even named it. Nebula Kernel.

Learning alot about kernels since I started working on it. As I am tweaking nebula for myself and i'll use this kernel as my daily driver so i'll add tweaks and governors according to me, the ones which I'll use. I like keeping things light and simple! I'll use your github for reference and help. If I face any problems, I'll ask you.

Thank you for the guide!

yhy9yqen.jpg
 
  • Like
Reactions: jayc137

Top Liked Posts

  • There are no posts matching your filters.
  • 21
    Here are the steps to build your own kernel from source. This guide is showing you how to build your first the stock kernel on your own..... It is kick start for making things on your own way....

    This guide applies to i9082/i9082L and general devices also.:eek::laugh:

    This guide assumes you have basic knowledge of linux and linux system configuration.

    Prerequisites
    1. Ubuntu 13.10
    2. patience...lots and lots of patience.
    Here starts the fun:-

    1. Installing ubuntu 13.10.

    This can be done in 3 ways and I am not gonna cover it all.
    - along with windows ,i.e dual boot
    - in virtualbox within windows
    - as a windows application installation with "wubi" installer

    For starting user i think second option, i.e installing in virtualbox is best.
    here's starting tutorials
    http://www.youtube.com/watch?v=tDDRFiwHujg

    NOTE - you should have atleast 100 Gb partion for virtualbox.
    2. Getting the kernel source.

    Download source from http://opensource.samsung.com/
    Type i9082 in search box and download "GT-I9082_SEA_JB_Opensource_Update1.zip"

    After download unzip the source into new folder in home directory.
    Type in terminal from you kernel directory.

    Code:
    unzip GT-I9082_SEA_JB_Opensource_Update1.zip


    Then extract tar.

    Code:
    mkdir kernel
    tar xzf kernel.tar.gz -C kernel


    3. Setting up building environment.

    Initializing a fresh Android Build Environment in Ubuntu 13.10 sucks, right? The instructions at the AOSP page are outdated and inaccurate. Near as I can tell, they try to have you install 2 JDKs, the first one not even being the correct link for Saucy Salamander, and the second being OpenJDK. Which might work. But I dunno about all that, I’d rather have Oracle’s official stamp when it comes to building for Android.
    Currently most of the guides are up to 12.04 LTS, which is fine and dandy, but being on the cutting edge is nice too.
    This guide applies to all variations of Ubuntu 13.10 Saucy Salamander 64 bit. Do not use the 32 Bit version. Also, PAY CLOSE ATTENTION when to use “sudo” and when to not. It can make things funky if you do something as root that you shouldn’t.
    Much thanks goes out to Google, ProTekk, Canonical, and everyone else that I read a random paragraph here and snippet there.

    First, let’s set up the correct JDK.

    Many of you probably have some kind of wrong Java installed unless you’re starting with a fresh Ubuntu base, and even then maybe.

    Let’s get rid of that. Copy and paste this into a Terminal window:

    Code:
    sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
    Follow the instructions to remove OpenJDK.

    If you must keep it, it’s possible. But I’m not going to tell you how to do it here. I don’t want any chance of confusion or mistake.

    Now copy and paste the following into the Terminal:

    Code:
    sudo add-apt-repository ppa:webupd8team/java
    This will add the correct PPA to your system for updated builds of Java 6 JDK that are compatible with 13.10.

    No more unrecognized Java version errors! And it will update automatically with the rest of your system.

    Next, we actually need to install the package. More copy-paste:

    Code:
    sudo apt-get update && sudo apt-get install oracle-java6-installer
    Follow the on-screen instructions. You have to Accept the Licensing Agreement to complete the install. Hopefully no human centipede clauses.

    Let’s make sure the correct version of Java is activated, run the following Terminal command:

    Code:
    java -version
    You should see something like the following:

    Code:
    java version “1.6.0_45″
    Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
    Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)
    Ok, back to a fresh Terminal prompt. Time for installing the guts to build stuff in Ubuntu:

    Code:
    sudo apt-get install git-core gnupg ccache lzop flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5 lib32z1 lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python
    When that is done installing, run the following command in your Terminal window:

    Code:
    sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
    That’s it on the package side of things.

    You guessed it, time for more Terminal. This really is the easiest way, seriously. And it’s totally worth it when you’re basking in the glory of a bunch of people on XDA.

    The binary for a program called “repo” will let you talk to git servers and download all that precious source code. That second part after the && allows it to be executable:

    Code:
    mkdir ~/bin && curl http://commondatastorage.googleapis.com/git-repo-downloads/repo ~/bin/repo && chmod a+x ~/bin/repo
    Use your favorite text editor to open ~/.bashrc

    I like nano:

    Code:
    sudo nano ~/.bashrc
    At the very bottom, add the following line:

    Code:
    export PATH=~/bin:$PATH
    Save it. In nano that would be Ctrl-O and then Enter. Then Ctrl-X to exit back to a prompt. Restart bash:

    Code:
    source ~/.bashrc
    That should be everything. Now you’re ready to build Android the right way. Luck!


    4. Installing toolchain


    Anyway, first order of the day is to get the official arm toolchain, which I'm going to install in /usr/local/share/ since I plan to keep using it for some time:

    Code:
    # cd /usr/local/share/
    # git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
    Cloning into 'arm-eabi-4.6'...
    remote: Sending approximately 124.64 MiB ...
    remote: Counting objects: 33, done
    remote: Finding sources: 100% (33/33)
    remote: Total 580 (delta 146), reused 580 (delta 146)
    Receiving objects: 100% (580/580), 124.64 MiB | 715 KiB/s, done.
    Resolving deltas: 100% (146/146), done.
    Now, let's add that arm toolchain to our path:

    Code:
    # export PATH=$PATH:/usr/local/share/arm-eabi-4.6/bin
    # arm-eabi-gcc --version
    arm-eabi-gcc (GCC) 4.6.x-google 20120106 (prerelease)
    Copyright (C) 2011 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    5. Compiling kernel

    Now we need to set the variables that will tell the OS that we're cross compiling (again, something that you may want to do in your .profile using something like alias cross='export ARCH="arm";export SUBARCH="arm";export CROSS_COMPILE="arm-eabi-"'):

    Code:
    # export ARCH=arm
    # export SUBARCH=arm
    # export CROSS_COMPILE=arm-eabi-
    Finally, we can initialize our default config and get going:
    Prepare source for new compilation

    Code:
    make bcm28155_capri_ss_baffin_rev05_defconfig
      HOSTCC  scripts/basic/fixdep
      HOSTCC  scripts/kconfig/conf.o
      SHIPPED scripts/kconfig/zconf.tab.c
      SHIPPED scripts/kconfig/lex.zconf.c
      SHIPPED scripts/kconfig/zconf.hash.c
      HOSTCC  scripts/kconfig/zconf.tab.o
      HOSTLD  scripts/kconfig/conf
    arch/arm/mach-capri/custom_boards/Kconfig:19:warning: defaults for choice values not supported
    arch/arm/mach-capri/custom_boards/Kconfig:25:warning: defaults for choice values not supported
    arch/arm/mach-capri/custom_boards/Kconfig:31:warning: defaults for choice values not supported
    arch/arm/mach-capri/custom_boards/Kconfig:37:warning: defaults for choice values not supported
    #
    # configuration written to .config
    #
    Code:
    # make -j* 
    (...)
      OBJCOPY arch/arm/boot/zImage
      Kernel: arch/arm/boot/zImage is ready
    * stands for number of cpus your computer has.like my has 4 so I will make it j4

    * bcm28155_capri_ss_baffin_rev05_defconfig is stock config, for cm11 you will have diffrent config and for some cutom kernel something else.

    6. Crafting an Android boot.img

    The format of this Android boot images can be found in the bootimg.h of the mkbootimg tool from the android platform/system/core source. I guess we have to start somewhere, and we'll need to produce our own images, so let's start by fetching and recompiling mkbootimg then.

    Code:
    # git clone https://android.googlesource.com/platform/system/core bootimg-tools
    Cloning into 'bootimg-tools'...
    remote: Counting objects: 92, done
    remote: Finding sources: 100% (92/92)
    remote: Total 19302 (delta 11674), reused 19302 (delta 11674)
    Receiving objects: 100% (19302/19302), 5.87 MiB | 655 KiB/s, done.
    Resolving deltas: 100% (11674/11674), done.
    # cd bootimg-tools/libmincrypt/
    # gcc -c *.c -I../include
    # ar rcs libmincrypt.a *.o
    # cd ../mkbootimg
    # gcc mkbootimg.c -o mkbootimg -I../include ../libmincrypt/libmincrypt.a
    mkbootimg.c: In function 'main':
    mkbootimg.c:245:9: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
    # cp mkbootimg /usr/local/bin/
    # cd ../cpio
    # gcc mkbootfs.c  -o mkbootfs -I../include
    # cp mkbootfs /usr/local/bin/
    New improved bootimg-tools can be found at.

    Code:
    # wget https://github.com/pbatard/bootimg-tools/archive/master.zip
    lets compile from there

    Code:
    # cd /usr/src/android/bootimg-tools/mkbootimg/
    # wget https://raw.github.com/pbatard/bootimg-tools/master/mkbootimg/unmkbootimg.c
    # gcc -o unmkbootimg unmkbootimg.c
    # cp unmkbootimg /usr/local/bin/
    Now at last, you have the minimum of unmkbootimg, mkbootimg and mkbootfs installed in your path, and we can get going with our testing of the kernel.
    I'll assume that you have a /usr/src/android/boot where you copied your boot.img, so let's get going....

    Code:
    # cd /usr/src/android/boot/
    # ls
    boot.img
    # unmkbootimg -i boot.img
    kernel written to 'kernel' (4738320 bytes)
    ramdisk written to 'ramdisk.cpio.gz' (516287 bytes)
    
    To rebuild this boot image, you can use the command:
      mkbootimg --base 0 --pagesize 4096 --kernel_offset 0xa2008000 --ramdisk_offset 0xa3000000 --second_offset 0xa2f00000 --tags_offset 0xa2000100 --cmdline 'console=ttyS0,115200n8 mem=832M@0xA2000000 androidboot.console=ttyS0 vc-cma-mem=0/176M@0xCB000000' --kernel kernel --ramdisk ramdisk.cpio.gz -o boot.img
    Code:
    # ls
    boot.img  kernel  ramdisk.cpio.gz
    As an aside that you don't need to run, but since it should be elementary that this is the basic functionality you want from a proper boot image unpack tool, we can confirm that the data provided by the unpack tool will produce a boot.img that is binary identical to the original one-

    Code:
    # mkbootimg --base 0 --pagesize 4096 --kernel_offset 0xa2008000 --ramdisk_offset 0xa3000000 --second_offset 0xa2f00000 --tags_offset 0xa2000100 --cmdline 'console=ttyS0,115200n8 mem=832M@0xA2000000 androidboot.console=ttyS0 vc-cma-mem=0/176M@0xCB000000' --kernel kernel --ramdisk ramdisk.cpio.gz -o myboot.img
    Code:
    # ls
    boot.img  kernel  myboot.img  ramdisk.cpio.gz
    # cmp -l boot.img myboot.img
    #
    Moving on. Since we just want to test a kernel, we shouldn't really have to touch the cpio image (ramdisk), but then again, my goal here is to give you as many pointers as I can, so we might as well see how we craft our own ramdisk while we're at it. What we're going to do here, as an academical exercise, is add an it_works file at the root of the filesystem, which we'll look for after we booted, to confirm that can use our modified stuff all the way through.

    Code:
    # mkdir ramdisk
    # cd ramdisk
    # gunzip -c ../ramdisk.cpio.gz | cpio -iu
    1841 blocks
    
    # ls
    charger                           init.superuser.rc
    data                              init.trace.rc
    default.prop                      init.usb.rc
    dev                               lpm.rc
    file_contexts                     proc
    fstab.capri_ss_baffin             property_contexts
    fstab.goldfish                    res
    init                              sbin
    init.bcm281x5.usb.rc              seapp_contexts
    init.capri_ss_baffin.rc           sepolicy
    init.cm.rc                        sys
    init.environ.rc                   system
    init.goldfish.rc                  ueventd.capri_ss_baffin.rc
    init.log.rc                       ueventd.goldfish.rc
    init.rc                           ueventd.rc
    init.recovery.capri_ss_baffin.rc
    
    # touch it-works
    # ls
    
    
    charger                           init.superuser.rc
    data                              init.trace.rc
    default.prop                      init.usb.rc
    dev                               it-works
    file_contexts                     lpm.rc
    fstab.capri_ss_baffin             proc
    fstab.goldfish                    property_contexts
    init                              res
    init.bcm281x5.usb.rc              sbin
    init.capri_ss_baffin.rc           seapp_contexts
    init.cm.rc                        sepolicy
    init.environ.rc                   sys
    init.goldfish.rc                  system
    init.log.rc                       ueventd.capri_ss_baffin.rc
    init.rc                           ueventd.goldfish.rc
    init.recovery.capri_ss_baffin.rc  ueventd.rc
    
    
    # find . | cpio -o -H newc | gzip > ../myramdisk.cpio.gz
    
    1850 blocks
    
    # cd ..
    # ls
    boot.img  kernel  myramdisk.cpio.gz  ramdisk/  ramdisk.cpio.gz
    We're finally set for the last part, where we copy the kernel we compiled earlier, and invoke mkbootimg with the set of parameters we got from unmkbootimg, and use both our modified kernel and cpio image:

    Code:
    # cp ~/kernel/arch/arm/boot/zImage .
    # ls
    boot.img  kernel  myramdisk.cpio.gz  ramdisk/  ramdisk.cpio.gz  zImage*
    # mkbootimg --base 0 --pagesize 4096 --kernel_offset  0xa2008000 --ramdisk_offset 0xa3000000 --second_offset 0xa2f00000  --tags_offset 0xa2000100 --cmdline 'console=ttyS0,115200n8  mem=832M@0xA2000000 androidboot.console=ttyS0  vc-cma-mem=0/176M@0xCB000000' --kernel zImage --ramdisk myramdisk.cpio.gz  -o myboot.img
    # ls
    boot.img  kernel  myboot.img  myramdisk.cpio.gz  ramdisk/  ramdisk.cpio.gz  zImage*
    7. testing new boot.img

    Finally, a custom boot.img we can test. Let's press on by copying this myboot.img file into the directory we have adb and fastboot installed and run the following ser of commands which, unlike what many other guides seem to advise (what the heck, guys?), is NOT going to flash the kernel/boot.img but simply run it from memory. This means that, in case there's any mishap, you can simply power the "grand" off and you'll be good as new:

    Code:
    # ./adb start-server
    * daemon not running. starting it now on port 5037 *
    * daemon started successfully *
    # ./adb reboot bootloader
    # ./fastboot boot myboot.img
    downloading 'boot.img'...
    OKAY [  0.223s]
    booting...
    OKAY [  0.023s]
    finished. total time: 0.246s
    All in all, this looks fairly good. And a quick look to the root filesystem (through adb shell or through ssh) will also confirm that our it_works file is there, so we can also add whatever we want on the initial filesystem. Neat!

    From there on, you can go ahead and tweak your kernel and initial filesystem exactly as you see fit. And after you have tested that everything works as it should, you can go ahead and flash the boot partition with your shiny custom boot.img, using:

    ODIN or cwm flashable zip

    This is last part...

    8. making flashable files

    Tar your boot.img file so it can be flashed with Odin.
    tar cvf mynewkernel.tar boot.img
    md5sum -t
    mynewkernel.tar >> mynewkernel.tar
    mv
    mynewkernel.tar mynewkernel.tar.md5
    Note:- myboot.img is renamed to boot.img

    9.Flashing kernel through ODIN

    Flash mynewkernel.tar.md5 with odin under PDA. Please follow the flashing guides found in other posts.

    Hope i help few of you...
    Please HIT thanks if you find this helpful.:laugh::eek:
    1
    Thankyou k2wl for this tutorial :)and pls also tell how to get pawitp source code for rom and kernel from his repositries : https://github.com/pawitp/android_device_samsung_i9082
    https://github.com/pawitp/android_kernel_samsung_i9082

    Repo tool is not working because there is no android manifest file in his repository
    Pls help me

    run the following in terminal

    $git clone https://github.com/pawitp/android_device_samsung_i9082.git

    and

    $ git clone https://github.com/pawitp/android_kernel_samsung_i9082.git
    1
    hi

    well i already have done that cloning for cm11 but it had only downloaded files around 200KB and i dont think so that cm11 source code would be that much small :confused:

    That's not cm11 source. For that u need another tutorial.
    Meanwhile try wiki.CyanogenMod.org
    It has instructions for Building for new device
    1
    But what about boot.img ?
    We need a boot.img in /android/boot ?
    Now at last, you have the minimum of unmkbootimg, mkbootimg and mkbootfs installed in your path, and we can get going with our testing of the kernel.
    I'll assume that you have a /usr/src/android/boot where you copied your boot.img, so let's get going....
    1
    ok will check it out and will you make a guide for that also?? :D

    if people wanted it, will make cm11 compilation from source tutorial for it.