• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Building Kernels
2@jd:body
3
4<!--
5    Copyright 2015 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>This page details how to build only the kernel. The following instructions
28assume you have not downloaded all of AOSP; if you have already done so, you can
29skip the <code>git clone</code> steps except the step that downloads the kernel
30sources.</p>
31
32<p>All examples in this section use the <code>panda</code> kernel.</p>
33
34<h2 id="figuring-out-which-kernel-to-build">Figuring out which kernel to build</h2>
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>
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>
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>
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>
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>
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
159<p>After determining the device project you want to work with, view the git log
160for the kernel binary. Device projects use the form
161<code>device/&lt;vendor&gt;/&lt;name&gt;</code>.</p>
162
163<pre><code>$ git clone https://android.googlesource.com/device/ti/panda
164$ cd panda
165$ git log --max-count=1 kernel
166</code></pre>
167
168<p>The commit message for the kernel binary contains a partial git log of the
169kernel sources used to build the binary. The first entry in the log is the most
170recent (the one used to build the kernel). Make a note of the commit message
171as you will need it in a later step.</p>
172
173<h2 id="id-version">Identifying kernel version</h2>
174
175<p>To determine the kernel version used in a system image, run the following
176command 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'
179</code></pre>
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'
183</code></pre>
184
185
186<h2 id="downloading-sources">Downloading sources</h2>
187<p>Download the source for the kernel you want to build using the appropriate
188<code>git clone</code> command:</p>
189
190<pre><code>$ git clone https://android.googlesource.com/kernel/common.git
191$ git clone https://android.googlesource.com/kernel/x86_64.git
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>
199
200<ul>
201<li>The <code>goldfish</code> project contains the kernel sources for the emulated
202platforms.</li>
203<li>The <code>msm</code> project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6,
204Nexus 5X, Nexus 6P,
205and 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,
207and 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,
209and can be used as a starting point for work on Samsung Hummingbird chipsets.</li>
210<li>The <code>tegra</code> project is for Xoom, Nexus 7, Nexus 9,
211and 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,
213and can be used as a starting point for work on Samsung Exynos chipsets.</li>
214<li>The <code>x86_64</code> project has the kernel sources for Nexus Player,
215and can be used as a starting point for work on Intel x86_64 chipsets.</li>
216</ul>
217
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>
222<pre>$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH</pre>
223
224<p>On a Linux host, if you don't have an Android source tree, you can download
225the prebuilt toolchain from:
226<pre>$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6</pre>
227
228<h2 id="building">Building the kernel</h2>
229<p>When you know the last commit message for a kernel and have successfully
230downloaded the kernel source and prebuilt gcc, you are ready to build the
231kernel. The following build commands use the panda kernel:</p>
232<pre><code>$ export ARCH=arm
233$ export SUBARCH=arm
234$ export CROSS_COMPILE=arm-eabi-
235$ cd omap
236$ git checkout &lt;commit_from_first_step&gt;
237$ make panda_defconfig
238$ make
239</code></pre>
240
241<p>To build a different kernel, simply replace <code>panda</code> with the name
242of the kernel you want to build.</p>
243
244<p>The kernel binary is output as <code>arch/arm/boot/&lt;kernel_name&gt;</code>
245and can be copied into the Android source tree to build the matching boot image.
246Alternatively, you can include the <code>TARGET_PREBUILT_KERNEL</code>
247variable while using <code>make bootimage</code> (or any other make command line
248that builds a boot image). This variable is supported by all devices
249as it is set up via <code>device/common/populate-new-device.sh</code>. For
250example:</p>
251
252<pre><code>$ export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage-dtb
253</code></pre>
254
255<p class="note"><strong>Note:</strong> Kernel names differ by device. To locate
256the correct filename for your kernel, refer to
257<code>device/&lt;vendor&gt;/&lt;name&gt;</code> in the kernel source.</p>
258