Need help to build Android Kernel

Please describe your issue below:

Cannot build an Android Kernel.
I believe it’s related to cross compile tooling setup, but have no idea to fix it.

The host OS is Ubuntu 20.04 amd64.
And, one missing package is “gcc-4.8-aarch64-linux-gnu” which does not exist on Ubuntu 20.04.

Post a console log of your issue below:

$ cd bootloader/uboot
$ ./mk kvim4 --avb2 --vab 
(...)
output file are generated in build/ folder
Bootloader build done!

$ cd -
$ ./mk kvim4 -v 5.4 -j1
CONFIG_KERNEL_VERSION: 5.4
------device/khadas/kvim4/build.config.meson.arm64.trunk-----
KERNEL_DEVICETREE: kvim4
=====ab update & vendor boot mode=====
========================================================
= build config: kvim4/device/khadas/kvim4/build.config.meson.arm64.trunk
. common/build.config.common
. common/build.config.aarch64
. device/khadas/common/kernelbuild/build.config.common

DEFCONFIG=meson64_a64_defconfig
EXTRA_CMDS=''

#It is a must to set GPU driver's version
GPU_DRV_VERSION=r25p0

if [[ -n ${BOARD_COMPILE_HDMITX_ONLY} && \
         `echo "${BOARD_COMPILE_HDMITX_ONLY}" \
         |awk '{print length($0)}'` -eq 4 ]];then
echo "set kernel device tree to t7 hdmi only"
KERNEL_DEVICETREE=kvim4
else
KERNEL_DEVICETREE="kvim4"
fi
DTBO_DEVICETREE=android_overlay_dt
PRODUCT_DIRNAME=device/khadas/kvim4
BOARD_DEVICENAME=kvim4

ENABLE_KASAN=false

FILES=""

EXT_MODULES="
vendor/amlogic/common/wifi_bt/wifi/configs/5_4
vendor/amlogic/common/wifi_bt/bluetooth/configs/5_4
vendor/amlogic/common/gpu/bifrost
vendor/amlogic/common/tdk_linuxdriver
hardware/amlogic/media_modules
vendor/amlogic/common/arm_isp/linux_54_t7/kernel/subdev/iq
vendor/amlogic/common/arm_isp/linux_54_t7/kernel/subdev/lens
vendor/amlogic/common/arm_isp/linux_54_t7/kernel/subdev/sensor
vendor/amlogic/common/arm_isp/linux_54_t7/kernel/v4l2_dev
"

STOP_SHIP_TRACEPRINTK=1

PATH=kvim4/build/build-tools/path/linux-x86:kvim4/prebuilts/clang/host/linux-x86/clang-r383902/bin:/user/.local/bin:/user/bin:kvim4/prebuilts/jdk/jdk11/linux-x86/bin:kvim4/out/soong/host/linux-x86/bin:kvim4/out/host/linux-x86/bin:kvim4/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin:kvim4/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin:kvim4/development/scripts:kvim4/prebuilts/devtools/tools:kvim4/external/selinux/prebuilts/bin:kvim4/prebuilts/misc/linux-x86/dtc:kvim4/prebuilts/misc/linux-x86/libufdt:kvim4/prebuilts/clang/host/linux-x86/llvm-binutils-stable:kvim4/prebuilts/asuite/acloud/linux-x86:kvim4/prebuilts/asuite/aidegen/linux-x86:kvim4/prebuilts/asuite/atest/linux-x86:/user/.local/bin:/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

========================================================
 Setting up for build
+ '[' ']'
+ '[' '' == true ']'
+ '[' -n '' ']'
+ cp common/arch/arm64/configs/kvim4_a64_R_defconfig common/arch/arm64/configs/meson64_a64_gki_defconfig
+ '[' '!' -z '' ']'
+ '[' '' == user ']'
+ cd common
+ make CC=clang HOSTCC=clang LD=ld.lld NM=llvm-nm OBJCOPY=llvm-objcopy O=kvim4/out/android11-5.4/common meson64_a64_gki_defconfig
make[1]: Entering directory 'kvim4/out/android11-5.4/common'
  GEN     Makefile
arch/arm64/configs/meson64_a64_gki_defconfig:351:warning: override: reassigning to symbol PPP_DEFLATE
arch/arm64/configs/meson64_a64_gki_defconfig:352:warning: override: reassigning to symbol PPP_BSDCOMP
arch/arm64/configs/meson64_a64_gki_defconfig:562:warning: override: reassigning to symbol USB_SERIAL_OPTION
#
# No change to .config
#
make[1]: Leaving directory 'kvim4/out/android11-5.4/common'
+ rm -fr common/arch/arm64/configs/meson64_a64_gki_defconfig
+ set +x
========================================================
 Building kernel
+ find kvim4/out/android11-5.4/common/ -type f
+ grep '\.ko$'
+ xargs rm -fr
+ '[' ']'
+ cd kvim4/out/android11-5.4/common
+ make O=kvim4/out/android11-5.4/common CC=clang HOSTCC=clang LD=ld.lld NM=llvm-nm OBJCOPY=llvm-objcopy
arch/arm64/Makefile:52: Detected assembler with broken .inst; disassembly will be unreliable
  GEN     Makefile
  DTC     arch/arm64/boot/dts/amlogic/kvim4.dtb
grep: kvim4/common/.config: No such file or directory
  CC      scripts/mod/empty.o
/usr/bin/as: unrecognized option '-EL'
clang-11: error: assembler command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/user/projects/kvim4/common/scripts/Makefile.build:284: scripts/mod/empty.o] Error 1
make[1]: *** [/user/projects/kvim4/common/Makefile:1252: prepare0] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [/user/projects/kvim4/common/Makefile:179: sub-make] Error 2
build kernel error

My mistake. I was working on the wrong build environment. :wink:

Hi @windchaser. Im have same error Ubuntu bionic 18.04. Can you elaborate on that? How fix ‘-EL’ and gcc-4.8-aarch64-linux-gnu?
Fix me:

aptitude remove gcc-multilib g++-multilib
aptitude install gcc-aarch64-linux-gnu cpp-aarch64-linux-gnu
export PATH=$PATH:/opt/toolchains/gcc-linaro-7.3.1-2018.05-i686_aarch64-elf/bin
export PATH=$PATH:/opt/toolchains/xpack-riscv-none-embed-gcc-8.3.0-1.2/bin
./mk kvim4 -v 5.4

next error

ld.lld: error: undefined symbol: CRYPTO_STATIC_MUTEX_unlock_write
>>> referenced by bio.c:630 (external/boringssl/src/crypto/bio/bio.c:630)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/bio/bio.o:(BIO_get_new_index)
>>> referenced by err.c:358 (external/boringssl/src/crypto/err/err.c:358)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/err/err.o:(ERR_get_next_error_library)
>>> referenced by ex_data.c:164 (external/boringssl/src/crypto/ex_data.c:164)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/ex_data.o:(CRYPTO_get_ex_new_index)
>>> referenced by obj.c:539 (external/boringssl/src/crypto/obj/obj.c:539)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/obj/obj.o:(OBJ_create)
>>> referenced by obj.c:93 (external/boringssl/src/crypto/obj/obj.c:93)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/obj/obj.o:(obj_next_nid)
>>> referenced by rand.c:297 (external/boringssl/src/crypto/fipsmodule/rand/rand.c:297)
>>>               out/soong/.intermediates/external/boringssl/bcm_object/android_arm64_armv8-a_com.android.conscrypt/bcm_object.o:(RAND_bytes_with_additional_data)
>>> referenced by ec.c:546 (external/boringssl/src/crypto/fipsmodule/ec/ec.c:546)
>>>               out/soong/.intermediates/external/boringssl/bcm_object/android_arm64_armv8-a_com.android.conscrypt/bcm_object.o:(EC_GROUP_new_by_curve_name)
>>> referenced by rand.c:118 (external/boringssl/src/crypto/fipsmodule/rand/rand.c:118)
>>>               out/soong/.intermediates/external/boringssl/bcm_object/android_arm64_armv8-a_com.android.conscrypt/bcm_object.o:(rand_thread_state_free)
>>> referenced by urandom.c:368 (external/boringssl/src/crypto/fipsmodule/rand/urandom.c:368)
>>>               out/soong/.intermediates/external/boringssl/bcm_object/android_arm64_armv8-a_com.android.conscrypt/bcm_object.o:(RAND_set_urandom_fd)

ld.lld: error: undefined symbol: ChaCha20_ctr32
>>> referenced by chacha.c:97 (external/boringssl/src/crypto/chacha/chacha.c:97)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/chacha/chacha.o:(CRYPTO_chacha_20)

ld.lld: error: undefined symbol: CRYPTO_poly1305_init
>>> referenced by e_chacha20poly1305.c:169 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:169)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)

ld.lld: error: undefined symbol: CRYPTO_poly1305_update
>>> referenced by e_chacha20poly1305.c:170 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:170)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)
>>> referenced by e_chacha20poly1305.c:172 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:172)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)
>>> referenced by e_chacha20poly1305.c:174 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:174)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)
>>> referenced by e_chacha20poly1305.c:175 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:175)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)
>>> referenced by e_chacha20poly1305.c:178 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:178)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)
>>> referenced by e_chacha20poly1305.c:153 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:153)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)
>>> referenced by e_chacha20poly1305.c:153 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:153)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)

ld.lld: error: undefined symbol: CRYPTO_poly1305_finish
>>> referenced by e_chacha20poly1305.c:183 (external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c:183)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.o:(calc_tag)

ld.lld: error: undefined symbol: RC4_set_key
>>> referenced by e_rc4.c:69 (external/boringssl/src/crypto/cipher_extra/e_rc4.c:69)
>>>               out/soong/.intermediates/external/boringssl/libcrypto/android_arm64_armv8-a_shared_com.android.conscrypt/obj/external/boringssl/src/crypto/cipher_extra/e_rc4.o:(rc4_init_key)

ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
18:34:50 ninja failed with: exit status 1

#### failed to build some targets (58 seconds) ####