In this article, we will build and flash samsung kernel from source code.The test environment is on Samsung Note5 Android6.0, Ubuntu 14.04.

1.Download samsung firmware

download samsung firmware on

and download the android6.0 source code(if you want to build custom system.img,i will tell this part in the next article)

2.Get android toolchain

you need toolchain to compile kernel on host.

3.Edit kernel’s Makefile

extract the firmware file, you will get Kernel.tar.gz、Platform.tar.gz(we will tell how to build and make system.img in the next article),etc.

next,extract Kernel.tar.gz and edit “CROSS_COMPILE” to right toolchain path(You downloaded).

  •     EX)  CROSS_COMPILE= $(android platform directory you download)android/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
  •     Ex)  CROSS_COMPILE=/usr/local/toolchain/aarch64-linux-android-4.9/bin/aarch64-linux-android- // check the location of toolchain


first,you need to set up build environment ,then use the following commands to build kernel (ps: modify the kernel as you want):

output file:

  • – Kernel : arch/arm/boot/zImage  |  arch/arm64/boot/Image
  • – module : drivers/*/*.ko

5.Make boot.img

the quickest way to make boot.img is to use these commands:

another way, make a boot.img manually:

Download pack and unpack tools from :

the struct of boot.img is as follow:

** +—————–+
** | boot header     | 1 page
** +—————–+
** | kernel               | n pages
** +—————–+
** | ramdisk            | m pages
** +—————–+
** | second stage    | o pages
** +—————–+

Find a boot.img that fit your device, you can find such image from a ROM package(extract ROM package and get boot.img).

Then find out the detail info of this boot.img:

Use perl script file ‘split_boot’ to extract kernel、ramdisk from this boot.img:

the output directory contains these files: boot.img-kernel、ramdisk.gz、extract output directory of ramdisk.gz


i want to get kernel symbol directly on the device, so we must set /proc/sys/kernel/kptr_restrict to 0. Open the extract output directory of ramdisk.gz and edit init.rc, change this line:


then edit default.prop change these lines:



to generate new ramdisk.gz.Finally, make new boot.img by mkbootimg(you can get param values by boot_info):

NOTICE1 :  the param may be different, make sure that you use the right param

NOTICE2:  do not forget  wipe data/factory and wipe cache partition( reboot into recovery first)

NOTICE3:  you can directly use Android Image KitChen to pack and unpack boot.img

6.Flash boot.img to device

download CROM Service to unlock the Samsung bootloader.

In ubuntu,you should install heimdall and heimdall-frontend first (like odin in linux,you can download it from here:,and use sudo to run heimdall-frontend

the partition name in Samsung may be different from other devices:

Connect your device to Ubuntu by USB cable ,in utilities tab,you can click Detect button to  find out whether the device is being recognized or not:

Save as the pit file of your phone to a special file(Save as -> Download), then switch to flash tab,

use pit file you have just saved and add boot partition,choose boot.img that  built in step 5,  do not click Repartition checkbox , finally start flash and reboot the device, you will have custom kernel in your device!

NOTICE:if you don’t wipe data/factory and wipe cache, flash boot.img with system.img and cache.img,or could not reboot.