Building An Android Kernel

As I’ve been compiling Cyanogenmod for the ZTE Blade, I thought I’d have a look at compiling the kernel instead of applying binary patches. I found this tutorial which kind of helped, here’s my simplified summary:

1. Pull kernel source from Github (currently weighs in at 1.7Gb):

git clone git://

2. Get the .config file – most tutorials say to get this from your phone which is running the kernel that you want to compile, but actually its already stored in git:

cp ~/kernel_zte_blade/arch/arm/configs/cyanogen_blade_defconfig ~/kernel_zte_blade/.config

3. Build the kernel:

make ARCH=arm CROSS_COMPILE=~/cyanogenmod/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-

4. Build CM7 as usual, and to make things easier we’re going to copy a few files all into the same directory, including the we downloaded:

mkdir ~/custom_kernel
cd ~/custom_kernel/
cp ~/ .
cp ~/kernel_zte_blade/arch/arm/boot/zImage .
cp ~/cyanogenmod/out/host/linux-x86/bin/mkbootimg .
cp ~/cyanogenmod/out/target/product/blade/ .
cp ~/cyanogenmod/out/host/linux-x86/framework/signapk.jar .
cp ~/cyanogenmod/build/target/product/security/testkey.* .

6. Unzipping the KANG has given us the META-INF and system directories and boot.img file, which we must now unpack:

./ boot.img

6a. Optionally copy across the .ko files mentioned in modules.order to system/lib/modules/ the highlighted ones are probably not neccessary:

grep -v test modules.order | sed 's|^kernel/||g'


7. Recreate the boot.img with the new kernel:

./mkbootimg --cmdline 'androidboot.hardware=blade console=ttyMSM2,115200 g_android.product_id=0x1354 g_android.serial_number=Blade-CM7' --base 0x2600000 --kernel zImage --ramdisk boot.img-ramdisk.gz -o boot.img

6. Zip up the new boot.img and old META-INF and system directories:

zip -r META-INF boot.img system

7. Sign the zip:

java -jar signapk.jar testkey.x509.pem testkey.pk8

8. Generate an md5sum of the signed zip so users can check it downloaded properly:

md5sum >

And here’s the screenshot of the running ROM with my kernel:

Click for fullsize
Click for fullsize

2 thoughts on “Building An Android Kernel”

  1. Hi,

    A good tutorial you got there, thanks! I was just wondering if the compiled zImage is the “kernel” file in device/zte/blade? If that file is the kernel file that goes into boot.img, wouldn’t it be easier to replace device/zte/blade/kernel with the fresh zImage, git add/commit it and have it built in the following times you compile CM? This would save you from the whole unpack/repack/resign process.

  2. Yes I think you should be able to just replace the kernel file in git – assuming the modules are not needed – there should be no reason to do the repacking.

    You don’t need to commit it to git (its readonly anyway).

Comments are closed.