manticore icon indicating copy to clipboard operation
manticore copied to clipboard

Need transfer protocol for "small package" interfaces

Open osenft opened this issue 5 years ago • 2 comments

On some devices the maximum size of a "package" that can be transferred on a particular interface is smaller than the maximum supported message size. We need a transfer protocol that works across various interface types (e.g. I2C, SPI) that allows the transfer of "large" messages across multiple "transactions" on the particular interface. This transfer protocol can also be used for smaller messages that fit into one "package" to indicate the size of the message.

osenft avatar Jul 16 '20 14:07 osenft

In Manticore's current design, this is "out of scope" of what Manticore gives you (though we are working on changing this!).

Manticore's contract is that you need to hand it complete buffered Cerberus commands (while Cerberus operates on the level of MCTP packets). Actually bridging the physical and application layers is currently the integration's responsibility, and we expect the transport to vary from interface to interface.

For example, on I2C, we can use MCTP. However, over SPI, we might want to use a different protocol. For a very trivial two-device link, I think the following is a very simple strategy similar to what MCTP does:

  • Each packet consists of a start bit, a stop bit, a u16 length, and a payload.
  • Message assembly starts when a start bit is seen, and stops when a stop bit is seen. The message is the concatenation of the packets' payloads, and has an intrinsic length. Single-packet messages would send one packet with start and stop set.
  • Packetization is the opposite: you break up messages into "small enough" chunks, set the start and stop bits as necessary, and send them over the wire.

This is probably good enough for the short term, until Manticore gets a way of abstracting the transport layer.

mcy avatar Jul 16 '20 19:07 mcy

As we discussed via chat, I'm going to do the following specifically for Tock-on-Titan for the time being:

  1. Expect that a message fits into one buffer size.

  2. A buffer is 512 bytes in size, but it also contains SPI protocol data:

    • 1 byte command
    • 4 bytes address
    • 1 dummy byte (optional)

    This leaves us with 506 bytes of raw data.

  3. Prefix the message with its length (16 bit = 2 bytes). This leaves us with 504 bytes for the message.

The message on the SPI bus will then look like this:

Byte Content
0 SPI flash command
1..2 SPI flash address
3 dummy byte (optional, depending on SPI flash command)
4..5 message length
6..511 message

For this to work, we'll need to hold a 512 byte RX and 512 byte TX buffer in memory, which - from what I can tell by testing - is possible in the Tock-on-Titan environment.

osenft avatar Jul 16 '20 21:07 osenft