Introduction
Device Firmware Upgrade (DFU) is a standard from the USB Implementers Forum for updating a USB device’s firmware over its USB connection. The same specification defines a file format: the firmware image followed by a short suffix that says which device it is for, so the flashing tool can refuse to load it into the wrong one. Many microcontrollers have a DFU bootloader built in; dfu-util’s notes name the STM32F107, F2 and F4 series, which carry ST’s DfuSe bootloader in ROM.
STMicroelectronics uses an extended form, DfuSe, which also puts a prefix in front of the image and can hold several images, each with the flash address it belongs at.
Structure
The file is the raw firmware followed by a 16-byte suffix. Numbers in the suffix are
little-endian. The signature is the letters UFD, “DFU” backwards, because
the suffix is meant to be read from the end of the file. A vendor or product ID of
0xFFFF means the file is not tied to one. The last four bytes are a CRC-32
(without the usual final inversion) of everything before them. Every field is on the
DFU suffix page; ST’s DfuSe prefix, Target
prefix and image elements are on DfuSe prefix and
images; and the descriptors, requests, states and status codes used to send the
file to a device are on USB protocol
codes.
0firmware image (in DfuSe, a prefix and target sections)varies−16bcdDevice, the firmware release number2 bytes−14idProduct and idVendor4 bytes−10bcdDFU, the DFU version2 bytes−8signatureUFD3 bytes−5suffix length, 161 byte−4CRC4 bytes
Not described
Both the USB DFU 1.1 specification and ST’s UM0391 were read in full and agree with the pages. What is left:
Known, not yet covered
- Reference: ST’s DfuSe command protocol (the special “set address” and “erase” commands sent with DFU_DNLOAD); it is not part of UM0391, which covers the file only, and the DfuSe page gives no byte values for it.
- Viewer: there is no viewer for DFU files yet, so the suffix, CRC and DfuSe images are not decoded.
Unknown
- Reference: whether DfuSe’s multi-byte fields are little-endian, as the tools write them, or big-endian, as UM0391’s wording says; the manual has no byte example.
Links
Software
- dfu-util – flashes DFU devices, with
dfu-suffixanddfu-prefixto add and check suffixes (Windows, macOS, Linux) - STM32CubeProgrammer – ST’s tool for programming STM32 chips over DFU and other links (Windows, macOS, Linux)
Reference
- USB-IF document library – the USB Implementers Forum’s library, which holds the Device Firmware Upgrade class specification