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 OpenSTLinux BSP that includes the Linux® kernel source code[edit source]
2.1. For STM32MP1 series[edit source]
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.
- The OpenSTLinux BSP package is delivered through a tarball file named en.sources-stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26.tar.gz for STM32MP157x-EV1
, STM32MP157x-DKx
and STM32MP135x-DK
boards.
- Download and install the STM32MP1 OpenSTLinux BSP package.
STM32MP1 Developer Package - STM32MP1 ecosystem v5.1.0 release | |
---|---|
Download |
|
Installation |
cd <working directory path>/Developer-Package
tar xvf en.sources-stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26.tar.gz |
Release note |
Details about the content of the OpenSTLinux BSP package are available in the associated STM32 MPU OpenSTLinux release note.
|
2.2. For STM32MP2 series[edit source]
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.
- The OpenSTLinux BSP package is delivered through a tarball file named en.sources-stm32mp2-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26.tar.gz for STM32MP257F-EV1
boards.
- Download and install the STM32MPU OpenSTLinux BSP package.
STM32MPU Developer Package - STM32MPU ecosystem v5.1.0 release | |
---|---|
Download |
|
Installation |
cd <working directory path>/Developer-Package
tar xvf en.sources-stm32mp2-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26.tar.gz |
Release note |
Details about the content of the OpenSTLinux BSP package are available in the associated STM32 MPU OpenSTLinux release note.
|
3. Prepare the Linux® kernel source code[edit source]
3.1. For STM32MP1 series[edit source]
cd stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/arm-ostl-linux-gnueabi/linux-stm32mp-6.1.82-stm32mp-r2-r0
Extract the Linux® kernel source
tar xvf linux-6.1.82.tar.xz
Apply ST patches
cd linux-6.1.82 for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
- Configure build directory
export OUTPUT_BUILD_DIR=$PWD/../build mkdir -p ${OUTPUT_BUILD_DIR}
- Apply fragments
make O="${OUTPUT_BUILD_DIR}" defconfig fragment*.config for f in `ls -1 ../fragment*.config`; do scripts/kconfig/merge_config.sh -m -r -O ${OUTPUT_BUILD_DIR} ${OUTPUT_BUILD_DIR}/.config $f; done yes '' | make oldconfig O="${OUTPUT_BUILD_DIR}"
3.2. For STM32MP2 series[edit source]
cd stm32mp2-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/aarch64-ostl-linux/linux-stm32mp-6.1.82-stm32mp-r2-r0
Extract the Linux® kernel source
tar xvf linux-6.1.82.tar.xz
Apply ST patches
cd linux-6.1.82 for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
Apply fragments
make defconfig fragment*.config for f in `ls -1 ../fragment*.config`; do scripts/kconfig/merge_config.sh -m -r .config $f; done (yes '' || true) | make oldconfig
Prepare external device tree source needed to build Linux® kernel
cd ../../external-dt-v5.0-stm32mp-r1-r0/
tar xf unknown revision
To enable usage of external device tree source code for other component, you must:
- set the EXTDT_DIR variable to your shell environment
export EXTDT_DIR=$PWD/unknown revision
Return into Linux® directory
cd $HOME/STM32MPU_workspace/STM32MPU-Ecosystem-v5.1.0/Developer-Package/stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/arm-ostl-linux-gnueabi/linux-stm32mp-6.1.82-stm32mp-r2-r0/linux-6.1.82
4. Build the Linux® kernel source code for the first time[edit source]
4.1. For STM32MP1 series[edit source]
![]() |
Building the kernel for the first time can take several minutes. |
- Select which kind of image to build regarding the SDK installed
[ "${ARCH}" = "arm" ] && imgtarget="uImage" || imgtarget="Image.gz" export IMAGE_KERNEL=${imgtarget}
- Build kernel images ([uImage|Image.gz] and vmlinux) and device tree (dtbs)
make ${IMAGE_KERNEL} vmlinux dtbs LOADADDR=0xC2000040 O="${OUTPUT_BUILD_DIR}"
- Build kernel module
make modules O="${OUTPUT_BUILD_DIR}"
- Generate output build artifacts
make INSTALL_MOD_PATH="${OUTPUT_BUILD_DIR}/install_artifact" modules_install O="${OUTPUT_BUILD_DIR}" mkdir -p ${OUTPUT_BUILD_DIR}/install_artifact/boot/ cp ${OUTPUT_BUILD_DIR}/arch/${ARCH}/boot/${IMAGE_KERNEL} ${OUTPUT_BUILD_DIR}/install_artifact/boot/ find ${OUTPUT_BUILD_DIR}/arch/${ARCH}/boot/dts/ -name 'st*.dtb' -exec cp '{}' ${OUTPUT_BUILD_DIR}/install_artifact/boot/ \;
4.2. For STM32MP2 series[edit source]
![]() |
Building the kernel for the first time can take several minutes. |
- Build kernel images (uImage and vmlinux) and device tree (dtbs)
make Image.gz vmlinux dtbs LOADADDR=0xC2000040 KBUILD_EXTDTS="${EXTDT_DIR}/linux" make modules
- Generate output build artifacts
make INSTALL_MOD_PATH="$PWD/install_artifact" modules_install mkdir -p $PWD/install_artifact/boot/ cp $PWD/arch/$ARCH/boot/Image.gz $PWD/install_artifact/boot/ cp $PWD/arch/$ARCH/boot/dts/st/st*.dtb $PWD/install_artifact/boot/
5. Deploy the Linux® kernel on the board[edit source]
5.1. For STM32MP1 series[edit source]
5.1.1. Push the Linux® kernel and the devicetree onto the board[edit source]
cd ${OUTPUT_BUILD_DIR}/install_artifact scp -r boot/* root@<ip of board>:/boot/
5.1.2. Push the kernel modules onto the board[edit source]
- Remove the link created inside the install_artifact/lib/modules/<kernel version> directory
cd ${OUTPUT_BUILD_DIR}/ rm install_artifact/lib/modules/6.1.82/build install_artifact/lib/modules/6.1.82/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.1.3. Reboot the board[edit source]
reboot
5.2. For STM32MP2 series[edit source]
5.2.1. Push the Linux® kernel + devicetree onto the board[edit source]
cd install_artifact/ scp -r boot/* root@<ip of board>:/boot/
5.2.2. Push the kernel modules onto the board[edit source]
- Remove the link created inside the install_artifact/lib/modules/<kernel version> directory
rm lib/modules/6.1.28/source lib/modules/6.1.28/build
- Optionally, strip kernel modules (to reduce the size of each kernel modules)
find . -name "*.ko" | xargs $STRIP --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates
- Copy kernel modules
scp -r lib/modules/* root@<ip of board>:/lib/modules/
- Generate a list of module dependencies (modules.dep) and a list of symbols provided by modules (modules.symbols):
ssh root@<ip of board> /sbin/depmod -a
- Synchronize data on disk with memory
ssh root@<ip of board> sync
5.2.3. Reboot the board in order to take update into account[edit source]
ssh root@<ip of 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
dmesg | grep -i stm_drm_platform_probe
- Go to the Linux® kernel source directory
6.1. For STM32MP1 series[edit source]
cd $HOME/STM32MPU_workspace/STM32MPU-Ecosystem-v5.1.0/Developer-Package/stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/arm-ostl-linux-gnueabi/linux-stm32mp-6.1.82-stm32mp-r2-r0/linux-6.1.82
6.2. For STM32MP2 series[edit source]
cd $HOME/STM32MPU_workspace/STM32MPU-Ecosystem-v5.1.0/Developer-Package/stm32mp2-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/aarch64-ostl-linux/linux-stm32mp-6.1.82-stm32mp-r2-r0/linux-6.1.82
- 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
6.3. For STM32MP1 series[edit source]
- Rebuild the Linux® kernel
make ${IMAGE_KERNEL} LOADADDR=0xC2000040 O="${OUTPUT_BUILD_DIR}"
- Update the Linux kernel image into board
scp ${OUTPUT_BUILD_DIR}/arch/arm/boot/${IMAGE_KERNEL} 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
6.4. For STM32MP2 series[edit source]
- Rebuild the Linux® kernel
make Image.gz vmlinux LOADADDR=0xC2000040
- Update the Linux kernel image into board
scp arch/arm64/boot/Image.gz root@<ip of board>:/boot
- Reboot the board
ssh root@<ip of 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