|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +WIFI_FW_PATH="/hardware/arduino/firmwares/wifi-shield" |
| 4 | +AVR_TOOLS_PATH="/hardware/tools/avr/bin" |
| 5 | + |
| 6 | +progname=$0 |
| 7 | + |
| 8 | +usage () { |
| 9 | +cat <<EOF |
| 10 | +Usage: $progname [-a Arduino_path] [-f which_firmware] [-h] |
| 11 | + -a set the path where the Arduino IDE is installed |
| 12 | + -f the firmware you want to upload, valid parameters are: |
| 13 | + shield - to upgrade the WiFi shield firmware |
| 14 | + all - to upgrade both firmwares |
| 15 | + -h help |
| 16 | +EOF |
| 17 | + exit 0 |
| 18 | +} |
| 19 | + |
| 20 | +upgradeHDmodule () { |
| 21 | + sleep 1 # Give time to the shield to end the boot |
| 22 | + echo "****Upgrade HD WiFi module firmware****\n" |
| 23 | + dfu-programmer at32uc3a1256 erase |
| 24 | + dfu-programmer at32uc3a1256 flash --suppress-bootloader-mem $WIFI_FW_PATH/wifi_dnld.hex |
| 25 | + dfu-programmer at32uc3a1256 start |
| 26 | + echo -n "\nRemove the J3 jumper then press the RESET button on the shield then type [ENTER] to upgrade the firmware of the shield..\n" |
| 27 | + read readEnter |
| 28 | +} |
| 29 | + |
| 30 | +upgradeShield () { |
| 31 | + sleep 1 # Give time to the shield to end the boot |
| 32 | + echo "****Upgrade WiFi Shield firmware****\n" |
| 33 | + dfu-programmer at32uc3a1256 erase |
| 34 | + dfu-programmer at32uc3a1256 flash --suppress-bootloader-mem $WIFI_FW_PATH/wifiHD.hex |
| 35 | + dfu-programmer at32uc3a1256 start |
| 36 | + echo "\nDone. Remove the J3 jumper and press the RESET button on the shield." |
| 37 | + echo "Thank you!\n" |
| 38 | +} |
| 39 | + |
| 40 | +cat <<EOF |
| 41 | +
|
| 42 | + Arduino WiFi Shield upgrade |
| 43 | +========================================= |
| 44 | +Disclaimer: to access to the USB devices correctly, the dfu-programmer needs to be used as root. Run this script as root. |
| 45 | +
|
| 46 | +EOF |
| 47 | + |
| 48 | +if [ $USER = 'root' ] ; then #check if the current user is root |
| 49 | + while getopts ":a:f:h" opt; do |
| 50 | + case $opt in |
| 51 | + a) |
| 52 | + ARDUINO_PATH=$OPTARG |
| 53 | + WIFI_FW_PATH=$ARDUINO_PATH$WIFI_FW_PATH |
| 54 | + AVR_TOOLS_PATH=$ARDUINO_PATH$AVR_TOOLS_PATH |
| 55 | + cd $AVR_TOOLS_PATH |
| 56 | + ./avr-objcopy --output-target=ihex $WIFI_FW_PATH/wifi_dnld.elf $WIFI_FW_PATH/wifi_dnld.hex |
| 57 | + ./avr-objcopy --output-target=ihex $WIFI_FW_PATH/wifiHD.elf $WIFI_FW_PATH/wifiHD.hex |
| 58 | + ;; |
| 59 | + f) |
| 60 | + if [ "$ARDUINO_PATH" != "" ] ; then |
| 61 | + if [ "$OPTARG" = "all" ] ; then |
| 62 | + upgradeHDmodule |
| 63 | + upgradeShield |
| 64 | + exit 0 |
| 65 | + else |
| 66 | + if [ "$OPTARG" = "shield" ] ; then |
| 67 | + upgradeShield |
| 68 | + exit 0 |
| 69 | + else |
| 70 | + echo "invalid parameter for the -f [firmware] option, please retry." |
| 71 | + echo "Type -h for help\n" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + fi |
| 75 | + else |
| 76 | + echo "Arduino Path not setted. Retry...\n" |
| 77 | + fi |
| 78 | + ;; |
| 79 | + h) |
| 80 | + usage ;; |
| 81 | + \?) |
| 82 | + echo "Invalid option: $OPTARG" >&2 |
| 83 | + usage |
| 84 | + exit 1 |
| 85 | + ;; |
| 86 | + :) |
| 87 | + echo "Option -$OPTARG requires an argument." >&2 |
| 88 | + exit 1 |
| 89 | + ;; |
| 90 | + esac |
| 91 | + done |
| 92 | +else |
| 93 | + echo "You are not root!\n" |
| 94 | +fi |
| 95 | + |
| 96 | +shift $(($OPTIND - 1)) |
0 commit comments