From e367bcf0c1b21c9e21bf466a680da8bec53ca0c5 Mon Sep 17 00:00:00 2001 From: Marc Mattmueller Date: Wed, 2 Jun 2021 18:53:38 +0200 Subject: [PATCH] usb-hub/gnss-init: handle releasing resets at power-up and reboot start-up changes: - usb-hub is just released from reset - gnss-init service calls a script twice: - as pre-step: checking the hub state depending on the start reason: - at reboot --> just go on, at power-up - at power-up --> wait for a USB disconnect of a device for a certain time - as start step: releasing gnss module from reset shutdown changes: - no resets were triggered BugzID: 72787 Signed-off-by: Marc Mattmueller --- recipes-bsp/usb-hub-reset/files/usb-hub-reset | 26 ++-- .../usb-hub-reset/files/usb-hub-reset.service | 6 +- .../gnss-init/files/gnss-init.service | 7 +- .../gnss-init/files/gnss-reset | 111 ++++++++++++++++++ recipes-connectivity/gnss-init/gnss-init.bb | 3 + 5 files changed, 129 insertions(+), 24 deletions(-) create mode 100755 recipes-connectivity/gnss-init/files/gnss-reset diff --git a/recipes-bsp/usb-hub-reset/files/usb-hub-reset b/recipes-bsp/usb-hub-reset/files/usb-hub-reset index 41492f6..22bfb1d 100644 --- a/recipes-bsp/usb-hub-reset/files/usb-hub-reset +++ b/recipes-bsp/usb-hub-reset/files/usb-hub-reset @@ -7,11 +7,12 @@ # The USB hub in the HW23 connects the GNSS modem, the v2x- # module, the user interface and the user module. # -# During the configuration/start-up the v2x module and the -# GNSS modem are interfering. Thus a sequentialized startup +# When HW23 device is powering up the v2x module enters DFU +# mode. This mode leads to enumeration errors when releasing +# the gnss module from reset. Thus a sequentialized startup # is needed. -# This service just powers the USB hub and is the first -# service needed if GNSS or in case of HW23 v2x shall work. +# This script just sets the USB hub either into reset mode or +# releases it from reset. # ************************************************************ SCRIPT_NAME=$(basename "${0}") @@ -32,9 +33,9 @@ export HUB_RST_STATE="off" function printUsage() { echo -e "\\nUsage: ${SCRIPT_NAME} [OPTIONS] HUB_STATE\\n\\n" - echo -e " HUB_STATE The reqeusted state of the ubs hub:" - echo -e " * on = switch hub ON" - echo -e " * off = switch hub OFF (default)" + echo -e " HUB_STATE The requested state of the usb hub:" + echo -e " * on = release hub from reset" + echo -e " * off = set hub into reset state (default)" echo -e " OPTIONS:" echo -e " -h|--help Show this help" echo -e "" @@ -46,7 +47,7 @@ function printUsage() O=$(getopt -o h --long help -- "$@") || exit 1 if [ $? != 0 ]; then - echo "ERROR: Could not parse command line options" + echo "ERROR: Could not parse $SCRIPT_NAME command line options" exit 1 fi @@ -69,21 +70,18 @@ done if [ ! -f $HUB_RST ]; then - echo "ERROR: USB hub reset lines not available" + echo "ERROR $SCRIPT_NAME: USB hub reset lines not available" return 1 fi HUB_RST_VALUE=$OFF_VALUE [[ "${HUB_RST_STATE}" != "off" ]] && HUB_RST_VALUE=$ON_VALUE || true - +echo "$SCRIPT_NAME: set usb-hub=${HUB_RST_STATE}($HUB_RST_VALUE)..." echo $HUB_RST_VALUE > $HUB_RST if [[ "$?" != "0" ]]; then - echo "ERROR: Could not set usb hub to ${HUB_RST_STATE}" + echo "ERROR $SCRIPT_NAME: Could not set usb hub to ${HUB_RST_STATE}" exit 1 fi -# add a sleep to settle a potential off and on switching -sleep 0.5 - exit 0 diff --git a/recipes-bsp/usb-hub-reset/files/usb-hub-reset.service b/recipes-bsp/usb-hub-reset/files/usb-hub-reset.service index 411ceea..31d6f97 100644 --- a/recipes-bsp/usb-hub-reset/files/usb-hub-reset.service +++ b/recipes-bsp/usb-hub-reset/files/usb-hub-reset.service @@ -5,11 +5,7 @@ Before=gpsd.service [Service] Type=oneshot -ExecStartPre=/usr/bin/usb-hub-reset off -ExecStart=/usr/bin/echo releasing usb hub from reset... -ExecStartPost=/usr/bin/usb-hub-reset on -ExecStop=/usr/bin/echo set usb hub into reset state... -ExecStopPost=/usr/bin/usb-hub-reset off +ExecStart=/usr/bin/usb-hub-reset on RemainAfterExit=yes diff --git a/recipes-connectivity/gnss-init/files/gnss-init.service b/recipes-connectivity/gnss-init/files/gnss-init.service index 12ebc46..a31f2f5 100644 --- a/recipes-connectivity/gnss-init/files/gnss-init.service +++ b/recipes-connectivity/gnss-init/files/gnss-init.service @@ -5,11 +5,8 @@ After=usb-hub-reset.service v2x-ieee802.11p.service [Service] Type=oneshot -ExecStartPre=/bin/sh -c "echo 255 > /sys/class/leds/gnss_rst/brightness && sleep 1" -ExecStart=/usr/bin/echo releasing gnss modem from reset... -ExecStartPost=/bin/sh -c "echo 0 > /sys/class/leds/gnss_rst/brightness" -ExecStop=/usr/bin/echo setting gnss modem into reset... -ExecStopPost=/bin/sh -c "echo 255 > /sys/class/leds/gnss_rst/brightness" +ExecStartPre=/usr/bin/sh -c "/usr/bin/gnss-reset -c" +ExecStart=/usr/bin/sh -c "/usr/bin/gnss-reset -s on" RemainAfterExit=yes diff --git a/recipes-connectivity/gnss-init/files/gnss-reset b/recipes-connectivity/gnss-init/files/gnss-reset new file mode 100755 index 0000000..298ed99 --- /dev/null +++ b/recipes-connectivity/gnss-init/files/gnss-reset @@ -0,0 +1,111 @@ +#!/bin/sh + +# ************************************************************ +# GNSS Reset Script +# ----------------------- +# +# The USB hub in the HW23 connects the GNSS modem, the v2x- +# module, the user interface and the user module. +# +# When HW23 device is powering up the v2x module enters DFU +# mode. This mode leads to enumeration errors when releasing +# the gnss module from reset. Thus a sequentialized startup +# is needed. +# This script can be called with option -c to check for a +# specific time if the USB hub detects a disconnection of +# the v2x module. This is needed for a proper startup of +# the device. +# ************************************************************ + +SCRIPT_NAME=$(basename "${0}") +SCRIPT_DIR=$(dirname "${0}") +SCRIPT_PATH=$(realpath "${SCRIPT_DIR}") +MYDIR=$(pwd) + +START_REASON=/sys/kernel/broker/start-reason +GNSS_RST=/sys/class/leds/gnss_rst/brightness +ON_VALUE=0 +OFF_VALUE=255 +CHECK_TIMEOUT_S=50 + +export RST_STATE="off" +export IS_CHECK=false + +#********************************************************************************************** +# local helper functions +#********************************************************************************************** +function printUsage() +{ + echo -e "\\nUsage: ${SCRIPT_NAME} CMD \\n\\n" + echo -e " CMD:" + echo -e " -c|--check Check start reason and usb-hub message" + echo -e " -s|--set=STATE Set the requested STATE of the gnss module:" + echo -e " * on = release module from reset" + echo -e " * off = set module in reset mode (default)" + echo -e " -h|--help Show this help" + echo -e "" +} + +function checkDeviceState() +{ + if [ $(cat $START_REASON | grep reboot | wc -l) == 1 ]; then + echo "$SCRIPT_NAME: Reboot, no further check necessary" + else + echo "$SCRIPT_NAME: Power cycle detected, checking usb hub" + timeout $CHECK_TIMEOUT_S bash -c -- 'while true; do dmesg | grep "usb 1-1.*USB disconnect"; if [ $? == 0 ]; then break; fi; done' + if [ $? == 124 ]; then + echo "$SCRIPT_NAME: timed out - no reset of v2x module detected" + fi + fi +} + +#********************************************************************************************** +# main +#********************************************************************************************** + +O=$(getopt -o hcs: --long help,check,set: -- "$@") || exit 1 +if [ $? != 0 ]; then + echo "ERROR: Could not parse $SCRIPT_NAME command line options" + exit 1 +fi + +eval set -- "$O" +while true; do + case "${1}" in + -c|--check) + export IS_CHECK=true + shift + ;; + -s|--set) + export RST_STATE="${2}" + shift 2 + ;; + --) + break + ;; + *) + printUsage; exit 0 ;; + esac +done + +if [ ! -f $GNSS_RST ]; then + echo "ERROR $SCRIPT_NAME: GNSS module reset lines not available" + exit 1 +fi + +RST_VALUE=$OFF_VALUE +[[ "${RST_STATE}" != "off" ]] && RST_VALUE=$ON_VALUE || true + +if [[ "${IS_CHECK}" == "true" ]]; then + checkDeviceState + exit 0 +fi + +echo "$SCRIPT_NAME: setting $GNSS_RST=$RST_STATE($RST_VALUE)..." +echo $RST_VALUE > $GNSS_RST +if [[ "$?" != 0 ]]; then + echo "ERROR $SCRIPT_NAME: Could not set $RST_STATE ($RST_VALUE) in $GNSS_RST" + exit 1 +fi + +exit 0 diff --git a/recipes-connectivity/gnss-init/gnss-init.bb b/recipes-connectivity/gnss-init/gnss-init.bb index cdaa22b..a82a268 100644 --- a/recipes-connectivity/gnss-init/gnss-init.bb +++ b/recipes-connectivity/gnss-init/gnss-init.bb @@ -13,6 +13,7 @@ FILESEXTRAPATHS_append := ":${THISDIR}/files" SRC_URI_append = " \ file://gnss-init.service \ + file://gnss-reset \ " S = "${WORKDIR}" @@ -27,4 +28,6 @@ do_install_append() { install -d ${D}${systemd_unitdir}/system install -m 644 ${WORKDIR}/gnss-init.service ${D}${systemd_unitdir}/system/ + install -d ${D}${bindir} + install -m 744 ${WORKDIR}/gnss-reset ${D}${bindir} }