From d9f2029c38b86e957e88183adf857e4e460cdbf1 Mon Sep 17 00:00:00 2001 From: Ramon Moesching Date: Tue, 30 Jul 2019 14:26:23 +0200 Subject: [PATCH] jody-w1-bt init service: jody bluetooth patchram and init script initialize jody with patchram file and bring up hci0 interface use systemd for enabling and disabling: (requests BT_EN pin) systemctl start jody-w1-bt-init (default after boot) systemctl stop jody-w1-bt-init BugzID: 58086 Signed-off-by: Ramon Moesching --- .../jody-w1-bt-hcd/files/jody-w1-bt | 88 +++++++++++++++++++ .../files/jody-w1-bt-init.service | 17 ++++ .../jody-w1-bt-hcd/jody-w1-bt-hcd.bbappend | 28 ++++++ 3 files changed, 133 insertions(+) create mode 100755 recipes-connectivity/jody-w1-bt-hcd/files/jody-w1-bt create mode 100644 recipes-connectivity/jody-w1-bt-hcd/files/jody-w1-bt-init.service create mode 100644 recipes-connectivity/jody-w1-bt-hcd/jody-w1-bt-hcd.bbappend diff --git a/recipes-connectivity/jody-w1-bt-hcd/files/jody-w1-bt b/recipes-connectivity/jody-w1-bt-hcd/files/jody-w1-bt new file mode 100755 index 0000000..20f9e37 --- /dev/null +++ b/recipes-connectivity/jody-w1-bt-hcd/files/jody-w1-bt @@ -0,0 +1,88 @@ +#!/bin/sh +# +# JODY-W1 Bluetooth init script +# +# Copyright (C) u-blox +# u-blox reserves all rights in this deliverable (documentation, software, +# etc., hereafter “Deliverable”). +# u-blox grants you the right to use, copy, modify and distribute +# the Deliverable provided hereunder for any purpose without fee. provided this +# entire notice is included in all copies of any software which is or includes +# a copy or modification of this software and in all copies of the supporting +# documentation for such software. +# THIS DELIVERABLE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED +# WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR U-BLOX MAKES ANY +# REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS +# DELIVERABLE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. +# In case you provide us a feedback or make a contribution in the form of +# a further development of the Deliverable (“Contribution”), u-blox will have +# the same rights as granted to you, namely to use, copy, modify and distribute +# the Contribution provided to us for any purpose without fee. +# + +PIDFILE=/var/run/hciattach-jody-w1.pid +DAEMON=/usr/bin/hciattach +DESC="JODY-W1 Bluetooth" + +#needs to be parametrized +HCIATTACH_ARGS="any 3000000 flow" +TTY=/dev/ttyLP1 +PATCHRAMFILE=/lib/firmware/brcm/BCM89359_002.002.014.0120.0186.hcd + +RET=1 + +test -x $DAEMON || exit 1 + +start() { + let i=0 + while [ $i -lt 10 -a ! -c $TTY ]; do + sleep 1 + let i=i+1 + done + brcm_patchram_plus --no2bytes --tosleep 50000 --baudrate 3000000 \ + --use_baudrate_for_download --patchram "$PATCHRAMFILE" $TTY + modprobe -q hci_uart + pid=$($DAEMON -p $TTY $HCIATTACH_ARGS | tail -1) + if [ -z "$pid" ]; then + echo "failed" + exit 1 + fi + echo $pid > $PIDFILE + hciconfig all up +} + +stop() { + hciconfig all down + if [ -e $PIDFILE ]; then + kill $(cat $PIDFILE) + rm -f $PIDFILE + fi +} + +case "$1" in + start) + test -f $PIDFILE && exit 1 + echo -n "Starting ${DESC}: " + start + RET=$? + echo "$(basename $DAEMON)" + ;; + stop) + echo -n "Stopping ${DESC}: " + stop + RET=$? + echo "$(basename $DAEMON)" + ;; + restart) + echo -n "Restarting ${DESC}: " + stop + start + RET=$? + echo "$(basename $DAEMON)" + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + +exit $RET diff --git a/recipes-connectivity/jody-w1-bt-hcd/files/jody-w1-bt-init.service b/recipes-connectivity/jody-w1-bt-hcd/files/jody-w1-bt-init.service new file mode 100644 index 0000000..63f61c8 --- /dev/null +++ b/recipes-connectivity/jody-w1-bt-hcd/files/jody-w1-bt-init.service @@ -0,0 +1,17 @@ +[Unit] +Description=BT Firmware loader +After=network.target + +[Service] +Type=oneshot + +ExecStartPre=/bin/sh -c "gpioset `gpiofind BT_EN`=1" +ExecStart=/usr/bin/jody-w1-bt start +ExecStop=/usr/bin/jody-w1-bt stop +ExecStopPost=/bin/sh -c "gpioset `gpiofind BT_EN`=0" + +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target +RequiredBy=multi-user.target diff --git a/recipes-connectivity/jody-w1-bt-hcd/jody-w1-bt-hcd.bbappend b/recipes-connectivity/jody-w1-bt-hcd/jody-w1-bt-hcd.bbappend new file mode 100644 index 0000000..2897fd9 --- /dev/null +++ b/recipes-connectivity/jody-w1-bt-hcd/jody-w1-bt-hcd.bbappend @@ -0,0 +1,28 @@ +# Copyright (C) 2019 Ramon Moesching +# Released under the MIT license (see COPYING.MIT for the terms) + +inherit systemd + +FILESEXTRAPATHS_append := ":${THISDIR}/files" + +SRC_URI_append = " \ + file://jody-w1-bt-init.service \ + file://jody-w1-bt \ + " + +S = "${WORKDIR}" + +SYSTEMD_SERVICE_${PN} = " \ + jody-w1-bt-init.service \ + " + +FILES_${PN}_append = "${systemd_unitdir}/system ${bindir}" + +do_install_append() { + install -d ${D}${systemd_unitdir}/system + install -m 644 ${WORKDIR}/jody-w1-bt-init.service ${D}${systemd_unitdir}/system/ + + + install -d ${D}${bindir} + install -m 744 ${WORKDIR}/jody-w1-bt ${D}${bindir} +}