Skip to content

USB File Transfer opens at once, and a freeze ends in a restart with a report - #487

Draft
tarikbc wants to merge 7 commits into
mainfrom
usb-hang
Draft

tarikbc wants to merge 7 commits into
mainfrom
usb-hang

Conversation

@tarikbc

@tarikbc tarikbc commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

My Pixel 2 (1.1.0) froze opening USB File Transfer: once for hours with nothing in the log, once for about 10 s before the page came. roverfine's Pixel 2 sometimes stops in the kernel on a cold start, LED off and backlight on, for good. This makes the launcher never wait on the USB controller, opens File Transfer at once, leaves a link my computer took alone, and turns any freeze into a restart with a report.

Pairs with the boot-notice PR (the slow start's lines and Zyper's notice after a restart): #485. I'd merge this one first: boot-notice's reasons W and its "The handheld froze" bubble report on the watchdogs here. Either order builds and passes on its own. The second to merge takes main with two small conflicts, plastron/buildroot/package/zyperos/zyperos.init and plastron/buildroot/board/px2/rootfs-overlay/etc/init.d/datapart, both sides' lines kept (this one's hung_panic_off, boot-notice's stage calls). The start's stage lines and crashlog's summary for the launcher are boot-notice's; this branch has none of them.

What the 10 s freeze was

The log, all on the launcher's main thread before the page drew: "usb: the link to the computer is off: charging only", "...is on", "a computer is on the cable: a fresh link", "wire: the cable connection made fresh", "ssh: stopped", "ssh: dropbear ...", then "xfer: link step 2.0". The kernel's log has the gadget bound three times (87.6, 88.6 and 92.5 s): my Mac met the handheld three times over, over a link it had already configured.

The fixes

  1. The controller's writes never stop the launcher (src/hwput.c, hwput_run at :169). soft_connect and the gadget's UDC are written by a forked child, waited for 2 s at most or not at all; then "usb: the controller did not answer" and the launcher goes on. One job at a time, reaped when it ends, each write said in the log before it is made.
  2. The link is asked for, never waited on (src/gadget.c, gadget_link :225, gadget_pump :165, gadget_fresh :253). Binds, unbinds and the fresh link go to hwput's child; the last word wins; every look at the port reaps a job that ended and says it. The Pixel 2 (src/device/pixel2.c:1723) and the Brick (src/device/brick.c:1142) both use it. usb0's address and udhcpd come up on a thread of their own on the Pixel 2 (net_run, pixel2.c:1683).
  3. File Transfer draws at once (src/xfer_screen.c, xs_open :1394). Its first frame is the link steps' loading bar while the link comes (the screen's existing loading state, no new UI), and B and POWER work all through it. SSH and zyperos.local start once the page is up and usb0 has its address (xs_cable_services :1379).
  4. A link my computer took is left alone. As File Transfer opens, a configured link the computer answers on (ARP over usb0) is not bound again or toggled (src/cablefresh.c:158). At a plug in Developer Mode, the link is looked at 3 s after the plug and made fresh only if the computer has not configured it (src/usblink.c, USBLINK_SETTLE_MS); the Brick, whose controller cannot tell, gets the fresh link at once as before.
  5. Developer Mode's SSH is not restarted as File Transfer opens: it takes File Transfer's PIN in place, its sessions kept (sshlink_repin, src/sshlink.c:729), never while a radio is up.
  6. Timed log lines: "xfer: opened in N ms (link, art, systems, server and SSH)" and "xfer: the page's first frame N ms after it was asked for (the loading bar; drawn by N ms, its present N ms)" (xfer_screen.c:1506, :2248), so the next device run measures it.
  7. The launcher's watchdog (src/wdog.c): 60 s without the main loop, it says so and turns the backlight off; 120 s, sync and restart (sysrq s, b). SIGUSR2 stops the loop 150 s to show it.
  8. The Pixel 2's hardware watchdog: &wdt in the dts, the kernel's DW_WATCHDOG with watchdog.open_timeout=60, U-Boot's WDT autostart, and plastron's hwdog petting it from init's first line after the splash (mlockall, SCHED_FIFO), with a respawned second petter. zytest=hang and zytest=stall in zytest.txt on PX2BOOT test it once.
  9. Limits on the start: rootwait=20 in place of a wait forever, and a task stuck 60 s panics during the start only (set back to 0 by zyperos.init around the card's long writes and as the launcher starts). For roverfine's cold starts that stopped under a second in.
  10. The kernel's log keeps the launcher's lines (src/klog.c): usb:, wire:, xfer:, mdns:, crash:, power: and watchdog: lines go to /dev/kmsg too, which pstore keeps across a reset, so crashlog's report names the step.
  11. The screensaver no longer ends itself while its first snap opens (src/saver.c, its gap measured from the end of its last pass).

Checks

Open times on this Mac, desk mode over a stand-in cable whose controller writes take 3 s each (check-xferopen, src/device/deskcable.h):

before (1.1.0's waits, XFEROPEN_BEFORE=1) after
link off opened in 9329 ms, first frame 9363 ms opened in 5 to 75 ms, first frame drawn by 56 to 153 ms
configured, computer answers 6319 ms, 6377 ms 7 to 13 ms, 41 to 99 ms
configured, computer silent 6333 ms, 6426 ms 6 to 124 ms, 54 to 191 ms

The after times are from five runs while this Mac had other builds going (load average 15 to 210); the larger ones are the busiest runs, and the part that grew was the card's (systems) and the fork, not the link. The window's own present in desk mode (the handheld's face drawn around it) adds 40 to 250 ms here that a Pixel 2's flip does not. The device's real numbers come from the two xfer: lines on the next run. check-xferopen holds the open and the first frame under 1 s, a third of one controller write.

  • check-xferopen: four cases. A link that is off: the loading bar at once, B with the bind on its way, the bind landing in the background, the unbind B asked for, no child left. The same with POWER: its power-off asked at once and the launcher ends with the bind still on its way. A configured link the computer answers on: nothing bound, unbound or toggled. One it does not answer on: made fresh, "disconnect" then "connect". With XFEROPEN_BEFORE=1 it fails 19 times.
  • check-usbhang (with USBHANG_BEFORE=1 it fails 16 times), check-usblink (a link the computer took is not bound again; one it did not take in 3 s is made fresh once), check-linksteps, check-saver, check-crashlog: pass.
  • check-hwdog on Linux (Docker): pass. The Pixel 2's, the R36S's, the Brick's and the Smart Pro's platform code and the link's files compiled for Linux with the device build's warnings: clean.
  • File Transfer's loading states (steps-usb-unplugged, -taking, -opening, -noanswer) in 8 languages on the Pixel 2, the Brick and the Smart Pro (wide), light and dark: everything fits; I looked at them.
  • make check CHECK_JOBS=4: all 277 checks passed in 17 min, none flaky.

On a spare card

Build the image with both PRs together (python3 tools/merge-train.py --integrate-only 487 485) and write it to a spare card.

  1. File Transfer, off. Developer Mode off, the cable to the Mac, choose File Transfer at "Computer Connected". The page (the loading bar) comes at once; press B while it connects: it closes at once. Open it again and let it connect. In zyperos.log: "xfer: opened in N ms" and "xfer: the page's first frame N ms after it was asked for": both should be under 100 ms.
  2. File Transfer over Developer Mode's link. Developer Mode on, cable in, SSH signed in from the Mac (ssh root@zyperos.local). Open File Transfer: the page at once, the SSH session stays open, and the log says "usb: the computer answers over the cable: the link left as it is" and "ssh: dropbear N goes on with File Transfer's PIN, its sessions kept", with no "the gadget's UDC" line. dmesg | grep "bound driver" shows no new bind.
  3. A plug in Developer Mode. Unplug and plug the cable: one "bound driver" at most in dmesg, and the log says "usb: a computer is on the cable: its link looked at in 3 s", then "usb: the computer took the link: left as it is".
  4. The launcher's watchdog. Over SSH: kill -USR2 $(pidof zyperos.elf). At 60 s the backlight goes off; at 120 s the handheld restarts. zyperos-crash.txt on PX2BOOT has "zyperos: watchdog: ..." near its end.
  5. The chip's watchdog. echo zytest=hang > zytest.txt on PX2BOOT, start: init is held, about 60 s in the chip resets. On the next start zytest.txt says zytest=-, and the report on PX2BOOT has "hwdog: zytest=hang ..." before the reset. With boot-notice in the image, Zyper says "I had to restart!" with "Code K2W · ..." on the home, and About ZyperOS shows it as Last Restart.
  6. A freeze after the home. zytest=stall, start: the home comes, and about 60 s later the chip resets. With boot-notice, the next start says "The handheld froze. Code HX · ...".
  7. A cold start. Turn it off and on ten times with the cable out: every start reaches the home. If one stops in the kernel, it now restarts by itself within about a minute, and the next start's report names the stage.

My Pixel 2 froze opening USB File Transfer (2026-11-21): the screen kept
its last frame, POWER did nothing, and zyperos.log ended a minute earlier.
Every open wrote "disconnect" then "connect" to the controller's
soft_connect on the launcher's main thread, over a link in use too, and
dwc2 can hang in that toggle (Joshua's kernel.log: "dwc2_core_reset: HANG!
Soft Reset timeout").

- The fresh link only when the link needs it (src/cablefresh.c, the rule
  in linksteps.c): not for a link bound a moment ago, always for one that
  is not whole, and for one that looks whole only when the computer does
  not answer an ARP request over usb0, which keeps the Mac that dropped the
  Pixel while it said "configured" (2026-10-08) working. The Brick too.
- The controller's writes (soft_connect, the gadget's UDC bind and unbind)
  in a forked child (src/hwput.c): waited for 2 s at most, or not at all,
  then "usb: the controller did not answer" and the launcher carries on.
  No second job while one hangs, reaped when it ends, and it holds none of
  the launcher's descriptors. Each write is said in the log before it is
  made.
- The usb:, wire:, xfer:, mdns:, crash:, power: and watchdog: lines also go
  to the kernel's log, which pstore keeps across a warm reset, and
  zyperos.log is synced after them by a thread of its own (src/klog.c, a
  filter in front of stderr). New power: lines for POWER and the power-off.
- A watchdog thread (src/wdog.c) the main loop feeds from its frames, its
  input and its waits while a game or a program has the screen: 60 s
  without the loop, the stage said and the backlight off; 120 s, sysrq s
  and b. The main loop's own long tasks are held. SIGUSR2 stops the loop
  for 150 s, to show it.

make check-usbhang holds all of it; with USBHANG_BEFORE=1 it runs 1.1.0's
reconnect and fails 16 times.
It ended when 500 ms passed between its passes, measured from the start of
the pass before, and its own first pass opens a snap in mp4d, which takes
that long on a Pixel 2: "ended, something else had the screen (1 s)" 213
times in 40 minutes, a clip never shown. The gap is from the end of its
last pass now (saver_beat), so only what came between counts.
…t names the step

A freeze now ends in a restart with a report, from power on:

- The PX30's DesignWare watchdog, on by default. U-Boot starts it
  (CONFIG_WDT, DESIGNWARE_WATCHDOG, autostart, 30 s; u-boot-px2.bin
  rebuilt, main's config first reproduced byte for byte), the kernel pets
  it from its probe until something opens it (&wdt on in the dts,
  CONFIG_WATCHDOG, DW_WATCHDOG, HANDLE_BOOT_ENABLED, open_timeout=60;
  linux.config regenerated, main's fragment giving main's back), and
  package/hwdog pets it from init's first line after the splash: never the
  launcher, no file touched after it starts, mlockall and SCHED_FIFO, so a
  long copy to a slow card never makes it late (the false reset PR #115
  feared). A respawned second copy waits to take over. The magic close at
  a shutdown.
- rootwait=20 in place of rootwait (root is there 0.14 s after the wait
  begins on a cold start), and a task stuck 60 s panics during the start
  only (the hung task sysctls on the kernel's line, set back to 0 around a
  fresh card's format, an update's switch and a copy, and as the launcher
  starts). For roverfine's cold starts that stopped in the kernel under a
  second in, the backlight on, for good (2026-11-23).
- Each step of the start in the kernel's log and /tmp/splash-stage
  ("zyboot: stage=C1" to L1), from datapart and zyperos.init.
- crashlog says which reset it was (a panic's kind, rootwait, a stuck task,
  ZyperOS's watchdog, the hardware watchdog during the start) and writes
  its facts beside the report, zyperos-lastboot.txt on PX2BOOT and in /run,
  for ZyperOS's notice at the next start.
- zytest=hang or zytest=stall in zytest.txt on PX2BOOT tests the chain
  once: U-Boot passes it on and writes the file back as zytest=-.

make check-crashlog and the new check-hwdog hold them; docs/building.md
says how to test each watchdog.
The stage lines (zyboot) in datapart and zyperos.init, and crashlog's
reasons and zyperos-lastboot.txt, are boot-notice's to build, so they are
out of here again. The hung task panic is still set back to 0 around the
card's long writes and as the launcher starts.
…lone

Opening File Transfer over a Pixel 2's Developer Mode link froze the screen
for about 10 s: the gadget was unbound and bound again, the controller
toggled and SSH stopped and started, all on the launcher's main thread
before the page drew, and the computer met the handheld three times.

The link's work is now asked for and never waited on (src/gadget.h): the
binds, the unbinds and the fresh link go to hwput's child one job at a
time, the last word wins, and every look at the port reaps a job that ended
and says it. usb0's address and udhcpd come up on a thread of their own on
the Pixel 2. The page draws its first frame at once, the link steps' loading
bar while the link comes, and B and POWER work all through it.

A link the computer configured and answers on is never bound again or
toggled: not as File Transfer opens (cablefresh.h asks the computer first)
and not at a plug in Developer Mode, where the link is looked at 3 s after
the plug and only made fresh if the computer has not taken it. Developer
Mode's SSH takes File Transfer's PIN in place (sshlink_repin), its sessions
kept, instead of a stop and a start; SSH and zyperos.local start once the
page is up.

The log times each part: "xfer: opened in N ms (link, art, systems,
server and SSH)" and "xfer: the page's first frame N ms after it was asked
for". check-xferopen opens it in desk mode over a stand-in cable whose
controller writes take 3 s (src/device/deskcable.h): a link that is off, the
same with POWER, a configured one the computer answers on, and one it does
not.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant