Timesys Getting Started Guide for STMicroelectronics STM32MP157F-DK2 Board

$FILE

Contents

Introduction

This document will describe in detail the procedures for booting a Linux kernel image and mounting a root file system from an SD Card on the STMicroelectronics STM32MP157F-DK.

Prerequisites

Host Requirements

To properly boot the STMicroelectronics STM32MP157F-DK using software from Timesys, your host machine must meet the following requirements:
  • Modern GNU/Linux Distribution. Timesys recommends one of the following distributions:
    • Ubuntu (Most recent release or LTS)
    • Fedora (Most recent release)
  • Root or sudo permission on the Development Host.
  • A copy of the Linux Kernel (uImage-6.1-ts-armv7l) and Root File System (rootfs.tar.gz) for the Target Board downloaded from Factory. These are found in the output directory of your online build, or in the directory build_armv7l-timesys-linux-<libc>/images/ on the command line.
  • An available USB port on your Development Host.
  • A SD card slot or adapter on your Development Host.

Target Requirements

To boot the STMicroelectronics STM32MP157F-DK, you will need the following items:
  • STMicroelectronics STM32MP157F-DK
  • Micro SD Card
  • USB Type-C (power 5V-3A)
  • USB micro-B to a host PC that runs as Virtual COM port and debug port.
Once you have all of the necessary components, you should perform the following steps:
  1. Connect the USB micro-B serial cable to CN11. The following connections are relevant:
  2. Insert the SD card into your host machine. You will be loading your boot files onto this device.
  3. Connect the power supply to your board.

Preparing the Target

Configuring Serial Communication

The STM32MP157F-DK uses a serial debug port to communicate with the host machine.

The commands discussed in this section are meant to be performed by a privileged user account. This requires the root login or prepending each command with sudo.

Using Minicom

  1. Start minicom on your host machine in configuration mode. As root:

    # minicom -o -s -w

  2. A menu of configuration should appear. Use the Down-arrow key to scroll down and select the Serial port setup option, and press Enter.
  3. Verify that the listed serial port is the same one that is connected to the target board. If it is not, press A, and enter the correct device. This is /dev/ttyACM0 on most Linux distributions.
  4. Set the Bps/Par/Bits option by pressing the letter E and using the next menu to set the appropriate values. You press the key that corresponds to the value 115200, then press Enter.
  5. Set Hardware flow control to No using the F key.
  6. Set Software flow control to No using the G key.
  7. Press Enter to return to the main configuration menu, and then press Esc to exit this menu.
  8. Reset the board, and wait for a moment. If you do not see output from the board, press Enter several times until you see the prompt. If you do not see any output from the board, and have verified that the serial terminal connection is setup correctly, contact your board vendor.

TIP: If you experience an error similar to Device /dev/ttyACM0 is locked when starting minicom, it usually means that another process is using the serial port (which is usually another instance of minicom). You can find the process that is currently using the serial port by executing the following:

# fuser /dev/ttyACM0
/dev/ttyACM0:         28358

# ps 28358
  PID TTY      STAT  TIME COMMAND
  28923 pts/0    S+    0:00 minicom

This process can also be killed directly with fuser as root. Please use this command with caution:

# fuser -k /dev/ttyACM0

Using GNU Screen

To quickly connect to a board using Gnu Screen, execute the following:

# screen /dev/ttyACM0 115200

For more information about using screen, please consult the man page, or view the manual online at http://www.gnu.org/software/screen/manual/screen.html

Preparing the Secure Digital Card

The STM32MP157F-DK boots from an SD card. Some kits may be shipped with one that contains a sample kernel and RFS preloaded. We will be replacing these with the kernel and RFS from Factory. If you are using a blank SD card or have trouble replacing the software on the preloaded one, see Partitioning the SD Card. Otherwise, skip directly to Writing Boot Files to the SD Card.

Before you begin, you should determine the name of your SD card on your host system. To do so:

  1. Connect the SD card to your host system. Many modern systems have SD card slots on the case, or you can purchase a USB SD Card Reader for around $15 US.
  2. Determine the device name of the SD Card. This can be done using dmesg. In the following example, the device is /dev/sdX, which contains one partition sdX1.

    $ dmesg | tail
    [88050.184080] sd 4:0:0:0: [sdX] 1990656 512-byte hardware sectors: (1.01 GB/972 MiB)
    [88050.184821] sd 4:0:0:0: [sdX] Write Protect is off
    [88050.184824] sd 4:0:0:0: [sdX] Mode Sense: 03 00 00 00
    [88050.184827] sd 4:0:0:0: [sdX] Assuming drive cache: write through
    [88050.185575] sd 4:0:0:0: [sdX] 1990656 512-byte hardware sectors: (1.01 GB/972 MiB)
    [88050.186323] sd 4:0:0:0: [sdX] Write Protect is off
    [88050.186325] sd 4:0:0:0: [sdX] Mode Sense: 03 00 00 00
    [88050.186327] sd 4:0:0:0: [sdX] Assuming drive cache: write through
    [88050.186330]  sdX: sdX1

Partitioning the SD card

If you want to use a different SD card or its contents become corrupted, you can use the fdisk tool to create two partitions on your SD card. Please note that all data on the card will be lost upon completion of these steps.

  1. The minimal partitions requirements for boot are:
  2. A partitions "fsbl1" size at least 256KiB.The size of fip or ssbl partition must be enough for the associated binary file, 4MB and 2MB are default values.
  3. A partitions "fsbl2" size at least 256KiB.The size of fip or ssbl partition must be enough for the associated binary file, 4MB and 2MB are default values.
  4. one partition named "fip" for FIP or U-Boot (TF-A [Trusted Firmware-A ]search the "fip" partition and SPL search the 3th partition.Without FIP support in TF-A, a 3rd partition "fip" for u-boot.stm32 must be named "ssbl".
  5. The 4th, 5th partition are marked as bootable..
  6. As root, run the sgdisk utility on the drive for Delete the existing partition table.

    $ export DISK=/dev/sdb
    $ sudo dd if=/dev/zero of=$DISK bs=1M count=10
    $ sudo sgdisk -o $DISK

  7. In sgdisk, create a new partition table.
    sudo sgdisk --resize-table=128 -a 1 \
    -n 1:34:545         -c 1:fsbl1 \
    -n 2:546:1057               -c 2:fsbl2 \
    -n 3:1058:9249              -c 3:fip \
    -n 4:9250:10273              -c 4:u-boot-env \
    -n 5:10274:414719 -c 5:bootfs -a 5 -A 5:set:2 \
    -n 6:414720: -c 6:rootfs -a 6 -A 6:set:2 \
    -p $DISK
    

  8. Format the 4th, 5th partition using an ext4 filesystem using the mkfs.ext4 tool.

    $ sudo mkfs.ext4 -L bootfs $DISK5
    $ sudo mkfs.ext4 -L rootfs $DISK6

Writing Boot Files to the SD Card

Once you have a properly partitioned SD card, you can then populate it with the boot files generated by Factory.

  1. Mount the partitions. You can remove and reinsert the card to trigger the automount, or you can use the mount command to mount the partition to an arbitrary location.

    $ sudo mount $DISK4 /media/timesys/bootfs
    $ sudo mount $DISK5 /media/timesys/rootfs

  2. copy the tf-a-stm32mp157f-dk.stm32 file to the SD card.

    $ sudo dd if=tf-a-stm32mp157f-dk.stm32 of=$DISK1 conv=fdatasync
    $ sudo dd if=tf-a-stm32mp157f-dk.stm32 of=$DISK2 conv=fdatasync

  3. To create a file with no data but with required size A file with all zero written on it.

    $ sudo dd if=/dev/zero of=$DISK3 conv=fdatasync

  4. Copy fip.bin to the SD card.

    $ sudo dd if=fip.bin of=$DISK3 conv=fdatasync

  5. As root, copy the Image file, uImage-6.1-ts-armv7l, to the boot partition of the card.

    $ sudo cp uImage-6.1-ts-armv7l /media/bootfs/

  6. As root, copy the Device Tree Blob file, stm32mp157f-dk.dtb, to the boot partition of the card.

    $ sudo cp stm32mp157f-dk.dtb /media/bootfs/

  7. As root, extract the rootfs.tar.gz archive to the mounted directory. This file is located at build_armv7l-timesys-linux-<libc>/images/rfs/ on Desktop Factory builds.

    $ sudo tar xzf rootfs.tar.gz -C /media/rootfs

  8. To utilise factory Distro boot feature follow the steps bellow As root, copy the extlinux.conf file to the ext4 partition.

    $ sudo mkdir -p /media/bootfs/extlinux
    $ sudo cp extlinux.conf /media/bootfs/extlinux

    NOTE: Board will automatically boot by utilizing the environment variables specified in "extlinux.conf" file.

  9. As root, umount the SD Card.

    $ sync
    $ sudo umount $DISK*

  10. Remove the SD Card from the host machine, and insert it into the SD Card slot on the target board CN3. You should hear the card 'click' into place.

  11. Power on or press B2 to reset the board.

Preparing the Host

No additional host setup is required to boot from SD.

Booting the Board

Set Environment Variables

You must set a few environment variables in order to boot the board from the SD card. This is done with the setenv and saveenv commands in U-Boot.

On the target, set the following environment variables:

Variable Value          
bootargs console=ttySTM0,115200 root=/dev/mmcblk0p5 rootdelay=3 rw earlycon          
load_kernel ext4load mmc 0:4 0xc2000000 uImage-6.1-ts-armv7l          
load_dtb ext4load mmc 0:4 0xc4000000 stm32mp157f-dk.dtb          
bootcmd mmc rescan\; run load_kernel load_dtb\; bootm 0xc2000000 - 0xc4000000          

Example

> setenv bootargs console=ttySTM0,115200 root=/dev/mmcblk0p5 rootdelay=3 rw earlycon
> setenv load_kernel ext4load mmc 0:4 0xc2000000 uImage-6.1-ts-armv7l
> setenv load_dtb ext4load mmc 0:4 0xc4000000 stm32mp157f-dk.dtb
> setenv bootcmd mmc rescan\; run load_kernel load_dtb\; bootm 0xc2000000 - 0xc4000000
> saveenv

Load The Kernel

You can use the mmc subsystem to load the kernel from the SD card.

Example

> mmc rescan
> ext4load mmc 0:4 0xc2000000 uImage-6.1-ts-armv7l
reading uImage-6.1-ts-armv7l

3008612 bytes read

Load The Device Tree

You can use the mmc subsystem to load the device tree file (dtb) from the SD card.

Example

> mmc rescan
> ext4load mmc 0:4 0xc4000000 stm32mp157f-dk.dtb
reading stm32mp157f-dk.dtb

24612 bytes read

Boot the Kernel

The bootm command is used to boot the kernel. It loads the file that was previously loaded using the ext4load command.

Example

> bootm 0xc2000000 - 0xc4000000
## Booting kernel from Legacy Image at 0xc2000000 ..
   Image Name:   Linux-6.1
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3008548 Bytes =  2.9 MB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
## Flattened Device Tree blob at 0xc4000000
   Booting using the fdt blob at 0xc4000000
   Loading Kernel Image ... OK
OK

Additional Information

Factory Documentation