USB boot modes

There are two separate boot modes for USB:

  • USB device boot

  • USB host boot

The firmware chooses between the two modes at boot time based on the OTP bits. Two bits control USB boot. The first enables USB device boot and is enabled by default; the second enables USB host boot.

If the USB host boot mode bit is set, the processor reads the OTGID pin to decide whether to boot as a host (driven to zero as on any Raspberry Pi Model B/B+) or as a device (left floating). The Raspberry Pi Zero has access to the OTGID pin through the USB connector; the Compute Module has access to the OTGID pin on the edge connector.

Some other OTP bits allow certain GPIO pins to select the boot modes.

USB device boot mode

When this boot mode is activated (usually after a failure to boot from the SD card), the Raspberry Pi puts its USB port into device mode and awaits a USB reset from the host. Example code showing how the host needs to talk to the Raspberry Pi can be found on Github.

The host first sends a structure to the device down control endpoint 0. This contains the size and signature for the boot (security is not enabled, so no signature is required). Secondly, code is transmitted down endpoint 1 (bootcode.bin). Finally, the device will reply with one of the following codes:

  • 0 – Success

  • 0x80 – Failure

USB host boot mode

Host boot is available on the Compute Module series since Compute Module 3, Zero series since Zero 2 W, Raspberry Pi 2B (version 1.2), Raspberry Pi 3B, and all classic Raspberry Pi single-board computers since Raspberry Pi 3B+. Raspberry Pi 3A+ supports mass storage boot, but not network boot.

USB host boot mode uses the following logic:

  1. Enable the USB port and wait for D+ line to be pulled high indicating a USB 2.0 device (we only support USB2.0)

  2. If the device is a hub:

    1. Enable power to all downstream ports of the hub

    2. For each port, loop for a maximum of two seconds (or five seconds if program_usb_boot_timeout=1 has been set)

      1. Release from reset and wait for D+ to be driven high to indicate that a device is connected

      2. If a device is detected:

        1. Send "Get Device Descriptor"

          1. If VID == SMSC && PID == 9500

            1. Add device to Ethernet device list

        2. If the class interface is mass storage class

          1. Add device to mass storage device list

  3. Else

    1. Enumerate single device

  4. Go through mass storage device list

  5. Go through Ethernet device list

    1. Boot from Ethernet

On Raspberry Pi 3B, 3A+, and 3B+, host boot is disabled by default. To enable USB host boot, add a line containing program_usb_boot_mode=1 to the end of /boot/firmware/config.txt.

Any change you make to the OTP is permanent and cannot be undone.

On Raspberry Pi 3A+, setting the OTP bit to enable USB host boot mode will permanently prevent that Raspberry Pi from booting in USB device mode.