Last edited 3 weeks ago

How to customize Linux kernel for Android

Applicable for STM32MP25x lines

Warning DB.png Important
OpenSTDroid is validated against the ecosystem release v5.1.0 . It has not been ported yet on ecosystem release v6.0.0 More info.png .

1. Prerequisites[edit | edit source]

The environment must be installed using the Distribution Package adapted to your microprocessor device.

Get the kernel sources as explained in How to build kernel for Android.

To execute the following instructions, go to your distribution root directory and initialize your environment as follows:

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

2. Updating the kernel configuration[edit | 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 Generic Kernel Image configuration file named gki_defconfig available in the linux source.
  • The <STM32Series>_soc.config and the <STM32Series>_board.config files available in the device/stm/<STM32Series>-kernel/source/kconfig/<kernel version>/ directory.

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

2.1. Saving the current configuration[edit | edit source]

Before changing the kernel configuration, it is recommended to build the kernel using the current configuration:

build_kernel

A default config file named defconfig.default is generated in out-bsp/<STM32Series>/KERNEL_OBJ/ directory.

2.2. Creating a new kernel configuration[edit | edit source]

Start menuconfig:

build_kernel menuconfig

You can load a .config file and modify any entry using this interface. Instructions on how to navigate are provided at the top of the windows.

Do not forget to click save.

This generates a .config file located in out-bsp/<STM32Series>/KERNEL_OBJ/, as well as a defconfig file at the same location.

2.3. Testing the new kernel configuration[edit | edit source]

To test the new configuration, rebuild the kernel, update the prebuilts and flash, as explained in How to build kernel for Android.

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

To make your change permanent, first compare the new defconfig file with the defconfig.default file generated at first build.

You can use a graphical tool such as meld.

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


Then report the changes into the <STM32Series>_soc.config or into the <STM32Series>_board.config file located in device/stm/<STM32Series>-kernel/source/kconfig/<kernel version>/.

Eventually force the regeneration of the .config:

build_kernel defaultconfig

Note: the defconfig.default is then updated.

To test your configuration, rebuild the kernel and update the prebuilts and flash, as explain in How to build kernel for Android.

3. Changing the kernel command line[edit | edit source]

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

Adapt the value of the BOARD_KERNEL_CMDLINE variable to your needs.

Rebuild the bootimage to apply the changes:

make bootimage-nodeps

Then flash the boot partition:

Info white.png Information
To control the command line after compilation you can execute:
./system/tools/mkbootimg/unpack_bootimg.py --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 | edit source]

The kernel device tree is split with:

  • A component device tree installed in the vendor_boot partition. The directives to generate this partition are in the BoardConfig.mk file vendor_boot.img section) available under the device/stm/<STM32Series>/<BoardId>/ directory.
  • A product device tree overlay installed in the dtbo partition. The directives to generate this partition are in the dt.mk file available under the device/stm/<STM32Series>/build/tasks/ directory.

For more information refer to the Device tree and How to create your board device tree pages.

The device trees are located inside the Linux® kernel source code previously loaded. A Device Tree can be modified directly in device/stm/<STM32Series>-kernel/linux-<STM32Series>/arch/arm64/boot/dts/st/.

Once the Device Tree has been modified, rebuild it:

build_kernel -i dtb

make -j

Then flash again dtbo and vendor_bootpartitions.