Jetson TX2 r28 bluetooth service not working intermittendly

Hello,
I am using a Jetson TX2 Board with L4T r28 (with some minor modifications) and have it configured to connect to a Bluetooth device with a virtual serial port automatically. This works most of the time but sometimes the Bluetooth interface is not created properly during boot.

me@xyz:~$ ls /sys/class/bluetooth/
me@xyz:~$ sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:bluetoothd(8)

I tried to debug it and saw that the nvwifibt.service failed to start.

me@xyz:~$ systemctl status nvwifibt.service
● nvwifibt.service - NVIDIA bluetooth/wifi init script
   Loaded: loaded (/etc/systemd/system/nvwifibt.service; static; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-03-02 11:51:43 CET; 1h 46min ago
  Process: 1471 ExecStartPre=/etc/systemd/nvwifibt-pre.sh (code=exited, status=1/FAILURE)

This is because the nvwifibt-pre.sh script fails because there is no /var/run/nvbcm.

me@xyz:~$ cat /etc/systemd/nvwifibt-pre.sh
#!/bin/bash


SUBTASK=$1
BCMCHIP=$2
RET=1

if [ "$SUBTASK" = "register" ]; then
	if [ "x$BCMCHIP" != "x" ]; then
		if [ ! -f /var/run/nvbcm ]; then
			# record the type of chip
			echo "BCMCHIP=${BCMCHIP}" > /var/run/nvbcm
		fi
		RET=0
	fi
	exit $RET
fi

if [ -x /usr/sbin/brcm_patchram_plus -a -r /var/run/nvbcm -a -w /proc/bluetooth/sleep/lpm ]; then
	. /var/run/nvbcm
	for chip in 4329 4330 4324 4354; do
		if [ "x0x$chip" = "x$BCMCHIP" -a -f "/lib/firmware/bcm$chip.hcd" ]; then
			RET=0
			break
		fi
	done
fi

if [ "$RET" != "0" ]; then
	stop
fi

exit $RET

This file seems to be created when udev detects the CYW4354 chip on the sdio bus.

me@xyz:~$ cat /etc/udev/rules.d/99-nv-wifibt.rules 
#
# Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved.
#

# Broadcom wifi
ACTION=="add" SUBSYSTEM=="sdio" ATTR{vendor}=="0x02d0" RUN+="/etc/systemd/nvwifibt-pre.sh register $attr{device}"

# turn on/off bluetooth
# support all versions of bluedroid_pm
ACTION=="change" SUBSYSTEM=="rfkill" ATTR{name}=="bluedroid_pm*" ATTR{state}=="1" RUN+="/bin/systemctl start nvwifibt.service"
ACTION=="change" SUBSYSTEM=="rfkill" ATTR{name}=="bluedroid_pm*" ATTR{state}=="0" RUN+="/bin/systemctl stop nvwifibt.service"

What could be a reason, why this chip is not detected sometimes and how could I go about debugging this further?
It is a really strange issue. We have some devices where this never occurs, some where is occurs intermittendly and some where it almost always occurs.

Any help would be greatly appreciated.

Thanks,
Johannes

Hi,
I think I solved or at least created a workaround for my Problem. If the nvwifibt failed to start I can do the registration by hand and restart the Service. If I activate the Interface afterwards everything works again.

MfG
Johannes

me@xyz:~$ sudo nano /etc/systemd/nvwifibt-pre.sh register 0x4354
me@xyz:~$ sudo systemctl restart nvwifibt.service
me@xyz:~$ sudo hciconfig hci0 up

me@xyz:~$ sudo bluetoothctl 
[NEW] Controller 00:04:4B:E0:87:4F xyz [default]
[NEW] Device 00:03:19:89:28:7A R8-3, 5139473108: Trimble
[bluetooth]# paired-devices
Device 00:03:19:89:28:7A R8-3, 5139473108: Trimble
[bluetooth]# quit
[DEL] Controller 00:04:4B:E0:87:4F xyz [default]
me@xyz:~$ ls /dev/rf
rfcomm0  rfcomm1  rfcomm2  rfkill