Changeset 6116b9d0 in freewrt
- Timestamp:
- Jun 14, 2007, 1:43:54 PM (18 years ago)
- Children:
- 15ddbfc
- Parents:
- d1eeabf
- File:
-
- 1 edited
-
scripts/flash.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
scripts/flash.sh
rd1eeabf r6116b9d0 1 1 # $Id$ 2 # 3 # tftp flash script for wireless routers 4 # 5 # Copyright (c) 2006, 2007 by Thorsten Glaser <tg@mirbsd.de> 6 # Copyright (C) 2006 by Waldemar Brodkorb <wbx@freewrt.org> 7 # Copyright (C) 2004 by Oleg I. Vdovikin <oleg@cs.msu.su> 8 # 9 # This program is free software; you can redistribute it and/or modify 10 # it under the terms of the GNU General Public License as published by 11 # the Free Software Foundation; either version 2 of the License, or 12 # (at your option) any later version. 13 # 14 # This program is distributed in the hope that it will be useful, 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 # General Public License for more details. 18 # 19 # You should have received a copy of the GNU General Public License 20 # along with this program; if not, write to the Free Software 21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 2 #- 3 # This file is part of the FreeWRT project. FreeWRT is copyrighted 4 # material, please see the LICENCE file in the top-level directory 5 # or at http://www.freewrt.org/licence for details. 22 6 23 usage() { 24 cat <<EOF 25 Usage: $0 firmware.bin [address] 7 if test -z "$KSH_VERSION$BASH_VERSION"; then 8 echo >&2 Sorry, at the moment, a Korn shell or GNU bash is required. 9 exit 255 10 fi 26 11 27 The following models are supported: 28 asus-wl500g - Asus WL500g 29 asus-wl500g-deluxe - Asus WL500g Deluxe 30 asus-wl500g-premium - Asus WL500g Premium 31 linksys - All Linksys models 12 [[ -n $BASH_VERSION ]] && shopt -s extglob 13 [[ -n $KSH_VERSION ]] && alias which='whence -p' 32 14 33 IMPORTANT: 34 Notes for Linksys routers: 35 be sure you have set boot_wait to yes. Power on your router 36 after executing this script. 15 me=${0##*/} 37 16 38 Notes for Asus routers: 39 be sure POWER led is flashing (if this is not the case, 40 power off the device, then hold the reset button pushed 41 while powering it on again). 42 43 1) connect your PC to the LAN port 44 2) be sure your link is up and has an address in the 45 range 192.168.1.0/24 but other than 192.168.1.1, 46 or specify an IP address where to flash to 47 48 EOF 17 die() { 18 printf >&2 '%s: %s\n' "$me" "$*" 49 19 exit 1 50 20 } 51 21 52 # find an available tftp client 53 tftp= 54 for t in tftp atftp; do 55 if which $t >/dev/null 2>&1; then 56 tftp=$t 57 break 22 usage() { 23 cat >&2 <<-EOF 24 Syntax: $me [-c tftp] [-F | -f fwcf.bin] [-t type] file [ip] 25 Valid types are: 26 wl500g wl500gd wl500gp wl500gx linksys 27 Meta-types (no support for -f or -F): 28 wl500gx = wl500gd or wl500gp 29 linksys = all linksys models 30 EOF 31 exit 1 32 } 33 34 imgtype=auto 35 flashtype=auto 36 integer dopad=0 37 integer padsize=0 38 padfile= 39 tftp=tftp 40 41 while getopts ":c:Ff:t:" ch; do 42 case $ch in 43 (c) tftp=$OPTARG 44 [[ -x $tftp ]] || tftp=$(which $tftp 2>&-) 45 [[ -x $tftp ]] || die "TFTP client '$OPTARG' not found" 46 ;; 47 (F) dopad=1 48 padfile= 49 ;; 50 (f) dopad=1 51 padfile=$OPTARG 52 [[ -s $padfile ]] || die "Invalid pad file '$padfile'" 53 ;; 54 (t) flashtype=$OPTARG 55 ;; 56 (:) echo >&2 "$me: Error: missing argument to -$OPTARG" 57 usage 58 ;; 59 (*) echo >&2 "$me: Error: invalid option -$OPTARG" 60 usage 61 ;; 62 esac 63 done 64 shift $((OPTIND - 1)) 65 66 [[ $# -lt 1 || $# -gt 2 ]] && usage 67 imgfile=$1 68 ip=${2:-192.168.1.1} 69 70 [[ $imgfile = *@( )* ]] && die Spaces in filenames are not supported 71 [[ $ip = +([0-9]).+([0-9]).+([0-9]).+([0-9]) ]] || \ 72 die "Invalid IPv4 address '$ip'" 73 74 [[ $imgtype = auto ]] && case ${imgfile%.[bt][ir][nx]} in 75 *-asus-wl500g-premium-*) 76 imgtype=wl500gp ;; 77 *-asus-wl500g-deluxe-*) 78 imgtype=wl500gd ;; 79 *-asus-wl500g-*) 80 imgtype=wl500g ;; 81 *-linksys-*) 82 imgtype=linksys ;; 83 *) 84 die "Cannot determine model from filename '$imgfile', use -t option" ;; 85 esac 86 87 case $imgtype in 88 wl500g) 89 flashtype=wl500g ;; 90 wl500gd|wl500gp|wl500gx) 91 flashtype=wl500gx ;; 92 linksys) 93 flashtype=linksys ;; 94 *) 95 die "Unknown model '$imgtype'" ;; 96 esac 97 98 if (( dopad )); then 99 case $imgtype in 100 wl500gp) 101 padsize=7929856 ;; 102 *) 103 die "Cannot use -F or -f with a $imgtype yet" ;; 104 esac 105 TF=$(mktemp /tmp/fwflash.XXXXXXXXXX) || die Cannot mktemp 106 TI=$(mktemp /tmp/fwflash.XXXXXXXXXX) || { rm $TF; die Cannot mktemp; } 107 trap 'rm -f $TF $TI; exit 0' 0 108 trap 'rm -f $TF $TI; exit 1' 1 2 3 5 13 15 109 randsrc=/dev/arandom 110 [[ -e $randsrc ]] || randsrc=/dev/urandom 111 [[ -e $randsrc ]] || randsrc=/dev/random 112 [[ -e $randsrc ]] || die Cannot find an entropy source 113 dd if=$randsrc of=$TF bs=131072 count=1 2>&- 114 if [[ -n $padfile ]]; then 115 dd if="$padfile" of=$TF conv=notrunc 2>&- 116 echo "TRX file constructed from root='$imgfile' and fwcf='$padfile'" 117 else 118 printf 'FWCF\x18\x00\x00\x01\x01\x00\x00\x10\x12\x00\x11\x00\x00\x00\x00\x00\x74\x01\x7C\x18' | \ 119 dd of=$TF conv=notrunc 2>&- 120 echo "TRX file constructed from '$imgfile' and empty fwcf filesystem" 58 121 fi 59 done 60 if [ -z "$tftp" ]; then 61 echo "no tftp client found! make sure, tftp is in your path" 62 tftp=tftp 122 dd if=/dev/zero of=$TI bs=$padsize count=1 2>&- 123 dd if="$imgfile" of=$TI conv=notrunc 2>&- 124 cat $TF >>$TI 125 imgfile=$TI 126 else 127 echo "Using TRX file from '$imgfile'" 63 128 fi 64 129 65 file=${1-/nonexistant} 66 ip=${2-192.168.1.1} 130 echo ATTENTION: Do not turn off the power on your device $ip now! 131 sleep 3 67 132 68 test -s "$file" || usage 69 70 cd "$(dirname "$file")" 71 file=$(basename "$file") 72 73 case $file in 74 *\ *) 75 echo Spaces in filenames are not supported. 76 exit 1 133 case $flashtype in 134 wl500g) 135 echo Confirming IP address setting... 136 printf 'get ASUSSPACELINK\x01\x01\xA8\xC0 /dev/null\nquit\n' | $tftp $ip 137 echo Flashing image... 138 printf 'binary\nput %s ASUSSPACELINK\nquit\n' "$imgfile" | $tftp $ip 139 echo Please wait until the LEDs stop flashing. 140 echo This device will reboot itself automatically. 77 141 ;; 78 *-asus-wl500g-deluxe-*.bin | *-asus-wl500g-premium-*.bin | \ 79 *-asus-wl500g-deluxe-*.trx | *-asus-wl500g-premium-*.trx ) 80 echo Flashing $ip using "$file"... 81 printf "rexmt 1\ntrace\nbinary\nput $file\nquit\n" | $tftp $ip 82 echo Please wait 3 minutes and then remove the power. 142 wl500gx) 143 echo Flashing image... 144 printf 'rexmt 1\ntrace\nbinary\nput %s\nquit\n' "$imgfile" | $tftp $ip 145 echo Please wait 3-5 minutes and then remove the power plug. 83 146 echo This device does not reboot automatically after flashing. 84 147 ;; 85 *-asus-wl500g-*.bin | *-asus-wl500g-*.trx) 86 echo Confirming IP address setting... 87 printf "get ASUSSPACELINK\x01\x01\xa8\xc0 /dev/null\nquit\n" | $tftp $ip 88 echo Flashing $ip using "$file"... 89 printf "binary\nput $file ASUSSPACELINK\nquit\n" | $tftp $ip 90 echo Please wait until leds stops flashing. Device will automatically reboot. 91 ;; 92 *-linksys-*.bin) 93 echo Flashing $ip using "$file"... 94 printf "rexmt 1\ntrace\nbinary\nput $file\nquit\n" | $tftp $ip 95 echo Unit will automatically reboot within 3-5 minutes. Do not power off. 96 ;; 97 *) 98 echo Unsupported model "'$file'" 99 usage 148 linksys) 149 echo Flashing image... 150 printf 'rexmt 1\ntrace\nbinary\nput %s\nquit\n' "$imgfile" | $tftp $ip 151 echo Please wait 3-5 minutes. 152 echo This device will reboot itself automatically. 100 153 ;; 101 154 esac 102 echo After that you can login via: ssh admin@$ip 103 echo Default password, unless changed in menuconfig, is: FreeWRT 155 cat <<-EOF 156 After flashing is finished and the device has rebooted, it will need 157 to restart once if the filesystem type is squashfs with jffs2 overlay. 158 The power LED will flash quickly as long as startup is in progress. 159 160 Once it has finished flashing, you should be able to access the device 161 via ssh to the "admin" user, for example: ssh -l admin $ip 162 163 If you didn't change the password in menuconfig, it's "FreeWRT" (case 164 sensitive and without the quotation marks). Give the device a while to 165 generate the SSH keys for dropbear first. 166 167 After device initialisation and key generation has finished, it is 168 highly recommended to log in and isse the command "fwcf commit" so that 169 the SSH host keys will be stored in the configuration filesystem and 170 do not have to be regenerated each time the device starts. 171 172 EOF 173 exit 0
Note:
See TracChangeset
for help on using the changeset viewer.
