Home | History | Annotate | Download | only in source
      1 <html devsite>
      2   <head>
      3     <title>Building Kernels</title>
      4     <meta name="project_path" value="/_project.yaml" />
      5     <meta name="book_path" value="/_book.yaml" />
      6   </head>
      7   <body>
      8   <!--
      9       Copyright 2017 The Android Open Source Project
     10 
     11       Licensed under the Apache License, Version 2.0 (the "License");
     12       you may not use this file except in compliance with the License.
     13       You may obtain a copy of the License at
     14 
     15           http://www.apache.org/licenses/LICENSE-2.0
     16 
     17       Unless required by applicable law or agreed to in writing, software
     18       distributed under the License is distributed on an "AS IS" BASIS,
     19       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20       See the License for the specific language governing permissions and
     21       limitations under the License.
     22   -->
     23 
     24 
     25 
     26 <p>This page details how to build only the kernel. The following instructions
     27 assume you have not downloaded all of AOSP; if you have already done so, you can
     28 skip the <code>git clone</code> steps except the step that downloads the kernel
     29 sources.</p>
     30 
     31 <p>All examples in this section use the
     32 <a href="/source/devices.html#hikey-boards">hikey</a> kernel.</p>
     33 
     34 <h2 id="figuring-out-which-kernel-to-build">Selecting a kernel</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>marlin</td>
     45     <td>device/google/marlin-kernel</td>
     46     <td>kernel/msm</td>
     47     <td>marlin_defconfig</td>
     48   </tr>
     49   <tr>
     50     <td>sailfish</td>
     51     <td>device/google/marlin-kernel</td>
     52     <td>kernel/msm</td>
     53     <td>marlin_defconfig</td>
     54   </tr>
     55   <tr>
     56     <td>hikey</td>
     57     <td>device/linaro/hikey-kernel</td>
     58     <td>kernel/hikey-linaro</td>
     59     <td>hikey_defconfig</td>
     60   </tr>
     61   <tr>
     62     <td>angler</td>
     63     <td>device/huawei/angler-kernel</td>
     64     <td>kernel/msm</td>
     65     <td>angler_defconfig</td>
     66   </tr>
     67   <tr>
     68     <td>bullhead</td>
     69     <td>device/lge/bullhead-kernel</td>
     70     <td>kernel/msm</td>
     71     <td>bullhead_defconfig</td>
     72   </tr>
     73   <tr>
     74     <td>shamu</td>
     75     <td>device/moto/shamu-kernel</td>
     76     <td>kernel/msm</td>
     77     <td>shamu_defconfig</td>
     78   </tr>
     79   <tr>
     80     <td>fugu</td>
     81     <td>device/asus/fugu-kernel</td>
     82     <td>kernel/x86_64</td>
     83     <td>fugu_defconfig</td>
     84   </tr>
     85   <tr>
     86     <td>volantis</td>
     87     <td>device/htc/flounder-kernel</td>
     88     <td>kernel/tegra</td>
     89     <td>flounder_defconfig</td>
     90   </tr>
     91   <tr>
     92     <td>hammerhead</td>
     93     <td>device/lge/hammerhead-kernel</td>
     94     <td>kernel/msm</td>
     95     <td>hammerhead_defconfig</td>
     96   </tr>
     97   <tr>
     98     <td>flo</td>
     99     <td>device/asus/flo-kernel/kernel</td>
    100     <td>kernel/msm</td>
    101     <td>flo_defconfig</td>
    102   </tr>
    103   <tr>
    104     <td>deb</td>
    105     <td>device/asus/flo-kernel/kernel</td>
    106     <td>kernel/msm</td>
    107     <td>flo_defconfig</td>
    108   </tr>
    109   <tr>
    110     <td>manta</td>
    111     <td>device/samsung/manta/kernel</td>
    112     <td>kernel/exynos</td>
    113     <td>manta_defconfig</td>
    114   </tr>
    115   <tr>
    116     <td>mako</td>
    117     <td>device/lge/mako-kernel/kernel</td>
    118     <td>kernel/msm</td>
    119     <td>mako_defconfig</td>
    120   </tr>
    121   <tr>
    122     <td>grouper</td>
    123     <td>device/asus/grouper/kernel</td>
    124     <td>kernel/tegra</td>
    125     <td>tegra3_android_defconfig</td>
    126   </tr>
    127   <tr>
    128     <td>tilapia</td>
    129     <td>device/asus/grouper/kernel</td>
    130     <td>kernel/tegra</td>
    131     <td>tegra3_android_defconfig</td>
    132   </tr>
    133   <tr>
    134     <td>maguro</td>
    135     <td>device/samsung/tuna/kernel</td>
    136     <td>kernel/omap</td>
    137     <td>tuna_defconfig</td>
    138   </tr>
    139   <tr>
    140     <td>toro</td>
    141     <td>device/samsung/tuna/kernel</td>
    142     <td>kernel/omap</td>
    143     <td>tuna_defconfig</td>
    144   </tr>
    145   <tr>
    146     <td>panda</td>
    147     <td>device/ti/panda/kernel</td>
    148     <td>kernel/omap</td>
    149     <td>panda_defconfig</td>
    150   </tr>
    151   <tr>
    152     <td>stingray</td>
    153     <td>device/moto/wingray/kernel</td>
    154     <td>kernel/tegra</td>
    155     <td>stingray_defconfig</td>
    156   </tr>
    157   <tr>
    158     <td>wingray</td>
    159     <td>device/moto/wingray/kernel </td>
    160     <td>kernel/tegra</td>
    161     <td>stingray_defconfig</td>
    162   </tr>
    163   <tr>
    164     <td>crespo</td>
    165     <td>device/samsung/crespo/kernel</td>
    166     <td>kernel/samsung</td>
    167     <td>herring_defconfig</td>
    168   </tr>
    169   <tr>
    170     <td>crespo4g</td>
    171     <td>device/samsung/crespo/kernel</td>
    172     <td>kernel/samsung</td>
    173     <td>herring_defconfig</td>
    174   </tr>
    175 </table>
    176 
    177 <p>After determining the device project you want to work with, view the git log
    178 for the kernel binary. Device projects use the form
    179 <code>device/<var>VENDOR</var>/<var>NAME</var></code>.</p>
    180 
    181 <pre class="devsite-click-to-copy">
    182 <code class="devsite-terminal">git clone https://android.googlesource.com/kernel/hikey-linaro</code>
    183 <code class="devsite-terminal">cd hikey-linaro</code>
    184 <code class="devsite-terminal">git log --max-count=1 kernel</code>
    185 </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 class="devsite-terminal devsite-click-to-copy">
    198 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'
    199 </pre>
    200 
    201 <p>For Nexus 5 (hammerhead), the command is:</p>
    202 <pre class="devsite-terminal devsite-click-to-copy">
    203 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'
    204 </pre>
    205 
    206 
    207 <h2 id="downloading-sources">Downloading sources</h2>
    208 <p>Download the source for the kernel you want to build using the appropriate
    209 <code>git clone</code> command. For example, the following command clones the <code>common</code> kernel, a generic, customizable kernel:</p>
    210 <pre class="devsite-terminal devsite-click-to-copy">
    211 git clone https://android.googlesource.com/kernel/common
    212 </pre>
    213 
    214 <p>A full list of the kernel projects can be found in the <a href="https://android.googlesource.com/kernel">Kernel</a> directory. Below are some of the commonly used kernels and their respective <code>git clone</code> commands.</p>
    215 
    216 <p>The <code>exynos</code> project has the kernel sources for Nexus 10, and can be used as a starting point for work on Samsung Exynos chipsets.</p>
    217 <pre class="devsite-terminal devsite-click-to-copy">git clone https://android.googlesource.com/kernel/exynos</pre>
    218 
    219 <p>The <code>goldfish</code> project contains the kernel sources for the emulated platforms.</p>
    220 <pre class="devsite-terminal devsite-click-to-copy">git clone https://android.googlesource.com/kernel/goldfish</pre>
    221 
    222 <p>The <code>hikey-linaro</code> project is used for HiKey reference boards, and can be used as a starting point for work on HiSilicon 620 chipsets.</p>
    223 <pre class="devsite-terminal devsite-click-to-copy">git clone https://android.googlesource.com/kernel/hikey-linaro</pre>
    224 
    225 <p>The <code>msm</code> project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6, Nexus 5X, Nexus 6P, Nexus 7 (2013), Pixel, and Pixel XL, and can be used as a starting point for work on Qualcomm MSM chipsets.</p>
    226 <pre class="devsite-terminal devsite-click-to-copy">git clone https://android.googlesource.com/kernel/msm</pre>
    227 
    228 <p>The <code>omap</code> project is used for PandaBoard and Galaxy Nexus, and can be used as a starting point for work on TI OMAP chipsets.</p>
    229 <pre class="devsite-terminal devsite-click-to-copy">git clone https://android.googlesource.com/kernel/omap</pre>
    230 
    231 <p>The <code>samsung</code> project is used for Nexus S, and can be used as a starting point for work on Samsung Hummingbird chipsets.</p>
    232 <pre class="devsite-terminal devsite-click-to-copy">git clone https://android.googlesource.com/kernel/samsung</pre>
    233 
    234 <p>The <code>tegra</code> project is for Xoom, Nexus 7 (2012), Nexus 9, and can be used as a starting point for work on NVIDIA Tegra chipsets.</p>
    235 <pre class="devsite-terminal devsite-click-to-copy">git clone https://android.googlesource.com/kernel/tegra</pre>
    236 
    237 <p>The <code>x86_64</code> project has the kernel sources for Nexus Player, and can be used as a starting point for work on Intel x86_64 chipsets.</p>
    238 <pre class="devsite-terminal devsite-click-to-copy">git clone https://android.googlesource.com/kernel/x86_64</pre>
    239 
    240 <h2 id="building">Building the kernel</h2>
    241 <p>When you know the last commit message for a kernel and have successfully
    242 downloaded the kernel source and prebuilt gcc, you are ready to build the
    243 kernel. The following build commands use the hikey kernel:</p>
    244 <pre class="devsite-click-to-copy">
    245 <code class="devsite-terminal">export ARCH=arm64</code>
    246 <code class="devsite-terminal">export CROSS_COMPILE=aarch64-linux-android-</code>
    247 <code class="devsite-terminal">cd hikey-linaro</code>
    248 <code class="devsite-terminal">git checkout -b android-hikey-linaro-4.1 origin/android-hikey-linaro-4.1</code>
    249 <code class="devsite-terminal">make hikey_defconfig</code>
    250 <code class="devsite-terminal">make</code>
    251 </pre>
    252 
    253 <p>To build a different kernel, simply replace <code>hikey-linaro</code> with
    254 the name of the kernel you want to build.</p>
    255 
    256 <p>The image outputs to the <code>arch/arm64/boot/Image</code> directory; the
    257 kernel binary outputs to the
    258 <code>arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb</code> fle. Copy the
    259 <code>Image</code> directory and the <code>hi6220-hikey.dtb</code> file to the
    260 <code>hikey-kernel</code> directory.</p>
    261 
    262 <p>Alternatively, you can include the <code>TARGET_PREBUILT_KERNEL</code>
    263 variable while using <code>make bootimage</code> (or any other <code>make</code>
    264 command line that builds a boot image). This variable is supported by all
    265 devices as it is set up via <code>device/common/populate-new-device.sh</code>.
    266 For example:</p>
    267 
    268 <pre class="devsite-terminal devsite-click-to-copy">
    269 export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage-dtb
    270 </pre>
    271 
    272 <p class="note"><strong>Note:</strong> Kernel names differ by device. To locate
    273 the correct filename for your kernel, refer to
    274 <code>device/<var>VENDOR</var>/<var>NAME</var></code> in the kernel source.</p>
    275 
    276   </body>
    277 </html>
    278