Skip to content

Commit 39af424

Browse files
committed
Fixes for PUF ROT
1 parent 7cf327f commit 39af424

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

hal/zynq.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ void wc_Sha3_384_Free(wc_Sha3* sha)
288288
#endif
289289

290290
/* CSU PUF */
291-
#define PUF_REG_TIMEOUT 500000
291+
#ifdef CSU_PUF_ROT
292+
#define CSU_PUF_SYNDROME_WORDS 386
293+
#ifndef CSU_PUF_REG_TIMEOUT
294+
#define CSU_PUF_REG_TIMEOUT 500000
295+
#endif
292296
int csu_puf_register(uint32_t* syndrome, uint32_t* syndromeSz, uint32_t* chash,
293297
uint32_t* aux)
294298
{
@@ -299,16 +303,19 @@ int csu_puf_register(uint32_t* syndrome, uint32_t* syndromeSz, uint32_t* chash,
299303
wolfBoot_printf("CSU Puf Register\n");
300304
#endif
301305

302-
pmu_mmio_write(CSU_PUF_CFG0, CSU_PUF_CFG0_INIT);
303-
pmu_mmio_write(CSU_PUF_CFG1, CSU_PUF_CFG1_INIT);
304-
pmu_mmio_write(CSU_PUF_SHUTTER, CSU_PUF_SHUTTER_INIT);
305-
pmu_mmio_write(CSU_PUF_CMD, CSU_PUF_CMD_REGISTRATION);
306-
while (1) {
306+
ret = pmu_mmio_write(CSU_PUF_CFG0, CSU_PUF_CFG0_INIT);
307+
if (ret == 0)
308+
ret = pmu_mmio_write(CSU_PUF_CFG1, CSU_PUF_CFG1_INIT);
309+
if (ret == 0)
310+
ret = pmu_mmio_write(CSU_PUF_SHUTTER, CSU_PUF_SHUTTER_INIT);
311+
if (ret == 0)
312+
ret = pmu_mmio_write(CSU_PUF_CMD, CSU_PUF_CMD_REGISTRATION);
313+
while (ret == 0) {
307314
/* Wait for PUF status done */
308315
while (((puf_status = pmu_mmio_read(CSU_PUF_STATUS))
309316
& CSU_PUF_STATUS_SYN_WRD_RDY_MASK) == 0
310-
&& ++timeout < PUF_REG_TIMEOUT);
311-
if (timeout == PUF_REG_TIMEOUT) {
317+
&& ++timeout < CSU_PUF_REG_TIMEOUT);
318+
if (timeout == CSU_PUF_REG_TIMEOUT) {
312319
ret = -1; /* timeout */
313320
break;
314321
}
@@ -341,14 +348,16 @@ int csu_puf_register(uint32_t* syndrome, uint32_t* syndromeSz, uint32_t* chash,
341348

342349
return ret;
343350
}
351+
#endif /* CSU_PUF_ROT */
344352

345-
#define CSU_PUF_SYNDROME_WORDS 386
346353
int csu_init(void)
347354
{
348-
int ret;
355+
int ret = 0;
356+
#ifdef CSU_PUF_ROT
349357
uint32_t syndrome[CSU_PUF_SYNDROME_WORDS];
350358
uint32_t syndromeSz = (uint32_t)sizeof(syndrome);
351359
uint32_t chash=0, aux=0;
360+
#endif
352361
uint32_t reg1 = pmu_mmio_read(CSU_IDCODE);
353362
uint32_t reg2 = pmu_mmio_read(CSU_VERSION);
354363

@@ -371,7 +380,9 @@ int csu_init(void)
371380
hal_delay_ms(500); /* give time for debugger to break */
372381
#endif
373382

383+
#ifdef CSU_PUF_ROT
374384
ret = csu_puf_register(syndrome, &syndromeSz, &chash, &aux);
385+
#endif
375386

376387
return ret;
377388
}

hal/zynq.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,14 @@
485485
#define CSU_PUF_CMD_REGISTRATION 0x1 /* Key registration */
486486

487487
#define CSU_PUF_CFG0_INIT 0x2
488-
#define CSU_PUF_CFG1_INIT 0x0C230090 /* 0x00080080 */
489-
#define CSU_PUF_SHUTTER_INIT 0x0100005E /* 0x01000100 */
490-
491-
#define CSU_PUF_STATUS_OVERFLOW_MASK 0x30000000 /* Overflow, if bits are not 0. Reduce SHUT[SOPEN] value. */
492-
#define CSU_PUF_STATUS_AUX_MASK 0x0FFFFFF0 /* During provisioning, auxiliary sundrome bits are stored here and must be written to the eFuse or boot image. */
493-
#define CSU_PUF_STATUS_KEY_RDY_MASK 0x00000008
494-
#define CSU_PUF_STATUS_KEY_ZERO_MASK 0x00000002 /* Indicates that the PUF key has been zeroized */
495-
#define CSU_PUF_STATUS_SYN_WRD_RDY_MASK 0x00000001 /* Indicates a syndrome word is ready in the PUF_WORD register. */
488+
#define CSU_PUF_CFG1_INIT 0x0C230090U /* 4K */
489+
#define CSU_PUF_SHUTTER_INIT 0x00100005E /* 0x01000100 */
490+
491+
#define CSU_PUF_STATUS_OVERFLOW_MASK (0x3U << 28) /* Overflow, if bits are not 0. Reduce SHUT[SOPEN] value. */
492+
#define CSU_PUF_STATUS_AUX_MASK (0xFFFFFFU << 4) /* During provisioning, auxiliary sundrome bits are stored here and must be written to the eFuse or boot image. */
493+
#define CSU_PUF_STATUS_KEY_RDY_MASK (0x1U << 3) /* Indicates that the key is ready */
494+
#define CSU_PUF_STATUS_KEY_ZERO_MASK (0x1U << 1) /* Indicates that the PUF key has been zeroized */
495+
#define CSU_PUF_STATUS_SYN_WRD_RDY_MASK (0x1U << 0) /* Indicates a syndrome word is ready in the PUF_WORD register */
496496

497497
/* SHA3 */
498498
#define CSU_SHA_START (CSU_BASE + 0x2000U)

0 commit comments

Comments
 (0)