How to customize kernel for Android
This page explains how to change the kernel configuration and device tree. It is intended for Distribution Package users.
The environment must be installed using the Distribution Package adapted to your selected microprocessor device. See the list of Android Distribution Package.
You must get kernel sources as explained in How to build kernel for Android.
To be able to execute following instructions you need to work from your distribution root directory and initialise your environment:
PC $> source build/envsetup.sh PC $> bspsetup PC $> lunch aosp-<BoardId>-userdebug
2 Updating the kernel configuration
menuconfig, you can update the configuration file for your needs. Some guidelines are given below.
2.1 Save the current configuration
Before making any changes to the kernel configuration, it is advised to build the kernel with the current configuration:
PC $> build_kernel
A default config file named
defconfig.default is generated in
2.2 Create a new kernel configuration
PC $> build_kernel menuconfig
You can load a
.config file and modify any entry using this interface. Please read on the top of the windows the instructions to navigate.
Do not forget to hit save.
This will generate a
.config file located in
out-bsp/<STM32Series>/KERNEL_OBJ/, and will also generate a
defconfig file in the same place.
2.3 Test new kernel configuration
To test your new configuration you need to rebuild the kernel, then update the prebuilts and flash, like explain in more details in How to build kernel for Android.
2.4 Applying the newly generated kernel configuration
To make your change permanent, you need first to compare the new
defconfig file with the
defconfig.default file generated at first build.
You can use a graphical tool like
PC $> meld out-bsp/<STM32Series>/KERNEL_OBJ/defconfig out-bsp/<STM32Series>/KERNEL_OBJ/defconfig.default
Then report the changes to the
android-soc.config file located in
And force the regeneration of the .config:
PC $> build_kernel defaultconfig
defconfig.default is then updated.
To test your configuration you need to rebuild the kernel, then update the prebuilts and flash, like explain in more details in How to build kernel for Android.
3 Changing the kernel command line
You can customize the kernel command line call at boot time.
Arguments are defined in the
BoardConfig.mk file located in
Change the value of the BOARD_KERNEL_CMDLINE variable to your needs.
To apply changes, you need to rebuild the bootimage:
PC $> make bootimage-nodeps
And then flash the boot partition.
|To control the command line after compilation you can execute:
PC $> ./system/core/mkbootimg/unpack_bootimg --boot_img out/target/product/<BoardId>/boot.img
Check the "command line args" value from the output, it must match your changes.
4 Changing the Device Tree
The kernel device tree used is set in the
dt.mk file available in the
device/stm/<STM32Series>/build/tasks/ directory. For more information please refer to the Device tree and How to create your board device tree pages.
This device trees are located inside the Linux kernel source code previously loaded and can be modified directly in
After modification you need to rebuild the device tree by:
PC $> build_kernel -i dtb PC $> make -j
And then re-flash the DT partition.