Created
June 17, 2016 06:49
-
-
Save anonymous/a39572f22ff118bf59c65c4f523a4c3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find_firm.py | |
# finds firmware | |
# currently looks in: | |
# HDMI2USB-firmware-prebuilt/archive/master/*/atlys/hdmi2usb | |
import logging | |
import os | |
import serial | |
import subprocess | |
import time | |
logging.basicConfig( | |
level=logging.DEBUG, | |
format="%(levelname)s | %(asctime)s | %(module)s | %(message)s", | |
datefmt='%Y-%m-%d %H:%M:%S', | |
) | |
logger = logging.getLogger(__name__) | |
handler = logging.FileHandler("find_firm.log") | |
logger.addHandler(handler) | |
def run_cmd(cmd): | |
print( ' '.join(cmd) ) | |
p=subprocess.Popen(cmd) | |
p.wait() | |
retcode=p.returncode | |
print(retcode) | |
return retcode | |
def reset_usb(dev_id): | |
print("unbind") | |
open("/sys/bus/pci/drivers/ehci-pci/unbind",'wb').write(dev_id) | |
time.sleep(1) | |
print("bind") | |
open("/sys/bus/pci/drivers/ehci-pci/bind",'wb').write(dev_id) | |
print("sleeping...") | |
time.sleep(25) | |
return | |
def get_prompt(ser): | |
r = ser.write(b'\n') | |
line = ser.readline() | |
print( "line 1", line ) | |
# line 1 b'\n' | |
b = ser.write(b'\n') | |
line = ser.readline() | |
print( "line 2", line ) | |
# line 2 b'\x1b[1mBIOS>\x1b[0m \n' | |
b = ser.write(b'\n') | |
line = ser.readline() | |
print( "line 3", line ) | |
return line | |
def get_ver(ser): | |
while True: | |
r = ser.write(b'version\n') | |
line = ser.readline() | |
print( "line", line ) | |
line = str(line.strip()) | |
if "describe" in line: | |
ver = line.split(':')[1] | |
break | |
elif len(line)==0: | |
ver = "not found" | |
break | |
return ver | |
def test_one(root,f,board): | |
pth = os.path.join(root,f,board,"hdmi2usb") | |
run_cmd(["hdmi2usb-mode-switch", "--mode=jtag"]) | |
# fp = "{}/atlys_hdmi2usb-hdmi2usbsoc-atlys.bit".format(pth) | |
fp = "{pth}/{board}_hdmi2usb-hdmi2usbsoc-{board}.bit".format( | |
pth=pth, board=board) | |
run_cmd( ['openocd', '-f', 'board/digilent_atlys.cfg', | |
'-c', "init; pld load 0 {}; exit".format(fp) ] ) | |
fp = "{}/hdmi2usb.hex".format(pth) | |
run_cmd( ['fxload', '-B', 'libusb', | |
'-D', 'vid=0x16c0,pid=0x06ad', '-t', 'fx2lp', '-I', fp] ) | |
reset_usb(b"0000:00:1a.0") | |
with serial.Serial('/dev/ttyVIZ0', 115200, timeout=1) as ser: | |
print("name", ser.name) | |
prompt = get_prompt(ser) | |
if b"HDMI2USB>" in prompt: | |
mt = "pass" | |
elif b"BIOS" in prompt: | |
mt = "fail" | |
else: | |
mt = "unknown" | |
# remove the trailing \n | |
prompt = prompt.strip() | |
if mt == "pass": | |
ver = get_ver(ser) | |
else: | |
ver = "skipped" | |
logger.info("%s\t%s\t%s\t%s", f, mt, prompt, ver) | |
return | |
def test_all(root, board): | |
fs=os.listdir(root) | |
fs.sort(reverse=True) | |
for f in fs: | |
pth = os.path.join(root,f,board,"hdmi2usb") | |
found = os.path.exists(pth) | |
if found: | |
test_one(root, f, board) | |
else: | |
mt = "no dir" | |
logger.info("%s\t%s", f, mt) | |
return | |
def main(): | |
root="HDMI2USB-firmware-prebuilt/archive/master" | |
# board="opsis" | |
board="atlys" | |
logger.info(board) | |
# f = "v0.0.0-639-g956a8b3" | |
# test_one(root, f, board) | |
test_all( root, board ) | |
if __name__=='__main__': | |
# foo() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It should be possible to replace the openocd line with a mode-switch line.