- Last edited 6 months ago ago
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.
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/envsetup.sh PC $> bspsetup PC $> lunch aosp_<BoardId>-userdebug
The distribution includes prebuilt kernel binaries used to generate the partition images (
vendor). These binaries are available in the
2 Partition layout
The Linux® kernel binary is part of the
The Linux® kernel drivers built as loadable modules (
.ko files) are part of the
The device tree binary file is part of the
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
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
4 Build the kernel
After retrieving the kernel sources, it is built using:
PC $> build_kernel
|By default, kernel debug configuration is used for userdebug or eng build variant|
The output is located in:
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:
PC $> build_kernel vmlinux PC $> build_kernel modules PC $> build_kernel dtb PC $> build_kernel gpu
To get back more details on available options, run:
PC $> build_kernel -h
Here after, see the result for the version 1.4:
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 <val>/--debug=<val>: if <val>=1; integrate debug kernel configuration (default for userdebug or eng build variant) if <val>=0; remove debug kernel configuration (default for user build variant) -g/--gdb: generate vmlinux (kernel incl. symbols) and don't strip generated modules (keep symbols) --gcc: use gcc toolchain instead of clang (bspsetup shall be executed before) --verbose=<level>: enable verbosity (1 or 2 depending on level of verbosity required) 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 only kernel modules binaries (kernel is build if not already performed) modules_install: build kernel modules binaries (kernel is built if not already performed) and install them (also update the module.dep file) mrproper: execute make mrproper on targeted kernel vmlinux: build only kernel vmlinux binary
5 Integrate the kernel
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
|It's highly recommended to use the -d (debug) option, if you want to build the Linux kernel adapted to a |
PC $> build_kernel -i vmlinux PC $> build_kernel -i modules PC $> build_kernel -i gpu PC $> build_kernel -i dtb
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
If the kernel configuration has to be changed, refer to How to customize kernel for Android page.