Cuttlefish supports the following kernel manifests on aosp-main repo, branches: common-android14-6.1, common-android14-5.15, common-android-mainline
Define macros:
Initialize the repo:
Download source code:
Cuttlefish Device has its kernel build named virtual_device_x86_64 which is based on kernel_x86_64:
Build Virtual Device Kernel and Modules:
All modules will be included in InitRamFS.
Check the Kernel image:
Run with new Kernel
Cuttlefish Device
It is easy to tell Cuttlefish to use new kernel and initramfs (included all virtual kernel modules):
Android Virtual Device
This needs to be rebuilt to run with new kernel:
then run emulator as usual.
Compilation may fail due to a missing kernel module, remove it from makefile and build again.
Kernel Modules
Modules are pieces of code that can be loaded and unloaded into the kernel upon demand.
HAL implementations are packaged into modules and loaded by the Android system at the appropriate time.
A kernel module can be a device driver that handles or manages a hardware
As part of the module kernel requirements introduced in Android 8.0, all system-on-chip (SoC) kernels must support loadable kernel modules.
To support loadable kernel modules, android-base.cfg in all common kernels includes the following kernel-config options:
All device kernels must enable these options.
Kernel modules should also support unloading and reloading whenever possible.
From Android 11, Vendor Modules are recommended to built separately.
One part of Kleaf is the Driver Development Kit (DDK) which is used to build external modules.
Here is a simple vendor module structure:
Directorycommon-android14-6.1
Directoryvendor
Directorytrongvq # vendor name
BUILD.bazel # build file
Directoryhello_world # vendor module
hello_world.c
Build a Module
Create a folder for vendor packages:
Create a folder for venfor module and its source code:
Create a ddk_module so system will know that there is a module there,
this module is built for kernel named virtual_device_x86_64:
Compile the vendor module:
Load and test module on device:
Integrate Module to Kernel
Create a kernel_module_group and make it visible as a package __pkg__
for the target kernel build //common-modules/virtual-device:
In the target kernel build, make kernel_build visible for vendor packages,
and under a kernel_modules_install where it lists kernel modules,
add the vendor kernel_module_group into the list:
Compile the target kernel again:
Now, the vendor module should be copied into out/virtual_device_x86_64/dist/hello_world.ko
Load Cuttlefish again:
Check that vendor module is loaded automatically:
Note that module is loaded in InitRamFS, there is no init message printed in dmesg.
Check that vendor module is included in filesystem:
Some notes here:
the kerner target //common:kernel_x86_64 is a base build,
the target kernel //common-modules/virtual-device:virtual_device_x86_64 is defined with addition modules
if the vendor kernel is build for //common:kernel_x86_64, the need changes
in the build for /common/BUILD.bazel in the section which defines kernel_x86_64,
but it needs more work.