Topic: Low-level SPI communication

Hello,

I’m using WolfTPM, with a raspberry pi and an ST ST33TP SPI TPM2 in order to understand TPM at a low level. I use the native test example here to spy on the SPI bus and understand the frame format. This is what I get for GetRandom :

/* Get Random */
/* E4 e2 51 65 6c 39 9a 8e d4 14 94 ee 19 3c 25 bf 60 77 e0 36 cf d6 57 96 f b8 dc f4 fb b9 e6 88 */
MOSI: 80 d4  0 18 80  0
MISO:  0  0  0  0  1 84
MOSI:  0 d4  0 18  0  0  0 40
MISO:  0  0  0  0  0  0  1 ff
MOSI: 80 d4  0 18 80  0
MISO:  0  0  0  0  1 c4
MOSI:  b d4  0 24  b  b  b 80  1  0  0  0  c  0  0  1 7b  0 20
MISO:  0  0  0  0  0  0  1 ff ff ff ff ff ff ff ff ff ff ff ff
MOSI:  0 d4  0 18  0  0  0 20
MISO:  0  0  0  0  0  0  1 ff
MOSI: 80 d4  0 18 80  0
MISO:  0  0  0  0  1 94
MOSI: 89 d4  0 24 89  0  0  0  0  0  0  0  0  0  0
MISO:  0  0  0  0  1 80  1  0  0  0 2c  0  0  0  0
MOSI: 80 d4  0 18 80  0
MISO:  0  0  0  0  1 94
MOSI: 9f d4  0 24 9f  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
MISO:  0  0  0  0  1  0 20 dc f6 e9 eb fe  a 74 e1 7a 92 ac e7 ad 73 b9 33 2b a8 4c  6 94 cf a7 4f 40 c3  3 d4 a3 99
MOSI: 80 d4  0 18 80  0
MISO:  0  0  0  0  1 94
MOSI: 81 d4  0 24 81  0  0
MISO:  0  0  0  0  1 f2  d
MOSI:  0 d4  0 18  0  0  0 40
MISO:  0  0  0  0  0  0  1 ff

I can understand the dialogue between the TPM and the raspberry quite well except one thing.

When the command is written to the register 24 (TPM_DATA_FIFO), why is the first byte repeated 3 times after the address bytes? Is this some kind of padding / bit stuffing?

MOSI:  b d4  0 24  b  b  b 80  1  0  0  0  c  0  0  1 7b  0 20

Same thing with the other registers, except that this time the repetition is unique.

MOSI: 80 d4  0 18 80  0

This pattern is present on all the commands I observed. I then created a simple script rewriting the GetRandom command to /dev/spidev0.0 replacing the repeated bytes by 0. I then obtained the same results. Did I miss something? These repetitions seems useless to me.

Thanks in advance,
François

Share

Re: Low-level SPI communication

Hi François,

You can enable IO level debugging inside wolfTPM using `./configure --enable-debug=io`. The command code TPM_CC_GetRandom is `0x0000017B`. The command also includes a 16-bit request size at the end. The ST33 uses a SPI wait state, so the header is 4 bytes and a single byte is read until the 0x80 MSB is set. Then a tag, command size and command code are added.

b d4  0 24 /* header */
b  b  b /* ready bytes */
80 1  TAG 
0 0  0 c  SIZE
0  0  1 7b  COMMAND
0 20 Arguments (bytes requested)

Thanks,
David Garske, wolfSSL

Share

Re: Low-level SPI communication

Hi David,

Thank you very much for your reply!

It seems that the method I was using to log the SPI frames was causing some latencies on the bus and inducing wait states. The command `./configure --enable-debug=io ` made the ready bytes from the SPI wait states disappeared.

Thanks again,
François

Share