# [Howto]build your own kernel for CM9



## touchmypad (Jan 21, 2012)

Get the kernel from https://github.com/C...rloin/tree/ics:


```
<br />
$git clone [URL=git://github.com/CyanogenMod/hp-kernel-tenderloin]git://github.com/CyanogenMod/hp-kernel-tenderloin[/URL].git<br />
$git checkout ics<br />
$make tenderloin_android_defconfig<br />
$make CROSS_COMPILE=arm-linux-gnueabi- uImage<br />
```
Get the uRamdisk from the original uImage, make sure adb works and your tp is connected to your computer

```
<br />
#adb pull /boot/uImage.CyanogenMod uImage<br />
#mkimage -l uImage<br />
```
The last command will say there are two images in uImage: one is the kernel, the other one is the uRamdisk, which is what we want, so we are gonna extract that. To extract the uRamdisk, we need get its offset in the file. the formula is: 64 (header) + 2 (number of images) * 4 + 4 (a terminating zero) + size of the first image

Mine shows:

Contents:
Image 0: 3749392 Bytes = 3661 kB = 3 MB
Image 1: 221752 Bytes = 216 kb = 0 MB
So the offset is:
64 + 2 *4 + 4 + 3749392 = 3749468

Then run this command:

```
<br />
#dd if=uImage of=uRamdisk bs=1 skip=3749468<br />
#mkimage -l uRamdisk #check if you get it right, it should report it's a RAMDisk Image<br />
```
Now we can pack our own kernel and the uRamdisk

```
<br />
#mkimage -A arm -O linux -T multi -a 0x0 -e 0x0 -C none -a "Test Image" -d arch/arm/boot/uImage:uRamdisk uImage.your_test_kernel<br />
#adb shell mount -o rw,remount /boot<br />
#adb push uImage.your_test_kernel /boot<br />
#!check to make sure verything worked fine<br />
#adb reboot<br />
```


----------



## Phil79 (Oct 17, 2011)

Do you have any idea why I would be getting this error?:

In file included from arch/arm/mm/flush.c:12:0:
include/linux/pagemap.h: In function 'fault_in_pages_readable':
include/linux/pagemap.h:415:16: warning: variable 'c' set but not used [-Wunused-but-set-variable]
CC arch/arm/mm/ioremap.o
CC arch/arm/mm/mmap.o
CC arch/arm/mm/pgd.o
CC arch/arm/mm/mmu.o
CC arch/arm/mm/vmregion.o
CC arch/arm/mm/proc-syms.o
CC arch/arm/mm/alignment.o
arch/arm/mm/alignment.c: In function 'do_alignment':
arch/arm/mm/alignment.c:298:15: warning: 'offset.un' may be used uninitialized in this function [-Wuninitialized]
arch/arm/mm/alignment.c:720:21: note: 'offset.un' was declared here
AS arch/arm/mm/abort-ev7.o
AS arch/arm/mm/pabort-v7.o
AS arch/arm/mm/cache-v7.o
CC arch/arm/mm/copypage-v6.o
CC arch/arm/mm/context.o
AS arch/arm/mm/tlb-v7.o
AS arch/arm/mm/proc-v7.o
LD arch/arm/mm/built-in.o
CC arch/arm/common/gic.o
In file included from /root/android/kernel/hp-kernel-tenderloin/arch/arm/include/asm/mach/irq.h:13:0,
from arch/arm/common/gic.c:34:
include/linux/irq.h: In function 'alloc_desc_masks':
include/linux/irq.h:442:8: warning: variable 'gfp' set but not used [-Wunused-but-set-variable]
CC arch/arm/common/clkdev.o
LD arch/arm/common/built-in.o
CC arch/arm/mach-msm/io.o
CC arch/arm/mach-msm/dma.o
CC arch/arm/mach-msm/memory.o
CC arch/arm/mach-msm/clock.o
CC arch/arm/mach-msm/clock-voter.o
CC arch/arm/mach-msm/modem_notifier.o
CC arch/arm/mach-msm/cpufreq.o
CC arch/arm/mach-msm/nohlt.o
CC arch/arm/mach-msm/clock-debug.o
CC arch/arm/mach-msm/timer.o
In file included from arch/arm/mach-msm/timer.c:19:0:
include/linux/irq.h: In function 'alloc_desc_masks':
include/linux/irq.h:442:8: warning: variable 'gfp' set but not used [-Wunused-but-set-variable]
CC arch/arm/mach-msm/pmu.o
AS arch/arm/mach-msm/headsmp.o
CC arch/arm/mach-msm/platsmp.o
AS arch/arm/mach-msm/idle-v7.o
CC arch/arm/mach-msm/scm.o
/tmp/ccox030v.s: Assembler messages:
/tmp/ccox030v.s:33: Error: selected processor does not support ARM mode `smc #0'
/tmp/ccox030v.s:130: Error: selected processor does not support ARM mode `smc #0'
make[1]: *** [arch/arm/mach-msm/scm.o] Error 1
make: *** [arch/arm/mach-msm] Error 2


----------



## touchmypad (Jan 21, 2012)

Phil79 said:


> Do you have any idea why I would be getting this error?:
> 
> In file included from arch/arm/mm/flush.c:12:0:
> include/linux/pagemap.h: In function 'fault_in_pages_readable':
> ...


I have no idea, but from the error message, I would guess you have changed the config and chosen a different processor, haven't you?


----------



## ab-ster (Nov 24, 2011)

I was getting this too. I got around it by using the toolchain from android-ndk. I added this to my path:

android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin​
and used this for my make:

make CROSS_COMPILE=arm-linux-androideabi- uImage​


----------



## Phil79 (Oct 17, 2011)

ab-ster said:


> I was getting this too. I got around it by using the toolchain from android-ndk. I added this to my path:
> 
> android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin​
> and used this for my make:
> ...


Thanks ab-ster! this worked for me also


----------



## Redflea (Jun 7, 2011)

Got an almost immediate error...trying this on a setup that I've built the tenderloin ROM on...not working so far for the kernel.

Steps:

$git clone git://github.com/CyanogenMod/hp-kernel-tenderloin.git
$git checkout ics
$make tenderloin_android_defconfig

Getting an error at the first command:

~/android/system$ git clone git://github.com/CyanogenMod/hp-kernel-tenderloin.git
Initialized empty Git repository in /home/danabw/android/system/hp-kernel-tenderloin/.git/
remote: Counting objects: 40912, done.
remote: Compressing objects: 100% (33355/33355), done.
error: inflate: data stream error (incorrect data check)iB/s 
fatal: pack has bad object at offset 103390988: inflate returned -3
fatal: index-pack failed


----------



## fattire (Sep 6, 2011)

Oh hey... didn't see this thread until too late, but anyway, earlier this morning by request from eyeballer I wrote up a little kernel howto... it's here FWIW. Might be helpful to have more than one set of instructions to look at. I also added it to the build-from-source walkthrough.


----------



## brandycmc (Oct 8, 2011)

OK - Dumb question time. Go easy on me...









I thought I'd read somewhere that ICS was based on Linux kernel version 3.0.1. So I was expecting that when I ran uname -r that I'd get a response reflecting this. But instead I got "2.6.35-palm-tenderloin", which I think suggests that the CM9 ICS build is based on Linux kernel 2.6.35.

Is there an easy explanation that a noob could understand?

thanks

(The CM9 Android version currently on TouchPad is one that I build from source - including kernel - only two days ago).


----------



## Redflea (Jun 7, 2011)

fattire said:


> Oh hey... didn't see this thread until too late, but anyway, earlier this morning by request from eyeballer I wrote up a little kernel howto... it's here FWIW. Might be helpful to have more than one set of instructions to look at. I also added it to the build-from-source walkthrough.


Heartily recommend everyone also look at fattier's guide, really helpful.

Sent from my Galaxy Nexus using Tapatalk


----------



## McFatty (Aug 23, 2011)

brandycmc said:


> OK - Dumb question time. Go easy on me...
> 
> 
> 
> ...


Yaa, its not built on Linux Kernel 3.* yet. Google seriously has only a couple guys, 2-3, who work on the the kernel development, one day it will be all there probably, just not yet. I'm sure its coming one day thou. More then likely. I'd guess.


----------



## Snow02 (Jun 14, 2011)

McFatty said:


> Yaa, its not built on Linux Kernel 3.* yet. Google seriously has only a couple guys, 2-3, who work on the the kernel development, one day it will be all there probably, just not yet. I'm sure its coming one day thou. More then likely. I'd guess.


Huh? Google isn't working on the touchpad. The nexus kernel is 3.x. The touchpad kernel is not.


----------



## Redflea (Jun 7, 2011)

I wasn't quite clear on how to build the kernel again after the first time, with updated source...fattire provided me the info and thought it would help other noobs like me who require a little more help to get going and keep going/learning on this...

So to build the kernel again:

Second time:

Change to your kernel build directory (mine is kernel):


```
cd ~/android/kernel/hp-kernel-tenderloin
```
Update the kernel source:


```
git pull origin ics
```
Set path to mkimage (command is #PATH=${PATH}:/path/to/mkimage, on our setups it should be below):


```
PATH=${PATH}:/android/system/out/host/linux-x86/bin/mkimage
```
Change directory to the tenderloing kernel:


```
cd ~/gh/CyanogenMod/hp-kernel-tenderloin
```
Build the kernel:


```
make ARCH=arm tenderloin_android_defconfig<br />
<br />
make ARCH=arm -j8 CROSS_COMPILE=~/android/system/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- uImage
```
Copy the kernel to your boot diretory in your repo:


```
cp arch/arm/boot/uImage ~/android/system/device/hp/tenderloin/prebuilt/boot/kernel
```
Now just rebuild your Android project and the new kernel will be added automatically.


----------



## Redflea (Jun 7, 2011)

This morning I'm getting an interesting error...decided to start over and rebuild my kernel build environment.

I'm getting a failure on the first git...tried it a couple of times (see below)..

Has the kernel source been moved or blocked?

[email protected]:~/android/kernel$ git clone [email protected]:CyanogenMod/hp-kernel-tenderloin.git
Initialized empty Git repository in /home/danabw/android/kernel/hp-kernel-tenderloin/.git/
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Tried it again a few more times and this error repeated...

~/android/kernel$ git clone [email protected]:CyanogenMod/hp-kernel-tenderloin.git
Initialized empty Git repository in /home/danabw/android/kernel/hp-kernel-tenderloin/.git/
Permission denied (publickey).
fatal: The remote end hung up unexpectedly


----------



## Redflea (Jun 7, 2011)

DOH...works now...the git command wasn't right. This (from OP) works:

git clone git://github.com/CyanogenMod/hp-kernel-tenderloin.git

But...next command is now failing...can't figure out what's different, why it isn't working like it did before. 

[email protected]:~/android/kernel$ *git checkout ics*
*fatal: Not a git repository (or any of the parent directories): .git*


----------

