Merge branch 'adaptercomm'. bugzid: 654
[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
a2198e5e 29 echo "bl" | cec-client --bootloader
9c5f0a42
LOK
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
426652dd 47DISCONNECT THE HDMI CABLES BEFORE STARTING AND
9c5f0a42
LOK
48DO NOT POWER OFF OR DISCONNECT THE DEVICE WHILE THIS OPERATION IS IN PROGRESS!
49
50
51Are you sure you want to flash '$file' onto the CEC adapter?
52Type 'do it!' if you're sure. Anything else will cancel the operation.
53
54EOB
55 read confirmation
56 if [ ! "$confirmation" == "do it!" ]; then
57 echo "Exiting"
58 exit 0
59 fi
60
61 _prereq
62 if [ $? -eq 1 ]; then
63 exit 1
64 fi
65
66 _check_bootloader_device
67 if [ $? -eq 1 ]; then
68 exit 1
69 fi
70
71
72 echo "Erasing the previous firmware"
73 sudo dfu-programmer at90usb162 erase
74
75 echo "Flashing the new firmware"
76 sudo dfu-programmer at90usb162 flash "$file"
77
78 cat << EOB
79
80===============================================================================
81
82Done!
83
84Remove the USB cable from the device and reconnect it to use the new firmware.
85
86EOB
87 exit 0
88}
89
90_prereq()
91{
92 programmer=`which dfu-programmer`
93 if [ -z "$programmer" ]; then
94 echo "dfu-programmer was not found in your path, installing"
95 sudo apt-get install -y dfu-programmer
96 fi
97
98 programmer=`which dfu-programmer`
99 if [ -z "$programmer" ]; then
100 echo "ERROR: failed to find dfu-programmer"
101 return 1
102 fi
103 return 0
104}
105
106
107cat << EOB
108===============================================================================
109 Pulse-Eight CEC Adapter firmware flash tool
110===============================================================================
111
112EOB
113
114if [ -z "$1" ]; then
115 _usage
116else
117 _flash $1
118fi
119
120exit 0