blob: d5173498daf4e1f429ab0d067d08ba3b8144676e [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>
Bill Yicc8fda52014-12-04 10:59:08 -080044 <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 Murphyd72700d2013-11-20 11:40:26 -080062 <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 Queru3b418432013-07-11 15:44:44 -070068 <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 Ly40e3b6d2013-04-17 18:12:10 -070080 <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 Markham6ef40472015-11-04 12:57:03 -0800147<p>After determining the device project you want to work with, view the git log
148for the kernel binary. Device projects use the form
149<code>device/&lt;vendor&gt;/&lt;name&gt;</code>.</p>
Robert Ly40e3b6d2013-04-17 18:12:10 -0700150
Robert Ly35f2fda2013-01-29 16:27:05 -0800151<pre><code>$ git clone https://android.googlesource.com/device/ti/panda
152$ cd panda
Robert Ly40e3b6d2013-04-17 18:12:10 -0700153$ git log --max-count=1 kernel
Robert Ly35f2fda2013-01-29 16:27:05 -0800154</code></pre>
Robert Ly40e3b6d2013-04-17 18:12:10 -0700155
Heidi von Markham6ef40472015-11-04 12:57:03 -0800156<p>The commit message for the kernel binary contains a partial git log of the
157kernel sources used to build the binary. The first entry in the log is the most
158recent (the one used to build the kernel). Make a note of the commit message
159as you will need it in a later step.</p>
Clay Murphy4d366102013-11-19 14:37:52 -0800160
161<h2 id="id-version">Identifying kernel version</h2>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800162
163<p>To determine the kernel version used in a system image, run the following
164command 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 Murphy4d366102013-11-19 14:37:52 -0800167</code></pre>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800168
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 Murphy4d366102013-11-19 14:37:52 -0800171</code></pre>
172
173
Robert Ly35f2fda2013-01-29 16:27:05 -0800174<h2 id="downloading-sources">Downloading sources</h2>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800175<p>Download the source for the kernel you want to build using the appropriate
176<code>git clone</code> command:</p>
177
Robert Ly35f2fda2013-01-29 16:27:05 -0800178<pre><code>$ git clone https://android.googlesource.com/kernel/common.git
Bill Yicc8fda52014-12-04 10:59:08 -0800179$ git clone https://android.googlesource.com/kernel/x86_64.git
Robert Ly35f2fda2013-01-29 16:27:05 -0800180$ 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 Markham6ef40472015-11-04 12:57:03 -0800187
Robert Ly35f2fda2013-01-29 16:27:05 -0800188<ul>
189<li>The <code>goldfish</code> project contains the kernel sources for the emulated
190platforms.</li>
Bill Yicc8fda52014-12-04 10:59:08 -0800191<li>The <code>msm</code> project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6,
Robert Ly35f2fda2013-01-29 16:27:05 -0800192and 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,
194and 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,
196and can be used as a starting point for work on Samsung Hummingbird chipsets.</li>
Bill Yicc8fda52014-12-04 10:59:08 -0800197<li>The <code>tegra</code> project is for Xoom, Nexus 7, Nexus 9,
Robert Ly35f2fda2013-01-29 16:27:05 -0800198and 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,
200and can be used as a starting point for work on Samsung Exynos chipsets.</li>
Bill Yicc8fda52014-12-04 10:59:08 -0800201<li>The <code>x86_64</code> project has the kernel sources for Nexus Player,
202and can be used as a starting point for work on Intel x86_64 chipsets.</li>
Robert Ly35f2fda2013-01-29 16:27:05 -0800203</ul>
Robert Ly40e3b6d2013-04-17 18:12:10 -0700204
Heidi von Markham6ef40472015-11-04 12:57:03 -0800205<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 Ly40e3b6d2013-04-17 18:12:10 -0700209<pre>$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH</pre>
210
Heidi von Markham6ef40472015-11-04 12:57:03 -0800211<p>On a Linux host, if you don't have an Android source tree, you can download
Robert Ly40e3b6d2013-04-17 18:12:10 -0700212the 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 Markham6ef40472015-11-04 12:57:03 -0800215<h2 id="building">Building the kernel</h2>
216<p>When you know the last commit message for a kernel and have successfully
217downloaded the kernel source and prebuilt gcc, you are ready to build the
218kernel. The following build commands use the panda kernel:</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800219<pre><code>$ export ARCH=arm
220$ export SUBARCH=arm
221$ export CROSS_COMPILE=arm-eabi-
222$ cd omap
223$ git checkout &lt;commit_from_first_step&gt;
224$ make panda_defconfig
225$ make
226</code></pre>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800227
228<p>To build a different kernel, simply replace <code>panda</code> with the name
229of the kernel you want to build.</p>
230
231<p>The kernel binary is output as <code>arch/arm/boot/&lt;kernel_name&gt;</code>
232and can be copied into the Android source tree to build the matching boot image.
233Alternatively, you can include the <code>TARGET_PREBUILT_KERNEL</code>
234variable while using <code>make bootimage</code> (or any other make command line
235that builds a boot image). This variable is supported by all devices
236as it is set up via <code>device/common/populate-new-device.sh</code>. For
237example:</p>
238
239<pre><code>$ export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage-dtb
Clay Murphy4d366102013-11-19 14:37:52 -0800240</code></pre>
Heidi von Markham6ef40472015-11-04 12:57:03 -0800241
242<p class="note"><strong>Note:</strong> Kernel names differ by device. To locate
243the correct filename for your kernel, refer to
244<code>device/&lt;vendor&gt;/&lt;name&gt;</code> in the kernel source.</p>