Today I am going to shade some light on Android kernel and module building.
In my previous 3 post I have given details on
- AIDL for HIDL : The new paradigm shift in Android HAL
- Practical example of AIDLs for HIDLs
- Implement the User App to call Kernel API
Step 1 Download Android kernel
Why we need to download Android Kernel separately ?
The AOSP contains only pre-built kernel binaries. When AOSP system image is build, it copies the prebuilt kernel image to the output folder. Hence we need to download and build it with our changes.
you can use android official page to download kernel as per your choice.
I have downloaded following Android kernel .
Android Common Kernel ---- common-android13-5.15I have downloaded it because I am using Android 13 for my previous 3 blogs .
Note :- Different Android kernel version configured build differently
Android Common Kernels is used to run on Emulator. For real hardware devices, SoC companies (MTK, Qualcomm) will provide their customized kernel and build instruction.
Android 11 introduced GKI, which separates the kernel into a Google-maintained kernel image and vendor maintained-modules, which are built separately.
List of few Android kernel branch for Emulator
Android 11
- common-android11-5.4
- common-android12-5.4
- common-android12-5.10
- common-android13-5.10
- common-android13-5.15
Legacy dessert kernels were created to guarantee that new feature development didn’t interfere with merging from the Android Common Kernel
Android 10
- android-4.9-q
- android-4.14-q
- android-4.19-q
- android-4.14-stable
- android-4.19-stable
Building
Install libs for building kernelA common kernels are generic, customizable kernels and therefore don’t define a default configuration.sudo apt install libssl-dev libelf-dev
We have to set some environment settings:
Environment variable | Description | Example |
---|---|---|
BUILD_CONFIG | Build config file from where you initialize the build environment. The location must be defined relative to the Repo root directory. Defaults to build.config. Mandatory for common kernels. | BUILD_CONFIG=common/build.config.<target>.x86_64 |
CC | Override compiler to be used. Falls back to the default compiler defined by build.config. | CC=clang |
DIST_DIR | Base output directory for the kernel distribution. | DIST_DIR=/path/to/my/dist |
OUT_DIR | Base output directory for the kernel build. | OUT_DIR=/path/to/my/out |
SKIP_DEFCONFIG | Skip make defconfig | SKIP_DEFCONFIG=1 |
SKIP_MRPROPER | Skip make mrproper | SKIP_MRPROPER=1 |
Build Config for Android common kernel
I am going to build common-android13-5.15 hence using below configuration
BUILD_CONFIG=common-modules/virtual-device/build.config.cuttlefish.x86_64
build/build.shThen run below command for Emulator
BUILD_CONFIG=common-modules/virtual-device/build.config.virtual_device.x86_64build/build.sh
After build complete, check the kernel file
/home/saurabh/kernel-common-android13-5.15/out/android13-5.15/dist/bzImageIf you run file command for this bzImages yoy will get below output
Fast re-build
By default, Kernel is always built with mrproper target which removes all generated files + config + various backup files to create a clean build.
When developing on one or a few modules, we can skip the some initial steps and start re-build immediately:
BUILD_CONFIG=common-modules/virtual-device/build.config.virtual_device.x86_64LTO=noneFAST_BUILD=1SKIP_MRPROPER=1SKIP_DEFCONFIG=1build/build.sh
Step 3 Include custom kernel in AOSP Build System
Edit the kernel make file that generally lies in your device folder. For Emulator path isdevice/generic/goldfish/x86_64-kernel.mk
After modifying the Kernel make file , you need to rebuild AOSP completely to get Kernel image replaced.
make -j8
After successful build Run the emulator with below Command
emulator -verbose -show-kernel -selinux permissive -writable-system
Best live line in india
ReplyDeleteCan you make an example for android 14 ? trying to do it but failing bad.
ReplyDeleteHappy with your example
ReplyDeleteplease visit my site for more info:Best android app development
Thank you for information. Honey Web Solutions, is the first and foremost Best Online Marketing and Website designing and web development Company based out of Tirupati, India to be qualified and certified as Google Partner Company. Honey Web Solutions is one of The Best Web Designing Company in Tirupati , Digital Marketing Company Tirupati. We offer Advanced Digital Marketing and Web Designing Services., is the first and foremost Best Online Marketing and Website designing and web development Company based out of Tirupati, India to be qualified and certified as Google Partner Company. Honey Web Solutions is one of The Best Web Designing Company in Tirupati , Digital Marketing Company Tirupati. We offer Advanced Digital Marketing and Web Designing Services.
ReplyDeleteThis blog provides a comprehensive guide on building a custom kernel module for Android, offering step-by-step instructions and insights into the process. Great resource for developers diving into kernel-level development for Android devices!
ReplyDeleteSoftware Development Sydney
Nice blog .Thanks for sharing
ReplyDeletepython full stack