Running firmware on the STM32MP coprocessor

This page describes how to build, deploy, start and control firmware on the Cortex-M coprocessor of our STM32MP modules — STM32MP1 (Cortex-M4, QSMP-1xxx/TXMP-1xxx) and STM32MP2 (Cortex-M33, QSMP-2xxx/TXMP-2xxx) — while Linux runs on the Cortex-A cores. SoC-specific sections are marked with the SoC name. For the host setup (STM32Cube IDE, Developer Package) and the BSP customization see Development environment setup.

Boot modes (STM32MP1)

The STM32MP1 multiprocessor system allows to run independent firmwares on each CPU core:

  • Basicly, on the Cortex®-A7 core a Linux OS is running.

  • In Production boot mode, the Linux OS is loading the firmware on the Cortex®-M4 core and controls it (start/stop). Therefore, the Linux OS integrates the RemoteProc framework.

  • In Engineering boot mode, the firmware on the Cortex®-M4 core is already loaded and started by the bootloader.

  • Inter-processor communication of the two cores is based on RPMsg framework and Mailbox mechanisms.

  • For communication between the LinuxOs and the Cortex®-M4 software, virtual UARTs are implemented by the RPMsg framework.

The STM32MP1 can be run in 2 differents boot modes:

Production boot mode (default mode)

  • Firmware is loaded into the coprocessor by the Cortex®-A7 processor

  • System ressources (clocks, regulators, and so on) are managed directly by Linux

  • the Cortex®-M4 firmware is provided/downloaded in the Linux file system

  • the pre-built firmware is launched on the coprocessor through the Linux Remote Proc framework

  • the firmware on the Cortex®-M4 is started/stopped by the Linux running on the Cortex®-A7.

  • the Cortex®-M4 software can also be loaded by the U-Boot.

Engineering boot mode

  • this mode is used specifically for firmware testing directly on the coprocessor

  • all ressources are managed directly in the example source code (clocks, regulators, and so on)

  • the firmware can be loaded directly from your favorite IDE (JTAG debugger is needed)

important

Engineering bootmode cannot be setup by jumpering on our modules. The module provides only 1 bootmode pin that can select between boot from USB or boot from emmc. The STM32MP1 processor provides 3 bootmode pins to distinguish between different bootmodes. Two of these bootmode pins are fixed by resistors. To setup engineering boot mode for our modules one of the resistors must be changed by soldering. For detailed information about using engineering boot mode, please see Engineering Boot Mode Details

for more informations on using the different boot modes, please read: STM32CubeMP1 development guidelines.

Boot modes (STM32MP2)

The STM32MP2 Cortex-M33 boot mode is configured via BOOT pins, allowing it to act as the primary boot processor (Trusted Domain) from sources like SD-Card/eMMC, or to be started later by the Cortex-A35 (e.g., via Linux/remoteproc), depending on the chosen boot flavor and pin settings.

STM32MP2 supports two possible Trusted Domain (TD) configurations, defining which processor acts as the first trusted core after the ROM code. These configurations affect how the secure boot chain progresses and where trust anchors are placed.

important

Currently, the BSP only supports the A35-TD Flavor Boot Chain.

A35-TD flavor boot chain

Cortex-A35 is booting first. Cortex-M33 is kept under reset by hardware until application request to start it. The Trusted Domain continues on the CA35. After the immutable ROM boot (in the Manufacturer Trusted Domain), the secure boot chain flows directly toward the Cortex-A35.

Boot Sequence:

  1. ROM Code

    • Authenticates and loads next stage, Trusted Firmware-A (TF-A) used as the FSBL

  2. Trusted early boot on CA35

    • In TF-A BL31 - CA35 enters secure mode (EL3)

    • Loads secure monitor, trusted firmware, security services

  3. CA35 launches non-secure OS (Linux)

Result:

  • CA35 is the anchor for the Owner Trusted Domain

  • Secure services executed by the A35 secure monitor (OP-TEE)

  • CM33 is brought up after CA35 and typically runs non-trusted firmware unless OEM places additional constraints.

M33-TD flavor boot chain

The Trusted Domain continues on the CM33. This configuration gives the CM33 ownership of early secure boot and secure services.

Boot Sequence:

  1. ROM Code

    • Authenticates first CM33 firmware image

  2. CM33 secure boot execution

    • CM33 runs the trusted firmware stack

    • CM33 configures security boundaries (firewalls, SAU/IDAU, memory splits)

    • CM33 may host a TEE-like secure environment

  3. CM33 releases CA35

    • CA35 boots into Linux or other OS in non-secure domain

Result:

  • CM33 is the anchor of the Owner Trusted Domain

  • CM33 controls access to security-critical peripherals

  • CA35 is always subordinate to CM33’s security configuration

System resources

  • the GPIO and EXTI configurations are protected from concurrent accesses by hardware semaphores from HSEM.

  • the Cortex®-M4 cannot configure clock and regulator system resources

  • the resource manager (Linux) configures the clocks and the regulators before the Cortex®-M4 starts.

  • at runtime, the Cortex®-M4 STM32Cube application can ask the resource manager to update the clock and regulator configurations

  • in addition to the peripheral configuration, the Cortex®-M4 still has to enable/disable the pheripheral clock.

for further informations, please read the document: How to configure system resources.

Resource manager for coprocessing

The configuration of the system resources for the Cortex®-M is done in the m4_system_resources node of the Linux kernel device tree.

The rproc_srm driver parses this node to configure these resources.

Inside that node, the resources of each device controlled by the coprocessor must be described in a sub-node with the following template:

m4_system_resources {
   compatible = "rproc-srm-core";
   status = "okay";

   /* System resources for peripheral A */
   <m4_aliasA>: <deviceA>@<addressA> {
      compatible = "rproc-srm-dev";
      reg = <...>;
      clocks = <...>;
      clock-names = "...";
      x-supply = <...>;
      status = "okay";
   };

   /* System resources for peripheral B */
   <m4_aliasB>: <deviceB>@<addressB> {
      compatible = "rproc-srm-dev";
      reg = <...>;
      clocks = <...>;
      clock-names = "...";
      x-supply = <...>;
      status = "okay";
   };

};

Please note, that most part of the m4_system_resources node and sub-nodes is already defined (with a ‘disabled’ status) in the ST delivered device tree.

You will find these system resources defined in the file stm32mp15-m4-srm.dtsi.

To declare a resource for the Cortex®-M4, enable the appropriate device in m4_system_resources and disable the device for the Linux use.

example:

Using the QSMP Evalkit, that is utilising the QSMP-1570 module, we want to use the USART2 device by the Cortex®-M4.

As Device Tree is a (Tree) structure, where the leafs set the values, you can overwrite definitions - included by lower dts/dtsi-files - in your local projects’s dts-file.

first, to be sure that the resource manager is enabled:

&m4_rproc {
   m4_system_resources {
      status = "okay";
   };
};

The USART2 device is enabled in the Linux device tree inside the file stm32mp157-qsmp-1570.dts.

so we can disable it with:

&usart2 {
   status = "disable"
};

The m4_usart2 resource is already defined inside the file stm32mp15-m4-srm.dtsi, with status disabled.

So we enable the resource with the following definitions:

&m4_usart2{
   pinctrl-names = "default";
   pinctrl-0 = <&m4_usart2_pins_mx>;
   status = "okay";
};

&pinctrl {
   m4_usart2_pins_mx: m4_usart2_mx-0 {
      pins {
         pinmux =  <STM32_PINMUX('D', 5, RSVD)>, /* USART2_TX */
                   <STM32_PINMUX('D', 6, RSVD)>; /* USART2_RX */
      };
   };
};

for further informations, please read the document: Resource manager for coprocessing.

Deploying the firmware to the target

To start the firmware, we have to deploy it first to the target’s memory. That could be basicly, the internal emmc device of the SOM or the SD-card of the base board. The following example shows, how to deploy the firmware to the internal emmc device.

Note

On STM32MP1, the firmware examples built by the copro distro feature are already in the userfs, so only the firmware search path has to be set as described in Controlling the coprocessor from Linux below.

After building the yocto Linux and programming it with the uuu-tool to the target, we can examine the programmed partitions inside U-Boot:

part list mmc 0
Partition Map for MMC device 0  --   Partition Type: EFI
Part    Start LBA       End LBA         Name
        Attributes
        Type GUID
        Partition GUID
  1     0x00000800      0x000017ff      "fip"
        attrs:  0x0000000000000000
        type:   19d5df83-11b0-457b-be2c-7559c13142a5
                (19d5df83-11b0-457b-be2c-7559c13142a5)
        guid:   aff42d55-134f-449c-b892-92bf1a6f7955
  2     0x00001800      0x000217ff      "boot"
        attrs:  0x0000000000000000
        type:   bc13c2ff-59e6-4262-a352-b275fd6f7172
                (bc13c2ff-59e6-4262-a352-b275fd6f7172)
        guid:   36d1f7ae-9e50-46ce-accf-57989189f556
  3     0x00021800      0x000617ff      "rootfs"
        attrs:  0x0000000000000000
        type:   b921b045-1df0-41c3-af44-4c6f280d3fae
                (b921b045-1df0-41c3-af44-4c6f280d3fae)
        guid:   a0b81ad7-47ec-4181-8b1f-733702fdd8c6
  4     0x00061800      0x00747bff      "userfs"
        attrs:  0x0000000000000000
        type:   b0e01050-ee5f-4390-949a-9101b17104e9
                (b0e01050-ee5f-4390-949a-9101b17104e9)
        guid:   cd07e31f-4090-499c-a02b-7966aa57b421

The “boot”-partition contains the Linux- image and device trees. To store the firmware binary into that partition we use the USB Mass Storage U-Boot function to mount that partition to our Linux host PC:

ums 0 mmc 0:2

Mount the mass storage device on your host machine and copy the firmware .elf-file to the mounted boot-partition.

Stop the ums-device with CTRL + C in U-Boot.

List the contents of the boot-partition from U-Boot to check it:

ls mmc 0:2
16289800 Image
    1302 stm32mp25-karo-copro.dtb
     432 stm32mp25-karo-gpu.dtb
     531 stm32mp25-karo-rtc.dtb
    1075 stm32mp25-txmp-fdcan1.dtb
    1075 stm32mp25-txmp-fdcan2.dtb
     911 stm32mp25-txmp-ft5x06.dtb
    1144 stm32mp25-txmp-keypad.dtb
    7138 stm32mp25-txmp-lcd-panel.dtb
     903 stm32mp25-txmp-mb7-wakeup-btn.dtb
    1244 stm32mp25-txmp-mb7.dtb
     432 stm32mp25-txmp-sdcard1-cd.dtb
     432 stm32mp25-txmp-sdcard2-cd.dtb
    4314 stm32mp25-txmp-sound.dtb
     625 stm32mp25-txmp-spidev.dtb
   97656 stm32mp257f-txmp-2550.dtb
 3412056 OpenAMP_TTY_echo_CM33_NonSecure.elf

Create a firmware folder named /lib/firmware inside your rootfs if it does not already exist.

Copy the firmware image OpenAMP_TTY_echo_CM33_NonSecure.elf into the firmware folder

mkdir /lib/firmware
cp /media/OpenAMP_TTY_echo_CM33_NonSecure.elf /lib/firmware/

Starting the coprocessor from U-Boot

The coprocessor firmware can already be loaded and started by the U-Boot, before the Linux OS is started. For this U-Boot provides the rproc command to init and start the coprocessors. To list all coprocessors available do the following from the U-Boot prompt:

rproc init
rproc list
0 - Name:'m4@10000000' type:'internal memory mapped' supports: load start stop reset is_running

Please note, attention must be payed to the implementation of the Arm Cortex®-M4 firmware if the RPMsg is used to communicate with Linux afterwards. In this case a synchronization is required. The Arm Cortex®-M4 core has to wait until Linux is booted to start RPMsg communications.

for detailed information, please read: How to start the coprocessor from the bootloader.

Controlling the coprocessor from Linux

Basicly the Linux framework expects the firmware for the Cortex-M coprocessor (Cortex®-M4 on STM32MP1, Cortex®-M33 on STM32MP2) stored in the file system, by default in the /lib/firmware/ folder. Optionally another location can be set. In this case the remoteproc framework parses this new path in priority.

Below the command for adding a new path for firmware parsing:

echo -n <firmware_path> > /sys/module/firmware_class/parameters/path

If you want to evaluate one of the predefined samples provided under /usr/local/Cube-M4-examples/STM32MP157C-DK2/ by the Distro Feature copro (STM32MP1), you can setup the firmware path in the following way for the OpenAMP_TTY_echo sample:

echo -n /usr/local/Cube-M4-examples/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo/lib/firmware/ > /sys/module/firmware_class/parameters/path

To load the firmware into the coprocessor by the remoteproc framework, use this command:

echo -n <firmware_name.elf> > /sys/class/remoteproc/remoteproc0/firmware

Start the firmware with this comand:

echo start >/sys/class/remoteproc/remoteproc0/state

This stops the remote processor:

echo stop >/sys/class/remoteproc/remoteproc0/state

For debugging the remote processor you can get debug messages via the remoteproc framework:

cat /sys/kernel/debug/remoteproc/remoteproc0/trace0

Debugging

In case of problems, you can enable dynamic debugging to obtain valuable information.

echo -n 'file stm32-ipcc.c +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'file stm32_rproc.c +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'file remoteproc*.c +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'file virtio_rpmsg_bus.c +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'file virtio_ring.c +p' > /sys/kernel/debug/dynamic_debug/control