[Cryptech-Commits] [core/platform/novena] 01/01: add tools to configure and start an FPGA bitstream

git at cryptech.is git at cryptech.is
Tue Jun 23 22:52:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository core/platform/novena.

commit ce8f42a5182a4c365e9ae2703f41efdefa6420c9
Author: Paul Selkirk <paul at psgd.org>
Date:   Tue Jun 23 18:15:27 2015 -0400

    add tools to configure and start an FPGA bitstream
---
 sw/Makefile          |  9 ++++++---
 sw/configure-fpga.sh | 13 +++++++++++++
 sw/devmem3.c         | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/sw/Makefile b/sw/Makefile
index fc5faa6..928466e 100755
--- a/sw/Makefile
+++ b/sw/Makefile
@@ -3,7 +3,7 @@ AR = ar
 CFLAGS = -Wall -fPIC
 
 LIB = libcryptech.a
-BIN = hash hash_tester trng_extractor trng_tester aes_tester modexp_tester
+BIN = hash hash_tester trng_extractor trng_tester aes_tester modexp_tester devmem3
 INC = cryptech.h
 
 PREFIX = /usr/local
@@ -37,14 +37,17 @@ hash: hash.o $(LIB)
 trng_extractor: trng_extractor.o $(LIB)
 	$(CC) -o $@ $^
 
+devmem3: devmem3.o $(LIB)
+	$(CC) -o $@ $^
+
 install: $(LIB) $(BIN) $(INC)
 	install $(LIB) $(LIB_DIR)
-	install $(BIN) $(BIN_DIR)
+	install $(BIN) configure-fpga.sh $(BIN_DIR)
 	install $(INC) $(INC_DIR)
 
 uninstall:
 	rm -f $(LIB_DIR)/$(LIB)
-	rm -f $(foreach bin,$(BIN),$(BIN_DIR)/$(bin))
+	rm -f $(foreach bin,$(BIN) configure-fpga.sh,$(BIN_DIR)/$(bin))
 	rm -f $(INC_DIR)/$(INC)
 
 clean:
diff --git a/sw/configure-fpga.sh b/sw/configure-fpga.sh
new file mode 100644
index 0000000..7ebfb6b
--- /dev/null
+++ b/sw/configure-fpga.sh
@@ -0,0 +1,13 @@
+#!/bin/sh -
+bitfile="${1-novena_eim.bit}"
+echo "Setting export of reset pin"
+echo 135 > /sys/class/gpio/export
+echo "setting reset pin to out"
+echo out > /sys/class/gpio/gpio135/direction
+echo "flipping reset"                       
+echo 0 > /sys/class/gpio/gpio135/value
+echo 1 > /sys/class/gpio/gpio135/value
+echo "configuring FPGA"               
+dd if=${bitfile} of=/dev/spidev2.0 bs=128
+echo "turning on clock to FPGA"                              
+devmem3 0x020c8160 w 0x00000D2B
diff --git a/sw/devmem3.c b/sw/devmem3.c
new file mode 100644
index 0000000..3c3fa16
--- /dev/null
+++ b/sw/devmem3.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "novena-eim.h"
+
+int
+main(int argc, char *argv[])
+{
+    off_t offset;
+    uint32_t value, result;
+
+    if (argc < 3 || argc > 4) {
+    usage:
+	fprintf(stderr, "usage: %s offset r\n", argv[0]);
+	fprintf(stderr, "usage: %s offset w value\n", argv[0]);
+	exit(EXIT_FAILURE);
+    }
+
+    if (eim_setup() != 0) {
+        fprintf(stderr, "EIM setup failed\n");
+	exit(EXIT_FAILURE);
+    }
+
+    offset = (off_t)strtoul(argv[1], NULL, 0);
+    if (argv[2][0] == 'r') {
+	eim_read_32(offset, &result);
+	printf("%08x\n", result);
+    }
+    else if (argv[2][0] == 'w') {
+	value = strtoul(argv[3], NULL, 0);
+	eim_write_32(offset, &value);
+    }
+    else {
+	fprintf(stderr, "unknown command '%s'\n", argv[2]);
+	goto usage;
+    }
+
+    exit(EXIT_SUCCESS);
+}
+



More information about the Commits mailing list