Skip to content

Instantly share code, notes, and snippets.

@whitelynx
Last active April 16, 2024 12:38
Show Gist options
  • Save whitelynx/9f9bd4cb266b3924c64dfdff14bce2e8 to your computer and use it in GitHub Desktop.
Save whitelynx/9f9bd4cb266b3924c64dfdff14bce2e8 to your computer and use it in GitHub Desktop.
Adding Bluetooth support to ArchLinux ARM's Raspberry Pi 4 version
# /lib/udev/rules.d/90-pi-bluetooth.rules
# Copied from https://github.com/RPi-Distro/pi-bluetooth/blob/master/lib/udev/rules.d/90-pi-bluetooth.rules
# Raspberry Pi bluetooth module: enable routing of SCO packets to the HCI interface
ACTION=="add", SUBSYSTEM=="bluetooth", KERNEL=="hci[0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}+="bthelper@%k.service"
# /etc/udev/rules.d/99-serial.rules
# Copied from Raspbian's 99-com.rules
KERNEL=="ttyAMA[01]", PROGRAM="/bin/sh -c '\
ALIASES=/proc/device-tree/aliases; \
if cmp -s $ALIASES/uart0 $ALIASES/serial0; then \
echo 0;\
elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then \
echo 1; \
else \
exit 1; \
fi\
'", SYMLINK+="serial%c"
KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\
ALIASES=/proc/device-tree/aliases; \
if cmp -s $ALIASES/uart1 $ALIASES/serial0; then \
echo 0; \
elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then \
echo 1; \
else \
exit 1; \
fi \
'", SYMLINK+="serial%c"
#!/bin/sh
# /usr/bin/btuart
# Based on https://github.com/RPi-Distro/pi-bluetooth/blob/master/usr/bin/btuart
HCIATTACH=/usr/bin/btattach
if grep -q "Pi 4" /proc/device-tree/model; then
BDADDR=
else
SERIAL=`cat /proc/device-tree/serial-number | cut -c9-`
B1=`echo $SERIAL | cut -c3-4`
B2=`echo $SERIAL | cut -c5-6`
B3=`echo $SERIAL | cut -c7-8`
BDADDR=`printf b8:27:eb:%02x:%02x:%02x $((0x$B1 ^ 0xaa)) $((0x$B2 ^ 0xaa)) $((0x$B3 ^ 0xaa))`
fi
uart0="`cat /proc/device-tree/aliases/uart0`"
serial1="`cat /proc/device-tree/aliases/serial1`"
if [ "$uart0" = "$serial1" ] ; then
uart0_pins="`wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' '`"
if [ "$uart0_pins" = "16" ] ; then
$HCIATTACH -B /dev/serial1 -P bcm -S 3000000
else
$HCIATTACH -B /dev/serial1 -P bcm -S 921600 --noflowctl
fi
else
$HCIATTACH -B /dev/serial1 -P bcm -S 460800 --noflowctl
fi
# /lib/systemd/system/hciuart.service
# Copied from Raspbian
[Unit]
Description=Configure Bluetooth Modems connected by UART
ConditionFileNotEmpty=/proc/device-tree/soc/gpio@7e200000/bt_pins/brcm,pins
Requires=dev-serial1.device
After=dev-serial1.device
[Service]
Type=simple
ExecStart=/usr/bin/btuart
[Install]
WantedBy=multi-user.target
@yatli
Copy link

yatli commented Apr 16, 2024

Thanks for your efforts!
Linking back to the forum (for future visitors): https://archlinuxarm.org/forum/viewtopic.php?t=14244

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