Howto: Build a Kernel Port
| This page requires cleanup to meet CyanogenMod Wiki's style and formatting guidelines, or needs to be rewritten for general clarity. Please improve this page if you can. The talk page may contain suggestions. Once this page has been cleaned up, please remove this template. |
Currently CyanogenMod only runs on Dream/32B Magic hardware with the EBI0 kernel (1.xxx or 2.xxx radio versions, 192 MB total RAM) - but it's pretty easy to get it working on other handsets!
If you want to build a EBI1 kernel port package to get it to run on a 32A Magic (with 288 MB total RAM), or a device with the 3.xxx radio such as the Rogers 32A Magic and Rogers Dream, then you can follow the instructions below:
This guide uses the majority of the work of Radix's previous port writeup.
N.B. if you don't have unpack-H.pl/repack-H.pl or the sign tools - download them from here. Keep in mind that the regular repack/unpack will not work, as the offsets are different. Alternatively you can use mkbootimg --base 0x19200000.
Extract them somewhere in your PATH for easy access (such as SDK/tools directory).
Open up your terminal and follow these steps:
- 1. Get the Android source and build it. You will need JDK (openjdk-6-jdk or sun-java6-jdk), curl and git-core packages and probably also some other tools to get this working. Refer to the official SDK installation instructions if you don't already have the prerequisites for this. This process may a while to complete depending on the speed of your internet connection.
curl http://android.git.kernel.org/repo >~/bin/repo
chmod a+x ~/bin/repo
mkdir <Android source dir> && cd <Android source dir>
repo init -u git://github.com/CyanogenMod/android.git -b froyo
repo sync
- 2. Now we have the tools and compilers ready from the Android SDK, so we just need to add them to our PATH. You might want to include this in your Bash startup script as well.
export PATH=$PATH:~/<Android source dir>/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin
- 3. To obtain the Cyangenmod kernel source you can either use the code already downloaded in the previous step or make a new folder just for the kernel. The kernel source that's included in the full CyanogenMod source is located in the kernel-msm folder. This guide will assume you want to have separate cm-kernel folder. These next commands will create a cm-kernel folder in your home (~) directory.
cd ~
git clone git://github.com/CyanogenMod/cm-kernel.git
cd cm-kernel
git branch -r
git checkout --track -b cm-2.6.35 origin/android-msm-2.6.35
- (Once you've done this once - for future ports you can just do a 'git pull' to grab the latest changes.
- Remember to run the command 'make mrproper' to clean your source before you rebuild)
- 4. Set your environment variables for the Cyanogenmod kernel. Again you may want to include these in your bash startup script.
- Replace /full/path/to/ with the location your cm-kernel directory is stored in
export ARCH=arm
export CROSS_COMPILE=arm-eabi-
export KERNEL_DIR=/full/path/to/cm-kernel
- 6. Now get a configuration file (.config) for the kernel. You can make changes to this file to modify your build. This needs to be placed put in your cm-kernel root directory, where you will see a lot of folders and such. If you are using a file manager, this file is normally hidden. Instead of building your own from scratch, you can either:
- Pull an existing one from you device, it is found in /proc/config.gz.
zcat config.gz > ~/cm-kernel/.config
- Extract it from Cyanogen's boot.img:
cd <cm-kernel source dir>
scripts/extract-ikconfig boot.img > .config
- Use the default config and modify to add EBI1 support:
cd <cm-kernel source dir>
make cyanogen_msm_defconfig
Open the .config file in a file editor and set CONFIG_MSM_AMSS_SUPPORT_256MB_EBI1=y --OR--
sed -i 's/# CONFIG_MSM_AMSS_SUPPORT_256MB_EBI1 is not set/CONFIG_MSM_AMSS_SUPPORT_256MB_EBI1=y/' .config
- You can also ask on IRC for one from another developer.
- 7. To build the kernel:
make
- Wait for it to complete. The built kernel image will be in arch/arm/boot/zImage
- 8. The wlan module is built automatically with the kernel. It is located in:
<kernel source dir>/drivers/net/wireless/tiwlan1251/wlan.ko
- 9. Now you need to unpack and extract the ramdisk from Cyanogen's boot.img:
unpack-H.pl boot.img mkdir ramdisk cd ramdisk gunzip -c ../boot.img-ramdisk.gz | cpio -i cd ..
- 10. Now you need to decide how you want to package the port file. Normally, we would extract a boot.img, repack it with the compiled kernel and make a ROM specific port. The easier (and more versatile) option is to use Koush's AnyKernel zip package. This package allows a flashable package to be made with just a kernel and the wifi module. This makes it good for ANY ROM as we don't need to pack a ROM specific ramdisk.
Option 1: Koush's AnyKernel zip file Koush's AnyKernel repacks the kernel in the package with the ramdisk currently flashed to the device. Therefore, we need to change the boot.img --base address so the boot.img will boot on the 32A device. This change needs to be made in mkbootimg.sh in the package. Koush has a 32A branch of AnyKernel here: http://github.com/koush/AnyKernel Clone the AnyKernel repo
git clone git://github.com/koush/AnyKernel.git -b 32A
This will make a folder called AnyKernel in your working directory. Keep this and just copy it to your packaging directory.
Copy the AnyKernel folder to a working directory. In the AnyKernel folder you have three folders:
- kernel
- Put the zImage in this folder. Leave it named zImage
- META-INF
- system
- Put the wlan.ko in system/lib/modules. Replace the placeholder wlan.ko file.
Now you can zip the 3 folders together and sign them
zip -r port.zip *
java -classpath <path to SDK/tools>testsign.jar testsign port.zip signed-port.zip
for example:
java -jar ../SignApp/signapk.jar ../SignApp/testkey.x509.pem ../SignApp/testkey.pk8 port.zip update_signed.zip
This creates a signed zip file called port.zip and can be flashed. :) You are done.
Option 2: Regular ROM Specific Update.zip
Now repack the boot image with the ramdisk above:
- You will need to have the correct execute permissions on the associated binaries and scripts to successful run this step.
repack-H.pl /path/to/cm-kernel/arch/arm/boot/zImage ramdisk boot.img
or
mkbootimg --kernel zImage --ramdisk boot.img-ramdisk.gz --cmdline 'no_console_suspend=1 console=null quiet board_trout.disable_uart3=1' --base 0x19200000 -o boot.img
Download this skeleton zip file: http://briancrook.ca/android/port-tools/port-blank.zip, and then copy the new boot.img into the root of the port-blank folder and wlan.ko into /system/lib/modules/:
cp boot.img <packagedir> cp wlan.ko <packagedir>/system/lib/modules/wlan.ko
- 12. Zip up the <packagedir>, and sign it and it should be ready