[LG Optimus 2x] rugglez:
For any CM10 ROM, except new bootloader one, hackfest, and CM10.1

This tutorial shows you how to build CM10 kernel from RC and the CM team's source(it is their work), and using wkpark's ramhack patch or other patches

If you are uncomfortable in building the kernel, you use my flashable sample kernel at the end of the post, which uses 56 MB RAM hack.

Pre-requistes:

A Linux system

An internet connectionc

Some time and patience ;)

But the time required for downloading resources, and building once everything is set up, is only a fraction of the time required for a full CM10 ROM

You can follow this guide, with or without having built CM10 following Raum1807's excellent CM10 building guide. At one of the places, the difference occurs whether you had built CM10 before or not, and I have listed it at that place :)

For a first time build, you need to follow all the steps, but 2nd time onwards, you can skip to the build step or RAM hack setting step

Instructions:

STEP 1: SETTING UP THE ENVIRONMENT

Install any CM10 ROM on the device (old bootloader, non-hackfest, non-CM10.1 one)

If you already have CM10 environment set up, skip to "Create an environment variable..." part

Install development support packages:

Debian based Linux distributions (like Ubuntu)

64bit systems:

sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
python-markdown libxml2-utils schedtool pngcrush xsltproc zlib1g-dev:i386

then

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

Red Hat based Linux distributions

32bit and 64bit systems:

git gnupg java-1.6.0-openjdk-devel flex bison gperf SDL-devel esound-devel wxGTK-devel zip curl ncurses-devel zlib-devel gcc-c++ glibc-devel

64bit only:

glibc-devel.i686 libstdc++.i686 zlib-devel.i686 ncurses-devel.i686

Setting up Java (thanks to Raum for the java setup guide)

You need a Java Development Kit for building CM10. Recommended is the SUN JDK 6. As of writing the most recent version is SUN JDK 6 Update 37.

1. Download the jdk-6u37-linux-i586.bin from the Oracle/Sun Java Download Area. If you are on 64-bit Ubuntu as I am, you should grab jdk-6u37-linux-x64.bin.

2. Make the bin file executable:

$ chmod +x jdk-6u37-linux-x64.bin

3. Extract the bin file:

$ ./jdk-6u37-linux-x64.bin

4. Move the extracted folder to this this location:

$ sudo mv jdk1.6.0_37 /usr/lib/jvm/./jdk-6u37-linux-x64.bin

5. Install the new Java source in system:

$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-6u37-linux-x64.bin/bin/javac 1
$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-6u37-linux-x64.bin/bin/java 1
$ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk-6u37-linux-x64.bin/bin/javaws 1
$ sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk-6u37-linux-x64.bin/bin/javadoc 1
$ sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk-6u37-linux-x64.bin/bin/javah 1
$ sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk-6u37-linux-x64.bin/bin/javap 1
$ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-6u37-linux-x64.bin/bin/jar 1

6. Select the default Java version for your system:

$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javaws
$ sudo update-alternatives --config javadoc
$ sudo update-alternatives --config javah
$ sudo update-alternatives --config javap
$ sudo update-alternatives --config jar

7. Check Java version:

$ java -version

8. Verify the symlinks. Javac, Java, Javaws, Javadoc, Javah, Javap and Jar should all point to the new Java location and version:

$ ls -la /etc/alternatives/java* && ls -la /etc/alternatives/jar

Now,

If you have CM10 source fetched already (if you have built cm10)

If the directory name where the cm10 source exists is "cm10" (as in Raum's building guide)

Create an environment variable denoting the location of the android toolchain as follows:

export CCOMPILER=${HOME}/cm10/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-

Or else, replace the path/name if yours is different

(If your arm-eabi version is not 4.4.3, check the folder name and change it accordingly)

If you do not have cm10 source on your pc, then you need to download the ARM EABI Toolchain separately

Download link, ready to extract

If above does not work, download from official site here

Download and extract then, create an environment variable denoting the location of the toolchain as follows:

export CCOMPILER=[extraction directory]/bin/arm-eabi-

Download Kernel Source Code:

mkdir -p ~/kernel
cd ~/kernel

Now download RC's CM10 kernel source

In terminal, do

Old bootloader:

git clone git://github.com/CyanogenMod/lge-kernel-star.git -b jellybean

New bootloader:

Here, pengus77 has made the necessary changes in his repo, so we fetch from that

git clone git://github.com/pengus77/lge-kernel-star.git

Thus, there should be a folder named "lge-kernel-star" inside /kernel folder

Then in terminal, cd to that directory "lge-kernel-star"

cd lge-kernel-star

Getting the config file

The next step is to copy the file "/kernel/lge-kernel-star/arch/arm/configs/cyanogenmod_p990_defconfig" to "/kernel/lge-kernel-star and rename it to ".config"

using the command:

cp arch/arm/configs/cyanogenmod_p990_defconfig .config

(Thanks to tonyp for the tip!)

STEP 2: CONFIGURATION

Configure the build:

make ARCH=arm CROSS_COMPILE=$CCOMPILER oldconfig

If it happens to ask anything, just accept the defaults at every step by pressing enter.

STEP 3: APPLYING PATCHES

Applying patches like wkpark's RAM hack patch

If you skip this step, the kernel will work, but you'll have a completely stock kernel without RAM hack or other tweaks

Download wkpark's two patches from here and here, and put them in your /kernel directory

cd ~/kernel

Now to apply the patches, we use the patch command like this:

patch -Np1 -d lge-kernel-star < patchname.patch

(replace patchname with name of the patch file)

Here, -N is for ignoring patches that seem to be already applied or reversed

p<num> Strip the smallest prefix containing num(here num=1) leading slashes from each file name found in the patch file

In this case, num=1 according to the path names in wkpark's patch, and in a lot of cases, the value of 1 is common

-d is to change to the directory immediately, before doing anything else

You need to apply wkpark's two patches one by one (0001-..., then bootloader-...)

If you get errors while patching, if they are basic errors like file not found etc. then you should manage to fix it yourself.

But if you get errors like "HUNK ... failed",

try

patch -Np1 --ignore-whitespace -d lge-kernel-star < patchname.patch

A "HUNK ignored" is ok, if patch was attempted previously, since that file might have been successfully patched last time

if a HUNK still fails, then read the troubleshooting guide

Setting RAM hack size (If you skipped the above patching step, dont do this)

wkpark's patch makes it possible for you to set ramhack size in kernel command line parameter.

The cmdline parameter has to have the full boot.img command line parameters, which you can obtain from dmesg. I have done it for you, so you can save time on that ;)

Here's how it looks for the old bootloader: (for the new one, ignore this)

<5>[70:01:01 00:00:00.000] Kernel command line: loglevel=0 muic_state=1 CRC=10203036179a93 brdrev=1.0 uniqueid=37c7006421f6097 video=tegrafb console=ttyS0,115200n8 usbcore.old_scheme_first=1 tegraboot=sdmmc tegrapart=recovery:35e00:2800:800,linux:34700:1000:800,mbr:400:200:800,system:600:2bc00:800,cache:2c200:8000:800,misc:34200:400:800,userdata:38700:c0000:800 mem=512M@0M vmalloc=128M androidboot.mode=normal androidboot.hardware=star androidboot.serialno=37c7006421f6097

Paste the line starting from loglevel=0 till the end (serialno) into .config file in lge-kernel-star folder in

CONFIG_CMDLINE="<here>"

Insert a carveout size in between vmalloc and androidboot.mode

Determing carveout size: carveout=<152 - RAM hack size>M

For example, if RAM hack size is 56, then carveout is 96M

So in that case, the cmdline is like this:

old bootloader:

CONFIG_CMDLINE="loglevel=0 muic_state=1 CRC=10203036179a93 brdrev=1.0 uniqueid=37c7006421f6097 video=tegrafb console=ttyS0,115200n8 usbcore.old_scheme_first=1 tegraboot=sdmmc tegrapart=recovery:35e00:2800:800,linux:34700:1000:800,mbr:400:200:800,system:600:2bc00:800,cache:2c200:8000:800,misc:34200:400:800,userdata:38700:c0000:800 mem=512M@0M vmalloc=128M carveout=96M androidboot.mode=normal androidboot.hardware=star androidboot.serialno=37c7006421f6097"

new bootloader:

CONFIG_CMDLINE="tegraid=20.1.4.0.0 mem=512M@0M carveout=152M android.commchip=0 vmalloc=128M androidboot.serialno=037c7006421f6097 video=tegrafb no_console_suspend=1 console=ttyS0,115200n8 debug_uartport=lsport,-3 androidboot.mode=normal usbcore.old_scheme_first=1 lp0_vec=8192@0x1dd09000 tegra_fbmem=3073920@0x1dd0d000 muic_state=0 tegraboot=sdmmc tegrapart=recovery:35e00:2800:800,boot:34700:1000:800,mbr:400:200:800,persist:600:2bc00:800,cache:2c200:7f00:800,misc:34200:400:800,userdata:38700:c0000:800,bcttable:0:600:800,bootloader:100:300:800,data/ve:f8800:1400:800,system:34c000:40000:800 "

and save the file

Dont set carveout too low, or else some gpu-intensive stuff may not work properly.

STEP 4: BUILDING THE KERNEL

In terminal,

cd ~/kernel/lge-kernel-star

make ARCH=arm CROSS_COMPILE=$CCOMPILER -j`grep 'processor' /proc/cpuinfo | wc -l`

This step may take a while, depending on your computer. Took ~5-10 mins for the first build for me, and ~1 min for the second build onwards.

If it asks in the terminal "use default config?" then say "y", if not, then ignore this

If you get some error and the building aborts within a few seconds, try the "Create environment variable part" again, and then return back directly to the build step.

After it is done, you should have a kernel stored in ~/kernel/lge-kernel-star/arch/arm/boot/zImage

Preparing the flashable zip for the kernel

Some compiled modules need to be included so that problems like wifi not switching on dont occur.

They are:

drivers/misc/bthid/bthid.ko

drivers/scsi/scsi_wait_scan.ko

drivers/net/wireless/bcm4329/wireless.ko

They will be used while preparing the flashable zip below.

Thanks to feav's compiled modules and benee's anykernel updater for star, all this is ready-made and you can simply:

Download the sample kernel zip attached below and replace /kernel/zImage and and the above modules in system/lib/modules/hw in that with yours, edit updater-script if you want.

Your flashable zip is now ready :D

STEP 5: FLASHING AND TESTING THE KERNEL

Put the sample kernel below as a backup in case your kernel does not boot and you need a working phone immediately.

Flash the kernel in recovery, wipe cache, dalvik cache and reboot.

If the phone goes past the LG logo screen(s) and into the bootscreen of the ROM, then it should work :D

Then you can check "kernel version" in settings->about phone to see your kernel information,

and you can see the new RAM size (which should be 342 MB + RAM hack size) in some app like battery dr saver, or antutu benchmark's system info.

If it doesnt work, make sure you have followed the entire guide properly and then ask queries ;)

If you want to revert to another kernel, flash that kernel in recovery, or for stock kernel, flash your ROM.

Keeping kernel source up to date (for building again later after RC has made changes to the source):

cd ~/kernel/lge-kernel-star
git pull

This will update your source with the latest commits by RC. Then you can rebuild the kernel by doing the "create environment variable" and then skip directly to the build stage ;)

Standard disclaimer:

I am not responsible if anything goes wrong with your phone or anything else.

Credits:

aremcee/RC and the rest of the CM team for all their work. This is their kernel you are building

wkpark for his valuable contributions, including the ramhack patches and cracking the new bootloader

benee for his Anykernel updater for star, and other tweaks

feav for his compiled wifi modules

pengus77 for the work to make it suitable for the new bootloader

Download links for sample kernels:

SAMPLE 56 MB RAMHACK KERNEL

SAMPLE 32 MB RAMHACK KERNEL

SAMPLE 24 MB RAMHACK KERNEL