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 <marc.mattmueller@netmodule.com>
This commit is contained in:
Marc Mattmueller 2021-06-02 18:53:38 +02:00
parent c2eabcb4e9
commit e367bcf0c1
5 changed files with 129 additions and 24 deletions

View File

@ -7,11 +7,12 @@
# The USB hub in the HW23 connects the GNSS modem, the v2x- # The USB hub in the HW23 connects the GNSS modem, the v2x-
# module, the user interface and the user module. # module, the user interface and the user module.
# #
# During the configuration/start-up the v2x module and the # When HW23 device is powering up the v2x module enters DFU
# GNSS modem are interfering. Thus a sequentialized startup # mode. This mode leads to enumeration errors when releasing
# the gnss module from reset. Thus a sequentialized startup
# is needed. # is needed.
# This service just powers the USB hub and is the first # This script just sets the USB hub either into reset mode or
# service needed if GNSS or in case of HW23 v2x shall work. # releases it from reset.
# ************************************************************ # ************************************************************
SCRIPT_NAME=$(basename "${0}") SCRIPT_NAME=$(basename "${0}")
@ -32,9 +33,9 @@ export HUB_RST_STATE="off"
function printUsage() function printUsage()
{ {
echo -e "\\nUsage: ${SCRIPT_NAME} [OPTIONS] HUB_STATE\\n\\n" echo -e "\\nUsage: ${SCRIPT_NAME} [OPTIONS] HUB_STATE\\n\\n"
echo -e " HUB_STATE The reqeusted state of the ubs hub:" echo -e " HUB_STATE The requested state of the usb hub:"
echo -e " * on = switch hub ON" echo -e " * on = release hub from reset"
echo -e " * off = switch hub OFF (default)" echo -e " * off = set hub into reset state (default)"
echo -e " OPTIONS:" echo -e " OPTIONS:"
echo -e " -h|--help Show this help" echo -e " -h|--help Show this help"
echo -e "" echo -e ""
@ -46,7 +47,7 @@ function printUsage()
O=$(getopt -o h --long help -- "$@") || exit 1 O=$(getopt -o h --long help -- "$@") || exit 1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "ERROR: Could not parse command line options" echo "ERROR: Could not parse $SCRIPT_NAME command line options"
exit 1 exit 1
fi fi
@ -69,21 +70,18 @@ done
if [ ! -f $HUB_RST ]; then 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 return 1
fi fi
HUB_RST_VALUE=$OFF_VALUE HUB_RST_VALUE=$OFF_VALUE
[[ "${HUB_RST_STATE}" != "off" ]] && HUB_RST_VALUE=$ON_VALUE || true [[ "${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 echo $HUB_RST_VALUE > $HUB_RST
if [[ "$?" != "0" ]]; then 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 exit 1
fi fi
# add a sleep to settle a potential off and on switching
sleep 0.5
exit 0 exit 0

View File

@ -5,11 +5,7 @@ Before=gpsd.service
[Service] [Service]
Type=oneshot Type=oneshot
ExecStartPre=/usr/bin/usb-hub-reset off ExecStart=/usr/bin/usb-hub-reset on
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
RemainAfterExit=yes RemainAfterExit=yes

View File

@ -5,11 +5,8 @@ After=usb-hub-reset.service v2x-ieee802.11p.service
[Service] [Service]
Type=oneshot Type=oneshot
ExecStartPre=/bin/sh -c "echo 255 > /sys/class/leds/gnss_rst/brightness && sleep 1" ExecStartPre=/usr/bin/sh -c "/usr/bin/gnss-reset -c"
ExecStart=/usr/bin/echo releasing gnss modem from reset... ExecStart=/usr/bin/sh -c "/usr/bin/gnss-reset -s on"
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"
RemainAfterExit=yes RemainAfterExit=yes

View File

@ -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

View File

@ -13,6 +13,7 @@ FILESEXTRAPATHS_append := ":${THISDIR}/files"
SRC_URI_append = " \ SRC_URI_append = " \
file://gnss-init.service \ file://gnss-init.service \
file://gnss-reset \
" "
S = "${WORKDIR}" S = "${WORKDIR}"
@ -27,4 +28,6 @@ do_install_append() {
install -d ${D}${systemd_unitdir}/system install -d ${D}${systemd_unitdir}/system
install -m 644 ${WORKDIR}/gnss-init.service ${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}
} }