OpenBoot
Draft: this page is not reviewed yet.

OBLink debug linkDraft

OBLink is the debug link between a host computer and OpenBoot on the target machine (observed on the M5 series). It runs over plain USB: the board's debug port presents a CDC-ACM serial device and the host talks to it with an ordinary serial driver. It is the only debug link OpenBoot has; the earlier gadget that used Apple's debug protocol was removed.

OBLink does three things:

  • shows the console, including a replay of the boot log that was written before the host attached;
  • runs monitor commands (info, ms, log, reboot and the rest) and returns their text;
  • pushes an image into a window in the board's memory with resume and a checksum, so that a development image can be started without removable media.

The host side is a small daemon, oblinkd. The wire format is defined in tools/oblink/PROTOCOL.md; this page summarises it. The device side is openboot/src/dbg/oblink_core.c, a pure engine with no hardware access that is covered by host tests (tests/dbg_host/test_oblink.c).

Transport#

The debug core brings up a USB device with the vendor and product id 1209:316d containing two CDC-ACM functions. OBLink uses the lower one (control interface 0): the host selects it by id and the lowest interface number. The second function is unused. No driver is needed on Linux, macOS or Windows. Baud rate and line coding are ignored on both ends; the host opens the port raw, 8N1, without flow control.

The id is a host option, so a later change of the assigned id does not need a new host program.

One stream, two kinds of content#

The byte stream carries console text and frames together.

  • Device to host: console text as ASCII, with frames embedded in it. The device replaces every byte of 0x80 or above and every control byte except tab, carriage return and newline by ?, so text can never contain the frame magic. A frame is always written whole, so console text never splits one.
  • Host to device: frames. Other bytes the host sends outside frames are ignored by OBLink.

Frame format#

Offset Size Field
0 4 Magic: bytes FF FE 4F 42 (two marker bytes and the letters OB)
4 1 Version, currently 1
5 1 Type
6 2 Payload length, little endian, 0 to 16384
8 length Payload
8 + length 4 CRC-32, little endian, over version, type, length and payload

All integers in payloads are little endian. The CRC is the zlib / IEEE CRC-32 (polynomial 0xEDB88320, initial and final value all ones); the check value of the ASCII string 123456789 is 0xCBF43926.

Receivers follow these rules (the host decoder in tools/oblink/oblink/framing.py is the reference):

  1. Bytes before a magic are console text. A tail that could still be the start of a magic is held back until the next read.
  2. A frame with an unaccepted version or a length above 16384 is dropped by discarding its four magic bytes and rescanning after them.
  3. A frame with a wrong CRC is dropped the same way, because a real frame may start inside the bytes the bad one claimed.
  4. A partial frame that receives no new byte for 500 ms is abandoned.

A lost or damaged frame therefore costs that frame only. Text before and after it is intact, and each request has its own retry rule.

Frame types#

Type Name Direction Payload
0x01 HELLO both version, flags, 64-bit nonce
0x02 HELLO_REPLY device to host version, state, capabilities, max chunk, window, echoed nonce, build id text
0x03 PING both 32-bit token
0x04 PONG both echo of the PING payload
0x10 MON_REQ host to device request id, flags, command line
0x11 MON_OUT device to host request id, text
0x12 MON_END device to host request id, status
0x20 PUSH_BEGIN host to device id, flags, address (0 = device window), total size, chunk size, image CRC-32
0x21 PUSH_DATA host to device id, offset, data
0x22 PUSH_END host to device id, total size, image CRC-32
0x23 PUSH_ACK device to host id, status, next offset, resolved address
0x24 PUSH_DONE device to host id, status, device CRC-32, next offset
0x7F ERROR device to host id (0 if none), text

Unknown types are ignored, so new frame types do not need a new version.

Handshake#

After opening the port the host sends HELLO every 500 ms until a HELLO_REPLY arrives. The device answers every HELLO. The reply carries:

  • the state: 0 hold (OpenBoot is holding for a host), 1 OpenBoot running, 2 guest running (EL2 layer serving), 255 other;
  • the capabilities as bits: 1 monitor, 2 push, 4 replay of the console log ring (the device resends its log as plain text after the reply);
  • the largest PUSH_DATA payload the device accepts (8192 bytes in the current code) and the number of bytes the host may have in flight unacknowledged (32768);
  • the build id as text.

A device that restarts its OBLink stack without USB re-enumeration (an image handover) sends one HELLO itself; the host treats that as a lost session and handshakes again.

Monitor frames#

The host assigns a request id. The device runs one command at a time and answers a second MON_REQ with MON_END status 0x10 (busy). The output comes back as MON_OUT chunks (at most 4096 bytes of text each), followed by MON_END with status 0 (OK) or 1 (error). A command line is at most 511 bytes. A command that restarts the board, such as reboot or sideload image, may never send MON_END; the host treats the loss of the port as the event.

Push frames#

The device has one receive window in DRAM. The host streams an image with a cumulative-acknowledgement, windowed protocol. The device keeps the received prefix, so a push survives a lost frame or a cable replug.

  • The resume key is the triple of address, total size and image CRC-32. On PUSH_BEGIN the device answers PUSH_ACK with the number of contiguous bytes it already holds for the same key (0 for a new key). A different key starts over.
  • The device stores a PUSH_DATA only if its offset equals the bytes it holds, then acknowledges at least every half window and on the last byte. Any other offset is not stored and is answered at once with status 4 and the offset the device expects.
  • The host retransmits from the last acknowledged offset when no acknowledgement arrives for 2 seconds.
  • PUSH_END makes the device check the byte count and compute the CRC-32 of the whole window data. PUSH_DONE carries status 0 and the device's CRC, 4 when bytes are missing, 5 on a CRC mismatch (and the held prefix is dropped). The host compares the device's CRC with its own.
  • The device writes bytes into the window but executes nothing until a monitor command says so.

Status codes: 0 ok, 1 bad arguments, 2 no window or too big, 3 busy, 4 out of order or incomplete, 5 CRC mismatch.

Not verified#

  • Throughput has not been measured in a documentation pass.
  • While the plain-USB hold window is open, the same serial pipe may also be read by an older proxy parser; the interaction is described only in the protocol file.