Android kernel 5.15/6.1 for emulator

189 Views Asked by At

I'm struggling with making the Linux kernel for the android emulator. I'm working on Android 14/kernel 6.1 now, but the same issues occur with Android 13/kernel 5.15. My aim is to add few kernel modules.

So I'd like to replace the kernel.

I download and build it like that:

repo init -u https://android.googlesource.com/kernel/manifest -b common-android14-6.1 && repo sync
tools/bazel build //common:kernel_x86_64_dist && tools/bazel run //common:kernel_x86_64_dist -- --dist_dir=out_dist
tools/bazel build //common-modules/virtual-device:virtual_device_x86_64_dist

Then I've tried two ways to use the kernel.

  1. Run the emulator with the custom kernel
emulator -avd XXX -kernel kernel-source/out_dist/bzImage
  1. Build the system with the custom kernel

    a) set KERNEL_ARTIFACTS_PATH := kernel-custom/out_dist, VIRTUAL_DEVICE_KERNEL_MODULES_PATH := kernel-custom/bazel-bin/common-modules/virtual-device/virtual_device_x86_64, and EMULATOR_KERNEL_FILE := $(KERNEL_ARTIFACTS_PATH)/bzImage in AOSP_source/device/generic/goldfish/x86_64-kernel.mk

    b) build the system with m && m emu_zip_img and start it as usual (from CLI or Android Studio)

In both ways the emulator doesn't start.

With "not working" kernel, the emulator starts enough to use adb to extract /proc/config.gz, so I've compared "working" and "not working" kernel configurations and found 48 differences - seems to be enough to break the emulator.

The next step was to configure the kernel in the same way as the original, working one. The first try was to find problematic configurations and to change it, eg. in common/arch/x86/configs/gki_defconfig file.

It doesn't work - I can't build such a kernel.

The second try was to create a new config. I've created a new file kernel/configs/u/android-6.1/android-emulator.config file with all 48 changes and made a config with

ARCH=x86_64 scripts/kconfig/merge_config.sh arch/x86/configs/gki_defconfig ../kernel/configs/u/android-6.1/android-base.config ../kernel/configs/u/android-6.1/android-emulator.config kernel/configs/android-recommended.config

The created .config file is same as the extracted, working configuration but I still can't build such a kernel.

I've removed my 48 changes and tried again with no luck.

ARCH=x86_64 scripts/kconfig/merge_config.sh arch/x86/configs/gki_defconfig ../kernel/configs/u/android-6.1/android-base.config kernel/configs/android-recommended.config 

The building issue is the same each time. As you can see, I can't make the kernel nor the modules.

$ tools/bazel build //common-modules/virtual-device:virtual_device_x86_64_dist
INFO: Analyzed target //common-modules/virtual-device:virtual_device_x86_64_dist (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/user/android/android-kernel/common/BUILD.bazel:124:22: Building kernel (lto=default;notrim) @//common:kernel_x86_64 failed: (Exit 2): bash failed: error executing KernelBuild command (from target //common:kernel_x86_64) /bin/bash -c ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
***
*** The source tree is not clean, please run 'make mrproper'
*** in /home/user/android/android-kernel/out/bazel/output_user_root/d081e55683ee5a4e5c4919613c21ecf2/sandbox/linux-sandbox/88/execroot/__main__/common
***
make[2]: *** [/home/user/android/android-kernel/out/bazel/output_user_root/d081e55683ee5a4e5c4919613c21ecf2/sandbox/linux-sandbox/88/execroot/__main__/common/Makefile:676: outputmakefile] Error 1
make[1]: *** [/home/user/android/android-kernel/out/bazel/output_user_root/d081e55683ee5a4e5c4919613c21ecf2/sandbox/linux-sandbox/88/execroot/__main__/common/Makefile:825: include/config/auto.conf.cmd] Error 2
make[1]: *** [include/config/auto.conf.cmd] Deleting file 'include/generated/rustc_cfg'
make[1]: *** [include/config/auto.conf.cmd] Deleting file 'include/generated/autoconf.h'
make: *** [Makefile:256: __sub-make] Error 2
Target //common-modules/virtual-device:virtual_device_x86_64_dist failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/user/android/android-kernel/common-modules/virtual-device/BUILD.bazel:353:14 Middleman _middlemen/common-modules_Svirtual-device_Svirtual_Udevice_Ux86_U64_Udist-runfiles failed: (Exit 2): bash failed: error executing KernelBuild command (from target //common:kernel_x86_64) /bin/bash -c ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
INFO: Elapsed time: 22.335s, Critical Path: 21.82s
INFO: 4 processes: 4 internal.
ERROR: Build did NOT complete successfully



$ tools/bazel build //common:kernel_x86_64_dist
INFO: Analyzed target //common:kernel_x86_64_dist (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/user/android/android-kernel/common/BUILD.bazel:124:22: Preparing for module build (lto=default;notrim) @//common:kernel_x86_64_modules_prepare failed: (Exit 2): bash failed: error executing ModulesPrepare command (from target //common:kernel_x86_64_modules_prepare) /bin/bash -c ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
***
*** The source tree is not clean, please run 'make mrproper'
*** in /home/user/android/android-kernel/out/bazel/output_user_root/d081e55683ee5a4e5c4919613c21ecf2/sandbox/linux-sandbox/90/execroot/__main__/common
***
make[2]: *** [/home/user/android/android-kernel/out/bazel/output_user_root/d081e55683ee5a4e5c4919613c21ecf2/sandbox/linux-sandbox/90/execroot/__main__/common/Makefile:676: outputmakefile] Error 1
make[1]: *** [/home/user/android/android-kernel/out/bazel/output_user_root/d081e55683ee5a4e5c4919613c21ecf2/sandbox/linux-sandbox/90/execroot/__main__/common/Makefile:825: include/config/auto.conf.cmd] Error 2
make[1]: *** [include/config/auto.conf.cmd] Deleting file 'include/generated/rustc_cfg'
make[1]: *** [include/config/auto.conf.cmd] Deleting file 'include/generated/autoconf.h'
make: *** [Makefile:256: __sub-make] Error 2
Target //common:kernel_x86_64_dist failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/user/android/android-kernel/common/BUILD.bazel:124:22 Middleman _middlemen/common_Skernel_Ux86_U64_Udist-runfiles failed: (Exit 2): bash failed: error executing ModulesPrepare command (from target //common:kernel_x86_64_modules_prepare) /bin/bash -c ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
INFO: Elapsed time: 8.328s, Critical Path: 7.73s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully

Please help, I don't know, what I'm doing wrong.

How should I customize the kernel 6.1 for Android 14 for emulator?

0

There are 0 best solutions below