U-Boot recovery for STM32MP1 DHSOM via DFU: Difference between revisions
Ageisreiter (talk | contribs) |
Jneuhauser (talk | contribs) →U-Boot booting via DFU: Add kernel log check also for USB download gadget |
||
(2 intermediate revisions by the same user not shown) | |||
Line 32: | Line 32: | ||
=== Download/Build U-Boot SPL and U-Boot binaries === | === Download/Build U-Boot SPL and U-Boot binaries === | ||
There are two ways to get the required U-Boot binaries. | |||
These can either be downloaded or built from the sources by yourself. | |||
Follow one of the two steps below. | |||
==== Download prebuilt binaries ==== | ==== Download prebuilt binaries ==== | ||
Line 120: | Line 124: | ||
Then load U-Boot in the DRAM of your STM32MP1 and continue the boot process using the shown key combination. | Then load U-Boot in the DRAM of your STM32MP1 and continue the boot process using the shown key combination. | ||
=== | === Download of U-Boot SPL with <code>dfu-util</code> === | ||
(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: | (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: | ||
<syntaxhighlight lang="shell"> | <syntaxhighlight lang="shell"> | ||
sudo dmesg | sudo dmesg | ||
Line 134: | Line 138: | ||
usb 2-2: SerialNumber: 0040001D3130510439373430 | usb 2-2: SerialNumber: 0040001D3130510439373430 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Download of U-Boot SPL with dfu-util to connected device: | Download of U-Boot SPL with dfu-util to connected device: | ||
Line 177: | Line 179: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Download of U-Boot with <code>dfu-util</code> === | === Download of U-Boot with <code>dfu-util</code> === | ||
(Re-)Connect the USB cable with your host computer and the OTG port of your baseboard and check the kernel log for a available '''USB download gadget''' device: | |||
<syntaxhighlight lang="shell"> | |||
sudo dmesg | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="console" highlight="5"> | |||
... | |||
usb 3-2: new high-speed USB device number 8 using xhci_hcd | |||
usb 3-2: New USB device found, idVendor=0483, idProduct=df11, bcdDevice= 2.27 | |||
usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 | |||
usb 3-2: Product: USB download gadget | |||
usb 3-2: Manufacturer: dh | |||
</syntaxhighlight> | |||
Download of U-Boot with dfu-util to connected device: | Download of U-Boot with dfu-util to connected device: |
Latest revision as of 08:42, 9 September 2022
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
- Linux host computer (Virtual Machine for Application Development is used in this guide)
- U-Boot 2022.04 for your board (download and build instructions below)
- dfu-util (for DFU boot mode)
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) (for DFU boot mode)
- SD card (for SD card boot mode)
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
There are two ways to get the required U-Boot binaries. These can either be downloaded or built from the sources by yourself. Follow one of the two steps below.
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.
Download of U-Boot SPL with dfu-util
(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 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
(Re-)Connect the USB cable with your host computer and the OTG port of your baseboard and check the kernel log for a available USB download gadget device:
sudo dmesg
...
usb 3-2: new high-speed USB device number 8 using xhci_hcd
usb 3-2: New USB device found, idVendor=0483, idProduct=df11, bcdDevice= 2.27
usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 3-2: Product: USB download gadget
usb 3-2: Manufacturer: dh
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
U-Boot booting via SD card
Set the disk:
STM32_DISK=/dev/sdc
Partition a SD card
Create partition table and partitions:
parted --script -- ${STM32_DISK} \
mktable gpt \
mkpart fsbl1 1MiB 1.25MiB \
mkpart fsbl2 2MiB 2.25MiB \
mkpart ssbl 3MiB 5MiB \
mkpart rootfs ext4 5MiB 100% \
set 4 legacy_boot on \
unit MiB \
print
Model: Generic STORAGE DEVICE (scsi)
Disk /dev/sdc: 954MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1.00MiB 1.25MiB 0.25MiB fsbl1
2 2.00MiB 2.25MiB 0.25MiB fsbl2
3 3.00MiB 5.00MiB 2.00MiB ssbl
4 5.00MiB 953MiB 948MiB ext4 rootfs legacy_boot
Redetect partitions:
partprobe ${STM32_DISK}
Create file system on partition 4
Create filesystem on partition 4:
mkfs.ext4 -m 0 -L rootfs ${STM32_DISK}4
mke2fs 1.46.2 (28-Feb-2021)
Creating filesystem with 242688 4k blocks and 60672 inodes
Filesystem UUID: bda8eff7-aa5a-4ed8-aa53-f22e3a1e3203
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
Write U-Boot SPL and U-Boot to the SD card
Write u-boot spl and u-boot to boot partitions 1, 2 and 3:
dd if=u-boot-spl.stm32 of=${STM32_DISK}1
dd if=u-boot-spl.stm32 of=${STM32_DISK}2
dd if=u-boot.itb of=${STM32_DISK}3
314+1 records in
314+1 records out
160911 bytes (161 kB, 157 KiB) copied, 0.274919 s, 585 kB/s
314+1 records in
314+1 records out
160911 bytes (161 kB, 157 KiB) copied, 0.280309 s, 574 kB/s
1600+1 records in
1600+1 records out
819232 bytes (819 kB, 800 KiB) copied, 0.862246 s, 950 kB/s
Copy u-boot spl and u-boot to directory boot
on rootfs partition 4:
mkdir -p rootfs
mount ${STM32_DISK}4 rootfs
mkdir -p rootfs/boot
cp u-boot-spl.stm32 u-boot.itb rootfs/boot/
umount rootfs && rmdir rootfs
Boot from SD card
- Hold the button for SD card boot mode on the SODIMM-200 module (DHCOM) below the eMMC chip.
- Reset the device. To reset the device, press the reset button on the baseboard or unplug and plug in the power plug.
- Release the button for SD card boot mode
U-Boot flashing via SD card
Write U-Boot SPL and U-Boot to the SD card
Follow the instructions in U-Boot booting via SD card to prepare an SD card with a file system on partition 4 that contains the required u-boot-spl.stm32
and u-boot.itb
binaries.
Write U-Boot SPL and U-Boot to SPI-NOR-Flash
- Start U-Boot by U-Boot booting via DFU or by Boot from SD card
- Attach prepared SD card to the on module SD card slot
- Program U-Boot SPL and U-Boot by the script
update_sf
stored in the U-Boot environment.STM32MP> run update_sf
160911 bytes read in 80 ms (1.9 MiB/s) 819232 bytes read in 115 ms (6.8 MiB/s) SF: Detected w25q16cl with page size 256 Bytes, erase size 4 KiB, total 2 MiB SF: 2097152 bytes @ 0x0 Erased: OK device 0 offset 0x0, size 0x2748f 160911 bytes written, 0 bytes skipped in 1.664s, speed 98903 B/s device 0 offset 0x40000, size 0x2748f 160911 bytes written, 0 bytes skipped in 1.626s, speed 101211 B/s device 0 offset 0x80000, size 0xc8020 815136 bytes written, 4096 bytes skipped in 8.379s, speed 100094 B/s