How to build kernel for Android

This article explains how to build the Android® kernel binaries (including the kernel image, the modules and the device trees) for a selected STM32 device. It is intended for Distribution Package users.

The AndroidTM Linux® Common kernel is used in the distribution package.

1 Prerequisites[edit]

The environment must be installed using the Distribution Package adapted to the selected microprocessor device. See the list of AndroidTM Distribution Package.

To be able to execute the following instructions work from the distribution root directory and initialize the environment:

PC $> source build/
PC $> bspsetup
PC $> lunch aosp_<BoardId>-userdebug

Info.png The bspsetup instruction only needs to be run once for the each distribution

The distribution includes prebuilt kernel binaries used to generate the partition images (boot, dt and vendor). These binaries are available in the device/stm/<STM32Series>-kernel/prebuilt directory.

2 Partition layout[edit]

The Linux® kernel binary is part of the boot partition.

The Linux® kernel drivers built as loadable modules (.ko files) are part of the vendor partition.

The device tree binary file is part of the dt partition.

For information on the complete partition layout for the selected development platform, refer to the corresponding Flash mapping article named Your_development_platform Flash mapping for Android. Example: STM32MP15 Flash mapping for Android for the STM32MP15 boards.

All Flash mapping for AndroidTM articles belong to the Category:Flash mapping for Android.

3 Load the kernel sources[edit]

By default, the kernel sources are not part of the STM32MPU distribution for AndroidTM. To load the sources, execute the following instruction:

PC $> load_kernel

This will load the Android™ common Linux® kernel sources. These are located in the device/stm/<STM32Series>-kernel/linux-<STM32Series> directory.


The load_kernel script uses the configuration file available in the /device/stm/<STM32Series>-kernel/source/patch/<kernel version>/ directory.

4 Build the kernel[edit]

After retrieving the kernel sources, it is built using:

PC $> build_kernel

The output is located in: out-bsp/<STM32Series>/KERNEL_OBJ

This instruction generates the kernel, DT and gpu modules. It is possible to generate them separately from one another:

PC $> build_kernel dtb
PC $> build_kernel gpu
PC $> build_kernel vmlinux

For more details check the instruction helper:

PC $> build_kernel --help
PC $> Usage: build_kernel [Options] [Command]

This script builds the Linux® kernel source


PC $>  -h/--help: print this message
PC $>  -i/--install: update prebuilt images
PC $>   -v/--version: get script version
PC $>   --verbose: enable verbose output.

Instruction: only one instruction is supported at a time.

PC $>  dtb: build only device-tree binaries
PC $>  gpu: build only gpu module (the kernel is build if not already performed)
PC $>  defaultconfig: build only .config based on default defconfig files and fragments
PC $>  menuconfig: display standard Linux® kernel menuconfig interface
PC $>  modules: build only kernel modules binaries (kernel is build if not already performed)
PC $>  mrproper: execute make mrproper on targeted kernel
PC $>  vmlinux: build only kernel vmlinux binary

5 Integrate the kernel[edit]

To integrate the new kernel, modules or/and device tree in the distribution, the prebuilt images have to be update first:

PC $> build_kernel -i


PC $> build_kernel -i dtb
PC $> build_kernel -i modules
PC $> build_kernel -i vmlinux

And then build the distribution to generate output images.

PC $> make -j

Finally, update the associated device partitions. Refer to How to populate boards for Android

6 Customize the kernel[edit]

If the kernel configuration has to be changed, refer to How to customize kernel for Android page.