forked from bear-lab-3d/Prusa-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_eeprom
executable file
·54 lines (45 loc) · 1.07 KB
/
update_eeprom
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
#!/bin/sh
prg=$(basename "$0")
# parse arguments
while getopts f:h optname
do
case $optname in
f) port="$OPTARG" ;;
*) help=1 ;;
esac
done
shift `expr $OPTIND - 1`
old="$1"
new="$2"
if [ -z "$old" -o "$help" = "-h" -o "$#" -gt 2 ]
then
echo "usage: $0 [-f <port>] <old dump> [<new dump>]" >&2
echo "Convert <old dump> to instructions to update instructions." >&2
echo "With <new dump>, generate instructions to update EEPROM changes only." >&2
echo "Optionally write such changes directly if <port> if given." >&2
exit 1
fi
set -e
instr=$(mktemp)
trap "rm -f \"$instr\"" EXIT
convert()
{
sed -ne 's/^\([0-9a-f]\{4\}\) \([0-9a-f ]*\)$/D3 Ax\1 C16 X\2/p' "$@"
}
if [ -z "$new" ]; then
# convert the instructions to updates
convert "$old" > "$instr"
else
tmp1=$(mktemp)
tmp2=$(mktemp)
trap "rm -f \"$tmp1\" \"$tmp2\"" EXIT
convert "$old" > "$tmp1"
convert "$new" > "$tmp2"
comm -13 "$tmp1" "$tmp2" > "$instr"
fi
# write the instructions if requested
if [ -z "$port" ]; then
cat "$instr"
else
printcore -v "$port" "$instr"
fi