[Note Edge General] AlaskaLinuxUser:
Post #6. kernel - How to build just a kernel stand alone.

Post #6. kernel - How to build just a kernel stand alone, without 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.

Part 1 - The setup:

Go to

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

This will take a while. Then:

$ cd ~
$ mkdir playground
$ cd playground/
$ mkdir toolchain
$ cd toolchain

Now type this for 4.9:

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

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

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

The output either way should look like this:

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.

That will take a few minutes. Then:

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

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:

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

$ cd ~/playground/toolchain/kernel/kernel_samsung_tblte/
$ make clean
$ make mrproper

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

$ make menuconfig apq8084_sec_defconfig

OR

$ make menuconfig apq8084_sec_tblte_eur_defconfig

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:

$ make

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

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

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.

Good luck!

Make it a flashable zip:

You will need to follow Post #7 and break down another boot image, insert your kernel, then re-pack that boot image with all of the proper arguments. This is the main reason I do not recommend building a kernel for Android outside of rom source.