Home | History | Annotate | Download | only in source
      1 page.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
     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
     33 <a href="{@docRoot}source/devices.html#hikey-boards">hikey</a> kernel.</p>
     34 
     35 <h2 id="figuring-out-which-kernel-to-build">Selecting a kernel</h2>
     36 <p>This table lists the name and locations of the kernel sources and binaries:
     37 <table>
     38   <tr>
     39     <th>Device</th>
     40     <th>Binary location</th>
     41     <th>Source location</th>
     42     <th>Build configuration</th>
     43   </tr>
     44   <tr>
     45     <td>marlin</td>
     46     <td>device/google/marlin-kernel</td>
     47     <td>kernel/msm</td>
     48     <td>marlin_defconfig</td>
     49   </tr>
     50   <tr>
     51     <td>sailfish</td>
     52     <td>device/google/marlin-kernel</td>
     53     <td>kernel/msm</td>
     54     <td>marlin_defconfig</td>
     55   </tr>
     56   <tr>
     57     <td>hikey</td>
     58     <td>device/linaro/hikey-kernel</td>
     59     <td>kernel/hikey-linaro</td>
     60     <td>hikey_defconfig</td>
     61   </tr>
     62   <tr>
     63     <td>angler</td>
     64     <td>device/huawei/angler-kernel</td>
     65     <td>kernel/msm</td>
     66     <td>angler_defconfig</td>
     67   </tr>
     68   <tr>
     69     <td>bullhead</td>
     70     <td>device/lge/bullhead-kernel</td>
     71     <td>kernel/msm</td>
     72     <td>bullhead_defconfig</td>
     73   </tr>
     74   <tr>
     75     <td>shamu</td>
     76     <td>device/moto/shamu-kernel</td>
     77     <td>kernel/msm</td>
     78     <td>shamu_defconfig</td>
     79   </tr>
     80   <tr>
     81     <td>fugu</td>
     82     <td>device/asus/fugu-kernel</td>
     83     <td>kernel/x86_64</td>
     84     <td>fugu_defconfig</td>
     85   </tr>
     86   <tr>
     87     <td>volantis</td>
     88     <td>device/htc/flounder-kernel</td>
     89     <td>kernel/tegra</td>
     90     <td>flounder_defconfig</td>
     91   </tr>
     92   <tr>
     93     <td>hammerhead</td>
     94     <td>device/lge/hammerhead-kernel</td>
     95     <td>kernel/msm</td>
     96     <td>hammerhead_defconfig</td>
     97   </tr>
     98   <tr>
     99     <td>flo</td>
    100     <td>device/asus/flo-kernel/kernel</td>
    101     <td>kernel/msm</td>
    102     <td>flo_defconfig</td>
    103   </tr>
    104   <tr>
    105     <td>deb</td>
    106     <td>device/asus/flo-kernel/kernel</td>
    107     <td>kernel/msm</td>
    108     <td>flo_defconfig</td>
    109   </tr>
    110   <tr>
    111     <td>manta</td>
    112     <td>device/samsung/manta/kernel</td>
    113     <td>kernel/exynos</td>
    114     <td>manta_defconfig</td>
    115   </tr>
    116   <tr>
    117     <td>mako</td>
    118     <td>device/lge/mako-kernel/kernel</td>
    119     <td>kernel/msm</td>
    120     <td>mako_defconfig</td>
    121   </tr>
    122   <tr>
    123     <td>grouper</td>
    124     <td>device/asus/grouper/kernel</td>
    125     <td>kernel/tegra</td>
    126     <td>tegra3_android_defconfig</td>
    127   </tr>
    128   <tr>
    129     <td>tilapia</td>
    130     <td>device/asus/grouper/kernel</td>
    131     <td>kernel/tegra</td>
    132     <td>tegra3_android_defconfig</td>
    133   </tr>
    134   <tr>
    135     <td>maguro</td>
    136     <td>device/samsung/tuna/kernel</td>
    137     <td>kernel/omap</td>
    138     <td>tuna_defconfig</td>
    139   </tr>
    140   <tr>
    141     <td>toro</td>
    142     <td>device/samsung/tuna/kernel</td>
    143     <td>kernel/omap</td>
    144     <td>tuna_defconfig</td>
    145   </tr>
    146   <tr>
    147     <td>panda</td>
    148     <td>device/ti/panda/kernel</td>
    149     <td>kernel/omap</td>
    150     <td>panda_defconfig</td>
    151   </tr>
    152   <tr>
    153     <td>stingray</td>
    154     <td>device/moto/wingray/kernel</td>
    155     <td>kernel/tegra</td>
    156     <td>stingray_defconfig</td>
    157   </tr>
    158   <tr>
    159     <td>wingray</td>
    160     <td>device/moto/wingray/kernel </td>
    161     <td>kernel/tegra</td>
    162     <td>stingray_defconfig</td>
    163   </tr>
    164   <tr>
    165     <td>crespo</td>
    166     <td>device/samsung/crespo/kernel</td>
    167     <td>kernel/samsung</td>
    168     <td>herring_defconfig</td>
    169   </tr>
    170   <tr>
    171     <td>crespo4g</td>
    172     <td>device/samsung/crespo/kernel</td>
    173     <td>kernel/samsung</td>
    174     <td>herring_defconfig</td>
    175   </tr>
    176 </table>
    177 
    178 <p>After determining the device project you want to work with, view the git log
    179 for the kernel binary. Device projects use the form
    180 <code>device/&lt;vendor&gt;/&lt;name&gt;</code>.</p>
    181 
    182 <pre><code>$ git clone https://android.googlesource.com/kernel/hikey-linaro
    183 $ cd hikey-linaro
    184 $ git log --max-count=1 kernel
    185 </code></pre>
    186 
    187 <p>The commit message for the kernel binary contains a partial git log of the
    188 kernel sources used to build the binary. The first entry in the log is the most
    189 recent (the one used to build the kernel). Make a note of the commit message
    190 as you will need it in a later step.</p>
    191 
    192 <h2 id="id-version">Identifying kernel version</h2>
    193 
    194 <p>To determine the kernel version used in a system image, run the following
    195 command against the kernel file:</p>
    196 
    197 <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'
    198 </code></pre>
    199 
    200 <p>For Nexus 5 (hammerhead), the command is:</p>
    201 <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'
    202 </code></pre>
    203 
    204 
    205 <h2 id="downloading-sources">Downloading sources</h2>
    206 <p>Download the source for the kernel you want to build using the appropriate
    207 <code>git clone</code> command:</p>
    208 
    209 <pre><code>$ git clone https://android.googlesource.com/kernel/common.git
    210 $ git clone https://android.googlesource.com/kernel/hikey-linaro
    211 $ git clone https://android.googlesource.com/kernel/x86_64.git
    212 $ git clone https://android.googlesource.com/kernel/exynos.git
    213 $ git clone https://android.googlesource.com/kernel/goldfish.git
    214 $ git clone https://android.googlesource.com/kernel/msm.git
    215 $ git clone https://android.googlesource.com/kernel/omap.git
    216 $ git clone https://android.googlesource.com/kernel/samsung.git
    217 $ git clone https://android.googlesource.com/kernel/tegra.git
    218 </code></pre>
    219 
    220 <ul>
    221 <li>The <code>goldfish</code> project contains the kernel sources for the
    222 emulated platforms.</li>
    223 <li>The <code>msm</code> project has the sources for ADP1, ADP2, Nexus One,
    224 Nexus 4, Nexus 5, Nexus 6, Nexus 5X, Nexus 6P, Nexus 7 (2013), Pixel,
    225 and Pixel XL, and can be used
    226 as a starting point for work on Qualcomm MSM chipsets.</li>
    227 <li>The <code>omap</code> project is used for PandaBoard and Galaxy Nexus,
    228 and can be used as a starting point for work on TI OMAP chipsets.</li>
    229 <li>The <code>samsung</code> project is used for Nexus S, and can be used as a
    230 starting point for work on Samsung Hummingbird chipsets.</li>
    231 <li>The <code>tegra</code> project is for Xoom, Nexus 7 (2012), Nexus 9,
    232 and can be used as a starting point for work on NVIDIA Tegra chipsets.</li>
    233 <li>The <code>exynos</code> project has the kernel sources for Nexus 10,
    234 and can be used as a starting point for work on Samsung Exynos chipsets.</li>
    235 <li>The <code>x86_64</code> project has the kernel sources for Nexus Player,
    236 and can be used as a starting point for work on Intel x86_64 chipsets.</li>
    237 <li>The <code>hikey-linaro</code> project is used for HiKey reference boards,
    238 and can be used as a starting point for work on HiSilicon 620 chipsets.</li>
    239 </ul>
    240 
    241 <h2 id="downloading-a-prebuilt-gcc">Downloading a prebuilt gcc</h2>
    242 <p>Ensure the prebuilt toolchain is in your path:</p>
    243 <pre>$ export PATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH</pre>
    244 <p>or</p>
    245 <pre>$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH</pre>
    246 
    247 <p>On a Linux host, if you don't have an Android source tree, you can download
    248 the prebuilt toolchain from:
    249 <pre>$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6</pre>
    250 
    251 <h2 id="building">Building the kernel</h2>
    252 <p>When you know the last commit message for a kernel and have successfully
    253 downloaded the kernel source and prebuilt gcc, you are ready to build the
    254 kernel. The following build commands use the hikey kernel:</p>
    255 <pre><code>$ export ARCH=arm64
    256 $ export CROSS_COMPILE=aarch64-linux-android-
    257 $ cd hikey-linaro
    258 $ git checkout -b android-hikey-linaro-4.1 origin/android-hikey-linaro-4.1
    259 $ make hikey_defconfig
    260 $ make
    261 </code></pre>
    262 
    263 <p>To build a different kernel, simply replace <code>hikey-linaro</code> with
    264 the name of the kernel you want to build.</p>
    265 
    266 <p>The image outputs to the <code>arch/arm64/boot/Image</code> directory; the
    267 kernel binary outputs to the
    268 <code>arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb</code> fle. Copy the
    269 <code>Image</code> directory and the <code>hi6220-hikey.dtb</code> file to the
    270 <code>hikey-kernel</code> directory.</p>
    271 
    272 <p>Alternatively, you can include the <code>TARGET_PREBUILT_KERNEL</code>
    273 variable while using <code>make bootimage</code> (or any other <code>make</code>
    274 command line that builds a boot image). This variable is supported by all
    275 devices as it is set up via <code>device/common/populate-new-device.sh</code>.
    276 For example:</p>
    277 
    278 <pre><code>$ export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage-dtb
    279 </code></pre>
    280 
    281 <p class="note"><strong>Note:</strong> Kernel names differ by device. To locate
    282 the correct filename for your kernel, refer to
    283 <code>device/&lt;vendor&gt;/&lt;name&gt;</code> in the kernel source.</p>
    284