Monthly Archives: November 2013

PBM P4 image file format

What is PBM P4?

PBM P4 is a hybrid monochrome file format, a mixture of ASCII and binary data.
It can be opened by several imaging software (eg. Gimp).

PBM P4 structure

Source of example.pbm :

P4
# CREATOR: bitmap2pbm Version 1.0.0
8 4 @0@0

The file starts with the ASCII section and ends with the binary section.

ASCII section

“P4” is the magic word which identifies the file format
The line starts with “#” is a comment (optional).
“8 4” is the dimension of the binary data
The ASCII section ends with exactly one whitespace after dimension

A character is a whitespace if isspace() returns true for it.
A comment line must end with CR of LF.
Any number of whitespaces could appear between the tokens.

Binary section

Contains the image data, where every bit corresponds to one pixel.
The example file consists of “@0@0” which is 4 bytes => 32 bits total.
Character code of “@” is 64, which is 01000000 in binary.
Character code of “0” is 48 which is 00110000 in binary.

“8 4” dimension means 4 lines of 8 bit binary data.
pbm8x4

“16 2” dimension means 2 lines of 16 bit binary data.
pbm16x2

BUT!

“5 4” dimension means 4 lines of 8 bit binary data, where only the most significant 5 bits are used.
pbm5x4

“15 2” dimension means 2 lines of 16 bit binary data, where only the most significant 15 bits are used.
pbm15x2

With lines there are no problems, they can be anything > 0.

Converting Asus WL-500g Deluxe and TP-Link TL-WR1043ND to OpenFlow switches (Part 3)

Uploading and setting up the firmware on TP-Link TL-WR1043ND router

  1. Connect your PC’s Ethernet adapter to TP-Link TL-WR1043ND router’s LAN port
    Note: The adapter configuration must remain the same as in Asus WL-500g Deluxe setup.
  2. Open http://192.168.1.1 in your browser
    Type your username and password!
    (default admin/admin)
    Click System Tools
    Click Firmware Upgrade
    Click Browse…
    Select “openwrt-ar71xx-tl-wr1043nd-v1-squashfs-factory.bin” file and click Open
    Click Upgrade
    Click OK for question about the upgrade
  3. Wait until the progress bar finish
  4. From a terminal login to the router:
    $ telnet 192.168.1.1
    You should get:
    Connected to 192.168.1.1.
    Escape character is '^]'.
    === IMPORTANT ============================
    Use 'passwd' to set your login password
    this will disable telnet and enable SSH
    ------------------------------------------
    BusyBox v1.15.3 (2013-11-16 00:12:17 CET) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
     _______                     ________        __
    |       |.-----.-----.-----.|  |  |  |.----.|  |_
    |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
    |_______||   __|_____|__|__||________||__|  |____|
    |__| W I R E L E S S   F R E E D O M
    ---------------------------------------------------
    Backfire (10.03.x Snapshot, r33081)
    ---------------------------------------------------
    * 1/3 shot Kahlua    In a shot glass, layer Kahlua
    * 1/3 shot Bailey's  on the bottom, then Bailey's,
    * 1/3 shot Vodka     then Vodka.
    ---------------------------------------------------
    root@OpenWrt:/#
  5. Change the routers IP address (just for running config):
    root@OpenWrt:/# ifconfig br-lan 192.168.1.2

    Close telnet (Ctrl + C, or by closing the terminal)

  6. Login to your router
    $ telnet 192.168.1.2
  7. Change your password:
    root@OpenWrt:/# passwd

    Enter your new password 2 times.

  8. Reconnect to the router using SSH
    root@OpenWrt:/# exit
    $ ssh root@192.168.1.2

    Type “yes” for the question about the RSA key and press Enter
    Give your password and press Enter

  9. Change switch identifier in openflow configuration:
    root@OpenWrt:/# nano /etc/config/openflow
    Change line

    option 'dpid' '000000000001'

    to

    option 'dpid' '000000000002'

    Press Ctrl+O, Enter than Ctrl+X to exit

  10. Change the network configuration
    • You can this by hand:
      root@OpenWrt:/# nano /etc/config/network
      Correct configuration:

      config 'switch'
      	option 'name' 'rtl8366rb'
      	option 'reset' '1'
      	option 'enable_vlan' '1'
      	option 'enable_learning' '0'
      config 'switch_vlan'
      	option 'device' 'rtl8366rb'
      	option 'vlan' '1'
      	option 'ports' '1 5t'
      config 'switch_vlan'
      	option 'device' 'rtl8366rb'
      	option 'vlan' '2'
      	option 'ports' '2 5t'
      config 'switch_vlan'
      	option 'device' 'rtl8366rb'
      	option 'vlan' '3'
      	option 'ports' '3 5t'
      config 'switch_vlan'
      	option 'device' 'rtl8366rb'
      	option 'vlan' '4'
      	option 'ports' '4 5t'
      config 'switch_vlan'
      	option 'device' 'rtl8366rb'
      	option 'vlan' '5'
      	option 'ports' '0 5t'
      config 'interface' 'loopback'
      	option 'ifname' 'lo'
      	option 'proto'  'static'
      	option 'ipaddr' '127.0.0.1'
      	option 'netmask' '255.0.0.0'
      config 'interface'
      	option 'ifname' 'eth0.1'
      	option 'proto' 'static'
      config 'interface'
      	option 'ifname' 'eth0.2'
      	option 'proto' 'static'
      config 'interface'
      	option 'ifname' 'eth0.3'
      	option 'proto' 'static'
      config 'interface'
      	option 'ifname' 'eth0.4'
      	option 'proto' 'static'
      config 'interface'
      	option 'ifname' 'eth0.5'
      	option 'proto' 'static'
      	option 'ipaddr' '192.168.1.2'
      	option 'netmask' '255.255.255.0'

      Press Ctrl+O, Enter than Ctrl+X to exit

    • You can do this with scp:
      Download this file with your browser: network-tplink

       $ scp network-tplink root@192.168.1.2:/etc/config/network

      Enter the router’s password

  11. Reboot the router
    root@OpenWrt:/# reboot
  12. Connect your PC’s Ethernet adapter to TP-Link TL-WR1043ND router’s WAN port
    (this is the configuration port, and the out-of-band communication port for OpenFlow)

That’s all! From now you can install an OpenFlow controller (eg. POX). The default controller address is 192.168.1.10:6633 (which can be set in /etc/config/openflow file).

If you want to restore the factory firmware:
Restoring factory firmware on TP-Link TL-WR1043ND

Jump to previous: Converting Asus WL-500g Deluxe and TP-Link TL-WR1043ND to OpenFlow switches (Part 2)

Converting Asus WL-500g Deluxe and TP-Link TL-WR1043ND to OpenFlow switches (Part 2)

Uploading and setting up the firmware on Asus WL-500g Deluxe router

Note:
OpenWrt wiki is wrong. You cannot upload the firmware through Asus WL-500g Deluxe web interface (aka OEM easy installation).

  1. Connect your PC’s Ethernet adapter to Asus WL-500g Deluxe router’s LAN port
  2. Set your network configuration to:
    IP address: 192.168.1.10
    Netmask: 255.255.255.0

    Note 1:
    If you want to make it in VirtualBox than you also have to set bridged networking by:

    1. Click Settings
    2. Click Network
    3. Select “Adapter 1” tab
    4. Set “Attached to:” to “Bridged Adapter”
    5. Set “Promiscuous Mode:” to “Allow All”
    6. Click OK

    Note 2:
    In Fedora 19, you can do this by:

    1. Click the network icon (top right corner)
    2. Click Network Settings
    3. Select Wired
    4. Click the setup icon (bottom right corner)
    5. Select IPv4
    6. Set Addresses to Manual
    7. Set Address to 192.168.1.10
    8. Set Netmask to 255.255.255.0
    9. Set Gateway to 192.168.1.1 (this is only required because of a Fedora 19 bug)
    10. Click Apply
    11. Set the “On” switch to “Off”
    12. Set the “Off” switch to “On”
    13. Close the windows
  3. Install a tftp client if you don’t have one
    $ sudo yum -y install tftp
  4. Disconnect the router from power
  5. Press and hold the reset button (at it’s back)
  6. Power up the Asus WL-500g Deluxe router (still holding the reset button)
  7. After the four LAN leds turn dark you can release the reset button
  8. The power led should start flashing slowly (if not try again from the disconnect part)
  9. From a terminal:
    $ tftp
    tftp> binary
    tftp> trace
    tftp> put openwrt-brcm47xx-squashfs.trx
    Wait until it finish
    tftp> quit
  10. Wait at least 2 minutes (for safety)
  11. Toggle the power
  12. Install a telnet client if you don’t have one
    Note: Yes it’s a shame, but Linux distributions are weird today.

    $ sudo yum -y install telnet
  13. Login to the router
    $ telnet 192.168.1.1
    You should get:

    Connected to 192.168.1.1.
    Escape character is '^]'.
    === IMPORTANT ============================
    Use 'passwd' to set your login password
    this will disable telnet and enable SSH
    ------------------------------------------
    BusyBox v1.15.3 (2013-11-16 00:12:17 CET) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    _______                     ________        __
    |       |.-----.-----.-----.|  |  |  |.----.|  |_
    |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
    |_______||   __|_____|__|__||________||__|  |____|
    |__| W I R E L E S S   F R E E D O M
    ---------------------------------------------------
    Backfire (10.03.x Snapshot, r33081)
    ---------------------------------------------------
    * 1/3 shot Kahlua    In a shot glass, layer Kahlua
    * 1/3 shot Bailey's  on the bottom, then Bailey's,
    * 1/3 shot Vodka     then Vodka.
    ---------------------------------------------------
    root@OpenWrt:/#
  14. Setup the router’s password
    root@OpenWrt:/# passwd

    Enter your new password 2 times.

  15. Reconnect to the router using SSH
    root@OpenWrt:/# exit
    $ ssh root@192.168.1.1

    Type “yes” for the question about the RSA key and press Enter
    Give your password and press Enter

  16. Change the network configuration
    • You can this by hand:
      root@OpenWrt:/# nano /etc/config/network

      Note:
      You may get here “Error opening terminal: xterm-256color.”
      It’s a Fedora 19 bug, type:
      root@OpenWrt:/# export TERM=xterm-color
      Correct configuration:

      #### VLAN configuration
      config switch eth0
      	option enable   1
      
      config switch_vlan eth0_0
      	option device   "eth0"
      	option vlan     0
      	option ports    "0 5"
      
      config switch_vlan eth0_1
      	option device   "eth0"
      	option vlan     1
      	option ports    "4 5"
      
      config switch_vlan eth0_2
      	option device   "eth0"
      	option vlan     2
      	option ports    "3 5"
      
      config switch_vlan eth0_3
      	option device   "eth0"
      	option vlan     3
      	option ports    "2 5"
      
      config switch_vlan eth0_4
      	option device   "eth0"
      	option vlan     4
      	option ports    "1 5"
      
      #### Loopback configuration
      config interface loopback
      	option ifname    "lo"
      	option proto    static
      	option ipaddr    127.0.0.1
      	option netmask    255.0.0.0
      
      #### LAN configuration
      config interface lan
      	option type     bridge
      	option ifname    "eth0.0"
      	option proto    static
      	option ipaddr    192.168.1.1
      	option netmask    255.255.255.0
      
      config interface
      	option ifname    "eth0.1"
      	option proto    static
      
      config interface
      	option ifname    "eth0.2"
      	option proto    static
      
      config interface
      	option ifname    "eth0.3"
      	option proto    static
      
      config interface
      	option ifname    "eth0.4"
      	option proto    static

      Press Ctrl+O, Enter than Ctrl+X to exit

    • You can do this with scp:
      Download this file with your browser: network-asus

      $ scp network-asus root@192.168.1.1:/etc/config/network

      Enter the router’s password

  17. Reboot the router
    root@OpenWrt:/# reboot
  18. Connect your PC’s Ethernet adapter to Asus WL-500g Deluxe router’s WAN port
    (this is the configuration port, and the out-of-band communication port for OpenFlow)

That’s all! From now you can install an OpenFlow controller (eg. POX). The default controller address is 192.168.1.10:6633 (which can be set in /etc/config/openflow file).

If you want to restore the factory firmware:
Restoring factory firmware on Asus WL-500g Deluxe

Jump to next: Converting Asus WL-500g Deluxe and TP-Link TL-WR1043ND to OpenFlow switches (Part 3)
Jump to previous: Converting Asus WL-500g Deluxe and TP-Link TL-WR1043ND to OpenFlow switches (Part 1)

Converting Asus WL-500g Deluxe and TP-Link TL-WR1043ND to OpenFlow switches (Part 1)

In this guide I will install OpenWrt Backfire on these routers with OpenFlow package.

WARNING: you may brick your router if version is > 1.7!
See Version/Model table

Device: TP-Link TL-WR1043ND Ver: 1.6
FCC ID: TE7WR1043NX
CPU: Atheros AR9132
RAM: 32 MB
Flash: 8 MB
Network: 4 + 1 ports (10/100/1000 Mb/s)
IP address before: 192.168.1.1
IP address after: 192.168.1.2
Software before: TL-WR1043ND_v1_130428
Version: 3.13.13 Build 130428 Rel.58290n

Software after: OpenWrt Backfire
Version: 10.03.1 (r33081)

OpenFlow
Stanford reference implementation
Version: 1.0
Device: Asus WL-500g Deluxe
FCC ID: MSQWL500GD
CPU: Broadcom 5365
RAM: 32 MB
Flash: 4 MB
Network: 4 + 1 ports (10/100 Mb/s)
IP address: 192.168.1.1
Software before: WL-500gD English Firmware
Version: 1.9.6.0
Software after: OpenWrt Backfire
Version: 10.03.1 (r33081)
OpenFlow

Stanford reference implementation
Version: 1.0

Build system:
Fedora 19 (64 bit)

If you are not using Fedora 19, you should virtualize it:
Installing Fedora 19 (64 bit) in VirtualBox

Building OpenWrt with OpenFlow package

  1. Open a terminal (by clicking Activities, typing “terminal” and press Enter)
  2. Update Fedora
    $ sudo yum -y update

    Enter your password
    Press Enter

  3. Install the packages that necessary to build OpenWrt
     $ sudo yum -y install git subversion binutils bzip2 gcc gcc-c++ gawk gettext flex ncurses-devel zlib-devel make patch unzip perl-ExtUtils-MakeMaker glibc glibc-devel glibc-static quilt sed sdcc intltool sharutils bison wget

    Note: All packages are necessary but some of them may has been already installed. And I am not wrong, you need subversion package because scripts use it.
    Enter your password
    Press Enter

  4. Download OpenWrt Backfire source from the OpenWrt Git repository:
    $ git clone git://git.openwrt.org/10.03/openwrt.git
  5. Get in the downloaded directory
    $ cd openwrt
  6. Update and install feeds
    $ ./scripts/feeds update -a
    $ ./scripts/feeds install -a
  7. Get out from openwrt directory
    $ cd ..
  8. Download the Stanford reference implementation of OpenFlow 1.0
    $ git clone git://gitosis.stanford.edu/openflow-openwrt

    If it doesn’t work here is a copy of it one my site: openflow-openwrt.tar.gz
    In this case you must extract it: $ tar -zxvf openflow-openwrt.tar.gz

  9. Get in the downloaded directory
    $ cd openflow-openwrt
  10. Move to the Broadcom branch
    $ git checkout -b openflow-1.0/brcm origin/openflow-1.0/brcm
  11. Link OpenFlow extension and configuration files in the OpenWrt directory
    $ cd ~/openwrt/package
    $ ln -s ~/openflow-openwrt/openflow-1.0/
    $ cd ..
    $ ln -s ~/openflow-openwrt/openflow-1.0/files
  12. Configure the build
    $ make menuconfig

    Select “Target System (…) —>”
    Select “Broadcom BCM947xx/953xx”
    Select “Target Profile (…) —>”
    Select “No WiFi”
    Select “Network —>”
    Check “openflow” package (to built-in <*>)
    Check “tc” package (to built-in <*>)
    Exit
    Select “Kernel modules —>”
    Select “Network Support —>”
    Check “kmod-tun” package (to built-in <*>)
    Exit
    Exit
    Select “Utilites —>”
    Select “Editors —>”
    Check “nano” package (to built-in <*>)
    Exit
    Exit
    Exit
    A dialog asks you here “Do you wish to save your new OpenWrt configuration?”
    Select Yes and Press Enter

  13. Make the toolchain for the target
    $ make tools/install toolchain/install
  14. Configure the Linux kernel
    $ make kernel_menuconfig

    Select Networking Support
    Select Networking options
    Select QoS and/or fair queueing
    Check Hierarchical Token Bucket (HTB) (to built-in <*>)
    Exit
    Exit
    Exit
    Exit
    Select Yes and Press Enter

  15. Build the OpenWrt image
    $ make
  16. Get out from openwrt directory
    $ cd ..
  17. Copy the created general firmware to here
    $ cp openwrt/bin/brcm47xx/openwrt-brcm47xx-squashfs.trx .

    This will be the firmware for Asus WL-500g Deluxe.

  18. Enter to openwrt directory again
    $ cd openwrt
  19. Clean everything
    $ make clean tools/clean toolchain/clean

    Note: a toolchain/clean should be enough here (but I don’t want to meet OpenWrt bugs)

  20. Get out from openwrt directory
    $ cd ..
  21. Get in the openflow directory
    $ cd openflow-openwrt
  22. Move to the TP-Link branch
    $ git checkout -b openflow-1.0/tplink origin/openflow-1.0/tplink
  23. Get to the openwrt directory
    $ cd ~/openwrt
  24. Configure the build
    $ make menuconfig

    Select “Reset to defaults”
    Select “Target System (…) —>”
    Select “Atheros AR71xx/AR7240/AR913x”
    Select “Target Profile (…) —>”
    Select “TP-LINK TL-WR1043ND v1”
    Note: From Backfire version of OpenWrt the Wifi module is automatically built in this platform, so we must clear it later from selection. DO NOT select “Default Profile (no WiFi)” here!
    Select “Network —>”
    Check “openflow” package (to built-in <*>)
    Check “tc” package (to built-in <*>)
    Uncheck “wpad-mini” package
    Exit
    Select “Kernel modules —>”
    Select “Network Support —>”
    Check “kmod-tun” package (to built-in <*>)
    Exit
    Select “Wireless Drivers”
    Uncheck “kmod-ath9k”
    Exit
    Exit
    Select “Utilites —>”
    Select “Editors —>”
    Check “nano” package (to built-in <*>)
    Exit
    Exit
    Exit
    A dialog asks you here “Do you wish to save your new OpenWrt configuration?”
    Select Yes and Press Enter

  25. Make the toolchain for the target
    $ make tools/install toolchain/install

    Note: If you have not cleaned tools than tools/install is not necessary.

  26. Configure the Linux kernel
    $ make kernel_menuconfig

    Select Networking Support
    Select Networking options
    Select QoS and/or fair queueing
    Check Hierarchical Token Bucket (HTB) (to built-in <*>)
    Exit
    Exit
    Exit
    Exit
    Select Yes and Press Enter

  27. Build the OpenWrt image
    $ make
  28. Get out from openwrt directory
    $ cd ..
  29. Copy the created general firmware to here
    $ cp openwrt/bin/ar71xx/openwrt-ar71xx-tl-wr1043nd-v1-squashfs-factory.bin .

    This will be the firmware for TP-Link TL-WR1043ND.

  30. You can safely remove the created directories:
    $ rm -rf ~/openwrt ~/openflow-openwrt

Congratulation! You have built the OpenFlow capable OpenWrt firmwares for these devices.

Jump to: Converting Asus WL-500g Deluxe and TP-Link TL-WR1043ND to OpenFlow switches (Part 2)

Bitmap manipulation programs

bitmapdd

This program creates a bitmap from a file (or device). It’s mainly used for creating a usage map of input but it can also do conversions.

You can download bitmapdd from GitHub:

$ git clone https://github.com/andmaj/bitmapdd.git

Scenario 1:

You have a file which consists of blocks of data. If a block is full of zeros than it’s free, otherwise it’s used. You want to make a bitmap from it where a bit in the file is 0 if the corresponding block is zero, otherwise it’s 1.

For example with block size set to 4:

$ bitmapdd --bs 4 --if input.dat --of output.dat

bitmapdd1

Scenerio 2:

Converting a text of zeros and ones to a binary file where every bit corresponds to one character in the original file.

$ bitmapdd --bs 1 --null 48 --if usagemap.txt --of usagemap.dat

Note: null byte has been set to 48 which is the code of character “0” in the ASCII character table. 

usagemap.txt contains text:
001100000100000001000001

usagemap.dat will contain text:
0@A

Character Decimal code Binary code
0 48 00110000
@ 64 01000000
A 65 01000001

bitmap2pbm

Creates a P4 type PBM image from a binary file. With this program you can visualize your binary (for example a usage map).

You can download bitmap2pbm from GitHub:

$ git clone https://github.com/andmaj/bitmap2pbm.git

How to use

For example creating an image of the first 10000 bytes of memtest binary:

$ head -c 10000 /boot/memtest86+-4.20 | bitmap2pbm --of memtest.pbm

You can view the image in Gimp.

bitmap2pbm

 

fat2bitmap

Creates a bitmap from FAT file system free/used clusters. The bitmap is in text format so contains zero (character 48) and one (character 49) bytes.

A zero means that the cluster is free, a one means that the cluster is used.

You can download fat2bitmap from GitHub:

$ git clone https://github.com/andmaj/fat2bitmap.git

How to use

Create a usage map of FAT file system (from filesys.iso image file)

$ fat2bitmap --if filesys.iso --of usagemap.txt

Convert the result to a binary image map with bitmapdd:

$ bitmapdd --bs 1 --null 48 --if usagemap.txt --of usagemap.dat

And finally display the usage map:

$ bitmap2pbm --if usagemap.dat --of usagemap.pbm
$ gimp usagemap.pbm &

You can also do these steps with one command:

$ fat2bitmap --if filesys.iso | bitmapdd --bs 1 --null 48 | bitmap2pbm --of usagem
ap.pbm

Note:
To create a FAT file system image file follow my guide:
http://fejlesztek.hu/create-a-fat-file-system-image-on-linux/

Create a FAT file system image on Linux

How to create the image file

[UPDATE: 2018.12.11.]
I’m sorry for the late correction, the approval request of comments landed in the SPAM. Stefan Naumann and Wojciech Franczyk pointed out correctly:

“Hi. In the point 3 you are creating FAT filesystem on the disk image, but you should have it created only on the partition. This is corrupting the image. You can check it trying fdisk -l test.img after performing the point 3 – you will get no partitions.

To fix it we first need to map the partition to /dev:
sudo losetup –offset 1048576 -f test.img
offset value is the start sector of the partition [2048] multiplied by sector size [512] to get bytes.

And create FAT filesystem on the partition, not disk:
sudo mkfs.vfat /dev/loop0

I’m leaving the solution here because I had exactly this problem as I needed valid whole disk image (to boot it), not only the partition 🙂
Nice tutorial thought, thanks for that, It helped me. Cheers.”

  1. Create a file filled with zeros:
    $ dd if=/dev/zero of=test.img count=50 bs=1M

    This command makes a 50 MB image file. Change the “count” argument for different size.

  2. Create the partition (and partition table):
    $ fdisk test.img
    
    Command (m for help): o
    Building a new DOS disklabel with disk identifier 0x46ac6035.
    
    Command (m for help): n
    Partition type:
      p primary (0 primary, 0 extended, 4 free)
      e extended
    Select (default p): <Enter>
    Using default response p
    Partition number (1-4, default 1): <Enter>
    First sector (2048-99999, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-99999, default 99999): <Enter>
    Using default value 99999
    Partition 1 of type Linux and of size 47.8 MiB is set
    
    Command (m for help): t
    Selected partition 1
    Hex code (type L to list all codes): c
    
    Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'
    
    Command (m for help): w
    The partition table has been altered!
    
    Syncing disks
  3. Create the FAT file system in the image
    $ mkfs.vfat test.img 
    mkfs.fat 3.0.22 (2013-07-19)

 How to mount the image and copy files

  1. Create a directory for mounting
    $ sudo mkdir /mnt/test
  2. Mount the image
    $ sudo mount test.img /mnt/test

    Now you can copy/delete files in /mnt/test directory which will be written into the image file.

  3. After file operations unmount the image
    $ sudo umount /mnt/test
  4. Delete the directory
    $ sudo rmdir /mnt/test

Restoring factory firmware on TP-Link TL-WR1043ND

If you have installed OpenWrt Backfire on your TP-Link TL-WR1043ND and want to restore the factory firmware than this guide is for you.

Device: TP-Link TL-WR1043ND Ver: 1.6
FCC ID: TE7WR1043NX
CPU: Atheros AR9132
RAM: 32 MB
Flash: 8 MB
Network: 4 + 1 ports (10/100/1000 Mb/s)
IP address: 192.168.1.2

Software on router before

OpenWrt Backfire
Version: 10.03.1 (r33081)

Software on router after

TL-WR1043ND_v1_130428
Version: 3.13.13 Build 130428 Rel.58290n

Host operation system is Fedora 19 (64 bit).
If you are not using Fedora 19, you should virtualize it:
Installing Fedora 19 (64 bit) in VirtualBox

I presume that you can communicate with your router.

Preparations

  1. Go to TP-Link Support site: http://www.tp-link.com/en/support/download/
    Click “TL- WR1043ND” (it’s in the 300Mbps Wireless N group)
    tplink_support
  2. Read the warning message and click “If you have read the above notice, please click here to find hardware version.
  3. My router is V1 because “Model: TL-WR1043ND Ver: 1.6” written on its back
    Click “TL-WR1043ND V1
    version_select
  4. Download the firmware by clicking “TL-WR1043ND_v1_130428
    Warning: Do NOT download an other firmware version because in case of TP-Link there may be different steps to take.
    If it doesn’t work here is a copy of it one my site: TL-WR1043ND_v1_130428.zip
    correct_firmware
  5. Decompress the firmware
     $ unzip TL-WR1043ND_v1_130428.zip
  6. Check firmware checksum
     $ sha1sum wr1043nv1_en_3_13_13_up_boot\(130428\).bin

    It should return:
    25c3c2bd86dba8bd4c68489489e28e580560bf6c wr1043nv1_en_3_13_13_up_boot(130428).bin

  7. This firmware version also contains the boot code so we have to strip it first
     $ dd if=wr1043nv1_en_3_13_13_up_boot\(130428\).bin of=wr1043nd_v1_correct.bin skip=257 bs=512
  8. Check the corrected firmware checksum
     $ sha1sum wr1043nd_v1_correct.bin

    It should return:
    6899d121113c92d93a20ae7b308bc06a3295aba0  wr1043nd_v1_correct.bin

Firmware update

  1. Copy this file in the router
     $ scp wr1043nd_v1_correct.bin root@192.168.1.2:/tmp/

    Note: My router IP address is 192.168.1.2, change it to your router IP address in all commands

  2. Login to your router
     $ ssh root@192.168.1.2

    Enter your password.

  3. Write the firmware to flash
    root@OpenWrt:~# mtd -r write /tmp/wr1043nd_v1_correct.bin firmware

    mtd

  4. Wait until “Rebooting …” appears
    Note: If you have configured your router as an OpenFlow switch before using my guide than you have to pull out the LAN cable from WAN port now and plug into a LAN port (eg. LAN1).
  5. Go to http://192.168.1.1 in your browser
    user: admin
    password: admin

    Press Enter

    login_page

Congratulation! You have just restored the original firmware.

Restoring factory firmware on Asus WL-500g Deluxe

If you have installed OpenWrt Backfire on your Asus WL-500g Deluxe and want to restore the factory firmware than this guide is for you.

Device: Asus WL-500g Deluxe
FCC ID: MSQWL500GD
CPU: Broadcom 5365
RAM: 32 MB
Flash: 4 MB
Network: 4 + 1 ports (10/100 Mb/s)
IP address: 192.168.1.1

Software on router before

OpenWrt Backfire
Version: 10.03.1 (r33081)

Software on router after

WL-500gD English Firmware
Version: 1.9.6.0

Host operation system is Fedora 19 (64 bit).
If you are not using Fedora 19, you should virtualize it:
Installing Fedora 19 (64 bit) in VirtualBox

I presume that you can communicate with your router.

Preparations

  1. Go to Asus Support site: http://support.asus.com/download/
    Type “wl-500g deluxe” in Model Name Search box
    Click Searchasus_support_search
  2. Click “WL-500g Deluxe
    found_wl500gd
  3. Select WinXP as OS
  4. Click Firmware
  5. Click “Global” in the Version 1.9.6.0 frame to download the firmware
    If it doesn’t work here is a copy of it one my site: WL500gx_1960_EN.zip
    router_page
  6. Decompress the firmware
    $ unzip WL500gx_1960_EN.zip
  7. Check firmware checksum
    $ sha1sum WL500gx_1.9.6.0_EN.trx

    It should return:
    a273a7e7c5278d4eb76c53c20492a772187ced59  WL500gx_1.9.6.0_EN.trx

Firmware update

  1. Copy this file in the router
    $ scp WL500gx_1.9.6.0_EN.trx root@192.168.1.1:/tmp/

    Note: My router IP address is 192.168.1.1, change it to your router IP address in all commands

  2. Login to your router
    $ ssh root@192.168.1.1

    Enter your password.

  3. Write the firmware to flash
    root@OpenWrt:~# mtd -r write /tmp/WL500gx_1.9.6.0_EN.trx linux

    mtd

  4. Wait until “Rebooting …” appears
    Note: If you have configured your router as an OpenFlow switch before using my guide than you have to pull out the LAN cable from WAN port now and plug into a LAN port (eg. LAN1).
  5. Go to http://192.168.1.1 in your browser
    user: admin
    password: admin

    Press Enter

    stock_firmware

Congratulation! You have just restored the original firmware.

Installing Fedora 19 (64 bit) in VirtualBox

Requirements

64 bit x86 processor

  • at least 20 GB free space
  • at least 4 GB ram
  • Internet connection

Preparations

  1. Download and install Oracle VM VirtualBox from here:
    https://www.virtualbox.org/wiki/Downloads

    Binaries are under “VirtualBox platform packages” label
    I’ve used version 4.3.0 (but any later version should work too)
  2. Download Fedora 19 Desktop Edition (64 bit) from here:
    http://fedoraproject.org/get-fedora

    Actual link for me:
    http://download.fedoraproject.org/pub/fedora/linux/releases/19/Live/x86_64/Fedora-Live-Desktop-x86_64-19-1.iso

Installation

  1. Start Oracle VM VirtualBox
  2. Click New button
  3. Give some details about the virtual machine
    Name: Fedora 19
    Type: Linux
    Version: Fedora (64 bit)

    Click Next

  4. Set memory size to at least 1500 MB
    Click Next
  5. Select “Create a virtual hard drive now” option
    Click Create
  6. Select “VDI (VirtualBox Disk Image)” option
    Click Next
  7. Select “Dynamically allocated” option
    Click Next
  8. Set the size of the virtual hard drive to at least 16.00 GB
    Click Create
  9. Right click on “Fedora 19” machine -> Settings…
  10. Optional step
    If you have more than 1 CPU cores in your host machine:
    Select System → Processor
    Increase processor count for up to (your cores number – 1).
  11. Select Storage
    Click Empty (under Controller: IDE)
    Click on the disk icon in Attributes frame on the right
    Choose a virtual CD/DVD disk file…
    Select Fedora-Live-Desktop-x86_64-19-1.iso
    Click Open
    Click Controller: SATA
    Check Use Host I/O Cache
    Click OK
  12. Start the virtual machine by double clicking on “Fedora 19” label
  13. Dismiss the warning messages (click on x)
    Click somewhere inside the window
    If you get an information message here:
    Check “Do not show this message again
    Note: After clicking in the window the mouse cursor will be captured and all input goes to the virtual machine. If you want to leave the virtual machine press the Right Ctrl key. However from a point Fedora 19 supports mouse pointer integration where it is not necessary.
  14. Select “Start Fedora Live
    Press Enter
    (or simply wait for Fedora Live to autostart)
  15. In “Welcome to Fedora” window click “Install to Hard Drive
  16. Select English (United States)
    Click Continue
  17. Optional steps
    To change the time zone click “Change Date & Time
    Select the region and the city
    Click Done
    To change the keyboard layout click “Keyboard

    Click on the “+” sign and select your layout
    Click Add
    Change the order of layouts by clicking on your layout and the “^” sign

    Click Done
    Warning: This layout will only work on your installed system. That means that if you are entering a password in the installer it will be written according to the us layout.
  18. Click “Installation destination
    Click on “ATA VBOX HARDDISK” under Local Standard Disks
    Click Done
  19. Select “Automatically configure my Fedora installation to the disk(s) I selected and return me to the main menu.
    Click Continue
  20. Click “Begin Installation
  21. During installation you should set root password and create a user
    Click “ROOT PASSWORD
    Enter a Root Password and confirm it
    Click Done (or if you’ve given a weak password click it twice)
    Click “USER CREATION
    Check “Make this user administrator
    Enter user data
    Click Done (or if you’ve given a weak password click it twice)
  22. After installation has finished click Quit
  23. Click “Live System User
    Click “Power Off
    Click “Power Off
  24. Right click on “Fedora 19” machine → Settings
    Choose Storage
    Click on “Fedora-Live-Desktop-..” (under Controller: IDE)
    Click on the disk icon in Attributes frame on the right
    Remove disk from virtual drive
    Click OK

Update the system

  1. Start the virtual machine by double clicking on “Fedora 19” machine
    Dismiss the message about “Auto capture keyboard”.
    This is the boot menu, Fedora will start automatically.
    Note: If you press a key here you interrupt the boot of the default configuration. In this case choose the highest option (which is right in most cases) and press Enter.
  2. Click on your user or press Enter
    Enter your password
    Click “Sign In” or press Enter
  3. In Welcome screen choose English (United States)
    Click Next
  4. Select your keyboard layout
    Click Next
    Click Next
    Click “Start using GNOME 3
  5. Watch the sort tutorial(s)
  6. Update your system manually by doing the following:
    Click Activities
    Type “update” in the search box
    Click “Software Update
    Click “Install Updates
    Note:
    At this point you may encounter a kernel bug:
    WARNING: at net/sched/sch_generic.c:255 dev_watchdog+0x248/0x260()
    In this case continue the update process from a terminal:
    Click Activities
    Type “terminal” in the search box
    Click “Terminal

    $ sudo yum -y update

    Press Enter
    Enter your password

  7. If “A restart is required.” message pops up than click Close
  8. Close every window
  9. Click on the user’s name (in the upper right side of the screen)
    Click “Power Off
    Click “Restart
  10. Login as before
  11. Check updates as before
  12. All software is up to date” message should appear
    Note: If more updates are available than apply them

Install Guest Additions

  1. Open a terminal (by clicking Activities, typing “terminal” and press Enter)
  2. Install kernel development tools:
     $ sudo yum install kernel-devel gcc

    Enter your password
    Type “y” and Enter

  3. Install Guest Additions:
    Click Devices in VirtualBox menu
    Click Install Guest Additions…
  4. Click Run
  5. Type your password and click Authenticate
  6. After finish press Enter
  7. Set clipboard sharing between the host and the virtual machine
    Click Devices menu in the VirtualBox window
    Check Shared Clipboard → Bidirectional
  8. Power off the virtual machine:
    Click on the user’s name (in the upper right side of the screen)
    Click “Power Off
    Click “Power Off

Congratulation! You have just installed Fedora 19 in VirtualBox

Make a snapshot (optional)

  1. Make a snapshot of this state to be able to restore it later
    Click “Snapshots” in the Oracle VM VirtualBox Manager window
    Click the “Take Snapshot” button that looks like a camera
  2. Type “Original” as Snapshot Name
    Click OK
    Note: Now you can restore any time the original state by clicking on “Original” and the “Restore snapshot” button (a camera with an arrow)