Debian: Getting Started with the STM32MP157

This is a page about ST’s STM32MP1 series of Cortex-A7 based Development Kits.

Availability

Boards:

Vendor Documentation

Basic Requirements

Cross Compiler: GCC

This is a pre-built (64bit) version of GCC that runs on generic linux, sorry (32bit) x86 users, it’s time to upgrade…
Download/Extract:

#user@localhost:~$
wget -c https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.3.0/x86_64-gcc-11.3.0-nolibc-arm-linux-gnueabi.tar.xz
tar -xf x86_64-gcc-11.3.0-nolibc-arm-linux-gnueabi.tar.xz
export CC32=`pwd`/gcc-11.3.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-

Test Cross Compiler:

#user@localhost:~$
${CC32}gcc --version
#Test Output:
arm-linux-gnueabi-gcc (GCC) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Bootloader: U-Boot

Das U-Boot – the Universal Boot Loader: http://www.denx.de/wiki/U-Boot
Depending on your Linux Distribution, you will also need a host gcc and other tools, so with Debian/Ubuntu start with installing the build-essential meta package.

Host Package Requirements

#user@localhost:~$
sudo apt update ; \
sudo apt-get install -y bc bison build-essential flex libgnutls28-dev ; \
sudo apt-get install -y libssl-dev python3-dev python3-minimal ; \
sudo apt-get install -y python3-setuptools swig uuid-dev

Download:

#user@localhost:~$
git clone -b v2025.04 https://github.com/u-boot/u-boot --depth=1

Configure and Build:

#user@localhost:~$
make -C ./u-boot/ CROSS_COMPILE=${CC32} distclean
make -C ./u-boot/ CROSS_COMPILE=${CC32} stm32mp15_trusted_defconfig

Build for: stm32mp157a-dk1

#user@localhost:~$
make -C ./u-boot/ CROSS_COMPILE=${CC32} DEVICE_TREE=stm32mp157a-dk1 all

Build for: stm32mp157c-dk2

#user@localhost:~$
make -C ./u-boot/ CROSS_COMPILE=${CC32} DEVICE_TREE=stm32mp157c-dk2 all

Bootloader: OP-TEE Trusted OS

OP-TEE Trusted OS: https://github.com/OP-TEE/optee_os
Host Package Requirements

#user@localhost:~$
sudo apt update ; \
sudo apt-get install -y build-essential python3-cryptography python3-pyelftools

Download:

#user@localhost:~$
git clone -b 4.5.0 https://github.com/OP-TEE/optee_os.git --depth=1

Configure and Build: stm32mp157a-dk1

#user@localhost:~$
make -C ./optee_os/ CROSS_COMPILE=${CC32} ARCH=arm PLATFORM=stm32mp1 CFG_EMBED_DTB_SOURCE_FILE=stm32mp157a-dk1.dts

Configure and Build: stm32mp157c-dk2

#user@localhost:~$
make -C ./optee_os/ CROSS_COMPILE=${CC32} ARCH=arm PLATFORM=stm32mp1 CFG_EMBED_DTB_SOURCE_FILE=stm32mp157c-dk2.dts

Bootloader: Trusted Firmware A (TF-A)

Trusted Firmware A (TF-A): https://github.com/TrustedFirmware-A/trusted-firmware-a
Host Package Requirements

#user@localhost:~$
sudo apt update ; \
sudo apt-get install -y build-essential device-tree-compiler

Download:

#user@localhost:~$
git clone -b lts-v2.10 https://github.com/TrustedFirmware-A/trusted-firmware-a.git --depth=1

Configure and Build: stm32mp157a-dk1

#user@localhost:~$
make -C ./trusted-firmware-a/ CROSS_COMPILE=${CC32} realclean
make -C ./trusted-firmware-a/ CROSS_COMPILE=${CC32} PLAT=stm32mp1 ARCH=aarch32 ARM_ARCH_MAJOR=7 DTB_FILE_NAME=stm32mp157a-dk1.dtb STM32MP_SDMMC=1
make -C ./trusted-firmware-a/ CROSS_COMPILE=${CC32} PLAT=stm32mp1 ARCH=aarch32 ARM_ARCH_MAJOR=7 AARCH32_SP=optee DTB_FILE_NAME=stm32mp157c-dk2.dtb BL33=../u-boot/u-boot-nodtb.bin BL33_CFG=../u-boot/u-boot.dtb BL32=../optee_os/out/arm-plat-stm32mp1/core/tee-header_v2.bin BL32_EXTRA1=../optee_os/out/arm-plat-stm32mp1/core/tee-pager_v2.bin BL32_EXTRA2=../optee_os/out/arm-plat-stm32mp1/core/tee-pageable_v2.bin fip

Copy tf-a-stm32mp157a-dk1.stm32 for stm32mp157a-dk1

#user@localhost:~$
mkdir -p ./input/
cp -v ./trusted-firmware-a/build/stm32mp1/release/tf-a-stm32mp157a-dk1.stm32 ./input/
cp -v ./trusted-firmware-a/build/stm32mp1/release/fip.bin ./input/

Configure and Build: stm32mp157c-dk2

#user@localhost:~$
make -C ./trusted-firmware-a/ CROSS_COMPILE=${CC32} realclean
make -C ./trusted-firmware-a/ CROSS_COMPILE=${CC32} PLAT=stm32mp1 ARCH=aarch32 ARM_ARCH_MAJOR=7 DTB_FILE_NAME=stm32mp157c-dk2.dtb STM32MP_SDMMC=1
make -C ./trusted-firmware-a/ CROSS_COMPILE=${CC32} PLAT=stm32mp1 ARCH=aarch32 ARM_ARCH_MAJOR=7 AARCH32_SP=optee DTB_FILE_NAME=stm32mp157c-dk2.dtb BL33=../u-boot/u-boot-nodtb.bin BL33_CFG=../u-boot/u-boot.dtb BL32=../optee_os/out/arm-plat-stm32mp1/core/tee-header_v2.bin BL32_EXTRA1=../optee_os/out/arm-plat-stm32mp1/core/tee-pager_v2.bin BL32_EXTRA2=../optee_os/out/arm-plat-stm32mp1/core/tee-pageable_v2.bin fip

Copy tf-a-stm32mp157c-dk2.stm32 for stm32mp157c-dk2

#user@localhost:~$
mkdir -p ./input/
cp -v ./trusted-firmware-a/build/stm32mp1/release/tf-a-stm32mp157c-dk2.stm32 ./input/
cp -v ./trusted-firmware-a/build/stm32mp1/release/fip.bin ./input/

Linux Kernel

This script will build the kernel, modules, device tree binaries and copy them to the deploy directory.

Download:

#user@localhost:~$
git clone https://github.com/RobertCNelson/armv7-lpae-multiplatform ./kernelbuildscripts
cd kernelbuildscripts/

For v6.12.x (Longterm 6.12.x):

#user@localhost:~/kernelbuildscripts$
git checkout origin/v6.12.x -b tmp

Build:

#user@localhost:~/kernelbuildscripts$
./build_kernel.sh

Root File System

Debian 12

User Password
debian temppwd

Download:

#user@localhost:~$
wget -c https://rcn-ee.com/rootfs/eewiki/minfs/debian-12.11-minimal-armhf-2025-05-28.tar.xz

Verify:

#user@localhost:~$
sha256sum debian-12.11-minimal-armhf-2025-05-28.tar.xz
#sha256sum output:
805d892548d199bcca75d7cad5feb55b304fa09ee20978b285c315a20a1b8423  debian-12.11-minimal-armhf-2025-05-28.tar.xz

Extract:

#user@localhost:~$
tar xf debian-12.11-minimal-armhf-2025-05-28.tar.xz

Install Kernel and Root File System

To help new users, since the kernel version can change on a daily basis. The kernel building scripts listed on this page will now give you a hint of what kernel version was built.

-----------------------------
Script Complete
eewiki.net: [user@localhost:~$ export kernel_version=5.X.Y-Z]
-----------------------------

Copy and paste that “export kernel_version=5.X.Y-Z” exactly as shown in your own build/desktop environment and hit enter to create an environment variable to be used later.

export kernel_version=5.X.Y-Z

Create Root File System with genimage:

The genimage https://github.com/pengutronix/genimage tool is now used to generate a sdcard.img vs directly interfacing with the microSD.

Host Package Requirements

#user@localhost:~$
sudo apt update ; \
sudo apt-get install -y dosfstools genimage mtools

Create working directory for genimage:

#user@localhost:~$
sudo mkdir -p ./input/.rootfs

Copy Root File System

#Debian; Root File System: user@localhost:~$
sudo tar xfvp ./debian-*-*-armhf-*/armhf-rootfs-*.tar -C ./input/.rootfs/
sync

Enable first boot customization

#user@localhost:~$
sudo mkdir -p ./input/.rootfs/boot/firmware/
sudo cp ./input/.rootfs/etc/bbb.io/templates/sysconf.txt ./input/.rootfs/boot/firmware/

Open ./input/.rootfs/boot/firmware/sysconf.txt in your text editor and change any user setting.

  • user_name=
  • user_password=
  • hostname=
#user@localhost:~$
sudo nano ./input/.rootfs/boot/firmware/sysconf.txt

Setup extlinux.conf

#user@localhost:~$
sudo mkdir -p ./input/.rootfs/boot/extlinux/
sudo sh -c "echo 'label Linux ${kernel_version}' > ./input/.rootfs/boot/extlinux/extlinux.conf"
sudo sh -c "echo '    kernel /boot/vmlinuz-${kernel_version}' >> ./input/.rootfs/boot/extlinux/extlinux.conf"
sudo sh -c "echo '    fdtdir /boot/dtbs/${kernel_version}/' >> ./input/.rootfs/boot/extlinux/extlinux.conf"
sudo sh -c "echo '    append console=ttySTM0,115200 root=/dev/mmcblk0p4 ro rootfstype=ext4 rootwait net.ifnames=0' >> ./input/.rootfs/boot/extlinux/extlinux.conf"

Copy Kernel Image

Kernel Image:

#user@localhost:~$
sudo cp -v ./kernelbuildscripts/deploy/${kernel_version}.zImage ./input/.rootfs/boot/vmlinuz-${kernel_version}

Copy Kernel Device Tree Binaries

#user@localhost:~$
sudo mkdir -p ./input/.rootfs/boot/dtbs/${kernel_version}/
sudo tar xfv ./kernelbuildscripts/deploy/${kernel_version}-dtbs.tar.gz -C ./input/.rootfs/boot/dtbs/${kernel_version}/

Copy Kernel Modules

#user@localhost:~$
sudo tar xfv ./kernelbuildscripts/deploy/${kernel_version}-modules.tar.gz -C ./input/.rootfs/usr/

File Systems Table (/etc/fstab)

#user@localhost:~/$
sudo sh -c "echo '/dev/mmcblk0p4  /  auto  errors=remount-ro  0  1' >> ./input/.rootfs/etc/fstab"

WiFi

#user@localhost:~$
wget -c https://raw.githubusercontent.com/STMicroelectronics/meta-st-stm32mp/refs/heads/scarthgap/recipes-kernel/linux-firmware/linux-firmware/brcmfmac43430-sdio.txt
sudo mkdir -p ./input/.rootfs/usr/lib/firmware/brcm/
sudo cp -v ./brcmfmac43430* ./input/.rootfs/usr/lib/firmware/brcm/

Check partition size

Verify Root File partition size, this can be used to modify the seek value below for size tweaking.

#user@localhost:~$
sudo du -sh ./input/.rootfs/

Create rootfs.ext4

#user@localhost:~$
sudo dd if=/dev/zero of=./input/rootfs.ext4 bs=1 count=0 seek=1600M
sudo mkfs.ext4 -F ./input/rootfs.ext4 -d ./input/.rootfs/

Create sdcard.img with genimage

The genimage https://github.com/pengutronix/genimage tool is now used to generate a sdcard.img vs directly interfacing with the microSD.

Create genimage.cfg file

#user@localhost:~$
nano genimage.cfg
#genimage.cfg
image sdcard.img {
	hdimage {
		partition-table-type = "gpt"
	}

	partition fsbl1 {
		image = "tf-a-stm32mp157c-dk2.stm32"
	}

	partition fsbl2 {
		image = "tf-a-stm32mp157c-dk2.stm32"
	}

	partition fip {
		image = "fip.bin"
		size = 2M
	}

	partition rootfs {
		image = "rootfs.ext4"
		bootable = "yes"
	}
}

Run genimage on genimage.cfg

#user@localhost:~$
genimage --config genimage.cfg

genimage output

sdcard.img can be flashed to a microSD using rpi-imager https://github.com/raspberrypi/rpi-imager or your favorite image writing software.

#user@localhost:~$
tree images/
images/
└── sdcard.img

1 directory, 1 file

Final Tweaks (extend rootfs partition)

Extend the rootfs partition to fill available space on drive.

Use growpart to extend a partition in a partition table

sudo growpart /dev/mmcblk0 4
voodoo@stm32mp1:~$ sudo growpart /dev/mmcblk0 4
CHANGED: partition=4 start=4954 old: size=2048000 end=2052953 new: size=15518853 end=15523806

First Reboot

sudo reboot

Use resize2fs to enlarge the existing filesystem

sudo resize2fs /dev/mmcblk0p4
voodoo@stm32mp1:~$ sudo resize2fs /dev/mmcblk0p4
resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/mmcblk0p4 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p4 is now 1939856 (4k) blocks long.

Second Reboot

This last reboot will take awhile as fsck is checking the partition on bootup.

sudo reboot

Comments

Any questions or comments please go to our TechForum: TechForum

1 Like

A post was split to a new topic: STM32MP157: create sdcard.img

A post was split to a new topic: STM32MP1 remotproc

3 posts were split to a new topic: New Rev: STM32MP157F-DK2