This is a cache of https://discuss.96boards.org/t/hikey960-aosp-kernel-build/4496. It is a snapshot of the page at 2024-09-20T08:09:54.922+0000.
Hikey960 AOSP kernel build - HiKey 960 - 96Boards Forum

Hikey960 AOSP kernel build

I’m new Hikey 960 user and do not know if this would work OK for me to build the newest AOSP and kernel from AOSP website:

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
make ARCH=arm64 hikey960_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -j24
cp arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dtb ./hi3660-hikey960.dtb-4.9
cp arch/arm64/boot/Image.gz-dtb ./Image.gz-dtb-hikey960-4.9
bootimage -j24

but make bootimage -j24 make me confused when it pop up to select many options

I find script but the para in build command below is still --os_version 7.0 --os_patch_level 2016-08-05, not sure if this need to modified to suit for the newest AOSP+Hikey kernel

./mkbootimg  --kernel Image.gz --ramdisk ${RAMDISK_IMG} --cmdline "loglevel=15 androidboot.hardware=hikey960 androidboot.selinux=permissive firmware_class.path=/system/etc/firmware" --base 0x0 --tags-addr 0x07A00000 --kernel_offset 0x00080000 --ramdisk_offset 0x07c00000 --os_version 7.0 --os_patch_level 2016-08-05  --output ${PRODUCT_OUT}/boot.img
./mkdtimg -d hi3660-hikey960.dtb -s 2048 -c -o ${PRODUCT_OUT}/dt.img

echo "dt.img boot.img build finished!"

Any advice on the AOSP kernel build ?

Have you executed below commands for android environment preparation?

. ./build/envsetup.sh
lunch hikey960-userdebug

@leo-yan thanks for your attention! Yes I run the command you attached , the build dir is like below. you mean the build command from rootdir should have build kernel and AOSP together?

    ~/code/AOSP$ tree -L 1
    .
    |-- android.bp -> build/soong/root.bp
    |-- art
    |-- bionic
    |-- bootable
    |-- bootstrap.bash -> build/soong/bootstrap.bash
    |-- build
    |-- compatibility
    |-- cts
    |-- dalvik
    |-- developers
    |-- development
    |-- device
    |-- external
    |-- frameworks
    |-- hardware
    |-- hikey-linaro <<<< put hikey linaro here
    |-- kernel
    |-- libcore
    |-- libnativehelper
    |-- Makefile
    |-- out
    |-- packages
    |-- pdk
    |-- platform_testing
    |-- prebuilts
    |-- sdk
    |-- sonar-project.properties
    |-- system
    |-- test
    |-- toolchain
    `-- tools

Yes, should execute command “make bootimage -j24” from AOSP root directory.

@leo-yan I followed your instruction, it get boot.img ramdisk.img in out/target/product/hikey960 no dt is generated

[100% 9216/9216] Target boot image: out/target/product/hikey960/boot.img

#### build completed successfully (04:48 (mm:ss)) ####

but when I moved hikey-linaro(kernel code) away from AOSP root, the boot.img ramdisk.img could generate again, that’s seem not trigger the kernel code I download to build.

We should expect dt.img is generated in the folder: $AOSP_ROOT/out/target/product/hikey960; could you check if hi3660-hikey960.dtb has been copied into the folder: $AOSP_ROOT/device/linaro/hikey-kernel/hi3660-hikey960.dtb-4.9?

I think so. :slight_smile:

From my understanding, the Linux kernel (Image/dtb) building and android building are individual, you need manually to copy hi3660-hikey960.dtb/Image into android folder $AOSP_ROOT/device/linaro/hikey-kernel and with command “make bootimage -j24” you should can see boot.img & dt.img in the folder $AOSP_ROOT/out/target/product/hikey960/.

Please note, ramdisk.img is generated by AOSP repository, it’s not derived from Linux kernel.

Yes I checked $AOSP_ROOT/device/linaro/hikey-kernel , seems AOSP already got this file in it(not auto copy from kernel src)

hi3660-hikey960.dtb-4.4  hi6220-hikey.dtb-3.18  hi6220-hikey.dtb-4.4  Image.gz-dtb-3.18  Image.gz-dtb-4.4  Image.gz-dtb-hikey960-4.4
hi3660-hikey960.dtb-4.9  hi6220-hikey.dtb-4.14  hi6220-hikey.dtb-4.9  Image.gz-dtb-4.14  Image.gz-dtb-4.9  Image.gz-dtb-hikey960-4.9

The boot.img generated from make bootimage -j24 is not from the code need build and copy by hand

So if i want to build kernel image using my own src, should follow steps:

  1. checkout hikey-linaro in $AOSP_ROOT
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
  1. build kernel in hikey-linaro with:
make ARCH=arm64 hikey960_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -j24
  1. copy new generated files to AOSP related path to update the default ones
cp $AOSP_ROOT/hikey-linaro/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dtb $AOSP_ROOT/device/linaro/hikey-kernel/hi3660-hikey960.dtb-4.9
cp $AOSP_ROOT/hikey-linaro/arch/arm64/boot/Image.gz-dtb $AOSP_ROOT/Image.gz-dtb-hikey960-4.9
  1. make a full AOSP build and generate kernel image
cd $AOSP_ROOT
source ./build/envsetup.sh
lunch hikey960-userdebug
make -j24
make bootimage -j24
  1. if no kernel code is modified , just run step4 to use the default kernel

Any instructions on switch kernel version e.g. using 4.14 kernel instead of 4.9?

I don’t know, might @jstultz @Loic @vchong can help for this.

The selected kernel is defined by TARGET_KERNEL_USE build variable:
cf:
device/linaro/hikey/hikey960.mk
device/linaro/hikey/hikey-common.mk

I assume you build kernel from origin/android-hikey-linaro-4.14 branch and change the TARGET_KERNEL_USE value to 4.14 in order use device/linaro/hikey-kernel/Image-dtb-4.14 and device/linaro/hikey-kernel/hi3660-hikey960.dtb-4.14. Now, I don’t know the compatibility status with AOSP userspace.

Loic is right here. The easiest way to build a different kernel version is to build with:

$ make TARGET_KERNEL_USE=4.14 -j

But also be aware, the 4.14 support for hikey960 is in-progress (I think the first kernel pre-built landed yesterday) and performance still needs work - which is why its not the default kernel yet.