diff --git a/board/common/cleanups.sh b/board/common/cleanups.sh index 2444701815..4139533adb 100755 --- a/board/common/cleanups.sh +++ b/board/common/cleanups.sh @@ -33,8 +33,6 @@ rm -rf $TARGET/usr/share/ffmpeg/ rm -rf $TARGET/usr/share/perl5/ rm -rf $TARGET/usr/share/common-lisp/ -find $TARGET -name '*libmount*' | xargs rm -rf - # various binaries rm -f $TARGET/bin/more rm -f $TARGET/bin/wdctl diff --git a/board/common/mkimage.sh b/board/common/mkimage.sh index d9ef3cffa5..3b8723c13c 100755 --- a/board/common/mkimage.sh +++ b/board/common/mkimage.sh @@ -50,7 +50,7 @@ mkdir -p $BOOT mount -o loop $loop_dev $BOOT msg "copying boot filesystem contents" -cp $BOOT_SRC/* $BOOT +cp -r $BOOT_SRC/* $BOOT sync msg "unmounting boot filesystem" diff --git a/board/common/overlay/etc/bluetooth/main.conf b/board/common/overlay/etc/bluetooth/main.conf new file mode 120000 index 0000000000..cfea82441f --- /dev/null +++ b/board/common/overlay/etc/bluetooth/main.conf @@ -0,0 +1 @@ +/var/lib/bluetooth.conf \ No newline at end of file diff --git a/board/common/overlay/etc/dbus-1/system.conf b/board/common/overlay/etc/dbus-1/system.conf new file mode 100644 index 0000000000..e79925c337 --- /dev/null +++ b/board/common/overlay/etc/dbus-1/system.conf @@ -0,0 +1,9 @@ + + + system + + + + + diff --git a/board/common/overlay/etc/firmware b/board/common/overlay/etc/firmware new file mode 120000 index 0000000000..4d673c0af5 --- /dev/null +++ b/board/common/overlay/etc/firmware @@ -0,0 +1 @@ +/lib/firmware \ No newline at end of file diff --git a/board/common/overlay/etc/hostname b/board/common/overlay/etc/hostname new file mode 120000 index 0000000000..5a7fdb0731 --- /dev/null +++ b/board/common/overlay/etc/hostname @@ -0,0 +1 @@ +/data/etc/hostname \ No newline at end of file diff --git a/board/common/overlay/etc/init.d/S30dbus b/board/common/overlay/etc/init.d/S30dbus new file mode 100755 index 0000000000..82e9519ba6 --- /dev/null +++ b/board/common/overlay/etc/init.d/S30dbus @@ -0,0 +1,53 @@ +#!/bin/bash + +sys_btconf="/etc/bluetooth.conf" +boot_btconf="/boot/bluetooth.conf" +btconf="/data/etc/bluetooth.conf" + +# dbus is only used by bluez +test -f $btconf || test -f $boot_btconf || test -f $sys_btconf || exit 0 + +test -n "$os_version" || source /etc/init.d/base + +start() { + mkdir -p /tmp/dbus + + msg_begin "Starting dbus" + + dbus-uuidgen --ensure + dbus-daemon --system + + test $? == 0 && msg_done || msg_fail +} + +stop() { + msg_begin "Stopping dbus" + udevadm control --stop-exec-queue + killall dbus-daemon &>/dev/null + test $? == 0 && msg_done || msg_fail + + rm -f /var/run/messagebus.pid +} + +case "$1" in + start) + start + ;; + + stop) + stop + ;; + + restart) + stop + start + ;; + + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 + ;; +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/S37bluetooth b/board/common/overlay/etc/init.d/S37bluetooth new file mode 100755 index 0000000000..c70568fb38 --- /dev/null +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -0,0 +1,95 @@ +#!/bin/bash + +sys_conf="/etc/bluetooth.conf" +boot_conf="/boot/bluetooth.conf" +conf="/data/etc/bluetooth.conf" + +if ! [ -f $conf ]; then + if [ -f $boot_conf ]; then + cp $boot_conf $conf + elif [ -f $sys_conf ]; then + cp $sys_conf $conf + fi +fi + +test -f $conf || exit 0 + +test -n "$os_version" || source /etc/init.d/base + +hci=hci0 +bluetoothd=/usr/libexec/bluetooth/bluetoothd +run_conf="/var/lib/bluetooth.conf" + +configure() { + cp $conf $run_conf + + # if no specific name configured, use hostname + if ! grep -E 'Name\s*=' $run_conf &>/dev/null; then + sed -ri "s/(\[General\])/\1\nName = $(hostname)/" $run_conf + fi + + # bring adapter up + hciconfig $hci up +} + +start() { + msg_begin "Configuring bluetooth" + + # wait up to 10 seconds for device + count=0 + while ! hciconfig $hci &>/dev/null; do + sleep 1 + count=$(($count + 1)) + if [ $count -ge 10 ]; then + msg_fail "no device" + logger -t bluetooth -s "bluetooth device not available, rebooting" + reboot + return 1 + fi + done + + if configure; then + msg_done + else + msg_fail + return 1 + fi + + msg_begin "Starting bluetoothd" + $bluetoothd &>/dev/null & + msg_done + + # if DiscoverableTimeout is set to 0, make adapter discoverable from boot time + if grep -E '^DiscoverableTimeout\s*=\s*0$' $run_conf &>/dev/null; then + sleep 1 + hciconfig $hci piscan + fi +} + +stop() { + msg_begin "Stopping bluetoothd" + killall bluetoothd &>/dev/null + test $? == 0 && msg_done || msg_fail +} + +case "$1" in + start) + start + ;; + + stop) + stop + ;; + + restart) + stop + start + ;; + + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/base b/board/common/overlay/etc/init.d/base index 563aefd10b..11a5ef95eb 100755 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -16,3 +16,7 @@ msg_fail() { test -n "$1" && echo $1 || echo "failed" } +msg_background() { + test -n "$1" && echo $1 || echo "pending" +} + diff --git a/board/common/overlay/lib/firmware/brcm/brcmfmac43430-sdio.bin b/board/common/overlay/lib/firmware/brcm/brcmfmac43430-sdio.bin index 84ab5b0dee..2f9647263c 100644 Binary files a/board/common/overlay/lib/firmware/brcm/brcmfmac43430-sdio.bin and b/board/common/overlay/lib/firmware/brcm/brcmfmac43430-sdio.bin differ diff --git a/board/raspberrypi/overlay/etc/init.d/S13btuart b/board/raspberrypi/overlay/etc/init.d/S13btuart new file mode 100755 index 0000000000..48464b8263 --- /dev/null +++ b/board/raspberrypi/overlay/etc/init.d/S13btuart @@ -0,0 +1,45 @@ +#!/bin/bash + +sys_conf="/etc/bluetooth.conf" +boot_conf="/boot/bluetooth.conf" +conf="/data/etc/bluetooth.conf" + +test -f $conf || test -f $boot_conf || test -f $sys_conf || exit 0 + +test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected + +test -n "$os_version" || source /etc/init.d/base + +function start() { + if [ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ] ; then + if [ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ] ; then + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null + else + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null + fi + else + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null + fi +} + +case "$1" in + start) + msg_begin "Attaching UART bluetooth modem" + # for some reason, sometimes the hciattach command needs to be run twice + (start || start) &>/dev/null & + msg_background + ;; + + stop) + msg_begin "Detaching UART bluetooth modem" + killall hciattach &>/dev/null + test $? == 0 && msg_done || msg_fail + ;; + + *) + echo $"Usage: $0 {start}" + exit 1 +esac + +exit $? + diff --git a/board/raspberrypi/overlay/etc/udev/rules.d/99-com.rules b/board/raspberrypi/overlay/etc/udev/rules.d/99-com.rules new file mode 100644 index 0000000000..a964057230 --- /dev/null +++ b/board/raspberrypi/overlay/etc/udev/rules.d/99-com.rules @@ -0,0 +1,32 @@ +SUBSYSTEM=="input", GROUP="input", MODE="0660" +SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660" +SUBSYSTEM=="spidev", GROUP="spi", MODE="0660" +SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660" + +SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\ + chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\ + chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\ + chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\ +'" + +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" diff --git a/board/raspberrypi/overlay/lib/firmware/BCM43430A1.hcd b/board/raspberrypi/overlay/lib/firmware/BCM43430A1.hcd new file mode 100644 index 0000000000..162275ac0b Binary files /dev/null and b/board/raspberrypi/overlay/lib/firmware/BCM43430A1.hcd differ diff --git a/board/raspberrypi/overlay/usr/bin/hciattach b/board/raspberrypi/overlay/usr/bin/hciattach new file mode 100755 index 0000000000..468a3342a6 Binary files /dev/null and b/board/raspberrypi/overlay/usr/bin/hciattach differ diff --git a/board/raspberrypi3/overlay/etc/init.d/S13btuart b/board/raspberrypi3/overlay/etc/init.d/S13btuart new file mode 100755 index 0000000000..6899065c82 --- /dev/null +++ b/board/raspberrypi3/overlay/etc/init.d/S13btuart @@ -0,0 +1,43 @@ +#!/bin/bash + +sys_conf="/etc/bluetooth.conf" +boot_conf="/boot/bluetooth.conf" +conf="/data/etc/bluetooth.conf" + +test -f $conf || test -f $boot_conf || test -f $sys_conf || exit 0 + +test -n "$os_version" || source /etc/init.d/base + +function start() { + if [ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ] ; then + if [ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ] ; then + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null + else + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null + fi + else + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null + fi +} + +case "$1" in + start) + msg_begin "Attaching UART bluetooth modem" + # for some reason, sometimes the hciattach command needs to be run twice + (start || start) &>/dev/null & + msg_background + ;; + + stop) + msg_begin "Detaching UART bluetooth modem" + killall hciattach &>/dev/null + test $? == 0 && msg_done || msg_fail + ;; + + *) + echo $"Usage: $0 {start}" + exit 1 +esac + +exit $? + diff --git a/board/raspberrypi3/overlay/etc/udev/rules.d/99-com.rules b/board/raspberrypi3/overlay/etc/udev/rules.d/99-com.rules new file mode 100644 index 0000000000..a964057230 --- /dev/null +++ b/board/raspberrypi3/overlay/etc/udev/rules.d/99-com.rules @@ -0,0 +1,32 @@ +SUBSYSTEM=="input", GROUP="input", MODE="0660" +SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660" +SUBSYSTEM=="spidev", GROUP="spi", MODE="0660" +SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660" + +SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\ + chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\ + chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\ + chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\ +'" + +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" diff --git a/board/raspberrypi3/overlay/lib/firmware/BCM43430A1.hcd b/board/raspberrypi3/overlay/lib/firmware/BCM43430A1.hcd new file mode 100644 index 0000000000..162275ac0b Binary files /dev/null and b/board/raspberrypi3/overlay/lib/firmware/BCM43430A1.hcd differ diff --git a/board/raspberrypi3/overlay/usr/bin/hciattach b/board/raspberrypi3/overlay/usr/bin/hciattach new file mode 100755 index 0000000000..468a3342a6 Binary files /dev/null and b/board/raspberrypi3/overlay/usr/bin/hciattach differ