|\ __________                          __   __                         __
         | |   __     |          _____ __    __\__/_|  |_ __ ___   _____   ___ |  |\_____     
         | |  /  \    |         /  _  \  \  /  /  |_    _|  /   \ /  _  \ /  _ \  |/  _  \    
         | |  \  /___ |        /  /_\  \  \/  /|  | |  |\|   /\  \  / \  \  / \   |  /_\  \   
         | |__/    _ \|        |  _____||    |\|  | |  | |  |\|  |  |\|  |  |\|   |  _____|\  
         | |___/\  \\_\        \  \____/  /\  \|  | |  | |  | |  |  \_/  /  \_/   |  \___ \|  
         | |    /   \_|         \_____/__/ /\__\__| |__| |__| |__|\_____/ \____/__|\_____/\   
         | |   / / \___|         \____\__\/  \__\__\|\__\|\__\|\__\\____\/ \___\\__\\____\/   
         | |__/_/_____|     
         |/                

Last changed: 27.09.2017

Howto build your own cyanogenmod kernel


I will update this page soon with the new commands needed to build LineageOs, the successor of CyanogenMod. Up to then I recommend this guide.

For those who only want to flash their devices with a prebuild image the following sites should be interesting

As you can read in the article about the Pwn Pad on the Nexus 7 the prebuild kernels you can find in the internet sometimes lack drivers for specific hardware which you might want to connect to the tablet via an USB OTG cable. This is the best reason to look into compiling the kernel yourself!

The procedure shown here covers only compiling for CyanogenMod 12.1 on the Nexus 7 2012 wifi (grouper). If you are willing to compile for another device you will have to modify some commands.

getting the source code


I won't list all packages here which you will need to compile. Check the links below to see if you are missing something. To get the CyanogenMod sources you can use the tool repo.

mkdir bin
mkdir cm-12.1
cd bin
curl https://storage.googleapis.com/git-repo-downloads/repo > repo
chmod a+x repo
export PATH=$(pwd):$PATH
cd ../cm-12.1
repo init -u git://github.com/CyanogenMod/android.git -b cm-12.1
repo sync

modifying the kernel config


Download the prebuild toolchain, setup the environment variables and load the default config for the Nexus 7.

cd cm-12.1
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
export PATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-eabi-
export LANG=C
source build/envsetup.sh
lunch cm_grouper-userdebug
cd kernel/asus/grouper
make tegra3_android_defconfig

I made the following changes to the kernel config:

make menuconfig

--- Networking support
--- Wireless
<*>   Generic IEEE 802.11 Networking Stack (mac80211)

    Device Drivers  --->
[*] Network device support  --->
--- Wireless LAN
<M>   Realtek 8187 and 8187B USB support
<*>   Ralink driver support  --->
--- Ralink driver support
<M>   Ralink rt2500 (USB) support
<M>   Ralink rt2501/rt73 (USB) support
<*>   Ralink rt27xx/rt28xx/rt30xx (USB) support
[*]     rt2800usb - Include support for rt33xx devices (NEW)
[*]     rt2800usb - Include support for rt35xx devices (EXPERIMENTAL) (NEW)
[*]     rt2800usb - Include support for rt53xx devices (EXPERIMENTAL)

saving the config and compiling the kernel


In order to compile the kernel you have to copy the config and clean the kernel folder.

cp .config arch/arm/configs/cyanogenmod_grouper_defconfig
make mrproper
cd ../../..
make -j4 bootimage

flash the boot image


The built kernel can be found in the folder out/target/target/product/grouper. To test the kernel it can be copied to the device without overwriting the boot partition.

cd out/target/product/grouper
sudo fastboot boot boot.img

If the devices boots without problems you can flash the boot partition.

sudo fastboot flash boot boot.img

compile drivers as kernel modules


Alternatively you can compile the drivers as loadable modules and activate lkm support in the kernel. In this case you will have to copy them from the folder out/target/product/grouper/system/lib/modules to the folder /system/lib/modules on the device. As system is mounted readonly you will have to remount it (needs root privileges).

root@grouper:/ # mount -o rw,remount /dev/block/platform/sdhci-tegra.3/by-name/APP system

solving the rt2x00lib_request_firmware error


The Ralink USB WLAN device I use tries to load the firmware files when it gets started. You will have to copy the firmware into the firmware folder on the Nexus 7 (e.g. /system/vendor/firmware). I accomplished this by loading the firmware with Linux Deploy in my Kali Linux chroot.

apt-get install firmware-ralink

Afterwards I copied the files with scp. Don\'t forget to remount system as described above.

scp user@localhost:/lib/firmware/rt*.bin /system/vendor/firmware

As there was an update of the firmware file included in the linux kernel you can find the old firmware on kernel.org or here.

sources


  1. http://wiki.cyanogenmod.org/w/Build_for_grouper#Build_CyanogenMod_and_ClockworkMod_Recovery
  2. http://wiki.cyanogenmod.org/w/Doc:_integrated_kernel_building
  3. http://source.android.com/source/building-kernels.html