Skip to content

Instantly share code, notes, and snippets.

@Programator2
Created November 7, 2019 09:42
Show Gist options
  • Save Programator2/795891b2cf4e044bd066ada9d7b172ff to your computer and use it in GitHub Desktop.
Save Programator2/795891b2cf4e044bd066ada9d7b172ff to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from subprocess import run, PIPE, Popen, CalledProcessError
from sys import exit
from os import chdir
def main():
# TODO CHANGE PATH TO MEDUSA
chdir('/home/user/medusa')
try:
run(['stty', '-F', '/dev/ttyS0', 'raw', '-echo'], check=True)
# run(['stty', '-F', '/dev/ttyS1', 'raw', '-echo'], check=True)
except CalledProcessError as e:
print('Error', e)
exit(-1)
p = Popen(['socat', '-d', '-d', '/dev/ttyS0', 'pty'], bufsize=1,stderr=PIPE,
universal_newlines=True)
while p.poll() is None:
out = p.stderr.readline()
print(out, end='')
if not out:
print('Error reading socat')
exit(-1)
i = out.find('N PTY is')
if i != -1:
lines = out[i+9:].splitlines()
pts = lines[0]
print(pts)
with open('remote.txt', 'w') as f:
f.write('target remote ' + pts + '\n')
break
run(['gdb', 'vmlinux', '-x', 'remote.txt'])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment