Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions scripts/run-coremark-serial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

import serial
import subprocess
import getpass
import time
import sys
import toml

config = toml.load("/tmp/coremark/serial-test-config.toml")

for i in ["U-Boot", "Bitfile"]:
result = 1
while result != 0:
result = subprocess.call((config[i]["flash_cmd"] + " " +
config[i]["path"]).split(" "))

print(i + " flash succesful.")

port_name = config["Connection"]["port_name"]
baud_rate = config["Connection"]["baud_rate"]

try:
ser = serial.Serial(port_name, baud_rate, timeout=1)
time.sleep(5) # Wait for device to initialize
print("Connected to " + port_name)

ser.flush()
result = subprocess.call(["cpu_reset"])

while True:
line = ser.readline().decode('utf-8').strip()
print("Received: " + line)
if "login:" in line:
data = input("Enter login:").encode("utf-8")
ser.write(data + b'\r\n')
ser.flush()
elif "Password" in line:
data = getpass.getpass().encode("utf-8")
ser.write(data + b'\r\n')
ser.flush()
time.sleep(10)
if ser.in_waiting:
break
time.sleep(0.01)

except serial.SerialException as e:
print("Error opening serial port " + str(e))
except KeyboardInterrupt:
print("Program terminated by user")
finally:
if ser and ser.is_open:
ser.close()
print("Serial port closed")
11 changes: 11 additions & 0 deletions scripts/serial-test-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Connection]
port_name = "/dev/ttyUSB2"
baud_rate = 115200

[U-Boot]
flash_cmd = "boston flash"
path = "/tmp/coremark/uboot-env.mcs"

[Bitfile]
flash_cmd = "boston bitfile"
path = "/tmp/coremark/example.bit"