USB mass storage in U-Boot
Udev Rules
- Die SD Karte in den STM32MP1 Boards kann per USB OTG an den Entwicklungsrechner als USB mass storage device eingeblendet werden
- Der Export des Gerätes erfolgt aus U-Boot heraus
- Geeignete Zugriffsrechte auf die entsprechenden block devices zum Schreiben der SD Card images werden per udev Regeln eingerichtet
- In /etc/udev/rules folgende Date 50-st-usb-msc.rules anlegen:
50-st-usb-msc.rules
# allow UMS_disk_0 access to everybody SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5720", \ MODE="666", GROUP="plugdev", TAG+="uaccess", ENV{ID_MM_DEVICE_IGNORE}="1", \ SYMLINK+="st-usb-msc_%n"
Modifizierte Variante
- Versuch der Differenzierung bei mehreren Boards am gleichen Rechner / Server
- alle MSC (Mass Storage Controller) Geräte teilen ein Wurzelverzeichnis
- Verschiedene Endpunkte erhalten eigene Unterverzeichnisse, die als Namen die Geräte ID tragen (%b)
- die Geräte ID ergibt sich fest aus der zugeordneten USB Buchse bzw. der ID des USB Hubs
- Tabelle der Zuordnungen der eindeutigen ST Link IDs zu USB Device ID / USB Buchse muss einmalig händisch erfolgen
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5720", \ MODE="0660", GROUP="users", TAG+="uaccess", ENV{ID_MM_DEVICE_IGNORE}="1", \ SYMLINK+="stm32mp1/%b/msc%n"
- Im Beispiel am MSC Device /dev/sda ergibt sich die Device ID 1-1.4
root@endurance:/local/itservice# udevadm info -a -p $(udevadm info -q path -n /dev/sda) Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/pci0000:00/0000:00:15.0/usb1/1-1/1-1.4/1-1.4:1.0/host1/target1:0:0/1:0:0:0/block/sda': KERNEL=="sda" SUBSYSTEM=="block" DRIVER=="" ATTR{alignment_offset}=="0" ATTR{capability}=="51" ATTR{discard_alignment}=="0" ATTR{events}=="media_change" ATTR{events_async}=="" ATTR{events_poll_msecs}=="-1" ATTR{ext_range}=="256" ATTR{hidden}=="0" ATTR{inflight}==" 0 0" ATTR{integrity/device_is_integrity_capable}=="0" ATTR{integrity/format}=="none" ATTR{integrity/protection_interval_bytes}=="0" ATTR{integrity/read_verify}=="0" ATTR{integrity/tag_size}=="0" ATTR{integrity/write_generate}=="0" ATTR{mq/0/cpu_list}=="0, 1, 2, 3" ATTR{mq/0/nr_reserved_tags}=="0" ATTR{mq/0/nr_tags}=="1" ATTR{power/async}=="disabled" ATTR{power/control}=="auto" ATTR{power/runtime_active_kids}=="0" ATTR{power/runtime_active_time}=="0" ATTR{power/runtime_enabled}=="disabled" ATTR{power/runtime_status}=="unsupported" ATTR{power/runtime_suspended_time}=="0" ATTR{power/runtime_usage}=="0" ATTR{queue/add_random}=="1" ATTR{queue/chunk_sectors}=="0" ATTR{queue/dax}=="0" ATTR{queue/discard_granularity}=="0" ATTR{queue/discard_max_bytes}=="0" ATTR{queue/discard_max_hw_bytes}=="0" ATTR{queue/discard_zeroes_data}=="0" ATTR{queue/fua}=="0" ATTR{queue/hw_sector_size}=="512" ATTR{queue/io_poll}=="0" ATTR{queue/io_poll_delay}=="-1" ATTR{queue/io_timeout}=="30000" ATTR{queue/iosched/fifo_batch}=="16" ATTR{queue/iosched/front_merges}=="1" ATTR{queue/iosched/read_expire}=="500" ATTR{queue/iosched/write_expire}=="5000" ATTR{queue/iosched/writes_starved}=="2" ATTR{queue/iostats}=="1" ATTR{queue/logical_block_size}=="512" ATTR{queue/max_discard_segments}=="1" ATTR{queue/max_hw_sectors_kb}=="120" ATTR{queue/max_integrity_segments}=="0" ATTR{queue/max_sectors_kb}=="120" ATTR{queue/max_segment_size}=="65536" ATTR{queue/max_segments}=="2048" ATTR{queue/minimum_io_size}=="512" ATTR{queue/nomerges}=="0" ATTR{queue/nr_requests}=="2" ATTR{queue/nr_zones}=="0" ATTR{queue/optimal_io_size}=="0" ATTR{queue/physical_block_size}=="512" ATTR{queue/read_ahead_kb}=="128" ATTR{queue/rotational}=="1" ATTR{queue/rq_affinity}=="1" ATTR{queue/scheduler}=="[mq-deadline] none" ATTR{queue/stable_writes}=="0" ATTR{queue/wbt_lat_usec}=="75000" ATTR{queue/write_cache}=="write back" ATTR{queue/write_same_max_bytes}=="0" ATTR{queue/write_zeroes_max_bytes}=="0" ATTR{queue/zone_append_max_bytes}=="0" ATTR{queue/zoned}=="none" ATTR{range}=="16" ATTR{removable}=="1" ATTR{ro}=="0" ATTR{size}=="31116288" ATTR{stat}==" 251 0 9307 1443 8 0 0 9 0 860 1462 0 0 0 0 8 9"
- udev rules neu laden
root@endurance:/etc/udev/rules.d# udevadm control --reload-rules && /etc/init.d/udev restart && sudo udevadm trigger
root@endurance:/local/itservice# ls -l /dev/stm32mp1/1-1.4 total 0 lrwxrwxrwx 1 root root 9 Aug 29 11:50 msc -> ../../sda lrwxrwxrwx 1 root root 17 Aug 29 11:50 msc0 -> ../../bsg/1:0:0:0 lrwxrwxrwx 1 root root 10 Aug 29 11:50 msc1 -> ../../sda1 lrwxrwxrwx 1 root root 10 Aug 29 11:50 msc2 -> ../../sda2 lrwxrwxrwx 1 root root 10 Aug 29 11:50 msc3 -> ../../sda3 lrwxrwxrwx 1 root root 10 Aug 29 11:50 msc4 -> ../../sda4 lrwxrwxrwx 1 root root 10 Aug 29 11:50 msc5 -> ../../sda5 lrwxrwxrwx 1 root root 10 Aug 29 11:50 msc6 -> ../../sda6 lrwxrwxrwx 1 root root 10 Aug 29 11:50 msc7 -> ../../sda7 root@endurance:/local/itservice# ls -l /dev/sda* brw-rw----+ 1 root users 8, 0 Aug 29 11:50 /dev/sda brw-rw----+ 1 root users 8, 1 Aug 29 11:50 /dev/sda1 brw-rw----+ 1 root users 8, 2 Aug 29 11:50 /dev/sda2 brw-rw----+ 1 root users 8, 3 Aug 29 11:50 /dev/sda3 brw-rw----+ 1 root users 8, 4 Aug 29 11:50 /dev/sda4 brw-rw----+ 1 root users 8, 5 Aug 29 11:50 /dev/sda5 brw-rw----+ 1 root users 8, 6 Aug 29 11:50 /dev/sda6 brw-rw----+ 1 root users 8, 7 Aug 29 11:50 /dev/sda7
Serielle Konsole
- minicom oder picocom sollten installiert sein
sudo apt install minicom picocom
Fix broken /dev/serial/by-id
sudo cp /usr/lib/udev/rules.d/60-serial.rules /usr/lib/udev/rules.d/60-serial.rules.bak
# do not edit this file, it will be overwritten on update ACTION=="remove", GOTO="serial_end" SUBSYSTEM!="tty", GOTO="serial_end" SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id", IMPORT{builtin}="hwdb --subsystem=usb" SUBSYSTEMS=="pci", ENV{ID_BUS}=="", ENV{ID_BUS}="pci", \ ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}", \ IMPORT{builtin}="hwdb --subsystem=pci" # /dev/serial/by-path/, /dev/serial/by-id/ for USB devices KERNEL!="ttyUSB[0-9]*|ttyACM[0-9]*", GOTO="serial_end" SUBSYSTEMS=="usb-serial", ENV{.ID_PORT}="$attr{port_number}" IMPORT{builtin}="path_id" ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="", SYMLINK+="serial/by-path/$env{ID_PATH}" ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="?*", SYMLINK+="serial/by-path/$env{ID_PATH}-port$env{.ID_PORT}" ENV{ID_BUS}=="", GOTO="serial_end" ENV{ID_SERIAL}=="", GOTO="serial_end" ENV{ID_USB_INTERFACE_NUM}=="", GOTO="serial_end" ENV{.ID_PORT}=="", SYMLINK+="serial/by-id/$env{ID_BUS}-$env{ID_SERIAL}-if$env{ID_USB_INTERFACE_NUM}" ENV{.ID_PORT}=="?*", SYMLINK+="serial/by-id/$env{ID_BUS}-$env{ID_SERIAL}-if$env{ID_USB_INTERFACE_NUM}-port$env{.ID_PORT}" LABEL="serial_end"
sudo udevadm control --reload-rules && sudo udevadm trigger
Dialout Gruppe
root@endurance:~# usermod -a -G dialout $USER
STM32CubeProgrammer
Installation
- Download STM32CubeProgrammer
- zip Datei entpacken und Installer starten
root@endurance:~# ./SetupSTM32CubeProgrammer-2.2.0.linux
Testen der Kommunikation mit der Karte
STM32CubeProgrammer kommuniziert über USB-C Buchse neben HDMI Port
Auf der Rückseite der Karte befindet sich ein Zweiwege-DIP-Schalter mit der Bezeichnung SW1, mit dem der Boot-Modus konfiguriert werden kann. Wenn beide Schalter auf "ON" stehen, bootet die Karte von der SD-Karte. Wenn beide Schalter auf "OFF" stehen, bootet das Board in den "USB-Boot for flashing mode", den wir verwenden werden. Schalten Sie also beide Schalter auf OFF, und setzen Sie das Board zurück.
root@endurance:/local/itservice/STMicroelectronics/STM32Cube/STM32CubeProgrammer# lsusb Bus 002 Device 003: ID 0bda:0415 Realtek Semiconductor Corp. 2-Port USB 3.0 Hub Bus 002 Device 002: ID 0bda:0411 Realtek Semiconductor Corp. Hub Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 006: ID 8087:0aaa Intel Corp. Bluetooth 9460/9560 Jefferson Peak (JfP) Bus 001 Device 005: ID 0bda:5415 Realtek Semiconductor Corp. 2-Port USB 2.0 Hub Bus 001 Device 003: ID 0483:3752 STMicroelectronics ST-LINK/V2.1 Bus 001 Device 008: ID 0483:df11 STMicroelectronics STM Device in DFU Mode Bus 001 Device 004: ID 413c:2514 Dell Computer Corp. Dell Universal Receiver Bus 001 Device 002: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub root@endurance:/local/itservice/STMicroelectronics/STM32Cube/STM32CubeProgrammer#
root@endurance:/local/itservice/STMicroelectronics/STM32Cube/STM32CubeProgrammer# ./bin/STM32_Programmer_CLI -l usb ------------------------------------------------------------------- STM32CubeProgrammer v2.14.0 ------------------------------------------------------------------- ===== DFU Interface ===== Total number of available STM32 device in DFU mode: 1 Device Index : USB1 USB Bus Number : 001 USB Address Number : 002 Product ID : DFU in HS Mode @Device ID /0x500, @Revision ID /0x0000 Serial number : 004300213338510B39303435 Firmware version : 0x0110 Device ID : 0x0500 root@endurance:/local/itservice/STMicroelectronics/STM32Cube/STM32CubeProgrammer#
root@endurance:/local/itservice/STMicroelectronics/STM32Cube/STM32CubeProgrammer/Drivers/rules# ls -l total 24 -rw-r--r-- 1 itservice itservice 604 Apr 25 2022 49-stlinkv2-1.rules -rw-r--r-- 1 itservice itservice 480 Apr 25 2022 49-stlinkv2.rules -rw-r--r-- 1 itservice itservice 982 Apr 25 2022 49-stlinkv3.rules -rw-r--r-- 1 itservice itservice 97 Apr 25 2022 50-usb-conf.rules -rw-r--r-- 1 itservice itservice 220 Apr 25 2022 Readme.txt -rw-r--r-- 1 itservice itservice 5 Apr 25 2022 version.txt root@endurance:/local/itservice/STMicroelectronics/STM32Cube/STM32CubeProgrammer/Drivers/rules# cp *.rules /etc/udev/rules.d/
itservice@endurance:~/STMicroelectronics/STM32Cube/STM32CubeProgrammer$ lsusb Bus 002 Device 003: ID 0bda:0415 Realtek Semiconductor Corp. 2-Port USB 3.0 Hub Bus 002 Device 002: ID 0bda:0411 Realtek Semiconductor Corp. Hub Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 006: ID 8087:0aaa Intel Corp. Bluetooth 9460/9560 Jefferson Peak (JfP) Bus 001 Device 005: ID 0bda:5415 Realtek Semiconductor Corp. 2-Port USB 2.0 Hub Bus 001 Device 003: ID 0483:3752 STMicroelectronics ST-LINK/V2.1 Bus 001 Device 009: ID 0483:df11 STMicroelectronics STM Device in DFU Mode Bus 001 Device 004: ID 413c:2514 Dell Computer Corp. Dell Universal Receiver Bus 001 Device 002: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub itservice@endurance:~/STMicroelectronics/STM32Cube/STM32CubeProgrammer$ ./bin/STM32_Programmer_CLI -l usb ------------------------------------------------------------------- STM32CubeProgrammer v2.14.0 ------------------------------------------------------------------- ===== DFU Interface ===== Total number of available STM32 device in DFU mode: 1 Device Index : USB1 USB Bus Number : 001 USB Address Number : 002 Product ID : DFU in HS Mode @Device ID /0x500, @Revision ID /0x0000 Serial number : 004300213338510B39303435 Firmware version : 0x0110 Device ID : 0x0500 itservice@endurance:~/STMicroelectronics/STM32Cube/STM32CubeProgrammer$
Udev Sammlung
udevadm info -a -p $(udevadm info -q path -n /dev/sda)|grep -iE "manufacturer|product"
Quellen
- https://www.st.com/en/development-tools/stm32cubeprog.html
- https://www.thushanfernando.com/posts/2023/missing-serial-by-id/
- https://www.digikey.de/en/maker/projects/intro-to-embedded-linux-part-1-buildroot/a73a56de62444610a2187cd9e681c3f2
- https://bootlin.com/blog/building-a-linux-system-for-the-stm32mp1-implementing-factory-flashing/
- https://wiki.somlabs.com/index.php/Installing_STM32CubeProgrammer_on_Ubuntu_18.04
- https://wiki.st.com/stm32mpu/wiki/How_to_use_USB_mass_storage_in_U-Boot