This page explains how to load and start U-Boot with the dfu-util
[1] tool over a USB port.
This tool, available on Linux or Windows, supports the DFU standard [2] and can replace STM32CubeProgrammer for the U-Boot load use case.
1. Overview[edit source]
To load and execute U-Boot in DDR with the DFU protocol, the dfu-util
tools can be used instead of STM32CubeProgrammer.
As the GetPhase is an STMicroelectronics protocol for STM32CubeProgrammer and is not supported by dfu-util
, you must follow the steps described in AN5275: USB DFU/USART protocols used in STM32MP1 Series bootloaders and provide the binaries in the order expected by the bootloaders:
- Download phase 0x1 by ROM code is the FSBL (TF-A BL2)
- DFU detach to request an FSBL start - not required for STM32MP15x lines
ROM code
- Download phase 0x3 by FSBL is the FIP file including the SSBL image (U-Boot)
- DFU detach to request an SSBL start
The FSBL, SSBL and FIP definitions can be found in the Boot chain overview.
The FIP includes the required SSBL = U-Boot, see How to configure TF-A FIP in order to update it with the U-Boot binary.
This feature can be used to debug U-Boot during board bring-up.
See also How to load U-Boot with STM32CubeProgrammer.
2. dfu-util[edit source]
The help message of dfu-util
is:
dfu-util --help
The minimal dfu-util
option used to load U-Boot is:
- -a/--alt select the alternate to load the requested phase
- -D/--download Download the requested binary for the selected phase
- -e/--detach request a DFU DETACH
2.1. Identify alternate[edit source]
You can also use the -l/--list option to check the alternate associated to each phase (see AN5275 for the coding of the alternate name).
For example the result of this command on ROM code with a USB serial boot is:
2.2. Select device[edit source]
In each dfu-util
command, the command device can be identified by:
- USB vendor and product identifiers (VID and PID)
- USB serial number
In the previous STM32MP15 example, the device has VID:PID=0483:df11 and its serial number is 004100323338511634383330.
In the following sections, you can add the -d/--device and -S/--serial options to select this specific device:
-d 0483:df11 -S 004100323338511634383330 ....dfu-util
It is required only when several devices are connected on the host.
3. The U-Boot load sequence[edit source]
The load sequence is described in #Overview, depending of the alternate (phase = P for alternate A) and the corresponding commands are:
- Download phase P =
dfu-util -a A -D [file]
- DFU detach =
dfu-util -a 0 -e
3.1. On STM32MP15x lines
[edit source]
1 -D tf-a-usb.stm32 dfu-util -a 3 -D fip.bin dfu-util -a 0 -edfu-util -a
3.2. On STM32MP13x lines
[edit source]
0 -D tf-a-usb.stm32 dfu-util -a 0 -e dfu-util -a 0 -D fip.bin dfu-util -a 0 -edfu-util -a
4. U-Boot DFU support[edit source]
After load sequence, U-Boot is running, the boot command is executed, the DFU stack is running and the stm32prog
is waiting the FlashLayout file before to reenumerate. you can:
- provided the flashlayout file in alternate 0: flashlayout.tsv or flashlayout.stm32, the same file with STM32 header:
0 -D flashlayout.tsv dfu-util -a 0 -edfu-util -a
- interrupt the
stm32prog
command by sending a Ctrl-C on the console or sending an empty flashlayout with 2 DFU detach:
-e dfu-util -a 0 -edfu-util -a 0
- request device reboot by a USB reset with option -R --reset:
-e -Rdfu-util -a 0
- #Execute a U-Boot script as explained in the next chapter
4.1. Generate an flashlayout.stm32 file[edit source]
You can generate the flashlayout.stm32 file from the tsv flashlayout file = flashlayout.tsv with the U-Boot mkimage
tool by using the following Linux shell commands:
flashlayout.tsv flashlayout.stm32mkimage -T stm32image -a 0xC0000000 -e 0xC0000000 -d
4.2. Execute a U-Boot script[edit source]
You can replace the flashlayout file with a U-Boot script containing a U-Boot image header. This is then executed automatically by U-Boot.
The following example is for a simple script to start U-Boot in dfu mode and then reset:
dfu 0
reset
script.uimgecho "dfu 0; reset" > script.cmd mkimage -C none -A arm -T script -d script.cmd
Then the complete sequence is:
1 -D tf-a-usb.stm32 dfu-util -a 3 -D fip.bin dfu-util -a 0 -e dfu-util -a 0 -D script.uimg dfu-util -a 0 -edfu-util -a
0 -D tf-a-usb.stm32 dfu-util -a 0 -e dfu-util -a 0 -D fip.bin dfu-util -a 0 -e dfu-util -a 0 -D script.uimg dfu-util -a 0 -edfu-util -a
5. GetPhase support with dfu-util[edit source]
The GetPhase is an STMicroelectronics addition, on top of DFU, not supported by dfu-util, see AN5275: USB DFU/USART protocols used in STM32MP1 Series bootloaders for details.
The expected Phase P and the expected DFU detach request are indicated by device in the Get Phase answer, read (= DFU_UPLOAD) in the last alternate, with alternate id = A, name = "virtual" with phase id = 0xF1 with the command:
A -U phase.bindfu-util -a
The format of the received data, the phase.bin file in this example, is:
Byte | Name | Description |
---|---|---|
1 | Phase | Phase P expected by device |
2-5 | Address | 0xFFFFFFFF or load address in embedded RAM |
6-9 | Offset | 0x0 |
10 | NeedDFUDetach | Present only if P = 0 1 : DFU detach is requested for a new USB enumeration |
This information can be used to dynamically manage the load sequence in script using dfu-util
as it is done in STM32CubeProgrammer.
6. References[edit source]
- ↑ dfu-util - Device Firmware Upgrade Utilities - http://dfu-util.sourceforge.net
- ↑ USB DFU - Universal Serial Bus Device Class Specification for Device Firmware Upgrade Version 1.1 - https://usb.org/sites/default/files/DFU_1.1.pdf