Skip to content

Commit

Permalink
Merge pull request #229 from dgarske/infineon_tc27x
Browse files Browse the repository at this point in the history
Support for Infineon TriCore TC2XX/TC3XX
  • Loading branch information
tatowicz authored Dec 22, 2022
2 parents 49f32aa + e93acab commit 04908e5
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Portable TPM 2.0 project designed for embedded use.

* This implementation provides all TPM 2.0 API’s in compliance with the specification.
* Wrappers provided to simplify Key Generation/Loading, RSA encrypt/decrypt, ECC sign/verify, ECDH, NV, Hashing/Hmac and AES.
* Testing done using the STM ST33TP* SPI/I2C, Infineon OPTIGA SLB9670/SLB9672, Microchip ATTPM20 TPM 2.0 modules and Nuvoton NPCT650.
* Testing done using the following TPM 2.0 modules: STM ST33TP* SPI/I2C, Infineon OPTIGA SLB9670/SLB9672, Microchip ATTPM20, Nations Tech Z32H330TC and Nuvoton NPCT650/NPCT750.
* wolfTPM uses the TPM Interface Specification (TIS) to communicate over SPI.
* wolfTPM can also use the Linux TPM kernel interface (/dev/tpmX) to talk with any physical TPM on SPI, I2C and even LPC bus.
* Platform support for Raspberry Pi, STM32 with CubeMX, Atmel ASF and Barebox.
* Platform support for Raspberry Pi, STM32 with CubeMX, Atmel ASF, Xilinx, Infineon TriCore and Barebox.
* The design allows for easy portability to different platforms:
* Native C code designed for embedded use.
* Single IO callback for hardware SPI interface.
Expand Down Expand Up @@ -74,8 +74,9 @@ The examples in this library are written for use on a Raspberry Pi and use the `

For interfacing to your hardware platform see the example `examples/tpm_io.c` callback function `TPM2_IoCb`. Here you can modify or insert your own IO callback code for the TPM demo.

There are examples here for Linux, STM32 CubeMX, Atmel ASF and BareBox. The advanced IO option is required for I2C support because it adds the register and read/write flag as parameter to the IO callback.
There are examples here for Linux, STM32 CubeMX, Atmel ASF, Xilinx, Infineon TriCore and BareBox.

The advanced IO option (`--enable-advio`/`WOLFTPM_ADV_IO`) is required for I2C support because it adds the register and read/write flag as parameter to the IO callback.

### Hardware

Expand Down
1 change: 1 addition & 0 deletions examples/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dist_example_DATA+= examples/README.md \
examples/tpm_io_atmel.c \
examples/tpm_io_barebox.c \
examples/tpm_io_linux.c \
examples/tpm_io_infineon.c \
examples/tpm_io_st.c \
examples/tpm_io_qnx.c \
examples/tpm_io_xilinx.c \
Expand Down
4 changes: 4 additions & 0 deletions examples/tpm_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include "examples/tpm_io_qnx.c"
#elif defined(__XILINX__)
#include "examples/tpm_io_xilinx.c"
#elif defined(WOLFTPM_INFINEON_TRICORE)
#include "examples/tpm_io_infineon.c"
#endif

#if !defined(WOLFTPM_I2C)
Expand All @@ -78,6 +80,8 @@ static int TPM2_IoCb_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf,
ret = TPM2_IoCb_QNX_SPI(ctx, txBuf, rxBuf, xferSz, userCtx);
#elif defined(__XILINX__)
ret = TPM2_IoCb_Xilinx_SPI(ctx, txBuf, rxBuf, xferSz, userCtx);
#elif defined(WOLFTPM_INFINEON_TRICORE)
ret = TPM2_IoCb_Infineon_TriCore_SPI(ctx, txBuf, rxBuf, xferSz, userCtx);
#else

/* TODO: Add your platform here for HW SPI interface */
Expand Down
3 changes: 3 additions & 0 deletions examples/tpm_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ int TPM2_IoCb_QNX_SPI(TPM2_CTX* ctx, const byte* txBuf,
#elif defined(__XILINX__)
int TPM2_IoCb_Xilinx_SPI(TPM2_CTX* ctx, const byte* txBuf,
byte* rxBuf, word16 xferSz, void* userCtx);
#elif defined(WOLFTPM_INFINEON_TRICORE)
int TPM2_IoCb_Infineon_TriCore_SPI(TPM2_CTX* ctx, const byte* txBuf,
byte* rxBuf, word16 xferSz, void* userCtx);
#endif /* WOLFSSL_ATMEL */
#endif /* WOLFTPM_I2C */

Expand Down
86 changes: 86 additions & 0 deletions examples/tpm_io_infineon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* tpm_io_infineon.c
*
* Copyright (C) 2006-2022 wolfSSL Inc.
*
* This file is part of wolfTPM.
*
* wolfTPM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfTPM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

/* This example shows IO interfaces for Infineon TriCore hardware:
* - TC2XX/TC3XX using macro: `WOLFTPM_INFINEON_TRICORE`.
*/


#include <wolftpm/tpm2.h>
#include <wolftpm/tpm2_tis.h>
#include "tpm_io.h"

/******************************************************************************/
/* --- BEGIN IO Callback Logic -- */
/******************************************************************************/

/* Included via tpm_io.c if WOLFTPM_INCLUDE_IO_FILE is defined */
#ifdef WOLFTPM_INCLUDE_IO_FILE

#if ! (defined(WOLFTPM_LINUX_DEV) || \
defined(WOLFTPM_SWTPM) || \
defined(WOLFTPM_WINAPI) )

/* Use the max speed by default - see tpm2_types.h for chip specific max values */
#ifndef TPM2_SPI_HZ
#define TPM2_SPI_HZ TPM2_SPI_MAX_HZ
#endif

#if defined(WOLFTPM_INFINEON_TRICORE)

#include <Ifx_Types.h>
#include <Qspi/SpiMaster/IfxQspi_SpiMaster.h>

/* externally declared SPI master channel */
extern IfxQspi_SpiMaster_Channel spiMasterChannel

static int TPM2_IoCb_Infineon_TriCore_SPI(TPM2_CTX* ctx, const byte* txBuf,
byte* rxBuf, word16 xferSz, void* userCtx)
{
int ret = TPM_RC_FAILURE;

#ifdef WOLFTPM_CHECK_WAIT_STATE
#error SPI check wait state logic not supported
#endif

/* wait for SPI not busy */
while (IfxQspi_SpiMaster_getStatus(&spiMasterChannel) ==
SpiIf_Status_busy) {};

/* synchronously send data */
if (IfxQspi_SpiMaster_exchange(&spiMasterChannel, txBuf, rxBuf,
xferSz) == SpiIf_Status_ok) {
ret = TPM_RC_SUCCESS;
}

(void)userCtx;
(void)ctx;

return ret;
}

#endif /* WOLFTPM_INFINEON_TRICORE */
#endif /* !(WOLFTPM_LINUX_DEV || WOLFTPM_SWTPM || WOLFTPM_WINAPI) */
#endif /* WOLFTPM_INCLUDE_IO_FILE */

/******************************************************************************/
/* --- END IO Callback Logic -- */
/******************************************************************************/

0 comments on commit 04908e5

Please sign in to comment.