1page.title=Building Kernels 2@jd:body 3 4<!-- 5 Copyright 2013 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18--> 19<div id="qv-wrapper"> 20 <div id="qv"> 21 <h2>In this document</h2> 22 <ol id="auto-toc"> 23 </ol> 24 </div> 25</div> 26 27<p>If you are only interested in the kernel, you may use this guide 28to download and build the appropriate kernel.</p> 29<p>The following instructions assume that you have not downloaded all 30of AOSP. If you have downloaded all of AOSP, you may skip the git 31clone steps other than the step to download the actual kernel sources.</p> 32<p>We will use the Pandaboard kernel in all the following examples.</p> 33<h2 id="figuring-out-which-kernel-to-build">Figuring out which kernel to build</h2> 34<p>This table lists the name and locations of the kernel sources and binaries: 35<table> 36 <tr> 37 <th>Device</th> 38 <th>Binary location</th> 39 <th>Source location</th> 40 <th>Build configuration</th> 41 </tr> 42 <tr> 43 <td>hammerhead</td> 44 <td>device/lge/hammerhead-kernel</td> 45 <td>kernel/msm</td> 46 <td>hammerhead_defconfig</td> 47 </tr> 48 <tr> 49 <td>flo</td> 50 <td>device/asus/flo-kernel/kernel</td> 51 <td>kernel/msm</td> 52 <td>flo_defconfig</td> 53 </tr> 54 <tr> 55 <td>deb</td> 56 <td>device/asus/flo-kernel/kernel</td> 57 <td>kernel/msm</td> 58 <td>flo_defconfig</td> 59 </tr> 60 <tr> 61 <td>manta</td> 62 <td>device/samsung/manta/kernel</td> 63 <td>kernel/exynos</td> 64 <td>manta_defconfig</td> 65 </tr> 66 <tr> 67 <td>mako</td> 68 <td>device/lge/mako-kernel/kernel</td> 69 <td>kernel/msm</td> 70 <td>mako_defconfig</td> 71 </tr> 72 <tr> 73 <td>grouper</td> 74 <td>device/asus/grouper/kernel</td> 75 <td>kernel/tegra</td> 76 <td>tegra3_android_defconfig</td> 77 </tr> 78 <tr> 79 <td>tilapia</td> 80 <td>device/asus/grouper/kernel</td> 81 <td>kernel/tegra</td> 82 <td>tegra3_android_defconfig</td> 83 </tr> 84 <tr> 85 <td>maguro</td> 86 <td>device/samsung/tuna/kernel</td> 87 <td>kernel/omap</td> 88 <td>tuna_defconfig</td> 89 </tr> 90 <tr> 91 <td>toro</td> 92 <td>device/samsung/tuna/kernel</td> 93 <td>kernel/omap</td> 94 <td>tuna_defconfig</td> 95 </tr> 96 <tr> 97 <td>panda</td> 98 <td>device/ti/panda/kernel</td> 99 <td>kernel/omap</td> 100 <td>panda_defconfig</td> 101 </tr> 102 <tr> 103 <td>stingray</td> 104 <td>device/moto/wingray/kernel</td> 105 <td>kernel/tegra</td> 106 <td>stingray_defconfig</td> 107 </tr> 108 <tr> 109 <td>wingray</td> 110 <td>device/moto/wingray/kernel </td> 111 <td>kernel/tegra</td> 112 <td>stingray_defconfig</td> 113 </tr> 114 <tr> 115 <td>crespo</td> 116 <td>device/samsung/crespo/kernel</td> 117 <td>kernel/samsung</td> 118 <td>herring_defconfig</td> 119 </tr> 120 <tr> 121 <td>crespo4g</td> 122 <td>device/samsung/crespo/kernel</td> 123 <td>kernel/samsung</td> 124 <td>herring_defconfig</td> 125 </tr> 126</table> 127 128<p>You will want to look at the git log for the kernel binary in the device 129project that you are interested in.</p> 130 131<p>Device projects are of the form device/<vendor>/<name>.</p> 132<pre><code>$ git clone https://android.googlesource.com/device/ti/panda 133$ cd panda 134$ git log --max-count=1 kernel 135</code></pre> 136 137<p>The commit message for the kernel binary contains a partial git log 138of the kernel sources that were used to build the binary in question. 139The first entry in the log is the most recent, i.e. the one used to 140build that kernel. You will need it at a later step.</p> 141 142 143<h2 id="id-version">Identifying kernel version</h2> 144<p>To determine the kernel version used in a particular system image, run the 145following command against the kernel file:</p> 146<pre><code> 147$ dd if=kernel bs=1 skip=$(LC_ALL=C grep -a -b -o $'\x1f\x8b\x08\x00\x00\x00\x00\x00' kernel | cut -d ':' -f 1) | zgrep -a 'Linux version' 148</code></pre> 149<p>For Nexus 5 (hammerhead), this can be accomplished with:</p> 150<pre><code> 151$ bzgrep -a 'Linux version' vmlinux.bz2 152</code></pre> 153 154 155<h2 id="downloading-sources">Downloading sources</h2> 156<p>Depending on which kernel you want,</p> 157<pre><code>$ git clone https://android.googlesource.com/kernel/common.git 158$ git clone https://android.googlesource.com/kernel/exynos.git 159$ git clone https://android.googlesource.com/kernel/goldfish.git 160$ git clone https://android.googlesource.com/kernel/msm.git 161$ git clone https://android.googlesource.com/kernel/omap.git 162$ git clone https://android.googlesource.com/kernel/samsung.git 163$ git clone https://android.googlesource.com/kernel/tegra.git 164</code></pre> 165<ul> 166<li>The <code>goldfish</code> project contains the kernel sources for the emulated 167platforms.</li> 168<li>The <code>msm</code> project has the sources for ADP1, ADP2, Nexus One, Nexus 4, 169and can be used as a starting point for work on Qualcomm MSM chipsets.</li> 170<li>The <code>omap</code> project is used for PandaBoard and Galaxy Nexus, 171and can be used as a starting point for work on TI OMAP chipsets.</li> 172<li>The <code>samsung</code> project is used for Nexus S, 173and can be used as a starting point for work on Samsung Hummingbird chipsets.</li> 174<li>The <code>tegra</code> project is for Xoom and Nexus 7, 175and can be used as a starting point for work on NVIDIA Tegra chipsets.</li> 176<li>The <code>exynos</code> project has the kernel sources for Nexus 10, 177and can be used as a starting point for work on Samsung Exynos chipsets.</li> 178</ul> 179<h2 id="downloading-a-prebuilt-gcc">Downloading a prebuilt gcc</h2> 180<p>Ensure that the prebuilt toolchain is in your path.</p> 181<pre>$ export PATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH</pre> 182 183or 184<pre>$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH</pre> 185 186<p>On a linux host, if you don't have an Android source tree, you can download 187the prebuilt toolchain from: 188<pre>$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6</pre> 189 190<h2 id="building">Building</h2> 191<p>As an example, we would build the panda kernel using the following commands:</p> 192<pre><code>$ export ARCH=arm 193$ export SUBARCH=arm 194$ export CROSS_COMPILE=arm-eabi- 195$ cd omap 196$ git checkout <commit_from_first_step> 197$ make panda_defconfig 198$ make 199</code></pre> 200<p>To build the tuna kernel, you may run the previous commands replacing all 201instances of "panda" with "tuna".</p> 202<p> 203The kernel binary is output as: `arch/arm/boot/zImage` It can be copied 204into the Android source tree in order to build the matching boot image. 205</p> 206<p>Or you can include the <code>TARGET_PREBUILT_KERNEL</code> variable while 207using <code>make bootimage</code> or any other make command line that builds a 208boot image.</p> 209<pre><code> 210$ export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage 211</code></pre> 212<p>That variable is supported by all devices as it is set up via 213device/common/populate-new-device.sh</p> 214