RPi-Distro / repo

Issue tracking for the archive.raspberrypi.org repo
37 stars 1 forks source link

Bluetooth service starts too early #374

Open OrangeDog opened 1 month ago

OrangeDog commented 1 month ago

I'm seeing this problem on slower hardware (e.g. RPi ZeroW) where at boot bluetooth.service is started before the hardware is ready, skipping running anything and immediately reaching bluetooth.target, but with no bluetooth available.

The service has to be manually started later on, which is not always possible or practical.

Some relevant log lines:

Oct 11 11:52:48 pi kernel: Booting Linux on physical CPU 0x0
Oct 11 11:52:48 pi kernel: Linux version 6.6.31+rpt-rpi-v6 (serge@raspberrypi.com) (gcc-12 (Raspbian 12.2.0-14+rpi1) 12.2.0, GNU ld (GNU Binutils for Raspbian) 2.40) #1 >
Oct 11 11:52:48 pi kernel: CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
Oct 11 11:52:48 pi kernel: CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
Oct 11 11:52:48 pi kernel: OF: fdt: Machine model: Raspberry Pi Zero W Rev 1.1
[...]
Oct 11 11:52:53 pi systemd[1]: Starting ufw.service - Uncomplicated firewall...
Jul 09 11:01:07 pi fake-hwclock[205]: Tue  9 Jul 10:01:07 UTC 2024
[...]
Jul 09 11:01:09 pi systemd[1]: Started dbus.service - D-Bus System Message Bus.
Jul 09 11:01:10 pi systemd[1]: bluetooth.service - Bluetooth service was skipped because of an unmet condition check (ConditionPathIsDirectory=/sys/class/bluetooth).
Jul 09 11:01:10 pi systemd[1]: Reached target bluetooth.target - Bluetooth Support.
[...]
Jul 09 11:01:12 pi systemd[1]: Finished ufw.service - Uncomplicated firewall.
Jul 09 11:01:12 pi systemd[1]: Reached target network-pre.target - Preparation for Network.
Jul 09 11:01:12 pi systemd[1]: Starting NetworkManager.service - Network Manager...
[...]
Jul 09 11:01:13 pi systemd[1]: Started NetworkManager.service - Network Manager.
Jul 09 11:01:13 pi NetworkManager[293]: <info>  [1720519273.7755] bus-manager: acquired D-Bus service "org.freedesktop.NetworkManager"
Jul 09 11:01:13 pi systemd[1]: Reached target network.target - Network.
[...]
Jul 09 11:01:18 pi NetworkManager[293]: <info>  [1720519278.3246] Loaded device plugin:NMBluezManager (/usr/lib/arm-linux-gnueabihf/NetworkManager/1.42.4/libnm-device-plugin-bluetooth.so)
[...]
Jul 09 11:01:18 pi kernel: Bluetooth: Core ver 2.22
Jul 09 11:01:18 pi kernel: NET: Registered PF_BLUETOOTH protocol family
Jul 09 11:01:18 pi kernel: Bluetooth: HCI device and connection manager initialized
Jul 09 11:01:18 pi kernel: Bluetooth: HCI socket layer initialized
Jul 09 11:01:18 pi kernel: Bluetooth: L2CAP socket layer initialized
Jul 09 11:01:18 pi kernel: Bluetooth: SCO socket layer initialized
[...]
Jul 09 11:01:18 pi kernel: Bluetooth: HCI UART driver ver 2.3
Jul 09 11:01:18 pi kernel: Bluetooth: HCI UART protocol H4 registered
Jul 09 11:01:18 pi kernel: Bluetooth: HCI UART protocol Three-wire (H5) registered
Jul 09 11:01:18 pi kernel: hci_uart_bcm serial0-0: supply vbat not found, using dummy regulator
Jul 09 11:01:18 pi kernel: hci_uart_bcm serial0-0: supply vddio not found, using dummy regulator
Jul 09 11:01:18 pi kernel: uart-pl011 20201000.serial: no DMA platform data
Jul 09 11:01:18 pi kernel: Bluetooth: HCI UART protocol Broadcom registered
[...]
Jul 09 11:01:19 pi kernel: Bluetooth: hci0: BCM: chip id 94
Jul 09 11:01:19 pi kernel: Bluetooth: hci0: BCM: features 0x2e
Jul 09 11:01:19 pi kernel: Bluetooth: hci0: BCM43430A1
Jul 09 11:01:19 pi kernel: Bluetooth: hci0: BCM43430A1 (001.002.009) build 0000
Jul 09 11:01:19 pi kernel: Bluetooth: hci0: BCM43430A1 'brcm/BCM43430A1.raspberrypi,model-zero-w.hcd' Patch
[...]
Jul 09 11:01:20 pi kernel: Bluetooth: hci0: BCM: features 0x2e
Jul 09 11:01:20 pi kernel: Bluetooth: hci0: BCM43438A1 37.4MHz Raspberry Pi 3-0141
Jul 09 11:01:20 pi kernel: Bluetooth: hci0: BCM43430A1 (001.002.009) build 0508

By the time I have logged in, the /sys/class/bluetooth directory now exists, presumably corresponding with the 11:01:18 logs. That is eight seconds after bluetooth.target and five seconds after network.target.

As a workaround I can use this drop-in:

[Unit]
ConditionPathIsDirectory=

Giving a boot log something usually like:

Jul 09 13:47:36 pi systemd[1]: Starting bluetooth.service - Bluetooth service...
Jul 09 13:47:38 pi systemd[1]: Finished ufw.service - Uncomplicated firewall.
Jul 09 13:47:38 pi systemd[1]: Reached target network-pre.target - Preparation for Network.
Jul 09 13:47:38 pi systemd[1]: Starting NetworkManager.service - Network Manager...
Jul 09 13:47:39 pi kernel: Bluetooth: Core ver 2.22
Jul 09 13:47:39 pi kernel: NET: Registered PF_BLUETOOTH protocol family
Jul 09 13:47:39 pi kernel: Bluetooth: HCI device and connection manager initialized
Jul 09 13:47:39 pi kernel: Bluetooth: HCI socket layer initialized
Jul 09 13:47:39 pi kernel: Bluetooth: L2CAP socket layer initialized
Jul 09 13:47:39 pi kernel: Bluetooth: SCO socket layer initialized
Jul 09 13:47:39 pi bluetoothd[248]: Bluetooth daemon 5.66
Jul 09 13:47:39 pi systemd[1]: Started bluetooth.service - Bluetooth service.
Jul 09 13:47:39 pi systemd[1]: Reached target bluetooth.target - Bluetooth Support.
Jul 09 13:47:39 pi bluetoothd[248]: Starting SDP server
[...]
Jul 09 13:47:42 pi kernel: Bluetooth: HCI UART driver ver 2.3
Jul 09 13:47:42 pi kernel: Bluetooth: HCI UART protocol H4 registered
Jul 09 13:47:42 pi kernel: Bluetooth: HCI UART protocol Three-wire (H5) registered
Jul 09 13:47:42 pi kernel: hci_uart_bcm serial0-0: supply vbat not found, using dummy regulator
Jul 09 13:47:42 pi kernel: hci_uart_bcm serial0-0: supply vddio not found, using dummy regulator
Jul 09 13:47:42 pi kernel: uart-pl011 20201000.serial: no DMA platform data
Jul 09 13:47:42 pi kernel: Bluetooth: HCI UART protocol Broadcom registered
Jul 09 13:47:42 pi kernel: Bluetooth: hci0: BCM: chip id 94
Jul 09 13:47:42 pi kernel: Bluetooth: hci0: BCM: features 0x2e
Jul 09 13:47:42 pi kernel: Bluetooth: hci0: BCM43430A1
Jul 09 13:47:42 pi kernel: Bluetooth: hci0: BCM43430A1 (001.002.009) build 0000
Jul 09 13:47:42 pi kernel: Bluetooth: hci0: BCM43430A1 'brcm/BCM43430A1.raspberrypi,model-zero-w.hcd' Patch
Jul 09 13:47:43 pi sshd[324]: Server listening on 0.0.0.0 port 22.
Jul 09 13:47:43 pi sshd[324]: Server listening on :: port 22.
Jul 09 13:47:43 pi systemd[1]: Started ssh.service - OpenBSD Secure Shell server.
Jul 09 13:47:43 pi systemd[1]: Reached target multi-user.target - Multi-User System.
[...]
Jul 09 13:47:43 pi kernel: Bluetooth: hci0: BCM: features 0x2e
Jul 09 13:47:43 pi kernel: Bluetooth: hci0: BCM43438A1 37.4MHz Raspberry Pi 3-0141
Jul 09 13:47:43 pi kernel: Bluetooth: hci0: BCM43430A1 (001.002.009) build 0508
Jul 09 13:47:43 pi kernel: videodev: Linux video capture interface: v2.00
Jul 09 13:47:43 pi kernel: Bluetooth: MGMT ver 1.22
Jul 09 13:47:44 pi kernel: NET: Registered PF_ALG protocol family
Jul 09 13:47:44 pi NetworkManager[290]: <info>  [1720529264.0563] Loaded device plugin: NMBluezManager (/usr/lib/arm-linux-gnueabihf/NetworkManager/1.42.4/libnm-device-plugin-bluetooth.so)