EmBIOS Monitor Protocol
This article describes the USB communcation protocol of emBIOS monitor.
Contents
- 1 Endpoints
- 2 General Structure
- 3 Commands
- 3.1 0: Invalid
- 3.2 1: Get device information
- 3.3 2: Reset
- 3.4 3: Power off
- 3.5 4: Read memory
- 3.6 5: Write memory
- 3.7 6: Read memory using DMA
- 3.8 7: Write memory using DMA
- 3.9 8: Read from I2C device
- 3.10 9: Write to I2C device
- 3.11 10: Read from the USB console
- 3.12 11: Write to the USB console
- 3.13 12: Write to device's consoles
- 3.14 13: Read from device's consoles
- 3.15 14: Flush device's console buffers
- 3.16 15: Get process information
- 3.17 16: (Un)Freeze scheduler
- 3.18 17: (Un)Suspend thread
- 3.19 18: Kill thread
- 3.20 19: Create thread
- 3.21 20: Flush CPU caches
- 3.22 21: Execute image
- 3.23 22: Read raw boot flash
- 3.24 23: Write raw boot flash
- 3.25 24: Execute firmware
- 3.26 25: Hardware key AES
- 3.27 26: HMAC-SHA1
Endpoints
The emBIOS Monitor interface contains 4 bulk endpoints, in the following order:
- Command OUT Endpoint
- Command IN Endpoint
- Data OUT Endpoint
- Data IN Endpoint
If not stated otherwise, everything is little endian.
General Structure
Each packet send to the Command OUT Endpoint has a 16 byte header. The first 4 bytes, interpreted as a 32bit little endian word, contain the command ID. The meaning of the other bytes depends on the command. For commands that send data to the device, it will immediately follow that header.
After sending a packet to the Command OUT Endpoint, listen on the Command IN Endpoint for a response. The response also has a 16 byte header, followed by an optional data stage, depending on the command. The first 4 bytes of the header, interpreted as a 32bit word, is the status code, the meaning of the other bytes depends on the command.
Status Code | Description |
---|---|
0 | Invalid response, you should bail out when receiving this |
1 | OK (everything went fine) |
2 | Command not supported |
3 | Device is busy, retry later (another asynchronous command is already running) |
Commands
0: Invalid
Never issue this command. It will be rejected with status code 2.
1: Get device information
Use this command to figure out various device properties.
Get version information
Offset | Size (bytes) | Description |
---|---|---|
0 | 4 | Command ID (1) |
4 | 4 | Requested information type (0) |
8 | 8 | Should be zero |
Offset | Size (bytes) | Description
Get packet size information
Get user memory address rangeProvides information about the range of memory not used by emBIOS itself.
2: ResetReboot the device.
Graceful reboots are asynchronous commands. Forced reboots won't send a response packet before rebooting.
The response indicates that the request has been acknowledged, however there might be substantial delay before device actually reboots.
3: Power offPower the device off.
Both variants are asynchronous commands.
The response indicates that the request has been acknowledged, however there might be substantial delay before device actually powers off.
4: Read memoryUse this command to read small amouts of memory through the command pipe. You may not request a transfer that would exceed the maximum Command IN Endpoint packet size (including the header).
5: Write memoryUse this command to write small amouts of memory through the command pipe. You may not request a transfer that would exceed the maximum Command OUT Endpoint packet size (including the header).
6: Read memory using DMAUse this command to read large amouts of memory through the data pipe. You may not request a transfer that would exceed the maximum Data IN Endpoint packet size.
After receiving the response, read the requested data from the Data IN Endpoint.
7: Write memory using DMAUse this command to read large amouts of memory through the data pipe. You may not request a transfer that would exceed the maximum Data OUT Endpoint packet size.
After receiving the response, send the data to be written to the Data OUT Endpoint.
8: Read from I2C deviceUse this command to read from an I2C slave. You may not request a transfer that would exceed the maximum Command IN Endpoint packet size (including the header) or 255 bytes (excluding the header), whichever is smaller.
I2C transactions are asynchronous commands.
9: Write to I2C deviceUse this command to write to an I2C slave. You may not request a transfer that would exceed the maximum Command OUT Endpoint packet size (including the header) or 255 bytes (excluding the header), whichever is smaller.
I2C transactions are asynchronous commands.
10: Read from the USB consoleUse this command to get data written to the USB console. You may not request a transfer that would exceed the maximum Command IN Endpoint packet size (including the header). As long as the console application is running, make sure to issue this request at least once a second. Otherwise the console might start dropping data and inserting an "\n\n[overflowed]\n\n" mark. If you can't receive any data but need to keep the console from dropping data, issue zero-length read requests.
11: Write to the USB consoleUse this command to write data to the USB console. You may not request a transfer that would exceed the maximum Command OUT Endpoint packet size (including the header).
12: Write to device's consolesUse this command to write data to one or more of the consoles. This is equivalent to the cwrite system call. You may not request a transfer that would exceed the maximum Command OUT Endpoint packet size (including the header).
13: Read from device's consolesUse this command to read data from one or more of the consoles. This is equivalent to the cread system call. You may not request a transfer that would exceed the maximum Command IN Endpoint packet size (including the header). This command will not block until there is data available.
14: Flush device's console buffersUse this command to flush one or more console's buffers. This is equivalent to the cflush system call.
15: Get process informationUse this command to obtain the current state of the scheduler. You may not request a transfer that would exceed the maximum Command IN Endpoint packet size (including the header).
16: (Un)Freeze schedulerUse this command to prevent execution of userspace code on the device while dumping or manipulating critical data.
17: (Un)Suspend threadSuspend or resume a thread
18: Kill threadKill a thread
19: Create threadCreate a new thread. This command uses an extended command size of 32 bytes.
20: Flush CPU cachesFlushes the CPU's instruction and data caches
21: Execute imageExecutes an emBIOS executable image. This is an asynchronous command.
22: Read raw boot flashReads raw data from the boot flash to RAM. This is an asynchronous command.
23: Write raw boot flashWrites raw data to the boot flash. Don't call this unless you really know what you're doing. This is an asynchronous command.
24: Execute firmwareExecutes a firmware image at the specified address. This is an asynchronous command.
25: Hardware key AESEncrypt or decrypt a buffer using a hardware key. This is an asynchronous command.
26: HMAC-SHA1Generate a HMAC-SHA1 hash of a buffer. This is an asynchronous command.
|
---|