[Zenfone 2 Laser Android Development] pokipokipxorn:
for reference, I won't be doing this forever, if any of u want to do the same in future, here is the workflow (wip) to compile a custom kernel for any rom. Setup a kernel development environment on linux, google on how to do this properly for your linux distro.

Example: [ROM] [UNOFFICIAL] XOSP N 7.1.1 for Z00L

#01 extract running kernel config

first download the extract config tool named extract-ikconfig, which is a script from Linus Torvalds to pull kernel config from any linux kernel

mkdir -p ~/kerneldev/config ;
cd ~/kerneldev/config ;
wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-ikconfig ;
chmod +x extract-ikconfig ;

copy boot.img from the ROM zip file to folder ~/kerneldev/config, then extract kernel config

./extract-ikconfig boot.img > xosp711_Z00L_defconfig

(boot.img is the kernel of the rom

> xosp711_Z00L_defconfig will output kernel config to file xosp711_Z00L_defconfig)

#02 identify running kernel version, source & commit

Settings > About Phone

Locate Kernel version

3.10.49-cyanogenmod-gb95f221

(kernel version is 3.10.49

source is from cyanogenmod

with latest commit gb95f221)

#03 locate & clone kernel source from github

note the branch & latest commit, kernel source

cd ~ ;
mkdir -p ~/kerneldev/source/xosp_nougat ;
cd ~/kerneldev/source/xosp_nougat ;
git init ;
git clone "https://github.com/CyanogenMod/android_kernel_asus_msm8916/tree/cm-14.1"

(source is around 1.6Gb, I'm on 4Mbps/512kbps line, took me 1.5 hours to download

it's best to setup a proper github account, google for tutorial

if rom dev did not publish kernel source, just search github for it, important to verify version, branch & commit info

kernel sources for nougat roms:

xosp https://github.com/CyanogenMod/android_kernel_asus_msm8916/tree/cm-14.1

aicp https://github.com/LineageOS/android_kernel_asus_msm8916

aokp https://github.com/LineageOS/android_kernel_asus_msm8916 )

#04 locate & clone toolchain

I use UBER-4.9-kernel toolchain for max. compatibility

mkdir -p ~/kerneldev/toolchain ;
cd ~/kerneldev/toolchain ;
git init ;
git clone "https://bitbucket.org/UBERTC/aarch64-linux-android-4.9-kernel.git" ;

(toolchain is a collection of libs, utils specific to the platform we are compiling for, which is arm64)

#05 setup environment for kernel compile

export PATH=~/kerneldev/toolchain/aarch64-linux-android-4.9-kernel/bin:$PATH ;
export CROSS_COMPILE=~/kerneldev/toolchain/aarch64-linux-android-4.9-kernel/bin/aarch64-linux-android- ;

(do this each time you open a terminal for kernel compile, it specifies the tools & path needed for successful compilation)

#06 compile ROM stock kernel for testing purposes, this verifies your kernel dev environment is error-free

mkdir -p ~/kerneldev/source/xosp_nougat/output ;
cd ~/kerneldev/source/xosp_nougat/android_kernel_asus_msm8916 ;

(folder output is the location of kernel after successful compilation

to be exact, the kernel file will be located at output/arch/arm64/boot/ folder)

make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output clean ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output mrproper ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output distclean ;

(flush the output folder, start with clean slate)

cp ~/kerneldev/config/xosp711_Z00L_defconfig ~/kerneldev/source/xosp_nougat/android_kernel_asus_msm8916/arch/arm64/configs/ ;

(copy the ROM stock kernel config to kernel source)

make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output xosp711_Z00L_defconfig ;

(ARCH=arm64 specifies the architecture we are cross-compiling for, note your pc is installed with linux x86/x86_64

O=~/kerneldev/source/xosp_nougat/output defines the output folder

xosp711_Z00L_defconfig, which is the ROM stock kernel config to be used for compile)

make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output savedefconfig ;

(make a copy of current kernel config, which is xosp711_Z00L_defconfig, to be used as default from now on)

make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image ;

(start compile of kernel

-j4 specifies the number of cpu cores to be used for compilation, if your cpu is dual-core, use -j4

if your cpu is quad-core, use -j8

more cores means faster compilation times

file Image is the kernel itself, required)

make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image.gz ;

(file Image.gz is a gzipped version of the kernel, required)

make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 dtbs ;

(files dtbs are qualcomm's device tree binaries, required)

make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image.gz-dtb ;

(file Image.gz-dtb is the kernel with qualcomm dtb files appended, which we will use for packing

it is located ~/kerneldev/source/xosp_nougat/output/arch/arm64/boot/)

#07 locate & clone boot image tools

mkdir -p ~/kerneldev/bootimg ;
cd ~/kerneldev/bootimg ;
git init ;
git clone https://github.com/xiaolu/mkbootimg_tools.git ;

#08 unpack original rom boot image, to extract ramdisk.packed & settings from file img_info

mkdir -p ~/kerneldev/bootimg/new ;
mkdir -p ~/kerneldev/bootimg/source ;
mkdir -p ~/kerneldev/bootimg/unpacked ;

copy boot.img from rom zip file into folder ~/kerneldev/bootimg/source then

mv boot.img xosp711_stock.img ;

(rename boot.img to xosp711_stock.img)

unpack xosp711_stock.img

~/kerneldev/bootimg/mkbootimg_tools/mkboot ~/kerneldev/bootimg/source/xosp711_stock.img ~/kerneldev/bootimg/unpacked/xosp711

(mkboot is the utility used for unpacking boot images

xosp711_stock.img is the boot image

~/kerneldev/bootimg/unpacked/xosp711 is the output folder)

open file ~/kerneldev/bootimg/unpacked/xosp711/img_info using any text editor, note the values

#09 repack boot image

cd ~/kerneldev/bootimg/unpacked/xosp711 ;
~/kerneldev/bootimg/mkbootimg_tools/mkbootimg --base 0x80000000 --pagesize 2048 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 --second_offset 0x00f00000 --tags_offset 0x00000100 --cmdline 'console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 buildvariant=userdebug' --kernel ~/kerneldev/source/xosp_nougat/output/arch/arm64/boot/Image.gz-dtb --ramdisk ramdisk.packed -o ~/kerneldev/bootimg/new/xosp711_MYstock.img ;

(mkbootimg is the utility to pack boot image

--base corresponds to base_addr in file img_info, value is 0x80000000

--pagesize corresponds to page_size in file img_info, value is 2048

--kernel_offset corresponds to kernel_offset in file img_info, value is 0x00008000

--ramdisk_offset corresponds to ramdisk_offset in file img_info, value is 0x01000000

--second_offset leave the value unchanged, which is 0x00f00000

--tags_offset corresponds to tags_offset in file img_info, value is 0x00000100

--cmdline is a bit tricky, the values is DIFFERENT for each rom/kernel, copy exactly from file img_info

--cmdline corresponds to cmd_line in file img_info, value is 'console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 buildvariant=userdebug'

--kernel points to full path of Image.gz-dtb, which is the final kernel file compiled in #06

--ramdisk points to stock ramdisk.packed

-o ~/kerneldev/bootimg/new/xosp711_MYstock.img points to output folder, with new boot image filename xosp711_MYstock.img)

#10 test your kernel

Note that, at this point, you have successfully re-compiled a kernel based on stock config from the ROM. Your boot image is exactly the same as the one being supplied in the ROM itself. Steps #01-#10 is necessary to prove your kernel development tools/environment is error-free. This reduces complications during custom kernel compile.

Connect phone to PC using USB cable, put phone into fastboot mode

fastboot boot ~/kerneldev/bootimg/new/xosp711_MYstock.img

(this will boot the phone using your kernel, one time only

nothing is being flashed onto the phone

If your phone boots into Home Screen, that means your kernel is complete and boots successfully)

if you want to FLASH (not test) a boot image:

Connect phone to PC using USB cable, put phone into fastboot mode

fastboot flash boot ~/path/to/boot.img

After phone boots successfully into Home Launcher screen, launch SuperSU to update its binary, select TWRP method, it will restart phone into TWRP and update itself automatically, followed by a restart again.

Once reach Home Launcher screen, launch SuperSU to verify everything is fine.

Install Kernel Adiutor Mod from XDA to test/use new kernel features. Just by compiling a feature into a custom kernel means nothing, if the feature does not work.

#11 custom kernel by editing kernel config file

open file ~/kerneldev/source/xosp_nougat/android_kernel_asus_msm8916/arch/arm64/configs/xosp711_Z00L_defconfig using any text editor

save file as xosp711v01_Z00L_defconfig

find the following strings, change value from =y to =n

CONFIG_CPU_BOOST
CONFIG_MSM_CORE_CTL_HELPER
CONFIG_MSM_CORE_CTL
CONFIG_MSM_PERFORMANCE
CONFIG_MSM_PERFORMANCE_HOTPLUG_ON

find the following string, change value from ="cubic" to ="westwood"

CONFIG_DEFAULT_TCP_CONG

scroll down to end of file, copy and paste the following

CONFIG_CLUSTER_PLUG=n
CONFIG_SCHED_SMT=n
CONFIG_IKCONFIG_PROC=y
CONFIG_NTFS_FS=y
CONFIG_NTFS_RW=y
CONFIG_NTFS_DEBUG=n
CONFIG_TCP_CONG_ADVANCED=y
CONFIG_TCP_CONG_WESTWOOD=y
CONFIG_KSM=y
CONFIG_CLEANCACHE=y
CONFIG_FRONTSWAP=y
CONFIG_ZSWAP=n
CONFIG_ZCACHE=n
CONFIG_TCP_CONG_BIC=y
CONFIG_TCP_CONG_HTCP=y
CONFIG_TCP_CONG_HSTCP=y
CONFIG_TCP_CONG_HYBLA=y
CONFIG_TCP_CONG_VEGAS=y
CONFIG_TCP_CONG_SCALABLE=y
CONFIG_TCP_CONG_LP=y
CONFIG_TCP_CONG_VENO=y
CONFIG_TCP_CONG_YEAH=y
CONFIG_TCP_CONG_ILLINOIS=y
CONFIG_DEFAULT_WESTWOOD=y

save and close file

( kernel features added:

- tcp-algorithm: westwood

- kernel config.gz at /proc

- filesystem: ntfs

- kernel: samepage merging, frontswap, cleancache)

( kernel features removed:

- cpu: cpu boost

- cpu hotplug: msm performance, including touch boost)

recompile kernel with custom config as above, we will label it as v01

cd ~/kerneldev/source/xosp_nougat/android_kernel_asus_msm8916 ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output xosp711v01_Z00L_defconfig ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output savedefconfig ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image.gz ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 dtbs ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image.gz-dtb ;

repeat steps #09 & #10, but use a different file name for kernel image, example xosp711_custom-v01.img

cd ~/kerneldev/source/xosp_nougat/android_kernel_asus_msm8916 ;
git status ;

(see 2 files listed in red color

these 2 files were the only changes in the kernel source so far)

git add arch/arm64/configs/xosp711_Z00L_defconfig ;
git add arch/arm64/configs/xosp711v01_Z00L_defconfig ;

(add the 2 files so git can track and commit to kernel source)

git commit ;

(will be presented with a vi screen

locate the 2 lines listing the 2 files

uncomment/delete the # at beginning of the 2 lines

save and quit

if you don't know how to use vi, google for tutorial)

git status ;

(nothing to commit, v01 changes added successfully to kernel source, tracked by git)

#12 cherry-pick worthy commits, one at a time

there are many custom kernels all over xda & other forums, with a lot of desired kernel features (example)

how do we choose which feature to implement?

some tips:

- always choose features from the same device family/model if possible

- best to choose only 1 feature to implement at a time, troubleshooting is easier

- kernel source date is not important, it could be 1 week ago or 2 years ago

- always choose the oldest commit date for that feature, example a file could be edited 10 times, but always choose the 1st change/commit

- the feature chosen may or may not work on our device, need to test & verify function, revert feature if necessary

explained here

For our usage, we will use the excellent Nemesis Fusion kernel by abhishekr700

go to Nemesis Fusion kernel thread

look through the features, choose one to implement in our custom kernel

example

[b]23.) Set SELINUX to permissive permanently from the kernel.[/b]

go to Nemesis Fusion kernel source page at github

top-left, "This repository" | Search

input: selinux

press ENTER

left-center, Commits "1", click

center, "Set SELINUX to permissive permanently", click

(there is only 1 commit for SELinux

note the commit hash 210b6576b592eaa30c10b688d9b770f3b2a09229 at upper-right

now examine the commit page

"Showing 1 changed file with 1 addition and 0 deletions."

note file security/selinux/selinuxfs.c

line 170 +

means the commit added lines 170-173 into file security/selinux/selinuxfs.c

note for some other commits, there could 2 or more file changes

+ is added lines or text

- is removed lines or text)

cd ~/kerneldev/source/xosp_nougat/android_kernel_asus_msm8916 ;
git fetch https://github.com/abhishekr700/Nemesis_Kernel.git ;

(fetch could take some time

fetch links our kernel source to Nemesis Fusion kernel source)

git cherry-pick 210b6576b592eaa30c10b688d9b770f3b2a09229 ;

(this will select commit hash 210b6576b592eaa30c10b688d9b770f3b2a09229

from Nemesis Fusion Kernel source to merge with our kernel source)

git status ;
git commit ;

kernel change log

version 02

kernel features added:

security: SELinux set to permissive

commit hash 210b6576b592eaa30c10b688d9b770f3b2a09229

recompile kernel with custom config as above, we will label it as v02

cd ~/kerneldev/source/xosp_nougat/android_kernel_asus_msm8916 ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output xosp711v01_Z00L_defconfig ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output savedefconfig ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image.gz ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 dtbs ;
make ARCH=arm64 O=~/kerneldev/source/xosp_nougat/output -j4 Image.gz-dtb ;

repeat steps #09 & #10, but use a different file name for kernel image, example xosp711_custom-v02.img

#13 Other commits == WIP ==

version 03

Disable CRC Check for 30% Performance Boost

38ce9f82183c3ded60115a061b6d1531d05a4051

version 04

Adding USB Fast Charge, credits to [MENTION=853975]ENG[/MENTION]stk

d90d3fe1a9efc6d870131467ccdf5b6b4dbb9400

.config append, CONFIG_FORCE_FAST_CHARGE=y

answer N to all other config options

version 05

added autosmp hotplug

autosmp.c file to be copied from

https://github.com/Tomoms/helium_kernel/commit/640b9d36ce0322d9817fe45f4a7424c130e66493

.config
CONFIG_ASMP=y
CONFIG_MSM_PERFORMANCE=n
CONFIG_MSM_PERFORMANCE_HOTPLUG_ON=n

Kconfig
config ASMP
bool "Multi-core automatic hotplug support"
depends on SMP
default y
help
Automatically hotplugs the multiple cpu cores on and off
based on cpu load and suspend state

Makefile
obj-$(CONFIG_ASMP)	+= autosmp.o

# compile new kernel (custom)

# repack new kernel (custom) into boot image

# test new boot image

# flash new boot image