meta-netmodule-bsp/recipes-bsp/v2x-ieee802.11p/files/v2x-fw-load

142 lines
3.5 KiB
Bash
Executable File

#!/bin/sh
SCRIPT_NAME=$(basename "${0}")
V2X_CONF=/etc/v2x0.conf
V2X_RST=/sys/class/leds/v2x_rst/brightness
ON_VALUE=0
#OFF_VALUE=255
IS_PLACEHOLDER_FW=false
#**********************************************************************************************
# local helper functions
#**********************************************************************************************
printUsage()
{
echo ""
echo "Usage: ${SCRIPT_NAME} [OPT] CMD"
echo ""
echo " CMD:"
echo " -h|--help Show this help"
echo ""
echo " OPT:"
echo " -c|--config-file=FILE The config file pathname (default=${V2X_CONF})"
echo ""
}
checkInputParameters()
{
if [ ! -f $V2X_RST ]; then
echo "ERROR $SCRIPT_NAME: v2x module reset lines not available"
exit 1
fi
if [ ! -f $V2X_CONF ]; then
echo "ERROR $SCRIPT_NAME: no v2x config file '${V2X_CONF}' found"
exit 1
fi
}
getConfigParameters()
{
echo "$SCRIPT_NAME: getting config parameter from $V2X_CONF"
placeholderEntry=$(grep is-placeholder-firmware $V2X_CONF | cut -d'=' -f2)
if [ "${placeholderEntry}" != "" ] && [ "${placeholderEntry}" = "true" ]; then
IS_PLACEHOLDER_FW=true
fi
}
enableTheModule()
{
pwrGpio="$(gpiofind UM_SUP_EN)"
echo "$SCRIPT_NAME: releasing v2x reset..."
echo $ON_VALUE > $V2X_RST
echo "$SCRIPT_NAME: toggling v2x module power..."
gpioset -m time -s 1 $pwrGpio=0
gpioset -m signal $pwrGpio=1 &
}
detectDfuMode()
{
timeoutS=30
echo "$SCRIPT_NAME: discovering DFU mode of v2x module (timeout=${timeoutS}s)..."
timeout $timeoutS bash -c -- 'while true; do lsusb | grep "0483:df11"; if [ $? == 0 ]; then break; fi; done'
if [ $? = 124 ]; then
echo "ERROR: v2x module is not available on usb bus"
exit 1
fi
}
waitForDfuModeExit()
{
disconnectTimeoutS=20
echo "$SCRIPT_NAME: wait for v2x module leaving DFU mode (timeout=${disconnectTimeoutS}s)..."
timeout $disconnectTimeoutS bash -c -- 'while true; do dmesg | grep "0483:df11"; if [ $? != 0 ]; then break; fi; done'
if [ $? = 124 ]; then
echo "$SCRIPT_NAME: no DFU mode exit of v2x module detected"
else
echo "$SCRIPT_NAME: v2x module exited DFU mode"
fi
}
loadFirmware()
{
echo "$SCRIPT_NAME: loading v2x firmware..."
output=$(dfu-util -d 0483:df11 -s 0x10000000 -D /lib/firmware/v2x/SECTON.packed_bin.rom 2>&1)
if [ $? != 0 ]; then
if echo "$output" | grep -i "Error during abort get_status"; then
echo "$SCRIPT_NAME: get_status abort error: ignoring"
exit 0
fi
echo "$SCRIPT_NAME: Something went wrong while uploading firmware:"
echo "$output"
exit 1
fi
}
#**********************************************************************************************
# main
#**********************************************************************************************
O=$(getopt -o hc: --long help,config-file: -- "$@") || exit 1
eval set -- "$O"
while true; do
case "${1}" in
-h|--help)
printUsage
exit 0
;;
-c|--config-file)
V2X_CONF=${2}
shift 2
;;
--)
break
;;
*)
printUsage; exit 0 ;;
esac
done
checkInputParameters
getConfigParameters
enableTheModule
detectDfuMode
if [ $IS_PLACEHOLDER_FW = true ]; then
echo "$SCRIPT_NAME: v2x placeholder firmware configured"
waitForDfuModeExit
exit 0
fi
loadFirmware
exit 0