Jump to: navigation, search

Serial Port Access and Firmware Recovery for MP-02

Author: Terry Gillett

Introduction

The following describes how to get access to the serial port on the MP-02 router and how to recover the firmware on the device in the event that the device is not accessible by normal means.

The process requires a PC running a serial port, a level shifter adapter, a serial terminal program, and a tftp server program.

A Serial Adapter specifically built for the MP-02 is available and is used as the basis of this description. Generic serial adapters and USB Serial Adapters may also be used by accessing the appropriate pins for TX, RX and Gnd.

Preparation

Using a MP-02 Serial Port Adaptor

A Serial Port adaptor board is available for the MP-02. This adapter board plugs in to the header between the power connector and the Ethernet connectors on the main MP-02 board, with the serial connector facing away from the board.

The adaptor board provides RS-232 level signals via a DB-9 connector. The connector is designed to be connected to the serial port on a PC via a straight DB-9 M-F serial cable.

NOTE: Ensure that the MP-02 device is powered OFF when fitting and removing the Adaptor to avoid damage.


Set Up Serial Terminal Program

To use the Serial interface on the MP-02, a Serial Terminal program is required on your PC.

Install a serial terminal program, e.g. GtkTerm for a Ubuntu PC. Set the configuration to be

 - 115kbps
 - no parity
 - 8 bits
 - 1 stop bit
 - No Flow Control

The serial port setting will typically be /dev/ttyS0 for the first serial port on the PC, or ttyUSB0 for a USB serial adapter.

Note 1: You need to add your user to the 'dialout' group to access the serial port:

 $ sudo  usermod  -a  -G  dialout  $USER

You *MUST* log out and log back in for this to become effective.

Check that the serial port is in the 'dialout' group

 $  ls -l /dev/ttyUSB0
       crw-rw---- 1 root dialout 188, 0 Apr 12 17:11 /dev/ttyUSB0

Note2: It may be necessary to run the terminal with root privileges if you have a problem with permissions to configure the ttyS0 or ttyUSB0 port. To do this, open a terminal and enter the command:

 $ sudo gtkterm

Connect the PC serial port to the serial port adapter on the MP-02 with a straight serial cable. A 'null modem' should not be required.

Using U-boot

Connect the serial port and power up the MP-02.

You should see the U-boot start up sequence, which includes two pauses to allow you to halt the normal startup process.

The first prompt allows you to press any key and invoke the U-boot prompt.

At the U-boot prompt, type '? <Enter>' to see a list of available commands.

 dr_boot> ?

The second prompt allows you to press the 'f' key, followed by 'Enter' to switch in to Failsafe mode.

If you do not interrupt the startup process, the normal boot sequence will continue until eventually you will get to a prompt to press 'Enter' to activate a terminal session. Pressing the Enter key at this point will take to to the system command line as the 'root' user.

Note that after this last prompt appears on screen, further output from the device will continue to appear on screen, and the prompt will scroll off screen. You may press Enter at any time to go to the command line.


Set up the TFTP Server

This section describes the installation and configuration of the tftpd-hpa software on a Ubuntu workstation.

(For a Windows workstation see e.g. http://tftpd32.jounin.net/)


A. Install tftpd-hpa

 $ sudo apt-get install tftpd-hpa


B. Configure tftpd-hpa for Daemon Operation

Configure the newly installed TFTP to run as a daemon by editing the /etc/default/tftpd-hpa file:

 $ gksudo gedit /etc/default/tftpd-hpa

Add the line:

 RUN_DAEMON="yes"


C. Set the TFTP root directory

This config file also defines where your TFTP server is serving from ie the tftp root directory.

The default location is /var/lib/tftpboot but may be changed in this file if desired.


D. Start the TFTP service Start the newly configured TFTP service as follows:

For Ubuntu 10.04 and later, use:

 $ sudo service tftpd-hpa start

For earlier versions of Ubuntu use:

 $ sudo /etc/init.d/tftpd-hpa start


E. Test the TFTP server

Save a suitable small file 'myfile' in the TFTP Server root directory.

Use the 'tftp' command in a terminal session to copy the file to a working directory

 $ tftp
 tftp> ?  (for a list of commands)
 tftp> connect localhost  OR   connect <IP_address_of_PC>
 tftp> get myfile

You should see the file received with details of size and time.


Flashing Firmware via Serial Port and TFTP

Firmware can be loaded on to the device using the serial port and the U-boot firmware on the device to set up a TFTP transfer via the Ethernet port.

This is useful to replace a firmware that can not be recovered by other means such as the OpenWrt Failsafe mechanism.

The U-boot firmware provides a tftp client. To flash the device with new firmware, you must have a tftp server set up on your PC as described above, and the necessary files available to the tftp server to send to the device.

To set up a tftp server, see the section above on installing the TFTP Server software.

By default, the U-boot firmware is configured with the tftp client on 192.168.255.1, and expects to find the tftp server on 192.168.255.2.

These values can be viewed, changed and saved with the U-boot commands printenv/setenv/saveenv


A. Set up the PC with a static IP of 192.168.255.2 on the Ethernet port and connect it to the LAN (eth0) port of the MP-02 with an Ethernet cable.

Ensure that the TFTP server is correctly configured and running.


B. Copy the 'kernel' and 'squashfs' files in to the TFTP Server root directory.

The required files are typically:

 openwrt-ar71xx-generic-dragino2-kernel.bin                              and
 openwrt-ar71xx-generic-dragino2-rootfs-squashfs.bin

Copy/rename these files to 'kernel' and 'squashfs' to match the tftp commands to be used in Step D (see below).


C. Start Serial Console

Connect the MP-02 serial port to the PC serial port.

Start up the Serial Terminal program and ensure it is correctly configured (115k,8,N,1).

Power up the MP-02 and interrupt the boot sequence to get to the U-boot prompt.

Try to ping the PC with the command:

 dr_boot>   ping 192.168.255.2

You should see a response indicating the the ping is successful.

NOTE: Make sure that the ping response indicates that the "eth0" port is alive. If the response indicates "eth1" then the Ethernet cable is in the wrong connector on the MP02. Change it and try again.


D. Restart the tftp server to ensure it is correctly associated with the running network:

For Ubuntu 10.04 and later, use:

$ sudo service tftpd-hpa restart

For earlier versions of Ubuntu use:

$ sudo /etc/init.d/tftpd-hpa restart


E. On the serial console of U-boot, enter these two commands to transfer the 'kernel' and 'squashfs' files and write them to memory:

 dr_boot>   tftp 0x81000000 kernel; erase 0x9f040000 +0x100000; cp.b 0x81000000 0x9f040000 $filesize
 dr_boot>   tftp 0x81000000 squashfs; erase 0x9f140000 +0xea0000; cp.b 0x81000000 0x9f140000 $filesize

You can copy these commands (starting at tftp ...) and paste them into the terminal window using the GtkTerm menu item Edit/Paste.


F. Once this is finished, boot from uboot:

 dr_boot>   boot

You should see the full boot sequence. Press Enter at the end of the sequence to enter terminal mode.


G. The MP-02 device should now be running normally. Power down the device and remove the serial port adaptor.