Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 1 | page.title=Building Kernels |
| 2 | @jd:body |
| 3 | |
| 4 | <!-- |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 5 | Copyright 2015 The Android Open Source Project |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 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 | |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 27 | <p>This page details how to build only the kernel. The following instructions |
| 28 | assume you have not downloaded all of AOSP; if you have already done so, you can |
| 29 | skip the <code>git clone</code> steps except the step that downloads the kernel |
| 30 | sources.</p> |
| 31 | |
| 32 | <p>All examples in this section use the <code>panda</code> kernel.</p> |
| 33 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 34 | <h2 id="figuring-out-which-kernel-to-build">Figuring out which kernel to build</h2> |
Robert Ly | 40e3b6d | 2013-04-17 18:12:10 -0700 | [diff] [blame] | 35 | <p>This table lists the name and locations of the kernel sources and binaries: |
| 36 | <table> |
| 37 | <tr> |
| 38 | <th>Device</th> |
| 39 | <th>Binary location</th> |
| 40 | <th>Source location</th> |
| 41 | <th>Build configuration</th> |
| 42 | </tr> |
| 43 | <tr> |
Xin Li | 4b1f12b | 2016-01-05 13:51:23 -0800 | [diff] [blame] | 44 | <td>angler</td> |
| 45 | <td>device/huawei/angler-kernel</td> |
| 46 | <td>kernel/msm</td> |
| 47 | <td>angler_defconfig</td> |
| 48 | </tr> |
| 49 | <tr> |
| 50 | <td>bullhead</td> |
| 51 | <td>device/lge/bullhead-kernel</td> |
| 52 | <td>kernel/msm</td> |
| 53 | <td>bullhead_defconfig</td> |
| 54 | </tr> |
| 55 | <tr> |
Bill Yi | cc8fda5 | 2014-12-04 10:59:08 -0800 | [diff] [blame] | 56 | <td>shamu</td> |
| 57 | <td>device/moto/shamu-kernel</td> |
| 58 | <td>kernel/msm</td> |
| 59 | <td>shamu_defconfig</td> |
| 60 | </tr> |
| 61 | <tr> |
| 62 | <td>fugu</td> |
| 63 | <td>device/asus/fugu-kernel</td> |
| 64 | <td>kernel/x86_64</td> |
| 65 | <td>fugu_defconfig</td> |
| 66 | </tr> |
| 67 | <tr> |
| 68 | <td>volantis</td> |
| 69 | <td>device/htc/flounder-kernel</td> |
| 70 | <td>kernel/tegra</td> |
| 71 | <td>flounder_defconfig</td> |
| 72 | </tr> |
| 73 | <tr> |
Clay Murphy | d72700d | 2013-11-20 11:40:26 -0800 | [diff] [blame] | 74 | <td>hammerhead</td> |
| 75 | <td>device/lge/hammerhead-kernel</td> |
| 76 | <td>kernel/msm</td> |
| 77 | <td>hammerhead_defconfig</td> |
| 78 | </tr> |
| 79 | <tr> |
Jean-Baptiste Queru | 3b41843 | 2013-07-11 15:44:44 -0700 | [diff] [blame] | 80 | <td>flo</td> |
| 81 | <td>device/asus/flo-kernel/kernel</td> |
| 82 | <td>kernel/msm</td> |
| 83 | <td>flo_defconfig</td> |
| 84 | </tr> |
| 85 | <tr> |
| 86 | <td>deb</td> |
| 87 | <td>device/asus/flo-kernel/kernel</td> |
| 88 | <td>kernel/msm</td> |
| 89 | <td>flo_defconfig</td> |
| 90 | </tr> |
| 91 | <tr> |
Robert Ly | 40e3b6d | 2013-04-17 18:12:10 -0700 | [diff] [blame] | 92 | <td>manta</td> |
| 93 | <td>device/samsung/manta/kernel</td> |
| 94 | <td>kernel/exynos</td> |
| 95 | <td>manta_defconfig</td> |
| 96 | </tr> |
| 97 | <tr> |
| 98 | <td>mako</td> |
| 99 | <td>device/lge/mako-kernel/kernel</td> |
| 100 | <td>kernel/msm</td> |
| 101 | <td>mako_defconfig</td> |
| 102 | </tr> |
| 103 | <tr> |
| 104 | <td>grouper</td> |
| 105 | <td>device/asus/grouper/kernel</td> |
| 106 | <td>kernel/tegra</td> |
| 107 | <td>tegra3_android_defconfig</td> |
| 108 | </tr> |
| 109 | <tr> |
| 110 | <td>tilapia</td> |
| 111 | <td>device/asus/grouper/kernel</td> |
| 112 | <td>kernel/tegra</td> |
| 113 | <td>tegra3_android_defconfig</td> |
| 114 | </tr> |
| 115 | <tr> |
| 116 | <td>maguro</td> |
| 117 | <td>device/samsung/tuna/kernel</td> |
| 118 | <td>kernel/omap</td> |
| 119 | <td>tuna_defconfig</td> |
| 120 | </tr> |
| 121 | <tr> |
| 122 | <td>toro</td> |
| 123 | <td>device/samsung/tuna/kernel</td> |
| 124 | <td>kernel/omap</td> |
| 125 | <td>tuna_defconfig</td> |
| 126 | </tr> |
| 127 | <tr> |
| 128 | <td>panda</td> |
| 129 | <td>device/ti/panda/kernel</td> |
| 130 | <td>kernel/omap</td> |
| 131 | <td>panda_defconfig</td> |
| 132 | </tr> |
| 133 | <tr> |
| 134 | <td>stingray</td> |
| 135 | <td>device/moto/wingray/kernel</td> |
| 136 | <td>kernel/tegra</td> |
| 137 | <td>stingray_defconfig</td> |
| 138 | </tr> |
| 139 | <tr> |
| 140 | <td>wingray</td> |
| 141 | <td>device/moto/wingray/kernel </td> |
| 142 | <td>kernel/tegra</td> |
| 143 | <td>stingray_defconfig</td> |
| 144 | </tr> |
| 145 | <tr> |
| 146 | <td>crespo</td> |
| 147 | <td>device/samsung/crespo/kernel</td> |
| 148 | <td>kernel/samsung</td> |
| 149 | <td>herring_defconfig</td> |
| 150 | </tr> |
| 151 | <tr> |
| 152 | <td>crespo4g</td> |
| 153 | <td>device/samsung/crespo/kernel</td> |
| 154 | <td>kernel/samsung</td> |
| 155 | <td>herring_defconfig</td> |
| 156 | </tr> |
| 157 | </table> |
| 158 | |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 159 | <p>After determining the device project you want to work with, view the git log |
| 160 | for the kernel binary. Device projects use the form |
| 161 | <code>device/<vendor>/<name></code>.</p> |
Robert Ly | 40e3b6d | 2013-04-17 18:12:10 -0700 | [diff] [blame] | 162 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 163 | <pre><code>$ git clone https://android.googlesource.com/device/ti/panda |
| 164 | $ cd panda |
Robert Ly | 40e3b6d | 2013-04-17 18:12:10 -0700 | [diff] [blame] | 165 | $ git log --max-count=1 kernel |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 166 | </code></pre> |
Robert Ly | 40e3b6d | 2013-04-17 18:12:10 -0700 | [diff] [blame] | 167 | |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 168 | <p>The commit message for the kernel binary contains a partial git log of the |
| 169 | kernel sources used to build the binary. The first entry in the log is the most |
| 170 | recent (the one used to build the kernel). Make a note of the commit message |
| 171 | as you will need it in a later step.</p> |
Clay Murphy | 4d36610 | 2013-11-19 14:37:52 -0800 | [diff] [blame] | 172 | |
| 173 | <h2 id="id-version">Identifying kernel version</h2> |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 174 | |
| 175 | <p>To determine the kernel version used in a system image, run the following |
| 176 | command against the kernel file:</p> |
| 177 | |
| 178 | <pre><code>$ 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' |
Clay Murphy | 4d36610 | 2013-11-19 14:37:52 -0800 | [diff] [blame] | 179 | </code></pre> |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 180 | |
| 181 | <p>For Nexus 5 (hammerhead), the command is:</p> |
| 182 | <pre><code>$ dd if=zImage-dtb bs=1 skip=$(LC_ALL=C od -Ad -x -w2 zImage-dtb | grep 8b1f | cut -d ' ' -f1 | head -1) | zgrep -a 'Linux version' |
Clay Murphy | 4d36610 | 2013-11-19 14:37:52 -0800 | [diff] [blame] | 183 | </code></pre> |
| 184 | |
| 185 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 186 | <h2 id="downloading-sources">Downloading sources</h2> |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 187 | <p>Download the source for the kernel you want to build using the appropriate |
| 188 | <code>git clone</code> command:</p> |
| 189 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 190 | <pre><code>$ git clone https://android.googlesource.com/kernel/common.git |
Bill Yi | cc8fda5 | 2014-12-04 10:59:08 -0800 | [diff] [blame] | 191 | $ git clone https://android.googlesource.com/kernel/x86_64.git |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 192 | $ git clone https://android.googlesource.com/kernel/exynos.git |
| 193 | $ git clone https://android.googlesource.com/kernel/goldfish.git |
| 194 | $ git clone https://android.googlesource.com/kernel/msm.git |
| 195 | $ git clone https://android.googlesource.com/kernel/omap.git |
| 196 | $ git clone https://android.googlesource.com/kernel/samsung.git |
| 197 | $ git clone https://android.googlesource.com/kernel/tegra.git |
| 198 | </code></pre> |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 199 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 200 | <ul> |
| 201 | <li>The <code>goldfish</code> project contains the kernel sources for the emulated |
| 202 | platforms.</li> |
Bill Yi | cc8fda5 | 2014-12-04 10:59:08 -0800 | [diff] [blame] | 203 | <li>The <code>msm</code> project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6, |
Xin Li | 4b1f12b | 2016-01-05 13:51:23 -0800 | [diff] [blame] | 204 | Nexus 5X, Nexus 6P, |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 205 | and can be used as a starting point for work on Qualcomm MSM chipsets.</li> |
| 206 | <li>The <code>omap</code> project is used for PandaBoard and Galaxy Nexus, |
| 207 | and can be used as a starting point for work on TI OMAP chipsets.</li> |
| 208 | <li>The <code>samsung</code> project is used for Nexus S, |
| 209 | and can be used as a starting point for work on Samsung Hummingbird chipsets.</li> |
Bill Yi | cc8fda5 | 2014-12-04 10:59:08 -0800 | [diff] [blame] | 210 | <li>The <code>tegra</code> project is for Xoom, Nexus 7, Nexus 9, |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 211 | and can be used as a starting point for work on NVIDIA Tegra chipsets.</li> |
| 212 | <li>The <code>exynos</code> project has the kernel sources for Nexus 10, |
| 213 | and can be used as a starting point for work on Samsung Exynos chipsets.</li> |
Bill Yi | cc8fda5 | 2014-12-04 10:59:08 -0800 | [diff] [blame] | 214 | <li>The <code>x86_64</code> project has the kernel sources for Nexus Player, |
| 215 | and can be used as a starting point for work on Intel x86_64 chipsets.</li> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 216 | </ul> |
Robert Ly | 40e3b6d | 2013-04-17 18:12:10 -0700 | [diff] [blame] | 217 | |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 218 | <h2 id="downloading-a-prebuilt-gcc">Downloading a prebuilt gcc</h2> |
| 219 | <p>Ensure the prebuilt toolchain is in your path:</p> |
| 220 | <pre>$ export PATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH</pre> |
| 221 | <p>or</p> |
Robert Ly | 40e3b6d | 2013-04-17 18:12:10 -0700 | [diff] [blame] | 222 | <pre>$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH</pre> |
| 223 | |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 224 | <p>On a Linux host, if you don't have an Android source tree, you can download |
Robert Ly | 40e3b6d | 2013-04-17 18:12:10 -0700 | [diff] [blame] | 225 | the prebuilt toolchain from: |
| 226 | <pre>$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6</pre> |
| 227 | |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 228 | <h2 id="building">Building the kernel</h2> |
| 229 | <p>When you know the last commit message for a kernel and have successfully |
| 230 | downloaded the kernel source and prebuilt gcc, you are ready to build the |
| 231 | kernel. The following build commands use the panda kernel:</p> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 232 | <pre><code>$ export ARCH=arm |
| 233 | $ export SUBARCH=arm |
| 234 | $ export CROSS_COMPILE=arm-eabi- |
| 235 | $ cd omap |
| 236 | $ git checkout <commit_from_first_step> |
| 237 | $ make panda_defconfig |
| 238 | $ make |
| 239 | </code></pre> |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 240 | |
| 241 | <p>To build a different kernel, simply replace <code>panda</code> with the name |
| 242 | of the kernel you want to build.</p> |
| 243 | |
| 244 | <p>The kernel binary is output as <code>arch/arm/boot/<kernel_name></code> |
| 245 | and can be copied into the Android source tree to build the matching boot image. |
| 246 | Alternatively, you can include the <code>TARGET_PREBUILT_KERNEL</code> |
| 247 | variable while using <code>make bootimage</code> (or any other make command line |
| 248 | that builds a boot image). This variable is supported by all devices |
| 249 | as it is set up via <code>device/common/populate-new-device.sh</code>. For |
| 250 | example:</p> |
| 251 | |
| 252 | <pre><code>$ export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage-dtb |
Clay Murphy | 4d36610 | 2013-11-19 14:37:52 -0800 | [diff] [blame] | 253 | </code></pre> |
Heidi von Markham | 6ef4047 | 2015-11-04 12:57:03 -0800 | [diff] [blame] | 254 | |
| 255 | <p class="note"><strong>Note:</strong> Kernel names differ by device. To locate |
| 256 | the correct filename for your kernel, refer to |
Xin Li | 4b1f12b | 2016-01-05 13:51:23 -0800 | [diff] [blame] | 257 | <code>device/<vendor>/<name></code> in the kernel source.</p> |