Modify, rebuild and reload the Linux® kernel

Applicable for STM32MP15x lines

STM32MP157X-DK2.png
Develop on Arm® Cortex®-A7 Develop on Arm® Cortex®-M4
Step category in.png Install the SDK Step.png Create a simple hello-world application Step.png Modify, rebuild and reload the Linux® kernel Step category out.png


1 Overview[edit]

This stage explains how modify, rebuild and reload the Linux® kernel.
You will first be guided to install the Linux® kernel source code in the Developer Package directory. Then you will execute step by step procedures to modify, rebuild and reload the Linux® kernel.

2 Download OpenSTLinux BSP that includes the Linux® kernel source code[edit]

The software package is provided AS IS, and by downloading it, you agree to be bound to the terms of the software license agreement (SLA). The detailed content licenses can be found here.

Warning white.png Warning
To download a package, it is recommended to be logged in to your "myst" account [1]. If, trying to download, you encounter a “403 error”, you could try to empty your browser cache to workaround the problem. We are working on the resolution of this problem.
We apologize for this inconvenience
  • The OpenSTLinux BSP package is delivered through a tarball file named en.SOURCES-stm32mp1-openstlinux-5.15-yocto-kirkstone-mp1-v22.11.23.tar.gz for STM32MP157x-EV1 More info green.png, STM32MP157x-DKx More info green.png and STM32MP135x-DK Warning.png boards.

  • Download and install the STM32MP1 OpenSTLinux BSP package.
STM32MP1 Developer Package - STM32MP1 ecosystem v4.1.0 release
Download

Log on my.st.com before accessing the following link:
en.SOURCES-stm32mp1-openstlinux-5.15-yocto-kirkstone-mp1-v22.11.23.tar.gz

Installation
 cd <working directory path>/Developer-Package
 tar xvf en.SOURCES-stm32mp1-openstlinux-5.15-yocto-kirkstone-mp1-v22.11.23.tar.gz
Release note

Details about the content of the OpenSTLinux BSP package are available in the associated STM32 MPU OpenSTLinux release note.

Archive box.png For information on older releases, go to Archives.


3 Prepare the Linux® kernel source code[edit]

 cd stm32mp1-openstlinux-5.15-yocto-kirkstone-mp1-v22.11.23/sources/arm-ostl-linux-gnueabi/linux-stm32mp-5.15.67-stm32mp-r2-r0

Extract the Linux® kernel source

 tar xvf linux-5.15.67.tar.xz


Apply ST patches

 cd linux-5.15.67
 for p in `ls -1 ../*.patch`; do patch -p1 < $p; done


Apply fragments

 make ARCH=arm multi_v7_defconfig "fragment*.config"
 for f in `ls -1 ../fragment*.config`; do scripts/kconfig/merge_config.sh -m -r .config $f; done
 yes '' | make ARCH=arm oldconfig

4 Build the Linux® kernel source code for the first time[edit]

Info white.png Information
Building the kernel for the first time can take several minutes.
  • Build kernel images (uImage and vmlinux) and device tree (dtbs)
 make ARCH=arm uImage vmlinux dtbs LOADADDR=0xC2000040
  • Build kernel module
 make ARCH=arm modules
  • Generate output build artifacts
 mkdir -p $PWD/install_artifact/
 make ARCH=arm INSTALL_MOD_PATH="$PWD/install_artifact" modules_install

5 Deploy the Linux® kernel on the board[edit]

5.1 Push the Linux® kernel onto the board[edit]

 scp arch/arm/boot/uImage root@<board ip address>:/boot

5.2 Push the devicetree into the board[edit]

 scp arch/arm/boot/dts/stm32mp1xx*.dtb root@<board ip address>:/boot

5.3 Push the kernel modules onto the board[edit]

  • Remove the link created inside the install_artifact/lib/modules/<kernel version> directory
 rm install_artifact/lib/modules/5.15.67/build install_artifact/lib/modules/5.15.67/source 
  • Optionally, strip kernel modules (to reduce the size of each kernel modules)
 find install_artifact/ -name "*.ko" | xargs $STRIP --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates
  • Copy kernel modules
 scp -r install_artifact/lib/modules/* root@<ip of board>:/lib/modules
  • Using the Linux® console, regenerate the list of module dependencies (modules.dep) and the list of symbols provided by modules (modules.symbols)
 /sbin/depmod -a
  • Synchronize data on disk with memory
 sync

5.4 Reboot the board[edit]

 reboot

6 Modify a built-in Linux® kernel device driver[edit]

This simple example adds unconditional log information when the display driver is probed.

  • Using the Linux® console, check that there is no log information when the display driver is probed
 dmesg | grep -i stm_drm_platform_probe

  • Go to the Linux® kernel source directory
 cd $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v4.1.0/Developer-Package/stm32mp1-openstlinux-5.15-yocto-kirkstone-mp1-v22.11.23/sources/arm-ostl-linux-gnueabi/linux-stm32mp-5.15.67-stm32mp-r2-r0/linux-5.15.67

  • Edit the ./drivers/gpu/drm/stm/drv.c source file
  • Add a log information in the stm_drm_platform_probe function as follows
static int stm_drm_platform_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct drm_device *ddev;
	int ret;
	[...]

	DRM_INFO("Simple example - %s\n", __func__);

	return 0;
	[...]
}
  • Save the file
  • Rebuild the Linux® kernel
 make uImage LOADADDR=0xC2000040
  • Update the Linux kernel image into board
 scp arch/arm/boot/uImage root@<board ip address>:/boot
  • Reboot the board
 reboot
  • Check that log information is now present when the display driver is probed
 dmesg | grep -i stm_drm_platform_probe
[    2.764080] [drm] Simple example - stm_drm_platform_probe



Back button.png Overview button.png Next button.png