Last edited 5 months ago

How to customize the Linux kernel: Difference between revisions

Registered User
Registered User
No edit summary
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude>{{ApplicableFor
{{ApplicableFor
|MPUs list=STM32MP13x, STM32MP15x
|MPUs list=STM32MP13x, STM32MP15x, STM32MP21x, STM32MP23x, STM32MP25x
|MPUs checklist=STM32MP13x,STM32MP15x
|MPUs checklist=STM32MP13x, STM32MP15x, STM32MP21x, STM32MP23x, STM32MP25x
}}</noinclude>
}}
<noinclude></noinclude>
==Purpose of article==
==Purpose of article==
This article gives the main steps needed to add kernel customization within the Yocto build process (with a Distribution Package).
This article gives the main steps needed to add kernel customization within the Yocto build process (with a Distribution Package).


==Pre-requesites==
==Pre-requisites==
You are already familiar with the Yocto build process and OpenSTLinux distribution.
You are already familiar with the Yocto build process and OpenSTLinux distribution.


Line 19: Line 20:
==Adding kernel customization (including Linux kernel device tree, configuration, driver modification)==
==Adding kernel customization (including Linux kernel device tree, configuration, driver modification)==


* First, create (in your custom layer) a <name of kernel recipe>.bbappend file
* First, create (in your custom layer) a {{HighlightParam|''<name of kernel recipe>''}}.bbappend file
  {{PC$}} touch ../meta-my-custo-layer/recipes-kernel/linux/<name of kernel recipe>.bbappend
  {{PC$}}touch ../meta-my-custo-layer/recipes-kernel/linux/{{HighlightParam|''<name of kernel recipe>''}}.bbappend


===Adding kernel configuration modifications===
===Adding kernel configuration modifications===
* Identify all new configs you set or unset with: {{PC$}} bitbake <name of kernel recipe> -c menuconfig
* Identify all new configs you set or unset with: {{PC$}}bitbake {{HighlightParam|''<name of kernel recipe>''}} -c menuconfig
* Put them inside a new fragment file and copy the fragment here:
* Put them inside a new fragment file and copy the fragment here:
  {{PC$}} cp <custom-fragment>.config  ../meta-my-custo-layer/recipes-kernel/linux/<name of kernel recipe>/<kernel version>/
  {{PC$}}cp {{HighlightParam|''<custom-fragment>''}}.config  ../meta-my-custo-layer/recipes-kernel/linux/{{HighlightParam|''<name of kernel recipe>''}}/{{HighlightParam|''<kernel version>''}}/
* Update accordingly <name of kernel recipe>.bbappend:
* Update accordingly <name of kernel recipe>.bbappend:
  # Needed to tell Yocto to search inside this path
  # Needed to tell Yocto to search inside this path
  FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  KERNEL_CONFIG_FRAGMENTS:append = " ${WORKDIR}/fragments/<kernel version>/<custom-fragment>.config"
  KERNEL_CONFIG_FRAGMENTS:append = " ${WORKDIR}/fragments/<kernel version>/{{HighlightParam|''<custom-fragment>''}}.config"
  SRC_URI:append = " file://<kernel version>/<custom-fragment>.config;subdir=fragments "
  SRC_URI:append = " file://{{HighlightParam|''<kernel version>''}}/{{HighlightParam|''<custom-fragment>''}}.config;subdir=fragments "


For the use case described in the [[How to cross-compile with the Distribution Package#modifying_kernel_configuration|modified the kernel configuration]] example, you should:
For the use case described in the [[How to cross-compile with the Distribution Package#modifying_kernel_configuration|modified the kernel configuration]] example, you should:
* Create fragment-cma-size.config with the following line:
* Create fragment-cma-size.config with the following line:
CONFIG_CMA_SIZE_MBYTES=256
CONFIG_CMA_SIZE_MBYTES=256
* Copy fragment-cma-size.config to ../meta-my-custo-layer/recipes-kernel/linux/linux-stm32mp/<kernel version>
* Copy fragment-cma-size.config to ../meta-my-custo-layer/recipes-kernel/linux/linux-stm32mp/{{HighlightParam|''<kernel version>''}}
* Update ../meta-my-custo-layer/recipes-kernel/linux/linux-stm32mp.bbappend accordingly by adding these lines:
* Update ../meta-my-custo-layer/recipes-kernel/linux/linux-stm32mp.bbappend accordingly by adding these lines:
  KERNEL_CONFIG_FRAGMENTS:append = " ${WORKDIR}/fragments/${LINUX_VERSION}/fragment-cma-size.config"
  KERNEL_CONFIG_FRAGMENTS:append = " ${WORKDIR}/fragments/${LINUX_VERSION}/fragment-cma-size.config"
Line 44: Line 45:
{{Info| The example given below is associated with the STM32MP15 Evaluation board, but the method is independent of the board. }}
{{Info| The example given below is associated with the STM32MP15 Evaluation board, but the method is independent of the board. }}


Once you have made the changes for the device tree in <build dir>/workspace/sources/<name of kernel recipe>/arch/arm/boot/dts/stm32mp157c-ed1.dts '''AND''', for built-in device driver in <build dir>/workspace/sources/<name of kernel recipe>/drivers/gpu/drm/stm/drv.c, you must:
Once you have made the changes for the device tree in <build dir>/workspace/sources/<name of kernel recipe>/arch/arm/boot/dts/st/stm32mp157c-ed1.dts '''AND''', for built-in device driver in {{HighlightParam|''<build dir>''}}/workspace/sources/{{HighlightParam|''<name of kernel recipe>''}}/drivers/gpu/drm/stm/drv.c, you must:


* Create the corresponding patch files:
* Create the corresponding patch files:
  {{PC$}} cd <build dir>/workspace/sources/<name of kernel recipe>/
  {{PC$}}cd {{HighlightParam|''<build dir>''}}/workspace/sources/{{HighlightParam|''<name of kernel recipe>''}}/
  {{PC$}} git format-patch -2
  {{PC$}}git format-patch -2
* Copy these patch files into the custom layer
* Copy these patch files into the custom layer
  {{PC$}} cp *.patch ../meta-my-custo-layer/recipes-kernel/linux/<name of kernel recipe>/<kernel version>/<kernel version>.<revision>/
  {{PC$}}cp *.patch ../meta-my-custo-layer/recipes-kernel/linux/{{HighlightParam|''<name of kernel recipe>''}}/<kernel version>/{{HighlightParam|''<kernel version>.<revision>''}}/
{{Warning|Patches are linked to a kernel version, which means that these patches are rebuilt if the kernel version changes, and copied to the according kernel version sub-folder}}
{{Warning|Patches are linked to a kernel version, which means that these patches are rebuilt if the kernel version changes, and copied to the according kernel version sub-folder}}
* Update <name of kernel recipe>.bbappend accordingly:
* Update <name of kernel recipe>.bbappend accordingly:

Latest revision as of 16:26, 5 November 2024

Applicable for STM32MP13x lines, STM32MP15x lines, Unknown MPU, Unknown MPU, Unknown MPU

1. Purpose of article[edit | edit source]

This article gives the main steps needed to add kernel customization within the Yocto build process (with a Distribution Package).

2. Pre-requisites[edit | edit source]

You are already familiar with the Yocto build process and OpenSTLinux distribution.

You have already created a customer layer (How to create a new open embedded layer) to update, for your own needs, the OpenSTLinux distribution.

We describe here what you must do once you have:

so that these modifications are taken into account in your build process.

3. Adding kernel customization (including Linux kernel device tree, configuration, driver modification)[edit | edit source]

  • First, create (in your custom layer) a <name of kernel recipe>.bbappend file
touch ../meta-my-custo-layer/recipes-kernel/linux/<name of kernel recipe>.bbappend

3.1. Adding kernel configuration modifications[edit | edit source]

  • Identify all new configs you set or unset with: bitbake <name of kernel recipe> -c menuconfig
  • Put them inside a new fragment file and copy the fragment here:
cp <custom-fragment>.config  ../meta-my-custo-layer/recipes-kernel/linux/<name of kernel recipe>/<kernel version>/
  • Update accordingly <name of kernel recipe>.bbappend:
# Needed to tell Yocto to search inside this path
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
KERNEL_CONFIG_FRAGMENTS:append = " ${WORKDIR}/fragments/<kernel version>/<custom-fragment>.config"
SRC_URI:append = " file://<kernel version>/<custom-fragment>.config;subdir=fragments "

For the use case described in the modified the kernel configuration example, you should:

  • Create fragment-cma-size.config with the following line:

CONFIG_CMA_SIZE_MBYTES=256

  • Copy fragment-cma-size.config to ../meta-my-custo-layer/recipes-kernel/linux/linux-stm32mp/<kernel version>
  • Update ../meta-my-custo-layer/recipes-kernel/linux/linux-stm32mp.bbappend accordingly by adding these lines:
KERNEL_CONFIG_FRAGMENTS:append = " ${WORKDIR}/fragments/${LINUX_VERSION}/fragment-cma-size.config"
SRC_URI:append = " file://${LINUX_VERSION}/fragment-cma-size.config;subdir=fragments"

3.2. Adding kernel driver or device tree modifications[edit | edit source]

Info white.png Information
The example given below is associated with the STM32MP15 Evaluation board, but the method is independent of the board.

Once you have made the changes for the device tree in <build dir>/workspace/sources/<name of kernel recipe>/arch/arm/boot/dts/st/stm32mp157c-ed1.dts AND, for built-in device driver in <build dir>/workspace/sources/<name of kernel recipe>/drivers/gpu/drm/stm/drv.c, you must:

  • Create the corresponding patch files:
cd <build dir>/workspace/sources/<name of kernel recipe>/
git format-patch -2
  • Copy these patch files into the custom layer
cp *.patch ../meta-my-custo-layer/recipes-kernel/linux/<name of kernel recipe>/<kernel version>/<kernel version>.<revision>/
Warning white.png Warning
Patches are linked to a kernel version, which means that these patches are rebuilt if the kernel version changes, and copied to the according kernel version sub-folder
  • Update <name of kernel recipe>.bbappend accordingly:
SRC_URI:append = " \
   file://${LINUX_VERSION}/${LINUX_VERSION}.${LINUX_SUBVERSION}/0001-DT-leds-change.patch \
   file://${LINUX_VERSION}/${LINUX_VERSION}.${LINUX_SUBVERSION}/0002-Driver-change.patch \
   "