NSLU2-Linux
view · edit · print · history

Purpose

The purpose of this page is to help you get access to the RedBoot bootloader.

The main reason for accessing the RedBoot bootloader is when you are attempting to Recover From A Bad Flash. It is also useful for Resetting the SysConf area if you have screwed up your non-volatile config settings.

Although the unslung 6.8 readme states that "You *must* test telnet Redboot access first before you flash the Unslung firmware," recovery from a bad flash can now also be done by the easier method of using the reset button to enter upgrade mode.

NAS200: RedBoot is also used on the NAS200, but there it uses 192.168.21.249 instead of 192.168.0.1. The RedBoot on the NAS200 doesn't have the "fconfig" or "fis" commands, but it does have a "flash" command. Don't use the flash command, it will overwrite your RedBoot without warning and brick your NAS200.

About RedBoot

RedBoot is a bootloader. The bootloader's job is to load things into the computer's memory and start up the OS, in this case Linux or the original NSLU2 firmware (which is Linux based, as well).

RedBoot is quite sophisticated, and has a user interface that you can access by telnet or serial. You can use it to load things into memory by TFTP, write to flash, and similar tasks. You should also be cautious when accessing RedBoot, as you can muck up the basic behaviour of the slug if you're not careful.

For more information about RedBoot in general, consult Red Hat's website or use Google.

How does RedBoot access work on the NSLU2?

When the slug starts up, for a few seconds RedBoot will listen for telnet connections on port 9000. RedBoot will insist on being 192.168.0.1 for this window, regardless of what you've set the address of the normal Linux portion of your slug to be. If it doesn't receive a telnet connection during that window, it will attempt to load the Linux kernel into main memory from flash and execute it.

What to do with RedBoot once you get access

The RedBoot prompt is RedBoot> . Try the following commands:

  • version prints out RedBoot's version information, and a memory map.
  • reset causes RedBoot to reset the NSLU2, in a similar way to the power-on sequence. This is a clean way out of RedBoot if you don't want to change anything. After doing this, the telnet session with RedBoot will go silent, and you'll need to interrupt and close it.
  • help prints out a list of RedBoot commands.

After you reset RedBoot, or otherwise end your session, you need to end the telnet connection. To do this, type ^] (control-right bracket). A prompt Telnet> appears. Type close. You return to your command prompt.

Preparation for RedBoot access

Before attempting to access RedBoot, there are some problem that you may need to sort out first.

  1. Ethernet Cable Linkage

    Since 192.168.0.1 could conflict with other equipment on many people's LANs, it is often easier to access RedBoot if it is set up either on its own dedicated network or directly to your computer with a crossover cable.

    However, if you have a fancy network card with auto-MDI/MDIX (i.e. you don't need to worry about whether to use a straight through or a crossover cable, as with all new Macs for instance) you may end up missing the brief telnet window as your computer's Ethernet card tries to work out what sex it should be.

    An easy way to get around this is by connecting via a cheap hub which doesn't have such hangups. Be aware that an Ethernet switch with spanning tree enabled will cause you to miss the window of opportunity too. The port will not enter forwarding state fast enough. Some vendors have features to override this (Eg. Cisco has PortFast).

    You could also try to set your Ethernet card to disable auto-MDI/MDIX, but this may be hard to do and may complicate your life in the future if you forget to turn it back on.
  2. IP Address Setup

    Your computer might not also be setup to talk on the 192.168.0.x network.

    If your computer is not on the 192.168.0.x subnet, you can either change its address temporarily or add a new route.

    1. Linux
      su to root and execute the command route add 192.168.0.1 eth0

      Alternately, set up an alias interface, like so:
      ifconfig eth0:1 inet 192.168.0.2 broadcast 192.168.0.255 netmask 255.255.255.0
      Adding an alias will also automatically add a subnet route.
    2. OS X
    • Determine the MAC address of your slug. arp -a
      • For example: ? (192.168.1.1) at 00:a0:c5:45:0b:17 on en0 [ethernet]
    • Setup en0 (or another port) to work with the slug
      1. Go to System Preferences >> Network
      2. Optionally, create a new Location to hold these RedBoot-specific network settings. This lets you switch quickly from normal to RedBoot-specific network settings by selecting different Location names.
      3. Select Built-in Ethernet (or your Network Adapter Choice)
      4. On the Configure IPv4 drop-down, select Manual
      5. Set the IP Address to 192.168.0.2 (the final digit may be any number from 2 to 254 inclusive)
      6. Set the Subnet Mask to 255.255.255.0
    • Setup an route
      1. Open Terminal and type: sudo arp -s 192.168.0.1 00:a0:c5:45:0b:17 where 00:a0:c5:45:0b:17 is the MAC address of your slug.
      • This may not be necessary, depending on what you are trying. On one Powerbook G4 running OS 10.3.9, the ping command could find the NSLU2 without it, but the TCL script (below) required the arp setting. The IP address had to be set to 192.168.0.x in both cases.
    • Continue following this guide.
      • On a Powerbook G4 running OS 10.3.9, the following command worked for me: bash -c 'while ! ping -r -c 1 192.168.0.1 2>&1 >/dev/null ; do true ; done && telnet 192.168.0.1 9000' (The alert student notes that this runs a script under the bash shell which the Mac OS's default tcsh shell can't directly handle.)
      • Some advise that the easiest way is to use the TCL script, though this didn't work on one Powerbook G4 running OS 10.3.9.
      • Some advise the ping, perl, and C scripts do not seem to work on OS X.
      • NOTE: Using a newer Mac (confirmed: MacBook Pro), you don't even need a crossover cable. The Auto-MDI/MDIX is fast enough that you can use a straight-through cable directly from the Mac to the Slug.
    • A good GUI for TFTP is TFTP Server: http://ww2.unime.it/flr/tftpserver/
    1. Windows XP SP2 (Common to other versions)
      Your computer must have a fixed IP address.
      Goto Network Connections on the Control Panel.
      Choose your Network card that it's connected to the NSLU2 via a crossover cable or via network switch (I have this and it worked)
      Select Properties
      Select TCP/IP Protocol on the List and again the button properties. Again make sure that you have a FIXED IP.
      Select Advanced
      Add a SECONDARY IP by selecting the ADD button on below the box that shows the current fixed IP.
      Input 192.168.0.2
      Exit all windows with Apply and Ok.
      Open an MS-DOS windows.
      Try to ping the new IP 192.168.0.2. It should work.
      Proceed to the next steps.
      • I was unsuccessful with the above WinXP approach - my machine is dual-ethernet NIC'd with DHCP normally used for both connections to a router. With a crossover (patch) cable connected from one NIC to the slug (while OFF) I was able to determine which NIC was reported by Control Panel => Network Connections as "Network cable unplugged". Then changed the settings for this NIC (click right on the connection entry and select "Properties" (new dialog opens), then select TCP/IP and click on "Properties" in new dialog) to:

        Select radio button for "Use the following IP address:" and set the following values:
        IP Address: 192.168.0.100
        Subnet: 255.255.255.0
        Default gateway: 192.168.0.1

        Note that at command prompt a 'ping 192.168.0.100' or 'ping 192.168.0.1' w/the slug OFF will NOT get a reply, but when you move to the next step (I used the 'An automatic Windows method' {using WSH} below) it will succeed. Don't forget to change the network connection back to using DHCP when you're done if you need to...

        DonV
    2. FreeBSD
      To add an alias, try ifconfig XX0 alias 192.168.0.2 192.168.0.255, where XX0 is the interface to add the alias to.
  3. Hosts setup (to prevent Telnet RDNS timeout)

    If it takes a long time (~30 seconds) for telnet to display the Trying 192.168.0.1... message, it may be that telnet is trying to do a Reverse DNS lookup, and timing out (this happened on my fresh install of Fedora Core 4). To get into RedBoot, telnet needs to execute immediately, so try adding 192.168.0.1 to your /etc/hosts (or c:\WINDOWS\system32\drivers\etc\hosts) file. For example, call it 'slug' and then use telnet slug 9000 instead of the IP address.


Changing your subnet may be an easy option if you already use a router which doles out IP addresses to your PC (via DHCP). Many home routers default to IP addresses of the form 192.168.1.xxx or 192.168.2.xxx, subnet mask of 255.255.255.0 If this is you, telling the router (via its web or telnet interface) to use a subnet mask of 255.255.252.0 may be all that's required, since this mask includes all addresses from 192.168.0.1 through 192.168.3.254.

Trying To Access RedBoot

The main trick with accessing RedBoot is the shortness of the telnet window. Since the telnet port is only alive for 2 seconds, it can be a bit of a challenge to do everything required within that time frame. You must:

  1. Recognise when the telnet session is available
  2. Start your telnet client talking to 192.168.0.1 9000
  3. Once telnet connects, press Ctrl-C to tell RedBoot you want access (try telnet in vt100 mode, if you receive strange characters instead of a readable prompt)

We will first describe basic manual methods of accessing RedBoot and then delve into more automated methods.

Accessing RedBoot from *nix

Manual Methods

  • sudo arping -f 192.168.0.1; telnet 192.168.0.1 9000
    • The telnet starts trying as soon as the IP address on the slug will respond, and all you have to do is remember to press Ctrl+C. :)
    • NOTE: If your arping doesn't understand -f, you probably have the standalone "arping" package. Install the version from iputils instead. (For Debian: apt-get install iputils-arping)
  • ping -f 192.168.0.1; telnet 192.168.0.1 9000
    • This will display a continous set of points (one for each packet that didn't had a response). When you see the points stopping from filling your screen, then you have to press Ctrl+C twice (once to stop the ping and one for the RedBoot prompt).
  • ping -c 1 -f 192.168.0.1; telnet 192.168.0.1 9000
    • This is a minor variation that will save you one Ctrl+C:
  • while ! ping -W 1 -c 1 192.168.0.1 2>&1 >/dev/null; do true; done && telnet 192.168.0.1 9000
    • This method is the variation of the previous two methods, with the advantage that it does not require root privileges to run.
    • This command will keep pinging RedBoot's IP address until first success, and then open into RedBoot where you'll have to press Ctrl+C to stop it form auto booting.

Accessing RedBoot from Windows

This worked for me. You can use similar ideas for any other graphical environment.

  1. Open a Windows command prompt (ie by typing cmd at the start and run prompt)
  2. At the command prompt type ping -t -w 1 192.168.0.1
  3. Do this process a couple more times and arrange the windows so that they're all visible.
    • This increases the number of pings and gives you a better chance of seeing the very short reply window you have to work with.
  4. Open hyper terminal and set this to connect via winsocks to 192.168.0.1 on port 9000.
  5. Set both windows so you can see them, set the ping running and have hyperterminal in the foreground.
  6. With your left hand on the mouse button and the mouse cursor over the connect buttonin hyperterminal, turn on the NSLU.
    • Move your other hand ready to hit Ctrl+C
  7. Watch the CMD windows. In about 5 seconds with the Ready light coloured amber, you should see a ping from 192.168.0.1
  8. Hit the mouse button with one hand and then Ctrl+C with the other.
    • If the Ready light starts to flash green it means you missed the window so try again. You will need to power cycle (by pressing ON button) the NSLU2 and reconnect it to reset it.

With newer versions (2007) the LED colour scheme is different. Just power cycle the slug and watch how many pings get lost until the redboot time-window opens after powering up. Use a Ethernet switch if your NIC takes too long to link up with a crossover cable.

Comment: Microsoft have seen fit to remove Hyper Terminal from Windows Vista. -- Dave Lane

Another option:

  1. Open a command window by typing "cmd" into the run window.
  2. Type "ping -t -w 1 192.168.0.1" and let it run.
  3. Open a second command window and type "telnet 192.168.0.1 9000" but don't hit enter.
  4. Turn on the slug. Have the second command window be your focus, but watch the pings from the first window.
  5. Hit enter when you see the ping reply. You will only get about three lines of ping replies, and if you miss them you will have to power off your slug and try again. When the telnet window opens, hit ctrl+c as fast as you can - RedBoot is available for only a short window of time. If you miss it, the slug will continue to load and you'll have missed your opportunity to get into RedBoot. --CatMarieS)

A mouseless option:

  1. WindowsKey+R
  2. Type cmd
  3. Repeat Steps 1-2
  4. Type ping -t -w 1 192.168.0.1 in the first command-window
  5. Type telnet 192.168.0.1 9000 in the second command-window
  6. Power the slug
  7. Push <ENTER> in the second command-window as soon as you see the ping reply
  8. Push <Ctrl+C> in the second command-window as soon as the telnet window opens

NOTE: On some systems you should ensure that the "Speed & Duplex" setting of your network card is set to "100 Mbps Full". "Auto" won't work. --cweber

An automatic Windows method:

As long as the steps have been followed in the “Preparation for RedBoot access” section of this Wiki, and if Windows Script Host is installed on your system (It should be on 2000 and XP systems. If not it can be d/l’ed from the Microsoft website.) the following batch file should boot the slug into RedBoot, if it does not try it again. Sometimes the ping is not caught. Also, the line:

echo Wscript.Sleep 500 >> redbootSlug.vbs

sets the time in milliseconds the script should wait for the before sending the ^C. You may have to change this if the RedBoot is not catching the SendKey.

For those who do not know how to create a batch file:

Open up Notepad and copy the code below and paste it into the Notepad window you just opened. Save the contents of the Notepad window to a file; it should end in “.txt”. In Windows Explorer, find the file you just saved and rename it “redBootSlug.bat”. You may get a message about changing the extension; if you do, just click yes.

With the slug turned off, run the batch file. When the ping timeout notices start, turn on the slug, and with any luck in a few seconds you should be in RedBoot mode. Again, if the slug boots up normally, try the batch file again. To end a script that has not caught the ping message, just close the command window.

The batch code follows:

echo off
echo Set objShell = WScript.CreateObject("WScript.Shell") > redbootSlug.vbs
echo Set objExecObject = objShell.Exec("cmd /c ping -t -w 1 192.168.0.1") >> redbootSlug.vbs
echo Wscript.Echo "Start slug after first ping timeout..." >> redbootSlug.vbs
echo Do While Not objExecObject.StdOut.AtEndOfStream >> redbootSlug.vbs
echo     strText = objExecObject.StdOut.ReadLine() >> redbootSlug.vbs
echo     Wscript.Echo strText >> redbootSlug.vbs
echo     If Instr(strText, "Reply") > 0 Then >> redbootSlug.vbs
echo         Exit Do >> redbootSlug.vbs
echo     End If >> redbootSlug.vbs
echo Loop >> redbootSlug.vbs
echo objShell.Run("Telnet 192.168.0.1 9000") >> redbootSlug.vbs
echo Do Until Success = True >> redbootSlug.vbs
echo     Success = objShell.AppActivate("Telnet") >> redbootSlug.vbs
echo Loop >> redbootSlug.vbs
echo Wscript.Sleep 500 >> redbootSlug.vbs
echo objShell.SendKeys "^C" >> redbootSlug.vbs
echo Wscript.Echo "Done... You can close this command window." >> redbootSlug.vbs
echo Wscript.Quit >> redbootSlug.vbs

CALL CScript redbootSlug.vbs
del redbootSlug.vbs

This line is not part of the batch code… I hope this helps. --dmbaker

Comment: Thanks a lot, this nice script really does the job automatically :) Just a note for localized non-English WinXP versions: In the following line echo If Instr(strText, "Reply") > 0 Then >> redbootSlug.vbs the script given above waits for the word "Reply" to come. In non-English WinXP this will not happen, so you have to replace the word "Reply" by the corresponding word of your localized WinXP, e.g. "Antwort" in German (look at your command line window). BTW, I had to use an old hub because my VAIO notebook LAN card did not want to connect directly via cross over cable :( -- Anguel Stankov

Comment: Users of Windows Vista will need to manually add Telnet support using the "Turn Windows Features on or off" link in Control Panel. -- Dave Lane

Alternative automatic Windows Method With Putty

Vista Compatible

For whatever reason the above method did not work for me, so I decided to use Putty since Putty by default send "^C" upon establishing a telnet connection.

  1. Download Putty. You can find putty at the following link http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.
    • Ensure you download the Telnet and SSH client itself.
  2. Copy Putty to "C:\Windows\System32\" - This assumes "C" is your default windows drive.
  3. Go Start Run and Type in "putty" and hit enter. - In Windows version XP SP2 and higher(Includes vista)you will get an Open File - Security Warning, Please ensure that the box that says "Always ask before opening this file" is not checked off and hit "Run"
  4. Close putty and run it again and ensure the security warning does not come up again.
  5. With putty open type in all the telnet information for Redboot found above. Host Name(192.168.0.1), Port(9000) and Connection Type(Telnet). Save the session settings as "red".
  6. Once you have saved the settings, close putty and start notepad, copy the code below and paste it into the Notepad window you just opened. Save the file as "redBootSlug.bat". Ensure the extension is ".bat"
  7. Run the batch file.
    • Note in Vista you will need to run the command prompt as administrator. Then change to the directory where you have the batch file saved. At the prompt type in "redBootSlug.bat" and hit enter.
    • Enusre that you run bat file with the slug turned off and that you turn on the slug only when ping timeout notices start. After a few seconds you will be in RedBoot mode. I have yet to see the following script fail, that is probably due to the fact that putty sends the "^C" command upon immediatley establishing telnet connection. --lithiumc

The batch code follows:

echo off
echo Set objShell = WScript.CreateObject("WScript.Shell") > redbootSlug.vbs
echo Set objExecObject = objShell.Exec("cmd /c ping -t -w 1 192.168.0.1") >> redbootSlug.vbs
echo Wscript.Echo "Start slug after first ping timeout..." >> redbootSlug.vbs
echo Do While Not objExecObject.StdOut.AtEndOfStream >> redbootSlug.vbs
echo     strText = objExecObject.StdOut.ReadLine() >> redbootSlug.vbs
echo     Wscript.Echo strText >> redbootSlug.vbs
echo     If Instr(strText, "Reply") > 0 Then >> redbootSlug.vbs
echo         Exit Do >> redbootSlug.vbs
echo     End If >> redbootSlug.vbs
echo Loop >> redbootSlug.vbs
echo objShell.Run("putty -load red") >> redbootSlug.vbs
echo Do Until Success = True >> redbootSlug.vbs
echo     Success = objShell.AppActivate("putty") >> redbootSlug.vbs
echo 	 Wscript.Sleep 200 >> redbootSlug.vbs
echo Loop >> redbootSlug.vbs
echo objShell.SendKeys "version" >> redbootSlug.vbs
echo objShell.SendKeys "{ENTER}" >> redbootSlug.vbs
echo Wscript.Echo "Done... You can close this command window." >> redbootSlug.vbs
echo Wscript.Quit >> redbootSlug.vbs

CALL CScript redbootSlug.vbs
del redbootSlug.vbs

Accessing RedBoot from FreeBSD

A small variation on the OSX instructions worked under FreeBSD:

 # Ping using a fraction of a second (must be root to do so)
 # Turn off name lookup on telnet
 sudo ping -i .3 -o 192.168.0.1 ;  telnet -N 192.168.0.1 9000

Automated Methods

Note: Once you succeed in connecting to 192.168.0.1 port 9000 and sending in a control-C to halt the automatic boot process, RedBoot will keep listening on 192.168.0.1:9000 until the next reboot. This means you that if you can automate catching the telnet you'll subsequently be able to telnet in manually.

Netcat

This is a fully automated one-liner from the shell. I created it using the manual method and Ethereal, using netcat to mimick the codes (for CTRL-C) being sent. Somehow, root and -vvv seems needed to netcat for this to work (timing issue??). Tested from FC5. I could not further automate input to RedBoot (yet), which would be a very nice feature.

This one-liner has been reformatted on to several lines, but should be executed on a single line. As root:

 echo -e "\0377\0364\0377\0375\0006" >break.bin; sudo /sbin/arping -f 192.
 168.0.1; sudo nc -D -vvv 192.168.0.1 9000 <break.bin; telnet 192.168.0.1 9000

-- Leon Woestenberg (likewise @IRC).

TCL Script

The following TCL script automates the process of telnet-ing in and issuing the control-C (and also dumps the RedBoot version info). Once the script has done the time-sensitive work you can telnet in at your leisure using your favorite telnet client.

The script was written on Windows. Tested on Windows, OS X. Should Work: Linux, Unix.

Preconditions: You need to run this from a machine can see the slug's 192.168.0.1 address.

 set done  0
 set state START

 proc on_nslu_writable { sock } {

     global state
     fileevent $sock writable ""
     if { $state == "START" } {

         puts "Connected to NSLU2..."
         set state CONN
         fileevent $sock readable [ list on_nslu_readable $sock ]
         after 1000 [list puts $sock ""]
     }
 }

 proc on_nslu_readable { sock } {

     global done state
     set data [read $sock]
     if { [eof $sock] } { puts "Got EOF - Failed."; exit }
     puts $data

     if { [string first "enter ^C to abort" $data] > 0 } {

         puts -nonewline $sock [format "%c" 3]

     } elseif { [string first "RedBoot>" $data] >= 0 } {

         if { $state == "SENTVER" } {
             set done 1
             puts ""
             puts -nonewline " Success - You should now be able"
             puts " to telnet to 192.168.0.1:9000"
         } else {
             puts $sock "version"
             set state SENTVER
         }
     }
 }

 proc try_nslu { } {

     global state
     if { $state == "START" } {
         set sock [socket -async "192.168.0.1" 9000]
         fileevent $sock writable [ list on_nslu_writable $sock ]
         fconfigure $sock -blocking false -buffering none
         after 500 try_nslu
     }
 }

 try_nslu
 vwait done

Example Usage:

  1. Save the script into a file (we'll assume you call it RedBoot.tcl).
  2. Run the script (e.g. tclsh RedBoot.tcl)
  3. Power up the slug.
  4. If everything works you should see:
 Connected to NSLU2...
 == Executing boot script in 1.800 seconds - enter ^C to abort

 ^C
 RedBoot>

 RedBoot(tm) bootstrap and debug environment [ROMRAM]
 Red Hat certified release, version 1.92 - built 15:16:07, Feb  3 2004

 Platform: IXDP425 Development Platform (XScale) 
 Copyright (C) 2000, 2001, 2002, Red Hat, Inc.

 RAM: 0x00000000-0x02000000, 0x000723a0-0x01ff3000 available
 FLASH: 0x50000000 - 0x50800000, 64 blocks of 0x00020000 bytes each.
 RedBoot>

 Success - You should now be able to telnet to 192.168.0.1:9000

-- Adrian Shotton

Using expect to connect to RedBoot

expect is a Tcl based tool for automating interactive programs. It's available on most - if not all *nix distributions. It may also be available for Windows - perhaps via Cygwin - but I haven't tried to get or run it under Windows. The following is an expect script to ping 192.168.0.1 and drop into a telnet session as soon as there's a response. It will automatically send the ^C and the version command, leaving you at the RedBoot> prompt. To use, copy the script below into your favorite text editor then save it as redboot.exp. Then enter "expect redboot,exp" from the command line, leaving off the quote marks.

  # expect script to connect to the (NSLU2) RedBoot loader.
  # set the IP address and the port for the loader.
  set target "192.168.0.1"
  set port 9000
  # 1. Start ping and wait for a response.
  # 2. When RedBoot is alive, start the telnet session.
  # 3. Allow .5 seconds after the connect for telnet 
  #    to get his act in order.
  # 4. Send the ^C and wait for the RedBoot prompt.
  # 5. Get the version information.
  # 6. Return control to the user.
  spawn ping $target
  set timeout -1
  expect {
    -re "time=.*$" close
  }
  spawn telnet $target $port
  expect -re "Escape character is.*$" {
    sleep .5
    send \003
    expect "RedBoot>" {
      send "version\r"
    }
  }
  interact

-- Ed Rubinsky

Perl Script

Here is a Perl script to automate the entire process.

  • Uses upslug (installed in /usr/local/bin) to reset the slug.
  • Assumes you have done ifconfig eth0:1 192.168.0.2 or something similar so you can reach the 192.168.0 net.
  • Assumes you are running as root.
  • Assumes you have Net::Telnet installed (OS X doesn't by default)
  • Tosses you into a telnet session after aborting the boot sequence.
 #!/usr/bin/perl -w
 # telnet_redboot.pl - ./upslug --reset;arping -f 192.168.0.1;telnet 192.168.0.1 9000

 use Net::Telnet ();

 my $host = '192.168.0.1';

 system("/usr/local/bin/upslug -r");
 printf("NSLU2 reset\n");
 system("/sbin/arping -f $host");
 printf("NSLU2 arping response\n");

 my $t = new Net::Telnet (Port => 9000, Timeout => 30);
 if(!defined($t)){
     print "new Net::Telnet failed\n";
     exit(1);
 } # if
 my $ok;
 $ok = $t->errmode("return");
 $ok = $t->open($host);
 if(!defined($ok)){
     print "open('$host') failed\n";
     $t->close();
     exit(1);
 } # if

 # == Executing boot script in 1.930 seconds - enter ^C to abort

 my $line;
 while($line = $t->getline()){
        $line =~ s/[\r\n]//;
        print "-> $line\n";
        if($line =~ m/enter \^C to abort/){
                $t->put(chr(3)); # send ^C
                print "<- \^C\n";
                $t->close();
                sleep(1);
                system("telnet $host 9000");
                exit(0);
        } # if
 } # while
 $t->close();

C program using Berkeley Sockets

The following C program will attempt a connection 10 times/second. After it successed it will send the control-C character, wait for a response, and then drop you into a telnet session. It's trivial to modify this program to run an arbitrary program with stdin/stdout connected to the slug instead of your terminal.

The telnet session has the tilde '~' character as the escape code. That can be very useful if the connection isn't dropped after a reset!

As always you can subsequently reconnect with telnet until the next reboot.

Tested on Debian linux (2006-02-12).

Preconditions: You need to run this from a machine can see the slug's 192.168.0.1 address.

#include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <netdb.h>

 #define SLUG_IP     "192.168.0.1" 
 #define SLUG_PORT   "9000"

 #define TELNET      "/usr/bin/telnet"

 char * const telnet_args[] = { "telnet", "-e", "~", SLUG_IP, SLUG_PORT, NULL };

 int main()
 {
    struct sockaddr_in sin;
    fd_set rfds, wfds;
    struct timeval timeout;
    int n;
    char buffer[1024];
    time_t stoptime = time(NULL);
    char outbound[] = { 0x03, 0x00 };
    char *out = outbound;

    int s = socket(PF_INET, SOCK_STREAM, 0);

    // set up socket address for port 9000 at 192.168.0.1
    struct hostent *h = gethostbyname(SLUG_IP);
    sin.sin_family = h->h_addrtype;
    sin.sin_port = htons(atoi(SLUG_PORT));
    memcpy(&sin.sin_addr, h->h_addr_list[0], h->h_length);

    // attempt to connect to remote system.
    while (connect(s, (struct sockaddr *) &sin, sizeof sin) == -1) {
        switch (errno) {
            case ECONNREFUSED:
            case ENETUNREACH:
            case EHOSTUNREACH:
                timeout.tv_sec = 0;
                timeout.tv_usec = 100000;  // every 100 ms
                select(1, NULL, NULL, NULL, &timeout);
                continue;
            default:
                fprintf(stderr, "connect error: %s (%s)\n",
                        strerror(errno), h->h_name);
                return errno;
        }
    }

    FD_ZERO(&rfds);
    FD_ZERO(&wfds);
    stoptime = time(NULL) + 15;
    while (difftime(stoptime, time(NULL)) > 0) {
        FD_SET(s, &rfds);
        FD_SET(s, &wfds);
        timeout.tv_sec = 0;
        timeout.tv_usec = 10000;  // every 10 ms
        n = select(s+1, &rfds, &wfds, NULL, &timeout);
        if (n == -1) {
            fprintf(stderr, "select error: %s\n", strerror(errno));
            return errno;
        }

        if (n == 0) { continue; }

        if (*out != 0 && FD_ISSET(s, &wfds)) { write(s, out++, 1); }

        if (FD_ISSET(s, &rfds)) {
            n = read(s, buffer, sizeof buffer);
            write(1, buffer, n);
            close(s);
            execv(TELNET, telnet_args);
            fprintf(stderr, "exec (%s): %s\n", TELNET, strerror(errno));
            exit(0); // just in case
        }
    }

    fprintf(stderr, "could not capture telnet port");
    close(s);

    return 0;
 }

-- Bear

Example using Red Hat Linux

You have to do the Ctrl+C really really quick.

 [root@dual root]# arping -f 192.168.0.1;telnet 192.168.0.1 9000
 ARPING 192.168.0.1 from 192.168.1.253 eth0
 Unicast reply from 192.168.0.1 [00:0F:66:7B:FE:96]  9.641ms
 Sent 7 probes (7 broadcast(s))
 Received 1 response(s)
 Trying 192.168.0.1...
 Connected to 192.168.0.1 (192.168.0.1).
 Escape character is '^]'.
 == Executing boot script in 1.820 seconds - enter ^C to abort
 ^C
 RedBoot>

The animated version.

Sources: [http://groups.yahoo.com/group/nslu2-linux/message/1096][http://groups.yahoo.com/group/nslu2-linux/message/1106]

Example using Ubuntu

I open a terminal and use the following command to get a root prompt:

 sudo su

I then use the following command to be able to access the NSLU2. My network is otherwise the typical 192.168.1.x:

 route add 192.168.0.1 eth0

My WRT54G router subnet is 255.255.255.0, and my NSLU2 is connected through a network switch, but this worked fine anyway.

  • Then I make sure my NSLU2 is powered _off_.

This is so I have all the time in the world to hit Ctrl-C when arping gets a reply. Now I use the following command to wait for telnet contact:

 arping -f 192.168.0.1; telnet 192.168.0.1 9000

The terminal now shows the following and waits for the NSLU2 to respond, which of course it won't do until I power it on:

 ARPING 192.168.0.1 from 192.168.1.102 eth0
  • Now I power _on_ the NSLU2.

Then I watch the terminal for a reply, such as the following:

 Unicast reply from 192.168.0.1 [00:18:39:31:64:A4]  6.125ms
 Sent 103 probes (103 broadcast(s))
 Received 1 response(s)
 Trying 192.168.0.1...
 Connected to 192.168.0.1.
 Escape character is '^]'.
 == Executing boot script in 1.910 seconds - enter ^C to abort

Finally, I immediately hit Ctrl-C and receive the RedBoot prompt in the terminal as shown below:

 ^C
 RedBoot>