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