Last edited 3 weeks ago

How to build kernel for Android

Applicable for STM32MP25x lines

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 Android Linux® Common kernel is used in the Distribution Package.

1. Prerequisites[edit | edit source]

The environment must be installed using the Distribution Package adapted to the selected microprocessor unit.

The environment setup must be carried out in accordance with the instructions provided here.


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

2. Partition layout[edit | edit source]

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_boot partition for modules required in the first stage of initialisation (part of an integrated ramdisk) and vendor partitions for the remaining modules.

The device tree binaries are part of the vendor_boot partition for the SoC dependent device-tree and of the dtbo partition for the Board dependent device tree overlay.

Information
For information on the complete partition layout for the corresponding development platform, refer to the STM32 MPU Flash mapping for Android article.

3. Load the kernel sources[edit | edit source]

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

load_kernel

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

Information

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 | edit source]

After retrieving the kernel sources, it is built using:

build_kernel
Information
By default, kernel debug configuration is used for userdebug or eng build variant

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

This instruction generates the kernel image, the device tree blobs and the modules (including the specific GPU driver module). It is possible to generate them separately from one another:

build_kernel defaultconfig
build_kernel vmlinux
build_kernel modules
build_kernel dtb
build_kernel gpu

To get back more details on available options, run:

build_kernel -h

Here after, see the result for the version 1.9:

Usage: build_kernel [Options] [Command]
 
  This script allows building the Linux kernel source
 
Options:
  -h/--help: print this message and exit
  -v/--version: print script version and exit
  -i/--install: update prebuilt images
  -d/--debug: enable script debug traces
  -g/--gdb: generate vmlinux (kernel incl. symbols) and don't strip generated modules (keep symbols)
  --16k: build with 16k page size option
  --verbose: enable verbosity
Command: only one command at a time supported
  dtb: build only device-tree binaries
  gpu: build only gpu module (kernel is build if not already performed)
  defaultconfig: build only .config based on default defconfig files and fragments
  menuconfig: display standard Linux kernel menuconfig interface
  modules: build kernel modules and sign (kernel is built if not already performed)
  mrproper: execute make mrproper on targeted kernel
  vmlinux: build only kernel vmlinux binary

5. Integrate the kernel[edit | edit source]

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

build_kernel -i

or

build_kernel -i vmlinux
build_kernel -i modules
build_kernel -i gpu
build_kernel -i dtb

And then build the distribution to generate the partition images.

make -j

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

6. Customize the kernel[edit | edit source]

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