feat: wireview firmware check + DFU flash (bundled image, dfu-util)
Port of the wireview-linux firmware update feature: - nvcurve/wireview_firmware.py: Intel-HEX parser (checksum-verified), BuildStruct identity extraction (vendor/product/version/build string at image base + 192), compatibility verdicts (version then build date, Noctua Edition product alias + 2026-09-02 floor), and a dfu-util flasher (progress parsing, exit-74-after-:leave quirk, timeouts). - Bundle TG-WV-PRO2-FW.hex (v05, build 20260902_0741, base 0x08000000) in nvcurve/firmware/. - WireViewSerialDevice.enter_bootloader() sends the top-level 0xF1 command; vendor/product ids are exposed in info(). - GET /api/wireview/firmware (device vs. bundled verdict, dfu-util availability, flash state) and POST /api/wireview/firmware/flash (gates: serial transport, product match, Noctua floor, downgrade/ same require override). The flash runs as a background task (bootloader -> wait for 0483:df11 -> dfu-util) with progress streamed over /ws/wireview. - WireView tab: Firmware card with device vs. bundled firmware, verdict, dfu-util/hwmon warnings, confirm dialog, live progress bar; re-checks after the device reboots. - tests/test_wireview_firmware.py: 66 tests (HEX parser, checksum rejection, identity, all verdict paths, mocked flasher, bootloader command via pty); added to the Makefile test target. - Docs: firmware section in docs/WireView.md, README note.
This commit is contained in:
1 parent
bf00e1149a
commit
1e11a2c18b
13 files changed
+9702
-7
No files matched your search
@@ -332,6 +332,7 @@ function MainApp({
|
||||
info={wireview.info}
|
||||
sample={wireview.sample}
|
||||
history={wireview.history}
|
||||
flash={wireview.flash}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex gap-4 items-start w-full">
|
||||
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
FanPoint,
|
||||
DashboardInfo,
|
||||
ProcessListResponse,
|
||||
WireViewFirmwareState,
|
||||
} from "../types.js";
|
||||
|
||||
export class ApiError extends Error {
|
||||
@@ -193,4 +194,18 @@ export const api = {
|
||||
"/report-bug",
|
||||
{ title, body },
|
||||
),
|
||||
|
||||
/** WireView Pro II */
|
||||
/**
|
||||
* Firmware check: device firmware vs. the bundled image (verdict,
|
||||
* dfu-util availability, flash state).
|
||||
*/
|
||||
wireviewFirmware: () => get<WireViewFirmwareState>("/wireview/firmware"),
|
||||
|
||||
/**
|
||||
* Flash the bundled firmware over USB DFU. override=true is required when
|
||||
* the bundled firmware is not newer than the device firmware.
|
||||
*/
|
||||
wireviewFlashFirmware: (override: boolean) =>
|
||||
post<{ ok: boolean }>("/wireview/firmware/flash", { override }),
|
||||
};
|
||||
@@ -1,11 +1,27 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { api } from "../../api/client.js";
|
||||
import { ConfirmDialog } from "../common/ConfirmDialog.js";
|
||||
import { GaugeCard } from "../Monitor/GaugeCard.js";
|
||||
import { fmt } from "../../utils/units.js";
|
||||
import type { WireViewInfo, WireViewSample } from "../../types.js";
|
||||
import type {
|
||||
WireViewFlashProgress,
|
||||
WireViewFirmwareState,
|
||||
WireViewInfo,
|
||||
WireViewSample,
|
||||
} from "../../types.js";
|
||||
|
||||
interface Props {
|
||||
info: WireViewInfo | null;
|
||||
sample: WireViewSample | null;
|
||||
history: WireViewSample[];
|
||||
flash: WireViewFlashProgress;
|
||||
}
|
||||
|
||||
// "v05 (TG-WV-PRO2-FW_20260902_0741)" — version padded like the official app.
|
||||
function formatFw(version: number | null, build: string | null): string {
|
||||
const v = version !== null ? `v${String(version).padStart(2, "0")}` : "?";
|
||||
return build ? `${v} (${build})` : v;
|
||||
}
|
||||
|
||||
// Per-pin current rating of the 12 VHPWR connector (A). The bar's
|
||||
@@ -157,7 +173,65 @@ function InfoItem({
|
||||
);
|
||||
}
|
||||
|
||||
export function WireViewPanel({ info, sample, history }: Props) {
|
||||
export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
const [firmware, setFirmware] = useState<WireViewFirmwareState | null>(null);
|
||||
const [firmwareError, setFirmwareError] = useState<string | null>(null);
|
||||
const [confirming, setConfirming] = useState<null | "update" | "override">(
|
||||
null,
|
||||
);
|
||||
const [starting, setStarting] = useState(false);
|
||||
|
||||
const flashActive =
|
||||
flash.state === "bootloader" ||
|
||||
flash.state === "waiting" ||
|
||||
flash.state === "flashing";
|
||||
|
||||
async function refreshFirmware() {
|
||||
try {
|
||||
setFirmware(await api.wireviewFirmware());
|
||||
setFirmwareError(null);
|
||||
} catch (err) {
|
||||
setFirmwareError(
|
||||
err instanceof Error ? err.message : "Failed to load firmware state",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const hasSample = sample !== null;
|
||||
// Fetch the firmware check when a device appears (the panel early-returns
|
||||
// without a sample, so no reset is needed when the device goes away).
|
||||
useEffect(() => {
|
||||
// setState calls happen after the await, not synchronously in the effect
|
||||
// body (rule false-positive on async fetch).
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (hasSample) refreshFirmware();
|
||||
}, [hasSample]);
|
||||
|
||||
// After a flash the device reboots and re-enumerates; re-check once it is
|
||||
// back so the verdict reflects the new firmware.
|
||||
useEffect(() => {
|
||||
if (flash.state !== "done" && flash.state !== "failed") return;
|
||||
const t = setTimeout(() => {
|
||||
refreshFirmware();
|
||||
}, 3000);
|
||||
return () => clearTimeout(t);
|
||||
}, [flash.state]);
|
||||
|
||||
async function startFlash(override: boolean) {
|
||||
setConfirming(null);
|
||||
setStarting(true);
|
||||
try {
|
||||
await api.wireviewFlashFirmware(override);
|
||||
toast.success("Firmware update started");
|
||||
} catch (err) {
|
||||
toast.error(
|
||||
err instanceof Error ? err.message : "Failed to start firmware update",
|
||||
);
|
||||
} finally {
|
||||
setStarting(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sample) {
|
||||
return (
|
||||
<div className="bg-zinc-900 rounded-lg p-10 text-center text-zinc-500 flex flex-col items-center gap-2">
|
||||
@@ -293,8 +367,14 @@ export function WireViewPanel({ info, sample, history }: Props) {
|
||||
{/* ── Faults + device info ───────────────────────────────────── */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="flex flex-col gap-3">
|
||||
<FaultBadge label="Fault Status" mask={sample.fault_status} />
|
||||
<FaultBadge label="Fault Log (latched)" mask={sample.fault_log} />
|
||||
<FaultBadge
|
||||
label="Fault Status"
|
||||
mask={sample.fault_status}
|
||||
/>
|
||||
<FaultBadge
|
||||
label="Fault Log (latched)"
|
||||
mask={sample.fault_log}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-zinc-900 rounded-lg p-4">
|
||||
<div className="text-xs text-zinc-500 uppercase tracking-wider font-semibold pb-3 border-b border-zinc-800">
|
||||
@@ -310,6 +390,141 @@ export function WireViewPanel({ info, sample, history }: Props) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Firmware ─────────────────────────────────────────── */}
|
||||
<div className="bg-zinc-900 rounded-lg p-4 border border-zinc-800">
|
||||
<div className="text-xs text-zinc-500 uppercase tracking-wider font-semibold pb-3 border-b border-zinc-800">
|
||||
Firmware
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-3 mt-3">
|
||||
<div className="flex flex-col gap-0.5 min-w-0">
|
||||
<span className="text-xs text-zinc-500">Device</span>
|
||||
<span className="text-sm font-mono text-zinc-200 truncate">
|
||||
{firmware?.device.connected
|
||||
? formatFw(firmware.device.version, firmware.device.build)
|
||||
: "not connected"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-0.5 min-w-0">
|
||||
<span className="text-xs text-zinc-500">Bundled image</span>
|
||||
<span className="text-sm font-mono text-zinc-200 truncate">
|
||||
{firmware?.image.available
|
||||
? formatFw(firmware.image.version, firmware.image.build)
|
||||
: firmware?.image.error ?? "missing"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{firmwareError && (
|
||||
<div className="mt-3 text-xs text-red-400">{firmwareError}</div>
|
||||
)}
|
||||
|
||||
{firmware && (
|
||||
<div className="mt-3 flex flex-col gap-2">
|
||||
{(() => {
|
||||
const v = firmware.verdict;
|
||||
const text =
|
||||
v === "newer"
|
||||
? { cls: "text-emerald-400", msg: "Newer firmware available." }
|
||||
: v === "same"
|
||||
? { cls: "text-zinc-400", msg: "Device already runs this firmware build." }
|
||||
: v === "unknown"
|
||||
? { cls: "text-zinc-400", msg: "Firmware comparison unknown (no build date)." }
|
||||
: v === "downgrade"
|
||||
? { cls: "text-amber-400", msg: "Bundled firmware is older than the device firmware." }
|
||||
: v === "product_mismatch"
|
||||
? { cls: "text-red-400", msg: "The bundled firmware does not match this device." }
|
||||
: v === "too_old_for_noctua"
|
||||
? { cls: "text-red-400", msg: "The bundled firmware predates Noctua Edition support." }
|
||||
: { cls: "text-zinc-500", msg: "" };
|
||||
return text.msg ? (
|
||||
<div className={`text-sm font-medium ${text.cls}`}>{text.msg}</div>
|
||||
) : null;
|
||||
})()}
|
||||
{firmware.device.connected &&
|
||||
firmware.device.transport !== "serial" && (
|
||||
<div className="text-xs text-zinc-500">
|
||||
Flashing requires the serial transport (wireviewd owns the
|
||||
port in hwmon mode).
|
||||
</div>
|
||||
)}
|
||||
{firmware.dfu_util === null && (
|
||||
<div className="text-xs text-amber-400">
|
||||
dfu-util not installed — install the "dfu-util" package to
|
||||
enable flashing.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{flashActive || starting ? (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<div className="flex items-center justify-between text-xs text-zinc-400">
|
||||
<span>{flash.status || "Starting…"}</span>
|
||||
<span className="font-mono">
|
||||
{Math.round(flash.progress * 100)}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="h-1.5 rounded-full bg-zinc-800 overflow-hidden">
|
||||
<div
|
||||
className="h-full rounded-full bg-violet-500 transition-all duration-300"
|
||||
style={{ width: `${flash.progress * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
firmware.device.connected &&
|
||||
firmware.device.transport === "serial" &&
|
||||
firmware.image.available &&
|
||||
firmware.dfu_util !== null &&
|
||||
firmware.verdict !== "product_mismatch" &&
|
||||
firmware.verdict !== "too_old_for_noctua" && (
|
||||
<button
|
||||
onClick={() =>
|
||||
setConfirming(
|
||||
firmware.verdict === "same" ||
|
||||
firmware.verdict === "downgrade"
|
||||
? "override"
|
||||
: "update",
|
||||
)
|
||||
}
|
||||
className={`self-start px-3 py-1.5 rounded text-xs font-semibold transition-colors ${
|
||||
firmware.verdict === "same" ||
|
||||
firmware.verdict === "downgrade"
|
||||
? "bg-amber-600 hover:bg-amber-500 text-white"
|
||||
: "bg-emerald-600 hover:bg-emerald-500 text-white"
|
||||
}`}
|
||||
>
|
||||
{firmware.verdict === "same" ||
|
||||
firmware.verdict === "downgrade"
|
||||
? "Flash anyway"
|
||||
: "Update firmware"}
|
||||
</button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Confirm dialogs */}
|
||||
{confirming !== null && firmware && (
|
||||
<ConfirmDialog
|
||||
message={
|
||||
confirming === "override"
|
||||
? firmware.verdict === "downgrade"
|
||||
? "The bundled firmware is older than the device firmware. Flash it anyway?"
|
||||
: "The device already runs this firmware build. Flash it again?"
|
||||
: `Flash firmware ${formatFw(firmware.image.version, firmware.image.build)} to ${info?.device_name ?? "WireView Pro II"}?`
|
||||
}
|
||||
detail={`The device runs ${
|
||||
firmware.device.connected
|
||||
? formatFw(firmware.device.version, firmware.device.build)
|
||||
: "an unknown firmware version"
|
||||
}.\n\nThe device restarts into its bootloader and is flashed over USB DFU. Do not unplug it until the update finishes.\n\nThis is unofficial software, not affiliated with Thermal Grizzly — flashing is at your own risk.`}
|
||||
confirmLabel={confirming === "override" ? "Flash anyway" : "Flash"}
|
||||
isDestructive={confirming === "override"}
|
||||
onConfirm={() => startFlash(confirming === "override")}
|
||||
onCancel={() => setConfirming(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { createWsConnection } from "../api/websocket.js";
|
||||
import type {
|
||||
WireViewFlashProgress,
|
||||
WireViewInfo,
|
||||
WireViewSample,
|
||||
WireViewWsMessage,
|
||||
@@ -8,11 +9,14 @@ import type {
|
||||
|
||||
const MAX_HISTORY = 120; // ~2 min at 1 s polling
|
||||
|
||||
const IDLE_FLASH: WireViewFlashProgress = { state: "idle", progress: 0, status: "" };
|
||||
|
||||
export function useWireview() {
|
||||
const [available, setAvailable] = useState(false);
|
||||
const [info, setInfo] = useState<WireViewInfo | null>(null);
|
||||
const [sample, setSample] = useState<WireViewSample | null>(null);
|
||||
const [history, setHistory] = useState<WireViewSample[]>([]);
|
||||
const [flash, setFlash] = useState<WireViewFlashProgress>(IDLE_FLASH);
|
||||
const wsRef = useRef<ReturnType<typeof createWsConnection> | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -24,6 +28,12 @@ export function useWireview() {
|
||||
setInfo(msg.info);
|
||||
setSample(msg.sample);
|
||||
setHistory((h) => [...h.slice(-(MAX_HISTORY - 1)), msg.sample]);
|
||||
} else if (msg.type === "firmware") {
|
||||
setFlash({
|
||||
state: msg.state,
|
||||
progress: msg.progress,
|
||||
status: msg.status,
|
||||
});
|
||||
} else {
|
||||
setAvailable(false);
|
||||
setInfo(null);
|
||||
@@ -36,5 +46,5 @@ export function useWireview() {
|
||||
return () => wsRef.current?.close();
|
||||
}, []);
|
||||
|
||||
return { available, info, sample, history };
|
||||
return { available, info, sample, history, flash };
|
||||
}
|
||||
+42
-1
@@ -211,6 +211,47 @@ export interface WireViewState {
|
||||
sample: WireViewSample | null;
|
||||
}
|
||||
|
||||
// ── WireView Pro II firmware (check + DFU flash) ──
|
||||
|
||||
export type WireViewFirmwareVerdict =
|
||||
| "newer"
|
||||
| "same"
|
||||
| "unknown"
|
||||
| "downgrade"
|
||||
| "product_mismatch"
|
||||
| "too_old_for_noctua";
|
||||
|
||||
export interface WireViewFlashProgress {
|
||||
state: "idle" | "bootloader" | "waiting" | "flashing" | "done" | "failed";
|
||||
progress: number;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface WireViewFirmwareState {
|
||||
device: {
|
||||
connected: boolean;
|
||||
transport: "serial" | "hwmon" | null;
|
||||
version: number | null;
|
||||
build: string | null;
|
||||
};
|
||||
image: {
|
||||
available: boolean;
|
||||
error: string | null;
|
||||
version: number | null;
|
||||
build: string | null;
|
||||
};
|
||||
verdict: WireViewFirmwareVerdict | null;
|
||||
/** dfu-util version string, null when the binary is missing */
|
||||
dfu_util: string | null;
|
||||
flash: WireViewFlashProgress;
|
||||
}
|
||||
|
||||
export type WireViewWsMessage =
|
||||
| { type: "unavailable" }
|
||||
| { type: "sample"; info: WireViewInfo; sample: WireViewSample };
|
||||
| { type: "sample"; info: WireViewInfo; sample: WireViewSample }
|
||||
| {
|
||||
type: "firmware";
|
||||
state: WireViewFlashProgress["state"];
|
||||
progress: number;
|
||||
status: string;
|
||||
};
|
||||
Reference in new issue
Block a user