Last edited one month ago

How to load U-Boot with STM32CubeProgrammer

Applicable for STM32MP13x lines  STM32MP15x lines    STM32MP23x lines  STM32MP25x lines

This page explains how to load and start U-Boot with STM32CubeProgrammer over a UART or USB port.

1. Overview[edit | edit source]

To load and execute U-Boot (the programming service) in DDR with STM32CubeProgrammer, you need first to follow the steps described in AN5275: USB DFU/USART protocols used in STM32MP1 series bootloaders:

  • STM32MP1 series
  1. Download phase 0x1 by ROM code, the FSBL = TF-A BL2
  2. Download phase 0x3 by FSBL, the FIP file including the SSBL image: U-Boot
  • STM32MP2 series
  1. Download phase 0x1 by ROM code, the FSBL = TF-A BL2
  2. Download phase 0x2 by FSBL, the FIP file including the DDR settings
  3. Download phase 0x3 by FSBL, the FIP file including the SSBL image: U-Boot

The FSBL, SSBL and FIP definitions can be found in the Boot chain overview (FIP includes the required SSBL).

This feature can be used to debug U-Boot features required for the programming service (USB support, Flash device support, and so on) during board bring-up.

See FAQ of STM32CubeProgrammer for answers to questions specific to this tool.

For information, the required DFU detach is automatically managed by STM32CubeProgrammer when flashlayout is used or with start command in CLI mode.

2. Prepare U-Boot to use the console[edit | edit source]

By default in the STM32 boot command the stm32prog command is executed when the boot device is UART or USB to allow U-Boot (the programming service) to communicate with STM32CubeProgrammer.

To access to U-Boot console when U-Boot is loaded with STM32CubeProgrammer:

  • For USB boot, you can easily interrupt this command stm32prog usb 0by pressing Ctrl + C in the console without U-Boot modification.
  • For UART boot, the U-Boot console is deactivated to execute the stm32prog serial ${boot_instance} command in the bootcmd.
    To use the U-Boot console after STM32CubeProgrammer load, you can deactivate this behavior by:
    • deactivate CONFIG_CMD_STM32PROG_SERIAL using one of the following method:
      • use make menuconfig as explained in Kbuild
      • add the line # CONFIG_CMD_STM32PROG_SERIAL is not set in your defconfig (for example in stm32mp13_defconfig, stm32mp15_defconfig or stm32mp25_defconfig)
    • recompile U-Boot

3. Load U-Boot using Flashlayout.tsv file[edit | edit source]

You can use a minimal "FlashLayout.tsv" files for <dev> serial boot, <dev>=usb or uart (see STM32CubeProgrammer_flashlayout for file format details):

  • for STM32MP1 series:
 #Opt	id	Name	Type		IP		Offset		Binary
 -	0x01	fsbl		Binary		none	0x00000000	tf-a_<dev>.stm32
 -	0x03	fip		FIP		none	0x00000000	fip.bin
  • for STM32MP2 series:
 #Opt	id	Name	Type		IP		Offset		Binary
 -	0x01	fsbl		Binary		none	0x00000000	tf-a_<dev>.stm32
 -	0x02	fip		FIP		none	0x00000000	fip_ddr.bin
 -	0x03	fip		FIP		none	0x00000000	fip.bin

You can then use this with STM32CubeProgrammer command:

 STM32_Programmer_CLI -c port=<dev_port> -w FlashLayout.tsv

With

  • For USB: <dev> = usb and <dev_port>=usb1
  • For UART: <dev> =uart and <dev_port>= UART Interface identifier (ex COM1, /dev/ttyS0,...)

4. Load U-Boot using CLI[edit | edit source]

You can also use the CLI interface with the options -d and -s to load and start U-Boot.

 STM32_Programmer_CLI --help
 Available commands for STM32 MPU:
 ..
  -s,     --start          
  -g,     --go           : Run the code at the specified partition ID.
      [<partitionID>]    : Partition ID
                           If not specified, last loaded partition
                           will be started
 ..
  -d,     --download     : Download the content of a file into device memory
      <file_path>        : File path name to be downloaded: (bin, stm32 file
      <partition_id>     : Partition ID to be downloaded

For serial USB boot, <dev>=usb device with port=usb1.

  • for STM32MP1 series
 STM32_Programmer_CLI -c port=usb1 \
    -d tf-a_usb.stm32 0x1 -s 0x1 \
    -d fip.bin 0x3 -s 0x3
  • for STM32MP2 series
 STM32_Programmer_CLI -c port=usb1 \
    -d tf-a_usb.stm32 0x1 -s 0x1 \
    -d fip_ddr.bin 0x2 -s 0x2 \
    -d fip.bin 0x3 -s 0x3

It is the same for serial UART boot with <dev>=uart and port= the UART Interface identifier.

When U-Boot is loaded, the stm32prog command is executed and it is waiting a .stm32 file flashlayout.stm32 in phase 0x0.

This command can be interrupted by enter aCtrl + C on the U-Boot console.

5. Load U-Boot script using CLI[edit | edit source]

When U-Boot receives in phase 0x0 a U-Boot script script.bin with U-Boot image header added by mkimage U-Boot tool, this script will be executed automatically by U-Boot.

Example for a simple script to start U-Boot in dfu mode and then reset:

dfu 0
reset
echo "dfu 0; reset" > script.cmd
mkimage -C none -A arm -T script -d script.cmd script.bin
  • for STM32MP1 series
 STM32_Programmer_CLI -c port=usb1 \
    -d tf-a_usb.stm32 0x1  -s 0x1 \
    -d fip.bin 0x3 -s 0x3 \
    -d script.bin 0x0 -s 0x0 --detach
  • for STM32MP2 series
 STM32_Programmer_CLI -c port=usb1 \
    -d tf-a_usb.stm32 0x1  -s 0x1 \
    -d fip_ddr.bin 0x2 -s 0x2 \
    -d fip.bin 0x3 -s 0x3 \
    -d script.bin 0x0 -s 0x0 --detach