diff options
author | Fredrik Thulin <fredrik@thulin.net> | 2016-08-15 15:37:41 +0200 |
---|---|---|
committer | Fredrik Thulin <fredrik@thulin.net> | 2016-08-15 15:37:41 +0200 |
commit | 7d4c495489ffa299118e3586d94d3a02af13a810 (patch) | |
tree | aaf87aeff1ae7328c1acb710acd9b619866d6626 | |
parent | 4758a8c13add7b04eda596595c7d192ffad9c3d5 (diff) |
-rwxr-xr-x | bin/cryptech_runcmd | 44 | ||||
-rwxr-xr-x | bin/cryptech_upload | 10 | ||||
-rwxr-xr-x | run.sh | 12 | ||||
-rwxr-xr-x | test.sh | 31 |
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' @@ -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 @@ -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" + |