Skip to content

Commit 7c079dd

Browse files
authored
Merge pull request #318 from dgarske/no_locking
No locking option, compiler warnings and STM IO improvements
2 parents 17fcfb6 + fb2ea5b commit 7c079dd

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

hal/tpm_io_st.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@
145145
}
146146

147147
#else /* STM32 CubeMX Hal SPI */
148+
#ifndef STM32_CUBEMX_SPI_TIMEOUT
148149
#define STM32_CUBEMX_SPI_TIMEOUT 250
150+
#endif
149151
#ifndef USE_SPI_CS_PORT
150152
#define USE_SPI_CS_PORT GPIOA
151153
#endif
@@ -218,6 +220,11 @@
218220

219221
if (status == HAL_OK)
220222
ret = TPM_RC_SUCCESS;
223+
#ifdef WOLFTPM_DEBUG_VERBOSE
224+
else {
225+
printf("SPI Failed: Xfer %d, Status=0x%x\n", xferSz, status);
226+
}
227+
#endif
221228

222229
(void)ctx;
223230

src/tpm2.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static volatile int gWolfCryptRefCount = 0;
5858
/******************************************************************************/
5959
static TPM_RC TPM2_AcquireLock(TPM2_CTX* ctx)
6060
{
61-
#if defined(WOLFTPM2_NO_WOLFCRYPT) || defined(SINGLE_THREADED)
61+
#if defined(WOLFTPM2_NO_WOLFCRYPT) || defined(WOLFTPM_NO_LOCK)
6262
(void)ctx;
6363
#else
6464
int ret;
@@ -86,7 +86,7 @@ static TPM_RC TPM2_AcquireLock(TPM2_CTX* ctx)
8686

8787
static void TPM2_ReleaseLock(TPM2_CTX* ctx)
8888
{
89-
#if defined(WOLFTPM2_NO_WOLFCRYPT) || defined(SINGLE_THREADED)
89+
#if defined(WOLFTPM2_NO_WOLFCRYPT) || defined(WOLFTPM_NO_LOCK)
9090
(void)ctx;
9191
#else
9292
ctx->lockCount--;
@@ -143,7 +143,7 @@ static int TPM2_CommandProcess(TPM2_CTX* ctx, TPM2_Packet* packet,
143143

144144
#ifdef WOLFTPM_DEBUG_VERBOSE
145145
printf("CommandProcess: Handles (Auth %d, In %d), CmdSz %d, AuthSz %d, ParamSz %d, EncSz %d\n",
146-
info->authCnt, info->inHandleCnt, cmdSz, authSz, paramSz, encParamSz);
146+
info->authCnt, info->inHandleCnt, (int)cmdSz, (int)authSz, paramSz, encParamSz);
147147
#else
148148
(void)paramSz;
149149
#endif
@@ -282,7 +282,7 @@ static int TPM2_ResponseProcess(TPM2_CTX* ctx, TPM2_Packet* packet,
282282

283283
#ifdef WOLFTPM_DEBUG_VERBOSE
284284
printf("ResponseProcess: Handles (Out %d), RespSz %d, ParamSz %d, DecSz %d, AuthSz %d\n",
285-
info->outHandleCnt, respSz, paramSz, decParamSz, respSz - authPos);
285+
info->outHandleCnt, (int)respSz, (int)paramSz, (int)decParamSz, (int)(respSz - authPos));
286286
#endif
287287

288288
for (i=0; i<info->authCnt; i++) {
@@ -662,7 +662,7 @@ TPM_RC TPM2_Cleanup(TPM2_CTX* ctx)
662662
wc_FreeRng(&ctx->rng);
663663
}
664664
#endif
665-
#ifndef SINGLE_THREADED
665+
#ifndef WOLFTPM_NO_LOCK
666666
if (ctx->hwLockInit) {
667667
ctx->hwLockInit = 0;
668668
wc_FreeMutex(&ctx->hwLock);

src/tpm2_param_enc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ int TPM2_CalcCpHash(TPMI_ALG_HASH authHash, TPM_CC cmdCode,
399399
}
400400

401401
#ifdef WOLFTPM_DEBUG_VERBOSE
402-
printf("cpHash: cmd %x, size %d\n", cmdCode, hash->size);
402+
printf("cpHash: cmd %x, size %d\n", (unsigned int)cmdCode, hash->size);
403403
TPM2_PrintBin(hash->buffer, hash->size);
404404
#endif
405405

@@ -448,7 +448,7 @@ int TPM2_CalcRpHash(TPMI_ALG_HASH authHash,
448448
}
449449

450450
#ifdef WOLFTPM_DEBUG_VERBOSE
451-
printf("rpHash: cmd %x, size %d\n", cmdCode, hash->size);
451+
printf("rpHash: cmd %x, size %d\n", (unsigned int)cmdCode, hash->size);
452452
TPM2_PrintBin(hash->buffer, hash->size);
453453
#endif
454454

wolftpm/tpm2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ typedef struct TPM2_CTX {
17101710
struct wolfTPM_winContext winCtx;
17111711
#endif
17121712
#ifndef WOLFTPM2_NO_WOLFCRYPT
1713-
#ifndef SINGLE_THREADED
1713+
#ifndef WOLFTPM_NO_LOCK
17141714
wolfSSL_Mutex hwLock;
17151715
int lockCount;
17161716
#endif
@@ -1733,7 +1733,7 @@ typedef struct TPM2_CTX {
17331733
byte rid;
17341734
/* Informational Bits - use unsigned int for best compiler compatibility */
17351735
#ifndef WOLFTPM2_NO_WOLFCRYPT
1736-
#ifndef SINGLE_THREADED
1736+
#ifndef WOLFTPM_NO_LOCK
17371737
unsigned int hwLockInit:1;
17381738
#endif
17391739
#ifndef WC_NO_RNG

wolftpm/tpm2_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ typedef int64_t INT64;
264264
#define printf XPRINTF
265265
#endif
266266

267+
/* check if locking / mutex should be enabled */
268+
#if defined(SINGLE_THREADED)
269+
#undef WOLFTPM_NO_LOCK
270+
#define WOLFTPM_NO_LOCK
271+
#endif
267272

268273

269274
/* ---------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)