Last edited 2 years ago

Modify, rebuild and reload the Linux® kernel

1. Overview[edit source]

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 the Linux® kernel source code[edit source]

2.1. For STM32MP13x lines More info.png[edit source]

  • The STM32MP1 Linux kernel is delivered through a tarball file named SOURCES-stm32mp13-disco-openstlinux-5.10-dunfell-mp13-21-11-30.tar.xz for STM32MP135x-DK More info green.png boards.

  • Download and install the STM32MP1 Linux kernel
STM32MP1 Developer Package Linux kernel - STM32MP13-Ecosystem-v3.1.0.ALPHA release
Download

If you didn't retrieve yet the file SOURCES-stm32mp13-disco-openstlinux-5.10-dunfell-mp13-21-11-30.tar.xz, please follow instructions on the downloading instructions page.
You will get all source files in the directory you choose when you extracted the .jar file.


  • Uncompress the tarball file to get the Linux® kernel tarball, the ST patches and the ST configuration fragments
PC $> cd $HOME/STM32MPU_workspace/STM32MP13-Ecosystem-v3.1.0/Developer-Package
PC $> tar xvf SOURCES-stm32mp13-disco-openstlinux-5.10-dunfell-mp13-21-11-30.tar.xz

2.2. For STM32MP15x lines More info.png[edit source]

3. Prepare the Linux® kernel source code[edit source]

  • For STM32MP13x lines More info.png:
PC $> cd stm32mp13-disco-openstlinux-5.10-dunfell-mp13-21-11-30/sources/arm-ostl-linux-gnueabi/linux-stm32mp-5.10.61-stm32mp13-r4-r0

Extract the Linux® kernel source

PC $> tar xvf linux-5.10.61.tar.xz

Apply ST patches

PC $> cd linux-5.10.61
PC $> for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
  • For STM32MP15x lines More info.png:


Apply fragments

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

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

  • Build kernel images (uImage and vmlinux) and device tree (dtbs)
PC $> make ARCH=arm uImage vmlinux dtbs LOADADDR=0xC2000040
  • Build kernel module
PC $> make ARCH=arm modules
  • Generate output build artifacts
PC $> mkdir -p $PWD/install_artifact/
PC $> make ARCH=arm INSTALL_MOD_PATH="$PWD/install_artifact" modules_install

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

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

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

5.2. Push the devicetree into the board[edit source]

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

5.3. Push the kernel modules onto the board[edit source]

  • Remove the link created inside the install_artifact/lib/modules/<kernel version> directory
PC $> rm install_artifact/lib/modules/5.10.61/build install_artifact/lib/modules/5.10.61/source 
  • Optionally, strip kernel modules (to reduce the size of each kernel modules)
PC $> find install_artifact/ -name "*.ko" | xargs $STRIP --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates
  • Copy kernel modules
PC $> 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)
Board $> /sbin/depmod -a
  • Synchronize data on disk with memory
Board $> sync

5.4. Reboot the board[edit source]

Board $> reboot

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

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
Board $> dmesg | grep -i stm_drm_platform_probe
Board $>


For STM32MP13x lines More info.png:

  • Go to the Linux® kernel source directory
PC $> cd $HOME/STM32MPU_workspace/STM32MP13-Ecosystem-v3.1.0/Developer-Package/stm32mp13-disco-openstlinux-5.10-dunfell-mp13-21-11-30/sources/arm-ostl-linux-gnueabi/linux-stm32mp-5.10.61-stm32mp13-r4-r0/linux-5.10.61

For STM32MP15x lines More info.png:

  • 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
PC $> make uImage LOADADDR=0xC2000040
  • Update the Linux kernel image into board
PC $> scp arch/arm/boot/uImage root@<board ip address>:/boot
  • Reboot the board
Board $> reboot
  • Check that log information is now present when the display driver is probed
Board $> dmesg | grep -i stm_drm_platform_probe
[    2.764080] [drm] Simple example - stm_drm_platform_probe