Last edited one month ago

How to use USB mass storage in U-Boot

Applicable for STM32MP13x lines, STM32MP15x lines, STM32MP21x lines, STM32MP23x lines, STM32MP25x lines

This page explains how to use the U-Boot command ums to update a SD card or eMMC on the device.

1. ums command[edit | edit source]

In U-Boot, you can directly export the available block devices (mmc/usb) such as USB mass storage devices with ums command:

 help ums
 ums - Use the UMS [USB Mass Storage]
 
 Usage:
 ums <USB_controller> [<devtype>] <dev[:part]>  e.g. ums 0 mmc 0
     devtype defaults to mmc

See U-Boot documentation for details: usage/cmd/ums.html.

This U-Boot command ums is infinite (a loop in USB treatments), and the U-Boot console is blocked until user enters a Ctrl-C.

2. Exporting a block device[edit | edit source]

On STMicroelectronics boards, the OTG USB controller device index is 0, SD card = mmc 0 and, when available, eMMC = mmc 1.
You can check the device connected on an SDMMC with the U-Boot command mmc list and mmc info.

 mmc list 
 STM32 SD/MMC: 0 (SD)
 STM32 SD/MMC: 1 (eMMC)
 mmc info 
 Device: STM32 SD/MMC
 Manufacturer ID: 3
 OEM: 5344
 Name: SS16G 
 Bus Speed: 50000000
 Mode: SD High Speed (50MHz)
 Rd Block Len: 512
 SD version 3.0
 High Capacity: Yes
 Capacity: 14.8 GiB
 Bus Width: 4-bit
 Erase Group Size: 512 Bytes
 mmc dev 1
 switch to partitions #1, OK
 mmc1 is current device
 mmc info   
 Device: STM32 SD/MMC
 Manufacturer ID: 11
 OEM: 0
 Name: 004GA0 
 Bus Speed: 52000000
 Mode: MMC High Speed (52MHz)
 Rd Block Len: 512
 MMC version 5.0
 High Capacity: Yes
 Capacity: 3.7 GiB
 Bus Width: 8-bit
 Erase Group Size: 512 KiB
 HC WP Group Size: 4 MiB
 User Capacity: 3.7 GiB WRREL
 Boot Capacity: 2 MiB ENH
 RPMB Capacity: 512 KiB ENH
 Boot area 0 is not write protected
 Boot area 1 is not write protected

Then, execute one of the following commands:

                                Comments
 ums 0 mmc 0 --> start ums on SD card
 Ctrl-C
                                Comments
 ums 0 mmc 1 --> start ums on eMMC
 Ctrl-C

You can also export a USB device connected to the USB host controller (USBH) = usb 0.

                                Comments
 usb start   --> start USB host controller
 ums 0 usb 0 --> start ums on USB device 0 (USB key for example)
 Ctrl-C
 usb stop    --> stop USB host controller

After a delay (up to 15 seconds), the host sees the exported block device and you can use any command on the PC to access the partitions of the exported memory (dd, mount, cp, rsync). A Ctrl-C is needed to stop the command.

See also How to manually update bootloaders.