How to customize kernel for Android

Revision as of 08:22, 21 August 2019 by Registered User

This page explains how to change the kernel configuration and device tree. It is intended for Distribution Package users.

1. Prerequisites[edit source]

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:

 source build/envsetup.sh
 bspsetup
 lunch aosp-<BoardId>-userdebug

Info white.png Information
The bspsetup command needs to be run only one time for the distribution

2. Updating the kernel configuration[edit source]

Info white.png Information

The kernel configuration file used is merged between the following files (this operation is performed at the beginning of the kernel build process):

  • The Android configuration files named android-base.config and android-recommended.config files available in the device/stm/<STM32Series>-kernel/source/kconfig/<kernel version>/ directory.
  • The android-soc.config file available in the device/stm/<STM32Series>-kernel/source/kconfig/<kernel version>/ directory.

By using menuconfig, you can update the configuration file for your needs. Some guidelines are given below.

2.1. Saving the current configuration[edit source]

Before making any changes to the kernel configuration, it is advised to save your current configuration in a defconfig.default file which is in the same format as used by the Linux kernel defconfig files:

 build_kernel defaultconfig

A default config file named defconfig.default is generated in out-bsp/<STM32Series>/KERNEL_OBJ/ directory which can the be copied to a safe location.

2.2. Creating a new kernel configuration[edit source]

Start menuconfig:

 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/.

2.3. Test new kernel configuration[edit source]

When change have been apply the command build_kernel will automaticaly merge the defaultconfig.config and the one above.

To test your configuration you need to rebuild the kernel, then update the prebuilds and flash it, like explain in more details in How to build kernel for Android:

build_kernel -i

make -j

2.4. Applying the newly generated kernel configuration[edit source]

To make your change permanente you need to compare the defconfig.default file with the one create above. You can you a graphical tool like meld.

 meld out-bsp/<STM32Series>/KERNEL_OBJ/myNewConfig.config out-bsp/<STM32Series>/KERNEL_OBJ/defconfig.default

Then report the changes to the android-soc.config file located in device/stm/<STM32Series>-kernel/source/kconfig/<kernel version>/.

And rebuild the kernel How to build kernel for Android.

3. Changing the kernel command line[edit source]

You can customize the kernel command line call at boot time. Arguments are defined in the BoardConfig.mk file located in device/stm/<STM32Series>/<BoardId>/.

Change the value of the BOARD_KERNEL_CMDLINE variable to your needs.

To Apply changes, you need to rebuild the bootimage:

make bootimage-nodeps

And flash your boot partition.

Info white.png Information
To control the command line after compilation you can execute:

./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[edit source]

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 see Device tree.

This file is located inside the Linux kernel source code previously loaded and can be modified directly in device/stm/<STM32Series>-kernel/linux-<STM32Series>/arch/arm/boot/dts.

After modification you need to rebuild the device tree by:

build_kernel -i dtb

make -j

And then flash the DT partition.