summaryrefslogtreecommitdiffstats
path: root/uno-runner.sh
diff options
context:
space:
mode:
Diffstat (limited to 'uno-runner.sh')
-rwxr-xr-xuno-runner.sh58
1 files changed, 58 insertions, 0 deletions
diff --git a/uno-runner.sh b/uno-runner.sh
new file mode 100755
index 0000000..066a598
--- /dev/null
+++ b/uno-runner.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env sh
+set -e
+
+case "$(uname -s)" in
+ Linux*) OS="Linux";;
+ Darwin*) OS="Mac";;
+ *) OS="Unknown";;
+esac
+
+if ! command -v numfmt > /dev/null 2>&1
+then
+ echo "numfmt is needed for human-readable sizes." >&2
+ echo "please install https://command-not-found.com/numfmt" >&2
+ alias numfmt=true
+fi
+
+if ! command -v avrdude > /dev/null 2>&1
+then
+ echo "required avrdude could not be found!" >&2
+ echo "please install https://command-not-found.com/avrdude" >&2
+ exit 1
+fi
+
+if [ $OS = "Linux" ]; then
+ SERIAL_PORT="/dev/ttyACM0"
+elif [ $OS = "Mac" ]; then
+ SERIAL_PORT="/dev/cu.usbmodem146201"
+else
+ echo "unsupported OS, things might not work" >&2
+ SERIAL_PORT="/dev/ttyACM0"
+fi
+
+if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
+ echo "usage: $0 <application.elf>" >&2
+ exit 1
+fi
+
+if [ "$#" -lt 1 ]; then
+ echo "$0: no ELF file given" >&2
+ exit 1
+fi
+
+NAME="$(basename "$1")"
+SIZE_TEXT="$(avr-size "$1" | tail -1 | cut -f1)"
+SIZE_DATA="$(avr-size "$1" | tail -1 | cut -f2)"
+SIZE_BSS="$(avr-size "$1" | tail -1 | cut -f3)"
+
+printf "\n"
+printf "Program: %s\n" "$NAME"
+printf "Size:\n"
+printf " .text %s (exact: %d)\n" "$(numfmt --to=si --padding=9 "$SIZE_TEXT")" "$SIZE_TEXT"
+printf " .data %s (exact: %d)\n" "$(numfmt --to=si --padding=9 "$SIZE_DATA")" "$SIZE_DATA"
+printf " .bss %s (exact: %d)\n" "$(numfmt --to=si --padding=9 "$SIZE_BSS")" "$SIZE_BSS"
+printf "\n"
+printf "Attempting to flash ...\n"
+printf "\n"
+
+avrdude -q -patmega328p -carduino -P"${SERIAL_PORT}" -D "-Uflash:w:$1:e"