How to customize kernel for Android

Revision as of 17:34, 6 August 2019 by Registered User

1. Article purpose[edit source]

This article is intended for Distribution Package users (see Which Package better suits your needs for more information).

This page explains how to change the kernel configuration.

2. Prerequisites[edit source]

The environment must be installed using the Distribution Package adapted to your selected microprocessor device, STM32MP1 Distribution Package for Android. 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 ST AOSP root directory STM32MP1 Distribution Package for Android, initialise your environment and then run lunch:

source build/envsetup.sh lunch aosp-eval-userdebug

3. Updating the kernel configuration[edit source]

Info white.png Information

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

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

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

3.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 <aosp>/out-bsp/stm32mp1/KERNEL_OBJ/ directory which can the be copied to a safe location.

3.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 <aosp>out-bsp/stm32mp1/KERNEL_OBJ/.

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

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

 meld out-bsp/stm32mp1/KERNEL_OBJ/myNewConfig.config out-bsp/stm32mp1/KERNEL_OBJ/defconfig.default

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

3.4. Rebuilding the kernel[edit source]

After having made the changes to android-soc.config, you can rebuild the kernel by invoking the command below. For more details, refer to How to build kernel for Android.

 build_kernel

4. Changing the default 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 <aosp>/device/stm/stm32mp1/<Board>/.

Change the value of the BOARD_KERNEL_CMDLINE variable to your needs.

5. Changing the Device Tree[edit source]

The kernel device tree (DTB0 or DTB1) used is set in the dt.mk file available in the <aosp>/device/stm/stm32mp1/build/tasks/ directory.

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