Building a kernel for an Android phone without the rom source

For the record, I do not recommend building kernels this way, I recommend that you build them within your ROM source. This method will work, but is far more labor intensive. However, here is how to build the kernel for a Samsung Galaxy Note Edge on Ubuntu 14.04.

Part 1 – The setup:
Go to

[CODE]
$ sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2 git make -y
[/CODE]

This will take a while. Then:

[CODE]
$ cd ~
$ mkdir playground
$ cd playground/
$ mkdir toolchain
$ cd toolchain
[/CODE]

Now type this for 4.9:

[CODE]
$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9
[/CODE]

OR this for 4.8, but for this I recommend 4.8.

[CODE]
$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8
[/CODE]

The output either way should look like this:

[CODE]
Cloning into ‘arm-linux-androideabi-4.8’…
remote: Sending approximately 170.26 MiB …
remote: Counting objects: 124, done
remote: Finding sources: 100% (124/124)
………EDITED FOR SPACE………………
Resolving deltas: 100% (652/652), done.
Checking connectivity… done.
[/CODE]

That will take a few minutes. Then:

[CODE]
$ mkdir kernel
$ cd kernel
$ git clone https://github.com/alaskalinuxuser/kernel_samsung_tblte.git
Cloning into ‘kernel_samsung_tblte’…
remote: Counting objects: 49082, done.
remote: Compressing objects: 100% (32/32), done.
………EDITED FOR SPACE………………
Checking connectivity… done.
Checking out files: 100% (46422/46422), done.
[/CODE]

This will take another few minutes, maybe longer, depending on your internet connection.

Part 2 – The kernel modifications

Before going further, this is when you can edit the files of the kernel, add things, remove things from the kernel itself. See the other posts here for how to do that. When you are ready, you can move onto the build.

Part 3 – The build

Open ~/playground/toolchain/kernel/kernel_samsung_tblte/Makefile, and go to line 195, it should say ARCH, edit it as such:

[CODE]
ARCH =arm
CROSS_COMPILE =/home/{YOURUSERNAME}/playground/toolchain/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-
[/CODE]

[CODE]
$ cd ~/playground/toolchain/kernel/kernel_samsung_tblte/
$ make clean
$ make mrproper
[/CODE]

You will likely see an error about TARGET, that is okay, just ignore it.

[CODE]
$ make menuconfig apq8084_sec_defconfig
[/CODE]

OR

[CODE]
$ make menuconfig apq8084_sec_tblte_eur_defconfig
[/CODE]

After some scrolling text, you will see a menu option. Use the arrow keys and the space bar to make selections. Make any changes you want. Remember, not all changes are good. With this setup, you will need to make changes to make this function.

Once you are done, select exit. Then select yes to save your config.

Now that you are back at the command line, all you have to do is type one more command:

[CODE]
$ make
[/CODE]

You will see a lot of scrolling text, like this:

[CODE]
arch/arm/kernel/return_address.c:63:2: warning: #warning “TODO: return_address should use unwind tables” [-Wcpp]
#warning “TODO: return_address should use unwind tables”
^
CC arch/arm/kernel/sched_clock.o
CC arch/arm/kernel/setup.o
CC arch/arm/kernel/signal.o
CC arch/arm/kernel/stacktrace.o
CC arch/arm/kernel/sys_arm.o
CC arch/arm/kernel/time.o
CC arch/arm/kernel/traps.o
CC arch/arm/kernel/atags_parse.o
CC arch/arm/kernel/cpuidle.o
[/CODE]

This is good. Make is making your kernel.
If you are good, or lucky, then it will compile successfully, if not, it will error. Check your changes and use Google to search for errors if you need help. Again, I recommend to build kernels within the backdrop of ROM source, as I mentioned in the other post, it is much, much easier. This method will work, but you may have to add or change a lot of options in your config to make it happen.

Linux – keep it simple.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s