docs: CHANGELOG in English, README without the mirror link; Haiku VM tooling
- CHANGELOG.md translated to English (GitHub release notes of v0.1.0 and v0.2.0 updated accordingly) - tools/haiku-vm.sh: Haiku R1/beta6 x86_64 VM under QEMU/KVM (verified image, 20 GB disk, virtual USB stick, SSH port forward, QMP socket) - tools/qmp.py: headless control through QMP (PNG screenshots, absolute clicks, typing, key combos, power-off) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
This commit is contained in:
1 parent
32412fe6be
commit
1c1ccd631a
4 files changed
+285
-31
No files matched your search
@@ -0,0 +1,82 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: MIT
|
||||
# Haiku R1/beta6 x86_64 development VM under QEMU (Linux / WSL2, KVM when available).
|
||||
#
|
||||
# tools/haiku-vm.sh fetch download + verify the official anyboot image
|
||||
# tools/haiku-vm.sh install boot the image with an empty 20 GB disk (run the Installer, see docs)
|
||||
# tools/haiku-vm.sh start boot the installed system (headless, VNC on 127.0.0.1:5901)
|
||||
# tools/haiku-vm.sh stop ACPI power-off (hard kill after 60 s)
|
||||
# tools/haiku-vm.sh ssh [cmd] ssh into the VM (port 2222, user "user")
|
||||
# tools/haiku-vm.sh status
|
||||
#
|
||||
# A 16 GB sparse raw image is attached as a USB mass-storage device ("the stick"), so the
|
||||
# Haiku USB backend can be tested end to end; inspect it from Linux with mtools.
|
||||
# The VM is driven with tools/qmp.py (screenshots, clicks, typing) through $VM_DIR/qmp.sock.
|
||||
set -eu
|
||||
|
||||
VM_DIR=${OPENPU_VM_DIR:-$HOME/openpu-vm}
|
||||
RELEASE=r1beta6
|
||||
ISO=$VM_DIR/haiku-$RELEASE-x86_64-anyboot.iso
|
||||
ISO_SHA256=bb7743474fd175aea511be1799764ba054465285bbdf54c4722ca61d1fb4f5c9
|
||||
ISO_URL=https://mirrors.rit.edu/haiku/$RELEASE/haiku-$RELEASE-x86_64-anyboot.iso
|
||||
DISK=$VM_DIR/haiku.qcow2
|
||||
STICK=$VM_DIR/haiku-usb.img
|
||||
QMP=$VM_DIR/qmp.sock
|
||||
PIDFILE=$VM_DIR/qemu.pid
|
||||
SSH_PORT=${OPENPU_VM_SSH_PORT:-2222}
|
||||
|
||||
mkdir -p "$VM_DIR"
|
||||
|
||||
running() { [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; }
|
||||
|
||||
qemu() {
|
||||
accel="-accel tcg"
|
||||
[ -w /dev/kvm ] && accel="-accel kvm -cpu host"
|
||||
[ -f "$STICK" ] || truncate -s 16G "$STICK"
|
||||
# shellcheck disable=SC2086
|
||||
qemu-system-x86_64 $accel -machine q35 -smp 4 -m 4096 \
|
||||
-drive file="$DISK",format=qcow2,if=none,id=hd0 -device ide-hd,drive=hd0,bus=ide.0 \
|
||||
-nic user,model=e1000,hostfwd=tcp:127.0.0.1:"$SSH_PORT"-:22 \
|
||||
-device qemu-xhci,id=xhci -device usb-tablet,bus=xhci.0 \
|
||||
-drive file="$STICK",format=raw,if=none,id=stick \
|
||||
-device usb-storage,bus=xhci.0,drive=stick,removable=on \
|
||||
-display none -vnc 127.0.0.1:1 \
|
||||
-qmp unix:"$QMP",server=on,wait=off \
|
||||
-daemonize -pidfile "$PIDFILE" "$@"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
fetch)
|
||||
[ -f "$ISO" ] || curl -fL -o "$ISO.part" "$ISO_URL" && { [ -f "$ISO" ] || mv "$ISO.part" "$ISO"; }
|
||||
echo "$ISO_SHA256 $ISO" | sha256sum -c -
|
||||
;;
|
||||
install)
|
||||
running && { echo "VM already running" >&2; exit 1; }
|
||||
[ -f "$DISK" ] || qemu-img create -f qcow2 "$DISK" 20G
|
||||
qemu -drive file="$ISO",media=cdrom,if=none,id=cd -device ide-cd,drive=cd,bus=ide.1 -boot d
|
||||
echo "installer booted (VNC 127.0.0.1:5901, QMP $QMP)"
|
||||
;;
|
||||
start)
|
||||
running && { echo "VM already running"; exit 0; }
|
||||
qemu -boot c
|
||||
echo "VM started (VNC 127.0.0.1:5901, ssh -p $SSH_PORT user@127.0.0.1)"
|
||||
;;
|
||||
stop)
|
||||
running || { echo "VM not running"; exit 0; }
|
||||
python3 "$(dirname "$0")/qmp.py" --socket "$QMP" powerdown || true
|
||||
for _ in $(seq 60); do running || { echo "stopped"; exit 0; }; sleep 1; done
|
||||
kill "$(cat "$PIDFILE")"; echo "killed"
|
||||
;;
|
||||
ssh)
|
||||
shift
|
||||
exec ssh -p "$SSH_PORT" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR \
|
||||
user@127.0.0.1 "$@"
|
||||
;;
|
||||
status)
|
||||
running && echo "running (pid $(cat "$PIDFILE"))" || echo "stopped"
|
||||
;;
|
||||
*)
|
||||
sed -n '3,12p' "$0" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Drive a headless QEMU VM through QMP: screenshots, absolute clicks, typing, power-off.
|
||||
|
||||
usage: python3 tools/qmp.py [--socket PATH] COMMAND...
|
||||
shot OUT.png screenshot (PNG, no external dependency)
|
||||
click X Y [right|double] click at screen pixel X,Y (needs a usb-tablet device)
|
||||
move X Y move the pointer
|
||||
type TEXT type text with a US keyboard layout
|
||||
key COMBO... press key combos, e.g. ret, tab, ctrl-alt-delete, alt-f4
|
||||
powerdown ACPI power button
|
||||
hmp COMMAND human monitor command (prints the answer)
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
import zlib
|
||||
|
||||
|
||||
class Qmp:
|
||||
def __init__(self, path):
|
||||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.sock.connect(path)
|
||||
self.buf = b""
|
||||
self._read() # greeting
|
||||
self.cmd("qmp_capabilities")
|
||||
|
||||
def _read(self):
|
||||
while b"\n" not in self.buf:
|
||||
chunk = self.sock.recv(65536)
|
||||
if not chunk:
|
||||
raise RuntimeError("QMP connection closed")
|
||||
self.buf += chunk
|
||||
line, self.buf = self.buf.split(b"\n", 1)
|
||||
return json.loads(line)
|
||||
|
||||
def cmd(self, name, **args):
|
||||
self.sock.sendall(json.dumps({"execute": name, "arguments": args}).encode() + b"\n")
|
||||
while True:
|
||||
msg = self._read()
|
||||
if "return" in msg:
|
||||
return msg["return"]
|
||||
if "error" in msg:
|
||||
raise RuntimeError(f"{name}: {msg['error'].get('desc')}")
|
||||
# asynchronous events are ignored
|
||||
|
||||
|
||||
def ppm_to_png(ppm, png):
|
||||
data = open(ppm, "rb").read()
|
||||
fields, pos = [], 0
|
||||
while len(fields) < 4: # P6, width, height, maxval
|
||||
while data[pos:pos + 1].isspace():
|
||||
pos += 1
|
||||
if data[pos:pos + 1] == b"#":
|
||||
pos = data.index(b"\n", pos) + 1
|
||||
continue
|
||||
end = pos
|
||||
while not data[end:end + 1].isspace():
|
||||
end += 1
|
||||
fields.append(data[pos:end])
|
||||
pos = end
|
||||
width, height = int(fields[1]), int(fields[2])
|
||||
pixels = data[pos + 1:]
|
||||
stride = width * 3
|
||||
raw = b"".join(b"\x00" + pixels[y * stride:(y + 1) * stride] for y in range(height))
|
||||
|
||||
def chunk(kind, payload):
|
||||
body = kind + payload
|
||||
return struct.pack(">I", len(payload)) + body + struct.pack(">I", zlib.crc32(body) & 0xFFFFFFFF)
|
||||
|
||||
with open(png, "wb") as f:
|
||||
f.write(b"\x89PNG\r\n\x1a\n")
|
||||
f.write(chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0)))
|
||||
f.write(chunk(b"IDAT", zlib.compress(raw, 6)))
|
||||
f.write(chunk(b"IEND", b""))
|
||||
return width, height
|
||||
|
||||
|
||||
def screen_size(q):
|
||||
tmp = f"/tmp/qmp-size-{os.getpid()}.ppm"
|
||||
q.cmd("screendump", filename=tmp)
|
||||
with open(tmp, "rb") as f:
|
||||
head = f.read(64).split()
|
||||
os.unlink(tmp)
|
||||
return int(head[1]), int(head[2])
|
||||
|
||||
|
||||
def move(q, x, y):
|
||||
w, h = screen_size(q)
|
||||
q.cmd("input-send-event", events=[
|
||||
{"type": "abs", "data": {"axis": "x", "value": int(x * 32767 / max(1, w - 1))}},
|
||||
{"type": "abs", "data": {"axis": "y", "value": int(y * 32767 / max(1, h - 1))}},
|
||||
])
|
||||
|
||||
|
||||
def click(q, x, y, mode="left"):
|
||||
move(q, x, y)
|
||||
button = "right" if mode == "right" else "left"
|
||||
for _ in range(2 if mode == "double" else 1):
|
||||
for down in (True, False):
|
||||
q.cmd("input-send-event", events=[{"type": "btn", "data": {"down": down, "button": button}}])
|
||||
time.sleep(0.05)
|
||||
|
||||
|
||||
SHIFTED = {"_": "minus", ":": "semicolon", "\"": "apostrophe", "<": "comma", ">": "dot", "?": "slash",
|
||||
"!": "1", "@": "2", "#": "3", "$": "4", "%": "5", "^": "6", "&": "7", "*": "8", "(": "9",
|
||||
")": "0", "+": "equal", "{": "bracket_left", "}": "bracket_right", "|": "backslash", "~": "grave_accent"}
|
||||
PLAIN = {" ": "spc", "-": "minus", ".": "dot", "/": "slash", ",": "comma", ";": "semicolon", "'": "apostrophe",
|
||||
"=": "equal", "[": "bracket_left", "]": "bracket_right", "\\": "backslash", "`": "grave_accent",
|
||||
"\n": "ret", "\t": "tab"}
|
||||
|
||||
|
||||
def keys_for(ch):
|
||||
if ch.isalpha() and ch.isascii():
|
||||
return (["shift"] if ch.isupper() else []) + [ch.lower()]
|
||||
if ch.isdigit():
|
||||
return [ch]
|
||||
if ch in PLAIN:
|
||||
return [PLAIN[ch]]
|
||||
if ch in SHIFTED:
|
||||
return ["shift", SHIFTED[ch]]
|
||||
raise ValueError(f"cannot type {ch!r}")
|
||||
|
||||
|
||||
def press(q, names):
|
||||
q.cmd("send-key", keys=[{"type": "qcode", "data": n} for n in names], **{"hold-time": 50})
|
||||
time.sleep(0.03)
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
path = os.path.expanduser("~/openpu-vm/qmp.sock")
|
||||
if args[:1] == ["--socket"]:
|
||||
path, args = args[1], args[2:]
|
||||
if not args:
|
||||
print(__doc__, file=sys.stderr)
|
||||
sys.exit(2)
|
||||
q = Qmp(path)
|
||||
cmd, rest = args[0], args[1:]
|
||||
if cmd == "shot":
|
||||
tmp = os.path.abspath(rest[0]) + ".ppm"
|
||||
q.cmd("screendump", filename=tmp)
|
||||
w, h = ppm_to_png(tmp, rest[0])
|
||||
os.unlink(tmp)
|
||||
print(f"{rest[0]} {w}x{h}")
|
||||
elif cmd == "click":
|
||||
click(q, int(rest[0]), int(rest[1]), rest[2] if len(rest) > 2 else "left")
|
||||
elif cmd == "move":
|
||||
move(q, int(rest[0]), int(rest[1]))
|
||||
elif cmd == "type":
|
||||
for ch in " ".join(rest):
|
||||
press(q, keys_for(ch))
|
||||
elif cmd == "key":
|
||||
for combo in rest:
|
||||
press(q, combo.split("-"))
|
||||
elif cmd == "powerdown":
|
||||
q.cmd("system_powerdown")
|
||||
elif cmd == "hmp":
|
||||
print(q.cmd("human-monitor-command", **{"command-line": " ".join(rest)}))
|
||||
else:
|
||||
print(__doc__, file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
main()
|
||||
Reference in new issue
Block a user