Modify, rebuild and reload the Linux® kernel

Stable: 29.06.2023 - 16:04 / Revision: 23.06.2023 - 20:32

I am here to prevent the first-page-empty bug!

1 Overview

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 step by step you will execute procedures to modify, rebuild and reload the Linux® kernel.

2 Download the the Linux® kernel source code

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

  • Download the [unknown revision /unknown revision STM32MP15-Ecosystem-v3.0.0 Developer Package Sources] to the following directory:
    $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v3.0.0/Developer-Package
  • Uncompress the tarball file to get the Linux® kernel tarball, the ST patches and the ST configuration fragments
 cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v3.0.0/Developer-Package
 tar xvf unknown revision 

3 Prepare the Linux® kernel source code

  • Extract the Linux® kernel source
 cd unknown revision 
 tar xvf unknown revision 
  • Apply the ST patches
 cd unknown revision 
 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

Info white.png Information
The first time the kernel is build it could 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

5.1 Push the Linux® kernel into the board

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

5.2 Push the devicetree into the board

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

5.3 Push the kernel modules into the board

  • Remove the link created inside the install_artifact/lib/modules/<kernel version> directory
 rm install_artifact/lib/modules/5.10.10/build install_artifact/lib/modules/5.10.10/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, re-generate 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

 reboot

6 Modifying a built-in Linux kernel device driver

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/STM32MP15-Ecosystem-v3.0.0/Developer-Package/unknown revision /unknown revision 

  • Edit the ./drivers/gpu/drm/stm/drv.c source file
  • Add a log information in the stm_drm_platform_probe function as follow
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
  • Rebuitd 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 there is now log information when the display driver is probed
 dmesg | grep -i stm_drm_platform_probe
[    2.764080] [drm] Simple example - stm_drm_platform_probe


IMPORTANT NOTICE – READ CAREFULLY
STMicroelectronics NV and its subsidiaries ("ST") reserve the right to make changes, corrections, enhancements, modifications, and improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgment.

Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of purchasers’ products.

No license, express or implied, to any intellectual property right is granted by ST herein.

Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.

ST and the ST logo are trademarks of ST. For additional information about ST trademarks, refer to www.st.com/trademarks. All other product or service names are the property of their respective owners.

Information in this document supersedes and replaces information previously supplied in any prior versions of this document.