[Xiaomi Redmi 2 ROMs, Kernels, Recoveries, & Other ] Ashish94:
[guide]compile zetsubou from source

I have been getting this a lot lately in my PM. So here it is complete step by step guide to compile ZETSUBOU from source.

This guide is only for Ubuntu 16.04, so if you are using any other Linux distro don't expect any support from me as I haven't used them.

/*Setting up build environment*/​

Assuming you did a fresh Ubuntu install first we need to install certain tools in our build machine to get things started. The best way to do this is use a readymade script by akhilnarang.

1) Open a terminal(ctrl+alt+t) and type the following:

sudo apt-get update

The "sudo" command will prompt you for Ubuntu password and then type:

sudo apt-get install

2) Next we will install git. This is essential if you want to share your code with the rest of community and it makes development a whole lot easier. Type the following in your terminal:

sudo apt-get install git-core

3) Next we will make a new folder where we will keep all our development related stuff like toolchains, kernel source etc. Type:

mkdir kernel

This will make a folder named "kernel" in your /home directory. Next we will go inside this kernel folder with:

cd kernel

4) Time to install all necessary build tools. Type:

git clone git://github.com/akhilnarang/scripts

What we did here is tell git to clone a certain repository from GitHub. In this case we are cloning akhilnarang's setup scripts which you can find here https://github.com/akhilnarang/scripts. By doing this you will see a new folder named "scripts" inside kernel folder. We will go inside scripts with

cd scripts

With "ls" command we can see all the files that exists​ inside script folder.

Next we will run the bash script for Ubuntu 16 with:

bash ubuntu1604linuxmint18.sh

Or you may also type

./ubuntu1604linuxmint18.sh

Both are same

/*Cloning sources*/​

Now that we are done with build environment setup time to get our sources

1) Clone ZETSUBOU kernel source. Right now we are inside "scripts" folder. To go back to "kernel" folder type

cd ..

Since we are keeping all our sources inside kernel folder.

Now it's time to clone kernel source. Type the following:

git clone https://github.com/AshishM94/android_kernel_wingtech_msm8916.git -b nougat

Wait wtf happened in there?

- First you need to know how to get clone url. To do this open GitHub repository in your browser in this case zetsubou's kernel source https://github.com/AshishM94/android_kernel_wingtech_msm8916. In your browser you will see a green tab "clone or download" at top right. Click on it and it will show you the clone url.

- Next is about "-b nougat". Here we are telling git to clone and checkout the nougat branch.

Sit back and put on your headphone till the source gets downloaded. It's close to 780MB.

2) Getting a toolchain. Here we will use ubertc 6.3.1 to compile our kernel. Here's the repo link https://bitbucket.org/matthewdalex/arm-eabi-6.x . The clone url is at top right corner. Type in your terminal:

git clone https://bitbucket.org/matthewdalex/arm-eabi-6.x.git

And with this we have everything we need to compile our kernel.

/*Compiling the kernel*/​

1) Let's get inside our kernel source with

cd android_kernel_wingtech_msm8916

Here you will see a file named build.sh . This is my build script which I use to compile my kernel. So you need to edit this file with your toolchain location and certain other things.

Check for this line:

export CROSS_COMPILE="$HOME/kernel/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-"

Change the path to yours

export CROSS_COMPILE="$HOME/kernel/arm-eabi-6.x/bin/arm-eabi-"

2) We are all set and done. Let's compile the kernel. Just type this in your terminal

./build.sh

Follow the onscreen instructions to compile kernel(zImage), dtb, changelog, flashable zip and you are done. If everything goes well you will get the following message:

Build completed successfully at "time"

Flashable zip package will be inside AnyKernel2 folder.

Use the one with *-signed written on it.

/*FAQs*/​

• How to add governors, schedulers and overclock?

- Well there is no universal guide for this. So you need to go through multiple repos to learn about them. For reference I can tell you governor files are under /drivers/cpufreq and scheduler files are under /block directory. You will find all these in your kernel source.

• Can I compile stock lineage kernel with this guide?

- Yes you can. Just copy the build script from my source and edit the defconfig: zetsubou_defconfig to wt88047_defconfig.

Also stock lineage uses gcc4.8 which you will get from here https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/

And you will also need /tools/dtbtoolcm from my source.

• How to sync my local source with your upstream changes?

- just type this in your terminal

git pull origin

• I have successfully compiled and flashed the kernel but now my camera won't work on non-los roms. What went wrong?

- Just checkout my nonlos branch for those roms before starting compiling by

git checkout nougat-nonlos

Enjoy :D