U-Boot recovery for STM32MP1 DHSOM via DFU

From Wiki-DB
Jump to navigationJump to search


To recover a corrupted U-Boot on a STM32MP1-based DHCOM, we can use the default fallback boot source DFU via serial link or USB to temporarily boot U-Boot SPL and U-Boot. From this U-Boot shell we can write both bootloader images from the SD card to the boot flash.

Requirements

Software

Hardware

  • STM32MP1 based DHCOM
  • DHCOM Premium Developer Kit Baseboard (or Baseboards with OTG ports)
  • USB cable for OTG port (Mini USB for PDK2, USB-C for PDK3)

Preparation

This installation was made on the Virtual Machine for Application Development. All console expressions refer to this Debian system, but any other debian based system should also work.

Install dfu-util (debian)

apt-get install dfu-util

Download/Build U-Boot SPL and U-Boot binaries

Download prebuilt binaries

Dropbox: U-Boot_recovery_for_STM32MP1_DHSOM_via_DFU (source)

curl -LsS https://www.dropbox.com/sh/os9so01tivajkxs/AACQ30W-7l-Zi_Zutu0Zv-Zua > recovery_binaryies.zip
unzip recovery_binaryies.zip
Archive:  recovery_binaryies.zip
warning:  stripped absolute path spec from /
mapname:  conversion of  failed
   creating: U-Boot_v2022.04_mainline/
   creating: U-Boot_v2022.04_mainline/av96/
   creating: U-Boot_v2022.04_mainline/pdk2/
   creating: U-Boot_v2022.04_mainline/drc02/
   creating: U-Boot_v2022.04_mainline/picoitx/
 extracting: U-Boot_v2022.04_mainline/av96/u-boot.itb  
 extracting: U-Boot_v2022.04_mainline/pdk2/u-boot.itb  
 extracting: U-Boot_v2022.04_mainline/drc02/u-boot.itb  
 extracting: U-Boot_v2022.04_mainline/picoitx/u-boot.itb  
 extracting: U-Boot_v2022.04_mainline/av96/u-boot-spl.stm32  
 extracting: U-Boot_v2022.04_mainline/pdk2/u-boot-spl.stm32  
 extracting: U-Boot_v2022.04_mainline/drc02/u-boot-spl.stm32  
 extracting: U-Boot_v2022.04_mainline/picoitx/u-boot-spl.stm32

Build binaries from source

Clone U-Boot mainline source code for release v2022.04:

UBOOT_SRC=/work/dev/u-boot_v2022.04
mkdir -p $UBOOT_SRC
git clone --branch v2022.04 --depth 1 https://source.denx.de/u-boot/u-boot.git $UBOOT_SRC
cd $UBOOT_SRC

Available U-Boot defconfigs for STM32MP1 based DHSOM devices with default device tree in bold:

  • stm32mp15_dhcom_basic_defconfig (pdk2, picoitx, drc02)
  • stm32mp15_dhcor_basic_defconfig (avenger96)
mkdir -p /work/dev/u-boot
git clone https://source.denx.de/u-boot/u-boot.git -b v2022.04 /work/dev/u-boot
cd /work/dev/u-boot
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make stm32mp15_dhcom_basic_defconfig

Change default device tree (Example for: stm32mp15xx-dhcom-picoitx):

sed -iE 's/(stm32mp15xx-dhcom-pdk2|stm32mp157a-dhcor-avenger96)/stm32mp15xx-dhcom-picoitx/' .config

Build linux binaries with all available cores:

ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make -j$(nproc)
...
SHIPPED dts/dt.dtb
CAT     u-boot-dtb.bin
MKIMAGE u-boot.img
COPY    u-boot.dtb
MKIMAGE u-boot-dtb.img
MKIMAGE u-boot.itb
...
LD      spl/u-boot-spl
OBJCOPY spl/u-boot-spl-nodtb.bin
SYM     spl/u-boot-spl.sym
CAT     spl/u-boot-spl-dtb.bin
COPY    spl/u-boot-spl.bin
BINMAN  all

Check that the required binaries have been created and are of the appropriate size:

ls -l u-boot.itb u-boot-spl.stm32
-rw-r--r-- 1 devel devel 819720 Apr 11 17:03 u-boot.itb
-rw-r--r-- 1 devel devel 124288 Apr 11 17:03 u-boot-spl.stm32

U-Boot booting via DFU

To boot U-Boot SPL and U-Boot via DFU boot mode, you must first check if you have a DFU device connected, then load U-Boot SPL into the SRAM of your STM32MP1 and wait until the DRAM is initialized. Then load U-Boot in the DRAM of your STM32MP1 and continue the boot process using the shown key combination.

Check for available DFU device

(Re-)Connect the USB cable with your host computer and the OTG port of your baseboard and check the kernel log for a available DFU device:

sudo dmesg
...
usb 2-2: New USB device found, idVendor=0483, idProduct=df11, bcdDevice= 2.00
usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-2: Product: DFU in HS Mode @Device ID /0x500, @Revision ID /0x0000
usb 2-2: Manufacturer: STMicroelectronics
usb 2-2: SerialNumber: 0040001D3130510439373430

Download of U-Boot SPL with dfu-util

Download of U-Boot SPL with dfu-util to connected device:

dfu-util -a 1 -D u-boot-spl.stm32
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 0110
Claiming USB DFU Interface...
Setting Alternate Setting #1 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0110
Device returned transfer size 1024
Copying data from PC to DFU device
Download	[=========================] 100%       160911 bytes
Download done.
state(7) = dfuMANIFEST, status(0) = No error condition is present
state(2) = dfuIDLE, status(0) = No error condition is present
Done!

Output of the serial console:

U-Boot SPL 2022.04 (Apr 05 2022 - 08:27:30 +0200)
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)
Code:  SoM:rev=1,ddr3=3 Board:rev=0
RAM: DDR3L 32bits 2x4Gb 533MHz
Trying to boot from DFU

Download of U-Boot with dfu-util

Download of U-Boot with dfu-util to connected device:

dfu-util -a 0 -D u-boot.itb
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 0110
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0110
Device returned transfer size 4096
Copying data from PC to DFU device
Download	[=========================] 100%       819232 bytes
Download done.
state(7) = dfuMANIFEST, status(0) = No error condition is present
state(2) = dfuIDLE, status(0) = No error condition is present
Done!

Output of the serial console:

#DOWNLOAD ... OK
Ctrl+C to exit ...

Output of the serial console after pressing Ctrl+C:

U-Boot 2022.04 (Apr 05 2022 - 08:27:30 +0200)

CPU: STM32MP157CAA Rev.Z
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)
Board: stm32mp1 in basic mode (dh,stm32mp15xx-dhcom-pdk2)
DRAM:  1 GiB
Clocks:
- MPU : 650 MHz
- MCU : 208.878 MHz
- AXI : 266.500 MHz
- PER : 24 MHz
- DDR : 533 MHz
Core:  255 devices, 31 uclasses, devicetree: separate
MMC:   STM32 SD/MMC: 2, STM32 SD/MMC: 0, STM32 SD/MMC: 1
Loading Environment from SPIFlash... SF: Detected w25q16cl with page size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@5800a000, eth1: ks8851mll@64000000
Hit any key to stop autoboot:  0

Troubleshooting

If there is a U-Boot starting, the DFU procedure may not work properly. There are two solutions to prevent the start of U-Boot from the SPI-NOR-Flash.

SD card boot mode (only HS00014)

  1. Boot in SD card boot mode to prevent booting the broken U-Boot from SPI-NOR-Flash
    1. Hold the button for SD card boot mode on the SODIMM-200 module (DHCOM) below the eMMC chip.
    2. Reset the device. To reset the device, press the reset button on the baseboard or unplug and plug in the power plug.
    3. Release the button for SD card boot mode
  2. If no new output is printed on the serial console (serial port), continue with the DFU booting procedure

Delete U-Boot

  1. sf probe
  2. sf erase 0x0 0xf0000
  3. Restart the board
  4. If no new output is printed on the serial console (serial port), continue with the DFU booting procedure