Switchable USB media¶
panio usb gives a target hands-free physical boot media: write an image
to a card on the control host, then hand the card to the target, which sees an
ordinary USB mass-storage device that firmware can boot. The same channel
also gives the target a repeatable USB plug/unplug: each switch to the
host side unplugs the device from the target, each switch back plugs it in.
It drives a USB mux (switch) through a per-target usb channel: the one inside some KVMs, or a cheap USB sharing switch pressed by a relay. The mux routes one device to the control host or the target, never both at once.
For downloading bytes into a target's RAM over USB, see Guarded RAM-only USB fastboot staging. That workflow uses an external fastboot client; the media-switching commands below do not stage RAM.
Supported hardware¶
| Device | Switched thing | Status |
|---|---|---|
| Openterface KVM-Go | onboard microSD reader | ✅ works, hardware-verified |
| Openterface Mini-KVM | switchable USB-A port | ⚠️ mechanism known, no helper support yet |
USB sharing switch + any relay (usbtoggle) |
one peripheral (keyboard, drive, hub) shared by two computers | ✅ works, hardware-verified through panio usb on this USB 3.0 sharing switch with a DSD TECH relay on its remote jack; check yours first |
KVM-Go: the mux uses the same serial port as the ch9329 helper, so a
device already set up as a hid channel needs only a second channel.
Mini-KVM: the mux needs a register write over the capture chip's HID
interface (mux spec);
no helper implements it, so panio usb cannot drive a Mini-KVM.
Wiring it up¶
On a KVM-Go, use the same device path as the hid channel:
panio hid set -t pi5 --cmd "ch9329 -d /dev/cu.usbmodem51201"
panio usb set -t pi5 --cmd "ch9329 -d /dev/cu.usbmodem51201"
--doctor on usb set has panio doctor also run <cmd> doctor --json,
the helper's own read-only health check (see
Helper health checks). ch9329 does
not implement it yet, so doctor reports no-check for it.
Using it¶
panio usb state -t pi5 # -> host | target
panio usb attach-host -t pi5 # route the card to the control host
panio usb attach-target -t pi5 # hand it to the target
A typical hand-off:
panio usb attach-host -t pi5
# ... wait for the block device, write your image to it, unmount ...
panio usb attach-target -t pi5
panio power-cycle -t pi5
USB sharing switch (usbtoggle)¶
A cheap 2-computer USB sharing switch has one peripheral port, two computer
ports, and a momentary button; many also have a jack for a remote button.
Pressing the button toggles which computer the peripheral is connected to.
On the verified unit VBUS, USB 2 and SuperSpeed all switch; that is not a
given for every model (check yours).
The usbtoggle helper turns one into
a usb channel: computer port A goes to the control host, port B to the
target, and a relay of your choice presses the button.
Why it needs a probe. The switch has no readable position; it only
toggles. So usbtoggle reads the position from the peripheral itself: it
looks for the peripheral on the control host's USB bus (--device). Present
means host. Absent means target, but that is an inference: the
peripheral could be unplugged or a hub dead, so usbtoggle says so on
stderr every time unless you add --target-check-cmd (exit 0 when the target
sees the device) or use --state-cmd (a command that prints host or
target). With a check configured, "absent and the check fails" is an error
("seen on neither side"), never a guess. After a press it polls for up to
--settle-ms (5000 by default) for the expected position and fails on
timeout; it never presses again on its own. An observation must complete
before the deadline to count as success. A zero settling time still allows
an already-at-the-requested-side no-op, but a press cannot be verified and
returns a timeout without a post-press read.
--settle-ms starts after the relay opens, so the initial position read and
the relay commands are outside it. Those have their own limit:
--command-timeout-ms (30000 by default, 1 ms to one day) caps every shell
command and USB probe, and a reading taken after a press also gets no more than
what is left of --settle-ms. A command past its limit is killed along with
anything it started, and the verb fails with a message naming it. A hung close
is killed and the open command still runs, so the worst case for a pair of hung
relay commands is twice the limit. doctor caps each step at 4 s, so a hang
shows up as a fail line inside panio's 10 s limit.
A command that exits normally is left alone, along with anything it left running
in the background. A listing of USB devices that hangs cannot be killed; it is
abandoned and the verb fails. If usbtoggle itself is killed (Ctrl-C included)
it cleans nothing up: the relay can stay closed and a running command keeps
running, because commands run in their own process group. A command that asks
for a password on the terminal will stop and time out.
For automation, add --require-verified. Exit 0 can otherwise mean only
"absent from the host", which a test could mistake for a real connection, and a
lost --target-check-cmd would go unnoticed apart from the stderr warning. With
the flag, usb state, usb host and usb target refuse a --device setup with
no --target-check-cmd before reading or pressing anything, and doctor reports
that as a fail on its verified line. --state-cmd counts as a trusted
verifier: nothing corroborates it. press verifies nothing, so it refuses the
flag. One positive reading is still only one sample: the flag does not show the
device stayed connected, and it cannot catch a check that wrongly exits 0.
--state-cmd replaces the whole reading, so the usb verbs ignore
--target-check-cmd when both are set and warn about it on stderr; only
doctor runs the check.
Check a switch before you rely on it¶
Many near-identical switches are sold under different names, and they differ in what they actually switch. One that leaves a signal connected is not a real unplug. Before using one as a plug/unplug tester, connect computer port A to the control host, leave port B empty, and check:
- VBUS. Put a meter on the peripheral port and press the button: it should read 0 V. If it stays at 5 V, the device never loses power and only the host sees a disconnect.
- SuperSpeed. A USB 3 device should come back at 5 Gb/s (System
Information on macOS,
lsusb -ton Linux). 480 Mb/s means the SuperSpeed pairs are not switched. - USB 2. A USB 2-only device (a mouse) should disappear and come back.
- No hub inside. With a hub between the mux and the peripheral port, the target sees the hub unplug, not your device, and the device may stay powered. A switch with one peripheral port usually has none; one with several usually does.
The verified unit (Amazon B0HCHDC8X4,
board marked KL-SW301-V1.2) passed all four: it has one peripheral port, a
USB 2 DPDT switch, a separate SuperSpeed 2:1 mux, P-channel MOSFETs on VBUS,
and no hub. A device came back about 0.65 s after the relay released.
Wiring. Put the relay's contacts across the button, at the remote jack or the button's own pads.
- A dry-contact relay (a DSD TECH board, most relay modules) is polarity-free: wire its two contacts to the jack's two conductors.
- A low-side output such as the Phidgets REL1100 is not a contact: it pulls its terminal to the module's shared ground. Wired across the jack like a relay, it did not press the button. It should work with the jack's pulled-up contact on the output and the jack's ground on the module ground; that wiring is untested.
- Keep the relay's USB connection off the hub the switch is on. During testing, a hub carrying both the switch and the relay board stopped responding (both its halves went empty) until it was power-cycled. The cause was not pinned down, but a relay on a wedged hub cannot press the button to recover.
- The relay can be any type;
usbtoggleonly runs the shell commands you give it. Test the wiring alone withusbtoggle --close-cmd ... --open-cmd ... pressbefore configuring the channel.
Configure the channel. --cmd is run by a shell, so quote the nested
commands with single quotes inside the double quotes (the example uses
placeholders; take the real VID:PID from lsusb or System Information):
panio usb set -t pi5 --doctor --cmd "usbtoggle --device 046d:c08b \
--close-cmd 'dsdrelay -s AA00BB11CC22DD33 off 1' \
--open-cmd 'dsdrelay -s AA00BB11CC22DD33 on 1'"
--device also takes an optional serial (046d:c08b:AA00BB11CC22DD33) to tell
two identical peripherals apart. Options are written before the verb, as with
every panio helper.
dsdrelay users. dsdrelay's verbs assume the target is wired through the
relay's NC contact. A button is wired to the NO contact, so the sense flips:
off energizes the coil (the contact closes: a press) and on releases it.
That is why the example above closes with off 1 and opens with on 1.
What happens when. usb host / usb target read the position first; if
the peripheral is already on the requested side they print it and exit 0
without pressing. Otherwise they press once (close, hold --hold-ms, default
200, then open) and verify. The open command always runs after the close was
attempted, even when the close fails. The relay commands' stdout goes to
usbtoggle's stderr; stdout carries only host or target. usbtoggle
doctor is read-only and never presses.
Four things that will bite you¶
Unmount before you switch. Switching yanks the device from the side that
has it, and panio cannot see mount state, so it will not stop you. On macOS
use diskutil unmount force; plain diskutil unmount often fails because
Spotlight holds the volume open.
Exit 0 means the mux moved, not that the media is ready. Wait a few seconds for the block device to appear on the receiving side.
Never assume the position persisted. The mux resets to host when the KVM
loses power, and a physical button can move it. Check panio usb state. (On
a sharing switch a hand on its button moves it too, and which side it picks
after losing power has not been measured.)
Not every device has a mux. A device without one does not answer, which the helper reports as a timeout.
The helper contract¶
As with the power hooks and hid channel, panio runs the configured command with a verb appended:
| panio command | what it runs |
|---|---|
panio usb attach-host |
<cmd> usb host |
panio usb attach-target |
<cmd> usb target |
panio usb state |
<cmd> usb state |
A helper implementing this contract must:
- exit non-zero on failure, and print the resulting side (
hostortarget) on stdout; - verify the switch: compare the position the device reports with the one requested (a KVM-Go that ignored the request still reports the old position).
Unlike panio hid send, no arguments are passed through; the vocabulary is
fixed at these three verbs.