cec: added a firmware flash script for linux. usage: ./support/cec-flash-device.sh...
[deb_libcec.git] / support / cec-flash-device.sh
CommitLineData
9c5f0a42
LOK
1#!/bin/bash
2
3_usage()
4{
5 echo "Usage: $0 /path/to/firmware.hex"
6}
7
8_check_bootloader_device()
9{
10 cec_adapter=`lsusb | grep "03eb:2ffa" | wc -l`
11 if [ $cec_adapter -eq 0 ]; then
12 _enter_bootloader
13 cec_adapter=`lsusb | grep "03eb:2ffa" | wc -l`
14 fi
15
16 if [ $cec_adapter -eq 0 ]; then
17 echo "ERROR: failed to find any CEC adapter in bootloader mode"
18 return 1
19 fi
20
21 return 0
22}
23
24_enter_bootloader()
25{
26 echo "Instructing the CEC adapter to enter bootloader mode"
27 cec_adapter=`lsusb | grep "2548:1001" | wc -l`
28 if [ $cec_adapter -gt 0 ]; then
29 echo "bl" | cec-client -s -d 2
30 echo "Waiting for the device to reinitialise"
31 sleep 5
32 fi
33}
34
35_flash()
36{
37 file=$1
38
39 if [ ! -f "$file" ]; then
40 echo "ERROR: firmware file '$file' does not exist"
41 exit 1
42 fi
43
44 cat << EOB
45Flash '$file' onto the CEC adapter
46
47DO NOT POWER OFF OR DISCONNECT THE DEVICE WHILE THIS OPERATION IS IN PROGRESS!
48
49
50Are you sure you want to flash '$file' onto the CEC adapter?
51Type 'do it!' if you're sure. Anything else will cancel the operation.
52
53EOB
54 read confirmation
55 if [ ! "$confirmation" == "do it!" ]; then
56 echo "Exiting"
57 exit 0
58 fi
59
60 _prereq
61 if [ $? -eq 1 ]; then
62 exit 1
63 fi
64
65 _check_bootloader_device
66 if [ $? -eq 1 ]; then
67 exit 1
68 fi
69
70
71 echo "Erasing the previous firmware"
72 sudo dfu-programmer at90usb162 erase
73
74 echo "Flashing the new firmware"
75 sudo dfu-programmer at90usb162 flash "$file"
76
77 cat << EOB
78
79===============================================================================
80
81Done!
82
83Remove the USB cable from the device and reconnect it to use the new firmware.
84
85EOB
86 exit 0
87}
88
89_prereq()
90{
91 programmer=`which dfu-programmer`
92 if [ -z "$programmer" ]; then
93 echo "dfu-programmer was not found in your path, installing"
94 sudo apt-get install -y dfu-programmer
95 fi
96
97 programmer=`which dfu-programmer`
98 if [ -z "$programmer" ]; then
99 echo "ERROR: failed to find dfu-programmer"
100 return 1
101 fi
102 return 0
103}
104
105
106cat << EOB
107===============================================================================
108 Pulse-Eight CEC Adapter firmware flash tool
109===============================================================================
110
111EOB
112
113if [ -z "$1" ]; then
114 _usage
115else
116 _flash $1
117fi
118
119exit 0