1
|
#!/bin/bash
|
2
|
# (C) Milosch Meriac <meriac@bitmanufaktur.de> 2006
|
3
|
# (C) Henryk Plötz <henryk@ploetzli.ch> 2007
|
4
|
|
5
|
#UART='/dev/ttyUSB1'
|
6
|
FLASH_FILE=$1
|
7
|
USB_ID='03eb:6124'
|
8
|
USB_MODALIAS='usb:v03EBp6124d0110dc02dsc00dp00ic0Aisc00ip00'
|
9
|
SAM7='/usr/local/bin/sam7'
|
10
|
LSUSB='/usr/sbin/lsusb'
|
11
|
|
12
|
echo "Automatic SAM-BA flasher ..."
|
13
|
echo
|
14
|
echo "Each time you want to reflash do the following:"
|
15
|
echo "1. unplug the USB cable and insert the SAM-BA jumper (Pin 1+2)"
|
16
|
echo "2. attach the USB cable"
|
17
|
echo "3. wait ten seconds"
|
18
|
echo "4. unplug the USB cable"
|
19
|
echo "5. remove the SAM-BA jumper"
|
20
|
echo "6. attach the USB cable"
|
21
|
echo "7. wait several seconds to allow the device to be detected by Linux"
|
22
|
echo "8. the device will automatically be flashed, wait for the confirmation message"
|
23
|
echo "9. disconnect and reconnect USB to use the device"
|
24
|
echo
|
25
|
echo "Press Ctrl-C if you want to abort this program"
|
26
|
echo
|
27
|
|
28
|
do_flash() {
|
29
|
$SAM7 -l $UART << ENDOFMYTEXT
|
30
|
set_clock
|
31
|
unlock_regions
|
32
|
flash $FLASH_FILE
|
33
|
ENDOFMYTEXT
|
34
|
}
|
35
|
|
36
|
blink_thinklight() {
|
37
|
if [ ! -w /proc/acpi/ibm/light ]; then return; fi
|
38
|
OLDSTATUS=`grep status < /proc/acpi/ibm/light | awk '{print $2;}'`
|
39
|
if [ "${OLDSTATUS}" = "off" ]; then
|
40
|
echo "on" > /proc/acpi/ibm/light
|
41
|
sleep 1
|
42
|
echo "off" > /proc/acpi/ibm/light
|
43
|
else
|
44
|
echo "off" > /proc/acpi/ibm/light
|
45
|
sleep 1
|
46
|
echo "on" > /proc/acpi/ibm/light
|
47
|
fi
|
48
|
}
|
49
|
|
50
|
flashing_failed() {
|
51
|
aplay /usr/kde/3.5/share/sounds/KDE_Error.wav > /dev/null 2>&1
|
52
|
}
|
53
|
flashing_successful() {
|
54
|
blink_thinklight &
|
55
|
aplay /usr/kde/3.5/share/sounds/KDE_Notify.wav > /dev/null 2>&1
|
56
|
}
|
57
|
|
58
|
do_detect() {
|
59
|
${LSUSB} -d ${USB_ID} > /dev/null
|
60
|
return $?
|
61
|
}
|
62
|
|
63
|
find_uart() {
|
64
|
DEV=`grep -l ${USB_MODALIAS} /sys/bus/usb-serial/devices/ttyUSB*/../modalias | head -n 1 | cut -d '/' --output-delimiter "
|
65
|
" -f - | egrep -i '^ttyUSB'`
|
66
|
UART="/dev/${DEV}"
|
67
|
return $?
|
68
|
}
|
69
|
|
70
|
attention() {
|
71
|
echo '*********************************************************************************'
|
72
|
echo -n `date -R`": "
|
73
|
}
|
74
|
|
75
|
while true; do
|
76
|
if do_detect; then
|
77
|
echo "Device detected, flashing ${FLASH_FILE}"
|
78
|
if [ ! -r "${FLASH_FILE}" ]; then
|
79
|
attention
|
80
|
echo
|
81
|
echo "File to be flashed '${FLASH_FILE}' does not exist or is not readable"
|
82
|
echo "Please provide the file, then disconnect and reconnect the device"
|
83
|
echo "Or hit Ctrl-C to cancel flashing"
|
84
|
else
|
85
|
if ! find_uart; then
|
86
|
echo "Can't find UART, internal error, aborting"
|
87
|
break
|
88
|
else
|
89
|
echo "UART at $UART"
|
90
|
fi
|
91
|
sleep 1
|
92
|
if do_flash; then
|
93
|
echo
|
94
|
attention
|
95
|
echo "Flashing successful"
|
96
|
flashing_successful
|
97
|
echo
|
98
|
else
|
99
|
echo
|
100
|
attention
|
101
|
echo "Flashing failed"
|
102
|
flashing_failed
|
103
|
echo "Disconnect and reconnect the device to retry"
|
104
|
echo "Or hit Ctrl-C to cancel flashing"
|
105
|
echo
|
106
|
fi
|
107
|
fi
|
108
|
while do_detect; do sleep 1; done
|
109
|
fi
|
110
|
sleep 1
|
111
|
done
|