summaryrefslogtreecommitdiff
path: root/openpicc/at91flash_automatic
blob: 8f929891f131a4b91aab07509f1a6dcfd1ac0ae8 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
# (C) Milosch Meriac <meriac@bitmanufaktur.de> 2006
# (C) Henryk Plötz <henryk@ploetzli.ch> 2007

#UART='/dev/ttyUSB1'
FLASH_FILE=$1
USB_ID='03eb:6124'
USB_MODALIAS='usb:v03EBp6124d0110dc02dsc00dp00ic0Aisc00ip00'
SAM7='/usr/local/bin/sam7'
LSUSB='/usr/sbin/lsusb'

echo "Automatic SAM-BA flasher ..."
echo
echo "Each time you want to reflash do the following:"
echo "1. unplug the USB cable and insert the SAM-BA jumper (Pin 1+2)"
echo "2. attach the USB cable"
echo "3. wait ten seconds"
echo "4. unplug the USB cable"
echo "5. remove the SAM-BA jumper"
echo "6. attach the USB cable"
echo "7. wait several seconds to allow the device to be detected by Linux"
echo "8. the device will automatically be flashed, wait for the confirmation message"
echo "9. disconnect and reconnect USB to use the device"
echo
echo "Press Ctrl-C if you want to abort this program"
echo

do_flash() {
    $SAM7 -l $UART << ENDOFMYTEXT
set_clock
unlock_regions
flash $FLASH_FILE
ENDOFMYTEXT
}

blink_thinklight() {
    if [ ! -w /proc/acpi/ibm/light ]; then return; fi
    OLDSTATUS=`grep status < /proc/acpi/ibm/light | awk '{print $2;}'`
    if [ "${OLDSTATUS}" = "off" ]; then
	echo "on" > /proc/acpi/ibm/light
	sleep 1
	echo "off" > /proc/acpi/ibm/light
    else
	echo "off" > /proc/acpi/ibm/light
	sleep 1
	echo "on" > /proc/acpi/ibm/light
    fi
}

flashing_failed() {
    aplay /usr/kde/3.5/share/sounds/KDE_Error.wav > /dev/null 2>&1
}
flashing_successful() {
    blink_thinklight &
    aplay /usr/kde/3.5/share/sounds/KDE_Notify.wav > /dev/null 2>&1
}

do_detect() {
    ${LSUSB} -d ${USB_ID} > /dev/null
    return $?
}

find_uart() {
    DEV=`grep -l ${USB_MODALIAS} /sys/bus/usb-serial/devices/ttyUSB*/../modalias | head -n 1 | cut -d '/' --output-delimiter "
" -f - | egrep -i '^ttyUSB'`
    UART="/dev/${DEV}"
    return $?
}

attention() {
    echo '*********************************************************************************'
    echo -n `date -R`": "
}

while true; do
    if do_detect; then
	echo "Device detected, flashing ${FLASH_FILE}"
	if [ ! -r "${FLASH_FILE}" ]; then
	    attention
	    echo
	    echo "File to be flashed '${FLASH_FILE}' does not exist or is not readable"
	    echo "Please provide the file, then disconnect and reconnect the device"
	    echo "Or hit Ctrl-C to cancel flashing"
	else
	    if ! find_uart; then
		echo "Can't find UART, internal error, aborting"
		break
	    else
		echo "UART at $UART"
	    fi
	    if do_flash; then
		echo
		attention
		echo "Flashing successful"
		flashing_successful
		echo
	    else
		echo
		attention
		echo "Flashing failed"
		flashing_failed
		echo "Disconnect and reconnect the device to retry"
		echo "Or hit Ctrl-C to cancel flashing"
		echo
	    fi
	fi
	while do_detect; do sleep 1; done
    fi
    sleep 1
done
personal git repositories of Harald Welte. Your mileage may vary