aboutsummaryrefslogtreecommitdiff
path: root/sw/trng_extractor.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2015-06-10 12:30:58 -0400
committerPaul Selkirk <paul@psgd.org>2015-06-10 12:30:58 -0400
commitf141a79d805acbab07876d9f007e8809603718b5 (patch)
tree62e2a730ce6b388efef8b20d32ccbef940697bdd /sw/trng_extractor.c
parent80205a9ff9a8b4da93aa74d7b73f16832682384a (diff)
generate core_selector, probe FPGA for cores at software startup
Diffstat (limited to 'sw/trng_extractor.c')
-rw-r--r--sw/trng_extractor.c58
1 files changed, 21 insertions, 37 deletions
diff --git a/sw/trng_extractor.c b/sw/trng_extractor.c
index e25ebf0..c0ff227 100644
--- a/sw/trng_extractor.c
+++ b/sw/trng_extractor.c
@@ -53,31 +53,18 @@ char *usage =
-v verbose operation\n\
";
-/* check availability of avalanche entropy core by reading core name and version */
-static int avalanche_check(void)
-{
- return
- tc_expected(ENTROPY1_ADDR_NAME0, (const uint8_t *)AVALANCHE_ENTROPY_NAME0, 4) ||
- tc_expected(ENTROPY1_ADDR_NAME1, (const uint8_t *)AVALANCHE_ENTROPY_NAME1, 4);
-}
+/* ---------------- startup code ---------------- */
-/* check availability of rosc core by reading the core name and version */
-static int rosc_check(void)
-{
- return
- tc_expected(ENTROPY2_ADDR_NAME0, (const uint8_t *)ROSC_ENTROPY_NAME0, 4) ||
- tc_expected(ENTROPY2_ADDR_NAME1, (const uint8_t *)ROSC_ENTROPY_NAME1, 4);
-}
+static off_t entropy1_addr_base, entropy2_addr_base, csprng_addr_base;
-/* check availability of csprng core by reading the core name and version */
-static int csprng_check(void)
+static void init(void)
{
- return
- tc_expected(CSPRNG_ADDR_NAME0, (const uint8_t *)CSPRNG_NAME0, 4) ||
- tc_expected(CSPRNG_ADDR_NAME1, (const uint8_t *)CSPRNG_NAME1, 4);
+ entropy1_addr_base = tc_core_base("extnoise");
+ entropy2_addr_base = tc_core_base("rosc ent");
+ csprng_addr_base = tc_core_base("csprng");
}
-/* extract one data sample */
+/* ---------------- extract one data sample ---------------- */
static int extract(off_t status_addr, off_t data_addr, uint32_t *data)
{
if (tc_wait(status_addr, ENTROPY1_STATUS_VALID, NULL) != 0) {
@@ -93,18 +80,20 @@ static int extract(off_t status_addr, off_t data_addr, uint32_t *data)
return 0;
}
-/* main */
+/* ---------------- main ---------------- */
int main(int argc, char *argv[])
{
int opt;
unsigned long num_words = 1, i;
char *endptr;
- off_t status_addr = CSPRNG_ADDR_STATUS;
- off_t data_addr = CSPRNG_ADDR_RANDOM;
+ off_t status_addr = 0;
+ off_t data_addr = 0;
FILE *output = stdout;
uint32_t data;
int verbose = 0;
+ init();
+
/* parse command line */
while ((opt = getopt(argc, argv, "h?varcn:o:")) != -1) {
switch (opt) {
@@ -113,16 +102,16 @@ int main(int argc, char *argv[])
printf(usage, argv[0]);
return EXIT_SUCCESS;
case 'a':
- status_addr = ENTROPY1_ADDR_STATUS;
- data_addr = ENTROPY1_ADDR_ENTROPY;
+ status_addr = entropy1_addr_base + ENTROPY1_ADDR_STATUS;
+ data_addr = entropy1_addr_base + ENTROPY1_ADDR_ENTROPY;
break;
case 'r':
- status_addr = ENTROPY2_ADDR_STATUS;
- data_addr = ENTROPY2_ADDR_ENTROPY;
+ status_addr = entropy2_addr_base + ENTROPY2_ADDR_STATUS;
+ data_addr = entropy2_addr_base + ENTROPY2_ADDR_ENTROPY;
break;
case 'c':
- status_addr = CSPRNG_ADDR_STATUS;
- data_addr = CSPRNG_ADDR_RANDOM;
+ status_addr = csprng_addr_base + CSPRNG_ADDR_STATUS;
+ data_addr = csprng_addr_base + CSPRNG_ADDR_RANDOM;
break;
case 'v':
verbose = 1;
@@ -171,15 +160,10 @@ int main(int argc, char *argv[])
goto errout;
}
- // Check that we can talk to the trng.
- if (verbose)
- printf("Checking that we can access the TRNG...\n");
- if (avalanche_check() || rosc_check() || csprng_check()) {
- fprintf(stderr, "Can't properly access the trng.\n");
- return EXIT_FAILURE;
+ if (status_addr == 0) {
+ status_addr = csprng_addr_base + CSPRNG_ADDR_STATUS;
+ data_addr = csprng_addr_base + CSPRNG_ADDR_RANDOM;
}
- if (verbose)
- printf("TRNG access ok..\n");
/* get the data */
for (i = 0; i < num_words; ++i) {