Introduction
UF2 is a firmware format made by Microsoft for its
MakeCode editor, for flashing microcontrollers
without special software. A board’s bootloader appears on the computer as a USB drive;
copying a .uf2 file onto it writes the firmware into flash, and the board
restarts. The Raspberry Pi Pico, many Adafruit boards and other hobby boards work this
way, and projects such as MicroPython and CircuitPython publish their firmware as UF2.
Structure
A UF2 file is a series of 512-byte blocks, each complete in itself. Every block carries its own target address, so the bootloader can write each one as it arrives, in any order, and ignore anything else the operating system writes to the drive. Each block starts with two magic numbers and ends with a third, all 32-bit little-endian, and holds up to 476 bytes of data, usually 256.
A flag can mark that the word at offset 28 is a family ID rather than the file size, which names the kind of chip the firmware is for, so a board can reject firmware meant for another.
0magic0x0A324655(UF2\n), then0x9E5D51578 bytes8flags4 bytes12target address in flash4 bytes16payload size, usually 2564 bytes20block number and total blocks8 bytes28file size or family ID4 bytes32data, padded with zeros476 bytes508final magic0x0AB16F304 bytes
Links
Software
- Microsoft MakeCode, which builds them (web)
- picotool, which inspects and loads them on Raspberry Pi boards (Windows, macOS, Linux)
- uf2conv.py, in Microsoft’s UF2 repository, which converts binary and HEX files to UF2 (Windows, macOS, Linux)
Reference
- microsoft/uf2, the specification, with the list of family IDs