2021-01-21 21:48:59 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# This script launches flash_sdcard.py, a utitlity that enables
|
|
|
|
# unattended firmware updates on boards with "SD Card" bootloaders
|
|
|
|
|
|
|
|
# Non-standard installations may need to change this location
|
|
|
|
KLIPPY_ENV="${HOME}/klippy-env/bin/python"
|
|
|
|
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
|
|
|
KLIPPER_BIN="${SRCDIR}/out/klipper.bin"
|
2021-07-09 15:55:16 +02:00
|
|
|
KLIPPER_BIN_DEFAULT=$KLIPPER_BIN
|
|
|
|
KLIPPER_DICT_DEFAULT="${SRCDIR}/out/klipper.dict"
|
2021-01-21 21:48:59 +01:00
|
|
|
SPI_FLASH="${SRCDIR}/scripts/spi_flash/spi_flash.py"
|
|
|
|
BAUD_ARG=""
|
|
|
|
# Force script to exit if an error occurs
|
|
|
|
set -e
|
|
|
|
|
|
|
|
print_help_message()
|
|
|
|
{
|
|
|
|
echo "SD Card upload utility for Klipper"
|
|
|
|
echo
|
2021-07-09 15:55:16 +02:00
|
|
|
echo "usage: flash_sdcard.sh [-h] [-l] [-b <baud>] [-f <firmware>] [-d <dictionary>]"
|
2021-01-21 21:48:59 +01:00
|
|
|
echo " <device> <board>"
|
|
|
|
echo
|
|
|
|
echo "positional arguments:"
|
2021-07-09 15:55:16 +02:00
|
|
|
echo " <device> device serial port"
|
|
|
|
echo " <board> board type"
|
2021-01-21 21:48:59 +01:00
|
|
|
echo
|
|
|
|
echo "optional arguments:"
|
2021-07-09 15:55:16 +02:00
|
|
|
echo " -h show this message"
|
|
|
|
echo " -l list available boards"
|
|
|
|
echo " -b <baud> serial baud rate (default is 250000)"
|
|
|
|
echo " -f <firmware> path to klipper.bin"
|
|
|
|
echo " -d <dictionary> path to klipper.dict for firmware validation"
|
2021-01-21 21:48:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Parse command line "optional args"
|
2021-07-09 15:55:16 +02:00
|
|
|
while getopts "hlb:f:d:" arg; do
|
2021-01-21 21:48:59 +01:00
|
|
|
case $arg in
|
|
|
|
h)
|
|
|
|
print_help_message
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
l)
|
|
|
|
${KLIPPY_ENV} ${SPI_FLASH} -l
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
b) BAUD_ARG="-b ${OPTARG}";;
|
|
|
|
f) KLIPPER_BIN=$OPTARG;;
|
2021-07-09 15:55:16 +02:00
|
|
|
d) KLIPPER_DICT=$OPTARG;;
|
2021-01-21 21:48:59 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Make sure that we have the correct number of positional args
|
|
|
|
if [ $(($# - $OPTIND + 1)) -ne 2 ]; then
|
|
|
|
echo "Invalid number of args: $(($# - $OPTIND + 1))"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
DEVICE=${@:$OPTIND:1}
|
|
|
|
BOARD=${@:$OPTIND+1:1}
|
|
|
|
|
|
|
|
if [ ! -f $KLIPPER_BIN ]; then
|
|
|
|
echo "No file found at '${KLIPPER_BIN}'"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e $DEVICE ]; then
|
|
|
|
echo "No device found at '${DEVICE}'"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
2021-07-09 15:55:16 +02:00
|
|
|
if [ ! $KLIPPER_DICT ] && [ $KLIPPER_BIN == $KLIPPER_BIN_DEFAULT ] ; then
|
|
|
|
KLIPPER_DICT=$KLIPPER_DICT_DEFAULT
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $KLIPPER_DICT ]; then
|
|
|
|
if [ ! -f $KLIPPER_DICT ]; then
|
|
|
|
echo "No file found at '${KLIPPER_BIN}'"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
KLIPPER_DICT="-d ${KLIPPER_DICT}"
|
|
|
|
fi
|
|
|
|
|
2021-01-21 21:48:59 +01:00
|
|
|
# Run Script
|
|
|
|
echo "Flashing ${KLIPPER_BIN} to ${DEVICE}"
|
2021-07-09 15:55:16 +02:00
|
|
|
${KLIPPY_ENV} ${SPI_FLASH} ${BAUD_ARG} ${KLIPPER_DICT} ${DEVICE} ${BOARD} ${KLIPPER_BIN}
|