From 735f640c80948e7cd4d0aa7533d0898fe4b0f0b4 Mon Sep 17 00:00:00 2001 From: henryk Date: Sun, 11 Nov 2007 04:30:07 +0000 Subject: Enhanced flash script with automatic UART detection and automatic flashing on connection Can be left running for longer times and will flash automatically when connecting device in SAM-BA mode git-svn-id: https://svn.openpcd.org:2342/trunk@319 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- openpicc/at91flash_automatic | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 openpicc/at91flash_automatic (limited to 'openpicc/at91flash_automatic') diff --git a/openpicc/at91flash_automatic b/openpicc/at91flash_automatic new file mode 100755 index 0000000..40c23a9 --- /dev/null +++ b/openpicc/at91flash_automatic @@ -0,0 +1,95 @@ +#!/bin/bash +# (C) Milosch Meriac 2006 +# (C) Henryk Plötz 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 +} + +flashing_failed() { + : +} +flashing_successful() { + : +} + +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 -- cgit v1.2.3