additional comments, code readability, and error check

This commit is contained in:
Jacob Barthelmeh
2021-06-14 21:40:51 +07:00
parent 9fadc21e0f
commit 70063213a5
2 changed files with 9 additions and 4 deletions

View File

@ -436,6 +436,7 @@ static void print_jdkek()
/* instantiate RNG and create JDKEK, TDKEK, and TDSK key */
#define WC_RNG_START_SIZE 6
static unsigned int wc_rng_start[] = {
CAAM_HEAD | 0x00000006,
CAAM_OP | CAAM_CLASS1 | CAAM_RNG | 0x00000004, /* Instantiate RNG handle 0
@ -459,7 +460,7 @@ int caamInitRng(struct CAAM_DEVICE* dev)
/* set up the job description for RNG initialization */
memset(&desc, 0, sizeof(DESCSTRUCT));
desc.desc[desc.idx++] = CAAM_HEAD; /* later will put size to header*/
for (i = 1; i < 6; i = i + 1) {
for (i = 1; i < WC_RNG_START_SIZE; i = i + 1) {
desc.desc[desc.idx++] = wc_rng_start[i];
}
desc.caam = dev;
@ -474,7 +475,7 @@ int caamInitRng(struct CAAM_DEVICE* dev)
/* Set up use of the TRNG for seeding wolfSSL HASH-DRBG */
/* check out the status and see if already setup */
CAAM_WRITE(CAAM_RTMCTL, CAAM_PRGM);
CAAM_WRITE(CAAM_RTMCTL, CAAM_READ(CAAM_RTMCTL) | 0x40); /* reset */
CAAM_WRITE(CAAM_RTMCTL, CAAM_READ(CAAM_RTMCTL) | CAAM_RTMCTL_RESET);
/* Set up reading from TRNG */
CAAM_WRITE(CAAM_RTMCTL, CAAM_READ(CAAM_RTMCTL) | CAAM_TRNG);
@ -494,7 +495,7 @@ int caamInitRng(struct CAAM_DEVICE* dev)
#endif
/* Set back to run mode and clear RTMCL error bit */
reg = CAAM_READ(CAAM_RTMCTL) ^ CAAM_PRGM;
reg = CAAM_READ(CAAM_RTMCTL) & (~CAAM_PRGM);
CAAM_WRITE(CAAM_RTMCTL, reg);
reg = CAAM_READ(CAAM_RTMCTL);
reg |= CAAM_CTLERR;
@ -1440,6 +1441,8 @@ int InitCAAM(void)
break;
}
if (ret != Success) {
WOLFSSL_MSG("Failed to find a partition on startup");
INTERRUPT_Panic();
return -1;
}

View File

@ -182,7 +182,8 @@
/* RNG Masks/Values */
#ifndef CAAM_ENT_DLY
/*less than half the default value to try and increase entropy collection */
/* Less than half the default value to try and increase entropy collection.
* Value is system clock cycles. */
#define CAAM_ENT_DLY 1200
#endif
#ifndef CAAM_ENT_DLY_INCREMENT
@ -206,6 +207,7 @@
#define CAAM_PRGM 0x00010000 /* Set RTMCTL to program state */
#define CAAM_TRNG 0x00000020 /* Set TRNG access */
#define CAAM_RTMCTL_RESET 0x40 /* TRNG reset to defaults */
#define CAAM_CTLERR 0x00001000
#define CAAM_ENTVAL 0x00000400 /* checking RTMCTL for entropy ready */