Author: Sam Protsenko <semen.protsenko at linaro dot org>

Date of last update: 03 Dec 2019

Building Android kernels with clang

This article describes building TI Android kernels with clang.

I only tested that on omap/kernel, which is:

For details on BeagleBoard-X15 build see next links:

Building with clang (64-bit, AM65x)

Google recommends/requires to build all the software with clang (rather than GCC) toolchains. If you want to go with clang for kernel build, use next instructions. Alas, for now we can only build 64-bit kernels with Android-based clang. See below for 32-bit clang build info. This section discusses the build for AM65x (AArch64).


Platform: AM65x EVM (64-bit) Android: TI Android Pie Kernel: TI kernel-4.19

Obtain toolchains

We don't have required clang toolchain version in Android-P, so let's obtain it first from AOSP master (along with GCC-4.9 toolchain):

    $ cd /opt
    $ sudo git clone --depth=1
    $ sudo git clone --depth=1

Configure and build

Configure kernel (don't configure clang environment just yet):

    $ make -j4 ARCH=arm64 distclean
    $ ./ti_config_fragments/ -t ti_sdk_arm64_android_release
    $ make ARCH=arm64 ti_sdk_arm64_android_release_defconfig

Configure the shell environment:

    $ export PATH=/opt/aarch64-gcc-4.9/bin:$PATH
    $ export PATH=/opt/clang-linux-x86/clang-r349610/bin:$PATH
    $ export CLANG_TRIPLE=aarch64-linux-gnu-
    $ export CROSS_COMPILE=aarch64-linux-android-
    $ export ARCH=arm64

Build kernel:

    $ make -j4 CC=clang HOSTCC=clang Image dtbs modules

Building with clang (32-bit, AM57x)

Linux kernel should be build-able for ARM32 now.

Command to build 32-bit kernel with clang:

    $ ./jenkins-scripts/ --distro bionic -- ./jenkins-scripts/ %% artifacts/jenkins/ --BUILD_URL '==rr[ci_config]' llvm-release-arm-mainline-defconfig '==rr[llvm_url]' '==rr[binutils_url]' no_binutils_url '==rr[gcc_url]' no_gcc_url '==rr[linux_url]' '==rr[llvm_branch]' 0399d5a9682b3cef71c653373e38890c63c4c365 '==rr[linux_branch]' f41def397161053eb0d3ed6861ef65985efbf293

It was taken from:

CI results are here:

(we are interested in linaro-local/ci/tcwg_kernel/llvm-release-arm-mainline-defconfig, etc).

Maxim Kuvyrkov (who works on Linaro toolchains, both GCC and LLVM) sent me those links, so you can ask him for more details.

LMG/Kernel/clang (last modified 2019-12-03 17:25:07)