diff options
author | Arksine <arksine.code@gmail.com> | 2021-01-21 15:48:59 -0500 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2021-02-05 19:37:56 -0500 |
commit | d79e7ab31b8ddb5790d5382d046098e716e32a0b (patch) | |
tree | 91f558616eeeb27a2492911647383f38ee261b92 /scripts/flash-sdcard.sh | |
parent | 44c1caf2b9cf05efbd7f4bce042193ab2e181ca9 (diff) | |
download | kutter-d79e7ab31b8ddb5790d5382d046098e716e32a0b.tar.gz kutter-d79e7ab31b8ddb5790d5382d046098e716e32a0b.tar.xz kutter-d79e7ab31b8ddb5790d5382d046098e716e32a0b.zip |
scripts: add flash-sdcard.sh helper script
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Diffstat (limited to 'scripts/flash-sdcard.sh')
-rwxr-xr-x | scripts/flash-sdcard.sh | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/scripts/flash-sdcard.sh b/scripts/flash-sdcard.sh new file mode 100755 index 00000000..b6f06ed8 --- /dev/null +++ b/scripts/flash-sdcard.sh @@ -0,0 +1,69 @@ +#!/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" +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 + echo "usage: flash_sdcard.sh [-h] [-l] [-b <baud>] [-f <firmware>]" + echo " <device> <board>" + echo + echo "positional arguments:" + echo " <device> device serial port" + echo " <board> board type" + echo + echo "optional arguments:" + 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" +} + +# Parse command line "optional args" +while getopts "hlb:f:" arg; do + 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;; + 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 + +# Run Script +echo "Flashing ${KLIPPER_BIN} to ${DEVICE}" +${KLIPPY_ENV} ${SPI_FLASH} ${BAUD_ARG} ${DEVICE} ${BOARD} ${KLIPPER_BIN} |