blob: cba14639a4a8489da834535684aa716a871d4914 [file] [log] [blame]
Robert Ly35f2fda2013-01-29 16:27:05 -08001page.title=Building Kernels
2@jd:body
3
4<!--
Heidi von Markham6ef40472015-11-04 12:57:03 -08005 Copyright 2015 The Android Open Source Project
Robert Ly35f2fda2013-01-29 16:27:05 -08006
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 Markham6ef40472015-11-04 12:57:03 -080027<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
Robert Ly35f2fda2013-01-29 16:27:05 -080034<h2 id="figuring-out-which-kernel-to-build">Figuring out which kernel to build</h2>
Robert Ly40e3b6d2013-04-17 18:12:10 -070035<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 Li4b1f12b2016-01-05 13:51:23 -080044 <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 Yicc8fda52014-12-04 10:59:08 -080056 <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 Murphyd72700d2013-11-20 11:40:26 -080074 <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 Queru3b418432013-07-11 15:44:44 -070080 <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 Ly40e3b6d2013-04-17 18:12:10 -070092 <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 Markham6ef40472015-11-04 12:57:03 -0800159<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>
Robert Ly40e3b6d2013-04-17 18:12:10 -0700162
Robert Ly35f2fda2013-01-29 16:27:05 -0800163<pre><code>$ git clone https://android.googlesource.com/device/ti/panda
164$ cd panda
Robert Ly40e3b6d2013-04-17 18:12:10 -0700165$ git log --max-count=1 kernel
Robert Ly35f2fda2013-01-29 16:27:05 -0800166</code></pre>
Robert Ly40e3b6d2013-04-17 18:12:10 -0700167
Heidi von Markham6ef40472015-11-04 12:57:03 -0800168<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>
Clay Murphy4d366102013-11-19 14:37:52 -0800172
173<h2 id="id-version">Identifying kernel version</h2>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800174
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'
Clay Murphy4d366102013-11-19 14:37:52 -0800179</code></pre>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800180
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 Murphy4d366102013-11-19 14:37:52 -0800183</code></pre>
184
185
Robert Ly35f2fda2013-01-29 16:27:05 -0800186<h2 id="downloading-sources">Downloading sources</h2>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800187<p>Download the source for the kernel you want to build using the appropriate
188<code>git clone</code> command:</p>
189
Robert Ly35f2fda2013-01-29 16:27:05 -0800190<pre><code>$ git clone https://android.googlesource.com/kernel/common.git
Bill Yicc8fda52014-12-04 10:59:08 -0800191$ git clone https://android.googlesource.com/kernel/x86_64.git
Robert Ly35f2fda2013-01-29 16:27:05 -0800192$ 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 Markham6ef40472015-11-04 12:57:03 -0800199
Robert Ly35f2fda2013-01-29 16:27:05 -0800200<ul>
201<li>The <code>goldfish</code> project contains the kernel sources for the emulated
202platforms.</li>
Bill Yicc8fda52014-12-04 10:59:08 -0800203<li>The <code>msm</code> project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6,
Xin Li4b1f12b2016-01-05 13:51:23 -0800204Nexus 5X, Nexus 6P,
Robert Ly35f2fda2013-01-29 16:27:05 -0800205and 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>
Bill Yicc8fda52014-12-04 10:59:08 -0800210<li>The <code>tegra</code> project is for Xoom, Nexus 7, Nexus 9,
Robert Ly35f2fda2013-01-29 16:27:05 -0800211and 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>
Bill Yicc8fda52014-12-04 10:59:08 -0800214<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>
Robert Ly35f2fda2013-01-29 16:27:05 -0800216</ul>
Robert Ly40e3b6d2013-04-17 18:12:10 -0700217
Heidi von Markham6ef40472015-11-04 12:57:03 -0800218<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 Ly40e3b6d2013-04-17 18:12:10 -0700222<pre>$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH</pre>
223
Heidi von Markham6ef40472015-11-04 12:57:03 -0800224<p>On a Linux host, if you don't have an Android source tree, you can download
Robert Ly40e3b6d2013-04-17 18:12:10 -0700225the 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 Markham6ef40472015-11-04 12:57:03 -0800228<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>
Robert Ly35f2fda2013-01-29 16:27:05 -0800232<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>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800240
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
Clay Murphy4d366102013-11-19 14:37:52 -0800253</code></pre>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800254
255<p class="note"><strong>Note:</strong> Kernel names differ by device. To locate
256the correct filename for your kernel, refer to
Xin Li4b1f12b2016-01-05 13:51:23 -0800257<code>device/&lt;vendor&gt;/&lt;name&gt;</code> in the kernel source.</p>