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