Skip to content

Recover Intel Bluetooth when an rfkill block interrupts the firmware load - #8022

Open
ezitounioussama wants to merge 1 commit into
omacom:quattrofrom
ezitounioussama:fix-intel-bluetooth-rfkill-firmware
Open

ezitounioussama wants to merge 1 commit into
omacom:quattrofrom
ezitounioussama:fix-intel-bluetooth-rfkill-firmware

Conversation

@ezitounioussama

@ezitounioussama ezitounioussama commented Aug 24, 2026 •

Copy link
Copy Markdown

The problem

Turning Bluetooth off and rebooting leaves an Intel CNVi machine with no Bluetooth adapter at all, not one that is merely powered off. bluetoothctl reports No default controller available, and turning Bluetooth back on cannot recover it.

Mechanism

omarchy-bluetooth-power off sets an rfkill soft block, and the reasoning in that script is sound: BlueZ never persists Powered, while systemd-rfkill saves every switch under /var/lib/systemd/rfkill and restores it early on the next boot.

The trouble is how early. On this adapter the restore lands while btusb is still downloading the firmware. The device drops off the bus mid-transfer, the download fails with -19 (ENODEV), and hci0 is torn down completely:

Bluetooth: hci0: Found device firmware: intel/ibt-0040-0041.sfi
Bluetooth: hci0: Boot Address: 0x100800
Bluetooth: hci0: Firmware Version: 202-5.26
Bluetooth: hci0: Failed to send firmware data (-19)
Bluetooth: hci0: sending frame failed (-19)
Bluetooth: hci0: FW download error recovery failed (-19)
Bluetooth: hci0: Failed to read MSFT supported features (-19)

/sys/class/bluetooth/ is then empty. That also defeats the recovery path in power_on(): it lifts the block and waits for BlueZ to auto-power the adapter, then falls back to bluetoothctl power on. Both need a controller to exist, so both fail and the helper reports that the adapter did not come up.

Evidence

Firmware load outcome per boot on one machine. The only failure is the boot where Bluetooth had been turned off beforehand:

boot blocked at boot firmware loaded firmware errors
-4 no yes 0
-3 no yes 0
-2 no yes 0
-1 no yes 0
0 yes only after a manual btusb reload 2

Reproduction

  1. On an Intel CNVi adapter, run omarchy-bluetooth-power off (or use the bar widget).
  2. Reboot.
  3. journalctl -b -k | grep hci0 shows the -19 failures.
  4. bluetoothctl list is empty.
  5. Turning Bluetooth back on does not help.

The change

A udev rule watches for the Bluetooth rfkill block being lifted and starts a oneshot unit that reloads btusb if that left no adapter behind.

It is deliberately inert outside the broken case. It waits for an adapter first and exits as soon as one appears, so hardware without this problem never reloads anything; and it exits when the block is still set, since a missing adapter is the intended state while Bluetooth is off.

  • bin/omarchy-bluetooth-recover — the recovery itself
  • bin/omarchy-hw-intel-bluetooth — detection, reading sysfs because usbutils is not in the base install so lsusb is usually absent
  • default/udev/intel-bluetooth-recover.rules — the trigger
  • install/hardware/intel/fix-bluetooth-rfkill-firmware.sh — installs the rule and unit, gated on the adapter being present
  • one line in install/hardware/all.sh

Testing

Verified on Omarchy 4.0.0-1, kernel 7.1.8-arch1-3, Intel Raptor Lake PCH CNVi (8087:0033, firmware intel/ibt-0040-0041.sfi).

The real failure, and that a btusb reload fixes it. Reached by turning Bluetooth off and rebooting. The boot logged the -19 failures above and left no adapter; reloading btusb recovered it:

Bluetooth: hci0: Firmware loaded in 1378869 usecs
Bluetooth: hci0: Device booted in 15662 usecs
Bluetooth: hci0: Fseq status: Success (0x00)

That the script takes the reload branch and recovers the adapter. btusb was removed without touching rfkill, so no device event could make udev auto-load it — leaving the module unloaded and no adapter, which is the state the script has to act on:

btusb loaded: 0   adapters: (none)
# omarchy-bluetooth-recover
omarchy-bluetooth-recover[48677]: No Bluetooth adapter after unblock; reloading btusb
btusb loaded: 1   adapters: hci0
Controller 08:9D:F4:86:E6:C3 ITS [default]

Exit status 0, no -19 errors. The controller in that run reported Firmware already loaded, since it kept the firmware from the previous successful load — so this run proves the recovery mechanics, while the case above proves a reload repairs a genuinely failed download.

That the guards keep it inert. With an adapter present the script exits in 2ms without reloading and logs nothing. With the block still set it exits without reloading, so turning Bluetooth off keeps working normally.

That the trigger fires. Unblocking Bluetooth starts the unit through the udev rule (Starting Recover Bluetooth adapter after rfkill unblock → Finished).

Detection. omarchy-hw-intel-bluetooth returns 0 on this hardware, matching 8087:0033 at device class e0. It reads sysfs deliberately: an earlier version used lsusb -d 8087:, which exits 127 on a base install because usbutils is not included — that would have silently disabled the fix.

Note on timing

omarchy-bluetooth-power gives up after POWER_WAIT_SECONDS (2s) while the recovery waits 5s for an adapter before reloading, so the first toggle after a blocked boot can still report that the adapter did not come up, with the adapter appearing a few seconds later. Happy to align those.

If you would rather keep this in one place, the reload could move into power_on() instead. That needs a privileged path, though: rfkill works unprivileged through the uaccess ACL on /dev/rfkill, but modprobe and systemctl restart bluetooth do not, and the helper is called detached from the shell where a sudo prompt has nowhere to go. That is why this is a root-side unit driven by udev.

…load

omarchy-bluetooth-power keeps the off state in the rfkill soft block because
that is the half systemd-rfkill restores across reboots. On Intel CNVi adapters
that restore lands while btusb is still downloading the firmware: the device
drops off the bus mid-transfer, the download fails with -19 (ENODEV) and hci0 is
torn down, so the machine boots with no Bluetooth controller at all rather than
one that is merely powered off.

  Bluetooth: hci0: Found device firmware: intel/ibt-0040-0041.sfi
  Bluetooth: hci0: Failed to send firmware data (-19)
  Bluetooth: hci0: FW download error recovery failed (-19)

Turning Bluetooth back on cannot recover from that on its own: power_on() lifts
the block and then waits for BlueZ to power an adapter that no longer exists,
then falls back to a bluetoothctl power on with no controller to address.

Watch for the unblock with a udev rule and reload btusb when it leaves no
adapter behind. The recovery waits for an adapter first and does nothing when
one shows up, so it stays inert on hardware without this problem, and it also
does nothing while the block is still set, since a missing adapter is then the
intended state.
@ezitounioussama
ezitounioussama marked this pull request as ready for review August 24, 2026 09:16
Copilot AI balanced review requested due to automatic review settings August 24, 2026 09:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 1317f4c. The diagnosis in the description is clear and the recovery script's guards hold up, but two things stop the fix from reaching the failure it describes.

1. The udev rule cannot fire once the adapter is gone. The rule at default/udev/intel-bluetooth-recover.rules:4 matches a change uevent on a Bluetooth rfkill device. That rfkill device belongs to hci0 and is unregistered with it, so in exactly the state this PR targets (/sys/class/bluetooth/ empty) there is nothing left to emit the event, and rfkill unblock bluetooth changes only the kernel's global state. I checked this on a disposable Omarchy VM (kernel 7.2.5-3-omarchy, systemd 261) with a virtual controller from hci_vhci and the rule and unit from this PR installed:

  • controller present, block then unblock: the unit starts every time (three cycles, three runs)
  • controller removed, rfkill list bluetooth empty, block then unblock: udevadm monitor --subsystem-match=rfkill sees no event and the unit never starts

The testing in the description covers the trigger with an adapter present and the reload branch run by hand, but not the two together. It would still fire on a machine that also has a platform Bluetooth switch (a ThinkPad's tpacpi_bluetooth_sw, for example), so rfkill list from your machine in the failed state would settle whether it ever worked there. Either way, the recovery needs a trigger that doesn't depend on the device that disappeared: at boot after systemd-rfkill, or from the failed power_on() path in bin/omarchy-bluetooth-power. Which is your call, and the maintainer's.

2. Existing installs never get it. install/hardware/intel/fix-bluetooth-rfkill-firmware.sh only runs from omarchy-apply-hardware during ISO finalization; omarchy-update runs migrations, not hardware setup. Without a migration, someone already hitting this can update and reboot without getting the fix. migrations/1786391100.sh and migrations/1787666837.sh show how other hardware fixes bridge that gap.

A smaller point: adapter_present() accepts any hci*, so with a USB dongle plugged in, a failed internal controller is never recovered. That's reasonable as a way to avoid disturbing the working controller, but worth a note in the script.

Related: #13085 (open) makes omarchy-restart-bluetooth restart bluetoothd and reload btusb when no controller shows up. It is a manual path from the menu rather than an automatic one, but it recovers the same missing-adapter state.

What was checked: the diff read against quattro's AGENTS.md and install-scripts guide; ./test/cli passed on the VM; the trigger was exercised as above. The firmware race itself needs Intel CNVi hardware and could not be reproduced on a VM, so once the trigger is settled the fix needs confirming on an affected machine, at the full commit SHA, by a reporter or maintainer other than the author.

Second opinion: Codex Medium reviewed it separately and raised findings 1 and 2 as well. It may have read this review's working notes, so its agreement is not guaranteed to be independent. It also claimed the unit would only start on the first unblock. That didn't hold: on the VM it started on every unblock. It raised the second-controller point above too.

Next: waiting on you for the trigger and a migration.

@omarchybot

Copy link
Copy Markdown
Collaborator

#20378 is on quattro at d360a0b37e9660253ae5efd6736057e8616e4d42. Turning Bluetooth off now leaves the platform switch alone when an hci* switch is present. A platform block saved by the old code can still be restored at boot. @ezitounioussama, please repeat the off → reboot → on sequence on a build with that commit, starting with Bluetooth on. If the -19 error returns, please share rfkill list bluetooth just after boot, before unblocking, and the relevant Bluetooth and USB lines from journalctl -b -k.

Codex High checked the current base and ran ./test/cli on a disposable Omarchy VM. All 116 CLI checks passed. With the PR's rule and service installed and no Bluetooth rfkill device present, unblocking produced zero rfkill events and the service never started. The worker lacked the affected Intel hardware. Opus 5.5 High and muse-wonder via pi, thinking high agreed on the trigger and update gaps. Their access to the working notes limits the independence of that agreement.

For manual recovery, #13085 can reach the reload without a Bluetooth rfkill event and checks for a controller in BlueZ. If both changes land, the restart command's unblock could trigger this service too and both could try to reload btusb. The maintainer can decide where recovery belongs once the hardware retest shows whether automatic recovery is still needed.

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

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants