[Cryptech-Commits] [user/ft/bootstrap] 06/06: add test script
git at cryptech.is
git at cryptech.is
Mon Aug 15 13:38:29 UTC 2016
This is an automated email from the git hooks/post-receive script.
fredrik at thulin.net pushed a commit to branch master
in repository user/ft/bootstrap.
commit 7d4c495489ffa299118e3586d94d3a02af13a810
Author: Fredrik Thulin <fredrik at thulin.net>
AuthorDate: Mon Aug 15 15:37:41 2016 +0200
add test script
---
bin/cryptech_runcmd | 44 ++++++++++++++++++++++++++++++--------------
bin/cryptech_upload | 10 +++++-----
run.sh | 12 ++++++++----
run.sh => test.sh | 26 +++++++++-----------------
4 files changed, 52 insertions(+), 40 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/run.sh b/test.sh
similarity index 53%
copy from run.sh
copy to test.sh
index d6243e2..8c74be1 100755
--- a/run.sh
+++ b/test.sh
@@ -3,37 +3,29 @@
set -e
echo "##########################################"
-echo "# Flashing bootloader"
-echo "##########################################"
-./bin/flash-target bootloader
-
-echo "##########################################"
-echo "# Flashing temporary HSM firmware"
+echo "# Flashing cli-test HSM firmware"
echo "##########################################"
./bin/flash-target firmware/cli-test
./bin/reset
sleep 5
echo "##########################################"
-echo "# Uploading bitstream"
+echo "# Checking FPGA"
echo "##########################################"
-
-./bin/cryptech_upload --fpga --username wheel
+./bin/cryptech_runcmd --username ct "show fpga cores"
echo "##########################################"
-echo "# Programming AVR"
+echo "# Testing SDRAM FMC bus"
echo "##########################################"
-avrdude -c usbtiny -p attiny828 -U flash:w:firmware/tamper.hex
+./bin/cryptech_runcmd --username ct --timeout 20 "test sdram"
echo "##########################################"
-echo "# Flashing official STM32 firmware"
+echo "# Uploading FMC test bitstream"
echo "##########################################"
-./bin/cryptech_upload --firmware --username wheel
-./bin/reset
-sleep 15
+./bin/cryptech_upload --fpga --username ct -i firmware/alpha_fmc_top.bit
echo "##########################################"
-echo "# Checking FPGA"
+echo "# Testing FPGA FMC bus"
echo "##########################################"
-./bin/cryptech_runcmd --username wheel "fpga show cores"
+./bin/cryptech_runcmd --username ct --timeout 20 "test fmc"
More information about the Commits
mailing list