| 1 | = Android Development On ORBIT = |
| 2 | |
| 3 | == 0. Setup device == |
| 4 | |
| 5 | In order to flash a custom kernel on your Android device, it must be rooted. |
| 6 | |
| 7 | To root an HTC device, you can use [http://unrevoked.com/recovery/ unrevoked3]. Otherwise, you will probably be able to use [http://forum.xda-developers.com/showthread.php?t=803682 SuperOneClick]. |
| 8 | |
| 9 | Once you are rooted, you may use the recovery to flash new kernels, as well as custom ROMS. The only prerequisite is that you have ClockworkMod recovery installed. Download ROM Manager from the Android market, and select "Flash ClockworkMod Recovery". Now you have a custom recovery installed that will let you flash custom kernels. The complete guide is available [http://www.androidpolice.com/2010/05/08/complete-guide-how-to-flash-a-custom-rom-to-your-android-phone-with-rom-manager-full-backup-restore/ here]. |
| 10 | |
| 11 | == 1. Setup environment == |
| 12 | |
| 13 | [http://www.orbit-lab.org/wiki/Documentation/Android Load the Android development image] onto a node and ssh into it. |
| 14 | |
| 15 | You will have to export some path files: |
| 16 | |
| 17 | {{{ |
| 18 | PATH=$PATH:/root/android-sdk-linux_x86/platform-tools/:/root/android-sdk-linux_x86/tools |
| 19 | export PATH |
| 20 | }}} |
| 21 | |
| 22 | Which will allow you to use adb, emulator, fastboot and other commands from any location. |
| 23 | |
| 24 | == 2. Get Source Code == |
| 25 | |
| 26 | The CyanogenMod source code is available at https://github.com/CyanogenMod/cm-kernel. |
| 27 | |
| 28 | If you would like to use a different kernel, you can find most active ones at http://forum.xda-developers.com in the Android Development forum for your device. |
| 29 | |
| 30 | You may have to download and extract the source code archive, or you can use git: |
| 31 | |
| 32 | {{{ |
| 33 | git clone git://github.com/CyanogenMod/cm-kernel |
| 34 | }}} |
| 35 | |
| 36 | == 3. Configure Kernel == |
| 37 | |
| 38 | Now we need to configure the kernel with all the features required. The default configuration files are located in arch/arm/configs |
| 39 | |
| 40 | Copy the correct file to .config in the kernel directory. |
| 41 | |
| 42 | {{{ |
| 43 | cp arch/arm/configs/cyanogen_supersonic_defconfig .config |
| 44 | }}} |
| 45 | |
| 46 | You can edit this with a text editor, or use make ARCH=arm CROSS_COMPILE-arm-none-eabi- menuconfig. Change CONFIG_LOCALVERSION so you can identify your kernel in About Phone on your device. |
| 47 | |
| 48 | If you manually edited this file, you can run |
| 49 | {{{ |
| 50 | make ARCH=arm CROSS_COMPILE=arm-none-eabi- menuconfig |
| 51 | }}} |
| 52 | |
| 53 | and go to Load Alternate Config file and select .config. |
| 54 | |
| 55 | == 4. Compile Kernel == |
| 56 | |
| 57 | To compile the kernel, just run |
| 58 | {{{ |
| 59 | make ARCH=arm CROSS_COMPILE=arm-none-eabi- -j8 |
| 60 | }}} |
| 61 | |
| 62 | If there is an error while compiling, that line will be prefixed by **, but the compilation will continue. |
| 63 | |
| 64 | Always run |
| 65 | {{{ |
| 66 | make clean |
| 67 | }}} |
| 68 | before recompiling. |
| 69 | |
| 70 | If you get an error like 'Selected processor does not support ARM mode ...' then run make with the extra parameter: |
| 71 | {{{ |
| 72 | make ARCH=arm CROSS_COMPILE=arm-none-eabi- EXTRA_AFLAGS=-mfpu=neon -j8 |
| 73 | }}} |
| 74 | |
| 75 | Most other errors can be resolved with Google. |
| 76 | |
| 77 | If your kernel compiled successfully, you will have a zImage file in arch/arm/boot, and it will print the path to the kernel modules that were also compiled. |
| 78 | |
| 79 | == 5. Make an update .zip file == |
| 80 | |
| 81 | ClockworkMod recovery installs .zip packages, so you will need to put everything into a template before you can flash it. |
| 82 | |
| 83 | Move to a different directory and get this source: |
| 84 | {{{ |
| 85 | git clone git://github.com/choochootrain/kernel-template |
| 86 | }}} |
| 87 | |
| 88 | It is a fork of koush's AnyKernel template that is modified for the HTC EVO (Supersonic). If you are using a different device, you can use koush's template or modify this one. |
| 89 | |
| 90 | The template contains a precompiled zImage in kernel/ , kernel modules in system/lib/modules/ , and an updater-script in META-INF/com/google/android/ |
| 91 | |
| 92 | Replace the zImage and kernel modules with yours. The updater-script is what is run to modfiy your device. If first dumps the kernel modules onto your phone, and then unpacks the current boot partition from the phone and repacks it with your zImage and then writes it to the boot partition. |
| 93 | |
| 94 | navigate to the template directory and zip the files: |
| 95 | {{{ |
| 96 | zip -r [name goes here].zip * |
| 97 | }}} |
| 98 | Make sure that the .zip contains kernel/, system/, and META-INF/ and not the whole containing directory. |
| 99 | |
| 100 | Now you need to push the .zip onto the device's sdcard. |
| 101 | {{{ |
| 102 | adb push [zip file] /sdcard/[zipfile] |
| 103 | }}} |
| 104 | |
| 105 | == 6. Flash kernel == |
| 106 | |
| 107 | Now you need to boot into recovery to flash the .zip. You can do this from ROM Manager, or by holding power and volume down (on most phones) when you turn the phone on and going to recovery from the bootloader. |
| 108 | |
| 109 | Make sure you have a backup in case the kernel doesnt boot. Before you flash the kernel, you need to wipe the dalvik cache which is located under Advanced from the main menu. |
| 110 | |
| 111 | Once the dalvik cache is wiped, you can install the .zip file. Go to Install zip from sdcard > choose zip from sdcard > [zip file] > yes and then the updater-script will be run. |
| 112 | |
| 113 | If there is an error and it aborts installation, check the updater-script file. |
| 114 | |
| 115 | If the installation completes, you can try rebooting your device. |
| 116 | |
| 117 | It will take longer to boot because it has to rebuild the dalvik cache |
| 118 | |
| 119 | == 7. Troubleshooting kernel == |
| 120 | |
| 121 | If the kernel causes your phone to hang on the splash screen or enters a boot loop, your kernel most likely has a problem. Pull the battery out, enter recovery by holding power and volume down and select recovery. |
| 122 | |
| 123 | Since the kernel only affects the boot partition, you can do a partial restore to fix your device. Go to Backup and restore > Advanced restore > [your latest backup] > boot.img |
| 124 | |
| 125 | Now your phone is back in working condition. |
| 126 | |
| 127 | You can see error messages during installation by following the log file after you install the .zip file. |
| 128 | {{{ |
| 129 | adb shell |
| 130 | cd tmp |
| 131 | cat recovery.log |
| 132 | }}} |
| 133 | |
| 134 | You can see error messages while the phone is running through dmesg: |
| 135 | {{{ |
| 136 | adb shell |
| 137 | dmesg |
| 138 | }}} |