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>shamu</td>
44    <td>device/moto/shamu-kernel</td>
45    <td>kernel/msm</td>
46    <td>shamu_defconfig</td>
47  </tr>
48  <tr>
49    <td>fugu</td>
50    <td>device/asus/fugu-kernel</td>
51    <td>kernel/x86_64</td>
52    <td>fugu_defconfig</td>
53  </tr>
54  <tr>
55    <td>volantis</td>
56    <td>device/htc/flounder-kernel</td>
57    <td>kernel/tegra</td>
58    <td>flounder_defconfig</td>
59  </tr>
60  <tr>
61    <td>hammerhead</td>
62    <td>device/lge/hammerhead-kernel</td>
63    <td>kernel/msm</td>
64    <td>hammerhead_defconfig</td>
65  </tr>
66  <tr>
67    <td>flo</td>
68    <td>device/asus/flo-kernel/kernel</td>
69    <td>kernel/msm</td>
70    <td>flo_defconfig</td>
71  </tr>
72  <tr>
73    <td>deb</td>
74    <td>device/asus/flo-kernel/kernel</td>
75    <td>kernel/msm</td>
76    <td>flo_defconfig</td>
77  </tr>
78  <tr>
79    <td>manta</td>
80    <td>device/samsung/manta/kernel</td>
81    <td>kernel/exynos</td>
82    <td>manta_defconfig</td>
83  </tr>
84  <tr>
85    <td>mako</td>
86    <td>device/lge/mako-kernel/kernel</td>
87    <td>kernel/msm</td>
88    <td>mako_defconfig</td>
89  </tr>
90  <tr>
91    <td>grouper</td>
92    <td>device/asus/grouper/kernel</td>
93    <td>kernel/tegra</td>
94    <td>tegra3_android_defconfig</td>
95  </tr>
96  <tr>
97    <td>tilapia</td>
98    <td>device/asus/grouper/kernel</td>
99    <td>kernel/tegra</td>
100    <td>tegra3_android_defconfig</td>
101  </tr>
102  <tr>
103    <td>maguro</td>
104    <td>device/samsung/tuna/kernel</td>
105    <td>kernel/omap</td>
106    <td>tuna_defconfig</td>
107  </tr>
108  <tr>
109    <td>toro</td>
110    <td>device/samsung/tuna/kernel</td>
111    <td>kernel/omap</td>
112    <td>tuna_defconfig</td>
113  </tr>
114  <tr>
115    <td>panda</td>
116    <td>device/ti/panda/kernel</td>
117    <td>kernel/omap</td>
118    <td>panda_defconfig</td>
119  </tr>
120  <tr>
121    <td>stingray</td>
122    <td>device/moto/wingray/kernel</td>
123    <td>kernel/tegra</td>
124    <td>stingray_defconfig</td>
125  </tr>
126  <tr>
127    <td>wingray</td>
128    <td>device/moto/wingray/kernel </td>
129    <td>kernel/tegra</td>
130    <td>stingray_defconfig</td>
131  </tr>
132  <tr>
133    <td>crespo</td>
134    <td>device/samsung/crespo/kernel</td>
135    <td>kernel/samsung</td>
136    <td>herring_defconfig</td>
137  </tr>
138  <tr>
139    <td>crespo4g</td>
140    <td>device/samsung/crespo/kernel</td>
141    <td>kernel/samsung</td>
142    <td>herring_defconfig</td>
143  </tr>
144</table>
145
146<p>You will want to look at the git log for the kernel binary in the device
147project that you are interested in.</p>
148
149<p>Device projects are of the form device/&lt;vendor&gt;/&lt;name&gt;.</p>
150<pre><code>$ git clone https://android.googlesource.com/device/ti/panda
151$ cd panda
152$ git log --max-count=1 kernel
153</code></pre>
154
155<p>The commit message for the kernel binary contains a partial git log
156of the kernel sources that were used to build the binary in question.
157The first entry in the log is the most recent, i.e. the one used to
158build that kernel. You will need it at a later step.</p>
159
160
161<h2 id="id-version">Identifying kernel version</h2>
162<p>To determine the kernel version used in a particular system image, run the
163following command against the kernel file:</p>
164<pre><code>
165$ 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'
166</code></pre>
167<p>For Nexus 5 (hammerhead), this can be accomplished with:</p>
168<pre><code>
169$ 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'
170</code></pre>
171
172
173<h2 id="downloading-sources">Downloading sources</h2>
174<p>Depending on which kernel you want,</p>
175<pre><code>$ git clone https://android.googlesource.com/kernel/common.git
176$ git clone https://android.googlesource.com/kernel/x86_64.git
177$ git clone https://android.googlesource.com/kernel/exynos.git
178$ git clone https://android.googlesource.com/kernel/goldfish.git
179$ git clone https://android.googlesource.com/kernel/msm.git
180$ git clone https://android.googlesource.com/kernel/omap.git
181$ git clone https://android.googlesource.com/kernel/samsung.git
182$ git clone https://android.googlesource.com/kernel/tegra.git
183</code></pre>
184<ul>
185<li>The <code>goldfish</code> project contains the kernel sources for the emulated
186platforms.</li>
187<li>The <code>msm</code> project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6,
188and can be used as a starting point for work on Qualcomm MSM chipsets.</li>
189<li>The <code>omap</code> project is used for PandaBoard and Galaxy Nexus,
190and can be used as a starting point for work on TI OMAP chipsets.</li>
191<li>The <code>samsung</code> project is used for Nexus S,
192and can be used as a starting point for work on Samsung Hummingbird chipsets.</li>
193<li>The <code>tegra</code> project is for Xoom, Nexus 7, Nexus 9,
194and can be used as a starting point for work on NVIDIA Tegra chipsets.</li>
195<li>The <code>exynos</code> project has the kernel sources for Nexus 10,
196and can be used as a starting point for work on Samsung Exynos chipsets.</li>
197<li>The <code>x86_64</code> project has the kernel sources for Nexus Player,
198and can be used as a starting point for work on Intel x86_64 chipsets.</li>
199</ul>
200<h2 id="downloading-a-prebuilt-gcc">Downloading a prebuilt gcc</h2>
201<p>Ensure that the prebuilt toolchain is in your path.</p>
202<pre>$ export PATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH</pre>
203
204or
205<pre>$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH</pre>
206
207<p>On a linux host, if you don't have an Android source tree, you can download
208the prebuilt toolchain from:
209<pre>$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6</pre>
210
211<h2 id="building">Building</h2>
212<p>As an example, we would build the panda kernel using the following commands:</p>
213<pre><code>$ export ARCH=arm
214$ export SUBARCH=arm
215$ export CROSS_COMPILE=arm-eabi-
216$ cd omap
217$ git checkout &lt;commit_from_first_step&gt;
218$ make panda_defconfig
219$ make
220</code></pre>
221<p>To build the tuna kernel, you may run the previous commands replacing all
222instances of "panda" with "tuna".</p>
223<p>
224The kernel binary is output as: `arch/arm/boot/zImage` It can be copied
225into the Android source tree in order to build the matching boot image.
226</p>
227<p>Or you can include the <code>TARGET_PREBUILT_KERNEL</code> variable while
228using <code>make bootimage</code> or any other make command line that builds a
229boot image.</p>
230<pre><code>
231$ export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage
232</code></pre>
233<p>That variable is supported by all devices as it is set up via
234device/common/populate-new-device.sh</p>
235