diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f5ced2..1e2610c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,46 +1,51 @@ # Changelog -Format: [Keep a Changelog](https://keepachangelog.com/fr/1.1.0/). Versions follow -[Semantic Versioning](https://semver.org/lang/fr/): `0.x` until the Linux and Haiku applications are +Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versions follow +[Semantic Versioning](https://semver.org/): `0.x` until the Linux and Haiku applications are complete; every release is an annotated git tag `vX.Y.Z` (see `tools/release.sh`). ## [Unreleased] +### Added +- Haiku development VM tooling: `tools/haiku-vm.sh` (Haiku R1/beta6 x86_64 under QEMU/KVM, with a + virtual USB stick) and `tools/qmp.py` (headless screenshots, clicks and typing through QMP). + ## [0.2.0] - 2026-11-28 -### Ajouté -- Interface graphique GTK4 (gtkmm) : véhicules, ajout par VIN, mises à jour disponibles, choix du - dossier, téléchargement avec reprise, choix de la clé USB, écriture, guide d'installation. -- Versionnage : version CMake + `git describe` à chaque compilation, `openpu-cli --version`, - boîte « À propos », User-Agent `OpenPU/`, script `tools/release.sh`. -- Infrastructure de traduction gettext (textes sources en anglais, français fourni). -- Liens vers les guides d'installation officiels (PDF) en français et en anglais. -- Préférences : dossier de téléchargement, langue (langue du système par défaut), recherche - automatique d'une nouvelle version d'OpenPU au démarrage. -- Recherche d'une nouvelle version d'OpenPU (releases GitHub) : proposition d'ouvrir la page de - téléchargement dans le navigateur ; `openpu-cli app-update`. -- Licence MIT (`LICENSE`, en-têtes SPDX). -- Intégration continue GitHub Actions : compilation et tests sur Linux x86_64 et arm64, ASan/UBSan. +### Added +- GTK4 (gtkmm) graphical interface: vehicles, adding a vehicle by VIN, available updates, download + folder, resumable download, USB stick selection, writing, installation guide. +- Versioning: CMake version + `git describe` on every build, `openpu-cli --version`, About dialog, + `OpenPU/` User-Agent, `tools/release.sh`. +- gettext translation infrastructure (English source strings, French translation). +- Links to the official installation guides (PDF) in French and English. +- Preferences: download folder, language (system language by default), automatic check for a new + OpenPU version at startup. +- New OpenPU version check (GitHub releases), offering to open the download page in the browser; + `openpu-cli app-update`. +- MIT license (`LICENSE`, SPDX headers). +- GitHub Actions continuous integration: build and tests on Linux x86_64 and arm64, ASan/UBSan. -### Prévu -- Paquets Linux `.deb`, Flatpak et AppImage ; paquet Haiku `.hpkg`. -- À partir de 1.0.0, binaires joints à chaque release, x86_64 et arm64. +### Changed +- The main repository is now https://github.com/yann64/openpu. +- `vehicles.json` keeps the order in which vehicles were added. -### Modifié -- Le dépôt principal est désormais https://github.com/yann64/openpu (Gitea reste un miroir). -- `vehicles.json` garde l'ordre d'ajout des véhicules. +### Planned +- Linux `.deb`, Flatpak and AppImage packages; Haiku `.hpkg` package. +- From 1.0.0 on, binaries attached to every release, for x86_64 and arm64. ## [0.1.0] - 2026-11-28 -### Ajouté -- Analyse de « Peugeot Update » 1.6.1 (`docs/analysis/`). -- `libopenpu` : client de l'API Majestic (VIN, calculateurs, mises à jour), téléchargement avec - reprise (Range), licence (placeholder vide de Majestic géré), archives tar (vérification, - extraction sécurisée sans `UpdateInfo.xml`), réglages et véhicules compatibles avec l'app - officielle, USB Linux via UDisks2 (MBR + FAT32, montage, éjection). -- `openpu-cli` : `check`, `download`, `verify`, `extract`, `usb-list`, `write-usb`, `write-dir`. -- Qualité : tests doctest, ASan/UBSan, valgrind, clang-tidy, cppcheck (`tools/check.sh`), test USB - de bout en bout sur image loop (`tools/e2e-usb.sh`). +### Added +- Analysis of "Peugeot Update" 1.6.1 (`docs/analysis/`, in French). +- `libopenpu`: Majestic API client (VIN, head units, updates), resumable downloads (HTTP Range), + license download (including the empty placeholder Majestic returns while generating it), tar + archives (integrity check, safe extraction skipping `UpdateInfo.xml`), settings and vehicles + compatible with the official application, Linux USB support through UDisks2 (MBR + FAT32, + mounting, ejecting). +- `openpu-cli`: `check`, `download`, `verify`, `extract`, `usb-list`, `write-usb`, `write-dir`. +- Quality: doctest unit tests, ASan/UBSan, valgrind, clang-tidy, cppcheck (`tools/check.sh`), + end-to-end USB test on a loop image (`tools/e2e-usb.sh`). [Unreleased]: https://github.com/yann64/openpu/compare/v0.2.0...HEAD [0.2.0]: https://github.com/yann64/openpu/releases/tag/v0.2.0 diff --git a/README.md b/README.md index 4345127..0697165 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ It is an alternative to the official "Peugeot Update" application (Windows/macOS > Independent project, not affiliated with Stellantis or Peugeot. The names mentioned are > trademarks of their respective owners. -- Repository: https://github.com/yann64/openpu (mirror: https://git.barbel.synology.me/yann64/opu) +- Repository: https://github.com/yann64/openpu - License: [MIT](LICENSE) - Release history: [CHANGELOG.md](CHANGELOG.md) diff --git a/tools/haiku-vm.sh b/tools/haiku-vm.sh new file mode 100644 index 0000000..fa68f6b --- /dev/null +++ b/tools/haiku-vm.sh @@ -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 diff --git a/tools/qmp.py b/tools/qmp.py new file mode 100644 index 0000000..35999b4 --- /dev/null +++ b/tools/qmp.py @@ -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()