-
Notifications
You must be signed in to change notification settings - Fork 2
/
compile-using.py
44 lines (31 loc) · 998 Bytes
/
compile-using.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
#!/usr/bin/env python3
import sys
from subprocess import Popen, PIPE, STDOUT
import os
import tempfile
# read input file into temp file to bypass qemu bash <() syntax buf
with open(sys.argv[1], "rb") as f:
kernel = f.read()
tmp_fd, tmp_path = tempfile.mkstemp()
with os.fdopen(tmp_fd, 'wb') as tmp:
tmp.write(kernel)
cmd = [
"qemu-system-aarch64",
"-M", "raspi4",
"-nographic",
"-serial", "mon:stdio",
"-monitor", "telnet::45454,server,nowait",
# "-monitor", "none",
"-kernel", tmp_path]
p = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
p.stdin.write((''.join(sys.stdin.readlines()).rstrip() + '\n\x00').encode())
p.stdin.close()
num_bytes = 0
num_bytes = (num_bytes << 8) + ord(p.stdout.read(1))
num_bytes = (num_bytes << 8) + ord(p.stdout.read(1))
num_bytes = (num_bytes << 8) + ord(p.stdout.read(1))
num_bytes = (num_bytes << 8) + ord(p.stdout.read(1))
for _ in range(num_bytes):
sys.stdout.buffer.write(p.stdout.read(1))
p.terminate()
os.remove(tmp_path)