wolfSSL / wolfTPM

wolfTPM is a highly portable TPM 2.0 library, designed for embedded use.
https://www.wolfssl.com
GNU General Public License v2.0
230 stars 55 forks source link

Corrected Linux usage of cs_change, added config overrides. #268

Closed billphipps closed 1 year ago

billphipps commented 1 year ago

The Linux IO subsystem's usage of cs_change within the SPI transfer ioctl() call has been corrected. Since all transactions are single messages (last transactions), the cs_change must be set to 1 when a sequence of transactions must be issued while CS is asserted. Only the last transaction should have the cs_change set back to 0 to ensure the cs line is desasserted. Specifically, the fsl-dspi Linux kernel driver does not have a method to dessert CS under error conditions. Hence, code was added to always complete all SPI transaction sequences with an additional byte transfer with cs_change=0 to ensure the kernel driver correctly reasserts cs. This code will only be triggered in error handling cases where the SPI transactions have either failed to be issued or timeout for wait states is exceeded.

This code was tested on a Raspberry Pi with a Nuvoton SPI TPM and an LS1028A connected to an Optiga SLB9672. Both configurations were run with and without auto detection as well as with and without wait state checking.

Additionally, logic was added to allow the spidev path and cs to be overridden at configuration time by setting the TPM2_SPI_DEV_PATH and TPM_SPI_DEV_CS macros to valid strings such as: ./configure CPPFLAGS="-DTPM2_SPI_DEV_PATH=\"/dev/spidev0.\" -DTPM2_SPI_DEV_CS=\"0\" "

pi_novuton_wraptest.txt ls1028a_optiga_wraptest.txt