aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/cryptech_runcmd44
-rwxr-xr-xbin/cryptech_upload10
-rwxr-xr-xrun.sh12
-rwxr-xr-xtest.sh31
4 files changed, 74 insertions, 23 deletions
diff --git a/bin/cryptech_runcmd b/bin/cryptech_runcmd
index 61f277a..b586c16 100755
--- a/bin/cryptech_runcmd
+++ b/bin/cryptech_runcmd
@@ -91,43 +91,59 @@ def _write(dst, data, debug=False):
print("Wrote {!r}".format(data))
-def _read(dst, args, verbose=True):
+def _read(dst, retry=10, verbose=True, debug=False):
res = ''
- x = dst.read(args.timeout)
- while not x:
- x = dst.read(args.timeout)
+ x = dst.read(1)
+ while not x and retry:
+ x = dst.read(1)
+ retry -= 1
while x:
res += x
- x = dst.read(args.timeout)
- #print ("Read {!r}".format(res))
+ x = dst.read(1)
+ if debug:
+ print ("Read {!r}".format(res))
if verbose:
sys.stdout.write(res)
return res
+def _read_until_prompt(dst, retry):
+ _write(dst, '\r')
+ while retry:
+ prompt = _read(dst, retry = 1)
+ retry -= 1
+ if prompt.endswith('Username: ') or \
+ prompt.endswith('Password: ') or \
+ prompt.endswith('> '):
+ return prompt
+ return ''
+
def _execute(dst, cmd, args):
global default_pins
- _write(dst, '\r')
- prompt = _read(dst, args)
+
+ prompt = _read_until_prompt(dst, retry = args.timeout)
+
if prompt.endswith('Username: '):
- _write(dst, args.username + "\r")
- prompt = _read(dst, args)
+ _write(dst, args.username + "\r", debug = True)
+ prompt = _read(dst, retry = args.timeout)
if prompt.endswith('Password: '):
pin = default_pins.get(args.username)
if not pin:
pin = getpass.getpass("{} PIN: ".format(args.username))
_write(dst, pin + '\r')
- prompt = _read(dst, args)
+ prompt = _read(dst, retry = args.timeout)
if not prompt.endswith('> '):
#sys.stderr.write('Device does not seem to be ready for a file transfer (got {!r})\n'.format(prompt))
return prompt
- _write(dst, cmd + '\r')
- response = _read(dst, args)
+
+ _write(dst, cmd)
+
+ response = _read_until_prompt(dst, retry = args.timeout)
return response
def main(args):
global pin
- dst = serial.Serial(args.device, 921600, timeout=args.timeout)
+ dst = serial.Serial(args.device, 921600, timeout=1)
for this in args.commands:
_execute(dst, this, args)
dst.close()
diff --git a/bin/cryptech_upload b/bin/cryptech_upload
index 3222e2e..d58ecd5 100755
--- a/bin/cryptech_upload
+++ b/bin/cryptech_upload
@@ -110,10 +110,10 @@ def parse_args():
def _write(dst, data):
dst.write(data)
- #if len(data) == 4:
- # print("Wrote 0x{!s}".format(data.encode("hex")))
- #else:
- # print("Wrote {!r}".format(data))
+ if len(data) == 4:
+ print("Wrote 0x{!s}".format(data.encode("hex")))
+ else:
+ print("Wrote {!r}".format(data))
def _read(dst):
@@ -124,7 +124,7 @@ def _read(dst):
while x:
res += x
x = dst.read(1)
- #print ("Read {!r}".format(res))
+ print ("Read {!r}".format(res))
return res
wheel_pin = 'YouReallyNeedToChangeThisPINRightNowWeAreNotKidding'
diff --git a/run.sh b/run.sh
index d6243e2..3c4454a 100755
--- a/run.sh
+++ b/run.sh
@@ -5,20 +5,24 @@ set -e
echo "##########################################"
echo "# Flashing bootloader"
echo "##########################################"
-./bin/flash-target bootloader
+./bin/flash-target firmware/bootloader
echo "##########################################"
-echo "# Flashing temporary HSM firmware"
+echo "# Flashing temporary cli-test HSM firmware"
echo "##########################################"
./bin/flash-target firmware/cli-test
./bin/reset
+
+echo "##########################################"
+echo "# Sleeping after reset"
+echo "##########################################"
sleep 5
echo "##########################################"
echo "# Uploading bitstream"
echo "##########################################"
-./bin/cryptech_upload --fpga --username wheel
+./bin/cryptech_upload --fpga --username ct
echo "##########################################"
echo "# Programming AVR"
@@ -28,7 +32,7 @@ avrdude -c usbtiny -p attiny828 -U flash:w:firmware/tamper.hex
echo "##########################################"
echo "# Flashing official STM32 firmware"
echo "##########################################"
-./bin/cryptech_upload --firmware --username wheel
+./bin/cryptech_upload --firmware --username ct
./bin/reset
sleep 15
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..8c74be1
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -e
+
+echo "##########################################"
+echo "# Flashing cli-test HSM firmware"
+echo "##########################################"
+./bin/flash-target firmware/cli-test
+./bin/reset
+sleep 5
+
+echo "##########################################"
+echo "# Checking FPGA"
+echo "##########################################"
+./bin/cryptech_runcmd --username ct "show fpga cores"
+
+echo "##########################################"
+echo "# Testing SDRAM FMC bus"
+echo "##########################################"
+./bin/cryptech_runcmd --username ct --timeout 20 "test sdram"
+
+echo "##########################################"
+echo "# Uploading FMC test bitstream"
+echo "##########################################"
+./bin/cryptech_upload --fpga --username ct -i firmware/alpha_fmc_top.bit
+
+echo "##########################################"
+echo "# Testing FPGA FMC bus"
+echo "##########################################"
+./bin/cryptech_runcmd --username ct --timeout 20 "test fmc"
+