forked from Rahix/avr-hal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
leonardo-runner.sh
executable file
·60 lines (51 loc) · 1.61 KB
/
leonardo-runner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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
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
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 "Please bring up the bootloader and press ENTER!\n"
read -r
printf "Attempting to flash ...\n"
printf "\n"
avrdude -qq -patmega32u4 -cavr109 -P"${SERIAL_PORT}" -b57600 -D "-Uflash:w:$1:e"