-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash.sh
executable file
·94 lines (80 loc) · 2.62 KB
/
flash.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
FIRMWARE="FM-DX-Tuner.ino.bin"
BACKUP="backup-$(date +"%Y%m%d")-$(date +"%H%M%S").bin"
VERIFICATION="verify-$(date +"%Y%m%d")-$(date +"%H%M%S").bin"
USB_ID="0483:df11"
ADDRESS="0x08000000"
FLASH_SIZE="131072"
if ! command -v ./tef-bootloader &> /dev/null
then
echo "ERROR: tef-bootloader not found"
exit 1
fi
if ! command -v dfu-util &> /dev/null
then
echo "ERROR: dfu-util not found"
exit 1
fi
if [ $# -eq 0 ]
then
echo "Usage: $0 port"
echo "Example: $0 /dev/ttyACM0"
exit 1
fi
echo '--------------------------------------------------------------------------'
echo "Switching tuner into the bootloader mode..."
echo '--------------------------------------------------------------------------'
./tef-bootloader $1
if [ $? -ne 0 ]
then
echo "ERROR: Failed to enter bootloader mode. Trying anyway."
fi
echo '--------------------------------------------------------------------------'
echo "Creating backup of current firmware..."
echo '--------------------------------------------------------------------------'
dfu-util -w -d "$USB_ID" -a 0 -s "$ADDRESS:$FLASH_SIZE" -U "$BACKUP"
if [ $? -ne 0 ]
then
echo "ERROR: Failed to create backup. Giving up."
exit 1
fi
echo '--------------------------------------------------------------------------'
echo "Flashing new firmware..."
echo '--------------------------------------------------------------------------'
dfu-util -d "$USB_ID" -a 0 -s "$ADDRESS" -D "$FIRMWARE"
if [ $? -ne 0 ]
then
echo "ERROR: Failed to update the firmware."
exit 1
fi
echo '--------------------------------------------------------------------------'
echo "Verifying new firmware..."
echo '--------------------------------------------------------------------------'
FW_SIZE=`wc -c < "$FIRMWARE"`
dfu-util -d "$USB_ID" -a 0 -s "$ADDRESS:$FW_SIZE" -U "$VERIFICATION"
if [ $? -ne 0 ]
then
echo "ERROR: Failed to retrieve the new firmware."
exit 1
fi
diff "$FIRMWARE" "$VERIFICATION" &> /dev/null
if [ $? -ne 0 ]
then
echo "ERROR: Verification FAILED, try to flash again."
exit 1
fi
rm -f "$VERIFICATION"
echo "Update finished sucessfully."
echo '--------------------------------------------------------------------------'
echo "Starting new firmware..."
echo '--------------------------------------------------------------------------'
dfu-util -d "$USB_ID" -a 0 -s "$ADDRESS":leave
if [ $? -ne 0 ]
then
echo "ERROR: Failed to start new firmware."
exit 1
fi
echo '--------------------------------------------------------------------------'
echo "Firmware started sucessfully"
echo '--------------------------------------------------------------------------'
exit 0