This is a cache of https://discuss.96boards.org/t/hikey960-linaro-kernel-compile-from-source-issue/5957. It is a snapshot of the page at 2024-10-31T09:26:44.841+0000.
HiKey960 linaro kernel - compile from source issue - HiKey 960 - 96Boards Forum

HiKey960 linaro kernel - compile from source issue

Hello,

I’m trying to build kernel from source following guide here:
https://source.android.com/setup/build/devices#hikey960

git clone https://android.googlesource.com/kernel/hikey-linaro
cd hikey-linaro
git checkout -b android-hikey-linaro-4.9 origin/android-hikey-linaro-4.9

Kernel sources are downloaded and compiled outside AOSP tree.

AOSP was already build and boots on my board (Hikey960 rev. B with, Hynix flash).
So I just copy two files as guide says (replacing existing prebuild ones) and make boot.img from AOSP tree.
After flashing all images (including new boot.img) board do not boot (kernel crashes).

I was expecting that kernel image that I get by compiling from sources ( arch/arm64/boot/Image.gz-dtb) will be the same as the prebuild one from AOSP (/device/linaro/hikey-kernel/Image.gz-dtb-hikey960-4.9).

Unfortunately my Image.gz-dtb differs from the prebuild one Image.gz-dtb-hikey960-4.9.
hi3660-hikey960.dtb is the same as hi3660-hikey960.dtb-4.9

Prebuild images are taken from AOSP master
repo init -u https://android.googlesource.com/platform/manifest -b master

What am I doing wrong?
Or how to get kernel sources which will allow me to build the same Kernel image as the prebuild one ?

Could you share the booting log?

One possibility for kernel booting failure is caused by you have not used correct kernel config file, could you confirm you are using hikey960_defconfig as kernel config?

Please aware for building one exactly same boot image, except the kernel code base, you also need to ensure you are using the toolchain which is the same one with prebuilt boot image.

Yes, I’m using using hikey960_defconfig

make ARCH=arm64 hikey960_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -j4

I know I won’t get binary equal Image with prebuild one, but the size difference is several kilobytes and my boot.img crashes.

About the toolchain what exactly can I verify here? I use the same which I successfully compile AOSP.

BTW this I get for my kernel sources:
/proj/hikey-linaro$ git describe --tags
hikey-4.9-android-8.0.0_r4-9042-gbbab5cb8a5bd

Collecting boot logs will take a bit longer than I thought …

This is a bit complex now, from the prebuilt kernel dmesg, I can know it uses clang:

[    0.000000] Linux version 4.9.124-g96a73cde6d81 (android-build@wprf9.hot.corp.google.com) (Android (4679922 based on r326829) clang version 7.0.1 (https://android.googlesource.com/toolchain/clang 32fb8450f65708b63c9a35046b2d
1ee775e08733) (https://android.googlesource.com/toolchain/llvm 67f3e6a51d93777841e0fb6d07f71fdf343df239) (based on LLVM 7.0.1svn)) #1 SMP PREEMPT Fri Aug 31 17:51:27 UTC 2018

At my side, I am using gcc: aarch64-linux-gnu-gcc (Linaro gcc 6.2-2016.11) 6.2.1 20161016; I can confirm it can work well both for 4.9 kernel and 4.14 kernel.

Yeah, checking the commit id is a good start point: in my code base, it has the same latest commit id bbab5cb8a5bd with yours.

Yes, please. After get log we might can dig a bit for it :slight_smile:

I verified at my side I can boot up system with latest 4.9 kernel, but I am using abootimg method for building boot.img, this is not an offical method in Google page but it’s more simple for myself due I don’t need to build the whole Android repository and only need one ramdisk.img [1]:

[1] http://snapshots.linaro.org/96boards/hikey960/linaro/aosp-master/629/ramdisk.img

#!/bin/sh

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-

BOOT=arch/arm64/boot
DTB=hi3660-hikey960.dtb

make hikey960_defconfig
make Image dtbs -j8 

RAMDISK=/home/leoy/work3/hikey960/download/aosp_latest_snapshot/ramdisk.img
cat $BOOT/Image $BOOT/dts/hisilicon/$DTB > $BOOT/Image-dtb
abootimg --create $BOOT/boot.img -k $BOOT/Image-dtb -r $RAMDISK -f bootimg-960.cfg

bootimg-960.cfg

bootsize = 0x2800000
pagesize = 0x800
kerneladdr = 0x80000
ramdiskaddr = 0x7c00000
secondaddr = 0xf00000
tagsaddr = 0x7a00000
name = 
cmdline = androidboot.hardware=hikey960 console=ttyFIQ0 androidboot.console=ttyFIQ0 firmware_class.path=/vendor/firmware loglevel=15 efi=noruntime overlay_mgr.overlay_dt_entry=hardware_cfg_enable_android_fstab buildvariant=userdebug console=ttyAMA6 androidboot.serialno=20AA934201847B0D initrd=0x7C00000,0x9F100

Trying to collect boot logs I have repeated whole steps to build kernel and boot image. Then I flashed all images and this time system booted correctly. Unless I mixed boot images, problem seems to be solved. But I will have to double check it. I have unconnected mouse and keyboard during latest boot, but I doubt this could have impact.
Thanks for the hints and alternative way of preparing boot.img. I have to try it also.

@Pawel : on the topic we were discussing before, I’ve been bringing up automotive to the september 11 manifest (including kernel). Its a little rough around the edges still, but you can take a peek;

I’d recommend that you keep hold of your 8.1 tree for the time being, and additionally add the 9.0 so that you can easily switch between the two.

@doitright: Yes, I already spoted your post and keep tracking progress. For sure will try it, thanks.
Great that you are pushing this project forward.:+1: