Last edited 5 years ago

How to customize kernel for Android: Difference between revisions

Registered User
No edit summary
Registered User
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This page explains how to change the kernel configuration and device tree. It is intended for Distribution Package users.
{{ReviewsComments | AJ 19W42 - I suggest to change the title into "How to customize the kernel for Android"}}


== Prerequisites ==
== Prerequisites ==


The environment must be installed using the Distribution Package adapted to your selected microprocessor device.
The environment must be installed using the Distribution Package adapted to your microprocessor device.
See the list of Android [[Which_STM32MPU_Embedded_Software_Package_for_Android_better_suits_your_needs#Distribution_Package | Distribution Package]].
See the list of Android [[Which_STM32MPU_Embedded_Software_Package_for_Android_better_suits_your_needs#Distribution_Package | Distribution Package]].


You must get kernel sources as explained in [[How to build kernel for Android]].
Get the kernel sources as explained in [[How to build kernel for Android]].


To be able to execute following instructions you need to work from your distribution root directory and initialise your environment:
To execute the following instructions, go to your distribution root directory and initialize your environment as follows:


  {{PC$}} source build/envsetup.sh
  {{PC$}} source build/envsetup.sh
  {{PC$}} bspsetup
  {{PC$}} bspsetup
  {{PC$}} lunch aosp-{{HighlightParam|''<BoardId>''}}-userdebug
  {{PC$}} lunch aosp_{{HighlightParam|''<BoardId>''}}-userdebug
{{Info| The <code>bspsetup</code> command needs to be run only one time for the distribution}}
{{Info| The <code>bspsetup</code> command needs to be run only once for the distribution}}


== Updating the kernel configuration ==
== Updating the kernel configuration ==
{{Info |
{{Info |
The kernel configuration file used is merged between the following files (this operation is performed at the beginning of the kernel build process):  
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 configuration files named <code>android-base.config</code> and <code>android-recommended.config</code> files available in the <code>device/stm/{{HighlightParam|''<STM32Series>''}}-kernel/source/kconfig/{{HighlightParam|''<kernel version>''}}/</code> directory.
* The Android configuration files named <code>android-base.config</code> and <code>android-recommended.config</code> available in the <code>device/stm/{{HighlightParam|''<STM32Series>''}}-kernel/source/kconfig/{{HighlightParam|''<kernel version>''}}/</code> directory.
* The <code>android-soc.config</code> file available in the <code>device/stm/{{HighlightParam|''<STM32Series>''}}-kernel/source/kconfig/{{HighlightParam|''<kernel version>''}}/</code> directory.
* The <code>android-soc.config</code> file available in the <code>device/stm/{{HighlightParam|''<STM32Series>''}}-kernel/source/kconfig/{{HighlightParam|''<kernel version>''}}/</code> directory.
}}
}}


By using <code>menuconfig</code>, you can update the configuration file for your needs. Some guidelines are given below.
By using <code>menuconfig</code>, you can adapt the configuration file to your needs. Some guidelines are given below.


=== Save the current configuration ===
=== Saving the current configuration ===


Before making any changes to the kernel configuration, it is advised to build the kernel with the current configuration:
Before changing the kernel configuration, it is recommended to build the kernel using the current configuration:


  {{PC$}} build_kernel
  {{PC$}} build_kernel
Line 32: Line 32:
A default config file named <code>defconfig.default</code> is generated in <code>out-bsp/{{HighlightParam|''<STM32Series>''}}/KERNEL_OBJ/</code> directory.
A default config file named <code>defconfig.default</code> is generated in <code>out-bsp/{{HighlightParam|''<STM32Series>''}}/KERNEL_OBJ/</code> directory.


=== Create a new kernel configuration ===
=== Creating a new kernel configuration ===


Start <code>menuconfig</code>:
Start <code>menuconfig</code>:
Line 38: Line 38:
  {{PC$}} build_kernel menuconfig
  {{PC$}} build_kernel menuconfig


You can load a <code>.config</code> file and modify any entry using this interface. Please read on the top of the windows the instructions to navigate.
You can load a <code>.config</code> 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 hit save.
Do not forget to click '''save'''.


This will generate a <code>.config</code> file located in <code>out-bsp/{{HighlightParam|''<STM32Series>''}}/KERNEL_OBJ/</code>, and will also generate a <code>defconfig</code> file in the same place.
This generates a <code>.config</code> file located in <code>out-bsp/{{HighlightParam|''<STM32Series>''}}/KERNEL_OBJ/</code>, as well as a <code>defconfig</code> file at the same location.


=== Test new kernel configuration===
=== Testing the new kernel configuration===


To test your new configuration you need to rebuild the kernel, then update the prebuilts and flash, like explain in more details in [[How to build kernel for Android]].
To test the new configuration, rebuild the kernel, update the prebuilts and flash, as explained in [[How to build kernel for Android]].


=== Applying the newly generated kernel configuration ===
=== Applying the newly generated kernel configuration ===


To make your change permanent, you need first to compare the new <code>defconfig</code> file with the <code>defconfig.default</code> file generated at first build.
To make your change permanent, first compare the new <code>defconfig</code> file with the <code>defconfig.default</code> file generated at first build.


You can use a graphical tool like <code>meld</code>.
You can use a graphical tool such as <code>meld</code>.
  {{PC$}} meld out-bsp/{{HighlightParam|''<STM32Series>''}}/KERNEL_OBJ/defconfig out-bsp/{{HighlightParam|''<STM32Series>''}}/KERNEL_OBJ/defconfig.default
  {{PC$}} meld out-bsp/{{HighlightParam|''<STM32Series>''}}/KERNEL_OBJ/defconfig out-bsp/{{HighlightParam|''<STM32Series>''}}/KERNEL_OBJ/defconfig.default




Then report the changes to the <code>android-soc.config</code> file located in <code>device/stm/{{HighlightParam|''<STM32Series>''}}-kernel/source/kconfig/{{HighlightParam|''<kernel version>''}}/</code>.
Then report the changes into the <code>android-soc.config</code> file located in <code>device/stm/{{HighlightParam|''<STM32Series>''}}-kernel/source/kconfig/{{HighlightParam|''<kernel version>''}}/</code>.


And force the regeneration of the .config:
Eventually force the regeneration of the .config:
  {{PC$}} build_kernel defaultconfig
  {{PC$}} build_kernel defaultconfig
''Note: the  <code>defconfig.default </code> is then updated''.
''Note: the  <code>defconfig.default </code> is then updated''.


To test your configuration you need to rebuild the kernel, then update the prebuilts and flash, like explain in more details in [[How to build kernel for Android]].
To test your configuration, rebuild the kernel and update the prebuilts and flash, as explain in [[How to build kernel for Android]].


== Changing the kernel command line ==
== Changing the kernel command line ==


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


Change the value of the '''BOARD_KERNEL_CMDLINE''' variable to your needs.
Adapt the value of the '''BOARD_KERNEL_CMDLINE''' variable to your needs.


To apply changes, you need to rebuild the bootimage:
Rebuild the bootimage to apply the changes:


  {{PC$}} make bootimage-nodeps
  {{PC$}} make bootimage-nodeps


And then flash the boot partition.
Then flash the boot partition:


{{ Info| To control the command line after compilation you can execute:
{{ Info| To control the command line after compilation you can execute:
Line 81: Line 81:
  {{PC$}} ./system/core/mkbootimg/unpack_bootimg --boot_img out/target/product/{{HighlightParam|''<BoardId>''}}/boot.img
  {{PC$}} ./system/core/mkbootimg/unpack_bootimg --boot_img out/target/product/{{HighlightParam|''<BoardId>''}}/boot.img


Check the '''"command line args"''' value from the output, it must match your changes.
Check the '''"command line args"''' value from the output: it must match your changes.
}}
}}


== Changing the Device Tree ==
== Changing the Device Tree ==


The kernel device tree used is set in the <code>dt.mk</code> file available in the <code>device/stm/{{HighlightParam|''<STM32Series>''}}/build/tasks/</code> directory. For more information please refer to the [[Device tree]] and [[How to create your board device tree]] pages.
The kernel device tree used is set in the <code>dt.mk</code> file available under the <code>device/stm/{{HighlightParam|''<STM32Series>''}}/build/tasks/</code> directory. For more information refer to the [[Device tree]] and [[How to create your board device tree]] pages.


This device trees are located inside the Linux kernel source code previously loaded and can be modified directly in <code>device/stm/{{HighlightParam|''<STM32Series>''}}-kernel/linux-{{HighlightParam|''<STM32Series>''}}/arch/arm/boot/dts</code>.
The device trees are located inside the Linux<sup>&reg;</sup> kernel source code previously loaded. A Device Tree can be modified directly in <code>device/stm/{{HighlightParam|''<STM32Series>''}}-kernel/linux-{{HighlightParam|''<STM32Series>''}}/arch/arm/boot/dts</code>.


After modification you need to rebuild the device tree by:
Once the Device Tree has been modified, rebuild it:


  {{PC$}} build_kernel -i dtb
  {{PC$}} build_kernel -i dtb
Line 96: Line 96:
  {{PC$}} make -j
  {{PC$}} make -j


And then re-flash the DT partition.
Then flash again the DT partition.


<noinclude>
<noinclude>

Latest revision as of 13:35, 18 October 2019


1. Prerequisites[edit source]

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

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
 bspsetup
 lunch aosp_<BoardId>-userdebug
Info white.png Information
The bspsetup command needs to be run only once for the distribution

2. Updating the kernel configuration[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 configuration files named android-base.config and android-recommended.config available in the device/stm/<STM32Series>-kernel/source/kconfig/<kernel version>/ directory.
  • The android-soc.config file 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 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 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 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 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 android-soc.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 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/core/mkbootimg/unpack_bootimg --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 source]

The kernel device tree used is set 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/arm/boot/dts.

Once the Device Tree has been modified, rebuild it:

 build_kernel -i dtb

 make -j

Then flash again the DT partition.