forked from Rahix/avr-hal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkhex.sh
executable file
·36 lines (30 loc) · 889 Bytes
/
mkhex.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
#!/bin/sh
set -e
if [ $# -gt 2 -o $1 = "--help" ]; then
echo "usage: $0 [--release|--debug] <elf-name>" >&2
exit 1
fi
BUILD="debug"
if [ "$1" = "--debug" ]; then
shift 1
BUILD="debug"
elif [ "$1" = "--release" ]; then
shift 1
BUILD="release"
fi
TARGET="$(realpath --relative-to="$(pwd)" "$(dirname "$0")/target")"
HEX="$TARGET/$1.hex"
ELF="$(echo "$TARGET"/avr-*/"$BUILD/examples/$1.elf")"
if [ ! -e "$ELF" ]; then
echo "No $1.elf found. The following binaries exist:" >&2
for target_dir in "$TARGET"/avr-*; do
for bin in "$target_dir/$BUILD/examples"/*.elf; do
echo " - $(basename -s.elf "$bin")" >&2
done
done
exit 1
fi
avr-objcopy -S -j .text -j .data -O ihex "$ELF" "$HEX"
BYTES=$(avr-size "$ELF" | tail -1 | cut -f4 | bc)
echo "$ELF:" >&2
echo " $(numfmt --to=si "$BYTES") Bytes used ($BYTES exact)." >&2