-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.py
executable file
·55 lines (41 loc) · 1.08 KB
/
loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/env python
import serial
import os
import sys, termios, atexit
from select import select
import threading
import queue
def send_magic(ser):
ser.write([1,1,1,1])
def send_file(file_name):
file_size = os.path.getsize(file_name)
ser.write(file_size.to_bytes(4, 'little'))
print(f'Sending {file_name}({file_size} bytes)')
with open(file_name, mode= 'rb') as f:
contents = f.read(file_size)
ser.write(contents)
def get_input():
print('> ', end='')
return input()
def get_term(ser):
msg = b''
while True:
c = ser.read()
msg += c
if c == b'\n':
break
return msg.decode('utf-8')
def boot(ser, file_name):
send_magic(ser)
send_file(file_name)
if __name__ == '__main__':
ser = serial.Serial('/dev/ttyUSB1', 115200)
file_name = 'target/armv7a-none-eabi/release/kernel'
boot(ser, file_name)
while True:
msg = ser.read()
try:
print(msg.decode('utf-8'), end='')
except UnicodeDecodeError:
print(msg)
ser.close()