Below are the steps taken by me to build a working Android kernel image for the ADP1 (a.k.a. the developer G1). This image is based on linux kernel 2.6.27 and relies on the Android 1.5 "cupcake" radio image from HTC. If you are trying to build a kernel for a different version replace references to cupcake as appropriate below. As before this page is here as a reminder to me for when I come to do it again. This is what worked for me, your mileage may vary.
Before building the build environment needs to be set up:
- Install the Android SDK, as described previously
- Install repo and get the Android toolchain as per http://source.android.com/download .
- make sdk threw up an error about javac so I needed to sudo apt-get install sun-java6-jdk . I also needed to install g++ , bison , flex and zlib1g-dev . I also had to follow this resolution as I got "No such file or directory" errors about X11/Xlib.h and X11/Xatom.h.
- Create a small ~/bin/g1make script for building to save me typing the same build parameters over and over again. I'm sure there are more elegant ways to do this but it works for me.
#!/bin/bash
make ARCH=arm CROSS_COMPILE=arm-eabi- $1
- Edit ~/.bashrc to add the cross-compilation toolchain to $PATH. Since I don't do much native compilation I also aliased make to g1make because I was frequently typing make out of habit and screwing up my build.
# Add in path to Android toolchain for compilation
export PATH=$PATH:/home/cianer/wandroid/src/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin
# Save my sanity when cross-compiling
alias make=g1make
alias realmake='/usr/bin/make'
Now get the source code:
- Checkout the source code from the git repository (see git guide if you are unfamiliar with it)
git clone git://android.git.kernel.org/kernel/msm.git
- Switch to the 2.6.27 branch
cianer@Feegle:~/msm$ git branch -r
origin/HEAD
origin/android-msm-2.6.25
origin/android-msm-2.6.27
origin/android-msm-htc-2.6.25
origin/msm-2.6.25
cianer@Feegle:~/msm$ git checkout --track -b android-msm-2.6.27 origin/android-msm-htc-2.6.27
Branch android-msm-2.6.27 set up to track remote branch refs/remotes/origin/android-msm-htc-2.6.27.
Switched to a new branch "android-msm-2.6.27"
cianer@Feegle:~/msm$ git branch
* android-msm-2.6.27
cianer@Feegle:~/msm$
- Set up the initial .config file. This can be done one of two ways. The simple way is to call make msm_defconfig to autogenerate the default config file. The (slightly) more complicated way is to pull the existing file from the phone. Both methods result in identical files as far as I can see. Note: To use the latter method the phone must be running cupcake (i.e. the same software you are trying to build).
cianer@Feegle:~/wandroid/msm$ adb pull /proc/config.gz .
84 KB/s (7233 bytes in 0.083s)
cianer@Feegle:~/wandroid/msm$ gunzip config.gz
cianer@Feegle:~/wandroid/msm$ mv config .config
- Now call make to build the image.
Putting the new kernel onto the phone:
- Firstly ensure the phone has been upgraded to Android 1.5 as the radio image and system has to match the kernel.
- Backup the existing boot & recovery images from the phone as described in the android-dls.com AndroidWiki
cianer@Feegle:~/images$ adb shell
$ su
# cat /dev/mtd/mtd1 > /sdcard/mtd1.img
# cat /dev/mtd/mtd2 > /sdcard/mtd2.img
# exit
$ exit
cianer@Feegle:~/images$ adb pull /sdcard/mtd2.img .
1296 KB/s (2621440 bytes in 1.973s)
cianer@Feegle:~/images$ adb pull /sdcard/mtd1.img .
1516 KB/s (5242880 bytes in 3.376s)
cianer@Feegle:~/images$
- Extract the filesystem from the system image using the android-dls.com unpack-bootimg.pl script
cianer@Feegle:~/images$ unpack-bootimg.pl mtd2.img
kernel written to mtd2.img-kernel.gz
ramdisk written to mtd2.img-ramdisk.cpio.gz
488 blocks
gzip: ../mtd2.img-ramdisk.cpio.gz: decompression OK, trailing garbage ignored
extracted ramdisk contents to directory mtd2.img-ramdisk/
cianer@Feegle:~/images$
- This is a good time to make changes to the filesystem, such as allowing it to be remounted read-write
- Now repack the boot image using the new kernel and the filesystem pulled from the phone
cianer@Feegle:~/images$ repack-bootimg.pl kernel.cupcake.gz mtd2.img-ramdisk img.cianer
488 blocks
repacked boot image written at img.cianer
cianer@Feegle:~/images$
- Finally write the image to /dev/mtd/mtd2
cianer@Feegle:~/images$ adb push img.cianer /sdcard
1325 KB/s (1642496 bytes in 1.210s)
cianer@Feegle:~/images$ adb shell
$ su
# sync
# cat /dev/zero > /dev/mtd/mtd2
write: No space left on device
# flash_image boot /sdcard/img.cianer
# exit
$ exit
cianer@Feegle:~/images$
- Reboot & enjoy!